Commit d69b86f6 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

[fix] allocate only the necessary renderer when headrotation is switched in external renderer

parent 1c663132
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -167,6 +167,7 @@

#define FIX_718_JBM_MD_UDPATE                           /* Fhg: fix issue #718, wrong setting of the update flag in the TD obj renderer in the JBM path */
#define FIX_719_CRASH_IN_CLEANUP                        /* VA: issue 719: fix Decoder crash after call to goto to cleanup */
#define FIX_513_REND_MC_ALLOC                           /* FhG: issue 513, optimise external renderer allocation for multichannel */


/* ################## End BE DEVELOPMENT switches ######################### */
+106 −36
Original line number Diff line number Diff line
@@ -2182,9 +2182,32 @@ static ivas_error initMcBinauralRendering(
#endif
    int32_t binauralDelayNs;
    int32_t outSampleRate;
#ifdef FIX_513_REND_MC_ALLOC
    int8_t useTDRend;

    /* check if re-initialization */
    if ( inputMc->tdRendWrapper.hBinRendererTd != NULL )
    /* Allocate TD binaural renderer for custom loudspeaker layouts (regardless of headrotation)
      or planar MC layouts with headrotation, CREND for the rest */
    useTDRend = FALSE;
    if ( outConfig != AUDIO_CONFIG_BINAURAL_ROOM_IR )
    {
        if ( inConfig == AUDIO_CONFIG_LS_CUSTOM )
        {
            useTDRend = TRUE;
        }
        else if ( ( inConfig == AUDIO_CONFIG_5_1 || inConfig == AUDIO_CONFIG_7_1 ) &&
                  ( inputMc->base.ctx.pHeadRotData->headRotEnabled ) )
        {
            useTDRend = TRUE;
        }
    }
#endif

    /* if TD renderer was open and we need to use CREND, close it */
    if (
#ifdef FIX_513_REND_MC_ALLOC
        !useTDRend &&
#endif
        inputMc->tdRendWrapper.hBinRendererTd != NULL )
    {
        ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd );
        inputMc->tdRendWrapper.hHrtfTD = NULL;
@@ -2201,45 +2224,47 @@ static ivas_error initMcBinauralRendering(
    }
#endif

#ifdef FIX_513_REND_MC_ALLOC
    /* if we need to use TD renderer and CREND was open, close it */
    if ( useTDRend )
    {
#endif
        ivas_rend_closeCrend( &inputMc->crendWrapper
#ifdef SPLIT_REND_WITH_HEAD_ROT
                              ,
                              inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses
#endif
        );
#ifdef FIX_513_REND_MC_ALLOC
    }
#endif

#ifdef FIX_513_REND_MC_ALLOC
    if ( !useTDRend && outConfig != AUDIO_CONFIG_BINAURAL_ROOM_REVERB && inputMc->hReverb != NULL )
    {
#endif
        ivas_reverb_close( &inputMc->hReverb );
#ifdef FIX_513_REND_MC_ALLOC
    }
#endif

#ifdef FIX_513_REND_MC_ALLOC
    if ( inConfig == AUDIO_CONFIG_LS_CUSTOM && !inputMc->base.ctx.pHeadRotData->headRotEnabled )
    {
#endif
        if ( inputMc->efapInWrapper.hEfap != NULL )
        {
            efap_free_data( &inputMc->efapInWrapper.hEfap );
        }
#ifdef FIX_513_REND_MC_ALLOC
    }
#endif

    outSampleRate = *inputMc->base.ctx.pOutSampleRate;

    /* Needs optimization, see issue 513 */
    // bool initTDRend;
    // initTDRend = false;
    // #ifdef FIX_196_REFACTOR_RENDERER_OUTPUT_CONFIG
    // if ( ( outConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM ) &&
    //      ( outConfig != AUDIO_CONFIG_BINAURAL_ROOM_IR ) && ( outConfig != AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    // #else
    // if ( outConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM )
    // #endif
    // {
    //     if ( inConfig == AUDIO_CONFIG_LS_CUSTOM )
    //     {
    //         initTDRend = true;
    //     }
    //     else if ( ( inConfig == AUDIO_CONFIG_5_1 || inConfig == AUDIO_CONFIG_7_1 ) &&
    //               ( inputMc->base.ctx.pHeadRotData->headRotEnabled ) )
    //     {
    //         initTDRend = true;
    //     }
    // }

    // if ( initTDRend )
    /* Allocate TD binaural renderer for planar MC layouts or custom MC layouts with headrotation, CREND for the rest */
#ifdef FIX_513_REND_MC_ALLOC
    if ( useTDRend && inputMc->tdRendWrapper.hBinRendererTd == NULL )
#endif
    {
        if ( ( error = ivas_td_binaural_open_ext( &inputMc->tdRendWrapper, inConfig, hRendCfg, &inputMc->customLsInput, outSampleRate ) ) != IVAS_ERR_OK )
        {
@@ -2263,7 +2288,11 @@ static ivas_error initMcBinauralRendering(
        }

#endif
        if ( outConfig == AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
        if ( outConfig == AUDIO_CONFIG_BINAURAL_ROOM_REVERB
#ifdef FIX_513_REND_MC_ALLOC
             && inputMc->hReverb == NULL
#endif
        )
        {
            if ( ( error = ivas_reverb_open( &( inputMc->hReverb ), outConfig, NULL, inputMc->tdRendWrapper.hBinRendererTd->HrFiltSet_p->lr_energy_and_iac, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK )
            {
@@ -2271,7 +2300,9 @@ static ivas_error initMcBinauralRendering(
            }
        }
    }

#ifdef FIX_513_REND_MC_ALLOC
    else if ( !useTDRend && inputMc->crendWrapper->hCrend == NULL ) /* open CREND */
#endif
    {
        if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( inConfig == AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : inConfig, outConfig, hRendCfg, NULL, outSampleRate
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -2285,7 +2316,11 @@ static ivas_error initMcBinauralRendering(
    }

    /* Initialise the EFAP handle for rotation on input layout */
    if ( inConfig != AUDIO_CONFIG_LS_CUSTOM && inputMc->base.ctx.pHeadRotData->headRotEnabled )
    if ( inConfig != AUDIO_CONFIG_LS_CUSTOM && inputMc->base.ctx.pHeadRotData->headRotEnabled
#ifdef FIX_513_REND_MC_ALLOC
         && inputMc->efapInWrapper.hEfap == NULL
#endif
    )
    {
        if ( ( error = initEfap( &inputMc->efapInWrapper, inConfig, NULL ) ) != IVAS_ERR_OK )
        {
@@ -2455,6 +2490,9 @@ static ivas_error setRendInputActiveMc(
#endif
    inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut );
    set_zero( inputMc->lfeDelayBuffer, MAX_BIN_DELAY_SAMPLES );
#ifdef FIX_513_REND_MC_ALLOC
    inputMc->binauralDelaySmp = 0;
#endif

#ifdef SPLIT_REND_WITH_HEAD_ROT
    for ( i = 0; i < (int16_t) ( sizeof( inputMc->splitTdRendWrappers ) / sizeof( *inputMc->splitTdRendWrappers ) ); ++i )
@@ -5277,7 +5315,7 @@ ivas_error IVAS_REND_SetHeadRotation(
#endif
)
{
#ifndef API_5MS
#if !defined( API_5MS ) || defined( FIX_513_REND_MC_ALLOC )
    int16_t i;
#endif
    IVAS_QUATERNION rotQuat;
@@ -5294,6 +5332,20 @@ ivas_error IVAS_REND_SetHeadRotation(
        return IVAS_ERR_INVALID_OUTPUT_FORMAT;
    }

#ifdef FIX_513_REND_MC_ALLOC
    hIvasRend->headRotData.headRotEnabled = 1;

    /* reconfigure binaural rendering to allocate
       the necessary renderers and free unused ones */
    for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
    {
        initMcBinauralRendering( &hIvasRend->inputsMc[i],
                                 hIvasRend->inputsMc[i].base.inConfig,
                                 hIvasRend->outputConfig,
                                 hIvasRend->hRendererConfig );
    }
#endif

#ifdef API_5MS
    /* check for Euler angle signaling */
    if ( headRot.w == -3.0f )
@@ -5379,6 +5431,9 @@ IVAS_REND_DisableHeadRotation(
    IVAS_REND_HANDLE hIvasRend /* i/o: Renderer handle                                     */
)
{
#ifdef FIX_513_REND_MC_ALLOC
    int16_t i;
#endif
    /* Validate function arguments */
    if ( hIvasRend == NULL )
    {
@@ -5386,6 +5441,21 @@ IVAS_REND_DisableHeadRotation(
    }

    hIvasRend->headRotData.headRotEnabled = 0;
#ifdef FIX_513_REND_MC_ALLOC
    /* reconfigure binaural rendering to allocate
       the necessary renderers and free unused ones */
    if ( getAudioConfigType( hIvasRend->outputConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL )
    {
        for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i )
        {
            initMcBinauralRendering( &hIvasRend->inputsMc[i],
                                     hIvasRend->inputsMc[i].base.inConfig,
                                     hIvasRend->outputConfig,
                                     hIvasRend->hRendererConfig );
        }
    }

#endif
    return IVAS_ERR_OK;
}
#endif