diff options
Diffstat (limited to 'all_pairs/source/gsm_dec/gsm_dec.c')
-rw-r--r-- | all_pairs/source/gsm_dec/gsm_dec.c | 764 |
1 files changed, 764 insertions, 0 deletions
diff --git a/all_pairs/source/gsm_dec/gsm_dec.c b/all_pairs/source/gsm_dec/gsm_dec.c new file mode 100644 index 0000000..7a0a1bd --- /dev/null +++ b/all_pairs/source/gsm_dec/gsm_dec.c | |||
@@ -0,0 +1,764 @@ | |||
1 | /* | ||
2 | |||
3 | This program is part of the TACLeBench benchmark suite. | ||
4 | Version V 2.0 | ||
5 | |||
6 | Name: gsm_dec | ||
7 | |||
8 | Author: Jutta Degener and Carsten Bormann, | ||
9 | Technische Universitaet Berlin | ||
10 | |||
11 | Function: Decoding of GSM data | ||
12 | |||
13 | Source: included in MediaBench/gsm | ||
14 | |||
15 | Original name: gsm_decode | ||
16 | |||
17 | Changes: no major functional changes | ||
18 | |||
19 | License: see the accompanying COPYRIGHT file | ||
20 | |||
21 | */ | ||
22 | |||
23 | |||
24 | #include "../extra.h" | ||
25 | #include "gsm.h" | ||
26 | #include "add.h" | ||
27 | #include "data.h" | ||
28 | #include "private.h" | ||
29 | |||
30 | #define SAMPLES 20 | ||
31 | |||
32 | /* | ||
33 | Forward declaration of global variables | ||
34 | */ | ||
35 | |||
36 | struct gsm_state gsm_dec_state; | ||
37 | gsm gsm_dec_state_ptr; | ||
38 | volatile int gsm_dec_result; | ||
39 | |||
40 | /* | ||
41 | Forward declaration of functions | ||
42 | */ | ||
43 | |||
44 | extern word gsm_dec_sub( word a, word b ); | ||
45 | extern word gsm_dec_asl( word a, int n ); | ||
46 | void gsm_dec_Decoding_of_the_coded_Log_Area_Ratios( | ||
47 | word *LARc, /* coded log area ratio [0..7] IN */ | ||
48 | word *LARpp ); /* out: decoded .. */ | ||
49 | |||
50 | void gsm_dec_Coefficients_0_12( word *LARpp_j_1, word *LARpp_j, word *LARp ); | ||
51 | |||
52 | void gsm_dec_LARp_to_rp( word *LARp ); /* [0..7] IN/OUT */ | ||
53 | |||
54 | extern int gsm_dec_decode( gsm, gsm_byte *, gsm_signal * ); | ||
55 | |||
56 | extern void gsm_dec_Decoder( struct gsm_state *S, | ||
57 | word *LARcr, /* [0..7] IN */ | ||
58 | word *Ncr, /* [0..3] IN */ | ||
59 | word *bcr, /* [0..3] IN */ | ||
60 | word *Mcr, /* [0..3] IN */ | ||
61 | word *xmaxcr, /* [0..3] IN */ | ||
62 | word *xMcr, /* [0..13*4] IN */ | ||
63 | word *s ); /* [0..159] OUT */ | ||
64 | |||
65 | extern void gsm_dec_Long_Term_Synthesis_Filtering( | ||
66 | struct gsm_state *S, word Ncr, word bcr, | ||
67 | word *erp, /* [0..39] IN */ | ||
68 | word *drp ); /* [-120..-1] IN, [0..40] OUT */ | ||
69 | |||
70 | void gsm_dec_RPE_Decoding( word xmaxcr, word Mcr, | ||
71 | word *xMcr, /* [0..12], 3 bits IN */ | ||
72 | word *erp ); /* [0..39] OUT */ | ||
73 | |||
74 | void gsm_dec_RPE_grid_positioning( word Mc, /* grid position IN */ | ||
75 | word *xMp, /* [0..12] IN */ | ||
76 | word *ep /* [0..39] OUT */ | ||
77 | ); | ||
78 | |||
79 | void gsm_dec_APCM_inverse_quantization( word *xMc, /* [0..12] IN */ | ||
80 | word mant, word exp, | ||
81 | word *xMp ); /* [0..12] OUT */ | ||
82 | |||
83 | extern word gsm_dec_asr( word a, int n ); | ||
84 | |||
85 | void gsm_dec_APCM_quantization_xmaxc_to_exp_mant( | ||
86 | word xmaxc, /* IN */ | ||
87 | word *exp_out, /* OUT */ | ||
88 | word *mant_out ); /* OUT */ | ||
89 | |||
90 | void gsm_dec_Postprocessing( struct gsm_state *S, word *s ); | ||
91 | |||
92 | void gsm_dec_Coefficients_13_26( word *LARpp_j_1, word *LARpp_j, | ||
93 | word *LARp ); | ||
94 | |||
95 | void gsm_dec_Coefficients_40_159( word *LARpp_j, word *LARp ); | ||
96 | |||
97 | void gsm_dec_Short_term_synthesis_filtering( struct gsm_state *S, | ||
98 | word *rrp, /* [0..7] IN */ | ||
99 | int k, /* k_end - k_start */ | ||
100 | word *wt, /* [0..k-1] IN */ | ||
101 | word *sr /* [0..k-1] OUT */ | ||
102 | ); | ||
103 | |||
104 | void gsm_dec_Short_Term_Synthesis_Filter( | ||
105 | struct gsm_state *S, word *LARcr, /* received log area ratios [0..7] IN */ | ||
106 | word *wt, /* received d [0..159] IN */ | ||
107 | word *s /* signal s [0..159] OUT */ | ||
108 | ); | ||
109 | |||
110 | void gsm_dec_Coefficients_27_39( word *LARpp_j_1, word *LARpp_j, word *LARp ); | ||
111 | |||
112 | gsm gsm_dec_create( void ); | ||
113 | void gsm_dec_init( void ); | ||
114 | void gsm_dec_main( void ); | ||
115 | //int main( void ); | ||
116 | |||
117 | /* add.c */ | ||
118 | |||
119 | word gsm_dec_sub( word a, word b ) | ||
120 | { | ||
121 | longword diff = ( longword )a - ( longword )b; | ||
122 | return saturate( diff ); | ||
123 | } | ||
124 | |||
125 | word gsm_dec_asl( word a, int n ) | ||
126 | { | ||
127 | if ( n >= 16 ) | ||
128 | return 0; | ||
129 | if ( n <= -16 ) | ||
130 | return -( a < 0 ); | ||
131 | if ( n < 0 ) | ||
132 | return gsm_dec_asr( a, -n ); | ||
133 | return a << n; | ||
134 | } | ||
135 | |||
136 | /* short_term.c */ | ||
137 | /* | ||
138 | SHORT TERM ANALYSIS FILTERING SECTION | ||
139 | */ | ||
140 | |||
141 | /* 4.2.8 */ | ||
142 | |||
143 | void gsm_dec_Decoding_of_the_coded_Log_Area_Ratios( | ||
144 | word *LARc, /* coded log area ratio [0..7] IN */ | ||
145 | word *LARpp ) /* out: decoded .. */ | ||
146 | { | ||
147 | word temp1 /* for STEP */; | ||
148 | long ltmp; /* for GSM_ADD */ | ||
149 | |||
150 | /* This procedure requires for efficient implementation | ||
151 | two tables. | ||
152 | |||
153 | INVA[1..8] = integer( (32768 * 8) / real_A[1..8]) | ||
154 | MIC[1..8] = minimum value of the LARc[1..8] | ||
155 | */ | ||
156 | |||
157 | /* Compute the LARpp[1..8] | ||
158 | */ | ||
159 | |||
160 | /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) { | ||
161 | |||
162 | temp1 = GSM_ADD( *LARc, *MIC ) << 10; | ||
163 | temp2 = *B << 1; | ||
164 | temp1 = GSM_SUB( temp1, temp2 ); | ||
165 | |||
166 | temp1 = GSM_MULT_R( *INVA, temp1 ); | ||
167 | LARpp = GSM_ADD( temp1, temp1 ); | ||
168 | } | ||
169 | */ | ||
170 | |||
171 | #undef STEP | ||
172 | #define STEP(B, MIC, INVA) \ | ||
173 | temp1 = GSM_ADD(*LARc++, MIC) << 10; \ | ||
174 | temp1 = GSM_SUB(temp1, B << 1); \ | ||
175 | temp1 = GSM_MULT_R(INVA, temp1); \ | ||
176 | *LARpp++ = GSM_ADD(temp1, temp1); | ||
177 | |||
178 | STEP( 0, -32, 13107 ); | ||
179 | STEP( 0, -32, 13107 ); | ||
180 | STEP( 2048, -16, 13107 ); | ||
181 | STEP( 2560, -16, 13107 ); | ||
182 | |||
183 | STEP( 94, -8, 19223 ); | ||
184 | STEP( 1792, -8, 17476 ); | ||
185 | STEP( 341, -4, 31454 ); | ||
186 | STEP( 1144, -4, 29708 ); | ||
187 | |||
188 | /* NOTE: the addition of *MIC is used to restore the sign of *LARc. | ||
189 | */ | ||
190 | } | ||
191 | |||
192 | /* 4.2.9 */ | ||
193 | /* Computation of the quantized reflection coefficients | ||
194 | */ | ||
195 | |||
196 | /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8] | ||
197 | */ | ||
198 | |||
199 | /* | ||
200 | Within each frame of 160 analyzed speech samples the short term | ||
201 | analysis and synthesis filters operate with four different sets of | ||
202 | coefficients, derived from the previous set of decoded LARs(LARpp(j-1)) | ||
203 | and the actual set of decoded LARs (LARpp(j)) | ||
204 | |||
205 | (Initial value: LARpp(j-1)[1..8] = 0.) | ||
206 | */ | ||
207 | |||
208 | |||
209 | void gsm_dec_Coefficients_0_12( word *LARpp_j_1, word *LARpp_j, word *LARp ) | ||
210 | { | ||
211 | int i; | ||
212 | longword ltmp; | ||
213 | |||
214 | _Pragma( "loopbound min 8 max 8" ) | ||
215 | for ( i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++ ) { | ||
216 | *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ) ); | ||
217 | *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1 ) ); | ||
218 | } | ||
219 | } | ||
220 | |||
221 | /* 4.2.9.2 */ | ||
222 | |||
223 | void gsm_dec_LARp_to_rp( word *LARp ) /* [0..7] IN/OUT */ | ||
224 | /* | ||
225 | The input of this procedure is the interpolated LARp[0..7] array. | ||
226 | The reflection coefficients, rp[i], are used in the analysis | ||
227 | filter and in the synthesis filter. | ||
228 | */ | ||
229 | { | ||
230 | int i; | ||
231 | word temp; | ||
232 | longword ltmp; | ||
233 | |||
234 | _Pragma( "loopbound min 8 max 8" ) | ||
235 | for ( i = 1; i <= 8; i++, LARp++ ) { | ||
236 | |||
237 | /* temp = GSM_ABS( *LARp ); | ||
238 | |||
239 | if (temp < 11059) temp <<= 1; | ||
240 | else if (temp < 20070) temp += 11059; | ||
241 | else temp = GSM_ADD( temp >> 2, 26112 ); | ||
242 | |||
243 | * *LARp = *LARp < 0 ? -temp : temp; | ||
244 | */ | ||
245 | |||
246 | if ( *LARp < 0 ) { | ||
247 | temp = *LARp == MIN_WORD ? MAX_WORD : -( *LARp ); | ||
248 | *LARp = -( ( temp < 11059 ) ? temp << 1 | ||
249 | : ( ( temp < 20070 ) ? temp + 11059 | ||
250 | : GSM_ADD( temp >> 2, 26112 ) ) ); | ||
251 | } else { | ||
252 | temp = *LARp; | ||
253 | *LARp = ( temp < 11059 ) | ||
254 | ? temp << 1 | ||
255 | : ( ( temp < 20070 ) ? temp + 11059 : GSM_ADD( temp >> 2, 26112 ) ); | ||
256 | } | ||
257 | } | ||
258 | } | ||
259 | |||
260 | void gsm_dec_Decoder( struct gsm_state *S, | ||
261 | word *LARcr, /* [0..7] IN */ | ||
262 | word *Ncr, /* [0..3] IN */ | ||
263 | word *bcr, /* [0..3] IN */ | ||
264 | word *Mcr, /* [0..3] IN */ | ||
265 | word *xmaxcr, /* [0..3] IN */ | ||
266 | word *xMcr, /* [0..13*4] IN */ | ||
267 | word *s ) /* [0..159] OUT */ | ||
268 | { | ||
269 | int j, k; | ||
270 | word erp[40], wt[160]; | ||
271 | word *drp = S->dp0 + 120; | ||
272 | |||
273 | _Pragma( "loopbound min 4 max 4" ) | ||
274 | for ( j = 0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13 ) { | ||
275 | |||
276 | gsm_dec_RPE_Decoding( *xmaxcr, *Mcr, xMcr, erp ); | ||
277 | gsm_dec_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp ); | ||
278 | |||
279 | _Pragma( "loopbound min 40 max 40" ) | ||
280 | for ( k = 0; k <= 39; k++ ) | ||
281 | wt[j * 40 + k] = drp[k]; | ||
282 | } | ||
283 | |||
284 | gsm_dec_Short_Term_Synthesis_Filter( S, LARcr, wt, s ); | ||
285 | gsm_dec_Postprocessing( S, s ); | ||
286 | } | ||
287 | |||
288 | /* 4.3.2 */ | ||
289 | void gsm_dec_Long_Term_Synthesis_Filtering( | ||
290 | struct gsm_state *S, | ||
291 | word Ncr, word bcr, word *erp, /* [0..39] IN */ | ||
292 | word *drp /* [-120..-1] IN, [0..40] OUT */ | ||
293 | ) | ||
294 | /* | ||
295 | This procedure uses the bcr and Ncr parameter to realize the | ||
296 | long term synthesis filtering. The decoding of bcr needs | ||
297 | table 4.3b. | ||
298 | */ | ||
299 | { | ||
300 | longword ltmp; /* for ADD */ | ||
301 | int k; | ||
302 | word brp, drpp, Nr; | ||
303 | |||
304 | /* Check the limits of Nr. | ||
305 | */ | ||
306 | Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr; | ||
307 | S->nrp = Nr; | ||
308 | |||
309 | /* Decoding of the LTP gain bcr | ||
310 | */ | ||
311 | brp = gsm_dec_QLB[bcr]; | ||
312 | |||
313 | /* Computation of the reconstructed short term residual | ||
314 | signal drp[0..39] | ||
315 | */ | ||
316 | |||
317 | _Pragma( "loopbound min 40 max 40" ) | ||
318 | for ( k = 0; k <= 39; k++ ) { | ||
319 | drpp = GSM_MULT_R( brp, drp[k - Nr] ); | ||
320 | drp[k] = GSM_ADD( erp[k], drpp ); | ||
321 | } | ||
322 | |||
323 | /* | ||
324 | Update of the reconstructed short term residual signal | ||
325 | drp[ -1..-120 ] | ||
326 | */ | ||
327 | |||
328 | _Pragma( "loopbound min 120 max 120" ) | ||
329 | for ( k = 0; k <= 119; k++ ) | ||
330 | drp[-120 + k] = drp[-80 + k]; | ||
331 | } | ||
332 | |||
333 | void gsm_dec_RPE_Decoding( word xmaxcr, word Mcr, | ||
334 | word *xMcr, /* [0..12], 3 bits IN */ | ||
335 | word *erp ) /* [0..39] OUT */ | ||
336 | { | ||
337 | word exp, mant; | ||
338 | word xMp[13]; | ||
339 | |||
340 | gsm_dec_APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant ); | ||
341 | gsm_dec_APCM_inverse_quantization( xMcr, mant, exp, xMp ); | ||
342 | gsm_dec_RPE_grid_positioning( Mcr, xMp, erp ); | ||
343 | } | ||
344 | |||
345 | /* 4.2.17 */ | ||
346 | void gsm_dec_RPE_grid_positioning( | ||
347 | word Mc, /* grid position IN */ | ||
348 | word *xMp, /* [0..12] IN */ | ||
349 | word *ep /* [0..39] OUT */ ) | ||
350 | /* | ||
351 | This procedure computes the reconstructed long term residual signal | ||
352 | ep[0..39] for the LTP analysis filter. The inputs are the Mc | ||
353 | which is the grid position selection and the xMp[0..12] decoded | ||
354 | RPE samples which are upsampled by a factor of 3 by inserting zero | ||
355 | values. | ||
356 | */ | ||
357 | { | ||
358 | int i = 13; | ||
359 | |||
360 | /* Rewritten Duff's device for WCET analysis! */ | ||
361 | switch ( Mc ) { | ||
362 | case 3: | ||
363 | *ep++ = 0; | ||
364 | case 2: | ||
365 | *ep++ = 0; | ||
366 | case 1: | ||
367 | *ep++ = 0; | ||
368 | case 0: | ||
369 | *ep++ = *xMp++; | ||
370 | i--; | ||
371 | } | ||
372 | |||
373 | _Pragma( "loopbound min 12 max 12" ) | ||
374 | do { | ||
375 | *ep++ = 0; | ||
376 | *ep++ = 0; | ||
377 | *ep++ = *xMp++; | ||
378 | } while ( --i ); | ||
379 | |||
380 | _Pragma( "loopbound min 0 max 2" ) | ||
381 | while ( ++Mc < 4 ) | ||
382 | *ep++ = 0; | ||
383 | |||
384 | } | ||
385 | |||
386 | /* 4.2.16 */ | ||
387 | void gsm_dec_APCM_inverse_quantization( word *xMc, /* [0..12] IN */ | ||
388 | word mant, | ||
389 | word exp, | ||
390 | word *xMp ) /* [0..12] OUT */ | ||
391 | /* | ||
392 | This part is for decoding the RPE sequence of coded xMc[0..12] | ||
393 | samples to obtain the xMp[0..12] array. Table 4.6 is used to get | ||
394 | the mantissa of xmaxc (FAC[0..7]). | ||
395 | */ | ||
396 | { | ||
397 | int i; | ||
398 | word temp, temp1, temp2, temp3; | ||
399 | longword ltmp; | ||
400 | |||
401 | temp1 = gsm_dec_FAC[mant]; /* see 4.2-15 for mant */ | ||
402 | temp2 = gsm_dec_sub( 6, exp ); /* see 4.2-15 for exp */ | ||
403 | temp3 = gsm_dec_asl( 1, gsm_dec_sub( temp2, 1 ) ); | ||
404 | |||
405 | _Pragma( "loopbound min 13 max 13" ) | ||
406 | for ( i = 13; i--; ) { | ||
407 | |||
408 | /* temp = gsm_sub( *xMc++ << 1, 7 ); */ | ||
409 | temp = ( *xMc++ << 1 ) - 7; /* restore sign */ | ||
410 | |||
411 | temp <<= 12; /* 16 bit signed */ | ||
412 | temp = GSM_MULT_R( temp1, temp ); | ||
413 | temp = GSM_ADD( temp, temp3 ); | ||
414 | *xMp++ = gsm_dec_asr( temp, temp2 ); | ||
415 | } | ||
416 | } | ||
417 | |||
418 | /* | ||
419 | 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION | ||
420 | */ | ||
421 | word gsm_dec_asr( word a, int n ) | ||
422 | { | ||
423 | if ( n >= 16 ) | ||
424 | return -( a < 0 ); | ||
425 | if ( n <= -16 ) | ||
426 | return 0; | ||
427 | if ( n < 0 ) | ||
428 | return a << -n; | ||
429 | |||
430 | return a >> n; | ||
431 | } | ||
432 | |||
433 | /* rpe.c */ | ||
434 | /* 4.12.15 */ | ||
435 | void gsm_dec_APCM_quantization_xmaxc_to_exp_mant( word xmaxc, /* IN */ | ||
436 | word *exp_out, /* OUT */ | ||
437 | word *mant_out ) /* OUT */ | ||
438 | { | ||
439 | word exp, mant; | ||
440 | |||
441 | /* Compute exponent and mantissa of the decoded version of xmaxc | ||
442 | */ | ||
443 | exp = 0; | ||
444 | if ( xmaxc > 15 ) | ||
445 | exp = SASR( xmaxc, 3 ) - 1; | ||
446 | mant = xmaxc - ( exp << 3 ); | ||
447 | |||
448 | if ( mant == 0 ) { | ||
449 | exp = -4; | ||
450 | mant = 7; | ||
451 | } else { | ||
452 | _Pragma( "loopbound min 0 max 3" ) | ||
453 | while ( mant <= 7 ) { | ||
454 | mant = mant << 1 | 1; | ||
455 | exp--; | ||
456 | } | ||
457 | mant -= 8; | ||
458 | } | ||
459 | |||
460 | *exp_out = exp; | ||
461 | *mant_out = mant; | ||
462 | } | ||
463 | |||
464 | /* decode.c */ | ||
465 | /* | ||
466 | 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER | ||
467 | */ | ||
468 | void gsm_dec_Postprocessing( struct gsm_state *S, word *s ) | ||
469 | { | ||
470 | int k; | ||
471 | word msr = S->msr; | ||
472 | longword ltmp; /* for GSM_ADD */ | ||
473 | word tmp; | ||
474 | |||
475 | _Pragma( "loopbound min 159 max 159" ) | ||
476 | for ( k = 160; --k; ++s ) { | ||
477 | tmp = GSM_MULT_R( msr, 28180 ); | ||
478 | msr = GSM_ADD( *s, tmp ); /* Deemphasis */ | ||
479 | *s = GSM_ADD( msr, msr ) & 0xFFF8; /* Truncation & Upscaling */ | ||
480 | } | ||
481 | S->msr = msr; | ||
482 | } | ||
483 | |||
484 | void gsm_dec_Coefficients_13_26( word *LARpp_j_1, word *LARpp_j, word *LARp ) | ||
485 | { | ||
486 | int i; | ||
487 | longword ltmp; | ||
488 | _Pragma( "loopbound min 8 max 8" ) | ||
489 | for ( i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++ ) | ||
490 | *LARp = GSM_ADD( SASR( *LARpp_j_1, 1 ), SASR( *LARpp_j, 1 ) ); | ||
491 | } | ||
492 | |||
493 | void gsm_dec_Coefficients_40_159( word *LARpp_j, word *LARp ) | ||
494 | { | ||
495 | int i; | ||
496 | |||
497 | _Pragma( "loopbound min 8 max 8" ) | ||
498 | for ( i = 1; i <= 8; i++, LARp++, LARpp_j++ ) | ||
499 | *LARp = *LARpp_j; | ||
500 | } | ||
501 | |||
502 | void gsm_dec_Short_term_synthesis_filtering( struct gsm_state *S, | ||
503 | word *rrp, /* [0..7] IN */ | ||
504 | int k, /* k_end - k_start */ | ||
505 | word *wt, /* [0..k-1] IN */ | ||
506 | word *sr ) /* [0..k-1] OUT */ | ||
507 | { | ||
508 | word *v = S->v; | ||
509 | int i; | ||
510 | word sri, tmp1, tmp2; | ||
511 | longword ltmp; /* for GSM_ADD & GSM_SUB */ | ||
512 | |||
513 | _Pragma( "loopbound min 12 max 118" ) | ||
514 | while ( --k ) { | ||
515 | sri = *wt++; | ||
516 | _Pragma( "loopbound min 8 max 8" ) | ||
517 | for ( i = 8; i--; ) { | ||
518 | |||
519 | /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) ); | ||
520 | */ | ||
521 | tmp1 = rrp[i]; | ||
522 | tmp2 = v[i]; | ||
523 | tmp2 = | ||
524 | ( tmp1 == MIN_WORD && tmp2 == MIN_WORD | ||
525 | ? MAX_WORD | ||
526 | : 0x0FFFF & ( ( ( longword )tmp1 * ( longword )tmp2 + 16384 ) >> 15 ) ); | ||
527 | |||
528 | sri = GSM_SUB( sri, tmp2 ); | ||
529 | |||
530 | /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) ); | ||
531 | */ | ||
532 | tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD | ||
533 | ? MAX_WORD | ||
534 | : 0x0FFFF & ( ( ( longword )tmp1 * ( longword )sri + 16384 ) >> 15 ) ); | ||
535 | |||
536 | v[i + 1] = GSM_ADD( v[i], tmp1 ); | ||
537 | } | ||
538 | *sr++ = v[0] = sri; | ||
539 | } | ||
540 | } | ||
541 | |||
542 | void gsm_dec_Short_Term_Synthesis_Filter( | ||
543 | struct gsm_state *S, | ||
544 | word *LARcr, /* received log area ratios [0..7] IN */ | ||
545 | word *wt, /* received d [0..159] IN */ | ||
546 | word *s /* signal s [0..159] OUT */ | ||
547 | ) | ||
548 | { | ||
549 | word *LARpp_j = S->LARpp[S->j]; | ||
550 | word *LARpp_j_1 = S->LARpp[S->j ^= 1]; | ||
551 | |||
552 | word LARp[8]; | ||
553 | |||
554 | gsm_dec_Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j ); | ||
555 | |||
556 | gsm_dec_Coefficients_0_12( LARpp_j_1, LARpp_j, LARp ); | ||
557 | gsm_dec_LARp_to_rp( LARp ); | ||
558 | gsm_dec_Short_term_synthesis_filtering( S, LARp, 13, wt, s ); | ||
559 | |||
560 | gsm_dec_Coefficients_13_26( LARpp_j_1, LARpp_j, LARp ); | ||
561 | gsm_dec_LARp_to_rp( LARp ); | ||
562 | gsm_dec_Short_term_synthesis_filtering( S, LARp, 14, wt + 13, s + 13 ); | ||
563 | |||
564 | gsm_dec_Coefficients_27_39( LARpp_j_1, LARpp_j, LARp ); | ||
565 | gsm_dec_LARp_to_rp( LARp ); | ||
566 | gsm_dec_Short_term_synthesis_filtering( S, LARp, 13, wt + 27, s + 27 ); | ||
567 | |||
568 | gsm_dec_Coefficients_40_159( LARpp_j, LARp ); | ||
569 | gsm_dec_LARp_to_rp( LARp ); | ||
570 | gsm_dec_Short_term_synthesis_filtering( S, LARp, 120, wt + 40, s + 40 ); | ||
571 | } | ||
572 | |||
573 | void gsm_dec_Coefficients_27_39( word *LARpp_j_1, word *LARpp_j, word *LARp ) | ||
574 | { | ||
575 | int i; | ||
576 | longword ltmp; | ||
577 | |||
578 | _Pragma( "loopbound min 8 max 8" ) | ||
579 | for ( i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++ ) { | ||
580 | *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ) ); | ||
581 | *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ) ); | ||
582 | } | ||
583 | } | ||
584 | |||
585 | /* | ||
586 | Initialization- and return-value-related functions | ||
587 | */ | ||
588 | |||
589 | gsm gsm_dec_create( void ) | ||
590 | { | ||
591 | unsigned int i; | ||
592 | gsm r; | ||
593 | volatile char x = 0; | ||
594 | |||
595 | r = &gsm_dec_state; | ||
596 | |||
597 | _Pragma( "loopbound min 648 max 648" ) | ||
598 | for ( i = 0; i < sizeof( *r ); i++ ) | ||
599 | ( ( char * )r )[i] = 0 + x; | ||
600 | |||
601 | r->nrp = 40; | ||
602 | |||
603 | return r; | ||
604 | } | ||
605 | |||
606 | void gsm_dec_init( void ) | ||
607 | { | ||
608 | gsm_dec_state_ptr = gsm_dec_create(); | ||
609 | } | ||
610 | |||
611 | int gsm_dec_return( void ) | ||
612 | { | ||
613 | return gsm_dec_result; | ||
614 | } | ||
615 | |||
616 | /* | ||
617 | Main functions | ||
618 | */ | ||
619 | |||
620 | /* gsm_decode.c */ | ||
621 | int gsm_dec_decode( gsm s, gsm_byte *c, gsm_signal *target ) | ||
622 | { | ||
623 | word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13 * 4]; | ||
624 | |||
625 | /* GSM_MAGIC = (*c >> 4) & 0xF; */ | ||
626 | |||
627 | if ( ( ( *c >> 4 ) & 0x0F ) != GSM_MAGIC ) | ||
628 | return -1; | ||
629 | |||
630 | LARc[0] = ( *c++ & 0xF ) << 2; /* 1 */ | ||
631 | LARc[0] |= ( *c >> 6 ) & 0x3; | ||
632 | LARc[1] = *c++ & 0x3F; | ||
633 | LARc[2] = ( *c >> 3 ) & 0x1F; | ||
634 | LARc[3] = ( *c++ & 0x7 ) << 2; | ||
635 | LARc[3] |= ( *c >> 6 ) & 0x3; | ||
636 | LARc[4] = ( *c >> 2 ) & 0xF; | ||
637 | LARc[5] = ( *c++ & 0x3 ) << 2; | ||
638 | LARc[5] |= ( *c >> 6 ) & 0x3; | ||
639 | LARc[6] = ( *c >> 3 ) & 0x7; | ||
640 | LARc[7] = *c++ & 0x7; | ||
641 | Nc[0] = ( *c >> 1 ) & 0x7F; | ||
642 | bc[0] = ( *c++ & 0x1 ) << 1; | ||
643 | bc[0] |= ( *c >> 7 ) & 0x1; | ||
644 | Mc[0] = ( *c >> 5 ) & 0x3; | ||
645 | xmaxc[0] = ( *c++ & 0x1F ) << 1; | ||
646 | xmaxc[0] |= ( *c >> 7 ) & 0x1; | ||
647 | xmc[0] = ( *c >> 4 ) & 0x7; | ||
648 | xmc[1] = ( *c >> 1 ) & 0x7; | ||
649 | xmc[2] = ( *c++ & 0x1 ) << 2; | ||
650 | xmc[2] |= ( *c >> 6 ) & 0x3; | ||
651 | xmc[3] = ( *c >> 3 ) & 0x7; | ||
652 | xmc[4] = *c++ & 0x7; | ||
653 | xmc[5] = ( *c >> 5 ) & 0x7; | ||
654 | xmc[6] = ( *c >> 2 ) & 0x7; | ||
655 | xmc[7] = ( *c++ & 0x3 ) << 1; /* 10 */ | ||
656 | xmc[7] |= ( *c >> 7 ) & 0x1; | ||
657 | xmc[8] = ( *c >> 4 ) & 0x7; | ||
658 | xmc[9] = ( *c >> 1 ) & 0x7; | ||
659 | xmc[10] = ( *c++ & 0x1 ) << 2; | ||
660 | xmc[10] |= ( *c >> 6 ) & 0x3; | ||
661 | xmc[11] = ( *c >> 3 ) & 0x7; | ||
662 | xmc[12] = *c++ & 0x7; | ||
663 | Nc[1] = ( *c >> 1 ) & 0x7F; | ||
664 | bc[1] = ( *c++ & 0x1 ) << 1; | ||
665 | bc[1] |= ( *c >> 7 ) & 0x1; | ||
666 | Mc[1] = ( *c >> 5 ) & 0x3; | ||
667 | xmaxc[1] = ( *c++ & 0x1F ) << 1; | ||
668 | xmaxc[1] |= ( *c >> 7 ) & 0x1; | ||
669 | xmc[13] = ( *c >> 4 ) & 0x7; | ||
670 | xmc[14] = ( *c >> 1 ) & 0x7; | ||
671 | xmc[15] = ( *c++ & 0x1 ) << 2; | ||
672 | xmc[15] |= ( *c >> 6 ) & 0x3; | ||
673 | xmc[16] = ( *c >> 3 ) & 0x7; | ||
674 | xmc[17] = *c++ & 0x7; | ||
675 | xmc[18] = ( *c >> 5 ) & 0x7; | ||
676 | xmc[19] = ( *c >> 2 ) & 0x7; | ||
677 | xmc[20] = ( *c++ & 0x3 ) << 1; | ||
678 | xmc[20] |= ( *c >> 7 ) & 0x1; | ||
679 | xmc[21] = ( *c >> 4 ) & 0x7; | ||
680 | xmc[22] = ( *c >> 1 ) & 0x7; | ||
681 | xmc[23] = ( *c++ & 0x1 ) << 2; | ||
682 | xmc[23] |= ( *c >> 6 ) & 0x3; | ||
683 | xmc[24] = ( *c >> 3 ) & 0x7; | ||
684 | xmc[25] = *c++ & 0x7; | ||
685 | Nc[2] = ( *c >> 1 ) & 0x7F; | ||
686 | bc[2] = ( *c++ & 0x1 ) << 1; /* 20 */ | ||
687 | bc[2] |= ( *c >> 7 ) & 0x1; | ||
688 | Mc[2] = ( *c >> 5 ) & 0x3; | ||
689 | xmaxc[2] = ( *c++ & 0x1F ) << 1; | ||
690 | xmaxc[2] |= ( *c >> 7 ) & 0x1; | ||
691 | xmc[26] = ( *c >> 4 ) & 0x7; | ||
692 | xmc[27] = ( *c >> 1 ) & 0x7; | ||
693 | xmc[28] = ( *c++ & 0x1 ) << 2; | ||
694 | xmc[28] |= ( *c >> 6 ) & 0x3; | ||
695 | xmc[29] = ( *c >> 3 ) & 0x7; | ||
696 | xmc[30] = *c++ & 0x7; | ||
697 | xmc[31] = ( *c >> 5 ) & 0x7; | ||
698 | xmc[32] = ( *c >> 2 ) & 0x7; | ||
699 | xmc[33] = ( *c++ & 0x3 ) << 1; | ||
700 | xmc[33] |= ( *c >> 7 ) & 0x1; | ||
701 | xmc[34] = ( *c >> 4 ) & 0x7; | ||
702 | xmc[35] = ( *c >> 1 ) & 0x7; | ||
703 | xmc[36] = ( *c++ & 0x1 ) << 2; | ||
704 | xmc[36] |= ( *c >> 6 ) & 0x3; | ||
705 | xmc[37] = ( *c >> 3 ) & 0x7; | ||
706 | xmc[38] = *c++ & 0x7; | ||
707 | Nc[3] = ( *c >> 1 ) & 0x7F; | ||
708 | bc[3] = ( *c++ & 0x1 ) << 1; | ||
709 | bc[3] |= ( *c >> 7 ) & 0x1; | ||
710 | Mc[3] = ( *c >> 5 ) & 0x3; | ||
711 | xmaxc[3] = ( *c++ & 0x1F ) << 1; | ||
712 | xmaxc[3] |= ( *c >> 7 ) & 0x1; | ||
713 | xmc[39] = ( *c >> 4 ) & 0x7; | ||
714 | xmc[40] = ( *c >> 1 ) & 0x7; | ||
715 | xmc[41] = ( *c++ & 0x1 ) << 2; | ||
716 | xmc[41] |= ( *c >> 6 ) & 0x3; | ||
717 | xmc[42] = ( *c >> 3 ) & 0x7; | ||
718 | xmc[43] = *c++ & 0x7; /* 30 */ | ||
719 | xmc[44] = ( *c >> 5 ) & 0x7; | ||
720 | xmc[45] = ( *c >> 2 ) & 0x7; | ||
721 | xmc[46] = ( *c++ & 0x3 ) << 1; | ||
722 | xmc[46] |= ( *c >> 7 ) & 0x1; | ||
723 | xmc[47] = ( *c >> 4 ) & 0x7; | ||
724 | xmc[48] = ( *c >> 1 ) & 0x7; | ||
725 | xmc[49] = ( *c++ & 0x1 ) << 2; | ||
726 | xmc[49] |= ( *c >> 6 ) & 0x3; | ||
727 | xmc[50] = ( *c >> 3 ) & 0x7; | ||
728 | xmc[51] = *c & 0x7; /* 33 */ | ||
729 | |||
730 | gsm_dec_Decoder( s, LARc, Nc, bc, Mc, xmaxc, xmc, target ); | ||
731 | |||
732 | return 0; | ||
733 | } | ||
734 | |||
735 | void _Pragma( "entrypoint" ) gsm_dec_main( void ) | ||
736 | { | ||
737 | gsm r; | ||
738 | unsigned i; | ||
739 | gsm_dec_result = 0; | ||
740 | |||
741 | r = gsm_dec_state_ptr; | ||
742 | |||
743 | _Pragma( "loopbound min 1 max 1" ) | ||
744 | for ( i = 0; i < SAMPLES; i++ ) { | ||
745 | if ( gsm_dec_decode( r, gsm_dec_gsmdata + i * sizeof( gsm_frame ), | ||
746 | gsm_dec_pcmdata + i * 160 ) ) { | ||
747 | gsm_dec_result = 1; | ||
748 | return; | ||
749 | } | ||
750 | } | ||
751 | } | ||
752 | |||
753 | int main( int argc, char **argv) | ||
754 | { | ||
755 | SET_UP | ||
756 | for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){ | ||
757 | START_LOOP | ||
758 | gsm_dec_init(); | ||
759 | gsm_dec_main(); | ||
760 | STOP_LOOP | ||
761 | } | ||
762 | WRITE_TO_FILE | ||
763 | return ( gsm_dec_return() ); | ||
764 | } | ||