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