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 697640 : 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 697640 : error = IVAS_ERR_OK;
64 :
65 : /*-----------------------------------------------------------------*
66 : * General parameters
67 : *-----------------------------------------------------------------*/
68 :
69 697640 : st->codec_mode = MODE1;
70 697640 : st->last_codec_mode = MODE1;
71 697640 : st->core = ACELP_CORE;
72 697640 : st->L_frame = L_FRAME;
73 697640 : st->extl = -1;
74 697640 : st->extl_orig = -1;
75 697640 : st->extl_brate_orig = 0;
76 697640 : st->last_bits_frame_nominal = -1;
77 697640 : st->total_brate = ACELP_8k00;
78 697640 : st->last_total_brate = -1;
79 697640 : st->last_total_brate_ber = -1;
80 697640 : st->core_brate = ACELP_8k00;
81 697640 : st->ini_frame = 0;
82 697640 : if ( st->element_mode == EVS_MONO )
83 : {
84 1266 : st->bwidth = NB;
85 1266 : st->last_bwidth = NB;
86 : }
87 : else
88 : {
89 696374 : st->bwidth = WB;
90 696374 : st->last_bwidth = WB;
91 : }
92 697640 : st->extl_brate = 0;
93 :
94 697640 : st->coder_type = GENERIC;
95 697640 : st->last_coder_type = GENERIC;
96 697640 : st->inactive_coder_type_flag = 0;
97 697640 : st->last_L_frame = st->L_frame;
98 697640 : st->last_core_brate = st->core_brate;
99 697640 : st->last_core = -1;
100 697640 : st->last_extl = st->extl;
101 :
102 697640 : 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 697640 : mvr2r( GEWB_Ave, st->mem_AR, M );
110 :
111 697640 : set_f( st->mem_MA, 0, M );
112 697640 : set_f( st->dispMem, 0, 8 );
113 :
114 697640 : st->tilt_code = 0.0f;
115 697640 : st->gc_threshold = 0.0f;
116 697640 : st->last_good = UNVOICED_CLAS;
117 697640 : st->clas_dec = UNVOICED_CLAS;
118 697640 : st->low_rate_mode = 0;
119 697640 : st->last_low_rate_mode = 0;
120 :
121 697640 : st->lp_gainp = 0.0f;
122 697640 : st->lp_gainc = 0.0f;
123 :
124 697640 : set_f( st->old_exc, 0, L_EXC_MEM_DEC );
125 :
126 : /* AVQ pre-quantizer memory */
127 697640 : st->mem_preemp_preQ = 0.0f;
128 697640 : st->last_nq_preQ = 0;
129 697640 : st->last_code_preq = 0;
130 697640 : st->use_acelp_preq = 0;
131 :
132 697640 : st->mem_deemph = 0.0f;
133 :
134 697640 : set_f( st->mem_syn1, 0, M );
135 697640 : set_f( st->mem_syn2, 0, M );
136 697640 : st->stab_fac = 0.0f;
137 697640 : st->stab_fac_smooth = 0.0f;
138 697640 : set_f( st->agc_mem2, 0, 2 );
139 697640 : set_f( st->mem_syn3, 0, M );
140 697640 : st->stab_fac_smooth_lt = 0.0f;
141 697640 : st->log_energy_diff_lt = 0.0f;
142 697640 : st->log_energy_old = 0.0f;
143 :
144 697640 : mvr2r( GEWB_Ave, st->lsf_old, M );
145 697640 : lsf2lsp( st->lsf_old, st->lsp_old, M, INT_FS_12k8 );
146 :
147 697640 : st->mid_lsf_int = 0;
148 697640 : st->safety_net = 0;
149 :
150 : /* FEC */
151 697640 : st->scaling_flag = 0;
152 697640 : st->lp_ener_FEC_av = 5.0e5f;
153 697640 : st->lp_ener_FEC_max = 5.0e5f;
154 697640 : st->prev_bfi = 0;
155 697640 : st->lp_ener_bfi = 60.0f;
156 697640 : st->old_enr_LP = 0.0f;
157 697640 : st->lp_ener = 0.0f;
158 697640 : st->enr_old = 0.0f;
159 697640 : st->bfi_pitch = (float) L_SUBFR;
160 697640 : st->bfi_pitch_frame = L_FRAME;
161 697640 : set_f( st->mem_syn_clas_estim, 0.0f, L_SYN_MEM_CLAS_ESTIM );
162 697640 : st->last_con_tcx = 0;
163 :
164 7674040 : for ( i = 0; i < 2 * NB_SUBFR16k; i++ )
165 : {
166 6976400 : st->old_pitch_buf[i] = (float) L_SUBFR;
167 : }
168 :
169 697640 : st->upd_cnt = MAX_UPD_CNT;
170 :
171 697640 : mvr2r( GEWB_Ave, st->lsfoldbfi0, M );
172 697640 : mvr2r( GEWB_Ave, st->lsfoldbfi1, M );
173 697640 : mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M );
174 :
175 697640 : st->seed_acelp = RANDOM_INITSEED;
176 697640 : st->seed = RANDOM_INITSEED;
177 697640 : st->nbLostCmpt = 0;
178 697640 : st->decision_hyst = 0;
179 :
180 : /* Stationary noise UV modification */
181 697640 : st->unv_cnt = 0;
182 697640 : st->ge_sm = 10;
183 697640 : st->uv_count = 0;
184 697640 : st->act_count = 3;
185 697640 : mvr2r( st->lsp_old, st->lspold_s, M );
186 697640 : st->noimix_seed = RANDOM_INITSEED;
187 697640 : st->min_alpha = 1;
188 697640 : st->exc_pe = 0;
189 :
190 697640 : st->prev_coder_type = GENERIC;
191 697640 : st->tilt_wb = 0.0f;
192 :
193 697640 : st->last_voice_factor = 0.0f;
194 697640 : set_f( st->prev_synth_buffer, 0, NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) );
195 :
196 697640 : st->old_bfi_cnt = 0;
197 :
198 : /*-----------------------------------------------------------------*
199 : * parameters for AC mode (GSC)
200 : *-----------------------------------------------------------------*/
201 :
202 697640 : st->GSC_noisy_speech = 0;
203 697640 : st->GSC_IVAS_mode = 0;
204 697640 : st->Last_GSC_noisy_speech_flag = 0;
205 :
206 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
207 : {
208 271870 : 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 271870 : GSC_dec_init( st->hGSCDec );
214 : }
215 : else
216 : {
217 425770 : st->hGSCDec = NULL;
218 : }
219 :
220 : /*-----------------------------------------------------------------*
221 : * parameters for fast recovery (WI)
222 : *-----------------------------------------------------------------*/
223 :
224 697640 : if ( st->output_Fs == 16000 && st->element_mode == EVS_MONO )
225 : {
226 546 : 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 546 : set_f( st->hWIDec->old_exc2, 0, L_EXC_MEM );
232 546 : set_f( st->hWIDec->old_syn2, 0, L_EXC_MEM );
233 : }
234 : else
235 : {
236 697094 : st->hWIDec = NULL;
237 : }
238 :
239 : /*-----------------------------------------------------------------*
240 : * NB/formant post-filter
241 : *-----------------------------------------------------------------*/
242 :
243 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
244 : {
245 271870 : 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 271870 : Init_post_filter( st->hPFstat );
251 271870 : st->psf_lp_noise = 0.0f;
252 : }
253 : else
254 : {
255 425770 : st->hPFstat = NULL;
256 : }
257 :
258 : /*-----------------------------------------------------------------*
259 : * HF (6-7kHz) (zero) BWE parameters
260 : *-----------------------------------------------------------------*/
261 :
262 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
263 : {
264 271870 : 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 271870 : hf_synth_init( st->hBWE_zero );
270 : }
271 : else
272 : {
273 425770 : st->hBWE_zero = NULL;
274 : }
275 :
276 :
277 : /*-----------------------------------------------------------------*
278 : * LD music post-filter
279 : *-----------------------------------------------------------------*/
280 :
281 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
282 : {
283 271870 : 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 271870 : music_postfilt_init( st->hMusicPF );
289 : }
290 : else
291 : {
292 425770 : st->hMusicPF = NULL;
293 : }
294 :
295 : /*-----------------------------------------------------------------*
296 : * CNG and DTX
297 : *-----------------------------------------------------------------*/
298 :
299 697640 : st->first_CNG = 0;
300 697640 : st->cng_type = -1;
301 697640 : st->last_vad = 0;
302 697640 : st->last_active_brate = ACELP_7k20;
303 697640 : st->last_CNG_L_frame = L_FRAME;
304 697640 : st->active_cnt = CNG_TYPE_HO;
305 :
306 697640 : if ( idchan == 0 && ( st->element_mode == EVS_MONO || st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) )
307 : {
308 8724 : 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 8724 : td_cng_dec_init( st );
314 : }
315 : else
316 : {
317 688916 : st->hTdCngDec = NULL;
318 : }
319 :
320 697640 : st->masa_sid_format = 0;
321 :
322 : /*-----------------------------------------------------------------*
323 : * HQ core parameters
324 : *-----------------------------------------------------------------*/
325 :
326 697640 : st->prev_old_bfi = 0;
327 697640 : set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
328 697640 : set_f( st->previoussynth, 0, L_FRAME48k );
329 :
330 697640 : if ( st->element_mode == EVS_MONO )
331 : {
332 1266 : set_f( st->old_synth_sw, 0.0f, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) );
333 : }
334 :
335 697640 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE || st->element_mode == EVS_MONO ) )
336 : {
337 690182 : 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 690182 : HQ_core_dec_init( st->hHQ_core );
344 :
345 690182 : if ( st->element_mode == EVS_MONO )
346 : {
347 : /* HQ NB FEC initialization */
348 1266 : 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 1266 : HQ_nbfec_init( st->hHQ_nbfec );
353 : }
354 : else
355 : {
356 688916 : st->hHQ_nbfec = NULL;
357 : }
358 : }
359 : else
360 : {
361 7458 : st->hHQ_core = NULL;
362 7458 : st->hHQ_nbfec = NULL;
363 : }
364 :
365 : /*-----------------------------------------------------------------*
366 : * TBE parameters
367 : *-----------------------------------------------------------------*/
368 :
369 697640 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
370 : {
371 271870 : 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 271870 : td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs );
377 : }
378 : else
379 : {
380 425770 : st->hBWE_TD = NULL;
381 : }
382 :
383 697640 : st->old_bwe_delay = -1;
384 697640 : set_f( st->hb_prev_synth_buffer, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
385 :
386 : /*-----------------------------------------------------------------*
387 : * SWB BWE parameters
388 : *-----------------------------------------------------------------*/
389 :
390 697640 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
391 : {
392 271870 : 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 271870 : fd_bwe_dec_init( st->hBWE_FD );
398 : }
399 : else
400 : {
401 425770 : st->hBWE_FD = NULL;
402 : }
403 :
404 : /*-----------------------------------------------------------------*
405 : * WB/SWB bandwidth switching parameters
406 : *-----------------------------------------------------------------*/
407 :
408 697640 : st->tilt_swb = 0.0f;
409 697640 : st->prev_ener_shb = 0.0f;
410 697640 : st->prev_enerLH = 0.0f;
411 697640 : st->enerLH = 0.0f;
412 697640 : st->enerLL = 0.0f;
413 697640 : st->prev_enerLL = 0.0f;
414 697640 : st->prev_fractive = 0;
415 697640 : st->prev_bws_cnt = 0;
416 697640 : st->bws_cnt = N_WS2N_FRAMES;
417 697640 : st->bws_cnt1 = N_NS2W_FRAMES;
418 697640 : st->attenu1 = 0.1f;
419 697640 : st->last_inner_frame = L_FRAME8k;
420 :
421 : /*-----------------------------------------------------------------*
422 : * HR SWB BWE parameters
423 : *-----------------------------------------------------------------*/
424 :
425 697640 : if ( st->element_mode == EVS_MONO )
426 : {
427 1266 : 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 1266 : hr_bwe_dec_init( st->hBWE_FD_HR );
433 : }
434 : else
435 : {
436 696374 : st->hBWE_FD_HR = NULL;
437 : }
438 :
439 : /*----------------------------------------------------------------------------------*
440 : * AMR-WB IO mode parameters
441 : *----------------------------------------------------------------------------------*/
442 :
443 697640 : if ( st->Opt_AMR_WB || st->element_mode == EVS_MONO )
444 : {
445 1266 : 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 1266 : amr_wb_dec_init( st->hAmrwb_IO );
452 :
453 : /* AMR-WB IO HF synth init */
454 1266 : hf_synth_amr_wb_init( st->hAmrwb_IO );
455 : }
456 : else
457 : {
458 696374 : st->hAmrwb_IO = NULL;
459 : }
460 :
461 : /*-----------------------------------------------------------------*
462 : * channel-aware mode parameters
463 : *-----------------------------------------------------------------*/
464 :
465 697640 : set_f( st->tilt_code_dec, 0.0f, NB_SUBFR16k );
466 :
467 697640 : st->use_partial_copy = 0;
468 697640 : st->prev_use_partial_copy = 0;
469 697640 : st->rf_flag = 0;
470 697640 : st->rf_flag_last = 0;
471 697640 : st->prev_rf_frame_type = 0;
472 697640 : st->next_coder_type = 0;
473 :
474 697640 : st->rf_target_bits = 0;
475 :
476 697640 : st->rf_indx_nelp_fid = 0;
477 697640 : st->rf_indx_nelp_iG1 = 0;
478 697640 : st->rf_indx_nelp_iG2[0] = 0;
479 697640 : st->rf_indx_nelp_iG2[1] = 0;
480 697640 : st->rf_indx_tbeGainFr = 0;
481 :
482 : /*-----------------------------------------------------------------*
483 : * Bass post-filter parameters
484 : *-----------------------------------------------------------------*/
485 :
486 697640 : st->bpf_off = 0;
487 :
488 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
489 : {
490 271870 : 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 271870 : bass_psfilter_init( st->hBPF );
496 : }
497 : else
498 : {
499 425770 : st->hBPF = NULL;
500 : }
501 :
502 : /*-----------------------------------------------------------------*
503 : * FD BPF & resampling tools parameters
504 : *-----------------------------------------------------------------*/
505 :
506 697640 : 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 271870 : 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 271870 : 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 425770 : st->cldfbAna = NULL;
523 425770 : st->cldfbBPF = NULL;
524 : }
525 :
526 : /* open synthesis for output sampling rate */
527 697640 : 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 697640 : st->cldfbSynHB = NULL;
533 :
534 697640 : st->last_active_bandsToZero_bwdec = 0;
535 697640 : st->perc_bwddec = 0.0f;
536 697640 : st->last_flag_filter_NB = 0;
537 697640 : st->active_frame_cnt_bwddec = 0;
538 697640 : st->total_frame_cnt_bwddec = 0;
539 697640 : set_s( st->flag_buffer, 0, 20 );
540 697640 : st->avg_nrg_LT = 0.0f;
541 :
542 : /*-----------------------------------------------------------------*
543 : * Noise gate parameters
544 : *-----------------------------------------------------------------*/
545 :
546 697640 : st->ng_ener_ST = -51.0f;
547 :
548 697640 : st->old_Es_pred = 0;
549 697640 : set_f( st->old_Aq_12_8 + 1, 0, M );
550 697640 : st->old_Aq_12_8[0] = 1;
551 :
552 : /*-----------------------------------------------------------------*
553 : * SC-VBR parameters
554 : *-----------------------------------------------------------------*/
555 :
556 697640 : if ( st->element_mode == EVS_MONO )
557 : {
558 1266 : 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 1266 : sc_vbr_dec_init( st->hSC_VBR );
564 : }
565 : else
566 : {
567 696374 : st->hSC_VBR = NULL;
568 : }
569 :
570 697640 : st->last_ppp_mode_dec = 0;
571 697640 : st->old_ppp_mode = 0;
572 697640 : st->ppp_mode_dec = 0;
573 697640 : st->last_nelp_mode_dec = 0;
574 697640 : st->nelp_mode_dec = 0;
575 697640 : st->prev_gain_pit_dec = 0.0f;
576 697640 : st->prev_tilt_code_dec = 0.0f;
577 697640 : st->vbr_hw_BWE_disable_dec = 0;
578 697640 : st->last_vbr_hw_BWE_disable_dec = 0;
579 :
580 :
581 : /*-----------------------------------------------------------------*
582 : * TCX core
583 : *-----------------------------------------------------------------*/
584 :
585 : /* TCX-LTP */
586 697640 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
587 : {
588 690182 : 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 7458 : st->hTcxLtpDec = NULL;
596 : }
597 :
598 : /* TCX core */
599 :
600 697640 : if ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT )
601 : {
602 690182 : 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 690182 : set_f( st->hTcxDec->FBTCXdelayBuf, 0.0f, 111 );
608 :
609 690182 : st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS );
610 690182 : st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS );
611 : }
612 : else
613 : {
614 7458 : st->hTcxDec = NULL;
615 : }
616 :
617 : /* TCX config. data structure */
618 697640 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
619 : {
620 690182 : 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 7458 : st->hTcxCfg = NULL;
628 : }
629 :
630 : /* Tonal MDCT concealment data structure */
631 697640 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
632 : {
633 690182 : 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 7458 : st->hTonalMDCTConc = NULL;
641 : }
642 :
643 : /*-----------------------------------------------------------------*
644 : * IGF
645 : *-----------------------------------------------------------------*/
646 :
647 697640 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
648 : {
649 690182 : 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 690182 : st->igf = 0;
655 690182 : init_igf_dec( st->hIGFDec );
656 : }
657 : else
658 : {
659 7458 : st->hIGFDec = NULL;
660 : }
661 :
662 : /*-----------------------------------------------------------------*
663 : * Mode 2 initialization
664 : *-----------------------------------------------------------------*/
665 :
666 697640 : if ( st->element_mode == EVS_MONO )
667 : {
668 1266 : 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 696374 : st->hPlcInfo = NULL;
676 : }
677 :
678 697640 : if ( st->element_mode == EVS_MONO )
679 : {
680 1266 : 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 696374 : st->hTECDec = NULL;
688 : }
689 :
690 : /* Init Core Decoder */
691 697640 : open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 );
692 :
693 : /* PLC mode initialization */
694 697640 : st->m_decodeMode = DEC_NO_FRAM_LOSS;
695 :
696 : /* Init bandwidth / frame_type */
697 697640 : st->m_frame_type = ACTIVE_FRAME;
698 697640 : st->m_old_frame_type = ACTIVE_FRAME;
699 :
700 697640 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) )
701 : {
702 271870 : resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC );
703 271870 : resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC );
704 : }
705 :
706 : /*-----------------------------------------------------------------*
707 : * FD-CNG decoder
708 : *-----------------------------------------------------------------*/
709 :
710 697640 : 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 539028 : if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
714 : {
715 0 : return error;
716 : }
717 :
718 : /* Init FD-CNG */
719 539028 : initFdCngDec( st );
720 : }
721 : else
722 : {
723 158612 : st->hFdCngDec = NULL;
724 : }
725 :
726 697640 : st->cngTDLevel = 0.f;
727 697640 : st->lp_noise = -20.0f;
728 697640 : st->force_lpd_reset = 0;
729 :
730 : /*-----------------------------------------------------------------*
731 : * IVAS parameters
732 : *-----------------------------------------------------------------*/
733 :
734 697640 : st->tdm_LRTD_flag = 0;
735 697640 : st->cna_dirac_flag = 0;
736 697640 : st->cng_sba_flag = 0;
737 697640 : st->cng_ism_flag = 0;
738 :
739 697640 : return error;
740 : }
741 :
742 :
743 : /*----------------------------------------------------------------------*
744 : * reset_preecho_dec()
745 : *
746 : * Initialization of static variables for pre-echo
747 : *----------------------------------------------------------------------*/
748 :
749 62437620 : void reset_preecho_dec(
750 : HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */
751 : )
752 : {
753 62437620 : hHQ_core->memfilt_lb = 0;
754 62437620 : hHQ_core->mean_prev_hb = 0;
755 62437620 : hHQ_core->smoothmem = 1;
756 62437620 : hHQ_core->mean_prev = 0;
757 62437620 : hHQ_core->mean_prev_nc = 0;
758 62437620 : hHQ_core->wmold_hb = 1;
759 62437620 : hHQ_core->prevflag = 0;
760 62437620 : hHQ_core->pastpre = 0;
761 :
762 62437620 : return;
763 : }
764 :
765 :
766 : /*----------------------------------------------------------------------*
767 : * destroy_cldfb_decoder()
768 : *
769 : * Free memory which was allocated in init_decoder()
770 : *----------------------------------------------------------------------*/
771 :
772 697640 : void destroy_cldfb_decoder(
773 : Decoder_State *st /* o : Decoder static variables structure */
774 : )
775 : {
776 : /* CLDFB BPF & resampling tools */
777 697640 : deleteCldfb( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
778 697640 : deleteCldfb( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
779 697640 : deleteCldfb( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
780 697640 : deleteCldfb( &st->cldfbSynHB );
781 :
782 697640 : deleteFdCngDec( &st->hFdCngDec );
783 :
784 697640 : return;
785 : }
|