Commit 5471470d authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

Ported ivas_set_reverb_acoustic_data() - requires testing and cleanup

parent a992f675
Loading
Loading
Loading
Loading
Loading
+47 −44
Original line number Diff line number Diff line
@@ -1282,20 +1282,6 @@ static void set_reverb_acoustic_data_fx(
    ivas_reverb_interp_on_freq_grid_fx( nr_fc_input, pFc_input_fx, pAcoustic_rt60_fx, nr_fc_fft_filter, pFc_fx, pRt60_fx ); // Q26
    ivas_reverb_interp_on_freq_grid_fx( nr_fc_input, pFc_input_fx, pAcoustic_dsr_fx, nr_fc_fft_filter, pFc_fx, pDsr_fx );   // Q30

    ///* ---------Start Debugging Block --------------------*/
    // FILE *filewriter = fopen( "output.csv", "w" );
    // if (filewriter == NULL)
    //{
    //     perror("Failed to open file");
    // }
    // fprintf( filewriter, "T60, DSR\n" );
    // for ( int i = 0; i < nr_fc_fft_filter; ++i )
    //{
    //     fprintf(filewriter, "%f,%f\n",(float)pRt60_fx[i]/(1 << 26), (float)pDsr_fx[i] / (1<<30));
    // }
    // fclose( filewriter );
    ///* ---------End Debugging Block --------------------*/

    ///* adjust DSR for the delay difference */

    delay_diff_fx = L_sub( pRoomAcoustics->inputPreDelay_fx, pRoomAcoustics->acousticPreDelay_fx ); // Q27
@@ -1312,42 +1298,59 @@ static void set_reverb_acoustic_data_fx(
        exp_argument_fx = L_shr_sat( exp_argument_fx, sub( 6, exp_argument_e ) ); //exp_argument_fx in Q26 - verified

        /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */

        // 23 in Q26
        tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 1543503872, 5 );
        IF( tmp_flag > 0 )
        IF( GT_32( exp_argument_fx, 1543503872 ) ) // 23 in Q26
        {
            exp_argument_fx = 23552;
            move16();
            exp_argument_e = 5;
            move16();
            exp_argument_fx = 1543503872;
        }

        tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 0, 31 );
        IF( tmp_flag < 0 )
        IF( LT_32( exp_argument_fx, -1543503872 ) ) //-23 in Q26
        {
            tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( negate( exp_argument_fx ) ), exp_argument_e, 1543503872, 5 );
            IF( tmp_flag < 0 )
            {
                exp_argument_fx = -23552;
                move16();
                exp_argument_e = 5;
                move16();
            }
            exp_argument_fx = -1543503872;
        }

        Word16 tmp_exp;
        /* expf(exp_argument) -> pow(2, log2(e) * exp_argument) */
        tmp = mult( 23637, exp_argument_fx ); // exp_argument_e + 1
        tmp_exp = add( exp_argument_e, 1 );
        L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp );
        L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] );
        tmp_exp = add( pow_exp, pDsr_e[bin_idx] );
        tmp = Mpy_32_32( 96817114, exp_argument_fx ); // Q21 -> multiplication of Q26 by Q26 // x * 1/ln(2) it is ensured that exp_argument_fx is always in Q26

        L_tmp = BASOP_util_Pow2( tmp, 10, &pow_exp );  // Q28 -> not always, because pow_exp is not fixed
        L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] );  // Q27 if result of previous step is in Q28
        L_tmp = L_shl_sat( L_tmp, add( 1, pow_exp ) ); // L_tmp in Q31

        pDsr_fx[bin_idx] = L_tmp;
        move32();
        pDsr_e[bin_idx] = tmp_exp;
        move16();

        // 23 in Q26
        //tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 1543503872, 5 );
        //IF( tmp_flag > 0 )
        //{
        //    exp_argument_fx = 23552;
        //    move16();
        //    exp_argument_e = 5;
        //    move16();
        //}

        //tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( exp_argument_fx ), exp_argument_e, 0, 31 );
        //IF( tmp_flag < 0 )
        //{
        //    tmp_flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( negate( exp_argument_fx ) ), exp_argument_e, 1543503872, 5 );
        //    IF( tmp_flag < 0 )
        //    {
        //        exp_argument_fx = -23552;
        //        move16();
        //        exp_argument_e = 5;
        //        move16();
        //    }
        //}

        //Word16 tmp_exp;
        ///* expf(exp_argument) -> pow(2, log2(e) * exp_argument) */
        //tmp = mult( 23637, exp_argument_fx ); // exp_argument_e + 1
        //tmp_exp = add( exp_argument_e, 1 );
        //L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp );
        //L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] );
        //tmp_exp = add( pow_exp, pDsr_e[bin_idx] );

        //pDsr_fx[bin_idx] = L_tmp;
        //move32();
        //pDsr_e[bin_idx] = tmp_exp;
        //move16();
    }
    return;
}