From 5a518fa78c273cd4935d5946c2bea8d9a076f025 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 13:56:32 +0100 Subject: [PATCH 1/8] fix FIX_2252_TD_CNG_STARTS_SID --- lib_com/options.h | 1 + lib_dec/decision_matrix_dec_fx.c | 10 ++++++++++ lib_dec/init_dec_fx.c | 18 ++++++++++++++++++ lib_dec/ivas_decision_matrix_dec_fx.c | 6 ++++++ 4 files changed, 35 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index dd41dd1bc..fe7fead81 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,6 +96,7 @@ #define FIX_2015_PREMPH_SAT_ALT_PART2 /* VA: Add missing scaling factor to be passed to AVQ_cod() */ #define FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH /* VA: Fix Issue 2253 where the encoder and decoder could get out of sync */ #define NONBE_FIX_1967_SBA_DECODER_MONO_OUT_BIG_DIFFERENCES /* Dolby: Fix basop issue 1967 */ +#define FIX_2252_TD_CNG_STARTS_SID /* VA: issues 2251 and 2252: Resolve "MSAN with bitstream that starts with an SID" */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 1bd406e7a..e905b8237 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -76,10 +76,20 @@ void decision_matrix_dec_fx( move16(); tmp16 = get_next_indice_fx( st, 1 ); // Q0 +#ifdef FIX_2252_TD_CNG_STARTS_SID + IF ( EQ_16( tmp16, 1 ) ) +#else if ( EQ_16( tmp16, 1 ) ) +#endif { st->L_frame = L_FRAME16k; move16(); +#ifdef FIX_2252_TD_CNG_STARTS_SID + st->nb_subfr = NB_SUBFR16k; + move16(); + st->bwidth = WB; + move16(); +#endif } } ELSE diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index ec2c0ce0b..4288a6722 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -91,12 +91,30 @@ ivas_error init_decoder_fx( move16(); st_fx->ini_frame = 0; move16(); +#ifdef FIX_2252_TD_CNG_STARTS_SID + IF( st->element_mode == EVS_MONO ) + { + st->bwidth = NB; + move16(); + st->last_bwidth = NB; + move16(); + } + ELSE + { + st_fx->bwidth = WB; + move16(); + st_fx->last_bwidth = WB; + move16(); + } +#else st_fx->bwidth = NB; move16(); st_fx->last_bwidth = NB; move16(); +#endif st_fx->extl_brate = 0; move16(); + st_fx->coder_type = GENERIC; /* low-rate mode flag */ move16(); st_fx->last_coder_type = GENERIC; diff --git a/lib_dec/ivas_decision_matrix_dec_fx.c b/lib_dec/ivas_decision_matrix_dec_fx.c index 4ba2a386a..20f7159a9 100644 --- a/lib_dec/ivas_decision_matrix_dec_fx.c +++ b/lib_dec/ivas_decision_matrix_dec_fx.c @@ -115,6 +115,12 @@ void ivas_decision_matrix_dec_fx( { st->L_frame = L_FRAME16k; move16(); +#ifdef FIX_2252_TD_CNG_STARTS_SID + st->nb_subfr = NB_SUBFR16k; + move16(); + st->bwidth = WB; + move16(); +#endif } ELSE { -- GitLab From 2137b4e735bdea3d6e576ebf0df7d609c86680af Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 14:06:48 +0100 Subject: [PATCH 2/8] clang-format --- lib_dec/decision_matrix_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index e905b8237..85a6e1f35 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -77,7 +77,7 @@ void decision_matrix_dec_fx( tmp16 = get_next_indice_fx( st, 1 ); // Q0 #ifdef FIX_2252_TD_CNG_STARTS_SID - IF ( EQ_16( tmp16, 1 ) ) + IF( EQ_16( tmp16, 1 ) ) #else if ( EQ_16( tmp16, 1 ) ) #endif -- GitLab From 2259aa70684f196709b7e389708b5b31912eef4e Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 5 Dec 2025 14:57:54 +0100 Subject: [PATCH 3/8] [revert-me] change CI ref --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f84bc99f..1e36678fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information - IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF main + IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF fix-name-checks-basop-ci # If you need to set some config variable only in a local branch, then add an overwrite here # One example is DISABLE_HRTF - this will be set on a branch which is about to be merged and will be removed in a subsequent second MR # this is more easily done directly here in the child repo -- GitLab From 822d4483143d25da4af5fc2923929463021dae4a Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Fri, 5 Dec 2025 15:19:38 +0100 Subject: [PATCH 4/8] Revert "[revert-me] change CI ref" This reverts commit 2259aa70684f196709b7e389708b5b31912eef4e. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1e36678fc..3f84bc99f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information - IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF fix-name-checks-basop-ci + IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF main # If you need to set some config variable only in a local branch, then add an overwrite here # One example is DISABLE_HRTF - this will be set on a branch which is about to be merged and will be removed in a subsequent second MR # this is more easily done directly here in the child repo -- GitLab From 260458b717df12ba7c1e55d56701f449818de74e Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 17:39:18 +0100 Subject: [PATCH 5/8] fix --- lib_com/options.h | 2 +- lib_dec/decision_matrix_dec_fx.c | 5 ++--- lib_dec/init_dec_fx.c | 12 ++++++------ lib_dec/ivas_decision_matrix_dec_fx.c | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index fe7fead81..7422af1cf 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,7 +96,7 @@ #define FIX_2015_PREMPH_SAT_ALT_PART2 /* VA: Add missing scaling factor to be passed to AVQ_cod() */ #define FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH /* VA: Fix Issue 2253 where the encoder and decoder could get out of sync */ #define NONBE_FIX_1967_SBA_DECODER_MONO_OUT_BIG_DIFFERENCES /* Dolby: Fix basop issue 1967 */ -#define FIX_2252_TD_CNG_STARTS_SID /* VA: issues 2251 and 2252: Resolve "MSAN with bitstream that starts with an SID" */ +#define FIX_2252_LP_CNG_STARTS_SID /* VA: issues 2251 and 2252: fix LP CNG uninitialized value in bitstream that starts with an SID */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 85a6e1f35..cddc16314 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -84,11 +84,10 @@ void decision_matrix_dec_fx( { st->L_frame = L_FRAME16k; move16(); -#ifdef FIX_2252_TD_CNG_STARTS_SID +#ifdef FIX_2252_LP_CNG_STARTS_SID st->nb_subfr = NB_SUBFR16k; move16(); - st->bwidth = WB; - move16(); + st->bwidth = s_max( st->bwidth, WB ); #endif } } diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 4288a6722..2033f284a 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -91,20 +91,20 @@ ivas_error init_decoder_fx( move16(); st_fx->ini_frame = 0; move16(); -#ifdef FIX_2252_TD_CNG_STARTS_SID - IF( st->element_mode == EVS_MONO ) +#ifdef FIX_2252_LP_CNG_STARTS_SID + IF( st_fx->element_mode == EVS_MONO ) { - st->bwidth = NB; + st_fx->bwidth = NB; move16(); - st->last_bwidth = NB; + st_fx->last_bwidth = NB; move16(); } ELSE { st_fx->bwidth = WB; move16(); - st_fx->last_bwidth = WB; - move16(); + // st_fx->last_bwidth = WB; // TBV + // move16(); } #else st_fx->bwidth = NB; diff --git a/lib_dec/ivas_decision_matrix_dec_fx.c b/lib_dec/ivas_decision_matrix_dec_fx.c index 20f7159a9..fadd9d008 100644 --- a/lib_dec/ivas_decision_matrix_dec_fx.c +++ b/lib_dec/ivas_decision_matrix_dec_fx.c @@ -115,11 +115,10 @@ void ivas_decision_matrix_dec_fx( { st->L_frame = L_FRAME16k; move16(); -#ifdef FIX_2252_TD_CNG_STARTS_SID +#ifdef FIX_2252_LP_CNG_STARTS_SID st->nb_subfr = NB_SUBFR16k; move16(); - st->bwidth = WB; - move16(); + st->bwidth = s_max( st->bwidth, WB ); #endif } ELSE -- GitLab From b58c9f747903ccc0692a2f7da4b35d6bdd962db6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 17:56:11 +0100 Subject: [PATCH 6/8] fix --- lib_dec/init_dec_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 1a064689d..51195ca8c 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -103,8 +103,9 @@ ivas_error init_decoder_fx( { st_fx->bwidth = WB; move16(); + st_fx->last_bwidth = NB; // st_fx->last_bwidth = WB; // TBV - // move16(); + move16(); } #else st_fx->bwidth = NB; -- GitLab From ff7b1776d1314d6ab090dd69e5b9ec624a48583e Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 21:33:18 +0100 Subject: [PATCH 7/8] another attempt to get BE --- lib_dec/init_dec_fx.c | 1549 +++++++++++++++++++++-------------------- 1 file changed, 777 insertions(+), 772 deletions(-) diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 51195ca8c..65b2ea925 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -101,960 +101,965 @@ ivas_error init_decoder_fx( } ELSE { +#if 0 // keep deactivated for the moment to keep BE st_fx->bwidth = WB; move16(); + st_fx->last_bwidth = WB; +#else + st_fx->bwidth = NB; + move16(); st_fx->last_bwidth = NB; - // st_fx->last_bwidth = WB; // TBV +#endif move16(); } #else - st_fx->bwidth = NB; - move16(); - st_fx->last_bwidth = NB; - move16(); + st_fx->bwidth = NB; + move16(); + st_fx->last_bwidth = NB; + move16(); #endif - st_fx->extl_brate = 0; - move16(); + st_fx->extl_brate = 0; + move16(); - st_fx->coder_type = GENERIC; /* low-rate mode flag */ - move16(); - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->inactive_coder_type_flag = 0; - move16(); - st_fx->last_L_frame = st_fx->L_frame; - move16(); - st_fx->last_core_brate = st_fx->core_brate; - move16(); - st_fx->last_core = -1; - move16(); - st_fx->last_extl = st_fx->extl; - move16(); + st_fx->coder_type = GENERIC; /* low-rate mode flag */ + move16(); + st_fx->last_coder_type = GENERIC; + move16(); + st_fx->inactive_coder_type_flag = 0; + move16(); + st_fx->last_L_frame = st_fx->L_frame; + move16(); + st_fx->last_core_brate = st_fx->core_brate; + move16(); + st_fx->last_core = -1; + move16(); + st_fx->last_extl = st_fx->extl; + move16(); - st_fx->flag_ACELP16k = set_ACELP_flag( st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1 ); - move16(); + st_fx->flag_ACELP16k = set_ACELP_flag( st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1 ); + move16(); - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * ACELP core parameters + *-----------------------------------------------------------------*/ - /* LSF initilaizations */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); + /* LSF initilaizations */ + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); + init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - set16_fx( st_fx->mem_MA_fx, 0, M ); + set16_fx( st_fx->mem_MA_fx, 0, M ); - st_fx->dm_fx.prev_state = 0; /* This corresponds to st_fx->dispMem in FLP */ - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); - FOR( i = 2; i < 8; i++ ) - { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + st_fx->dm_fx.prev_state = 0; /* This corresponds to st_fx->dispMem in FLP */ + move16(); + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + FOR( i = 2; i < 8; i++ ) + { + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + move16(); + } + st_fx->tilt_code_fx = 0; + move16(); + st_fx->gc_threshold_fx = 0; + move32(); + st_fx->last_good = UNVOICED_CLAS; + move16(); + st_fx->clas_dec = UNVOICED_CLAS; + move16(); + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + move16(); + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + move16(); + st_fx->lp_gainp_fx = 0; + move16(); + st_fx->lp_gainc_fx = 0; move16(); - } - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = 0; - move32(); - st_fx->last_good = UNVOICED_CLAS; - move16(); - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - st_fx->mem_deemph_fx = 0; - move16(); + /* AVQ pre-quantizer memory */ + st_fx->mem_preemp_preQ_fx = 0; + move16(); + st_fx->last_nq_preQ = 0; + move16(); + st_fx->use_acelp_preq = 0; + move16(); - set16_fx( st_fx->mem_syn1_fx, 0, M ); - set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; - move16(); - st_fx->stab_fac_smooth_fx = 0; - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - set16_fx( st_fx->mem_syn3_fx, 0, M ); + st_fx->mem_deemph_fx = 0; + move16(); - st_fx->stab_fac_smooth_lt_fx = 0; - move16(); - st_fx->log_energy_diff_lt_fx = 0; - move32(); - st_fx->log_energy_old_fx = 0; - move32(); + set16_fx( st_fx->mem_syn1_fx, 0, M ); + set16_fx( st_fx->mem_syn2_fx, 0, M ); + st_fx->stab_fac_fx = 0; + move16(); + st_fx->stab_fac_smooth_fx = 0; + move16(); + set16_fx( st_fx->agc_mem_fx, 0, 2 ); + set16_fx( st_fx->mem_syn3_fx, 0, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_12k8 ); + st_fx->stab_fac_smooth_lt_fx = 0; + move16(); + st_fx->log_energy_diff_lt_fx = 0; + move32(); + st_fx->log_energy_old_fx = 0; + move32(); - st_fx->mid_lsf_int = 0; - move16(); - st_fx->safety_net = 0; - move16(); + Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_12k8 ); - /* FEC */ - st_fx->scaling_flag = 0; - move16(); - st_fx->lp_ener_FEC_av = 500000; - move32(); - st_fx->lp_ener_FEC_max = 500000; - move32(); - st_fx->prev_bfi = 0; - move16(); - st_fx->lp_ener_FER_fx = 15360; /*60 in Q8*/ - move16(); - st_fx->old_enr_LP = 0; - move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); - st_fx->enr_old_fx = L_deposit_l( 0 ); - st_fx->bfi_pitch_fx = L_SUBFR_Q6; - move16(); - st_fx->bfi_pitch_frame = L_FRAME; - move16(); - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - st_fx->last_con_tcx = 0; - move16(); + st_fx->mid_lsf_int = 0; + move16(); + st_fx->safety_net = 0; + move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ + /* FEC */ + st_fx->scaling_flag = 0; + move16(); + st_fx->lp_ener_FEC_av = 500000; move32(); - } + st_fx->lp_ener_FEC_max = 500000; + move32(); + st_fx->prev_bfi = 0; + move16(); + st_fx->lp_ener_FER_fx = 15360; /*60 in Q8*/ + move16(); + st_fx->old_enr_LP = 0; + move16(); + st_fx->lp_ener_fx = L_deposit_l( 0 ); + st_fx->enr_old_fx = L_deposit_l( 0 ); + st_fx->bfi_pitch_fx = L_SUBFR_Q6; + move16(); + st_fx->bfi_pitch_frame = L_FRAME; + move16(); + set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); + st_fx->classifier_Q_mem_syn = 0; + move16(); + st_fx->last_con_tcx = 0; + move16(); - st_fx->upd_cnt = MAX_UPD_CNT; - move16(); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); + FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) + { + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ + move32(); + } - st_fx->seed_acelp = RANDOM_INITSEED; - move16(); - st_fx->seed = RANDOM_INITSEED; - move16(); - st_fx->nbLostCmpt = 0; - move16(); - st_fx->decision_hyst = 0; - move16(); - st_fx->unv_cnt = 0; - move16(); - st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 32767; /*1; Q15*/ - move16(); - st_fx->exc_pe_fx = 0; - move16(); - st_fx->Q_stat_noise = 31; - move16(); - st_fx->prev_coder_type = GENERIC; - move16(); + st_fx->upd_cnt = MAX_UPD_CNT; + move16(); + Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); + Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); + Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); + st_fx->seed_acelp = RANDOM_INITSEED; + move16(); + st_fx->seed = RANDOM_INITSEED; + move16(); + st_fx->nbLostCmpt = 0; + move16(); + st_fx->decision_hyst = 0; + move16(); + st_fx->unv_cnt = 0; + move16(); + st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ + st_fx->uv_count = 0; + move16(); + st_fx->act_count = 3; + move16(); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); + st_fx->noimix_seed = RANDOM_INITSEED; + move16(); + st_fx->min_alpha_fx = 32767; /*1; Q15*/ + move16(); + st_fx->exc_pe_fx = 0; + move16(); + st_fx->Q_stat_noise = 31; + move16(); + st_fx->prev_coder_type = GENERIC; + move16(); - st_fx->last_voice_factor_fx = 0; - move16(); + st_fx->tilt_wb_fx = 0; // Q11 + move16(); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + st_fx->last_voice_factor_fx = 0; + move16(); - st_fx->old_bfi_cnt = 0; - move16(); + set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + st_fx->Qprev_synth_buffer_fx = 15; + move16(); + set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); - /*-----------------------------------------------------------------* - * parameters for AC mode (GSC) - *-----------------------------------------------------------------*/ + st_fx->old_bfi_cnt = 0; + move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->GSC_IVAS_mode = 0; - move16(); - st_fx->Last_GSC_noisy_speech_flag = 0; - move16(); + /*-----------------------------------------------------------------* + * parameters for AC mode (GSC) + *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + st_fx->GSC_noisy_speech = 0; + move16(); + st_fx->GSC_IVAS_mode = 0; + move16(); + st_fx->Last_GSC_noisy_speech_flag = 0; + move16(); + + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } + IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); + } - GSC_dec_init_fx( st_fx->hGSCDec ); - } - ELSE - { - st_fx->hGSCDec = NULL; - } + GSC_dec_init_fx( st_fx->hGSCDec ); + } + ELSE + { + st_fx->hGSCDec = NULL; + } - /*-----------------------------------------------------------------* - * parameters for fast recovery (WI) - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * parameters for fast recovery (WI) + *-----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) + test(); + IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); + IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); + } + set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); + set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); + } + ELSE + { + st_fx->hWIDec = NULL; } - set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); - } - ELSE - { - st_fx->hWIDec = NULL; - } - /*-----------------------------------------------------------------* - * NB/formant post-filter - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * NB/formant post-filter + *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); + IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); + } + + Init_post_filter_fx( st_fx->hPFstat ); + st_fx->psf_lp_noise_fx = 0; + move16(); + } + ELSE + { + st_fx->hPFstat = NULL; } - Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; - move16(); - } - ELSE - { - st_fx->hPFstat = NULL; - } + /*-----------------------------------------------------------------* + * HF (6-7kHz) (zero) BWE parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * HF (6-7kHz) (zero) BWE parameters - *-----------------------------------------------------------------*/ + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); + } - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) + hf_synth_init_fx( st_fx->hBWE_zero ); + set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); + st_fx->hBWE_zero = NULL; } - hf_synth_init_fx( st_fx->hBWE_zero ); - set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); - } - ELSE - { - st_fx->hBWE_zero = NULL; - } + /*-----------------------------------------------------------------* + * LD music post-filter + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * LD music post-filter - *-----------------------------------------------------------------*/ + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); + } - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + music_postfilt_init( st_fx->hMusicPF ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); + st_fx->hMusicPF = NULL; } - music_postfilt_init( st_fx->hMusicPF ); - } - ELSE - { - st_fx->hMusicPF = NULL; - } + /*-----------------------------------------------------------------* + * CNG and DTX + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * CNG and DTX - *-----------------------------------------------------------------*/ + st_fx->first_CNG = 0; + move16(); + st_fx->cng_type = -1; + move16(); + st_fx->last_active_brate = ACELP_7k20; + move32(); + st_fx->last_CNG_L_frame = L_FRAME; + move16(); + st_fx->last_vad_fx = 0; + move16(); + st_fx->active_cnt = CNG_TYPE_HO; + move16(); - st_fx->first_CNG = 0; - move16(); - st_fx->cng_type = -1; - move16(); - st_fx->last_active_brate = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame = L_FRAME; - move16(); - st_fx->last_vad_fx = 0; - move16(); - st_fx->active_cnt = CNG_TYPE_HO; - move16(); + test(); + test(); + test(); + IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) + { + IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); + } - test(); - test(); - test(); - IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) - { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + td_cng_dec_init_fx( st_fx ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); + st_fx->hTdCngDec = NULL; } - td_cng_dec_init_fx( st_fx ); - } - ELSE - { - st_fx->hTdCngDec = NULL; - } - - st_fx->masa_sid_format = 0; - move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; - move16(); - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ + st_fx->masa_sid_format = 0; + move16(); + st_fx->Q_stat_noise_ge = GE_SHIFT; + move16(); - st_fx->prev_old_bfi = 0; - move16(); + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); + st_fx->prev_old_bfi = 0; + move16(); - set32_fx( st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set32_fx( st_fx->previoussynth_fx_32, 0, L_FRAME48k ); + set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); - IF( st_fx->element_mode == EVS_MONO ) - { - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); - } + set32_fx( st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + set32_fx( st_fx->previoussynth_fx_32, 0, L_FRAME48k ); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) - { - IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + IF( st_fx->element_mode == EVS_MONO ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); + set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); } - /* HQ core initialization */ - HQ_core_dec_init_fx( st_fx->hHQ_core ); - - IF( st_fx->element_mode == EVS_MONO ) + test(); + test(); + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) { - /* HQ NB FEC initialization */ - IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } - HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); + /* HQ core initialization */ + HQ_core_dec_init_fx( st_fx->hHQ_core ); + + IF( st_fx->element_mode == EVS_MONO ) + { + /* HQ NB FEC initialization */ + IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); + } + + HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); + } + ELSE + { + st_fx->hHQ_nbfec = NULL; + } } ELSE { + st_fx->hHQ_core = NULL; st_fx->hHQ_nbfec = NULL; } - } - ELSE - { - st_fx->hHQ_core = NULL; - st_fx->hHQ_nbfec = NULL; - } - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + test(); + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); - } + IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); + } + + td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); - td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); + st_fx->prev_Q_bwe_exc = 31; + move16(); + } + ELSE + { + st_fx->hBWE_TD = NULL; + } - st_fx->prev_Q_bwe_exc = 31; + st_fx->old_bwe_delay = -1; /*Q0*/ move16(); - } - ELSE - { - st_fx->hBWE_TD = NULL; - } + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); - st_fx->old_bwe_delay = -1; /*Q0*/ - move16(); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + test(); + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); + } - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + fd_bwe_dec_init_fx( st_fx->hBWE_FD ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); + st_fx->hBWE_FD = NULL; } - fd_bwe_dec_init_fx( st_fx->hBWE_FD ); - } - ELSE - { - st_fx->hBWE_FD = NULL; - } + /*-----------------------------------------------------------------* + * WB/SWB bandwidth switching parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * WB/SWB bandwidth switching parameters - *-----------------------------------------------------------------*/ + st_fx->tilt_swb_fx = 0; // Q24 + move16(); + st_fx->prev_ener_shb_fx = 0; // Q1 + move16(); + st_fx->prev_enerLH_fx = 0; // Q1 + move16(); + st_fx->enerLH_fx = L_deposit_l( 0 ); + st_fx->enerLL_fx = L_deposit_l( 0 ); + st_fx->prev_enerLL_fx = 0; + move16(); + st_fx->prev_fractive = 0; + move16(); + st_fx->prev_bws_cnt = 0; + move16(); + st_fx->bws_cnt = N_WS2N_FRAMES; + move16(); + st_fx->bws_cnt1 = N_NS2W_FRAMES; + move16(); + st_fx->attenu_fx = 3277; // Q15 + move16(); + st_fx->last_inner_frame = L_FRAME8k; + move16(); - st_fx->tilt_swb_fx = 0; // Q24 - move16(); - st_fx->prev_ener_shb_fx = 0; // Q1 - move16(); - st_fx->prev_enerLH_fx = 0; // Q1 - move16(); - st_fx->enerLH_fx = L_deposit_l( 0 ); - st_fx->enerLL_fx = L_deposit_l( 0 ); - st_fx->prev_enerLL_fx = 0; - move16(); - st_fx->prev_fractive = 0; - move16(); - st_fx->prev_bws_cnt = 0; - move16(); - st_fx->bws_cnt = N_WS2N_FRAMES; - move16(); - st_fx->bws_cnt1 = N_NS2W_FRAMES; - move16(); - st_fx->attenu_fx = 3277; // Q15 - move16(); - st_fx->last_inner_frame = L_FRAME8k; - move16(); + /*-----------------------------------------------------------------* + * HR SWB BWE parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ + IF( ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); + } - IF( ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) + hr_bwe_dec_init( st_fx->hBWE_FD_HR ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); + st_fx->hBWE_FD_HR = NULL; } - hr_bwe_dec_init( st_fx->hBWE_FD_HR ); - } - ELSE - { - st_fx->hBWE_FD_HR = NULL; - } + /*----------------------------------------------------------------------------------* + * AMR-WB IO mode parameters + *----------------------------------------------------------------------------------*/ + test(); + IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); + } - /*----------------------------------------------------------------------------------* - * AMR-WB IO mode parameters - *----------------------------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) + /* AMR-WB IO init */ + amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); + + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); + st_fx->hAmrwb_IO = NULL; } - /* AMR-WB IO init */ - amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); + /*-----------------------------------------------------------------* + * channel-aware mode parameters + *-----------------------------------------------------------------*/ - /* AMR-WB IO HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - } - ELSE - { - st_fx->hAmrwb_IO = NULL; - } + set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); + st_fx->use_partial_copy = 0; + move16(); + st_fx->prev_use_partial_copy = 0; + move16(); + st_fx->rf_flag = 0; + move16(); + st_fx->rf_flag_last = 0; + move16(); + st_fx->prev_rf_frame_type = 0; + move16(); + st_fx->next_coder_type = 0; + move16(); + st_fx->rf_target_bits = 0; + move16(); + st_fx->rf_indx_nelp_fid = 0; + move16(); + st_fx->rf_indx_nelp_iG1 = 0; + move16(); + st_fx->rf_indx_nelp_iG2[0] = 0; + move16(); + st_fx->rf_indx_nelp_iG2[1] = 0; + move16(); + st_fx->rf_indx_tbeGainFr = 0; + move16(); - /*-----------------------------------------------------------------* - * channel-aware mode parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Bass post-filter parameters + *-----------------------------------------------------------------*/ - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - st_fx->use_partial_copy = 0; - move16(); - st_fx->prev_use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - move16(); - st_fx->prev_rf_frame_type = 0; - move16(); - st_fx->next_coder_type = 0; - move16(); - st_fx->rf_target_bits = 0; - move16(); - st_fx->rf_indx_nelp_fid = 0; - move16(); - st_fx->rf_indx_nelp_iG1 = 0; - move16(); - st_fx->rf_indx_nelp_iG2[0] = 0; - move16(); - st_fx->rf_indx_nelp_iG2[1] = 0; - move16(); - st_fx->rf_indx_tbeGainFr = 0; - move16(); + st_fx->bpf_off = 0; + move16(); - /*-----------------------------------------------------------------* - * Bass post-filter parameters - *-----------------------------------------------------------------*/ + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); + } - st_fx->bpf_off = 0; - move16(); + bass_psfilter_init_fx( st_fx->hBPF ); + } + ELSE + { + st_fx->hBPF = NULL; + } - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + /*-----------------------------------------------------------------* + * FD BPF & resampling tools parameters + *-----------------------------------------------------------------*/ + + IF( st_fx->element_mode == EVS_MONO ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) + { + return error; + } } + ELSE + { + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + st_fx->cldfbAna = NULL; + st_fx->cldfbBPF = NULL; + } - bass_psfilter_init_fx( st_fx->hBPF ); - } - ELSE - { - st_fx->hBPF = NULL; - } + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + { + return error; + } + } - /*-----------------------------------------------------------------* - * FD BPF & resampling tools parameters - *-----------------------------------------------------------------*/ + st_fx->cldfbSynHB = NULL; + st_fx->last_active_bandsToZero_bwdec = 0; + move16(); + st_fx->perc_bwddec = 0; + move16(); + st_fx->last_flag_filter_NB = 0; + move16(); + st_fx->active_frame_cnt_bwddec = 0; + move16(); + st_fx->total_frame_cnt_bwddec = 0; + move16(); + set16_fx( st_fx->flag_buffer, 0, 20 ); + st_fx->avg_nrg_LT = 0; + move32(); + + /*-----------------------------------------------------------------* + * Noise gate parameters + *-----------------------------------------------------------------*/ + + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); + st_fx->old_Aq_12_8_fx[0] = ONE_IN_Q12; + move16(); + st_fx->Ng_ener_ST_fx = -13056; /*-51 IN Q8*/ + move16(); + st_fx->old_Es_pred_fx = 0; + move16(); + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); + st_fx->old_Aq_12_8_fx[0] = 4096; /*1 in Q12*/ + move16(); + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + IF( st_fx->element_mode == EVS_MONO ) + { + IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); + } - IF( st_fx->element_mode == EVS_MONO ) - { - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) + sc_vbr_dec_init( st_fx->hSC_VBR ); + } + ELSE { - return error; + st_fx->hSC_VBR = NULL; } - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) + st_fx->last_ppp_mode_dec = 0; + move16(); + st_fx->old_ppp_mode = 0; + move16(); + st_fx->ppp_mode_dec = 0; + move16(); + st_fx->last_nelp_mode_dec = 0; + move16(); + st_fx->nelp_mode_dec = 0; + move16(); + st_fx->prev_gain_pit_dec_fx = 0; + move16(); + st_fx->prev_tilt_code_dec_fx = 0; + move16(); + st_fx->vbr_hw_BWE_disable_dec = 0; + move16(); + st_fx->last_vbr_hw_BWE_disable_dec = 0; + move16(); + + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ + + /* TCX-LTP */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - return error; + IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); + } } - - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) + ELSE { - return error; + st_fx->hTcxLtpDec = NULL; } - } - ELSE - { - test(); + + /* TCX core */ test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { - return error; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); } - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); + + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); + } + ELSE + { + st_fx->hTcxDec = NULL; + } + + /* TCX config. data structure */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { - return error; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } + st_fx->hTcxCfg->tcx_mdct_window_length = L_FRAME32k / 2; + move16(); } ELSE { - st_fx->cldfbAna = NULL; - st_fx->cldfbBPF = NULL; + st_fx->hTcxCfg = NULL; } - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) + /* Tonal MDCT concealment data structure */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - return error; + IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); + } + } + ELSE + { + st_fx->hTonalMDCTConc = NULL; } - } - - st_fx->cldfbSynHB = NULL; - st_fx->last_active_bandsToZero_bwdec = 0; - move16(); - st_fx->perc_bwddec = 0; - move16(); - st_fx->last_flag_filter_NB = 0; - move16(); - st_fx->active_frame_cnt_bwddec = 0; - move16(); - st_fx->total_frame_cnt_bwddec = 0; - move16(); - set16_fx( st_fx->flag_buffer, 0, 20 ); - st_fx->avg_nrg_LT = 0; - move32(); - - /*-----------------------------------------------------------------* - * Noise gate parameters - *-----------------------------------------------------------------*/ - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = ONE_IN_Q12; - move16(); - st_fx->Ng_ener_ST_fx = -13056; /*-51 IN Q8*/ - move16(); - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; /*1 in Q12*/ - move16(); + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + } - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) + st_fx->igf = 0; + move16(); + init_igf_dec( st_fx->hIGFDec ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); + st_fx->hIGFDec = NULL; } - sc_vbr_dec_init( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } - - st_fx->last_ppp_mode_dec = 0; - move16(); - st_fx->old_ppp_mode = 0; - move16(); - st_fx->ppp_mode_dec = 0; - move16(); - st_fx->last_nelp_mode_dec = 0; - move16(); - st_fx->nelp_mode_dec = 0; - move16(); - st_fx->prev_gain_pit_dec_fx = 0; - move16(); - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - st_fx->vbr_hw_BWE_disable_dec = 0; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec = 0; - move16(); - - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ - /* TCX-LTP */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); + IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); + } } - } - ELSE - { - st_fx->hTcxLtpDec = NULL; - } - - /* TCX core */ - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); + st_fx->hPlcInfo = NULL; } - set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); - } - ELSE - { - st_fx->hTcxDec = NULL; - } - - /* TCX config. data structure */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + IF( st_fx->element_mode == EVS_MONO ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); + IF( ( st_fx->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); + } } - st_fx->hTcxCfg->tcx_mdct_window_length = L_FRAME32k / 2; - move16(); - } - ELSE - { - st_fx->hTcxCfg = NULL; - } - - /* Tonal MDCT concealment data structure */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); + st_fx->hTECDec = NULL; } - } - ELSE - { - st_fx->hTonalMDCTConc = NULL; - } - - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + /* Init Decoder */ + IF( st_fx->element_mode == EVS_MONO ) + { + open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); + } + ELSE { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); } - st_fx->igf = 0; + /* PLC mode initialization */ + st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; move16(); - init_igf_dec( st_fx->hIGFDec ); - } - ELSE - { - st_fx->hIGFDec = NULL; - } - /*-----------------------------------------------------------------* - * Mode 2 initialization - *-----------------------------------------------------------------*/ + /* Init bandwidth / frame_type */ + st_fx->m_frame_type = ACTIVE_FRAME; + move16(); + st_fx->m_old_frame_type = ACTIVE_FRAME; + move16(); - IF( ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) + IF( st_fx->element_mode == EVS_MONO ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + } + ELSE + { + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + } } - } - ELSE - { - st_fx->hPlcInfo = NULL; - } - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) + /*-----------------------------------------------------------------* + * FD-CNG decoder + *-----------------------------------------------------------------*/ + + test(); + test(); + test(); + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); + /* Create FD_CNG instance */ + IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* Init FD-CNG */ +#ifdef FIX_2245_INIT_FD_CNG_EVS + initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); +#else + initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); +#endif + } + ELSE + { + st_fx->hFdCngDec = NULL; } - } - ELSE - { - st_fx->hTECDec = NULL; - } - /* Init Decoder */ - IF( st_fx->element_mode == EVS_MONO ) - { - open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); - } - ELSE - { - Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; + st_fx->cngTDLevel = 0; move16(); + st_fx->cngTDLevel_e = 0; move16(); + st_fx->lp_noise = -167772160l /*-20.f Q23*/; + move32(); + st_fx->force_lpd_reset = 0; move16(); + + + /*-----------------------------------------------------------------* + * initialzie Q values + *-----------------------------------------------------------------*/ + + st_fx->Q_syn2 = 0; move16(); + st_fx->Q_exc = 8; move16(); + st_fx->prev_Q_exc = 0; move16(); + st_fx->Q_syn = 0; move16(); + st_fx->prev_Q_syn = 0; move16(); - open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); - } - - /* PLC mode initialization */ - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); - - /* Init bandwidth / frame_type */ - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - st_fx->m_old_frame_type = ACTIVE_FRAME; - move16(); - IF( st_fx->element_mode == EVS_MONO ) - { - resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); - resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); - } - ELSE - { - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + FOR( i = 0; i < L_Q_MEM; i++ ) { - resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + st_fx->Q_subfr[i] = 8; + move16(); } - } - - /*-----------------------------------------------------------------* - * FD-CNG decoder - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) - { - /* Create FD_CNG instance */ - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) - { - return error; - } + st_fx->prev_Q_exc_fr = 0; + move16(); + st_fx->prev_Q_syn_fr = 0; + move16(); - /* Init FD-CNG */ -#ifdef FIX_2245_INIT_FD_CNG_EVS - initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); -#else - initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); -#endif - } - ELSE - { - st_fx->hFdCngDec = NULL; - } + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ - st_fx->cngTDLevel = 0; - move16(); - st_fx->cngTDLevel_e = 0; - move16(); - st_fx->lp_noise = -167772160l /*-20.f Q23*/; - move32(); - st_fx->force_lpd_reset = 0; - move16(); + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + move16(); + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + move16(); + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + move16(); + st_fx->cng_ism_flag = 0; + move16(); + return error; + } - /*-----------------------------------------------------------------* - * initialzie Q values - *-----------------------------------------------------------------*/ - st_fx->Q_syn2 = 0; - move16(); - st_fx->Q_exc = 8; - move16(); - st_fx->prev_Q_exc = 0; - move16(); - st_fx->Q_syn = 0; - move16(); - st_fx->prev_Q_syn = 0; - move16(); + /*----------------------------------------------------------------------* + * reset_preecho_dec() + * + * Initialization of static variables for pre-echo + *----------------------------------------------------------------------*/ - FOR( i = 0; i < L_Q_MEM; i++ ) + void reset_preecho_dec_fx( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ + ) { - st_fx->Q_subfr[i] = 8; + hHQ_core->memfilt_lb_fx = 0; + move16(); + hHQ_core->mean_prev_hb_fx = L_deposit_l( 0 ); + hHQ_core->smoothmem_fx = 32767; + move16(); + hHQ_core->mean_prev_fx = L_deposit_l( 0 ); + hHQ_core->mean_prev_nc_fx = L_deposit_l( 0 ); + hHQ_core->wmold_hb_fx = 32767; + move16(); + hHQ_core->prevflag = 0; + move16(); + hHQ_core->pastpre = 0; move16(); - } - - st_fx->prev_Q_exc_fr = 0; - move16(); - st_fx->prev_Q_syn_fr = 0; - move16(); - - /*-----------------------------------------------------------------* - * IVAS parameters - *-----------------------------------------------------------------*/ - - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); - st_fx->cng_ism_flag = 0; - move16(); - - return error; -} - - -/*----------------------------------------------------------------------* - * reset_preecho_dec() - * - * Initialization of static variables for pre-echo - *----------------------------------------------------------------------*/ - -void reset_preecho_dec_fx( - HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ -) -{ - hHQ_core->memfilt_lb_fx = 0; - move16(); - hHQ_core->mean_prev_hb_fx = L_deposit_l( 0 ); - hHQ_core->smoothmem_fx = 32767; - move16(); - hHQ_core->mean_prev_fx = L_deposit_l( 0 ); - hHQ_core->mean_prev_nc_fx = L_deposit_l( 0 ); - hHQ_core->wmold_hb_fx = 32767; - move16(); - hHQ_core->prevflag = 0; - move16(); - hHQ_core->pastpre = 0; - move16(); - return; -} + return; + } -/*----------------------------------------------------------------------* - * destroy_cldfb_decoder_fx() - * - * Free memory which was allocated in init_decoder() - *----------------------------------------------------------------------*/ + /*----------------------------------------------------------------------* + * destroy_cldfb_decoder_fx() + * + * Free memory which was allocated in init_decoder() + *----------------------------------------------------------------------*/ -void destroy_cldfb_decoder_fx( - Decoder_State *st_fx /* o: Decoder static variables structure */ -) -{ - /* CLDFB BPF & resampling tools */ - deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ - deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ - deleteCldfb_fx( &st_fx->cldfbSynHB ); + void destroy_cldfb_decoder_fx( + Decoder_State * st_fx /* o: Decoder static variables structure */ + ) + { + /* CLDFB BPF & resampling tools */ + deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ + deleteCldfb_fx( &st_fx->cldfbSynHB ); - deleteFdCngDec_fx( &st_fx->hFdCngDec ); + deleteFdCngDec_fx( &st_fx->hFdCngDec ); - return; -} + return; + } -- GitLab From 1f8dfc0fb3aab00b97beb61fbdac41c070be2949 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 5 Dec 2025 21:52:25 +0100 Subject: [PATCH 8/8] clang-format --- lib_dec/init_dec_fx.c | 1548 ++++++++++++++++++++--------------------- 1 file changed, 774 insertions(+), 774 deletions(-) diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 65b2ea925..763b581ad 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -113,953 +113,953 @@ ivas_error init_decoder_fx( move16(); } #else - st_fx->bwidth = NB; - move16(); - st_fx->last_bwidth = NB; - move16(); + st_fx->bwidth = NB; + move16(); + st_fx->last_bwidth = NB; + move16(); #endif - st_fx->extl_brate = 0; - move16(); + st_fx->extl_brate = 0; + move16(); - st_fx->coder_type = GENERIC; /* low-rate mode flag */ - move16(); - st_fx->last_coder_type = GENERIC; - move16(); - st_fx->inactive_coder_type_flag = 0; - move16(); - st_fx->last_L_frame = st_fx->L_frame; - move16(); - st_fx->last_core_brate = st_fx->core_brate; - move16(); - st_fx->last_core = -1; - move16(); - st_fx->last_extl = st_fx->extl; - move16(); + st_fx->coder_type = GENERIC; /* low-rate mode flag */ + move16(); + st_fx->last_coder_type = GENERIC; + move16(); + st_fx->inactive_coder_type_flag = 0; + move16(); + st_fx->last_L_frame = st_fx->L_frame; + move16(); + st_fx->last_core_brate = st_fx->core_brate; + move16(); + st_fx->last_core = -1; + move16(); + st_fx->last_extl = st_fx->extl; + move16(); - st_fx->flag_ACELP16k = set_ACELP_flag( st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1 ); - move16(); + st_fx->flag_ACELP16k = set_ACELP_flag( st_fx->element_mode, st_fx->total_brate, st_fx->total_brate, idchan, 0, -1, -1 ); + move16(); - /*-----------------------------------------------------------------* - * ACELP core parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * ACELP core parameters + *-----------------------------------------------------------------*/ - /* LSF initilaizations */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); + /* LSF initilaizations */ + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); - init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); + init_lvq_fx( st_fx->offset_scale1_fx, st_fx->offset_scale2_fx, st_fx->offset_scale1_p_fx, st_fx->offset_scale2_p_fx, st_fx->no_scales_fx, st_fx->no_scales_p_fx ); - set16_fx( st_fx->mem_MA_fx, 0, M ); + set16_fx( st_fx->mem_MA_fx, 0, M ); - st_fx->dm_fx.prev_state = 0; /* This corresponds to st_fx->dispMem in FLP */ - move16(); - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); - FOR( i = 2; i < 8; i++ ) - { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; - move16(); - } - st_fx->tilt_code_fx = 0; - move16(); - st_fx->gc_threshold_fx = 0; - move32(); - st_fx->last_good = UNVOICED_CLAS; - move16(); - st_fx->clas_dec = UNVOICED_CLAS; - move16(); - st_fx->low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ - move16(); - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; + st_fx->dm_fx.prev_state = 0; /* This corresponds to st_fx->dispMem in FLP */ + move16(); + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + FOR( i = 2; i < 8; i++ ) + { + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; move16(); + } + st_fx->tilt_code_fx = 0; + move16(); + st_fx->gc_threshold_fx = 0; + move32(); + st_fx->last_good = UNVOICED_CLAS; + move16(); + st_fx->clas_dec = UNVOICED_CLAS; + move16(); + st_fx->low_rate_mode = 0; /* low-rate mode flag */ + move16(); + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + move16(); + st_fx->lp_gainp_fx = 0; + move16(); + st_fx->lp_gainc_fx = 0; + move16(); - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - - /* AVQ pre-quantizer memory */ - st_fx->mem_preemp_preQ_fx = 0; - move16(); - st_fx->last_nq_preQ = 0; - move16(); - st_fx->use_acelp_preq = 0; - move16(); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); - st_fx->mem_deemph_fx = 0; - move16(); + /* AVQ pre-quantizer memory */ + st_fx->mem_preemp_preQ_fx = 0; + move16(); + st_fx->last_nq_preQ = 0; + move16(); + st_fx->use_acelp_preq = 0; + move16(); - set16_fx( st_fx->mem_syn1_fx, 0, M ); - set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; - move16(); - st_fx->stab_fac_smooth_fx = 0; - move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); - set16_fx( st_fx->mem_syn3_fx, 0, M ); + st_fx->mem_deemph_fx = 0; + move16(); - st_fx->stab_fac_smooth_lt_fx = 0; - move16(); - st_fx->log_energy_diff_lt_fx = 0; - move32(); - st_fx->log_energy_old_fx = 0; - move32(); + set16_fx( st_fx->mem_syn1_fx, 0, M ); + set16_fx( st_fx->mem_syn2_fx, 0, M ); + st_fx->stab_fac_fx = 0; + move16(); + st_fx->stab_fac_smooth_fx = 0; + move16(); + set16_fx( st_fx->agc_mem_fx, 0, 2 ); + set16_fx( st_fx->mem_syn3_fx, 0, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_12k8 ); + st_fx->stab_fac_smooth_lt_fx = 0; + move16(); + st_fx->log_energy_diff_lt_fx = 0; + move32(); + st_fx->log_energy_old_fx = 0; + move32(); - st_fx->mid_lsf_int = 0; - move16(); - st_fx->safety_net = 0; - move16(); + Copy( GEWB_Ave_fx, st_fx->lsf_old_fx, M ); + lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, INT_FS_12k8 ); - /* FEC */ - st_fx->scaling_flag = 0; - move16(); - st_fx->lp_ener_FEC_av = 500000; - move32(); - st_fx->lp_ener_FEC_max = 500000; - move32(); - st_fx->prev_bfi = 0; - move16(); - st_fx->lp_ener_FER_fx = 15360; /*60 in Q8*/ - move16(); - st_fx->old_enr_LP = 0; - move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); - st_fx->enr_old_fx = L_deposit_l( 0 ); - st_fx->bfi_pitch_fx = L_SUBFR_Q6; - move16(); - st_fx->bfi_pitch_frame = L_FRAME; - move16(); - set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); - st_fx->classifier_Q_mem_syn = 0; - move16(); - st_fx->last_con_tcx = 0; - move16(); + st_fx->mid_lsf_int = 0; + move16(); + st_fx->safety_net = 0; + move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) - { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ - move32(); - } + /* FEC */ + st_fx->scaling_flag = 0; + move16(); + st_fx->lp_ener_FEC_av = 500000; + move32(); + st_fx->lp_ener_FEC_max = 500000; + move32(); + st_fx->prev_bfi = 0; + move16(); + st_fx->lp_ener_FER_fx = 15360; /*60 in Q8*/ + move16(); + st_fx->old_enr_LP = 0; + move16(); + st_fx->lp_ener_fx = L_deposit_l( 0 ); + st_fx->enr_old_fx = L_deposit_l( 0 ); + st_fx->bfi_pitch_fx = L_SUBFR_Q6; + move16(); + st_fx->bfi_pitch_frame = L_FRAME; + move16(); + set16_fx( st_fx->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); + st_fx->classifier_Q_mem_syn = 0; + move16(); + st_fx->last_con_tcx = 0; + move16(); - st_fx->upd_cnt = MAX_UPD_CNT; - move16(); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); + FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) + { + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ + move32(); + } - st_fx->seed_acelp = RANDOM_INITSEED; - move16(); - st_fx->seed = RANDOM_INITSEED; - move16(); - st_fx->nbLostCmpt = 0; - move16(); - st_fx->decision_hyst = 0; - move16(); - st_fx->unv_cnt = 0; - move16(); - st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ - st_fx->uv_count = 0; - move16(); - st_fx->act_count = 3; - move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); - st_fx->noimix_seed = RANDOM_INITSEED; - move16(); - st_fx->min_alpha_fx = 32767; /*1; Q15*/ - move16(); - st_fx->exc_pe_fx = 0; - move16(); - st_fx->Q_stat_noise = 31; - move16(); - st_fx->prev_coder_type = GENERIC; - move16(); + st_fx->upd_cnt = MAX_UPD_CNT; + move16(); + Copy( GEWB_Ave_fx, st_fx->lsfoldbfi0_fx, M ); + Copy( GEWB_Ave_fx, st_fx->lsfoldbfi1_fx, M ); + Copy( GEWB_Ave_fx, st_fx->lsf_adaptive_mean_fx, M ); - st_fx->tilt_wb_fx = 0; // Q11 - move16(); + st_fx->seed_acelp = RANDOM_INITSEED; + move16(); + st_fx->seed = RANDOM_INITSEED; + move16(); + st_fx->nbLostCmpt = 0; + move16(); + st_fx->decision_hyst = 0; + move16(); + st_fx->unv_cnt = 0; + move16(); + st_fx->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ + st_fx->uv_count = 0; + move16(); + st_fx->act_count = 3; + move16(); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); + st_fx->noimix_seed = RANDOM_INITSEED; + move16(); + st_fx->min_alpha_fx = 32767; /*1; Q15*/ + move16(); + st_fx->exc_pe_fx = 0; + move16(); + st_fx->Q_stat_noise = 31; + move16(); + st_fx->prev_coder_type = GENERIC; + move16(); - st_fx->last_voice_factor_fx = 0; - move16(); + st_fx->tilt_wb_fx = 0; // Q11 + move16(); - set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); - st_fx->Qprev_synth_buffer_fx = 15; - move16(); - set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + st_fx->last_voice_factor_fx = 0; + move16(); - st_fx->old_bfi_cnt = 0; - move16(); + set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); + st_fx->Qprev_synth_buffer_fx = 15; + move16(); + set32_fx( st_fx->prev_synth_buffer32_fx, 0, NS2SA_FX2( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ) ); - /*-----------------------------------------------------------------* - * parameters for AC mode (GSC) - *-----------------------------------------------------------------*/ + st_fx->old_bfi_cnt = 0; + move16(); - st_fx->GSC_noisy_speech = 0; - move16(); - st_fx->GSC_IVAS_mode = 0; - move16(); - st_fx->Last_GSC_noisy_speech_flag = 0; - move16(); + /*-----------------------------------------------------------------* + * parameters for AC mode (GSC) + *-----------------------------------------------------------------*/ - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); - } + st_fx->GSC_noisy_speech = 0; + move16(); + st_fx->GSC_IVAS_mode = 0; + move16(); + st_fx->Last_GSC_noisy_speech_flag = 0; + move16(); - GSC_dec_init_fx( st_fx->hGSCDec ); - } - ELSE + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) { - st_fx->hGSCDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - /*-----------------------------------------------------------------* - * parameters for fast recovery (WI) - *-----------------------------------------------------------------*/ + GSC_dec_init_fx( st_fx->hGSCDec ); + } + ELSE + { + st_fx->hGSCDec = NULL; + } - test(); - IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); - } - set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); - set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); - } - ELSE + /*-----------------------------------------------------------------* + * parameters for fast recovery (WI) + *-----------------------------------------------------------------*/ + + test(); + IF( EQ_32( st_fx->output_Fs, 16000 ) && ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) { - st_fx->hWIDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FEC WI\n" ) ); } + set16_fx( st_fx->hWIDec->old_exc2_fx, 0, L_EXC_MEM ); + set16_fx( st_fx->hWIDec->old_syn2_fx, 0, L_EXC_MEM ); + } + ELSE + { + st_fx->hWIDec = NULL; + } - /*-----------------------------------------------------------------* - * NB/formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); - } + /*-----------------------------------------------------------------* + * NB/formant post-filter + *-----------------------------------------------------------------*/ - Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; - move16(); - } - ELSE + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) { - st_fx->hPFstat = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); } - /*-----------------------------------------------------------------* - * HF (6-7kHz) (zero) BWE parameters - *-----------------------------------------------------------------*/ + Init_post_filter_fx( st_fx->hPFstat ); + st_fx->psf_lp_noise_fx = 0; + move16(); + } + ELSE + { + st_fx->hPFstat = NULL; + } - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); - } + /*-----------------------------------------------------------------* + * HF (6-7kHz) (zero) BWE parameters + *-----------------------------------------------------------------*/ - hf_synth_init_fx( st_fx->hBWE_zero ); - set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); - } - ELSE + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) { - st_fx->hBWE_zero = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); } - /*-----------------------------------------------------------------* - * LD music post-filter - *-----------------------------------------------------------------*/ + hf_synth_init_fx( st_fx->hBWE_zero ); + set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); + } + ELSE + { + st_fx->hBWE_zero = NULL; + } - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); - } + /*-----------------------------------------------------------------* + * LD music post-filter + *-----------------------------------------------------------------*/ - music_postfilt_init( st_fx->hMusicPF ); - } - ELSE + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) { - st_fx->hMusicPF = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); } - /*-----------------------------------------------------------------* - * CNG and DTX - *-----------------------------------------------------------------*/ + music_postfilt_init( st_fx->hMusicPF ); + } + ELSE + { + st_fx->hMusicPF = NULL; + } - st_fx->first_CNG = 0; - move16(); - st_fx->cng_type = -1; - move16(); - st_fx->last_active_brate = ACELP_7k20; - move32(); - st_fx->last_CNG_L_frame = L_FRAME; - move16(); - st_fx->last_vad_fx = 0; - move16(); - st_fx->active_cnt = CNG_TYPE_HO; - move16(); + /*-----------------------------------------------------------------* + * CNG and DTX + *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) - { - IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); - } + st_fx->first_CNG = 0; + move16(); + st_fx->cng_type = -1; + move16(); + st_fx->last_active_brate = ACELP_7k20; + move32(); + st_fx->last_CNG_L_frame = L_FRAME; + move16(); + st_fx->last_vad_fx = 0; + move16(); + st_fx->active_cnt = CNG_TYPE_HO; + move16(); - td_cng_dec_init_fx( st_fx ); - } - ELSE + test(); + test(); + test(); + IF( idchan == 0 && ( ( st_fx->element_mode == EVS_MONO ) || EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) ) + { + IF( ( st_fx->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { - st_fx->hTdCngDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); } - st_fx->masa_sid_format = 0; - move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; - move16(); - - /*-----------------------------------------------------------------* - * HQ core parameters - *-----------------------------------------------------------------*/ - - st_fx->prev_old_bfi = 0; - move16(); + td_cng_dec_init_fx( st_fx ); + } + ELSE + { + st_fx->hTdCngDec = NULL; + } - set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); + st_fx->masa_sid_format = 0; + move16(); + st_fx->Q_stat_noise_ge = GE_SHIFT; + move16(); - set32_fx( st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); - set32_fx( st_fx->previoussynth_fx_32, 0, L_FRAME48k ); + /*-----------------------------------------------------------------* + * HQ core parameters + *-----------------------------------------------------------------*/ - IF( st_fx->element_mode == EVS_MONO ) - { - set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); - } + st_fx->prev_old_bfi = 0; + move16(); - test(); - test(); - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) - { - IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); - } + set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + set16_fx( st_fx->previoussynth_fx, 0, L_FRAME48k ); - /* HQ core initialization */ - HQ_core_dec_init_fx( st_fx->hHQ_core ); + set32_fx( st_fx->delay_buf_out32_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); + set32_fx( st_fx->previoussynth_fx_32, 0, L_FRAME48k ); - IF( st_fx->element_mode == EVS_MONO ) - { - /* HQ NB FEC initialization */ - IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); - } + IF( st_fx->element_mode == EVS_MONO ) + { + set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); + } - HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); - } - ELSE - { - st_fx->hHQ_nbfec = NULL; - } - } - ELSE + test(); + test(); + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( st_fx->element_mode, IVAS_SCE ) || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) + { + IF( ( st_fx->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) { - st_fx->hHQ_core = NULL; - st_fx->hHQ_nbfec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); } - /*-----------------------------------------------------------------* - * TBE parameters - *-----------------------------------------------------------------*/ + /* HQ core initialization */ + HQ_core_dec_init_fx( st_fx->hHQ_core ); - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( st_fx->element_mode == EVS_MONO ) { - IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + /* HQ NB FEC initialization */ + IF( ( st_fx->hHQ_nbfec = (HQ_NBFEC_HANDLE) malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); } - td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); - - st_fx->prev_Q_bwe_exc = 31; - move16(); + HQ_nbfec_init_fx( st_fx->hHQ_nbfec ); } ELSE { - st_fx->hBWE_TD = NULL; + st_fx->hHQ_nbfec = NULL; } + } + ELSE + { + st_fx->hHQ_core = NULL; + st_fx->hHQ_nbfec = NULL; + } - st_fx->old_bwe_delay = -1; /*Q0*/ - move16(); - set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); - - /*-----------------------------------------------------------------* - * SWB BWE parameters - *-----------------------------------------------------------------*/ - test(); - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); - } + /*-----------------------------------------------------------------* + * TBE parameters + *-----------------------------------------------------------------*/ - fd_bwe_dec_init_fx( st_fx->hBWE_FD ); - } - ELSE + test(); + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { - st_fx->hBWE_FD = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } - /*-----------------------------------------------------------------* - * WB/SWB bandwidth switching parameters - *-----------------------------------------------------------------*/ + td_bwe_dec_init_fx( st_fx->hBWE_TD, st_fx->extl, st_fx->output_Fs ); - st_fx->tilt_swb_fx = 0; // Q24 - move16(); - st_fx->prev_ener_shb_fx = 0; // Q1 - move16(); - st_fx->prev_enerLH_fx = 0; // Q1 + st_fx->prev_Q_bwe_exc = 31; move16(); - st_fx->enerLH_fx = L_deposit_l( 0 ); - st_fx->enerLL_fx = L_deposit_l( 0 ); - st_fx->prev_enerLL_fx = 0; - move16(); - st_fx->prev_fractive = 0; - move16(); - st_fx->prev_bws_cnt = 0; - move16(); - st_fx->bws_cnt = N_WS2N_FRAMES; - move16(); - st_fx->bws_cnt1 = N_NS2W_FRAMES; - move16(); - st_fx->attenu_fx = 3277; // Q15 - move16(); - st_fx->last_inner_frame = L_FRAME8k; - move16(); - - /*-----------------------------------------------------------------* - * HR SWB BWE parameters - *-----------------------------------------------------------------*/ - - IF( ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); - } - - hr_bwe_dec_init( st_fx->hBWE_FD_HR ); - } - ELSE - { - st_fx->hBWE_FD_HR = NULL; - } - - /*----------------------------------------------------------------------------------* - * AMR-WB IO mode parameters - *----------------------------------------------------------------------------------*/ - test(); - IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); - } + } + ELSE + { + st_fx->hBWE_TD = NULL; + } - /* AMR-WB IO init */ - amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); + st_fx->old_bwe_delay = -1; /*Q0*/ + move16(); + set16_fx( st_fx->hb_prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS ) ); - /* AMR-WB IO HF synth init */ - hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); - } - ELSE + /*-----------------------------------------------------------------* + * SWB BWE parameters + *-----------------------------------------------------------------*/ + test(); + IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) { - st_fx->hAmrwb_IO = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); } - /*-----------------------------------------------------------------* - * channel-aware mode parameters - *-----------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - st_fx->use_partial_copy = 0; - move16(); - st_fx->prev_use_partial_copy = 0; - move16(); - st_fx->rf_flag = 0; - move16(); - st_fx->rf_flag_last = 0; - move16(); - st_fx->prev_rf_frame_type = 0; - move16(); - st_fx->next_coder_type = 0; - move16(); - st_fx->rf_target_bits = 0; - move16(); - st_fx->rf_indx_nelp_fid = 0; - move16(); - st_fx->rf_indx_nelp_iG1 = 0; - move16(); - st_fx->rf_indx_nelp_iG2[0] = 0; - move16(); - st_fx->rf_indx_nelp_iG2[1] = 0; - move16(); - st_fx->rf_indx_tbeGainFr = 0; - move16(); + fd_bwe_dec_init_fx( st_fx->hBWE_FD ); + } + ELSE + { + st_fx->hBWE_FD = NULL; + } - /*-----------------------------------------------------------------* - * Bass post-filter parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * WB/SWB bandwidth switching parameters + *-----------------------------------------------------------------*/ - st_fx->bpf_off = 0; - move16(); + st_fx->tilt_swb_fx = 0; // Q24 + move16(); + st_fx->prev_ener_shb_fx = 0; // Q1 + move16(); + st_fx->prev_enerLH_fx = 0; // Q1 + move16(); + st_fx->enerLH_fx = L_deposit_l( 0 ); + st_fx->enerLL_fx = L_deposit_l( 0 ); + st_fx->prev_enerLL_fx = 0; + move16(); + st_fx->prev_fractive = 0; + move16(); + st_fx->prev_bws_cnt = 0; + move16(); + st_fx->bws_cnt = N_WS2N_FRAMES; + move16(); + st_fx->bws_cnt1 = N_NS2W_FRAMES; + move16(); + st_fx->attenu_fx = 3277; // Q15 + move16(); + st_fx->last_inner_frame = L_FRAME8k; + move16(); - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); - } + /*-----------------------------------------------------------------* + * HR SWB BWE parameters + *-----------------------------------------------------------------*/ - bass_psfilter_init_fx( st_fx->hBPF ); - } - ELSE + IF( ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hBWE_FD_HR = (HR_BWE_DEC_HANDLE) malloc( sizeof( HR_BWE_DEC_DATA ) ) ) == NULL ) { - st_fx->hBPF = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HR BWE\n" ) ); } - /*-----------------------------------------------------------------* - * FD BPF & resampling tools parameters - *-----------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) - { - return error; - } + hr_bwe_dec_init( st_fx->hBWE_FD_HR ); + } + ELSE + { + st_fx->hBWE_FD_HR = NULL; + } - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE + /*----------------------------------------------------------------------------------* + * AMR-WB IO mode parameters + *----------------------------------------------------------------------------------*/ + test(); + IF( st_fx->Opt_AMR_WB || ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hAmrwb_IO = (AMRWB_IO_DEC_HANDLE) malloc( sizeof( AMRWB_IO_DEC_DATA ) ) ) == NULL ) { - test(); - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - /* open analysis for max. SR 48kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* open analysis BPF for max. SR 16kHz */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - st_fx->cldfbAna = NULL; - st_fx->cldfbBPF = NULL; - } - - /* open synthesis for output SR */ - IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) - { - return error; - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } - st_fx->cldfbSynHB = NULL; - st_fx->last_active_bandsToZero_bwdec = 0; - move16(); - st_fx->perc_bwddec = 0; - move16(); - st_fx->last_flag_filter_NB = 0; - move16(); - st_fx->active_frame_cnt_bwddec = 0; - move16(); - st_fx->total_frame_cnt_bwddec = 0; - move16(); - set16_fx( st_fx->flag_buffer, 0, 20 ); - st_fx->avg_nrg_LT = 0; - move32(); - - /*-----------------------------------------------------------------* - * Noise gate parameters - *-----------------------------------------------------------------*/ + /* AMR-WB IO init */ + amr_wb_dec_init_fx( st_fx->hAmrwb_IO ); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = ONE_IN_Q12; - move16(); - st_fx->Ng_ener_ST_fx = -13056; /*-51 IN Q8*/ - move16(); - st_fx->old_Es_pred_fx = 0; - move16(); - set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); - st_fx->old_Aq_12_8_fx[0] = 4096; /*1 in Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * SC-VBR parameters - *-----------------------------------------------------------------*/ + /* AMR-WB IO HF synth init */ + hf_synth_amr_wb_init_fx( st_fx->hAmrwb_IO ); + } + ELSE + { + st_fx->hAmrwb_IO = NULL; + } - IF( st_fx->element_mode == EVS_MONO ) - { - IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); - } + /*-----------------------------------------------------------------* + * channel-aware mode parameters + *-----------------------------------------------------------------*/ - sc_vbr_dec_init( st_fx->hSC_VBR ); - } - ELSE - { - st_fx->hSC_VBR = NULL; - } + set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); + st_fx->use_partial_copy = 0; + move16(); + st_fx->prev_use_partial_copy = 0; + move16(); + st_fx->rf_flag = 0; + move16(); + st_fx->rf_flag_last = 0; + move16(); + st_fx->prev_rf_frame_type = 0; + move16(); + st_fx->next_coder_type = 0; + move16(); + st_fx->rf_target_bits = 0; + move16(); + st_fx->rf_indx_nelp_fid = 0; + move16(); + st_fx->rf_indx_nelp_iG1 = 0; + move16(); + st_fx->rf_indx_nelp_iG2[0] = 0; + move16(); + st_fx->rf_indx_nelp_iG2[1] = 0; + move16(); + st_fx->rf_indx_tbeGainFr = 0; + move16(); - st_fx->last_ppp_mode_dec = 0; - move16(); - st_fx->old_ppp_mode = 0; - move16(); - st_fx->ppp_mode_dec = 0; - move16(); - st_fx->last_nelp_mode_dec = 0; - move16(); - st_fx->nelp_mode_dec = 0; - move16(); - st_fx->prev_gain_pit_dec_fx = 0; - move16(); - st_fx->prev_tilt_code_dec_fx = 0; - move16(); - st_fx->vbr_hw_BWE_disable_dec = 0; - move16(); - st_fx->last_vbr_hw_BWE_disable_dec = 0; - move16(); + /*-----------------------------------------------------------------* + * Bass post-filter parameters + *-----------------------------------------------------------------*/ - /*-----------------------------------------------------------------* - * TCX core - *-----------------------------------------------------------------*/ + st_fx->bpf_off = 0; + move16(); - /* TCX-LTP */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); - } - } - ELSE + test(); + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + { + IF( ( st_fx->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) { - st_fx->hTcxLtpDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); } - /* TCX core */ - test(); - IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) - { - IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); - } + bass_psfilter_init_fx( st_fx->hBPF ); + } + ELSE + { + st_fx->hBPF = NULL; + } - set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); + /*-----------------------------------------------------------------* + * FD BPF & resampling tools parameters + *-----------------------------------------------------------------*/ - st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); - st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); - } - ELSE + IF( st_fx->element_mode == EVS_MONO ) + { + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000 ) ), IVAS_ERR_OK ) ) { - st_fx->hTcxDec = NULL; + return error; } - /* TCX config. data structure */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000 ) ), IVAS_ERR_OK ) ) { - IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); - } - st_fx->hTcxCfg->tcx_mdct_window_length = L_FRAME32k / 2; - move16(); - } - ELSE - { - st_fx->hTcxCfg = NULL; + return error; } - /* Tonal MDCT concealment data structure */ - test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); - } - } - ELSE + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs ) ), IVAS_ERR_OK ) ) { - st_fx->hTonalMDCTConc = NULL; + return error; } - - /*-----------------------------------------------------------------* - * IGF - *-----------------------------------------------------------------*/ - + } + ELSE + { test(); - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + /* open analysis for max. SR 48kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + return error; } - st_fx->igf = 0; - move16(); - init_igf_dec( st_fx->hIGFDec ); - } - ELSE - { - st_fx->hIGFDec = NULL; - } - - /*-----------------------------------------------------------------* - * Mode 2 initialization - *-----------------------------------------------------------------*/ - - IF( ( st_fx->element_mode == EVS_MONO ) ) - { - IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) + /* open analysis BPF for max. SR 16kHz */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); + return error; } } ELSE { - st_fx->hPlcInfo = NULL; + st_fx->cldfbAna = NULL; + st_fx->cldfbBPF = NULL; } - IF( st_fx->element_mode == EVS_MONO ) + /* open synthesis for output SR */ + IF( NE_32( ( error = openCldfb_ivas_fx( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, st_fx->output_Fs, CLDFB_PROTOTYPE_1_25MS, DEC ) ), IVAS_ERR_OK ) ) { - IF( ( st_fx->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); - } + return error; } - ELSE + } + + st_fx->cldfbSynHB = NULL; + st_fx->last_active_bandsToZero_bwdec = 0; + move16(); + st_fx->perc_bwddec = 0; + move16(); + st_fx->last_flag_filter_NB = 0; + move16(); + st_fx->active_frame_cnt_bwddec = 0; + move16(); + st_fx->total_frame_cnt_bwddec = 0; + move16(); + set16_fx( st_fx->flag_buffer, 0, 20 ); + st_fx->avg_nrg_LT = 0; + move32(); + + /*-----------------------------------------------------------------* + * Noise gate parameters + *-----------------------------------------------------------------*/ + + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); + st_fx->old_Aq_12_8_fx[0] = ONE_IN_Q12; + move16(); + st_fx->Ng_ener_ST_fx = -13056; /*-51 IN Q8*/ + move16(); + st_fx->old_Es_pred_fx = 0; + move16(); + set16_fx( st_fx->old_Aq_12_8_fx + 1, 0, M ); + st_fx->old_Aq_12_8_fx[0] = 4096; /*1 in Q12*/ + move16(); + + /*-----------------------------------------------------------------* + * SC-VBR parameters + *-----------------------------------------------------------------*/ + + IF( st_fx->element_mode == EVS_MONO ) + { + IF( ( st_fx->hSC_VBR = (SC_VBR_DEC_HANDLE) malloc( sizeof( SC_VBR_DEC_DATA ) ) ) == NULL ) { - st_fx->hTECDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SC-VBR\n" ) ); } - /* Init Decoder */ - IF( st_fx->element_mode == EVS_MONO ) + sc_vbr_dec_init( st_fx->hSC_VBR ); + } + ELSE + { + st_fx->hSC_VBR = NULL; + } + + st_fx->last_ppp_mode_dec = 0; + move16(); + st_fx->old_ppp_mode = 0; + move16(); + st_fx->ppp_mode_dec = 0; + move16(); + st_fx->last_nelp_mode_dec = 0; + move16(); + st_fx->nelp_mode_dec = 0; + move16(); + st_fx->prev_gain_pit_dec_fx = 0; + move16(); + st_fx->prev_tilt_code_dec_fx = 0; + move16(); + st_fx->vbr_hw_BWE_disable_dec = 0; + move16(); + st_fx->last_vbr_hw_BWE_disable_dec = 0; + move16(); + + /*-----------------------------------------------------------------* + * TCX core + *-----------------------------------------------------------------*/ + + /* TCX-LTP */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) { - open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); } - ELSE + } + ELSE + { + st_fx->hTcxLtpDec = NULL; + } + + /* TCX core */ + test(); + IF( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + { + IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) { - Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxDec\n" ) ); } - /* PLC mode initialization */ - st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); + set32_fx( st_fx->hTcxDec->FBTCXdelayBuf_32, 0, 111 ); - /* Init bandwidth / frame_type */ - st_fx->m_frame_type = ACTIVE_FRAME; - move16(); - st_fx->m_old_frame_type = ACTIVE_FRAME; - move16(); + st_fx->hTcxDec->old_synthFB_fx = st_fx->hTcxDec->synth_history_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_MEM_NS ); + st_fx->hTcxDec->prev_good_synth_fx = st_fx->hTcxDec->old_synthFB_fx + NS2SA_FX2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ); + } + ELSE + { + st_fx->hTcxDec = NULL; + } - IF( st_fx->element_mode == EVS_MONO ) + /* TCX config. data structure */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) { - resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); - resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } - ELSE + st_fx->hTcxCfg->tcx_mdct_window_length = L_FRAME32k / 2; + move16(); + } + ELSE + { + st_fx->hTcxCfg = NULL; + } + + /* Tonal MDCT concealment data structure */ + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) { - test(); - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) - { - resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TonalMDCTConcealment\n" ) ); } + } + ELSE + { + st_fx->hTonalMDCTConc = NULL; + } - /*-----------------------------------------------------------------* - * FD-CNG decoder - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * IGF + *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) + test(); + IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + { + IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) { - /* Create FD_CNG instance */ - IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) - { - return error; - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + } - /* Init FD-CNG */ -#ifdef FIX_2245_INIT_FD_CNG_EVS - initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); -#else - initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); -#endif + st_fx->igf = 0; + move16(); + init_igf_dec( st_fx->hIGFDec ); + } + ELSE + { + st_fx->hIGFDec = NULL; + } + + /*-----------------------------------------------------------------* + * Mode 2 initialization + *-----------------------------------------------------------------*/ + + IF( ( st_fx->element_mode == EVS_MONO ) ) + { + IF( ( st_fx->hPlcInfo = (T_PLCInfo_HANDLE) malloc( sizeof( T_PLCInfo ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PLC handle\n" ) ); } - ELSE + } + ELSE + { + st_fx->hPlcInfo = NULL; + } + + IF( st_fx->element_mode == EVS_MONO ) + { + IF( ( st_fx->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) { - st_fx->hFdCngDec = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n" ) ); } + } + ELSE + { + st_fx->hTECDec = NULL; + } - st_fx->cngTDLevel = 0; + /* Init Decoder */ + IF( st_fx->element_mode == EVS_MONO ) + { + open_decoder_LPD_fx( st_fx, st_fx->total_brate, st_fx->bwidth ); + } + ELSE + { + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; move16(); - st_fx->cngTDLevel_e = 0; move16(); - st_fx->lp_noise = -167772160l /*-20.f Q23*/; - move32(); - st_fx->force_lpd_reset = 0; move16(); - - - /*-----------------------------------------------------------------* - * initialzie Q values - *-----------------------------------------------------------------*/ - - st_fx->Q_syn2 = 0; move16(); - st_fx->Q_exc = 8; move16(); - st_fx->prev_Q_exc = 0; move16(); - st_fx->Q_syn = 0; move16(); - st_fx->prev_Q_syn = 0; move16(); + open_decoder_LPD_ivas_fx( st_fx, st_fx->total_brate, st_fx->last_total_brate, st_fx->bwidth, 0, st_fx->element_mode, 1, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8 ); + } + + /* PLC mode initialization */ + st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; + move16(); + + /* Init bandwidth / frame_type */ + st_fx->m_frame_type = ACTIVE_FRAME; + move16(); + st_fx->m_old_frame_type = ACTIVE_FRAME; + move16(); - FOR( i = 0; i < L_Q_MEM; i++ ) + IF( st_fx->element_mode == EVS_MONO ) + { + resampleCldfb( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + resampleCldfb( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ), st_fx->L_frame, 1 ); + } + ELSE + { + test(); + IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { - st_fx->Q_subfr[i] = 8; - move16(); + resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st_fx->cldfbBPF, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); } + } - st_fx->prev_Q_exc_fr = 0; - move16(); - st_fx->prev_Q_syn_fr = 0; - move16(); - - /*-----------------------------------------------------------------* - * IVAS parameters - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * FD-CNG decoder + *-----------------------------------------------------------------*/ - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ - move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ - move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ - move16(); - st_fx->cng_ism_flag = 0; - move16(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || idchan == 0 ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) + { + /* Create FD_CNG instance */ + IF( NE_32( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ), IVAS_ERR_OK ) ) + { + return error; + } - return error; + /* Init FD-CNG */ +#ifdef FIX_2245_INIT_FD_CNG_EVS + initFdCngDec_fx( st_fx, st_fx->cldfbSyn->scale ); +#else + initFdCngDec_ivas_fx( st_fx, st_fx->cldfbSyn->scale ); +#endif + } + ELSE + { + st_fx->hFdCngDec = NULL; } + st_fx->cngTDLevel = 0; + move16(); + st_fx->cngTDLevel_e = 0; + move16(); + st_fx->lp_noise = -167772160l /*-20.f Q23*/; + move32(); + st_fx->force_lpd_reset = 0; + move16(); + + + /*-----------------------------------------------------------------* + * initialzie Q values + *-----------------------------------------------------------------*/ - /*----------------------------------------------------------------------* - * reset_preecho_dec() - * - * Initialization of static variables for pre-echo - *----------------------------------------------------------------------*/ + st_fx->Q_syn2 = 0; + move16(); + st_fx->Q_exc = 8; + move16(); + st_fx->prev_Q_exc = 0; + move16(); + st_fx->Q_syn = 0; + move16(); + st_fx->prev_Q_syn = 0; + move16(); - void reset_preecho_dec_fx( - HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ - ) + FOR( i = 0; i < L_Q_MEM; i++ ) { - hHQ_core->memfilt_lb_fx = 0; - move16(); - hHQ_core->mean_prev_hb_fx = L_deposit_l( 0 ); - hHQ_core->smoothmem_fx = 32767; - move16(); - hHQ_core->mean_prev_fx = L_deposit_l( 0 ); - hHQ_core->mean_prev_nc_fx = L_deposit_l( 0 ); - hHQ_core->wmold_hb_fx = 32767; + st_fx->Q_subfr[i] = 8; move16(); - hHQ_core->prevflag = 0; - move16(); - hHQ_core->pastpre = 0; - move16(); - - return; } - /*----------------------------------------------------------------------* - * destroy_cldfb_decoder_fx() - * - * Free memory which was allocated in init_decoder() - *----------------------------------------------------------------------*/ + st_fx->prev_Q_exc_fr = 0; + move16(); + st_fx->prev_Q_syn_fr = 0; + move16(); + + /*-----------------------------------------------------------------* + * IVAS parameters + *-----------------------------------------------------------------*/ - void destroy_cldfb_decoder_fx( - Decoder_State * st_fx /* o: Decoder static variables structure */ - ) - { - /* CLDFB BPF & resampling tools */ - deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ - deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ - deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ - deleteCldfb_fx( &st_fx->cldfbSynHB ); + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + move16(); + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + move16(); + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + move16(); + st_fx->cng_ism_flag = 0; + move16(); - deleteFdCngDec_fx( &st_fx->hFdCngDec ); + return error; +} - return; - } + +/*----------------------------------------------------------------------* + * reset_preecho_dec() + * + * Initialization of static variables for pre-echo + *----------------------------------------------------------------------*/ + +void reset_preecho_dec_fx( + HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ +) +{ + hHQ_core->memfilt_lb_fx = 0; + move16(); + hHQ_core->mean_prev_hb_fx = L_deposit_l( 0 ); + hHQ_core->smoothmem_fx = 32767; + move16(); + hHQ_core->mean_prev_fx = L_deposit_l( 0 ); + hHQ_core->mean_prev_nc_fx = L_deposit_l( 0 ); + hHQ_core->wmold_hb_fx = 32767; + move16(); + hHQ_core->prevflag = 0; + move16(); + hHQ_core->pastpre = 0; + move16(); + + return; +} + +/*----------------------------------------------------------------------* + * destroy_cldfb_decoder_fx() + * + * Free memory which was allocated in init_decoder() + *----------------------------------------------------------------------*/ + +void destroy_cldfb_decoder_fx( + Decoder_State *st_fx /* o: Decoder static variables structure */ +) +{ + /* CLDFB BPF & resampling tools */ + deleteCldfb_fx( &st_fx->cldfbAna ); /* delete analysis for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbBPF ); /* delete analysis BPF for max. SR 16kHz */ + deleteCldfb_fx( &st_fx->cldfbSyn ); /* delete synthesis for output SR */ + deleteCldfb_fx( &st_fx->cldfbSynHB ); + + deleteFdCngDec_fx( &st_fx->hFdCngDec ); + + return; +} -- GitLab