Commit 9c27f397 authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

Added general interpolate function and converted center frequency calculation to fixed point

parent 62e78a91
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1122,6 +1122,14 @@ void ivas_reverb_interpolate_energies_fx(
    Word32 *pOutput_ene_r   // output in Q28
);
#endif
void ivas_reverb_interp_on_freq_grid_fx(
    const Word16 input_table_size,
    const Word32 *pInput_fc, //input center frequencies in Q16
    const Word32 *pInput_grid, //input data vector in an arbitrary Q-format
    const Word16 output_table_size,
    const Word32 *pOutput_fc,
    Word32 *pOutput_grid //output in the same Q-format as input
);
/*---------------------------------------------------------------------------------*
 * Shoebox Prototypes
 *-----------------------------------------------------------------------------------*/
+72 −32
Original line number Diff line number Diff line
@@ -908,20 +908,6 @@ void ivas_reverb_interpolate_acoustic_data_fx(

        pOutput_t60[output_idx] = L_add( pInput_t60[input_idx], Mpy_32_32( rel_offset, L_sub( pInput_t60[input_idx_next], pInput_t60[input_idx] ) ) );
        pOutput_dsr[output_idx] = L_add( pInput_dsr[input_idx], Mpy_32_32( rel_offset, L_sub( pInput_dsr[input_idx_next], pInput_dsr[input_idx] ) ) );
        //Word32 mult1;
        //Word16 mult_e = 0;
        //move16();
        //mult1 = Mpy_32_32( rel_offset, L_sub( pInput_t60[input_idx + 1], pInput_t60[input_idx] ) );
        //pOutput_t60[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_t60[input_idx], 5, mult1, add( 5, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 26 - 31)
        //move32();
        ////pOutput_t60_e[output_idx] = mult_e;
        //move16();

        //mult1 = Mpy_32_32( rel_offset, L_sub( pInput_dsr[input_idx + 1], pInput_dsr[input_idx] ) );
        //pOutput_dsr[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_dsr[input_idx], 1, mult1, add( 1, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 26 - 31) // If DSR is in Q30 -> Should this not be 31 - (31 - rel_offset_e + 30 - 31)??
        //move32();
        ////pOutput_dsr_e[output_idx] = mult_e;
        //move16();
    }

    return;
@@ -1000,24 +986,78 @@ void ivas_reverb_interpolate_energies_fx(

        pOutput_ene_l[output_idx] = L_add( pInput_ene_l[input_idx], Mpy_32_32( rel_offset, L_sub( pInput_ene_l[input_idx_next], pInput_ene_l[input_idx] ) ) );
        pOutput_ene_r[output_idx] = L_add( pInput_ene_r[input_idx], Mpy_32_32( rel_offset, L_sub( pInput_ene_r[input_idx_next], pInput_ene_r[input_idx] ) ) );
    }

        //Word32 mult1;
        //Word16 mult_e = 0;
    return;
}
#endif

/*-------------------------------------------------------------------*
 * ivas_reverb_interp_on_freq_grid_fx()
 *
 * Interpolates data from an input grid of center frequencies to an output grid of center frequencies
 * Note: the fc frequencies both for the input and the output must be in the ascending order
 *-------------------------------------------------------------------*/
void ivas_reverb_interp_on_freq_grid_fx(
    const Word16 input_grid_size,
    const Word32 *pInput_fc,   // input center frequencies in Q16
    const Word32 *pInput_data, // input data vector in an arbitrary Q-format
    const Word16 output_grid_size,
    const Word32 *pOutput_fc,
    Word32 *pOutput_data // output data vector in the same Q-format as input
)
{
    Word16 input_idx, input_idx_next, output_idx;
    Word32 rel_offset;
    Word16 rel_offset_e;
    input_idx = 0;
    input_idx_next = 0;
    move16();
    move16();

        //move16();
        //mult1 = Mpy_32_32( rel_offset, L_sub( pInput_ene_l[input_idx + 1], pInput_ene_l[input_idx] ) );
        //pOutput_ene_l_m[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_ene_l[input_idx], 3, mult1, add( 3, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 28 - 31)
        //move32();
        //pOutput_ene_l_e[output_idx] = mult_e;
        //move16();
    FOR( output_idx = 0; output_idx < output_grid_size; output_idx++ )
    {
        /* if the bin frequency is lower than the 1st frequency point in the input table, take this 1st point */
        IF( LT_32( pOutput_fc[output_idx], pInput_fc[0] ) )
        {
            input_idx = 0;
            move16();
            input_idx_next = 0;
            move16();
            rel_offset = 0;
            move32();
            rel_offset_e = 0;
            move16();
        }
        ELSE
        {
            /* if the bin frequency is higher than the last frequency point in the input table, take this last point */
            IF( GT_32( pOutput_fc[output_idx], pInput_fc[input_grid_size - 1] ) )
            {
                input_idx = sub( input_grid_size, 2 );
                input_idx_next = add( input_idx, 1 );
                rel_offset = ONE_IN_Q15;
                move32();
                rel_offset_e = 1;
                move16();
            }
            /* otherwise use linear interpolation between 2 consecutive points in the input table */
            ELSE
            {
                WHILE( GT_32( pOutput_fc[output_idx], pInput_fc[input_idx + 1] ) )
                {
                    input_idx = add( input_idx, 1 );
                }
                input_idx_next = add( input_idx, 1 );
                rel_offset = BASOP_Util_Divide3232_Scale( L_sub( pOutput_fc[output_idx], pInput_fc[input_idx] ), L_sub( pInput_fc[input_idx + 1], pInput_fc[input_idx] ), &rel_offset_e ); // Q15
                rel_offset = L_shl_sat( rel_offset, add( 16, rel_offset_e ) );
                rel_offset_e = 0;
                move16();
            }
        }

        //mult1 = Mpy_32_32( rel_offset, L_sub( pInput_ene_r[input_idx + 1], pInput_ene_r[input_idx] ) );
        //pOutput_ene_r_m[output_idx] = BASOP_Util_Add_Mant32Exp( pInput_ene_r[input_idx], 3, mult1, add( 3, rel_offset_e ), &mult_e ); // 31 - (31 - rel_offset_e + 28 - 31)
        //move32();
        //pOutput_ene_r_e[output_idx] = mult_e;
        //move16();
        pOutput_data[output_idx] = L_add( pInput_data[input_idx], Mpy_32_32( rel_offset, L_sub( pInput_data[input_idx_next], pInput_data[input_idx] ) ) );
    }

    return;
}
#endif
+24 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(

    Word32 delay_diff_fx, ln_1e6_inverted_fx, L_tmp;
    const Word32 dmx_gain_2_fx = 1852986624; // Q16
    const Word32 cldfb_band_width = 26214400; // 400 in Q16
    Word16 pow_exp, tmp_exp;
    Word32 tmp, exp_argument_fx;

@@ -105,6 +106,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(

        output_fc_fx[idx] = mult( add( ( mult(idx, ONE_IN_Q16) << 1 ), ONE_IN_Q16 ), halfstep );//Debug

        output_fc_fx[idx] = L_add( L_shr( cldfb_band_width, 1 ), L_shl(Mult_32_16( cldfb_band_width, idx ), 15 ) );
        int a = 1; // for debugging
    }

@@ -112,6 +114,27 @@ ivas_error ivas_reverb_prepare_cldfb_params(

    ivas_reverb_interpolate_acoustic_data_fx( pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_rt60_fx, pInput_params->pAcoustic_dsr_fx,
                                              CLDFB_NO_CHANNELS_MAX, output_fc_fx, output_t60_fx, output_ene_fx );

    //write to csv
    /*FILE *filewriter = fopen("output.csv", "w");
    if (filewriter == NULL)
    {
        perror("Failed to open file");
        return;
    }
    fprintf( filewriter, "T60(old function),DSR (old fucntion)\n" );

     FOR( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
         fprintf( filewriter, "%f,%f", (float) output_t60_fx / ( 1 << 26 ), (float) output_ene_fx / ( 1 << 30 ) );
    }*/
    
    //Testing generalised interpolate function - write values to csv for comparison
    //T60
    ivas_reverb_interp_on_freq_grid_fx( pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX, output_fc_fx, output_t60_fx );
    //DSR
    ivas_reverb_interp_on_freq_grid_fx( pInput_params->nBands, pInput_params->pFc_input_fx, pInput_params->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX, output_fc_fx, output_ene_fx );

    //output_t60_fx: Q26, output_ene_fx: Q30

    /* adjust DSR for the delay difference */