Commit c68d8aa6 authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

fixed bugs in acousticPreDelay,input_fc_fx and resolved floating point data...

fixed bugs in acousticPreDelay,input_fc_fx and resolved floating point data members in room acoustics config data + code cleanup
parent ce311bf4
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -317,11 +317,6 @@ typedef struct _IVAS_ROOM_ACOUSTICS_CONFIG
{
    Word16 override;
    Word16 nBands;                                                                                                                       /* Number of frequency bands for which reverb properties are provided, integer, range [2..256]        */
    float pFc_input[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                         /* Center frequencies for which following values are provided:                                        */
    float pAcoustic_rt60[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                    /*  - The room's T60 per center frequency                                                             */
    float pAcoustic_dsr[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                     /*  - The room's Diffuse to Source Ratio per center frequency                                         */
    float acousticPreDelay;                                                                                                              /* Time elapsed between input signal and late reverberation start, float, range [0.001..10]           */
    float inputPreDelay;                                                                                                                 /* Offset in seconds from where DSR is computed in the RIR (0 = at source), float, range [0.001..10]  */
    Word32 pFc_input_fx[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                     /*Q16 Center frequencies for which following values are provided:                                         */
    Word32 pAcoustic_rt60_fx[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                /*Q26  - The room's T60 per center frequency                                                             */
    Word32 pAcoustic_dsr_fx[IVAS_CLDFB_NO_CHANNELS_MAX];                                                                                 /*Q30  - The room's Diffuse to Source Ratio per center frequency                                         */
+12 −31
Original line number Diff line number Diff line
@@ -40,9 +40,6 @@
#include <assert.h>
#include "wmc_auto.h"
#include "debug.h"
#define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) )
#define float_to_fixQ31( n )      ( round( n * 0x7fffffff ) )
#define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) )

static Word16 wrap_rad_fixed(
    Word32 angle /* Q13 */ )
@@ -123,24 +120,12 @@ typedef struct ivas_reverb_params_t
    /*       Currently this is fixed to 2.                                                  */                                                                            /* Mix [S][L] matrix from feedback loops to outputs.                                    */
    Word16 pLoop_extract_matrix_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES]; /* Mix [S][L] matrix from feedback loops to outputs.                                    */ /* In Matlab: [S x L] - Currently S=2, later may be more than 2 for speaker playback.   */
    Word16 t60_filter_order;                                                                                                                                              /* Filter order (length of vector)                                                      */
    // float pT60_filter_coeff[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH];                                                                  /* Filters [][] in feedback loops, controlling T60.                                    */
    Word16 pT60_filter_coeff_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH];
    /* In Matlab: IIR: [(2 * L) x (<order> + 1)] (odd: b-vector, even: a-vector)            */
    /* In Matlab: FIR: [L       x <order>]                                                  */
    // float *pFc;                                                                                                                                                           /* Center frequencies for FFT filter design                                             */
    // float *pRt60;                                                                                                                                                         /* RT60 values at these frequencies                                                     */
    // float *pDsr;                                                                                                                                                          /* DSR values at these frequencies                                                      */
    Word16 pT60_filter_coeff_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH];                                                              /* Filters [][] in feedback loops, controlling T60.                                    */
    Word32 *pFc_fx;                                                                                                                                                       /* Center frequencies for FFT filter design                                             */
    Word32 *pRt60_fx;                                                                                                                                                     /* RT60 values at these frequencies                                                     */
    Word16 *pRt60_e;                                                                                                                                                      /* exponents for RT60 values at these frequencies                                                     */
    Word32 *pDsr_fx;                                                                                                                                                      /* DSR values at these frequencies                                                      */
    Word16 *pDsr_e;                                                                                                                                                       /* DSR values at these frequencies                                                      */
    // float *pHrtf_avg_pwr_response_l;                                                                                                                                      /* The HRTF set's average left  ear power response                                      */
    // float *pHrtf_avg_pwr_response_r;                                                                                                                                      /* The HRTF set's average right ear power response                                      */
    // float *pHrtf_inter_aural_coherence;                                                                                                                                   /* The HRTF set's inter-aural coherence for diffuse sound                               */
    // const float *pHrtf_avg_pwr_response_l_const;                                                                                                                          /* The HRTF set's average left  ear power response                                      */
    // const float *pHrtf_avg_pwr_response_r_const;                                                                                                                          /* The HRTF set's average right ear power response                                      */
    // const float *pHrtf_inter_aural_coherence_const;                                                                                                                       /* The HRTF set's inter-aural coherence for diffuse sound                               */

    Word32 *pHrtf_avg_pwr_response_l_fx;                /* The HRTF set's average left  ear power response                                      */
    Word32 *pHrtf_avg_pwr_response_r_fx;                /* The HRTF set's average right ear power response                                      */
@@ -2434,12 +2419,13 @@ ivas_error ivas_binaural_reverb_init(
    Word32 t60[CLDFB_NO_CHANNELS_MAX];
    Word32 ene[CLDFB_NO_CHANNELS_MAX];
    Word16 preDelay;
    Word16 temp16, s;
    Word32 temp32;

    error = IVAS_ERR_OK;

    if ( ( roomAcoustics != NULL ) && roomAcoustics->override )
    {

        revTimes = t60;
        revEne = ene;

@@ -2448,15 +2434,10 @@ ivas_error ivas_binaural_reverb_init(
            return error;
        }

        //Port this??
        preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX );
/*
#ifdef FIX_1741_REVERB_TIMES_Q_FORMAT
        floatToFixed_arrL( t60_temp, t60, Q26, CLDFB_NO_CHANNELS_MAX );
#else
        floatToFixed_arrL( t60_temp, t60, Q31, CLDFB_NO_CHANNELS_MAX );
#endif
        floatToFixed_arrL( ene_temp, ene, Q31, CLDFB_NO_CHANNELS_MAX );*/
        temp16 = BASOP_Util_Divide3216_Scale( sampling_rate, CLDFB_NO_CHANNELS_MAX, &s );
        temp16 = shl( temp16, s );                                         // Q0
        temp32 = Mult_32_16( roomAcoustics->acousticPreDelay_fx, temp16 ); // Q11
        preDelay = shr( add( temp32, shl( 1, 10 ) ), 11 );                 // Q0
    }
    else
    {
+29 −35
Original line number Diff line number Diff line
@@ -54,15 +54,15 @@
 * Local function prototypes
 *-----------------------------------------------------------------------------------------*/

typedef struct cldfb_convolver_state
{
    const float *filter_taps_left_re[CLDFB_NO_CHANNELS_MAX];
    const float *filter_taps_left_im[CLDFB_NO_CHANNELS_MAX];
    const float *filter_taps_right_re[CLDFB_NO_CHANNELS_MAX];
    const float *filter_taps_right_im[CLDFB_NO_CHANNELS_MAX];
    float filter_states_re[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
    float filter_states_im[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
} cldfb_convolver_state;
//typedef struct cldfb_convolver_state
//{
//    const float *filter_taps_left_re[CLDFB_NO_CHANNELS_MAX];
//    const float *filter_taps_left_im[CLDFB_NO_CHANNELS_MAX];
//    const float *filter_taps_right_re[CLDFB_NO_CHANNELS_MAX];
//    const float *filter_taps_right_im[CLDFB_NO_CHANNELS_MAX];
//    float filter_states_re[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
//    float filter_states_im[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
//} cldfb_convolver_state;

static void ivas_reverb_set_energies( const Word32 *avg_pwr_l, const Word32 *avg_pwr_r, const Word32 sampling_rate, Word32 *avg_pwr_l_out, Word32 *avg_pwr_r_out );

@@ -109,7 +109,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(

    ln_1e6_inverted_fx = 155440049; // Q31 /* 1.0f / logf( 1e06f ) */

    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    FOR( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        L_tmp = Mpy_32_32( output_t60_fx[idx], ln_1e6_inverted_fx ); // L_tmp in Q26

@@ -142,11 +142,11 @@ ivas_error ivas_reverb_prepare_cldfb_params(

    ivas_reverb_set_energies( hHrtfStatistics->average_energy_l, hHrtfStatistics->average_energy_r, output_Fs, avg_pwr_left_fx, avg_pwr_right_fx ); //This function returns avg powers for left and right in Q28 -> why?? how??

    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    FOR( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        Word32 tmp_ene;

        tmp_ene = ( L_add( avg_pwr_left_fx[idx], avg_pwr_right_fx[idx] ) ) >> 1; //Q28
        tmp_ene = L_shr( L_add( avg_pwr_left_fx[idx], avg_pwr_right_fx[idx] ), 1 ); //Q28
        tmp_ene = Mpy_32_32( tmp_ene, dmx_gain_2_fx );                              //Q13
        pOutput_ene[idx] = Mpy_32_32( pOutput_ene[idx], tmp_ene );                  //Q13
        //Scale final output to Q31 for compatibility with further computations
@@ -181,22 +181,16 @@ static void ivas_reverb_set_energies(
    Word16 s;
    Word16 temp;
#endif

    float input_fc[FFT_SPECTRUM_SIZE];

    const Word16 avg_pwr_len = sampling_rate == 16000 ? LR_IAC_LENGTH_NR_FC_16KHZ : LR_IAC_LENGTH_NR_FC;
    temp = BASOP_Util_Divide3216_Scale( sampling_rate, sub( avg_pwr_len, 1 ), &s );

    FOR( freq_idx = 0; freq_idx < CLDFB_NO_CHANNELS_MAX; freq_idx++ )
    FOR( freq_idx = 0; freq_idx < avg_pwr_len; freq_idx++ )
    {
        input_fc_fx[freq_idx] = L_shl( L_mult( temp, freq_idx ), add( 15, s ) );

       /* input_fc[freq_idx] = freq_idx * ( 0.5f * sampling_rate / (float) ( avg_pwr_len - 1 ) );
        input_fc_fx[freq_idx] = input_fc[freq_idx] * ONE_IN_Q16;*/
    }

#ifdef FIX_1741_REVERB_TIMES_Q_FORMAT
    for ( freq_idx = 0; freq_idx < CLDFB_NO_CHANNELS_MAX; freq_idx++ )
    FOR( freq_idx = 0; freq_idx < CLDFB_NO_CHANNELS_MAX; freq_idx++ )
    {
        output_fc_fx[freq_idx] = L_add( L_shr( cldfb_band_width, 1 ), L_shl( Mult_32_16( cldfb_band_width, freq_idx ), 15 ) );
    }
@@ -237,7 +231,7 @@ static void ivas_reverb_set_energies(
                                              CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx, avg_pwr_left_e, avg_pwr_right_e );
#endif

    for ( int i = 0; i < 60; i++ )
    FOR( int i = 0; i < 60; i++ )
    {
        avg_pwr_left[i] = avg_pwr_left_fx[i];
        avg_pwr_right[i] = avg_pwr_right_fx[i];
+20 −33
Original line number Diff line number Diff line
@@ -1140,46 +1140,21 @@ ivas_error RenderConfigReader_checkValues(
        return IVAS_ERR_WRONG_PARAMS;
    }

    /* Verify input pre-delay value */
    if ( ( pRoom_acoustics->inputPreDelay > INPUTPREDELAY_MAX ) || ( pRoom_acoustics->inputPreDelay < INPUTPREDELAY_MIN ) )
    {
        return IVAS_ERR_WRONG_PARAMS;
    }

    /* Verify data per band in the acoustic properties table */
    for ( band_idx = 0; band_idx < pRoom_acoustics->nBands; band_idx++ )
    {
        /* Verify if the frequencies are in the ascending order (required for interpolation) */
        if ( band_idx != 0 )
        {
            if ( pRoom_acoustics->pFc_input[band_idx] <= pRoom_acoustics->pFc_input[band_idx - 1] )
            {
                tab_value_err_count++;
            }
        }

        /* Check the input frequencies */
        if ( ( pRoom_acoustics->pFc_input[band_idx] > FC_INPUT_MAX ) || ( pRoom_acoustics->pFc_input[band_idx] < FC_INPUT_MIN ) )
            if ( pRoom_acoustics->pFc_input_fx[band_idx] <= pRoom_acoustics->pFc_input_fx[band_idx - 1] )
            {
                tab_value_err_count++;
            }

        /* Check the input RT60 values */
        if ( ( pRoom_acoustics->pAcoustic_rt60[band_idx] > ACOUSTIC_RT60_MAX ) || ( pRoom_acoustics->pAcoustic_rt60[band_idx] < ACOUSTIC_RT60_MIN ) )
        {
            tab_value_err_count++;
        }

        /* Check the input DSR values */
        if ( ( pRoom_acoustics->pAcoustic_dsr[band_idx] > ACOUSTIC_DSR_MAX ) || ( pRoom_acoustics->pAcoustic_dsr[band_idx] < ACOUSTIC_DSR_MIN ) )
        {
            tab_value_err_count++;
        }

        /* Replace zero DSR values with very small positive values, to avoid issues with coloration filter design */
        if ( pRoom_acoustics->pAcoustic_dsr[band_idx] <= 0.0f )
        if ( pRoom_acoustics->pAcoustic_dsr_fx[band_idx] == 0 )
        {
            pRoom_acoustics->pAcoustic_dsr[band_idx] = ACOUSTIC_DSR_EPSILON;
            pRoom_acoustics->pAcoustic_dsr_fx[band_idx] = ACOUSTIC_DSR_EPSILON_FX;
        }
    }
@@ -2230,11 +2205,12 @@ ivas_error RenderConfigReader_read(
                    /* Acoustic pre-delay */
                    else if ( strcmp( item, "ACOUSTICPREDELAY" ) == 0 )
                    {
                        if ( !sscanf( pValue, "%f", &hRenderConfig->roomAcoustics.acousticPreDelay ) )
                        float f;
                        if ( !sscanf( pValue, "%f", &f ) )
                        {
                            errorHandler( item, ERROR_VALUE_INVALID );
                        }
                        hRenderConfig->roomAcoustics.acousticPreDelay_fx = (Word32) ( hRenderConfig->roomAcoustics.acousticPreDelay * ONE_IN_Q27 );
                        hRenderConfig->roomAcoustics.acousticPreDelay_fx = (Word32) ( f * ONE_IN_Q27 );
                    }
                    /* Pre-delay */
                    else if ( strcmp( item, "PREDELAY" ) == 0 )
@@ -2657,13 +2633,24 @@ ivas_error RenderConfigReader_getAcousticEnvironment(
        if ( id == pRenderConfigReader->pAE[n].id )
        {
            pAcEnv->nBands = (int16_t) pRenderConfigReader->pAE[n].pFG->nrBands;
            pAcEnv->inputPreDelay = pRenderConfigReader->pAE[n].preDelay;
            pAcEnv->inputPreDelay_fx = (Word32) ( pRenderConfigReader->pAE[n].preDelay * ONE_IN_Q27 );
            if (pRenderConfigReader->pAE[n].preDelay > INPUTPREDELAY_MAX ||
                pRenderConfigReader->pAE[n].preDelay < INPUTPREDELAY_MIN)
            {
                return IVAS_ERR_INVALID_RENDER_CONFIG;
            }
            for ( m = 0; m < pAcEnv->nBands; m++ )
            {
                pAcEnv->pFc_input[m] = pRenderConfigReader->pAE[n].pFG->pFc[m];
                pAcEnv->pAcoustic_rt60[m] = pRenderConfigReader->pAE[n].pRT60[m];
                pAcEnv->pAcoustic_dsr[m] = pRenderConfigReader->pAE[n].pDSR[m];
                if ( pRenderConfigReader->pAE[n].pFG->pFc[m] > FC_INPUT_MAX ||
                     pRenderConfigReader->pAE[n].pFG->pFc[m] < FC_INPUT_MIN ||
                     pRenderConfigReader->pAE[n].pRT60[m] > ACOUSTIC_RT60_MAX ||
                     pRenderConfigReader->pAE[n].pRT60[m] < ACOUSTIC_RT60_MIN ||
                     pRenderConfigReader->pAE[n].pDSR[m] > ACOUSTIC_DSR_MAX ||
                     pRenderConfigReader->pAE[n].pDSR[m] < ACOUSTIC_DSR_MIN )
                {
                    return IVAS_ERR_INVALID_RENDER_CONFIG;
                }

                pAcEnv->pFc_input_fx[m] = (Word32) ( pRenderConfigReader->pAE[n].pFG->pFc[m] * ONE_IN_Q16 );
                pAcEnv->pAcoustic_rt60_fx[m] = (Word32) ( pRenderConfigReader->pAE[n].pRT60[m] * ONE_IN_Q26 );
                pAcEnv->pAcoustic_dsr_fx[m] = (Word32) ( pRenderConfigReader->pAE[n].pDSR[m] * ONE_IN_Q30 );