From 759285f6f3ef192cdfc5677ce2271d9da8cc0c86 Mon Sep 17 00:00:00 2001 From: "Azizi, Arash" Date: Fri, 17 Apr 2026 14:58:17 +0200 Subject: [PATCH 1/3] Issue 2546: adding switch --- lib_com/options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/options.h b/lib_com/options.h index 499a45afc..2b3a45611 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,6 +98,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 FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* FhG: Fix issue 2546 Harmonize function tcx_scalar_quantization_rateloop*/ /* #################### End BE switches ################################## */ -- GitLab From 6a54b86297c349fb965de287a1948170383a013a Mon Sep 17 00:00:00 2001 From: "Azizi, Arash" Date: Mon, 20 Apr 2026 10:29:29 +0200 Subject: [PATCH 2/3] Issue 2546: Harmonizing function tcx_scalar_quantization_rateloop_ivas_fx(), minor editorial changes --- lib_enc/cod_tcx_fx.c | 61 ++++++++++++----- lib_enc/tcx_utils_enc_fx.c | 130 ++++++++++++++++++++++++++++++++++--- 2 files changed, 167 insertions(+), 24 deletions(-) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 72a8d01d3..913a53dbf 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1594,21 +1594,52 @@ void QuantizeSpectrum_fx( phm_cfg = hm_cfg; move16(); } - sqBits = tcx_scalar_quantization_rateloop_fx( spectrum, *spectrum_e, - sqQ, - L_spec, - &sqGain, &sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros, - prm_lastnz, /* lastnz */ - sqTargetBits, - &nEncoded, - &stop, - sqBits_noStop, - sqBits, - hTcxCfg->tcxRateLoopOpt, - tcxonly, - phm_cfg ); +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + sqBits = tcx_scalar_quantization_rateloop_fx(spectrum, *spectrum_e, + sqQ, + L_spec, + &sqGain, &sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + prm_lastnz, /* lastnz */ + sqTargetBits, + &nEncoded, + &stop, + sqBits_noStop, + sqBits, + hTcxCfg->tcxRateLoopOpt, + tcxonly, + phm_cfg ); +#else + Word16 max_iter = 4; + move16(); + IF(EQ_16(st->element_mode, IVAS_CPE_MDCT)) + { + max_iter = 2; + move16(); + } + sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum, *spectrum_e, + sqQ, + L_spec, + &sqGain, &sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + prm_lastnz, /* lastnz */ + sqTargetBits, + &nEncoded, + &stop, + sqBits_noStop, + sqBits, + hTcxCfg->tcxRateLoopOpt, + tcxonly, + phm_cfg, + max_iter, + st->element_mode); + //sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode); + +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + + IF( ctxHmBits > 0 ) /* Mapping tool is enabled */ { diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index db3c828d5..649a8f08c 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1753,14 +1753,15 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( move16(); Word16 tmp, fac1, fac2; Word32 tmp32; + Word16 lastnz, saturated, minSqGain = 0; move16(); - /* Init */ saturated = 0; move16(); /* minSqGain = (float) sqrt( (float) NORM_MDCT_FACTOR / (float) L_frame ); in Q14*/ - SWITCH( L_frame ) +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + SWITCH(L_frame) { case 80: minSqGain = 23170; @@ -1814,9 +1815,71 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( minSqGain = 4579; BREAK; default: - assert( 0 ); + assert(0); } move16(); +#else + IF(NE_16(element_mode, EVS_MONO)) { + SWITCH(L_frame) + { + case 80: + minSqGain = 23170; + BREAK; + case 100: + minSqGain = 20724; + BREAK; + case 160: + minSqGain = 16384; + BREAK; + case 200: + minSqGain = 14654; + BREAK; + case 240: + minSqGain = 13377; + BREAK; + case 300: + minSqGain = 11965; + BREAK; + case 320: + minSqGain = 11585; + BREAK; + case 400: + minSqGain = 10362; + BREAK; + case 480: + minSqGain = 9459; + BREAK; + case 600: + minSqGain = 8461; + BREAK; + case 640: + minSqGain = 8192; + BREAK; + case 800: + minSqGain = 7327; + BREAK; + case 960: + minSqGain = 6689; + BREAK; + case 1200: + minSqGain = 5983; + BREAK; + case 1440: + minSqGain = 5461; + BREAK; + case 1800: + minSqGain = 4885; + BREAK; + case 2048: + minSqGain = 4579; + BREAK; + default: + assert(0); + } + move16(); + } +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + sqGain = *gain; move16(); sqGain_e = *gain_e; @@ -1876,8 +1939,15 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( lb_e = sqGain_e; move16(); w_lb = add( sub( stopFlag, target ), kDampen ); +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR saturated = 0; move16(); +#else + IF(NE_16(element_mode, EVS_MONO)) { + saturated = 0; + move16(); + } +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR IF( ubfound != 0 ) { /* common exponent for addition */ @@ -1938,7 +2008,7 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( sqGain = mult( sqGain, sub( tmp, add( mod_adjust1, (Word16) 0x8000 ) ) ); sqGain = normalize16( sqGain, &sqGain_e ); } - +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR Word16 shift_tmp = s_max( sqGain_e, 1 ); move16(); test(); @@ -1951,11 +2021,33 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( saturated = 1; move16(); } +#else + IF(NE_16(element_mode, EVS_MONO )) { + Word16 shift_tmp = s_max(sqGain_e, 1); + move16(); + test(); + IF(LT_16(shl(sqGain, sub(sqGain_e, shift_tmp)), shl(minSqGain, sub(1, shift_tmp))) && EQ_16(tcxRateLoopOpt, 3)) + { + sqGain = minSqGain; + move16(); + sqGain_e = 1; + move16(); + saturated = 1; + move16(); + } + } +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR } +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR ELSE { BREAK; /* we cannot go any lower anyway*/ } +#else + ELSE IF(NE_16(element_mode, EVS_MONO)){ + BREAK; /* we cannot go any lower anyway*/ + } +#endif // FIX_BASOP_2546_HARMONIZE_TCX_SCALAR } ELSE /* tcxRateLoopOpt != 2 */ { @@ -2013,8 +2105,16 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( } /* Quantize spectrum */ - tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); - +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); +#else + IF(EQ_16(element_mode, EVS_MONO)) { + tcx_scalar_quantization_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); + } + ELSE{ + tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); + } +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* Estimate bitrate */ stopFlag = 1; move16(); @@ -2023,8 +2123,11 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( stopFlag = 0; move16(); } - - IF( GT_16( element_mode, EVS_MONO ) ) +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR + IF(GT_16(element_mode, EVS_MONO)) +#else + IF(NE_16(element_mode, EVS_MONO)) +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR { sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, 0, hm_cfg ); } @@ -2066,8 +2169,17 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( IF( GE_16( tcxRateLoopOpt, 1 ) ) { +#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* Quantize spectrum */ - tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); + tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); +#else + IF(EQ_16(element_mode, EVS_MONO)) { + tcx_scalar_quantization_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); + } + ELSE{ + tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); + } +#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* Output */ *nEncoded = old_nEncoded; -- GitLab From cae4c577fa85eef5dd590dd80a4ea50a5daa4920 Mon Sep 17 00:00:00 2001 From: "Azizi, Arash" Date: Mon, 20 Apr 2026 10:36:55 +0200 Subject: [PATCH 3/3] Issue 2546: Clang formatting patch --- lib_enc/cod_tcx_fx.c | 69 ++++++++-------- lib_enc/tcx_utils_enc_fx.c | 156 +++++++++++++++++++------------------ 2 files changed, 116 insertions(+), 109 deletions(-) diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 913a53dbf..e729dc67a 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1595,52 +1595,51 @@ void QuantizeSpectrum_fx( move16(); } #ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR - sqBits = tcx_scalar_quantization_rateloop_fx(spectrum, *spectrum_e, - sqQ, - L_spec, - &sqGain, &sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros, - prm_lastnz, /* lastnz */ - sqTargetBits, - &nEncoded, - &stop, - sqBits_noStop, - sqBits, - hTcxCfg->tcxRateLoopOpt, - tcxonly, - phm_cfg ); + sqBits = tcx_scalar_quantization_rateloop_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + &sqGain, &sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + prm_lastnz, /* lastnz */ + sqTargetBits, + &nEncoded, + &stop, + sqBits_noStop, + sqBits, + hTcxCfg->tcxRateLoopOpt, + tcxonly, + phm_cfg ); #else Word16 max_iter = 4; move16(); - IF(EQ_16(st->element_mode, IVAS_CPE_MDCT)) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { max_iter = 2; move16(); } - sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum, *spectrum_e, - sqQ, - L_spec, - &sqGain, &sqGain_e, - hTcxCfg->sq_rounding, - hTcxEnc->memQuantZeros, - prm_lastnz, /* lastnz */ - sqTargetBits, - &nEncoded, - &stop, - sqBits_noStop, - sqBits, - hTcxCfg->tcxRateLoopOpt, - tcxonly, - phm_cfg, - max_iter, - st->element_mode); - //sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode); + sqBits = tcx_scalar_quantization_rateloop_ivas_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + &sqGain, &sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + prm_lastnz, /* lastnz */ + sqTargetBits, + &nEncoded, + &stop, + sqBits_noStop, + sqBits, + hTcxCfg->tcxRateLoopOpt, + tcxonly, + phm_cfg, + max_iter, + st->element_mode ); + // sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode); #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR - IF( ctxHmBits > 0 ) /* Mapping tool is enabled */ { /* Truncate spectrum */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 649a8f08c..7c0abe833 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1761,7 +1761,7 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( move16(); /* minSqGain = (float) sqrt( (float) NORM_MDCT_FACTOR / (float) L_frame ); in Q14*/ #ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR - SWITCH(L_frame) + SWITCH( L_frame ) { case 80: minSqGain = 23170; @@ -1815,66 +1815,67 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( minSqGain = 4579; BREAK; default: - assert(0); + assert( 0 ); } move16(); #else - IF(NE_16(element_mode, EVS_MONO)) { - SWITCH(L_frame) + IF( NE_16( element_mode, EVS_MONO ) ) + { + SWITCH( L_frame ) { - case 80: - minSqGain = 23170; - BREAK; - case 100: - minSqGain = 20724; - BREAK; - case 160: - minSqGain = 16384; - BREAK; - case 200: - minSqGain = 14654; - BREAK; - case 240: - minSqGain = 13377; - BREAK; - case 300: - minSqGain = 11965; - BREAK; - case 320: - minSqGain = 11585; - BREAK; - case 400: - minSqGain = 10362; - BREAK; - case 480: - minSqGain = 9459; - BREAK; - case 600: - minSqGain = 8461; - BREAK; - case 640: - minSqGain = 8192; - BREAK; - case 800: - minSqGain = 7327; - BREAK; - case 960: - minSqGain = 6689; - BREAK; - case 1200: - minSqGain = 5983; - BREAK; - case 1440: - minSqGain = 5461; - BREAK; - case 1800: - minSqGain = 4885; - BREAK; - case 2048: - minSqGain = 4579; - BREAK; - default: - assert(0); + case 80: + minSqGain = 23170; + BREAK; + case 100: + minSqGain = 20724; + BREAK; + case 160: + minSqGain = 16384; + BREAK; + case 200: + minSqGain = 14654; + BREAK; + case 240: + minSqGain = 13377; + BREAK; + case 300: + minSqGain = 11965; + BREAK; + case 320: + minSqGain = 11585; + BREAK; + case 400: + minSqGain = 10362; + BREAK; + case 480: + minSqGain = 9459; + BREAK; + case 600: + minSqGain = 8461; + BREAK; + case 640: + minSqGain = 8192; + BREAK; + case 800: + minSqGain = 7327; + BREAK; + case 960: + minSqGain = 6689; + BREAK; + case 1200: + minSqGain = 5983; + BREAK; + case 1440: + minSqGain = 5461; + BREAK; + case 1800: + minSqGain = 4885; + BREAK; + case 2048: + minSqGain = 4579; + BREAK; + default: + assert( 0 ); } move16(); } @@ -1943,7 +1944,8 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( saturated = 0; move16(); #else - IF(NE_16(element_mode, EVS_MONO)) { + IF( NE_16( element_mode, EVS_MONO ) ) + { saturated = 0; move16(); } @@ -2022,11 +2024,12 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( move16(); } #else - IF(NE_16(element_mode, EVS_MONO )) { - Word16 shift_tmp = s_max(sqGain_e, 1); + IF( NE_16( element_mode, EVS_MONO ) ) + { + Word16 shift_tmp = s_max( sqGain_e, 1 ); move16(); test(); - IF(LT_16(shl(sqGain, sub(sqGain_e, shift_tmp)), shl(minSqGain, sub(1, shift_tmp))) && EQ_16(tcxRateLoopOpt, 3)) + IF( LT_16( shl( sqGain, sub( sqGain_e, shift_tmp ) ), shl( minSqGain, sub( 1, shift_tmp ) ) ) && EQ_16( tcxRateLoopOpt, 3 ) ) { sqGain = minSqGain; move16(); @@ -2044,7 +2047,8 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( BREAK; /* we cannot go any lower anyway*/ } #else - ELSE IF(NE_16(element_mode, EVS_MONO)){ + ELSE IF( NE_16( element_mode, EVS_MONO ) ) + { BREAK; /* we cannot go any lower anyway*/ } #endif // FIX_BASOP_2546_HARMONIZE_TCX_SCALAR @@ -2106,13 +2110,15 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( /* Quantize spectrum */ #ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR - tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); + tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); #else - IF(EQ_16(element_mode, EVS_MONO)) { - tcx_scalar_quantization_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); + IF( EQ_16( element_mode, EVS_MONO ) ) + { + tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); } - ELSE{ - tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly); + ELSE + { + tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); } #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* Estimate bitrate */ @@ -2124,9 +2130,9 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( move16(); } #ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR - IF(GT_16(element_mode, EVS_MONO)) + IF( GT_16( element_mode, EVS_MONO ) ) #else - IF(NE_16(element_mode, EVS_MONO)) + IF( NE_16( element_mode, EVS_MONO ) ) #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR { sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, 0, hm_cfg ); @@ -2171,13 +2177,15 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( { #ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR /* Quantize spectrum */ - tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); + tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); #else - IF(EQ_16(element_mode, EVS_MONO)) { - tcx_scalar_quantization_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); + IF( EQ_16( element_mode, EVS_MONO ) ) + { + tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); } - ELSE{ - tcx_scalar_quantization_ivas_fx(x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly); + ELSE + { + tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); } #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR -- GitLab