Commit 1d5804fd authored by bayers's avatar bayers
Browse files

Merge remote-tracking branch 'remotes/origin/main' into FhG/5ms-api-continuation

parents 98e0e7a1 e5a2a984
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@
#define FIX_632_USAN_ERROR_NULL_POINTER                 /* FhG: issue 632 USAN offset to null pointer proto_diffuse_buffer_f in dirac rendering*/
#define FIX_759_CODE_COVERAGE_OSBA                      /* VA: issue 759: remove obsolete code in the OSBA encoder */
#define FIX_708_AEID_COMMAND_LINE                       /* VA: issue 708: improve AEID command-line robustness */
#define FIX_513_REND_MC_ALLOC                           /* FhG: issue 513, optimise external renderer allocation for multichannel */
#define FIX_518_ISM_BRIR_EXTREND                        /* FhG: fix issue #518, cleanup ISM to BINAURAL_ROOM_IR rendering in the external renderer */
#define FIX_764_HARM_CODE                               /* VA: issue 764: introduce new function for the same code block at four different places */
#define FIX_747_ISM_TODOS                               /* VA: issue 747 - address ISM ToDos */
@@ -229,6 +230,7 @@
#define NONBE_FIX_798_OSBA_MC_DEC_CRASH
#define NONBE_FIX_806_OMASA_ONE_SEP_TRANSPORT_MIX             /* Nokia: issue 806: fix one separated object mode transport mix of the separated object */
#define NONBE_FIX_809_EXTERNAL_TARGET_INTERPOLATION           /* FhG: issue 809: unify external target interpolation inter and intra frame behaviour */
#define NONBE_FIX_775_OSBA_BR_SWITCHING_CRASH                 /* FhG: issue 775: fix crash in OSBA with bitrate switching and output order lower than input order */

#define JBM_FOR_OSBA                                          /* FhG: implement OSBA format in the JBM path */

+6 −0
Original line number Diff line number Diff line
@@ -483,6 +483,12 @@ ivas_error ivas_sba_dec_reconfigure(

        ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
                                 st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
#ifdef NONBE_FIX_775_OSBA_BR_SWITCHING_CRASH
        if ( st_ivas->hDirAC )
        {
            st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band;
        }
#endif
    }
#endif

+260 −141
Original line number Diff line number Diff line
@@ -2171,7 +2171,12 @@ static ivas_error initMcBinauralRendering(
    input_mc *inputMc,
    const AUDIO_CONFIG inConfig,
    const AUDIO_CONFIG outConfig,
    RENDER_CONFIG_DATA *hRendCfg )
    RENDER_CONFIG_DATA *hRendCfg
#ifdef FIX_513_REND_MC_ALLOC
    ,
    uint8_t reconfigureFlag
#endif
)
{
    ivas_error error;
#ifdef SPLIT_REND_WITH_HEAD_ROT
@@ -2179,15 +2184,45 @@ 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 != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
    {
        if ( inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
        {
            useTDRend = TRUE;
        }
        else if ( ( inConfig == IVAS_AUDIO_CONFIG_5_1 || inConfig == IVAS_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
        !reconfigureFlag || ( !useTDRend &&
#endif
                              inputMc->tdRendWrapper.hBinRendererTd != NULL )
#ifdef FIX_513_REND_MC_ALLOC
    )
#endif
    {
        ivas_td_binaural_close( &inputMc->tdRendWrapper.hBinRendererTd );
        inputMc->tdRendWrapper.hHrtfTD = NULL;
    }

#ifdef SPLIT_REND_WITH_HEAD_ROT
#ifdef FIX_513_REND_MC_ALLOC
    if ( !reconfigureFlag || !useTDRend )
    {
#endif
        for ( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
        {
            if ( inputMc->splitTdRendWrappers[i].hBinRendererTd != NULL )
@@ -2196,44 +2231,52 @@ static ivas_error initMcBinauralRendering(
                inputMc->splitTdRendWrappers[i].hHrtfTD = NULL;
            }
        }
#ifdef FIX_513_REND_MC_ALLOC
    }
#endif
#endif

    ivas_rend_closeCrend( &inputMc->crendWrapper, inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses );
#else
    ivas_rend_closeCrend( &inputMc->crendWrapper );
#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 ( !reconfigureFlag || ( !useTDRend && outConfig != IVAS_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 ( !reconfigureFlag || ( inConfig == IVAS_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 != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) && ( outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
    // #else
    // if ( outConfig != IVAS_REND_AUDIO_CONFIG_BINAURAL_ROOM )
    // #endif
    // {
    //     if ( inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM )
    //     {
    //         initTDRend = true;
    //     }
    //     else if ( ( inConfig == IVAS_AUDIO_CONFIG_5_1 || inConfig == IVAS_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 )
        {
@@ -2257,7 +2300,11 @@ static ivas_error initMcBinauralRendering(
        }

#endif
        if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
        if ( outConfig == IVAS_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 )
            {
@@ -2265,7 +2312,10 @@ static ivas_error initMcBinauralRendering(
            }
        }
    }

#ifdef FIX_513_REND_MC_ALLOC
    else if ( !useTDRend && inputMc->crendWrapper == NULL ) /* open CREND */
#endif
    {
#ifdef SPLIT_REND_WITH_HEAD_ROT
        if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( inConfig == IVAS_AUDIO_CONFIG_LS_CUSTOM ) ? IVAS_AUDIO_CONFIG_7_1_4 : inConfig, outConfig, hRendCfg, NULL, outSampleRate, ( ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) || ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) ? inputMc->base.ctx.pSplitRendWrapper->multiBinPoseData.num_poses : 1 ) ) != IVAS_ERR_OK )
#else
@@ -2275,9 +2325,16 @@ static ivas_error initMcBinauralRendering(
        {
            return error;
        }
#ifdef FIX_513_REND_MC_ALLOC
    }
#endif

    /* Initialise the EFAP handle for rotation on input layout */
    if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM && inputMc->base.ctx.pHeadRotData->headRotEnabled )
    if ( inConfig != IVAS_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 )
        {
@@ -2446,6 +2503,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 )
@@ -2458,7 +2518,12 @@ static ivas_error setRendInputActiveMc(
        if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
#endif
    {
        if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRendCfg ) ) != IVAS_ERR_OK )
        if ( ( error = initMcBinauralRendering( inputMc, inConfig, outConfig, hRendCfg
#ifdef FIX_513_REND_MC_ALLOC
                                                ,
                                                FALSE
#endif
                                                ) ) != IVAS_ERR_OK )
        {
            return error;
        }
@@ -4357,9 +4422,14 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout(
     * set for the MC input. */
    inputMc->customLsInput = makeCustomLsSetup( layout );

    inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig, inputMc->customLsInput, hIvasRend->outputConfig, *inputMc->base.ctx.pCustomLsOut );
    inputMc->lfeRouting = defaultLfeRouting( inputMc->base.inConfig,
                                             inputMc->customLsInput,
                                             hIvasRend->outputConfig,
                                             *inputMc->base.ctx.pCustomLsOut );

    if ( ( error = initEfap( &inputMc->efapInWrapper, inputMc->base.inConfig, &inputMc->customLsInput ) ) != IVAS_ERR_OK )
    if ( ( error = initEfap( &inputMc->efapInWrapper,
                             inputMc->base.inConfig,
                             &inputMc->customLsInput ) ) != IVAS_ERR_OK )
    {
        return error;
    }
@@ -4370,7 +4440,15 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout(
        if ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
#endif
    {
        if ( ( error = initMcBinauralRendering( inputMc, inputMc->base.inConfig, hIvasRend->outputConfig, hIvasRend->hRendererConfig ) ) != IVAS_ERR_OK )
        if ( ( error = initMcBinauralRendering( inputMc,
                                                inputMc->base.inConfig,
                                                hIvasRend->outputConfig,
                                                hIvasRend->hRendererConfig
#ifdef FIX_513_REND_MC_ALLOC
                                                ,
                                                FALSE
#endif
                                                ) ) != IVAS_ERR_OK )
        {
            return error;
        }
@@ -5186,6 +5264,9 @@ ivas_error IVAS_REND_SetHeadRotation(
#endif
    const int16_t sf_idx )
{
#ifdef FIX_513_REND_MC_ALLOC
    int16_t i;
#endif
    IVAS_QUATERNION rotQuat;
    ivas_error error;

@@ -5201,6 +5282,23 @@ 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 )
    {
        if ( hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID )
        {
            initMcBinauralRendering( &hIvasRend->inputsMc[i],
                                     hIvasRend->inputsMc[i].base.inConfig,
                                     hIvasRend->outputConfig,
                                     hIvasRend->hRendererConfig,
                                     TRUE );
        }
    }
#endif
    /* check for Euler angle signaling */
    if ( headRot.w == -3.0f )
    {
@@ -5236,6 +5334,9 @@ ivas_error 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 )
    {
@@ -5243,7 +5344,25 @@ ivas_error 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 )
        {
            if ( hIvasRend->inputsMc[i].base.inConfig != IVAS_AUDIO_CONFIG_INVALID )
            {
                initMcBinauralRendering( &hIvasRend->inputsMc[i],
                                         hIvasRend->inputsMc[i].base.inConfig,
                                         hIvasRend->outputConfig,
                                         hIvasRend->hRendererConfig,
                                         TRUE );
            }
        }
    }

#endif
    return IVAS_ERR_OK;
}