From f14d119d02d7c6911f74d2ee236defecb43d4184 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 27 Oct 2025 12:35:22 -0400 Subject: [PATCH 1/4] possible fix to 2015 --- lib_com/options.h | 2 +- lib_enc/ivas_core_pre_proc_front_fx.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index ea5fad27e..1ee92b2ac 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -81,7 +81,7 @@ #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 */ #define FIX_APA_EXECS_SCALING /* VA: fix scaling of JBM APA buffer */ #define FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT /* Nokia: Issue 2164: Prevent overflow when calculating equalization coefficient for editing before clamping to safe range */ - +#define FIX_2015_PREMPH_SAT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index fff73a248..aaa0c396a 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -231,7 +231,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); Word16 input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) +#ifndef FIX_2015_PREMPH_SAT Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); +#else + Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 + 1 ) ); +#endif Q_min = s_max( -2, Q_min ); Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min st->q_inp = Q_min; -- GitLab From 26fb5a3d19df93c3514c5d0924d30e0e761c40ff Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 28 Oct 2025 13:48:37 -0400 Subject: [PATCH 2/4] alternative fix to 2015 --- lib_com/options.h | 5 ++++- lib_com/preemph_fx.c | 29 ++++++++++++++++++++++++++- lib_com/prot_fx.h | 15 +++++++++++++- lib_enc/ivas_core_pre_proc_front_fx.c | 6 ++++-- lib_enc/ivas_core_pre_proc_fx.c | 6 ++++-- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c0c815697..2d722bee1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,10 @@ #define FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT /* Nokia: Issue 2164: Prevent overflow when calculating equalization coefficient for editing before clamping to safe range */ #define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */ -#define FIX_2015_PREMPH_SAT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor */ +/*#define FIX_2015_PREMPH_SAT*/ /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor */ +#ifndef FIX_2015_PREMPH_SAT +#define FIX_2015_PREMPH_SAT_ALT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor, alternative fix where only preemphis gets 1 more bit headroom */ +#endif /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 0184a4aa3..e8dfb4018 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -39,7 +39,7 @@ void preemph_copy_fx( return; } - +#ifndef FIX_2015_PREMPH_SAT_ALT void preemph_copy_32fx( const Word16 x[], /* i : input signal Qx */ Word32 y[], /* o : output signal Qx */ @@ -66,7 +66,34 @@ void preemph_copy_32fx( return; } +#else +void preemph_copy_32fx2( + const Word16 x[], /* i : input signal Qx */ + Word32 y[], /* o : output signal Qx-1*/ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ +) +{ + Word16 i, temp; + + temp = x[lg - 1]; /* Qx */ + move16(); + FOR( i = lg - 1; i > 0; i-- ) + { + y[i] = L_msu0_sat( L_mult( x[i], 16384 ), x[i - 1], mu ); /* Qx+16 */ + move16(); + } + y[0] = L_msu0_sat( L_mult( x[0], 16384 ), *mem, mu ); /* Qx+16 */ + move16(); + + *mem = temp; /* Qx */ + move16(); + + return; +} +#endif /*-------------------------------------------------------------* * preemph_ivas_fx() * diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 32b8a00ee..8202b5548 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2754,8 +2754,11 @@ void lag_wind_32( // preemp_fx.c #define PREEMPH_FX( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) +#ifndef FIX_2015_PREMPH_SAT_ALT #define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) - +#else +#define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx2( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) +#endif void preemph_copy_fx( const Word16 x[], /* i : i signal Qx */ Word16 y[], /* o : output signal Qx */ @@ -2764,6 +2767,7 @@ void preemph_copy_fx( Word16 *mem /* i/o: memory (x[-1]) Qx */ ); +#ifndef FIX_2015_PREMPH_SAT_ALT void preemph_copy_32fx( const Word16 x[], /* i : i signal Qx */ Word32 y[], /* o : output signal Qx */ @@ -2771,6 +2775,15 @@ void preemph_copy_32fx( const Word16 lg, /* i : vector size Q0 */ Word16 *mem /* i/o: memory (x[-1]) Qx */ ); +#else +void preemph_copy_32fx2( + const Word16 x[], /* i : i signal Qx */ + Word32 y[], /* o : output signal Qx */ + const Word16 mu, /* i : preemphasis coefficient Q15 */ + const Word16 lg, /* i : vector size Q0 */ + Word16 *mem /* i/o: memory (x[-1]) Qx */ +); +#endif void E_UTIL_f_preemph2( Word16 shift, /* Q0 */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index aaa0c396a..0711b778d 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -718,9 +718,11 @@ ivas_error pre_proc_front_ivas_fx( *Q_new = add( *Q_new, Q_inp_const ); move16(); - +#ifndef FIX_2015_PREMPH_SAT_ALT Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( *Q_new, st->q_inp ) ); /* Q_new */ - +#else + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( add( *Q_new, 1 ), st->q_inp ) ); /* Q_new */ +#endif Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, st->q_inp ) ); /* Q_new */ cldfbScale.hb_scale = cldfbScale.lb_scale; diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 623b38e68..5246e2026 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1071,9 +1071,11 @@ ivas_error ivas_compute_core_buffers_fx( } st->Q_max_16k[i] = shift; move16(); - +#ifndef FIX_2015_PREMPH_SAT_ALT Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); - +#else + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) ); +#endif Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new ); } ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ -- GitLab From a51c49619841707dd6def5e6ad36fe65cd71c157 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 28 Oct 2025 13:56:58 -0400 Subject: [PATCH 3/4] fix clang format --- lib_com/prot_fx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 8202b5548..1f373c285 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2753,7 +2753,7 @@ void lag_wind_32( ); // preemp_fx.c -#define PREEMPH_FX( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) +#define PREEMPH_FX( signal, mu, L, mem ) preemph_copy_fx( ( signal ), ( signal ), ( mu ), ( L ), ( mem ) ) #ifndef FIX_2015_PREMPH_SAT_ALT #define PREEMPH_32FX( signal, signal_out, mu, L, mem ) preemph_copy_32fx( ( signal ), ( signal_out ), ( mu ), ( L ), ( mem ) ) #else -- GitLab From e453a4f4d1e5046fe8dbf806d1aaac95bd6520ea Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 30 Oct 2025 13:21:10 -0400 Subject: [PATCH 4/4] Keep the fix that has a minimal impact --- lib_com/options.h | 5 +---- lib_enc/ivas_core_pre_proc_front_fx.c | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 251456f2f..02e8d48a5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,10 +84,7 @@ #define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */ #define OPT_2146_BASOP_UTIL_ADD_MANT32EXP /* Dlb: optimized version of BASOP_Util_Add_Mant32Exp() */ -/*#define FIX_2015_PREMPH_SAT*/ /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor */ -#ifndef FIX_2015_PREMPH_SAT -#define FIX_2015_PREMPH_SAT_ALT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor, alternative fix where only preemphis gets 1 more bit headroom */ -#endif +#define FIX_2015_PREMPH_SAT_ALT /* VA: saturation can happen during preemphasis filtering due to a too aggressive scaling factor, allows preemphis to get 1 more bit headroom */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 0711b778d..0a12c05ea 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -231,11 +231,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_min = add( sub( 15, st->exp_old_inp_12k8 ), norm_arr( st->old_inp_12k8_fx, L_INP_MEM ) ); Word16 input_frame_full = shl( input_frame, 1 ); //(old frame input length + new frame input length) -#ifndef FIX_2015_PREMPH_SAT Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 ) ); -#else - Q_min = s_min( Q_min, sub( add( getScaleFactor32( st->input32_fx - input_frame, input_frame_full ), st->q_inp32 ), 16 + 1 ) ); -#endif Q_min = s_max( -2, Q_min ); Copy_Scale_sig_32_16( st->input32_fx - input_frame, st->input_fx - input_frame, input_frame_full, sub( Q_min, st->q_inp32 ) ); // Q_min st->q_inp = Q_min; -- GitLab