Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <assert.h>
6 : #include <stdint.h>
7 : #include "options.h"
8 : #include "cnst.h" /* Common constants */
9 : #include "rom_com.h" /* Static table prototypes */
10 : #include "prot_fx.h" /* Function prototypes */
11 :
12 : /*-------------------------------------------------------------------*
13 : * updt_dec()
14 : *
15 : * Common updates (all frame types)
16 : *-------------------------------------------------------------------*/
17 162587 : void updt_dec_fx(
18 : Decoder_State *st_fx, /* i/o: state structure */
19 : const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */
20 : const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/
21 : const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/
22 : const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */
23 : const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/
24 : const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/
25 : const Word16 voice_factors[], /* i : voicing factors Q15*/
26 : const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/
27 : const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/
28 : )
29 : {
30 : Word16 i, len;
31 : HQ_DEC_HANDLE hHQ_core;
32 : TD_BWE_DEC_HANDLE hBWE_TD;
33 162587 : hBWE_TD = st_fx->hBWE_TD;
34 162587 : hHQ_core = st_fx->hHQ_core;
35 :
36 : /* update old excitation buffer */
37 162587 : Copy( &old_exc_fx[st_fx->L_frame], st_fx->old_exc_fx, L_EXC_MEM_DEC );
38 162587 : test();
39 162587 : IF( !st_fx->Opt_AMR_WB && hBWE_TD != NULL )
40 : {
41 155238 : Copy( &old_bwe_exc_fx[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 );
42 : }
43 :
44 : /* update old LSP and LSF vector */
45 162587 : Copy( lsf_new_fx, st_fx->lsf_old_fx, M );
46 162587 : Copy( lsp_new_fx, st_fx->lsp_old_fx, M );
47 :
48 : /* update last coding type */
49 162587 : st_fx->last_coder_type = st_fx->coder_type;
50 162587 : move16();
51 162587 : test();
52 162587 : test();
53 162587 : test();
54 162587 : if ( EQ_16( st_fx->coder_type, INACTIVE ) || ( EQ_16( st_fx->bpf_off, 1 ) && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, TRANSITION ) ) )
55 : {
56 34892 : st_fx->last_coder_type = UNVOICED;
57 34892 : move16();
58 : }
59 162587 : IF( st_fx->hGSCDec != NULL )
60 : {
61 155333 : test();
62 155333 : test();
63 155333 : if ( ( NE_16( st_fx->coder_type, AUDIO ) || st_fx->Last_GSC_noisy_speech_flag != 0 ) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0 )
64 : {
65 10104 : st_fx->hGSCDec->Last_GSC_pit_band_idx = 0;
66 10104 : move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */
67 : }
68 : }
69 :
70 : /* this ensures that st_fx->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */
71 :
72 162587 : test();
73 162587 : if ( GT_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->coder_type, INACTIVE ) )
74 : {
75 2496 : st_fx->last_coder_type = GENERIC;
76 2496 : move16();
77 : }
78 162587 : test();
79 162587 : test();
80 162587 : test();
81 162587 : IF( EQ_16( st_fx->Opt_AMR_WB, 1 ) && EQ_16( st_fx->coder_type, INACTIVE ) &&
82 : NE_32( st_fx->core_brate, SID_1k75 ) && NE_32( st_fx->core_brate, FRAME_NO_DATA ) )
83 : {
84 : /* overwrite previous coding type to help FEC */
85 0 : st_fx->last_coder_type = UNVOICED;
86 0 : move16();
87 0 : st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1]; // Q15
88 0 : move16();
89 : }
90 :
91 162587 : IF( !st_fx->Opt_AMR_WB )
92 : {
93 : /* update voicing factor of TBE to help FEC */
94 :
95 162587 : st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k - 1];
96 162587 : move16();
97 162587 : if ( EQ_16( st_fx->L_frame, L_FRAME ) )
98 : {
99 81355 : st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR - 1];
100 81355 : move16();
101 : }
102 : }
103 162587 : test();
104 162587 : test();
105 162587 : IF( st_fx->hGSCDec != NULL && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) )
106 : {
107 120669 : st_fx->hGSCDec->noise_lev = NOISE_LEVEL_SP3;
108 120669 : move16();
109 120669 : set16_fx( st_fx->hGSCDec->old_y_gain_fx, 0, MBANDS_GN );
110 :
111 31011933 : FOR( i = 0; i < L_FRAME; i++ )
112 : {
113 30891264 : Word16 tmp_seed = st_fx->hGSCDec->seed_tcx;
114 30891264 : move16();
115 30891264 : st_fx->hGSCDec->Last_GSC_spectrum_fx[i] = shr_r( Random( &tmp_seed ), 5 );
116 30891264 : move16(); /*Q10*/
117 : }
118 : }
119 :
120 : /* update last GSC SWB speech flag for FEC */
121 162587 : st_fx->Last_GSC_noisy_speech_flag = st_fx->GSC_noisy_speech;
122 162587 : move16();
123 :
124 : /* update counter for FEC pitch estimate */
125 162587 : st_fx->upd_cnt = add( st_fx->upd_cnt, 1 );
126 :
127 162587 : st_fx->upd_cnt = s_min( st_fx->upd_cnt, MAX_UPD_CNT );
128 :
129 162587 : len = shr( st_fx->L_frame, 6 );
130 162587 : Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len );
131 894167 : FOR( i = 0; i < len; i++ )
132 : {
133 731580 : st_fx->old_pitch_buf_fx[len + i] = L_mult0( pitch_buf_fx[i], 1 << 10 ); /* 15Q16 */
134 731580 : move32();
135 : }
136 162587 : Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[add( st_fx->L_frame / L_SUBFR, 2 )], st_fx->L_frame / L_SUBFR );
137 162587 : IF( EQ_16( st_fx->L_frame, L_FRAME ) )
138 : {
139 81355 : st_fx->mem_pitch_gain[2] = gain_buf[3]; // Q14
140 81355 : move16();
141 81355 : st_fx->mem_pitch_gain[3] = gain_buf[2]; // Q14
142 81355 : move16();
143 81355 : st_fx->mem_pitch_gain[4] = gain_buf[1]; // Q14
144 81355 : move16();
145 81355 : st_fx->mem_pitch_gain[5] = gain_buf[0]; // Q14
146 81355 : move16();
147 : }
148 : ELSE
149 : {
150 81232 : st_fx->mem_pitch_gain[2] = gain_buf[4]; // Q14
151 81232 : move16();
152 81232 : st_fx->mem_pitch_gain[3] = gain_buf[3]; // Q14
153 81232 : move16();
154 81232 : st_fx->mem_pitch_gain[4] = gain_buf[2]; // Q14
155 81232 : move16();
156 81232 : st_fx->mem_pitch_gain[5] = gain_buf[1]; // Q14
157 81232 : move16();
158 81232 : st_fx->mem_pitch_gain[6] = gain_buf[0]; // Q14
159 81232 : move16();
160 : }
161 :
162 :
163 : /* FEC - update adaptive LSF mean vector */
164 162587 : Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M );
165 162587 : Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M );
166 :
167 : /* update of pitch and voicing information for HQ FEC */
168 162587 : IF( hHQ_core != NULL )
169 : {
170 158836 : IF( NE_16( st_fx->last_core, HQ_CORE ) )
171 : {
172 158591 : hHQ_core->HqVoicing = 1;
173 158591 : move16();
174 158591 : test();
175 158591 : if ( !st_fx->Opt_AMR_WB && EQ_16( st_fx->coder_type, UNVOICED ) )
176 : {
177 1449 : hHQ_core->HqVoicing = 0;
178 1449 : move16();
179 : }
180 : }
181 : }
182 :
183 : /* SC-VBR */
184 162587 : st_fx->old_ppp_mode = st_fx->last_ppp_mode_dec;
185 162587 : move16();
186 162587 : st_fx->last_ppp_mode_dec = st_fx->ppp_mode_dec;
187 162587 : move16();
188 162587 : st_fx->last_nelp_mode_dec = st_fx->nelp_mode_dec;
189 162587 : move16();
190 162587 : st_fx->last_vbr_hw_BWE_disable_dec = st_fx->vbr_hw_BWE_disable_dec;
191 162587 : move16();
192 :
193 : /*core switching updates*/
194 162587 : Copy( &Aq[imult1616( sub( st_fx->L_frame / L_SUBFR, 1 ), ( M + 1 ) )], st_fx->old_Aq_12_8_fx, M + 1 );
195 162587 : st_fx->old_Es_pred_fx = Es_pred;
196 162587 : move16();
197 :
198 162587 : return;
199 : }
200 :
201 : /*-------------------------------------------------------------------*
202 : * updt_IO_switch()
203 : *
204 : * Common updates for AMR-WB IO mode and EVS primary switching
205 : *-------------------------------------------------------------------*/
206 0 : void updt_IO_switch_dec_fx(
207 : const Word16 output_frame, /* i : output frame length */
208 : Decoder_State *st_fx /* o : Decoder static variables structure */
209 : )
210 : {
211 : Word16 xsp_tmp[M];
212 : Word16 tmp_buf[MAX_LT];
213 : FD_BWE_DEC_HANDLE hBWE_FD;
214 : TD_BWE_DEC_HANDLE hBWE_TD;
215 :
216 0 : hBWE_TD = st_fx->hBWE_TD;
217 0 : hBWE_FD = st_fx->hBWE_FD;
218 :
219 0 : IF( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) /* switching to EVS primary mode */
220 : {
221 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode mode LSF(LSP) */
222 0 : Copy( stable_LSP_fx, xsp_tmp, M );
223 0 : isf2lsf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp );
224 0 : Copy( stable_LSP_fx, xsp_tmp, M );
225 : /*isp2lsp( st->lsp_old, st->lsp_old, xsp_tmp, M, grid100 );*/
226 0 : isp2lsp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M );
227 :
228 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode uses LSF(LSP) */
229 0 : Copy( stable_LSP_fx, xsp_tmp, M );
230 : /*isp2lsp( st->lspCNG, st->lspCNG, xsp_tmp, M, grid100 );*/
231 0 : isp2lsp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M );
232 0 : IF( st_fx->hTdCngDec != NULL )
233 : {
234 0 : st_fx->hTdCngDec->old_enr_index = s_min( shl( st_fx->hTdCngDec->old_enr_index, 1 ), 127 );
235 : }
236 : /* reset TD BWE buffers */
237 0 : st_fx->last_voice_factor_fx = 0;
238 0 : move16();
239 0 : IF( hBWE_TD != NULL )
240 : {
241 0 : set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
242 0 : set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
243 0 : hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
244 0 : move16();
245 :
246 0 : wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx );
247 0 : wb_tbe_extras_reset_synth_fx( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_32and48k_WB_upsample_fx, hBWE_TD->mem_resamp_HB_fx );
248 0 : IF( GE_16( output_frame, L_FRAME32k ) )
249 : {
250 0 : swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
251 0 : hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx, hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
252 0 : set16_fx( hBWE_TD->GainShape_Delay_fx, 0, NUM_SHB_SUBFR / 2 );
253 0 : hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*Q0 1.f*/
254 0 : move32();
255 0 : hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/
256 0 : move16();
257 0 : swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32 );
258 : }
259 :
260 0 : IF( EQ_16( output_frame, L_FRAME48k ) )
261 : {
262 0 : hBWE_FD->prev_fb_ener_adjust_fx = 0;
263 0 : move16();
264 0 : set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
265 0 : hBWE_TD->fb_tbe_demph_fx = 0;
266 0 : move16();
267 0 : fb_tbe_reset_synth_fx( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx );
268 : }
269 0 : hBWE_FD->prev_Energy_wb_fx = L_deposit_l( 0 );
270 0 : hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/
271 0 : move16();
272 : }
273 :
274 0 : IF( hBWE_FD != NULL )
275 : {
276 : /* reset FD BWE buffers */
277 0 : hBWE_FD->prev_mode = NORMAL;
278 0 : move16();
279 0 : hBWE_FD->prev_Energy_fx = 0;
280 0 : move16();
281 0 : hBWE_FD->prev_L_swb_norm = 8;
282 0 : move16();
283 0 : hBWE_FD->prev_frica_flag = 0;
284 0 : move16();
285 0 : set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k );
286 0 : hBWE_FD->prev_td_energy_fx = 0;
287 0 : move16();
288 0 : set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k );
289 : }
290 : /* HQ core buffers */
291 0 : set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
292 :
293 : /* reset the unvoiced/audio signal improvement memories */
294 0 : if ( st_fx->hGSCDec != NULL )
295 : {
296 0 : st_fx->hGSCDec->seed_tcx = 15687; // Q0
297 0 : move16();
298 : }
299 0 : st_fx->hAmrwb_IO->UV_cnt_fx = 30;
300 0 : st_fx->hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 );
301 :
302 0 : move16();
303 0 : move16();
304 :
305 0 : st_fx->use_acelp_preq = 0;
306 0 : move16();
307 0 : move16();
308 0 : move16();
309 0 : move16();
310 0 : move16();
311 0 : move16();
312 0 : move16();
313 0 : if ( EQ_16( st_fx->last_flag_filter_NB, 1 ) )
314 : {
315 0 : st_fx->cldfbSyn->bandsToZero = 0;
316 : }
317 0 : st_fx->last_active_bandsToZero_bwdec = 0;
318 0 : st_fx->perc_bwddec = 0;
319 0 : st_fx->last_flag_filter_NB = 0;
320 0 : st_fx->active_frame_cnt_bwddec = 0;
321 0 : set16_fx( st_fx->flag_buffer, 0, 20 );
322 : }
323 : ELSE /* switching to AMR-WB IO mode */
324 : {
325 : /* ISF Q memories */
326 0 : set16_fx( st_fx->mem_MA_fx, 0, M );
327 :
328 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
329 0 : Copy( stable_ISP_fx, xsp_tmp, M );
330 0 : lsf2isf_fx( st_fx->lsf_old_fx, st_fx->lsf_old_fx, xsp_tmp, M );
331 0 : Copy( stable_ISP_fx, xsp_tmp, M );
332 0 : lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M );
333 :
334 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
335 0 : Copy( stable_ISP_fx, xsp_tmp, M );
336 0 : lsp2isp_fx( st_fx->lspCNG_fx, st_fx->lspCNG_fx, xsp_tmp, M );
337 :
338 0 : IF( st_fx->hTdCngDec != NULL )
339 : {
340 0 : st_fx->hTdCngDec->old_enr_index = s_max( s_min( shr( st_fx->hTdCngDec->old_enr_index, 1 ), 63 ), 0 );
341 : }
342 :
343 : /* HF synthesis memories */
344 0 : st_fx->Ng_ener_ST_fx = -51 * 256; /*Q8*/
345 0 : move16();
346 :
347 : /* reset the unvoiced/audio signal improvement memories */
348 0 : if ( st_fx->hGSCDec != NULL )
349 : {
350 0 : st_fx->hGSCDec->seed_tcx = 15687;
351 0 : move16();
352 : }
353 :
354 0 : Copy( st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT );
355 0 : amr_wb_dec_init_fx( st_fx->hAmrwb_IO );
356 0 : Copy( tmp_buf, st_fx->hAmrwb_IO->lt_diff_etot_fx, MAX_LT );
357 0 : hf_synth_amr_wb_reset_fx( st_fx->hBWE_zero, st_fx->hAmrwb_IO );
358 :
359 0 : st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) );
360 :
361 : /* reset VBR signalling */
362 0 : st_fx->last_ppp_mode_dec = 0;
363 0 : move16();
364 0 : st_fx->last_nelp_mode_dec = 0;
365 0 : move16();
366 0 : st_fx->ppp_mode_dec = 0;
367 0 : move16();
368 0 : st_fx->nelp_mode_dec = 0;
369 0 : move16();
370 : }
371 :
372 : /* CNG - reset */
373 0 : IF( st_fx->hTdCngDec != NULL )
374 : {
375 0 : st_fx->hTdCngDec->ho_hist_size = 0;
376 : }
377 0 : move16();
378 :
379 : /* LSF Q memories */
380 0 : Copy( UVWB_Ave_fx, st_fx->mem_AR_fx, M );
381 :
382 : /* FEC - update adaptive LSF mean vector */
383 0 : Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M );
384 0 : Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M );
385 0 : Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M );
386 :
387 0 : return;
388 : }
389 :
390 : /*-------------------------------------------------------------------*
391 : * updt_bw_switching()
392 : *
393 : * Updates for BW switching
394 : *-------------------------------------------------------------------*/
395 :
396 1852 : void updt_bw_switching_fx(
397 : Decoder_State *st_fx, /* i/o: decoder state structure */
398 : const Word16 *synth, /* i : fixed point synthesis signal Qpost */
399 : const Word16 Qpost )
400 : {
401 1852 : test();
402 1852 : IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) )
403 : {
404 786 : st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11
405 : }
406 :
407 1852 : st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q
408 1852 : move32();
409 1852 : st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q
410 1852 : move32();
411 1852 : st_fx->last_bwidth = st_fx->bwidth;
412 1852 : move32();
413 :
414 1852 : IF( EQ_16( st_fx->core, ACELP_CORE ) )
415 : {
416 1423 : st_fx->last_inner_frame = L_FRAME32k;
417 1423 : move16();
418 1423 : test();
419 1423 : if ( EQ_16( st_fx->bwidth, WB ) && st_fx->bws_cnt == 0 )
420 : {
421 0 : st_fx->last_inner_frame = L_FRAME16k;
422 0 : move16();
423 : }
424 : }
425 : ELSE
426 : {
427 429 : test();
428 429 : test();
429 429 : test();
430 429 : IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && LE_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && st_fx->bws_cnt > 0 && LT_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) )
431 : {
432 429 : st_fx->last_inner_frame = inner_frame_tbl[st_fx->bwidth];
433 429 : move16();
434 : }
435 : }
436 1852 : st_fx->prev_bws_cnt = st_fx->bws_cnt;
437 1852 : move16();
438 1852 : return;
439 : }
440 :
441 : /*-------------------------------------------------------------------*
442 : * updt_dec_common()
443 : *
444 : * Common updates for MODE1 and MODE2
445 : *-------------------------------------------------------------------*/
446 :
447 3100 : void updt_dec_common_fx(
448 : Decoder_State *st_fx, /* i/o: decoder state structure */
449 : Word16 hq_core_type_fx, /* i : HQ core type */
450 : const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */
451 : const Word16 *synth, /* i : decoded synthesis Qpostd */
452 : const Word16 Qpostd /* i : Synthesis Q value */
453 :
454 : )
455 : {
456 : Word16 i;
457 : Word32 L_tmp;
458 :
459 : TCX_DEC_HANDLE hTcxDec;
460 3100 : hTcxDec = st_fx->hTcxDec;
461 :
462 3100 : st_fx->last_codec_mode = st_fx->codec_mode;
463 3100 : move16();
464 3100 : st_fx->last_extl = st_fx->extl;
465 3100 : move16();
466 3100 : st_fx->last_L_frame = st_fx->L_frame;
467 3100 : move16();
468 :
469 3100 : st_fx->prev_old_bfi = st_fx->prev_bfi;
470 3100 : move16();
471 3100 : st_fx->prev_bfi = st_fx->bfi;
472 3100 : move16();
473 3100 : if ( NE_16( st_fx->core, AMR_WB_CORE ) )
474 : {
475 3100 : st_fx->old_bfi_cnt = st_fx->nbLostCmpt;
476 3100 : move16();
477 : }
478 3100 : move16();
479 3100 : st_fx->last_con_tcx = st_fx->con_tcx;
480 3100 : move16();
481 3100 : st_fx->con_tcx = 0;
482 :
483 3100 : move16();
484 3100 : if ( st_fx->hHQ_nbfec != NULL )
485 : {
486 3100 : st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core;
487 : }
488 3100 : if ( st_fx->hTcxDec != NULL )
489 : {
490 3100 : hTcxDec->tcxConceal_recalc_exc = 0;
491 3100 : move16();
492 : }
493 3100 : test();
494 3100 : test();
495 3100 : IF( ( GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) && st_fx->use_partial_copy && st_fx->bfi ) || !st_fx->bfi )
496 : {
497 3100 : test();
498 3100 : test();
499 3100 : test();
500 3100 : test();
501 3100 : if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL )
502 : {
503 0 : hTcxDec->tcxConceal_recalc_exc = 1;
504 0 : move16();
505 : }
506 3100 : st_fx->last_good = st_fx->clas_dec;
507 3100 : move16();
508 : }
509 3100 : IF( st_fx->use_partial_copy )
510 : {
511 0 : st_fx->prev_rf_frame_type = st_fx->rf_frame_type;
512 0 : move16();
513 : }
514 : ELSE
515 : {
516 3100 : st_fx->prev_rf_frame_type = INACTIVE;
517 3100 : move16();
518 : }
519 :
520 3100 : if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( NE_16( st_fx->bfi, 1 ) || st_fx->use_partial_copy != 0 ) )
521 : {
522 3100 : st_fx->rf_flag_last = st_fx->rf_flag;
523 3100 : move16();
524 : }
525 :
526 3100 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
527 : {
528 1852 : test();
529 1852 : if ( !st_fx->bfi && ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) )
530 : {
531 1852 : move16();
532 1852 : st_fx->last_active_brate = st_fx->total_brate;
533 : }
534 :
535 1852 : move16();
536 1852 : move16();
537 1852 : st_fx->last_core = st_fx->core;
538 1852 : if ( st_fx->hHQ_core != NULL )
539 : {
540 1852 : st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx;
541 : }
542 : }
543 1248 : ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) )
544 : {
545 1248 : test();
546 1248 : if ( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) )
547 : {
548 1248 : move16();
549 1248 : st_fx->last_active_brate = st_fx->total_brate;
550 : }
551 : /* INFO: moved from update_decoder_LPD_cng() */
552 1248 : if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
553 : {
554 0 : move16();
555 0 : st_fx->last_is_cng = 1;
556 : }
557 :
558 :
559 1248 : if ( !st_fx->bfi )
560 : {
561 1248 : st_fx->last_core = st_fx->core;
562 : }
563 1248 : move16();
564 1248 : move16();
565 1248 : st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */
566 : }
567 3100 : move16();
568 3100 : st_fx->last_core_brate = st_fx->core_brate;
569 :
570 : /* save synthesis for core switching */
571 3100 : test();
572 3100 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) )
573 : {
574 3100 : Copy_Scale_sig( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec );
575 : }
576 3100 : test();
577 3100 : test();
578 3100 : test();
579 3100 : IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) )
580 :
581 : {
582 : /* reset LP memories */
583 0 : set16_fx( st_fx->mem_MA_fx, 0, M );
584 0 : IF( EQ_32( st_fx->sr_core, INT_FS_16k ) )
585 : {
586 0 : Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M );
587 : }
588 : ELSE
589 : {
590 0 : Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M );
591 : }
592 : }
593 3100 : IF( EQ_16( st_fx->codec_mode, MODE2 ) )
594 : {
595 1248 : test();
596 1248 : IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) )
597 : {
598 0 : st_fx->last_nelp_mode_dec = 1;
599 0 : move16();
600 : }
601 : ELSE
602 : {
603 1248 : st_fx->last_nelp_mode_dec = 0;
604 1248 : move16();
605 : }
606 : }
607 :
608 3100 : st_fx->prev_use_partial_copy = st_fx->use_partial_copy;
609 3100 : move16();
610 :
611 3100 : st_fx->prev_tilt_code_dec_fx = 0;
612 3100 : move16();
613 :
614 3100 : st_fx->prev_Q_exc = st_fx->Q_exc;
615 3100 : move16();
616 :
617 3100 : L_tmp = L_mult( st_fx->tilt_code_dec_fx[0], 4096 );
618 12400 : FOR( i = 1; i < NB_SUBFR; i++ )
619 : {
620 9300 : L_tmp = L_mac( L_tmp, st_fx->tilt_code_dec_fx[i], 4096 );
621 : }
622 3100 : st_fx->prev_tilt_code_dec_fx = round_fx( L_tmp );
623 :
624 3100 : IF( EQ_16( st_fx->core, HQ_CORE ) )
625 : {
626 429 : st_fx->prev_coder_type = GENERIC;
627 429 : move16();
628 : }
629 2671 : ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) )
630 : {
631 2671 : st_fx->prev_coder_type = st_fx->coder_type;
632 2671 : move16();
633 : }
634 :
635 3100 : test();
636 3100 : IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL )
637 : {
638 0 : if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) )
639 : {
640 0 : st_fx->hTdCngDec->act_cnt = 0;
641 0 : move16();
642 : }
643 :
644 0 : st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 );
645 :
646 0 : test();
647 0 : if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) )
648 : {
649 0 : st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 );
650 : }
651 :
652 0 : st_fx->hTdCngDec->act_cnt2 = add( st_fx->hTdCngDec->act_cnt2, 1 );
653 0 : if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) )
654 : {
655 0 : st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD;
656 0 : move16();
657 : }
658 : }
659 :
660 3100 : test();
661 3100 : test();
662 3100 : if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) )
663 : {
664 0 : st_fx->first_CNG = 1;
665 0 : move16();
666 : }
667 :
668 : /* update bandwidth switching parameters */
669 3100 : st_fx->last_flag_cna = st_fx->flag_cna;
670 3100 : move16();
671 3100 : if ( st_fx->hFdCngDec != NULL )
672 : {
673 3100 : st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type;
674 3100 : move16();
675 : }
676 :
677 3100 : if ( GT_16( st_fx->element_mode, EVS_MONO ) )
678 : {
679 0 : st_fx->m_old_frame_type = st_fx->m_frame_type;
680 0 : move16();
681 : }
682 3100 : test();
683 3100 : test();
684 : /* update bandwidth switching parameters */
685 3100 : IF( EQ_16( st_fx->core, AMR_WB_CORE ) )
686 : {
687 0 : st_fx->last_bwidth = WB;
688 :
689 0 : st_fx->prev_bws_cnt = 0;
690 0 : st_fx->bws_cnt = 0;
691 0 : st_fx->bws_cnt1 = 0;
692 0 : move16();
693 0 : move16();
694 0 : move16();
695 0 : move16();
696 : }
697 3100 : ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) )
698 : {
699 1852 : updt_bw_switching_fx( st_fx, synth, Qpostd );
700 : }
701 : ELSE
702 : {
703 1248 : st_fx->last_bwidth = st_fx->bwidth;
704 1248 : st_fx->prev_bws_cnt = st_fx->bws_cnt;
705 1248 : move32();
706 1248 : move16();
707 : }
708 :
709 : /* synchronisation of CNG seeds*/
710 3100 : test();
711 3100 : test();
712 3100 : test();
713 3100 : test();
714 3100 : IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) )
715 : {
716 3100 : Random( &( st_fx->hTdCngDec->cng_seed ) );
717 3100 : Random( &( st_fx->hTdCngDec->cng_ener_seed ) );
718 : }
719 :
720 3100 : test();
721 3100 : test();
722 3100 : test();
723 3100 : IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) )
724 : {
725 : /* update the parameters used in waveform adjustment */
726 0 : concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX );
727 : }
728 :
729 3100 : st_fx->last_total_brate_ber = st_fx->total_brate;
730 3100 : move32();
731 3100 : IF( st_fx->bfi == 0 )
732 : {
733 3100 : st_fx->last_total_brate = st_fx->total_brate;
734 3100 : st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal;
735 3100 : move32();
736 3100 : move32();
737 : }
738 3100 : st_fx->last_low_rate_mode = st_fx->low_rate_mode;
739 3100 : move16();
740 3100 : if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) )
741 : {
742 600 : st_fx->ini_frame = add( st_fx->ini_frame, 1 );
743 : }
744 :
745 3100 : return;
746 : }
747 :
748 :
749 1003508 : static void ivas_updt_bw_switching_fx(
750 : Decoder_State *st_fx, /* i/o: decoder state structure */
751 : const Word32 *synth, /* i : fixed point synthesis signal Qpost */
752 : const Word16 Qpost )
753 : {
754 1003508 : test();
755 1003508 : IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) )
756 : {
757 173965 : st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k );
758 : }
759 :
760 1003508 : st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q
761 1003508 : move32();
762 1003508 : st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q
763 1003508 : move32();
764 1003508 : st_fx->last_bwidth = st_fx->bwidth;
765 1003508 : move32();
766 :
767 1003508 : IF( EQ_16( st_fx->core, ACELP_CORE ) )
768 : {
769 146164 : st_fx->last_inner_frame = L_FRAME32k;
770 146164 : move16();
771 146164 : test();
772 146164 : if ( EQ_16( st_fx->bwidth, WB ) && ( st_fx->bws_cnt == 0 ) )
773 : {
774 26305 : st_fx->last_inner_frame = L_FRAME16k;
775 26305 : move16();
776 : }
777 : }
778 : ELSE
779 : {
780 857344 : test();
781 857344 : test();
782 857344 : test();
783 857344 : IF( !( GE_16( st_fx->last_inner_frame, L_FRAME16k ) && LE_16( inner_frame_tbl[st_fx->bwidth], L_FRAME16k ) && st_fx->bws_cnt > 0 && LT_16( st_fx->bws_cnt, N_WS2N_FRAMES ) ) )
784 : {
785 857344 : st_fx->last_inner_frame = inner_frame_tbl[st_fx->bwidth];
786 857344 : move16();
787 : }
788 : }
789 1003508 : st_fx->prev_bws_cnt = st_fx->bws_cnt; // TODO: Duplicate variables
790 1003508 : move16();
791 1003508 : return;
792 : }
793 :
794 1029590 : static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx
795 : {
796 1029590 : Word64 sum = 0;
797 : Word16 i;
798 853964950 : FOR( i = 0; i < length; i++ )
799 : {
800 852935360 : sum = W_add( sum, W_mult_32_32( x[i], x[i] ) ); // 2*Qx -1
801 : }
802 1029590 : return W_round64_L( sum );
803 : }
804 :
805 1029590 : void ivas_updt_dec_common_fx(
806 : Decoder_State *st_fx, /* i/o: decoder state structure */
807 : Word16 hq_core_type_fx, /* i : HQ core type */
808 : const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */
809 : const Word32 *synth, /* i : decoded synthesis Qpostd */
810 : const Word16 Qpostd /* i : Synthesis Q value */
811 :
812 : )
813 : {
814 : Word16 i;
815 : Word32 L_tmp;
816 :
817 : TCX_DEC_HANDLE hTcxDec;
818 1029590 : hTcxDec = st_fx->hTcxDec;
819 :
820 1029590 : st_fx->last_codec_mode = st_fx->codec_mode;
821 1029590 : move16();
822 1029590 : st_fx->last_extl = st_fx->extl;
823 1029590 : move16();
824 1029590 : st_fx->last_L_frame = st_fx->L_frame;
825 1029590 : move16();
826 :
827 1029590 : st_fx->prev_old_bfi = st_fx->prev_bfi;
828 1029590 : move16();
829 1029590 : st_fx->prev_bfi = st_fx->bfi;
830 1029590 : move16();
831 1029590 : IF( NE_16( st_fx->core, AMR_WB_CORE ) )
832 : {
833 1029590 : st_fx->old_bfi_cnt = st_fx->nbLostCmpt;
834 1029590 : move16();
835 : }
836 1029590 : move16();
837 1029590 : st_fx->last_con_tcx = st_fx->con_tcx;
838 1029590 : move16();
839 1029590 : st_fx->con_tcx = 0;
840 :
841 1029590 : move16();
842 1029590 : IF( st_fx->hHQ_nbfec != NULL )
843 : {
844 0 : st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core;
845 0 : move16();
846 : }
847 :
848 1029590 : IF( st_fx->hTcxDec != NULL )
849 : {
850 1025839 : hTcxDec->tcxConceal_recalc_exc = 0;
851 1025839 : move16();
852 : }
853 1029590 : test();
854 1029590 : test();
855 1029590 : test();
856 1029590 : test();
857 1029590 : IF( ( GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) && st_fx->use_partial_copy && st_fx->bfi ) || !st_fx->bfi )
858 : {
859 1012562 : test();
860 1012562 : test();
861 1012562 : test();
862 1012562 : test();
863 :
864 1012562 : if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL )
865 : {
866 0 : hTcxDec->tcxConceal_recalc_exc = 1;
867 0 : move16();
868 : }
869 1012562 : st_fx->last_good = st_fx->clas_dec;
870 1012562 : move16();
871 : }
872 1029590 : IF( st_fx->use_partial_copy )
873 : {
874 0 : st_fx->prev_rf_frame_type = st_fx->rf_frame_type;
875 0 : move16();
876 : }
877 : ELSE
878 : {
879 1029590 : st_fx->prev_rf_frame_type = INACTIVE;
880 1029590 : move16();
881 : }
882 1029590 : test();
883 1029590 : test();
884 1029590 : if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) )
885 : {
886 17028 : st_fx->rf_flag_last = st_fx->rf_flag;
887 17028 : move16();
888 : }
889 :
890 1029590 : IF( EQ_16( st_fx->codec_mode, MODE1 ) )
891 : {
892 1029590 : test();
893 1029590 : test();
894 1029590 : test();
895 1029590 : if ( !st_fx->bfi && ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) )
896 : {
897 986480 : move16();
898 986480 : st_fx->last_active_brate = st_fx->total_brate;
899 : }
900 :
901 1029590 : move16();
902 1029590 : move16();
903 1029590 : if ( !st_fx->bfi || st_fx->element_mode == EVS_MONO )
904 : {
905 1012562 : st_fx->last_core = st_fx->core;
906 : }
907 1029590 : st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */
908 1029590 : if ( st_fx->hHQ_core != NULL )
909 : {
910 1025839 : st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx;
911 1025839 : move16();
912 : }
913 : }
914 0 : ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) )
915 : {
916 0 : test();
917 0 : if ( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) )
918 : {
919 0 : move16();
920 0 : st_fx->last_active_brate = st_fx->total_brate;
921 : }
922 : /* INFO: moved from update_decoder_LPD_cng() */
923 0 : if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) )
924 : {
925 0 : move16();
926 0 : st_fx->last_is_cng = 1;
927 : }
928 :
929 :
930 0 : if ( !st_fx->bfi )
931 : {
932 0 : st_fx->last_core = st_fx->core;
933 : }
934 0 : move16();
935 0 : move16();
936 0 : st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */
937 : }
938 1029590 : move16();
939 1029590 : st_fx->last_core_brate = st_fx->core_brate;
940 :
941 : /* save synthesis for core switching */
942 1029590 : test();
943 1029590 : IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) )
944 : {
945 0 : Copy_Scale_sig_32_16( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec );
946 : }
947 1029590 : test();
948 1029590 : test();
949 1029590 : test();
950 1029590 : IF( st_fx->element_mode != EVS_MONO )
951 : {
952 1029590 : Word16 q_div = sub( Q31, shl( Qpostd, 1 ) );
953 1029590 : Word16 output_frame = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS );
954 1029590 : move16();
955 1029590 : Word32 sum_val = sum_32_32_fx( synth, output_frame ); // 2*Q_syn -1
956 1029590 : Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div );
957 1029590 : Word32 log_energy = L_add( L_shl( L_deposit_l( add( q_div, sub( Q31, shl( Qpostd, 1 ) ) ) ), Q15 ),
958 : L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); // Q15
959 1029590 : Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); // Q15
960 1029590 : st_fx->log_energy_old_fx = log_energy; // Q15
961 1029590 : move32();
962 1029590 : st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); // Q15
963 :
964 1029590 : IF( EQ_16( st_fx->core, HQ_CORE ) )
965 : {
966 7475 : st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); // Q15
967 7475 : st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); // Q15
968 : }
969 1029590 : st_fx->stab_fac_smooth_lt_fx = extract_h( L_add( L_mult( ENV_SMOOTH_FAC_FX, st_fx->stab_fac_fx ),
970 1029590 : L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); // Q15
971 : }
972 :
973 1029590 : test();
974 1029590 : test();
975 1029590 : test();
976 1029590 : test();
977 1029590 : IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || ( st_fx->element_mode > EVS_MONO ) ) ) )
978 : {
979 : /* reset LP memories */
980 769694 : set16_fx( st_fx->mem_MA_fx, 0, M );
981 769694 : IF( EQ_32( st_fx->sr_core, INT_FS_16k ) )
982 : {
983 77074 : Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M );
984 : }
985 : ELSE
986 : {
987 692620 : Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M );
988 : }
989 : }
990 1029590 : IF( EQ_16( st_fx->codec_mode, MODE2 ) )
991 : {
992 0 : test();
993 0 : IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) )
994 : {
995 0 : st_fx->last_nelp_mode_dec = 1;
996 0 : move16();
997 : }
998 : ELSE
999 : {
1000 0 : st_fx->last_nelp_mode_dec = 0;
1001 0 : move16();
1002 : }
1003 : }
1004 :
1005 1029590 : st_fx->prev_use_partial_copy = st_fx->use_partial_copy;
1006 1029590 : move16();
1007 :
1008 1029590 : st_fx->prev_tilt_code_dec_fx = 0;
1009 1029590 : move16();
1010 :
1011 1029590 : st_fx->prev_Q_exc = st_fx->Q_exc;
1012 1029590 : move16();
1013 :
1014 1029590 : L_tmp = L_mult( st_fx->tilt_code_dec_fx[0], 4096 );
1015 4118360 : FOR( i = 1; i < NB_SUBFR; i++ )
1016 : {
1017 3088770 : L_tmp = L_mac( L_tmp, st_fx->tilt_code_dec_fx[i], 4096 );
1018 : }
1019 1029590 : st_fx->prev_tilt_code_dec_fx = round_fx( L_tmp );
1020 :
1021 1029590 : IF( EQ_16( st_fx->core, HQ_CORE ) )
1022 : {
1023 7475 : st_fx->prev_coder_type = GENERIC;
1024 7475 : move16();
1025 : }
1026 1022115 : ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) )
1027 : {
1028 1022115 : st_fx->prev_coder_type = st_fx->coder_type;
1029 1022115 : move16();
1030 : }
1031 :
1032 1029590 : test();
1033 1029590 : test();
1034 1029590 : test();
1035 1029590 : test();
1036 1029590 : IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL )
1037 : {
1038 :
1039 17729 : if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) )
1040 : {
1041 670 : st_fx->hTdCngDec->act_cnt = 0;
1042 670 : move16();
1043 : }
1044 :
1045 17729 : st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 );
1046 :
1047 17729 : test();
1048 :
1049 17729 : if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) )
1050 : {
1051 244 : st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 );
1052 : }
1053 :
1054 17729 : if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) )
1055 : {
1056 0 : st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD;
1057 0 : move16();
1058 : }
1059 : }
1060 :
1061 1029590 : test();
1062 1029590 : test();
1063 1029590 : test();
1064 1029590 : if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) )
1065 : {
1066 88 : st_fx->first_CNG = 1;
1067 88 : move16();
1068 : }
1069 :
1070 : /* update bandwidth switching parameters */
1071 1029590 : test();
1072 1029590 : test();
1073 1029590 : st_fx->last_flag_cna = st_fx->flag_cna;
1074 1029590 : move16();
1075 1029590 : if ( st_fx->hFdCngDec != NULL )
1076 : {
1077 861859 : st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type;
1078 861859 : move16();
1079 : }
1080 :
1081 1029590 : if ( st_fx->element_mode > EVS_MONO )
1082 : {
1083 1029590 : st_fx->m_old_frame_type = st_fx->m_frame_type;
1084 1029590 : move16();
1085 : }
1086 :
1087 : /* update bandwidth switching parameters */
1088 1029590 : test();
1089 1029590 : test();
1090 1029590 : IF( EQ_16( st_fx->core, AMR_WB_CORE ) )
1091 : {
1092 0 : st_fx->last_bwidth = WB;
1093 :
1094 0 : st_fx->prev_bws_cnt = 0;
1095 0 : st_fx->bws_cnt = 0;
1096 0 : st_fx->bws_cnt1 = 0;
1097 0 : move16();
1098 0 : move16();
1099 0 : move16();
1100 0 : move16();
1101 : }
1102 1029590 : ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) )
1103 : {
1104 1003508 : ivas_updt_bw_switching_fx( st_fx, synth, Qpostd );
1105 : }
1106 : ELSE
1107 : {
1108 26082 : st_fx->last_bwidth = st_fx->bwidth;
1109 26082 : st_fx->prev_bws_cnt = st_fx->bws_cnt;
1110 26082 : move32();
1111 26082 : move16();
1112 : }
1113 :
1114 : /* synchronisation of CNG seeds*/
1115 1029590 : test();
1116 1029590 : test();
1117 1029590 : test();
1118 1029590 : test();
1119 1029590 : IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) )
1120 : {
1121 220217 : Random( &( st_fx->hTdCngDec->cng_seed ) );
1122 220217 : Random( &( st_fx->hTdCngDec->cng_ener_seed ) );
1123 : }
1124 :
1125 1029590 : test();
1126 1029590 : test();
1127 1029590 : test();
1128 1029590 : IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) )
1129 : {
1130 : /* update the parameters used in waveform adjustment */
1131 0 : concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX );
1132 : }
1133 :
1134 1029590 : st_fx->last_total_brate_ber = st_fx->total_brate;
1135 1029590 : move32();
1136 1029590 : IF( st_fx->bfi == 0 )
1137 : {
1138 1012562 : st_fx->last_total_brate = st_fx->total_brate;
1139 1012562 : st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal;
1140 1012562 : move32();
1141 1012562 : move32();
1142 : }
1143 1029590 : st_fx->last_low_rate_mode = st_fx->low_rate_mode;
1144 1029590 : move16();
1145 1029590 : if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) )
1146 : {
1147 358336 : st_fx->ini_frame = add( st_fx->ini_frame, 1 );
1148 : }
1149 :
1150 1029590 : return;
1151 : }
1152 :
1153 : /*-------------------------------------------------------------------*
1154 : * update_decoder_LPD_cng()
1155 : *
1156 : *
1157 : *--------------------------------------------------------------------*/
1158 :
1159 0 : void update_decoder_LPD_cng(
1160 : Decoder_State *st,
1161 : Word16 coder_type,
1162 : Word16 *timeDomainBuffer, /*QtimeDomainBuffer*/
1163 : Word16 *A, /*Q12*/
1164 : Word16 *bpf_noise_buf /*Qbpf_noise_buf*/
1165 : )
1166 : {
1167 : Word16 i;
1168 : Word16 lsp[M], lsf[M];
1169 : Word16 *synth, synth_buf[M + 1 + L_FRAME_MAX + L_FRAME_MAX / 2], tmp;
1170 : Word16 buf_synth[OLD_SYNTH_SIZE_DEC + L_FRAME_MAX + M];
1171 : Word16 pf_pitch[NB_SUBFR16k];
1172 : Word16 pf_gain[NB_SUBFR16k];
1173 : Word16 pitch[NB_SUBFR16k];
1174 : TCX_DEC_HANDLE hTcxDec;
1175 :
1176 0 : hTcxDec = st->hTcxDec;
1177 0 : synth = synth_buf + ( 1 + M );
1178 :
1179 : /* LPC order */
1180 0 : move16();
1181 :
1182 : /* LPC -> LSP */
1183 0 : E_LPC_a_lsp_conversion( A, lsp, st->lsp_old_fx, M );
1184 :
1185 : /* LSP -> LSF */
1186 0 : IF( EQ_16( st->L_frame, L_FRAME16k ) )
1187 : {
1188 0 : lsp2lsf_fx( lsp, lsf, M, INT_FS_16k_FX );
1189 : }
1190 : ELSE
1191 : {
1192 0 : E_LPC_lsp_lsf_conversion( lsp, lsf, M );
1193 : }
1194 :
1195 0 : IF( hTcxDec != NULL )
1196 : {
1197 0 : Copy( hTcxDec->old_synth, buf_synth, hTcxDec->old_synth_len );
1198 0 : Copy( timeDomainBuffer, buf_synth + hTcxDec->old_synth_len, st->L_frame );
1199 :
1200 : /* Update synth memory */
1201 :
1202 0 : move16();
1203 :
1204 0 : Copy( st->syn, synth_buf, 1 + M );
1205 0 : Copy( timeDomainBuffer, synth, st->L_frame );
1206 0 : Copy( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M );
1207 0 : Copy( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, sub( hTcxDec->old_synth_len, st->L_frame ) );
1208 0 : Copy( synth, hTcxDec->old_synth + sub( hTcxDec->old_synth_len, st->L_frame ), st->L_frame );
1209 0 : bufferCopyFx( synth + sub( st->L_frame, ( st->L_frame / 2 ) ), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ );
1210 :
1211 0 : hTcxDec->tcxltp_last_gain_unmodified = 0;
1212 0 : move16();
1213 0 : hTcxDec->envWeighted = 0;
1214 0 : move16();
1215 : }
1216 :
1217 : /* Update pe-synth memory */
1218 0 : move16();
1219 0 : tmp = synth[-( 1 + M )];
1220 :
1221 0 : st->Q_syn = E_UTIL_f_preemph3( synth - M, st->preemph_fac, M + st->L_frame, &tmp, 1 );
1222 0 : st->prev_Q_syn = st->Q_syn = sub( st->Q_syn, 1 );
1223 0 : move16();
1224 0 : move16();
1225 0 : Copy( synth + st->L_frame - M, st->mem_syn2_fx, M );
1226 0 : Copy( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM );
1227 :
1228 : /* Update excitation memory */
1229 0 : assert( st->L_frame < L_EXC_MEM_DEC );
1230 0 : IF( NE_16( add( st->Q_syn, 1 ), st->Q_exc ) )
1231 : {
1232 0 : Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( add( st->Q_syn, 1 ), st->Q_exc ) );
1233 : }
1234 0 : st->Q_exc = add( st->Q_syn, 1 );
1235 0 : Copy( st->old_exc_fx + st->L_frame, st->old_exc_fx, sub( L_EXC_MEM_DEC, st->L_frame ) );
1236 0 : Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 1 );
1237 :
1238 : /* Update LPC-related memories */
1239 :
1240 0 : Copy( lsp, st->lsp_old_fx, M );
1241 0 : Copy( lsf, st->lsf_old_fx, M );
1242 0 : Copy( lsp, st->lspold_uw, M );
1243 0 : Copy( lsf, st->lsfold_uw, M );
1244 0 : move16();
1245 0 : move16();
1246 0 : Copy( A, st->old_Aq_12_8_fx, M + 1 );
1247 0 : st->old_Es_pred_fx = 0;
1248 :
1249 : /* Reset acelp memories */
1250 :
1251 0 : move16();
1252 0 : st->dm_fx.prev_gain_code = L_deposit_l( 0 );
1253 0 : set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
1254 0 : st->dm_fx.prev_state = 0;
1255 :
1256 0 : move16();
1257 0 : move16();
1258 0 : st->tilt_code_fx = TILT_CODE;
1259 0 : st->gc_threshold_fx = 0;
1260 :
1261 : /* Update ace/tcx mode */
1262 0 : st->core = ACELP_CORE;
1263 0 : move16();
1264 0 : move16();
1265 0 : move16();
1266 0 : st->last_is_cng = 1;
1267 0 : move16();
1268 :
1269 : /* Reset TCX overlap */
1270 0 : move16();
1271 0 : move16();
1272 0 : IF( st->hTcxCfg != NULL )
1273 : {
1274 0 : st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1275 : }
1276 : /* For BBWE and Postfilter */
1277 :
1278 0 : Copy( A, &( st->mem_Aq[0] ), M + 1 );
1279 0 : Copy( A, &( st->mem_Aq[( M + 1 )] ), M + 1 );
1280 0 : Copy( A, &( st->mem_Aq[2 * ( M + 1 )] ), M + 1 );
1281 0 : Copy( A, &( st->mem_Aq[3 * ( M + 1 )] ), M + 1 );
1282 0 : IF( EQ_16( st->L_frame, L_FRAME16k ) )
1283 : {
1284 0 : Copy( A, &( st->mem_Aq[4 * ( M + 1 )] ), M + 1 );
1285 : }
1286 :
1287 : /* Update for concealment */
1288 0 : move16();
1289 0 : move16();
1290 0 : st->nbLostCmpt = 0;
1291 0 : st->prev_old_bfi = 0;
1292 :
1293 0 : FOR( i = 0; i < M; i++ )
1294 : {
1295 0 : move16();
1296 0 : move16();
1297 0 : move16();
1298 0 : st->lsf_adaptive_mean_fx[i] = add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), add( mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( lsf[i], 10923 /*1.0f/3.0f Q15*/ ) ) );
1299 0 : st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i];
1300 0 : st->lsfoldbfi0_fx[i] = lsf[i];
1301 : }
1302 :
1303 0 : set16_fx( pitch, shl( L_SUBFR, 6 ), NB_SUBFR16k );
1304 :
1305 0 : FEC_clas_estim_fx(
1306 : st,
1307 : /*Opt_AMR_WB*/ 0, /*A*/
1308 0 : st->L_frame,
1309 : &( st->clas_dec ),
1310 : coder_type,
1311 : pitch,
1312 : synth,
1313 : &st->lp_ener_FER_fx,
1314 : /**decision_hyst*/ NULL, /* i/o: hysteresis of the music/speech decision */
1315 : /**UV_cnt*/ NULL, /* i/o: number of consecutives frames classified as UV */
1316 : /**LT_UV_cnt*/ NULL, /* i/o: long term consecutives frames classified as UV */
1317 : /**Last_ener*/ NULL, /* i/o: last_energy frame */
1318 : /**locattack*/ NULL, /* i/o: detection of attack (mainly to localized speech burst) */
1319 : /**lt_diff_etot*/ NULL, /* i/o: long-term total energy variation */
1320 : /**amr_io_class*/ NULL, /* i/o: classification for AMR-WB IO mode */
1321 0 : st->Q_syn, /* i : Synthesis scaling */
1322 : /**class_para*/ NULL, /* o : classification para. fmerit1 */
1323 0 : st->mem_syn_clas_estim_fx, /* i/o: memory of the synthesis signal for frame class estimation */
1324 : &st->classifier_Q_mem_syn, /*i/o : exponent for memory of synthesis signal for frame class estimation */
1325 : -32768 /*-1.f Q15*/, /* i : LTP Gain */
1326 : 0 /*CLASSIFIER_ACELP*/, /* i : signal classifier mode */
1327 : 0 /*bfi*/, /* i : bad frame indicator */
1328 : st->last_core_brate, /* i : bitrate of previous frame */
1329 : -1 );
1330 : /* Postfiltering */
1331 0 : set16_fx( pf_pitch, L_SUBFR, NB_SUBFR16k );
1332 0 : set16_fx( pf_gain, 0, NB_SUBFR16k );
1333 0 : st->bpf_gain_param = 0;
1334 0 : move16();
1335 :
1336 0 : post_decoder( st, buf_synth, pf_gain, pf_pitch, timeDomainBuffer, bpf_noise_buf );
1337 :
1338 0 : return;
1339 : }
|