904856318f0c01ee160f11d273d972ff22e931be
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"
13 * SHORT TERM ANALYSIS FILTERING SECTION
18 static void Decoding_of_the_coded_Log_Area_Ratios (
19 word
* LARc
, /* coded log area ratio [0..7] IN */
20 word
* LARpp
) /* out: decoded .. */
22 register word temp1
/* , temp2 */;
24 /* This procedure requires for efficient implementation
27 * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
28 * MIC[1..8] = minimum value of the LARc[1..8]
31 /* Compute the LARpp[1..8]
34 /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
36 * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
38 * temp1 = GSM_SUB( temp1, temp2 );
40 * assert(*INVA != MIN_WORD);
42 * temp1 = GSM_MULT_R( *INVA, temp1 );
43 * *LARpp = GSM_ADD( temp1, temp1 );
48 #define STEP( B, MIC, INVA ) \
49 temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
50 temp1 = GSM_SUB( temp1, B << 1 ); \
51 temp1 = GSM_MULT_R( INVA, temp1 ); \
52 *LARpp++ = GSM_ADD( temp1, temp1 );
54 STEP( 0, -32, 13107 );
55 STEP( 0, -32, 13107 );
56 STEP( 2048, -16, 13107 );
57 STEP( -2560, -16, 13107 );
59 STEP( 94, -8, 19223 );
60 STEP( -1792, -8, 17476 );
61 STEP( -341, -4, 31454 );
62 STEP( -1144, -4, 29708 );
64 /* NOTE: the addition of *MIC is used to restore
70 /* Computation of the quantized reflection coefficients
73 /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
77 * Within each frame of 160 analyzed speech samples the short term
78 * analysis and synthesis filters operate with four different sets of
79 * coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
80 * and the actual set of decoded LARs (LARpp(j))
82 * (Initial value: LARpp(j-1)[1..8] = 0.)
85 static void Coefficients_0_12 (
86 register word
* LARpp_j_1
,
87 register word
* LARpp_j
,
92 for (i
= 1; i
<= 8; i
++, LARp
++, LARpp_j_1
++, LARpp_j
++) {
93 *LARp
= GSM_ADD( SASR_W( *LARpp_j_1
, 2 ), SASR_W( *LARpp_j
, 2 ));
94 *LARp
= GSM_ADD( *LARp
, SASR_W( *LARpp_j_1
, 1));
98 static void Coefficients_13_26 (
99 register word
* LARpp_j_1
,
100 register word
* LARpp_j
,
101 register word
* LARp
)
104 for (i
= 1; i
<= 8; i
++, LARpp_j_1
++, LARpp_j
++, LARp
++) {
105 *LARp
= GSM_ADD( SASR_W( *LARpp_j_1
, 1), SASR_W( *LARpp_j
, 1 ));
109 static void Coefficients_27_39 (
110 register word
* LARpp_j_1
,
111 register word
* LARpp_j
,
112 register word
* LARp
)
116 for (i
= 1; i
<= 8; i
++, LARpp_j_1
++, LARpp_j
++, LARp
++) {
117 *LARp
= GSM_ADD( SASR_W( *LARpp_j_1
, 2 ), SASR_W( *LARpp_j
, 2 ));
118 *LARp
= GSM_ADD( *LARp
, SASR_W( *LARpp_j
, 1 ));
123 static void Coefficients_40_159 (
124 register word
* LARpp_j
,
125 register word
* LARp
)
129 for (i
= 1; i
<= 8; i
++, LARp
++, LARpp_j
++)
135 static void LARp_to_rp (
136 register word
* LARp
) /* [0..7] IN/OUT */
138 * The input of this procedure is the interpolated LARp[0..7] array.
139 * The reflection coefficients, rp[i], are used in the analysis
140 * filter and in the synthesis filter.
146 for (i
= 1; i
<= 8; i
++, LARp
++) {
148 /* temp = GSM_ABS( *LARp );
150 * if (temp < 11059) temp <<= 1;
151 * else if (temp < 20070) temp += 11059;
152 * else temp = GSM_ADD( temp >> 2, 26112 );
154 * *LARp = *LARp < 0 ? -temp : temp;
158 temp
= *LARp
== MIN_WORD
? MAX_WORD
: -(*LARp
);
159 *LARp
= - ((temp
< 11059) ? temp
<< 1
160 : ((temp
< 20070) ? temp
+ 11059
161 : GSM_ADD( (word
) (temp
>> 2), (word
) 26112 )));
164 *LARp
= (temp
< 11059) ? temp
<< 1
165 : ((temp
< 20070) ? temp
+ 11059
166 : GSM_ADD( (word
) (temp
>> 2), (word
) 26112 ));
173 static void Short_term_analysis_filtering (
174 struct gsm_state
* S
,
175 register word
* rp
, /* [0..7] IN */
176 register int k_n
, /* k_end - k_start */
177 register word
* s
/* [0..n-1] IN/OUT */
180 * This procedure computes the short term residual signal d[..] to be fed
181 * to the RPE-LTP loop from the s[..] signal and from the local rp[..]
182 * array (quantized reflection coefficients). As the call of this
183 * procedure can be done in many ways (see the interpolation of the LAR
184 * coefficient), it is assumed that the computation begins with index
185 * k_start (for arrays d[..] and s[..]) and stops with index k_end
186 * (k_start and k_end are defined in 4.2.9.1). This procedure also
187 * needs to keep the array u[0..7] in memory for each call.
190 register word
* u
= S
->u
;
192 register word di
, zzz
, ui
, sav
, rpi
;
198 for (i
= 0; i
< 8; i
++) { /* YYY */
204 zzz
= GSM_MULT_R(rpi
, di
);
205 sav
= GSM_ADD( ui
, zzz
);
207 zzz
= GSM_MULT_R(rpi
, ui
);
208 di
= GSM_ADD( di
, zzz
);
215 #if defined(USE_FLOAT_MUL) && defined(FAST)
217 static void Fast_Short_term_analysis_filtering (
218 struct gsm_state
* S
,
219 register word
* rp
, /* [0..7] IN */
220 register int k_n
, /* k_end - k_start */
221 register word
* s
/* [0..n-1] IN/OUT */
224 register word
* u
= S
->u
;
230 register float scalef
= 3.0517578125e-5;
231 register float sav
, di
, temp
;
233 for (i
= 0; i
< 8; ++i
) {
235 rpf
[i
] = rp
[i
] * scalef
;
239 for (i
= 0; i
< 8; ++i
) {
240 register float rpfi
= rpf
[i
];
241 register float ufi
= uf
[i
];
244 temp
= rpfi
* di
+ ufi
;
250 for (i
= 0; i
< 8; ++i
) u
[i
] = uf
[i
];
252 #endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
254 static void Short_term_synthesis_filtering (
255 struct gsm_state
* S
,
256 register word
* rrp
, /* [0..7] IN */
257 register int k
, /* k_end - k_start */
258 register word
* wt
, /* [0..k-1] IN */
259 register word
* sr
/* [0..k-1] OUT */
262 register word
* v
= S
->v
;
264 register word sri
, tmp1
, tmp2
;
270 /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
274 tmp2
= ( tmp1
== MIN_WORD
&& tmp2
== MIN_WORD
276 : 0x0FFFF & (( (longword
)tmp1
* (longword
)tmp2
279 sri
= GSM_SUB( sri
, tmp2
);
281 /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
283 tmp1
= ( tmp1
== MIN_WORD
&& sri
== MIN_WORD
285 : 0x0FFFF & (( (longword
)tmp1
* (longword
)sri
288 v
[i
+1] = GSM_ADD( v
[i
], tmp1
);
295 #if defined(FAST) && defined(USE_FLOAT_MUL)
297 static void Fast_Short_term_synthesis_filtering (
298 struct gsm_state
* S
,
299 register word
* rrp
, /* [0..7] IN */
300 register int k
, /* k_end - k_start */
301 register word
* wt
, /* [0..k-1] IN */
302 register word
* sr
/* [0..k-1] OUT */
305 register word
* v
= S
->v
;
308 float va
[9], rrpa
[8];
309 register float scalef
= 3.0517578125e-5, temp
;
311 for (i
= 0; i
< 8; ++i
) {
313 rrpa
[i
] = (float)rrp
[i
] * scalef
;
316 register float sri
= *wt
++;
318 sri
-= rrpa
[i
] * va
[i
];
319 if (sri
< -32768.) sri
= -32768.;
320 else if (sri
> 32767.) sri
= 32767.;
322 temp
= va
[i
] + rrpa
[i
] * sri
;
323 if (temp
< -32768.) temp
= -32768.;
324 else if (temp
> 32767.) temp
= 32767.;
329 for (i
= 0; i
< 9; ++i
) v
[i
] = va
[i
];
332 #endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
334 void Gsm_Short_Term_Analysis_Filter (
336 struct gsm_state
* S
,
338 word
* LARc
, /* coded log area ratio [0..7] IN */
339 word
* s
/* signal [0..159] IN/OUT */
342 word
* LARpp_j
= S
->LARpp
[ S
->j
];
343 word
* LARpp_j_1
= S
->LARpp
[ S
->j
^= 1 ];
348 #if defined(FAST) && defined(USE_FLOAT_MUL)
349 # define FILTER (* (S->fast \
350 ? Fast_Short_term_analysis_filtering \
351 : Short_term_analysis_filtering ))
354 # define FILTER Short_term_analysis_filtering
357 Decoding_of_the_coded_Log_Area_Ratios( LARc
, LARpp_j
);
359 Coefficients_0_12( LARpp_j_1
, LARpp_j
, LARp
);
361 FILTER( S
, LARp
, 13, s
);
363 Coefficients_13_26( LARpp_j_1
, LARpp_j
, LARp
);
365 FILTER( S
, LARp
, 14, s
+ 13);
367 Coefficients_27_39( LARpp_j_1
, LARpp_j
, LARp
);
369 FILTER( S
, LARp
, 13, s
+ 27);
371 Coefficients_40_159( LARpp_j
, LARp
);
373 FILTER( S
, LARp
, 120, s
+ 40);
376 void Gsm_Short_Term_Synthesis_Filter (
377 struct gsm_state
* S
,
379 word
* LARcr
, /* received log area ratios [0..7] IN */
380 word
* wt
, /* received d [0..159] IN */
382 word
* s
/* signal s [0..159] OUT */
385 word
* LARpp_j
= S
->LARpp
[ S
->j
];
386 word
* LARpp_j_1
= S
->LARpp
[ S
->j
^=1 ];
391 #if defined(FAST) && defined(USE_FLOAT_MUL)
393 # define FILTER (* (S->fast \
394 ? Fast_Short_term_synthesis_filtering \
395 : Short_term_synthesis_filtering ))
397 # define FILTER Short_term_synthesis_filtering
400 Decoding_of_the_coded_Log_Area_Ratios( LARcr
, LARpp_j
);
402 Coefficients_0_12( LARpp_j_1
, LARpp_j
, LARp
);
404 FILTER( S
, LARp
, 13, wt
, s
);
406 Coefficients_13_26( LARpp_j_1
, LARpp_j
, LARp
);
408 FILTER( S
, LARp
, 14, wt
+ 13, s
+ 13 );
410 Coefficients_27_39( LARpp_j_1
, LARpp_j
, LARp
);
412 FILTER( S
, LARp
, 13, wt
+ 27, s
+ 27 );
414 Coefficients_40_159( LARpp_j
, LARp
);
416 FILTER(S
, LARp
, 120, wt
+ 40, s
+ 40);