Mercurial > mplayer.hg
annotate libmpcodecs/native/xa_gsm.c @ 24654:effaeb5f7fde
Require atleast libnemesi 0.6.2 (range api and h263 support
author | lu_zero |
---|---|
date | Sun, 30 Sep 2007 11:11:54 +0000 |
parents | f580a7755ac5 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
1 | 1 |
867 | 2 /* |
3 Written by Mark Podlipec <podlipec@ici.net>. | |
4 | |
5 Most of this code comes from a GSM 06.10 library by | |
6 Jutta Degener and Carsten Bormann, available via | |
7 <http://www.pobox.com/~jutta/toast.html>. | |
8 | |
9 That library is distributed with the following copyright: | |
10 | |
1 | 11 Copyright 1992 by Jutta Degener and Carsten Bormann, |
12 Technische Universitaet Berlin | |
13 | |
14 Any use of this software is permitted provided that this notice is not | |
15 removed and that neither the authors nor the Technische Universitaet Berlin | |
16 are deemed to have made any representations as to the suitability of this | |
17 software for any purpose nor are held responsible for any defects of | |
18 this software. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. | |
19 | |
20 As a matter of courtesy, the authors request to be informed about uses | |
21 this software has found, about bugs in this software, and about any | |
22 improvements that may be of general interest. | |
23 | |
24 Berlin, 15.09.1992 | |
25 Jutta Degener | |
26 Carsten Bormann | |
867 | 27 */ |
1 | 28 |
29 | |
30 #include <stdio.h> | |
2476 | 31 #include <string.h> |
1 | 32 #include <assert.h> /* POD optional */ |
33 #include "xa_gsm_int.h" | |
34 | |
35 //void XA_MSGSM_Decoder(); | |
36 static void GSM_Decode(); | |
37 static void Gsm_RPE_Decoding(); | |
38 | |
39 //static short gsm_buf[320]; | |
40 static XA_GSM_STATE gsm_state; | |
41 | |
42 | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
7098
diff
changeset
|
43 void GSM_Init(void) |
1 | 44 { |
45 memset((char *)(&gsm_state), 0, sizeof(XA_GSM_STATE)); | |
46 gsm_state.nrp = 40; | |
47 } | |
48 | |
49 | |
50 /* Table 4.3b Quantization levels of the LTP gain quantizer | |
51 */ | |
52 /* bc 0 1 2 3 */ | |
53 static word gsm_QLB[4] = { 3277, 11469, 21299, 32767 }; | |
54 | |
55 /* Table 4.6 Normalized direct mantissa used to compute xM/xmax | |
56 */ | |
57 /* i 0 1 2 3 4 5 6 7 */ | |
58 static word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 }; | |
59 | |
60 | |
61 | |
62 /****************/ | |
63 #define saturate(x) \ | |
64 ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) | |
65 | |
66 /****************/ | |
67 static word gsm_sub (a,b) | |
68 word a; | |
69 word b; | |
70 { | |
71 longword diff = (longword)a - (longword)b; | |
72 return saturate(diff); | |
73 } | |
74 | |
75 /****************/ | |
76 static word gsm_asr (a,n) | |
77 word a; | |
78 int n; | |
79 { | |
80 if (n >= 16) return -(a < 0); | |
81 if (n <= -16) return 0; | |
82 if (n < 0) return a << -n; | |
83 | |
84 # ifdef SASR | |
85 return a >> n; | |
86 # else | |
87 if (a >= 0) return a >> n; | |
88 else return -(word)( -(uword)a >> n ); | |
89 # endif | |
90 } | |
91 | |
92 /****************/ | |
93 static word gsm_asl (a,n) | |
94 word a; | |
95 int n; | |
96 { | |
97 if (n >= 16) return 0; | |
98 if (n <= -16) return -(a < 0); | |
99 if (n < 0) return gsm_asr(a, -n); | |
100 return a << n; | |
101 } | |
102 | |
103 | |
104 /* | |
105 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische | |
106 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for | |
107 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. | |
108 */ | |
109 | |
110 /**** 4.2.17 */ | |
111 static void RPE_grid_positioning(Mc,xMp,ep) | |
112 word Mc; /* grid position IN */ | |
113 register word * xMp; /* [0..12] IN */ | |
114 register word * ep; /* [0..39] OUT */ | |
115 /* | |
116 * This procedure computes the reconstructed long term residual signal | |
117 * ep[0..39] for the LTP analysis filter. The inputs are the Mc | |
118 * which is the grid position selection and the xMp[0..12] decoded | |
119 * RPE samples which are upsampled by a factor of 3 by inserting zero | |
120 * values. | |
121 */ | |
122 { | |
123 int i = 13; | |
124 | |
125 assert(0 <= Mc && Mc <= 3); | |
126 | |
127 switch (Mc) { | |
128 case 3: *ep++ = 0; | |
129 case 2: do { | |
130 *ep++ = 0; | |
131 case 1: *ep++ = 0; | |
132 case 0: *ep++ = *xMp++; | |
133 } while (--i); | |
134 } | |
135 while (++Mc < 4) *ep++ = 0; | |
136 | |
137 /* | |
138 | |
139 int i, k; | |
140 for (k = 0; k <= 39; k++) ep[k] = 0; | |
141 for (i = 0; i <= 12; i++) { | |
142 ep[ Mc + (3*i) ] = xMp[i]; | |
143 } | |
144 */ | |
145 } | |
146 | |
147 | |
148 /**** 4.2.16 */ | |
149 static void APCM_inverse_quantization (xMc,mant,exp,xMp) | |
150 register word * xMc; /* [0..12] IN */ | |
151 word mant; | |
152 word exp; | |
153 register word * xMp; /* [0..12] OUT */ | |
154 /* | |
155 * This part is for decoding the RPE sequence of coded xMc[0..12] | |
156 * samples to obtain the xMp[0..12] array. Table 4.6 is used to get | |
157 * the mantissa of xmaxc (FAC[0..7]). | |
158 */ | |
159 { | |
160 int i; | |
161 word temp, temp1, temp2, temp3; | |
162 longword ltmp; | |
163 | |
164 assert( mant >= 0 && mant <= 7 ); | |
165 | |
166 temp1 = gsm_FAC[ mant ]; /* see 4.2-15 for mant */ | |
167 temp2 = gsm_sub( 6, exp ); /* see 4.2-15 for exp */ | |
168 temp3 = gsm_asl( 1, gsm_sub( temp2, 1 )); | |
169 | |
170 for (i = 13; i--;) { | |
171 | |
172 assert( *xMc <= 7 && *xMc >= 0 ); /* 3 bit unsigned */ | |
173 | |
174 /* temp = gsm_sub( *xMc++ << 1, 7 ); */ | |
175 temp = (*xMc++ << 1) - 7; /* restore sign */ | |
176 assert( temp <= 7 && temp >= -7 ); /* 4 bit signed */ | |
177 | |
178 temp <<= 12; /* 16 bit signed */ | |
179 temp = GSM_MULT_R( temp1, temp ); | |
180 temp = GSM_ADD( temp, temp3 ); | |
181 *xMp++ = gsm_asr( temp, temp2 ); | |
182 } | |
183 } | |
184 | |
185 | |
186 /**** 4.12.15 */ | |
187 static void APCM_quantization_xmaxc_to_exp_mant (xmaxc,exp_out,mant_out) | |
188 word xmaxc; /* IN */ | |
189 word * exp_out; /* OUT */ | |
190 word * mant_out; /* OUT */ | |
191 { | |
192 word exp, mant; | |
193 | |
194 /* Compute exponent and mantissa of the decoded version of xmaxc | |
195 */ | |
196 | |
197 exp = 0; | |
198 if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1; | |
199 mant = xmaxc - (exp << 3); | |
200 | |
201 if (mant == 0) { | |
202 exp = -4; | |
203 mant = 7; | |
204 } | |
205 else { | |
206 while (mant <= 7) { | |
207 mant = mant << 1 | 1; | |
208 exp--; | |
209 } | |
210 mant -= 8; | |
211 } | |
212 | |
213 assert( exp >= -4 && exp <= 6 ); | |
214 assert( mant >= 0 && mant <= 7 ); | |
215 | |
216 *exp_out = exp; | |
217 *mant_out = mant; | |
218 } | |
219 | |
220 static void Gsm_RPE_Decoding (S, xmaxcr, Mcr, xMcr, erp) | |
221 XA_GSM_STATE * S; | |
222 word xmaxcr; | |
223 word Mcr; | |
224 word * xMcr; /* [0..12], 3 bits IN */ | |
225 word * erp; /* [0..39] OUT */ | |
226 | |
227 { | |
228 word exp, mant; | |
229 word xMp[ 13 ]; | |
230 | |
231 APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant ); | |
232 APCM_inverse_quantization( xMcr, mant, exp, xMp ); | |
233 RPE_grid_positioning( Mcr, xMp, erp ); | |
234 | |
235 } | |
236 | |
237 | |
238 /* | |
239 * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER | |
240 */ | |
241 | |
242 static void Postprocessing(S,s) | |
243 XA_GSM_STATE * S; | |
244 register word * s; | |
245 { | |
246 register int k; | |
247 register word msr = S->msr; | |
248 register longword ltmp; /* for GSM_ADD */ | |
249 register word tmp; | |
250 | |
251 for (k = 160; k--; s++) | |
252 { | |
253 tmp = GSM_MULT_R( msr, 28180 ); | |
254 msr = GSM_ADD(*s, tmp); /* Deemphasis */ | |
255 *s = GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */ | |
256 } | |
257 S->msr = msr; | |
258 } | |
259 | |
260 /**** 4.3.2 */ | |
261 void Gsm_Long_Term_Synthesis_Filtering (S,Ncr,bcr,erp,drp) | |
262 XA_GSM_STATE * S; | |
263 word Ncr; | |
264 word bcr; | |
265 register word * erp; /* [0..39] IN */ | |
266 register word * drp; /* [-120..-1] IN, [-120..40] OUT */ | |
267 | |
268 /* | |
269 * This procedure uses the bcr and Ncr parameter to realize the | |
270 * long term synthesis filtering. The decoding of bcr needs | |
271 * table 4.3b. | |
272 */ | |
273 { | |
274 register longword ltmp; /* for ADD */ | |
275 register int k; | |
276 word brp, drpp, Nr; | |
277 | |
278 /* Check the limits of Nr. | |
279 */ | |
280 Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr; | |
281 S->nrp = Nr; | |
282 assert(Nr >= 40 && Nr <= 120); | |
283 | |
284 /* Decoding of the LTP gain bcr | |
285 */ | |
286 brp = gsm_QLB[ bcr ]; | |
287 | |
288 /* Computation of the reconstructed short term residual | |
289 * signal drp[0..39] | |
290 */ | |
291 assert(brp != MIN_WORD); | |
292 | |
293 for (k = 0; k <= 39; k++) { | |
294 drpp = GSM_MULT_R( brp, drp[ k - Nr ] ); | |
295 drp[k] = GSM_ADD( erp[k], drpp ); | |
296 } | |
297 | |
298 /* | |
299 * Update of the reconstructed short term residual signal | |
300 * drp[ -1..-120 ] | |
301 */ | |
302 | |
303 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ]; | |
304 } | |
305 | |
306 static void Short_term_synthesis_filtering (S,rrp,k,wt,sr) | |
307 XA_GSM_STATE *S; | |
308 register word *rrp; /* [0..7] IN */ | |
309 register int k; /* k_end - k_start */ | |
310 register word *wt; /* [0..k-1] IN */ | |
311 register word *sr; /* [0..k-1] OUT */ | |
312 { | |
313 register word * v = S->v; | |
314 register int i; | |
315 register word sri, tmp1, tmp2; | |
316 register longword ltmp; /* for GSM_ADD & GSM_SUB */ | |
317 | |
318 while (k--) { | |
319 sri = *wt++; | |
320 for (i = 8; i--;) { | |
321 | |
322 /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) ); | |
323 */ | |
324 tmp1 = rrp[i]; | |
325 tmp2 = v[i]; | |
326 tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD | |
327 ? MAX_WORD | |
328 : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2 | |
329 + 16384) >> 15)) ; | |
330 | |
331 sri = GSM_SUB( sri, tmp2 ); | |
332 | |
333 /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) ); | |
334 */ | |
335 tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD | |
336 ? MAX_WORD | |
337 : 0x0FFFF & (( (longword)tmp1 * (longword)sri | |
338 + 16384) >> 15)) ; | |
339 | |
340 v[i+1] = GSM_ADD( v[i], tmp1); | |
341 } | |
342 *sr++ = v[0] = sri; | |
343 } | |
344 } | |
345 | |
346 /* 4.2.8 */ | |
347 | |
348 static void Decoding_of_the_coded_Log_Area_Ratios (LARc,LARpp) | |
349 word * LARc; /* coded log area ratio [0..7] IN */ | |
350 word * LARpp; /* out: decoded .. */ | |
351 { | |
352 register word temp1 /* , temp2 */; | |
353 register long ltmp; /* for GSM_ADD */ | |
354 | |
355 /* This procedure requires for efficient implementation | |
356 * two tables. | |
357 * | |
358 * INVA[1..8] = integer( (32768 * 8) / real_A[1..8]) | |
359 * MIC[1..8] = minimum value of the LARc[1..8] | |
360 */ | |
361 | |
362 /* Compute the LARpp[1..8] | |
363 */ | |
364 | |
365 /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) { | |
366 * | |
367 * temp1 = GSM_ADD( *LARc, *MIC ) << 10; | |
368 * temp2 = *B << 1; | |
369 * temp1 = GSM_SUB( temp1, temp2 ); | |
370 * | |
371 * assert(*INVA != MIN_WORD); | |
372 * | |
373 * temp1 = GSM_MULT_R( *INVA, temp1 ); | |
374 * *LARpp = GSM_ADD( temp1, temp1 ); | |
375 * } | |
376 */ | |
377 | |
378 #undef STEP | |
379 #define STEP( B, MIC, INVA ) \ | |
380 temp1 = GSM_ADD( *LARc++, MIC ) << 10; \ | |
381 temp1 = GSM_SUB( temp1, B << 1 ); \ | |
382 temp1 = GSM_MULT_R( INVA, temp1 ); \ | |
383 *LARpp++ = GSM_ADD( temp1, temp1 ); | |
384 | |
385 STEP( 0, -32, 13107 ); | |
386 STEP( 0, -32, 13107 ); | |
387 STEP( 2048, -16, 13107 ); | |
388 STEP( -2560, -16, 13107 ); | |
389 | |
390 STEP( 94, -8, 19223 ); | |
391 STEP( -1792, -8, 17476 ); | |
392 STEP( -341, -4, 31454 ); | |
393 STEP( -1144, -4, 29708 ); | |
394 | |
395 /* NOTE: the addition of *MIC is used to restore | |
396 * the sign of *LARc. | |
397 */ | |
398 } | |
399 | |
400 /* 4.2.9 */ | |
401 /* Computation of the quantized reflection coefficients | |
402 */ | |
403 | |
404 /* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8] | |
405 */ | |
406 | |
407 /* | |
408 * Within each frame of 160 analyzed speech samples the short term | |
409 * analysis and synthesis filters operate with four different sets of | |
410 * coefficients, derived from the previous set of decoded LARs(LARpp(j-1)) | |
411 * and the actual set of decoded LARs (LARpp(j)) | |
412 * | |
413 * (Initial value: LARpp(j-1)[1..8] = 0.) | |
414 */ | |
415 | |
416 static void Coefficients_0_12 (LARpp_j_1, LARpp_j, LARp) | |
417 register word * LARpp_j_1; | |
418 register word * LARpp_j; | |
419 register word * LARp; | |
420 { | |
421 register int i; | |
422 register longword ltmp; | |
423 | |
424 for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) { | |
425 *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 )); | |
426 *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1)); | |
427 } | |
428 } | |
429 | |
430 static void Coefficients_13_26 (LARpp_j_1, LARpp_j, LARp) | |
431 register word * LARpp_j_1; | |
432 register word * LARpp_j; | |
433 register word * LARp; | |
434 { | |
435 register int i; | |
436 register longword ltmp; | |
437 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { | |
438 *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 )); | |
439 } | |
440 } | |
441 | |
442 static void Coefficients_27_39 (LARpp_j_1, LARpp_j, LARp) | |
443 register word * LARpp_j_1; | |
444 register word * LARpp_j; | |
445 register word * LARp; | |
446 { | |
447 register int i; | |
448 register longword ltmp; | |
449 | |
450 for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) { | |
451 *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 )); | |
452 *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 )); | |
453 } | |
454 } | |
455 | |
456 | |
457 static void Coefficients_40_159 (LARpp_j, LARp) | |
458 register word * LARpp_j; | |
459 register word * LARp; | |
460 { | |
461 register int i; | |
462 | |
463 for (i = 1; i <= 8; i++, LARp++, LARpp_j++) | |
464 *LARp = *LARpp_j; | |
465 } | |
466 /* 4.2.9.2 */ | |
467 | |
468 static void LARp_to_rp (LARp) | |
469 register word * LARp; /* [0..7] IN/OUT */ | |
470 /* | |
471 * The input of this procedure is the interpolated LARp[0..7] array. | |
472 * The reflection coefficients, rp[i], are used in the analysis | |
473 * filter and in the synthesis filter. | |
474 */ | |
475 { | |
476 register int i; | |
477 register word temp; | |
478 register longword ltmp; | |
479 | |
480 for (i = 1; i <= 8; i++, LARp++) { | |
481 | |
482 /* temp = GSM_ABS( *LARp ); | |
483 * | |
484 * if (temp < 11059) temp <<= 1; | |
485 * else if (temp < 20070) temp += 11059; | |
486 * else temp = GSM_ADD( temp >> 2, 26112 ); | |
487 * | |
488 * *LARp = *LARp < 0 ? -temp : temp; | |
489 */ | |
490 | |
491 if (*LARp < 0) { | |
492 temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp); | |
493 *LARp = - ((temp < 11059) ? temp << 1 | |
494 : ((temp < 20070) ? temp + 11059 | |
495 : GSM_ADD( temp >> 2, 26112 ))); | |
496 } else { | |
497 temp = *LARp; | |
498 *LARp = (temp < 11059) ? temp << 1 | |
499 : ((temp < 20070) ? temp + 11059 | |
500 : GSM_ADD( temp >> 2, 26112 )); | |
501 } | |
502 } | |
503 } | |
504 | |
505 | |
506 | |
507 | |
508 | |
509 /**** */ | |
510 static void Gsm_Short_Term_Synthesis_Filter (S, LARcr, wt, s) | |
511 XA_GSM_STATE * S; | |
512 word * LARcr; /* received log area ratios [0..7] IN */ | |
513 word * wt; /* received d [0..159] IN */ | |
514 word * s; /* signal s [0..159] OUT */ | |
515 { | |
516 word * LARpp_j = S->LARpp[ S->j ]; | |
517 word * LARpp_j_1 = S->LARpp[ S->j ^=1 ]; | |
518 | |
519 word LARp[8]; | |
520 | |
521 #undef FILTER | |
522 #if defined(FAST) && defined(USE_FLOAT_MUL) | |
523 | |
524 # define FILTER (* (S->fast \ | |
525 ? Fast_Short_term_synthesis_filtering \ | |
526 : Short_term_synthesis_filtering )) | |
527 #else | |
528 # define FILTER Short_term_synthesis_filtering | |
529 #endif | |
530 | |
531 Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j ); | |
532 | |
533 Coefficients_0_12( LARpp_j_1, LARpp_j, LARp ); | |
534 LARp_to_rp( LARp ); | |
535 FILTER( S, LARp, 13, wt, s ); | |
536 | |
537 Coefficients_13_26( LARpp_j_1, LARpp_j, LARp); | |
538 LARp_to_rp( LARp ); | |
539 FILTER( S, LARp, 14, wt + 13, s + 13 ); | |
540 | |
541 Coefficients_27_39( LARpp_j_1, LARpp_j, LARp); | |
542 LARp_to_rp( LARp ); | |
543 FILTER( S, LARp, 13, wt + 27, s + 27 ); | |
544 | |
545 Coefficients_40_159( LARpp_j, LARp ); | |
546 LARp_to_rp( LARp ); | |
547 FILTER(S, LARp, 120, wt + 40, s + 40); | |
548 } | |
549 | |
550 | |
551 | |
552 | |
553 static void GSM_Decode(S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s) | |
554 XA_GSM_STATE *S; | |
555 word *LARcr; /* [0..7] IN */ | |
556 word *Ncr; /* [0..3] IN */ | |
557 word *bcr; /* [0..3] IN */ | |
558 word *Mcr; /* [0..3] IN */ | |
559 word *xmaxcr; /* [0..3] IN */ | |
560 word *xMcr; /* [0..13*4] IN */ | |
561 word *s; /* [0..159] OUT */ | |
562 { | |
563 int j, k; | |
564 word erp[40], wt[160]; | |
565 word *drp = S->dp0 + 120; | |
566 | |
567 for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) | |
568 { | |
569 Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp ); | |
570 Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp ); | |
571 for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ]; | |
572 } | |
573 | |
574 Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s ); | |
575 Postprocessing(S, s); | |
576 } | |
577 | |
578 | |
579 | |
580 /****-------------------------------------------------------------------**** | |
581 **** Podlipec: For AVI/WAV files GSM 6.10 combines two 33 bytes frames | |
582 **** into one 65 byte frame. | |
583 ****-------------------------------------------------------------------****/ | |
584 void XA_MSGSM_Decoder(unsigned char *ibuf,unsigned short *obuf) | |
585 { word sr; | |
586 word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; | |
587 | |
588 sr = *ibuf++; | |
589 | |
590 LARc[0] = sr & 0x3f; sr >>= 6; | |
591 sr |= (word)*ibuf++ << 2; | |
592 LARc[1] = sr & 0x3f; sr >>= 6; | |
593 sr |= (word)*ibuf++ << 4; | |
594 LARc[2] = sr & 0x1f; sr >>= 5; | |
595 LARc[3] = sr & 0x1f; sr >>= 5; | |
596 sr |= (word)*ibuf++ << 2; | |
597 LARc[4] = sr & 0xf; sr >>= 4; | |
598 LARc[5] = sr & 0xf; sr >>= 4; | |
599 sr |= (word)*ibuf++ << 2; /* 5 */ | |
600 LARc[6] = sr & 0x7; sr >>= 3; | |
601 LARc[7] = sr & 0x7; sr >>= 3; | |
602 sr |= (word)*ibuf++ << 4; | |
603 Nc[0] = sr & 0x7f; sr >>= 7; | |
604 bc[0] = sr & 0x3; sr >>= 2; | |
605 Mc[0] = sr & 0x3; sr >>= 2; | |
606 sr |= (word)*ibuf++ << 1; | |
607 xmaxc[0] = sr & 0x3f; sr >>= 6; | |
608 xmc[0] = sr & 0x7; sr >>= 3; | |
609 sr = *ibuf++; | |
610 xmc[1] = sr & 0x7; sr >>= 3; | |
611 xmc[2] = sr & 0x7; sr >>= 3; | |
612 sr |= (word)*ibuf++ << 2; | |
613 xmc[3] = sr & 0x7; sr >>= 3; | |
614 xmc[4] = sr & 0x7; sr >>= 3; | |
615 xmc[5] = sr & 0x7; sr >>= 3; | |
616 sr |= (word)*ibuf++ << 1; /* 10 */ | |
617 xmc[6] = sr & 0x7; sr >>= 3; | |
618 xmc[7] = sr & 0x7; sr >>= 3; | |
619 xmc[8] = sr & 0x7; sr >>= 3; | |
620 sr = *ibuf++; | |
621 xmc[9] = sr & 0x7; sr >>= 3; | |
622 xmc[10] = sr & 0x7; sr >>= 3; | |
623 sr |= (word)*ibuf++ << 2; | |
624 xmc[11] = sr & 0x7; sr >>= 3; | |
625 xmc[12] = sr & 0x7; sr >>= 3; | |
626 sr |= (word)*ibuf++ << 4; | |
627 Nc[1] = sr & 0x7f; sr >>= 7; | |
628 bc[1] = sr & 0x3; sr >>= 2; | |
629 Mc[1] = sr & 0x3; sr >>= 2; | |
630 sr |= (word)*ibuf++ << 1; | |
631 xmaxc[1] = sr & 0x3f; sr >>= 6; | |
632 xmc[13] = sr & 0x7; sr >>= 3; | |
633 sr = *ibuf++; /* 15 */ | |
634 xmc[14] = sr & 0x7; sr >>= 3; | |
635 xmc[15] = sr & 0x7; sr >>= 3; | |
636 sr |= (word)*ibuf++ << 2; | |
637 xmc[16] = sr & 0x7; sr >>= 3; | |
638 xmc[17] = sr & 0x7; sr >>= 3; | |
639 xmc[18] = sr & 0x7; sr >>= 3; | |
640 sr |= (word)*ibuf++ << 1; | |
641 xmc[19] = sr & 0x7; sr >>= 3; | |
642 xmc[20] = sr & 0x7; sr >>= 3; | |
643 xmc[21] = sr & 0x7; sr >>= 3; | |
644 sr = *ibuf++; | |
645 xmc[22] = sr & 0x7; sr >>= 3; | |
646 xmc[23] = sr & 0x7; sr >>= 3; | |
647 sr |= (word)*ibuf++ << 2; | |
648 xmc[24] = sr & 0x7; sr >>= 3; | |
649 xmc[25] = sr & 0x7; sr >>= 3; | |
650 sr |= (word)*ibuf++ << 4; /* 20 */ | |
651 Nc[2] = sr & 0x7f; sr >>= 7; | |
652 bc[2] = sr & 0x3; sr >>= 2; | |
653 Mc[2] = sr & 0x3; sr >>= 2; | |
654 sr |= (word)*ibuf++ << 1; | |
655 xmaxc[2] = sr & 0x3f; sr >>= 6; | |
656 xmc[26] = sr & 0x7; sr >>= 3; | |
657 sr = *ibuf++; | |
658 xmc[27] = sr & 0x7; sr >>= 3; | |
659 xmc[28] = sr & 0x7; sr >>= 3; | |
660 sr |= (word)*ibuf++ << 2; | |
661 xmc[29] = sr & 0x7; sr >>= 3; | |
662 xmc[30] = sr & 0x7; sr >>= 3; | |
663 xmc[31] = sr & 0x7; sr >>= 3; | |
664 sr |= (word)*ibuf++ << 1; | |
665 xmc[32] = sr & 0x7; sr >>= 3; | |
666 xmc[33] = sr & 0x7; sr >>= 3; | |
667 xmc[34] = sr & 0x7; sr >>= 3; | |
668 sr = *ibuf++; /* 25 */ | |
669 xmc[35] = sr & 0x7; sr >>= 3; | |
670 xmc[36] = sr & 0x7; sr >>= 3; | |
671 sr |= (word)*ibuf++ << 2; | |
672 xmc[37] = sr & 0x7; sr >>= 3; | |
673 xmc[38] = sr & 0x7; sr >>= 3; | |
674 sr |= (word)*ibuf++ << 4; | |
675 Nc[3] = sr & 0x7f; sr >>= 7; | |
676 bc[3] = sr & 0x3; sr >>= 2; | |
677 Mc[3] = sr & 0x3; sr >>= 2; | |
678 sr |= (word)*ibuf++ << 1; | |
679 xmaxc[3] = sr & 0x3f; sr >>= 6; | |
680 xmc[39] = sr & 0x7; sr >>= 3; | |
681 sr = *ibuf++; | |
682 xmc[40] = sr & 0x7; sr >>= 3; | |
683 xmc[41] = sr & 0x7; sr >>= 3; | |
684 sr |= (word)*ibuf++ << 2; /* 30 */ | |
685 xmc[42] = sr & 0x7; sr >>= 3; | |
686 xmc[43] = sr & 0x7; sr >>= 3; | |
687 xmc[44] = sr & 0x7; sr >>= 3; | |
688 sr |= (word)*ibuf++ << 1; | |
689 xmc[45] = sr & 0x7; sr >>= 3; | |
690 xmc[46] = sr & 0x7; sr >>= 3; | |
691 xmc[47] = sr & 0x7; sr >>= 3; | |
692 sr = *ibuf++; | |
693 xmc[48] = sr & 0x7; sr >>= 3; | |
694 xmc[49] = sr & 0x7; sr >>= 3; | |
695 sr |= (word)*ibuf++ << 2; | |
696 xmc[50] = sr & 0x7; sr >>= 3; | |
697 xmc[51] = sr & 0x7; sr >>= 3; | |
698 | |
699 GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, obuf); | |
700 | |
701 /* | |
702 carry = sr & 0xf; | |
703 sr = carry; | |
704 */ | |
705 /* 2nd frame */ | |
706 sr &= 0xf; | |
707 sr |= (word)*ibuf++ << 4; /* 1 */ | |
708 LARc[0] = sr & 0x3f; sr >>= 6; | |
709 LARc[1] = sr & 0x3f; sr >>= 6; | |
710 sr = *ibuf++; | |
711 LARc[2] = sr & 0x1f; sr >>= 5; | |
712 sr |= (word)*ibuf++ << 3; | |
713 LARc[3] = sr & 0x1f; sr >>= 5; | |
714 LARc[4] = sr & 0xf; sr >>= 4; | |
715 sr |= (word)*ibuf++ << 2; | |
716 LARc[5] = sr & 0xf; sr >>= 4; | |
717 LARc[6] = sr & 0x7; sr >>= 3; | |
718 LARc[7] = sr & 0x7; sr >>= 3; | |
719 sr = *ibuf++; /* 5 */ | |
720 Nc[0] = sr & 0x7f; sr >>= 7; | |
721 sr |= (word)*ibuf++ << 1; | |
722 bc[0] = sr & 0x3; sr >>= 2; | |
723 Mc[0] = sr & 0x3; sr >>= 2; | |
724 sr |= (word)*ibuf++ << 5; | |
725 xmaxc[0] = sr & 0x3f; sr >>= 6; | |
726 xmc[0] = sr & 0x7; sr >>= 3; | |
727 xmc[1] = sr & 0x7; sr >>= 3; | |
728 sr |= (word)*ibuf++ << 1; | |
729 xmc[2] = sr & 0x7; sr >>= 3; | |
730 xmc[3] = sr & 0x7; sr >>= 3; | |
731 xmc[4] = sr & 0x7; sr >>= 3; | |
732 sr = *ibuf++; | |
733 xmc[5] = sr & 0x7; sr >>= 3; | |
734 xmc[6] = sr & 0x7; sr >>= 3; | |
735 sr |= (word)*ibuf++ << 2; /* 10 */ | |
736 xmc[7] = sr & 0x7; sr >>= 3; | |
737 xmc[8] = sr & 0x7; sr >>= 3; | |
738 xmc[9] = sr & 0x7; sr >>= 3; | |
739 sr |= (word)*ibuf++ << 1; | |
740 xmc[10] = sr & 0x7; sr >>= 3; | |
741 xmc[11] = sr & 0x7; sr >>= 3; | |
742 xmc[12] = sr & 0x7; sr >>= 3; | |
743 sr = *ibuf++; | |
744 Nc[1] = sr & 0x7f; sr >>= 7; | |
745 sr |= (word)*ibuf++ << 1; | |
746 bc[1] = sr & 0x3; sr >>= 2; | |
747 Mc[1] = sr & 0x3; sr >>= 2; | |
748 sr |= (word)*ibuf++ << 5; | |
749 xmaxc[1] = sr & 0x3f; sr >>= 6; | |
750 xmc[13] = sr & 0x7; sr >>= 3; | |
751 xmc[14] = sr & 0x7; sr >>= 3; | |
752 sr |= (word)*ibuf++ << 1; /* 15 */ | |
753 xmc[15] = sr & 0x7; sr >>= 3; | |
754 xmc[16] = sr & 0x7; sr >>= 3; | |
755 xmc[17] = sr & 0x7; sr >>= 3; | |
756 sr = *ibuf++; | |
757 xmc[18] = sr & 0x7; sr >>= 3; | |
758 xmc[19] = sr & 0x7; sr >>= 3; | |
759 sr |= (word)*ibuf++ << 2; | |
760 xmc[20] = sr & 0x7; sr >>= 3; | |
761 xmc[21] = sr & 0x7; sr >>= 3; | |
762 xmc[22] = sr & 0x7; sr >>= 3; | |
763 sr |= (word)*ibuf++ << 1; | |
764 xmc[23] = sr & 0x7; sr >>= 3; | |
765 xmc[24] = sr & 0x7; sr >>= 3; | |
766 xmc[25] = sr & 0x7; sr >>= 3; | |
767 sr = *ibuf++; | |
768 Nc[2] = sr & 0x7f; sr >>= 7; | |
769 sr |= (word)*ibuf++ << 1; /* 20 */ | |
770 bc[2] = sr & 0x3; sr >>= 2; | |
771 Mc[2] = sr & 0x3; sr >>= 2; | |
772 sr |= (word)*ibuf++ << 5; | |
773 xmaxc[2] = sr & 0x3f; sr >>= 6; | |
774 xmc[26] = sr & 0x7; sr >>= 3; | |
775 xmc[27] = sr & 0x7; sr >>= 3; | |
776 sr |= (word)*ibuf++ << 1; | |
777 xmc[28] = sr & 0x7; sr >>= 3; | |
778 xmc[29] = sr & 0x7; sr >>= 3; | |
779 xmc[30] = sr & 0x7; sr >>= 3; | |
780 sr = *ibuf++; | |
781 xmc[31] = sr & 0x7; sr >>= 3; | |
782 xmc[32] = sr & 0x7; sr >>= 3; | |
783 sr |= (word)*ibuf++ << 2; | |
784 xmc[33] = sr & 0x7; sr >>= 3; | |
785 xmc[34] = sr & 0x7; sr >>= 3; | |
786 xmc[35] = sr & 0x7; sr >>= 3; | |
787 sr |= (word)*ibuf++ << 1; /* 25 */ | |
788 xmc[36] = sr & 0x7; sr >>= 3; | |
789 xmc[37] = sr & 0x7; sr >>= 3; | |
790 xmc[38] = sr & 0x7; sr >>= 3; | |
791 sr = *ibuf++; | |
792 Nc[3] = sr & 0x7f; sr >>= 7; | |
793 sr |= (word)*ibuf++ << 1; | |
794 bc[3] = sr & 0x3; sr >>= 2; | |
795 Mc[3] = sr & 0x3; sr >>= 2; | |
796 sr |= (word)*ibuf++ << 5; | |
797 xmaxc[3] = sr & 0x3f; sr >>= 6; | |
798 xmc[39] = sr & 0x7; sr >>= 3; | |
799 xmc[40] = sr & 0x7; sr >>= 3; | |
800 sr |= (word)*ibuf++ << 1; | |
801 xmc[41] = sr & 0x7; sr >>= 3; | |
802 xmc[42] = sr & 0x7; sr >>= 3; | |
803 xmc[43] = sr & 0x7; sr >>= 3; | |
804 sr = (word)*ibuf++; /* 30 */ | |
805 xmc[44] = sr & 0x7; sr >>= 3; | |
806 xmc[45] = sr & 0x7; sr >>= 3; | |
807 sr |= (word)*ibuf++ << 2; | |
808 xmc[46] = sr & 0x7; sr >>= 3; | |
809 xmc[47] = sr & 0x7; sr >>= 3; | |
810 xmc[48] = sr & 0x7; sr >>= 3; | |
811 sr |= (word)*ibuf++ << 1; | |
812 xmc[49] = sr & 0x7; sr >>= 3; | |
813 xmc[50] = sr & 0x7; sr >>= 3; | |
814 xmc[51] = sr & 0x7; sr >>= 3; | |
815 | |
816 GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, &obuf[160]); | |
817 | |
818 /* Return number of source bytes consumed and output samples produced */ | |
819 // *icnt = 65; | |
820 // *ocnt = 320; | |
821 return; | |
822 } | |
823 | |
824 #define GSM_MAGIC 0xd | |
825 | |
826 void XA_GSM_Decoder(unsigned char *ibuf,unsigned short *obuf) | |
827 { word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4]; | |
828 | |
829 /* Sanity */ | |
830 if (((*ibuf >> 4) & 0x0F) != GSM_MAGIC) | |
831 { int i; | |
832 for(i=0;i<160;i++) obuf[i] = 0; | |
833 // *icnt = 33; | |
834 // *ocnt = 160; | |
835 return; | |
836 } | |
837 | |
838 LARc[0] = (*ibuf++ & 0xF) << 2; /* 1 */ | |
839 LARc[0] |= (*ibuf >> 6) & 0x3; | |
840 LARc[1] = *ibuf++ & 0x3F; | |
841 LARc[2] = (*ibuf >> 3) & 0x1F; | |
842 LARc[3] = (*ibuf++ & 0x7) << 2; | |
843 LARc[3] |= (*ibuf >> 6) & 0x3; | |
844 LARc[4] = (*ibuf >> 2) & 0xF; | |
845 LARc[5] = (*ibuf++ & 0x3) << 2; | |
846 LARc[5] |= (*ibuf >> 6) & 0x3; | |
847 LARc[6] = (*ibuf >> 3) & 0x7; | |
848 LARc[7] = *ibuf++ & 0x7; | |
849 | |
850 Nc[0] = (*ibuf >> 1) & 0x7F; | |
851 | |
852 bc[0] = (*ibuf++ & 0x1) << 1; | |
853 bc[0] |= (*ibuf >> 7) & 0x1; | |
854 | |
855 Mc[0] = (*ibuf >> 5) & 0x3; | |
856 | |
857 xmaxc[0] = (*ibuf++ & 0x1F) << 1; | |
858 xmaxc[0] |= (*ibuf >> 7) & 0x1; | |
859 | |
860 xmc[0] = (*ibuf >> 4) & 0x7; | |
861 xmc[1] = (*ibuf >> 1) & 0x7; | |
862 xmc[2] = (*ibuf++ & 0x1) << 2; | |
863 xmc[2] |= (*ibuf >> 6) & 0x3; | |
864 xmc[3] = (*ibuf >> 3) & 0x7; | |
865 xmc[4] = *ibuf++ & 0x7; | |
866 xmc[5] = (*ibuf >> 5) & 0x7; | |
867 xmc[6] = (*ibuf >> 2) & 0x7; | |
868 xmc[7] = (*ibuf++ & 0x3) << 1; /* 10 */ | |
869 xmc[7] |= (*ibuf >> 7) & 0x1; | |
870 xmc[8] = (*ibuf >> 4) & 0x7; | |
871 xmc[9] = (*ibuf >> 1) & 0x7; | |
872 xmc[10] = (*ibuf++ & 0x1) << 2; | |
873 xmc[10] |= (*ibuf >> 6) & 0x3; | |
874 xmc[11] = (*ibuf >> 3) & 0x7; | |
875 xmc[12] = *ibuf++ & 0x7; | |
876 | |
877 Nc[1] = (*ibuf >> 1) & 0x7F; | |
878 | |
879 bc[1] = (*ibuf++ & 0x1) << 1; | |
880 bc[1] |= (*ibuf >> 7) & 0x1; | |
881 | |
882 Mc[1] = (*ibuf >> 5) & 0x3; | |
883 | |
884 xmaxc[1] = (*ibuf++ & 0x1F) << 1; | |
885 xmaxc[1] |= (*ibuf >> 7) & 0x1; | |
886 | |
887 | |
888 xmc[13] = (*ibuf >> 4) & 0x7; | |
889 xmc[14] = (*ibuf >> 1) & 0x7; | |
890 xmc[15] = (*ibuf++ & 0x1) << 2; | |
891 xmc[15] |= (*ibuf >> 6) & 0x3; | |
892 xmc[16] = (*ibuf >> 3) & 0x7; | |
893 xmc[17] = *ibuf++ & 0x7; | |
894 xmc[18] = (*ibuf >> 5) & 0x7; | |
895 xmc[19] = (*ibuf >> 2) & 0x7; | |
896 xmc[20] = (*ibuf++ & 0x3) << 1; | |
897 xmc[20] |= (*ibuf >> 7) & 0x1; | |
898 xmc[21] = (*ibuf >> 4) & 0x7; | |
899 xmc[22] = (*ibuf >> 1) & 0x7; | |
900 xmc[23] = (*ibuf++ & 0x1) << 2; | |
901 xmc[23] |= (*ibuf >> 6) & 0x3; | |
902 xmc[24] = (*ibuf >> 3) & 0x7; | |
903 xmc[25] = *ibuf++ & 0x7; | |
904 | |
905 Nc[2] = (*ibuf >> 1) & 0x7F; | |
906 | |
907 bc[2] = (*ibuf++ & 0x1) << 1; /* 20 */ | |
908 bc[2] |= (*ibuf >> 7) & 0x1; | |
909 | |
910 Mc[2] = (*ibuf >> 5) & 0x3; | |
911 | |
912 xmaxc[2] = (*ibuf++ & 0x1F) << 1; | |
913 xmaxc[2] |= (*ibuf >> 7) & 0x1; | |
914 | |
915 | |
916 xmc[26] = (*ibuf >> 4) & 0x7; | |
917 xmc[27] = (*ibuf >> 1) & 0x7; | |
918 xmc[28] = (*ibuf++ & 0x1) << 2; | |
919 xmc[28] |= (*ibuf >> 6) & 0x3; | |
920 xmc[29] = (*ibuf >> 3) & 0x7; | |
921 xmc[30] = *ibuf++ & 0x7; | |
922 xmc[31] = (*ibuf >> 5) & 0x7; | |
923 xmc[32] = (*ibuf >> 2) & 0x7; | |
924 xmc[33] = (*ibuf++ & 0x3) << 1; | |
925 xmc[33] |= (*ibuf >> 7) & 0x1; | |
926 xmc[34] = (*ibuf >> 4) & 0x7; | |
927 xmc[35] = (*ibuf >> 1) & 0x7; | |
928 xmc[36] = (*ibuf++ & 0x1) << 2; | |
929 xmc[36] |= (*ibuf >> 6) & 0x3; | |
930 xmc[37] = (*ibuf >> 3) & 0x7; | |
931 xmc[38] = *ibuf++ & 0x7; | |
932 | |
933 Nc[3] = (*ibuf >> 1) & 0x7F; | |
934 | |
935 bc[3] = (*ibuf++ & 0x1) << 1; | |
936 bc[3] |= (*ibuf >> 7) & 0x1; | |
937 | |
938 Mc[3] = (*ibuf >> 5) & 0x3; | |
939 | |
940 xmaxc[3] = (*ibuf++ & 0x1F) << 1; | |
941 xmaxc[3] |= (*ibuf >> 7) & 0x1; | |
942 | |
943 xmc[39] = (*ibuf >> 4) & 0x7; | |
944 xmc[40] = (*ibuf >> 1) & 0x7; | |
945 xmc[41] = (*ibuf++ & 0x1) << 2; | |
946 xmc[41] |= (*ibuf >> 6) & 0x3; | |
947 xmc[42] = (*ibuf >> 3) & 0x7; | |
948 xmc[43] = *ibuf++ & 0x7; /* 30 */ | |
949 xmc[44] = (*ibuf >> 5) & 0x7; | |
950 xmc[45] = (*ibuf >> 2) & 0x7; | |
951 xmc[46] = (*ibuf++ & 0x3) << 1; | |
952 xmc[46] |= (*ibuf >> 7) & 0x1; | |
953 xmc[47] = (*ibuf >> 4) & 0x7; | |
954 xmc[48] = (*ibuf >> 1) & 0x7; | |
955 xmc[49] = (*ibuf++ & 0x1) << 2; | |
956 xmc[49] |= (*ibuf >> 6) & 0x3; | |
957 xmc[50] = (*ibuf >> 3) & 0x7; | |
958 xmc[51] = *ibuf & 0x7; /* 33 */ | |
959 | |
960 GSM_Decode(&gsm_state, LARc, Nc, bc, Mc, xmaxc, xmc, obuf); | |
961 | |
962 /* Return number of source bytes consumed and output samples produced */ | |
963 // *icnt = 33; | |
964 // *ocnt = 160; | |
965 } |