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.
18 * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
23 * This module computes the LTP gain (bc) and the LTP lag (Nc)
24 * for the long term analysis filter. This is done by calculating a
25 * maximum of the cross-correlation function between the current
26 * sub-segment short term residual signal d[0..39] (output of
27 * the short term analysis filter; for simplification the index
28 * of this array begins at 0 and ends at 39 for each sub-segment of the
29 * RPE-LTP analysis) and the previous reconstructed short term
30 * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
31 * performed to avoid overflow.
34 /* The next procedure exists in six versions. First two integer
35 * version (if USE_FLOAT_MUL is not defined); then four floating
36 * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
37 * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
38 * option used). Every pair has first a Cut version (see the -C
39 * option to toast or the LTP_CUT option to gsm_option()), then the
40 * uncut one. (For a detailed explanation of why this is altogether
41 * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
49 static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
51 struct gsm_state * st,
53 register word * d, /* [0..39] IN */
54 register word * dp, /* [-120..-1] IN */
55 word * bc_out, /* OUT */
56 word * Nc_out /* OUT */
59 register int k, lambda;
64 longword L_max, L_power;
65 word R, S, dmax, scal, best_k;
68 register word temp, wt_k;
70 /* Search of the optimum scaling of d[0..39].
73 for (k = 0; k <= 39; k++) {
75 temp = GSM_ABS( temp );
82 if (dmax == 0) scal = 0;
85 temp = gsm_norm( (longword)dmax << 16 );
87 if (temp > 6) scal = 0;
91 /* Search for the maximum cross-correlation and coding of the LTP lag
94 Nc = 40; /* index for the maximum cross-correlation */
95 wt_k = SASR(d[best_k], scal);
97 for (lambda = 40; lambda <= 120; lambda++) {
98 L_result = (longword)wt_k * dp[best_k - lambda];
99 if (L_result > L_max) {
107 /* Rescaling of L_max
109 assert(scal <= 100 && scal >= -100);
110 L_max = L_max >> (6 - scal); /* sub(6, scal) */
112 assert( Nc <= 120 && Nc >= 40);
114 /* Compute the power of the reconstructed short term residual
118 for (k = 0; k <= 39; k++) {
120 register longword L_temp;
122 L_temp = SASR( dp[k - Nc], 3 );
123 L_power += L_temp * L_temp;
125 L_power <<= 1; /* from L_MULT */
127 /* Normalization of L_max and L_power
134 if (L_max >= L_power) {
139 temp = gsm_norm( L_power );
141 R = SASR( L_max << temp, 16 );
142 S = SASR( L_power << temp, 16 );
144 /* Coding of the LTP gain
147 /* Table 4.3a must be used to obtain the level DLB[i] for the
148 * quantization of the LTP gain b to get the coded version bc.
150 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
156 static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
157 register word * d, /* [0..39] IN */
158 register word * dp, /* [-120..-1] IN */
159 word * bc_out, /* OUT */
160 word * Nc_out /* OUT */
163 register int k, lambda;
167 longword L_max, L_power;
168 word R, S, dmax, scal;
171 /* Search of the optimum scaling of d[0..39].
175 for (k = 0; k <= 39; k++) {
177 temp = GSM_ABS( temp );
178 if (temp > dmax) dmax = temp;
182 if (dmax == 0) scal = 0;
185 temp = gsm_norm( (longword)dmax << 16 );
188 if (temp > 6) scal = 0;
189 else scal = 6 - temp;
193 /* Initialization of a working array wt
196 for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
198 /* Search for the maximum cross-correlation and coding of the LTP lag
201 Nc = 40; /* index for the maximum cross-correlation */
203 for (lambda = 40; lambda <= 120; lambda++) {
206 # define STEP(k) (longword)wt[k] * dp[k - lambda]
208 register longword L_result;
210 L_result = STEP(0) ; L_result += STEP(1) ;
211 L_result += STEP(2) ; L_result += STEP(3) ;
212 L_result += STEP(4) ; L_result += STEP(5) ;
213 L_result += STEP(6) ; L_result += STEP(7) ;
214 L_result += STEP(8) ; L_result += STEP(9) ;
215 L_result += STEP(10) ; L_result += STEP(11) ;
216 L_result += STEP(12) ; L_result += STEP(13) ;
217 L_result += STEP(14) ; L_result += STEP(15) ;
218 L_result += STEP(16) ; L_result += STEP(17) ;
219 L_result += STEP(18) ; L_result += STEP(19) ;
220 L_result += STEP(20) ; L_result += STEP(21) ;
221 L_result += STEP(22) ; L_result += STEP(23) ;
222 L_result += STEP(24) ; L_result += STEP(25) ;
223 L_result += STEP(26) ; L_result += STEP(27) ;
224 L_result += STEP(28) ; L_result += STEP(29) ;
225 L_result += STEP(30) ; L_result += STEP(31) ;
226 L_result += STEP(32) ; L_result += STEP(33) ;
227 L_result += STEP(34) ; L_result += STEP(35) ;
228 L_result += STEP(36) ; L_result += STEP(37) ;
229 L_result += STEP(38) ; L_result += STEP(39) ;
231 if (L_result > L_max) {
242 /* Rescaling of L_max
244 assert(scal <= 100 && scal >= -100);
245 L_max = L_max >> (6 - scal); /* sub(6, scal) */
247 assert( Nc <= 120 && Nc >= 40);
249 /* Compute the power of the reconstructed short term residual
253 for (k = 0; k <= 39; k++) {
255 register longword L_temp;
257 L_temp = SASR( dp[k - Nc], 3 );
258 L_power += L_temp * L_temp;
260 L_power <<= 1; /* from L_MULT */
262 /* Normalization of L_max and L_power
269 if (L_max >= L_power) {
274 temp = gsm_norm( L_power );
276 R = SASR( L_max << temp, 16 );
277 S = SASR( L_power << temp, 16 );
279 /* Coding of the LTP gain
282 /* Table 4.3a must be used to obtain the level DLB[i] for the
283 * quantization of the LTP gain b to get the coded version bc.
285 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
289 #else /* USE_FLOAT_MUL */
293 static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
294 struct gsm_state * st, /* IN */
295 register word * d, /* [0..39] IN */
296 register word * dp, /* [-120..-1] IN */
297 word * bc_out, /* OUT */
298 word * Nc_out /* OUT */
301 register int k, lambda;
306 float dp_float_base[120], * dp_float = dp_float_base + 120;
308 longword L_max, L_power;
309 word R, S, dmax, scal;
312 /* Search of the optimum scaling of d[0..39].
316 for (k = 0; k <= 39; k++) {
318 temp = GSM_ABS( temp );
319 if (temp > dmax) dmax = temp;
323 if (dmax == 0) scal = 0;
326 temp = gsm_norm( (longword)dmax << 16 );
329 if (temp > 6) scal = 0;
330 else scal = 6 - temp;
333 ltp_cut = (longword)SASR(dmax, scal) * st->ltp_cut / 100;
336 /* Initialization of a working array wt
339 for (k = 0; k < 40; k++) {
340 register word w = SASR( d[k], scal );
341 if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
348 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
350 /* Search for the maximum cross-correlation and coding of the LTP lag
353 Nc = 40; /* index for the maximum cross-correlation */
355 for (lambda = 40; lambda <= 120; lambda += 9) {
357 /* Calculate L_result for l = lambda .. lambda + 9.
359 register float *lp = dp_float - lambda;
362 register float a = lp[-8], b = lp[-7], c = lp[-6],
363 d = lp[-5], e = lp[-4], f = lp[-3],
364 g = lp[-2], h = lp[-1];
366 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
367 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
370 # define STEP(K, a, b, c, d, e, f, g, h) \
371 if ((W = wt_float[K]) != 0.0) { \
372 E = W * a; S8 += E; \
373 E = W * b; S7 += E; \
374 E = W * c; S6 += E; \
375 E = W * d; S5 += E; \
376 E = W * e; S4 += E; \
377 E = W * f; S3 += E; \
378 E = W * g; S2 += E; \
379 E = W * h; S1 += E; \
381 E = W * a; S0 += E; } else (a = lp[K])
383 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
384 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
385 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
386 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
387 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
388 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
389 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
390 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
392 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
393 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
395 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
396 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
398 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
399 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
401 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
402 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
404 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
405 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
407 if (S0 > L_max) { L_max = S0; Nc = lambda; }
408 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
409 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
410 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
411 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
412 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
413 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
414 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
415 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
422 /* Rescaling of L_max
424 assert(scal <= 100 && scal >= -100);
425 L_max = L_max >> (6 - scal); /* sub(6, scal) */
427 assert( Nc <= 120 && Nc >= 40);
429 /* Compute the power of the reconstructed short term residual
433 for (k = 0; k <= 39; k++) {
435 register longword L_temp;
437 L_temp = SASR( dp[k - Nc], 3 );
438 L_power += L_temp * L_temp;
440 L_power <<= 1; /* from L_MULT */
442 /* Normalization of L_max and L_power
449 if (L_max >= L_power) {
454 temp = gsm_norm( L_power );
456 R = SASR( L_max << temp, 16 );
457 S = SASR( L_power << temp, 16 );
459 /* Coding of the LTP gain
462 /* Table 4.3a must be used to obtain the level DLB[i] for the
463 * quantization of the LTP gain b to get the coded version bc.
465 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
471 static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
472 register word * d, /* [0..39] IN */
473 register word * dp, /* [-120..-1] IN */
474 word * bc_out, /* OUT */
475 word * Nc_out /* OUT */
478 register int k, lambda;
482 float dp_float_base[120], * dp_float = dp_float_base + 120;
484 longword L_max, L_power;
485 word R, S, dmax, scal;
488 /* Search of the optimum scaling of d[0..39].
492 for (k = 0; k <= 39; k++) {
494 temp = GSM_ABS( temp );
495 if (temp > dmax) dmax = temp;
499 if (dmax == 0) scal = 0;
502 temp = gsm_norm( (longword)dmax << 16 );
505 if (temp > 6) scal = 0;
506 else scal = 6 - temp;
510 /* Initialization of a working array wt
513 for (k = 0; k < 40; k++) wt_float[k] = SASR( d[k], scal );
514 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
516 /* Search for the maximum cross-correlation and coding of the LTP lag
519 Nc = 40; /* index for the maximum cross-correlation */
521 for (lambda = 40; lambda <= 120; lambda += 9) {
523 /* Calculate L_result for l = lambda .. lambda + 9.
525 register float *lp = dp_float - lambda;
528 register float a = lp[-8], b = lp[-7], c = lp[-6],
529 d = lp[-5], e = lp[-4], f = lp[-3],
530 g = lp[-2], h = lp[-1];
532 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
533 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
536 # define STEP(K, a, b, c, d, e, f, g, h) \
538 E = W * a; S8 += E; \
539 E = W * b; S7 += E; \
540 E = W * c; S6 += E; \
541 E = W * d; S5 += E; \
542 E = W * e; S4 += E; \
543 E = W * f; S3 += E; \
544 E = W * g; S2 += E; \
545 E = W * h; S1 += E; \
549 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
550 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
551 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
552 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
553 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
554 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
555 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
556 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
558 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
559 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
561 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
562 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
564 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
565 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
567 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
568 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
570 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
571 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
573 if (S0 > L_max) { L_max = S0; Nc = lambda; }
574 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
575 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
576 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
577 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
578 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
579 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
580 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
581 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
587 /* Rescaling of L_max
589 assert(scal <= 100 && scal >= -100);
590 L_max = L_max >> (6 - scal); /* sub(6, scal) */
592 assert( Nc <= 120 && Nc >= 40);
594 /* Compute the power of the reconstructed short term residual
598 for (k = 0; k <= 39; k++) {
600 register longword L_temp;
602 L_temp = SASR( dp[k - Nc], 3 );
603 L_power += L_temp * L_temp;
605 L_power <<= 1; /* from L_MULT */
607 /* Normalization of L_max and L_power
614 if (L_max >= L_power) {
619 temp = gsm_norm( L_power );
621 R = SASR( L_max << temp, 16 );
622 S = SASR( L_power << temp, 16 );
624 /* Coding of the LTP gain
627 /* Table 4.3a must be used to obtain the level DLB[i] for the
628 * quantization of the LTP gain b to get the coded version bc.
630 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
637 static void Cut_Fast_Calculation_of_the_LTP_parameters P5((st,
639 struct gsm_state * st, /* IN */
640 register word * d, /* [0..39] IN */
641 register word * dp, /* [-120..-1] IN */
642 word * bc_out, /* OUT */
643 word * Nc_out /* OUT */
646 register int k, lambda;
647 register float wt_float;
649 word wt_max, best_k, ltp_cut;
651 float dp_float_base[120], * dp_float = dp_float_base + 120;
653 register float L_result, L_max, L_power;
657 for (k = 0; k < 40; ++k) {
658 if ( d[k] > wt_max) wt_max = d[best_k = k];
659 else if (-d[k] > wt_max) wt_max = -d[best_k = k];
663 wt_float = (float)wt_max;
665 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
667 /* Search for the maximum cross-correlation and coding of the LTP lag
670 Nc = 40; /* index for the maximum cross-correlation */
672 for (lambda = 40; lambda <= 120; lambda++) {
673 L_result = wt_float * dp_float[best_k - lambda];
674 if (L_result > L_max) {
686 /* Compute the power of the reconstructed short term residual
691 for (k = 0; k < 40; ++k) {
692 register float f = dp_float[k];
696 if (L_max >= L_power) {
701 /* Coding of the LTP gain
702 * Table 4.3a must be used to obtain the level DLB[i] for the
703 * quantization of the LTP gain b to get the coded version bc.
705 lambda = L_max / L_power * 32768.;
706 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
712 static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
713 register word * d, /* [0..39] IN */
714 register word * dp, /* [-120..-1] IN */
715 word * bc_out, /* OUT */
716 word * Nc_out /* OUT */
719 register int k, lambda;
723 float dp_float_base[120], * dp_float = dp_float_base + 120;
725 register float L_max, L_power;
727 for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];
728 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
730 /* Search for the maximum cross-correlation and coding of the LTP lag
733 Nc = 40; /* index for the maximum cross-correlation */
735 for (lambda = 40; lambda <= 120; lambda += 9) {
737 /* Calculate L_result for l = lambda .. lambda + 9.
739 register float *lp = dp_float - lambda;
742 register float a = lp[-8], b = lp[-7], c = lp[-6],
743 d = lp[-5], e = lp[-4], f = lp[-3],
744 g = lp[-2], h = lp[-1];
746 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
747 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
750 # define STEP(K, a, b, c, d, e, f, g, h) \
752 E = W * a; S8 += E; \
753 E = W * b; S7 += E; \
754 E = W * c; S6 += E; \
755 E = W * d; S5 += E; \
756 E = W * e; S4 += E; \
757 E = W * f; S3 += E; \
758 E = W * g; S2 += E; \
759 E = W * h; S1 += E; \
763 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
764 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
765 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
766 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
767 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
768 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
769 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
770 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
772 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
773 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
775 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
776 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
778 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
779 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
781 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
782 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
784 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
785 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
787 if (S0 > L_max) { L_max = S0; Nc = lambda; }
788 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
789 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
790 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
791 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
792 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
793 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
794 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
795 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
804 /* Compute the power of the reconstructed short term residual
809 for (k = 0; k < 40; ++k) {
810 register float f = dp_float[k];
814 if (L_max >= L_power) {
819 /* Coding of the LTP gain
820 * Table 4.3a must be used to obtain the level DLB[i] for the
821 * quantization of the LTP gain b to get the coded version bc.
823 lambda = L_max / L_power * 32768.;
824 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
829 #endif /* USE_FLOAT_MUL */
834 static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e),
837 register word * dp, /* previous d [-120..-1] IN */
838 register word * d, /* d [0..39] IN */
839 register word * dpp, /* estimate [0..39] OUT */
840 register word * e /* long term res. signal [0..39] OUT */
843 * In this part, we have to decode the bc parameter to compute
844 * the samples of the estimate dpp[0..39]. The decoding of bc needs the
845 * use of table 4.3b. The long term residual signal e[0..39]
846 * is then calculated to be fed to the RPE encoding section.
850 register longword ltmp;
854 for (k = 0; k <= 39; k++) { \
855 dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
856 e[k] = GSM_SUB( d[k], dpp[k] ); \
860 case 0: STEP( 3277 ); break;
861 case 1: STEP( 11469 ); break;
862 case 2: STEP( 21299 ); break;
863 case 3: STEP( 32767 ); break;
867 void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc), /* 4x for 160 samples */
869 struct gsm_state * S,
871 word * d, /* [0..39] residual signal IN */
872 word * dp, /* [-120..-1] d' IN */
874 word * e, /* [0..39] OUT */
875 word * dpp, /* [0..39] OUT */
876 word * Nc, /* correlation lag OUT */
877 word * bc /* gain factor OUT */
880 assert( d ); assert( dp ); assert( e );
881 assert( dpp); assert( Nc ); assert( bc );
883 #if defined(FAST) && defined(USE_FLOAT_MUL)
885 #if defined (LTP_CUT)
887 Cut_Fast_Calculation_of_the_LTP_parameters(S,
891 Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
893 #endif /* FAST & USE_FLOAT_MUL */
896 Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
899 Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
901 Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
905 void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp),
906 struct gsm_state * S,
910 register word * erp, /* [0..39] IN */
911 register word * drp /* [-120..-1] IN, [-120..40] OUT */
914 * This procedure uses the bcr and Ncr parameter to realize the
915 * long term synthesis filtering. The decoding of bcr needs
919 register longword ltmp; /* for ADD */
923 /* Check the limits of Nr.
925 Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
927 assert(Nr >= 40 && Nr <= 120);
929 /* Decoding of the LTP gain bcr
931 brp = gsm_QLB[ bcr ];
933 /* Computation of the reconstructed short term residual
936 assert(brp != MIN_WORD);
938 for (k = 0; k <= 39; k++) {
939 drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
940 drp[k] = GSM_ADD( erp[k], drpp );
944 * Update of the reconstructed short term residual signal
948 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];