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.
7 /* $Header: /cvsroot/sox/sox/libgsm/long_term.c,v 1.2 2007/11/04 16:32:36 robs Exp $ */
17 * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
22 * This module computes the LTP gain (bc) and the LTP lag (Nc)
23 * for the long term analysis filter. This is done by calculating a
24 * maximum of the cross-correlation function between the current
25 * sub-segment short term residual signal d[0..39] (output of
26 * the short term analysis filter; for simplification the index
27 * of this array begins at 0 and ends at 39 for each sub-segment of the
28 * RPE-LTP analysis) and the previous reconstructed short term
29 * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
30 * performed to avoid overflow.
33 /* The next procedure exists in six versions. First two integer
34 * version (if USE_FLOAT_MUL is not defined); then four floating
35 * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
36 * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
37 * option used). Every pair has first a Cut version (see the -C
38 * option to toast or the LTP_CUT option to gsm_option()), then the
39 * uncut one. (For a detailed explanation of why this is altogether
40 * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
48 static void Cut_Calculation_of_the_LTP_parameters (
50 struct gsm_state
* st
,
52 register word
* d
, /* [0..39] IN */
53 register word
* dp
, /* [-120..-1] IN */
54 word
* bc_out
, /* OUT */
55 word
* Nc_out
/* OUT */
58 register int k
, lambda
;
63 longword L_max
, L_power
;
64 word R
, S
, dmax
, scal
, best_k
;
67 register word temp
, wt_k
;
69 /* Search of the optimum scaling of d[0..39].
72 for (k
= 0; k
<= 39; k
++) {
74 temp
= GSM_ABS( temp
);
81 if (dmax
== 0) scal
= 0;
84 temp
= gsm_norm( (longword
)dmax
<< 16 );
86 if (temp
> 6) scal
= 0;
90 /* Search for the maximum cross-correlation and coding of the LTP lag
93 Nc
= 40; /* index for the maximum cross-correlation */
94 wt_k
= SASR(d
[best_k
], scal
);
96 for (lambda
= 40; lambda
<= 120; lambda
++) {
97 L_result
= (longword
)wt_k
* dp
[best_k
- lambda
];
98 if (L_result
> L_max
) {
106 /* Rescaling of L_max
108 assert(scal
<= 100 && scal
>= -100);
109 L_max
= L_max
>> (6 - scal
); /* sub(6, scal) */
111 assert( Nc
<= 120 && Nc
>= 40);
113 /* Compute the power of the reconstructed short term residual
117 for (k
= 0; k
<= 39; k
++) {
119 register longword L_temp
;
121 L_temp
= SASR( dp
[k
- Nc
], 3 );
122 L_power
+= L_temp
* L_temp
;
124 L_power
<<= 1; /* from L_MULT */
126 /* Normalization of L_max and L_power
133 if (L_max
>= L_power
) {
138 temp
= gsm_norm( L_power
);
140 R
= SASR( L_max
<< temp
, 16 );
141 S
= SASR( L_power
<< temp
, 16 );
143 /* Coding of the LTP gain
146 /* Table 4.3a must be used to obtain the level DLB[i] for the
147 * quantization of the LTP gain b to get the coded version bc.
149 for (bc
= 0; bc
<= 2; bc
++) if (R
<= gsm_mult(S
, gsm_DLB
[bc
])) break;
155 static void Calculation_of_the_LTP_parameters (
156 register word
* d
, /* [0..39] IN */
157 register word
* dp
, /* [-120..-1] IN */
158 word
* bc_out
, /* OUT */
159 word
* Nc_out
/* OUT */
162 register int k
, lambda
;
166 longword L_max
, L_power
;
167 word R
, S
, dmax
, scal
;
170 /* Search of the optimum scaling of d[0..39].
174 for (k
= 0; k
<= 39; k
++) {
176 temp
= GSM_ABS( temp
);
177 if (temp
> dmax
) dmax
= temp
;
181 if (dmax
== 0) scal
= 0;
184 temp
= gsm_norm( (longword
)dmax
<< 16 );
187 if (temp
> 6) scal
= 0;
188 else scal
= 6 - temp
;
192 /* Initialization of a working array wt
195 for (k
= 0; k
<= 39; k
++) wt
[k
] = SASR( d
[k
], scal
);
197 /* Search for the maximum cross-correlation and coding of the LTP lag
200 Nc
= 40; /* index for the maximum cross-correlation */
202 for (lambda
= 40; lambda
<= 120; lambda
++) {
205 # define STEP(k) (longword)wt[k] * dp[k - lambda]
207 register longword L_result
;
209 L_result
= STEP(0) ; L_result
+= STEP(1) ;
210 L_result
+= STEP(2) ; L_result
+= STEP(3) ;
211 L_result
+= STEP(4) ; L_result
+= STEP(5) ;
212 L_result
+= STEP(6) ; L_result
+= STEP(7) ;
213 L_result
+= STEP(8) ; L_result
+= STEP(9) ;
214 L_result
+= STEP(10) ; L_result
+= STEP(11) ;
215 L_result
+= STEP(12) ; L_result
+= STEP(13) ;
216 L_result
+= STEP(14) ; L_result
+= STEP(15) ;
217 L_result
+= STEP(16) ; L_result
+= STEP(17) ;
218 L_result
+= STEP(18) ; L_result
+= STEP(19) ;
219 L_result
+= STEP(20) ; L_result
+= STEP(21) ;
220 L_result
+= STEP(22) ; L_result
+= STEP(23) ;
221 L_result
+= STEP(24) ; L_result
+= STEP(25) ;
222 L_result
+= STEP(26) ; L_result
+= STEP(27) ;
223 L_result
+= STEP(28) ; L_result
+= STEP(29) ;
224 L_result
+= STEP(30) ; L_result
+= STEP(31) ;
225 L_result
+= STEP(32) ; L_result
+= STEP(33) ;
226 L_result
+= STEP(34) ; L_result
+= STEP(35) ;
227 L_result
+= STEP(36) ; L_result
+= STEP(37) ;
228 L_result
+= STEP(38) ; L_result
+= STEP(39) ;
230 if (L_result
> L_max
) {
241 /* Rescaling of L_max
243 assert(scal
<= 100 && scal
>= -100);
244 L_max
= L_max
>> (6 - scal
); /* sub(6, scal) */
246 assert( Nc
<= 120 && Nc
>= 40);
248 /* Compute the power of the reconstructed short term residual
252 for (k
= 0; k
<= 39; k
++) {
254 register longword L_temp
;
256 L_temp
= SASR( dp
[k
- Nc
], 3 );
257 L_power
+= L_temp
* L_temp
;
259 L_power
<<= 1; /* from L_MULT */
261 /* Normalization of L_max and L_power
268 if (L_max
>= L_power
) {
273 temp
= gsm_norm( L_power
);
275 R
= SASR( L_max
<< temp
, 16 );
276 S
= SASR( L_power
<< temp
, 16 );
278 /* Coding of the LTP gain
281 /* Table 4.3a must be used to obtain the level DLB[i] for the
282 * quantization of the LTP gain b to get the coded version bc.
284 for (bc
= 0; bc
<= 2; bc
++) if (R
<= gsm_mult(S
, gsm_DLB
[bc
])) break;
288 #else /* USE_FLOAT_MUL */
292 static void Cut_Calculation_of_the_LTP_parameters (
293 struct gsm_state
* st
, /* IN */
294 register word
* d
, /* [0..39] IN */
295 register word
* dp
, /* [-120..-1] IN */
296 word
* bc_out
, /* OUT */
297 word
* Nc_out
/* OUT */
300 register int k
, lambda
;
305 float dp_float_base
[120], * dp_float
= dp_float_base
+ 120;
307 longword L_max
, L_power
;
308 word R
, S
, dmax
, scal
;
311 /* Search of the optimum scaling of d[0..39].
315 for (k
= 0; k
<= 39; k
++) {
317 temp
= GSM_ABS( temp
);
318 if (temp
> dmax
) dmax
= temp
;
322 if (dmax
== 0) scal
= 0;
325 temp
= gsm_norm( (longword
)dmax
<< 16 );
328 if (temp
> 6) scal
= 0;
329 else scal
= 6 - temp
;
332 ltp_cut
= (longword
)SASR(dmax
, scal
) * st
->ltp_cut
/ 100;
335 /* Initialization of a working array wt
338 for (k
= 0; k
< 40; k
++) {
339 register word w
= SASR( d
[k
], scal
);
340 if (w
< 0 ? w
> -ltp_cut
: w
< ltp_cut
) {
347 for (k
= -120; k
< 0; k
++) dp_float
[k
] = dp
[k
];
349 /* Search for the maximum cross-correlation and coding of the LTP lag
352 Nc
= 40; /* index for the maximum cross-correlation */
354 for (lambda
= 40; lambda
<= 120; lambda
+= 9) {
356 /* Calculate L_result for l = lambda .. lambda + 9.
358 register float *lp
= dp_float
- lambda
;
361 register float a
= lp
[-8], b
= lp
[-7], c
= lp
[-6],
362 d
= lp
[-5], e
= lp
[-4], f
= lp
[-3],
363 g
= lp
[-2], h
= lp
[-1];
365 register float S0
= 0, S1
= 0, S2
= 0, S3
= 0, S4
= 0,
366 S5
= 0, S6
= 0, S7
= 0, S8
= 0;
369 # define STEP(K, a, b, c, d, e, f, g, h) \
370 if ((W = wt_float[K]) != 0.0) { \
371 E = W * a; S8 += E; \
372 E = W * b; S7 += E; \
373 E = W * c; S6 += E; \
374 E = W * d; S5 += E; \
375 E = W * e; S4 += E; \
376 E = W * f; S3 += E; \
377 E = W * g; S2 += E; \
378 E = W * h; S1 += E; \
380 E = W * a; S0 += E; } else (a = lp[K])
382 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
383 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
384 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
385 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
386 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
387 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
388 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
389 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
391 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
392 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
394 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
395 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
397 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
398 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
400 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
401 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
403 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
404 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
406 if (S0
> L_max
) { L_max
= S0
; Nc
= lambda
; }
407 if (S1
> L_max
) { L_max
= S1
; Nc
= lambda
+ 1; }
408 if (S2
> L_max
) { L_max
= S2
; Nc
= lambda
+ 2; }
409 if (S3
> L_max
) { L_max
= S3
; Nc
= lambda
+ 3; }
410 if (S4
> L_max
) { L_max
= S4
; Nc
= lambda
+ 4; }
411 if (S5
> L_max
) { L_max
= S5
; Nc
= lambda
+ 5; }
412 if (S6
> L_max
) { L_max
= S6
; Nc
= lambda
+ 6; }
413 if (S7
> L_max
) { L_max
= S7
; Nc
= lambda
+ 7; }
414 if (S8
> L_max
) { L_max
= S8
; Nc
= lambda
+ 8; }
421 /* Rescaling of L_max
423 assert(scal
<= 100 && scal
>= -100);
424 L_max
= L_max
>> (6 - scal
); /* sub(6, scal) */
426 assert( Nc
<= 120 && Nc
>= 40);
428 /* Compute the power of the reconstructed short term residual
432 for (k
= 0; k
<= 39; k
++) {
434 register longword L_temp
;
436 L_temp
= SASR( dp
[k
- Nc
], 3 );
437 L_power
+= L_temp
* L_temp
;
439 L_power
<<= 1; /* from L_MULT */
441 /* Normalization of L_max and L_power
448 if (L_max
>= L_power
) {
453 temp
= gsm_norm( L_power
);
455 R
= SASR( L_max
<< temp
, 16 );
456 S
= SASR( L_power
<< temp
, 16 );
458 /* Coding of the LTP gain
461 /* Table 4.3a must be used to obtain the level DLB[i] for the
462 * quantization of the LTP gain b to get the coded version bc.
464 for (bc
= 0; bc
<= 2; bc
++) if (R
<= gsm_mult(S
, gsm_DLB
[bc
])) break;
470 static void Calculation_of_the_LTP_parameters (
471 register word
* d
, /* [0..39] IN */
472 register word
* dp
, /* [-120..-1] IN */
473 word
* bc_out
, /* OUT */
474 word
* Nc_out
/* OUT */
477 register int k
, lambda
;
481 float dp_float_base
[120], * dp_float
= dp_float_base
+ 120;
483 longword L_max
, L_power
;
484 word R
, S
, dmax
, scal
;
487 /* Search of the optimum scaling of d[0..39].
491 for (k
= 0; k
<= 39; k
++) {
493 temp
= GSM_ABS( temp
);
494 if (temp
> dmax
) dmax
= temp
;
498 if (dmax
== 0) scal
= 0;
501 temp
= gsm_norm( (longword
)dmax
<< 16 );
504 if (temp
> 6) scal
= 0;
505 else scal
= 6 - temp
;
509 /* Initialization of a working array wt
512 for (k
= 0; k
< 40; k
++) wt_float
[k
] = SASR( d
[k
], scal
);
513 for (k
= -120; k
< 0; k
++) dp_float
[k
] = dp
[k
];
515 /* Search for the maximum cross-correlation and coding of the LTP lag
518 Nc
= 40; /* index for the maximum cross-correlation */
520 for (lambda
= 40; lambda
<= 120; lambda
+= 9) {
522 /* Calculate L_result for l = lambda .. lambda + 9.
524 register float *lp
= dp_float
- lambda
;
527 register float a
= lp
[-8], b
= lp
[-7], c
= lp
[-6],
528 d
= lp
[-5], e
= lp
[-4], f
= lp
[-3],
529 g
= lp
[-2], h
= lp
[-1];
531 register float S0
= 0, S1
= 0, S2
= 0, S3
= 0, S4
= 0,
532 S5
= 0, S6
= 0, S7
= 0, S8
= 0;
535 # define STEP(K, a, b, c, d, e, f, g, h) \
537 E = W * a; S8 += E; \
538 E = W * b; S7 += E; \
539 E = W * c; S6 += E; \
540 E = W * d; S5 += E; \
541 E = W * e; S4 += E; \
542 E = W * f; S3 += E; \
543 E = W * g; S2 += E; \
544 E = W * h; S1 += E; \
548 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
549 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
550 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
551 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
552 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
553 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
554 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
555 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
557 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
558 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
560 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
561 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
563 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
564 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
566 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
567 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
569 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
570 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
572 if (S0
> L_max
) { L_max
= S0
; Nc
= lambda
; }
573 if (S1
> L_max
) { L_max
= S1
; Nc
= lambda
+ 1; }
574 if (S2
> L_max
) { L_max
= S2
; Nc
= lambda
+ 2; }
575 if (S3
> L_max
) { L_max
= S3
; Nc
= lambda
+ 3; }
576 if (S4
> L_max
) { L_max
= S4
; Nc
= lambda
+ 4; }
577 if (S5
> L_max
) { L_max
= S5
; Nc
= lambda
+ 5; }
578 if (S6
> L_max
) { L_max
= S6
; Nc
= lambda
+ 6; }
579 if (S7
> L_max
) { L_max
= S7
; Nc
= lambda
+ 7; }
580 if (S8
> L_max
) { L_max
= S8
; Nc
= lambda
+ 8; }
586 /* Rescaling of L_max
588 assert(scal
<= 100 && scal
>= -100);
589 L_max
= L_max
>> (6 - scal
); /* sub(6, scal) */
591 assert( Nc
<= 120 && Nc
>= 40);
593 /* Compute the power of the reconstructed short term residual
597 for (k
= 0; k
<= 39; k
++) {
599 register longword L_temp
;
601 L_temp
= SASR( dp
[k
- Nc
], 3 );
602 L_power
+= L_temp
* L_temp
;
604 L_power
<<= 1; /* from L_MULT */
606 /* Normalization of L_max and L_power
613 if (L_max
>= L_power
) {
618 temp
= gsm_norm( L_power
);
620 R
= SASR( L_max
<< temp
, 16 );
621 S
= SASR( L_power
<< temp
, 16 );
623 /* Coding of the LTP gain
626 /* Table 4.3a must be used to obtain the level DLB[i] for the
627 * quantization of the LTP gain b to get the coded version bc.
629 for (bc
= 0; bc
<= 2; bc
++) if (R
<= gsm_mult(S
, gsm_DLB
[bc
])) break;
636 static void Cut_Fast_Calculation_of_the_LTP_parameters (
637 struct gsm_state
* st
, /* IN */
638 register word
* d
, /* [0..39] IN */
639 register word
* dp
, /* [-120..-1] IN */
640 word
* bc_out
, /* OUT */
641 word
* Nc_out
/* OUT */
644 register int k
, lambda
;
645 register float wt_float
;
647 word wt_max
, best_k
, ltp_cut
;
649 float dp_float_base
[120], * dp_float
= dp_float_base
+ 120;
651 register float L_result
, L_max
, L_power
;
655 for (k
= 0; k
< 40; ++k
) {
656 if ( d
[k
] > wt_max
) wt_max
= d
[best_k
= k
];
657 else if (-d
[k
] > wt_max
) wt_max
= -d
[best_k
= k
];
661 wt_float
= (float)wt_max
;
663 for (k
= -120; k
< 0; ++k
) dp_float
[k
] = (float)dp
[k
];
665 /* Search for the maximum cross-correlation and coding of the LTP lag
668 Nc
= 40; /* index for the maximum cross-correlation */
670 for (lambda
= 40; lambda
<= 120; lambda
++) {
671 L_result
= wt_float
* dp_float
[best_k
- lambda
];
672 if (L_result
> L_max
) {
684 /* Compute the power of the reconstructed short term residual
689 for (k
= 0; k
< 40; ++k
) {
690 register float f
= dp_float
[k
];
694 if (L_max
>= L_power
) {
699 /* Coding of the LTP gain
700 * Table 4.3a must be used to obtain the level DLB[i] for the
701 * quantization of the LTP gain b to get the coded version bc.
703 lambda
= L_max
/ L_power
* 32768.;
704 for (bc
= 0; bc
<= 2; ++bc
) if (lambda
<= gsm_DLB
[bc
]) break;
710 static void Fast_Calculation_of_the_LTP_parameters (
711 register word
* d
, /* [0..39] IN */
712 register word
* dp
, /* [-120..-1] IN */
713 word
* bc_out
, /* OUT */
714 word
* Nc_out
/* OUT */
717 register int k
, lambda
;
721 float dp_float_base
[120], * dp_float
= dp_float_base
+ 120;
723 register float L_max
, L_power
;
725 for (k
= 0; k
< 40; ++k
) wt_float
[k
] = (float)d
[k
];
726 for (k
= -120; k
< 0; ++k
) dp_float
[k
] = (float)dp
[k
];
728 /* Search for the maximum cross-correlation and coding of the LTP lag
731 Nc
= 40; /* index for the maximum cross-correlation */
733 for (lambda
= 40; lambda
<= 120; lambda
+= 9) {
735 /* Calculate L_result for l = lambda .. lambda + 9.
737 register float *lp
= dp_float
- lambda
;
740 register float a
= lp
[-8], b
= lp
[-7], c
= lp
[-6],
741 d
= lp
[-5], e
= lp
[-4], f
= lp
[-3],
742 g
= lp
[-2], h
= lp
[-1];
744 register float S0
= 0, S1
= 0, S2
= 0, S3
= 0, S4
= 0,
745 S5
= 0, S6
= 0, S7
= 0, S8
= 0;
748 # define STEP(K, a, b, c, d, e, f, g, h) \
750 E = W * a; S8 += E; \
751 E = W * b; S7 += E; \
752 E = W * c; S6 += E; \
753 E = W * d; S5 += E; \
754 E = W * e; S4 += E; \
755 E = W * f; S3 += E; \
756 E = W * g; S2 += E; \
757 E = W * h; S1 += E; \
761 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
762 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
763 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
764 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
765 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
766 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
767 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
768 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
770 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
771 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
773 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
774 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
776 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
777 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
779 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
780 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
782 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
783 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
785 if (S0
> L_max
) { L_max
= S0
; Nc
= lambda
; }
786 if (S1
> L_max
) { L_max
= S1
; Nc
= lambda
+ 1; }
787 if (S2
> L_max
) { L_max
= S2
; Nc
= lambda
+ 2; }
788 if (S3
> L_max
) { L_max
= S3
; Nc
= lambda
+ 3; }
789 if (S4
> L_max
) { L_max
= S4
; Nc
= lambda
+ 4; }
790 if (S5
> L_max
) { L_max
= S5
; Nc
= lambda
+ 5; }
791 if (S6
> L_max
) { L_max
= S6
; Nc
= lambda
+ 6; }
792 if (S7
> L_max
) { L_max
= S7
; Nc
= lambda
+ 7; }
793 if (S8
> L_max
) { L_max
= S8
; Nc
= lambda
+ 8; }
802 /* Compute the power of the reconstructed short term residual
807 for (k
= 0; k
< 40; ++k
) {
808 register float f
= dp_float
[k
];
812 if (L_max
>= L_power
) {
817 /* Coding of the LTP gain
818 * Table 4.3a must be used to obtain the level DLB[i] for the
819 * quantization of the LTP gain b to get the coded version bc.
821 lambda
= L_max
/ L_power
* 32768.;
822 for (bc
= 0; bc
<= 2; ++bc
) if (lambda
<= gsm_DLB
[bc
]) break;
827 #endif /* USE_FLOAT_MUL */
832 static void Long_term_analysis_filtering (
835 register word
* dp
, /* previous d [-120..-1] IN */
836 register word
* d
, /* d [0..39] IN */
837 register word
* dpp
, /* estimate [0..39] OUT */
838 register word
* e
/* long term res. signal [0..39] OUT */
841 * In this part, we have to decode the bc parameter to compute
842 * the samples of the estimate dpp[0..39]. The decoding of bc needs the
843 * use of table 4.3b. The long term residual signal e[0..39]
844 * is then calculated to be fed to the RPE encoding section.
848 register longword ltmp
;
852 for (k = 0; k <= 39; k++) { \
853 dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
854 e[k] = GSM_SUB( d[k], dpp[k] ); \
858 case 0: STEP( 3277 ); break;
859 case 1: STEP( 11469 ); break;
860 case 2: STEP( 21299 ); break;
861 case 3: STEP( 32767 ); break;
865 void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
867 struct gsm_state
* S
,
869 word
* d
, /* [0..39] residual signal IN */
870 word
* dp
, /* [-120..-1] d' IN */
872 word
* e
, /* [0..39] OUT */
873 word
* dpp
, /* [0..39] OUT */
874 word
* Nc
, /* correlation lag OUT */
875 word
* bc
/* gain factor OUT */
878 (void)S
; /* Denotes intentionally unused */
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 (
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
];