Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include <math.h>
43 : #include "prot.h"
44 : #include "rom_enc.h"
45 : #include "rom_com.h"
46 : #include "wmc_auto.h"
47 : #ifdef DEBUG_PLOT
48 : #include "deb_out.h"
49 : #endif
50 :
51 :
52 : /*---------------------------------------------------------------------*
53 : * interpolate_corr()
54 : *
55 : *
56 : *---------------------------------------------------------------------*/
57 :
58 : /*! r: interpolated value */
59 88269828 : static float interpolate_corr(
60 : const float *x, /* i : input vector */
61 : const int16_t frac, /* i : fraction of lag */
62 : const int16_t frac_max /* i : max fraction */
63 : )
64 : {
65 : int16_t i;
66 : float s;
67 : const float *c1, *c2, *x1, *x2, *win;
68 :
69 :
70 88269828 : if ( frac_max == 6 )
71 : {
72 5004329 : win = E_ROM_inter6_1;
73 : }
74 : else
75 : {
76 83265499 : win = E_ROM_inter4_1;
77 : }
78 :
79 88269828 : x1 = &x[0];
80 88269828 : x2 = &x[1];
81 88269828 : c1 = &win[frac];
82 88269828 : c2 = &win[frac_max - frac];
83 88269828 : s = 0.0f;
84 441349140 : for ( i = 0; i < 4; i++, c1 += frac_max, c2 += frac_max )
85 : {
86 353079312 : s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
87 : }
88 :
89 88269828 : return s;
90 : }
91 :
92 :
93 : /*---------------------------------------------------------------------*
94 : * tcx_ltp_pitch_search()
95 : *
96 : *
97 : *---------------------------------------------------------------------*/
98 :
99 17213791 : static void tcx_ltp_pitch_search(
100 : const int16_t pitch_ol,
101 : int16_t *pitch_int,
102 : int16_t *pitch_fr,
103 : int16_t *index,
104 : float *norm_corr,
105 : const int16_t len,
106 : const float *wsp,
107 : const int16_t pitmin,
108 : const int16_t pitfr1,
109 : const int16_t pitfr2,
110 : const int16_t pitmax,
111 : const int16_t pitres,
112 : const int16_t check_border_case,
113 : int16_t *border_case )
114 : {
115 : int16_t i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta;
116 : float temp, cor_max, cor[256], *pt_cor;
117 :
118 17213791 : if ( pitres == 6 )
119 : {
120 2023119 : delta = 8;
121 : }
122 : else
123 : {
124 15190672 : delta = 16;
125 : }
126 :
127 17213791 : t0_min = (int16_t) pitch_ol - ( delta >> 1 );
128 17213791 : t0_max = (int16_t) pitch_ol + ( delta >> 1 ) - 1;
129 :
130 17213791 : if ( t0_min < pitmin )
131 : {
132 1495217 : t0_min = pitmin;
133 1495217 : t0_max = t0_min + delta - 1;
134 : }
135 17213791 : if ( t0_max > pitmax )
136 : {
137 391064 : t0_max = pitmax;
138 391064 : t0_min = t0_max - delta + 1;
139 : }
140 :
141 :
142 17213791 : t_min = t0_min - L_INTERPOL1;
143 17213791 : t_max = t0_max + L_INTERPOL1;
144 :
145 17213791 : pt_cor = cor;
146 414159823 : for ( t = t_min; t <= t_max; t++ )
147 : {
148 396946032 : *pt_cor++ = dotp( wsp, wsp - t, len );
149 : }
150 :
151 17213791 : pt_cor = cor + L_INTERPOL1;
152 17213791 : cor_max = *pt_cor++;
153 17213791 : t1 = t0_min;
154 259235704 : for ( t = t0_min + 1; t <= t0_max; t++ )
155 : {
156 242021913 : if ( *pt_cor > cor_max )
157 : {
158 78842502 : cor_max = *pt_cor;
159 78842502 : t1 = t;
160 : }
161 242021913 : pt_cor++;
162 : }
163 17213791 : temp = dotp( wsp, wsp, len ) * dotp( wsp - t1, wsp - t1, len );
164 17213791 : *norm_corr = cor_max / (float) sqrt( temp + 0.1f );
165 :
166 : /* check for border cases at the low lag border */
167 : /*pt_cor=cor;*/
168 17213791 : if ( check_border_case && t1 == t0_min )
169 : {
170 : float tmpCor;
171 5909729 : for ( t = t1 - L_INTERPOL1; t < t1; t++ )
172 : {
173 5084393 : tmpCor = dotp( wsp, wsp - t, len );
174 5084393 : if ( tmpCor > cor_max )
175 : {
176 : /* no real maximum but still on a rising slope */
177 : /* keep t1 but set norm_corr to zero to avoid activating the LTP here */
178 1148867 : *border_case = 1;
179 1148867 : break;
180 : }
181 : }
182 : }
183 :
184 17213791 : if ( t1 >= pitfr1 )
185 : {
186 2938120 : *pitch_int = t1;
187 2938120 : *pitch_fr = 0;
188 2938120 : *index = t1 - pitfr1 + ( ( pitfr2 - pitmin ) * pitres ) + ( ( pitfr1 - pitfr2 ) * ( pitres >> 1 ) );
189 2938120 : return;
190 : }
191 :
192 : /*------------------------------------------------------------------*
193 : * Search fractional pitch with 1/4 subsample resolution.
194 : * search the fractions around t0 and choose the one which maximizes
195 : * the interpolated normalized correlation.
196 : *-----------------------------------------------------------------*/
197 :
198 14275671 : pt_cor = cor + L_INTERPOL1 - t0_min;
199 14275671 : t0 = t1;
200 14275671 : if ( t0 >= pitfr2 )
201 : {
202 2671190 : step = 2;
203 2671190 : fraction = 2;
204 : }
205 : else
206 : {
207 11604481 : step = 1;
208 11604481 : fraction = 1;
209 : }
210 :
211 14275671 : if ( t0 == t0_min ) /* Limit case */
212 : {
213 1756423 : fraction = 0;
214 1756423 : cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
215 : }
216 : else /* Process negative fractions */
217 : {
218 12519248 : t0--;
219 12519248 : cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
220 33700753 : for ( i = ( fraction + step ); i <= pitres - 1; i = i + step )
221 : {
222 21181505 : temp = interpolate_corr( &pt_cor[t0], i, pitres );
223 21181505 : if ( temp > cor_max )
224 : {
225 19913931 : cor_max = temp;
226 19913931 : fraction = i;
227 : }
228 : }
229 : }
230 :
231 67088323 : for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */
232 : {
233 52812652 : temp = interpolate_corr( &pt_cor[t1], i, pitres );
234 52812652 : if ( temp > cor_max )
235 : {
236 14937736 : cor_max = temp;
237 14937736 : fraction = i;
238 14937736 : t0 = t1;
239 : }
240 : }
241 14275671 : *pitch_int = t0;
242 14275671 : *pitch_fr = fraction;
243 14275671 : if ( t0 >= pitfr2 )
244 : {
245 2655953 : *index = t0 * ( pitres >> 1 ) + ( fraction >> 1 ) - ( pitfr2 * ( pitres >> 1 ) ) + ( ( pitfr2 - pitmin ) * pitres );
246 : }
247 : else
248 : {
249 11619718 : *index = t0 * pitres + fraction - ( pitmin * pitres );
250 : }
251 :
252 14275671 : return;
253 : }
254 :
255 :
256 : /*---------------------------------------------------------------------*
257 : * tcx_ltp_find_gain()
258 : *
259 : *
260 : *---------------------------------------------------------------------*/
261 :
262 12906435 : static void tcx_ltp_find_gain(
263 : const float *speech,
264 : float *pred_speech,
265 : const int16_t L_frame,
266 : float *gain,
267 : int16_t *gain_index )
268 : {
269 12906435 : int16_t gainbits = 2;
270 :
271 : /* Find gain */
272 12906435 : *gain = get_gain( speech, pred_speech, L_frame, NULL );
273 :
274 : /* Quantize gain */
275 12906435 : if ( *gain >= 0.875f )
276 : {
277 2360674 : *gain_index = 3; /* 1.00/2 */
278 : }
279 10545761 : else if ( *gain >= 0.625f )
280 : {
281 2822622 : *gain_index = 2; /* 0.75/2 */
282 : }
283 7723139 : else if ( *gain >= 0.375f )
284 : {
285 3328590 : *gain_index = 1; /* 0.50/2 */
286 : }
287 4394549 : else if ( *gain >= 0.125f )
288 : {
289 3547897 : *gain_index = 0; /* 0.25/2 */
290 : }
291 : else
292 : {
293 846652 : *gain_index = -1; /* escape */
294 : }
295 : /* Dequantize gain */
296 12906435 : *gain = (float) ( *gain_index + 1 ) * 0.625f / (float) ( 1 << gainbits );
297 :
298 12906435 : return;
299 : }
300 :
301 : /*---------------------------------------------------------------------*
302 : * tcx_ltp_encode()
303 : *
304 : *
305 : *---------------------------------------------------------------------*/
306 :
307 12906435 : void tcx_ltp_encode(
308 : Encoder_State *st,
309 : const int16_t tcxMode,
310 : const int16_t L_frame,
311 : const float *speech,
312 : float *speech_ltp,
313 : const float *wsp,
314 : const int16_t Top[],
315 : int16_t *ltp_param,
316 : int16_t *ltp_bits,
317 : float *A,
318 : const int16_t disable_ltp,
319 : const int16_t element_mode )
320 : {
321 : int16_t i, j, n;
322 : int16_t ltp_on, tcxOnly, L_subfr, SideInfoOnly, delta;
323 : float s;
324 : float norm_corr;
325 : float pred_speech[L_FRAME_PLUS];
326 : float tempFlatness;
327 : float maxEnergyChange;
328 : float buf_zir[M + L_FRAME_PLUS / 4], *zir;
329 : float r[M + 1], Aest[M + 1];
330 : float alpha, step;
331 : float si_gain;
332 : int16_t border_case;
333 :
334 12906435 : TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
335 :
336 12906435 : tcxOnly = st->tcxonly;
337 12906435 : L_subfr = L_SUBFR;
338 12906435 : SideInfoOnly = st->sr_core > 25600;
339 :
340 : /* Reset memory if past frame is acelp */
341 12906435 : if ( st->last_core == ACELP_CORE )
342 : {
343 122910 : hTcxEnc->tcxltp_pitch_int_past = L_frame;
344 122910 : hTcxEnc->tcxltp_pitch_fr_past = 0;
345 122910 : hTcxEnc->tcxltp_gain_past = 0.f;
346 : }
347 :
348 : /* By default, LTP is off */
349 12906435 : ltp_param[0] = 0;
350 12906435 : norm_corr = 0.0f;
351 12906435 : border_case = 0;
352 :
353 12906435 : if ( hTcxEnc->tcxltp || SideInfoOnly )
354 : {
355 : /* Find pitch lag */
356 12906435 : if ( st->pit_res_max == 6 )
357 : {
358 2023119 : delta = 8;
359 : }
360 : else
361 : {
362 10883316 : delta = 16;
363 : }
364 :
365 12906435 : if ( st->element_mode == IVAS_CPE_MDCT )
366 : {
367 10145551 : if ( abs( Top[0] - Top[1] ) < ( delta / 2 ) )
368 : {
369 : /* estimates are close enough and stable, take the artihmetic mean as estimate */
370 5838195 : tcx_ltp_pitch_search( ( Top[0] + Top[1] ) / 2, &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, <p_param[1], &norm_corr, L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
371 : }
372 : else
373 : {
374 : /* pitch jumps between half frames, calc ltp for both estimates, choose the better one */
375 : int16_t pitch_int_2[2];
376 : int16_t pitch_fr_2[2];
377 : float norm_corr_2[2];
378 : int16_t pit_param_2[2];
379 :
380 12922068 : for ( i = 0; i < 2; i++ )
381 : {
382 8614712 : tcx_ltp_pitch_search( Top[i], &pitch_int_2[i], &pitch_fr_2[i], &pit_param_2[i], &norm_corr_2[i], L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
383 : }
384 :
385 4307356 : i = ( norm_corr_2[1] > norm_corr_2[0] ) ? 1 : 0;
386 4307356 : hTcxEnc->tcxltp_pitch_int = pitch_int_2[i];
387 4307356 : hTcxEnc->tcxltp_pitch_fr = pitch_fr_2[i];
388 4307356 : ltp_param[1] = pit_param_2[i];
389 4307356 : norm_corr = norm_corr_2[i];
390 : }
391 : }
392 : else
393 : {
394 2760884 : tcx_ltp_pitch_search( Top[1], &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, <p_param[1], &norm_corr, L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, ( element_mode > EVS_MONO ) ? 1 : 0, &border_case );
395 : }
396 :
397 12906435 : if ( border_case )
398 : {
399 1076845 : norm_corr = 0.0f;
400 : }
401 12906435 : if ( st->element_mode == IVAS_CPE_DFT )
402 : {
403 338794 : tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, ( NSUBBLOCKS_SHIFT + 1 ) + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
404 :
405 338794 : maxEnergyChange = GetTCXMaxenergyChange( st->hTranDet, tcxMode == TCX_10, NSUBBLOCKS - NSUBBLOCKS_SHIFT, ( NSUBBLOCKS_SHIFT + 1 ) + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * (float) ( hTcxEnc->tcxltp_pitch_int ) / (float) L_frame ) ) );
406 : }
407 : else
408 : {
409 12567641 : tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
410 :
411 12567641 : maxEnergyChange = GetTCXMaxenergyChange( st->hTranDet, tcxMode == TCX_10, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * (float) ( hTcxEnc->tcxltp_pitch_int ) / (float) L_frame ) ) );
412 : }
413 :
414 : /* Switch LTP on */
415 12906435 : if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr * hTcxEnc->tcxltp_norm_corr_past > 0.25f && tempFlatness < 3.5f ) ||
416 12124415 : ( tcxOnly == 1 && tcxMode == TCX_10 && max( norm_corr, hTcxEnc->tcxltp_norm_corr_past ) > 0.5f && maxEnergyChange < 3.5f ) ||
417 : /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < hTcxEnc->tcxltp_pitch_int <=> norm_corr > 1.2f-hTcxEnc->/L_frame */
418 12112074 : ( tcxOnly == 1 && norm_corr > 0.44f && L_frame * ( 1.2f - norm_corr ) < hTcxEnc->tcxltp_pitch_int ) ||
419 10065362 : ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
420 : {
421 5969415 : if ( disable_ltp == 0 )
422 : {
423 5968481 : ltp_param[0] = 1;
424 : }
425 : }
426 :
427 : /* hysteresis for stable ltp prediction */
428 12906435 : ltp_on = 0;
429 12906435 : if ( tcxOnly == 1 && st->element_mode == IVAS_CPE_MDCT && ( ( sqrt( (float) ( hTcxEnc->tcxltp_on_mem ) ) * (norm_corr) *0.9f ) > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
430 : {
431 4670757 : ltp_on = 1;
432 : }
433 :
434 12906435 : if ( tcxOnly == 1 && ltp_param[0] == 1 )
435 : {
436 : /* increase ltp counter */
437 5187395 : hTcxEnc->tcxltp_on_mem = min( 5, hTcxEnc->tcxltp_on_mem + 1 );
438 : }
439 7719040 : else if ( ltp_on == 1 )
440 : {
441 : /* hysteresis takes effect, decrease counter */
442 543560 : hTcxEnc->tcxltp_on_mem = max( 0, hTcxEnc->tcxltp_on_mem - 1 );
443 543560 : ltp_param[0] = ltp_on;
444 : }
445 : else
446 : {
447 : /* no ltp in this frame, reset counter */
448 7175480 : hTcxEnc->tcxltp_on_mem = 0;
449 : }
450 : }
451 :
452 : /* Find predicted signal */
453 12906435 : predict_signal( speech, pred_speech, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, L_frame );
454 :
455 : /* Find gain */
456 12906435 : tcx_ltp_find_gain( speech, pred_speech, L_frame, &hTcxEnc->tcxltp_gain, <p_param[2] );
457 :
458 12906435 : if ( ltp_param[0] )
459 : {
460 : /* Total number of bits for LTP */
461 6512041 : if ( ltp_param[2] + 1 ) /* hTcxEnc->tcxltp_gain > 0 */
462 : {
463 6509840 : *ltp_bits = 12;
464 : }
465 : else /* hTcxEnc->tcxltp_gain <= 0 -> turn off LTP */
466 : {
467 2201 : ltp_param[0] = 0;
468 : }
469 : }
470 :
471 12906435 : if ( !ltp_param[0] )
472 : {
473 : /* No LTP -> set everything to zero */
474 6396595 : hTcxEnc->tcxltp_pitch_int = L_frame;
475 6396595 : hTcxEnc->tcxltp_pitch_fr = 0;
476 6396595 : ltp_param[1] = 0;
477 6396595 : set_zero( pred_speech, L_frame );
478 6396595 : hTcxEnc->tcxltp_gain = 0.f;
479 6396595 : ltp_param[2] = 0;
480 6396595 : if ( hTcxEnc->tcxltp || SideInfoOnly )
481 : {
482 6396595 : *ltp_bits = 1;
483 : }
484 : else
485 : {
486 0 : *ltp_bits = 0;
487 : }
488 : }
489 :
490 12906435 : si_gain = 0;
491 12906435 : if ( SideInfoOnly )
492 : {
493 4902339 : si_gain = hTcxEnc->tcxltp_gain;
494 4902339 : hTcxEnc->tcxltp_gain = 0.f;
495 : }
496 :
497 12906435 : if ( speech_ltp != NULL )
498 : {
499 2422090 : if ( hTcxEnc->tcxltp_gain_past == 0.f && hTcxEnc->tcxltp_gain == 0.f )
500 : {
501 1637628 : mvr2r( speech, speech_ltp, L_subfr );
502 : }
503 784462 : else if ( hTcxEnc->tcxltp_gain_past == 0.f )
504 : {
505 119453 : alpha = 0.f;
506 119453 : step = 1.f / (float) ( L_subfr );
507 7764445 : for ( n = 0; n < L_subfr; n++ )
508 : {
509 7644992 : speech_ltp[n] = speech[n] - alpha * hTcxEnc->tcxltp_gain * pred_speech[n];
510 7644992 : alpha += step;
511 : }
512 : }
513 : else
514 : {
515 665009 : if ( A == NULL )
516 : {
517 11779830 : for ( i = 0; i <= M; i++ )
518 : {
519 11125395 : s = 0.0;
520 3334525435 : for ( j = 0; j < L_frame - i; j++ )
521 : {
522 3323400040 : s += speech[j - L_frame] * speech[j + i - L_frame];
523 : }
524 11125395 : r[i] = s;
525 : }
526 654435 : if ( r[0] < 100.0f )
527 : {
528 3504 : r[0] = 100.0f;
529 : }
530 654435 : r[0] *= 1.0001f;
531 654435 : lev_dur( Aest, r, M, NULL );
532 654435 : A = Aest;
533 : }
534 :
535 665009 : if ( hTcxEnc->tcxltp_gain > 0.f )
536 : {
537 581769 : predict_signal( speech - M, buf_zir, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, M );
538 : }
539 : else
540 : {
541 83240 : set_f( buf_zir, 0.0f, M );
542 : }
543 :
544 11305153 : for ( n = 0; n < M; n++ )
545 : {
546 10640144 : buf_zir[n] = speech_ltp[n - M] - speech[n - M] + hTcxEnc->tcxltp_gain * buf_zir[n];
547 : }
548 :
549 665009 : zir = buf_zir + M;
550 665009 : set_f( zir, 0.0f, L_subfr );
551 665009 : syn_filt( A, M, zir, zir, L_subfr, buf_zir, 0 );
552 665009 : alpha = 1.f;
553 665009 : step = 1.f / (float) ( L_subfr / 2 );
554 :
555 21945297 : for ( n = L_subfr / 2; n < L_subfr; n++ )
556 : {
557 21280288 : zir[n] *= alpha;
558 21280288 : alpha -= step;
559 : }
560 :
561 43225585 : for ( n = 0; n < L_subfr; n++ )
562 : {
563 42560576 : speech_ltp[n] = ( speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n] ) + zir[n];
564 : }
565 : }
566 :
567 2422090 : if ( SideInfoOnly || hTcxEnc->tcxltp_gain == 0.0f )
568 : {
569 682572964 : for ( n = L_subfr; n < L_frame; n++ )
570 : {
571 680852096 : speech_ltp[n] = speech[n];
572 : }
573 : }
574 : else
575 : {
576 170526246 : for ( n = L_subfr; n < L_frame; n++ )
577 : {
578 169825024 : speech_ltp[n] = speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n];
579 : }
580 : }
581 : }
582 :
583 : /* Update */
584 12906435 : hTcxEnc->tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int;
585 12906435 : hTcxEnc->tcxltp_pitch_fr_past = hTcxEnc->tcxltp_pitch_fr;
586 12906435 : hTcxEnc->tcxltp_gain_past = hTcxEnc->tcxltp_gain;
587 :
588 12906435 : if ( SideInfoOnly )
589 : {
590 4902339 : hTcxEnc->tcxltp_gain = si_gain;
591 : }
592 :
593 12906435 : hTcxEnc->tcxltp_norm_corr_past = norm_corr;
594 :
595 12906435 : return;
596 : }
|