Commit d91367bd authored by sbsarac's avatar sbsarac
Browse files

Use precomputed energy tables in FastConv

parent 35e4df9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1232,7 +1232,7 @@ ivas_error ivas_binRenderer_open(
    if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    {
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
        if ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
        if ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ivas_binaural_reverb_open_fastconv( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#endif
+11 −0
Original line number Diff line number Diff line
@@ -1003,7 +1003,9 @@ ivas_error ivas_binaural_reverb_open_fastconv(
    const int16_t numBins,                                      /* i  : number of CLDFB bins                    */
    const int16_t numCldfbSlotsPerFrame,                        /* i  : number of CLDFB slots per frame         */
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics,             /* i/o: room acoustics parameters               */
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    const AUDIO_CONFIG internal_config,                         /* i  : internal audio config for FastConv      */
#endif
    const int32_t sampling_rate,                                /* i  : sampling rate                           */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv                   /* i  : FastConv HRTF handle                    */
);
@@ -1200,6 +1202,14 @@ void ivas_reverb_calc_color_levels(
    float *pTarget_color_R
);

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
ivas_error ivas_reverb_prepare_cldfb_params(
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pInput_params,
    const HRTFS_STATISTICS_HANDLE hHrtfStatistics,
    const int32_t output_Fs,
    float *pOutput_t60,
    float *pOutput_ene );
#else
ivas_error ivas_reverb_prepare_cldfb_params(
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pInput_params,
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv,
@@ -1208,6 +1218,7 @@ ivas_error ivas_reverb_prepare_cldfb_params(
    const int32_t output_Fs,
    float *pOutput_t60,
    float *pOutput_ene );
#endif

void ivas_reverb_interpolate_acoustic_data(
    const int16_t input_table_size,
+15 −21
Original line number Diff line number Diff line
@@ -1803,10 +1803,6 @@ void ivas_binaural_reverb_processSubframe(

static ivas_error ivas_binaural_reverb_open(
    REVERB_STRUCT_HANDLE *hReverbPr,     /* i/o: binaural reverb handle                                  */
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    const HRTFS_STATISTICS_HANDLE hHrtfStatistics, /* i  : HRTF statistics handle                                  */
#else
#endif
    const int16_t numBins,               /* i  : number of CLDFB bins                                    */
    const int16_t numCldfbSlotsPerFrame, /* i  : number of CLDFB slots per frame                         */
    const int32_t sampling_rate,         /* i  : sampling rate                                           */
@@ -1923,7 +1919,9 @@ ivas_error ivas_binaural_reverb_open_fastconv(
    const int16_t numBins,                          /* i  : number of CLDFB bins                 */
    const int16_t numCldfbSlotsPerFrame,            /* i  : number of CLDFB slots per frame      */
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters            */
#ifndef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    const AUDIO_CONFIG internal_config, /* i  : internal audio config for FastConv   */
#endif
    const int32_t sampling_rate,              /* i  : sampling rate                        */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv /* i  : FastConv HRTF handle                 */
)
@@ -1941,7 +1939,11 @@ ivas_error ivas_binaural_reverb_open_fastconv(
    {
        revTimes = t60;
        revEne = ene;
#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
        if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfStatistics, sampling_rate, t60, ene ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -1954,11 +1956,7 @@ ivas_error ivas_binaural_reverb_open_fastconv(
        preDelay = 10;
    }

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    error = ivas_binaural_reverb_open( hReverbPr, hHrtfStatistics, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay );
#else
    error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay );
#endif

    return error;
}
@@ -2010,11 +2008,7 @@ ivas_error ivas_binaural_reverb_open_parambin(
        preDelay = 10;
    }

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
    error = ivas_binaural_reverb_open( hReverbPr, hHrtfStatistics, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay );
#else
    error = ivas_binaural_reverb_open( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay );
#endif

    return error;
}
+83 −0
Original line number Diff line number Diff line
@@ -67,9 +67,63 @@ typedef struct cldfb_convolver_state
    float filter_states_im[BINAURAL_CONVBANDS][CLDFB_CONVOLVER_NTAPS_MAX];
} cldfb_convolver_state;

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
static void ivas_reverb_set_energies( const float *avg_pwr_l, const float *avg_pwr_r, const int32_t sampling_rate, float *avg_pwr_l_out, float *avg_pwr_r_out );
#else
static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies( const HRTFS_FASTCONV_HANDLE hHrtfFastConv, const AUDIO_CONFIG input_audio_config, const int16_t use_brir, const int32_t sampling_rate, float *avg_pwr_left, float *avg_pwr_right );
#endif

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
/*-----------------------------------------------------------------------------------------*
 * Function ivas_reverb_prepare_cldfb_params()
 *
 * Prepares reverb parameters for CLDFB-based reverberator
 *-----------------------------------------------------------------------------------------*/

ivas_error ivas_reverb_prepare_cldfb_params(
    IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pInput_params,
    const HRTFS_STATISTICS_HANDLE hHrtfStatistics,
    const int32_t output_Fs,
    float *pOutput_t60,
    float *pOutput_ene )
{
    int16_t idx;
    float fc[CLDFB_NO_CHANNELS_MAX];
    float avg_pwr_left[CLDFB_NO_CHANNELS_MAX];
    float avg_pwr_right[CLDFB_NO_CHANNELS_MAX];
    float delay_diff, ln_1e6_inverted, exp_argument;
    const float dist = DEFAULT_SRC_DIST;
    const float dmx_gain_2 = 4.0f * EVS_PI * dist * dist / 0.001f;

    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        fc[idx] = ( (float) idx + 0.5f ) * ( (float) MAX_SAMPLING_RATE / (float) ( 2 * CLDFB_NO_CHANNELS_MAX ) );
    }

    ivas_reverb_interpolate_acoustic_data( pInput_params->nBands, pInput_params->pFc_input, pInput_params->pAcoustic_rt60, pInput_params->pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX, fc, pOutput_t60, pOutput_ene );

    /* adjust DSR for the delay difference */
    delay_diff = pInput_params->inputPreDelay - pInput_params->acousticPreDelay;
    ln_1e6_inverted = 1.0f / logf( 1e06f );
    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        exp_argument = delay_diff / ( pOutput_t60[idx] * ln_1e6_inverted );
        /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */
        exp_argument = min( exp_argument, 23.0f );
        exp_argument = max( exp_argument, -23.0f );
        pOutput_ene[idx] *= expf( exp_argument );
    }

    ivas_reverb_set_energies( hHrtfStatistics->average_energy_l, hHrtfStatistics->average_energy_r, output_Fs, avg_pwr_left, avg_pwr_right );

    for ( idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ )
    {
        pOutput_ene[idx] *= 0.5f * ( avg_pwr_left[idx] + avg_pwr_right[idx] ) * dmx_gain_2;
    }

    return IVAS_ERR_OK;
}
#else
/*-----------------------------------------------------------------------------------------*
 * Function ivas_reverb_prepare_cldfb_params()
 *
@@ -470,8 +524,36 @@ static ivas_error ivas_reverb_get_cldfb_hrtf_set_properties(

    return IVAS_ERR_OK;
}
#endif

#ifdef NONBE_FIX_922_PRECOMPUTED_HRTF_PROPERTIES
/*-----------------------------------------------------------------------------------------*
 * Function ivas_reverb_set_energies()
 *
 * Function gets the precalculated left/right energies and computes average
 * left/right energies to CLDFB bin center frequencies.
 *-----------------------------------------------------------------------------------------*/

static void ivas_reverb_set_energies( const float *avg_pwr_l, const float *avg_pwr_r, const int32_t sampling_rate, float *avg_pwr_l_out, float *avg_pwr_r_out )
{
    int16_t freq_idx;
    const int16_t cldfb_freq_halfstep = MAX_SAMPLING_RATE / ( 4 * CLDFB_NO_CHANNELS_MAX );
    float input_fc[FFT_SPECTRUM_SIZE];
    float output_fc[CLDFB_NO_CHANNELS_MAX];

    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 ) );
    }

    for ( freq_idx = 0; freq_idx < CLDFB_NO_CHANNELS_MAX; freq_idx++ )
    {
        output_fc[freq_idx] = (float) ( ( 2 * freq_idx + 1 ) * cldfb_freq_halfstep );
    }

    ivas_reverb_interpolate_acoustic_data( FFT_SPECTRUM_SIZE, input_fc, avg_pwr_l, avg_pwr_r, CLDFB_NO_CHANNELS_MAX, output_fc, avg_pwr_l_out, avg_pwr_r_out );
}
#else
/*-----------------------------------------------------------------------------------------*
 * Function ivas_reverb_get_fastconv_hrtf_set_energies()
 *
@@ -515,3 +597,4 @@ static ivas_error ivas_reverb_get_fastconv_hrtf_set_energies(

    return IVAS_ERR_OK;
}
#endif
 No newline at end of file