From 3ea42c3cfc076a1aa860992788690a628de86156 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 31 Jan 2024 16:45:08 +0100 Subject: [PATCH] Add FIX_963_USAN_ERROR to address division by zero --- 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 73710db2b0..dd3daf3f18 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,7 @@ #define FIX_955_FASTCONV_REND_IN_ISM /* VA: put FastConv rendering call under DEBUGGING */ #define FIX_969_USAN_IGF_ARITH /* FhG: issue 969: fix USAN error in igf_sce_dec; same issue as #962 */ #define FIX_959_MASA_LINEAR_REND /* VA: issue 959: remove unused calling of ivas_sba_linear_renderer() in MASA rendering */ +#define FIX_963_USAN_ERROR /* Eri: Issue 963: USAN error in Stereo CNG, division by zero */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index d3336f4eb6..13b72ea7b9 100755 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -908,7 +908,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++ ) { @@ -943,7 +954,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