Commit 16650c8a authored by bayers's avatar bayers
Browse files

[fix] fixed binaural rendering for MC bitrate switching

parent 9a68006f
Loading
Loading
Loading
Loading
+101 −5
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ ivas_error ivas_mc_dec_config(
    AUDIO_CONFIG signaled_config;
    MC_MODE last_mc_mode;
    ivas_error error;

    MC_MODE mc_mode;
    error = IVAS_ERR_OK;

    /* store last frame MC mode */
@@ -646,24 +646,34 @@ ivas_error ivas_mc_dec_reconfig(
{
    int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old;
    int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i;
    int16_t renderer_type_old;
    ivas_error error;

    MC_MODE mc_mode;
    error = IVAS_ERR_OK;
    
    nchan_transport_old = st_ivas->nchan_transport;
    
    /* we have to temporally set the current mc_mode back to the previous one to make sure the following call to 
       ivas_init_dec_get_num_cldfb_instances() returns the correct counts */
    mc_mode = st_ivas->mc_mode;
    st_ivas->mc_mode = last_mc_mode;
    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
    st_ivas->mc_mode = mc_mode;

    nSCE_old = st_ivas->nSCE;
    nCPE_old = st_ivas->nCPE;
    sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;

    /* renderer might have changed, reselect */
    renderer_type_old = st_ivas->renderer_type;
    ivas_renderer_select( st_ivas );
    if ( st_ivas->mc_mode == MC_MODE_MCT )
    {
        st_ivas->nSCE = 0;
        st_ivas->nCPE = st_ivas->hDecoderConfig->nchan_out / 2;


        st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) );
        st_ivas->nSCE = 0;
        st_ivas->nCPE = st_ivas->nchan_transport / 2;

        if ( last_mc_mode != MC_MODE_MCT )
        {
@@ -891,6 +901,92 @@ ivas_error ivas_mc_dec_reconfig(
        set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k );
    }


    /* renderers */
    if ( renderer_type_old != st_ivas->renderer_type )
    {
        AUDIO_CONFIG output_config;

        output_config = st_ivas->hDecoderConfig->output_config;
        /* binaural renderers*/
        if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM )
        {
            /* remove unneeded binaural renderers */
            if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) )
            {
                ivas_binRenderer_close( &st_ivas->hBinRenderer );
            }
            if ( st_ivas->hCrend != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD || st_ivas->hRenderConfig->roomAcoustics.late_reverb_on == 0 ) ) )
            {
                ivas_crend_close( st_ivas );
            }
            if ( st_ivas->hBinRendererTd != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) )
            {
                ivas_td_binaural_close( &st_ivas->hBinRendererTd );
            }
            if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
            {
                ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin );
            }
            /* init necessary new renderers */
            if ( st_ivas->hBinRenderer == NULL && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
            {
                if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) )
            {
                if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else if ( st_ivas->hBinRendererTd == NULL && st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD )
            {
                if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK )
                {
                    return error;
                }

                if ( st_ivas->hCrend == NULL && st_ivas->hRenderConfig->roomAcoustics.late_reverb_on )
                {
                    if ( ( st_ivas->hCrend = (CREND_HANDLE) count_malloc( sizeof( CREND_DATA ) ) ) == NULL )
                    {
                        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR Crend\n" );
                    }
                }
            }
            else if ( st_ivas->hCrend == NULL && (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ))
            {
                if ( ivas_crend_open( st_ivas ) != IVAS_ERR_OK )
                {
                    return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "ivas_crend_open failed" );
                }
            }
        }
        /* stereo */
        else if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO )
        {
            /* nothing should happen here... */
        }
        /* LS */
        else if ( output_config == AUDIO_CONFIG_5_1 || output_config == AUDIO_CONFIG_5_1_2 || output_config == AUDIO_CONFIG_5_1_4 || output_config == AUDIO_CONFIG_7_1 || output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_LS_CUSTOM )
        {
#ifdef DEBUGGING
            assert( st_ivas->renderer_type == RENDERER_MC || st_ivas->renderer_type == RENDERER_MC_PARAMMC || st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_DISABLE );
#endif
        }
#ifdef DEBUGGING
        else if ( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 )
        {
            /* FOA/HOA output */
            /* Nothing to do, is always RENDERER_SBA_LINEAR_ENC */
            assert( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC && renderer_type_old == RENDERER_SBA_LINEAR_ENC );
        }
#endif
    }
    return error;
}
#endif