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.
18 * SHORT TERM ANALYSIS FILTERING SECTION
23 static void Decoding_of_the_coded_Log_Area_Ratios P2((LARc,LARpp),
24 word * LARc, /* coded log area ratio [0..7] IN */
25 word * LARpp) /* out: decoded .. */
27 register word temp1 /* , temp2 */;
28 register long ltmp; /* for GSM_ADD */
30 /* This procedure requires for efficient implementation
33 * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
34 * MIC[1..8] = minimum value of the LARc[1..8]
37 /* Compute the LARpp[1..8]
40 /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
42 * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
44 * temp1 = GSM_SUB( temp1, temp2 );
46 * assert(*INVA != MIN_WORD);
48 * temp1 = GSM_MULT_R( *INVA, temp1 );
49 * *LARpp = GSM_ADD( temp1, temp1 );
54 #define STEP( B, MIC, INVA ) \
55 temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
56 temp1 = GSM_SUB( temp1, B << 1 ); \
57 temp1 = GSM_MULT_R( INVA, temp1 ); \
58 *LARpp++ = GSM_ADD( temp1, temp1 );
60 STEP( 0, -32, 13107 );
61 STEP( 0, -32, 13107 );
62 STEP( 2048, -16, 13107 );
63 STEP( -2560, -16, 13107 );
65 STEP( 94, -8, 19223 );
66 STEP( -1792, -8, 17476 );
67 STEP( -341, -4, 31454 );
68 STEP( -1144, -4, 29708 );
70 /* NOTE: the addition of *MIC is used to restore
76 /* Computation of the quantized reflection coefficients
79 /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
83 * Within each frame of 160 analyzed speech samples the short term
84 * analysis and synthesis filters operate with four different sets of
85 * coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
86 * and the actual set of decoded LARs (LARpp(j))
88 * (Initial value: LARpp(j-1)[1..8] = 0.)
91 static void Coefficients_0_12 P3((LARpp_j_1, LARpp_j, LARp),
92 register word * LARpp_j_1,
93 register word * LARpp_j,
97 register longword ltmp;
99 for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
100 *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
101 *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1));
105 static void Coefficients_13_26 P3((LARpp_j_1, LARpp_j, LARp),
106 register word * LARpp_j_1,
107 register word * LARpp_j,
108 register word * LARp)
111 register longword ltmp;
112 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
113 *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
117 static void Coefficients_27_39 P3((LARpp_j_1, LARpp_j, LARp),
118 register word * LARpp_j_1,
119 register word * LARpp_j,
120 register word * LARp)
123 register longword ltmp;
125 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
126 *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
127 *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
132 static void Coefficients_40_159 P2((LARpp_j, LARp),
133 register word * LARpp_j,
134 register word * LARp)
138 for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
144 static void LARp_to_rp P1((LARp),
145 register word * LARp) /* [0..7] IN/OUT */
147 * The input of this procedure is the interpolated LARp[0..7] array.
148 * The reflection coefficients, rp[i], are used in the analysis
149 * filter and in the synthesis filter.
154 register longword ltmp;
156 for (i = 1; i <= 8; i++, LARp++) {
158 /* temp = GSM_ABS( *LARp );
160 * if (temp < 11059) temp <<= 1;
161 * else if (temp < 20070) temp += 11059;
162 * else temp = GSM_ADD( temp >> 2, 26112 );
164 * *LARp = *LARp < 0 ? -temp : temp;
168 temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
169 *LARp = - ((temp < 11059) ? temp << 1
170 : ((temp < 20070) ? temp + 11059
171 : GSM_ADD( temp >> 2, 26112 )));
174 *LARp = (temp < 11059) ? temp << 1
175 : ((temp < 20070) ? temp + 11059
176 : GSM_ADD( temp >> 2, 26112 ));
183 static void Short_term_analysis_filtering P4((S,rp,k_n,s),
184 struct gsm_state * S,
185 register word * rp, /* [0..7] IN */
186 register int k_n, /* k_end - k_start */
187 register word * s /* [0..n-1] IN/OUT */
190 * This procedure computes the short term residual signal d[..] to be fed
191 * to the RPE-LTP loop from the s[..] signal and from the local rp[..]
192 * array (quantized reflection coefficients). As the call of this
193 * procedure can be done in many ways (see the interpolation of the LAR
194 * coefficient), it is assumed that the computation begins with index
195 * k_start (for arrays d[..] and s[..]) and stops with index k_end
196 * (k_start and k_end are defined in 4.2.9.1). This procedure also
197 * needs to keep the array u[0..7] in memory for each call.
200 register word * u = S->u;
202 register word di, zzz, ui, sav, rpi;
203 register longword ltmp;
209 for (i = 0; i < 8; i++) { /* YYY */
215 zzz = GSM_MULT_R(rpi, di);
216 sav = GSM_ADD( ui, zzz);
218 zzz = GSM_MULT_R(rpi, ui);
219 di = GSM_ADD( di, zzz );
226 #if defined(USE_FLOAT_MUL) && defined(FAST)
228 static void Fast_Short_term_analysis_filtering P4((S,rp,k_n,s),
229 struct gsm_state * S,
230 register word * rp, /* [0..7] IN */
231 register int k_n, /* k_end - k_start */
232 register word * s /* [0..n-1] IN/OUT */
235 register word * u = S->u;
241 register float scalef = 3.0517578125e-5;
242 register float sav, di, temp;
244 for (i = 0; i < 8; ++i) {
246 rpf[i] = rp[i] * scalef;
250 for (i = 0; i < 8; ++i) {
251 register float rpfi = rpf[i];
252 register float ufi = uf[i];
255 temp = rpfi * di + ufi;
261 for (i = 0; i < 8; ++i) u[i] = uf[i];
263 #endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
265 static void Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
266 struct gsm_state * S,
267 register word * rrp, /* [0..7] IN */
268 register int k, /* k_end - k_start */
269 register word * wt, /* [0..k-1] IN */
270 register word * sr /* [0..k-1] OUT */
273 register word * v = S->v;
275 register word sri, tmp1, tmp2;
276 register longword ltmp; /* for GSM_ADD & GSM_SUB */
282 /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
286 tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
288 : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
291 sri = GSM_SUB( sri, tmp2 );
293 /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
295 tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD
297 : 0x0FFFF & (( (longword)tmp1 * (longword)sri
300 v[i+1] = GSM_ADD( v[i], tmp1);
307 #if defined(FAST) && defined(USE_FLOAT_MUL)
309 static void Fast_Short_term_synthesis_filtering P5((S,rrp,k,wt,sr),
310 struct gsm_state * S,
311 register word * rrp, /* [0..7] IN */
312 register int k, /* k_end - k_start */
313 register word * wt, /* [0..k-1] IN */
314 register word * sr /* [0..k-1] OUT */
317 register word * v = S->v;
320 float va[9], rrpa[8];
321 register float scalef = 3.0517578125e-5, temp;
323 for (i = 0; i < 8; ++i) {
325 rrpa[i] = (float)rrp[i] * scalef;
328 register float sri = *wt++;
330 sri -= rrpa[i] * va[i];
331 if (sri < -32768.) sri = -32768.;
332 else if (sri > 32767.) sri = 32767.;
334 temp = va[i] + rrpa[i] * sri;
335 if (temp < -32768.) temp = -32768.;
336 else if (temp > 32767.) temp = 32767.;
341 for (i = 0; i < 9; ++i) v[i] = va[i];
344 #endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
346 void Gsm_Short_Term_Analysis_Filter P3((S,LARc,s),
348 struct gsm_state * S,
350 word * LARc, /* coded log area ratio [0..7] IN */
351 word * s /* signal [0..159] IN/OUT */
354 word * LARpp_j = S->LARpp[ S->j ];
355 word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
360 #if defined(FAST) && defined(USE_FLOAT_MUL)
361 # define FILTER (* (S->fast \
362 ? Fast_Short_term_analysis_filtering \
363 : Short_term_analysis_filtering ))
366 # define FILTER Short_term_analysis_filtering
369 Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
371 Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
373 FILTER( S, LARp, 13, s);
375 Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
377 FILTER( S, LARp, 14, s + 13);
379 Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
381 FILTER( S, LARp, 13, s + 27);
383 Coefficients_40_159( LARpp_j, LARp);
385 FILTER( S, LARp, 120, s + 40);
388 void Gsm_Short_Term_Synthesis_Filter P4((S, LARcr, wt, s),
389 struct gsm_state * S,
391 word * LARcr, /* received log area ratios [0..7] IN */
392 word * wt, /* received d [0..159] IN */
394 word * s /* signal s [0..159] OUT */
397 word * LARpp_j = S->LARpp[ S->j ];
398 word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
403 #if defined(FAST) && defined(USE_FLOAT_MUL)
405 # define FILTER (* (S->fast \
406 ? Fast_Short_term_synthesis_filtering \
407 : Short_term_synthesis_filtering ))
409 # define FILTER Short_term_synthesis_filtering
412 Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
414 Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
416 FILTER( S, LARp, 13, wt, s );
418 Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
420 FILTER( S, LARp, 14, wt + 13, s + 13 );
422 Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
424 FILTER( S, LARp, 13, wt + 27, s + 27 );
426 Coefficients_40_159( LARpp_j, LARp );
428 FILTER(S, LARp, 120, wt + 40, s + 40);