From 89f908357bd4154f6fcd9e3fc6ab22de50eb9914 Mon Sep 17 00:00:00 2001 From: naghibza Date: Wed, 22 Oct 2025 20:45:45 +0200 Subject: [PATCH 1/3] Replace L_shl with L_shl_sat to prevent overflow when calculating scale factors for very small numbers in the logarithmic domain --- lib_com/options.h | 2 +- lib_enc/bw_detect_fx.c | 35 +++++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 5b0054649..3de0ebe28 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,7 @@ #define FIX_1785_ASSERT_IN_IVAS_JBM_DEC_RENDER_FX /* Orange: 10ms Rendering: Assert in ivas_jbm_dec_render_fx() -> scale_sig32 */ #define FIX_2081_REVISE_H1_SCALING /* VA: accommodate for H1 overshoot that was causing assert in set_impule. Not BE with MASA on LTV with bitrate switching for only 2 instances */ #define TEMP_FIX_2088_MSAN_INIT_ERROR /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */ - +#define FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING /* FhG: Replace L_shl with L_shl_sat to prevent overflow when calculating scale factors for very small numbers in the logarithmic domain */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 3f0def007..9cb8c4812 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -117,14 +117,25 @@ void bw_detect_fx( move32(); /* Q31 */ cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); - +#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING + if ( cldfb_bin[0] == 0 ) + { + cldfb_bin[0] = L_deposit_l( 1 ); + move32(); + } +#else if ( cldfb_bin[i] == 0 ) { cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ - L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif + L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ +#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING + L_tmp = L_add_sat( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#else + L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif cldfb_bin[0] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); move32(); /* 1/log2(10) */ /* Q25 */ @@ -153,8 +164,12 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ +#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING + L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); move32(); /* 1/log2(10) */ /* Q25 */ } @@ -192,8 +207,12 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ +#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING + L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); move32(); /* 1/log2(10) */ /* Q25 */ } @@ -225,8 +244,12 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ +#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING + L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#endif cldfb_bin[i] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); move32(); /* 1/log2(10) */ /* Q25 */ } -- GitLab From 4b0daa3bee815c7f2ce13d4fb87485882642f5f3 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 23 Oct 2025 09:45:15 +0200 Subject: [PATCH 2/3] Remove one fix to check the pipeline results. --- lib_enc/bw_detect_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 9cb8c4812..c46e5c010 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -117,7 +117,7 @@ void bw_detect_fx( move32(); /* Q31 */ cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); -#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifndef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING if ( cldfb_bin[0] == 0 ) { cldfb_bin[0] = L_deposit_l( 1 ); -- GitLab From e6cb9b3d347a7b566f2e66ce3c98fd0a428a1444 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 23 Oct 2025 11:25:02 +0200 Subject: [PATCH 3/3] Set cldfb_bin[0] to epsilon when it is zero. --- lib_com/options.h | 2 +- lib_enc/bw_detect_fx.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c3d344343..d5d5bd218 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -78,7 +78,7 @@ #define TEMP_FIX_2088_MSAN_INIT_ERROR /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */ #define FIX_2092_ASSERT_IN_OMASA_RENDER /* FhG, Nokia: Fix LTV crash due to overflow in OMASA EXT output */ #define FIX_2084_FLOATING_POINT_LEFTOVERS /* FhG: convert floating-point leftovers in IVAS_ENC_FeedObjectMetadata() */ -#define FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING /* FhG: Replace L_shl with L_shl_sat to prevent overflow when calculating scale factors for very small numbers in the logarithmic domain */ +#define FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING /* FhG: Replace L_shl with L_shl_sat to prevent overflow when calculating scale factors for very small numbers in the logarithmic domain */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index c46e5c010..49391f60f 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -117,7 +117,7 @@ void bw_detect_fx( move32(); /* Q31 */ cldfb_bin_Exp[0] = add( cldfb_bin_Exp[0], CLDFBscalingFactor_EXP ); move16(); -#ifndef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING if ( cldfb_bin[0] == 0 ) { cldfb_bin[0] = L_deposit_l( 1 ); @@ -131,7 +131,7 @@ void bw_detect_fx( } #endif L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING L_tmp = L_add_sat( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ #else L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -165,7 +165,7 @@ void bw_detect_fx( move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ #else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -208,7 +208,7 @@ void bw_detect_fx( move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ #else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ @@ -245,7 +245,7 @@ void bw_detect_fx( move32(); } L_tmp = BASOP_Util_Log2( cldfb_bin[i] ); /*(log2(660423549*2^(-31))/64)*2^31*/ -#ifdef FIX_ASSERT_IN_OMASA_BITRATE_SWITSCHING +#ifdef FIX_2141_ASSERT_IN_OMASA_BITRATE_SWITSCHING L_tmp = L_add( L_tmp, L_shl_sat( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ #else L_tmp = L_add( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[i] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ -- GitLab