From de86dcf18c360f6e5154c30de8cb8090e191ddf1 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 24 Mar 2025 08:55:42 +0100 Subject: [PATCH] Port fix FIX_963_USAN_ERROR to address division-by-zero in Stereo CNG --- lib_com/options.h | 1 + lib_enc/ivas_stereo_dft_enc_itd_fx.c | 32 ++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 3b3adbf01..6de35cc23 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -189,6 +189,7 @@ #define FIX_929_RENDERER_CMDL /* Nokia: issue #929: renderer command line option */ #define NONBE_FIX_BINAURAL_ROOM_IR_REVERBERATOR /* FhG: re-enable acidentially disabled reverberator for BINAURAL_ROOM_IR */ #define NONBE_FIX_1058_DECODER_ERROR_WITH_REVERB_ROOM /* FhG: issue 1058: do not initialize EFAP when IntSetup is HOA3 */ +#define FIX_963_USAN_ERROR /* Eri: Issue 963: USAN error in Stereo CNG, division by zero */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_enc/ivas_stereo_dft_enc_itd_fx.c b/lib_enc/ivas_stereo_dft_enc_itd_fx.c index af10f7dea..2853cb989 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd_fx.c +++ b/lib_enc/ivas_stereo_dft_enc_itd_fx.c @@ -1713,11 +1713,24 @@ void stereo_dft_enc_compute_itd_fx( move16(); } // cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); - +#ifdef FIX_963_USAN_ERROR + IF( add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ) == 0 ) + { + cng_xcorr_filt = CORR_FILT_Q31; + move32(); + cng_xcorr_filt = L_max( cng_xcorr_filt, sfm_L ); // Q31 + } + ELSE + { + cng_xcorr_filt = BASOP_Util_Divide3232_Scale_cadence( 8 /*10.0f * CORR_FILT*/, add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ), &cng_xcorr_filt_e ); + cng_xcorr_filt = L_shl_sat( cng_xcorr_filt, cng_xcorr_filt_e ); // Q31 + cng_xcorr_filt = L_max( L_min( CORR_FILT_Q31, cng_xcorr_filt ), sfm_L ); // Q31 + } +#else cng_xcorr_filt = BASOP_Util_Divide3232_Scale_cadence( 8 /*10.0f * CORR_FILT*/, add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ), &cng_xcorr_filt_e ); cng_xcorr_filt = L_shl_sat( cng_xcorr_filt, cng_xcorr_filt_e ); // Q31 cng_xcorr_filt = L_max( L_min( CORR_FILT_Q31, cng_xcorr_filt ), sfm_L ); // Q31 - +#endif hStereoDft->currentNumUpdates = add( hStereoDft->currentNumUpdates, 1 ); move16(); FOR( i = 1; i < NFFT / 4; i++ ) @@ -1773,6 +1786,20 @@ void stereo_dft_enc_compute_itd_fx( { /* expectedNumUpdates updated after call to dtx() in SID frames */ // cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); +#ifdef FIX_963_USAN_ERROR + IF( add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ) == 0 ) + { + cng_xcorr_filt = CORR_FILT_Q31; + move32(); + cng_xcorr_filt = L_max( cng_xcorr_filt, sfm_L ); // Q31 + } + ELSE + { + cng_xcorr_filt = BASOP_Util_Divide3232_Scale_cadence( 8 /*10.0f * CORR_FILT*/, add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ), &cng_xcorr_filt_e ); + cng_xcorr_filt = L_shl_sat( cng_xcorr_filt, cng_xcorr_filt_e ); // Q31 + cng_xcorr_filt = L_max( L_min( CORR_FILT_Q31, cng_xcorr_filt ), sfm_L ); // Q31 + } +#else IF( add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ) != 0 ) { cng_xcorr_filt = BASOP_Util_Divide3232_Scale_cadence( 8 /*10.0f * CORR_FILT*/, add( hStereoDft->expectedNumUpdates, hStereoDft->currentNumUpdates ), &cng_xcorr_filt_e ); @@ -1785,6 +1812,7 @@ void stereo_dft_enc_compute_itd_fx( move32(); cng_xcorr_filt = L_max( cng_xcorr_filt, sfm_L ); // Q31 } +#endif hStereoDft->currentNumUpdates = add( hStereoDft->currentNumUpdates, 1 ); move16(); hStereoDft->sfm_fx = cng_xcorr_filt; -- GitLab