Commit 9a99d91e authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Change exponent calculation to make the code more readable in compute_t60_coeffs_fx().

parent 70166a4c
Loading
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -703,6 +703,7 @@ static ivas_error compute_t60_coeffs_fx(
                // If RT60 is 0, target gain is -120dB
#ifdef FIX_1942_ASSERTION_LOWSHELF
                target_gains_db_fx[bin_idx] = M120Q8;
                move16();
#else
                target_gains_db_fx[bin_idx] = min120q8;
#endif
@@ -711,25 +712,28 @@ static ivas_error compute_t60_coeffs_fx(
            {
                tmp = BASOP_Util_Divide3232_Scale( L_deposit_h( loop_delay_sec_fx ), pParams->pRt60_fx[bin_idx], &e );
#ifdef FIX_1942_ASSERTION_LOWSHELF
                tmp_e = sub( add( e, 0 ), 5 ); // L_deposit_h( loop_delay_sec_fx ):Q0.31, pParams->pRt60_fx[bin_idx]:Q5.26
                tmp_e = add( e, sub( 0 , 5 ) ); // L_deposit_h( loop_delay_sec_fx ):Q0.31, pParams->pRt60_fx[bin_idx]:Q5.26
                
                tmp_e = add( tmp_e, 6 ); // + Q6.9(M60Q9)
                target_gains_db_fx[bin_idx] = mult( M60Q9, tmp );
                tmp_e = add( tmp_e, 6 ); // + Q6.9(Q9)
                
                // gain < - 120 ? -120: gain
                IF( GT_16( tmp_e, 7 ) ) // Q7.8(Q8)
                tmp_e = sub( tmp_e, 7 ); // - Q7.8(M120Q8)
                IF( GT_16( tmp_e, 0 ) )
                {
                    IF( LT_16( target_gains_db_fx[bin_idx], shr( M120Q8, tmp_e - 7 ) ) )
                    IF( LT_16( target_gains_db_fx[bin_idx], shr( M120Q8, tmp_e ) ) )
                    {
                        target_gains_db_fx[bin_idx] = M120Q8; // Q8
                        move16();
                    }
                    ELSE
                    {
                        target_gains_db_fx[bin_idx] = shl_r( target_gains_db_fx[bin_idx], tmp_e - 7 ); // Q8, gain must be less than 128
                        target_gains_db_fx[bin_idx] = shl_r( target_gains_db_fx[bin_idx], tmp_e ); // Q8, gain must be less than 128
                    }
                }
                ELSE
                {
                    target_gains_db_fx[bin_idx] = shl_r( target_gains_db_fx[bin_idx], tmp_e - 7 ); // Q8, gain must be less than 128
                    target_gains_db_fx[bin_idx] = shl_r( target_gains_db_fx[bin_idx], tmp_e ); // Q8, gain must be less than 128
                    IF( LT_16( target_gains_db_fx[bin_idx], M120Q8 ) )
                    {
                        target_gains_db_fx[bin_idx] = M120Q8; // Q8