FreeCalypso > hg > efr-experiments
comparison src/cod_12k2.c @ 0:56410792419a
src: original EFR source from ETSI
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 03 Apr 2024 05:31:37 +0000 |
| parents | |
| children | 6119d2c1e7d9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:56410792419a |
|---|---|
| 1 /*************************************************************************** | |
| 2 * | |
| 3 * FILE NAME: cod_12k2.c | |
| 4 * | |
| 5 * FUNCTIONS DEFINED IN THIS FILE: | |
| 6 * Coder_12k2 and Init_Coder_12k2 | |
| 7 * | |
| 8 * | |
| 9 * Init_Coder_12k2(void): | |
| 10 * Initialization of variables for the coder section. | |
| 11 * | |
| 12 * Coder_12k2(Word16 ana[], Word16 synth[]): | |
| 13 * Speech encoder routine operating on a frame basis. | |
| 14 * | |
| 15 | |
| 16 ***************************************************************************/ | |
| 17 | |
| 18 #include "typedef.h" | |
| 19 #include "basic_op.h" | |
| 20 #include "sig_proc.h" | |
| 21 #include "count.h" | |
| 22 #include "codec.h" | |
| 23 #include "cnst.h" | |
| 24 | |
| 25 #include "window2.tab" | |
| 26 | |
| 27 #include "vad.h" | |
| 28 #include "dtx.h" | |
| 29 | |
| 30 /*-----------------------------------------------------------* | |
| 31 * Coder constant parameters (defined in "cnst.h") * | |
| 32 *-----------------------------------------------------------* | |
| 33 * L_WINDOW : LPC analysis window size * | |
| 34 * L_FRAME : Frame size * | |
| 35 * L_FRAME_BY2 : Half the frame size * | |
| 36 * L_SUBFR : Sub-frame size * | |
| 37 * M : LPC order * | |
| 38 * MP1 : LPC order+1 * | |
| 39 * L_TOTAL : Total size of speech buffer * | |
| 40 * PIT_MIN : Minimum pitch lag * | |
| 41 * PIT_MAX : Maximum pitch lag * | |
| 42 * L_INTERPOL : Length of filter for interpolation * | |
| 43 *-----------------------------------------------------------*/ | |
| 44 | |
| 45 /*--------------------------------------------------------* | |
| 46 * Static memory allocation. * | |
| 47 *--------------------------------------------------------*/ | |
| 48 | |
| 49 /* Speech vector */ | |
| 50 | |
| 51 static Word16 old_speech[L_TOTAL]; | |
| 52 static Word16 *speech, *p_window, *p_window_mid; | |
| 53 Word16 *new_speech; /* Global variable */ | |
| 54 | |
| 55 /* Weight speech vector */ | |
| 56 | |
| 57 static Word16 old_wsp[L_FRAME + PIT_MAX]; | |
| 58 static Word16 *wsp; | |
| 59 | |
| 60 /* Excitation vector */ | |
| 61 | |
| 62 static Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL]; | |
| 63 static Word16 *exc; | |
| 64 | |
| 65 /* Zero vector */ | |
| 66 | |
| 67 static Word16 ai_zero[L_SUBFR + MP1]; | |
| 68 static Word16 *zero; | |
| 69 | |
| 70 /* Impulse response vector */ | |
| 71 | |
| 72 static Word16 *h1; | |
| 73 static Word16 hvec[L_SUBFR * 2]; | |
| 74 | |
| 75 /* Spectral expansion factors */ | |
| 76 | |
| 77 static const Word16 F_gamma1[M] = | |
| 78 { | |
| 79 29491, 26542, 23888, 21499, 19349, | |
| 80 17414, 15672, 14105, 12694, 11425 | |
| 81 }; | |
| 82 static const Word16 F_gamma2[M] = | |
| 83 { | |
| 84 19661, 11797, 7078, 4247, 2548, | |
| 85 1529, 917, 550, 330, 198 | |
| 86 }; | |
| 87 | |
| 88 /* Lsp (Line spectral pairs) */ | |
| 89 | |
| 90 static Word16 lsp_old[M]; | |
| 91 static Word16 lsp_old_q[M]; | |
| 92 | |
| 93 /* Filter's memory */ | |
| 94 | |
| 95 static Word16 mem_syn[M], mem_w0[M], mem_w[M]; | |
| 96 static Word16 mem_err[M + L_SUBFR], *error; | |
| 97 | |
| 98 /*************************************************************************** | |
| 99 * FUNCTION: Init_Coder_12k2 | |
| 100 * | |
| 101 * PURPOSE: Initialization of variables for the coder section. | |
| 102 * | |
| 103 * DESCRIPTION: | |
| 104 * - initilize pointers to speech buffer | |
| 105 * - initialize static pointers | |
| 106 * - set static vectors to zero | |
| 107 * | |
| 108 ***************************************************************************/ | |
| 109 | |
| 110 void Init_Coder_12k2 (void) | |
| 111 { | |
| 112 | |
| 113 /*--------------------------------------------------------------------------* | |
| 114 * Initialize pointers to speech vector. * | |
| 115 *--------------------------------------------------------------------------*/ | |
| 116 | |
| 117 new_speech = old_speech + L_TOTAL - L_FRAME;/* New speech */ | |
| 118 speech = new_speech; /* Present frame */ | |
| 119 p_window = old_speech + L_TOTAL - L_WINDOW; /* For LPC window */ | |
| 120 p_window_mid = p_window; /* For LPC window */ | |
| 121 | |
| 122 /* Initialize static pointers */ | |
| 123 | |
| 124 wsp = old_wsp + PIT_MAX; | |
| 125 exc = old_exc + PIT_MAX + L_INTERPOL; | |
| 126 zero = ai_zero + MP1; | |
| 127 error = mem_err + M; | |
| 128 h1 = &hvec[L_SUBFR]; | |
| 129 | |
| 130 /* Static vectors to zero */ | |
| 131 | |
| 132 Set_zero (old_speech, L_TOTAL); | |
| 133 Set_zero (old_exc, PIT_MAX + L_INTERPOL); | |
| 134 Set_zero (old_wsp, PIT_MAX); | |
| 135 Set_zero (mem_syn, M); | |
| 136 Set_zero (mem_w, M); | |
| 137 Set_zero (mem_w0, M); | |
| 138 Set_zero (mem_err, M); | |
| 139 Set_zero (zero, L_SUBFR); | |
| 140 Set_zero (hvec, L_SUBFR); /* set to zero "h1[-L_SUBFR..-1]" */ | |
| 141 | |
| 142 /* Initialize lsp_old [] */ | |
| 143 | |
| 144 lsp_old[0] = 30000; | |
| 145 lsp_old[1] = 26000; | |
| 146 lsp_old[2] = 21000; | |
| 147 lsp_old[3] = 15000; | |
| 148 lsp_old[4] = 8000; | |
| 149 lsp_old[5] = 0; | |
| 150 lsp_old[6] = -8000; | |
| 151 lsp_old[7] = -15000; | |
| 152 lsp_old[8] = -21000; | |
| 153 lsp_old[9] = -26000; | |
| 154 | |
| 155 /* Initialize lsp_old_q[] */ | |
| 156 | |
| 157 Copy (lsp_old, lsp_old_q, M); | |
| 158 | |
| 159 return; | |
| 160 } | |
| 161 | |
| 162 /*************************************************************************** | |
| 163 * FUNCTION: Coder_12k2 | |
| 164 * | |
| 165 * PURPOSE: Principle encoder routine. | |
| 166 * | |
| 167 * DESCRIPTION: This function is called every 20 ms speech frame, | |
| 168 * operating on the newly read 160 speech samples. It performs the | |
| 169 * principle encoding functions to produce the set of encoded parameters | |
| 170 * which include the LSP, adaptive codebook, and fixed codebook | |
| 171 * quantization indices (addresses and gains). | |
| 172 * | |
| 173 * INPUTS: | |
| 174 * No input arguments are passed to this function. However, before | |
| 175 * calling this function, 160 new speech data samples should be copied to | |
| 176 * the vector new_speech[]. This is a global pointer which is declared in | |
| 177 * this file (it points to the end of speech buffer minus 160). | |
| 178 * | |
| 179 * OUTPUTS: | |
| 180 * | |
| 181 * ana[]: vector of analysis parameters. | |
| 182 * synth[]: Local synthesis speech (for debugging purposes) | |
| 183 * | |
| 184 ***************************************************************************/ | |
| 185 | |
| 186 void Coder_12k2 ( | |
| 187 Word16 ana[], /* output : Analysis parameters */ | |
| 188 Word16 synth[] /* output : Local synthesis */ | |
| 189 ) | |
| 190 { | |
| 191 /* LPC coefficients */ | |
| 192 | |
| 193 Word16 r_l[MP1], r_h[MP1]; /* Autocorrelations lo and hi */ | |
| 194 Word16 A_t[(MP1) * 4]; /* A(z) unquantized for the 4 subframes */ | |
| 195 Word16 Aq_t[(MP1) * 4]; /* A(z) quantized for the 4 subframes */ | |
| 196 Word16 Ap1[MP1]; /* A(z) with spectral expansion */ | |
| 197 Word16 Ap2[MP1]; /* A(z) with spectral expansion */ | |
| 198 Word16 *A, *Aq; /* Pointer on A_t and Aq_t */ | |
| 199 Word16 lsp_new[M], lsp_new_q[M];/* LSPs at 4th subframe */ | |
| 200 Word16 lsp_mid[M], lsp_mid_q[M];/* LSPs at 2nd subframe */ | |
| 201 | |
| 202 /* Other vectors */ | |
| 203 | |
| 204 Word16 xn[L_SUBFR]; /* Target vector for pitch search */ | |
| 205 Word16 xn2[L_SUBFR]; /* Target vector for codebook search */ | |
| 206 Word16 res2[L_SUBFR]; /* Long term prediction residual */ | |
| 207 Word16 code[L_SUBFR]; /* Fixed codebook excitation */ | |
| 208 Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */ | |
| 209 Word16 y2[L_SUBFR]; /* Filtered fixed codebook excitation */ | |
| 210 | |
| 211 /* Scalars */ | |
| 212 | |
| 213 Word16 i, j, k, i_subfr; | |
| 214 Word16 T_op, T0, T0_min, T0_max, T0_frac; | |
| 215 Word16 gain_pit, gain_code, pit_flag, pit_sharp; | |
| 216 Word16 temp; | |
| 217 Word32 L_temp; | |
| 218 | |
| 219 Word16 scal_acf, VAD_flag, lags[2], rc[4]; | |
| 220 | |
| 221 extern Word16 ptch; | |
| 222 extern Word16 txdtx_ctrl, CN_excitation_gain; | |
| 223 extern Word32 L_pn_seed_tx; | |
| 224 extern Word16 dtx_mode; | |
| 225 | |
| 226 /*----------------------------------------------------------------------* | |
| 227 * - Perform LPC analysis: (twice per frame) * | |
| 228 * * autocorrelation + lag windowing * | |
| 229 * * Levinson-Durbin algorithm to find a[] * | |
| 230 * * convert a[] to lsp[] * | |
| 231 * * quantize and code the LSPs * | |
| 232 * * find the interpolated LSPs and convert to a[] for all * | |
| 233 * subframes (both quantized and unquantized) * | |
| 234 *----------------------------------------------------------------------*/ | |
| 235 | |
| 236 /* LP analysis centered at 2nd subframe */ | |
| 237 | |
| 238 | |
| 239 scal_acf = Autocorr (p_window_mid, M, r_h, r_l, window_160_80); | |
| 240 /* Autocorrelations */ | |
| 241 | |
| 242 #if (WMOPS) | |
| 243 fwc (); /* function worst case */ | |
| 244 #endif | |
| 245 | |
| 246 Lag_window (M, r_h, r_l); /* Lag windowing */ | |
| 247 | |
| 248 #if (WMOPS) | |
| 249 fwc (); /* function worst case */ | |
| 250 #endif | |
| 251 | |
| 252 Levinson (r_h, r_l, &A_t[MP1], rc); /* Levinson-Durbin */ | |
| 253 | |
| 254 #if (WMOPS) | |
| 255 fwc (); /* function worst case */ | |
| 256 #endif | |
| 257 | |
| 258 Az_lsp (&A_t[MP1], lsp_mid, lsp_old); /* From A(z) to lsp */ | |
| 259 | |
| 260 #if (WMOPS) | |
| 261 fwc (); /* function worst case */ | |
| 262 #endif | |
| 263 | |
| 264 /* LP analysis centered at 4th subframe */ | |
| 265 | |
| 266 /* Autocorrelations */ | |
| 267 scal_acf = Autocorr (p_window, M, r_h, r_l, window_232_8); | |
| 268 | |
| 269 #if (WMOPS) | |
| 270 fwc (); /* function worst case */ | |
| 271 #endif | |
| 272 | |
| 273 Lag_window (M, r_h, r_l); /* Lag windowing */ | |
| 274 | |
| 275 #if (WMOPS) | |
| 276 fwc (); /* function worst case */ | |
| 277 #endif | |
| 278 | |
| 279 Levinson (r_h, r_l, &A_t[MP1 * 3], rc); /* Levinson-Durbin */ | |
| 280 | |
| 281 #if (WMOPS) | |
| 282 fwc (); /* function worst case */ | |
| 283 #endif | |
| 284 | |
| 285 Az_lsp (&A_t[MP1 * 3], lsp_new, lsp_mid); /* From A(z) to lsp */ | |
| 286 | |
| 287 #if (WMOPS) | |
| 288 fwc (); /* function worst case */ | |
| 289 #endif | |
| 290 | |
| 291 if (dtx_mode == 1) | |
| 292 { | |
| 293 /* DTX enabled, make voice activity decision */ | |
| 294 VAD_flag = vad_computation (r_h, r_l, scal_acf, rc, ptch); | |
| 295 move16 (); | |
| 296 | |
| 297 tx_dtx (VAD_flag, &txdtx_ctrl); /* TX DTX handler */ | |
| 298 } | |
| 299 else | |
| 300 { | |
| 301 /* DTX disabled, active speech in every frame */ | |
| 302 VAD_flag = 1; | |
| 303 txdtx_ctrl = TX_VAD_FLAG | TX_SP_FLAG; | |
| 304 } | |
| 305 | |
| 306 /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */ | |
| 307 | |
| 308 Q_plsf_5 (lsp_mid, lsp_new, lsp_mid_q, lsp_new_q, ana, txdtx_ctrl); | |
| 309 | |
| 310 #if (WMOPS) | |
| 311 fwc (); /* function worst case */ | |
| 312 #endif | |
| 313 ana += 5; move16 (); | |
| 314 | |
| 315 /*--------------------------------------------------------------------* | |
| 316 * Find interpolated LPC parameters in all subframes (both quantized * | |
| 317 * and unquantized). * | |
| 318 * The interpolated parameters are in array A_t[] of size (M+1)*4 * | |
| 319 * and the quantized interpolated parameters are in array Aq_t[] * | |
| 320 *--------------------------------------------------------------------*/ | |
| 321 | |
| 322 Int_lpc2 (lsp_old, lsp_mid, lsp_new, A_t); | |
| 323 | |
| 324 #if (WMOPS) | |
| 325 fwc (); /* function worst case */ | |
| 326 #endif | |
| 327 | |
| 328 test (); logic16 (); | |
| 329 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 330 { | |
| 331 Int_lpc (lsp_old_q, lsp_mid_q, lsp_new_q, Aq_t); | |
| 332 | |
| 333 /* update the LSPs for the next frame */ | |
| 334 for (i = 0; i < M; i++) | |
| 335 { | |
| 336 lsp_old[i] = lsp_new[i]; move16 (); | |
| 337 lsp_old_q[i] = lsp_new_q[i]; move16 (); | |
| 338 } | |
| 339 } | |
| 340 else | |
| 341 { | |
| 342 /* Use unquantized LPC parameters in case of no speech activity */ | |
| 343 for (i = 0; i < MP1; i++) | |
| 344 { | |
| 345 Aq_t[i] = A_t[i]; move16 (); | |
| 346 Aq_t[i + MP1] = A_t[i + MP1]; move16 (); | |
| 347 Aq_t[i + MP1 * 2] = A_t[i + MP1 * 2]; move16 (); | |
| 348 Aq_t[i + MP1 * 3] = A_t[i + MP1 * 3]; move16 (); | |
| 349 } | |
| 350 | |
| 351 /* update the LSPs for the next frame */ | |
| 352 for (i = 0; i < M; i++) | |
| 353 { | |
| 354 lsp_old[i] = lsp_new[i]; move16 (); | |
| 355 lsp_old_q[i] = lsp_new[i]; move16 (); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 #if (WMOPS) | |
| 360 fwc (); /* function worst case */ | |
| 361 #endif | |
| 362 | |
| 363 /*----------------------------------------------------------------------* | |
| 364 * - Find the weighted input speech wsp[] for the whole speech frame * | |
| 365 * - Find the open-loop pitch delay for first 2 subframes * | |
| 366 * - Set the range for searching closed-loop pitch in 1st subframe * | |
| 367 * - Find the open-loop pitch delay for last 2 subframes * | |
| 368 *----------------------------------------------------------------------*/ | |
| 369 | |
| 370 A = A_t; move16 (); | |
| 371 for (i = 0; i < L_FRAME; i += L_SUBFR) | |
| 372 { | |
| 373 Weight_Ai (A, F_gamma1, Ap1); | |
| 374 | |
| 375 #if (WMOPS) | |
| 376 fwc (); /* function worst case */ | |
| 377 #endif | |
| 378 | |
| 379 Weight_Ai (A, F_gamma2, Ap2); | |
| 380 | |
| 381 #if (WMOPS) | |
| 382 fwc (); /* function worst case */ | |
| 383 #endif | |
| 384 | |
| 385 Residu (Ap1, &speech[i], &wsp[i], L_SUBFR); | |
| 386 | |
| 387 #if (WMOPS) | |
| 388 fwc (); /* function worst case */ | |
| 389 #endif | |
| 390 | |
| 391 Syn_filt (Ap2, &wsp[i], &wsp[i], L_SUBFR, mem_w, 1); | |
| 392 | |
| 393 #if (WMOPS) | |
| 394 fwc (); /* function worst case */ | |
| 395 #endif | |
| 396 | |
| 397 A += MP1; move16 (); | |
| 398 } | |
| 399 | |
| 400 /* Find open loop pitch lag for first two subframes */ | |
| 401 | |
| 402 T_op = Pitch_ol (wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2); move16 (); | |
| 403 | |
| 404 #if (WMOPS) | |
| 405 fwc (); /* function worst case */ | |
| 406 #endif | |
| 407 | |
| 408 lags[0] = T_op; move16 (); | |
| 409 | |
| 410 test (); logic16 (); | |
| 411 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 412 { | |
| 413 /* Range for closed loop pitch search in 1st subframe */ | |
| 414 | |
| 415 T0_min = sub (T_op, 3); | |
| 416 test (); | |
| 417 if (sub (T0_min, PIT_MIN) < 0) | |
| 418 { | |
| 419 T0_min = PIT_MIN; move16 (); | |
| 420 } | |
| 421 T0_max = add (T0_min, 6); | |
| 422 test (); | |
| 423 if (sub (T0_max, PIT_MAX) > 0) | |
| 424 { | |
| 425 T0_max = PIT_MAX; move16 (); | |
| 426 T0_min = sub (T0_max, 6); | |
| 427 } | |
| 428 #if (WMOPS) | |
| 429 fwc (); /* function worst case */ | |
| 430 #endif | |
| 431 } | |
| 432 /* Find open loop pitch lag for last two subframes */ | |
| 433 | |
| 434 T_op = Pitch_ol (&wsp[L_FRAME_BY2], PIT_MIN, PIT_MAX, L_FRAME_BY2); | |
| 435 move16 (); | |
| 436 | |
| 437 #if (WMOPS) | |
| 438 fwc (); /* function worst case */ | |
| 439 #endif | |
| 440 | |
| 441 if (dtx_mode == 1) | |
| 442 { | |
| 443 lags[1] = T_op; move16 (); | |
| 444 periodicity_update (lags, &ptch); | |
| 445 } | |
| 446 /*----------------------------------------------------------------------* | |
| 447 * Loop for every subframe in the analysis frame * | |
| 448 *----------------------------------------------------------------------* | |
| 449 * To find the pitch and innovation parameters. The subframe size is * | |
| 450 * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. * | |
| 451 * - find the weighted LPC coefficients * | |
| 452 * - find the LPC residual signal res[] * | |
| 453 * - compute the target signal for pitch search * | |
| 454 * - compute impulse response of weighted synthesis filter (h1[]) * | |
| 455 * - find the closed-loop pitch parameters * | |
| 456 * - encode the pitch delay * | |
| 457 * - update the impulse response h1[] by including pitch * | |
| 458 * - find target vector for codebook search * | |
| 459 * - codebook search * | |
| 460 * - encode codebook address * | |
| 461 * - VQ of pitch and codebook gains * | |
| 462 * - find synthesis speech * | |
| 463 * - update states of weighting filter * | |
| 464 *----------------------------------------------------------------------*/ | |
| 465 | |
| 466 /* pointer to interpolated LPC parameters */ | |
| 467 A = A_t; move16 (); | |
| 468 /* pointer to interpolated quantized LPC parameters */ | |
| 469 Aq = Aq_t; move16 (); | |
| 470 | |
| 471 for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) | |
| 472 { | |
| 473 | |
| 474 test (); logic16 (); | |
| 475 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 476 { | |
| 477 | |
| 478 /*---------------------------------------------------------------* | |
| 479 * Find the weighted LPC coefficients for the weighting filter. * | |
| 480 *---------------------------------------------------------------*/ | |
| 481 | |
| 482 Weight_Ai (A, F_gamma1, Ap1); | |
| 483 | |
| 484 #if (WMOPS) | |
| 485 fwc (); /* function worst case */ | |
| 486 #endif | |
| 487 | |
| 488 Weight_Ai (A, F_gamma2, Ap2); | |
| 489 | |
| 490 #if (WMOPS) | |
| 491 fwc (); /* function worst case */ | |
| 492 #endif | |
| 493 | |
| 494 /*---------------------------------------------------------------* | |
| 495 * Compute impulse response, h1[], of weighted synthesis filter * | |
| 496 *---------------------------------------------------------------*/ | |
| 497 | |
| 498 for (i = 0; i <= M; i++) | |
| 499 { | |
| 500 ai_zero[i] = Ap1[i]; move16 (); | |
| 501 } | |
| 502 | |
| 503 Syn_filt (Aq, ai_zero, h1, L_SUBFR, zero, 0); | |
| 504 | |
| 505 #if (WMOPS) | |
| 506 fwc (); /* function worst case */ | |
| 507 #endif | |
| 508 | |
| 509 Syn_filt (Ap2, h1, h1, L_SUBFR, zero, 0); | |
| 510 | |
| 511 #if (WMOPS) | |
| 512 fwc (); /* function worst case */ | |
| 513 #endif | |
| 514 | |
| 515 } | |
| 516 /*---------------------------------------------------------------* | |
| 517 * Find the target vector for pitch search: * | |
| 518 *---------------------------------------------------------------*/ | |
| 519 | |
| 520 Residu (Aq, &speech[i_subfr], res2, L_SUBFR); /* LPC residual */ | |
| 521 | |
| 522 #if (WMOPS) | |
| 523 fwc (); /* function worst case */ | |
| 524 #endif | |
| 525 | |
| 526 test (); logic16 (); | |
| 527 if ((txdtx_ctrl & TX_SP_FLAG) == 0) | |
| 528 { | |
| 529 /* Compute comfort noise excitation gain based on | |
| 530 LP residual energy */ | |
| 531 | |
| 532 CN_excitation_gain = compute_CN_excitation_gain (res2); | |
| 533 move16 (); | |
| 534 } | |
| 535 else | |
| 536 { | |
| 537 Copy (res2, &exc[i_subfr], L_SUBFR); | |
| 538 | |
| 539 #if (WMOPS) | |
| 540 fwc (); /* function worst case */ | |
| 541 #endif | |
| 542 | |
| 543 Syn_filt (Aq, &exc[i_subfr], error, L_SUBFR, mem_err, 0); | |
| 544 | |
| 545 #if (WMOPS) | |
| 546 fwc (); /* function worst case */ | |
| 547 #endif | |
| 548 | |
| 549 Residu (Ap1, error, xn, L_SUBFR); | |
| 550 | |
| 551 #if (WMOPS) | |
| 552 fwc (); /* function worst case */ | |
| 553 #endif | |
| 554 | |
| 555 Syn_filt (Ap2, xn, xn, L_SUBFR, mem_w0, 0); /* target signal xn[]*/ | |
| 556 | |
| 557 #if (WMOPS) | |
| 558 fwc (); /* function worst case */ | |
| 559 #endif | |
| 560 | |
| 561 /*--------------------------------------------------------------* | |
| 562 * Closed-loop fractional pitch search * | |
| 563 *--------------------------------------------------------------*/ | |
| 564 | |
| 565 /* flag for first and 3th subframe */ | |
| 566 pit_flag = i_subfr; move16 (); | |
| 567 test (); | |
| 568 /* set t0_min and t0_max for 3th subf.*/ | |
| 569 if (sub (i_subfr, L_FRAME_BY2) == 0) | |
| 570 { | |
| 571 T0_min = sub (T_op, 3); | |
| 572 | |
| 573 test (); | |
| 574 if (sub (T0_min, PIT_MIN) < 0) | |
| 575 { | |
| 576 T0_min = PIT_MIN; move16 (); | |
| 577 } | |
| 578 T0_max = add (T0_min, 6); | |
| 579 test (); | |
| 580 if (sub (T0_max, PIT_MAX) > 0) | |
| 581 { | |
| 582 T0_max = PIT_MAX; move16 (); | |
| 583 T0_min = sub (T0_max, 6); | |
| 584 } | |
| 585 pit_flag = 0; move16 (); | |
| 586 } | |
| 587 #if (WMOPS) | |
| 588 fwc (); /* function worst case */ | |
| 589 #endif | |
| 590 | |
| 591 T0 = Pitch_fr6 (&exc[i_subfr], xn, h1, L_SUBFR, T0_min, T0_max, | |
| 592 pit_flag, &T0_frac); move16 (); | |
| 593 | |
| 594 #if (WMOPS) | |
| 595 fwc (); /* function worst case */ | |
| 596 #endif | |
| 597 | |
| 598 *ana = Enc_lag6 (T0, &T0_frac, &T0_min, &T0_max, PIT_MIN, | |
| 599 PIT_MAX, pit_flag); | |
| 600 move16 (); | |
| 601 | |
| 602 #if (WMOPS) | |
| 603 fwc (); /* function worst case */ | |
| 604 #endif | |
| 605 } | |
| 606 ana++; | |
| 607 /* Incrementation of ana is done here to work also | |
| 608 when no speech activity is present */ | |
| 609 | |
| 610 test (); logic16 (); | |
| 611 | |
| 612 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 613 { | |
| 614 | |
| 615 /*---------------------------------------------------------------* | |
| 616 * - find unity gain pitch excitation (adaptive codebook entry) * | |
| 617 * with fractional interpolation. * | |
| 618 * - find filtered pitch exc. y1[]=exc[] convolved with h1[] * | |
| 619 * - compute pitch gain and limit between 0 and 1.2 * | |
| 620 * - update target vector for codebook search * | |
| 621 * - find LTP residual. * | |
| 622 *---------------------------------------------------------------*/ | |
| 623 | |
| 624 Pred_lt_6 (&exc[i_subfr], T0, T0_frac, L_SUBFR); | |
| 625 | |
| 626 #if (WMOPS) | |
| 627 fwc (); /* function worst case */ | |
| 628 #endif | |
| 629 | |
| 630 Convolve (&exc[i_subfr], h1, y1, L_SUBFR); | |
| 631 | |
| 632 #if (WMOPS) | |
| 633 fwc (); /* function worst case */ | |
| 634 #endif | |
| 635 | |
| 636 gain_pit = G_pitch (xn, y1, L_SUBFR); move16 (); | |
| 637 | |
| 638 #if (WMOPS) | |
| 639 fwc (); /* function worst case */ | |
| 640 #endif | |
| 641 | |
| 642 *ana = q_gain_pitch (&gain_pit); move16 (); | |
| 643 | |
| 644 #if (WMOPS) | |
| 645 fwc (); /* function worst case */ | |
| 646 #endif | |
| 647 | |
| 648 } | |
| 649 else | |
| 650 { | |
| 651 gain_pit = 0; move16 (); | |
| 652 } | |
| 653 | |
| 654 ana++; /* Incrementation of ana is done here to work | |
| 655 also when no speech activity is present */ | |
| 656 | |
| 657 test (); logic16 (); | |
| 658 | |
| 659 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 660 { | |
| 661 /* xn2[i] = xn[i] - y1[i] * gain_pit */ | |
| 662 /* res2[i] -= exc[i+i_subfr] * gain_pit */ | |
| 663 | |
| 664 for (i = 0; i < L_SUBFR; i++) | |
| 665 { | |
| 666 L_temp = L_mult (y1[i], gain_pit); | |
| 667 L_temp = L_shl (L_temp, 3); | |
| 668 xn2[i] = sub (xn[i], extract_h (L_temp)); move16 (); | |
| 669 | |
| 670 L_temp = L_mult (exc[i + i_subfr], gain_pit); | |
| 671 L_temp = L_shl (L_temp, 3); | |
| 672 res2[i] = sub (res2[i], extract_h (L_temp)); move16 (); | |
| 673 } | |
| 674 | |
| 675 #if (WMOPS) | |
| 676 fwc (); /* function worst case */ | |
| 677 #endif | |
| 678 | |
| 679 /*-------------------------------------------------------------* | |
| 680 * - include pitch contribution into impulse resp. h1[] * | |
| 681 *-------------------------------------------------------------*/ | |
| 682 | |
| 683 /* pit_sharp = gain_pit; */ | |
| 684 /* if (pit_sharp > 1.0) pit_sharp = 1.0; */ | |
| 685 | |
| 686 pit_sharp = shl (gain_pit, 3); | |
| 687 | |
| 688 for (i = T0; i < L_SUBFR; i++) | |
| 689 { | |
| 690 temp = mult (h1[i - T0], pit_sharp); | |
| 691 h1[i] = add (h1[i], temp); move16 (); | |
| 692 } | |
| 693 | |
| 694 #if (WMOPS) | |
| 695 fwc (); /* function worst case */ | |
| 696 #endif | |
| 697 | |
| 698 /*--------------------------------------------------------------* | |
| 699 * - Innovative codebook search (find index and gain) * | |
| 700 *--------------------------------------------------------------*/ | |
| 701 | |
| 702 code_10i40_35bits (xn2, res2, h1, code, y2, ana); | |
| 703 | |
| 704 #if (WMOPS) | |
| 705 fwc (); /* function worst case */ | |
| 706 #endif | |
| 707 | |
| 708 } | |
| 709 else | |
| 710 { | |
| 711 build_CN_code (code, &L_pn_seed_tx); | |
| 712 } | |
| 713 ana += 10; move16 (); | |
| 714 | |
| 715 test (); logic16 (); | |
| 716 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 717 { | |
| 718 | |
| 719 /*-------------------------------------------------------* | |
| 720 * - Add the pitch contribution to code[]. * | |
| 721 *-------------------------------------------------------*/ | |
| 722 | |
| 723 for (i = T0; i < L_SUBFR; i++) | |
| 724 { | |
| 725 temp = mult (code[i - T0], pit_sharp); | |
| 726 code[i] = add (code[i], temp); move16 (); | |
| 727 } | |
| 728 | |
| 729 #if (WMOPS) | |
| 730 fwc (); /* function worst case */ | |
| 731 #endif | |
| 732 | |
| 733 /*------------------------------------------------------* | |
| 734 * - Quantization of fixed codebook gain. * | |
| 735 *------------------------------------------------------*/ | |
| 736 | |
| 737 gain_code = G_code (xn2, y2); move16 (); | |
| 738 | |
| 739 #if (WMOPS) | |
| 740 fwc (); /* function worst case */ | |
| 741 #endif | |
| 742 | |
| 743 } | |
| 744 *ana++ = q_gain_code (code, L_SUBFR, &gain_code, txdtx_ctrl, i_subfr); | |
| 745 move16 (); | |
| 746 | |
| 747 #if (WMOPS) | |
| 748 fwc (); /* function worst case */ | |
| 749 #endif | |
| 750 | |
| 751 /*------------------------------------------------------* | |
| 752 * - Find the total excitation * | |
| 753 * - find synthesis speech corresponding to exc[] * | |
| 754 * - update filter memories for finding the target * | |
| 755 * vector in the next subframe * | |
| 756 * (update mem_err[] and mem_w0[]) * | |
| 757 *------------------------------------------------------*/ | |
| 758 | |
| 759 for (i = 0; i < L_SUBFR; i++) | |
| 760 { | |
| 761 /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */ | |
| 762 | |
| 763 L_temp = L_mult (exc[i + i_subfr], gain_pit); | |
| 764 L_temp = L_mac (L_temp, code[i], gain_code); | |
| 765 L_temp = L_shl (L_temp, 3); | |
| 766 exc[i + i_subfr] = round (L_temp); move16 (); | |
| 767 } | |
| 768 | |
| 769 #if (WMOPS) | |
| 770 fwc (); /* function worst case */ | |
| 771 #endif | |
| 772 | |
| 773 Syn_filt (Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem_syn, 1); | |
| 774 | |
| 775 #if (WMOPS) | |
| 776 fwc (); /* function worst case */ | |
| 777 #endif | |
| 778 | |
| 779 test (); logic16 (); | |
| 780 if ((txdtx_ctrl & TX_SP_FLAG) != 0) | |
| 781 { | |
| 782 | |
| 783 for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++) | |
| 784 { | |
| 785 mem_err[j] = sub (speech[i_subfr + i], synth[i_subfr + i]); | |
| 786 move16 (); | |
| 787 temp = extract_h (L_shl (L_mult (y1[i], gain_pit), 3)); | |
| 788 k = extract_h (L_shl (L_mult (y2[i], gain_code), 5)); | |
| 789 mem_w0[j] = sub (xn[i], add (temp, k)); move16 (); | |
| 790 } | |
| 791 } | |
| 792 else | |
| 793 { | |
| 794 for (j = 0; j < M; j++) | |
| 795 { | |
| 796 mem_err[j] = 0; move16 (); | |
| 797 mem_w0[j] = 0; move16 (); | |
| 798 } | |
| 799 } | |
| 800 | |
| 801 #if (WMOPS) | |
| 802 fwc (); /* function worst case */ | |
| 803 #endif | |
| 804 /* interpolated LPC parameters for next subframe */ | |
| 805 A += MP1; move16 (); | |
| 806 Aq += MP1; move16 (); | |
| 807 } | |
| 808 | |
| 809 /*--------------------------------------------------* | |
| 810 * Update signal for next frame. * | |
| 811 * -> shift to the left by L_FRAME: * | |
| 812 * speech[], wsp[] and exc[] * | |
| 813 *--------------------------------------------------*/ | |
| 814 | |
| 815 Copy (&old_speech[L_FRAME], &old_speech[0], L_TOTAL - L_FRAME); | |
| 816 | |
| 817 #if (WMOPS) | |
| 818 fwc (); /* function worst case */ | |
| 819 #endif | |
| 820 | |
| 821 Copy (&old_wsp[L_FRAME], &old_wsp[0], PIT_MAX); | |
| 822 | |
| 823 #if (WMOPS) | |
| 824 fwc (); /* function worst case */ | |
| 825 #endif | |
| 826 | |
| 827 Copy (&old_exc[L_FRAME], &old_exc[0], PIT_MAX + L_INTERPOL); | |
| 828 | |
| 829 #if (WMOPS) | |
| 830 fwc (); /* function worst case */ | |
| 831 #endif | |
| 832 | |
| 833 return; | |
| 834 } |
