Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include "cnst.h"
43 : #include "ivas_cnst.h"
44 : #include "rom_com.h"
45 : #include "prot.h"
46 : #include "wmc_auto.h"
47 :
48 : /*----------------------------------------------------------------------*
49 : * init_decoder()
50 : *
51 : * Initialization of static variables for the decoder
52 : *----------------------------------------------------------------------*/
53 :
54 26496 : ivas_error init_decoder(
55 : Decoder_State *st, /* o : Decoder static variables structure */
56 : const int16_t idchan, /* i : channel ID */
57 : const MC_MODE mc_mode /* i : MC mode */
58 : )
59 : {
60 : int16_t i;
61 : ivas_error error;
62 :
63 26496 : error = IVAS_ERR_OK;
64 :
65 : /*-----------------------------------------------------------------*
66 : * General parameters
67 : *-----------------------------------------------------------------*/
68 :
69 26496 : st->codec_mode = MODE1;
70 26496 : st->last_codec_mode = MODE1;
71 26496 : st->core = ACELP_CORE;
72 26496 : st->L_frame = L_FRAME;
73 26496 : st->extl = -1;
74 26496 : st->extl_orig = -1;
75 26496 : st->extl_brate_orig = 0;
76 26496 : st->last_bits_frame_nominal = -1;
77 26496 : st->total_brate = ACELP_8k00;
78 26496 : st->last_total_brate = -1;
79 26496 : st->last_total_brate_ber = -1;
80 26496 : st->core_brate = ACELP_8k00;
81 26496 : st->ini_frame = 0;
82 26496 : st->bwidth = NB;
83 26496 : st->last_bwidth = NB;
84 26496 : st->extl_brate = 0;
85 :
86 26496 : st->coder_type = GENERIC;
87 26496 : st->last_coder_type = GENERIC;
88 26496 : st->inactive_coder_type_flag = 0;
89 26496 : st->last_L_frame = st->L_frame;
90 26496 : st->last_core_brate = st->core_brate;
91 26496 : st->last_core = -1;
92 26496 : st->last_extl = st->extl;
93 :
94 26496 : st->flag_ACELP16k = set_ACELP_flag( st->element_mode, st->total_brate, st->total_brate, idchan, 0, -1, -1 );
95 :
96 : /*-----------------------------------------------------------------*
97 : * ACELP core parameters
98 : *-----------------------------------------------------------------*/
99 :
100 : /* LSF initilalizations */
101 26496 : mvr2r( GEWB_Ave, st->mem_AR, M );
102 :
103 26496 : set_f( st->mem_MA, 0, M );
104 26496 : set_f( st->dispMem, 0, 8 );
105 :
106 26496 : st->tilt_code = 0.0f;
107 26496 : st->gc_threshold = 0.0f;
108 26496 : st->last_good = UNVOICED_CLAS;
109 26496 : st->clas_dec = UNVOICED_CLAS;
110 26496 : st->low_rate_mode = 0;
111 26496 : st->last_low_rate_mode = 0;
112 :
113 26496 : st->lp_gainp = 0.0f;
114 26496 : st->lp_gainc = 0.0f;
115 :
116 26496 : set_f( st->old_exc, 0, L_EXC_MEM_DEC );
117 :
118 : /* AVQ pre-quantizer memory */
119 26496 : st->mem_preemp_preQ = 0.0f;
120 26496 : st->last_nq_preQ = 0;
121 26496 : st->last_code_preq = 0;
122 26496 : st->use_acelp_preq = 0;
123 :
124 26496 : st->mem_deemph = 0.0f;
125 :
126 26496 : set_f( st->mem_syn1, 0, M );
127 26496 : set_f( st->mem_syn2, 0, M );
128 26496 : st->stab_fac = 0.0f;
129 26496 : st->stab_fac_smooth = 0.0f;
130 26496 : set_f( st->agc_mem2, 0, 2 );
131 26496 : set_f( st->mem_syn3, 0, M );
132 26496 : st->stab_fac_smooth_lt = 0.0f;
133 26496 : st->log_energy_diff_lt = 0.0f;
134 26496 : st->log_energy_old = 0.0f;
135 :
136 26496 : mvr2r( GEWB_Ave, st->lsf_old, M );
137 26496 : lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 );
138 :
139 26496 : st->mid_lsf_int = 0;
140 26496 : st->safety_net = 0;
141 :
142 : /* FEC */
143 26496 : st->scaling_flag = 0;
144 26496 : st->lp_ener_FEC_av = 5.0e5f;
145 26496 : st->lp_ener_FEC_max = 5.0e5f;
146 26496 : st->prev_bfi = 0;
147 26496 : st->lp_ener_bfi = 60.0f;
148 26496 : st->old_enr_LP = 0.0f;
149 26496 : st->lp_ener = 0.0f;
150 26496 : st->enr_old = 0.0f;
151 26496 : st->bfi_pitch = (float) L_SUBFR;
152 26496 : st->bfi_pitch_frame = L_FRAME;
153 26496 : set_f( st->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM );
154 26496 : st->last_con_tcx = 0;
155 :
156 291456 : for ( i = 0; i < 2 * NB_SUBFR16k; i++ )
157 : {
158 264960 : st->old_pitch_buf[i] = (float) L_SUBFR;
159 : }
160 :
161 26496 : st->upd_cnt = MAX_UPD_CNT;
162 :
163 26496 : mvr2r( GEWB_Ave, st->lsfoldbfi0, M );
164 26496 : mvr2r( GEWB_Ave, st->lsfoldbfi1, M );
165 26496 : mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M );
166 :
167 26496 : st->seed_acelp = RANDOM_INITSEED;
168 26496 : st->seed = RANDOM_INITSEED;
169 26496 : st->nbLostCmpt = 0;
170 26496 : st->decision_hyst = 0;
171 :
172 : /* Stationary noise UV modification */
173 26496 : st->unv_cnt = 0;
174 26496 : st->ge_sm = 10;
175 26496 : st->uv_count = 0;
176 26496 : st->act_count = 3;
177 26496 : mvr2r( st->lsp_old, st->lspold_s, M );
178 26496 : st->noimix_seed = RANDOM_INITSEED;
179 26496 : st->min_alpha = 1;
180 26496 : st->exc_pe = 0;
181 :
182 26496 : st->prev_coder_type = GENERIC;
183 26496 : st->tilt_wb = 0.0f;
184 :
185 26496 : st->last_voice_factor = 0.0f;
186 26496 : set_f( st->prev_synth_buffer, 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) );
187 :
188 26496 : st->old_bfi_cnt = 0;
189 :
190 : /*-----------------------------------------------------------------*
191 : * parameters for AC mode (GSC)
192 : *-----------------------------------------------------------------*/
193 :
194 26496 : st->GSC_noisy_speech = 0;
195 26496 : st->GSC_IVAS_mode = 0;
196 26496 : st->Last_GSC_noisy_speech_flag = 0;
197 :
198 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
199 : {
200 9249 : if ( ( st->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL )
201 : {
202 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) );
203 : }
204 :
205 9249 : GSC_dec_init( st->hGSCDec );
206 : }
207 : else
208 : {
209 17247 : st->hGSCDec = NULL;
210 : }
211 :
212 : /*-----------------------------------------------------------------*
213 : * parameters for fast recovery (WI)
214 : *-----------------------------------------------------------------*/
215 :
216 26496 : if ( st->output_Fs == 16000 && st->element_mode == EVS_MONO )
217 : {
218 0 : if ( ( st->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL )
219 : {
220 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) );
221 : }
222 :
223 0 : set_f( st->hWIDec->old_exc2, 0, L_EXC_MEM );
224 0 : set_f( st->hWIDec->old_syn2, 0, L_EXC_MEM );
225 : }
226 : else
227 : {
228 26496 : st->hWIDec = NULL;
229 : }
230 :
231 : /*-----------------------------------------------------------------*
232 : * NB/formant post-filter
233 : *-----------------------------------------------------------------*/
234 :
235 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
236 : {
237 9249 : if ( ( st->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL )
238 : {
239 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) );
240 : }
241 :
242 9249 : Init_post_filter( st->hPFstat );
243 9249 : st->psf_lp_noise = 0.0f;
244 : }
245 : else
246 : {
247 17247 : st->hPFstat = NULL;
248 : }
249 :
250 : /*-----------------------------------------------------------------*
251 : * HF (6-7kHz) (zero) BWE parameters
252 : *-----------------------------------------------------------------*/
253 :
254 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
255 : {
256 9249 : if ( ( st->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL )
257 : {
258 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) );
259 : }
260 :
261 9249 : hf_synth_init( st->hBWE_zero );
262 : }
263 : else
264 : {
265 17247 : st->hBWE_zero = NULL;
266 : }
267 :
268 :
269 : /*-----------------------------------------------------------------*
270 : * LD music post-filter
271 : *-----------------------------------------------------------------*/
272 :
273 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
274 : {
275 9249 : if ( ( st->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL )
276 : {
277 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) );
278 : }
279 :
280 9249 : music_postfilt_init( st->hMusicPF );
281 : }
282 : else
283 : {
284 17247 : st->hMusicPF = NULL;
285 : }
286 :
287 : /*-----------------------------------------------------------------*
288 : * CNG and DTX
289 : *-----------------------------------------------------------------*/
290 :
291 26496 : st->first_CNG = 0;
292 26496 : st->cng_type = -1;
293 26496 : st->last_vad = 0;
294 26496 : st->last_active_brate = ACELP_7k20;
295 26496 : st->last_CNG_L_frame = L_FRAME;
296 :
297 26496 : st->active_cnt = 20;
298 :
299 26496 : if ( idchan == 0 && ( st->element_mode == EVS_MONO || st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) )
300 : {
301 306 : if ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL )
302 : {
303 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) );
304 : }
305 :
306 306 : td_cng_dec_init( st );
307 : }
308 : else
309 : {
310 26190 : st->hTdCngDec = NULL;
311 : }
312 :
313 26496 : st->masa_sid_format = 0;
314 :
315 : /*-----------------------------------------------------------------*
316 : * HQ core parameters
317 : *-----------------------------------------------------------------*/
318 :
319 26496 : st->prev_old_bfi = 0;
320 26496 : set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
321 26496 : set_f( st->previoussynth, 0, L_FRAME48k );
322 :
323 26496 : if ( st->element_mode == EVS_MONO )
324 : {
325 9 : set_f( st->old_synth_sw, 0.0f, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) );
326 : }
327 :
328 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE || st->element_mode == EVS_MONO ) )
329 : {
330 26199 : if ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL )
331 : {
332 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) );
333 : }
334 :
335 : /* HQ core initialization */
336 26199 : HQ_core_dec_init( st->hHQ_core );
337 :
338 26199 : if ( st->element_mode == EVS_MONO )
339 : {
340 : /* HQ NB FEC initialization */
341 9 : if ( ( st->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL )
342 : {
343 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) );
344 : }
345 9 : HQ_nbfec_init( st->hHQ_nbfec );
346 : }
347 : else
348 : {
349 26190 : st->hHQ_nbfec = NULL;
350 : }
351 : }
352 : else
353 : {
354 297 : st->hHQ_core = NULL;
355 297 : st->hHQ_nbfec = NULL;
356 : }
357 :
358 : /*-----------------------------------------------------------------*
359 : * TBE parameters
360 : *-----------------------------------------------------------------*/
361 :
362 26496 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
363 : {
364 9249 : if ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL )
365 : {
366 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) );
367 : }
368 :
369 9249 : td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs );
370 : }
371 : else
372 : {
373 17247 : st->hBWE_TD = NULL;
374 : }
375 :
376 26496 : st->old_bwe_delay = -1;
377 26496 : set_f( st->hb_prev_synth_buffer, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
378 :
379 : /*-----------------------------------------------------------------*
380 : * SWB BWE parameters
381 : *-----------------------------------------------------------------*/
382 :
383 26496 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
384 : {
385 9249 : if ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL )
386 : {
387 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) );
388 : }
389 :
390 9249 : fd_bwe_dec_init( st->hBWE_FD );
391 : }
392 : else
393 : {
394 17247 : st->hBWE_FD = NULL;
395 : }
396 :
397 : /*-----------------------------------------------------------------*
398 : * WB/SWB bandwidth switching parameters
399 : *-----------------------------------------------------------------*/
400 :
401 26496 : st->tilt_swb = 0.0f;
402 26496 : st->prev_ener_shb = 0.0f;
403 26496 : st->prev_enerLH = 0.0f;
404 26496 : st->enerLH = 0.0f;
405 26496 : st->enerLL = 0.0f;
406 26496 : st->prev_enerLL = 0.0f;
407 26496 : st->prev_fractive = 0;
408 26496 : st->prev_bws_cnt = 0;
409 26496 : st->bws_cnt = N_WS2N_FRAMES;
410 26496 : st->bws_cnt1 = N_NS2W_FRAMES;
411 26496 : st->attenu1 = 0.1f;
412 26496 : st->last_inner_frame = L_FRAME8k;
413 :
414 : /*-----------------------------------------------------------------*
415 : * HR SWB BWE parameters
416 : *-----------------------------------------------------------------*/
417 :
418 26496 : if ( st->element_mode == EVS_MONO )
419 : {
420 9 : if ( ( st->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL )
421 : {
422 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) );
423 : }
424 :
425 9 : hr_bwe_dec_init( st->hBWE_FD_HR );
426 : }
427 : else
428 : {
429 26487 : st->hBWE_FD_HR = NULL;
430 : }
431 :
432 : /*----------------------------------------------------------------------------------*
433 : * AMR-WB IO mode parameters
434 : *----------------------------------------------------------------------------------*/
435 :
436 26496 : if ( st->Opt_AMR_WB || st->element_mode == EVS_MONO )
437 : {
438 9 : if ( ( st->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL )
439 : {
440 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) );
441 : }
442 :
443 : /* AMR-WB IO init */
444 9 : amr_wb_dec_init( st->hAmrwb_IO );
445 :
446 : /* AMR-WB IO HF synth init */
447 9 : hf_synth_amr_wb_init( st->hAmrwb_IO );
448 : }
449 : else
450 : {
451 26487 : st->hAmrwb_IO = NULL;
452 : }
453 :
454 : /*-----------------------------------------------------------------*
455 : * channel-aware mode parameters
456 : *-----------------------------------------------------------------*/
457 :
458 26496 : set_f( st->tilt_code_dec, 0.0f, NB_SUBFR16k );
459 :
460 26496 : st->use_partial_copy = 0;
461 26496 : st->prev_use_partial_copy = 0;
462 26496 : st->rf_flag = 0;
463 26496 : st->rf_flag_last = 0;
464 26496 : st->prev_rf_frame_type = 0;
465 26496 : st->next_coder_type = 0;
466 :
467 26496 : st->rf_target_bits = 0;
468 :
469 26496 : st->rf_indx_nelp_fid = 0;
470 26496 : st->rf_indx_nelp_iG1 = 0;
471 26496 : st->rf_indx_nelp_iG2[0] = 0;
472 26496 : st->rf_indx_nelp_iG2[1] = 0;
473 26496 : st->rf_indx_tbeGainFr = 0;
474 :
475 : /*-----------------------------------------------------------------*
476 : * Bass post-filter parameters
477 : *-----------------------------------------------------------------*/
478 :
479 26496 : st->bpf_off = 0;
480 :
481 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
482 : {
483 9249 : if ( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL )
484 : {
485 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) );
486 : }
487 :
488 9249 : bass_psfilter_init( st->hBPF );
489 : }
490 : else
491 : {
492 17247 : st->hBPF = NULL;
493 : }
494 :
495 : /*-----------------------------------------------------------------*
496 : * FD BPF & resampling tools parameters
497 : *-----------------------------------------------------------------*/
498 :
499 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
500 : {
501 : /* open analysis for max. sampling rate 48kHz */
502 9249 : if ( ( error = openCldfb( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
503 : {
504 0 : return error;
505 : }
506 :
507 : /* open analysis BPF for max. internal sampling rate 16kHz */
508 9249 : if ( ( error = openCldfb( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
509 : {
510 0 : return error;
511 : }
512 : }
513 : else
514 : {
515 17247 : st->cldfbAna = NULL;
516 17247 : st->cldfbBPF = NULL;
517 : }
518 :
519 : /* open synthesis for output sampling rate */
520 26496 : if ( ( error = openCldfb( &st->cldfbSyn, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
521 : {
522 0 : return error;
523 : }
524 :
525 26496 : st->cldfbSynHB = NULL;
526 :
527 26496 : st->last_active_bandsToZero_bwdec = 0;
528 26496 : st->perc_bwddec = 0.0f;
529 26496 : st->last_flag_filter_NB = 0;
530 26496 : st->active_frame_cnt_bwddec = 0;
531 26496 : st->total_frame_cnt_bwddec = 0;
532 26496 : set_s( st->flag_buffer, 0, 20 );
533 26496 : st->avg_nrg_LT = 0.0f;
534 :
535 : /*-----------------------------------------------------------------*
536 : * Noise gate parameters
537 : *-----------------------------------------------------------------*/
538 :
539 26496 : st->ng_ener_ST = -51.0f;
540 :
541 26496 : st->old_Es_pred = 0;
542 26496 : set_f( st->old_Aq_12_8 + 1, 0, M );
543 26496 : st->old_Aq_12_8[0] = 1;
544 :
545 : /*-----------------------------------------------------------------*
546 : * SC-VBR parameters
547 : *-----------------------------------------------------------------*/
548 :
549 26496 : if ( st->element_mode == EVS_MONO )
550 : {
551 9 : if ( ( st->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL )
552 : {
553 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) );
554 : }
555 :
556 9 : sc_vbr_dec_init( st->hSC_VBR );
557 : }
558 : else
559 : {
560 26487 : st->hSC_VBR = NULL;
561 : }
562 :
563 26496 : st->last_ppp_mode_dec = 0;
564 26496 : st->old_ppp_mode = 0;
565 26496 : st->ppp_mode_dec = 0;
566 26496 : st->last_nelp_mode_dec = 0;
567 26496 : st->nelp_mode_dec = 0;
568 26496 : st->prev_gain_pit_dec = 0.0f;
569 26496 : st->prev_tilt_code_dec = 0.0f;
570 26496 : st->vbr_hw_BWE_disable_dec = 0;
571 26496 : st->last_vbr_hw_BWE_disable_dec = 0;
572 :
573 :
574 : /*-----------------------------------------------------------------*
575 : * TCX core
576 : *-----------------------------------------------------------------*/
577 :
578 : /* TCX-LTP */
579 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
580 : {
581 26199 : if ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL )
582 : {
583 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) );
584 : }
585 : }
586 : else
587 : {
588 297 : st->hTcxLtpDec = NULL;
589 : }
590 :
591 : /* TCX core */
592 :
593 26496 : if ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT )
594 : {
595 26199 : if ( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL )
596 : {
597 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) );
598 : }
599 :
600 26199 : set_f( st->hTcxDec->FBTCXdelayBuf, 0.0f, 111 );
601 :
602 26199 : st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS );
603 26199 : st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS );
604 : }
605 : else
606 : {
607 297 : st->hTcxDec = NULL;
608 : }
609 :
610 : /* TCX config. data structure */
611 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
612 : {
613 26199 : if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL )
614 : {
615 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) );
616 : }
617 : }
618 : else
619 : {
620 297 : st->hTcxCfg = NULL;
621 : }
622 :
623 : /* Tonal MDCT concealment data structure */
624 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
625 : {
626 26199 : if ( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL )
627 : {
628 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) );
629 : }
630 : }
631 : else
632 : {
633 297 : st->hTonalMDCTConc = NULL;
634 : }
635 :
636 : /*-----------------------------------------------------------------*
637 : * IGF
638 : *-----------------------------------------------------------------*/
639 :
640 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
641 : {
642 26199 : if ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL )
643 : {
644 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) );
645 : }
646 :
647 26199 : st->igf = 0;
648 26199 : init_igf_dec( st->hIGFDec );
649 : }
650 : else
651 : {
652 297 : st->hIGFDec = NULL;
653 : }
654 :
655 : /*-----------------------------------------------------------------*
656 : * Mode 2 initialization
657 : *-----------------------------------------------------------------*/
658 :
659 26496 : if ( st->element_mode == EVS_MONO )
660 : {
661 9 : if ( ( st->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL )
662 : {
663 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) );
664 : }
665 : }
666 : else
667 : {
668 26487 : st->hPlcInfo = NULL;
669 : }
670 :
671 26496 : if ( st->element_mode == EVS_MONO )
672 : {
673 9 : if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL )
674 : {
675 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) );
676 : }
677 : }
678 : else
679 : {
680 26487 : st->hTECDec = NULL;
681 : }
682 :
683 : /* Init Core Decoder */
684 26496 : open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 );
685 :
686 : /* PLC mode initialization */
687 26496 : st->m_decodeMode = DEC_NO_FRAM_LOSS;
688 :
689 : /* Init bandwidth / frame_type */
690 26496 : st->m_frame_type = ACTIVE_FRAME;
691 26496 : st->m_old_frame_type = ACTIVE_FRAME;
692 :
693 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) )
694 : {
695 9249 : resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC );
696 9249 : resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC );
697 : }
698 :
699 : /*-----------------------------------------------------------------*
700 : * FD-CNG decoder
701 : *-----------------------------------------------------------------*/
702 :
703 26496 : if ( ( st->element_mode == IVAS_CPE_MDCT || idchan == 0 ) && mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX )
704 : {
705 : /* Create FD_CNG instance */
706 20019 : if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
707 : {
708 0 : return error;
709 : }
710 :
711 : /* Init FD-CNG */
712 20019 : initFdCngDec( st );
713 : }
714 : else
715 : {
716 6477 : st->hFdCngDec = NULL;
717 : }
718 :
719 26496 : st->cngTDLevel = 0.f;
720 26496 : st->lp_noise = -20.0f;
721 26496 : st->force_lpd_reset = 0;
722 :
723 : /*-----------------------------------------------------------------*
724 : * IVAS parameters
725 : *-----------------------------------------------------------------*/
726 :
727 26496 : st->tdm_LRTD_flag = 0;
728 26496 : st->cna_dirac_flag = 0;
729 26496 : st->cng_sba_flag = 0;
730 26496 : st->cng_ism_flag = 0;
731 :
732 26496 : return error;
733 : }
734 :
735 :
736 : /*----------------------------------------------------------------------*
737 : * reset_preecho_dec()
738 : *
739 : * Initialization of static variables for pre-echo
740 : *----------------------------------------------------------------------*/
741 :
742 3397494 : void reset_preecho_dec(
743 : HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */
744 : )
745 : {
746 3397494 : hHQ_core->memfilt_lb = 0;
747 3397494 : hHQ_core->mean_prev_hb = 0;
748 3397494 : hHQ_core->smoothmem = 1;
749 3397494 : hHQ_core->mean_prev = 0;
750 3397494 : hHQ_core->mean_prev_nc = 0;
751 3397494 : hHQ_core->wmold_hb = 1;
752 3397494 : hHQ_core->prevflag = 0;
753 3397494 : hHQ_core->pastpre = 0;
754 :
755 3397494 : return;
756 : }
757 :
758 :
759 : /*----------------------------------------------------------------------*
760 : * destroy_cldfb_decoder()
761 : *
762 : * Free memory which was allocated in init_decoder()
763 : *----------------------------------------------------------------------*/
764 :
765 26496 : void destroy_cldfb_decoder(
766 : Decoder_State *st /* o : Decoder static variables structure */
767 : )
768 : {
769 : /* CLDFB BPF & resampling tools */
770 26496 : deleteCldfb( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
771 26496 : deleteCldfb( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
772 26496 : deleteCldfb( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
773 26496 : deleteCldfb( &st->cldfbSynHB );
774 :
775 26496 : deleteFdCngDec( &st->hFdCngDec );
776 :
777 26496 : return;
778 : }
|