From 41b5c863f553a5f30233a5b4fcef7fcf3855c176 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 14 Sep 2025 22:35:38 +0200 Subject: [PATCH 1/3] prep_tbe_exc_fx(): introduce differen Q-factors for code_preQ_fx[] --- lib_com/options.h | 1 + lib_com/prot_fx.h | 21 ++++++++++-------- lib_com/swb_tbe_com_fx.c | 37 ++++++++++++++++++++++--------- lib_dec/dec_ace_fx.c | 5 +++++ lib_dec/dec_gen_voic_fx.c | 7 ++++++ lib_dec/dec_tran_fx.c | 7 ++++++ lib_dec/ivas_td_low_rate_dec_fx.c | 4 ++++ lib_enc/cod_ace_fx.c | 6 +++++ lib_enc/enc_gen_voic_fx.c | 16 ++++++++++++- lib_enc/enc_tran_fx.c | 11 +++++++++ lib_enc/ivas_td_low_rate_enc_fx.c | 4 ++++ 11 files changed, 98 insertions(+), 21 deletions(-) mode change 100755 => 100644 lib_com/swb_tbe_com_fx.c diff --git a/lib_com/options.h b/lib_com/options.h index 31c786278..92c5871eb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,6 +99,7 @@ #define FIX_ISSUE_2013_MDCT_STEREO_DTX_DISCONTINUITIES /* Eri/FhG: Issue 2013 fix for dtx discontinuities */ #define FIX_ISSUE_2013_MDCT_STEREO_FER_DISCONTINUITIES /* Eri/FhG: Issue 2013 fix for FER discontinuities */ #define FIX_2000_NON_LINEARITY_OVERSHOOT /* Eri: Issue 2000: SWB TBE energy overshoot in non-linearity. Aligns with float */ +#define FIX_2010_PREP_TBE_EXC /* FhG: fix issues with varying Q-values for code_preQ_fx[] */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ddd0bfdcc..92512d349 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3192,15 +3192,18 @@ void prep_tbe_exc_fx( Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - const Word16 T0, /* i : integer pitch variables Q0 */ - const Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#ifdef FIX_2010_PREP_TBE_EXC + const Word16 Q_code_preQ, /* i : Q, prequantizer excitation */ +#endif + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + const Word16 T0, /* i : integer pitch variables Q0 */ + const Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ); /*! r: Formant filter strength [0,1] */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c old mode 100755 new mode 100644 index be3d1f29c..fb59ab3f3 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7203,15 +7203,18 @@ void prep_tbe_exc_fx( Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - const Word16 T0, /* i : integer pitch variables Q0 */ - const Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +#ifdef FIX_2010_PREP_TBE_EXC + const Word16 Q_code_preQ, /* i : Q, prequantizer excitation */ +#endif + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + const Word16 T0, /* i : integer pitch variables Q0 */ + const Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { @@ -7307,14 +7310,26 @@ void prep_tbe_exc_fx( ELSE { Word16 shift = 4; +#ifdef FIX_2010_PREP_TBE_EXC + IF( element_mode != EVS_MONO ) + { + /* shift of 4 assumes code_preQ_fx[] in Q9 - this is however not always given */ + shift = add( 2 + 1 - 1, Q_code_preQ ); /* gain_preQ_fx in Q2, code_preQ_fx[] in Q_code_preQ, 1 additional left-shift by L_mult() - factor of 2 (from "2 * gain_preQ * code_preQ[i]") */ + shift = sub( 16, shift ); + } +#endif move16(); IF( gain_preQ_fx != 0 ) { FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ +#ifdef FIX_2010_PREP_TBE_EXC + Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q_code_preQ */ +#else + Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ +#endif #ifdef ISSUE_1836_replace_overflow_libcom Ltemp1 = L_shl_sat( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/ ); /*Q_exc+16 */ diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index d7f8f7ab0..78b6c593f 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -532,8 +532,13 @@ void decoder_acelp_fx( move16(); IF( st->igf != 0 ) { +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, + gain_preQ, code_preQ, Q9, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); +#else prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); +#endif } /*---------------------------------------------------------* diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index ac1df74b2..c7490ce52 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -322,10 +322,17 @@ ivas_error decod_gen_voic_fx( idx = idiv1616( i_subfr_fx, L_SUBFR ); } +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q6, + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*----------------------------------------------------------------* diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index de3a1ff3f..b01977023 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -254,10 +254,17 @@ void decod_tran_fx( tmp_idx_2 = idiv1616( i_subfr, L_SUBFR ); } +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q10, + st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index fb984f11f..2d2876585 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -326,7 +326,11 @@ void decod_gen_2sbfr_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, Q9, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#endif voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */ move16(); diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 5dae2f7f0..a21781c0b 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -377,9 +377,15 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->igf != 0 ) { +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc, gain_preQ, code_preQ, Q9, Q_new, T0, T0_frac, st->coder_type, st->core_brate, + st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#endif } /*---------------------------------------------------------* diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index b425b2c28..9598b3596 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -441,10 +441,17 @@ void encod_gen_voic_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q6, Q_new, + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -745,7 +752,7 @@ void encod_gen_voic_ivas_fx( Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_sat( Lgcode ); #else - Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_o( Lgcode, &Overflow ); #endif @@ -859,10 +866,17 @@ void encod_gen_voic_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_AVQ_OUT_DEC, Q_new, + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index e04d42331..b355d540c 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -330,8 +330,13 @@ Word16 encod_tran_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -735,9 +740,15 @@ Word16 encod_tran_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); +#endif /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 82bfcbd2f..61413ba9e 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -376,7 +376,11 @@ void encod_gen_2sbfr( * Prepare TBE excitation *-----------------------------------------------------------------*/ +#ifdef FIX_2010_PREP_TBE_EXC + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q9, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); +#endif voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; /* Q15 */ move16(); -- GitLab From e514cc1ac1e42866127a89b67ff04cd8f0cd1c8f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 15 Sep 2025 00:00:30 +0200 Subject: [PATCH 2/3] fix comment + BE occurrances --- lib_com/swb_tbe_com_fx.c | 7 +++++-- lib_dec/ivas_td_low_rate_dec_fx.c | 2 +- lib_enc/ivas_td_low_rate_enc_fx.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index fb59ab3f3..ac42d1a0c 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7311,9 +7311,12 @@ void prep_tbe_exc_fx( { Word16 shift = 4; #ifdef FIX_2010_PREP_TBE_EXC - IF( element_mode != EVS_MONO ) + /* mul 2025-09-14 + TODO: check, which impact this has on EVS mono - for now, keep EVS modes BE + */ + IF( NE_16( element_mode, EVS_MONO ) ) { - /* shift of 4 assumes code_preQ_fx[] in Q9 - this is however not always given */ + /* shift of 4 assumes code_preQ_fx[] in Q10 - this is however not always given */ shift = add( 2 + 1 - 1, Q_code_preQ ); /* gain_preQ_fx in Q2, code_preQ_fx[] in Q_code_preQ, 1 additional left-shift by L_mult() - factor of 2 (from "2 * gain_preQ * code_preQ[i]") */ shift = sub( 16, shift ); } diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 2d2876585..385096ba6 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -327,7 +327,7 @@ void decod_gen_2sbfr_fx( *-----------------------------------------------------------------*/ #ifdef FIX_2010_PREP_TBE_EXC - prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, Q9, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, Q10, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #else prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #endif diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 61413ba9e..8832af43c 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -377,7 +377,7 @@ void encod_gen_2sbfr( *-----------------------------------------------------------------*/ #ifdef FIX_2010_PREP_TBE_EXC - prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q9, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q10, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #endif -- GitLab From 8871e698e22cf9dafa7e7d0f8236a932fd7f1391 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 15 Sep 2025 17:44:53 +0200 Subject: [PATCH 3/3] various smaller fixes and clarifications --- lib_com/swb_tbe_com_fx.c | 7 +++++-- lib_dec/dec_ace_fx.c | 2 +- lib_dec/dec_gen_voic_fx.c | 22 +++++++++++++++++++++- lib_dec/dec_tran_fx.c | 21 ++++++++++++++++++++- lib_enc/cod_ace_fx.c | 2 +- lib_enc/enc_gen_voic_fx.c | 7 ++++++- 6 files changed, 54 insertions(+), 7 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index ac42d1a0c..9f6b3f93b 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7311,8 +7311,11 @@ void prep_tbe_exc_fx( { Word16 shift = 4; #ifdef FIX_2010_PREP_TBE_EXC - /* mul 2025-09-14 - TODO: check, which impact this has on EVS mono - for now, keep EVS modes BE + /* multrus 2025-09-15 + TODO: + - leave shift = 4, since this is legacy code from EVS; + - check with vaillancourt, whether we really have a different scaling of code_preQ_fx[] for IVAS + - if the different scalings are confirmed, this condition could be simplified */ IF( NE_16( element_mode, EVS_MONO ) ) { diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 78b6c593f..b6554e02c 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -534,7 +534,7 @@ void decoder_acelp_fx( { #ifdef FIX_2010_PREP_TBE_EXC prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, - gain_preQ, code_preQ, Q9, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); + gain_preQ, code_preQ, Q10, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); #else prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index c7490ce52..39412a22e 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -100,6 +100,10 @@ ivas_error decod_gen_voic_fx( Word16 pf_temp[MAXLAG_WI]; Word16 pf_n2[MAXLAG_WI]; MUSIC_POSTFILT_HANDLE hMusicPF; +#ifdef FIX_2010_PREP_TBE_EXC + Word16 Q_code_preQ; +#endif + gain_pit_fx = 0; gain_code_fx = 0; norm_gain_code_fx = 0; @@ -323,8 +327,24 @@ ivas_error decod_gen_voic_fx( } #ifdef FIX_2010_PREP_TBE_EXC + /* + 2025-09-15 multrus: + TODO: + check with vaillancourt + - where this difference between EVS and IVAS comes from + - where Q_code_preQ could be derived + - whether any of the above calculations need to be adjusted + */ + Q_code_preQ = Q6; + move16(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + Q_code_preQ = Q10; + move16(); + } + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q6, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_code_preQ, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); #else diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index b01977023..b30b1a8c0 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -71,6 +71,9 @@ void decod_tran_fx( Word16 gain_code16; Word32 L_tmp; Word16 tmp16, tmp1_fx, tmp_fx; +#ifdef FIX_2010_PREP_TBE_EXC + Word16 Q_code_preQ; +#endif GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; MUSIC_POSTFILT_HANDLE hMusicPF; @@ -255,8 +258,24 @@ void decod_tran_fx( } #ifdef FIX_2010_PREP_TBE_EXC + /* + 2025-09-15 multrus: + TODO: + check with vaillancourt + - where this difference between EVS and IVAS comes from + - where Q_code_preQ could be derived + - whether any of the above calculations need to be adjusted + */ + Q_code_preQ = Q6; + move16(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + Q_code_preQ = Q10; + move16(); + } + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q10, + &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_code_preQ, st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); #else diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index a21781c0b..dc139873a 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -379,7 +379,7 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * { #ifdef FIX_2010_PREP_TBE_EXC prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q9, Q_new, T0, T0_frac, st->coder_type, st->core_brate, + bwe_exc, gain_preQ, code_preQ, Q10, Q_new, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #else prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 9598b3596..d0d293f70 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -442,8 +442,13 @@ void encod_gen_voic_fx( *-----------------------------------------------------------------*/ #ifdef FIX_2010_PREP_TBE_EXC + /* multrus 2025-09-15 + TODO: + - check with vaillancourt, whether Q10 is the correct scaling - it contradicts comments above, where it's rather indicated as Q6 + - comparing againt float, Q10 seems to be correct + */ prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q6, Q_new, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q10, Q_new, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); #else -- GitLab