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

fixed function reverb_set_energies

parent 61b13180
Loading
Loading
Loading
Loading
+40 −11
Original line number Diff line number Diff line
@@ -308,19 +308,20 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies(
    const int16_t use_brir,
#endif
    const int32_t sampling_rate,
    Word32 *avg_pwr_left,
    Word32 *avg_pwr_right )
    float *avg_pwr_left,
    float *avg_pwr_right )
{
    int16_t freq_idx;
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    float avg_pwr_left_fft[FFT_SPECTRUM_SIZE];
    float avg_pwr_right_fft[FFT_SPECTRUM_SIZE];
#endif
    Word32 input_fc[FFT_SPECTRUM_SIZE];
    Word32 output_fc[CLDFB_NO_CHANNELS_MAX];
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    float input_fc[FFT_SPECTRUM_SIZE];

#ifndef NON_BE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    ivas_error error;
#endif

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    const int16_t avg_pwr_len = sampling_rate == 16000 ? LR_IAC_LENGTH_NR_FC_16KHZ : LR_IAC_LENGTH_NR_FC;

@@ -329,7 +330,6 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies(
        input_fc[freq_idx] = freq_idx * ( 0.5f * sampling_rate / (float) ( avg_pwr_len - 1 ) );
    }
#else

    for ( freq_idx = 0; freq_idx < FFT_SPECTRUM_SIZE; freq_idx++ )
    {
        input_fc[freq_idx] = freq_idx * ( 0.5f * sampling_rate / (float) ( FFT_SPECTRUM_SIZE - 1 ) );
@@ -337,14 +337,42 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies(
#endif

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    ivas_reverb_interpolate_acoustic_data_fx( avg_pwr_len, input_fc, avg_pwr_l, avg_pwr_r, CLDFB_NO_CHANNELS_MAX, output_fc, avg_pwr_left, avg_pwr_right );
#else

    Word32 *input_fc_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );
    Word32 *avg_pwr_left_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );
    Word32 *avg_pwr_right_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );

    Word32 *output_fc_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) );
    Word32 *avg_pwr_left_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) );
    Word16 *avg_pwr_left_e = (Word16 *) malloc( 257 * sizeof( Word16 * ) );
    Word32 *avg_pwr_right_fx = (Word32 *) malloc( 257 * sizeof( Word32 * ) );
    Word16 *avg_pwr_right_e = (Word16 *) malloc( 257 * sizeof( Word16 * ) );

    for ( int i = 0; i < 60; i++ )
    {
        input_fc_fx[i] = (Word32) input_fc[i] * ( 1 << 16 );
    }

    for ( int i = 0; i < 257; i++ )
    {
        output_fc_fx[i] = (Word32) input_fc[i] * ONE_IN_Q16;
    }

    ivas_reverb_interpolate_acoustic_data_fx( FFT_SPECTRUM_SIZE, input_fc_fx, avg_pwr_l, avg_pwr_r,
                                              CLDFB_NO_CHANNELS_MAX, output_fc_fx, avg_pwr_left_fx, avg_pwr_right_fx, avg_pwr_left_e, avg_pwr_right_e );

    free( input_fc_fx );
    free( output_fc_fx );
    free( avg_pwr_left_fx );
    free( avg_pwr_left_e );
    free( avg_pwr_right_fx );
    free( avg_pwr_right_e );

#else
    if ( ( error = ivas_reverb_get_cldfb_hrtf_set_properties( input_audio_config, hHrtfFastConv, use_brir, sampling_rate, avg_pwr_left_fft, avg_pwr_right_fft ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    Word32 *input_fc_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );
    Word32 *avg_pwr_left_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );
    Word32 *avg_pwr_right_fft_fx = (Word32 *) malloc( 60 * sizeof( Word32 * ) );
@@ -374,6 +402,7 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies(
        avg_pwr_left[i] = (float) fabs( me2f( avg_pwr_left_fx[i], avg_pwr_left_e[i] ) );
        avg_pwr_right[i] = (float) fabs( me2f( avg_pwr_right_fx[i], avg_pwr_right_e[i] ) );
    }

    free( input_fc_fx );
    free( avg_pwr_left_fft_fx );
    free( avg_pwr_right_fft_fx );