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.
10 #include "gsm610_priv.h"
15 * SHORT TERM ANALYSIS FILTERING SECTION
20 static void Decoding_of_the_coded_Log_Area_Ratios (
21 word * LARc, /* coded log area ratio [0..7] IN */
22 word * LARpp) /* out: decoded .. */
24 register word temp1 /* , temp2 */;
26 /* This procedure requires for efficient implementation
29 * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
30 * MIC[1..8] = minimum value of the LARc[1..8]
33 /* Compute the LARpp[1..8]
36 /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
38 * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
40 * temp1 = GSM_SUB( temp1, temp2 );
42 * assert(*INVA != MIN_WORD);
44 * temp1 = GSM_MULT_R( *INVA, temp1 );
45 * *LARpp = GSM_ADD( temp1, temp1 );
50 #define STEP( B, MIC, INVA ) \
51 temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
52 temp1 = GSM_SUB( temp1, B << 1 ); \
53 temp1 = GSM_MULT_R( INVA, temp1 ); \
54 *LARpp++ = GSM_ADD( temp1, temp1 );
56 STEP( 0, -32, 13107 );
57 STEP( 0, -32, 13107 );
58 STEP( 2048, -16, 13107 );
59 STEP( -2560, -16, 13107 );
61 STEP( 94, -8, 19223 );
62 STEP( -1792, -8, 17476 );
63 STEP( -341, -4, 31454 );
64 STEP( -1144, -4, 29708 );
66 /* NOTE: the addition of *MIC is used to restore
72 /* Computation of the quantized reflection coefficients
75 /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
79 * Within each frame of 160 analyzed speech samples the short term
80 * analysis and synthesis filters operate with four different sets of
81 * coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
82 * and the actual set of decoded LARs (LARpp(j))
84 * (Initial value: LARpp(j-1)[1..8] = 0.)
87 static void Coefficients_0_12 (
88 register word * LARpp_j_1,
89 register word * LARpp_j,
94 for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
95 *LARp = GSM_ADD( SASR_W( *LARpp_j_1, 2 ), SASR_W( *LARpp_j, 2 ));
96 *LARp = GSM_ADD( *LARp, SASR_W( *LARpp_j_1, 1));
100 static void Coefficients_13_26 (
101 register word * LARpp_j_1,
102 register word * LARpp_j,
103 register word * LARp)
106 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
107 *LARp = GSM_ADD( SASR_W( *LARpp_j_1, 1), SASR_W( *LARpp_j, 1 ));
111 static void Coefficients_27_39 (
112 register word * LARpp_j_1,
113 register word * LARpp_j,
114 register word * LARp)
118 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
119 *LARp = GSM_ADD( SASR_W( *LARpp_j_1, 2 ), SASR_W( *LARpp_j, 2 ));
120 *LARp = GSM_ADD( *LARp, SASR_W( *LARpp_j, 1 ));
125 static void Coefficients_40_159 (
126 register word * LARpp_j,
127 register word * LARp)
131 for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
137 static void LARp_to_rp (
138 register word * LARp) /* [0..7] IN/OUT */
140 * The input of this procedure is the interpolated LARp[0..7] array.
141 * The reflection coefficients, rp[i], are used in the analysis
142 * filter and in the synthesis filter.
148 for (i = 1; i <= 8; i++, LARp++) {
150 /* temp = GSM_ABS( *LARp );
152 * if (temp < 11059) temp <<= 1;
153 * else if (temp < 20070) temp += 11059;
154 * else temp = GSM_ADD( temp >> 2, 26112 );
156 * *LARp = *LARp < 0 ? -temp : temp;
160 temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
161 *LARp = - ((temp < 11059) ? temp << 1
162 : ((temp < 20070) ? temp + 11059
163 : GSM_ADD( (word) (temp >> 2), (word) 26112 )));
166 *LARp = (temp < 11059) ? temp << 1
167 : ((temp < 20070) ? temp + 11059
168 : GSM_ADD( (word) (temp >> 2), (word) 26112 ));
175 static void Short_term_analysis_filtering (
176 struct gsm_state * S,
177 register word * rp, /* [0..7] IN */
178 register int k_n, /* k_end - k_start */
179 register word * s /* [0..n-1] IN/OUT */
182 * This procedure computes the short term residual signal d[..] to be fed
183 * to the RPE-LTP loop from the s[..] signal and from the local rp[..]
184 * array (quantized reflection coefficients). As the call of this
185 * procedure can be done in many ways (see the interpolation of the LAR
186 * coefficient), it is assumed that the computation begins with index
187 * k_start (for arrays d[..] and s[..]) and stops with index k_end
188 * (k_start and k_end are defined in 4.2.9.1). This procedure also
189 * needs to keep the array u[0..7] in memory for each call.
192 register word * u = S->u;
194 register word di, zzz, ui, sav, rpi;
200 for (i = 0; i < 8; i++) { /* YYY */
206 zzz = GSM_MULT_R(rpi, di);
207 sav = GSM_ADD( ui, zzz);
209 zzz = GSM_MULT_R(rpi, ui);
210 di = GSM_ADD( di, zzz );
217 #if defined(USE_FLOAT_MUL) && defined(FAST)
219 static void Fast_Short_term_analysis_filtering (
220 struct gsm_state * S,
221 register word * rp, /* [0..7] IN */
222 register int k_n, /* k_end - k_start */
223 register word * s /* [0..n-1] IN/OUT */
226 register word * u = S->u;
232 register float scalef = 3.0517578125e-5;
233 register float sav, di, temp;
235 for (i = 0; i < 8; ++i) {
237 rpf[i] = rp[i] * scalef;
241 for (i = 0; i < 8; ++i) {
242 register float rpfi = rpf[i];
243 register float ufi = uf[i];
246 temp = rpfi * di + ufi;
252 for (i = 0; i < 8; ++i) u[i] = uf[i];
254 #endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
256 static void Short_term_synthesis_filtering (
257 struct gsm_state * S,
258 register word * rrp, /* [0..7] IN */
259 register int k, /* k_end - k_start */
260 register word * wt, /* [0..k-1] IN */
261 register word * sr /* [0..k-1] OUT */
264 register word * v = S->v;
266 register word sri, tmp1, tmp2;
272 /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
276 tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
278 : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
281 sri = GSM_SUB( sri, tmp2 );
283 /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
285 tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD
287 : 0x0FFFF & (( (longword)tmp1 * (longword)sri
290 v[i+1] = GSM_ADD( v[i], tmp1);
297 #if defined(FAST) && defined(USE_FLOAT_MUL)
299 static void Fast_Short_term_synthesis_filtering (
300 struct gsm_state * S,
301 register word * rrp, /* [0..7] IN */
302 register int k, /* k_end - k_start */
303 register word * wt, /* [0..k-1] IN */
304 register word * sr /* [0..k-1] OUT */
307 register word * v = S->v;
310 float va[9], rrpa[8];
311 register float scalef = 3.0517578125e-5, temp;
313 for (i = 0; i < 8; ++i) {
315 rrpa[i] = (float)rrp[i] * scalef;
318 register float sri = *wt++;
320 sri -= rrpa[i] * va[i];
321 if (sri < -32768.) sri = -32768.;
322 else if (sri > 32767.) sri = 32767.;
324 temp = va[i] + rrpa[i] * sri;
325 if (temp < -32768.) temp = -32768.;
326 else if (temp > 32767.) temp = 32767.;
331 for (i = 0; i < 9; ++i) v[i] = va[i];
334 #endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
336 void Gsm_Short_Term_Analysis_Filter (
338 struct gsm_state * S,
340 word * LARc, /* coded log area ratio [0..7] IN */
341 word * s /* signal [0..159] IN/OUT */
344 word * LARpp_j = S->LARpp[ S->j ];
345 word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
350 #if defined(FAST) && defined(USE_FLOAT_MUL)
351 # define FILTER (* (S->fast \
352 ? Fast_Short_term_analysis_filtering \
353 : Short_term_analysis_filtering ))
356 # define FILTER Short_term_analysis_filtering
359 Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
361 Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
363 FILTER( S, LARp, 13, s);
365 Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
367 FILTER( S, LARp, 14, s + 13);
369 Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
371 FILTER( S, LARp, 13, s + 27);
373 Coefficients_40_159( LARpp_j, LARp);
375 FILTER( S, LARp, 120, s + 40);
378 void Gsm_Short_Term_Synthesis_Filter (
379 struct gsm_state * S,
381 word * LARcr, /* received log area ratios [0..7] IN */
382 word * wt, /* received d [0..159] IN */
384 word * s /* signal s [0..159] OUT */
387 word * LARpp_j = S->LARpp[ S->j ];
388 word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
393 #if defined(FAST) && defined(USE_FLOAT_MUL)
395 # define FILTER (* (S->fast \
396 ? Fast_Short_term_synthesis_filtering \
397 : Short_term_synthesis_filtering ))
399 # define FILTER Short_term_synthesis_filtering
402 Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
404 Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
406 FILTER( S, LARp, 13, wt, s );
408 Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
410 FILTER( S, LARp, 14, wt + 13, s + 13 );
412 Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
414 FILTER( S, LARp, 13, wt + 27, s + 27 );
416 Coefficients_40_159( LARpp_j, LARp );
418 FILTER(S, LARp, 120, wt + 40, s + 40);
421 ** Do not edit or modify anything in this comment block.
422 ** The arch-tag line is a file identity tag for the GNU Arch
423 ** revision control system.
425 ** arch-tag: 019ac7ba-c6dd-4540-abf0-8644b6c4a633