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 * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
20 * This module computes the LTP gain (bc) and the LTP lag (Nc)
21 * for the long term analysis filter. This is done by calculating a
22 * maximum of the cross-correlation function between the current
23 * sub-segment short term residual signal d[0..39] (output of
24 * the short term analysis filter; for simplification the index
25 * of this array begins at 0 and ends at 39 for each sub-segment of the
26 * RPE-LTP analysis) and the previous reconstructed short term
27 * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
28 * performed to avoid overflow.
31 /* The next procedure exists in six versions. First two integer
32 * version (if USE_FLOAT_MUL is not defined); then four floating
33 * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
34 * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
35 * option used). Every pair has first a Cut version (see the -C
36 * option to toast or the LTP_CUT option to gsm_option()), then the
37 * uncut one. (For a detailed explanation of why this is altogether
38 * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
46 static void Cut_Calculation_of_the_LTP_parameters (
48 struct gsm_state * st,
50 register word * d, /* [0..39] IN */
51 register word * dp, /* [-120..-1] IN */
52 word * bc_out, /* OUT */
53 word * Nc_out /* OUT */
56 register int k, lambda;
61 longword L_max, L_power;
62 word R, S, dmax, scal, best_k;
65 register word temp, wt_k;
67 /* Search of the optimum scaling of d[0..39].
70 for (k = 0; k <= 39; k++) {
72 temp = GSM_ABS( temp );
79 if (dmax == 0) scal = 0;
82 temp = gsm_norm( (longword)dmax << 16 );
84 if (temp > 6) scal = 0;
88 /* Search for the maximum cross-correlation and coding of the LTP lag
91 Nc = 40; /* index for the maximum cross-correlation */
92 wt_k = SASR_W(d[best_k], scal);
94 for (lambda = 40; lambda <= 120; lambda++) {
95 L_result = (longword)wt_k * dp[best_k - lambda];
96 if (L_result > L_max) {
104 /* Rescaling of L_max
106 assert(scal <= 100 && scal >= -100);
107 L_max = L_max >> (6 - scal); /* sub(6, scal) */
109 assert( Nc <= 120 && Nc >= 40);
111 /* Compute the power of the reconstructed short term residual
115 for (k = 0; k <= 39; k++) {
117 register longword L_temp;
119 L_temp = SASR_W( dp[k - Nc], 3 );
120 L_power += L_temp * L_temp;
122 L_power <<= 1; /* from L_MULT */
124 /* Normalization of L_max and L_power
131 if (L_max >= L_power) {
136 temp = gsm_norm( L_power );
138 R = SASR( L_max << temp, 16 );
139 S = SASR( L_power << temp, 16 );
141 /* Coding of the LTP gain
144 /* Table 4.3a must be used to obtain the level DLB[i] for the
145 * quantization of the LTP gain b to get the coded version bc.
147 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
153 static void Calculation_of_the_LTP_parameters (
154 register word * d, /* [0..39] IN */
155 register word * dp, /* [-120..-1] IN */
156 word * bc_out, /* OUT */
157 word * Nc_out /* OUT */
160 register int k, lambda;
164 longword L_max, L_power;
165 word R, S, dmax, scal;
168 /* Search of the optimum scaling of d[0..39].
172 for (k = 0; k <= 39; k++) {
174 temp = GSM_ABS( temp );
175 if (temp > dmax) dmax = temp;
179 if (dmax == 0) scal = 0;
182 temp = gsm_norm( (longword)dmax << 16 );
185 if (temp > 6) scal = 0;
186 else scal = 6 - temp;
190 /* Initialization of a working array wt
193 for (k = 0; k <= 39; k++) wt[k] = SASR_W( d[k], scal );
195 /* Search for the maximum cross-correlation and coding of the LTP lag
198 Nc = 40; /* index for the maximum cross-correlation */
200 for (lambda = 40; lambda <= 120; lambda++) {
203 # define STEP(k) (longword)wt[k] * dp[k - lambda]
205 register longword L_result;
207 L_result = STEP(0) ; L_result += STEP(1) ;
208 L_result += STEP(2) ; L_result += STEP(3) ;
209 L_result += STEP(4) ; L_result += STEP(5) ;
210 L_result += STEP(6) ; L_result += STEP(7) ;
211 L_result += STEP(8) ; L_result += STEP(9) ;
212 L_result += STEP(10) ; L_result += STEP(11) ;
213 L_result += STEP(12) ; L_result += STEP(13) ;
214 L_result += STEP(14) ; L_result += STEP(15) ;
215 L_result += STEP(16) ; L_result += STEP(17) ;
216 L_result += STEP(18) ; L_result += STEP(19) ;
217 L_result += STEP(20) ; L_result += STEP(21) ;
218 L_result += STEP(22) ; L_result += STEP(23) ;
219 L_result += STEP(24) ; L_result += STEP(25) ;
220 L_result += STEP(26) ; L_result += STEP(27) ;
221 L_result += STEP(28) ; L_result += STEP(29) ;
222 L_result += STEP(30) ; L_result += STEP(31) ;
223 L_result += STEP(32) ; L_result += STEP(33) ;
224 L_result += STEP(34) ; L_result += STEP(35) ;
225 L_result += STEP(36) ; L_result += STEP(37) ;
226 L_result += STEP(38) ; L_result += STEP(39) ;
228 if (L_result > L_max) {
239 /* Rescaling of L_max
241 assert(scal <= 100 && scal >= -100);
242 L_max = L_max >> (6 - scal); /* sub(6, scal) */
244 assert( Nc <= 120 && Nc >= 40);
246 /* Compute the power of the reconstructed short term residual
250 for (k = 0; k <= 39; k++) {
252 register longword L_temp;
254 L_temp = SASR_W( dp[k - Nc], 3 );
255 L_power += L_temp * L_temp;
257 L_power <<= 1; /* from L_MULT */
259 /* Normalization of L_max and L_power
266 if (L_max >= L_power) {
271 temp = gsm_norm( L_power );
273 R = SASR_L( L_max << temp, 16 );
274 S = SASR_L( L_power << temp, 16 );
276 /* Coding of the LTP gain
279 /* Table 4.3a must be used to obtain the level DLB[i] for the
280 * quantization of the LTP gain b to get the coded version bc.
282 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
286 #else /* USE_FLOAT_MUL */
290 static void Cut_Calculation_of_the_LTP_parameters (
291 struct gsm_state * st, /* IN */
292 register word * d, /* [0..39] IN */
293 register word * dp, /* [-120..-1] IN */
294 word * bc_out, /* OUT */
295 word * Nc_out /* OUT */
298 register int k, lambda;
303 float dp_float_base[120], * dp_float = dp_float_base + 120;
305 longword L_max, L_power;
306 word R, S, dmax, scal;
309 /* Search of the optimum scaling of d[0..39].
313 for (k = 0; k <= 39; k++) {
315 temp = GSM_ABS( temp );
316 if (temp > dmax) dmax = temp;
320 if (dmax == 0) scal = 0;
323 temp = gsm_norm( (longword)dmax << 16 );
326 if (temp > 6) scal = 0;
327 else scal = 6 - temp;
330 ltp_cut = (longword)SASR_W(dmax, scal) * st->ltp_cut / 100;
333 /* Initialization of a working array wt
336 for (k = 0; k < 40; k++) {
337 register word w = SASR_W( d[k], scal );
338 if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
345 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
347 /* Search for the maximum cross-correlation and coding of the LTP lag
350 Nc = 40; /* index for the maximum cross-correlation */
352 for (lambda = 40; lambda <= 120; lambda += 9) {
354 /* Calculate L_result for l = lambda .. lambda + 9.
356 register float *lp = dp_float - lambda;
359 register float a = lp[-8], b = lp[-7], c = lp[-6],
360 d = lp[-5], e = lp[-4], f = lp[-3],
361 g = lp[-2], h = lp[-1];
363 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
364 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
367 # define STEP(K, a, b, c, d, e, f, g, h) \
368 if ((W = wt_float[K]) != 0.0) { \
369 E = W * a; S8 += E; \
370 E = W * b; S7 += E; \
371 E = W * c; S6 += E; \
372 E = W * d; S5 += E; \
373 E = W * e; S4 += E; \
374 E = W * f; S3 += E; \
375 E = W * g; S2 += E; \
376 E = W * h; S1 += E; \
378 E = W * a; S0 += E; } else (a = lp[K])
380 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
381 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
382 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
383 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
384 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
385 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
386 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
387 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
389 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
390 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
392 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
393 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
395 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
396 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
398 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
399 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
401 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
402 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
404 if (S0 > L_max) { L_max = S0; Nc = lambda; }
405 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
406 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
407 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
408 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
409 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
410 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
411 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
412 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
419 /* Rescaling of L_max
421 assert(scal <= 100 && scal >= -100);
422 L_max = L_max >> (6 - scal); /* sub(6, scal) */
424 assert( Nc <= 120 && Nc >= 40);
426 /* Compute the power of the reconstructed short term residual
430 for (k = 0; k <= 39; k++) {
432 register longword L_temp;
434 L_temp = SASR_W( dp[k - Nc], 3 );
435 L_power += L_temp * L_temp;
437 L_power <<= 1; /* from L_MULT */
439 /* Normalization of L_max and L_power
446 if (L_max >= L_power) {
451 temp = gsm_norm( L_power );
453 R = SASR( L_max << temp, 16 );
454 S = SASR( L_power << temp, 16 );
456 /* Coding of the LTP gain
459 /* Table 4.3a must be used to obtain the level DLB[i] for the
460 * quantization of the LTP gain b to get the coded version bc.
462 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
468 static void Calculation_of_the_LTP_parameters (
469 register word * din, /* [0..39] IN */
470 register word * dp, /* [-120..-1] IN */
471 word * bc_out, /* OUT */
472 word * Nc_out /* OUT */
475 register int k, lambda;
479 float dp_float_base[120], * dp_float = dp_float_base + 120;
481 longword L_max, L_power;
482 word R, S, dmax, scal;
485 /* Search of the optimum scaling of d[0..39].
489 for (k = 0; k <= 39; k++) {
491 temp = GSM_ABS (temp) ;
492 if (temp > dmax) dmax = temp;
496 if (dmax == 0) scal = 0;
499 temp = gsm_norm( (longword)dmax << 16 );
502 if (temp > 6) scal = 0;
503 else scal = 6 - temp;
507 /* Initialization of a working array wt
510 for (k = 0; k < 40; k++) wt_float[k] = SASR_W (din [k], scal) ;
511 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
513 /* Search for the maximum cross-correlation and coding of the LTP lag
516 Nc = 40; /* index for the maximum cross-correlation */
518 for (lambda = 40; lambda <= 120; lambda += 9) {
520 /* Calculate L_result for l = lambda .. lambda + 9.
522 register float *lp = dp_float - lambda;
525 register float a = lp[-8], b = lp[-7], c = lp[-6],
526 d = lp[-5], e = lp[-4], f = lp[-3],
527 g = lp[-2], h = lp[-1];
529 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
530 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
533 # define STEP(K, a, b, c, d, e, f, g, h) \
535 E = W * a; S8 += E; \
536 E = W * b; S7 += E; \
537 E = W * c; S6 += E; \
538 E = W * d; S5 += E; \
539 E = W * e; S4 += E; \
540 E = W * f; S3 += E; \
541 E = W * g; S2 += E; \
542 E = W * h; S1 += E; \
546 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
547 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
548 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
549 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
550 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
551 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
552 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
553 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
555 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
556 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
558 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
559 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
561 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
562 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
564 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
565 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
567 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
568 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
570 if (S0 > L_max) { L_max = S0; Nc = lambda; }
571 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
572 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
573 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
574 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
575 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
576 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
577 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
578 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
584 /* Rescaling of L_max
586 assert(scal <= 100 && scal >= -100);
587 L_max = L_max >> (6 - scal); /* sub(6, scal) */
589 assert( Nc <= 120 && Nc >= 40);
591 /* Compute the power of the reconstructed short term residual
595 for (k = 0; k <= 39; k++) {
597 register longword L_temp;
599 L_temp = SASR_W( dp[k - Nc], 3 );
600 L_power += L_temp * L_temp;
602 L_power <<= 1; /* from L_MULT */
604 /* Normalization of L_max and L_power
611 if (L_max >= L_power) {
616 temp = gsm_norm( L_power );
618 R = SASR_L ( L_max << temp, 16 );
619 S = SASR_L ( L_power << temp, 16 );
621 /* Coding of the LTP gain
624 /* Table 4.3a must be used to obtain the level DLB[i] for the
625 * quantization of the LTP gain b to get the coded version bc.
627 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
634 static void Cut_Fast_Calculation_of_the_LTP_parameters (
635 struct gsm_state * st, /* IN */
636 register word * d, /* [0..39] IN */
637 register word * dp, /* [-120..-1] IN */
638 word * bc_out, /* OUT */
639 word * Nc_out /* OUT */
642 register int k, lambda;
643 register float wt_float;
645 word wt_max, best_k, ltp_cut;
647 float dp_float_base[120], * dp_float = dp_float_base + 120;
649 register float L_result, L_max, L_power;
653 for (k = 0; k < 40; ++k) {
654 if ( d[k] > wt_max) wt_max = d[best_k = k];
655 else if (-d[k] > wt_max) wt_max = -d[best_k = k];
659 wt_float = (float)wt_max;
661 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
663 /* Search for the maximum cross-correlation and coding of the LTP lag
666 Nc = 40; /* index for the maximum cross-correlation */
668 for (lambda = 40; lambda <= 120; lambda++) {
669 L_result = wt_float * dp_float[best_k - lambda];
670 if (L_result > L_max) {
682 /* Compute the power of the reconstructed short term residual
687 for (k = 0; k < 40; ++k) {
688 register float f = dp_float[k];
692 if (L_max >= L_power) {
697 /* Coding of the LTP gain
698 * Table 4.3a must be used to obtain the level DLB[i] for the
699 * quantization of the LTP gain b to get the coded version bc.
701 lambda = L_max / L_power * 32768.;
702 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
708 static void Fast_Calculation_of_the_LTP_parameters (
709 register word * din, /* [0..39] IN */
710 register word * dp, /* [-120..-1] IN */
711 word * bc_out, /* OUT */
712 word * Nc_out /* OUT */
715 register int k, lambda;
719 float dp_float_base[120], * dp_float = dp_float_base + 120;
721 register float L_max, L_power;
723 for (k = 0; k < 40; ++k) wt_float[k] = (float) din [k] ;
724 for (k = -120; k < 0; ++k) dp_float[k] = (float) dp [k] ;
726 /* Search for the maximum cross-correlation and coding of the LTP lag
729 Nc = 40; /* index for the maximum cross-correlation */
731 for (lambda = 40; lambda <= 120; lambda += 9) {
733 /* Calculate L_result for l = lambda .. lambda + 9.
735 register float *lp = dp_float - lambda;
738 register float a = lp[-8], b = lp[-7], c = lp[-6],
739 d = lp[-5], e = lp[-4], f = lp[-3],
740 g = lp[-2], h = lp[-1];
742 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
743 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
746 # define STEP(K, a, b, c, d, e, f, g, h) \
748 E = W * a; S8 += E; \
749 E = W * b; S7 += E; \
750 E = W * c; S6 += E; \
751 E = W * d; S5 += E; \
752 E = W * e; S4 += E; \
753 E = W * f; S3 += E; \
754 E = W * g; S2 += E; \
755 E = W * h; S1 += E; \
759 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
760 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
761 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
762 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
763 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
764 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
765 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
766 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
768 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
769 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
771 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
772 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
774 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
775 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
777 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
778 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
780 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
781 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
783 if (S0 > L_max) { L_max = S0; Nc = lambda; }
784 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
785 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
786 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
787 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
788 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
789 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
790 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
791 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
800 /* Compute the power of the reconstructed short term residual
805 for (k = 0; k < 40; ++k) {
806 register float f = dp_float[k];
810 if (L_max >= L_power) {
815 /* Coding of the LTP gain
816 * Table 4.3a must be used to obtain the level DLB[i] for the
817 * quantization of the LTP gain b to get the coded version bc.
819 lambda = L_max / L_power * 32768.;
820 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
825 #endif /* USE_FLOAT_MUL */
830 static void Long_term_analysis_filtering (
833 register word * dp, /* previous d [-120..-1] IN */
834 register word * d, /* d [0..39] IN */
835 register word * dpp, /* estimate [0..39] OUT */
836 register word * e /* long term res. signal [0..39] OUT */
839 * In this part, we have to decode the bc parameter to compute
840 * the samples of the estimate dpp[0..39]. The decoding of bc needs the
841 * use of table 4.3b. The long term residual signal e[0..39]
842 * is then calculated to be fed to the RPE encoding section.
849 for (k = 0; k <= 39; k++) { \
850 dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
851 e[k] = GSM_SUB( d[k], dpp[k] ); \
855 case 0: STEP( 3277 ); break;
856 case 1: STEP( 11469 ); break;
857 case 2: STEP( 21299 ); break;
858 case 3: STEP( 32767 ); break;
862 void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
864 struct gsm_state * S,
866 word * d, /* [0..39] residual signal IN */
867 word * dp, /* [-120..-1] d' IN */
869 word * e, /* [0..39] OUT */
870 word * dpp, /* [0..39] OUT */
871 word * Nc, /* correlation lag OUT */
872 word * bc /* gain factor OUT */
875 assert( d ); assert( dp ); assert( e );
876 assert( dpp); assert( Nc ); assert( bc );
878 #if defined(FAST) && defined(USE_FLOAT_MUL)
880 #if defined (LTP_CUT)
882 Cut_Fast_Calculation_of_the_LTP_parameters(S,
886 Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
888 #endif /* FAST & USE_FLOAT_MUL */
891 Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
894 Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
896 Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
900 void Gsm_Long_Term_Synthesis_Filtering (
901 struct gsm_state * S,
905 register word * erp, /* [0..39] IN */
906 register word * drp /* [-120..-1] IN, [-120..40] OUT */
909 * This procedure uses the bcr and Ncr parameter to realize the
910 * long term synthesis filtering. The decoding of bcr needs
917 /* Check the limits of Nr.
919 Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
921 assert(Nr >= 40 && Nr <= 120);
923 /* Decoding of the LTP gain bcr
925 brp = gsm_QLB[ bcr ];
927 /* Computation of the reconstructed short term residual
930 assert(brp != MIN_WORD);
932 for (k = 0; k <= 39; k++) {
933 drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
934 drp[k] = GSM_ADD( erp[k], drpp );
938 * Update of the reconstructed short term residual signal
942 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
945 ** Do not edit or modify anything in this comment block.
946 ** The arch-tag line is a file identity tag for the GNU Arch
947 ** revision control system.
949 ** arch-tag: b369b90d-0284-42a0-87b0-99a25bbd93ac