Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 : #include <stdint.h>
37 : #include <assert.h>
38 : #include <math.h>
39 : #include "options.h"
40 : #include "cnst.h"
41 : #include "rom_com.h"
42 : #include "prot_fx.h"
43 : #include "ivas_cnst.h"
44 : #include "ivas_rom_com.h"
45 : #include "wmc_auto.h"
46 : #include "ivas_prot_fx.h"
47 :
48 :
49 : /*-------------------------------------------------------------------*
50 : * acelp_core_dec_fx()
51 : *
52 : * ACELP core decoder
53 : *-------------------------------------------------------------------*/
54 :
55 169147 : ivas_error acelp_core_dec_fx(
56 : Decoder_State *st, /* i/o: decoder state structure */
57 : Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/
58 : Word16 synth_fx16[], /* o : synthesis Q_syn2*/
59 : Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/
60 : Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/
61 : Word16 *voice_factors_fx, /* o : voicing factors Q15*/
62 : Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/
63 : const Word16 sharpFlag, /* i : formant sharpening flag */
64 : Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe Q6*/
65 : Word16 *unbits, /* o : number of unused bits */
66 : Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */
67 : STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle Qlog2(2.56)*/
68 : const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel Q15*/
69 : const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */
70 : const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */
71 : const Word16 last_element_mode, /* i : last element mode */
72 : const Word32 last_element_brate, /* i : last element bitrate */
73 : const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */
74 : const Word16 nchan_out, /* i : number of output channels */
75 : STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
76 : const Word16 read_sid_info /* i : read SID info flag */
77 : )
78 : {
79 : Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/;
80 : Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */
81 : Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */
82 : Word16 output_frame; /* frame length at output sampling freq. */
83 : Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */
84 : Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */
85 : Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */
86 : Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */
87 : Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */
88 : Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */
89 : Word32 enr_q_fx; /* E information for FER protection */
90 : Word16 tmp_noise_fx; /* Long term temporary noise energy */
91 : Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */
92 : Word16 FEC_pitch_fx; /* FEC pitch */
93 : Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */
94 : Word16 *bwe_exc_fx; /* Excitation for SWB TBE */
95 : Word16 i, j, int_fs;
96 : Word16 tc_subfr;
97 : Word16 allow_cn_step;
98 : Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM];
99 : Word16 last_pulse_pos;
100 : Word16 T0_tmp;
101 : Word16 do_WI;
102 : Word16 dct_buffer_fx[DCT_L_POST];
103 : Word16 exc_buffer_fx[DCT_L_POST];
104 : Word16 dct_exc_tmp_fx[L_FRAME16k];
105 : Word16 nb_bits; /* number of bits */
106 : Word16 indice; /* parameter indices to write */
107 : Word16 gain_buf_fx[NB_SUBFR16k];
108 : Word16 syn_fx_tmp2[L_FRAME_16k];
109 : Word16 pitch_buf_tmp[NB_SUBFR16k];
110 : Word16 update_flg;
111 : Word32 q_env_fx[20];
112 : Word16 exc3_fx[L_FRAME16k];
113 : Word16 syn1_tmp_fx[L_FRAME16k + 2], *syn1_fx;
114 : Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX];
115 : Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
116 : Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
117 : Word16 LSF_Q_prediction; /* LSF prediction mode */
118 : Word16 avoid_lpc_burst_on_recovery;
119 : Word16 tmpF_fx;
120 : Word16 uc_two_stage_flag;
121 : Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag;
122 : Word16 *old_exc_s_fx; /* Start of last excitation frame */
123 : Word16 *p_tdm_Pri_pitch_buf_fx;
124 : Word16 tmp, exp, local_element_mode;
125 : ivas_error error;
126 : Word32 bpf_error_signal_fx[L_FRAME16k];
127 : Word16 bpf_error_signal_16fx[L_FRAME16k];
128 : Word16 Q_real;
129 : Word32 max_real, max_imag, max_val;
130 :
131 169147 : set32_fx( bpf_error_signal_fx, 0, L_FRAME16k );
132 169147 : set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k );
133 169147 : set16_fx( Aq_fx, 0, NB_SUBFR16k * ( M + 1 ) );
134 169147 : set16_fx( old_bwe_exc_fx, 0, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) );
135 :
136 169147 : error = IVAS_ERR_OK;
137 169147 : move32();
138 :
139 169147 : test();
140 169147 : test();
141 169147 : test();
142 169147 : IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) )
143 : {
144 : /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */
145 1090 : return error;
146 : }
147 :
148 168057 : push_wmops( "acelp_core_dec" );
149 :
150 : /* output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); */
151 168057 : output_frame = extract_l( Mpy_32_32( st->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
152 :
153 : /*----------------------------------------------------------------*
154 : * stereo SID and CNG frames processing
155 : *----------------------------------------------------------------*/
156 :
157 168057 : test();
158 168057 : test();
159 168057 : IF( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) )
160 : {
161 5470 : IF( EQ_16( st->cng_type, FD_CNG ) )
162 : {
163 4233 : configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
164 :
165 : Word16 old_NoiseEstExp;
166 4233 : old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
167 4233 : move16();
168 :
169 : /* Only run parameter decoding in SID frames */
170 4233 : IF( EQ_32( st->core_brate, SID_2k40 ) )
171 : {
172 571 : FdCng_decodeSID_ivas_fx( st );
173 :
174 : Word16 n1, n2;
175 571 : n1 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART );
176 571 : n2 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART );
177 :
178 571 : Word16 common_e = s_max( sub( old_NoiseEstExp, n2 ), sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, n1 ) );
179 571 : scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, common_e ) );
180 571 : scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, common_e ) );
181 571 : st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e;
182 571 : move16();
183 : }
184 :
185 105825 : FOR( i = 0; i < NPART; i++ )
186 : {
187 101592 : st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
188 101592 : STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] );
189 101592 : move32();
190 : }
191 :
192 4233 : ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 );
193 : }
194 : ELSE
195 : {
196 1237 : configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode );
197 :
198 : /* decode CNG parameters */
199 1237 : CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx );
200 :
201 : /* comfort noise generation */
202 1237 : CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode );
203 :
204 1237 : Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/
205 :
206 : /* update old LSP and LSF vector */
207 1237 : Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/
208 1237 : Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/
209 : }
210 :
211 5470 : set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
212 5470 : set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */
213 :
214 : /* CN generation done in DFT domain */
215 5470 : pop_wmops();
216 :
217 5470 : return error;
218 : }
219 :
220 : /*----------------------------------------------------------------*
221 : * Active frames processing
222 : *----------------------------------------------------------------*/
223 :
224 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
225 2763979 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
226 : {
227 2601392 : set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
228 2601392 : set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX );
229 2601392 : realBuffer_fx[i] = realBufferTmp_fx[i];
230 2601392 : imagBuffer_fx[i] = imagBufferTmp_fx[i];
231 : }
232 :
233 : /*----------------------------------------------------------------*
234 : * Initialization
235 : *----------------------------------------------------------------*/
236 :
237 162587 : LSF_Q_prediction = -1;
238 162587 : move16();
239 162587 : set16_fx( syn_tmp_fx, 0, L_SUBFR );
240 162587 : psyn_fx = syn_tmp_fx + L_SUBFR;
241 162587 : syn1_tmp_fx[0] = 0;
242 162587 : move16();
243 162587 : syn1_tmp_fx[1] = 0;
244 162587 : move16();
245 162587 : syn1_fx = syn1_tmp_fx + 2;
246 162587 : st->bpf_off = 0;
247 162587 : move16();
248 :
249 162587 : test();
250 162587 : test();
251 162587 : test();
252 162587 : test();
253 162587 : test();
254 162587 : test();
255 162587 : IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) )
256 : {
257 : /* in case of HQ->ACELP switching, do not apply BPF */
258 18854 : st->bpf_off = 1;
259 18854 : move16();
260 18854 : if ( st->hPFstat != NULL )
261 : {
262 : /* in case of core switching, reset post-filter memories */
263 11600 : st->hPFstat->on = 0;
264 11600 : move16();
265 : }
266 :
267 18854 : if ( st->hGSCDec != NULL )
268 : {
269 : /* reset the GSC pre echo energy threshold in case of switching */
270 11600 : st->hGSCDec->Last_frame_ener_fx = MAX_32;
271 11600 : move32();
272 : }
273 : }
274 :
275 162587 : test();
276 162587 : if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) )
277 : {
278 : /* reset the GSC pre echo energy threshold in case of FEC */
279 2971 : st->hGSCDec->Last_frame_ener_fx = MAX_32;
280 2971 : move32();
281 : }
282 :
283 162587 : test();
284 162587 : test();
285 162587 : test();
286 162587 : test();
287 162587 : IF( st->hFdCngDec != NULL && ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) )
288 : {
289 5001 : set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN );
290 5001 : set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN );
291 : }
292 :
293 162587 : st->clas_dec = st->last_good;
294 162587 : move16();
295 162587 : enr_q_fx = 0;
296 162587 : move32();
297 162587 : Es_pred_fx = 0;
298 162587 : move16();
299 162587 : tmp_noise_fx = 0;
300 162587 : move16();
301 162587 : Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/
302 162587 : exc_fx = old_exc_fx + L_EXC_MEM_DEC;
303 :
304 162587 : IF( st->hWIDec != NULL )
305 : {
306 0 : Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM );
307 : }
308 : ELSE
309 : {
310 162587 : set16_fx( old_exc2_fx, 0, L_EXC_MEM );
311 : }
312 162587 : exc2_fx = old_exc2_fx + L_EXC_MEM;
313 :
314 162587 : IF( st->hBWE_TD != NULL )
315 : {
316 155238 : Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/
317 155238 : bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2;
318 : }
319 : ELSE
320 : {
321 7349 : bwe_exc_fx = NULL;
322 : }
323 :
324 162587 : last_pulse_pos = 0;
325 162587 : move16();
326 162587 : do_WI = 0;
327 162587 : move16();
328 162587 : st->GSC_noisy_speech = 0;
329 162587 : move16();
330 162587 : st->relax_prev_lsf_interp = 0;
331 162587 : move16();
332 162587 : set16_fx( gain_buf_fx, 0, NB_SUBFR16k );
333 :
334 162587 : IF( EQ_16( st->L_frame, L_FRAME ) )
335 : {
336 81355 : st->gamma = GAMMA1;
337 81355 : move16();
338 81355 : st->inv_gamma = GAMMA1_INV;
339 81355 : move16();
340 81355 : st->preemph_fac = PREEMPH_FAC;
341 81355 : move16();
342 81355 : int_fs = INT_FS_12k8;
343 81355 : move16();
344 : }
345 : ELSE
346 : {
347 81232 : st->gamma = GAMMA16k;
348 81232 : move16();
349 81232 : st->inv_gamma = GAMMA16k_INV;
350 81232 : move16();
351 81232 : st->preemph_fac = PREEMPH_FAC_16k;
352 81232 : move16();
353 81232 : int_fs = INT_FS_16k;
354 81232 : move16();
355 : }
356 :
357 162587 : test();
358 : /* reset post-filter in case of switching */
359 162587 : if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) )
360 : {
361 23134 : st->hPFstat->reset = 1;
362 23134 : move16();
363 : }
364 :
365 162587 : avoid_lpc_burst_on_recovery = 0;
366 162587 : move16();
367 162587 : test();
368 162587 : test();
369 162587 : if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) )
370 : {
371 28 : avoid_lpc_burst_on_recovery = 1;
372 28 : move16();
373 : }
374 162587 : test();
375 :
376 : /* TD stereo parameters */
377 162587 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
378 : {
379 3751 : tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag;
380 3751 : move16();
381 3751 : tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode;
382 3751 : move16();
383 3751 : tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag;
384 3751 : move16();
385 3751 : p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx;
386 : }
387 : ELSE
388 : {
389 158836 : tdm_lp_reuse_flag = 0;
390 158836 : move16();
391 158836 : tdm_low_rate_mode = 0;
392 158836 : move16();
393 158836 : test();
394 158836 : if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
395 : {
396 7168 : tdm_low_rate_mode = 1;
397 7168 : move16();
398 : }
399 158836 : tdm_Pitch_reuse_flag = 0;
400 158836 : move16();
401 158836 : p_tdm_Pri_pitch_buf_fx = NULL;
402 : }
403 :
404 : /*----------------------------------------------------------------*
405 : * Updates in case of internal sampling rate switching
406 : *----------------------------------------------------------------*/
407 :
408 162587 : test();
409 162587 : test();
410 162587 : IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) )
411 : {
412 : Word16 dec;
413 :
414 690 : IF( ( st->hPFstat->on != 0 ) )
415 : {
416 : Word16 mem_syn_r_size_old, mem_syn_r_size_new;
417 619 : mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/
418 619 : mem_syn_r_size_new = mult_r( 2048, st->L_frame ); /* 1.25/20.f = 2048 (Q15)*/
419 619 : lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
420 619 : lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
421 : }
422 :
423 : /* convert quantized LSP vector */
424 690 : st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
425 690 : move16();
426 :
427 : /* convert old quantized LSF vector */
428 690 : lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs );
429 :
430 : /* FEC - update adaptive LSF mean vector */
431 690 : Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/
432 690 : Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/
433 690 : Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/
434 :
435 : /* Reset LPC mem */
436 690 : IF( EQ_32( st->sr_core, INT_FS_16k ) )
437 : {
438 414 : Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/
439 : }
440 : ELSE
441 : {
442 276 : Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/
443 : }
444 690 : set16_fx( st->mem_MA_fx, 0, M );
445 :
446 : /* update synthesis filter memories */
447 690 : dec = DEC;
448 690 : move16();
449 690 : if ( st->element_mode != EVS_MONO )
450 : {
451 690 : dec = DEC_IVAS;
452 690 : move16();
453 : }
454 690 : ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec );
455 690 : Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/
456 690 : Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/
457 690 : Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/
458 : }
459 :
460 : /* update buffer of old subframe pitch values */
461 162587 : IF( NE_16( st->last_L_frame, st->L_frame ) )
462 : {
463 1846 : IF( EQ_16( st->L_frame, L_FRAME ) )
464 : {
465 1088 : IF( EQ_16( st->last_L_frame, L_FRAME32k ) )
466 : {
467 267 : tmpF_fx = 13107; // Q15
468 267 : move16();
469 : }
470 821 : ELSE IF( EQ_16( st->last_L_frame, 512 ) )
471 : {
472 268 : tmpF_fx = 16384; // Q15
473 268 : move16();
474 : }
475 : ELSE /* st->last_L_frame == L_FRAME16k */
476 : {
477 553 : tmpF_fx = 26214; // Q15
478 553 : move16();
479 : }
480 :
481 5440 : FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ )
482 : {
483 4352 : st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16
484 4352 : move32();
485 : }
486 :
487 5440 : FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ )
488 : {
489 4352 : st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16
490 4352 : move32();
491 : }
492 : }
493 : ELSE
494 : {
495 758 : exp = 0;
496 758 : move16();
497 758 : IF( EQ_16( st->last_L_frame, L_FRAME32k ) )
498 : {
499 41 : tmpF_fx = 16384; // Q15
500 41 : move16();
501 : }
502 717 : ELSE IF( EQ_16( st->last_L_frame, 512 ) )
503 : {
504 259 : tmpF_fx = 20480; // Q15
505 259 : move16();
506 : }
507 : ELSE /* st->last_L_frame == L_FRAME12k8 */
508 : {
509 458 : tmpF_fx = 20480; // Q14
510 458 : move16();
511 458 : exp = 1;
512 458 : move16();
513 : }
514 3790 : FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- )
515 : {
516 3032 : st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15
517 3032 : move32();
518 : }
519 758 : st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2];
520 758 : move32();
521 :
522 3790 : FOR( i = NB_SUBFR - 1; i >= 0; i-- )
523 : {
524 3032 : st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15
525 3032 : move32();
526 : }
527 758 : st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1];
528 758 : move32();
529 : }
530 : }
531 :
532 162587 : IF( NE_16( st->bfi_pitch_frame, st->L_frame ) )
533 : {
534 2978 : IF( EQ_16( st->L_frame, L_FRAME ) )
535 : {
536 1069 : IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) )
537 : {
538 267 : tmpF_fx = 13107; // Q15
539 267 : move16();
540 : }
541 802 : ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) )
542 : {
543 270 : tmpF_fx = 16384; // Q15
544 270 : move16();
545 : }
546 : ELSE /* st->bfi_pitch_frame == L_FRAME16k */
547 : {
548 532 : tmpF_fx = 26214; // Q15
549 532 : move16();
550 : }
551 1069 : st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx );
552 1069 : move16();
553 1069 : st->bfi_pitch_frame = L_FRAME;
554 1069 : move16();
555 : }
556 : ELSE
557 : {
558 1909 : exp = 0;
559 1909 : move16();
560 1909 : IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) )
561 : {
562 41 : tmpF_fx = 16384; // Q15
563 41 : move16();
564 : }
565 1868 : ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) )
566 : {
567 259 : tmpF_fx = 20480; // Q15
568 259 : move16();
569 : }
570 : ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */
571 : {
572 1609 : tmpF_fx = 20480; // Q14
573 1609 : move16();
574 1609 : exp = 1;
575 1609 : move16();
576 : }
577 :
578 1909 : st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx );
579 1909 : move16();
580 1909 : st->bfi_pitch_frame = L_FRAME16k;
581 1909 : move16();
582 : }
583 : }
584 :
585 162587 : test();
586 162587 : test();
587 162587 : if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) )
588 : {
589 0 : st->rate_switching_reset = 1;
590 0 : move16();
591 : }
592 :
593 : /*----------------------------------------------------------------------*
594 : * GOOD frame
595 : *----------------------------------------------------------------------*/
596 :
597 162587 : IF( !st->bfi )
598 : {
599 :
600 : /*----------------------------------------------------------------*
601 : * Decoding of TC subframe classification
602 : *----------------------------------------------------------------*/
603 :
604 159648 : tc_subfr = -1;
605 159648 : move16();
606 159648 : IF( EQ_16( st->coder_type, TRANSITION ) )
607 : {
608 12668 : tc_subfr = tc_classif_fx( st, st->L_frame );
609 : }
610 :
611 : /*----------------------------------------------------------------*
612 : * Decoding of GSC IVAS mode
613 : *----------------------------------------------------------------*/
614 :
615 159648 : test();
616 159648 : test();
617 159648 : test();
618 159648 : test();
619 159648 : IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode )
620 : {
621 128272 : test();
622 128272 : test();
623 128272 : IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && EQ_16( st->inactive_coder_type_flag, 1 ) ) )
624 : {
625 13791 : st->GSC_IVAS_mode = get_next_indice_fx( st, 2 );
626 13791 : move16();
627 : }
628 : }
629 :
630 : /*----------------------------------------------------------------*
631 : * Decoding of inactive CNG frames
632 : *----------------------------------------------------------------*/
633 :
634 159648 : test();
635 159648 : IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) )
636 19522 : {
637 : /* decode CNG parameters */
638 19522 : IF( st->cng_type == LP_CNG )
639 : {
640 1141 : CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx );
641 1141 : Copy( Aq_fx, st->Aq_cng, add( M, 1 ) );
642 :
643 : /* comfort noise generation */
644 1141 : local_element_mode = st->element_mode;
645 1141 : move16();
646 :
647 1141 : test();
648 1141 : test();
649 1141 : if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) )
650 : {
651 1141 : local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */
652 1141 : move16();
653 : }
654 1141 : CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode );
655 : }
656 : ELSE
657 : {
658 18381 : test();
659 18381 : IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
660 : {
661 1342 : IF( EQ_16( st->element_mode, EVS_MONO ) )
662 : {
663 0 : FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st );
664 : }
665 : ELSE
666 : {
667 1342 : Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
668 1342 : move16();
669 :
670 1342 : FdCng_decodeSID_ivas_fx( st );
671 :
672 1342 : Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) );
673 1342 : Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx
674 : }
675 :
676 1342 : *sid_bw = 0;
677 1342 : move16();
678 : }
679 :
680 18381 : IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
681 : {
682 3740 : assert( nchan_out == 1 );
683 :
684 93500 : FOR( i = 0; i < NPART; i++ )
685 : {
686 89760 : st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ),
687 89760 : STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] );
688 89760 : move32();
689 : }
690 :
691 3740 : ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
692 :
693 3740 : Word16 new_sidNoiseEstExp = 31 - Q4;
694 3740 : move16();
695 3740 : Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp)
696 3740 : Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp)
697 3740 : st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp;
698 3740 : move16();
699 3740 : Word16 new_cngNoiseLevelExp = 31 - Q4;
700 3740 : move16();
701 3740 : Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp)
702 3740 : st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp;
703 3740 : move16();
704 :
705 3740 : test();
706 3740 : ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) );
707 :
708 3740 : IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 )
709 : {
710 1192 : Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp)
711 1192 : st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0;
712 1192 : move16();
713 : }
714 : }
715 :
716 18381 : IF( !read_sid_info )
717 : {
718 : Word32 noise_lvl_highest_fx;
719 :
720 3159 : noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1];
721 3159 : move32();
722 :
723 65640 : FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ )
724 : {
725 62481 : st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx;
726 62481 : move32();
727 : }
728 : }
729 :
730 18381 : IF( EQ_16( st->element_mode, EVS_MONO ) )
731 : {
732 0 : generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 );
733 : }
734 : ELSE
735 : {
736 18381 : generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out );
737 : }
738 :
739 18381 : FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
740 :
741 18381 : Copy( exc2_fx, exc3_fx, st->L_frame );
742 : }
743 :
744 19522 : Word16 delta_mem_scale = 3;
745 19522 : move16();
746 19522 : test();
747 19522 : if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */
748 : {
749 72 : delta_mem_scale = 0;
750 72 : move16();
751 : }
752 19522 : i = st->Q_exc;
753 19522 : move16();
754 :
755 19522 : test();
756 19522 : IF( st->hMusicPF && st->hGSCDec )
757 : {
758 12268 : IF( EQ_16( st->element_mode, EVS_MONO ) )
759 : {
760 : // VE: TBV: should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS?
761 0 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame,
762 0 : st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE );
763 : }
764 : ELSE
765 : {
766 12268 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame,
767 12268 : L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE );
768 : }
769 : }
770 :
771 19522 : IF( st->hPFstat != NULL )
772 : {
773 12268 : Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale,
774 12268 : &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL );
775 : }
776 : ELSE
777 : {
778 7254 : Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale,
779 : &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL );
780 : }
781 :
782 19522 : Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc
783 :
784 : /* update past excitation signals for LD music post-filter */
785 19522 : IF( st->hMusicPF != NULL )
786 : {
787 12268 : Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
788 12268 : Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
789 :
790 : /* Update music post processing values */
791 : /* Filter energies update */
792 12268 : IF( EQ_16( st->element_mode, EVS_MONO ) )
793 : {
794 0 : FOR( i = 0; i < DCT_L_POST; i++ )
795 : {
796 0 : st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) );
797 0 : move16();
798 : }
799 : }
800 : ELSE
801 : {
802 7863788 : FOR( i = 0; i < DCT_L_POST; i++ )
803 : {
804 7851520 : st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15, 9830 =.3f in Q15, 22937=.7f in Q15
805 7851520 : move16();
806 : }
807 : }
808 : }
809 :
810 : /* synthesis at 12.8kHz sampling rate */
811 19522 : move16();
812 19522 : syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
813 19522 : syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn );
814 :
815 : /* reset the decoder */
816 19522 : CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx );
817 :
818 19522 : IF( EQ_16( st->element_mode, EVS_MONO ) )
819 : {
820 : /* update st_fx->mem_syn1 for ACELP core switching */
821 0 : Copy( st->mem_syn3_fx, st->mem_syn1_fx, M );
822 : }
823 : ELSE
824 : {
825 19522 : st->Q_syn_cng = st->Q_syn;
826 19522 : move16();
827 19522 : st->Q_exc_cng = st->Q_exc;
828 19522 : move16();
829 :
830 : /* update st->mem_syn1 for ACELP core switching */
831 19522 : Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1)
832 : }
833 :
834 : /* update old synthesis for classification */
835 19522 : Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM );
836 :
837 : /* save and delay synthesis to be used by SWB BWE */
838 19522 : Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn -> Q(-1)
839 19522 : IF( st->hBWE_FD != NULL )
840 : {
841 12299 : save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
842 : }
843 : }
844 :
845 : /*----------------------------------------------------------------*
846 : * Decoding of all other frames
847 : *----------------------------------------------------------------*/
848 :
849 : ELSE
850 : {
851 :
852 : /*-----------------------------------------------------------------*
853 : * Configure ACELP bit allocation
854 : *-----------------------------------------------------------------*/
855 :
856 140126 : nb_bits = 0;
857 140126 : move16();
858 140126 : st->acelp_cfg.FEC_mode = 0;
859 140126 : move16();
860 140126 : uc_two_stage_flag = 0;
861 140126 : move16();
862 :
863 140126 : test();
864 140126 : IF( !st->nelp_mode_dec && !st->ppp_mode_dec )
865 : {
866 : Word16 tc_subfr_tmp;
867 :
868 140126 : tc_subfr_tmp = tc_subfr;
869 140126 : move16();
870 140126 : if ( LT_16( tc_subfr_tmp, L_SUBFR ) )
871 : {
872 133555 : tc_subfr_tmp = 0;
873 133555 : move16();
874 : }
875 :
876 140126 : if ( EQ_16( tc_subfr, TC_0_192 ) )
877 : {
878 188 : nb_bits = -1;
879 188 : move16();
880 : }
881 :
882 140126 : config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
883 :
884 140126 : test();
885 140126 : test();
886 140126 : IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) )
887 : {
888 3519 : config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode );
889 : }
890 : }
891 :
892 : /*-----------------------------------------------------------------*
893 : * After CNG period, use the most up-to-date LSPs
894 : *-----------------------------------------------------------------*/
895 :
896 140126 : test();
897 140126 : test();
898 140126 : IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) )
899 : {
900 614 : Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/
901 614 : lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs );
902 : }
903 :
904 : /*-----------------------------------------------------------------*
905 : * Reset higher ACELP pre-quantizer in case of switching
906 : *-----------------------------------------------------------------*/
907 :
908 140126 : IF( !st->use_acelp_preq )
909 : {
910 129005 : st->mem_preemp_preQ_fx = 0;
911 129005 : move16();
912 129005 : st->last_nq_preQ = 0;
913 129005 : move16();
914 129005 : st->last_code_preq = 0;
915 129005 : move16();
916 : }
917 :
918 140126 : st->use_acelp_preq = 0;
919 140126 : move16();
920 :
921 : /*-----------------------------------------------------------------*
922 : * LSF de-quantization and interpolation
923 : *-----------------------------------------------------------------*/
924 :
925 140126 : IF( !tdm_lp_reuse_flag )
926 : {
927 139985 : lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx );
928 : }
929 : ELSE
930 : {
931 : const Word16 *pt_interp_2_fx;
932 :
933 141 : IF( NE_16( st->active_cnt, 1 ) )
934 : {
935 : Word16 beta_index;
936 :
937 141 : beta_index = get_next_indice_fx( st, TDM_IC_LSF_PRED_BITS );
938 141 : tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index );
939 : }
940 : ELSE
941 : {
942 0 : Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M );
943 0 : Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M );
944 : }
945 :
946 141 : IF( st->rate_switching_reset )
947 : {
948 : /* extrapolation in case of unstable LSF convert */
949 0 : Copy( lsp_new_fx, st->lsp_old_fx, M );
950 0 : Copy( lsf_new_fx, st->lsf_old_fx, M );
951 : }
952 :
953 141 : pt_interp_2_fx = interpol_frac_fx;
954 141 : test();
955 141 : if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) )
956 : {
957 0 : pt_interp_2_fx = interpol_frac2_fx;
958 : }
959 :
960 141 : IF( EQ_16( st->active_cnt, 1 ) )
961 : {
962 0 : Copy( lsp_new_fx, st->lsp_old_fx, M );
963 0 : lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core );
964 : }
965 :
966 : /* LSP interpolation and conversion of LSPs to A(z) */
967 141 : int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 );
968 :
969 : /* Check LSF stability (distance between old LSFs and current LSFs) */
970 141 : st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame );
971 141 : move16();
972 : }
973 :
974 140126 : test();
975 140126 : IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO )
976 : {
977 : /* Prepare ACB memory from last HQ frame */
978 216 : old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame );
979 216 : tmpF_fx = *old_exc_s_fx;
980 216 : st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */
981 216 : move16();
982 216 : PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx );
983 216 : Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M );
984 216 : Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */
985 216 : Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 );
986 216 : Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); /* Q0 -> Q_exc */
987 : }
988 :
989 140126 : test();
990 140126 : IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO )
991 : {
992 : /* Prepare ACB memory of old_bwe_exc */
993 5990 : IF( EQ_16( st->L_frame, L_FRAME ) )
994 : {
995 3040 : lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC );
996 : }
997 : ELSE
998 : {
999 2950 : lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC << 1, L_EXC_MEM_DEC );
1000 : }
1001 : }
1002 :
1003 : /*-----------------------------------------------------------------*
1004 : * FEC - first good frame after lost frame(s) (possibility to correct the ACB)
1005 : *-----------------------------------------------------------------*/
1006 :
1007 140126 : IF( st->acelp_cfg.FEC_mode > 0 )
1008 : {
1009 109205 : last_pulse_pos = 0;
1010 109205 : move16();
1011 :
1012 : /* decode the last glottal pulse position */
1013 109205 : T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits );
1014 :
1015 109205 : test();
1016 109205 : test();
1017 109205 : IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) )
1018 : {
1019 108960 : test();
1020 108960 : test();
1021 108960 : test();
1022 108960 : test();
1023 108960 : test();
1024 108960 : test();
1025 108960 : IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) )
1026 : {
1027 3 : FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc );
1028 : }
1029 108957 : ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL )
1030 : {
1031 0 : do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx );
1032 : }
1033 : }
1034 : }
1035 :
1036 : /*------------------------------------------------------------*
1037 : * In case of first frame after an erasure and transition from voiced to unvoiced or inactive
1038 : * redo the LPC interpolation
1039 : *------------------------------------------------------------*/
1040 :
1041 140126 : test();
1042 140126 : test();
1043 140126 : test();
1044 140126 : test();
1045 140126 : test();
1046 140126 : test();
1047 140126 : IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) )
1048 : {
1049 99 : int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 );
1050 : }
1051 :
1052 : /*---------------------------------------------------------------*
1053 : * Decoding of the scaled predicted innovation energy
1054 : *---------------------------------------------------------------*/
1055 :
1056 140126 : IF( nb_bits > 0 )
1057 : {
1058 116366 : indice = get_next_indice_fx( st, nb_bits );
1059 116366 : Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag );
1060 : }
1061 :
1062 : /*------------------------------------------------------------*
1063 : * Decode excitation according to coding type
1064 : *------------------------------------------------------------*/
1065 :
1066 140126 : test();
1067 140126 : test();
1068 140126 : IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */
1069 : {
1070 6763 : IF( LE_16( st->coder_type, UNVOICED ) )
1071 : {
1072 6763 : tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx );
1073 6763 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1074 : }
1075 : ELSE /* GENERIC */
1076 : {
1077 0 : decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx );
1078 :
1079 0 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
1080 : {
1081 0 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1082 : }
1083 : }
1084 : }
1085 133363 : ELSE IF( st->nelp_mode_dec )
1086 : {
1087 0 : Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
1088 0 : st->Q_exc = 0;
1089 0 : move16();
1090 :
1091 : /* SC-VBR - NELP frames */
1092 0 : decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx );
1093 :
1094 0 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
1095 : }
1096 133363 : ELSE IF( EQ_16( st->coder_type, UNVOICED ) )
1097 : {
1098 : /* UNVOICED frames */
1099 1374 : decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx );
1100 :
1101 1374 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1102 : }
1103 131989 : ELSE IF( st->ppp_mode_dec )
1104 : {
1105 0 : Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
1106 0 : st->Q_exc = 0;
1107 0 : move16();
1108 :
1109 : /* SC-VBR - PPP frames */
1110 0 : IF( NE_32( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ), IVAS_ERR_OK ) )
1111 : {
1112 0 : return error;
1113 : }
1114 :
1115 0 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
1116 : }
1117 131989 : ELSE IF( EQ_16( st->coder_type, TRANSITION ) )
1118 : {
1119 12668 : decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx );
1120 : }
1121 119321 : ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) )
1122 : {
1123 : /* AUDIO and INACTIVE frames (coded by GSC technology) */
1124 13797 : decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx,
1125 : tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx );
1126 :
1127 13797 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1128 : }
1129 : ELSE
1130 : {
1131 : /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */
1132 105524 : IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) )
1133 : {
1134 0 : return error;
1135 : }
1136 :
1137 105524 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
1138 : {
1139 6778 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1140 : }
1141 : }
1142 :
1143 : /* synthesis for ACELP core switching and SWB BWE */
1144 140126 : syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 );
1145 :
1146 : /* save and delay synthesis to be used by SWB BWE */
1147 140126 : IF( st->hBWE_FD != NULL )
1148 : {
1149 140000 : save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
1150 : }
1151 :
1152 : /*-----------------------------------------------------------------*
1153 : * Apply energy matching when switching to inactive frames
1154 : *-----------------------------------------------------------------*/
1155 :
1156 140126 : Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
1157 :
1158 : /*------------------------------------------------------------*
1159 : * Decode information and modify the excitation signal of stationary unvoiced frames
1160 : *------------------------------------------------------------*/
1161 :
1162 140126 : test();
1163 140126 : test();
1164 140126 : test();
1165 140126 : test();
1166 140126 : IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) )
1167 : {
1168 129695 : Word16 temp_q_exc = st->Q_exc;
1169 129695 : move16();
1170 129695 : stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag );
1171 129695 : IF( NE_16( temp_q_exc, st->Q_exc ) )
1172 : {
1173 0 : scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM + st->L_frame, sub( st->Q_exc, temp_q_exc ) );
1174 : }
1175 : }
1176 :
1177 : /*------------------------------------------------------------*
1178 : * Save filter memory in case the synthesis is redone after scaling
1179 : * Synthesis at 12k8 Hz sampling rate
1180 : *------------------------------------------------------------*/
1181 :
1182 : /* update past excitation signals for LD music post-filter */
1183 140126 : IF( st->hMusicPF != NULL )
1184 : {
1185 140126 : Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
1186 140126 : Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
1187 140126 : Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 );
1188 : }
1189 :
1190 140126 : test();
1191 140126 : test();
1192 140126 : test();
1193 140126 : IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) )
1194 9313 : {
1195 9313 : Word16 last_coder_type = st->last_coder_type;
1196 9313 : move16();
1197 :
1198 9313 : test();
1199 9313 : test();
1200 9313 : test();
1201 9313 : if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) )
1202 : {
1203 4029 : last_coder_type = AUDIO;
1204 4029 : move16();
1205 : }
1206 :
1207 9313 : Word16 qdct = 0;
1208 9313 : move16();
1209 :
1210 : /* Extrapolation of the last future part, windowing and high resolution DCT transform */
1211 9313 : IF( EQ_16( st->element_mode, EVS_MONO ) )
1212 : {
1213 : // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate'
1214 0 : Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_coder_type, st->element_mode, pitch_buf_fx,
1215 0 : st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct );
1216 : }
1217 : ELSE
1218 : {
1219 9313 : Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct );
1220 : }
1221 :
1222 : /* LD music post-filter */
1223 9313 : LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct );
1224 :
1225 : /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */
1226 9313 : IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS
1227 : {
1228 9313 : Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/
1229 : }
1230 :
1231 9313 : Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn,
1232 9313 : &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx,
1233 9313 : &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx );
1234 : }
1235 : ELSE
1236 : {
1237 : /* Core synthesis at 12.8kHz or 16kHz */
1238 130813 : i = 1;
1239 130813 : move16();
1240 130813 : test();
1241 130813 : if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO )
1242 : {
1243 6 : i = 0;
1244 6 : move16();
1245 : }
1246 :
1247 : /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
1248 130813 : Word16 k = 0;
1249 130813 : move16();
1250 130813 : test();
1251 130813 : test();
1252 130813 : if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) )
1253 : {
1254 708 : k = 1;
1255 708 : move16();
1256 : }
1257 :
1258 130813 : Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
1259 130813 : st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx );
1260 :
1261 130813 : Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/
1262 130813 : syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
1263 :
1264 130813 : IF( st->hMusicPF != NULL )
1265 : {
1266 83851133 : FOR( i = 0; i < DCT_L_POST; i++ )
1267 : {
1268 83720320 : st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) );
1269 83720320 : move16();
1270 : }
1271 : }
1272 : }
1273 :
1274 : /*------------------------------------------------------------*
1275 : * FEC - Estimate the classification information
1276 : *------------------------------------------------------------*/
1277 :
1278 140126 : FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst,
1279 140126 : NULL, NULL, NULL, NULL, 0, NULL, st->Q_syn, temp_buf_fx, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode );
1280 :
1281 : /*------------------------------------------------------------*
1282 : * FEC - Estimate pitch
1283 : *------------------------------------------------------------*/
1284 :
1285 140126 : FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx,
1286 140126 : &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode );
1287 :
1288 : /*------------------------------------------------------------*
1289 : * FEC - Smooth the speech energy evolution when recovering after a BAD frame
1290 : * (smoothing is performed in the excitation domain and signal is resynthesized after)
1291 : *------------------------------------------------------------*/
1292 :
1293 140126 : Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
1294 :
1295 140126 : FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction,
1296 140126 : &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
1297 140126 : exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 );
1298 :
1299 140126 : test();
1300 140126 : test();
1301 140126 : test();
1302 140126 : test();
1303 : /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
1304 140126 : IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
1305 : {
1306 113 : frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 );
1307 : }
1308 : }
1309 :
1310 : } /* End of GOOD FRAME */
1311 :
1312 : /*----------------------------------------------------------------*
1313 : * BAD frame
1314 : *----------------------------------------------------------------*/
1315 :
1316 : ELSE
1317 : {
1318 : /* SC-VBR */
1319 2939 : if ( EQ_16( st->last_nelp_mode_dec, 1 ) )
1320 : {
1321 0 : st->nelp_mode_dec = 1;
1322 0 : move16();
1323 : }
1324 :
1325 2939 : test();
1326 2939 : test();
1327 : /* long burst frame erasures */
1328 2939 : if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) )
1329 : {
1330 19 : st->last_good = VOICED_TRANSITION;
1331 19 : move16();
1332 : }
1333 :
1334 : /* LSF estimation and A(z) calculation */
1335 2939 : lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth );
1336 :
1337 2939 : FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx );
1338 2939 : IF( EQ_16( st->nelp_mode_dec, 1 ) )
1339 : {
1340 : /* SC-VBR */
1341 0 : Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0
1342 0 : st->Q_exc = 0;
1343 0 : move16();
1344 :
1345 0 : decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx );
1346 0 : FEC_pitch_fx = pitch_buf_fx[3];
1347 0 : move16();
1348 0 : Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type );
1349 : }
1350 : ELSE
1351 : {
1352 : /* calculation of excitation signal */
1353 2939 : FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx );
1354 :
1355 2939 : Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0,
1356 2939 : &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type );
1357 :
1358 2939 : tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/
1359 :
1360 : /* SC-VBR */
1361 2939 : st->prev_gain_pit_dec_fx = st->lp_gainp_fx;
1362 2939 : move16();
1363 : }
1364 :
1365 : /* synthesis for ACELP core switching and SWB BWE */
1366 2939 : syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 );
1367 :
1368 : /* save and delay synthesis to be used by SWB BWE */
1369 2939 : IF( st->hBWE_FD != NULL )
1370 : {
1371 2939 : save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
1372 : }
1373 :
1374 : /* Apply energy matching when switching to inactive frames */
1375 2939 : Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode );
1376 :
1377 : /* update past excitation signals for LD music post-filter */
1378 2939 : IF( st->hMusicPF != NULL )
1379 : {
1380 2939 : Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 );
1381 2939 : Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME );
1382 :
1383 : /* Update music post processing values */
1384 : /* Filter energies update */
1385 1883899 : FOR( i = 0; i < DCT_L_POST; i++ )
1386 : {
1387 1880960 : st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( 1228 << 16, 22938, st->hMusicPF->filt_lfE_fx[i] ) );
1388 1880960 : move16();
1389 : }
1390 :
1391 : /* Update circular buffer, keep last energy difference unchanged */
1392 117560 : FOR( i = 1; i < MAX_LT; i++ )
1393 : {
1394 114621 : st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i];
1395 114621 : move16();
1396 : }
1397 : }
1398 :
1399 : /* synthesis at 12k8 Hz sampling rate */
1400 : /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */
1401 2939 : Word16 k = 0;
1402 2939 : move16();
1403 2939 : test();
1404 2939 : test();
1405 2939 : if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) )
1406 : {
1407 0 : k = 1;
1408 0 : move16();
1409 : }
1410 :
1411 2939 : Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx,
1412 2939 : st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx );
1413 :
1414 2939 : test();
1415 2939 : IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
1416 : {
1417 0 : Copy( st->mem_syn2_fx, mem_tmp_fx, M );
1418 : }
1419 2939 : syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn );
1420 :
1421 : /* update buffer for classifier */
1422 2939 : IF( st->hWIDec != NULL )
1423 : {
1424 0 : Copy( exc2_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_exc2_fx, L_EXC_MEM );
1425 0 : Copy( psyn_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_syn2_fx, L_EXC_MEM );
1426 : }
1427 2939 : st->prev_Q_exc_fr = st->Q_exc;
1428 2939 : move16();
1429 2939 : st->prev_Q_syn_fr = st->Q_syn;
1430 2939 : move16();
1431 2939 : Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM_CLAS_ESTIM ), st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM );
1432 :
1433 : /*------------------------------------------------------------*
1434 : * FEC - Smooth the speech energy evolution when recovering after a BAD frame
1435 : * (smoothing is performed in the excitation domain and signal is resynthesized after)
1436 : *------------------------------------------------------------*/
1437 :
1438 2939 : test();
1439 2939 : IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) )
1440 : {
1441 0 : Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
1442 :
1443 0 : FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction,
1444 0 : &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate,
1445 0 : exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 );
1446 : }
1447 :
1448 : /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */
1449 2939 : frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 );
1450 :
1451 2939 : IF( NE_16( st->nelp_mode_dec, 1 ) )
1452 : {
1453 : /* modify the excitation signal of stationary unvoiced frames */
1454 2939 : stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx,
1455 2939 : &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx,
1456 2939 : &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge );
1457 : }
1458 : }
1459 :
1460 162587 : IF( st->hBWE_TD != NULL )
1461 : {
1462 155238 : IF( EQ_16( st->L_frame, L_FRAME ) )
1463 : {
1464 81229 : Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
1465 : }
1466 : ELSE
1467 : {
1468 74009 : Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) );
1469 : }
1470 : }
1471 :
1472 : /*--------------------------------------------------------*
1473 : * Apply NB postfilter in case of 8kHz output
1474 : *--------------------------------------------------------*/
1475 :
1476 162587 : test();
1477 162587 : IF( st->last_bwidth == NB && st->hPFstat != NULL )
1478 : {
1479 1987 : Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0
1480 :
1481 1987 : IF( st->bwidth == NB )
1482 : {
1483 0 : st->hPFstat->on = 1;
1484 0 : move16();
1485 0 : nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 );
1486 : }
1487 : ELSE
1488 : {
1489 1987 : st->hPFstat->on = 0;
1490 1987 : move16();
1491 1987 : nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 );
1492 : }
1493 : }
1494 : ELSE
1495 : {
1496 160600 : st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) );
1497 160600 : move16();
1498 : }
1499 :
1500 : /*------------------------------------------------------------------*
1501 : * Perform fixed deemphasis through 1/(1 - g*z^-1)
1502 : *-----------------------------------------------------------------*/
1503 :
1504 : /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
1505 162587 : Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM );
1506 162587 : deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) );
1507 162587 : unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame );
1508 162587 : Copy( syn_fx_tmp2, psyn_fx, st->L_frame );
1509 162587 : IF( st->hTcxDec != NULL )
1510 : {
1511 158836 : Copy_Scale_sig( psyn_fx + shr( st->L_frame, 1 ), st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/
1512 158836 : st->hTcxDec->Q_old_syn_Overl = -1;
1513 : }
1514 162587 : Copy_Scale_sig( psyn_fx + sub( st->L_frame, M + 1 ), st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/
1515 :
1516 : /*------------------------------------------------------------------*
1517 : * Formant post-filter
1518 : *-----------------------------------------------------------------*/
1519 :
1520 162587 : test();
1521 162587 : test();
1522 162587 : test();
1523 162587 : test();
1524 162587 : IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) )
1525 : {
1526 144372 : st->hPFstat->on = 1;
1527 144372 : move16();
1528 144372 : Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k );
1529 144372 : set16_fx( st->hPFstat->mem_zero, 0, M );
1530 :
1531 144372 : formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 );
1532 : }
1533 18215 : ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) )
1534 : {
1535 8974 : IF( st->hPFstat->on )
1536 : {
1537 971 : Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M );
1538 971 : Copy( psyn_fx, temp_buf_fx + M, L_SUBFR );
1539 :
1540 971 : Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 );
1541 971 : E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M );
1542 971 : scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR );
1543 971 : Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) );
1544 971 : blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 );
1545 : }
1546 8974 : st->hPFstat->on = 0;
1547 8974 : move16();
1548 : }
1549 :
1550 : /*----------------------------------------------------------------*
1551 : * Comfort noise addition
1552 : *----------------------------------------------------------------*/
1553 :
1554 162587 : test();
1555 162587 : test();
1556 162587 : IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
1557 : {
1558 155333 : test();
1559 155333 : test();
1560 155333 : test();
1561 155333 : test();
1562 155333 : test();
1563 155333 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) )
1564 : {
1565 : /*VAD only for non inactive frame*/
1566 136885 : test();
1567 136885 : st->VAD = st->VAD && st->coder_type != INACTIVE;
1568 136885 : move16();
1569 136885 : test();
1570 136885 : test();
1571 136885 : test();
1572 136885 : test();
1573 136885 : test();
1574 136885 : IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) )
1575 : {
1576 : /*Noisy speech detector*/
1577 131647 : noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn );
1578 :
1579 131647 : st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ );
1580 131647 : move16();
1581 131647 : IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 )
1582 : {
1583 18672 : st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ );
1584 18672 : move16();
1585 : }
1586 131647 : move32();
1587 : }
1588 :
1589 136885 : if ( st->idchan == 0 )
1590 : {
1591 133134 : st->lp_noise = st->hFdCngDec->lp_noise;
1592 133134 : move32();
1593 : }
1594 :
1595 136885 : test();
1596 136885 : IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag )
1597 : {
1598 : /* Noise estimate */
1599 124231 : ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
1600 : }
1601 :
1602 136885 : IF( !st->cna_dirac_flag )
1603 : {
1604 134341 : test();
1605 134341 : test();
1606 134341 : test();
1607 134341 : test();
1608 134341 : test();
1609 134341 : test();
1610 134341 : test();
1611 134341 : test();
1612 134341 : test();
1613 : /* CNA: Generate additional comfort noise to mask potential coding artefacts */
1614 134341 : IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
1615 : {
1616 73394 : test();
1617 73394 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) )
1618 : {
1619 888 : IF( hStereoCng->flag_cna_fade )
1620 : {
1621 12 : generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
1622 12 : hStereoCng->flag_cna_fade = 0;
1623 12 : move16();
1624 : }
1625 : ELSE
1626 : {
1627 876 : test();
1628 876 : IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) )
1629 : {
1630 : /* Clear memory for secondary channel CNA */
1631 1 : set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) );
1632 : }
1633 :
1634 876 : generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out );
1635 : }
1636 : }
1637 72506 : ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
1638 : {
1639 36104 : IF( EQ_16( st->element_mode, EVS_MONO ) )
1640 : {
1641 754 : generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 );
1642 : }
1643 : ELSE
1644 : {
1645 35350 : IF( st->idchan == 0 )
1646 : {
1647 35239 : IF( NE_16( st->element_mode, last_element_mode ) )
1648 : {
1649 0 : set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen );
1650 : }
1651 :
1652 : Word32 psyn_32_fx[L_FRAME16k];
1653 35239 : Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6
1654 35239 : Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15
1655 :
1656 35239 : generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out );
1657 :
1658 35239 : Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn
1659 35239 : Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0
1660 : }
1661 : }
1662 : }
1663 : }
1664 60947 : ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) )
1665 : {
1666 1264 : test();
1667 1264 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) )
1668 : {
1669 0 : generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out );
1670 0 : hStereoCng->flag_cna_fade = 1;
1671 0 : move16();
1672 : }
1673 : ELSE
1674 : {
1675 163056 : FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ )
1676 : {
1677 161792 : psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) );
1678 161792 : move16();
1679 : }
1680 : }
1681 : }
1682 : ELSE
1683 : {
1684 59683 : IF( hStereoCng != NULL )
1685 : {
1686 7777 : hStereoCng->flag_cna_fade = 1;
1687 7777 : move16();
1688 7777 : hStereoCng->enableSecCNA = 0;
1689 7777 : move16();
1690 : }
1691 : }
1692 :
1693 134341 : IF( EQ_16( st->element_mode, IVAS_CPE_TD ) )
1694 : {
1695 7344 : test();
1696 7344 : test();
1697 7344 : test();
1698 : /*Noise estimate*/
1699 7344 : IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) )
1700 : {
1701 3593 : ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) );
1702 : }
1703 : }
1704 : }
1705 : }
1706 :
1707 155333 : IF( !st->cna_dirac_flag )
1708 : {
1709 150061 : test();
1710 150061 : test();
1711 150061 : test();
1712 150061 : test();
1713 150061 : test();
1714 150061 : test();
1715 150061 : test();
1716 150061 : IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) )
1717 : {
1718 99 : IF( EQ_16( st->element_mode, EVS_MONO ) )
1719 : {
1720 : // VE: TBV - is it correct in EVS? in FLP, it is:
1721 : // v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 );
1722 : // v_add( temp_buf, syn, syn, st->L_frame / 2 );
1723 0 : FOR( i = 0; i < st->L_frame / 2; i++ )
1724 : {
1725 0 : psyn_fx[i] = add( psyn_fx[i], shr_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->L_frame / 4], negate( st->Q_syn ) ) );
1726 0 : move16();
1727 : }
1728 : }
1729 : ELSE
1730 : {
1731 15939 : FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ )
1732 : {
1733 15840 : psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) );
1734 15840 : move16();
1735 : }
1736 : }
1737 : }
1738 :
1739 150061 : test();
1740 150061 : test();
1741 150061 : test();
1742 150061 : IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) )
1743 : {
1744 76667 : IF( st->idchan == 0 )
1745 : {
1746 73477 : set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen );
1747 : }
1748 76667 : IF( hStereoCng != NULL && ( st->idchan == 0 ) )
1749 : {
1750 5075 : set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen );
1751 : }
1752 : }
1753 : }
1754 : }
1755 :
1756 : /*----------------------------------------------------------------*
1757 : * Resample to the output sampling rate (8/16/32/48 kHz)
1758 : * Bass post-filter
1759 : *----------------------------------------------------------------*/
1760 :
1761 162587 : IF( EQ_16( st->element_mode, EVS_MONO ) )
1762 : {
1763 : CLDFB_SCALE_FACTOR scaleFactor;
1764 : Word32 workBuffer[128 * 3];
1765 :
1766 : /* check if the CLDFB works on the right sample rate */
1767 1423 : IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame )
1768 : {
1769 : /* resample to ACELP internal sampling rate */
1770 1 : Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) );
1771 1 : resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 );
1772 1 : resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 );
1773 :
1774 1 : IF( st->ini_frame > 0 )
1775 : {
1776 0 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
1777 0 : move16();
1778 : }
1779 : }
1780 :
1781 1423 : test();
1782 1423 : IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) )
1783 : {
1784 0 : IF( EQ_16( st->L_frame, L_FRAME ) )
1785 : {
1786 0 : retro_interp5_4_fx( st->hBPF->pst_old_syn_fx );
1787 : }
1788 0 : ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) )
1789 : {
1790 0 : retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx );
1791 : }
1792 : }
1793 :
1794 1423 : bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off,
1795 1423 : st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx );
1796 :
1797 : /* analysis of the synthesis at internal sampling rate */
1798 1423 : cldfbAnalysis_fx( st->cldfbAna, realBuffer_fx, imagBuffer_fx, &scaleFactor, psyn_fx, negate( st->Q_syn ), CLDFB_NO_COL_MAX, workBuffer );
1799 :
1800 1423 : scaleFactor.hb_scale = scaleFactor.lb_scale;
1801 1423 : move16();
1802 :
1803 : /* analysis and add the BPF error signal */
1804 1423 : i = 0;
1805 1423 : move16();
1806 1423 : if ( st->bpf_off == 0 )
1807 : {
1808 1394 : i = CLDFB_NO_COL_MAX;
1809 1394 : move16();
1810 : }
1811 :
1812 1423 : addBassPostFilter_fx( bpf_error_signal_16fx, realBuffer_fx, imagBuffer_fx, st->cldfbBPF, workBuffer, negate( st->Q_syn ),
1813 1423 : i, st->cldfbAna->no_col, st->cldfbAna->no_channels, &scaleFactor );
1814 :
1815 : /* set output mask for upsampling */
1816 1423 : IF( EQ_16( st->bwidth, NB ) )
1817 : {
1818 : /* set NB mask for upsampling */
1819 0 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 );
1820 0 : move16();
1821 : }
1822 1423 : ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) )
1823 : {
1824 : /* in case of BW switching, re-init to default */
1825 18 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
1826 18 : move16();
1827 : }
1828 :
1829 : /*WB/SWB-FD_CNG*/
1830 1423 : scaleFactor.hb_scale = scaleFactor.lb_scale;
1831 1423 : move16();
1832 :
1833 1423 : test();
1834 1423 : test();
1835 1423 : test();
1836 1423 : IF( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) )
1837 : {
1838 0 : generate_comfort_noise_dec_hf_fx( realBuffer_fx, imagBuffer_fx, &scaleFactor.hb_scale, st );
1839 :
1840 0 : st->cldfbSyn->bandsToZero = 0;
1841 0 : move16();
1842 0 : IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) )
1843 : {
1844 0 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand );
1845 0 : move16();
1846 : }
1847 0 : st->cldfbSyn->lsb = st->cldfbAna->no_channels;
1848 0 : move16();
1849 : }
1850 :
1851 : /* synthesis of the combined signal */
1852 1423 : st->Q_syn2 = st->Q_syn;
1853 1423 : move16();
1854 1423 : cldfbSynthesis_fx( st->cldfbSyn, realBuffer_fx, imagBuffer_fx, &scaleFactor, synth_fx16, negate( st->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer );
1855 :
1856 : /* Bring CLDFB output to Q0 */
1857 1423 : Scale_sig( synth_fx16, output_frame, negate( st->Q_syn2 ) );
1858 1423 : st->Q_syn2 = 0;
1859 1423 : move16();
1860 :
1861 : /* save synthesis - needed in case of core switching */
1862 1423 : Copy( synth_fx16, st->previoussynth_fx, output_frame );
1863 : }
1864 : ELSE
1865 : {
1866 : /* check if the CLDFB works on the right sample rate */
1867 161164 : IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) )
1868 : {
1869 3084 : resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
1870 3084 : resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) );
1871 :
1872 3084 : IF( st->ini_frame > 0 )
1873 : {
1874 1901 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
1875 1901 : move16();
1876 : }
1877 : }
1878 :
1879 : /* analyze pitch coherence for bass post-filter */
1880 : Word32 pitch_buf_fx_q20[12];
1881 161164 : Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4)
1882 161164 : Word16 lim = shr( st->L_frame, 6 );
1883 886383 : FOR( Word16 lp = 0; lp < lim; lp++ )
1884 : {
1885 725219 : pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 );
1886 725219 : move32();
1887 : }
1888 161164 : bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 );
1889 161164 : Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx
1890 :
1891 161164 : test();
1892 161164 : IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) )
1893 : {
1894 153910 : test();
1895 153910 : IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) )
1896 : {
1897 1608 : IF( EQ_16( st->L_frame, L_FRAME ) )
1898 : {
1899 1086 : retro_interp5_4_fx( st->hBPF->pst_old_syn_fx );
1900 : }
1901 522 : ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) )
1902 : {
1903 522 : retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx );
1904 : }
1905 : }
1906 :
1907 153910 : bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off,
1908 153910 : st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx );
1909 : }
1910 :
1911 : Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx;
1912 161164 : set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR );
1913 161164 : syn_32_fx = syn_tmp_32_fx + L_SUBFR;
1914 161164 : test();
1915 161164 : IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft )
1916 137467 : {
1917 : /* analysis of the synthesis at internal sampling rate */
1918 : Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
1919 : Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
1920 : Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX];
1921 2336939 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
1922 : {
1923 2199472 : pRealSave_fx[i] = realBufferSave_fx[i];
1924 2199472 : pImagSave_fx[i] = imagBufferSave_fx[i];
1925 : }
1926 137467 : IF( st->p_bpf_noise_buf_32 )
1927 : {
1928 125804 : Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1
1929 125804 : Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame );
1930 125804 : Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11
1931 : }
1932 :
1933 39539707 : FOR( i = 0; i < st->L_frame; i++ )
1934 : {
1935 39402240 : syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12
1936 39402240 : move32();
1937 : }
1938 :
1939 137467 : Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
1940 137467 : Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12
1941 137467 : st->cldfbAna->Q_cldfb_state = Q12;
1942 137467 : move16();
1943 :
1944 137467 : cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna );
1945 :
1946 137467 : Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11
1947 137467 : st->cldfbAna->Q_cldfb_state = Q11;
1948 137467 : move16();
1949 : /* analysis and add the BPF error signal */
1950 : Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
1951 : Word16 q_bpf_error_signal;
1952 137467 : Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels );
1953 :
1954 137467 : q_bpf_error_signal = Q6;
1955 137467 : move16();
1956 137467 : Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6
1957 2336939 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
1958 : {
1959 2199472 : Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
1960 2199472 : Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
1961 : }
1962 137467 : Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6)
1963 137467 : st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal;
1964 137467 : move16();
1965 137467 : tmp = -1;
1966 137467 : move16();
1967 137467 : if ( st->bpf_off )
1968 : {
1969 25756 : tmp = 0;
1970 25756 : move16();
1971 : }
1972 :
1973 137467 : addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF );
1974 :
1975 137467 : Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10
1976 137467 : st->cldfbBPF->Q_cldfb_state = Q10;
1977 137467 : move16();
1978 : /* set output mask for upsampling */
1979 137467 : IF( EQ_16( st->bwidth, NB ) )
1980 : {
1981 : /* set NB mask for upsampling */
1982 0 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 );
1983 0 : move16();
1984 : }
1985 137467 : ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) )
1986 : {
1987 : /* in case of BW switching, re-init to default */
1988 14964 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels );
1989 14964 : move16();
1990 : }
1991 137467 : test();
1992 137467 : IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
1993 : {
1994 127373 : test();
1995 127373 : test();
1996 127373 : test();
1997 : /*WB/SWB-FD_CNG*/
1998 127373 : IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) )
1999 : {
2000 15059 : Word16 tmpBufferScale = 0;
2001 15059 : move16();
2002 15059 : generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag );
2003 :
2004 256003 : FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ )
2005 : {
2006 240944 : Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0
2007 240944 : Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0
2008 : }
2009 :
2010 15059 : IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) )
2011 : {
2012 11403 : st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand );
2013 11403 : move16();
2014 : }
2015 : ELSE
2016 : {
2017 3656 : st->cldfbSyn->bandsToZero = 0;
2018 3656 : move16();
2019 : }
2020 : }
2021 : }
2022 :
2023 137467 : IF( save_hb_synth_fx16 != NULL )
2024 : {
2025 : /* save and then zero-out lowband */
2026 91 : max_real = 0;
2027 91 : max_imag = 0;
2028 91 : move32();
2029 91 : move32();
2030 1547 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2031 : {
2032 88816 : FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
2033 : {
2034 87360 : max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
2035 87360 : max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
2036 : }
2037 : }
2038 91 : max_val = L_max( max_real, max_imag );
2039 91 : Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
2040 1547 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2041 : {
2042 1456 : scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2043 1456 : scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2044 : }
2045 : #ifndef OPT_AVOID_STATE_BUF_RESCALE
2046 : #ifdef OPT_STEREO_32KBPS_V1
2047 : scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
2048 : #else /* OPT_STEREO_32KBPS_V1 */
2049 : scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1)
2050 : #endif /* OPT_STEREO_32KBPS_V1 */
2051 : st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 );
2052 : move16();
2053 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2054 :
2055 5551 : FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
2056 : {
2057 92820 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2058 : {
2059 87360 : realBufferSave_fx[i][j] = realBuffer_fx[i][j];
2060 87360 : imagBufferSave_fx[i][j] = imagBuffer_fx[i][j];
2061 87360 : move32();
2062 87360 : move32();
2063 87360 : IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) )
2064 : {
2065 29120 : realBuffer_fx[i][j] = 0;
2066 29120 : imagBuffer_fx[i][j] = 0;
2067 29120 : move32();
2068 29120 : move32();
2069 : }
2070 : }
2071 : }
2072 :
2073 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
2074 91 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB );
2075 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
2076 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, 0, st->cldfbSynHB );
2077 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2078 :
2079 : #ifndef OPT_AVOID_STATE_BUF_RESCALE
2080 : Scale_sig32( save_hb_synth_fx, L_FRAME48k, negate( ( sub( Q_real, 1 ) ) ) ); // Q0
2081 : Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10
2082 : st->cldfbSynHB->Q_cldfb_state = Q10;
2083 : move16();
2084 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2085 : /* restore lowband */
2086 5551 : FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
2087 : {
2088 92820 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2089 : {
2090 87360 : realBuffer_fx[i][j] = realBufferSave_fx[i][j];
2091 87360 : imagBuffer_fx[i][j] = imagBufferSave_fx[i][j];
2092 87360 : move32();
2093 87360 : move32();
2094 : }
2095 : }
2096 : #ifndef OPT_AVOID_STATE_BUF_RESCALE
2097 : Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1
2098 : st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 );
2099 : move16();
2100 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2101 :
2102 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
2103 91 : cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSyn );
2104 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
2105 : cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, 0, st->cldfbSyn );
2106 : Scale_sig32( synth_fx, L_FRAME48k, negate( sub( Q_real, 1 ) ) ); // Q0
2107 : Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10
2108 : st->cldfbSynHB->Q_cldfb_state = Q10;
2109 : move16();
2110 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2111 : }
2112 : ELSE
2113 : {
2114 : /* synthesis of the combined signal */
2115 137376 : max_real = 0;
2116 137376 : max_imag = 0;
2117 137376 : move32();
2118 137376 : move32();
2119 2335392 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2120 : {
2121 134078976 : FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
2122 : {
2123 131880960 : max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
2124 131880960 : max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
2125 : }
2126 : }
2127 137376 : max_val = L_max( max_real, max_imag );
2128 137376 : Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
2129 2335392 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2130 : {
2131 2198016 : scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2132 2198016 : scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2133 : }
2134 : #ifdef OPT_STEREO_32KBPS_V1
2135 137376 : scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
2136 : #else /* OPT_STEREO_32KBPS_V1 */
2137 : scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
2138 : #endif /* OPT_STEREO_32KBPS_V1 */
2139 137376 : st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 );
2140 137376 : move16();
2141 :
2142 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
2143 137376 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, 0, st->cldfbSyn );
2144 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
2145 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, st->cldfbSyn );
2146 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2147 137376 : scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0
2148 137376 : scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10
2149 137376 : st->cldfbSyn->Q_cldfb_state = Q10;
2150 137376 : move16();
2151 : }
2152 :
2153 : /* save synthesis - needed in case of core switching */
2154 137467 : Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0
2155 : }
2156 : ELSE
2157 : {
2158 23697 : Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */
2159 :
2160 : /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */
2161 7035473 : FOR( i = 0; i < st->L_frame; i++ )
2162 : {
2163 7011776 : syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) );
2164 7011776 : move32();
2165 : }
2166 :
2167 23697 : Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels );
2168 23697 : Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12
2169 23697 : st->cldfbAna->Q_cldfb_state = Q12;
2170 23697 : move16();
2171 :
2172 23697 : cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna );
2173 :
2174 23697 : Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11
2175 23697 : st->cldfbAna->Q_cldfb_state = Q11;
2176 23697 : move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */
2177 : Word32 tmp_bpf_error_signal_fx[L_FRAME16k];
2178 : Word16 q_bpf_error_signal;
2179 : Word16 cldfb_state_offset;
2180 23697 : cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels );
2181 :
2182 : // Get Q-factor
2183 23697 : q_bpf_error_signal = Q6;
2184 23697 : move16();
2185 23697 : Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6
2186 402849 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2187 : {
2188 379152 : Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
2189 379152 : Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0
2190 : }
2191 23697 : Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6)
2192 23697 : st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal;
2193 23697 : move16();
2194 23697 : tmp = 0;
2195 23697 : move16();
2196 23697 : if ( !st->bpf_off )
2197 : {
2198 22559 : tmp = nSamples;
2199 22559 : move16();
2200 : }
2201 :
2202 23697 : addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF );
2203 :
2204 23697 : Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10
2205 23697 : st->cldfbBPF->Q_cldfb_state = Q10;
2206 23697 : move16();
2207 : /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */
2208 23697 : max_real = 0;
2209 23697 : max_imag = 0;
2210 23697 : move32();
2211 23697 : move32();
2212 402849 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2213 : {
2214 23128272 : FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
2215 : {
2216 22749120 : max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) );
2217 22749120 : max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) );
2218 : }
2219 : }
2220 23697 : max_val = L_max( max_real, max_imag );
2221 23697 : Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */;
2222 402849 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
2223 : {
2224 379152 : scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2225 379152 : scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real
2226 : }
2227 : #ifndef OPT_AVOID_STATE_BUF_RESCALE
2228 : #ifdef OPT_STEREO_32KBPS_V1
2229 : scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1)
2230 : #else /* OPT_STEREO_32KBPS_V1 */
2231 : scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1)
2232 : #endif /* OPT_STEREO_32KBPS_V1 */
2233 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2234 :
2235 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
2236 23697 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), sub( Q10, sub( Q_real, 1 ) ), -10, st->cldfbSyn );
2237 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
2238 : cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), 0, st->cldfbSyn );
2239 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2240 :
2241 : #ifndef OPT_AVOID_STATE_BUF_RESCALE
2242 : Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0
2243 : Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10
2244 : st->cldfbSyn->Q_cldfb_state = Q10;
2245 : move16();
2246 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2247 23697 : IF( st->p_bpf_noise_buf_32 )
2248 : {
2249 23071 : Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1
2250 23071 : Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame );
2251 :
2252 23071 : Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11
2253 : }
2254 :
2255 23697 : set32_fx( synth_fx, 0, output_frame );
2256 : }
2257 :
2258 : /* Copy output signal */
2259 161164 : Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0
2260 161164 : IF( st->element_mode > EVS_MONO )
2261 : {
2262 161164 : Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/
2263 : }
2264 :
2265 161164 : st->Q_syn2 = 0;
2266 161164 : move16();
2267 : }
2268 :
2269 : /*-----------------------------------------------------------------*
2270 : * Bandwidth extension 6kHz-7kHz
2271 : *-----------------------------------------------------------------*/
2272 :
2273 162587 : IF( st->hBWE_zero != NULL )
2274 : {
2275 155333 : test();
2276 155333 : test();
2277 155333 : test();
2278 155333 : test();
2279 155333 : test();
2280 155333 : test();
2281 155333 : test();
2282 155333 : IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) &&
2283 : ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) )
2284 : {
2285 14951 : IF( EQ_16( st->element_mode, EVS_MONO ) )
2286 : {
2287 0 : hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 );
2288 : }
2289 : ELSE
2290 : {
2291 14951 : Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0
2292 14951 : hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 );
2293 14951 : Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 );
2294 : }
2295 : }
2296 : ELSE
2297 : {
2298 140382 : hf_synth_reset_fx( st->hBWE_zero );
2299 140382 : IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment
2300 : {
2301 138959 : set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 );
2302 : }
2303 : }
2304 : }
2305 :
2306 : /*-----------------------------------------------------------------*
2307 : * Populate parameters for SWB TBE
2308 : *-----------------------------------------------------------------*/
2309 :
2310 162587 : IF( st->hBWE_TD != NULL )
2311 : {
2312 155238 : test();
2313 155238 : test();
2314 155238 : test();
2315 155238 : test();
2316 155238 : test();
2317 155238 : test();
2318 155238 : test();
2319 155238 : test();
2320 155238 : test();
2321 155238 : test();
2322 155238 : test();
2323 155238 : test();
2324 155238 : IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) )
2325 : {
2326 8141 : st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
2327 8141 : move32();
2328 8141 : set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
2329 : }
2330 :
2331 155238 : test();
2332 155238 : test();
2333 155238 : test();
2334 155238 : test();
2335 155238 : test();
2336 155238 : IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) )
2337 : {
2338 155238 : IF( EQ_16( st->element_mode, EVS_MONO ) )
2339 : {
2340 1423 : non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame );
2341 : }
2342 : ELSE
2343 : {
2344 153815 : Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
2345 153815 : non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame );
2346 153815 : Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc
2347 : }
2348 : }
2349 :
2350 155238 : test();
2351 155238 : if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) )
2352 : {
2353 12299 : st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
2354 12299 : move32();
2355 : }
2356 : }
2357 :
2358 : /*----------------------------------------------------------------------*
2359 : * Updates
2360 : *----------------------------------------------------------------------*/
2361 :
2362 162587 : updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx );
2363 :
2364 162587 : test();
2365 162587 : test();
2366 162587 : IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL )
2367 : {
2368 : /* update CNG parameters in active frames */
2369 98889 : IF( EQ_16( st->element_mode, EVS_MONO ) )
2370 : {
2371 1423 : cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx,
2372 1423 : st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate );
2373 : }
2374 : ELSE
2375 : {
2376 97466 : cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size,
2377 97466 : st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode,
2378 97466 : st->hFdCngDec->hFdCngCom->CngBandwidth );
2379 : }
2380 :
2381 : /* Set 16k LSP flag for CNG buffer */
2382 98889 : st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0;
2383 98889 : move16();
2384 98889 : if ( NE_16( st->L_frame, L_FRAME ) )
2385 : {
2386 52056 : st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1;
2387 52056 : move16();
2388 : }
2389 : }
2390 :
2391 162587 : IF( NE_16( st->element_mode, EVS_MONO ) )
2392 : {
2393 161164 : IF( save_hb_synth_fx16 )
2394 : {
2395 91 : Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0
2396 : }
2397 161164 : Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2
2398 : }
2399 :
2400 162587 : pop_wmops();
2401 162587 : return error;
2402 : }
|