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 26496 : st->active_cnt = CNG_TYPE_HO;
297 :
298 26496 : if ( idchan == 0 && ( st->element_mode == EVS_MONO || st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) )
299 : {
300 306 : if ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL )
301 : {
302 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) );
303 : }
304 :
305 306 : td_cng_dec_init( st );
306 : }
307 : else
308 : {
309 26190 : st->hTdCngDec = NULL;
310 : }
311 :
312 26496 : st->masa_sid_format = 0;
313 :
314 : /*-----------------------------------------------------------------*
315 : * HQ core parameters
316 : *-----------------------------------------------------------------*/
317 :
318 26496 : st->prev_old_bfi = 0;
319 26496 : set_f( st->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP );
320 26496 : set_f( st->previoussynth, 0, L_FRAME48k );
321 :
322 26496 : if ( st->element_mode == EVS_MONO )
323 : {
324 9 : set_f( st->old_synth_sw, 0.0f, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) );
325 : }
326 :
327 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT || st->element_mode == IVAS_SCE || st->element_mode == EVS_MONO ) )
328 : {
329 26199 : if ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL )
330 : {
331 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) );
332 : }
333 :
334 : /* HQ core initialization */
335 26199 : HQ_core_dec_init( st->hHQ_core );
336 :
337 26199 : if ( st->element_mode == EVS_MONO )
338 : {
339 : /* HQ NB FEC initialization */
340 9 : if ( ( st->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL )
341 : {
342 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) );
343 : }
344 9 : HQ_nbfec_init( st->hHQ_nbfec );
345 : }
346 : else
347 : {
348 26190 : st->hHQ_nbfec = NULL;
349 : }
350 : }
351 : else
352 : {
353 297 : st->hHQ_core = NULL;
354 297 : st->hHQ_nbfec = NULL;
355 : }
356 :
357 : /*-----------------------------------------------------------------*
358 : * TBE parameters
359 : *-----------------------------------------------------------------*/
360 :
361 26496 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
362 : {
363 9249 : if ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL )
364 : {
365 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) );
366 : }
367 :
368 9249 : td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs );
369 : }
370 : else
371 : {
372 17247 : st->hBWE_TD = NULL;
373 : }
374 :
375 26496 : st->old_bwe_delay = -1;
376 26496 : set_f( st->hb_prev_synth_buffer, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) );
377 :
378 : /*-----------------------------------------------------------------*
379 : * SWB BWE parameters
380 : *-----------------------------------------------------------------*/
381 :
382 26496 : if ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT )
383 : {
384 9249 : if ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL )
385 : {
386 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) );
387 : }
388 :
389 9249 : fd_bwe_dec_init( st->hBWE_FD );
390 : }
391 : else
392 : {
393 17247 : st->hBWE_FD = NULL;
394 : }
395 :
396 : /*-----------------------------------------------------------------*
397 : * WB/SWB bandwidth switching parameters
398 : *-----------------------------------------------------------------*/
399 :
400 26496 : st->tilt_swb = 0.0f;
401 26496 : st->prev_ener_shb = 0.0f;
402 26496 : st->prev_enerLH = 0.0f;
403 26496 : st->enerLH = 0.0f;
404 26496 : st->enerLL = 0.0f;
405 26496 : st->prev_enerLL = 0.0f;
406 26496 : st->prev_fractive = 0;
407 26496 : st->prev_bws_cnt = 0;
408 26496 : st->bws_cnt = N_WS2N_FRAMES;
409 26496 : st->bws_cnt1 = N_NS2W_FRAMES;
410 26496 : st->attenu1 = 0.1f;
411 26496 : st->last_inner_frame = L_FRAME8k;
412 :
413 : /*-----------------------------------------------------------------*
414 : * HR SWB BWE parameters
415 : *-----------------------------------------------------------------*/
416 :
417 26496 : if ( st->element_mode == EVS_MONO )
418 : {
419 9 : if ( ( st->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL )
420 : {
421 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) );
422 : }
423 :
424 9 : hr_bwe_dec_init( st->hBWE_FD_HR );
425 : }
426 : else
427 : {
428 26487 : st->hBWE_FD_HR = NULL;
429 : }
430 :
431 : /*----------------------------------------------------------------------------------*
432 : * AMR-WB IO mode parameters
433 : *----------------------------------------------------------------------------------*/
434 :
435 26496 : if ( st->Opt_AMR_WB || st->element_mode == EVS_MONO )
436 : {
437 9 : if ( ( st->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL )
438 : {
439 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) );
440 : }
441 :
442 : /* AMR-WB IO init */
443 9 : amr_wb_dec_init( st->hAmrwb_IO );
444 :
445 : /* AMR-WB IO HF synth init */
446 9 : hf_synth_amr_wb_init( st->hAmrwb_IO );
447 : }
448 : else
449 : {
450 26487 : st->hAmrwb_IO = NULL;
451 : }
452 :
453 : /*-----------------------------------------------------------------*
454 : * channel-aware mode parameters
455 : *-----------------------------------------------------------------*/
456 :
457 26496 : set_f( st->tilt_code_dec, 0.0f, NB_SUBFR16k );
458 :
459 26496 : st->use_partial_copy = 0;
460 26496 : st->prev_use_partial_copy = 0;
461 26496 : st->rf_flag = 0;
462 26496 : st->rf_flag_last = 0;
463 26496 : st->prev_rf_frame_type = 0;
464 26496 : st->next_coder_type = 0;
465 :
466 26496 : st->rf_target_bits = 0;
467 :
468 26496 : st->rf_indx_nelp_fid = 0;
469 26496 : st->rf_indx_nelp_iG1 = 0;
470 26496 : st->rf_indx_nelp_iG2[0] = 0;
471 26496 : st->rf_indx_nelp_iG2[1] = 0;
472 26496 : st->rf_indx_tbeGainFr = 0;
473 :
474 : /*-----------------------------------------------------------------*
475 : * Bass post-filter parameters
476 : *-----------------------------------------------------------------*/
477 :
478 26496 : st->bpf_off = 0;
479 :
480 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
481 : {
482 9249 : if ( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL )
483 : {
484 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) );
485 : }
486 :
487 9249 : bass_psfilter_init( st->hBPF );
488 : }
489 : else
490 : {
491 17247 : st->hBPF = NULL;
492 : }
493 :
494 : /*-----------------------------------------------------------------*
495 : * FD BPF & resampling tools parameters
496 : *-----------------------------------------------------------------*/
497 :
498 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) || st->element_mode == IVAS_CPE_TD )
499 : {
500 : /* open analysis for max. sampling rate 48kHz */
501 9249 : if ( ( error = openCldfb( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
502 : {
503 0 : return error;
504 : }
505 :
506 : /* open analysis BPF for max. internal sampling rate 16kHz */
507 9249 : if ( ( error = openCldfb( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
508 : {
509 0 : return error;
510 : }
511 : }
512 : else
513 : {
514 17247 : st->cldfbAna = NULL;
515 17247 : st->cldfbBPF = NULL;
516 : }
517 :
518 : /* open synthesis for output sampling rate */
519 26496 : if ( ( error = openCldfb( &st->cldfbSyn, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK )
520 : {
521 0 : return error;
522 : }
523 :
524 26496 : st->cldfbSynHB = NULL;
525 :
526 26496 : st->last_active_bandsToZero_bwdec = 0;
527 26496 : st->perc_bwddec = 0.0f;
528 26496 : st->last_flag_filter_NB = 0;
529 26496 : st->active_frame_cnt_bwddec = 0;
530 26496 : st->total_frame_cnt_bwddec = 0;
531 26496 : set_s( st->flag_buffer, 0, 20 );
532 26496 : st->avg_nrg_LT = 0.0f;
533 :
534 : /*-----------------------------------------------------------------*
535 : * Noise gate parameters
536 : *-----------------------------------------------------------------*/
537 :
538 26496 : st->ng_ener_ST = -51.0f;
539 :
540 26496 : st->old_Es_pred = 0;
541 26496 : set_f( st->old_Aq_12_8 + 1, 0, M );
542 26496 : st->old_Aq_12_8[0] = 1;
543 :
544 : /*-----------------------------------------------------------------*
545 : * SC-VBR parameters
546 : *-----------------------------------------------------------------*/
547 :
548 26496 : if ( st->element_mode == EVS_MONO )
549 : {
550 9 : if ( ( st->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL )
551 : {
552 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) );
553 : }
554 :
555 9 : sc_vbr_dec_init( st->hSC_VBR );
556 : }
557 : else
558 : {
559 26487 : st->hSC_VBR = NULL;
560 : }
561 :
562 26496 : st->last_ppp_mode_dec = 0;
563 26496 : st->old_ppp_mode = 0;
564 26496 : st->ppp_mode_dec = 0;
565 26496 : st->last_nelp_mode_dec = 0;
566 26496 : st->nelp_mode_dec = 0;
567 26496 : st->prev_gain_pit_dec = 0.0f;
568 26496 : st->prev_tilt_code_dec = 0.0f;
569 26496 : st->vbr_hw_BWE_disable_dec = 0;
570 26496 : st->last_vbr_hw_BWE_disable_dec = 0;
571 :
572 :
573 : /*-----------------------------------------------------------------*
574 : * TCX core
575 : *-----------------------------------------------------------------*/
576 :
577 : /* TCX-LTP */
578 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
579 : {
580 26199 : if ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL )
581 : {
582 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) );
583 : }
584 : }
585 : else
586 : {
587 297 : st->hTcxLtpDec = NULL;
588 : }
589 :
590 : /* TCX core */
591 :
592 26496 : if ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT )
593 : {
594 26199 : if ( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL )
595 : {
596 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) );
597 : }
598 :
599 26199 : set_f( st->hTcxDec->FBTCXdelayBuf, 0.0f, 111 );
600 :
601 26199 : st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS );
602 26199 : st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS );
603 : }
604 : else
605 : {
606 297 : st->hTcxDec = NULL;
607 : }
608 :
609 : /* TCX config. data structure */
610 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
611 : {
612 26199 : if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL )
613 : {
614 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) );
615 : }
616 : }
617 : else
618 : {
619 297 : st->hTcxCfg = NULL;
620 : }
621 :
622 : /* Tonal MDCT concealment data structure */
623 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
624 : {
625 26199 : if ( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL )
626 : {
627 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) );
628 : }
629 : }
630 : else
631 : {
632 297 : st->hTonalMDCTConc = NULL;
633 : }
634 :
635 : /*-----------------------------------------------------------------*
636 : * IGF
637 : *-----------------------------------------------------------------*/
638 :
639 26496 : if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
640 : {
641 26199 : if ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL )
642 : {
643 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) );
644 : }
645 :
646 26199 : st->igf = 0;
647 26199 : init_igf_dec( st->hIGFDec );
648 : }
649 : else
650 : {
651 297 : st->hIGFDec = NULL;
652 : }
653 :
654 : /*-----------------------------------------------------------------*
655 : * Mode 2 initialization
656 : *-----------------------------------------------------------------*/
657 :
658 26496 : if ( st->element_mode == EVS_MONO )
659 : {
660 9 : if ( ( st->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL )
661 : {
662 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) );
663 : }
664 : }
665 : else
666 : {
667 26487 : st->hPlcInfo = NULL;
668 : }
669 :
670 26496 : if ( st->element_mode == EVS_MONO )
671 : {
672 9 : if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL )
673 : {
674 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) );
675 : }
676 : }
677 : else
678 : {
679 26487 : st->hTECDec = NULL;
680 : }
681 :
682 : /* Init Core Decoder */
683 26496 : open_decoder_LPD( st, st->total_brate, st->last_total_brate, st->bwidth, 0, st->element_mode, 1 );
684 :
685 : /* PLC mode initialization */
686 26496 : st->m_decodeMode = DEC_NO_FRAM_LOSS;
687 :
688 : /* Init bandwidth / frame_type */
689 26496 : st->m_frame_type = ACTIVE_FRAME;
690 26496 : st->m_old_frame_type = ACTIVE_FRAME;
691 :
692 26496 : if ( ( idchan == 0 && st->element_mode != IVAS_CPE_MDCT ) )
693 : {
694 9249 : resampleCldfb( st->cldfbAna, st->L_frame * FRAMES_PER_SEC );
695 9249 : resampleCldfb( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC );
696 : }
697 :
698 : /*-----------------------------------------------------------------*
699 : * FD-CNG decoder
700 : *-----------------------------------------------------------------*/
701 :
702 26496 : if ( ( st->element_mode == IVAS_CPE_MDCT || idchan == 0 ) && mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX )
703 : {
704 : /* Create FD_CNG instance */
705 20019 : if ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK )
706 : {
707 0 : return error;
708 : }
709 :
710 : /* Init FD-CNG */
711 20019 : initFdCngDec( st );
712 : }
713 : else
714 : {
715 6477 : st->hFdCngDec = NULL;
716 : }
717 :
718 26496 : st->cngTDLevel = 0.f;
719 26496 : st->lp_noise = -20.0f;
720 26496 : st->force_lpd_reset = 0;
721 :
722 : /*-----------------------------------------------------------------*
723 : * IVAS parameters
724 : *-----------------------------------------------------------------*/
725 :
726 26496 : st->tdm_LRTD_flag = 0;
727 26496 : st->cna_dirac_flag = 0;
728 26496 : st->cng_sba_flag = 0;
729 26496 : st->cng_ism_flag = 0;
730 :
731 26496 : return error;
732 : }
733 :
734 :
735 : /*----------------------------------------------------------------------*
736 : * reset_preecho_dec()
737 : *
738 : * Initialization of static variables for pre-echo
739 : *----------------------------------------------------------------------*/
740 :
741 3397494 : void reset_preecho_dec(
742 : HQ_DEC_HANDLE hHQ_core /* i/o: HQ decoder handle */
743 : )
744 : {
745 3397494 : hHQ_core->memfilt_lb = 0;
746 3397494 : hHQ_core->mean_prev_hb = 0;
747 3397494 : hHQ_core->smoothmem = 1;
748 3397494 : hHQ_core->mean_prev = 0;
749 3397494 : hHQ_core->mean_prev_nc = 0;
750 3397494 : hHQ_core->wmold_hb = 1;
751 3397494 : hHQ_core->prevflag = 0;
752 3397494 : hHQ_core->pastpre = 0;
753 :
754 3397494 : return;
755 : }
756 :
757 :
758 : /*----------------------------------------------------------------------*
759 : * destroy_cldfb_decoder()
760 : *
761 : * Free memory which was allocated in init_decoder()
762 : *----------------------------------------------------------------------*/
763 :
764 26496 : void destroy_cldfb_decoder(
765 : Decoder_State *st /* o : Decoder static variables structure */
766 : )
767 : {
768 : /* CLDFB BPF & resampling tools */
769 26496 : deleteCldfb( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */
770 26496 : deleteCldfb( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */
771 26496 : deleteCldfb( &st->cldfbSyn ); /* delete synthesis at output sampling rate */
772 26496 : deleteCldfb( &st->cldfbSynHB );
773 :
774 26496 : deleteFdCngDec( &st->hFdCngDec );
775 :
776 26496 : return;
777 : }
|