Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : /*BASOp version info: This file is up to date with trunk rev. 39929 */
6 :
7 : #include <stdint.h>
8 : #include <stdio.h>
9 : #include <assert.h>
10 : #include "options.h"
11 : #include "prot_fx.h"
12 : #include "basop_util.h"
13 : #include "stl.h"
14 : #include "rom_com.h"
15 : /*-------------------------------------------------------------------*
16 : * decoder_acelp_fx()
17 : *
18 : * Decode ACELP frame MODE2
19 : *-------------------------------------------------------------------*/
20 610 : void decoder_acelp_fx(
21 : Decoder_State *st,
22 : Word16 prm[], /* i : parameters */
23 : Word16 A[], /* i : coefficients NxAz[M+1] */
24 : ACELP_config acelp_cfg, /* i : ACELP config Q12 */
25 : Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */
26 : Word16 *pT, /* o : pitch for all subframe Q0 */
27 : Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */
28 : Word16 stab_fac, /* i : stability of isf */
29 : Word16 *pitch_buffer, /* o : pitch values for each subfr. Q6 */
30 : Word16 *voice_factors, /* o : voicing factors Q15 */
31 : const Word16 LSF_Q_prediction, /* i : LSF prediction mode */
32 : Word16 *bwe_exc /* o : excitation for SWB TBE Q_exc */
33 : )
34 : {
35 : Word16 i, j, i_subfr;
36 : Word16 T0, T0_frac, T0_min, T0_min_frac, T0_max, T0_max_frac, T0_res;
37 : Word16 tmp, tmp2, gain_pit /*Q14*/, Es_pred, tmp_deemph;
38 : Word32 Ltmp, Ltmp2, gain_code;
39 : Word16 code[L_SUBFR];
40 : Word16 mem_syn[M];
41 : Word16 *syn, syn_buf[M + L_FRAME16k + L_FRAME16k / 2];
42 : Word16 *exc, exc_buf[L_EXC_MEM_DEC + L_FRAME16k + 1];
43 : Word16 exc2[L_FRAME_16k];
44 : Word16 *p_A;
45 : Word32 pitch_buf[NB_SUBFR16k];
46 : Word16 dummy_pitch_buf[NB_SUBFR16k];
47 : Word16 gain_inov;
48 : Word16 mem_back[M]; // Q_mem_back
49 : Word16 update_flg;
50 : Word16 Q_mem_back; /*Q format of mem_back*/
51 : Word16 h1[L_FRAME_16k / 4 + 1];
52 : Word16 mem[M];
53 : Word16 *pA;
54 : PulseConfig config;
55 : Word16 weights[5]; /* Q15 */
56 :
57 : Word16 reScaleLen_fx; /* rescaling length for the BWE buffers */
58 : Word16 reSampLen;
59 :
60 : /*Q formats of buffers */
61 : Word16 prev_Q_syn;
62 610 : Word32 gain_code2 = 0;
63 610 : move32();
64 : Word16 code2[L_SUBFR];
65 610 : Word16 error = 0;
66 610 : move16();
67 610 : Word16 gain_preQ = 0; /* Gain of prequantizer excitation */
68 610 : move16();
69 : Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */
70 : Word16 lp_flag;
71 :
72 :
73 : Word16 prev_gain_pit;
74 : Word16 tmp_noise; /* Long term temporary noise energy */
75 : Word32 gain_code_tmp;
76 : Word16 gain_pit_tmp;
77 : Word32 gain_code_pre;
78 : Word16 avoid_lpc_burst_on_recovery;
79 : Word16 force_scale_syn;
80 : TD_BWE_DEC_HANDLE hBWE_TD;
81 : TCX_DEC_HANDLE hTcxDec;
82 :
83 610 : hBWE_TD = st->hBWE_TD;
84 610 : hTcxDec = st->hTcxDec;
85 :
86 610 : gain_code_pre = 0;
87 610 : move16();
88 :
89 :
90 610 : set16_fx( code_preQ, 0, L_SUBFR );
91 :
92 610 : gain_inov = 0; /* to avoid compilation warnings */
93 610 : T0 = 0; /* to avoid compilation warnings */
94 610 : T0_frac = 0; /* to avoid compilation warnings */
95 610 : T0_res = 0; /* to avoid compilation warnings */
96 610 : prev_Q_syn = st->prev_Q_syn = st->Q_syn;
97 610 : move16();
98 610 : move16();
99 610 : move16();
100 610 : move16();
101 610 : move16();
102 610 : move16();
103 610 : gain_pit = 0;
104 610 : gain_code = 0;
105 610 : move16();
106 610 : move16();
107 610 : move16();
108 610 : update_flg = 0;
109 610 : move16();
110 610 : gain_code2 = 0;
111 :
112 610 : prev_gain_pit = 0;
113 610 : move16();
114 610 : tmp_noise = 0;
115 610 : move16();
116 :
117 610 : IF( EQ_16( st->nb_subfr, 4 ) )
118 : {
119 0 : move16();
120 0 : move16();
121 0 : move16();
122 0 : move16();
123 0 : weights[0] = 3277 /*0.1f Q15*/;
124 0 : weights[1] = 6554 /*0.2f Q15*/;
125 0 : weights[2] = 9830 /*0.3f Q15*/;
126 0 : weights[3] = 13107 /*0.4f Q15*/;
127 : }
128 : ELSE /*nb_subfr == 5*/
129 : {
130 610 : move16();
131 610 : move16();
132 610 : move16();
133 610 : move16();
134 610 : move16();
135 610 : weights[0] = 2185 /*(float)1/15 Q15*/;
136 610 : weights[1] = 4369 /*(float)2/15 Q15*/;
137 610 : weights[2] = 6554 /*(float)3/15 Q15*/;
138 610 : weights[3] = 8738 /*(float)4/15 Q15*/;
139 610 : weights[4] = 10923 /*float)5/15 Q15*/;
140 : }
141 610 : st->Mode2_lp_gainp = 0;
142 610 : move32();
143 610 : st->Mode2_lp_gainc = 0;
144 610 : move32();
145 :
146 610 : avoid_lpc_burst_on_recovery = 0;
147 610 : move16();
148 610 : test();
149 610 : test();
150 610 : if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) )
151 : {
152 0 : avoid_lpc_burst_on_recovery = 1;
153 0 : move16();
154 : }
155 :
156 :
157 : /*------------------------------------------------------------------------*
158 : * Previous frame is TCX *
159 : *------------------------------------------------------------------------*/
160 :
161 :
162 : /* Reset phase dispersion */
163 610 : IF( st->last_core_bfi > ACELP_CORE )
164 : {
165 30 : st->dm_fx.prev_gain_code = 0;
166 30 : move32();
167 30 : set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
168 30 : st->dm_fx.prev_state = 0;
169 30 : move16();
170 : }
171 :
172 : /* Update of synthesis filter memories in case of 12k8 core */
173 610 : test();
174 610 : test();
175 610 : IF( st->prev_bfi && st->last_con_tcx && LT_16( st->L_frame, L_FRAME16k ) )
176 : {
177 0 : synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
178 : }
179 :
180 610 : test();
181 610 : IF( st->last_con_tcx && st->old_enr_LP )
182 : {
183 : Word16 enr_LP, ratio;
184 :
185 : /* rescale excitation buffer if LPC energies differs too much */
186 0 : enr_LP = Enr_1_Az_fx( A, L_SUBFR );
187 :
188 0 : IF( LT_16( st->old_enr_LP, enr_LP ) )
189 : {
190 0 : ratio = div_s( st->old_enr_LP, enr_LP ); /* Q15 */
191 0 : IF( LT_16( ratio, 26215 /*.8f in Q15*/ ) )
192 : {
193 0 : FOR( i = 0; i < L_EXC_MEM_DEC; i++ )
194 : {
195 0 : st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); // Q_exc
196 0 : move16();
197 : }
198 : }
199 : }
200 : }
201 :
202 : /*------------------------------------------------------------------------*
203 : * Initialize buffers *
204 : *------------------------------------------------------------------------*/
205 610 : Copy( st->mem_syn2_fx, mem_back, M );
206 610 : move16();
207 610 : Q_mem_back = st->Q_syn;
208 : /* set ACELP synthesis memory */
209 610 : Copy( st->mem_syn2_fx, mem_syn, M );
210 :
211 : /* set excitation memory*/
212 610 : exc = exc_buf + L_EXC_MEM_DEC;
213 610 : Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC );
214 610 : *( exc + st->L_frame ) = 0;
215 610 : move16();
216 : /* Init syn buffer */
217 610 : syn = syn_buf + M;
218 610 : Copy( st->mem_syn2_fx, syn_buf, M );
219 :
220 : /*------------------------------------------------------------------------*
221 : * Fast recovery flag
222 : *------------------------------------------------------------------------*/
223 610 : test();
224 610 : if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) )
225 : {
226 : /*Force BPF to be applied fully*/
227 0 : st->bpf_gain_param = 3;
228 0 : move16();
229 : }
230 :
231 : /*------------------------------------------------------------------------*
232 : * - decode mean_ener_code for gain decoder (d_gain2.c) *
233 : *------------------------------------------------------------------------*/
234 610 : Es_pred = 0;
235 610 : move16();
236 610 : IF( acelp_cfg.nrg_mode > 0 )
237 : {
238 610 : d_gain_pred_fx( acelp_cfg.nrg_mode, &Es_pred, &prm );
239 : }
240 :
241 : /*------------------------------------------------------------------------*
242 : * Loop for every subframe in the analysis frame *
243 : *------------------------------------------------------------------------*
244 : * To find the pitch and innovation parameters. The subframe size is *
245 : * L_subfr and the loop is repeated L_ACELP/L_subfr times. *
246 : * - compute impulse response of weighted synthesis filter (h1[]) *
247 : * - compute the target signal for pitch search *
248 : * - find the closed-loop pitch parameters *
249 : * - encode the pitch delay *
250 : * - update the impulse response h1[] by including fixed-gain pitch *
251 : * - find target vector for codebook search *
252 : * - correlation between target vector and impulse response *
253 : * - codebook search *
254 : * - encode codebook address *
255 : * - VQ of pitch and codebook gains *
256 : * - find synthesis speech *
257 : * - update states of weighting filter *
258 : *------------------------------------------------------------------------*/
259 :
260 610 : p_A = A;
261 :
262 3660 : FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
263 : {
264 :
265 3050 : Word16 idx = 0;
266 3050 : IF( i_subfr != 0 )
267 : {
268 2440 : idx = idiv1616( i_subfr, L_SUBFR );
269 : }
270 :
271 3050 : test();
272 3050 : IF( EQ_16( st->use_partial_copy, 1 ) && EQ_16( st->rf_frame_type, RF_NELP ) )
273 : {
274 0 : IF( i_subfr == 0 )
275 : {
276 0 : decod_nelp_fx( st, &tmp_noise, dummy_pitch_buf, exc, exc2, voice_factors, bwe_exc, &st->Q_exc, st->bfi, pgainT );
277 0 : set32_fx( pitch_buf, L_SUBFR_Q16, NB_SUBFR );
278 0 : set16_fx( pitch_buffer, 4096, NB_SUBFR ); /* L_SUBFR_Q16 in Q6 */
279 : }
280 : }
281 : ELSE
282 : {
283 :
284 : /*-------------------------------------------------------*
285 : * - Decode adaptive codebook. *
286 : *-------------------------------------------------------*/
287 :
288 3050 : test();
289 3050 : if ( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 )
290 : {
291 0 : gain_pit = prev_gain_pit;
292 0 : move16();
293 : }
294 :
295 3050 : IF( acelp_cfg.ltp_bits != 0 )
296 : {
297 : /* pitch lag decoding */
298 6100 : pitch_buf[idx] = Mode2_pit_decode( acelp_cfg.ltp_mode, i_subfr, L_SUBFR, &prm, &T0, &T0_frac, &T0_res,
299 3050 : &T0_min, &T0_min_frac, &T0_max, &T0_max_frac, st->pit_min, st->pit_fr1, st->pit_fr1b, st->pit_fr2, st->pit_max, st->pit_res_max );
300 3050 : move32();
301 : /* find pitch excitation */
302 3050 : test();
303 3050 : IF( EQ_16( st->pit_res_max, 6 ) && !( st->use_partial_copy ) )
304 : {
305 3050 : IF( EQ_16( T0_res, shr( st->pit_res_max, 1 ) ) )
306 : {
307 2940 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl( T0_frac, 1 ), L_SUBFR + 1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 );
308 : }
309 : ELSE
310 : {
311 110 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter6_2, PIT_L_INTERPOL6_2, PIT_UP_SAMP6 );
312 : }
313 : }
314 : ELSE
315 : {
316 0 : IF( EQ_16( T0_res, shr( st->pit_res_max, 1 ) ) )
317 : {
318 0 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, shl( T0_frac, 1 ), L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
319 : }
320 : ELSE
321 : {
322 0 : pred_lt4( &exc[i_subfr], &exc[i_subfr], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP );
323 : }
324 : }
325 :
326 : /* LP filtering of the adaptive excitation*/
327 3050 : lp_flag = acelp_cfg.ltf_mode;
328 3050 : move16();
329 :
330 3050 : IF( EQ_16( acelp_cfg.ltf_mode, NORMAL_OPERATION ) )
331 : {
332 1340 : lp_flag = *prm;
333 1340 : move16();
334 1340 : prm++;
335 : }
336 :
337 3050 : lp_filt_exc_dec_fx( st, MODE2, i_subfr, L_SUBFR, st->L_frame, lp_flag, exc );
338 : }
339 : ELSE
340 : {
341 : /* No adaptive codebook (UC) */
342 0 : set16_fx( &exc[i_subfr], 0, L_SUBFR );
343 :
344 0 : T0 = L_SUBFR;
345 0 : move16();
346 0 : T0_frac = 0;
347 0 : move16();
348 0 : T0_res = 1;
349 0 : move16();
350 0 : pitch_buf[idx] = L_deposit_h( L_SUBFR ); // Q16
351 0 : move32();
352 : }
353 :
354 3050 : IF( st->igf != 0 )
355 : {
356 3050 : tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc );
357 : }
358 :
359 3050 : pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6
360 3050 : move16();
361 :
362 : /*-------------------------------------------------------*
363 : * - Decode innovative codebook. *
364 : *-------------------------------------------------------*/
365 3050 : test();
366 3050 : test();
367 3050 : test();
368 3050 : test();
369 3050 : IF( EQ_16( st->use_partial_copy, 1 ) &&
370 : ( EQ_16( st->rf_frame_type, RF_ALLPRED ) ||
371 : ( EQ_16( st->rf_frame_type, RF_GENPRED ) &&
372 : ( EQ_16( i_subfr, L_SUBFR ) || EQ_16( i_subfr, 3 * L_SUBFR ) ) ) ) )
373 : {
374 0 : set16_fx( code, 0, L_SUBFR );
375 : }
376 : ELSE
377 : {
378 3050 : config = PulseConfTable[acelp_cfg.fixed_cdk_index[idx]];
379 3050 : D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, prm, &st->BER_detect );
380 3050 : ( prm ) += 8;
381 : /*-------------------------------------------------------*
382 : * - Add the fixed-gain pitch contribution to code[]. *
383 : *-------------------------------------------------------*/
384 :
385 3050 : cb_shape_fx( acelp_cfg.pre_emphasis, acelp_cfg.pitch_sharpening, acelp_cfg.phase_scrambling, acelp_cfg.formant_enh, acelp_cfg.formant_tilt,
386 3050 : acelp_cfg.formant_enh_num, acelp_cfg.formant_enh_den, p_A, code, st->tilt_code_fx, extract_h( L_add( pitch_buf[i_subfr / L_SUBFR], 26216 ) ), 1, L_SUBFR );
387 : }
388 : /*-------------------------------------------------------*
389 : * - Generate Gaussian excitation *
390 : *-------------------------------------------------------*/
391 3050 : test();
392 3050 : IF( EQ_16( acelp_cfg.gains_mode[idx], 7 ) && !st->use_partial_copy )
393 : {
394 0 : gaus_L2_dec( code2, st->tilt_code_fx, p_A, acelp_cfg.formant_enh_num, &( st->seed_acelp ) );
395 : }
396 : ELSE
397 : {
398 3050 : gain_code2 = 0;
399 3050 : move32();
400 3050 : set16_fx( code2, 0, L_SUBFR );
401 : }
402 :
403 : /*-------------------------------------------------*
404 : * - Decode codebooks gains. *
405 : *-------------------------------------------------*/
406 3050 : IF( st->acelp_cfg.gains_mode[idx] != 0 )
407 : {
408 3050 : decode_acelp_gains_fx( code, acelp_cfg.gains_mode[idx], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ),
409 : &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 );
410 : }
411 3050 : test();
412 3050 : if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_ALLPRED ) )
413 : {
414 0 : st->past_gcode = 0;
415 0 : move32();
416 : }
417 3050 : test();
418 3050 : if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_NOPRED ) )
419 : {
420 0 : st->past_gpit = 67; //.004089f in Q14
421 0 : move32();
422 : }
423 3050 : IF( st->igf != 0 )
424 : {
425 : /* Rescaling for 12.8k and 16k cores related to BWE */
426 3050 : IF( EQ_16( st->L_frame, L_FRAME ) )
427 : {
428 : /* 5/2 times resampled past memories*/
429 0 : reScaleLen_fx = add( shl( i_subfr, 1 ), shr( i_subfr, 1 ) );
430 0 : reSampLen = ( L_SUBFR * HIBND_ACB_L_FAC );
431 0 : move16();
432 : }
433 : ELSE
434 : {
435 : /* 2 times resampled past memories*/
436 3050 : reScaleLen_fx = shl( i_subfr, 1 );
437 3050 : reSampLen = ( L_SUBFR * 2 );
438 3050 : move16();
439 : }
440 :
441 3050 : Rescale_exc( NULL, &exc[i_subfr], &bwe_exc[reScaleLen_fx],
442 3050 : NULL, L_SUBFR, reSampLen, gain_code, &( st->Q_exc ), st->Q_subfr,
443 : exc2, i_subfr, GENERIC );
444 : }
445 : ELSE
446 : {
447 0 : Rescale_exc( NULL, &exc[i_subfr], NULL, NULL, L_SUBFR, 0,
448 0 : gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, GENERIC );
449 : }
450 :
451 : /*----------------------------------------------------------*
452 : * Update parameters for the next subframe. *
453 : * - tilt of code: 0.0 (unvoiced) to 0.5 (voiced) *
454 : *----------------------------------------------------------*/
455 3050 : E_UTIL_voice_factor( exc, i_subfr, code, gain_pit, gain_code, &( st->voice_fac ), &( st->tilt_code_fx ), L_SUBFR, acelp_cfg.voice_tilt, st->Q_exc, 0 );
456 :
457 3050 : pgainT[idx] = gain_pit;
458 3050 : move16();
459 :
460 : /*-------------------------------------------------------*
461 : * - Find the total excitation. *
462 : *-------------------------------------------------------*/
463 3050 : gain_code_tmp = gain_code;
464 3050 : move32();
465 3050 : gain_pit_tmp = gain_pit;
466 3050 : move16();
467 3050 : if ( i_subfr == 0 )
468 : {
469 610 : gain_code_pre = 0;
470 610 : move32();
471 : }
472 3050 : test();
473 3050 : test();
474 3050 : test();
475 3050 : IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) )
476 : {
477 0 : test();
478 0 : test();
479 0 : test();
480 0 : test();
481 0 : test();
482 0 : test();
483 0 : test();
484 0 : test();
485 0 : IF( i_subfr > 0 && GT_16( gain_pit, 20152 /*1.23 in Q14*/ ) && GT_16( st->prev_tilt_code_dec_fx, 6553 /*1.23 in Q15*/ ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) )
486 : {
487 0 : gain_pit = mult( gain_pit, sub( 26214 /*.8f in Q15*/, mult( i_subfr, 51 /*1.0f/640 in Q15*/ ) ) );
488 : }
489 0 : ELSE IF( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && NE_16( st->next_coder_type, UNVOICED ) && LT_32( gain_code, gain_code_pre ) )
490 :
491 : {
492 0 : gain_code = 0;
493 0 : move32();
494 : }
495 : }
496 3050 : gain_code_pre = gain_code;
497 3050 : move32();
498 3050 : st->tilt_code_dec_fx[idx] = st->tilt_code_fx;
499 3050 : move16();
500 :
501 :
502 3050 : tmp2 = shr( L_SUBFR, 1 );
503 9150 : FOR( j = 0; j < 2; j++ )
504 : {
505 201300 : FOR( i = ( tmp2 - ( L_SUBFR / 2 ) ); i < tmp2; i++ )
506 : {
507 : /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */
508 195200 : Ltmp = Mpy_32_16_1( gain_code2, code2[i] );
509 195200 : Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) );
510 195200 : Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] );
511 195200 : exc2[( i + i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) );
512 195200 : move16();
513 195200 : Ltmp2 = Mpy_32_16_1( gain_code, code[i] );
514 195200 : Ltmp2 = L_shl( Ltmp2, add( 5, st->Q_exc ) );
515 195200 : Ltmp = L_add( Ltmp, Ltmp2 );
516 : BASOP_SATURATE_WARNING_OFF_EVS
517 195200 : Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */
518 : BASOP_SATURATE_WARNING_ON_EVS
519 195200 : exc[( i + i_subfr )] = round_fx_sat( Ltmp );
520 195200 : move16();
521 : }
522 6100 : tmp2 = L_SUBFR;
523 6100 : move16();
524 : }
525 :
526 : /*-----------------------------------------------------------------*
527 : * Prepare TBE excitation
528 : *-----------------------------------------------------------------*/
529 3050 : gain_code = gain_code_tmp;
530 3050 : move32();
531 3050 : gain_pit = gain_pit_tmp;
532 3050 : move16();
533 3050 : IF( st->igf != 0 )
534 : {
535 : #ifdef REMOVE_EVS_DUPLICATES
536 3050 : prep_tbe_exc_ivas_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc,
537 3050 : gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 );
538 : #else
539 : prep_tbe_exc_fx( st->L_frame,
540 : i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc,
541 : gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate );
542 : #endif
543 : }
544 :
545 : /*---------------------------------------------------------*
546 : * Enhance the excitation *
547 : *---------------------------------------------------------*/
548 3050 : E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold_fx ), code, &exc2[i_subfr],
549 3050 : gain_pit, &st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, &st->dm_fx.prev_state, st->coder_type,
550 3050 : acelp_cfg.fixed_cdk_index[idx], L_SUBFR, st->L_frame, st->Q_exc );
551 :
552 : } /* !RF_NELP frame partial copy */
553 : /*----------------------------------------------------------*
554 : * - compute the synthesis speech *
555 : *----------------------------------------------------------*/
556 3050 : rescale_mem( &st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr );
557 :
558 3050 : E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M );
559 :
560 : /*-----------------------------------------------------------------*
561 : * update lp_filtered gains for the case of frame erasure
562 : *-----------------------------------------------------------------*/
563 :
564 3050 : st->Mode2_lp_gainp = L_add( st->Mode2_lp_gainp, L_mult0( st->past_gpit, weights[idx] ) ); /* 2Q29=1Q14*Q15 */
565 3050 : move32();
566 3050 : st->Mode2_lp_gainc = L_add( st->Mode2_lp_gainc, Mpy_32_16_1( st->past_gcode, weights[idx] ) ); /* 15Q16=15Q16*Q15 */
567 3050 : move32();
568 :
569 : /*----------------------------------------------------------*
570 : * - update pitch lag for guided ACELP *
571 : *----------------------------------------------------------*/
572 3050 : test();
573 3050 : if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) )
574 : {
575 610 : st->T0_4th = T0;
576 610 : move16();
577 : }
578 :
579 : /*----------------------------------------------------------*
580 : * - Update LPC coeffs *
581 : *----------------------------------------------------------*/
582 3050 : p_A += ( M + 1 );
583 :
584 : /* copy current gain for next subframe use, in case there is no explicit encoding */
585 3050 : prev_gain_pit = gain_pit;
586 3050 : move16();
587 : } /* end of subframe loop */
588 :
589 610 : IF( st->BER_detect )
590 : {
591 0 : FOR( i = 0; i < st->L_frame; i++ )
592 : {
593 0 : exc[i] = 0;
594 0 : move16();
595 : }
596 :
597 0 : int_lsp_fx( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 );
598 :
599 0 : p_A = st->Aq_cng;
600 0 : IF( LT_16( st->last_good, UNVOICED_TRANSITION ) )
601 : {
602 0 : Copy( st->mem_syn2_fx, mem_syn, M );
603 : }
604 : ELSE
605 : {
606 0 : set16_fx( mem_syn, 0, M );
607 : }
608 :
609 0 : FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
610 : {
611 0 : E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M );
612 0 : p_A += ( M + 1 );
613 : }
614 : }
615 :
616 610 : tmp = 0;
617 610 : move16();
618 610 : pA = A + ( st->nb_subfr - 1 ) * ( M + 1 );
619 610 : set16_fx( h1, 0, add( L_SUBFR, 1 ) );
620 610 : set16_fx( mem, 0, M );
621 610 : h1[0] = 32768 / 32;
622 610 : move16();
623 610 : E_UTIL_synthesis( 0, pA, h1, h1, L_SUBFR, mem, 0, M ); /* impulse response of LPC */
624 610 : deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */
625 : /* impulse response level = gain introduced by synthesis+deemphasis */
626 610 : Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e );
627 610 : st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ );
628 610 : move16();
629 610 : st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); // Q(15-last_gain_syn_deemph_e - (16))
630 610 : move16();
631 :
632 : /* Do the classification */
633 : {
634 : Word16 pit16[NB_SUBFR16k];
635 : Word16 k;
636 3660 : FOR( k = 0; k < st->nb_subfr; k++ )
637 : {
638 3050 : pit16[k] = shl( extract_h( pitch_buf[k] ), 6 ); /*Q6*/
639 3050 : move16();
640 : }
641 :
642 610 : FEC_clas_estim_fx( st, /*Opt_AMR_WB*/ 0, st->L_frame, &( st->clas_dec ), st->core_ext_mode, pit16, syn,
643 : &st->lp_ener_FER_fx, /**decision_hyst*/ NULL, /**UV_cnt*/ NULL, /**LT_UV_cnt*/ NULL, /**Last_ener*/ NULL, /**locattack*/ NULL,
644 610 : /**lt_diff_etot*/ NULL, /**amr_io_class*/ NULL, st->Q_syn, /**class_para*/ NULL, st->mem_syn_clas_estim_fx,
645 : &st->classifier_Q_mem_syn, -32768 /*-1.f Q15*/, 0 /*CLASSIFIER_ACELP*/, 0 /*bfi*/, st->last_core_brate, -1 );
646 : }
647 :
648 : /* Update Pitch Lag memory */
649 :
650 610 : Copy32( &st->old_pitch_buf_fx[st->nb_subfr], st->old_pitch_buf_fx, st->nb_subfr );
651 610 : Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr );
652 :
653 :
654 : {
655 : Word16 pBuf_scaleSyn[NB_SUBFR16k];
656 610 : Word16 L_frame_fr = 0;
657 610 : IF( st->L_frame != 0 )
658 : {
659 610 : L_frame_fr = idiv1616( st->L_frame, L_SUBFR );
660 : }
661 :
662 3660 : FOR( i = 0; i < L_frame_fr; i++ )
663 : {
664 3050 : pBuf_scaleSyn[i] = round_fx( pitch_buf[i] );
665 3050 : move16();
666 : }
667 :
668 610 : Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); // Q_syn
669 :
670 610 : force_scale_syn = 0;
671 610 : move16();
672 :
673 610 : test();
674 610 : test();
675 610 : if ( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) )
676 : {
677 503 : force_scale_syn = 1;
678 503 : move16();
679 : }
680 :
681 : #ifdef REMOVE_EVS_DUPLICATES
682 610 : FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0,
683 610 : st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
684 610 : exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, force_scale_syn );
685 : #else
686 : FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0,
687 : st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
688 : exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, force_scale_syn );
689 : #endif
690 : }
691 : /* update ACELP synthesis memory */
692 610 : Copy( mem_syn, st->mem_syn2_fx, M );
693 610 : Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
694 :
695 : /* Deemphasis and output synth and ZIR */
696 610 : tmp_deemph = st->syn[M];
697 610 : move16();
698 610 : E_UTIL_deemph2( st->Q_syn, syn, st->preemph_fac, st->L_frame, &tmp_deemph ); /* tmp_deemph and syn in Q0 starting from here*/
699 :
700 610 : bufferCopyFx( syn + shr( st->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ );
701 :
702 610 : Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Q0*/
703 :
704 610 : Copy( syn, synth, st->L_frame );
705 610 : IF( st->hBWE_TD != NULL )
706 : {
707 610 : Copy( syn, hBWE_TD->old_core_synth_fx, st->L_frame );
708 : }
709 :
710 :
711 : /* update old_Aq */
712 610 : Copy( exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC );
713 :
714 : /* Output pitch parameters for bass post-filter */
715 3660 : FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR )
716 : {
717 3050 : Word16 idx = 0;
718 3050 : move16();
719 3050 : IF( i_subfr != 0 )
720 : {
721 2440 : idx = idiv1616( i_subfr, L_SUBFR );
722 : }
723 3050 : *pT++ = round_fx( pitch_buf[idx] ); // Q0
724 : }
725 :
726 :
727 610 : hTcxDec->tcxltp_last_gain_unmodified = 0;
728 610 : move16();
729 :
730 : /*Update MODE1*/
731 610 : Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 );
732 610 : st->old_Es_pred_fx = Es_pred;
733 610 : move16();
734 :
735 610 : hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch;
736 610 : move32();
737 610 : hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
738 610 : move32();
739 610 : st->old_fpitch = pitch_buf[( ( st->L_frame >> 6 ) - 1 )];
740 610 : move32();
741 :
742 :
743 610 : return;
744 : }
|