Commit 8bc69a4a authored by multrus's avatar multrus
Browse files

add safety mechanism to not overflow when adding the two energy values

parent eb97f380
Loading
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -3261,11 +3261,19 @@ void stereo_dft_generate_res_pred_fx(
            dmx_nrg = L_shl( dmx_nrg, norm_dmx_nrg );
            q_dmx_nrg = add( sub( shl( hStereoDft->q_dft, 1 ), 31 ), norm_dmx_nrg );

            q_diff = sub( hStereoDft->q_hb_nrg[0], q_dmx_nrg );

            /* dmx_nrg * 2 / hStereoDft->NFFT */
            L_temp = BASOP_Util_Divide3232_Scale_newton( dmx_nrg, shr( hStereoDft->NFFT, 1 ), &temp_e );
            L_temp = L_shr( L_temp, sub( 31, temp_e ) );
            L_temp = L_shr( L_temp, sub( 31, temp_e ) ); /* q_dmx_nrg */

            /* for L_temp we have at least one bit of headroom due to the division above; check also for hStereoDft->hb_nrg_fx[0] and possibly reserve one bit*/
            test();
            IF( norm_l( hStereoDft->hb_nrg_fx[0] ) == 0 && hStereoDft->hb_nrg_fx[0] != 0 )
            {
                hStereoDft->hb_nrg_fx[0] = L_shr( hStereoDft->hb_nrg_fx[0], 1 );
                hStereoDft->q_hb_nrg[0] = sub( hStereoDft->q_hb_nrg[0], 1 );
            }

            q_diff = sub( hStereoDft->q_hb_nrg[0], q_dmx_nrg );

            IF( GT_16( q_diff, 0 ) )
            {