From adeac5396d848b470fad63fcd02bdcb513a2a3c4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 2 Nov 2022 09:28:05 +0100 Subject: [PATCH 1/4] - BRATE_SWITCHING_FRAMEWORK - Bitrate switching changes related to the general framework - BRATE_SWITCHING_RENDERING - Bitrate switching changes related to the renderers --- lib_com/options.h | 4 + lib_dec/ivas_binauralRenderer.c | 11 ++- lib_dec/ivas_binaural_reverb.c | 3 + lib_dec/ivas_dirac_dec.c | 4 + lib_dec/ivas_dirac_dec_binaural_functions.c | 57 +++++++++++--- lib_dec/ivas_sba_dec.c | 86 +++++++++++++++++---- lib_enc/ivas_dirac_enc.c | 4 + lib_enc/ivas_mct_enc.c | 59 ++++++++++++++ 8 files changed, 199 insertions(+), 29 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9bdbbc81aa..f7d5ea7607 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,6 +154,10 @@ #define FIX_TCX_DEC_RECONF_BFI #define FIX_SBA_DTX_DECODE_ERROR /* Issue 176: SBA decoder error with DTX at 80kbps SWB, Issue 21: SBA front-VAD threshold (203) */ + +#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 */ #endif diff --git a/lib_dec/ivas_binauralRenderer.c b/lib_dec/ivas_binauralRenderer.c index 45108a92fa..95ce12b6bc 100644 --- a/lib_dec/ivas_binauralRenderer.c +++ b/lib_dec/ivas_binauralRenderer.c @@ -552,10 +552,17 @@ ivas_error ivas_binRenderer_open( } ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); - if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + +#ifdef BRATE_SWITCHING_RENDERING + if ( st_ivas->hoa_dec_mtx == NULL ) +#endif { - return error; + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } } + hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; st_ivas->binaural_latency_ns = (int32_t) ( FASTCONV_BRIR_latency_s * 1000000000.f ); } diff --git a/lib_dec/ivas_binaural_reverb.c b/lib_dec/ivas_binaural_reverb.c index b03c8c0053..db12954a1e 100644 --- a/lib_dec/ivas_binaural_reverb.c +++ b/lib_dec/ivas_binaural_reverb.c @@ -538,6 +538,9 @@ void ivas_binaural_reverb_close( } count_free( ( *hReverb ) ); +#ifdef BRATE_SWITCHING_RENDERING + ( *hReverb ) = NULL; +#endif return; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ec9a712065..13b93f227f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -270,6 +270,10 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef BRATE_SWITCHING_FRAMEWORK + st_ivas->nchan_transport = nchan_transport_orig; +#endif + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index ca9f0a4587..6c406ba536 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -98,9 +98,21 @@ ivas_error ivas_dirac_dec_init_binaural_data( float binCenterFreq, tmpFloat; ivas_error error; - if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) count_malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) +#ifdef BRATE_SWITCHING_RENDERING + hBinaural = st_ivas->hDiracDecBin; + + if ( hBinaural == NULL ) +#endif { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); + 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; @@ -189,18 +201,31 @@ ivas_error ivas_dirac_dec_init_binaural_data( { mvr2r( parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); - if ( hBinaural->useSubframeMode ) +#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 ) ) ) { - 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 ) - { - return error; - } + ivas_binaural_reverb_close( &( hBinaural->hReverb ) ); } - else + + if ( hBinaural->hReverb == NULL ) +#endif { - 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 ) + if ( hBinaural->useSubframeMode ) { - return error; + 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 ) + { + return error; + } + } + 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 ) + { + return error; + } } } } @@ -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 ) { - ivas_spar_td_decorr_dec_open( &( hBinaural->hTdDecorr ), output_Fs, 3, 1 ); +#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; diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 3d91d6834d..274b00a17b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -347,26 +347,29 @@ ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t i; - int16_t nchan_transport, nchan_transport_old; - int16_t nSCE_old, nCPE_old, nchan_hp20_old; + int16_t i, nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; AUDIO_CONFIG intern_config_old; int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; int16_t sba_dirac_stereo_flag_old; int32_t ivas_total_brate, last_ivas_total_brate; + DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; /*-----------------------------------------------------------------* - * Allocate, initalize, and configure SBA and rendering handles + * Set SBA high-level parameters + * Save old SBA high-level parameters *-----------------------------------------------------------------*/ ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifndef BRATE_SWITCHING_RENDERING numCldfbAnalyses = 0; +#endif nchan_hp20_old = getNumChanSynthesis( st_ivas ); @@ -377,9 +380,12 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &st_ivas->nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + - st_ivas->nchan_transport = nchan_transport; + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ /* renderer might have changed */ intern_config_old = st_ivas->intern_config; @@ -391,9 +397,45 @@ ivas_error ivas_sba_dec_reconfigure( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } +#ifdef BRATE_SWITCHING_RENDERING + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else 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->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( 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 ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } +#endif + + /*-----------------------------------------------------------------* + * hDirAC decoder handle configuration + *-----------------------------------------------------------------*/ + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { @@ -405,15 +447,15 @@ ivas_error ivas_sba_dec_reconfigure( int16_t sba_order_internal; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); + ivas_spar_config( hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) { return error; } } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || st_ivas->nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) { @@ -464,13 +506,24 @@ ivas_error ivas_sba_dec_reconfigure( /* 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 ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && nchan_transport > 1 ) + if ( nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) { deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); st_ivas->cldfbAnaDec[1] = NULL; numCldfbAnalyses_old--; } +#ifdef BRATE_SWITCHING_RENDERING + /* 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 ); + } + } +#endif + /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { @@ -486,7 +539,7 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } @@ -508,14 +561,14 @@ ivas_error ivas_sba_dec_reconfigure( /* create additional CLDFB synthesis instances */ for ( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } - +#ifndef BRATE_SWITCHING_RENDERING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ @@ -545,6 +598,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif return error; } diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 96a005a0b3..9b4256996f 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -131,6 +131,10 @@ ivas_error ivas_dirac_enc_open( } else { +#ifdef BRATE_SWITCHING_FRAMEWORK + hDirAC->num_samples_synchro_delay = 0; +#endif + for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) { hDirAC->sba_synchro_buffer[i] = NULL; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 18c3b93fb9..9fbf63c952 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -44,6 +44,48 @@ #include "wmops.h" +#ifdef BRATE_SWITCHING_FRAMEWORK +/*-------------------------------------------------------------------* + * set_mct_enc_params() + * + * Set hMCT handle parameters + *-------------------------------------------------------------------*/ + +static void set_mct_enc_params( + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const SBA_MODE sba_mode, /* i : SBA mode */ + const uint16_t b_nchan_change /* i : flag indicating different channel count */ +) +{ + int16_t n; + + if ( b_nchan_change ) + { + hMCT->currBlockDataCnt = 0; + + /*Initialize bits required to signal channel-pair index*/ + hMCT->bitsChannelPairIndex = max( 1, (int16_t) ( floor( ( log( hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) / log( 2. ) ) ) + 1 ) ); + + set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + + for ( n = 0; n < MCT_MAX_CHANNELS; n++ ) + { + set_f( hMCT->lastxCorrMatrix[n], 0, MCT_MAX_CHANNELS ); + } + } + + hMCT->hbr_mct = 0; + if ( sba_mode == SBA_MODE_SPAR && ivas_total_brate >= IVAS_256k ) + { + hMCT->hbr_mct = 1; + } + + return; +} +#endif + + /*-------------------------------------------------------------------* * ivas_mct_enc() * @@ -276,6 +318,10 @@ ivas_error create_mct_enc( * Initializations *-----------------------------------------------------------------*/ +#ifdef BRATE_SWITCHING_FRAMEWORK + set_mct_enc_params( hMCT, ivas_total_brate, st_ivas->sba_mode, 1 ); +#else + hMCT->currBlockDataCnt = 0; /*Initialize bits required to signal channel-pair index*/ @@ -292,6 +338,7 @@ ivas_error create_mct_enc( { hMCT->hbr_mct = 1; } +#endif st_ivas->hMCT = hMCT; @@ -332,6 +379,13 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = st_ivas->hEncoderConfig->nchan_inp - 1; /* LFE channel is coded separately */ hMCT->num_lfe = TRUE; } +#ifdef BRATE_SWITCHING_FRAMEWORK + else if ( ivas_format == SBA_FORMAT ) + { + hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + hMCT->num_lfe = FALSE; + } +#else else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) // VE: this condition to be reviewed together with the following one { hMCT->nchan_out_woLFE = ivas_get_sba_num_TCs( ivas_total_brate, st_ivas->sba_analysis_order ); @@ -342,6 +396,7 @@ ivas_error mct_enc_reconfigure( hMCT->nchan_out_woLFE = ivas_sba_get_nchan( st_ivas->sba_analysis_order, st_ivas->hEncoderConfig->sba_planar ); hMCT->num_lfe = FALSE; } +#endif else { assert( !"IVAS format currently not supported for MCT" ); @@ -454,6 +509,9 @@ ivas_error mct_enc_reconfigure( * Initializations *-----------------------------------------------------------------*/ +#ifdef BRATE_SWITCHING_FRAMEWORK + set_mct_enc_params( hMCT, ivas_total_brate, st_ivas->sba_mode, b_nchan_change ); +#else if ( b_nchan_change ) { hMCT->currBlockDataCnt = 0; @@ -467,6 +525,7 @@ ivas_error mct_enc_reconfigure( set_f( hMCT->lastxCorrMatrix[n], 0, MCT_MAX_CHANNELS ); } } +#endif return IVAS_ERR_OK; } -- GitLab From 46c805e87be9011554ea961d05c1255f506da297 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 23 Nov 2022 12:10:09 +0100 Subject: [PATCH 2/4] update with main --- lib_com/options.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2f90f2c877..d717b4ebb2 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -161,11 +161,10 @@ #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 */ #endif -- GitLab From 7e44f316ab8f25934693904ec3a409f20dabed7b Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 23 Nov 2022 12:50:36 +0100 Subject: [PATCH 3/4] introduce function ivas_cldfb_dec_reconfig() --- lib_com/ivas_prot.h | 9 +++ lib_dec/ivas_corecoder_dec_reconfig.c | 89 +++++++++++++++++++++++++++ lib_dec/ivas_sba_dec.c | 12 ++++ 3 files changed, 110 insertions(+) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index eac8ec005a..1a170720f8 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -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 */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index b11ba6cd39..b8d4e66cf4 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -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 diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9834cb0552..975fb60480 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -549,9 +549,17 @@ ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef BRATE_SWITCHING_RENDERING + int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; +#else int16_t i, nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; +#endif AUDIO_CONFIG intern_config_old; +#ifdef BRATE_SWITCHING_RENDERING + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; +#else int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; +#endif int16_t sba_dirac_stereo_flag_old; int32_t ivas_total_brate, last_ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig; @@ -704,6 +712,9 @@ ivas_error ivas_sba_dec_reconfigure( * CLDFB instances *-----------------------------------------------------------------*/ +#ifdef BRATE_SWITCHING_RENDERING + ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); +#else 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, @@ -769,6 +780,7 @@ ivas_error ivas_sba_dec_reconfigure( } } } +#endif #ifndef BRATE_SWITCHING_RENDERING /*-------------------------------------------------------------------* -- GitLab From 8dd9ee4a4a632d0e1f2df8074620babc924e8a5e Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 23 Nov 2022 13:00:05 +0100 Subject: [PATCH 4/4] call "st_ivas->nchan_transport = nchan_transport_orig" assignment only at one place; under BRATE_SWITCHING_FRAMEWORK --- lib_dec/ivas_dirac_dec.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 2daed39221..5f9e908481 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -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 ); @@ -273,15 +277,12 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { -#ifdef BRATE_SWITCHING_FRAMEWORK - st_ivas->nchan_transport = nchan_transport_orig; -#endif - 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; @@ -876,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; } -- GitLab