2 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
10 #include "gsm610_priv.h"
13 * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
18 * This module computes the LTP gain (bc) and the LTP lag (Nc)
19 * for the long term analysis filter. This is done by calculating a
20 * maximum of the cross-correlation function between the current
21 * sub-segment short term residual signal d[0..39] (output of
22 * the short term analysis filter; for simplification the index
23 * of this array begins at 0 and ends at 39 for each sub-segment of the
24 * RPE-LTP analysis) and the previous reconstructed short term
25 * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
26 * performed to avoid overflow.
29 /* The next procedure exists in six versions. First two integer
30 * version (if USE_FLOAT_MUL is not defined); then four floating
31 * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
32 * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
33 * option used). Every pair has first a Cut version (see the -C
34 * option to toast or the LTP_CUT option to gsm_option()), then the
35 * uncut one. (For a detailed explanation of why this is altogether
36 * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
44 static void Cut_Calculation_of_the_LTP_parameters (
46 struct gsm_state * st,
48 register word * d, /* [0..39] IN */
49 register word * dp, /* [-120..-1] IN */
50 word * bc_out, /* OUT */
51 word * Nc_out /* OUT */
54 register int k, lambda;
59 longword L_max, L_power;
60 word R, S, dmax, scal, best_k;
63 register word temp, wt_k;
65 /* Search of the optimum scaling of d[0..39].
68 for (k = 0; k <= 39; k++) {
70 temp = GSM_ABS( temp );
77 if (dmax == 0) scal = 0;
80 temp = gsm_norm( (longword)dmax << 16 );
82 if (temp > 6) scal = 0;
86 /* Search for the maximum cross-correlation and coding of the LTP lag
89 Nc = 40; /* index for the maximum cross-correlation */
90 wt_k = SASR_W(d[best_k], scal);
92 for (lambda = 40; lambda <= 120; lambda++) {
93 L_result = (longword)wt_k * dp[best_k - lambda];
94 if (L_result > L_max) {
102 /* Rescaling of L_max
104 assert(scal <= 100 && scal >= -100);
105 L_max = L_max >> (6 - scal); /* sub(6, scal) */
107 assert( Nc <= 120 && Nc >= 40);
109 /* Compute the power of the reconstructed short term residual
113 for (k = 0; k <= 39; k++) {
115 register longword L_temp;
117 L_temp = SASR_W( dp[k - Nc], 3 );
118 L_power += L_temp * L_temp;
120 L_power <<= 1; /* from L_MULT */
122 /* Normalization of L_max and L_power
129 if (L_max >= L_power) {
134 temp = gsm_norm( L_power );
136 R = SASR( L_max << temp, 16 );
137 S = SASR( L_power << temp, 16 );
139 /* Coding of the LTP gain
142 /* Table 4.3a must be used to obtain the level DLB[i] for the
143 * quantization of the LTP gain b to get the coded version bc.
145 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
151 static void Calculation_of_the_LTP_parameters (
152 register word * d, /* [0..39] IN */
153 register word * dp, /* [-120..-1] IN */
154 word * bc_out, /* OUT */
155 word * Nc_out /* OUT */
158 register int k, lambda;
162 longword L_max, L_power;
163 word R, S, dmax, scal;
166 /* Search of the optimum scaling of d[0..39].
170 for (k = 0; k <= 39; k++) {
172 temp = GSM_ABS( temp );
173 if (temp > dmax) dmax = temp;
177 if (dmax == 0) scal = 0;
180 temp = gsm_norm( (longword)dmax << 16 );
183 if (temp > 6) scal = 0;
184 else scal = 6 - temp;
188 /* Initialization of a working array wt
191 for (k = 0; k <= 39; k++) wt[k] = SASR_W( d[k], scal );
193 /* Search for the maximum cross-correlation and coding of the LTP lag
196 Nc = 40; /* index for the maximum cross-correlation */
198 for (lambda = 40; lambda <= 120; lambda++) {
201 # define STEP(k) (longword)wt[k] * dp[k - lambda]
203 register longword L_result;
205 L_result = STEP(0) ; L_result += STEP(1) ;
206 L_result += STEP(2) ; L_result += STEP(3) ;
207 L_result += STEP(4) ; L_result += STEP(5) ;
208 L_result += STEP(6) ; L_result += STEP(7) ;
209 L_result += STEP(8) ; L_result += STEP(9) ;
210 L_result += STEP(10) ; L_result += STEP(11) ;
211 L_result += STEP(12) ; L_result += STEP(13) ;
212 L_result += STEP(14) ; L_result += STEP(15) ;
213 L_result += STEP(16) ; L_result += STEP(17) ;
214 L_result += STEP(18) ; L_result += STEP(19) ;
215 L_result += STEP(20) ; L_result += STEP(21) ;
216 L_result += STEP(22) ; L_result += STEP(23) ;
217 L_result += STEP(24) ; L_result += STEP(25) ;
218 L_result += STEP(26) ; L_result += STEP(27) ;
219 L_result += STEP(28) ; L_result += STEP(29) ;
220 L_result += STEP(30) ; L_result += STEP(31) ;
221 L_result += STEP(32) ; L_result += STEP(33) ;
222 L_result += STEP(34) ; L_result += STEP(35) ;
223 L_result += STEP(36) ; L_result += STEP(37) ;
224 L_result += STEP(38) ; L_result += STEP(39) ;
226 if (L_result > L_max) {
237 /* Rescaling of L_max
239 assert(scal <= 100 && scal >= -100);
240 L_max = L_max >> (6 - scal); /* sub(6, scal) */
242 assert( Nc <= 120 && Nc >= 40);
244 /* Compute the power of the reconstructed short term residual
248 for (k = 0; k <= 39; k++) {
250 register longword L_temp;
252 L_temp = SASR_W( dp[k - Nc], 3 );
253 L_power += L_temp * L_temp;
255 L_power <<= 1; /* from L_MULT */
257 /* Normalization of L_max and L_power
264 if (L_max >= L_power) {
269 temp = gsm_norm( L_power );
271 R = SASR_L( L_max << temp, 16 );
272 S = SASR_L( L_power << temp, 16 );
274 /* Coding of the LTP gain
277 /* Table 4.3a must be used to obtain the level DLB[i] for the
278 * quantization of the LTP gain b to get the coded version bc.
280 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
284 #else /* USE_FLOAT_MUL */
288 static void Cut_Calculation_of_the_LTP_parameters (
289 struct gsm_state * st, /* IN */
290 register word * d, /* [0..39] IN */
291 register word * dp, /* [-120..-1] IN */
292 word * bc_out, /* OUT */
293 word * Nc_out /* OUT */
296 register int k, lambda;
301 float dp_float_base[120], * dp_float = dp_float_base + 120;
303 longword L_max, L_power;
304 word R, S, dmax, scal;
307 /* Search of the optimum scaling of d[0..39].
311 for (k = 0; k <= 39; k++) {
313 temp = GSM_ABS( temp );
314 if (temp > dmax) dmax = temp;
318 if (dmax == 0) scal = 0;
321 temp = gsm_norm( (longword)dmax << 16 );
324 if (temp > 6) scal = 0;
325 else scal = 6 - temp;
328 ltp_cut = (longword)SASR_W(dmax, scal) * st->ltp_cut / 100;
331 /* Initialization of a working array wt
334 for (k = 0; k < 40; k++) {
335 register word w = SASR_W( d[k], scal );
336 if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
343 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
345 /* Search for the maximum cross-correlation and coding of the LTP lag
348 Nc = 40; /* index for the maximum cross-correlation */
350 for (lambda = 40; lambda <= 120; lambda += 9) {
352 /* Calculate L_result for l = lambda .. lambda + 9.
354 register float *lp = dp_float - lambda;
357 register float a = lp[-8], b = lp[-7], c = lp[-6],
358 d = lp[-5], e = lp[-4], f = lp[-3],
359 g = lp[-2], h = lp[-1];
361 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
362 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
365 # define STEP(K, a, b, c, d, e, f, g, h) \
366 if ((W = wt_float[K]) != 0.0) { \
367 E = W * a; S8 += E; \
368 E = W * b; S7 += E; \
369 E = W * c; S6 += E; \
370 E = W * d; S5 += E; \
371 E = W * e; S4 += E; \
372 E = W * f; S3 += E; \
373 E = W * g; S2 += E; \
374 E = W * h; S1 += E; \
376 E = W * a; S0 += E; } else (a = lp[K])
378 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
379 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
380 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
381 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
382 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
383 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
384 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
385 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
387 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
388 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
390 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
391 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
393 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
394 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
396 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
397 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
399 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
400 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
411 if (S0 > L_max) { L_max = S0; Nc = lambda; }
412 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
413 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
414 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
415 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
416 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
417 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
418 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
419 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
426 /* Rescaling of L_max
428 assert(scal <= 100 && scal >= -100);
429 L_max = L_max >> (6 - scal); /* sub(6, scal) */
431 assert( Nc <= 120 && Nc >= 40);
433 /* Compute the power of the reconstructed short term residual
437 for (k = 0; k <= 39; k++) {
439 register longword L_temp;
441 L_temp = SASR_W( dp[k - Nc], 3 );
442 L_power += L_temp * L_temp;
444 L_power <<= 1; /* from L_MULT */
446 /* Normalization of L_max and L_power
453 if (L_max >= L_power) {
458 temp = gsm_norm( L_power );
460 R = SASR( L_max << temp, 16 );
461 S = SASR( L_power << temp, 16 );
463 /* Coding of the LTP gain
466 /* Table 4.3a must be used to obtain the level DLB[i] for the
467 * quantization of the LTP gain b to get the coded version bc.
469 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
475 static void Calculation_of_the_LTP_parameters (
476 register word * din, /* [0..39] IN */
477 register word * dp, /* [-120..-1] IN */
478 word * bc_out, /* OUT */
479 word * Nc_out /* OUT */
482 register int k, lambda;
486 float dp_float_base[120], * dp_float = dp_float_base + 120;
488 longword L_max, L_power;
489 word R, S, dmax, scal;
492 /* Search of the optimum scaling of d[0..39].
496 for (k = 0; k <= 39; k++) {
498 temp = GSM_ABS (temp) ;
499 if (temp > dmax) dmax = temp;
503 if (dmax == 0) scal = 0;
506 temp = gsm_norm( (longword)dmax << 16 );
509 if (temp > 6) scal = 0;
510 else scal = 6 - temp;
514 /* Initialization of a working array wt
517 for (k = 0; k < 40; k++) wt_float[k] = SASR_W (din [k], scal) ;
518 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
520 /* Search for the maximum cross-correlation and coding of the LTP lag
523 Nc = 40; /* index for the maximum cross-correlation */
525 for (lambda = 40; lambda <= 120; lambda += 9) {
527 /* Calculate L_result for l = lambda .. lambda + 9.
529 register float *lp = dp_float - lambda;
532 register float a = lp[-8], b = lp[-7], c = lp[-6],
533 d = lp[-5], e = lp[-4], f = lp[-3],
534 g = lp[-2], h = lp[-1];
536 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
537 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
540 # define STEP(K, a, b, c, d, e, f, g, h) \
542 E = W * a; S8 += E; \
543 E = W * b; S7 += E; \
544 E = W * c; S6 += E; \
545 E = W * d; S5 += E; \
546 E = W * e; S4 += E; \
547 E = W * f; S3 += E; \
548 E = W * g; S2 += E; \
549 E = W * h; S1 += E; \
553 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
554 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
555 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
556 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
557 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
558 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
559 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
560 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
562 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
563 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
565 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
566 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
568 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
569 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
571 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
572 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
574 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
575 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
586 if (S0 > L_max) { L_max = S0; Nc = lambda; }
587 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
588 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
589 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
590 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
591 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
592 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
593 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
594 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
600 /* Rescaling of L_max
602 assert(scal <= 100 && scal >= -100);
603 L_max = L_max >> (6 - scal); /* sub(6, scal) */
605 assert( Nc <= 120 && Nc >= 40);
607 /* Compute the power of the reconstructed short term residual
611 for (k = 0; k <= 39; k++) {
613 register longword L_temp;
615 L_temp = SASR_W( dp[k - Nc], 3 );
616 L_power += L_temp * L_temp;
618 L_power <<= 1; /* from L_MULT */
620 /* Normalization of L_max and L_power
627 if (L_max >= L_power) {
632 temp = gsm_norm( L_power );
634 R = SASR_L ( L_max << temp, 16 );
635 S = SASR_L ( L_power << temp, 16 );
637 /* Coding of the LTP gain
640 /* Table 4.3a must be used to obtain the level DLB[i] for the
641 * quantization of the LTP gain b to get the coded version bc.
643 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
650 static void Cut_Fast_Calculation_of_the_LTP_parameters (
651 struct gsm_state * st, /* IN */
652 register word * d, /* [0..39] IN */
653 register word * dp, /* [-120..-1] IN */
654 word * bc_out, /* OUT */
655 word * Nc_out /* OUT */
658 register int k, lambda;
659 register float wt_float;
661 word wt_max, best_k, ltp_cut;
663 float dp_float_base[120], * dp_float = dp_float_base + 120;
665 register float L_result, L_max, L_power;
669 for (k = 0; k < 40; ++k) {
670 if ( d[k] > wt_max) wt_max = d[best_k = k];
671 else if (-d[k] > wt_max) wt_max = -d[best_k = k];
675 wt_float = (float)wt_max;
677 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
679 /* Search for the maximum cross-correlation and coding of the LTP lag
682 Nc = 40; /* index for the maximum cross-correlation */
684 for (lambda = 40; lambda <= 120; lambda++) {
685 L_result = wt_float * dp_float[best_k - lambda];
686 if (L_result > L_max) {
698 /* Compute the power of the reconstructed short term residual
703 for (k = 0; k < 40; ++k) {
704 register float f = dp_float[k];
708 if (L_max >= L_power) {
713 /* Coding of the LTP gain
714 * Table 4.3a must be used to obtain the level DLB[i] for the
715 * quantization of the LTP gain b to get the coded version bc.
717 lambda = L_max / L_power * 32768.;
718 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
724 static void Fast_Calculation_of_the_LTP_parameters (
725 register word * din, /* [0..39] IN */
726 register word * dp, /* [-120..-1] IN */
727 word * bc_out, /* OUT */
728 word * Nc_out /* OUT */
731 register int k, lambda;
735 float dp_float_base[120], * dp_float = dp_float_base + 120;
737 register float L_max, L_power;
739 for (k = 0; k < 40; ++k) wt_float[k] = (float) din [k] ;
740 for (k = -120; k < 0; ++k) dp_float[k] = (float) dp [k] ;
742 /* Search for the maximum cross-correlation and coding of the LTP lag
745 Nc = 40; /* index for the maximum cross-correlation */
747 for (lambda = 40; lambda <= 120; lambda += 9) {
749 /* Calculate L_result for l = lambda .. lambda + 9.
751 register float *lp = dp_float - lambda;
754 register float a = lp[-8], b = lp[-7], c = lp[-6],
755 d = lp[-5], e = lp[-4], f = lp[-3],
756 g = lp[-2], h = lp[-1];
758 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
759 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
762 # define STEP(K, a, b, c, d, e, f, g, h) \
764 E = W * a; S8 += E; \
765 E = W * b; S7 += E; \
766 E = W * c; S6 += E; \
767 E = W * d; S5 += E; \
768 E = W * e; S4 += E; \
769 E = W * f; S3 += E; \
770 E = W * g; S2 += E; \
771 E = W * h; S1 += E; \
775 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
776 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
777 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
778 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
779 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
780 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
781 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
782 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
784 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
785 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
787 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
788 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
790 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
791 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
793 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
794 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
796 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
797 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
799 if (S0 > L_max) { L_max = S0; Nc = lambda; }
800 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
801 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
802 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
803 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
804 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
805 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
806 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
807 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
816 /* Compute the power of the reconstructed short term residual
821 for (k = 0; k < 40; ++k) {
822 register float f = dp_float[k];
826 if (L_max >= L_power) {
831 /* Coding of the LTP gain
832 * Table 4.3a must be used to obtain the level DLB[i] for the
833 * quantization of the LTP gain b to get the coded version bc.
835 lambda = L_max / L_power * 32768.;
836 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
841 #endif /* USE_FLOAT_MUL */
846 static void Long_term_analysis_filtering (
849 register word * dp, /* previous d [-120..-1] IN */
850 register word * d, /* d [0..39] IN */
851 register word * dpp, /* estimate [0..39] OUT */
852 register word * e /* long term res. signal [0..39] OUT */
855 * In this part, we have to decode the bc parameter to compute
856 * the samples of the estimate dpp[0..39]. The decoding of bc needs the
857 * use of table 4.3b. The long term residual signal e[0..39]
858 * is then calculated to be fed to the RPE encoding section.
865 for (k = 0; k <= 39; k++) { \
866 dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
867 e[k] = GSM_SUB( d[k], dpp[k] ); \
871 case 0: STEP( 3277 ); break;
872 case 1: STEP( 11469 ); break;
873 case 2: STEP( 21299 ); break;
874 case 3: STEP( 32767 ); break;
878 void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
880 struct gsm_state * S,
882 word * d, /* [0..39] residual signal IN */
883 word * dp, /* [-120..-1] d' IN */
885 word * e, /* [0..39] OUT */
886 word * dpp, /* [0..39] OUT */
887 word * Nc, /* correlation lag OUT */
888 word * bc /* gain factor OUT */
891 assert( d ); assert( dp ); assert( e );
892 assert( dpp); assert( Nc ); assert( bc );
894 #if defined(FAST) && defined(USE_FLOAT_MUL)
896 #if defined (LTP_CUT)
898 Cut_Fast_Calculation_of_the_LTP_parameters(S,
902 Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
904 #endif /* FAST & USE_FLOAT_MUL */
907 Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
910 Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
912 Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
916 void Gsm_Long_Term_Synthesis_Filtering (
917 struct gsm_state * S,
921 register word * erp, /* [0..39] IN */
922 register word * drp /* [-120..-1] IN, [-120..40] OUT */
925 * This procedure uses the bcr and Ncr parameter to realize the
926 * long term synthesis filtering. The decoding of bcr needs
933 /* Check the limits of Nr.
935 Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
937 assert(Nr >= 40 && Nr <= 120);
939 /* Decoding of the LTP gain bcr
941 brp = gsm_QLB[ bcr ];
943 /* Computation of the reconstructed short term residual
946 assert(brp != MIN_WORD);
948 for (k = 0; k <= 39; k++) {
949 drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
950 drp[k] = GSM_ADD( erp[k], drpp );
954 * Update of the reconstructed short term residual signal
958 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];