From 84c43f03b94816f87c9b16ec74bbb90bf2acf31f Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 14 Jan 2026 15:13:28 +0100 Subject: [PATCH 1/2] HARM_CORECODER_UPDT --- lib_com/options.h | 1 + lib_com/prot_fx.h | 21 +++- lib_dec/amr_wb_dec_fx.c | 4 + lib_dec/evs_dec_fx.c | 10 ++ lib_dec/ivas_core_dec_fx.c | 4 + lib_dec/ivas_mct_dec_fx.c | 4 + lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 4 + lib_dec/updt_dec_fx.c | 145 +++++++++++++++++++------ lib_enc/amr_wb_enc_fx.c | 4 + lib_enc/evs_enc_fx.c | 4 + lib_enc/ivas_core_enc_fx.c | 4 + lib_enc/ivas_mct_enc_fx.c | 6 +- lib_enc/long_enr_fx.c | 20 +++- lib_enc/prot_fx_enc.h | 2 + lib_enc/updt_enc_fx.c | 4 +- 15 files changed, 193 insertions(+), 44 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 4a272cf24..891f5b8fc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -124,6 +124,7 @@ #define REMOVE_UNUSED_CODE_IVAS_DEC /* VA: remove unused code in ivas_jbm_dec_tc_fx() */ #define FIX_2294_CLANG_18_WARNINGS_ENC /* VA: Fix some encoder clang-18 warnings, desc. in 2294 */ #define REMOVE_CAM_FROM_IVAS /* VA: basop issue 210: remove obsoelte CAM code from IVAS */ +#define HARM_CORECODER_UPDT /* VA: basop issue 2342: Remove duplicated code in core-coder common update functions */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 588617196..dcbd9d4b1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5380,6 +5380,7 @@ Word32 sign_l( const Word32 x /* i : input value of x */ ); +#ifndef HARM_CORECODER_UPDT void ivas_updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ @@ -5387,7 +5388,7 @@ void ivas_updt_dec_common_fx( const Word32 *synth, /* i : decoded synthesis */ const Word16 Qpostd /* i : Synthesis Q value */ ); - +#endif /* Random generator with Gaussian distribution with mean 0 and std 1 */ Word32 rand_gauss( Word16 *seed ); @@ -7850,17 +7851,24 @@ void updt_IO_switch_dec_fx( Decoder_State *st_fx /* o : Decoder static variables structure */ ); +#ifndef HARM_CORECODER_UPDT void updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 *synth, /* i : synthesis signal Qpost */ - const Word16 Qpost ); - + const Word16 Qpost /* i : Synthesis Q value */ +); +#endif void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word16 *synth, /* i : decoded synthesis */ - const Word16 Qpostd /* i : Synthesis Q value */ +#ifdef HARM_CORECODER_UPDT + const Word16 *synth16, /* i : decoded synthesis Qpostd */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ +#else + const Word16 *synth, /* i : decoded synthesis */ +#endif + const Word16 Qpostd /* i : Synthesis Q value */ ); void update_decoder_LPD_cng( @@ -10522,11 +10530,12 @@ void core_encode_update_ivas_fx( Encoder_State *st /* i/o: Encoder state structure */ ); +#ifndef HARM_CORECODER_UPDT void updt_enc_common_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 Q_new /* i : CUrrent frame scaling */ ); - +#endif /* o : Q(2x - 31 - gb) */ Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector, Qx */ diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d7dcf5b03..632992d96 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -993,7 +993,11 @@ ivas_error amr_wb_dec_fx( st_fx->last_flag_cna = flag_cna; move16(); +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( st_fx, -1, -1, NULL, NULL, 0 ); +#else updt_dec_common_fx( st_fx, -1, -1, NULL, 0 ); +#endif /*----------------------------------------------------------------* * Overlap of ACELP synthesis with old MDCT memory diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index a358cbe8a..2831c57ab 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1374,7 +1374,12 @@ ivas_error evs_dec_fx( st_fx->bfi = 1; move16(); } + +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, NULL, Qpostd ); +#else updt_dec_common_fx( st_fx, -1, concealWholeFrameTmp, output_sp, Qpostd ); +#endif } ELSE { @@ -1383,7 +1388,12 @@ ivas_error evs_dec_fx( st_fx->bfi = 0; move16(); } + +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, NULL, Qpostd ); +#else updt_dec_common_fx( st_fx, hq_core_type, concealWholeFrameTmp, output_sp, Qpostd ); +#endif } pop_wmops(); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index bf1f75333..655fc7ff0 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1492,7 +1492,11 @@ ivas_error ivas_core_dec_fx( save_synthesis_hq_fec_fx( st, NULL, output_fx_loc, output_frame, 0, hCPE ); /* Updates */ +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, NULL, output_32_fx[n], Q11 ); +#else ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); +#endif Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); // Q0 diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 5c5b0ac52..7c1cae860 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -380,7 +380,11 @@ ivas_error ivas_mct_dec_fx( save_synthesis_hq_fec_fx( sts[n], NULL, output_fx_, output_frame, 0, hCPE ); /* CoreCoder common updates */ +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, NULL, output_fx[( cpe_id * CPE_CHANNELS ) + n], Q11 ); +#else ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[( cpe_id * CPE_CHANNELS ) + n], 11 ); +#endif } /* n_channels loop */ diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 37bc17138..7ed00053c 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1508,7 +1508,11 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_core_switching_fx( hCPE, output[0] /*hSCE->save_output*/, hSCE->save_synth_fx, hSCE->save_hb_synth_fx, DFT, output_frame, 0, dtx_flag, &q, &q_dft[0] ); /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ +#ifdef HARM_CORECODER_UPDT + updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, NULL, hSCE->save_synth_fx, q ); +#else ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q ); +#endif q_synth = sub( getScaleFactor32( tmp_synth, hSCE->hCoreCoder[0]->L_frame ), 10 ); scale_sig32( tmp_synth, hSCE->hCoreCoder[0]->L_frame, q_synth ); /*hSCE->q_save_synth_fx + q_synth*/ diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 240f9545c..7f42e6b69 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -14,17 +14,18 @@ * * Common updates (all frame types) *-------------------------------------------------------------------*/ + void updt_dec_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 *old_exc_fx, /* i : buffer of excitation Q_exc */ const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/ - const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ - const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ - const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ - const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ - const Word16 voice_factors[], /* i : voicing factors Q15*/ - const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ - const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ + const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ + const Word16 voice_factors[], /* i : voicing factors Q15*/ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ + const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ ) { Word16 i, len; @@ -56,6 +57,7 @@ void updt_dec_fx( st_fx->last_coder_type = UNVOICED; move16(); } + IF( st_fx->hGSCDec != NULL ) { test(); @@ -68,13 +70,13 @@ void updt_dec_fx( } /* this ensures that st_fx->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */ - test(); if ( GT_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->coder_type, INACTIVE ) ) { st_fx->last_coder_type = GENERIC; move16(); } + test(); test(); test(); @@ -91,7 +93,6 @@ void updt_dec_fx( IF( !st_fx->Opt_AMR_WB ) { /* update voicing factor of TBE to help FEC */ - st_fx->last_voice_factor_fx = voice_factors[NB_SUBFR16k - 1]; move16(); if ( EQ_16( st_fx->L_frame, L_FRAME ) ) @@ -100,6 +101,7 @@ void updt_dec_fx( move16(); } } + test(); test(); IF( st_fx->hGSCDec != NULL && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) ) @@ -159,7 +161,6 @@ void updt_dec_fx( move16(); } - /* FEC - update adaptive LSF mean vector */ Copy( st_fx->lsfoldbfi0_fx, st_fx->lsfoldbfi1_fx, M ); Copy( lsf_new_fx, st_fx->lsfoldbfi0_fx, M ); @@ -198,13 +199,15 @@ void updt_dec_fx( return; } + /*-------------------------------------------------------------------* * updt_IO_switch() * * Common updates for AMR-WB IO mode and EVS primary switching *-------------------------------------------------------------------*/ + void updt_IO_switch_dec_fx( - const Word16 output_frame, /* i : output frame length */ + const Word16 output_frame, /* i : output frame length */ Decoder_State *st_fx /* o : Decoder static variables structure */ ) { @@ -393,15 +396,32 @@ void updt_IO_switch_dec_fx( * Updates for BW switching *-------------------------------------------------------------------*/ +#ifdef HARM_CORECODER_UPDT +static void updt_bw_switching_fx( +#else void updt_bw_switching_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : synthesis signal Qpost */ - const Word16 Qpost ) +#endif + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *synth, /* i : synthesis signal Qpost */ +#ifdef HARM_CORECODER_UPDT + const Word32 *synth32, /* i : synthesis signal32 Qpost */ +#endif + const Word16 Qpost /* i : Synthesis Q value */ +) { test(); IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { - st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 +#ifdef HARM_CORECODER_UPDT + IF( st_fx->element_mode != EVS_MONO ) + { + st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth32, Qpost, L_FRAME32k ); + } + ELSE +#endif + { + st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); // Q27 - 16 = Q11 + } } st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q @@ -433,17 +453,20 @@ void updt_bw_switching_fx( move16(); } } + st_fx->prev_bws_cnt = st_fx->bws_cnt; move16(); + return; } + /*-------------------------------------------------------------------* * updt_dec_common() * * Common updates for MODE1 and MODE2 *-------------------------------------------------------------------*/ - +#ifndef HARM_CORECODER_UPDT void updt_dec_common_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ @@ -790,8 +813,9 @@ static void ivas_updt_bw_switching_fx( move16(); return; } +#endif -static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx +static Word32 sum_32_32_fx( const Word32 *x, const Word16 length ) // Qx { Word64 sum = 0; Word16 i; @@ -802,19 +826,28 @@ static Word32 sum_32_32_fx( const Word32 *x, Word16 length ) // Qx return W_round64_L( sum ); } +#ifdef HARM_CORECODER_UPDT +void updt_dec_common_fx( +#else void ivas_updt_dec_common_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 hq_core_type_fx, /* i : HQ core type */ const Word16 concealWholeFrameTmp, /* i : concealWholeFrameTmp flag */ - const Word32 *synth, /* i : decoded synthesis Qpostd */ - const Word16 Qpostd /* i : Synthesis Q value */ +#ifdef HARM_CORECODER_UPDT + const Word16 *synth16, /* i : decoded synthesis Qpostd */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ +#else + const Word32 *synth, /* i : decoded synthesis Qpostd */ +#endif + const Word16 Qpostd /* i : Synthesis Q value */ ) { Word16 i; Word32 L_tmp; - TCX_DEC_HANDLE hTcxDec; + hTcxDec = st_fx->hTcxDec; st_fx->last_codec_mode = st_fx->codec_mode; @@ -845,11 +878,12 @@ void ivas_updt_dec_common_fx( move16(); } - IF( st_fx->hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 0; move16(); } + test(); test(); test(); @@ -860,8 +894,7 @@ void ivas_updt_dec_common_fx( test(); test(); test(); - - if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) + if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 1; move16(); @@ -869,6 +902,7 @@ void ivas_updt_dec_common_fx( st_fx->last_good = st_fx->clas_dec; move16(); } + IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; @@ -879,9 +913,14 @@ void ivas_updt_dec_common_fx( st_fx->prev_rf_frame_type = INACTIVE; move16(); } + test(); test(); +#ifdef HARM_CORECODER_UPDT + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( NE_16( st_fx->bfi, 1 ) || st_fx->use_partial_copy != 0 ) ) +#else if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) ) +#endif { st_fx->rf_flag_last = st_fx->rf_flag; move16(); @@ -898,6 +937,24 @@ void ivas_updt_dec_common_fx( st_fx->last_active_brate = st_fx->total_brate; } +#ifdef HARM_CORECODER_UPDT + IF( st_fx->element_mode == EVS_MONO ) + { + st_fx->last_core = st_fx->core; + move16(); + } + ELSE + { + test(); + if ( !st_fx->bfi || st_fx->element_mode == EVS_MONO ) + { + st_fx->last_core = st_fx->core; + move16(); + } + st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ + move16(); + } +#else move16(); move16(); if ( !st_fx->bfi || st_fx->element_mode == EVS_MONO ) @@ -905,6 +962,8 @@ void ivas_updt_dec_common_fx( st_fx->last_core = st_fx->core; } st_fx->last_core_bfi = st_fx->core; /* also required for clean channel decoding */ +#endif + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; @@ -919,14 +978,13 @@ void ivas_updt_dec_common_fx( move16(); st_fx->last_active_brate = st_fx->total_brate; } - /* INFO: moved from update_decoder_LPD_cng() */ + if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { move16(); st_fx->last_is_cng = 1; } - if ( !st_fx->bfi ) { st_fx->last_core = st_fx->core; @@ -942,8 +1000,13 @@ void ivas_updt_dec_common_fx( test(); IF( EQ_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { +#ifdef HARM_CORECODER_UPDT + Copy_Scale_sig( synth16 + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); +#else Copy_Scale_sig_32_16( synth + NS2SA_FX2( st_fx->output_Fs, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), st_fx->hHQ_core->Q_old_postdec ); +#endif } + test(); test(); test(); @@ -987,6 +1050,7 @@ void ivas_updt_dec_common_fx( Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); } } + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); @@ -1035,7 +1099,6 @@ void ivas_updt_dec_common_fx( test(); IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) { - if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) { st_fx->hTdCngDec->act_cnt = 0; @@ -1045,12 +1108,17 @@ void ivas_updt_dec_common_fx( st_fx->hTdCngDec->act_cnt = add( st_fx->hTdCngDec->act_cnt, 1 ); test(); - if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) { st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); } +#ifdef HARM_CORECODER_UPDT + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->hTdCngDec->act_cnt2 = add( st_fx->hTdCngDec->act_cnt2, 1 ); + } +#endif if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; @@ -1101,7 +1169,11 @@ void ivas_updt_dec_common_fx( } ELSE IF( EQ_16( st_fx->codec_mode, MODE1 ) && ( ( GT_32( st_fx->core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { +#ifdef HARM_CORECODER_UPDT + updt_bw_switching_fx( st_fx, synth16, synth, Qpostd ); +#else ivas_updt_bw_switching_fx( st_fx, synth, Qpostd ); +#endif } ELSE { @@ -1125,10 +1197,19 @@ void ivas_updt_dec_common_fx( test(); test(); test(); - IF( st_fx->hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) + IF( hTcxDec != NULL && st_fx->enablePlcWaveadjust && !concealWholeFrameTmp && NE_16( st_fx->core, AMR_WB_CORE ) ) { /* update the parameters used in waveform adjustment */ - concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); +#ifdef HARM_CORECODER_UPDT + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + concealment_update2_x( (const Word16 *) synth16, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); + } + ELSE +#endif + { + concealment_update2_x( (const Word16 *) synth, st_fx->hPlcInfo, hTcxDec->L_frameTCX ); + } } st_fx->last_total_brate_ber = st_fx->total_brate; @@ -1140,8 +1221,10 @@ void ivas_updt_dec_common_fx( move32(); move32(); } + st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); + if ( LT_16( st_fx->ini_frame, MAX_FRAME_COUNTER ) ) { st_fx->ini_frame = add( st_fx->ini_frame, 1 ); diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 9b20100ba..b5e2a6042 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -579,7 +579,11 @@ void amr_wb_enc_fx( updt_enc_fx( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec parameters */ +#ifdef HARM_CORECODER_UPDT + updt_enc_common_fx( st, Q_new ); +#else updt_enc_common_fx( st, Etot, Q_new ); +#endif #ifdef DEBUG_MODE_INFO dbgwrite( &st->codec_mode, sizeof( short ), 1, input_frame, "res/codec" ); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 34336ef79..46d357b17 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -541,7 +541,11 @@ ivas_error evs_enc_fx( signalling_enc_rf_fx( st ); #endif +#ifdef HARM_CORECODER_UPDT + updt_enc_common_fx( st, Q_new ); +#else updt_enc_common_fx( st, Etot, Q_new ); +#endif if ( EQ_16( st->mdct_sw, MODE1 ) ) { diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 4c9b00d46..acc9df330 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -847,7 +847,11 @@ ivas_error ivas_core_enc_fx( IF( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ { +#ifdef HARM_CORECODER_UPDT + updt_enc_common_fx( st, Q_new[n] ); +#else updt_enc_common_ivas_fx( st, Q_new[n] ); +#endif } IF( st->hBWE_FD != NULL ) diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 88e88a865..534450f79 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -482,9 +482,13 @@ ivas_error ivas_mct_enc_fx( Copy32( hCPE->hCoreCoder[n]->input32_fx, hCPE->hCoreCoder[n]->old_input_signal32_fx, input_frame ); hCPE->hCoreCoder[n]->q_old_inp32 = hCPE->hCoreCoder[n]->q_inp32; move16(); - /* common encoder updates */ + /* common encoder updates */ +#ifdef HARM_CORECODER_UPDT + updt_enc_common_fx( hCPE->hCoreCoder[n], Q_new_out[cpe_id][n] ); +#else updt_enc_common_ivas_fx( hCPE->hCoreCoder[n], Q_new_out[cpe_id][n] ); +#endif } } diff --git a/lib_enc/long_enr_fx.c b/lib_enc/long_enr_fx.c index 0228b6cbe..45660c619 100644 --- a/lib_enc/long_enr_fx.c +++ b/lib_enc/long_enr_fx.c @@ -145,9 +145,11 @@ void ivas_long_enr_fx( move32(); } +#ifndef HARM_CORECODER_UPDT /*-----------------------------------------------------------------* * Initialize parameters for energy tracking and signal dynamics *-----------------------------------------------------------------*/ +#endif return; } @@ -168,7 +170,9 @@ void long_enr_fx( * and total active speech energy *-----------------------------------------------------------------*/ +#ifndef HARM_CORECODER_UPDT { +#endif IF( LT_16( st_fx->ini_frame, 4 ) ) { st_fx->lp_noise_fx = hNoiseEst->totalNoise_fx; /* Q8 */ @@ -210,10 +214,16 @@ void long_enr_fx( } } } - } - /*-----------------------------------------------------------------* - * Initialize parameters for energy tracking and signal dynamics - *-----------------------------------------------------------------*/ - return; +#ifdef HARM_CORECODER_UPDT + /* Update */ + st_fx->hNoiseEst->Etot_last_fx = Etot; +#else } +/*-----------------------------------------------------------------* + * Initialize parameters for energy tracking and signal dynamics + *-----------------------------------------------------------------*/ +#endif + + return; + } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 06630ab57..00acce41a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -812,7 +812,9 @@ void sc_vbr_enc_init_fx( void updt_enc_common_fx( Encoder_State *st, /* i/o: encoder state structure */ +#ifndef HARM_CORECODER_UPDT const Word16 Etot, /* i : total energy */ +#endif const Word16 Q_new /* i : CUrrent frame scaling */ ); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 2eb3e1a17..b9bf810e1 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -297,6 +297,7 @@ void updt_IO_switch_enc_fx( return; } + /*-------------------------------------------------------------------* * updt_enc_common_fx() * @@ -304,6 +305,7 @@ void updt_IO_switch_enc_fx( *-------------------------------------------------------------------*/ void updt_enc_common_fx( +#ifndef HARM_CORECODER_UPDT Encoder_State *st, /* i/o: encoder state structure */ const Word16 Etot, /* i : total energy */ const Word16 Q_new /* i : CUrrent frame scaling */ @@ -526,8 +528,8 @@ void updt_enc_common_fx( return; } - void updt_enc_common_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 Q_new /* i : CUrrent frame scaling */ ) -- GitLab From 1a2a27f94c05b577b711c44c8aed6426fdab0752 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 14 Jan 2026 17:14:10 +0100 Subject: [PATCH 2/2] fix init --- lib_com/prot_fx.h | 2 +- lib_enc/core_enc_updt_fx.c | 30 +++++++++++++++++++++++------- lib_enc/updt_enc_fx.c | 4 ++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index dcbd9d4b1..10f6ed23f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10526,11 +10526,11 @@ void swb_pre_proc_ivas_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); +#ifndef HARM_CORECODER_UPDT void core_encode_update_ivas_fx( Encoder_State *st /* i/o: Encoder state structure */ ); -#ifndef HARM_CORECODER_UPDT void updt_enc_common_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 Q_new /* i : CUrrent frame scaling */ diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index 94a2ef746..9ec6eda6f 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -3,7 +3,6 @@ ====================================================================================*/ #include -//#include "prot_fx.h" #include "options.h" #include "cnst.h" /* Common constants */ #include "basop_util.h" @@ -12,6 +11,7 @@ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ +#ifndef HARM_CORECODER_UPDT void core_encode_update_fx( Encoder_State *st ) { Word16 n; @@ -61,11 +61,14 @@ void core_encode_update_fx( Encoder_State *st ) Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } } +#endif + /*-------------------------------------------------------------------* * core_encode_update_cng_fx() * * Common updates in case of CNG *-------------------------------------------------------------------*/ + void core_encode_update_cng_fx( Encoder_State *st, Word16 *timeDomainBuffer, @@ -150,7 +153,6 @@ void core_encode_update_cng_fx( p_A += ( M + 1 ); } - tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp ); hLPDmem->mem_w0 = sub_sat( st->wspeech_enc[st->L_frame - 1], tmp ); @@ -200,7 +202,11 @@ void core_encode_update_cng_fx( * Common updates of buffers *-------------------------------------------------------------------*/ +#ifdef HARM_CORECODER_UPDT +void core_encode_update_fx( +#else void core_encode_update_ivas_fx( +#endif Encoder_State *st /* i/o: Encoder state structure */ ) { @@ -226,11 +232,20 @@ void core_encode_update_ivas_fx( test(); IF( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) ) { - Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, st->exp_buf_speech_enc ); - Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e) - Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e) - st->hTcxEnc->exp_buf_speech_ltp = max_e; - move16(); +#ifdef HARM_CORECODER_UPDT + IF( st->element_mode == EVS_MONO ) + { + Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame ); + } + ELSE +#endif + { + Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, st->exp_buf_speech_enc ); + Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e) + Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e) + st->hTcxEnc->exp_buf_speech_ltp = max_e; + move16(); + } } } @@ -265,5 +280,6 @@ void core_encode_update_ivas_fx( set16_fx( st->mem_MA_fx, 0, M ); Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); // 2.56 scaling } + return; } diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index b9bf810e1..138312847 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -707,7 +707,11 @@ void updt_enc_common_ivas_fx( } /* Update Core */ +#ifdef HARM_CORECODER_UPDT + core_encode_update_fx( st ); +#else core_encode_update_ivas_fx( st ); +#endif /*---------------------------------------------------------------------* * RF mode updates -- GitLab