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 <stdio.h>
8 : #include <string.h>
9 : #include "options.h"
10 : #include "prot_fx.h"
11 : #include "basop_util.h"
12 : #include "rom_com.h"
13 : #include "cnst.h" /* for MIN_CNG_LEV */
14 :
15 : /*-----------------------------------------------------------------------*
16 : * open_decoder_LPD_fx()
17 : *
18 : * Initialization of state variables
19 : *-----------------------------------------------------------------------*/
20 35 : void open_decoder_LPD_fx(
21 : Decoder_State *st,
22 : const Word32 total_brate, /* Q0 */
23 : const Word16 bwidth /* Q0 */
24 : )
25 : {
26 : Word16 i;
27 : Word16 mem_syn_r_size_new;
28 : Word16 mem_syn_r_size_old;
29 : Word16 fscaleFB;
30 : BPF_DEC_HANDLE hBPF;
31 : TD_BWE_DEC_HANDLE hBWE_TD;
32 : TCX_LTP_DEC_HANDLE hTcxLtpDec;
33 : HQ_DEC_HANDLE hHQ_core;
34 : TCX_DEC_HANDLE hTcxDec;
35 :
36 35 : hBPF = st->hBPF;
37 35 : hBWE_TD = st->hBWE_TD;
38 35 : hHQ_core = st->hHQ_core;
39 35 : hTcxLtpDec = st->hTcxLtpDec;
40 35 : hTcxDec = st->hTcxDec;
41 :
42 35 : st->total_brate = total_brate;
43 35 : move32();
44 :
45 35 : if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/
46 : {
47 32 : st->fscale_old = st->fscale;
48 32 : move16();
49 : }
50 35 : st->sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
51 35 : move32();
52 :
53 35 : st->fscale = sr2fscale_fx( st->sr_core );
54 35 : move16();
55 35 : fscaleFB = sr2fscale_fx( st->output_Fs );
56 :
57 : /* initializing variables for frame lengths etc. right in the beginning */
58 35 : st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) );
59 35 : move16();
60 35 : hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) );
61 35 : move16();
62 35 : IF( st->ini_frame == 0 )
63 : {
64 4 : st->last_L_frame = st->L_frame_past = st->L_frame;
65 4 : move16();
66 4 : move16();
67 4 : st->L_frameTCX_past = hTcxDec->L_frameTCX;
68 4 : move16();
69 : }
70 35 : st->tcxonly = getTcxonly(
71 : st->total_brate
72 : /*, st->is_ism_format Needed in the last version of float IVAS */
73 : );
74 35 : move16();
75 :
76 : /* the TD TCX PLC in MODE1 still runs with 80ms subframes */
77 35 : st->nb_subfr = NB_SUBFR;
78 35 : move16();
79 35 : test();
80 35 : test();
81 35 : test();
82 35 : test();
83 35 : test();
84 35 : test();
85 35 : test();
86 35 : test();
87 :
88 35 : IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) ||
89 : ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) ||
90 : ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) )
91 : {
92 12 : st->nb_subfr = NB_SUBFR16k;
93 12 : move16();
94 : }
95 :
96 : /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->total_brate */
97 35 : st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
98 35 : move16();
99 :
100 : assert( FSCALE_DENOM == 512 );
101 35 : assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
102 35 : assert( st->bits_frame == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) );
103 :
104 35 : st->TcxBandwidth = getTcxBandwidth( bwidth );
105 35 : move16();
106 35 : st->narrowBand = 0;
107 35 : move16();
108 35 : if ( EQ_16( bwidth, NB ) )
109 : {
110 3 : st->narrowBand = 1;
111 3 : move16();
112 : }
113 :
114 35 : IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
115 : {
116 0 : st->pit_res_max = initPitchLagParameters( INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
117 0 : move16();
118 0 : IF( hTcxDec != NULL )
119 : {
120 : // st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max);
121 : // hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800);
122 : // hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800);
123 0 : i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); /* Q6 */
124 0 : hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
125 0 : move16();
126 0 : hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
127 0 : move16();
128 : }
129 : }
130 : ELSE
131 : {
132 35 : st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
133 35 : move16();
134 35 : IF( hTcxDec != NULL )
135 : {
136 35 : i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /* Q6 */
137 35 : hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
138 35 : move16();
139 35 : hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
140 35 : move16();
141 : }
142 : }
143 35 : if ( !st->ini_frame )
144 : {
145 4 : st->pit_res_max_past = st->pit_res_max;
146 4 : move16();
147 : }
148 :
149 : /*Preemphasis param*/
150 35 : st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/
151 35 : move16();
152 35 : IF( LT_16( st->fscale, 640 ) ) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/
153 : {
154 23 : st->preemph_fac = PREEMPH_FAC; /*WB*/
155 23 : move16();
156 : }
157 12 : ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */
158 : {
159 12 : st->preemph_fac = PREEMPH_FAC_16k; /*WB*/
160 12 : move16();
161 : }
162 :
163 35 : st->gamma = GAMMA1;
164 35 : move16();
165 35 : st->inv_gamma = GAMMA1_INV;
166 35 : move16();
167 35 : test();
168 35 : test();
169 35 : IF( EQ_32( st->sr_core, INT_FS_16k ) ||
170 : ( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) )
171 : {
172 12 : st->gamma = GAMMA16k;
173 12 : move16();
174 12 : st->inv_gamma = GAMMA16k_INV;
175 12 : move16();
176 : }
177 :
178 : /* LPC quantization */
179 35 : st->lpcQuantization = 0;
180 35 : move16();
181 35 : test();
182 35 : if ( ( st->tcxonly == 0 ) && LE_32( st->sr_core, INT_FS_16k ) )
183 : {
184 35 : st->lpcQuantization = 1;
185 35 : move16();
186 : }
187 :
188 35 : st->numlpc = 2;
189 35 : move16();
190 35 : if ( st->tcxonly == 0 )
191 : {
192 35 : st->numlpc = 1;
193 35 : move16();
194 : }
195 :
196 : /* Initialize TBE */
197 35 : st->prev_coder_type = GENERIC;
198 35 : move16();
199 35 : IF( st->hBWE_TD != NULL )
200 : {
201 35 : set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */
202 35 : hBWE_TD->prev_tilt_para_fx = 0;
203 35 : move16();
204 35 : set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */
205 : }
206 :
207 : /*TCX config*/
208 35 : st->hTcxCfg->preemph_fac = st->preemph_fac;
209 35 : move16();
210 35 : st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length;
211 35 : move16();
212 35 : init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config
213 35 : IF( st->ini_frame == 0 )
214 : {
215 4 : st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
216 4 : move16();
217 4 : move16();
218 : }
219 :
220 : /* TCX Offset */
221 35 : st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); /* Q0 */
222 35 : move16();
223 35 : st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); /* Q0 */
224 35 : move16();
225 :
226 : /* Initialize FAC */
227 35 : st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); /* Q0 */
228 35 : move16();
229 35 : st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxDec->L_frameTCX, 2 ) ); /* Q0 */
230 35 : move16();
231 :
232 : /* set number of coded lines */
233 35 : st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( st->bwidth );
234 35 : move16();
235 :
236 : /* TNS in TCX */
237 35 : st->hTcxCfg->pCurrentTnsConfig = NULL;
238 35 : st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode );
239 35 : move16();
240 :
241 35 : IF( st->hTcxCfg->fIsTNSAllowed != 0 )
242 : {
243 12 : InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ );
244 : }
245 : /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/
246 35 : if ( st->tcxonly == 0 )
247 : {
248 35 : assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) );
249 : }
250 :
251 : IF( 1 ) // st->element_mode == EVS_MONO)
252 : {
253 35 : IF( st->hTECDec == NULL )
254 : {
255 3 : IF( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL )
256 : {
257 : // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n"));
258 0 : assert( 0 );
259 : }
260 : }
261 : }
262 : ELSE
263 : {
264 : st->hTECDec = NULL;
265 : }
266 35 : resetTecDec_Fx( st->hTECDec );
267 :
268 : /* Initialize decoder delay */
269 :
270 :
271 35 : if ( NE_16( st->element_mode, IVAS_SCE ) )
272 : {
273 35 : st->flag_cna = 0;
274 35 : move16();
275 : }
276 35 : IF( st->ini_frame == 0 )
277 : {
278 4 : st->flag_cna = 0;
279 4 : st->last_flag_cna = 0;
280 4 : move16();
281 4 : move16();
282 : }
283 :
284 : /* Static vectors to zero */
285 35 : IF( st->ini_frame == 0 )
286 : {
287 :
288 4 : st->last_is_cng = 0;
289 4 : move16();
290 :
291 4 : st->rate_switching_reset = 0;
292 4 : move16();
293 4 : IF( hTcxDec != NULL )
294 : {
295 4 : set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */
296 :
297 4 : set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl_TDAC */
298 4 : set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec-> Q_syn_OverlFB */
299 4 : set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */
300 :
301 4 : set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl */
302 :
303 4 : set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
304 4 : hTcxDec->q_old_synth = 0;
305 4 : move16();
306 4 : set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); /* hTcxDec->q_synth_history_fx */
307 4 : hTcxDec->q_synth_history_fx = 0;
308 4 : move16();
309 : }
310 4 : set16_fx( st->syn, 0, add( M, 1 ) ); /* Qx */
311 :
312 4 : set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */
313 :
314 4 : mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
315 4 : move16();
316 4 : mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
317 4 : move16();
318 :
319 4 : st->con_tcx = 0; /* Q0 */
320 4 : move16();
321 : }
322 : ELSE
323 : {
324 : /* Reset old_synth in case of core sampling rate switching and codec switching*/
325 31 : test();
326 31 : test();
327 31 : IF( st->hTcxDec != NULL && ( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) )
328 : {
329 31 : set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
330 31 : hTcxDec->q_old_synth = 0;
331 31 : move16();
332 : }
333 :
334 : /*Size of LPC syn memory*/
335 : /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
336 31 : mem_syn_r_size_old = shr( st->last_L_frame, 4 ); /* Q0 */
337 31 : mem_syn_r_size_new = shr( st->L_frame, 4 ); /* Q0 */
338 :
339 : /*Reset LPC mem*/
340 31 : test();
341 31 : test();
342 31 : IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) )
343 : {
344 : /*LPC quant. mem*/
345 18 : set16_fx( st->mem_MA_fx, 0, M ); /* (Qx2.56) */
346 18 : IF( EQ_32( st->sr_core, INT_FS_16k ) )
347 : {
348 11 : Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */
349 : }
350 : ELSE
351 : {
352 7 : Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */
353 : }
354 : }
355 :
356 : /*Codec switching*/
357 31 : test();
358 31 : IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO )
359 : {
360 31 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
361 31 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
362 31 : set16_fx( st->syn, 0, M ); /* Q_syn */
363 : }
364 31 : IF( EQ_16( st->last_core, AMR_WB_CORE ) )
365 : {
366 0 : st->last_core = ACELP_CORE;
367 0 : move16();
368 0 : st->last_core_bfi = ACELP_CORE;
369 0 : move16();
370 : }
371 :
372 : /*Codec switching from ACELP-A */
373 31 : test();
374 31 : test();
375 31 : test();
376 31 : test();
377 31 : IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
378 : {
379 13 : st->last_core_bfi = ACELP_CORE;
380 13 : move16();
381 :
382 : /*PLC*/
383 13 : IF( st->prev_bfi != 0 )
384 : {
385 : PWord16 const *w;
386 : Word16 W1, W2, nz, delay_comp;
387 :
388 0 : W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; /* Q0 */
389 0 : move16();
390 0 : W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
391 0 : w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/
392 :
393 0 : nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS );
394 0 : move16();
395 0 : delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/
396 0 : move16();
397 :
398 0 : Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* hHQ_core->Q_fer_samples*/
399 : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
400 0 : hTcxDec->Q_syn_OverlFB = hHQ_core->Q_fer_samples;
401 0 : move16();
402 : #endif
403 0 : lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/
404 : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
405 0 : hTcxDec->Q_syn_Overl = hHQ_core->Q_fer_samples;
406 0 : move16();
407 : #endif
408 :
409 : /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
410 0 : hHQ_core->Q_old_wtda = -1;
411 0 : move16();
412 0 : set16_fx( hHQ_core->old_out_fx, 0, nz ); /* exp(exp_old_out) */
413 0 : Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/
414 :
415 0 : FOR( i = 0; i < W2; i++ )
416 : {
417 0 : hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
418 0 : move16();
419 : }
420 0 : FOR( ; i < W1; i++ )
421 : {
422 0 : hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - ( 1 + ( i - W2 ) )].v.im, w[W2 - ( 1 + ( i - W2 ) )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
423 0 : move16();
424 : }
425 0 : set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz );
426 :
427 0 : lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX );
428 :
429 0 : Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* exp(exp_old_out) */
430 0 : hTcxDec->Q_syn_Overl_TDACFB = hHQ_core->Q_old_wtda;
431 0 : move16();
432 0 : nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS );
433 0 : move16();
434 0 : Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* hHQ_core->q_old_outLB_fx */
435 0 : hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda;
436 0 : move16();
437 0 : hTcxDec->Q_syn_Overl_TDAC = hHQ_core->Q_old_wtda_LB;
438 0 : move16();
439 : }
440 : }
441 :
442 31 : test();
443 31 : test();
444 31 : test();
445 31 : test();
446 31 : test();
447 31 : test();
448 31 : IF( EQ_16( st->last_codec_mode, MODE2 ) &&
449 : NE_16( st->L_frame, st->last_L_frame ) &&
450 : ( ( EQ_16( st->m_frame_type, SID_FRAME ) && ( st->last_core > ACELP_CORE ) ) ||
451 : ( ( st->last_core > ACELP_CORE ) && ( st->core > ACELP_CORE ) ) ||
452 : st->prev_bfi ) )
453 : {
454 0 : lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame );
455 : }
456 :
457 : /* Rate switching */
458 31 : test();
459 31 : test();
460 31 : test();
461 31 : test();
462 31 : test();
463 31 : IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) )
464 : {
465 : /*Codec switching from MDCT */
466 :
467 : /*Reset of ACELP memories*/
468 18 : st->rate_switching_reset = 1;
469 18 : st->tilt_code_fx = TILT_CODE;
470 18 : move16();
471 18 : move16();
472 18 : set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
473 18 : set16_fx( st->syn, 0, 1 + M ); /* Q_syn */
474 18 : set16_fx( st->mem_syn2_fx, 0, M ); /* Q_syn */
475 :
476 : /*OLA -> zero */
477 18 : IF( st->hTcxDec != NULL )
478 : {
479 18 : set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_old_syn_Overl */
480 18 : set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDAC */
481 18 : set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDACFB */
482 18 : set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl */
483 : }
484 18 : IF( st->hTcxCfg != NULL )
485 : {
486 18 : Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* exp(exp_old_out) */
487 :
488 18 : st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ /* Q0 */
489 18 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
490 18 : move16();
491 18 : move16();
492 : }
493 : /*OLA for MDCT-LB always reset in codec switching cases*/
494 18 : IF( st->hHQ_core != NULL )
495 : {
496 18 : set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* hHQ_core->q_old_outLB_fx */
497 : }
498 18 : st->last_core_bfi = TCX_20_CORE;
499 18 : move16();
500 :
501 18 : if ( st->hPFstat != NULL )
502 : {
503 18 : st->hPFstat->on = 0;
504 18 : move16();
505 : }
506 : /* reset CLDFB memories */
507 18 : cldfb_reset_memory( st->cldfbAna );
508 18 : cldfb_reset_memory( st->cldfbBPF );
509 18 : cldfb_reset_memory( st->cldfbSyn );
510 : }
511 13 : ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/
512 : {
513 : /*Interpolation of ACELP memories*/
514 :
515 : /* convert quantized LSP vector */
516 0 : st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
517 0 : move16();
518 0 : IF( st->tcxonly == 0 )
519 : {
520 0 : lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
521 : }
522 : ELSE
523 : {
524 0 : E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
525 : }
526 0 : E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M );
527 :
528 :
529 0 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
530 0 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.5 */
531 :
532 0 : IF( !st->last_con_tcx )
533 : {
534 0 : synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
535 : }
536 :
537 : /*mem of deemphasis stayed unchanged.*/
538 : }
539 13 : ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */
540 : {
541 : /*Partial reset of ACELP memories*/
542 0 : st->rate_switching_reset = 1;
543 0 : move16();
544 :
545 : /*reset partly some memories*/
546 0 : st->tilt_code_fx = TILT_CODE;
547 0 : move16();
548 0 : IF( !st->last_con_tcx )
549 : {
550 0 : set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
551 : }
552 0 : set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */
553 :
554 : /*Resamp others memories*/
555 : /*Size of LPC syn memory*/
556 0 : lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); /* Q_mem_syn_r */
557 0 : Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Q_mem_syn_r */
558 :
559 : /*Untouched memories : st->syn */
560 : }
561 13 : ELSE IF( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) )
562 : {
563 0 : lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
564 : }
565 : }
566 :
567 35 : test();
568 35 : test();
569 35 : IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 )
570 : {
571 0 : st->rate_switching_reset = 1;
572 0 : move16();
573 : }
574 35 : IF( st->hTcxDec != NULL )
575 : {
576 35 : hTcxDec->old_synth_len = shl( st->L_frame, 1 ); /* Q0 */
577 35 : move16();
578 35 : hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 ); /* Q0 */
579 35 : move16();
580 : }
581 : /* bass pf reset */
582 35 : st->bpf_gain_param = 0;
583 35 : move16();
584 35 : IF( st->hBPF != NULL )
585 : {
586 35 : set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX );
587 : }
588 : /* Formant postfilter */
589 35 : IF( st->ini_frame == 0 )
590 : {
591 : /*do nothing*/
592 : }
593 31 : ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) )
594 : {
595 0 : IF( st->tcxonly == 0 )
596 : {
597 0 : IF( st->hPFstat->on != 0 )
598 : {
599 0 : lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
600 0 : lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
601 : }
602 : ELSE
603 : {
604 0 : set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM );
605 0 : set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM );
606 0 : st->hPFstat->reset = 1;
607 0 : move16();
608 0 : st->hPFstat->gain_prec = 16384; /* Q14 */
609 0 : move16();
610 : }
611 : }
612 0 : ELSE IF( st->hPFstat->on != 0 )
613 : {
614 0 : lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
615 0 : lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
616 : }
617 : }
618 : ELSE
619 : {
620 : /*codec switching*/
621 : /*reset post-filter except for Narrowband*/
622 31 : IF( NE_32( st->output_Fs, 8000 ) )
623 : {
624 31 : IF( st->hPFstat != NULL )
625 : {
626 31 : st->hPFstat->reset = 1;
627 31 : move16();
628 31 : IF( st->hPFstat->on != 0 )
629 : {
630 0 : st->hPFstat->reset = 0;
631 0 : move16();
632 0 : Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */
633 0 : Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */
634 0 : lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
635 0 : lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
636 : }
637 : }
638 : }
639 : ELSE
640 : {
641 0 : IF( st->hPFstat != NULL )
642 : {
643 0 : Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */
644 0 : Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */
645 0 : Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */
646 : }
647 : /*feed last value old_synth as it is used for pre-emphasis mem*/
648 0 : if ( st->hTcxDec != NULL )
649 : {
650 0 : hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; /* Q_syn */
651 0 : move16();
652 : }
653 0 : if ( st->hBPF != NULL )
654 : {
655 0 : hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* Q_syn */
656 0 : move16();
657 : }
658 : }
659 : }
660 :
661 : /* lsf and lsp initialization */
662 35 : IF( st->ini_frame == 0 )
663 : {
664 4 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
665 4 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
666 :
667 4 : set16_fx( st->lsf_cng, 0, M );
668 : }
669 :
670 35 : st->seed_tcx_plc = RANDOM_INITSEED;
671 35 : move16();
672 35 : st->past_gpit = 0;
673 35 : move16();
674 35 : st->past_gcode = L_deposit_l( 0 );
675 35 : move32();
676 35 : st->gc_threshold_fx = L_deposit_l( 0 );
677 35 : move32();
678 :
679 35 : E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M );
680 35 : E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M );
681 35 : st->plcBackgroundNoiseUpdated = 0;
682 35 : move16();
683 35 : Copy( st->lsf_old_fx, st->lsf_q_cng, M ); /* Q2.56 */
684 35 : Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */
685 35 : Copy( st->lsp_old_fx, st->lsp_q_cng, M ); /* Q15 */
686 35 : Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */
687 35 : set16_fx( st->mem_syn_unv_back, 0, M );
688 :
689 35 : st->last_gain_syn_deemph = 32768 / 2; /* Q15 */
690 35 : move16();
691 35 : st->last_gain_syn_deemph_e = 1;
692 35 : move16();
693 35 : test();
694 35 : IF( EQ_16( st->last_codec_mode, MODE1 ) || st->ini_frame == 0 )
695 : {
696 : /* this assumes that MODE1 fades out in the frequency domain -
697 : otherwise some data from MODE1 would be needed here */
698 35 : st->last_concealed_gain_syn_deemph = 32768 / 2; /* Q15 */
699 35 : move16();
700 35 : st->last_concealed_gain_syn_deemph_e = 1;
701 35 : move16();
702 35 : if ( hTcxDec != NULL )
703 : {
704 35 : hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/
705 35 : move16();
706 : }
707 : }
708 :
709 : /* Post processing */
710 35 : set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, ( M + 1 ) ) );
711 35 : st->lp_ener_FER_fx = 15360;
712 35 : move16(); /*60 in Q8*/
713 35 : IF( st->ini_frame == 0 )
714 : {
715 4 : st->prev_bfi = 0;
716 4 : move16();
717 4 : st->last_core_bfi = -1;
718 4 : move16();
719 : }
720 35 : st->prev_old_bfi = 0;
721 35 : move16();
722 :
723 : /*st->noise_filling_index = 0;*/ /* not in BASOP */
724 :
725 35 : Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */
726 35 : Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /* Q2.56 */
727 35 : Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /* Q2.56 */
728 :
729 35 : st->clas_dec = UNVOICED_CLAS;
730 35 : move16();
731 35 : if ( !st->last_con_tcx )
732 : {
733 35 : move16();
734 35 : st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
735 : }
736 :
737 35 : IF( st->prev_bfi )
738 : {
739 : /* calculate energy at the end of the previous frame */
740 0 : test();
741 0 : IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) )
742 : {
743 0 : frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 );
744 : }
745 : }
746 : ELSE
747 : {
748 35 : st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */
749 35 : move16();
750 35 : st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ /* Q0 */
751 35 : move32();
752 : }
753 35 : st->Mode2_lp_gainc = L_deposit_l( 0 ); /* 15Q16 */
754 35 : move32();
755 35 : st->Mode2_lp_gainp = L_deposit_l( 0 ); /* 15Q16 */
756 35 : move32();
757 :
758 35 : st->hTcxDec->prev_widow_left_rect = 0;
759 35 : move16();
760 35 : if ( st->hTcxDec != NULL )
761 : {
762 35 : hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/
763 35 : move16();
764 35 : hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; /* Q0 */
765 35 : move16();
766 35 : hTcxDec->conCurrLevelIndex = 0; /* Q0 */
767 35 : move16();
768 35 : hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/
769 35 : move16();
770 35 : set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/
771 35 : set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
772 35 : hTcxDec->conLastFrameLevel_e = 0; /* Q15 */
773 35 : move16();
774 35 : hTcxDec->conCngLevelBackgroundTrace_e = -6;
775 35 : move16();
776 :
777 35 : hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
778 35 : move16();
779 : }
780 35 : st->cummulative_damping = 32767 /*1.0f Q15*/;
781 35 : move16();
782 :
783 455 : FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
784 : {
785 420 : st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min );
786 420 : move16();
787 : }
788 :
789 455 : FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
790 : {
791 420 : st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/
792 420 : move16();
793 : }
794 :
795 :
796 35 : st->old_fpitch = L_deposit_h( st->pit_min );
797 35 : move32();
798 35 : st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX );
799 35 : move32();
800 35 : st->rate_switching_init = 1;
801 35 : move16();
802 :
803 35 : st->reset_mem_AR = 0;
804 35 : move16();
805 :
806 : /* For phase dispersion */
807 35 : st->dm_fx.prev_gain_code = L_deposit_l( 0 );
808 35 : move32();
809 35 : set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
810 35 : st->dm_fx.prev_state = 0;
811 35 : move16();
812 :
813 35 : st->voice_fac = -1; /* purely unvoiced */
814 35 : move16();
815 :
816 : /* TCX-LTP */
817 35 : if ( hTcxLtpDec != NULL )
818 : {
819 35 : hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
820 35 : move16();
821 : }
822 35 : move16();
823 :
824 35 : test();
825 35 : test();
826 35 : test();
827 35 : IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) )
828 : {
829 35 : hTcxLtpDec->tcxltp_pitch_int = st->pit_max; /* Q0 */
830 35 : move16();
831 35 : hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */
832 35 : move16();
833 35 : if ( hTcxDec != NULL )
834 : {
835 35 : hTcxDec->tcxltp_last_gain_unmodified = 0; /* Q15 */
836 35 : move16();
837 : }
838 35 : IF( st->ini_frame == 0 )
839 : {
840 4 : set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* hTcxLtpDec->exp_tcxltp_mem_out */
841 4 : set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); /* hTcxLtpDec->exp_tcxltp_mem_out */
842 4 : hTcxLtpDec->tcxltp_pitch_int_post_prev = 0;
843 4 : move16();
844 4 : hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0;
845 4 : move16();
846 4 : hTcxLtpDec->tcxltp_gain_post_prev = 0;
847 4 : move16();
848 4 : hTcxLtpDec->tcxltp_filt_idx_prev = -1;
849 4 : move16();
850 : }
851 : }
852 :
853 : /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */
854 35 : IF( st->hBPF != NULL )
855 : {
856 :
857 35 : st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */
858 35 : move32();
859 : }
860 : ELSE
861 : {
862 0 : st->lp_error_ener = 0;
863 0 : move16();
864 : }
865 35 : st->mem_error = L_deposit_l( 0 );
866 35 : move32();
867 35 : st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag );
868 35 : move16();
869 35 : st->last_ctx_hm_enabled = 0; /* Q0 */
870 35 : move16();
871 :
872 35 : st->hTcxCfg->resq = getResq( total_brate ); /* Q0 */
873 35 : move16();
874 :
875 35 : st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
876 35 : move16();
877 35 : IF( hTcxDec != NULL )
878 : {
879 35 : hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
880 35 : move16();
881 35 : hTcxDec->envWeighted = 0;
882 35 : move16();
883 : }
884 :
885 35 : st->p_bpf_noise_buf = NULL;
886 35 : if ( st->tcxonly == 0 )
887 : {
888 35 : st->p_bpf_noise_buf = st->bpf_noise_buf; /* q_p_bpf_noise_buf */
889 : }
890 :
891 35 : st->tec_tfa = 0; /* Q0 */
892 35 : move16();
893 35 : test();
894 35 : test();
895 35 : test();
896 35 : IF( EQ_16( bwidth, SWB ) &&
897 : ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
898 : {
899 12 : st->tec_tfa = 1;
900 12 : move16();
901 : }
902 :
903 35 : st->tec_flag = 0;
904 35 : move16();
905 35 : st->tfa_flag = 0;
906 35 : move16();
907 :
908 35 : st->enableGplc = 0;
909 35 : move16();
910 :
911 35 : st->flagGuidedAcelp = 0;
912 35 : move16();
913 35 : st->T0_4th = L_SUBFR;
914 35 : move16();
915 35 : st->guidedT0 = st->T0_4th;
916 35 : move16();
917 :
918 35 : st->enablePlcWaveadjust = 0;
919 35 : move16();
920 35 : test();
921 35 : test();
922 35 : IF( st->hTcxDec != NULL && GE_32( st->total_brate, 48000 ) && st->element_mode == EVS_MONO )
923 : {
924 0 : st->enablePlcWaveadjust = 1;
925 0 : move16();
926 0 : test();
927 0 : test();
928 0 : test();
929 0 : IF( EQ_16( st->ini_frame, 0 ) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset )
930 : {
931 0 : concealment_init_x( hTcxDec->L_frameTCX, st->hPlcInfo );
932 : }
933 : }
934 :
935 : /* PLC: [TCX: Tonal Concealment] */
936 35 : test();
937 35 : test();
938 35 : IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) )
939 : {
940 35 : st->hTonalMDCTConc->nScaleFactors = 0;
941 35 : move16();
942 35 : st->hTonalMDCTConc->nSamples = 0;
943 35 : move16();
944 35 : st->hTonalMDCTConc->lastPcmOut = 0x0;
945 35 : move16();
946 35 : st->hTonalMDCTConc->q_lastPcmOut = Q15;
947 35 : move16();
948 35 : st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
949 35 : move16();
950 35 : st->hTonalMDCTConc->lastBlockData.nSamples = 0;
951 35 : move16();
952 :
953 35 : TonalMDCTConceal_Init( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
954 : }
955 35 : st->last_tns_active = 0;
956 35 : move16();
957 35 : st->second_last_tns_active = 0;
958 35 : move16();
959 35 : st->second_last_core = -1;
960 35 : move16();
961 35 : IF( hTcxDec != NULL )
962 : {
963 35 : hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; /*15Q16*/
964 35 : move16();
965 35 : hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; /*15Q16*/
966 35 : move16();
967 : }
968 35 : move16();
969 35 : st->dec_glr = 0;
970 35 : test();
971 35 : test();
972 35 : test();
973 35 : IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
974 : {
975 12 : test();
976 12 : test();
977 12 : test();
978 12 : IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) ||
979 : ( EQ_32( st->total_brate, 24400 ) ) ) &&
980 : st->element_mode == EVS_MONO )
981 : {
982 12 : move16();
983 12 : st->dec_glr = 1;
984 : }
985 : }
986 35 : move16();
987 35 : st->dec_glr_idx = 0;
988 35 : IF( hTcxDec != NULL )
989 : {
990 35 : hTcxDec->enableTcxLpc = 1;
991 35 : move16();
992 35 : st->VAD = 0;
993 35 : move16();
994 35 : hTcxDec->old_gaintcx_bfi = 0;
995 35 : move16();
996 35 : hTcxDec->old_gaintcx_bfi_e = 0;
997 35 : move16();
998 35 : hTcxDec->tcx_hm_LtpPitchLag = -1;
999 35 : move16();
1000 : }
1001 35 : st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
1002 35 : move16();
1003 35 : if ( hTcxLtpDec != NULL )
1004 : {
1005 35 : hTcxLtpDec->tcxltp_gain = 0; /* Q15 */
1006 35 : move16();
1007 : }
1008 35 : return;
1009 : }
1010 :
1011 30029 : void tcxltp_dec_init_fx(
1012 : TCX_LTP_DEC_HANDLE hTcxLtpDec, /* Q0 */
1013 : const Word16 ini_frame, /* Q0 */
1014 : const Word16 last_codec_mode, /* Q0 */
1015 : const Word16 element_mode, /* Q0 */
1016 : const Word16 pit_max, /* Q0 */
1017 : const Word32 sr_core /* Q0 */
1018 : )
1019 : {
1020 30029 : hTcxLtpDec->tcxltp_gain = 0; /* Q15 */
1021 30029 : move16();
1022 :
1023 30029 : hTcxLtpDec->tcxltp = getTcxLtp( sr_core );
1024 30029 : test();
1025 30029 : test();
1026 30029 : IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && element_mode == EVS_MONO ) )
1027 : {
1028 13943 : hTcxLtpDec->tcxltp_pitch_int = pit_max; /* Q0 */
1029 13943 : move16();
1030 13943 : hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */
1031 13943 : move16();
1032 :
1033 13943 : IF( ini_frame == 0 )
1034 : {
1035 13943 : set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* exp_tcxltp_mem_in */
1036 13943 : set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); /* exp_tcxltp_mem_out */
1037 13943 : set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); /* exp_tcxltp_mem_in */
1038 13943 : set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); /* exp_tcxltp_mem_out */
1039 13943 : hTcxLtpDec->exp_tcxltp_mem_in = 0;
1040 13943 : move16();
1041 13943 : hTcxLtpDec->exp_tcxltp_mem_out = 0;
1042 13943 : move16();
1043 13943 : hTcxLtpDec->tcxltp_pitch_int_post_prev = 0;
1044 13943 : move16();
1045 13943 : hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0;
1046 13943 : move16();
1047 13943 : hTcxLtpDec->tcxltp_gain_post_prev = 0;
1048 13943 : move16();
1049 13943 : hTcxLtpDec->tcxltp_filt_idx_prev = -1;
1050 13943 : move16();
1051 : }
1052 : }
1053 :
1054 30029 : return;
1055 : }
1056 :
1057 156 : void acelp_plc_mdct_transition_fx(
1058 : Decoder_State *st /* i/o: Decoder state */
1059 : )
1060 : {
1061 : PWord16 const *w;
1062 : Word16 W1, W2, nz, delay_comp;
1063 : Word16 i;
1064 :
1065 : /*PLC*/
1066 156 : test();
1067 156 : IF( st->prev_bfi != 0 && st->hTcxCfg != NULL )
1068 : {
1069 156 : W1 = st->hTcxCfg->tcx_mdct_window_lengthFB;
1070 156 : move16();
1071 156 : W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
1072 156 : w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/
1073 :
1074 156 : nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS );
1075 156 : move16();
1076 156 : delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS );
1077 156 : move16(); /*CLDFB delay*/
1078 :
1079 156 : Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* Q_fer_samples */
1080 : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
1081 156 : st->hTcxDec->Q_syn_OverlFB = st->hHQ_core->Q_fer_samples;
1082 156 : move16();
1083 : #endif
1084 156 : lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/
1085 : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
1086 156 : st->hTcxDec->Q_syn_Overl = st->hHQ_core->Q_fer_samples;
1087 156 : move16();
1088 : #endif
1089 : /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
1090 156 : st->hHQ_core->Q_old_wtda = -1;
1091 156 : move16();
1092 156 : set16_fx( st->hHQ_core->old_out_fx, 0, nz ); // Q_old_out is 0
1093 156 : Copy_Scale_sig( st->hHQ_core->fer_samples_fx + delay_comp, st->hHQ_core->old_out_fx + nz, W1, st->hHQ_core->Q_old_wtda ); /*Q-1*/
1094 :
1095 25216 : FOR( i = 0; i < W2; i++ )
1096 : {
1097 25060 : st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */
1098 25060 : move16();
1099 : }
1100 25216 : FOR( ; i < W1; i++ )
1101 : {
1102 25060 : st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */
1103 25060 : move16();
1104 : }
1105 156 : set16_fx( &st->hHQ_core->old_out_fx[W1 + nz], 0, nz );
1106 :
1107 156 : lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX );
1108 156 : Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* exp_old_out */
1109 156 : st->hTcxDec->Q_syn_Overl_TDACFB = st->hHQ_core->Q_old_wtda;
1110 156 : move16();
1111 :
1112 156 : nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS );
1113 156 : Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* exp_old_out */
1114 156 : st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda;
1115 156 : move16();
1116 156 : st->hTcxDec->Q_syn_Overl_TDAC = st->hHQ_core->Q_old_wtda_LB;
1117 156 : move16();
1118 : }
1119 :
1120 156 : return;
1121 : }
1122 :
1123 28535 : void open_decoder_LPD_ivas_fx(
1124 : Decoder_State *st, /* i/o: decoder state structure */
1125 : const Word32 total_brate, /* i : total bitrate Q0*/
1126 : const Word32 last_total_brate, /* i : last total bitrate Q0*/
1127 : const Word16 bwidth, /* i : audio bandwidth Q0*/
1128 : const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
1129 : const Word16 last_element_mode, /* i : last element mode Q0*/
1130 : const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization Q0*/
1131 : Word16 *Q_syn_Overl_TDAC,
1132 : Word16 *Q_fer_samples,
1133 : Word16 *Q_syn_Overl,
1134 : Word16 *Q_syn_Overl_TDACFB,
1135 : Word16 *Q_syn_OverlFB,
1136 : Word16 *Q_old_out,
1137 : Word16 *Q_old_outLB,
1138 : Word16 *Q_old_Aq_12_8 )
1139 : {
1140 : Word16 i;
1141 : Word16 mem_syn_r_size_new;
1142 : Word16 mem_syn_r_size_old;
1143 : Word16 fscaleFB;
1144 : BPF_DEC_HANDLE hBPF;
1145 : TD_BWE_DEC_HANDLE hBWE_TD;
1146 : TCX_LTP_DEC_HANDLE hTcxLtpDec;
1147 : HQ_DEC_HANDLE hHQ_core;
1148 : TCX_DEC_HANDLE hTcxDec;
1149 :
1150 28535 : hBPF = st->hBPF;
1151 28535 : hBWE_TD = st->hBWE_TD;
1152 28535 : hHQ_core = st->hHQ_core;
1153 28535 : hTcxLtpDec = st->hTcxLtpDec;
1154 28535 : hTcxDec = st->hTcxDec;
1155 :
1156 28535 : if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/
1157 : {
1158 0 : st->fscale_old = st->fscale; /* Q0 */
1159 0 : move16();
1160 : }
1161 :
1162 28535 : st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
1163 28535 : move16();
1164 28535 : st->fscale = sr2fscale_fx( st->sr_core );
1165 28535 : move16();
1166 28535 : fscaleFB = sr2fscale_fx( st->output_Fs );
1167 28535 : move16();
1168 :
1169 : /* initializing variables for frame lengths etc. right in the beginning */
1170 28535 : st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); /* 0.02 in Q15 */
1171 28535 : move16();
1172 28535 : if ( st->ini_frame == 0 )
1173 : {
1174 12449 : st->last_L_frame = st->L_frame_past = st->L_frame; /* Q0 */
1175 12449 : move16();
1176 12449 : move16();
1177 : }
1178 28535 : IF( st->hTcxDec != NULL )
1179 : {
1180 28438 : st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); /* 0.02 in Q15 */
1181 28438 : move16();
1182 28438 : st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */
1183 28438 : move16();
1184 28438 : if ( st->ini_frame == 0 )
1185 : {
1186 12352 : st->L_frameTCX_past = st->hTcxDec->L_frameTCX;
1187 12352 : move16();
1188 : }
1189 : }
1190 :
1191 28535 : st->tcxonly = getTcxonly_fx( st->element_mode, total_brate, MCT_flag, st->is_ism_format );
1192 28535 : move16();
1193 :
1194 : /* the TD TCX PLC in MODE1 still runs with 80ms subframes */
1195 28535 : test();
1196 28535 : test();
1197 28535 : test();
1198 28535 : test();
1199 28535 : test();
1200 28535 : test();
1201 28535 : test();
1202 28535 : test();
1203 28535 : IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) ||
1204 : ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) ||
1205 : ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) )
1206 : {
1207 10902 : st->nb_subfr = NB_SUBFR16k;
1208 10902 : move16();
1209 : }
1210 : ELSE
1211 : {
1212 17633 : st->nb_subfr = NB_SUBFR;
1213 17633 : move16();
1214 : }
1215 28535 : st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */
1216 : // assert(FSCALE_DENOM == 512);
1217 : // assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
1218 : // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f));
1219 28535 : move16();
1220 28535 : st->TcxBandwidth = getTcxBandwidth( bwidth );
1221 28535 : move16();
1222 28535 : st->narrowBand = 0;
1223 28535 : move16();
1224 28535 : if ( EQ_16( bwidth, NB ) )
1225 : {
1226 7233 : st->narrowBand = 1;
1227 7233 : move16();
1228 : }
1229 :
1230 28535 : IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
1231 : {
1232 15828 : st->pit_res_max = initPitchLagParameters( INT_FS_12k8, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
1233 15828 : move16();
1234 15828 : IF( hTcxDec != NULL )
1235 : {
1236 15828 : i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); /* Q6 */
1237 15828 : hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
1238 15828 : move16();
1239 15828 : hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
1240 15828 : move16();
1241 : }
1242 : }
1243 : ELSE
1244 : {
1245 12707 : st->pit_res_max = initPitchLagParameters( st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max );
1246 12707 : move16();
1247 12707 : IF( hTcxDec != NULL )
1248 : {
1249 12610 : i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /* Q6 */
1250 12610 : hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */
1251 12610 : move16();
1252 12610 : hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */
1253 12610 : move16();
1254 : }
1255 : }
1256 :
1257 28535 : if ( st->ini_frame == 0 )
1258 : {
1259 12449 : st->pit_res_max_past = st->pit_res_max;
1260 12449 : move16();
1261 : }
1262 :
1263 : /*Preemphasis param*/
1264 28535 : IF( LT_16( st->fscale, 640 ) ) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/
1265 : {
1266 11029 : st->preemph_fac = PREEMPH_FAC; /*WB*/
1267 11029 : move16();
1268 : }
1269 17506 : ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/
1270 : {
1271 5598 : st->preemph_fac = PREEMPH_FAC_16k; /*WB*/
1272 5598 : move16();
1273 : }
1274 : ELSE
1275 : {
1276 11908 : st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/
1277 11908 : move16();
1278 : }
1279 :
1280 28535 : st->inv_gamma = GAMMA1_INV;
1281 28535 : move16();
1282 28535 : test();
1283 28535 : IF( EQ_32( st->sr_core, INT_FS_16k ) )
1284 : {
1285 5598 : st->gamma = GAMMA16k;
1286 5598 : move16();
1287 5598 : st->inv_gamma = GAMMA16k_INV;
1288 5598 : move16();
1289 : }
1290 22937 : ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
1291 : {
1292 10612 : st->gamma = GAMMA16k;
1293 10612 : move16();
1294 10612 : st->inv_gamma = GAMMA16k_INV;
1295 10612 : move16();
1296 : }
1297 : ELSE
1298 : {
1299 12325 : st->gamma = GAMMA1;
1300 12325 : move16();
1301 : }
1302 :
1303 : /* LPC quantization */
1304 28535 : test();
1305 28535 : IF( LE_32( st->sr_core, INT_FS_16k ) && EQ_16( st->tcxonly, 0 ) )
1306 : {
1307 15994 : st->lpcQuantization = 1;
1308 15994 : move16();
1309 : }
1310 : ELSE
1311 : {
1312 12541 : st->lpcQuantization = 0;
1313 12541 : move16();
1314 : }
1315 :
1316 28535 : IF( ( st->tcxonly == 0 ) )
1317 : {
1318 15994 : st->numlpc = 1;
1319 15994 : move16();
1320 : }
1321 : ELSE
1322 : {
1323 12541 : st->numlpc = 2;
1324 12541 : move16();
1325 : }
1326 :
1327 : /* Initialize TBE */
1328 28535 : st->prev_coder_type = GENERIC;
1329 28535 : move16();
1330 28535 : IF( st->hBWE_TD != NULL )
1331 : {
1332 13966 : set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */
1333 13966 : hBWE_TD->prev_tilt_para_fx = 0;
1334 13966 : move16();
1335 13966 : set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */
1336 : }
1337 :
1338 28535 : IF( st->hIGFDec != NULL )
1339 : {
1340 28438 : test();
1341 28438 : IF( !is_init || NE_16( st->element_mode, IVAS_CPE_MDCT ) )
1342 : {
1343 23830 : init_tcx_cfg_fx( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag, fscaleFB );
1344 : }
1345 : ELSE
1346 : {
1347 4608 : st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1348 4608 : move16();
1349 4608 : move16();
1350 4608 : st->hTcxCfg->last_aldo = 1;
1351 4608 : move16();
1352 : }
1353 : }
1354 28535 : IF( st->hTECDec != NULL )
1355 : {
1356 : /*constraint for adaptive bpf, otherwise parameter estimation and post-processing not time aligned*/
1357 0 : resetTecDec_Fx( st->hTECDec );
1358 : }
1359 :
1360 28535 : if ( NE_16( st->element_mode, IVAS_SCE ) )
1361 : {
1362 18889 : st->flag_cna = 0;
1363 18889 : move16();
1364 : }
1365 28535 : IF( st->ini_frame == 0 )
1366 : {
1367 12449 : st->flag_cna = 0;
1368 12449 : move16();
1369 12449 : st->last_flag_cna = 0;
1370 12449 : move16();
1371 : }
1372 :
1373 : /* Static vectors to zero */
1374 28535 : IF( ( st->ini_frame == 0 ) )
1375 : {
1376 12449 : st->last_is_cng = 0;
1377 12449 : move16();
1378 :
1379 12449 : st->rate_switching_reset = 0;
1380 12449 : move16();
1381 :
1382 12449 : IF( st->hTcxDec != NULL )
1383 : {
1384 12352 : reset_tcx_overl_buf_fx( st->hTcxDec );
1385 12352 : set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); /* Qx */
1386 12352 : set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
1387 12352 : hTcxDec->q_old_synth = 0;
1388 12352 : move16();
1389 12352 : set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); /* hTcxDec->q_synth_history_fx */
1390 12352 : hTcxDec->q_synth_history_fx = 0;
1391 12352 : move16();
1392 : }
1393 12449 : set16_fx( st->syn, 0, M + 1 ); /* Q_syn */
1394 12449 : set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */
1395 :
1396 12449 : mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */
1397 12449 : move16();
1398 12449 : mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */
1399 12449 : move16();
1400 :
1401 12449 : st->con_tcx = 0;
1402 12449 : move16();
1403 : }
1404 : ELSE
1405 : {
1406 : /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/
1407 16086 : test();
1408 16086 : test();
1409 16086 : test();
1410 16086 : IF( st->hTcxDec != NULL && ( NE_16( st->L_frame, st->last_L_frame ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) )
1411 : {
1412 5927 : set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* q_old_synth */
1413 5927 : hTcxDec->q_old_synth = 0;
1414 5927 : move16();
1415 : }
1416 :
1417 : /*Compute size of old and new memories*/
1418 : /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */
1419 16086 : mem_syn_r_size_old = shr( st->last_L_frame, 4 );
1420 16086 : mem_syn_r_size_new = shr( st->L_frame, 4 );
1421 :
1422 : /*Reset LPC mem*/
1423 16086 : test();
1424 16086 : test();
1425 16086 : IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) )
1426 : {
1427 6272 : set16_fx( st->mem_MA_fx, 0, M ); /* Qx2.56 */
1428 6272 : IF( EQ_32( st->sr_core, INT_FS_16k ) )
1429 : {
1430 1502 : Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */
1431 : }
1432 : ELSE
1433 : {
1434 4770 : Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */
1435 : }
1436 : }
1437 :
1438 : /*Mode 1/2 switching*/
1439 16086 : test();
1440 16086 : IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO )
1441 : {
1442 0 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
1443 0 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
1444 0 : set16_fx( st->syn, 0, M );
1445 : }
1446 16086 : IF( EQ_16( st->last_core, AMR_WB_CORE ) )
1447 : {
1448 0 : st->last_core = ACELP_CORE;
1449 0 : move16();
1450 0 : st->last_core_bfi = ACELP_CORE;
1451 0 : move16();
1452 : }
1453 :
1454 : /*Codec switching from ACELP-A */
1455 16086 : test();
1456 16086 : test();
1457 16086 : test();
1458 16086 : test();
1459 16086 : IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
1460 : {
1461 : /* Switching from Mode 1 ACELP */
1462 7168 : st->last_core_bfi = ACELP_CORE;
1463 7168 : move16();
1464 7168 : test();
1465 7168 : IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL )
1466 : {
1467 156 : acelp_plc_mdct_transition_fx( st );
1468 156 : *Q_syn_Overl_TDAC = sub( *Q_fer_samples, 1 );
1469 156 : move16();
1470 156 : *Q_syn_Overl = *Q_fer_samples;
1471 156 : move16();
1472 156 : *Q_syn_Overl_TDACFB = sub( *Q_fer_samples, 1 );
1473 156 : move16();
1474 156 : *Q_syn_OverlFB = *Q_fer_samples;
1475 156 : move16();
1476 156 : *Q_old_out = sub( *Q_fer_samples, 1 );
1477 156 : move16();
1478 156 : *Q_old_outLB = sub( *Q_fer_samples, 1 );
1479 156 : move16();
1480 : }
1481 : }
1482 16086 : test();
1483 16086 : test();
1484 16086 : test();
1485 16086 : test();
1486 16086 : test();
1487 16086 : test();
1488 16086 : IF( EQ_16( st->last_codec_mode, MODE2 ) && NE_16( st->L_frame, st->last_L_frame ) &&
1489 : ( ( EQ_16( st->m_frame_type, SID_FRAME ) && ( st->last_core > ACELP_CORE ) ) ||
1490 : ( ( st->last_core > ACELP_CORE ) && ( st->core > ACELP_CORE ) ) || st->prev_bfi ) )
1491 : {
1492 0 : lerp( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->last_L_frame );
1493 : }
1494 :
1495 : /* Rate switching */
1496 16086 : test();
1497 16086 : test();
1498 16086 : test();
1499 16086 : IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) )
1500 : {
1501 : /* Switching from MDCT */
1502 :
1503 : /*Reset of ACELP memories*/
1504 359 : st->rate_switching_reset = 1;
1505 359 : move16();
1506 : // To be removed later
1507 359 : st->tilt_code_fx = TILT_CODE;
1508 359 : move16();
1509 359 : set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
1510 359 : set16_fx( st->syn, 0, 1 + M ); /* Q_syn */
1511 359 : set16_fx( st->mem_syn2_fx, 0, M ); /* Q_syn */
1512 :
1513 : /*OLA -> zero */
1514 359 : IF( st->hTcxDec != NULL )
1515 : {
1516 359 : reset_tcx_overl_buf_fx( st->hTcxDec );
1517 : }
1518 :
1519 359 : IF( st->hTcxCfg != NULL )
1520 : {
1521 359 : Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* Q_old_out */
1522 359 : *Q_syn_OverlFB = *Q_old_out;
1523 359 : move16();
1524 359 : st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
1525 359 : move16();
1526 359 : st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
1527 359 : move16();
1528 : }
1529 :
1530 : /*OLA for Mode 2 TCX always reset in Mode switching cases*/
1531 359 : IF( st->hHQ_core != NULL )
1532 : {
1533 359 : set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* q_old_outLB_fx */
1534 : }
1535 :
1536 359 : st->last_core_bfi = TCX_20_CORE;
1537 359 : move16();
1538 :
1539 359 : IF( st->hPFstat != NULL )
1540 : {
1541 359 : st->hPFstat->on = 0;
1542 359 : move16();
1543 : }
1544 :
1545 : /* reset CLDFB memories */
1546 359 : cldfb_reset_memory_fx( st->cldfbAna );
1547 359 : cldfb_reset_memory_fx( st->cldfbBPF );
1548 359 : cldfb_reset_memory_fx( st->cldfbSyn );
1549 359 : IF( st->cldfbSynHB != NULL )
1550 : {
1551 2 : cldfb_reset_memory_fx( st->cldfbSynHB );
1552 : }
1553 : }
1554 15727 : ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/
1555 : {
1556 : /*Interpolation of ACELP memories*/
1557 :
1558 : /* convert quantized LSP vector */
1559 500 : st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
1560 500 : move16();
1561 500 : IF( EQ_16( st->tcxonly, 0 ) )
1562 : {
1563 500 : lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
1564 : }
1565 : ELSE
1566 : {
1567 0 : E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
1568 : }
1569 500 : E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M );
1570 500 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
1571 500 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
1572 500 : *Q_old_Aq_12_8 = 14;
1573 500 : move16();
1574 500 : IF( !st->last_con_tcx )
1575 : {
1576 498 : 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 );
1577 : }
1578 :
1579 : /*mem of deemphasis stayed unchanged.*/
1580 : }
1581 15227 : ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */
1582 : {
1583 : /*Partial reset of ACELP memories*/
1584 5413 : st->rate_switching_reset = 1;
1585 5413 : move16();
1586 :
1587 : /*reset partly some memories*/
1588 5413 : st->tilt_code_fx = TILT_CODE;
1589 5413 : move16();
1590 5413 : IF( !st->last_con_tcx )
1591 : {
1592 5391 : set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */
1593 : }
1594 5413 : set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */
1595 :
1596 : /*Resamp others memories*/
1597 : /*Size of LPC syn memory*/
1598 5413 : lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
1599 5413 : Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Qx */
1600 : }
1601 : /* update of lsf_old only needed in BASOP */
1602 : /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
1603 : /* { */
1604 : /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */
1605 : /* } */
1606 : }
1607 28535 : test();
1608 28535 : test();
1609 28535 : if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) )
1610 : {
1611 0 : st->rate_switching_reset = 1;
1612 0 : move16();
1613 : }
1614 :
1615 28535 : IF( st->hTcxDec != NULL )
1616 : {
1617 28438 : st->hTcxDec->old_synth_len = shl( st->L_frame, 1 );
1618 28438 : st->hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 );
1619 28438 : move16();
1620 28438 : move16();
1621 : }
1622 :
1623 : /* bass pf reset */
1624 28535 : st->bpf_gain_param = 0;
1625 28535 : move16();
1626 28535 : IF( st->hBPF != NULL )
1627 : {
1628 12610 : set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* q_pst_old_syn */
1629 : }
1630 :
1631 : /* Formant postfilter */
1632 28535 : IF( ( st->ini_frame == 0 ) )
1633 : {
1634 : /* do nothing */
1635 : }
1636 16086 : ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) )
1637 : {
1638 0 : IF( !st->tcxonly )
1639 : {
1640 0 : IF( st->hPFstat->on )
1641 : {
1642 0 : lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
1643 0 : lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
1644 : }
1645 : ELSE
1646 : {
1647 0 : set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM ); /* Qx */
1648 0 : set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); /* Qx */
1649 0 : st->hPFstat->reset = 1;
1650 0 : st->hPFstat->gain_prec = 16384; /* Q14 */
1651 0 : move16();
1652 0 : move16();
1653 : }
1654 : }
1655 0 : ELSE IF( st->hPFstat->on )
1656 : {
1657 0 : lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
1658 0 : lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
1659 : }
1660 : }
1661 : ELSE
1662 : {
1663 : /*codec mode switching*/
1664 :
1665 : /*reset post-filter except for Narrowband*/
1666 16086 : IF( NE_32( st->output_Fs, i_mult( L_FRAME8k, FRAMES_PER_SEC ) ) )
1667 : {
1668 16086 : IF( st->hPFstat != NULL )
1669 : {
1670 9498 : st->hPFstat->reset = 1;
1671 9498 : move16();
1672 9498 : IF( st->hPFstat->on != 0 )
1673 : {
1674 5684 : st->hPFstat->reset = 0;
1675 5684 : move16();
1676 : //-------------Present in EVS
1677 : // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */
1678 : // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */
1679 : //--------------
1680 5684 : 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 );
1681 5684 : 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 );
1682 : }
1683 : }
1684 : }
1685 : ELSE
1686 : {
1687 : //----------------Present in EVS
1688 : // IF(st->hPFstat != NULL)
1689 : //{
1690 : // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */
1691 : // Scale_sig(st->hPFstat->mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */
1692 : // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn)); /* NB post_filter mem */
1693 : //}
1694 : //------------------
1695 : /*feed last value old_synth as it is used for pre-emphasis mem*/
1696 0 : if ( st->hTcxDec != NULL )
1697 : {
1698 0 : st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; /* q_old_synth */
1699 0 : move16();
1700 : }
1701 0 : if ( st->hBPF != NULL )
1702 : {
1703 0 : st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* q_pst_old_syn */
1704 0 : move16();
1705 : }
1706 : }
1707 : }
1708 :
1709 : /* lsf and lsp initialization */
1710 28535 : IF( ( st->ini_frame == 0 ) )
1711 : {
1712 12449 : Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
1713 12449 : Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
1714 12449 : set16_fx( st->lsf_cng, 0, M );
1715 : }
1716 :
1717 28535 : st->seed_tcx_plc = RANDOM_INITSEED;
1718 28535 : move16();
1719 28535 : st->past_gpit = 0;
1720 28535 : move16();
1721 28535 : st->past_gcode = L_deposit_l( 0 ); /*15Q16*/
1722 28535 : move32();
1723 28535 : st->gc_threshold_fx = L_deposit_l( 0 ); /* Q16 */
1724 28535 : move32();
1725 :
1726 28535 : E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M );
1727 28535 : E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M );
1728 28535 : st->plcBackgroundNoiseUpdated = 0;
1729 28535 : move16();
1730 28535 : Copy( st->lsf_old_fx, st->lsf_q_cng, M ); /* Q2.56 */
1731 28535 : Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */
1732 28535 : Copy( st->lsp_old_fx, st->lsp_q_cng, M ); /* Q15 */
1733 28535 : Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */
1734 28535 : set16_fx( st->mem_syn_unv_back, 0, M );
1735 28535 : st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/
1736 28535 : move16();
1737 :
1738 28535 : test();
1739 28535 : IF( EQ_16( st->last_codec_mode, MODE1 ) || ( st->ini_frame == 0 ) )
1740 : {
1741 : /* this assumes that MODE1 fades out in the frequency domain -
1742 : otherwise some data from MODE1 would be needed here */
1743 28535 : st->last_concealed_gain_syn_deemph = 32768 / 2;
1744 28535 : move16();
1745 28535 : st->last_concealed_gain_syn_deemph_e = 1;
1746 28535 : move16();
1747 28535 : if ( hTcxDec != NULL )
1748 : {
1749 28438 : hTcxDec->conceal_eof_gain32 = ONE_IN_Q30; /*Q30*/
1750 28438 : hTcxDec->conceal_eof_gain_e = 1;
1751 28438 : move16();
1752 28438 : move32();
1753 28438 : move16();
1754 : }
1755 : }
1756 : /* Post processing */
1757 28535 : set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, ( M + 1 ) ) );
1758 :
1759 28535 : st->lp_ener_FER_fx = 15360; /*60.0f Q8*/
1760 28535 : move16();
1761 28535 : IF( EQ_16( st->ini_frame, 0 ) )
1762 : {
1763 12449 : st->prev_bfi = 0;
1764 12449 : move16();
1765 12449 : st->last_core_bfi = -1;
1766 12449 : move16();
1767 12449 : if ( st->hTcxDec != NULL )
1768 : {
1769 12352 : hTcxDec->tcxConceal_recalc_exc = 0;
1770 12352 : move16();
1771 : }
1772 : }
1773 28535 : st->prev_old_bfi = 0;
1774 28535 : move16();
1775 :
1776 28535 : IF( st->hTcxDec != NULL )
1777 : {
1778 28438 : st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0;
1779 28438 : move16();
1780 28438 : move16();
1781 28438 : st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0;
1782 28438 : move16();
1783 28438 : move16();
1784 28438 : set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); /* Q15 */
1785 : }
1786 :
1787 28535 : Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */
1788 28535 : Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /* Q2.56 */
1789 28535 : Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /* Q2.56 */
1790 :
1791 28535 : st->clas_dec = UNVOICED_CLAS;
1792 28535 : move16();
1793 :
1794 28535 : if ( !st->last_con_tcx )
1795 : {
1796 28500 : st->old_enr_LP = 0;
1797 28500 : move16(); /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */
1798 : }
1799 :
1800 28535 : IF( st->prev_bfi )
1801 : {
1802 : /* calculate energy at the end of the previous frame */
1803 331 : test();
1804 331 : IF( st->core == ACELP_CORE && EQ_16( st->last_core, HQ_CORE ) )
1805 : {
1806 0 : st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */
1807 0 : move16();
1808 0 : frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 );
1809 : }
1810 : }
1811 : ELSE
1812 : {
1813 28204 : st->last_good = UNVOICED_CLAS;
1814 28204 : move16(); /* last good received frame for concealment */
1815 28204 : st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */
1816 28204 : move32();
1817 : }
1818 28535 : st->Mode2_lp_gainc = L_deposit_l( 0 );
1819 28535 : move32();
1820 28535 : st->Mode2_lp_gainp = L_deposit_l( 0 );
1821 28535 : move32();
1822 28535 : st->lp_gainc_fx = 0; /* Q3 */
1823 28535 : move16();
1824 28535 : st->lp_gainp_fx = 0; /* Q14 */
1825 28535 : move16();
1826 :
1827 28535 : IF( st->hTcxDec != NULL )
1828 : {
1829 28438 : st->hTcxDec->prev_widow_left_rect = 0;
1830 28438 : move16();
1831 28438 : test();
1832 28438 : test();
1833 28438 : test();
1834 28438 : IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) )
1835 : {
1836 25608 : st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1;
1837 25608 : move16();
1838 25608 : st->hTcxDec->CurrLevelIndex_bfi = 0;
1839 25608 : move16();
1840 25608 : st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV;
1841 25608 : move16();
1842 25608 : set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE );
1843 25608 : set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
1844 25608 : st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
1845 25608 : move16();
1846 :
1847 25608 : hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/
1848 25608 : move16();
1849 25608 : hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1;
1850 25608 : move16();
1851 25608 : hTcxDec->conCurrLevelIndex = 0;
1852 25608 : move16();
1853 25608 : hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/
1854 25608 : move16();
1855 25608 : set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/
1856 25608 : set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
1857 25608 : hTcxDec->conLastFrameLevel_e = 0;
1858 25608 : move16();
1859 25608 : hTcxDec->conCngLevelBackgroundTrace_e = -6;
1860 25608 : move16();
1861 :
1862 25608 : hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
1863 25608 : move16();
1864 : }
1865 : }
1866 28535 : st->cummulative_damping = 32767 /*1.0f Q15*/;
1867 28535 : move16();
1868 :
1869 370955 : FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
1870 : {
1871 342420 : st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); /* 15Q16 */
1872 342420 : move32();
1873 : }
1874 :
1875 370955 : FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ )
1876 : {
1877 342420 : st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/
1878 342420 : move16();
1879 : }
1880 28535 : st->old_fpitch = L_deposit_h( st->pit_min );
1881 28535 : move32();
1882 28535 : st->rate_switching_init = 1;
1883 28535 : move16();
1884 :
1885 28535 : st->reset_mem_AR = 0;
1886 28535 : move16();
1887 :
1888 : /* For phase dispersion */
1889 28535 : st->dm_fx.prev_gain_code = L_deposit_l( 0 );
1890 28535 : move32();
1891 28535 : set16_fx( st->dm_fx.prev_gain_pit, 0, 6 );
1892 28535 : st->dm_fx.prev_state = 0;
1893 28535 : move16();
1894 28535 : st->voice_fac = -1;
1895 28535 : move16();
1896 :
1897 : /* TCX-LTP */
1898 28535 : IF( hTcxLtpDec != NULL )
1899 : {
1900 28438 : tcxltp_dec_init_fx( hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core );
1901 : }
1902 :
1903 : /* TCX */
1904 28535 : IF( hTcxDec != NULL )
1905 : {
1906 28438 : st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX );
1907 28438 : move32();
1908 28438 : test();
1909 28438 : test();
1910 28438 : IF( ( st->ini_frame == 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) )
1911 : {
1912 12352 : hTcxDec->tcxltp_last_gain_unmodified = 0;
1913 12352 : move16();
1914 : }
1915 :
1916 : /* TCX */
1917 28438 : hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
1918 28438 : move16();
1919 28438 : hTcxDec->envWeighted = 0;
1920 28438 : move16();
1921 : }
1922 :
1923 28535 : IF( st->hBPF != NULL )
1924 : {
1925 12610 : st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */
1926 12610 : move32();
1927 12610 : hBPF->pst_mem_deemp_err_fx = 0; /* Q_syn2 - 1 */
1928 12610 : move16();
1929 : }
1930 : ELSE
1931 : {
1932 15925 : st->lp_error_ener = 0;
1933 15925 : move32();
1934 : }
1935 28535 : st->mem_error = L_deposit_l( 0 );
1936 28535 : move32();
1937 28535 : IF( st->tcxonly )
1938 : {
1939 12541 : st->p_bpf_noise_buf = NULL;
1940 12541 : st->p_bpf_noise_buf_32 = NULL;
1941 : }
1942 : ELSE
1943 : {
1944 15994 : st->p_bpf_noise_buf = st->bpf_noise_buf;
1945 15994 : move32();
1946 15994 : st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32;
1947 15994 : move32();
1948 : }
1949 28535 : test();
1950 28535 : test();
1951 28535 : test();
1952 28535 : IF( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
1953 : {
1954 0 : st->tec_tfa = 1;
1955 0 : move16();
1956 : }
1957 : ELSE
1958 : {
1959 28535 : st->tec_tfa = 0;
1960 28535 : move16();
1961 : }
1962 :
1963 28535 : st->tec_flag = 0;
1964 28535 : move16();
1965 28535 : st->tfa_flag = 0;
1966 28535 : move16();
1967 :
1968 : /* needed in decoder to read the bitstream */
1969 28535 : st->enableGplc = 0;
1970 28535 : move16();
1971 :
1972 28535 : st->flagGuidedAcelp = 0;
1973 28535 : move16();
1974 28535 : st->tonal_mdct_plc_active = 0;
1975 28535 : move16();
1976 28535 : st->T0_4th = L_SUBFR;
1977 28535 : move16();
1978 28535 : st->guidedT0 = st->T0_4th;
1979 28535 : move16();
1980 28535 : test();
1981 28535 : test();
1982 28535 : IF( st->hPlcInfo != NULL && GE_32( total_brate, HQ_48k ) && st->element_mode == EVS_MONO )
1983 : {
1984 0 : st->enablePlcWaveadjust = 1;
1985 0 : move16();
1986 :
1987 0 : IF( st->hTcxDec != NULL && ( st->ini_frame == 0 || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) )
1988 : {
1989 0 : concealment_init_ivas_fx( st->hTcxDec->L_frameTCX, st->hPlcInfo );
1990 : }
1991 : }
1992 : ELSE
1993 : {
1994 28535 : st->enablePlcWaveadjust = 0;
1995 28535 : move16();
1996 : }
1997 :
1998 : /* PLC: [TCX: Tonal Concealment] */
1999 28535 : test();
2000 28535 : test();
2001 28535 : test();
2002 28535 : IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && ( st->ini_frame != 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) )
2003 : {
2004 13011 : st->hTonalMDCTConc->nScaleFactors = 0;
2005 13011 : move16();
2006 13011 : st->hTonalMDCTConc->nSamples = 0;
2007 13011 : move16();
2008 13011 : st->hTonalMDCTConc->lastPcmOut = 0x0;
2009 13011 : move16();
2010 13011 : st->hTonalMDCTConc->q_lastPcmOut = Q15;
2011 13011 : move16();
2012 13011 : st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0;
2013 13011 : move16();
2014 13011 : st->hTonalMDCTConc->lastBlockData.nSamples = 0;
2015 13011 : move16();
2016 13011 : TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
2017 : }
2018 :
2019 28535 : st->last_tns_active = 0;
2020 28535 : move16();
2021 28535 : st->second_last_tns_active = 0;
2022 28535 : move16();
2023 28535 : st->second_last_core = -1;
2024 28535 : move16();
2025 :
2026 28535 : IF( st->hTcxCfg != NULL && st->element_mode != EVS_MONO )
2027 : {
2028 : Word32 gettns_temp;
2029 28438 : IF( is_init )
2030 : {
2031 7136 : gettns_temp = total_brate;
2032 7136 : move32();
2033 : }
2034 : ELSE
2035 : {
2036 21302 : gettns_temp = L_mult( st->bits_frame_nominal, ( FRAMES_PER_SEC >> 1 ) ); /* Q0 */
2037 : }
2038 28438 : st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( gettns_temp, st->igf, st->element_mode );
2039 28438 : move16();
2040 : }
2041 28535 : IF( hTcxDec != NULL )
2042 : {
2043 28438 : hTcxDec->tcxltp_second_last_pitch = st->old_fpitch;
2044 28438 : move16();
2045 28438 : hTcxDec->tcxltp_third_last_pitch = st->old_fpitch;
2046 28438 : move16();
2047 : }
2048 28535 : test();
2049 28535 : test();
2050 28535 : test();
2051 28535 : IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
2052 : {
2053 0 : st->dec_glr = 1;
2054 0 : move16();
2055 : }
2056 : ELSE
2057 : {
2058 28535 : st->dec_glr = 0;
2059 28535 : move16();
2060 : }
2061 :
2062 28535 : st->dec_glr_idx = 0;
2063 28535 : move16();
2064 :
2065 28535 : st->VAD = 0;
2066 28535 : move16();
2067 28535 : IF( hTcxDec != NULL )
2068 : {
2069 28438 : hTcxDec->enableTcxLpc = 1;
2070 28438 : move16();
2071 28438 : hTcxDec->old_gaintcx_bfi = 0;
2072 28438 : move16();
2073 28438 : hTcxDec->old_gaintcx_bfi_e = 0;
2074 28438 : move16();
2075 :
2076 28438 : hTcxDec->tcx_hm_LtpPitchLag = -1;
2077 28438 : move16();
2078 : }
2079 :
2080 28535 : IF( st->hTcxCfg != NULL )
2081 : {
2082 28438 : st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
2083 28438 : move16();
2084 : }
2085 :
2086 28535 : return;
2087 : }
2088 :
2089 : /*-----------------------------------------------------------------------*
2090 : * reset_tcx_overl_buf()
2091 : *
2092 : * Reset TCX core overlap buffers
2093 : *-----------------------------------------------------------------------*/
2094 :
2095 13394 : void reset_tcx_overl_buf_fx(
2096 : TCX_DEC_HANDLE hTcxDec /* i/o: TCX decoder handle */
2097 : )
2098 : {
2099 13394 : set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
2100 13394 : hTcxDec->Q_old_syn_Overl = 0;
2101 13394 : move16();
2102 13394 : set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
2103 13394 : hTcxDec->Q_syn_Overl_TDAC = 0;
2104 13394 : move16();
2105 13394 : set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
2106 13394 : hTcxDec->Q_syn_Overl = 0;
2107 13394 : move16();
2108 : #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT
2109 13394 : set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME48k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
2110 13394 : hTcxDec->Q_syn_OverlFB = 0;
2111 13394 : move16();
2112 : #endif
2113 13394 : set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/
2114 13394 : hTcxDec->Q_syn_Overl_TDACFB = 0;
2115 13394 : move16();
2116 13394 : return;
2117 : }
|