Commit 0d52c934 authored by vaclav's avatar vaclav
Browse files

Merge branch '114-bitrate-switching-in-sba-framework' into 'main'

Bitrate switching in SBA - framework changes

See merge request !226
parents 4b906d96 8dd9ee4a
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -3053,6 +3053,7 @@ ivas_error ivas_sba_dec_reinit(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
);
#endif

ivas_error ivas_sba_dec_reconfigure(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
);
@@ -3063,6 +3064,14 @@ void ivas_init_dec_get_num_cldfb_instances(
    int16_t *numCldfbSyntheses                                  /* o  : number of CLDFB synthesis instances     */
);

#ifdef BRATE_SWITCHING_RENDERING
ivas_error ivas_cldfb_dec_reconfig(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                                */
    const int16_t nchan_transport_old,                          /* i  : number of TCs in previous frame                       */
    int16_t numCldfbAnalyses_old,                               /* i  : number of CLDFB analysis instances in previous frame  */
    const int16_t numCldfbSyntheses_old                         /* i  : number of CLDFB synthesis instances in previous frame */
);
#endif
/*! r: Ambisonic (SBA) order */
int16_t ivas_sba_get_order(
    const int16_t nb_channels,                                  /* i  : Number of ambisonic channels            */
+3 −0
Original line number Diff line number Diff line
@@ -161,6 +161,9 @@
#define FIX_I218_PARAMISM_NOISY_SPEECH                  /* Issue 218: Fix noisy speech buffer in ParamISM */
#define FIX_I217_GSC_FLAG_IN_ISM                        /* Issue 217: fix BER detected in ISM4 due to desynchronized 'GSC_IVAS_mode' parameter */
#define FIX_158_DIRAC_MEM                               /* Issue 158: Reduce memory consumption in the hDirac_mem handle */
#define BRATE_SWITCHING_FRAMEWORK                       /* Bitrate switching changes related to the general framework  */
#define BRATE_SWITCHING_RENDERING                       /* Bitrate switching changes related to the renderers */


/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+89 −0
Original line number Diff line number Diff line
@@ -398,3 +398,92 @@ ivas_error ivas_hp20_dec_reconfig(

    return error;
}


#ifdef BRATE_SWITCHING_RENDERING
/*-------------------------------------------------------------------*
 * ivas_cldfb_dec_reconfig()
 *
 * Allocate, initialize, and configure CLDFB handles in case of bitrate switching
 *-------------------------------------------------------------------*/

ivas_error ivas_cldfb_dec_reconfig(
    Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                                */
    const int16_t nchan_transport_old,  /* i  : number of TCs in previous frame                       */
    int16_t numCldfbAnalyses_old,       /* i  : number of CLDFB analysis instances in previous frame  */
    const int16_t numCldfbSyntheses_old /* i  : number of CLDFB synthesis instances in previous frame */
)
{
    int16_t i, numCldfbAnalyses, numCldfbSyntheses;
    DECODER_CONFIG_HANDLE hDecoderConfig;
    ivas_error error;

    hDecoderConfig = st_ivas->hDecoderConfig;

    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses );

    /* special case, if there was one transport channel in the previous frame and more than one in the current frame,
       remove the second CLDFB here, it was for CNA/CNG */
    if ( st_ivas->ivas_format == SBA_FORMAT && nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 )
    {
        deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) );
        st_ivas->cldfbAnaDec[1] = NULL;
        numCldfbAnalyses_old--;
    }

    /* resample CLDFB analysis instances */
    for ( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ )
    {
        if ( ( st_ivas->cldfbAnaDec[i]->no_channels * st_ivas->cldfbAnaDec[i]->no_col ) != ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ) )
        {
            resampleCldfb( st_ivas->cldfbAnaDec[i], hDecoderConfig->output_Fs );
        }
    }

    /* Analysis*/
    if ( numCldfbAnalyses_old > numCldfbAnalyses )
    {
        /* delete superfluous CLDFB synthesis instances */
        for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ )
        {
            deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) );
            st_ivas->cldfbAnaDec[i] = NULL;
        }
    }
    else if ( numCldfbAnalyses_old < numCldfbAnalyses )
    {
        /* create additional CLDFB synthesis instances */
        for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ )
        {
            if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }

    /* Synthesis */
    if ( numCldfbSyntheses_old > numCldfbSyntheses )
    {
        /* delete superfluous CLDFB synthesis instances */
        for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ )
        {
            deleteCldfb( &( st_ivas->cldfbSynDec[i] ) );
            st_ivas->cldfbSynDec[i] = NULL;
        }
    }
    else if ( numCldfbSyntheses_old < numCldfbSyntheses )
    {
        /* create additional CLDFB synthesis instances */
        for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ )
        {
            if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }

    return IVAS_ERR_OK;
}
#endif
+8 −2
Original line number Diff line number Diff line
@@ -262,6 +262,10 @@ ivas_error ivas_dirac_dec_config(
     * set input parameters
     *-----------------------------------------------------------------*/

#ifdef BRATE_SWITCHING_FRAMEWORK
    st_ivas->nchan_transport = nchan_transport_orig;
#endif

    if ( flag_config == DIRAC_OPEN )
    {
        hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );
@@ -276,8 +280,9 @@ ivas_error ivas_dirac_dec_config(
        return IVAS_ERR_OK;
    }

#ifndef BRATE_SWITCHING_FRAMEWORK
    st_ivas->nchan_transport = nchan_transport_orig;

#endif
    if ( nchan_transport_orig > 2 && hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC )
    {
        hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS;
@@ -872,8 +877,9 @@ ivas_error ivas_dirac_dec_config(
        st_ivas->hDirAC = hDirAC;
    }

#ifndef BRATE_SWITCHING_FRAMEWORK
    st_ivas->nchan_transport = nchan_transport_orig;

#endif
    return error;
}

+46 −11
Original line number Diff line number Diff line
@@ -98,11 +98,23 @@ ivas_error ivas_dirac_dec_init_binaural_data(
    float binCenterFreq, tmpFloat;
    ivas_error error;

#ifdef BRATE_SWITCHING_RENDERING
    hBinaural = st_ivas->hDiracDecBin;

    if ( hBinaural == NULL )
#endif
    {
        if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " );
        }

#ifdef BRATE_SWITCHING_RENDERING
        hBinaural->hTdDecorr = NULL;
        hBinaural->hReverb = NULL;
#endif
    }

    nBins = st_ivas->hDirAC->num_freq_bands;
    output_Fs = st_ivas->hDecoderConfig->output_Fs;
    renderer_type = st_ivas->renderer_type;
@@ -189,6 +201,18 @@ ivas_error ivas_dirac_dec_init_binaural_data(
    {
        mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins );

#ifdef BRATE_SWITCHING_RENDERING
        /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */
        if ( hBinaural->hReverb != NULL && ( ( hBinaural->hReverb->numBins != nBins ) ||
                                             ( hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) ||
                                             ( !hBinaural->useSubframeMode && hBinaural->hReverb->blockSize != CLDFB_NO_COL_MAX ) ) )
        {
            ivas_binaural_reverb_close( &( hBinaural->hReverb ) );
        }

        if ( hBinaural->hReverb == NULL )
#endif
        {
            if ( hBinaural->useSubframeMode )
            {
                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 )
@@ -204,6 +228,7 @@ ivas_error ivas_dirac_dec_init_binaural_data(
                }
            }
        }
    }
    else if ( renderer_type == RENDERER_STEREO_PARAMETRIC )
    {
        set_f( hBinaural->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX );
@@ -219,7 +244,13 @@ ivas_error ivas_dirac_dec_init_binaural_data(
    {
        if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT )
        {
#ifdef BRATE_SWITCHING_RENDERING
            if ( hBinaural->hTdDecorr == NULL )
#endif
            {
                ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 );
            }

            if ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 )
            {
                hBinaural->hTdDecorr->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR;
@@ -236,7 +267,11 @@ ivas_error ivas_dirac_dec_init_binaural_data(
    }
    else
    {
#ifdef BRATE_SWITCHING_RENDERING
        ivas_spar_td_decorr_dec_close( &( hBinaural->hTdDecorr ) );
#else
        hBinaural->hTdDecorr = NULL;
#endif
    }

    st_ivas->hDiracDecBin = hBinaural;
Loading