2
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
7
/* $Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/short_term.c,v 1.2 1994/05/10 20:18:47 jutta Exp $ */
19
* SHORT TERM ANALYSIS FILTERING SECTION
24
static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp),
25
word * LARc, /* coded log area ratio [0..7] IN */
26
word * LARpp) /* out: decoded .. */
28
register word temp1 /* , temp2 */;
29
register long ltmp; /* for GSM_ADD */
31
/* This procedure requires for efficient implementation
34
* INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
35
* MIC[1..8] = minimum value of the LARc[1..8]
38
/* Compute the LARpp[1..8]
41
/* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
43
* temp1 = GSM_ADD( *LARc, *MIC ) << 10;
45
* temp1 = GSM_SUB( temp1, temp2 );
47
* assert(*INVA != MIN_WORD);
49
* temp1 = GSM_MULT_R( *INVA, temp1 );
50
* *LARpp = GSM_ADD( temp1, temp1 );
55
#define STEP( B, MIC, INVA ) \
56
temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
57
temp1 = GSM_SUB( temp1, B << 1 ); \
58
temp1 = GSM_MULT_R( INVA, temp1 ); \
59
*LARpp++ = GSM_ADD( temp1, temp1 );
61
STEP( 0, -32, 13107 );
62
STEP( 0, -32, 13107 );
63
STEP( 2048, -16, 13107 );
64
STEP( -2560, -16, 13107 );
66
STEP( 94, -8, 19223 );
67
STEP( -1792, -8, 17476 );
68
STEP( -341, -4, 31454 );
69
STEP( -1144, -4, 29708 );
71
/* NOTE: the addition of *MIC is used to restore
77
/* Computation of the quantized reflection coefficients
80
/* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
84
* Within each frame of 160 analyzed speech samples the short term
85
* analysis and synthesis filters operate with four different sets of
86
* coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
87
* and the actual set of decoded LARs (LARpp(j))
89
* (Initial value: LARpp(j-1)[1..8] = 0.)
92
static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp),
93
register word * LARpp_j_1,
94
register word * LARpp_j,
98
register longword ltmp;
100
for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
101
*LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
102
*LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1));
106
static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp),
107
register word * LARpp_j_1,
108
register word * LARpp_j,
109
register word * LARp)
112
register longword ltmp;
113
for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
114
*LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
118
static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp),
119
register word * LARpp_j_1,
120
register word * LARpp_j,
121
register word * LARp)
124
register longword ltmp;
126
for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
127
*LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
128
*LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
133
static void Coefficients_40_159 P2((LARpp_j, LARp),
134
register word * LARpp_j,
135
register word * LARp)
139
for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
145
static void LARp_to_rp P1((LARp),
146
register word * LARp) /* [0..7] IN/OUT */
148
* The input of this procedure is the interpolated LARp[0..7] array.
149
* The reflection coefficients, rp[i], are used in the analysis
150
* filter and in the synthesis filter.
155
register longword ltmp;
157
for (i = 1; i <= 8; i++, LARp++) {
159
/* temp = GSM_ABS( *LARp );
161
* if (temp < 11059) temp <<= 1;
162
* else if (temp < 20070) temp += 11059;
163
* else temp = GSM_ADD( temp >> 2, 26112 );
165
* *LARp = *LARp < 0 ? -temp : temp;
169
temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
170
*LARp = - ((temp < 11059) ? temp << 1
171
: ((temp < 20070) ? temp + 11059
172
: GSM_ADD( temp >> 2, 26112 )));
175
*LARp = (temp < 11059) ? temp << 1
176
: ((temp < 20070) ? temp + 11059
177
: GSM_ADD( temp >> 2, 26112 ));
184
static void Short_term_analysis_filtering P4((S,rp,k_n,s),
185
struct gsm_state * S,
186
register word * rp, /* [0..7] IN */
187
register int k_n, /* k_end - k_start */
188
register word * s /* [0..n-1] IN/OUT */
191
* This procedure computes the short term residual signal d[..] to be fed
192
* to the RPE-LTP loop from the s[..] signal and from the local rp[..]
193
* array (quantized reflection coefficients). As the call of this
194
* procedure can be done in many ways (see the interpolation of the LAR
195
* coefficient), it is assumed that the computation begins with index
196
* k_start (for arrays d[..] and s[..]) and stops with index k_end
197
* (k_start and k_end are defined in 4.2.9.1). This procedure also
198
* needs to keep the array u[0..7] in memory for each call.
201
register word * u = S->u;
203
register word di, zzz, ui, sav, rpi;
204
register longword ltmp;
210
for (i = 0; i < 8; i++) { /* YYY */
216
zzz = GSM_MULT_R(rpi, di);
217
sav = GSM_ADD( ui, zzz);
219
zzz = GSM_MULT_R(rpi, ui);
220
di = GSM_ADD( di, zzz );
227
#if defined(USE_FLOAT_MUL) && defined(FAST)
229
static void Fast_Short_term_analysis_filtering P4((S,rp,k_n,s),
230
struct gsm_state * S,
231
register word * rp, /* [0..7] IN */
232
register int k_n, /* k_end - k_start */
233
register word * s /* [0..n-1] IN/OUT */
236
register word * u = S->u;
242
register float scalef = 3.0517578125e-5;
243
register float sav, di, temp;
245
for (i = 0; i < 8; ++i) {
247
rpf[i] = rp[i] * scalef;
251
for (i = 0; i < 8; ++i) {
252
register float rpfi = rpf[i];
253
register float ufi = uf[i];
256
temp = rpfi * di + ufi;
262
for (i = 0; i < 8; ++i) u[i] = uf[i];
264
#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
266
static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
267
struct gsm_state * S,
268
register word * rrp, /* [0..7] IN */
269
register int k, /* k_end - k_start */
270
register word * wt, /* [0..k-1] IN */
271
register word * sr /* [0..k-1] OUT */
274
register word * v = S->v;
276
register word sri, tmp1, tmp2;
277
register longword ltmp; /* for GSM_ADD & GSM_SUB */
283
/* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
287
tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
289
: 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
292
sri = GSM_SUB( sri, tmp2 );
294
/* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
296
tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD
298
: 0x0FFFF & (( (longword)tmp1 * (longword)sri
301
v[i+1] = GSM_ADD( v[i], tmp1);
308
#if defined(FAST) && defined(USE_FLOAT_MUL)
310
static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
311
struct gsm_state * S,
312
register word * rrp, /* [0..7] IN */
313
register int k, /* k_end - k_start */
314
register word * wt, /* [0..k-1] IN */
315
register word * sr /* [0..k-1] OUT */
318
register word * v = S->v;
321
float va[9], rrpa[8];
322
register float scalef = 3.0517578125e-5, temp;
324
for (i = 0; i < 8; ++i) {
326
rrpa[i] = (float)rrp[i] * scalef;
329
register float sri = *wt++;
331
sri -= rrpa[i] * va[i];
332
if (sri < -32768.) sri = -32768.;
333
else if (sri > 32767.) sri = 32767.;
335
temp = va[i] + rrpa[i] * sri;
336
if (temp < -32768.) temp = -32768.;
337
else if (temp > 32767.) temp = 32767.;
342
for (i = 0; i < 9; ++i) v[i] = va[i];
345
#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
347
void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s),
349
struct gsm_state * S,
351
word * LARc, /* coded log area ratio [0..7] IN */
352
word * s /* signal [0..159] IN/OUT */
355
word * LARpp_j = S->LARpp[ S->j ];
356
word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
361
#if defined(FAST) && defined(USE_FLOAT_MUL)
362
# define FILTER (* (S->fast \
363
? Fast_Short_term_analysis_filtering \
364
: Short_term_analysis_filtering ))
367
# define FILTER Short_term_analysis_filtering
370
Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
372
Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
374
FILTER( S, LARp, 13, s);
376
Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
378
FILTER( S, LARp, 14, s + 13);
380
Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
382
FILTER( S, LARp, 13, s + 27);
384
Coefficients_40_159( LARpp_j, LARp);
386
FILTER( S, LARp, 120, s + 40);
389
void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s),
390
struct gsm_state * S,
392
word * LARcr, /* received log area ratios [0..7] IN */
393
word * wt, /* received d [0..159] IN */
395
word * s /* signal s [0..159] OUT */
398
word * LARpp_j = S->LARpp[ S->j ];
399
word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
404
#if defined(FAST) && defined(USE_FLOAT_MUL)
406
# define FILTER (* (S->fast \
407
? Fast_Short_term_synthesis_filtering \
408
: Short_term_synthesis_filtering ))
410
# define FILTER Short_term_synthesis_filtering
413
Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
415
Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
417
FILTER( S, LARp, 13, wt, s );
419
Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
421
FILTER( S, LARp, 14, wt + 13, s + 13 );
423
Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
425
FILTER( S, LARp, 13, wt + 27, s + 27 );
427
Coefficients_40_159( LARpp_j, LARp );
429
FILTER(S, LARp, 120, wt + 40, s + 40);