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