From 3b3693992a954e8b3077a9f44780fa1ff821fb8d Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 24 Mar 2025 08:19:04 +0100 Subject: [PATCH] Port fix FIX_963_USAN_ERROR to resolve division-by-zero in Stereo CNG --- lib_com/options.h | 1 + lib_enc/ivas_stereo_dft_enc_itd.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index ee26612db..78b334485 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -204,6 +204,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.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 1d973e92d..305031975 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -914,7 +914,18 @@ void stereo_dft_enc_compute_itd( { hStereoDft->expectedNumUpdates += 1 + min( hCPE->hFrontVad[0]->rem_dtx_ho, hCPE->hFrontVad[1]->rem_dtx_ho ); } +#ifdef FIX_963_USAN_ERROR + if ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates == 0 ) + { + cng_xcorr_filt = max( CORR_FILT, sfm_L ); + } + else + { + cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); + } +#else cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); +#endif hStereoDft->currentNumUpdates++; for ( i = 1; i < NFFT / 2; i++ ) { @@ -949,7 +960,18 @@ void stereo_dft_enc_compute_itd( if ( vad_flag_dtx[0] == 0 ) { /* expectedNumUpdates updated after call to dtx() in SID frames */ +#ifdef FIX_963_USAN_ERROR + if ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates == 0 ) + { + cng_xcorr_filt = max( CORR_FILT, sfm_L ); + } + else + { + cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); + } +#else cng_xcorr_filt = max( min( CORR_FILT, 10.0f * CORR_FILT / ( hStereoDft->expectedNumUpdates + hStereoDft->currentNumUpdates ) ), sfm_L ); +#endif hStereoDft->currentNumUpdates++; hStereoDft->sfm = cng_xcorr_filt; } -- GitLab