From bca9f9845a9be0e520e715eb8a656806111ef433 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 16 Apr 2026 10:49:29 +0200 Subject: [PATCH 1/2] add macro HARMONIZE_2543_SQ_gain and code --- lib_com/options.h | 1 + lib_enc/cod_tcx_fx.c | 24 ++++++++++++++++++++++++ lib_enc/prot_fx_enc.h | 11 +++++++++++ lib_enc/tcx_utils_enc_fx.c | 30 +++++++++++++++++++++++------- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 5f27f69da..4f42728df 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -97,6 +97,7 @@ #define FIX_BASOP_2509_EVS_CONCEAL_UNINIT_MEM /* FhG: BASOP 2509: st->hTcxCfg->psychParamsCurrent is not initialized */ #define HARMONIZE_2499_CONFIGUREFDCNGDEC /* FhG: basop issue 2499: harmonoize configureFdCngDec */ #define FIX_BASOP_2530_IVAS_DECISION_MAT /* VA: Fix ambiguous usage of extract_l() */ +#define HARMONIZE_2543_SQ_gain /* FhG: Harmonize SQ_gain */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 72a8d01d3..c67dc3562 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1432,10 +1432,18 @@ void QuantizeSpectrum_fx( /* Quantize original spectrum */ +#ifdef HARMONIZE_2543_SQ_gain + sqGain = SQ_gain_fx( OriginalSpectrum, OriginalSpectrum_e, + shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), + L_spec, + &sqGain_e, + EVS_MONO ); +#else sqGain = SQ_gain_fx( OriginalSpectrum, OriginalSpectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); +#endif tcx_scalar_quantization_fx( OriginalSpectrum, OriginalSpectrum_e, sqQ, @@ -1524,10 +1532,18 @@ void QuantizeSpectrum_fx( PeriodicityIndex = -1; move16(); +#ifdef HARMONIZE_2543_SQ_gain + sqGain = SQ_gain_fx( spectrum, *spectrum_e, + shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), + L_spec, + &sqGain_e, + EVS_MONO ); +#else sqGain = SQ_gain_fx( spectrum, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); +#endif /* Quantize spectrum */ @@ -3027,7 +3043,11 @@ void QuantizeTCXSpectrum_fx( } /* Quantize original spectrum */ +#ifdef HARMONIZE_2543_SQ_gain + sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e, st->element_mode ); +#else sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e ); +#endif tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly ); @@ -3118,7 +3138,11 @@ void QuantizeTCXSpectrum_fx( } ELSE { +#ifdef HARMONIZE_2543_SQ_gain + sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e, st->element_mode ); +#else sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); +#endif } /* Quantize spectrum */ tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d59870610..824a986dc 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1081,6 +1081,16 @@ void AdaptLowFreqEmph_fx( const Word16 lg ); /* o : SQ gain */ +#ifdef HARMONIZE_2543_SQ_gain +Word16 SQ_gain_fx( + Word32 x[], /* i : vector to quantize */ + Word16 x_e, /* i : exponent */ + Word16 nbitsSQ, /* i : number of bits targeted */ + Word16 lg, /* i : vector size (2048 max) */ + Word16 *gain_e, /* o : SQ gain exponent */ + Word16 element_mode /* i : is EVS or not */ +); +#else Word16 SQ_gain_fx( Word32 x[], /* i : vector to quantize */ Word16 x_e, /* i : exponent */ @@ -1097,6 +1107,7 @@ Word16 SQ_gain_ivas_fx( Word16 lg, /* i : vector size (2048 max) */ Word16 *gain_e /* o : SQ gain exponent */ ); +#endif /* o : SQ gain */ Word16 SQ_gain_estimate_fx( diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index db3c828d5..f8bdd73a7 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -827,7 +827,7 @@ void PsychAdaptLowFreqEmph_fx( return; } - +#ifndef HARMONIZE_2543_SQ_gain /* o: SQ gain */ Word16 SQ_gain_fx( Word32 x[], /* i : vector to quantize */ @@ -941,15 +941,27 @@ Word16 SQ_gain_fx( return tmp16; } - +#endif /* o: SQ gain */ +#ifdef HARMONIZE_2543_SQ_gain +Word16 SQ_gain_fx( + Word32 x[], /* i : vector to quantize */ + Word16 x_e, /* i : exponent */ + Word16 nbitsSQ, /* i : number of bits targeted */ + Word16 lg, /* i : vector size (2048 max) */ + Word16 *gain_e, /* o : SQ gain exponent */ + Word16 element_mode /* i : is EVS or not */ +) +#else Word16 SQ_gain_ivas_fx( - Word32 x[], /* i : vector to quantize */ - Word16 x_e, /* i : exponent */ - Word16 nbitsSQ, /* i : number of bits targeted */ - Word16 lg, /* i : vector size (2048 max) */ - Word16 *gain_e ) /* o : SQ gain exponent */ + Word32 x[], /* i : vector to quantize */ + Word16 x_e, /* i : exponent */ + Word16 nbitsSQ, /* i : number of bits targeted */ + Word16 lg, /* i : vector size (2048 max) */ + Word16 *gain_e /* o : SQ gain exponent */ +) +#endif { Word16 i, iter, lg_4, s, tmp16; Word32 ener, tmp32; @@ -1009,7 +1021,11 @@ Word16 SQ_gain_ivas_fx( s = shl( sub( x_e, s ), 1 ); /* log */ +#ifdef HARMONIZE_2543_SQ_gain + IF( EQ_32( ener, 1 ) && GT_16( element_mode, EVS_MONO ) ) +#else IF( EQ_32( ener, 1 ) ) +#endif { en[i] = -131072; /* log10(0.01) in Q16 */ move32(); -- GitLab From d331117da682fa11bbf098a031200d78f1c6be03 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 16 Apr 2026 10:32:27 +0000 Subject: [PATCH 2/2] make really sure we dont use EVS in IVAS case --- lib_enc/cod_tcx_fx.c | 4 ++-- lib_enc/tcx_utils_enc_fx.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index c67dc3562..b16e25b0d 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3044,7 +3044,7 @@ void QuantizeTCXSpectrum_fx( /* Quantize original spectrum */ #ifdef HARMONIZE_2543_SQ_gain - sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e, st->element_mode ); + sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e, 1 /*signal non-EVS*/ ); #else sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e ); #endif @@ -3139,7 +3139,7 @@ void QuantizeTCXSpectrum_fx( ELSE { #ifdef HARMONIZE_2543_SQ_gain - sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e, st->element_mode ); + sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e, 1 /*signal non-EVS*/ ); #else sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e ); #endif diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index f8bdd73a7..e833af057 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1022,6 +1022,7 @@ Word16 SQ_gain_ivas_fx( /* log */ #ifdef HARMONIZE_2543_SQ_gain + test(); IF( EQ_32( ener, 1 ) && GT_16( element_mode, EVS_MONO ) ) #else IF( EQ_32( ener, 1 ) ) -- GitLab