Commit 5bad2637 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

Cleanup and fixes:

- Complete TODOs for reverb parameters
- Minor refactoring, prevent double free() by passing down
  st_ivas->hHrtfFastConv
parent 9fd62bc0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -3263,6 +3263,10 @@ ivas_error ivas_binaural_reverb_open(
    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                           */
    #ifdef HRTF_BINARY_FASTCONV
    ,
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv                   /* i  : FastConv HRTF handle                    */
    #endif
);

void ivas_binaural_reverb_close(
@@ -5483,6 +5487,9 @@ void ivas_reverb_calc_color_levels(

void ivas_reverb_prepare_cldfb_params(
    ivas_roomAcoustics_t *pInput_params,
#ifdef HRTF_BINARY_FASTCONV
    const HRTFS_FASTCONV_HANDLE hHrtfFastConv,
#endif
    const AUDIO_CONFIG input_audio_config,
    const int16_t use_brir,
    const int32_t output_Fs,
+22 −0
Original line number Diff line number Diff line
@@ -191,14 +191,36 @@ ivas_error ivas_dirac_dec_init_binaural_data(

        if ( hBinaural->useSubframeMode )
        {
#ifdef HRTF_BINARY_FASTCONV
            if ( ( error = ivas_binaural_reverb_open( &hBinaural->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 ) ) != IVAS_ERR_OK )
#else
            if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
        }
        else
        {
#ifdef HRTF_BINARY_FASTCONV
            if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb,
                                                      nBins,
                                                      CLDFB_NO_COL_MAX,
                                                      NULL,
                                                      st_ivas->hIntSetup.output_config,
                                                      output_Fs,
                                                      RENDERER_BINAURAL_PARAMETRIC_ROOM,
                                                      st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#else
            if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, nBins, CLDFB_NO_COL_MAX, NULL, st_ivas->hIntSetup.output_config, output_Fs, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
+0 −1
Original line number Diff line number Diff line
@@ -2005,7 +2005,6 @@ static ivas_error doSanityChecks_IVAS(
#endif

#ifdef HRTF_BINARY_FILE
// TODO tmu check
#ifdef DEBUGGING
    if ( ( st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || output_config != AUDIO_CONFIG_BINAURAL || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) )
    {
+0 −6
Original line number Diff line number Diff line
@@ -1311,12 +1311,6 @@ typedef struct ivas_binaural_rendering_struct
    /* Variables related to reverb module */
    float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX];
    REVERB_STRUCT_HANDLE hReverb;

#ifdef HRTF_BINARY_FASTCONV
    /* HRTF tables */
    HRTFS_FASTCONV_HANDLE hHrtfFastConv;

#endif
} BINAURAL_RENDERER, *BINAURAL_RENDERER_HANDLE;


+55 −46
Original line number Diff line number Diff line
@@ -124,7 +124,12 @@ static ivas_error ivas_binRenderer_convModuleOpen(
    const int16_t renderer_type,
    const int16_t isLoudspeaker,
    const AUDIO_CONFIG input_config,
    const RENDER_CONFIG_DATA *hRenderConfig )
    const RENDER_CONFIG_DATA *hRenderConfig
#ifdef HRTF_BINARY_FASTCONV
    ,
    const HRTFS_FASTCONV_HANDLE hHrtf
#endif
)
{
    int16_t bandIdx, chIdx;
    BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule;
@@ -312,10 +317,10 @@ static ivas_error ivas_binRenderer_convModuleOpen(
                if ( isLoudspeaker )
                {
#ifdef HRTF_BINARY_FASTCONV
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftBRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftBRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightBRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightBRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftBRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftBRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightBRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightBRIRImag[bandIdx][tmp];
#else
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = leftBRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = leftBRIRImag[bandIdx][tmp];
@@ -340,10 +345,10 @@ static ivas_error ivas_binRenderer_convModuleOpen(
                if ( isLoudspeaker )
                {
#ifdef HRTF_BINARY_FASTCONV
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftHRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftHRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightHRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightHRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag[bandIdx][tmp];
#else
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = leftHRIRReal[bandIdx][tmp];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = leftHRIRImag[bandIdx][tmp];
@@ -355,10 +360,10 @@ static ivas_error ivas_binRenderer_convModuleOpen(
                {
                    /* HOA3 filter coefficients */
#ifdef HRTF_BINARY_FASTCONV
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftHRIRReal_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->leftHRIRImag_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightHRIRReal_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hBinRenderer->hHrtfFastConv->rightHRIRImag_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3[bandIdx][chIdx];
#else
                    hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = leftHRIRReal_HOA3[bandIdx][chIdx];
                    hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = leftHRIRImag_HOA3[bandIdx][chIdx];
@@ -383,19 +388,18 @@ static ivas_error ivas_binRenderer_convModuleOpen(
 *-------------------------------------------------------------------------*/

static ivas_error ivas_binaural_hrtf_open(
    BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle    */
    HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i  : fastconv HRTF handle */
)
{
    int16_t i, j;
    if ( hHrtfFastConv != NULL && *hHrtfFastConv != NULL )
    {
        /* Use tables loaded from file */
        hBinRenderer->hHrtfFastConv = *hHrtfFastConv;
        /* Tables already loaded from file */
        return IVAS_ERR_OK;
    }
    else
    {
        /* Use tables from ROM */
        /* Initialise tables from ROM */
        HRTFS_FASTCONV *HrtfFastConv;

        if ( ( HrtfFastConv = (HRTFS_FASTCONV *) count_malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL )
@@ -435,26 +439,10 @@ static ivas_error ivas_binaural_hrtf_open(
        mvr2r( fastconvReverberationEneCorrections, HrtfFastConv->fastconvReverberationEneCorrections, CLDFB_NO_CHANNELS_MAX );

        *hHrtfFastConv = HrtfFastConv;
        hBinRenderer->hHrtfFastConv = HrtfFastConv;
    }

    return IVAS_ERR_OK;
}

static void ivas_binaural_hrtf_close(
    HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: fastconv HRTF handle */
)
{
    if ( hHrtfFastConv == NULL )
    {
        return;
    }

    count_free( ( *hHrtfFastConv ) );
    ( *hHrtfFastConv ) = NULL;

    return;
}
#endif

/*-------------------------------------------------------------------------*
@@ -645,7 +633,7 @@ ivas_error ivas_binRenderer_open(

#ifdef HRTF_BINARY_FASTCONV
    /* Load HRTF tables */
    ivas_binaural_hrtf_open( hBinRenderer, &st_ivas->hHrtfFastConv );
    ivas_binaural_hrtf_open( &st_ivas->hHrtfFastConv );
#endif

    if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) )
@@ -653,7 +641,16 @@ ivas_error ivas_binRenderer_open(
        IVAS_OUTPUT_SETUP out_setup;

        /* Allocate memories and buffers needed for convolutional module in CICP19 */
#ifdef HRTF_BINARY_FASTCONV
        if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer,
                                                        st_ivas->renderer_type,
                                                        1,
                                                        AUDIO_CONFIG_7_1_4,
                                                        st_ivas->hRenderConfig,
                                                        st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, AUDIO_CONFIG_7_1_4, st_ivas->hRenderConfig ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -665,7 +662,7 @@ ivas_error ivas_binRenderer_open(
        }
        hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx;
#ifdef HRTF_BINARY_FASTCONV
        st_ivas->binaural_latency_ns = (int32_t) ( hBinRenderer->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f );
        st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f );
#else
        st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f );
#endif
@@ -673,7 +670,16 @@ ivas_error ivas_binRenderer_open(
    else
    {
        /* Allocate memories and buffers needed for convolutional module */
#ifdef HRTF_BINARY_FASTCONV
        if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer,
                                                        st_ivas->renderer_type,
                                                        st_ivas->hIntSetup.is_loudspeaker_setup,
                                                        st_ivas->hIntSetup.output_config,
                                                        st_ivas->hRenderConfig,
                                                        st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hRenderConfig ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -681,7 +687,7 @@ ivas_error ivas_binRenderer_open(
        if ( hBinRenderer->ivas_format == MC_FORMAT )
        {
#ifdef HRTF_BINARY_FASTCONV
            st_ivas->binaural_latency_ns = (int32_t) ( hBinRenderer->hHrtfFastConv->FASTCONV_HRIR_latency_s * 1000000000.f );
            st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s * 1000000000.f );
#else
            st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HRIR_latency_s * 1000000000.f );
#endif
@@ -689,7 +695,7 @@ ivas_error ivas_binRenderer_open(
        else
        {
#ifdef HRTF_BINARY_FASTCONV
            st_ivas->binaural_latency_ns = (int32_t) ( hBinRenderer->hHrtfFastConv->FASTCONV_HOA3_latency_s * 1000000000.f );
            st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s * 1000000000.f );
#else
            st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_HOA3_latency_s * 1000000000.f );
#endif
@@ -699,7 +705,18 @@ ivas_error ivas_binRenderer_open(
    /* Allocate memories needed for reverb module */
    if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
    {
#ifdef HRTF_BINARY_FASTCONV
        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_ROOM,
                                                  st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
#else
        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_ROOM ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -843,14 +860,6 @@ void ivas_binRenderer_close(
        return;
    }

#ifdef HRTF_BINARY_FASTCONV
    // TODO tmu check
    if ( ( *hBinRenderer )->hHrtfFastConv != NULL )
    {
        ivas_binaural_hrtf_close( &( *hBinRenderer )->hHrtfFastConv );
    }
#endif

    if ( ( *hBinRenderer )->hBinRenConvModule != NULL )
    {
        ivas_binRenderer_convModuleClose( hBinRenderer );
Loading