51static void Cut_Calculation_of_the_LTP_parameters
P5((st,
d,dp,bc_out,Nc_out),
61 register int k, lambda;
70 register word temp, wt_k;
75 for (k = 0; k <= 39; k++) {
84 if (
dmax == 0) scal = 0;
89 if (temp > 6) scal = 0;
97 wt_k =
SASR(
d[best_k], scal);
99 for (lambda = 40; lambda <= 120; lambda++) {
100 L_result = (
longword)wt_k * dp[best_k - lambda];
101 if (L_result > L_max) {
111 assert(scal <= 100 && scal >= -100);
112 L_max = L_max >> (6 - scal);
114 assert( Nc <= 120 && Nc >= 40);
120 for (k = 0; k <= 39; k++) {
124 L_temp =
SASR( dp[k -
Nc], 3 );
125 L_power += L_temp * L_temp;
136 if (L_max >= L_power) {
141 temp = gsm_norm( L_power );
143 R =
SASR( L_max << temp, 16 );
144 S =
SASR( L_power << temp, 16 );
158static void Calculation_of_the_LTP_parameters
P4((
d,dp,bc_out,Nc_out),
180 for (k = 0; k <= 39; k++) {
187 if (
dmax == 0) scal = 0;
193 if (temp > 6) scal = 0;
194 else scal = 6 - temp;
201 for (k = 0; k <= 39; k++) wt[k] =
SASR(
d[k], scal );
206 L_max = k6maxcc(wt,dp,&
Nc);
211 for (lambda = 40; lambda <= 120; lambda++) {
214# define STEP(k) (longword)wt[k] * dp[k - lambda]
218 L_result =
STEP(0) ; L_result +=
STEP(1) ;
219 L_result +=
STEP(2) ; L_result +=
STEP(3) ;
220 L_result +=
STEP(4) ; L_result +=
STEP(5) ;
221 L_result +=
STEP(6) ; L_result +=
STEP(7) ;
222 L_result +=
STEP(8) ; L_result +=
STEP(9) ;
223 L_result +=
STEP(10) ; L_result +=
STEP(11) ;
224 L_result +=
STEP(12) ; L_result +=
STEP(13) ;
225 L_result +=
STEP(14) ; L_result +=
STEP(15) ;
226 L_result +=
STEP(16) ; L_result +=
STEP(17) ;
227 L_result +=
STEP(18) ; L_result +=
STEP(19) ;
228 L_result +=
STEP(20) ; L_result +=
STEP(21) ;
229 L_result +=
STEP(22) ; L_result +=
STEP(23) ;
230 L_result +=
STEP(24) ; L_result +=
STEP(25) ;
231 L_result +=
STEP(26) ; L_result +=
STEP(27) ;
232 L_result +=
STEP(28) ; L_result +=
STEP(29) ;
233 L_result +=
STEP(30) ; L_result +=
STEP(31) ;
234 L_result +=
STEP(32) ; L_result +=
STEP(33) ;
235 L_result +=
STEP(34) ; L_result +=
STEP(35) ;
236 L_result +=
STEP(36) ; L_result +=
STEP(37) ;
237 L_result +=
STEP(38) ; L_result +=
STEP(39) ;
239 if (L_result > L_max) {
252 assert(scal <= 100 && scal >= -100);
253 L_max = L_max >> (6 - scal);
255 assert( Nc <= 120 && Nc >= 40);
261 for (k = 0; k <= 39; k++) {
265 L_temp =
SASR( dp[k -
Nc], 3 );
266 L_power += L_temp * L_temp;
277 if (L_max >= L_power) {
282 temp = gsm_norm( L_power );
284 R = (
word)
SASR( L_max << temp, 16 );
301static void Cut_Calculation_of_the_LTP_parameters
P5((st,
d,dp,bc_out,Nc_out),
309 register int k, lambda;
314 float dp_float_base[120], * dp_float = dp_float_base + 120;
324 for (k = 0; k <= 39; k++) {
331 if (
dmax == 0) scal = 0;
337 if (temp > 6) scal = 0;
338 else scal = 6 - temp;
347 for (k = 0; k < 40; k++) {
349 if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
356 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
363 for (lambda = 40; lambda <= 120; lambda += 9) {
367 register float *lp = dp_float - lambda;
370 register float a = lp[-8],
b = lp[-7],
c = lp[-6],
371 d = lp[-5], e = lp[-4], f = lp[-3],
372 g = lp[-2], h = lp[-1];
374 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
375 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
378# define STEP(K, a, b, c, d, e, f, g, h) \
379 if ((W = wt_float[K]) != 0.0) { \
380 E = W * a; S8 += E; \
381 E = W * b; S7 += E; \
382 E = W * c; S6 += E; \
383 E = W * d; S5 += E; \
384 E = W * e; S4 += E; \
385 E = W * f; S3 += E; \
386 E = W * g; S2 += E; \
387 E = W * h; S1 += E; \
389 E = W * a; S0 += E; } else (a = lp[K])
391# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
392# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
393# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
394# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
395# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
396# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
397# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
398# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
400 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
401 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
403 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
404 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
406 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
407 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
409 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
410 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
412 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
413 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
415 if (S0 > L_max) { L_max = S0;
Nc = lambda; }
416 if (S1 > L_max) { L_max = S1;
Nc = lambda + 1; }
417 if (S2 > L_max) { L_max = S2;
Nc = lambda + 2; }
418 if (S3 > L_max) { L_max = S3;
Nc = lambda + 3; }
419 if (S4 > L_max) { L_max = S4;
Nc = lambda + 4; }
420 if (S5 > L_max) { L_max = S5;
Nc = lambda + 5; }
421 if (S6 > L_max) { L_max = S6;
Nc = lambda + 6; }
422 if (S7 > L_max) { L_max = S7;
Nc = lambda + 7; }
423 if (S8 > L_max) { L_max = S8;
Nc = lambda + 8; }
432 assert(scal <= 100 && scal >= -100);
433 L_max = L_max >> (6 - scal);
435 assert( Nc <= 120 && Nc >= 40);
441 for (k = 0; k <= 39; k++) {
445 L_temp =
SASR( dp[k -
Nc], 3 );
446 L_power += L_temp * L_temp;
457 if (L_max >= L_power) {
462 temp = gsm_norm( L_power );
464 R =
SASR( L_max << temp, 16 );
465 S =
SASR( L_power << temp, 16 );
479static void Calculation_of_the_LTP_parameters
P4((
d,dp,bc_out,Nc_out),
486 register int k, lambda;
490 float dp_float_base[120], * dp_float = dp_float_base + 120;
500 for (k = 0; k <= 39; k++) {
507 if (
dmax == 0) scal = 0;
513 if (temp > 6) scal = 0;
514 else scal = 6 - temp;
521 for (k = 0; k < 40; k++) wt_float[k] =
SASR(
d[k], scal );
522 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
529 for (lambda = 40; lambda <= 120; lambda += 9) {
533 register float *lp = dp_float - lambda;
536 register float a = lp[-8],
b = lp[-7],
c = lp[-6],
537 d = lp[-5], e = lp[-4], f = lp[-3],
538 g = lp[-2], h = lp[-1];
540 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
541 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
544# define STEP(K, a, b, c, d, e, f, g, h) \
546 E = W * a; S8 += E; \
547 E = W * b; S7 += E; \
548 E = W * c; S6 += E; \
549 E = W * d; S5 += E; \
550 E = W * e; S4 += E; \
551 E = W * f; S3 += E; \
552 E = W * g; S2 += E; \
553 E = W * h; S1 += E; \
557# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
558# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
559# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
560# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
561# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
562# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
563# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
564# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
566 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
567 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
569 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
570 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
572 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
573 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
575 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
576 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
578 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
579 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
581 if (S0 > L_max) { L_max = S0;
Nc = lambda; }
582 if (S1 > L_max) { L_max = S1;
Nc = lambda + 1; }
583 if (S2 > L_max) { L_max = S2;
Nc = lambda + 2; }
584 if (S3 > L_max) { L_max = S3;
Nc = lambda + 3; }
585 if (S4 > L_max) { L_max = S4;
Nc = lambda + 4; }
586 if (S5 > L_max) { L_max = S5;
Nc = lambda + 5; }
587 if (S6 > L_max) { L_max = S6;
Nc = lambda + 6; }
588 if (S7 > L_max) { L_max = S7;
Nc = lambda + 7; }
589 if (S8 > L_max) { L_max = S8;
Nc = lambda + 8; }
597 assert(scal <= 100 && scal >= -100);
598 L_max = L_max >> (6 - scal);
600 assert( Nc <= 120 && Nc >= 40);
606 for (k = 0; k <= 39; k++) {
610 L_temp =
SASR( dp[k -
Nc], 3 );
611 L_power += L_temp * L_temp;
622 if (L_max >= L_power) {
627 temp = gsm_norm( L_power );
629 R =
SASR( L_max << temp, 16 );
630 S =
SASR( L_power << temp, 16 );
645static void Cut_Fast_Calculation_of_the_LTP_parameters
P5((st,
654 register int k, lambda;
655 register float wt_float;
657 word wt_max, best_k, ltp_cut;
659 float dp_float_base[120], * dp_float = dp_float_base + 120;
661 register float L_result, L_max, L_power;
665 for (k = 0; k < 40; ++k) {
666 if (
d[k] > wt_max) wt_max =
d[best_k = k];
667 else if (-
d[k] > wt_max) wt_max = -
d[best_k = k];
671 wt_float = (float)wt_max;
673 for (k = -120; k < 0; ++k) dp_float[k] = (
float)dp[k];
680 for (lambda = 40; lambda <= 120; lambda++) {
681 L_result = wt_float * dp_float[best_k - lambda];
682 if (L_result > L_max) {
699 for (k = 0; k < 40; ++k) {
700 register float f = dp_float[k];
704 if (L_max >= L_power) {
713 lambda = L_max / L_power * 32768.;
720static void Fast_Calculation_of_the_LTP_parameters
P4((
d,dp,bc_out,Nc_out),
727 register int k, lambda;
731 float dp_float_base[120], * dp_float = dp_float_base + 120;
733 register float L_max, L_power;
735 for (k = 0; k < 40; ++k) wt_float[k] = (
float)
d[k];
736 for (k = -120; k < 0; ++k) dp_float[k] = (
float)dp[k];
743 for (lambda = 40; lambda <= 120; lambda += 9) {
747 register float *lp = dp_float - lambda;
750 register float a = lp[-8],
b = lp[-7],
c = lp[-6],
751 d = lp[-5], e = lp[-4], f = lp[-3],
752 g = lp[-2], h = lp[-1];
754 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
755 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
758# define STEP(K, a, b, c, d, e, f, g, h) \
760 E = W * a; S8 += E; \
761 E = W * b; S7 += E; \
762 E = W * c; S6 += E; \
763 E = W * d; S5 += E; \
764 E = W * e; S4 += E; \
765 E = W * f; S3 += E; \
766 E = W * g; S2 += E; \
767 E = W * h; S1 += E; \
771# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
772# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
773# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
774# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
775# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
776# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
777# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
778# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
780 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
781 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
783 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
784 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
786 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
787 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
789 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
790 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
792 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
793 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
795 if (S0 > L_max) { L_max = S0;
Nc = lambda; }
796 if (S1 > L_max) { L_max = S1;
Nc = lambda + 1; }
797 if (S2 > L_max) { L_max = S2;
Nc = lambda + 2; }
798 if (S3 > L_max) { L_max = S3;
Nc = lambda + 3; }
799 if (S4 > L_max) { L_max = S4;
Nc = lambda + 4; }
800 if (S5 > L_max) { L_max = S5;
Nc = lambda + 5; }
801 if (S6 > L_max) { L_max = S6;
Nc = lambda + 6; }
802 if (S7 > L_max) { L_max = S7;
Nc = lambda + 7; }
803 if (S8 > L_max) { L_max = S8;
Nc = lambda + 8; }
817 for (k = 0; k < 40; ++k) {
818 register float f = dp_float[k];
822 if (L_max >= L_power) {
831 lambda = L_max / L_power * 32768.;
842static void Long_term_analysis_filtering
P6((
bc,
Nc,dp,
d,dpp,e),
861 for (k = 0; k <= 39; k++) { \
862 dpp[k] = (word)GSM_MULT_R( BP, dp[k - Nc]); \
863 e[k] = GSM_SUB( d[k], dpp[k] ); \
867 case 0:
STEP( 3277 );
break;
868 case 1:
STEP( 11469 );
break;
869 case 2:
STEP( 21299 );
break;
870 case 3:
STEP( 32767 );
break;
874void Gsm_Long_Term_Predictor
P7((
S,
d,dp,e,dpp,
Nc,
bc),
887 assert(
d ); assert( dp ); assert( e );
888 assert( dpp); assert(
Nc ); assert(
bc );
890#if defined(FAST) && defined(USE_FLOAT_MUL)
894 Cut_Fast_Calculation_of_the_LTP_parameters(
S,
898 Fast_Calculation_of_the_LTP_parameters(
d, dp,
bc,
Nc );
903 Cut_Calculation_of_the_LTP_parameters(
S,
d, dp,
bc,
Nc);
906 Calculation_of_the_LTP_parameters(
d, dp,
bc,
Nc);
908 Long_term_analysis_filtering( *
bc, *
Nc, dp,
d, dpp, e );
912void Gsm_Long_Term_Synthesis_Filtering
P5((
S,Ncr,bcr,erp,drp),
931 Nr = Ncr < 40 || Ncr > 120 ?
S->nrp : Ncr;
933 assert(Nr >= 40 && Nr <= 120);
944 for (k = 0; k <= 39; k++) {
946 drp[k] =
GSM_ADD( erp[k], drpp );
954 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
static word GSM_ADD(longword a, longword b)
static void Calculation_of_the_LTP_parameters P4((d, dp, bc_out, Nc_out), register word *d, register word *dp, word *bc_out, word *Nc_out)
void Gsm_Long_Term_Predictor P7((S, d, dp, e, dpp, Nc, bc), struct gsm_state *S, word *d, word *dp, word *e, word *dpp, word *Nc, word *bc)
void Gsm_Long_Term_Synthesis_Filtering P5((S, Ncr, bcr, erp, drp), struct gsm_state *S, word Ncr, word bcr, register word *erp, register word *drp)
static void Long_term_analysis_filtering P6((bc, Nc, dp, d, dpp, e), word bc, word Nc, register word *dp, register word *d, register word *dpp, register word *e)