Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include <assert.h> /* Debug prototypes */
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 : #include "basop_util.h" /* Function prototypes */
11 :
12 : /*--------------------------------------------------------------------------*
13 : * evs_dec_fx()
14 : *
15 : * Principal decoder routine
16 : *--------------------------------------------------------------------------*/
17 :
18 3100 : ivas_error evs_dec_fx(
19 : Decoder_State *st_fx, /* i/o : Decoder state structure */
20 : Word16 output_sp[], /* o : output synthesis signal Q0*/
21 : FRAME_MODE frameMode /* i : Decoder frame mode */
22 : )
23 : {
24 : Word16 i, j, output_frame;
25 : Word16 sharpFlag;
26 : Word16 tmps, incr;
27 : Word16 core_switching_flag;
28 : Word16 unbits;
29 : Word16 hq_core_type;
30 : Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET];
31 : Word16 voice_factors_fx[NB_SUBFR16k];
32 : Word16 hb_synth_fx[L_FRAME48k];
33 : Word16 hb_synth_fx_exp;
34 : Word32 L_tmp;
35 : Word16 exp, fra;
36 : Word16 tmp_buffer_fx[L_FRAME48k];
37 : Word16 tmp16, tmp16_2;
38 : Word16 synth_fx[L_FRAME48k];
39 : Word16 fb_exc_fx[L_FRAME16k];
40 3100 : Word16 pitch_buf_fx[NB_SUBFR16k] = { 0 };
41 : Word16 Q_fb_exc;
42 : Word16 old_syn_12k8_16k_fx[L_FRAME16k];
43 3100 : Word16 sid_bw = -1;
44 : Word16 pcmbufFB[L_FRAME_MAX];
45 : Word32 workBuffer[128 * 3];
46 : Word16 delta;
47 : Word16 nab;
48 : Word16 concealWholeFrame;
49 3100 : Word16 concealWholeFrameTmp = -1;
50 : Word16 delay_comp, delay_tdbwe;
51 :
52 : Word16 Qpostd;
53 : Word16 Q_synth;
54 : Word16 Qpostd_prev;
55 :
56 : Word16 timeIn_e;
57 : TD_BWE_DEC_HANDLE hBWE_TD;
58 : HQ_DEC_HANDLE hHQ_core;
59 : TCX_LTP_DEC_HANDLE hTcxLtpDec;
60 : TCX_DEC_HANDLE hTcxDec;
61 : ivas_error error;
62 :
63 3100 : push_wmops( "evs_dec_fx" );
64 :
65 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
66 3100 : Flag Overflow = 0;
67 3100 : move16();
68 : #endif
69 3100 : hBWE_TD = st_fx->hBWE_TD;
70 3100 : hHQ_core = st_fx->hHQ_core;
71 3100 : hTcxLtpDec = st_fx->hTcxLtpDec;
72 3100 : hTcxDec = st_fx->hTcxDec;
73 3100 : error = IVAS_ERR_OK;
74 3100 : move16();
75 3100 : move16();
76 3100 : move16();
77 :
78 3100 : timeIn_e = 0;
79 3100 : move16();
80 :
81 3100 : delay_tdbwe = 0; /* for compiler warning*/
82 3100 : move16();
83 3100 : Qpostd = 0;
84 3100 : move16(); /* default and used for MODE2 */
85 3100 : concealWholeFrame = -1;
86 3100 : move16();
87 :
88 : /*------------------------------------------------------------------*
89 : * Initialization
90 : *-----------------------------------------------------------------*/
91 :
92 3100 : st_fx->idchan = 0;
93 3100 : move16();
94 3100 : st_fx->element_brate = st_fx->total_brate; /*Q0*/
95 3100 : move32();
96 3100 : st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 );
97 :
98 3100 : if ( st_fx->bfi == 0 )
99 : {
100 3100 : st_fx->extl = -1;
101 3100 : move16();
102 : }
103 :
104 3100 : output_frame = st_fx->output_frame_fx; /*Q0*/
105 3100 : move16();
106 :
107 3100 : core_switching_flag = 0;
108 3100 : move16();
109 3100 : sharpFlag = 0;
110 3100 : move16();
111 3100 : unbits = 0;
112 3100 : move16();
113 :
114 3100 : st_fx->use_partial_copy = 0;
115 3100 : move16();
116 3100 : st_fx->rf_flag = 0;
117 3100 : move16();
118 :
119 3100 : Qpostd_prev = st_fx->Qprev_synth_buffer_fx;
120 3100 : move16();
121 :
122 3100 : IF( EQ_16( st_fx->bfi, 1 ) )
123 : {
124 0 : hq_core_type = hHQ_core->last_hq_core_type; /*Q0*/
125 0 : move16();
126 0 : st_fx->coder_type = st_fx->last_coder_type; /*Q0*/
127 0 : move16();
128 : }
129 : ELSE
130 : {
131 3100 : hq_core_type = -1;
132 3100 : move16();
133 3100 : st_fx->coder_type = INACTIVE;
134 3100 : move16();
135 : }
136 :
137 :
138 : /* PLC: [TCX: Fade-out-recovery]
139 : * PLC: overlapping part needs to be attenuated for first good frame */
140 3100 : test();
141 3100 : test();
142 3100 : test();
143 3100 : test();
144 3100 : IF( !st_fx->bfi && st_fx->prev_bfi && ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) )
145 : {
146 : /* v_multc(st_fx->old_out_fx, st_fx->hPlcInfo.recovery_gain, st_fx->old_out_fx, st_fx->L_frameTCX); */
147 0 : FOR( i = 0; i < hTcxDec->L_frameTCX; i++ )
148 : {
149 0 : hHQ_core->old_out_fx[i] = shl_sat( mult_r( hHQ_core->old_out_fx[i], st_fx->hPlcInfo->recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/
150 0 : move16();
151 : }
152 0 : FOR( i = 0; i < st_fx->L_frame; i++ )
153 : {
154 0 : hHQ_core->old_out_LB_fx[i] = shl_sat( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->hPlcInfo->recovery_gain ), 1 ); /*hHQ_core->exp_old_out*/
155 0 : move16();
156 : }
157 : /* attenuate PLC buffers, if no aldo window
158 : is used and if no sid or zero frame is received */
159 0 : IF( st_fx->hTcxCfg->last_aldo == 0 )
160 : {
161 : Word32 f;
162 : Word16 s;
163 : Word16 tmp1;
164 0 : f = L_deposit_l( hTcxDec->conceal_eof_gain ); /*Q14*/
165 0 : s = norm_l( f );
166 0 : s = sub( 16, s );
167 0 : tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/
168 0 : FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ )
169 : {
170 0 : hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); /*hTcxDec->Q_syn_Overl*/
171 0 : move16();
172 : }
173 0 : s = norm_l( f );
174 0 : s = sub( 16, s );
175 0 : tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/
176 0 : FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_length; i++ )
177 : {
178 0 : hTcxDec->syn_Overl[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_Overl[i] ), s ); /*hTcxDec->Q_syn_Overl*/
179 0 : move16();
180 : }
181 : }
182 : }
183 :
184 3100 : set16_fx( voice_factors_fx, 0, NB_SUBFR16k );
185 3100 : set16_fx( hb_synth_fx, 0, L_FRAME48k );
186 3100 : hb_synth_fx_exp = 0;
187 3100 : move16();
188 :
189 3100 : st_fx->rate_switching_reset = 0;
190 3100 : move16();
191 :
192 3100 : if ( !st_fx->bfi )
193 : {
194 3100 : st_fx->flagGuidedAcelp = 0;
195 3100 : move16();
196 : }
197 :
198 : /*----------------------------------------------------------------*
199 : * Updates in case of AMR-WB IO mode -> EVS primary switching
200 : *----------------------------------------------------------------*/
201 :
202 3100 : IF( EQ_16( st_fx->last_core, AMR_WB_CORE ) )
203 : {
204 0 : updt_IO_switch_dec_fx( output_frame, st_fx );
205 : }
206 :
207 3100 : IF( NE_16( frameMode, FRAMEMODE_MISSING ) ) /* frame mode normal or future frame */
208 : {
209 3100 : getPartialCopyInfo( st_fx, &st_fx->coder_type, &sharpFlag );
210 3100 : frameMode = st_fx->bfi; /*Q0*/
211 3100 : move16();
212 : }
213 :
214 3100 : test();
215 3100 : IF( EQ_16( st_fx->rf_frame_type, RF_NO_DATA ) && EQ_16( st_fx->use_partial_copy, 1 ) )
216 : {
217 : /* the partial copy is a RF FRAME_NO_DATA frame and should follow the concealment path*/
218 0 : st_fx->bfi = 1;
219 0 : move16();
220 0 : st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/
221 0 : move16();
222 0 : frameMode = FRAMEMODE_MISSING;
223 0 : move16();
224 0 : st_fx->use_partial_copy = 0;
225 0 : move16();
226 : }
227 :
228 : /* if previous frame was concealed via ACELP, drop TCX partial copy info and continue ACELP concealment */
229 3100 : test();
230 3100 : test();
231 3100 : test();
232 3100 : IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->core, TCX_20_CORE ) &&
233 : EQ_16( st_fx->prev_bfi, 1 ) && EQ_16( st_fx->last_core, ACELP_CORE ) )
234 : {
235 0 : st_fx->bfi = 1;
236 0 : move16();
237 0 : st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/
238 0 : move16();
239 0 : frameMode = FRAMEMODE_MISSING;
240 0 : move16();
241 0 : st_fx->use_partial_copy = 0;
242 0 : move16();
243 0 : st_fx->core = ACELP_CORE;
244 0 : move16();
245 : }
246 :
247 : /* if previous frame was HQ Core or TCX10, drop partial copy info and continue HQ Core/TCX10 concealment */
248 3100 : test();
249 3100 : test();
250 3100 : test();
251 3100 : test();
252 3100 : IF( st_fx->use_partial_copy && ( ( sub( st_fx->last_core, HQ_CORE ) == 0 ) || ( sub( st_fx->last_core, TCX_10_CORE ) == 0 ) || ( ( sub( st_fx->last_core, TCX_20_CORE ) == 0 ) && getTcxonly( /*EVS_MONO, */ st_fx->last_total_brate /*, 0, 0*/ ) ) ) )
253 : {
254 0 : st_fx->bfi = 1;
255 0 : move16();
256 0 : st_fx->codec_mode = st_fx->last_codec_mode; /*Q0*/
257 0 : move16();
258 0 : frameMode = FRAMEMODE_MISSING;
259 0 : move16();
260 0 : st_fx->use_partial_copy = 0;
261 0 : move16();
262 0 : st_fx->core = st_fx->last_core;
263 0 : move16();
264 : }
265 :
266 : /*------------------------------------------------------------------*
267 : * Decoding
268 : *-----------------------------------------------------------------*/
269 :
270 3100 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
271 : {
272 : /*------------------------------------------------------------------*
273 : * Decision matrix (selection of technologies)
274 : *-----------------------------------------------------------------*/
275 :
276 1852 : IF( NE_16( st_fx->bfi, 1 ) )
277 : {
278 1852 : decision_matrix_dec_fx( st_fx, &sharpFlag, &hq_core_type, &core_switching_flag );
279 1852 : IF( NE_16( st_fx->bfi, 1 ) )
280 : {
281 1852 : st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); /*Q0*/
282 1852 : st_fx->fscale_old = st_fx->fscale; /*Q0*/
283 1852 : move16();
284 1852 : st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /*Q0*/
285 : }
286 : ELSE
287 : {
288 0 : frameMode = FRAMEMODE_MISSING; /*Q0*/
289 0 : move16();
290 : }
291 : }
292 : }
293 :
294 3100 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
295 : {
296 : /*------------------------------------------------------------------*
297 : * Initialization
298 : *-----------------------------------------------------------------*/
299 :
300 1852 : IF( EQ_16( st_fx->bfi, 1 ) )
301 : {
302 0 : st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 );
303 : }
304 : ELSE
305 : {
306 1852 : st_fx->nbLostCmpt = 0;
307 1852 : move16();
308 : }
309 1852 : st_fx->enablePlcWaveadjust = 0;
310 1852 : move16();
311 :
312 : /*---------------------------------------------------------------------*
313 : * Detect bandwidth switching
314 : *---------------------------------------------------------------------*/
315 :
316 1852 : bandwidth_switching_detect_fx( st_fx );
317 :
318 : /*---------------------------------------------------------------------*
319 : * Preprocessing (preparing) for ACELP/HQ core switching
320 : *---------------------------------------------------------------------*/
321 :
322 1852 : IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK )
323 : {
324 0 : return error;
325 : }
326 :
327 : /*---------------------------------------------------------------------*
328 : * ACELP core decoding
329 : * HQ core decoding
330 : *---------------------------------------------------------------------*/
331 :
332 1852 : IF( EQ_16( st_fx->core, ACELP_CORE ) )
333 : {
334 : /* ACELP core decoder */
335 : #ifdef REMOVE_EVS_DUPLICATES
336 1423 : IF( ( error = acelp_core_dec_ivas_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK )
337 : #else
338 : IF( ( error = acelp_core_dec_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK )
339 : #endif
340 : {
341 0 : return error;
342 : }
343 1423 : Qpostd = st_fx->Q_syn2;
344 1423 : move16();
345 : }
346 : ELSE
347 : {
348 429 : hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag );
349 429 : Qpostd = Q_synth;
350 429 : move16();
351 : }
352 :
353 : /*---------------------------------------------------------------------*
354 : * Postprocessing for ACELP/HQ core switching
355 : *---------------------------------------------------------------------*/
356 :
357 1852 : if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK )
358 : {
359 0 : return error;
360 : }
361 :
362 : /*---------------------------------------------------------------------*
363 : * Pre-processing for bandwidth switching
364 : *---------------------------------------------------------------------*/
365 :
366 1852 : bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx );
367 :
368 : /*---------------------------------------------------------------------*
369 : * WB TBE decoding
370 : * WB BWE decoding
371 : *---------------------------------------------------------------------*/
372 :
373 1852 : IF( EQ_16( st_fx->extl, WB_TBE ) )
374 : {
375 : /* WB TBE decoder */
376 0 : wb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp );
377 : }
378 1852 : ELSE IF( EQ_16( st_fx->extl, WB_BWE ) && st_fx->bws_cnt == 0 )
379 : {
380 : /* WB BWE decoder */
381 0 : hb_synth_fx_exp = wb_bwe_dec_fx( synth_fx, hb_synth_fx, output_frame, voice_factors_fx, pitch_buf_fx, st_fx, &Qpostd ); /*Q0*/
382 : }
383 :
384 : /*---------------------------------------------------------------------*
385 : * SWB TBE decoding
386 : * SWB BWE decoding
387 : * FB TBE decoding
388 : *---------------------------------------------------------------------*/
389 1852 : test();
390 1852 : test();
391 1852 : test();
392 1852 : test();
393 1852 : test();
394 1852 : test();
395 1852 : test();
396 1852 : test();
397 1852 : test();
398 1852 : test();
399 1852 : test();
400 1852 : test();
401 1852 : test();
402 1852 : test();
403 1852 : test();
404 1852 : test();
405 1852 : test();
406 1852 : test();
407 1852 : test();
408 1852 : test();
409 1852 : IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) )
410 : {
411 : /* SWB TBE decoder */
412 748 : swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx,
413 : old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx );
414 :
415 : /* FB TBE decoder */
416 748 : test();
417 748 : IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) )
418 : {
419 0 : fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp );
420 : }
421 : }
422 1104 : ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ||
423 : ( GE_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->core, ACELP_CORE ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) )
424 : {
425 : /* SWB BWE decoder */
426 6 : hb_synth_fx_exp = swb_bwe_dec_fx( st_fx, synth_fx, hb_synth_fx, output_frame, &Qpostd ); /*Q0*/
427 : }
428 1098 : ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) )
429 : {
430 669 : hb_synth_fx_exp = swb_bwe_dec_hr_fx( st_fx, old_syn_12k8_16k_fx, Qpostd, hb_synth_fx, output_frame, unbits, pitch_buf_fx ); /*Q0*/
431 : }
432 :
433 : /*---------------------------------------------------------------------*
434 : * FEC - recovery after lost HQ core (smoothing of the BWE component)
435 : *---------------------------------------------------------------------*/
436 :
437 1852 : test();
438 1852 : test();
439 1852 : IF( st_fx->prev_bfi && EQ_16( st_fx->last_core, HQ_CORE ) && NE_16( st_fx->extl, -1 ) )
440 : {
441 : /*tmp = FRAC_BWE_SMOOTH/output_frame;*/
442 0 : tmp16 = shr( 410, shr( output_frame, 8 ) );
443 0 : if ( EQ_16( output_frame, L_FRAME48k ) )
444 : {
445 0 : tmp16 = 68;
446 0 : move16();
447 : }
448 : /*output_frame/FRAC_BWE_SMOOTH*/
449 0 : j = shr( output_frame, 1 ); /*Q0*/
450 0 : tmp16_2 = 0;
451 0 : move16();
452 0 : FOR( i = 0; i < j; i++ )
453 : {
454 : /*hb_synth[i] *= (i*tmp);*/
455 0 : hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); /*hb_synth_fx_exp*/
456 0 : move16();
457 0 : tmp16_2 = add_o( tmp16_2, tmp16, &Overflow );
458 : }
459 : }
460 :
461 : /*---------------------------------------------------------------------*
462 : * SWB CNG
463 : *---------------------------------------------------------------------*/
464 :
465 1852 : IF( GE_16( output_frame, L_FRAME32k ) )
466 : {
467 : /* SHB CNG decoder */
468 1852 : swb_CNG_dec_fx( st_fx, synth_fx, hb_synth_fx, sid_bw, Qpostd );
469 :
470 1852 : test();
471 1852 : if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->bws_cnt == 0 )
472 : {
473 0 : hb_synth_fx_exp = 3;
474 0 : move16();
475 : }
476 : }
477 :
478 : /*----------------------------------------------------------------*
479 : * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers
480 : *----------------------------------------------------------------*/
481 :
482 1852 : IF( GE_16( output_frame, L_FRAME16k ) )
483 : {
484 1852 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/
485 :
486 1852 : exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx );
487 1852 : Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/
488 1852 : Qpostd = exp;
489 1852 : move16();
490 1852 : Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); /*exp*/
491 1852 : st_fx->Qprev_synth_buffer_fx = exp;
492 1852 : move16();
493 1852 : delay_signal_fx( synth_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); /*exp, t_fx->Qprev_synth_buffer_fx*/
494 : }
495 : ELSE
496 : {
497 0 : exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx );
498 0 : Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/
499 0 : Qpostd = exp;
500 0 : move16();
501 0 : st_fx->Qprev_synth_buffer_fx = exp;
502 0 : move16();
503 : }
504 :
505 1852 : test();
506 1852 : test();
507 1852 : test();
508 1852 : test();
509 1852 : test();
510 1852 : test();
511 1852 : test();
512 1852 : test();
513 1852 : IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) )
514 : {
515 0 : tmps = 0;
516 0 : move16();
517 0 : IF( GE_16( output_frame, L_FRAME16k ) )
518 : {
519 0 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
520 : }
521 :
522 0 : waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth_fx + tmps, tmps, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi );
523 0 : st_fx->hPlcInfo->Pitch_fx = 0;
524 0 : move16();
525 : }
526 :
527 : /*----------------------------------------------------------------*
528 : * Addition of BWE components to the ACELP core synthesis
529 : *----------------------------------------------------------------*/
530 :
531 1852 : test();
532 1852 : test();
533 1852 : IF( NE_16( st_fx->extl, -1 ) || ( st_fx->bws_cnt > 0 && EQ_16( st_fx->core, ACELP_CORE ) ) )
534 : {
535 : /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */
536 1423 : IF( EQ_16( st_fx->L_frame, L_FRAME ) )
537 : {
538 : /* TBE on top of ACELP@12.8kHz */
539 754 : tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /*Q0*/
540 : }
541 : ELSE
542 : {
543 669 : test();
544 669 : IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) )
545 : {
546 : /* HR SWB BWE on top of ACELP@16kHz */
547 669 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
548 : }
549 : ELSE
550 : {
551 : /* TBE on top of ACELP@16kHz */
552 0 : tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /*Q0*/
553 : }
554 : }
555 :
556 : /* Smooth transitions when switching between different technologies */
557 1423 : test();
558 1423 : test();
559 1423 : test();
560 1423 : test();
561 1423 : IF( ( NE_16( st_fx->extl, st_fx->last_extl ) || ( EQ_16( st_fx->extl, st_fx->last_extl ) && EQ_16( ( st_fx->core ^ st_fx->last_core ), HQ_CORE ) ) ) && !( EQ_16( st_fx->extl, SWB_CNG ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) )
562 : {
563 : /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/
564 33 : incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/
565 33 : tmp16 = 0;
566 33 : move16();
567 1298 : FOR( i = 0; i < tmps; i++ )
568 : {
569 1265 : hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] /*Q15*/ ); /*Q15 - hb_synth_fx_exp*/
570 1265 : move16();
571 1265 : tmp16 = add( tmp16, incr );
572 : }
573 33 : set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, tmps );
574 : }
575 1390 : ELSE IF( LT_16( tmps, st_fx->old_bwe_delay ) )
576 : {
577 : /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */
578 : /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/
579 0 : incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/
580 0 : tmp16 = 0;
581 0 : move16();
582 0 : FOR( i = 0; i < tmps; i++ )
583 : {
584 0 : tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ),
585 0 : st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16] /*Q15*/ ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
586 0 : move16();
587 0 : tmp16 = add( tmp16, incr );
588 : }
589 0 : Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
590 : }
591 1390 : ELSE IF( GT_16( tmps, st_fx->old_bwe_delay ) )
592 : {
593 : /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */
594 : /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/
595 2 : incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); /*Q0*/
596 2 : tmp16 = 0;
597 2 : move16();
598 2 : FOR( i = 0; i < st_fx->old_bwe_delay; i++ )
599 : {
600 0 : tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
601 0 : move16();
602 0 : tmp16 = add( tmp16, incr );
603 : }
604 115 : FOR( ; i < tmps; i++ )
605 : {
606 113 : tmp_buffer_fx[i] = 0;
607 113 : move16();
608 : }
609 2 : tmp16 = 0;
610 2 : FOR( i = 0; i < st_fx->old_bwe_delay; i++ )
611 : {
612 : /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/
613 0 : tmp_buffer_fx[( ( tmps - 1 ) - i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[( ( tmps - 1 ) - i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[( ( st_fx->old_bwe_delay - 1 ) - i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
614 0 : move16();
615 0 : tmp16 = add( tmp16, incr );
616 : }
617 :
618 2 : Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
619 : }
620 :
621 : /* Delay hb_synth */
622 1423 : tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp );
623 1423 : IF( tmp16 != 0 )
624 : {
625 810 : Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); /*Q15 - hb_synth_fx_exp*/
626 : }
627 1423 : delay_signal_fx( hb_synth_fx, output_frame, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hb_synth_fx_exp, Q15 - hb_synth_fx_exp*/
628 :
629 1423 : st_fx->old_bwe_delay = tmps;
630 1423 : move16();
631 :
632 1423 : test();
633 1423 : test();
634 1423 : test();
635 1423 : test();
636 1423 : test();
637 1423 : IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( GT_16( st_fx->bws_cnt, 1 ) || NE_16( st_fx->last_extl, -1 ) ) )
638 : {
639 0 : Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
640 0 : IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) )
641 : {
642 0 : hb_synth_fx_exp = add( hBWE_TD->prev_hb_synth_fx_exp, 1 );
643 : }
644 : ELSE
645 : {
646 0 : hb_synth_fx_exp = 14;
647 0 : move16();
648 : }
649 : }
650 : ELSE
651 : {
652 1423 : Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
653 : }
654 :
655 1423 : add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame );
656 :
657 : /* SWB CNG/DTX - calculate SHB energy */
658 1423 : test();
659 1423 : IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st_fx->extl, SWB_CNG ) )
660 : {
661 1423 : SWITCH( output_frame )
662 : {
663 0 : case L_FRAME8k:
664 0 : tmp16 = 205;
665 0 : move16();
666 0 : BREAK; /*Q15*/
667 0 : case L_FRAME16k:
668 0 : tmp16 = 102;
669 0 : move16();
670 0 : BREAK; /*Q15*/
671 754 : case L_FRAME32k:
672 754 : tmp16 = 51;
673 754 : move16();
674 754 : BREAK; /*Q15*/
675 669 : case L_FRAME48k:
676 669 : tmp16 = 34;
677 669 : move16();
678 669 : BREAK; /*Q15*/
679 : }
680 :
681 1423 : L_tmp = L_deposit_l( 1 );
682 1126223 : FOR( i = 0; i < output_frame; i++ )
683 : {
684 1124800 : L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( hb_synth_fx[i], hb_synth_fx[i] ), tmp16 ) ); /*Q30 - 2*hb_synth_fx_exp*/
685 : }
686 1423 : exp = norm_l( L_tmp );
687 1423 : fra = Log2_norm_lc( L_shl( L_tmp, exp ) );
688 1423 : exp = sub( sub( 30, shl( hb_synth_fx_exp, 1 ) ), exp );
689 1423 : L_tmp = Mpy_32_16( exp, fra, LG10 );
690 1423 : st_fx->hTdCngDec->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/
691 : }
692 : }
693 1852 : hBWE_TD->prev_hb_synth_fx_exp = hb_synth_fx_exp;
694 1852 : move16();
695 :
696 : /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */
697 1852 : delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/
698 1852 : Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
699 1852 : Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
700 1852 : tcx_ltp_post_fx( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL );
701 :
702 : /* final output of synthesis signal */
703 1852 : Copy( synth_fx, output_sp, output_frame ); /*Qpostd*/
704 : }
705 : ELSE /* Mode 2 */
706 : {
707 :
708 : /* -------------------------------------------------------------- */
709 : /* Mode 2 concealment */
710 : /* -------------------------------------------------------------- */
711 :
712 1248 : concealWholeFrame = 0;
713 1248 : move16();
714 :
715 1248 : if ( EQ_32( frameMode, FRAMEMODE_NORMAL ) )
716 : {
717 1248 : st_fx->m_decodeMode = DEC_NO_FRAM_LOSS;
718 1248 : move32();
719 : }
720 :
721 1248 : IF( EQ_32( frameMode, FRAMEMODE_MISSING ) )
722 : {
723 0 : test();
724 0 : test();
725 0 : IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) )
726 : {
727 0 : st_fx->m_decodeMode = DEC_NO_FRAM_LOSS;
728 0 : move32();
729 : }
730 : ELSE
731 : {
732 0 : st_fx->m_decodeMode = DEC_CONCEALMENT_EXT;
733 0 : move32();
734 : }
735 : }
736 :
737 1248 : SWITCH( st_fx->m_decodeMode )
738 : {
739 1248 : case DEC_NO_FRAM_LOSS:
740 1248 : BREAK;
741 0 : case DEC_CONCEALMENT_EXT:
742 0 : concealWholeFrame = 1;
743 0 : move16();
744 0 : BREAK;
745 : }
746 :
747 :
748 : /* -------------------------------------------------------------- */
749 : /* Decode core */
750 : /* -------------------------------------------------------------- */
751 :
752 1248 : dec_acelp_tcx_frame_fx( st_fx, &concealWholeFrame, output_sp, st_fx->p_bpf_noise_buf, pcmbufFB, bwe_exc_extended_fx, voice_factors_fx, pitch_buf_fx );
753 :
754 1248 : concealWholeFrameTmp = concealWholeFrame; /*Q0*/
755 1248 : move16();
756 1248 : if ( st_fx->bfi )
757 : {
758 0 : frameMode = FRAMEMODE_MISSING;
759 0 : move32();
760 : }
761 :
762 1248 : IF( st_fx->igf )
763 : {
764 : /* TBE for Mode 2 interface */
765 1248 : test();
766 1248 : test();
767 1248 : IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE )
768 : {
769 610 : test();
770 610 : test(), test();
771 610 : SWITCH( st_fx->bwidth )
772 : {
773 0 : case WB:
774 0 : st_fx->extl = WB_TBE;
775 0 : move16();
776 0 : st_fx->extl_brate = WB_TBE_0k35;
777 0 : move32();
778 0 : BREAK;
779 :
780 610 : case SWB:
781 610 : st_fx->extl = SWB_TBE;
782 610 : move16();
783 610 : st_fx->extl_brate = SWB_TBE_1k6;
784 610 : move32();
785 :
786 610 : IF( LT_32( st_fx->total_brate, ACELP_13k20 ) )
787 : {
788 0 : st_fx->extl_brate = SWB_TBE_0k95;
789 0 : move32();
790 : }
791 610 : ELSE IF( GE_32( st_fx->total_brate, ACELP_24k40 ) )
792 : {
793 610 : st_fx->extl_brate = SWB_TBE_2k8;
794 610 : move32();
795 : }
796 610 : BREAK;
797 :
798 0 : case FB:
799 0 : st_fx->extl = FB_TBE;
800 0 : move16();
801 0 : st_fx->extl_brate = FB_TBE_1k8;
802 0 : move32();
803 0 : IF( GE_32( st_fx->total_brate, ACELP_24k40 ) )
804 : {
805 0 : st_fx->extl_brate = FB_TBE_3k0;
806 0 : move32();
807 : }
808 0 : BREAK;
809 : }
810 610 : }
811 : ELSE
812 : {
813 638 : st_fx->extl = IGF_BWE;
814 638 : move16();
815 638 : st_fx->extl_brate = L_deposit_l( 0 );
816 : }
817 :
818 1248 : test();
819 1248 : test();
820 1248 : if ( EQ_32( st_fx->output_Fs, 8000 ) || ( EQ_32( st_fx->output_Fs, INT_FS_16k ) && EQ_16( st_fx->L_frame, L_FRAME16k ) ) )
821 : {
822 0 : st_fx->extl = -1;
823 0 : move16();
824 : }
825 :
826 1248 : st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); /*Q0*/
827 :
828 1248 : st_fx->bws_cnt = 0;
829 1248 : move16();
830 1248 : st_fx->bws_cnt1 = 0;
831 1248 : move16();
832 1248 : st_fx->tilt_wb_fx = 0;
833 1248 : move16();
834 :
835 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
836 : {
837 1248 : test();
838 1248 : test();
839 1248 : IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE )
840 : {
841 610 : test();
842 610 : IF( EQ_16( st_fx->extl, WB_TBE ) )
843 : {
844 0 : wb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hb_synth_fx, &hb_synth_fx_exp );
845 : }
846 610 : ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) )
847 : {
848 : /* SWB TBE decoder */
849 610 : swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx,
850 : fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx );
851 610 : test();
852 610 : IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) )
853 : {
854 0 : fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp );
855 : }
856 : }
857 610 : Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
858 : }
859 : ELSE
860 : {
861 638 : IF( EQ_16( st_fx->last_core, ACELP_CORE ) )
862 : {
863 36 : test();
864 36 : test();
865 36 : test();
866 36 : test();
867 36 : IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) &&
868 : ( ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
869 : {
870 23 : GenTransition_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs, st_fx->rf_flag, st_fx->total_brate );
871 :
872 23 : hb_synth_fx_exp = hBWE_TD->prev_Q_bwe_syn2;
873 23 : move16();
874 : }
875 13 : ELSE IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->last_extl, WB_TBE ) )
876 : {
877 0 : GenTransition_WB_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs );
878 :
879 0 : hb_synth_fx_exp = hBWE_TD->prev_Qx;
880 0 : move16();
881 : }
882 :
883 36 : TBEreset_dec_fx( st_fx );
884 : }
885 602 : ELSE IF( EQ_16( st_fx->last_codec_mode, MODE1 ) )
886 : {
887 11 : swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
888 11 : hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
889 :
890 11 : IF( EQ_16( st_fx->extl, FB_TBE ) )
891 : {
892 0 : set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
893 0 : hBWE_TD->fb_tbe_demph_fx = 0;
894 0 : move16();
895 0 : fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx );
896 : }
897 :
898 11 : swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 );
899 : }
900 : }
901 : }
902 : }
903 :
904 1248 : IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
905 : {
906 0 : st_fx->extl = -1;
907 0 : move16();
908 0 : st_fx->extl_brate = L_deposit_l( 0 );
909 : }
910 :
911 : /* -------------------------------------------------------------- */
912 : /* Postprocessing */
913 : /* -------------------------------------------------------------- */
914 :
915 : {
916 : Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX];
917 : Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
918 :
919 21216 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
920 : {
921 19968 : set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
922 19968 : set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
923 19968 : realBuffer[i] = realBufferTmp[i];
924 19968 : move32();
925 19968 : imagBuffer[i] = imagBufferTmp[i];
926 19968 : move32();
927 : }
928 :
929 1248 : nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/
930 1248 : st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/
931 1248 : st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; /*Q0*/
932 1248 : move16();
933 1248 : st_fx->cldfbAna->lsb = st_fx->cldfbAna->no_channels;
934 1248 : move16();
935 1248 : st_fx->cldfbAna->usb = st_fx->cldfbAna->no_channels;
936 1248 : move16();
937 :
938 1248 : test();
939 1248 : test();
940 1248 : test();
941 1248 : test();
942 1248 : IF( st_fx->hFdCngDec != NULL && ( EQ_32( st_fx->sr_core, 8000 ) || EQ_32( st_fx->sr_core, INT_FS_12k8 ) || EQ_32( st_fx->sr_core, INT_FS_16k ) ) && LE_32( st_fx->total_brate, ACELP_32k ) )
943 : {
944 : /* -------------------------------------------------------------- *
945 : * In CLDFB domain:
946 : * - perform noise estimation during active frames
947 : * - do CNG during inactive frames
948 : * -------------------------------------------------------------- */
949 :
950 1248 : HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec;
951 1248 : noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ), output_sp, 0 );
952 :
953 1248 : hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); /*Q15*/
954 1248 : if ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 )
955 : {
956 0 : hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); /*Q15*/
957 : }
958 1248 : st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/
959 1248 : move32();
960 : #ifdef REMOVE_EVS_DUPLICATES
961 1248 : ApplyFdCng_ivas_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 );
962 : #else
963 : ApplyFdCng_fx( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 );
964 : #endif
965 : /* Generate additional comfort noise to mask potential coding artefacts */
966 1248 : test();
967 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && st_fx->flag_cna )
968 : {
969 264 : generate_masking_noise_fx( output_sp, 0, hFdCngDec->hFdCngCom, hFdCngDec->hFdCngCom->frameSize, 0 );
970 : }
971 : }
972 :
973 1248 : test();
974 1248 : test();
975 1248 : test();
976 1248 : test();
977 1248 : test();
978 1248 : test();
979 1248 : IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
980 : {
981 0 : FOR( i = 0; i < st_fx->L_frame / 2; i++ )
982 : {
983 0 : output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); /*Q0*/
984 0 : move16();
985 : }
986 : }
987 :
988 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
989 : {
990 1248 : timeIn_e = s_max( 0, sub( getScaleFactor16( output_sp, st_fx->L_frame ), 3 ) );
991 1248 : IF( NE_16( st_fx->core, ACELP_CORE ) )
992 : {
993 638 : timeIn_e = s_max( 0, s_min( sub( getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3 ), timeIn_e ) );
994 : }
995 1248 : Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
996 1248 : timeIn_e = negate( timeIn_e );
997 1248 : cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer );
998 1248 : st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale;
999 1248 : move16();
1000 : }
1001 : ELSE
1002 : {
1003 : Word16 timeDomainBuffer[L_FRAME16k];
1004 : Word16 A[M + 1];
1005 :
1006 0 : Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); /*Q0*/
1007 0 : Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); /*Q12*/
1008 :
1009 0 : update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf );
1010 :
1011 : /* Generate additional comfort noise to mask potential coding artefacts */
1012 0 : test();
1013 0 : test();
1014 0 : test();
1015 0 : test();
1016 0 : test();
1017 0 : IF( st_fx->flag_cna )
1018 : {
1019 0 : generate_masking_noise_fx( timeDomainBuffer, 0, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 );
1020 : }
1021 0 : ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) )
1022 : {
1023 0 : FOR( i = 0; i < st_fx->L_frame / 2; i++ )
1024 : {
1025 0 : timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[( i + ( 5 * ( st_fx->L_frame / 4 ) ) )] ); /*Q0*/
1026 0 : move16();
1027 : }
1028 : }
1029 :
1030 : /* check if the CLDFB works on the right sample rate */
1031 0 : IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) )
1032 : {
1033 0 : Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) );
1034 :
1035 0 : resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 );
1036 0 : resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 );
1037 : }
1038 :
1039 0 : st_fx->cldfbSyn->bandsToZero = 0;
1040 0 : move16();
1041 0 : test();
1042 0 : IF( EQ_16( st_fx->bwidth, NB ) && GT_16( st_fx->cldfbSyn->no_channels, 10 ) )
1043 : {
1044 0 : st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 );
1045 : }
1046 0 : ELSE IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) )
1047 : {
1048 0 : st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand );
1049 : }
1050 :
1051 0 : timeIn_e = 2;
1052 0 : move16();
1053 0 : Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1054 0 : IF( st_fx->p_bpf_noise_buf )
1055 : {
1056 0 : Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1057 : }
1058 :
1059 0 : timeIn_e = negate( timeIn_e );
1060 0 : cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer );
1061 : }
1062 :
1063 1248 : IF( st_fx->flag_cna == 0 )
1064 : {
1065 984 : set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen );
1066 : }
1067 :
1068 1248 : IF( st_fx->p_bpf_noise_buf )
1069 : {
1070 1248 : Word16 timeInBpf_e = timeIn_e;
1071 1248 : move16();
1072 1248 : if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1073 : {
1074 1248 : timeInBpf_e = 0;
1075 1248 : move16();
1076 : }
1077 :
1078 1248 : addBassPostFilter_fx( st_fx->p_bpf_noise_buf, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer,
1079 1248 : timeInBpf_e, CLDFB_NO_COL_MAX, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &st_fx->scaleFactor );
1080 :
1081 1248 : IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1082 : {
1083 0 : Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1084 : }
1085 : }
1086 :
1087 1248 : IF( GT_32( st_fx->output_Fs, 8000 ) )
1088 : {
1089 1248 : st_fx->hTECDec->cldfbExp = add( 15, st_fx->scaleFactor.lb_scale );
1090 :
1091 1248 : calcGainTemp_TBE_Fx( realBuffer, imagBuffer, st_fx->hTECDec->cldfbExp, st_fx->hTECDec->loBuffer,
1092 : 0, /*startPos,*/ /*!< Start position of the current envelope. */
1093 1248 : st_fx->cldfbAna->no_col,
1094 : /*stopPos,*/ /*!< Stop position of the current envelope. */
1095 1248 : st_fx->cldfbAna->no_channels, /*lowSubband*/
1096 1248 : st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e, st_fx->tec_flag );
1097 : }
1098 :
1099 : /* set high band buffers to zero. Covering the current frame and the overlap area. */
1100 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1101 : {
1102 21216 : FOR( i = 0; i < 16; i++ )
1103 : {
1104 19968 : set32_fx( &realBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) );
1105 19968 : set32_fx( &imagBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) );
1106 : }
1107 : }
1108 :
1109 1248 : timeIn_e = s_min( 0, add( timeIn_e, 2 ) );
1110 1248 : cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); /*CLDFB output always in timeIn_e*/
1111 :
1112 : /* MODE1 MDCT to ACELP 2 transition */
1113 1248 : delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS );
1114 1248 : Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /*Q0*/
1115 1248 : hHQ_core->Q_old_postdec = 0;
1116 1248 : move16();
1117 1248 : delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/
1118 1248 : IF( GE_16( output_frame, L_FRAME16k ) )
1119 : {
1120 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); /*Qpostd*/
1121 : }
1122 :
1123 1248 : test();
1124 1248 : IF( EQ_16( st_fx->last_codec_mode, MODE1 ) && GT_16( st_fx->last_core_bfi, ACELP_CORE ) )
1125 : {
1126 18 : Copy_Scale_sig( st_fx->delay_buf_out_fx, output_sp, delay_comp, negate( timeIn_e ) ); /* copy the HQ/ACELP delay synchronization buffer at the beginning of ACELP frame */ /*-timeIn_e*/
1127 18 : IF( EQ_16( st_fx->core, ACELP_CORE ) )
1128 : {
1129 : Word16 step, alpha, nz;
1130 :
1131 7 : i = 15;
1132 7 : move16();
1133 7 : tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); /*Q0*/
1134 7 : nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); /*Q0*/
1135 7 : step = Inv16( tmps, &i ); /*Q15 - i*/
1136 7 : step = shl( step, i );
1137 7 : alpha = 0;
1138 7 : move16();
1139 :
1140 7 : test();
1141 7 : IF( st_fx->prev_bfi && hHQ_core->HqVoicing )
1142 : {
1143 0 : Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); /*hHQ_core->Q_fer_samples*/
1144 : }
1145 : ELSE
1146 : {
1147 7 : Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); /*Q0*/
1148 : }
1149 7 : hHQ_core->Q_old_wtda = 0;
1150 7 : move16();
1151 :
1152 1015 : FOR( i = 0; i < tmps; i++ )
1153 : {
1154 1008 : output_sp[i + delay_comp] = msu_r_sat( L_mult_sat( output_sp[i + delay_comp], alpha ), shr( hHQ_core->old_out_fx[i + nz], timeIn_e ), add( alpha, -32768 ) ); /*timeIn_e*/
1155 1008 : move16();
1156 1008 : alpha = add( alpha, step );
1157 : }
1158 : }
1159 : ELSE
1160 : {
1161 11 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1162 : {
1163 0 : Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); /*Q0*/
1164 : }
1165 : ELSE
1166 : {
1167 11 : Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); /*st_fx->q_prev_synth_buffer_fx*/
1168 11 : Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); /*Q0*/
1169 : }
1170 : }
1171 : }
1172 :
1173 : /* set delay compensation between HQ synthesis and ACELP synthesis */
1174 1248 : test();
1175 1248 : IF( EQ_16( st_fx->core, ACELP_CORE ) && !( st_fx->con_tcx ) )
1176 : {
1177 610 : set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp );
1178 610 : Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); /*timeIn_e*/
1179 : }
1180 : ELSE
1181 : {
1182 638 : Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); /*Q0*/
1183 638 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1184 : {
1185 0 : Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/
1186 : }
1187 : ELSE
1188 : {
1189 638 : Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/
1190 : }
1191 638 : Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); /*Q0*/
1192 : }
1193 : }
1194 :
1195 : /* Delay compensation for TD-BWE*/
1196 1248 : IF( GE_16( output_frame, L_FRAME16k ) )
1197 : {
1198 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, negate( timeIn_e ) );
1199 1248 : delay_signal_fx( output_sp, output_frame, st_fx->prev_synth_buffer_fx, delay_tdbwe ); /*timeIn_e, st_fx->q_prev_synth_buffer_fx*/
1200 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e );
1201 : }
1202 :
1203 1248 : test();
1204 1248 : IF( st_fx->igf != 0 && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1205 : {
1206 1248 : test();
1207 1248 : test();
1208 1248 : test();
1209 1248 : test();
1210 1248 : IF( st_fx->bfi == 0 && EQ_16( st_fx->core, ACELP_CORE ) && ( st_fx->tec_flag != 0 || st_fx->tfa_flag != 0 ) && GT_32( st_fx->output_Fs, 8000 ) /*&& st_fx->hTECDec_fx != NULL*/ )
1211 : {
1212 68 : tmp16 = 0;
1213 68 : move16();
1214 68 : if ( EQ_16( st_fx->tec_flag, 2 ) )
1215 : {
1216 5 : tmp16 = 1;
1217 5 : move16();
1218 : }
1219 :
1220 68 : hb_synth_fx_exp = procTecTfa_TBE_Fx( hb_synth_fx, hb_synth_fx_exp, st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e,
1221 68 : st_fx->tfa_flag, st_fx->last_core, shr( output_frame, 4 ), tmp16 );
1222 : }
1223 :
1224 1248 : test();
1225 1248 : test();
1226 1248 : test();
1227 1248 : test();
1228 1248 : test();
1229 1248 : test();
1230 1248 : IF( ( ( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) ||
1231 : ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( NE_16( st_fx->bwidth, NB ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) ) &&
1232 : ( GT_32( st_fx->output_Fs, 8000 ) ) )
1233 : {
1234 : /* Add the delayed hb_synth component to the delayed core synthesis */
1235 633 : add_vec_fx( output_sp, negate( timeIn_e ), hb_synth_fx, hb_synth_fx_exp, output_sp, negate( timeIn_e ), output_frame );
1236 : }
1237 : }
1238 :
1239 1248 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1240 : {
1241 0 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /*Q0*/
1242 : }
1243 : ELSE
1244 : {
1245 1248 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
1246 : }
1247 1248 : delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/
1248 :
1249 1248 : test();
1250 1248 : test();
1251 1248 : test();
1252 : /* TCX/ACELP/HQ-CORE->TCX */
1253 1248 : IF( ( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) || GT_16( st_fx->core, ACELP_CORE ) )
1254 : {
1255 638 : test();
1256 638 : test();
1257 638 : test();
1258 638 : test();
1259 : /* TCX / HQ-CORE / TD-TCX-PLC -> TCX / TD-TCX-PLC */
1260 638 : IF( GT_16( st_fx->last_core_bfi, ACELP_CORE ) || ( st_fx->bfi && st_fx->last_core > ACELP_CORE ) || ( st_fx->prev_bfi && st_fx->last_con_tcx ) )
1261 : {
1262 601 : Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); /*Q0*/
1263 601 : Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); /*Q0*/
1264 : }
1265 : /* ACELP -> TCX */
1266 : ELSE
1267 : {
1268 : /*cross-fading between LB-TCX and FB-TCX over 2.3125ms*/
1269 : Word16 step, alpha;
1270 :
1271 37 : i = 15;
1272 37 : move16();
1273 37 : step = Inv16( tmps, &i );
1274 37 : step = shl( step, i );
1275 37 : alpha = 0;
1276 37 : move16();
1277 :
1278 3663 : FOR( i = 0; i < tmps; i++ )
1279 : {
1280 3626 : output_sp[i + tmps] = msu_r_sat( L_mult_sat( shr( pcmbufFB[i], timeIn_e ), alpha ), output_sp[i + tmps], add( alpha, -32768 ) ); /*Q0*/
1281 3626 : move16();
1282 3626 : alpha = add( alpha, step );
1283 : }
1284 37 : Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); /*Q0*/
1285 : }
1286 :
1287 638 : Copy( pcmbufFB + sub( hTcxDec->L_frameTCX, tmps ), hTcxDec->FBTCXdelayBuf, tmps );
1288 :
1289 638 : test();
1290 638 : IF( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) )
1291 : {
1292 0 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1293 : {
1294 0 : Copy( hTcxDec->FBTCXdelayBuf, st_fx->delay_buf_out_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*st_fx->q_prev_synth_buffer_fx*/
1295 : }
1296 : ELSE
1297 : {
1298 0 : Copy( hTcxDec->FBTCXdelayBuf, st_fx->prev_synth_buffer_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /*st_fx->Qprev_synth_buffer_fx*/
1299 0 : Copy( hTcxDec->FBTCXdelayBuf + NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), st_fx->delay_buf_out_fx, NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ) ); /*Q0*/
1300 : }
1301 : }
1302 : }
1303 : /* TCX/TD TCX PLC->ACELP */
1304 610 : ELSE IF( ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( GT_16( st_fx->last_core, ACELP_CORE ) ) )
1305 : {
1306 : Word16 step, alpha;
1307 :
1308 23 : Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); /*Q0*/
1309 :
1310 23 : i = 15;
1311 23 : move16();
1312 23 : step = Inv16( sub( tmps, delta ), &i );
1313 23 : step = shl( step, i );
1314 23 : alpha = 0;
1315 23 : move16();
1316 :
1317 2300 : FOR( i = delta; i < tmps; i++ )
1318 : {
1319 2277 : output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); /*Q0*/
1320 2277 : move16();
1321 2277 : alpha = add_sat( alpha, step );
1322 : }
1323 : }
1324 :
1325 1248 : Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1326 1248 : Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1327 :
1328 1248 : Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/
1329 :
1330 1248 : tcx_ltp_post_fx( st_fx, hTcxLtpDec, st_fx->core, output_frame /*hTcxDec->L_frameTCX*/, add( NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS ), tmps ), output_sp, hTcxDec->FBTCXdelayBuf );
1331 1248 : Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/
1332 :
1333 : } /* end of Mode 2 */
1334 :
1335 :
1336 : /*----------------------------------------------------------------*
1337 : * Save synthesis for HQ FEC
1338 : *----------------------------------------------------------------*/
1339 :
1340 3100 : save_synthesis_hq_fec_fx( st_fx, synth_fx, NULL, output_frame, Qpostd, NULL );
1341 :
1342 : /*----------------------------------------------------------------*
1343 : * HP filtering
1344 : *----------------------------------------------------------------*/
1345 :
1346 3100 : st_fx->Qprev_synth_buffer_fx = Qpostd;
1347 3100 : move16();
1348 3100 : Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1349 3100 : hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) );
1350 :
1351 : /*----------------------------------------------------------------*
1352 : * Synthesis output
1353 : *----------------------------------------------------------------*/
1354 :
1355 3100 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
1356 : {
1357 : /* final output of synthesis signal */
1358 1852 : syn_output_fx( st_fx->codec_mode, synth_fx, output_frame, output_sp, Qpostd );
1359 : }
1360 : ELSE
1361 : {
1362 1248 : Copy( synth_fx, output_sp, output_frame ); /*Q0*/
1363 : }
1364 :
1365 : /*--------------------------------------------------------*
1366 : * Updates
1367 : *--------------------------------------------------------*/
1368 :
1369 3100 : test();
1370 3100 : IF( st_fx->last_is_cng == 0 && EQ_16( st_fx->codec_mode, MODE2 ) )
1371 : {
1372 1248 : st_fx->bfi = 0;
1373 1248 : move16();
1374 1248 : test();
1375 1248 : test();
1376 1248 : IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) )
1377 : {
1378 0 : if ( EQ_16( frameMode, FRAMEMODE_MISSING ) )
1379 : {
1380 0 : st_fx->bfi = 1;
1381 0 : move16();
1382 : }
1383 : }
1384 1248 : ELSE IF( EQ_16( st_fx->m_decodeMode, DEC_CONCEALMENT_EXT ) )
1385 : {
1386 0 : st_fx->bfi = 1;
1387 0 : move16();
1388 : }
1389 1248 : updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd );
1390 : }
1391 : ELSE
1392 : {
1393 1852 : if ( EQ_16( st_fx->codec_mode, MODE2 ) )
1394 : {
1395 0 : st_fx->bfi = 0;
1396 0 : move16();
1397 : }
1398 1852 : updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd );
1399 : }
1400 :
1401 3100 : pop_wmops();
1402 :
1403 3100 : return IVAS_ERR_OK;
1404 : }
|