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