Commit 662c0133 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

First step for refactoring and fixing ivas_binaural_reverb_open.

parent e4023bf9
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1230,7 +1230,7 @@ ivas_error ivas_binRenderer_open(
    /* Allocate memories needed for reverb module */
    if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    {
        if ( ( error = ivas_binaural_reverb_open( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, RENDERER_BINAURAL_FASTCONV, st_ivas->hHrtfFastConv, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
        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 )
        {
            return error;
        }
+2 −1
Original line number Diff line number Diff line
@@ -234,7 +234,8 @@ ivas_error ivas_dirac_dec_init_binaural_data(
        if ( hDiracDecBin->hReverb == NULL )
#endif
            {
                if ( ( error = ivas_binaural_reverb_open( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM, st_ivas->hHrtfFastConv, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
                /* Todo Philips: Room acoustics should be passed here once the underlying part works. Probably enough to pick it from st_ivas but you know best. */
                if ( ( error = ivas_binaural_reverb_open_parambin( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, output_Fs, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
+17 −10
Original line number Diff line number Diff line
@@ -884,15 +884,22 @@ ivas_error ivas_rend_crendProcessSubframe(
 * Reverberator
 *----------------------------------------------------------------------------------*/

ivas_error ivas_binaural_reverb_open(
ivas_error ivas_binaural_reverb_open_fastconv(
    REVERB_STRUCT_HANDLE *hReverbPr,                /* i/o: binaural reverb handle               */
    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            */
    const AUDIO_CONFIG internal_config,             /* i  : internal audio config for FastConv   */
    const int32_t sampling_rate,                    /* i  : sampling rate                        */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv       /* i  : FastConv HRTF handle                 */
);

ivas_error ivas_binaural_reverb_open_parambin(
    REVERB_STRUCT_HANDLE *hReverbPr,                /* i/o: binaural reverb handle               */
    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            */
    const AUDIO_CONFIG output_config,                           /* i  : output audio configuration              */
    const int32_t sampling_rate,                    /* i  : sampling rate                        */
    const RENDERER_TYPE renderer_type,                          /* i  : renderer type                           */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv,                  /* i  : FastConv HRTF handle                    */
    const HRTFS_PARAMBIN_HANDLE hHrtfParambin       /* i  : Parametric binauralizer HRTF handle  */
);

+98 −45
Original line number Diff line number Diff line
@@ -1788,24 +1788,18 @@ void ivas_binaural_reverb_processSubframe(
 * Allocate and initialize binaural room reverberator handle
 *------------------------------------------------------------------------*/

ivas_error ivas_binaural_reverb_open(
static ivas_error ivas_binaural_reverb_open(
    REVERB_STRUCT_HANDLE *hReverbPr,       /* i/o: binaural reverb handle                                  */
    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            */
    const AUDIO_CONFIG output_config,               /* i  : output audio configuration           */
    const int32_t sampling_rate,           /* i  : sampling rate                                           */
    const RENDERER_TYPE renderer_type,              /* i  : renderer type                        */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv,      /* i  : FastConv HRTF handle                 */
    const HRTFS_PARAMBIN_HANDLE hHrtfParambin       /* i  : Parametric binauralizer HRTF handle  */
    const float *revTimes,                 /* i  : reverberation times T60 for each CLDFB bin in seconds   */
    const float *revEnes,                  /* i  : spectrum for reverberated sound at each CLDFB bin       */
    const int16_t preDelay                 /* i  : reverb pre-delay in CLDFB slots                         */
)
{
    int16_t bin, chIdx, k, len;
    REVERB_STRUCT_HANDLE hReverb;
    const float *revTimes;
    float t60[CLDFB_NO_CHANNELS_MAX];
    float ene[CLDFB_NO_CHANNELS_MAX];
    ivas_error error;

    if ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL )
    {
@@ -1827,22 +1821,6 @@ ivas_error ivas_binaural_reverb_open(
        set_f( hReverb->preDelayBufferImag[k], 0.0f, hReverb->numBins );
    }

    if ( renderer_type == RENDERER_BINAURAL_FASTCONV )
    {
        if ( !roomAcoustics->override )
        {
            revTimes = hHrtfFastConv->fastconvReverberationTimes;
        }
        else
        {
            revTimes = t60;
        }
    }
    else
    {
        revTimes = hHrtfParambin->parametricReverberationTimes;
    }

    for ( bin = 0; bin < hReverb->numBins; bin++ )
    {
        /* Loop Buffer */
@@ -1905,33 +1883,108 @@ ivas_error ivas_binaural_reverb_open(
        }
    }

    ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, revTimes, revEnes );
    ivas_binaural_reverb_setPreDelay( hReverb, preDelay );

    return IVAS_ERR_OK;
}


    if ( ( roomAcoustics ) && ( roomAcoustics->override ) )
/*-------------------------------------------------------------------------
 * ivas_binaural_reverb_open_fastconv()
 *
 * Allocate and initialize binaural room reverberator handle for FastConv
 *------------------------------------------------------------------------*/

ivas_error ivas_binaural_reverb_open_fastconv(
    REVERB_STRUCT_HANDLE *hReverbPr,                /* i/o: binaural reverb handle               */
    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            */
    const AUDIO_CONFIG internal_config,             /* i  : internal audio config for FastConv   */
    const int32_t sampling_rate,                    /* i  : sampling rate                        */
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv       /* i  : FastConv HRTF handle                 */
)
{
        if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, output_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK )
    ivas_error error;
    const float *revTimes;
    const float *revEne;
    float t60[CLDFB_NO_CHANNELS_MAX];
    float ene[CLDFB_NO_CHANNELS_MAX];
    int16_t preDelay;

    error = IVAS_ERR_OK;

    if ( (roomAcoustics != NULL) && roomAcoustics->override )
    {
        revTimes = t60;
        revEne = ene;
        if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK )
        {
            return error;
        }
        ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, t60, ene );
        ivas_binaural_reverb_setPreDelay( hReverb, (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ) );
        preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX );
    }
    else
    {
        if ( renderer_type == RENDERER_BINAURAL_FASTCONV )
        revTimes = hHrtfFastConv->fastconvReverberationTimes;
        revEne = hHrtfFastConv->fastconvReverberationEneCorrections;
        preDelay = 10;
    }

    error = ivas_binaural_reverb_open(hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay);

    return error;
}


/*-------------------------------------------------------------------------
 * ivas_binaural_reverb_open_parambin()
 *
 * Allocate and initialize binaural room reverberator handle for ParamBin
 *------------------------------------------------------------------------*/

ivas_error ivas_binaural_reverb_open_parambin(
    REVERB_STRUCT_HANDLE *hReverbPr,                /* i/o: binaural reverb handle               */
    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            */
    const int32_t sampling_rate,                    /* i  : sampling rate                        */
    const HRTFS_PARAMBIN_HANDLE hHrtfParambin       /* i  : Parametric binauralizer HRTF handle  */
)
{
            ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, hHrtfFastConv->fastconvReverberationTimes, hHrtfFastConv->fastconvReverberationEneCorrections );
            ivas_binaural_reverb_setPreDelay( hReverb, 10 );
    ivas_error error;
    const float *revTimes;
    const float *revEne;
    float t60[CLDFB_NO_CHANNELS_MAX];
    float ene[CLDFB_NO_CHANNELS_MAX];
    int16_t preDelay;

    error = IVAS_ERR_OK;

    if ( (roomAcoustics != NULL) && roomAcoustics->override )
    {
        revTimes = t60;
        revEne = ene;
        /* Todo Philips: This needs a suitable function for ParamBin here. */
//        if ( ( error = ivas_reverb_prepare_cldfb_params( roomAcoustics, hHrtfFastConv, internal_config, false, sampling_rate, t60, ene ) ) != IVAS_ERR_OK )
//        {
//            return error;
//        }
        preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX );
    }
    else
    {
            ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, hHrtfParambin->parametricReverberationTimes, hHrtfParambin->parametricReverberationEneCorrections );
            ivas_binaural_reverb_setPreDelay( hReverb, 10 );
        }
        revTimes = hHrtfParambin->parametricReverberationTimes;
        revEne = hHrtfParambin->parametricReverberationEneCorrections;
        preDelay = 10;
    }

    return IVAS_ERR_OK;
}
    error = ivas_binaural_reverb_open(hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay);

    return error;

}

/*-------------------------------------------------------------------------
 * ivas_binaural_reverb_close()