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 1423 : 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 )
336 : {
337 0 : return error;
338 : }
339 1423 : Qpostd = st_fx->Q_syn2;
340 1423 : move16();
341 : }
342 : ELSE
343 : {
344 429 : hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag );
345 429 : Qpostd = Q_synth;
346 429 : move16();
347 : }
348 :
349 : /*---------------------------------------------------------------------*
350 : * Postprocessing for ACELP/HQ core switching
351 : *---------------------------------------------------------------------*/
352 :
353 1852 : if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK )
354 : {
355 0 : return error;
356 : }
357 :
358 : /*---------------------------------------------------------------------*
359 : * Pre-processing for bandwidth switching
360 : *---------------------------------------------------------------------*/
361 :
362 1852 : bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx );
363 :
364 : /*---------------------------------------------------------------------*
365 : * WB TBE decoding
366 : * WB BWE decoding
367 : *---------------------------------------------------------------------*/
368 :
369 1852 : IF( EQ_16( st_fx->extl, WB_TBE ) )
370 : {
371 : /* WB TBE decoder */
372 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 );
373 : }
374 1852 : ELSE IF( EQ_16( st_fx->extl, WB_BWE ) && st_fx->bws_cnt == 0 )
375 : {
376 : /* WB BWE decoder */
377 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*/
378 : }
379 :
380 : /*---------------------------------------------------------------------*
381 : * SWB TBE decoding
382 : * SWB BWE decoding
383 : * FB TBE decoding
384 : *---------------------------------------------------------------------*/
385 1852 : test();
386 1852 : test();
387 1852 : test();
388 1852 : test();
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 : 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 ) ) ) )
406 : {
407 : /* SWB TBE decoder */
408 748 : swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx,
409 : old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx );
410 :
411 : /* FB TBE decoder */
412 748 : test();
413 748 : IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) )
414 : {
415 0 : fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp );
416 : }
417 : }
418 1104 : ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ||
419 : ( 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 ) ) ) )
420 : {
421 : /* SWB BWE decoder */
422 6 : hb_synth_fx_exp = swb_bwe_dec_fx( st_fx, synth_fx, hb_synth_fx, output_frame, &Qpostd ); /*Q0*/
423 : }
424 1098 : ELSE IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) )
425 : {
426 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*/
427 : }
428 :
429 : /*---------------------------------------------------------------------*
430 : * FEC - recovery after lost HQ core (smoothing of the BWE component)
431 : *---------------------------------------------------------------------*/
432 :
433 1852 : test();
434 1852 : test();
435 1852 : IF( st_fx->prev_bfi && EQ_16( st_fx->last_core, HQ_CORE ) && NE_16( st_fx->extl, -1 ) )
436 : {
437 : /*tmp = FRAC_BWE_SMOOTH/output_frame;*/
438 0 : tmp16 = shr( 410, shr( output_frame, 8 ) );
439 0 : if ( EQ_16( output_frame, L_FRAME48k ) )
440 : {
441 0 : tmp16 = 68;
442 0 : move16();
443 : }
444 : /*output_frame/FRAC_BWE_SMOOTH*/
445 0 : j = shr( output_frame, 1 ); /*Q0*/
446 0 : tmp16_2 = 0;
447 0 : move16();
448 0 : FOR( i = 0; i < j; i++ )
449 : {
450 : /*hb_synth[i] *= (i*tmp);*/
451 0 : hb_synth_fx[i] = mult_r( hb_synth_fx[i], tmp16_2 ); /*hb_synth_fx_exp*/
452 0 : move16();
453 0 : tmp16_2 = add_o( tmp16_2, tmp16, &Overflow );
454 : }
455 : }
456 :
457 : /*---------------------------------------------------------------------*
458 : * SWB CNG
459 : *---------------------------------------------------------------------*/
460 :
461 1852 : IF( GE_16( output_frame, L_FRAME32k ) )
462 : {
463 : /* SHB CNG decoder */
464 1852 : swb_CNG_dec_fx( st_fx, synth_fx, hb_synth_fx, sid_bw, Qpostd );
465 :
466 1852 : test();
467 1852 : if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->bws_cnt == 0 )
468 : {
469 0 : hb_synth_fx_exp = 3;
470 0 : move16();
471 : }
472 : }
473 :
474 : /*----------------------------------------------------------------*
475 : * Delay ACELP core synthesis to be synchronized with the components of bandwidth extension layers
476 : *----------------------------------------------------------------*/
477 :
478 1852 : IF( GE_16( output_frame, L_FRAME16k ) )
479 : {
480 1852 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/
481 :
482 1852 : exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx );
483 1852 : Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/
484 1852 : Qpostd = exp;
485 1852 : move16();
486 1852 : Scale_sig( st_fx->prev_synth_buffer_fx, tmps, sub( exp, st_fx->Qprev_synth_buffer_fx ) ); /*exp*/
487 1852 : st_fx->Qprev_synth_buffer_fx = exp;
488 1852 : move16();
489 1852 : delay_signal_fx( synth_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); /*exp, t_fx->Qprev_synth_buffer_fx*/
490 : }
491 : ELSE
492 : {
493 0 : exp = s_min( Qpostd, st_fx->Qprev_synth_buffer_fx );
494 0 : Scale_sig( synth_fx, output_frame, sub( exp, Qpostd ) ); /*exp*/
495 0 : Qpostd = exp;
496 0 : move16();
497 0 : st_fx->Qprev_synth_buffer_fx = exp;
498 0 : move16();
499 : }
500 :
501 1852 : test();
502 1852 : test();
503 1852 : test();
504 1852 : test();
505 1852 : test();
506 1852 : test();
507 1852 : test();
508 1852 : test();
509 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 ) )
510 : {
511 0 : tmps = 0;
512 0 : move16();
513 0 : IF( GE_16( output_frame, L_FRAME16k ) )
514 : {
515 0 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
516 : }
517 :
518 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 );
519 0 : st_fx->hPlcInfo->Pitch_fx = 0;
520 0 : move16();
521 : }
522 :
523 : /*----------------------------------------------------------------*
524 : * Addition of BWE components to the ACELP core synthesis
525 : *----------------------------------------------------------------*/
526 :
527 1852 : test();
528 1852 : test();
529 1852 : IF( NE_16( st_fx->extl, -1 ) || ( st_fx->bws_cnt > 0 && EQ_16( st_fx->core, ACELP_CORE ) ) )
530 : {
531 : /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */
532 1423 : IF( EQ_16( st_fx->L_frame, L_FRAME ) )
533 : {
534 : /* TBE on top of ACELP@12.8kHz */
535 754 : tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); /*Q0*/
536 : }
537 : ELSE
538 : {
539 669 : test();
540 669 : IF( EQ_16( st_fx->extl, SWB_BWE_HIGHRATE ) || EQ_16( st_fx->extl, FB_BWE_HIGHRATE ) )
541 : {
542 : /* HR SWB BWE on top of ACELP@16kHz */
543 669 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
544 : }
545 : ELSE
546 : {
547 : /* TBE on top of ACELP@16kHz */
548 0 : tmps = NS2SA_FX2( st_fx->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); /*Q0*/
549 : }
550 : }
551 :
552 : /* Smooth transitions when switching between different technologies */
553 1423 : test();
554 1423 : test();
555 1423 : test();
556 1423 : test();
557 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 ) ) )
558 : {
559 : /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/
560 33 : incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/
561 33 : tmp16 = 0;
562 33 : move16();
563 1298 : FOR( i = 0; i < tmps; i++ )
564 : {
565 1265 : hb_synth_fx[i] = mult_r( hb_synth_fx[i], sin_table256_fx[tmp16] /*Q15*/ ); /*Q15 - hb_synth_fx_exp*/
566 1265 : move16();
567 1265 : tmp16 = add( tmp16, incr );
568 : }
569 33 : set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, tmps );
570 : }
571 1390 : ELSE IF( LT_16( tmps, st_fx->old_bwe_delay ) )
572 : {
573 : /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */
574 : /*incr = (short) ( L_FRAME / (tmps + 0.5f) );*/
575 0 : incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); /*Q0*/
576 0 : tmp16 = 0;
577 0 : move16();
578 0 : FOR( i = 0; i < tmps; i++ )
579 : {
580 0 : tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[( 255 - tmp16 )] ),
581 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*/
582 0 : move16();
583 0 : tmp16 = add( tmp16, incr );
584 : }
585 0 : Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
586 : }
587 1390 : ELSE IF( GT_16( tmps, st_fx->old_bwe_delay ) )
588 : {
589 : /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */
590 : /*incr = (short)( L_FRAME / (st->old_bwe_delay + 0.5f) );*/
591 2 : incr = idiv1616( L_FRAME * 2, add( shl( st_fx->old_bwe_delay, 1 ), 1 ) ); /*Q0*/
592 2 : tmp16 = 0;
593 2 : move16();
594 2 : FOR( i = 0; i < st_fx->old_bwe_delay; i++ )
595 : {
596 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*/
597 0 : move16();
598 0 : tmp16 = add( tmp16, incr );
599 : }
600 115 : FOR( ; i < tmps; i++ )
601 : {
602 113 : tmp_buffer_fx[i] = 0;
603 113 : move16();
604 : }
605 2 : tmp16 = 0;
606 2 : FOR( i = 0; i < st_fx->old_bwe_delay; i++ )
607 : {
608 : /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/
609 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*/
610 0 : move16();
611 0 : tmp16 = add( tmp16, incr );
612 : }
613 :
614 2 : Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); /*Q15 - hBWE_TD->prev_hb_synth_fx_exp*/
615 : }
616 :
617 : /* Delay hb_synth */
618 1423 : tmp16 = sub( hb_synth_fx_exp, hBWE_TD->prev_hb_synth_fx_exp );
619 1423 : IF( tmp16 != 0 )
620 : {
621 810 : Scale_sig( st_fx->hb_prev_synth_buffer_fx, tmps, tmp16 ); /*Q15 - hb_synth_fx_exp*/
622 : }
623 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*/
624 :
625 1423 : st_fx->old_bwe_delay = tmps;
626 1423 : move16();
627 :
628 1423 : test();
629 1423 : test();
630 1423 : test();
631 1423 : test();
632 1423 : test();
633 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 ) ) )
634 : {
635 0 : Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
636 0 : IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) )
637 : {
638 0 : hb_synth_fx_exp = add( hBWE_TD->prev_hb_synth_fx_exp, 1 );
639 : }
640 : ELSE
641 : {
642 0 : hb_synth_fx_exp = 14;
643 0 : move16();
644 : }
645 : }
646 : ELSE
647 : {
648 1423 : Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
649 : }
650 :
651 1423 : add_vec_fx( synth_fx, Qpostd, hb_synth_fx, hb_synth_fx_exp, synth_fx, Qpostd, output_frame );
652 :
653 : /* SWB CNG/DTX - calculate SHB energy */
654 1423 : test();
655 1423 : IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st_fx->extl, SWB_CNG ) )
656 : {
657 1423 : SWITCH( output_frame )
658 : {
659 0 : case L_FRAME8k:
660 0 : tmp16 = 205;
661 0 : move16();
662 0 : BREAK; /*Q15*/
663 0 : case L_FRAME16k:
664 0 : tmp16 = 102;
665 0 : move16();
666 0 : BREAK; /*Q15*/
667 754 : case L_FRAME32k:
668 754 : tmp16 = 51;
669 754 : move16();
670 754 : BREAK; /*Q15*/
671 669 : case L_FRAME48k:
672 669 : tmp16 = 34;
673 669 : move16();
674 669 : BREAK; /*Q15*/
675 : }
676 :
677 1423 : L_tmp = L_deposit_l( 1 );
678 1126223 : FOR( i = 0; i < output_frame; i++ )
679 : {
680 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*/
681 : }
682 1423 : exp = norm_l( L_tmp );
683 1423 : fra = Log2_norm_lc( L_shl( L_tmp, exp ) );
684 1423 : exp = sub( sub( 30, shl( hb_synth_fx_exp, 1 ) ), exp );
685 1423 : L_tmp = Mpy_32_16( exp, fra, LG10 );
686 1423 : st_fx->hTdCngDec->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/
687 : }
688 : }
689 1852 : hBWE_TD->prev_hb_synth_fx_exp = hb_synth_fx_exp;
690 1852 : move16();
691 :
692 : /* TCX-LTP Postfilter: used in MODE1 to update memories and to avoid discontinuities when the past frame was TCX */
693 1852 : delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/
694 1852 : Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
695 1852 : Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
696 1852 : tcx_ltp_post_fx( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_fx, NULL );
697 :
698 : /* final output of synthesis signal */
699 1852 : Copy( synth_fx, output_sp, output_frame ); /*Qpostd*/
700 : }
701 : ELSE /* Mode 2 */
702 : {
703 :
704 : /* -------------------------------------------------------------- */
705 : /* Mode 2 concealment */
706 : /* -------------------------------------------------------------- */
707 :
708 1248 : concealWholeFrame = 0;
709 1248 : move16();
710 :
711 1248 : if ( EQ_32( frameMode, FRAMEMODE_NORMAL ) )
712 : {
713 1248 : st_fx->m_decodeMode = DEC_NO_FRAM_LOSS;
714 1248 : move32();
715 : }
716 :
717 1248 : IF( EQ_32( frameMode, FRAMEMODE_MISSING ) )
718 : {
719 0 : test();
720 0 : test();
721 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 ) )
722 : {
723 0 : st_fx->m_decodeMode = DEC_NO_FRAM_LOSS;
724 0 : move32();
725 : }
726 : ELSE
727 : {
728 0 : st_fx->m_decodeMode = DEC_CONCEALMENT_EXT;
729 0 : move32();
730 : }
731 : }
732 :
733 1248 : SWITCH( st_fx->m_decodeMode )
734 : {
735 1248 : case DEC_NO_FRAM_LOSS:
736 1248 : BREAK;
737 0 : case DEC_CONCEALMENT_EXT:
738 0 : concealWholeFrame = 1;
739 0 : move16();
740 0 : BREAK;
741 : }
742 :
743 :
744 : /* -------------------------------------------------------------- */
745 : /* Decode core */
746 : /* -------------------------------------------------------------- */
747 :
748 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 );
749 :
750 1248 : concealWholeFrameTmp = concealWholeFrame; /*Q0*/
751 1248 : move16();
752 1248 : if ( st_fx->bfi )
753 : {
754 0 : frameMode = FRAMEMODE_MISSING;
755 0 : move32();
756 : }
757 :
758 1248 : IF( st_fx->igf )
759 : {
760 : /* TBE for Mode 2 interface */
761 1248 : test();
762 1248 : test();
763 1248 : IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE )
764 : {
765 610 : test();
766 610 : test(), test();
767 610 : SWITCH( st_fx->bwidth )
768 : {
769 0 : case WB:
770 0 : st_fx->extl = WB_TBE;
771 0 : move16();
772 0 : st_fx->extl_brate = WB_TBE_0k35;
773 0 : move32();
774 0 : BREAK;
775 :
776 610 : case SWB:
777 610 : st_fx->extl = SWB_TBE;
778 610 : move16();
779 610 : st_fx->extl_brate = SWB_TBE_1k6;
780 610 : move32();
781 :
782 610 : IF( LT_32( st_fx->total_brate, ACELP_13k20 ) )
783 : {
784 0 : st_fx->extl_brate = SWB_TBE_0k95;
785 0 : move32();
786 : }
787 610 : ELSE IF( GE_32( st_fx->total_brate, ACELP_24k40 ) )
788 : {
789 610 : st_fx->extl_brate = SWB_TBE_2k8;
790 610 : move32();
791 : }
792 610 : BREAK;
793 :
794 0 : case FB:
795 0 : st_fx->extl = FB_TBE;
796 0 : move16();
797 0 : st_fx->extl_brate = FB_TBE_1k8;
798 0 : move32();
799 0 : IF( GE_32( st_fx->total_brate, ACELP_24k40 ) )
800 : {
801 0 : st_fx->extl_brate = FB_TBE_3k0;
802 0 : move32();
803 : }
804 0 : BREAK;
805 : }
806 610 : }
807 : ELSE
808 : {
809 638 : st_fx->extl = IGF_BWE;
810 638 : move16();
811 638 : st_fx->extl_brate = L_deposit_l( 0 );
812 : }
813 :
814 1248 : test();
815 1248 : test();
816 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 ) ) )
817 : {
818 0 : st_fx->extl = -1;
819 0 : move16();
820 : }
821 :
822 1248 : st_fx->core_brate = L_sub( st_fx->total_brate, st_fx->extl_brate ); /*Q0*/
823 :
824 1248 : st_fx->bws_cnt = 0;
825 1248 : move16();
826 1248 : st_fx->bws_cnt1 = 0;
827 1248 : move16();
828 1248 : st_fx->tilt_wb_fx = 0;
829 1248 : move16();
830 :
831 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
832 : {
833 1248 : test();
834 1248 : test();
835 1248 : IF( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE )
836 : {
837 610 : test();
838 610 : IF( EQ_16( st_fx->extl, WB_TBE ) )
839 : {
840 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 );
841 : }
842 610 : ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) )
843 : {
844 : /* SWB TBE decoder */
845 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,
846 : fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx );
847 610 : test();
848 610 : IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) )
849 : {
850 0 : fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp );
851 : }
852 : }
853 610 : Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/
854 : }
855 : ELSE
856 : {
857 638 : IF( EQ_16( st_fx->last_core, ACELP_CORE ) )
858 : {
859 36 : test();
860 36 : test();
861 36 : test();
862 36 : test();
863 36 : IF( ( EQ_16( st_fx->bwidth, SWB ) || EQ_16( st_fx->bwidth, FB ) ) &&
864 : ( ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) )
865 : {
866 23 : GenTransition_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs, st_fx->rf_flag, st_fx->total_brate );
867 :
868 23 : hb_synth_fx_exp = hBWE_TD->prev_Q_bwe_syn2;
869 23 : move16();
870 : }
871 13 : ELSE IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->last_extl, WB_TBE ) )
872 : {
873 0 : GenTransition_WB_fx( hBWE_TD, hb_synth_fx, st_fx->output_Fs );
874 :
875 0 : hb_synth_fx_exp = hBWE_TD->prev_Qx;
876 0 : move16();
877 : }
878 :
879 36 : TBEreset_dec_fx( st_fx );
880 : }
881 602 : ELSE IF( EQ_16( st_fx->last_codec_mode, MODE1 ) )
882 : {
883 11 : swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
884 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 ) );
885 :
886 11 : IF( EQ_16( st_fx->extl, FB_TBE ) )
887 : {
888 0 : set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
889 0 : hBWE_TD->fb_tbe_demph_fx = 0;
890 0 : move16();
891 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 );
892 : }
893 :
894 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 );
895 : }
896 : }
897 : }
898 : }
899 :
900 1248 : IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
901 : {
902 0 : st_fx->extl = -1;
903 0 : move16();
904 0 : st_fx->extl_brate = L_deposit_l( 0 );
905 : }
906 :
907 : /* -------------------------------------------------------------- */
908 : /* Postprocessing */
909 : /* -------------------------------------------------------------- */
910 :
911 : {
912 : Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX];
913 : Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
914 :
915 21216 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
916 : {
917 19968 : set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
918 19968 : set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
919 19968 : realBuffer[i] = realBufferTmp[i];
920 19968 : move32();
921 19968 : imagBuffer[i] = imagBufferTmp[i];
922 19968 : move32();
923 : }
924 :
925 1248 : nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/
926 1248 : st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); /*Q0*/
927 1248 : st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; /*Q0*/
928 1248 : move16();
929 1248 : st_fx->cldfbAna->lsb = st_fx->cldfbAna->no_channels;
930 1248 : move16();
931 1248 : st_fx->cldfbAna->usb = st_fx->cldfbAna->no_channels;
932 1248 : move16();
933 :
934 1248 : test();
935 1248 : test();
936 1248 : test();
937 1248 : test();
938 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 ) )
939 : {
940 : /* -------------------------------------------------------------- *
941 : * In CLDFB domain:
942 : * - perform noise estimation during active frames
943 : * - do CNG during inactive frames
944 : * -------------------------------------------------------------- */
945 :
946 1248 : HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec;
947 1248 : noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ), output_sp, 0 );
948 :
949 1248 : hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); /*Q15*/
950 1248 : if ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 )
951 : {
952 0 : hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); /*Q15*/
953 : }
954 1248 : st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/
955 1248 : move32();
956 :
957 1248 : ApplyFdCng_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 );
958 :
959 : /* Generate additional comfort noise to mask potential coding artefacts */
960 1248 : test();
961 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && st_fx->flag_cna )
962 : {
963 264 : generate_masking_noise_fx( output_sp, 0, hFdCngDec->hFdCngCom, hFdCngDec->hFdCngCom->frameSize, 0 );
964 : }
965 : }
966 :
967 1248 : test();
968 1248 : test();
969 1248 : test();
970 1248 : test();
971 1248 : test();
972 1248 : test();
973 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 ) ) )
974 : {
975 0 : FOR( i = 0; i < st_fx->L_frame / 2; i++ )
976 : {
977 0 : output_sp[i] = add_sat( output_sp[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); /*Q0*/
978 0 : move16();
979 : }
980 : }
981 :
982 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
983 : {
984 1248 : timeIn_e = s_max( 0, sub( getScaleFactor16( output_sp, st_fx->L_frame ), 3 ) );
985 1248 : IF( NE_16( st_fx->core, ACELP_CORE ) )
986 : {
987 638 : timeIn_e = s_max( 0, s_min( sub( getScaleFactor16( pcmbufFB, hTcxDec->L_frameTCX ), 3 ), timeIn_e ) );
988 : }
989 1248 : Scale_sig( output_sp, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
990 1248 : timeIn_e = negate( timeIn_e );
991 1248 : cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, output_sp, timeIn_e, CLDFB_NO_COL_MAX, workBuffer );
992 1248 : st_fx->scaleFactor.hb_scale = st_fx->scaleFactor.lb_scale;
993 1248 : move16();
994 : }
995 : ELSE
996 : {
997 : Word16 timeDomainBuffer[L_FRAME16k];
998 : Word16 A[M + 1];
999 :
1000 0 : Copy( st_fx->hFdCngDec->hFdCngCom->timeDomainBuffer, timeDomainBuffer, st_fx->L_frame ); /*Q0*/
1001 0 : Copy( st_fx->hFdCngDec->hFdCngCom->A_cng, A, M + 1 ); /*Q12*/
1002 :
1003 0 : update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf );
1004 :
1005 : /* Generate additional comfort noise to mask potential coding artefacts */
1006 0 : test();
1007 0 : test();
1008 0 : test();
1009 0 : test();
1010 0 : test();
1011 0 : IF( st_fx->flag_cna )
1012 : {
1013 0 : generate_masking_noise_fx( timeDomainBuffer, 0, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 );
1014 : }
1015 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 ) ) )
1016 : {
1017 0 : FOR( i = 0; i < st_fx->L_frame / 2; i++ )
1018 : {
1019 0 : timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[( i + ( 5 * ( st_fx->L_frame / 4 ) ) )] ); /*Q0*/
1020 0 : move16();
1021 : }
1022 : }
1023 :
1024 : /* check if the CLDFB works on the right sample rate */
1025 0 : IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) )
1026 : {
1027 0 : Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) );
1028 :
1029 0 : resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 );
1030 0 : resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 );
1031 : }
1032 :
1033 0 : st_fx->cldfbSyn->bandsToZero = 0;
1034 0 : move16();
1035 0 : test();
1036 0 : IF( EQ_16( st_fx->bwidth, NB ) && GT_16( st_fx->cldfbSyn->no_channels, 10 ) )
1037 : {
1038 0 : st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 );
1039 : }
1040 0 : ELSE IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) )
1041 : {
1042 0 : st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand );
1043 : }
1044 :
1045 0 : timeIn_e = 2;
1046 0 : move16();
1047 0 : Scale_sig( timeDomainBuffer, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1048 0 : IF( st_fx->p_bpf_noise_buf )
1049 : {
1050 0 : Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1051 : }
1052 :
1053 0 : timeIn_e = negate( timeIn_e );
1054 0 : cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer );
1055 : }
1056 :
1057 1248 : IF( st_fx->flag_cna == 0 )
1058 : {
1059 984 : set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen );
1060 : }
1061 :
1062 1248 : IF( st_fx->p_bpf_noise_buf )
1063 : {
1064 1248 : Word16 timeInBpf_e = timeIn_e;
1065 1248 : move16();
1066 1248 : if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1067 : {
1068 1248 : timeInBpf_e = 0;
1069 1248 : move16();
1070 : }
1071 :
1072 1248 : addBassPostFilter_fx( st_fx->p_bpf_noise_buf, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer,
1073 1248 : timeInBpf_e, CLDFB_NO_COL_MAX, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &st_fx->scaleFactor );
1074 :
1075 1248 : IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1076 : {
1077 0 : Scale_sig( st_fx->p_bpf_noise_buf, st_fx->L_frame, timeIn_e ); /*timeIn_e*/
1078 : }
1079 : }
1080 :
1081 1248 : IF( GT_32( st_fx->output_Fs, 8000 ) )
1082 : {
1083 1248 : st_fx->hTECDec->cldfbExp = add( 15, st_fx->scaleFactor.lb_scale );
1084 :
1085 1248 : calcGainTemp_TBE_Fx( realBuffer, imagBuffer, st_fx->hTECDec->cldfbExp, st_fx->hTECDec->loBuffer,
1086 : 0, /*startPos,*/ /*!< Start position of the current envelope. */
1087 1248 : st_fx->cldfbAna->no_col,
1088 : /*stopPos,*/ /*!< Stop position of the current envelope. */
1089 1248 : st_fx->cldfbAna->no_channels, /*lowSubband*/
1090 1248 : st_fx->hTECDec->pGainTemp_m, st_fx->hTECDec->pGainTemp_e, st_fx->tec_flag );
1091 : }
1092 :
1093 : /* set high band buffers to zero. Covering the current frame and the overlap area. */
1094 1248 : IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1095 : {
1096 21216 : FOR( i = 0; i < 16; i++ )
1097 : {
1098 19968 : set32_fx( &realBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) );
1099 19968 : set32_fx( &imagBuffer[i][nab], 0, sub( st_fx->cldfbSyn->no_channels, nab ) );
1100 : }
1101 : }
1102 :
1103 1248 : timeIn_e = s_min( 0, add( timeIn_e, 2 ) );
1104 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*/
1105 :
1106 : /* MODE1 MDCT to ACELP 2 transition */
1107 1248 : delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS );
1108 1248 : Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /*Q0*/
1109 1248 : hHQ_core->Q_old_postdec = 0;
1110 1248 : move16();
1111 1248 : delay_tdbwe = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); /*Q0*/
1112 1248 : IF( GE_16( output_frame, L_FRAME16k ) )
1113 : {
1114 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, sub( Qpostd, st_fx->Qprev_synth_buffer_fx ) ); /*Qpostd*/
1115 : }
1116 :
1117 1248 : test();
1118 1248 : IF( EQ_16( st_fx->last_codec_mode, MODE1 ) && GT_16( st_fx->last_core_bfi, ACELP_CORE ) )
1119 : {
1120 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*/
1121 18 : IF( EQ_16( st_fx->core, ACELP_CORE ) )
1122 : {
1123 : Word16 step, alpha, nz;
1124 :
1125 7 : i = 15;
1126 7 : move16();
1127 7 : tmps = NS2SA_FX2( st_fx->output_Fs, 3000000L ); /*Q0*/
1128 7 : nz = NS2SA_FX2( st_fx->output_Fs, N_ZERO_MDCT_NS ); /*Q0*/
1129 7 : step = Inv16( tmps, &i ); /*Q15 - i*/
1130 7 : step = shl( step, i );
1131 7 : alpha = 0;
1132 7 : move16();
1133 :
1134 7 : test();
1135 7 : IF( st_fx->prev_bfi && hHQ_core->HqVoicing )
1136 : {
1137 0 : Copy( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps ); /*hHQ_core->Q_fer_samples*/
1138 : }
1139 : ELSE
1140 : {
1141 7 : Scale_sig( hHQ_core->old_out_fx, nz + tmps, negate( hHQ_core->Q_old_wtda ) ); /*Q0*/
1142 : }
1143 7 : hHQ_core->Q_old_wtda = 0;
1144 7 : move16();
1145 :
1146 1015 : FOR( i = 0; i < tmps; i++ )
1147 : {
1148 1008 : 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*/
1149 1008 : move16();
1150 1008 : alpha = add( alpha, step );
1151 : }
1152 : }
1153 : ELSE
1154 : {
1155 11 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1156 : {
1157 0 : Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf, delay_comp ); /*Q0*/
1158 : }
1159 : ELSE
1160 : {
1161 11 : Copy( st_fx->prev_synth_buffer_fx, hTcxDec->FBTCXdelayBuf, delay_tdbwe ); /*st_fx->q_prev_synth_buffer_fx*/
1162 11 : Copy( st_fx->delay_buf_out_fx, hTcxDec->FBTCXdelayBuf + delay_tdbwe, delay_comp ); /*Q0*/
1163 : }
1164 : }
1165 : }
1166 :
1167 : /* set delay compensation between HQ synthesis and ACELP synthesis */
1168 1248 : test();
1169 1248 : IF( EQ_16( st_fx->core, ACELP_CORE ) && !( st_fx->con_tcx ) )
1170 : {
1171 610 : set16_fx( st_fx->delay_buf_out_fx, 0, delay_comp );
1172 610 : Copy_Scale_sig( output_sp, st_fx->previoussynth_fx, output_frame, timeIn_e ); /*timeIn_e*/
1173 : }
1174 : ELSE
1175 : {
1176 638 : Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); /*Q0*/
1177 638 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1178 : {
1179 0 : Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/
1180 : }
1181 : ELSE
1182 : {
1183 638 : Copy( hTcxDec->FBTCXdelayBuf + delay_tdbwe, st_fx->previoussynth_fx, delay_comp ); /*st_fx->q_prev_synth_buffer_fx*/
1184 : }
1185 638 : Copy( pcmbufFB, st_fx->previoussynth_fx + delay_comp, sub( output_frame, delay_comp ) ); /*Q0*/
1186 : }
1187 : }
1188 :
1189 : /* Delay compensation for TD-BWE*/
1190 1248 : IF( GE_16( output_frame, L_FRAME16k ) )
1191 : {
1192 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, negate( timeIn_e ) );
1193 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*/
1194 1248 : Scale_sig( st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e );
1195 : }
1196 :
1197 1248 : test();
1198 1248 : IF( st_fx->igf != 0 && EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
1199 : {
1200 1248 : test();
1201 1248 : test();
1202 1248 : test();
1203 1248 : test();
1204 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*/ )
1205 : {
1206 68 : tmp16 = 0;
1207 68 : move16();
1208 68 : if ( EQ_16( st_fx->tec_flag, 2 ) )
1209 : {
1210 5 : tmp16 = 1;
1211 5 : move16();
1212 : }
1213 :
1214 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,
1215 68 : st_fx->tfa_flag, st_fx->last_core, shr( output_frame, 4 ), tmp16 );
1216 : }
1217 :
1218 1248 : test();
1219 1248 : test();
1220 1248 : test();
1221 1248 : test();
1222 1248 : test();
1223 1248 : test();
1224 1248 : IF( ( ( ( st_fx->bfi == 0 || st_fx->last_core == ACELP_CORE ) && st_fx->core == ACELP_CORE ) ||
1225 : ( ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && ( NE_16( st_fx->bwidth, NB ) && EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) ) &&
1226 : ( GT_32( st_fx->output_Fs, 8000 ) ) )
1227 : {
1228 : /* Add the delayed hb_synth component to the delayed core synthesis */
1229 633 : add_vec_fx( output_sp, negate( timeIn_e ), hb_synth_fx, hb_synth_fx_exp, output_sp, negate( timeIn_e ), output_frame );
1230 : }
1231 : }
1232 :
1233 1248 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1234 : {
1235 0 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /*Q0*/
1236 : }
1237 : ELSE
1238 : {
1239 1248 : tmps = NS2SA_FX2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); /*Q0*/
1240 : }
1241 1248 : delta = NS2SA_FX2( st_fx->output_Fs, TCXLTP_DELAY_NS ); /*Q0*/
1242 :
1243 1248 : test();
1244 1248 : test();
1245 1248 : test();
1246 : /* TCX/ACELP/HQ-CORE->TCX */
1247 1248 : IF( ( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) || GT_16( st_fx->core, ACELP_CORE ) )
1248 : {
1249 638 : test();
1250 638 : test();
1251 638 : test();
1252 638 : test();
1253 : /* TCX / HQ-CORE / TD-TCX-PLC -> TCX / TD-TCX-PLC */
1254 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 ) )
1255 : {
1256 601 : Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, tmps, negate( timeIn_e ) ); /*Q0*/
1257 601 : Copy_Scale_sig( pcmbufFB, output_sp + tmps, sub( hTcxDec->L_frameTCX, tmps ), negate( timeIn_e ) ); /*Q0*/
1258 : }
1259 : /* ACELP -> TCX */
1260 : ELSE
1261 : {
1262 : /*cross-fading between LB-TCX and FB-TCX over 2.3125ms*/
1263 : Word16 step, alpha;
1264 :
1265 37 : i = 15;
1266 37 : move16();
1267 37 : step = Inv16( tmps, &i );
1268 37 : step = shl( step, i );
1269 37 : alpha = 0;
1270 37 : move16();
1271 :
1272 3663 : FOR( i = 0; i < tmps; i++ )
1273 : {
1274 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*/
1275 3626 : move16();
1276 3626 : alpha = add( alpha, step );
1277 : }
1278 37 : Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); /*Q0*/
1279 : }
1280 :
1281 638 : Copy( pcmbufFB + sub( hTcxDec->L_frameTCX, tmps ), hTcxDec->FBTCXdelayBuf, tmps );
1282 :
1283 638 : test();
1284 638 : IF( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) )
1285 : {
1286 0 : IF( EQ_32( st_fx->output_Fs, 8000 ) )
1287 : {
1288 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*/
1289 : }
1290 : ELSE
1291 : {
1292 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*/
1293 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*/
1294 : }
1295 : }
1296 : }
1297 : /* TCX/TD TCX PLC->ACELP */
1298 610 : ELSE IF( ( EQ_16( st_fx->last_codec_mode, MODE2 ) ) && ( GT_16( st_fx->last_core, ACELP_CORE ) ) )
1299 : {
1300 : Word16 step, alpha;
1301 :
1302 23 : Copy_Scale_sig( hTcxDec->FBTCXdelayBuf, output_sp, delta, negate( timeIn_e ) ); /*Q0*/
1303 :
1304 23 : i = 15;
1305 23 : move16();
1306 23 : step = Inv16( sub( tmps, delta ), &i );
1307 23 : step = shl( step, i );
1308 23 : alpha = 0;
1309 23 : move16();
1310 :
1311 2300 : FOR( i = delta; i < tmps; i++ )
1312 : {
1313 2277 : output_sp[i] = msu_r_sat( L_mult( output_sp[i], alpha ), shr_sat( hTcxDec->FBTCXdelayBuf[i], timeIn_e ), add( alpha, -32768 ) ); /*Q0*/
1314 2277 : move16();
1315 2277 : alpha = add_sat( alpha, step );
1316 : }
1317 : }
1318 :
1319 1248 : Scale_sig( hTcxLtpDec->tcxltp_mem_in, delta, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1320 1248 : Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1321 :
1322 1248 : Scale_sig( output_sp, output_frame, timeIn_e ); /*timeIn_e*/
1323 :
1324 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 );
1325 1248 : Copy( output_sp, synth_fx, output_frame ); /*timeIn_e*/
1326 :
1327 : } /* end of Mode 2 */
1328 :
1329 :
1330 : /*----------------------------------------------------------------*
1331 : * Save synthesis for HQ FEC
1332 : *----------------------------------------------------------------*/
1333 :
1334 3100 : save_synthesis_hq_fec_fx( st_fx, synth_fx, NULL, output_frame, Qpostd, NULL );
1335 :
1336 : /*----------------------------------------------------------------*
1337 : * HP filtering
1338 : *----------------------------------------------------------------*/
1339 :
1340 3100 : st_fx->Qprev_synth_buffer_fx = Qpostd;
1341 3100 : move16();
1342 3100 : Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/
1343 3100 : hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) );
1344 :
1345 : /*----------------------------------------------------------------*
1346 : * Synthesis output
1347 : *----------------------------------------------------------------*/
1348 :
1349 3100 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
1350 : {
1351 : /* final output of synthesis signal */
1352 1852 : syn_output_fx( st_fx->codec_mode, synth_fx, output_frame, output_sp, Qpostd );
1353 : }
1354 : ELSE
1355 : {
1356 1248 : Copy( synth_fx, output_sp, output_frame ); /*Q0*/
1357 : }
1358 :
1359 : /*--------------------------------------------------------*
1360 : * Updates
1361 : *--------------------------------------------------------*/
1362 :
1363 3100 : test();
1364 3100 : IF( st_fx->last_is_cng == 0 && EQ_16( st_fx->codec_mode, MODE2 ) )
1365 : {
1366 1248 : st_fx->bfi = 0;
1367 1248 : move16();
1368 1248 : test();
1369 1248 : test();
1370 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 ) )
1371 : {
1372 0 : if ( EQ_16( frameMode, FRAMEMODE_MISSING ) )
1373 : {
1374 0 : st_fx->bfi = 1;
1375 0 : move16();
1376 : }
1377 : }
1378 1248 : ELSE IF( EQ_16( st_fx->m_decodeMode, DEC_CONCEALMENT_EXT ) )
1379 : {
1380 0 : st_fx->bfi = 1;
1381 0 : move16();
1382 : }
1383 1248 : updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd );
1384 : }
1385 : ELSE
1386 : {
1387 1852 : if ( EQ_16( st_fx->codec_mode, MODE2 ) )
1388 : {
1389 0 : st_fx->bfi = 0;
1390 0 : move16();
1391 : }
1392 1852 : updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd );
1393 : }
1394 :
1395 3100 : pop_wmops();
1396 :
1397 3100 : return IVAS_ERR_OK;
1398 : }
|