Commit de86dcf1 authored by norvell's avatar norvell
Browse files

Port fix FIX_963_USAN_ERROR to address division-by-zero in Stereo CNG

parent f9caa3f4
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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 ############################ */

+30 −2
Original line number Diff line number Diff line
@@ -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;