00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdio.h>
00010 #include <assert.h>
00011
00012 #include "private.h"
00013
00014 #include "gsm.h"
00015 #include "proto.h"
00016 #ifdef K6OPT
00017 #include "k6opt.h"
00018 #endif
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef USE_FLOAT_MUL
00048
00049 #ifdef LTP_CUT
00050
00051 static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
00052
00053 struct gsm_state * st,
00054
00055 register word * d,
00056 register word * dp,
00057 word * bc_out,
00058 word * Nc_out
00059 )
00060 {
00061 register int k, lambda;
00062 word Nc, bc;
00063 word wt[40];
00064
00065 longword L_result;
00066 longword L_max, L_power;
00067 word R, S, dmax, scal, best_k;
00068 word ltp_cut;
00069
00070 register word temp, wt_k;
00071
00072
00073
00074 dmax = 0;
00075 for (k = 0; k <= 39; k++) {
00076 temp = d[k];
00077 temp = GSM_ABS( temp );
00078 if (temp > dmax) {
00079 dmax = temp;
00080 best_k = k;
00081 }
00082 }
00083 temp = 0;
00084 if (dmax == 0) scal = 0;
00085 else {
00086 assert(dmax > 0);
00087 temp = gsm_norm( (longword)dmax << 16 );
00088 }
00089 if (temp > 6) scal = 0;
00090 else scal = 6 - temp;
00091 assert(scal >= 0);
00092
00093
00094
00095 L_max = 0;
00096 Nc = 40;
00097 wt_k = SASR(d[best_k], scal);
00098
00099 for (lambda = 40; lambda <= 120; lambda++) {
00100 L_result = (longword)wt_k * dp[best_k - lambda];
00101 if (L_result > L_max) {
00102 Nc = lambda;
00103 L_max = L_result;
00104 }
00105 }
00106 *Nc_out = Nc;
00107 L_max <<= 1;
00108
00109
00110
00111 assert(scal <= 100 && scal >= -100);
00112 L_max = L_max >> (6 - scal);
00113
00114 assert( Nc <= 120 && Nc >= 40);
00115
00116
00117
00118
00119 L_power = 0;
00120 for (k = 0; k <= 39; k++) {
00121
00122 register longword L_temp;
00123
00124 L_temp = SASR( dp[k - Nc], 3 );
00125 L_power += L_temp * L_temp;
00126 }
00127 L_power <<= 1;
00128
00129
00130
00131
00132 if (L_max <= 0) {
00133 *bc_out = 0;
00134 return;
00135 }
00136 if (L_max >= L_power) {
00137 *bc_out = 3;
00138 return;
00139 }
00140
00141 temp = gsm_norm( L_power );
00142
00143 R = SASR( L_max << temp, 16 );
00144 S = SASR( L_power << temp, 16 );
00145
00146
00147
00148
00149
00150
00151
00152 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
00153 *bc_out = bc;
00154 }
00155
00156 #endif
00157
00158 static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
00159 register word * d,
00160 register word * dp,
00161 word * bc_out,
00162 word * Nc_out
00163 )
00164 {
00165 register int k, lambda;
00166 word Nc, bc;
00167 word wt[40];
00168
00169 longword L_max, L_power;
00170 word R, S, dmax, scal;
00171 register word temp;
00172
00173
00174
00175 dmax = 0;
00176
00177 for (k = 0; k <= 39; k++) {
00178 temp = d[k];
00179 temp = GSM_ABS( temp );
00180 if (temp > dmax) dmax = temp;
00181 }
00182
00183 temp = 0;
00184 if (dmax == 0) scal = 0;
00185 else {
00186 assert(dmax > 0);
00187 temp = gsm_norm( (longword)dmax << 16 );
00188 }
00189
00190 if (temp > 6) scal = 0;
00191 else scal = 6 - temp;
00192
00193 assert(scal >= 0);
00194
00195
00196
00197
00198 for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
00199
00200
00201
00202 # ifdef K6OPT
00203 L_max = k6maxcc(wt,dp,&Nc);
00204 # else
00205 L_max = 0;
00206 Nc = 40;
00207
00208 for (lambda = 40; lambda <= 120; lambda++) {
00209
00210 # undef STEP
00211 # define STEP(k) (longword)wt[k] * dp[k - lambda]
00212
00213 register longword L_result;
00214
00215 L_result = STEP(0) ; L_result += STEP(1) ;
00216 L_result += STEP(2) ; L_result += STEP(3) ;
00217 L_result += STEP(4) ; L_result += STEP(5) ;
00218 L_result += STEP(6) ; L_result += STEP(7) ;
00219 L_result += STEP(8) ; L_result += STEP(9) ;
00220 L_result += STEP(10) ; L_result += STEP(11) ;
00221 L_result += STEP(12) ; L_result += STEP(13) ;
00222 L_result += STEP(14) ; L_result += STEP(15) ;
00223 L_result += STEP(16) ; L_result += STEP(17) ;
00224 L_result += STEP(18) ; L_result += STEP(19) ;
00225 L_result += STEP(20) ; L_result += STEP(21) ;
00226 L_result += STEP(22) ; L_result += STEP(23) ;
00227 L_result += STEP(24) ; L_result += STEP(25) ;
00228 L_result += STEP(26) ; L_result += STEP(27) ;
00229 L_result += STEP(28) ; L_result += STEP(29) ;
00230 L_result += STEP(30) ; L_result += STEP(31) ;
00231 L_result += STEP(32) ; L_result += STEP(33) ;
00232 L_result += STEP(34) ; L_result += STEP(35) ;
00233 L_result += STEP(36) ; L_result += STEP(37) ;
00234 L_result += STEP(38) ; L_result += STEP(39) ;
00235
00236 if (L_result > L_max) {
00237
00238 Nc = lambda;
00239 L_max = L_result;
00240 }
00241 }
00242 # endif
00243 *Nc_out = Nc;
00244
00245 L_max <<= 1;
00246
00247
00248
00249 assert(scal <= 100 && scal >= -100);
00250 L_max = L_max >> (6 - scal);
00251
00252 assert( Nc <= 120 && Nc >= 40);
00253
00254
00255
00256
00257 L_power = 0;
00258 for (k = 0; k <= 39; k++) {
00259
00260 register longword L_temp;
00261
00262 L_temp = SASR( dp[k - Nc], 3 );
00263 L_power += L_temp * L_temp;
00264 }
00265 L_power <<= 1;
00266
00267
00268
00269
00270 if (L_max <= 0) {
00271 *bc_out = 0;
00272 return;
00273 }
00274 if (L_max >= L_power) {
00275 *bc_out = 3;
00276 return;
00277 }
00278
00279 temp = gsm_norm( L_power );
00280
00281 R = SASR( L_max << temp, 16 );
00282 S = SASR( L_power << temp, 16 );
00283
00284
00285
00286
00287
00288
00289
00290 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
00291 *bc_out = bc;
00292 }
00293
00294 #else
00295
00296 #ifdef LTP_CUT
00297
00298 static void Cut_Calculation_of_the_LTP_parameters P5((st, d,dp,bc_out,Nc_out),
00299 struct gsm_state * st,
00300 register word * d,
00301 register word * dp,
00302 word * bc_out,
00303 word * Nc_out
00304 )
00305 {
00306 register int k, lambda;
00307 word Nc, bc;
00308 word ltp_cut;
00309
00310 float wt_float[40];
00311 float dp_float_base[120], * dp_float = dp_float_base + 120;
00312
00313 longword L_max, L_power;
00314 word R, S, dmax, scal;
00315 register word temp;
00316
00317
00318
00319 dmax = 0;
00320
00321 for (k = 0; k <= 39; k++) {
00322 temp = d[k];
00323 temp = GSM_ABS( temp );
00324 if (temp > dmax) dmax = temp;
00325 }
00326
00327 temp = 0;
00328 if (dmax == 0) scal = 0;
00329 else {
00330 assert(dmax > 0);
00331 temp = gsm_norm( (longword)dmax << 16 );
00332 }
00333
00334 if (temp > 6) scal = 0;
00335 else scal = 6 - temp;
00336
00337 assert(scal >= 0);
00338 ltp_cut = (longword)SASR(dmax, scal) * st->ltp_cut / 100;
00339
00340
00341
00342
00343
00344 for (k = 0; k < 40; k++) {
00345 register word w = SASR( d[k], scal );
00346 if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
00347 wt_float[k] = 0.0;
00348 }
00349 else {
00350 wt_float[k] = w;
00351 }
00352 }
00353 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
00354
00355
00356
00357 L_max = 0;
00358 Nc = 40;
00359
00360 for (lambda = 40; lambda <= 120; lambda += 9) {
00361
00362
00363
00364 register float *lp = dp_float - lambda;
00365
00366 register float W;
00367 register float a = lp[-8], b = lp[-7], c = lp[-6],
00368 d = lp[-5], e = lp[-4], f = lp[-3],
00369 g = lp[-2], h = lp[-1];
00370 register float E;
00371 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
00372 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
00373
00374 # undef STEP
00375 # define STEP(K, a, b, c, d, e, f, g, h) \
00376 if ((W = wt_float[K]) != 0.0) { \
00377 E = W * a; S8 += E; \
00378 E = W * b; S7 += E; \
00379 E = W * c; S6 += E; \
00380 E = W * d; S5 += E; \
00381 E = W * e; S4 += E; \
00382 E = W * f; S3 += E; \
00383 E = W * g; S2 += E; \
00384 E = W * h; S1 += E; \
00385 a = lp[K]; \
00386 E = W * a; S0 += E; } else (a = lp[K])
00387
00388 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
00389 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
00390 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
00391 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
00392 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
00393 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
00394 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
00395 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
00396
00397 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
00398 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
00399
00400 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
00401 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
00402
00403 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
00404 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
00405
00406 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
00407 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
00408
00409 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
00410 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
00411
00412 if (S0 > L_max) { L_max = S0; Nc = lambda; }
00413 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
00414 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
00415 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
00416 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
00417 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
00418 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
00419 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
00420 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
00421
00422 }
00423 *Nc_out = Nc;
00424
00425 L_max <<= 1;
00426
00427
00428
00429 assert(scal <= 100 && scal >= -100);
00430 L_max = L_max >> (6 - scal);
00431
00432 assert( Nc <= 120 && Nc >= 40);
00433
00434
00435
00436
00437 L_power = 0;
00438 for (k = 0; k <= 39; k++) {
00439
00440 register longword L_temp;
00441
00442 L_temp = SASR( dp[k - Nc], 3 );
00443 L_power += L_temp * L_temp;
00444 }
00445 L_power <<= 1;
00446
00447
00448
00449
00450 if (L_max <= 0) {
00451 *bc_out = 0;
00452 return;
00453 }
00454 if (L_max >= L_power) {
00455 *bc_out = 3;
00456 return;
00457 }
00458
00459 temp = gsm_norm( L_power );
00460
00461 R = SASR( L_max << temp, 16 );
00462 S = SASR( L_power << temp, 16 );
00463
00464
00465
00466
00467
00468
00469
00470 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
00471 *bc_out = bc;
00472 }
00473
00474 #endif
00475
00476 static void Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
00477 register word * d,
00478 register word * dp,
00479 word * bc_out,
00480 word * Nc_out
00481 )
00482 {
00483 register int k, lambda;
00484 word Nc, bc;
00485
00486 float wt_float[40];
00487 float dp_float_base[120], * dp_float = dp_float_base + 120;
00488
00489 longword L_max, L_power;
00490 word R, S, dmax, scal;
00491 register word temp;
00492
00493
00494
00495 dmax = 0;
00496
00497 for (k = 0; k <= 39; k++) {
00498 temp = d[k];
00499 temp = GSM_ABS( temp );
00500 if (temp > dmax) dmax = temp;
00501 }
00502
00503 temp = 0;
00504 if (dmax == 0) scal = 0;
00505 else {
00506 assert(dmax > 0);
00507 temp = gsm_norm( (longword)dmax << 16 );
00508 }
00509
00510 if (temp > 6) scal = 0;
00511 else scal = 6 - temp;
00512
00513 assert(scal >= 0);
00514
00515
00516
00517
00518 for (k = 0; k < 40; k++) wt_float[k] = SASR( d[k], scal );
00519 for (k = -120; k < 0; k++) dp_float[k] = dp[k];
00520
00521
00522
00523 L_max = 0;
00524 Nc = 40;
00525
00526 for (lambda = 40; lambda <= 120; lambda += 9) {
00527
00528
00529
00530 register float *lp = dp_float - lambda;
00531
00532 register float W;
00533 register float a = lp[-8], b = lp[-7], c = lp[-6],
00534 d = lp[-5], e = lp[-4], f = lp[-3],
00535 g = lp[-2], h = lp[-1];
00536 register float E;
00537 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
00538 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
00539
00540 # undef STEP
00541 # define STEP(K, a, b, c, d, e, f, g, h) \
00542 W = wt_float[K]; \
00543 E = W * a; S8 += E; \
00544 E = W * b; S7 += E; \
00545 E = W * c; S6 += E; \
00546 E = W * d; S5 += E; \
00547 E = W * e; S4 += E; \
00548 E = W * f; S3 += E; \
00549 E = W * g; S2 += E; \
00550 E = W * h; S1 += E; \
00551 a = lp[K]; \
00552 E = W * a; S0 += E
00553
00554 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
00555 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
00556 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
00557 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
00558 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
00559 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
00560 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
00561 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
00562
00563 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
00564 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
00565
00566 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
00567 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
00568
00569 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
00570 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
00571
00572 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
00573 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
00574
00575 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
00576 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
00577
00578 if (S0 > L_max) { L_max = S0; Nc = lambda; }
00579 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
00580 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
00581 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
00582 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
00583 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
00584 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
00585 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
00586 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
00587 }
00588 *Nc_out = Nc;
00589
00590 L_max <<= 1;
00591
00592
00593
00594 assert(scal <= 100 && scal >= -100);
00595 L_max = L_max >> (6 - scal);
00596
00597 assert( Nc <= 120 && Nc >= 40);
00598
00599
00600
00601
00602 L_power = 0;
00603 for (k = 0; k <= 39; k++) {
00604
00605 register longword L_temp;
00606
00607 L_temp = SASR( dp[k - Nc], 3 );
00608 L_power += L_temp * L_temp;
00609 }
00610 L_power <<= 1;
00611
00612
00613
00614
00615 if (L_max <= 0) {
00616 *bc_out = 0;
00617 return;
00618 }
00619 if (L_max >= L_power) {
00620 *bc_out = 3;
00621 return;
00622 }
00623
00624 temp = gsm_norm( L_power );
00625
00626 R = SASR( L_max << temp, 16 );
00627 S = SASR( L_power << temp, 16 );
00628
00629
00630
00631
00632
00633
00634
00635 for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
00636 *bc_out = bc;
00637 }
00638
00639 #ifdef FAST
00640 #ifdef LTP_CUT
00641
00642 static void Cut_Fast_Calculation_of_the_LTP_parameters P5((st,
00643 d,dp,bc_out,Nc_out),
00644 struct gsm_state * st,
00645 register word * d,
00646 register word * dp,
00647 word * bc_out,
00648 word * Nc_out
00649 )
00650 {
00651 register int k, lambda;
00652 register float wt_float;
00653 word Nc, bc;
00654 word wt_max, best_k, ltp_cut;
00655
00656 float dp_float_base[120], * dp_float = dp_float_base + 120;
00657
00658 register float L_result, L_max, L_power;
00659
00660 wt_max = 0;
00661
00662 for (k = 0; k < 40; ++k) {
00663 if ( d[k] > wt_max) wt_max = d[best_k = k];
00664 else if (-d[k] > wt_max) wt_max = -d[best_k = k];
00665 }
00666
00667 assert(wt_max >= 0);
00668 wt_float = (float)wt_max;
00669
00670 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
00671
00672
00673
00674 L_max = 0;
00675 Nc = 40;
00676
00677 for (lambda = 40; lambda <= 120; lambda++) {
00678 L_result = wt_float * dp_float[best_k - lambda];
00679 if (L_result > L_max) {
00680 Nc = lambda;
00681 L_max = L_result;
00682 }
00683 }
00684
00685 *Nc_out = Nc;
00686 if (L_max <= 0.) {
00687 *bc_out = 0;
00688 return;
00689 }
00690
00691
00692
00693
00694 dp_float -= Nc;
00695 L_power = 0;
00696 for (k = 0; k < 40; ++k) {
00697 register float f = dp_float[k];
00698 L_power += f * f;
00699 }
00700
00701 if (L_max >= L_power) {
00702 *bc_out = 3;
00703 return;
00704 }
00705
00706
00707
00708
00709
00710 lambda = L_max / L_power * 32768.;
00711 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
00712 *bc_out = bc;
00713 }
00714
00715 #endif
00716
00717 static void Fast_Calculation_of_the_LTP_parameters P4((d,dp,bc_out,Nc_out),
00718 register word * d,
00719 register word * dp,
00720 word * bc_out,
00721 word * Nc_out
00722 )
00723 {
00724 register int k, lambda;
00725 word Nc, bc;
00726
00727 float wt_float[40];
00728 float dp_float_base[120], * dp_float = dp_float_base + 120;
00729
00730 register float L_max, L_power;
00731
00732 for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];
00733 for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
00734
00735
00736
00737 L_max = 0;
00738 Nc = 40;
00739
00740 for (lambda = 40; lambda <= 120; lambda += 9) {
00741
00742
00743
00744 register float *lp = dp_float - lambda;
00745
00746 register float W;
00747 register float a = lp[-8], b = lp[-7], c = lp[-6],
00748 d = lp[-5], e = lp[-4], f = lp[-3],
00749 g = lp[-2], h = lp[-1];
00750 register float E;
00751 register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
00752 S5 = 0, S6 = 0, S7 = 0, S8 = 0;
00753
00754 # undef STEP
00755 # define STEP(K, a, b, c, d, e, f, g, h) \
00756 W = wt_float[K]; \
00757 E = W * a; S8 += E; \
00758 E = W * b; S7 += E; \
00759 E = W * c; S6 += E; \
00760 E = W * d; S5 += E; \
00761 E = W * e; S4 += E; \
00762 E = W * f; S3 += E; \
00763 E = W * g; S2 += E; \
00764 E = W * h; S1 += E; \
00765 a = lp[K]; \
00766 E = W * a; S0 += E
00767
00768 # define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
00769 # define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
00770 # define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
00771 # define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
00772 # define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
00773 # define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
00774 # define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
00775 # define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
00776
00777 STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
00778 STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
00779
00780 STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
00781 STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
00782
00783 STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
00784 STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
00785
00786 STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
00787 STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
00788
00789 STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
00790 STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
00791
00792 if (S0 > L_max) { L_max = S0; Nc = lambda; }
00793 if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
00794 if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
00795 if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
00796 if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
00797 if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
00798 if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
00799 if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
00800 if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
00801 }
00802 *Nc_out = Nc;
00803
00804 if (L_max <= 0.) {
00805 *bc_out = 0;
00806 return;
00807 }
00808
00809
00810
00811
00812 dp_float -= Nc;
00813 L_power = 0;
00814 for (k = 0; k < 40; ++k) {
00815 register float f = dp_float[k];
00816 L_power += f * f;
00817 }
00818
00819 if (L_max >= L_power) {
00820 *bc_out = 3;
00821 return;
00822 }
00823
00824
00825
00826
00827
00828 lambda = L_max / L_power * 32768.;
00829 for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
00830 *bc_out = bc;
00831 }
00832
00833 #endif
00834 #endif
00835
00836
00837
00838
00839 static void Long_term_analysis_filtering P6((bc,Nc,dp,d,dpp,e),
00840 word bc,
00841 word Nc,
00842 register word * dp,
00843 register word * d,
00844 register word * dpp,
00845 register word * e
00846 )
00847
00848
00849
00850
00851
00852
00853 {
00854 register int k;
00855 register longword ltmp;
00856
00857 # undef STEP
00858 # define STEP(BP) \
00859 for (k = 0; k <= 39; k++) { \
00860 dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
00861 e[k] = GSM_SUB( d[k], dpp[k] ); \
00862 }
00863
00864 switch (bc) {
00865 case 0: STEP( 3277 ); break;
00866 case 1: STEP( 11469 ); break;
00867 case 2: STEP( 21299 ); break;
00868 case 3: STEP( 32767 ); break;
00869 }
00870 }
00871
00872 void Gsm_Long_Term_Predictor P7((S,d,dp,e,dpp,Nc,bc),
00873
00874 struct gsm_state * S,
00875
00876 word * d,
00877 word * dp,
00878
00879 word * e,
00880 word * dpp,
00881 word * Nc,
00882 word * bc
00883 )
00884 {
00885 assert( d ); assert( dp ); assert( e );
00886 assert( dpp); assert( Nc ); assert( bc );
00887
00888 #if defined(FAST) && defined(USE_FLOAT_MUL)
00889 if (S->fast)
00890 #if defined (LTP_CUT)
00891 if (S->ltp_cut)
00892 Cut_Fast_Calculation_of_the_LTP_parameters(S,
00893 d, dp, bc, Nc);
00894 else
00895 #endif
00896 Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
00897 else
00898 #endif
00899 #ifdef LTP_CUT
00900 if (S->ltp_cut)
00901 Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
00902 else
00903 #endif
00904 Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
00905
00906 Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
00907 }
00908
00909
00910 void Gsm_Long_Term_Synthesis_Filtering P5((S,Ncr,bcr,erp,drp),
00911 struct gsm_state * S,
00912
00913 word Ncr,
00914 word bcr,
00915 register word * erp,
00916 register word * drp
00917 )
00918
00919
00920
00921
00922
00923 {
00924 register longword ltmp;
00925 register int k;
00926 word brp, drpp, Nr;
00927
00928
00929
00930 Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
00931 S->nrp = Nr;
00932 assert(Nr >= 40 && Nr <= 120);
00933
00934
00935
00936 brp = gsm_QLB[ bcr ];
00937
00938
00939
00940
00941 assert(brp != MIN_WORD);
00942
00943 for (k = 0; k <= 39; k++) {
00944 drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
00945 drp[k] = GSM_ADD( erp[k], drpp );
00946 }
00947
00948
00949
00950
00951
00952
00953 for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
00954 }