From 3c55d9a880a53c57e417912e45331289cc049afb Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 7 Oct 2022 14:20:42 +0200 Subject: [PATCH 01/42] first changes to enable bitrate swtiching for MC at encoder side. WIP. --- lib_com/ivas_prot.h | 17 +++ lib_com/options.h | 1 + lib_enc/ivas_corecoder_enc_reconfig.c | 6 + lib_enc/ivas_mc_param_enc.c | 123 +++++++++++++++++++ lib_enc/ivas_mct_enc.c | 163 +++++++++++++++++++++++++- 5 files changed, 308 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bd587c1e68..69a0487292 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -628,6 +628,13 @@ ivas_error ivas_mc_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +#ifdef MC_BITRATE_SWITCHING +ivas_error ivas_mc_enc_reconfig( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t last_mc_mode /* i: last frame mc mode */ +); +#endif + ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx /* i : LS config. index */ @@ -3483,7 +3490,17 @@ int16_t ivas_param_mc_getNumTransportChannels( ivas_error ivas_param_mc_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); +#ifdef MC_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_param_mc_enc_open() + * + * Initialize Parametric MC encoder handle + *------------------------------------------------------------------------*/ +ivas_error ivas_param_mc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); +#endif void ivas_param_mc_enc_close( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ const int32_t input_Fs /* i : input sampling rate */ diff --git a/lib_com/options.h b/lib_com/options.h index 7556ecb139..d6c426b75e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,6 +160,7 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ +#define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f4b302eefd..39b1733620 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -286,6 +286,12 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } } +#ifdef MC_BITRATE_SWITCHING + if ( nSCE_old ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } +#endif } } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index af7a48a80b..46083faac7 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -218,6 +218,129 @@ ivas_error ivas_param_mc_enc_open( return error; } +#ifdef MC_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_param_mc_enc_open() + * + * Initialize Parametric MC encoder handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_param_mc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + int16_t i, k, l; + PARAM_MC_ENC_HANDLE hParamMC; + uint16_t config_index; + MC_LS_SETUP mc_input_setup; + int16_t max_bwidth; + int32_t input_Fs, ivas_total_brate; + ivas_error error; + + error = IVAS_ERR_OK; + + mc_input_setup = st_ivas->hEncoderConfig->mc_input_setup; + max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + input_Fs = st_ivas->hEncoderConfig->input_Fs; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + hParamMC = st_ivas->hParamMC; + + /* Preparing Config */ + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_input_setup ); + + /* get configuration index */ + config_index = ivas_param_mc_get_configuration_index( mc_input_setup, ivas_total_brate ); + + /* set core coder dependent on the number of transport channels */ + switch ( st_ivas->nchan_transport ) + { + case 4: + case 3: + st_ivas->nCPE = 2; + st_ivas->nSCE = 0; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + break; + case 2: + st_ivas->nCPE = 1; + st_ivas->nSCE = 0; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + break; +#ifdef DEBUGGING + default: + assert( 0 && "Number of transport channels not supported by ParamMC!\n" ); +#endif + } + + /* get dmx factors */ + hParamMC->dmx_factors = ivas_param_mc_conf[config_index].dmx_fac; + + + /* open/init parameter coding */ + ivas_param_mc_metadata_open( mc_input_setup, hParamMC->lfe_index, ivas_total_brate, &hParamMC->hMetadataPMC ); + + /* init icc index states */ + for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) + { + set_s( hParamMC->icc_map_index[i], -1, PARAM_MC_SZ_ICC_MAP ); + + for ( l = 0; l < hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_lfe; l++ ) + { + for ( k = 0; k < hParamMC->hMetadataPMC.icc_map_size_full; k++ ) + { + if ( hParamMC->hMetadataPMC.icc_mapping[i][l][0] == hParamMC->hMetadataPMC.icc_map_full[0][k] && hParamMC->hMetadataPMC.icc_mapping[i][l][1] == hParamMC->hMetadataPMC.icc_map_full[1][k] ) + { + hParamMC->icc_map_index[i][l] = k; + } + } + } + } + + /* Band Grouping */ + if ( hParamMC->hMetadataPMC.num_parameter_bands == 20 ) + { + mvs2s( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); + } + else if ( hParamMC->hMetadataPMC.num_parameter_bands == 14 ) + { + mvs2s( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); + } + else if ( hParamMC->hMetadataPMC.num_parameter_bands == 10 ) + { + mvs2s( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); + } + else + { + assert( 0 && "nbands must be 20, 14, or 10!" ); + } + + /* set max parameter band for abs cov */ + i = 0; + while ( hParamMC->band_grouping[i] <= PARAM_MC_MAX_BAND_ABS_COV_ENC ) + { + hParamMC->max_param_band_abs_cov = ( i++ ); + } + + /* parameter band grouping: 60 band CLDFB to 240 band MDFT resolution */ + for ( i = 0; i < hParamMC->hMetadataPMC.num_parameter_bands + 1; i++ ) + { + hParamMC->band_grouping[i] *= CLDFB_TO_MDFT_FAC; + } + + /* set correct coded band width */ + hParamMC->hMetadataPMC.coded_bwidth = max_bwidth; + hParamMC->hMetadataPMC.last_coded_bwidth = max_bwidth; + ivas_param_mc_set_coded_bands( &hParamMC->hMetadataPMC ); + + /* initialize offset for transient detection */ + hParamMC->transient_detector_delay = ( NSUBBLOCKS_SHIFT + 1 ) + NSUBBLOCKS + 1 - (int16_t) ceilf( (float) NS2SA( input_Fs, DELAY_DIRAC_ENC_CMP_NS ) / (float) NS2SA( input_Fs, 2 * DIRAC_SLOT_NS ) ); + + /* Init total/dmx ener factors */ + set_f( hParamMC->ener_fac, 0.0f, PARAM_MC_MAX_PARAMETER_BANDS ); + + + return error; +} +#endif /*------------------------------------------------------------------------- * ivas_param_mc_enc_close() diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index bcf5482da9..1003697735 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -245,8 +245,9 @@ ivas_error create_mct_enc( for ( n = 0; n < max_blocks; n++ ) { +#ifndef MC_BITRATE_SWITCHING assert( st_ivas->hEncoderConfig->element_mode_init == IVAS_CPE_MDCT && "MCT is not supported for other stereo modes" ); - +#endif if ( ( hMCT->hBlockData[n] = (MCT_BLOCK_DATA_HANDLE) count_malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); @@ -542,9 +543,167 @@ ivas_error ivas_mc_enc_config( /* MC format switching */ if ( st_ivas->hEncoderConfig->last_ivas_total_brate != st_ivas->hEncoderConfig->ivas_total_brate || st_ivas->mc_mode != last_mc_mode ) { - /*ivas_mc_enc_reconfigure( st_ivas );*/ +#ifdef MC_BITRATE_SWITCHING + ivas_mc_enc_reconfig( st_ivas, last_mc_mode ); +#else return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: MC format switching not supported yet!!!\n\n" ); +#endif } return error; } + +#ifdef MC_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_mc_enc_reconfig() + * - reconfigure the MC format encoder + *-------------------------------------------------------------------------*/ + +ivas_error ivas_mc_enc_reconfig( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t last_mc_mode /* i: last frame mc mode */ +) +{ + int16_t nchan_transport_old, nSCE_old, nCPE_old; + ivas_error error; + + error = IVAS_ERR_OK; + + nchan_transport_old = st_ivas->nchan_transport; + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + st_ivas->nSCE = 0; + st_ivas->nCPE = st_ivas->hEncoderConfig->nchan_inp / 2; +#if 0 + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( cpe_id * CPE_CHANNELS + n == LFE_CHANNEL ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = 0; + continue; + } + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + } + + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); + + if ( last_mc_mode != MC_MODE_MCT ) + { +#if 0 + /*-----------------------------------------------------------------* + * Allocate MCT handle + *-----------------------------------------------------------------*/ + + if ( ( st_ivas->hMCT = (MCT_ENC_HANDLE) count_malloc( sizeof( MCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT\n" ) ); + } +#endif + + /*De-allocate handles for other MC modes*/ + if ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); + st_ivas->hParamMC = NULL; + } + + if ( st_ivas->hMcMasa != NULL ) + { + ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); + st_ivas->hMcMasa = NULL; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + if ( last_mc_mode != MC_MODE_PARAMMC ) + { + if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + } +#if 0 + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + + /* Metadata only initialized for the last CPE index*/ + if ( cpe_id == st_ivas->nCPE - 1 ) + { + st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); + } + } + + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); +#if 0 + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + } + + /* re-configure core coder*/ + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + + return error; +} +#endif \ No newline at end of file -- GitLab From e3d323ab544c8ac332eafed96fba3f15eeeee8d8 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 14 Oct 2022 16:28:29 +0200 Subject: [PATCH 02/42] enable decoder bitrate switching framework --- lib_com/ivas_prot.h | 17 +- lib_dec/ivas_mc_param_dec.c | 277 ++++++++++++++++++++++++++ lib_dec/ivas_mct_dec.c | 170 +++++++++++++++- lib_enc/ivas_corecoder_enc_reconfig.c | 6 - lib_enc/ivas_mct_enc.c | 137 ++++++------- 5 files changed, 522 insertions(+), 85 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6b714f25e3..27b9d21c0d 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -637,6 +637,12 @@ ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx /* i : LS config. index */ ); +#ifdef MC_BITRATE_SWITCHING +ivas_error ivas_mc_dec_reconfig( + Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t last_mc_mode /* i : last frame MC mode */ +); +#endif /*! r: MC format mode (MCT, McMASA, ParamMC) */ MC_MODE ivas_mc_mode_select( @@ -3501,12 +3507,6 @@ ivas_error ivas_param_mc_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); #ifdef MC_BITRATE_SWITCHING -/*------------------------------------------------------------------------- - * ivas_param_mc_enc_open() - * - * Initialize Parametric MC encoder handle - *------------------------------------------------------------------------*/ - ivas_error ivas_param_mc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); @@ -3526,6 +3526,11 @@ void ivas_param_mc_enc( ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef MC_BITRATE_SWITCHING +ivas_error ivas_param_mc_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */ diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 29e2ce4002..da643537e2 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -410,6 +410,283 @@ ivas_error ivas_param_mc_dec_open( return error; } +#ifdef MC_BITRATE_SWITCHING +ivas_error ivas_param_mc_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t k, nchan_transport; + PARAM_MC_DEC_HANDLE hParamMC; + IVAS_OUTPUT_SETUP hTransportSetup; + int16_t nchan_out_transport; + int16_t nchan_out_cov; + float proto_matrix[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + float proto_mtx_norm; + int16_t max_param_band_residual; + uint16_t config_index; + MC_LS_SETUP mc_ls_setup; + float frequency_axis[CLDFB_NO_CHANNELS_MAX]; + AUDIO_CONFIG output_config; + int32_t output_Fs, ivas_total_brate; + ivas_error error; + + error = IVAS_ERR_OK; + hParamMC = st_ivas->hParamMC; + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_config = st_ivas->hDecoderConfig->output_config; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + hTransportSetup = st_ivas->hTransSetup; + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + hParamMC->hoa_encoder = NULL; + + + hParamMC->ls_conv_dmx_matrix = NULL; + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else + { + nchan_out_cov = nchan_out_transport; + } + + st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); + nchan_transport = st_ivas->nchan_transport; + + switch ( nchan_transport ) + { + case 4: + case 3: + st_ivas->nCPE = 2; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + case 2: + st_ivas->nCPE = 1; + st_ivas->nSCE = 0; + st_ivas->element_mode_init = IVAS_CPE_MDCT; + + break; +#ifdef DEBUGGING + default: + assert( 0 && "Number of TC not supported for Parametric MC!" ); +#endif + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; + hParamMC->subframe_nbslots = CLDFB_NO_COL_MAX / PARAM_MC_NSUBFRAMES_DEC; + + hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; + ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); + + /* init arrays for quantized parameters */ + hParamMC->icc_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); + hParamMC->icld_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); + set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + + param_mc_set_num_synth_bands( output_Fs, hParamMC ); + + + /* Band Grouping */ + if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) + { + mvs2s( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); + } + else if ( hParamMC->hMetadataPMC->num_parameter_bands == 14 ) + { + mvs2s( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); + } + else if ( hParamMC->hMetadataPMC->num_parameter_bands == 10 ) + { + mvs2s( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); + } + else + { + assert( 0 && "nbands must be 20, 14, or 10!" ); + } + + /* set max parameter band for abs cov */ + k = 0; + while ( hParamMC->band_grouping[k] <= PARAM_MC_MAX_BAND_ABS_COV_DEC ) + { + hParamMC->max_param_band_abs_cov = ( k++ ); + } + + + /*-----------------------------------------------------------------* + * open sub-modules + *-----------------------------------------------------------------*/ + + /* prototype signal computation */ + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB || hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + hParamMC->ls_conv_dmx_matrix = (float *) count_malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); + for ( k = 0; k < nchan_out_transport; k++ ) + { + mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); + } + /* convert ParamMC parameter bands to SFB */ + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; + for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + } + } + else + { + /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */ + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + } + } + } + + hParamMC->proto_matrix_int = (float *) count_malloc( nchan_out_transport * nchan_transport * sizeof( float ) ); + mvr2r( ivas_param_mc_conf[config_index].dmx_fac, hParamMC->proto_matrix_int, nchan_transport * nchan_out_transport ); + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + matrix_product( hParamMC->ls_conv_dmx_matrix, nchan_out_cov, nchan_out_transport, 0, + ivas_param_mc_conf[config_index].dmx_fac, nchan_out_transport, nchan_transport, 0, + proto_matrix ); + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + proto_mtx_norm = 1.f; + for ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + { + proto_mtx_norm = max( fabsf( proto_mtx_norm ), fabsf( proto_matrix[k] ) ); + } + proto_mtx_norm = 1.f / proto_mtx_norm; + + /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ + for ( k = 0; k < nchan_transport; k++ ) + { + for ( int16_t i = 0; i < nchan_out_cov; i++ ) + { + st_ivas->hLsSetUpConversion->dmxMtx[k][i] = proto_matrix[k * nchan_out_cov + i] * proto_mtx_norm; + } + } + } + } + else + { + mvr2r( ivas_param_mc_conf[config_index].dmx_fac, proto_matrix, nchan_out_transport * nchan_transport ); + } + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + hParamMC->num_outputs_diff = 0; + hParamMC->diff_proto_info = NULL; + hParamMC->h_output_synthesis_params.use_onset_filters = 0; + hParamMC->max_band_decorr = 0; + hParamMC->h_freq_domain_decorr_ap_params = NULL; + hParamMC->h_freq_domain_decorr_ap_state = NULL; + } + else + { + hParamMC->num_outputs_diff = nchan_out_cov; + hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) count_malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ); + + param_mc_get_diff_proto_info( proto_matrix, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info ); + + /* decorrelation */ + hParamMC->h_freq_domain_decorr_ap_params = NULL; + hParamMC->h_freq_domain_decorr_ap_state = NULL; + + ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, hParamMC->num_freq_bands ); + + ivas_dirac_dec_decorr_open( &( hParamMC->h_freq_domain_decorr_ap_params ), + &( hParamMC->h_freq_domain_decorr_ap_state ), + hParamMC->num_freq_bands, + hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, + DIRAC_SYNTHESIS_COV_MC_LS, + frequency_axis, + nchan_transport, + output_Fs ); + + hParamMC->h_output_synthesis_params.use_onset_filters = 0; + hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + } + hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; + max_param_band_residual = 0; + + for ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + { + if ( hParamMC->band_grouping[k] <= hParamMC->max_band_decorr ) + { + max_param_band_residual = k; + assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); + break; + } + } + + /* output synthesis */ + ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), + &( hParamMC->h_output_synthesis_cov_state ), + hParamMC->max_band_decorr, + PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, + max_param_band_residual, + nchan_transport, + nchan_out_cov, + proto_matrix ); + + + /* Head rotation */ + if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation ) + { + hParamMC->hoa_encoder = (float *) count_malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ); + compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hParamMC->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); + } + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + if ( hParamMC->max_band_decorr > 0 ) + { + hParamMC->proto_frame_f = (float *) count_malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ); + hParamMC->proto_frame_dec_f = (float *) count_malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ); + } + else + { + hParamMC->proto_frame_f = NULL; + hParamMC->proto_frame_dec_f = NULL; + } + + ivas_param_mc_dec_init( hParamMC, nchan_transport, nchan_out_cov ); + + + return error; +} +#endif + /*------------------------------------------------------------------------- * param_mc_get_num_cldfb_syntheses() * diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index b4a4da3e3c..5095df6aed 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -622,8 +622,11 @@ ivas_error ivas_mc_dec_config( { if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) { - /*ivas_mc_dec_reconfigure( st_ivas );*/ +#ifdef MC_BITRATE_SWITCHING + ivas_mc_dec_reconfig( st_ivas, last_mc_mode ); +#else return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: MC format switching not supported yet!!!\n\n" ); +#endif } } @@ -632,3 +635,168 @@ ivas_error ivas_mc_dec_config( return error; } +#ifdef MC_BITRATE_SWITCHING +ivas_error ivas_mc_dec_reconfig( + Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t last_mc_mode /* i : last frame MC mode */ +) +{ + int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old; + ivas_error error; + + error = IVAS_ERR_OK; + + nchan_transport_old = st_ivas->nchan_transport; + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + + 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 ) ); + + if ( last_mc_mode != MC_MODE_MCT ) + { + /*De-allocate handles for other MC modes*/ + if ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_dec_close( &st_ivas->hParamMC ); + st_ivas->hParamMC = NULL; + } + + /* De-allocate McMasa-related handles */ + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_dec_close( st_ivas->hMasa ); + st_ivas->hMasa = NULL; + } + + if ( st_ivas->hQMetaData != NULL ) + { + ivas_qmetadata_close( &st_ivas->hQMetaData ); + st_ivas->hQMetaData = NULL; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + if ( last_mc_mode != MC_MODE_PARAMMC ) + { + if ( ( error = ivas_param_mc_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + ivas_param_mc_dec_reconfig( st_ivas ); + } + + /* De-allocate McMasa-related handles */ + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_dec_close( st_ivas->hMasa ); + st_ivas->hMasa = NULL; + } + + if ( st_ivas->hQMetaData != NULL ) + { + ivas_qmetadata_close( &st_ivas->hQMetaData ); + st_ivas->hQMetaData = NULL; + } + + if ( last_mc_mode == MC_MODE_MCT ) + { + if ( st_ivas->hMCT != NULL ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } + /* LFE handle */ + if ( st_ivas->hLFE != NULL ) + { + ivas_lfe_dec_close( st_ivas->hLFE ); + st_ivas->hLFE = NULL; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), st_ivas->hDecoderConfig->ivas_total_brate ); + + if ( last_mc_mode != MC_MODE_MCMASA ) + { + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->hParamMC != NULL ) + { + ivas_param_mc_dec_close( &st_ivas->hParamMC ); + st_ivas->hParamMC = NULL; + } + + if ( last_mc_mode == MC_MODE_MCT ) + { + if ( st_ivas->hMCT != NULL ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } + /* LFE handle */ + if ( st_ivas->hLFE != NULL ) + { + ivas_lfe_dec_close( st_ivas->hLFE ); + st_ivas->hLFE = NULL; + } + } + } + + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + + /* re-configure core coder*/ + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* re-configure hp20 memories */ + ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); + + /* Allocat the LFE handle that is coded seperately after the allocation of the core coders*/ + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + + if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* reuse core-coder buffers for LFE decoder */ + st_ivas->hLFE->prevsynth_buf = &st_ivas->hCPE[1]->hCoreCoder[1]->old_synth_sw[0]; + st_ivas->hLFE->prior_out_buffer = &st_ivas->hCPE[1]->hCoreCoder[1]->previoussynth[0]; + + set_zero( st_ivas->hLFE->prevsynth_buf, LFE_PLC_BUFLEN ); + set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k ); + } + + return error; +} +#endif diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 39b1733620..f4b302eefd 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -286,12 +286,6 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; } } -#ifdef MC_BITRATE_SWITCHING - if ( nSCE_old ) - { - st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; - } -#endif } } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 202cbd1dff..71d8f401fb 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -254,9 +254,9 @@ ivas_error create_mct_enc( for ( n = 0; n < max_blocks; n++ ) { -#ifndef MC_BITRATE_SWITCHING + assert( st_ivas->hEncoderConfig->element_mode_init == IVAS_CPE_MDCT && "MCT is not supported for other stereo modes" ); -#endif + if ( ( hMCT->hBlockData[n] = (MCT_BLOCK_DATA_HANDLE) count_malloc( sizeof( MCT_BLOCK_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT block data structure\n" ) ); @@ -599,45 +599,11 @@ ivas_error ivas_mc_enc_reconfig( { st_ivas->nSCE = 0; st_ivas->nCPE = st_ivas->hEncoderConfig->nchan_inp / 2; -#if 0 - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( cpe_id * CPE_CHANNELS + n == LFE_CHANNEL ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = 0; - continue; - } - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; - reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } - } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); if ( last_mc_mode != MC_MODE_MCT ) { -#if 0 - /*-----------------------------------------------------------------* - * Allocate MCT handle - *-----------------------------------------------------------------*/ - - if ( ( st_ivas->hMCT = (MCT_ENC_HANDLE) count_malloc( sizeof( MCT_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MCT\n" ) ); - } -#endif /*De-allocate handles for other MC modes*/ if ( st_ivas->hParamMC != NULL ) @@ -646,11 +612,23 @@ ivas_error ivas_mc_enc_reconfig( st_ivas->hParamMC = NULL; } + /* De-allocate McMasa-related handles */ if ( st_ivas->hMcMasa != NULL ) { ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hMcMasa = NULL; } + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); + st_ivas->hMasa = NULL; + } + + if ( st_ivas->hQMetaData != NULL ) + { + ivas_qmetadata_close( &st_ivas->hQMetaData ); + st_ivas->hQMetaData = NULL; + } } } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) @@ -664,59 +642,75 @@ ivas_error ivas_mc_enc_reconfig( } else { + ivas_param_mc_reconfig( st_ivas ); } -#if 0 - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; - reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } + /* De-allocate McMasa-related handles */ + if ( st_ivas->hMcMasa != NULL ) + { + ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); + st_ivas->hMcMasa = NULL; + } + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); + st_ivas->hMasa = NULL; + } - /* Metadata only initialized for the last CPE index*/ - if ( cpe_id == st_ivas->nCPE - 1 ) - { - st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; - reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); - } + if ( st_ivas->hQMetaData != NULL ) + { + ivas_qmetadata_close( &st_ivas->hQMetaData ); + st_ivas->hQMetaData = NULL; } - if ( st_ivas->nCPE > 1 ) + /* De-allocate MCT handle if last mode was MCT */ + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; } } -#endif - } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#if 0 - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + + if ( last_mc_mode != MC_MODE_MCMASA ) { - return error; + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( st_ivas->hParamMC != NULL ) { - return error; + ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); + st_ivas->hParamMC = NULL; } - - if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL ) { - return error; + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; } -#endif + } + + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } /* re-configure core coder*/ @@ -725,7 +719,6 @@ ivas_error ivas_mc_enc_reconfig( return error; } - return error; } #endif \ No newline at end of file -- GitLab From c3adc16e2eb939747956f2fc5dc11608dd306279 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 20 Oct 2022 09:02:54 +0200 Subject: [PATCH 03/42] * fixed memory leaks in ParamMC only bit rate switching * added remapping of parameter buffers for ParamMC if the number of TCs stay the same and the number of parameter bands are different on a bit rate switch --- lib_com/ivas_mc_param_com.c | 91 ++++++- lib_com/options.h | 2 +- lib_dec/ivas_mc_param_dec.c | 340 +++++++++++++++++++++----- lib_dec/ivas_mct_dec.c | 52 ++++ lib_enc/ivas_corecoder_enc_reconfig.c | 9 + lib_enc/ivas_init_enc.c | 1 + lib_enc/ivas_mc_param_enc.c | 14 ++ lib_enc/ivas_mct_enc.c | 51 +++- 8 files changed, 491 insertions(+), 69 deletions(-) diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 3690c1219f..bcdfc18c5f 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -329,6 +329,92 @@ void ivas_param_mc_default_icc_map( return; } +#ifdef MC_BITRATE_SWITCHING +int16_t ivas_param_mc_get_num_param_bands( + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ + ) +{ + int16_t num_parameter_bands; + num_parameter_bands = 0; + + /* parameter bands */ + switch ( mc_ls_setup ) + { + case MC_LS_SETUP_5_1: + switch ( ivas_total_brate ) + { + case IVAS_48k: + num_parameter_bands = 10; + break; + case IVAS_64k: + case IVAS_80k: + num_parameter_bands = 14; + break; + default: + assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" ); + } + break; + + case MC_LS_SETUP_7_1: + switch ( ivas_total_brate ) + { + case IVAS_48k: + num_parameter_bands = 10; + break; + case IVAS_64k: + case IVAS_80k: + num_parameter_bands = 14; + break; + case IVAS_96k: + num_parameter_bands = 20; + break; + } + break; + case MC_LS_SETUP_5_1_2: + switch ( ivas_total_brate ) + { + case IVAS_48k: + num_parameter_bands = 10; + break; + case IVAS_64k: + case IVAS_80k: + num_parameter_bands = 14; + break; + case IVAS_96k: + num_parameter_bands = 20; + break; + } + break; + case MC_LS_SETUP_5_1_4: + switch ( ivas_total_brate ) + { + case IVAS_96k: + num_parameter_bands = 14; + break; + case IVAS_128k: + num_parameter_bands = 20; + break; + } + break; + case MC_LS_SETUP_7_1_4: + switch ( ivas_total_brate ) + { + case IVAS_128k: + num_parameter_bands = 20; + break; + case IVAS_160k: + num_parameter_bands = 20; + break; + } + break; + default: + assert( 0 && "PARAM_MC: channel configuration not supportet!" ); + } + + return num_parameter_bands; +} +#endif /*------------------------------------------------------------------------- * Local functions @@ -427,6 +513,9 @@ static void ivas_param_mc_set_coding_scheme( assert( 0 && "PARAM_MC: channel configuration not supported!" ); } + #ifdef MC_BITRATE_SWITCHING + hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate ); + #else /* parameter bands */ switch ( mc_ls_setup ) { @@ -500,6 +589,6 @@ static void ivas_param_mc_set_coding_scheme( default: assert( 0 && "PARAM_MC: channel configuration not supportet!" ); } - +#endif return; } diff --git a/lib_com/options.h b/lib_com/options.h index a5f837cacb..28fb60c2e9 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ +#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ /*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index da643537e2..4e4bbac44d 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -411,6 +411,65 @@ ivas_error ivas_param_mc_dec_open( } #ifdef MC_BITRATE_SWITCHING + +typedef struct parameter_band_mapping_struct +{ + int16_t n_source_bands[20]; + int16_t source_band_idx[20][4]; + float source_band_factor[20][4]; + +} PARAM_MC_PARAMETER_BAND_MAPPING; + +static void ivas_param_mc_get_param_band_mapping( + const int16_t n_target_bands, + const int16_t *target_band_grouping, + const int16_t n_source_bands, + const int16_t *source_band_grouping, + PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping ) +{ + int16_t target_band_idx; + int16_t source_band_idx = 0; + int16_t source_band_cnt_total; + + for ( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ ) + { + int16_t upper = target_band_grouping[target_band_idx + 1]; + int16_t lower = target_band_grouping[target_band_idx]; + int16_t source_band_in_target_band_cnt = 0; + float norm_fac = 1.0f; + source_band_cnt_total = 0; + for ( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ ) + { + /* find lowest corresponding source band*/ + if ( source_band_grouping[source_band_idx] <= lower && source_band_grouping[source_band_idx + 1] >= lower ) + { + do + { + int16_t source_bands_in_target_band = min( source_band_grouping[source_band_idx + 1], upper ) - max( source_band_grouping[source_band_idx], lower ); + if ( source_bands_in_target_band ) + { + source_band_cnt_total += source_bands_in_target_band; + parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx; + parameter_band_mapping->source_band_factor[target_band_idx][source_band_in_target_band_cnt++] = (float) source_bands_in_target_band; + } + source_band_idx++; + } while ( source_band_grouping[source_band_idx] <= upper && source_band_idx < n_source_bands ); + break; + } + } + norm_fac = 1.0f / ( (float) source_band_cnt_total ); + for ( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ ) + { + + parameter_band_mapping->source_band_factor[target_band_idx][source_band_idx] *= norm_fac; + } + parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt; + } + + + return; +} + ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -429,9 +488,22 @@ ivas_error ivas_param_mc_dec_reconfig( AUDIO_CONFIG output_config; int32_t output_Fs, ivas_total_brate; ivas_error error; + int16_t nchan_transport_old; + int16_t num_param_bands_old; + const PARAM_MC_ILD_MAPPING *ild_mapping_conf_old; + const PARAM_MC_ICC_MAPPING *icc_mapping_conf_old; + const float *ild_factors_old; + PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping; + int16_t band_grouping_old[20 + 1]; error = IVAS_ERR_OK; hParamMC = st_ivas->hParamMC; + + + /* save important config information from the previous state */ + nchan_transport_old = st_ivas->nchan_transport; + num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands; + /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ @@ -490,16 +562,27 @@ ivas_error ivas_param_mc_dec_reconfig( hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; - ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); - /* init arrays for quantized parameters */ - hParamMC->icc_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); - hParamMC->icld_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); - set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + /* deallocate the full icc map, gets newly allocated in the metadata open function */ - param_mc_set_num_synth_bands( output_Fs, hParamMC ); + for ( k = 0; k < 2; k++ ) + { +#ifdef DEBUGGING + assert( hParamMC->hMetadataPMC->icc_map_full[k] != NULL ); +#endif + if ( hParamMC->hMetadataPMC->icc_map_full[k] != NULL ) + { + count_free( hParamMC->hMetadataPMC->icc_map_full[k] ); + hParamMC->hMetadataPMC->icc_map_full[k] = NULL; + } + } + ild_mapping_conf_old = hParamMC->hMetadataPMC->ild_mapping_conf; + icc_mapping_conf_old = hParamMC->hMetadataPMC->icc_mapping_conf; + ild_factors_old = hParamMC->hMetadataPMC->ild_factors; + mvs2s( hParamMC->band_grouping, band_grouping_old, hParamMC->hMetadataPMC->num_parameter_bands + 1 ); + + ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); /* Band Grouping */ if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) @@ -519,6 +602,66 @@ ivas_error ivas_param_mc_dec_reconfig( assert( 0 && "nbands must be 20, 14, or 10!" ); } + ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping ); + + if ( nchan_transport_old != nchan_transport || num_param_bands_old != hParamMC->hMetadataPMC->num_parameter_bands ) + { + float *ild_q_old = hParamMC->icld_q; + float *icc_q_old = hParamMC->icc_q; + + + /* init arrays for quantized parameters */ + hParamMC->icc_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); + hParamMC->icld_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); + set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + + /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ + if ( num_param_bands_old != hParamMC->hMetadataPMC->num_parameter_bands && nchan_transport_old == nchan_transport ) + { + int16_t new_param_band_idx, param_idx, source_param_idx; + int16_t num_param_lfe; + float *p_icc_new = hParamMC->icc_q; + float *p_ild_new = hParamMC->icld_q; + + /* ICC */ + num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; + for ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + for ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + { + *p_icc_new = 0.0f; + for ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + *p_icc_new += icc_q_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] * parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx]; + } + p_icc_new++; + } + } + + /* ILD */ + num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; + for ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + for ( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) + { + *p_ild_new = 0.0f; + for ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + *p_ild_new += powf( 10.0f, ild_q_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] / 10.0f ) * parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx]; + } + *p_ild_new = 10.0f * log10f( *p_ild_new ); + p_ild_new++; + } + } + } + count_free( ild_q_old ); + count_free( icc_q_old ); + } + + param_mc_set_num_synth_bands( output_Fs, hParamMC ); + + /* set max parameter band for abs cov */ k = 0; while ( hParamMC->band_grouping[k] <= PARAM_MC_MAX_BAND_ABS_COV_DEC ) @@ -533,41 +676,41 @@ ivas_error ivas_param_mc_dec_reconfig( /* prototype signal computation */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB || hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + if ( ( nchan_transport_old != nchan_transport ) && hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { + + if ( st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + } + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + count_free( hParamMC->ls_conv_dmx_matrix ); + hParamMC->ls_conv_dmx_matrix = (float *) count_malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); + for ( k = 0; k < nchan_out_transport; k++ ) { - hParamMC->ls_conv_dmx_matrix = (float *) count_malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); - for ( k = 0; k < nchan_out_transport; k++ ) - { - mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); - } - /* convert ParamMC parameter bands to SFB */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; - for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) - { - st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; - } - } - else - { - /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */ - ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); - } + mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); } - } + /* convert ParamMC parameter bands to SFB */ - hParamMC->proto_matrix_int = (float *) count_malloc( nchan_out_transport * nchan_transport * sizeof( float ) ); - mvr2r( ivas_param_mc_conf[config_index].dmx_fac, hParamMC->proto_matrix_int, nchan_transport * nchan_out_transport ); + st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; + for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + } + } + if ( nchan_transport_old != nchan_transport ) + { + count_free( hParamMC->proto_matrix_int ); + hParamMC->proto_matrix_int = (float *) count_malloc( nchan_out_transport * nchan_transport * sizeof( float ) ); + mvr2r( ivas_param_mc_conf[config_index].dmx_fac, hParamMC->proto_matrix_int, nchan_transport * nchan_out_transport ); + } if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { matrix_product( hParamMC->ls_conv_dmx_matrix, nchan_out_cov, nchan_out_transport, 0, @@ -598,17 +741,40 @@ ivas_error ivas_param_mc_dec_reconfig( mvr2r( ivas_param_mc_conf[config_index].dmx_fac, proto_matrix, nchan_out_transport * nchan_transport ); } - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - hParamMC->num_outputs_diff = 0; - hParamMC->diff_proto_info = NULL; - hParamMC->h_output_synthesis_params.use_onset_filters = 0; - hParamMC->max_band_decorr = 0; - hParamMC->h_freq_domain_decorr_ap_params = NULL; - hParamMC->h_freq_domain_decorr_ap_state = NULL; - } - else + if ( nchan_transport_old != nchan_transport && hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) { + int16_t i; + int16_t len; + /* close decorrelator */ + ivas_dirac_dec_decorr_close( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state ); + /* deallocate diffuse prototype info */ + if ( hParamMC->diff_proto_info ) + { + for ( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) + { + count_free( hParamMC->diff_proto_info->source_chan_idx[i] ); + hParamMC->diff_proto_info->source_chan_idx[i] = NULL; + + count_free( hParamMC->diff_proto_info->proto_fac[i] ); + hParamMC->diff_proto_info->proto_fac[i] = NULL; + } + + count_free( hParamMC->diff_proto_info->source_chan_idx ); + hParamMC->diff_proto_info->source_chan_idx = NULL; + + count_free( hParamMC->diff_proto_info->proto_fac ); + hParamMC->diff_proto_info->proto_fac = NULL; + + count_free( hParamMC->diff_proto_info->proto_index_diff ); + hParamMC->diff_proto_info->proto_index_diff = NULL; + + count_free( hParamMC->diff_proto_info->num_source_chan_diff ); + hParamMC->diff_proto_info->num_source_chan_diff = NULL; + + count_free( hParamMC->diff_proto_info ); + hParamMC->diff_proto_info = NULL; + } + hParamMC->num_outputs_diff = nchan_out_cov; hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) count_malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ); @@ -632,6 +798,16 @@ ivas_error ivas_param_mc_dec_reconfig( hParamMC->h_output_synthesis_params.use_onset_filters = 0; hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + /* init decorrelation */ + if ( hParamMC->max_band_decorr > 0 ) + { + + len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + + /* init onsetDetectionPower */ + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1, len ); + set_zero( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2, len ); + } } hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; max_param_band_residual = 0; @@ -646,43 +822,75 @@ ivas_error ivas_param_mc_dec_reconfig( } } - /* output synthesis */ - ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), - &( hParamMC->h_output_synthesis_cov_state ), - hParamMC->max_band_decorr, - PARAM_MC_MAX_NSLOTS, - hParamMC->hMetadataPMC->num_parameter_bands, - max_param_band_residual, - nchan_transport, - nchan_out_cov, - proto_matrix ); + if ( nchan_transport_old != nchan_transport || num_param_bands_old != hParamMC->hMetadataPMC->num_parameter_bands ) + { + DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state; + DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params; + float tmp_buf[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + set_zero( tmp_buf, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + /* output synthesis */ + ivas_dirac_dec_output_synthesis_cov_open( &( hParamMC->h_output_synthesis_params ), + &( hParamMC->h_output_synthesis_cov_state ), + hParamMC->max_band_decorr, + PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, + max_param_band_residual, + nchan_transport, + nchan_out_cov, + proto_matrix ); - /* Head rotation */ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation ) - { - hParamMC->hoa_encoder = (float *) count_malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ); - compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hParamMC->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); + ivas_dirac_dec_output_synthesis_cov_init( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); + + + /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ + if ( num_param_bands_old != hParamMC->hMetadataPMC->num_parameter_bands && nchan_transport_old == nchan_transport ) + { + int16_t new_param_band_idx, source_param_idx; + + + for ( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) + { + for ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + /* Cx */ + v_multc( cov_state_old.cx_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_transport_old * nchan_transport_old ); + v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.cx_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old[new_param_band_idx], nchan_transport_old * nchan_transport_old ); + /* Cy */ + v_multc( cov_state_old.cy_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_out_cov * nchan_out_cov ); + v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.cy_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old[new_param_band_idx], nchan_out_cov * nchan_out_cov ); + /* mixing matrix*/ + v_multc( cov_state_old.mixing_matrix_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_transport_old * nchan_out_cov ); + v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[new_param_band_idx], nchan_transport_old * nchan_out_cov ); + + } + } + for ( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) + { + for ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) + { + /* residual mixing matrix*/ + v_multc( cov_state_old.mixing_matrix_res_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_out_cov * nchan_out_cov ); + v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[new_param_band_idx], nchan_out_cov * nchan_out_cov ); + } + } + + } + ivas_dirac_dec_output_synthesis_cov_close( ¶ms_old, &cov_state_old ); } + /*-----------------------------------------------------------------* * memory allocation *-----------------------------------------------------------------*/ - if ( hParamMC->max_band_decorr > 0 ) + if ( hParamMC->max_band_decorr > 0 && nchan_transport_old != nchan_transport ) { + count_free( hParamMC->proto_frame_f ); hParamMC->proto_frame_f = (float *) count_malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( float ) ); - hParamMC->proto_frame_dec_f = (float *) count_malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( float ) ); - } - else - { - hParamMC->proto_frame_f = NULL; - hParamMC->proto_frame_dec_f = NULL; + set_zero( hParamMC->proto_frame_f, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); } - ivas_param_mc_dec_init( hParamMC, nchan_transport, nchan_out_cov ); - - return error; } #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 5095df6aed..908bc6f9bc 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -642,11 +642,13 @@ 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; ivas_error error; error = IVAS_ERR_OK; nchan_transport_old = st_ivas->nchan_transport; + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; @@ -780,6 +782,56 @@ ivas_error ivas_mc_dec_reconfig( /* re-configure hp20 memories */ ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); + + /* 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, st_ivas->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, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + /* Allocat the LFE handle that is coded seperately after the allocation of the core coders*/ if ( st_ivas->mc_mode == MC_MODE_MCT ) { diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f4b302eefd..f6687abe21 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -328,6 +328,15 @@ ivas_error ivas_corecoder_enc_reconfig( return error; } } +#ifdef MC_BITRATE_SWITCHING + else if (st_ivas->nCPE > 1 && st_ivas->hMCT == NULL && st_ivas->hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC) + { + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif /* metadata handling for CPEs */ if ( st_ivas->nCPE > 0 ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index e4db2ce2a1..0521a9b85d 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -570,6 +570,7 @@ ivas_error ivas_init_encoder( return error; } + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 46083faac7..8de7f442f5 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -275,6 +275,20 @@ ivas_error ivas_param_mc_reconfig( hParamMC->dmx_factors = ivas_param_mc_conf[config_index].dmx_fac; + /* deallocate the full icc map, gets newly allocated in the metadata open function */ + + for ( i = 0; i < 2; i++ ) + { +#ifdef DEBUGGING + assert( hParamMC->hMetadataPMC.icc_map_full[i] != NULL ); +#endif + if (hParamMC->hMetadataPMC.icc_map_full[i] != NULL) + { + count_free( hParamMC->hMetadataPMC.icc_map_full[i] ); + hParamMC->hMetadataPMC.icc_map_full[i] = NULL; + } + } + /* open/init parameter coding */ ivas_param_mc_metadata_open( mc_input_setup, hParamMC->lfe_index, ivas_total_brate, &hParamMC->hMetadataPMC ); diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 71d8f401fb..665b1d436a 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -347,6 +347,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 MC_BITRATE_SWITCHING + if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup ); + hMCT->num_lfe = FALSE; + } +#endif #ifdef HARMONIZE_SBA_NCHAN_TRANSPORT else if ( ivas_format == SBA_FORMAT && st_ivas->hDirAC ) // VE: this condition to be reviewed together with the following one { @@ -697,7 +704,7 @@ ivas_error ivas_mc_enc_reconfig( ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hParamMC = NULL; } - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL ) + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL) { ivas_mct_enc_close( st_ivas->hMCT ); st_ivas->hMCT = NULL; @@ -714,6 +721,48 @@ ivas_error ivas_mc_enc_reconfig( } /* re-configure core coder*/ + /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 + and might have IGF and TranDet static memory not allocated, set correct mct_chan_mode and init missing static mem + do it here since it is _very_ MC specific */ + if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > 2 ) + { + Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + if ( st_ivas->nchan_transport == 3 ) + { + st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + else + { + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + if ( st->hTranDet == NULL ) + { + + if ( ( st->hTranDet = (TRAN_DET_HANDLE) count_malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); + } + InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); + } + if ( st->hIGFEnc == NULL ) + { + if ( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) count_malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); + } + } + st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode, st->mct_chan_mode ); + } + else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) + { +#ifdef DEBUGGING + assert( st_ivas->hCPE[1] != NULL ); +#endif + Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st->mct_chan_mode = MCT_CHAN_MODE_LFE; + } + + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; -- GitLab From 5edfd1b7acfa938fea57218d066be704a16b503a Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Fri, 21 Oct 2022 13:01:50 +0200 Subject: [PATCH 04/42] * fixed most ParamMC<->MCT bit rate switch transitions --- lib_com/bitstream.c | 2 ++ lib_com/ivas_stereo_mdct_bands_com.c | 3 ++ lib_dec/init_dec.c | 5 ++++ lib_dec/ivas_dec.c | 4 +++ lib_dec/ivas_init_dec.c | 6 +++- lib_dec/ivas_mc_param_dec.c | 31 ++++++++++++-------- lib_dec/ivas_mct_dec.c | 41 ++++++++++++++++++++++++++- lib_enc/ivas_corecoder_enc_reconfig.c | 9 ------ lib_enc/ivas_cpe_enc.c | 10 ++++++- lib_enc/ivas_init_enc.c | 21 ++++++++++++++ lib_enc/ivas_mct_enc.c | 40 ++++++++++++++++++++------ 11 files changed, 140 insertions(+), 32 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 9ee771fb6b..0d72149ab5 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -879,10 +879,12 @@ static ivas_error write_indices_element( for ( n = 0; n < n_channels; n++ ) { +#ifndef MC_BITRATE_SWITCHING if ( ( st_ivas->hEncoderConfig->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCT ) && ( element_id * CPE_CHANNELS + n == LFE_CHANNEL ) ) { continue; } +#endif reset_indices_enc( sts[n]->hBstr, MAX_NUM_INDICES ); } } diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index 16149941e4..445eec09f9 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -225,6 +225,9 @@ void stereo_mdct_init_igf_start_band( { int16_t i, bitRateIndex, igfStartLine; const int16_t *swb_offset; +#ifdef DEBUGGING + stbParams->sfbIgfStart = 0; +#endif bitRateIndex = IGF_MapBitRateToIndex( element_brate, bwidth, IVAS_CPE_MDCT, 0 ); swb_offset = &swb_offset_LB_new[bitRateIndex][1]; diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 2e31017eaa..92a3ae55f1 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -616,17 +616,22 @@ ivas_error init_decoder( } /* TCX config. data structure */ +#ifndef MC_BITRATE_SWITCHING + /* for correct bit rate switching in MC we at least need the TcxCfg */ if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) { +#endif if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } +#ifndef MC_BITRATE_SWITCHING } else { st->hTcxCfg = NULL; } +#endif /* Tonal MDCT concealment data structure */ if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 7d54047014..1423cbb1f5 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -358,7 +358,11 @@ ivas_error ivas_dec( /* LFE channel decoder */ if ( st_ivas->mc_mode == MC_MODE_MCT ) { +#ifndef MC_BITRATE_SWITCHING + /* bay: this really killed the MC bitrate switching and took me one day to find it, at least a comment here why the messing with this pointers + happens would have been nice */ st_ivas->hCPE[1]->hCoreCoder[1]->hTcxCfg = st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg; +#endif ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, output_lfe_ch ); } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5cc41a429a..e183eda8e0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1439,7 +1439,11 @@ void destroy_core_dec( hCoreCoder->hTcxDec = NULL; } - if ( hCoreCoder->hTcxCfg != NULL && hCoreCoder->mct_chan_mode != MCT_CHAN_MODE_LFE ) + if ( hCoreCoder->hTcxCfg != NULL +#ifndef MC_BITRATE_SWITCHING + && hCoreCoder->mct_chan_mode != MCT_CHAN_MODE_LFE +#endif + ) { count_free( hCoreCoder->hTcxCfg ); hCoreCoder->hTcxCfg = NULL; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4e4bbac44d..6fbc52ff7e 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -56,6 +56,20 @@ #define PARAM_MC_LOCAL_SZ_LFE_MAP 5 +#ifdef MC_BITRATE_SWITCHING +/*-----------------------------------------------------------------------* + * Local typedefs + *-----------------------------------------------------------------------*/ + +typedef struct parameter_band_mapping_struct +{ + int16_t n_source_bands[20]; + int16_t source_band_idx[20][4]; + float source_band_factor[20][4]; + +} PARAM_MC_PARAMETER_BAND_MAPPING; +#endif + /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ @@ -87,6 +101,10 @@ static void param_mc_get_diff_proto_info( const float *proto_mtx, const uint16_t static void ivas_param_mc_mc2sba_cldfb( IVAS_OUTPUT_SETUP hTransSetup, float *hoa_encoder, const int16_t slot_idx, float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], const int16_t nBands, const float gain_lfe ); +#ifdef MC_BITRATE_SWITCHING +static void ivas_param_mc_get_param_band_mapping( const int16_t n_target_bands, const int16_t *target_band_grouping, const int16_t n_source_bands, const int16_t *source_band_grouping, PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping ); +#endif + void ivas_param_mc_bs_decode_parameter_values( uint16_t bit_buffer[], int16_t *bit_pos, const int16_t max_bits, int16_t *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const int16_t map_size_wo_lfe, const int16_t map_size, const int16_t num_lfe_bands, const int16_t band_step, const int16_t num_param_bands, float *value_buffer ); /*------------------------------------------------------------------------- @@ -411,15 +429,6 @@ ivas_error ivas_param_mc_dec_open( } #ifdef MC_BITRATE_SWITCHING - -typedef struct parameter_band_mapping_struct -{ - int16_t n_source_bands[20]; - int16_t source_band_idx[20][4]; - float source_band_factor[20][4]; - -} PARAM_MC_PARAMETER_BAND_MAPPING; - static void ivas_param_mc_get_param_band_mapping( const int16_t n_target_bands, const int16_t *target_band_grouping, @@ -862,19 +871,17 @@ ivas_error ivas_param_mc_dec_reconfig( /* mixing matrix*/ v_multc( cov_state_old.mixing_matrix_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_transport_old * nchan_out_cov ); v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[new_param_band_idx], nchan_transport_old * nchan_out_cov ); - } } for ( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) { for ( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { - /* residual mixing matrix*/ + /* residual mixing matrix*/ v_multc( cov_state_old.mixing_matrix_res_old[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor[new_param_band_idx][source_param_idx], tmp_buf, nchan_out_cov * nchan_out_cov ); v_add( tmp_buf, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[new_param_band_idx], nchan_out_cov * nchan_out_cov ); } } - } ivas_dirac_dec_output_synthesis_cov_close( ¶ms_old, &cov_state_old ); } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 908bc6f9bc..73f262f798 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -653,6 +653,8 @@ ivas_error ivas_mc_dec_reconfig( nCPE_old = st_ivas->nCPE; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + /* renderer might have changed, reselect */ + ivas_renderer_select( st_ivas ); if ( st_ivas->mc_mode == MC_MODE_MCT ) { st_ivas->nSCE = 0; @@ -712,7 +714,7 @@ ivas_error ivas_mc_dec_reconfig( if ( last_mc_mode == MC_MODE_MCT ) { - if ( st_ivas->hMCT != NULL ) + if ( st_ivas->hMCT != NULL && st_ivas->nchan_transport <= CPE_CHANNELS ) { ivas_mct_dec_close( &st_ivas->hMCT ); st_ivas->hMCT = NULL; @@ -773,7 +775,44 @@ ivas_error ivas_mc_dec_reconfig( st_ivas->element_mode_init = IVAS_CPE_MDCT; } + /* re-configure core coder*/ + /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 + and might have IGF static memory not allocated and the bit stream index list not set, + set correct mct_chan_mode and init missing static mem + do it here since it is _very_ MC specific */ + if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) + { + Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + if ( st_ivas->nchan_transport == 3 ) + { + st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + else + { + st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + + if ( st->hIGFDec == NULL ) + { + if ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) count_malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for IGF\n" ) ); + } + + st->igf = 0; + init_igf_dec( st->hIGFDec ); + } + } + else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) + { +#ifdef DEBUGGING + assert( st_ivas->hCPE[1] != NULL ); +#endif + Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st->mct_chan_mode = MCT_CHAN_MODE_LFE; + } + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f6687abe21..f4b302eefd 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -328,15 +328,6 @@ ivas_error ivas_corecoder_enc_reconfig( return error; } } -#ifdef MC_BITRATE_SWITCHING - else if (st_ivas->nCPE > 1 && st_ivas->hMCT == NULL && st_ivas->hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC) - { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif /* metadata handling for CPEs */ if ( st_ivas->nCPE > 0 ) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 5e5d4c9f10..15e3dcd6ba 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -816,7 +816,15 @@ ivas_error create_cpe_enc( * Metadata: allocate and initialize *-----------------------------------------------------------------*/ + +#ifdef MC_BITRATE_SWITCHING + /* we need the meta data handle also if we init as MC_FORMAT/MCT since it might be needed + at a bit rate switch to ParamMC or McMASA and the metadata index list is only really reachable + in the ivas_init_encoder() function and has to be connected to the MD handle there */ + if ( cpe_id == ( st_ivas->nCPE - 1 )) +#else if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) && ( cpe_id == ( st_ivas->nCPE - 1 ) ) ) +#endif { if ( ( hCPE->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) { @@ -880,7 +888,7 @@ ivas_error create_cpe_enc( #ifdef DEBUGGING if ( hEncoderConfig->Opt_DTX_ON && ( hCPE->element_mode == IVAS_CPE_TD || hEncoderConfig->stereo_mode_cmdl == 1 ) && !( ivas_format == MASA_FORMAT && element_mode_init == IVAS_CPE_MDCT ) ) #else - if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) +if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) #endif { for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 0521a9b85d..4768eb3b24 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -520,10 +520,14 @@ ivas_error ivas_init_encoder( st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels( hEncoderConfig->mc_input_setup ); +#ifdef MC_BITRATE_SWITCHING + st_ivas->hLFE = NULL; +#else if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->mc_mode == MC_MODE_MCT ) { @@ -539,14 +543,24 @@ ivas_error ivas_init_encoder( for ( n = 0; n < CPE_CHANNELS; n++ ) { + /* we need the correct bitstream also for the LFE channel since it might become a proper coded channel when + switching to ParamMC and ind_list is only visible here, can't be done later */ +#ifndef MC_BITRATE_SWITCHING if ( cpe_id * CPE_CHANNELS + n == LFE_CHANNEL ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = 0; continue; } +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); } + /* Metadata only initialized for the last CPE index*/ + if ( cpe_id == st_ivas->nCPE - 1 ) + { + st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); + } } if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) @@ -554,6 +568,13 @@ ivas_error ivas_init_encoder( return error; } +#ifdef MC_BITRATE_SWITCHING + if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 665b1d436a..9ffa451ab8 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -127,7 +127,11 @@ ivas_error ivas_mct_enc( /* joint MCT encoding */ ivas_mct_core_enc( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE + hMCT->num_lfe, ivas_total_brate, switch_bw, +#ifdef MC_BITRATE_SWITCHING + ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) ? (int16_t) st_ivas->hLFE->lfe_bits : 0 +#else ivas_format == MC_FORMAT ? (int16_t) st_ivas->hLFE->lfe_bits : 0 +#endif #ifdef FIX_I1_113 , st_ivas->hEncoderConfig->sba_order @@ -348,7 +352,7 @@ ivas_error mct_enc_reconfigure( hMCT->num_lfe = TRUE; } #ifdef MC_BITRATE_SWITCHING - if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) + else if ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMMC ) { hMCT->nchan_out_woLFE = ivas_param_mc_getNumTransportChannels( ivas_total_brate, st_ivas->hEncoderConfig->mc_input_setup ); hMCT->num_lfe = FALSE; @@ -611,7 +615,11 @@ ivas_error ivas_mc_enc_reconfig( if ( last_mc_mode != MC_MODE_MCT ) { - + /* create LFE handle */ + if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, st_ivas->hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } /*De-allocate handles for other MC modes*/ if ( st_ivas->hParamMC != NULL ) { @@ -671,11 +679,17 @@ ivas_error ivas_mc_enc_reconfig( } /* De-allocate MCT handle if last mode was MCT */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL ) + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL && st_ivas->nchan_transport <= CPE_CHANNELS ) { ivas_mct_enc_close( st_ivas->hMCT ); st_ivas->hMCT = NULL; } + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hLFE != NULL ) + { + /* LFE handle */ + ivas_lfe_enc_close( st_ivas->hLFE ); + st_ivas->hLFE = NULL; + } } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { @@ -704,10 +718,19 @@ ivas_error ivas_mc_enc_reconfig( ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hParamMC = NULL; } - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL) + if ( last_mc_mode == MC_MODE_MCT ) { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; + /* LFE handle */ + if ( st_ivas->hLFE != NULL ) + { + ivas_lfe_enc_close( st_ivas->hLFE ); + st_ivas->hLFE = NULL; + } + if ( st_ivas->hMCT != NULL ) + { + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } } } @@ -722,9 +745,10 @@ ivas_error ivas_mc_enc_reconfig( /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 - and might have IGF and TranDet static memory not allocated, set correct mct_chan_mode and init missing static mem + and might have IGF and TranDet static memory not allocated and the bit stream index list not set, + set correct mct_chan_mode and init missing static mem do it here since it is _very_ MC specific */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > 2 ) + if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; if ( st_ivas->nchan_transport == 3 ) -- GitLab From 9a68006f510561c6c61d85fdd30e3dd61ad3f8a0 Mon Sep 17 00:00:00 2001 From: rhb Date: Wed, 2 Nov 2022 16:57:15 +0100 Subject: [PATCH 05/42] fix crashes in MCT bitrate switching under FIX_MCT_BS_CRASH --- lib_com/options.h | 1 + lib_debug/mem_count.c | 4 ++++ lib_dec/ivas_mct_dec.c | 3 +++ lib_dec/ivas_mdct_core_dec.c | 4 ++++ lib_enc/ivas_mct_enc.c | 3 +++ lib_enc/ivas_mdct_core_enc.c | 8 ++++++++ 6 files changed, 23 insertions(+) mode change 100644 => 100755 lib_debug/mem_count.c mode change 100644 => 100755 lib_dec/ivas_mct_dec.c mode change 100644 => 100755 lib_dec/ivas_mdct_core_dec.c mode change 100644 => 100755 lib_enc/ivas_mct_enc.c mode change 100644 => 100755 lib_enc/ivas_mdct_core_enc.c diff --git a/lib_com/options.h b/lib_com/options.h index 28fb60c2e9..c4746956b8 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,6 +159,7 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ +#define FIX_MCT_BS_CRASH /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c old mode 100644 new mode 100755 index b12639ae3f..d83561f782 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,7 +93,11 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ +#ifdef FIX_MCT_BS_CRASH +#define MAX_INFO_RECORDS 5000 +#else #define MAX_INFO_RECORDS 3000 +#endif /* This is the length after which the function name will be truncated when the summary is printed. */ diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c old mode 100644 new mode 100755 index 73f262f798..62089463ca --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -458,6 +458,9 @@ ivas_error mct_dec_reconfigure( * run into a number of problems */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef FIX_MCT_BS_CRASH + st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; +#endif for ( n = 0; n < CPE_CHANNELS; n++ ) { st = st_ivas->hCPE[cpe_id]->hCoreCoder[n]; diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c old mode 100644 new mode 100755 index d05024c565..cfd81f7b4c --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -414,7 +414,11 @@ void ivas_mdct_dec_side_bits_frame_channel( param_lpc[0][0] = get_next_indice( st0, 1 ) << 1; /* read low br mode flag (if it is possible to be non-zero) */ +#ifdef FIX_MCT_BS_CRASH + if ( sts[0]->element_brate == IVAS_48k && !((sts[0]->core == TCX_20 && sts[1]->core == TCX_20) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#else if ( sts[0]->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) +#endif { sns_low_br_mode = get_next_indice( st0, 1 ); } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c old mode 100644 new mode 100755 index 9ffa451ab8..896b9ec61e --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -392,6 +392,9 @@ ivas_error mct_enc_reconfigure( /* indicate LFE for appropriate core-coder channel */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef FIX_MCT_BS_CRASH + st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; +#endif for ( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c old mode 100644 new mode 100755 index 0d2f5817d6..023c3e211b --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -900,7 +900,11 @@ void ivas_mdct_core_whitening_enc( } /* set low br mode, if possible. Can later be discarded, depending on the stereo mode used for SNS parameter decoding */ +#ifdef FIX_MCT_BS_CRASH + if ( hCPE->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#else if ( hCPE->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) +#endif { sns_low_br_mode = !sts[0]->sp_aud_decision0; } @@ -1120,7 +1124,11 @@ void ivas_mdct_core_whitening_enc( { push_next_indice( hBstr, param_lpc[0][0] >> 1, 1 ); +#ifdef FIX_MCT_BS_CRASH + if ( st->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#else if ( st->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) +#endif { /* write classifier decision to signal low br mode for SNS encoding, for all other configs, low_br mode is not possible */ push_next_indice( hBstr, sns_low_br_mode, 1 ); -- GitLab From 16650c8a8724ab041d3a0db2209704385cb3cd65 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 10 Nov 2022 11:58:06 +0100 Subject: [PATCH 06/42] [fix] fixed binaural rendering for MC bitrate switching --- lib_dec/ivas_mct_dec.c | 106 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 62089463ca..51ae63a4f8 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -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 -- GitLab From 7321d00c98e22701ee68bf2102b3e56fbe669bc2 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 10 Nov 2022 12:58:09 +0100 Subject: [PATCH 07/42] [fix] fix MONO and STEREO output for MC bitrate switching, only for switching ParamMC <-> MCT --- lib_dec/ivas_mc_param_dec.c | 7 ++----- lib_dec/ivas_mct_dec.c | 32 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 6fbc52ff7e..d861e31f35 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -526,9 +526,6 @@ ivas_error ivas_param_mc_dec_reconfig( nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hParamMC->hoa_encoder = NULL; - - hParamMC->ls_conv_dmx_matrix = NULL; - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; @@ -619,13 +616,13 @@ ivas_error ivas_param_mc_dec_reconfig( float *icc_q_old = hParamMC->icc_q; - /* init arrays for quantized parameters */ + /* init arrays for the quantized parameters */ hParamMC->icc_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( float ) ); hParamMC->icld_q = (float *) count_malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( float ) ); set_f( hParamMC->icld_q, PARAM_MC_DEFAULT_MIN_ILD, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); set_f( hParamMC->icc_q, 0.0f, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); - /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ + /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */ if ( num_param_bands_old != hParamMC->hMetadataPMC->num_parameter_bands && nchan_transport_old == nchan_transport ) { int16_t new_param_band_idx, param_idx, source_param_idx; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 51ae63a4f8..88f0a0bf26 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -650,10 +650,10 @@ ivas_error ivas_mc_dec_reconfig( 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 + + /* 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; @@ -682,6 +682,8 @@ ivas_error ivas_mc_dec_reconfig( { ivas_param_mc_dec_close( &st_ivas->hParamMC ); st_ivas->hParamMC = NULL; + /* remove ls conversion if it was allocated by ParamMC */ + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); } /* De-allocate McMasa-related handles */ @@ -696,12 +698,26 @@ ivas_error ivas_mc_dec_reconfig( ivas_qmetadata_close( &st_ivas->hQMetaData ); st_ivas->hQMetaData = NULL; } + + /* init LS conversion if the renderer type asks for it */ + if ( st_ivas->renderer_type == RENDERER_MC && st_ivas->hLsSetUpConversion == NULL) + { + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } } } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) { if ( last_mc_mode != MC_MODE_PARAMMC ) { + /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */ + if ( renderer_type_old == RENDERER_MC && st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + } if ( ( error = ivas_param_mc_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -757,6 +773,12 @@ ivas_error ivas_mc_dec_reconfig( } } + /* ls conversion */ + if ( st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + } + if ( st_ivas->hParamMC != NULL ) { ivas_param_mc_dec_close( &st_ivas->hParamMC ); @@ -885,7 +907,7 @@ ivas_error ivas_mc_dec_reconfig( } /* Allocat the LFE handle that is coded seperately after the allocation of the core coders*/ - if ( st_ivas->mc_mode == MC_MODE_MCT ) + if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL ) { if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) @@ -958,7 +980,7 @@ ivas_error ivas_mc_dec_reconfig( } } } - else if ( st_ivas->hCrend == NULL && (st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM )) + 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 ) { -- GitLab From e9467735a939668230c0afdc2bbb2978bded5cde Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 10 Nov 2022 21:58:30 +0100 Subject: [PATCH 08/42] merge define FIX_MCT_BS_CRASH to MC_BITRATE_SWITCHING --- lib_com/options.h | 1 - lib_debug/mem_count.c | 2 +- lib_dec/ivas_mct_dec.c | 4 ++-- lib_dec/ivas_mdct_core_dec.c | 4 ++-- lib_enc/ivas_mct_enc.c | 2 +- lib_enc/ivas_mdct_core_enc.c | 8 ++++---- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c4746956b8..28fb60c2e9 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,7 +159,6 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ -#define FIX_MCT_BS_CRASH /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index d83561f782..51202d5faf 100755 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,7 +93,7 @@ typedef INT64 int64_t; /* This is the maximum number of allocations for which to keep information. It can be increased if required. */ -#ifdef FIX_MCT_BS_CRASH +#ifdef MC_BITRATE_SWITCHING #define MAX_INFO_RECORDS 5000 #else #define MAX_INFO_RECORDS 3000 diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 88f0a0bf26..5be5813b04 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -458,7 +458,7 @@ ivas_error mct_dec_reconfigure( * run into a number of problems */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef FIX_MCT_BS_CRASH +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; #endif for ( n = 0; n < CPE_CHANNELS; n++ ) @@ -700,7 +700,7 @@ ivas_error ivas_mc_dec_reconfig( } /* init LS conversion if the renderer type asks for it */ - if ( st_ivas->renderer_type == RENDERER_MC && st_ivas->hLsSetUpConversion == NULL) + if ( st_ivas->renderer_type == RENDERER_MC && st_ivas->hLsSetUpConversion == NULL ) { if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index cfd81f7b4c..e2314b8cb6 100755 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -414,8 +414,8 @@ void ivas_mdct_dec_side_bits_frame_channel( param_lpc[0][0] = get_next_indice( st0, 1 ) << 1; /* read low br mode flag (if it is possible to be non-zero) */ -#ifdef FIX_MCT_BS_CRASH - if ( sts[0]->element_brate == IVAS_48k && !((sts[0]->core == TCX_20 && sts[1]->core == TCX_20) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#ifdef MC_BITRATE_SWITCHING + if ( sts[0]->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE ) ) #else if ( sts[0]->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) #endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 896b9ec61e..f4f8e6b8ee 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -392,7 +392,7 @@ ivas_error mct_enc_reconfigure( /* indicate LFE for appropriate core-coder channel */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef FIX_MCT_BS_CRASH +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = cp_bitrate; #endif for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 023c3e211b..080637fa9b 100755 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -900,8 +900,8 @@ void ivas_mdct_core_whitening_enc( } /* set low br mode, if possible. Can later be discarded, depending on the stereo mode used for SNS parameter decoding */ -#ifdef FIX_MCT_BS_CRASH - if ( hCPE->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#ifdef MC_BITRATE_SWITCHING + if ( hCPE->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE ) ) #else if ( hCPE->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) #endif @@ -1124,8 +1124,8 @@ void ivas_mdct_core_whitening_enc( { push_next_indice( hBstr, param_lpc[0][0] >> 1, 1 ); -#ifdef FIX_MCT_BS_CRASH - if ( st->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE) ) +#ifdef MC_BITRATE_SWITCHING + if ( st->element_brate == IVAS_48k && !( ( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) || sts[1]->mct_chan_mode == MCT_CHAN_MODE_LFE ) ) #else if ( st->element_brate == IVAS_48k && !( sts[0]->core == TCX_20 && sts[1]->core == TCX_20 ) ) #endif -- GitLab From 0bc24deadca2bc4e090f4be347067c2cca5d3f2f Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 10 Nov 2022 22:06:03 +0100 Subject: [PATCH 09/42] fix compiler errors --- lib_com/ivas_mc_param_com.c | 14 +++++++------- lib_dec/ivas_mc_param_dec.c | 8 -------- lib_dec/ivas_mct_dec.c | 6 +++--- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index bcdfc18c5f..29e7decb10 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -330,15 +330,15 @@ void ivas_param_mc_default_icc_map( } #ifdef MC_BITRATE_SWITCHING -int16_t ivas_param_mc_get_num_param_bands( - const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ - ) +static int16_t ivas_param_mc_get_num_param_bands( + const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ +) { int16_t num_parameter_bands; num_parameter_bands = 0; - /* parameter bands */ + /* parameter bands */ switch ( mc_ls_setup ) { case MC_LS_SETUP_5_1: @@ -513,9 +513,9 @@ static void ivas_param_mc_set_coding_scheme( assert( 0 && "PARAM_MC: channel configuration not supported!" ); } - #ifdef MC_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate ); - #else +#else /* parameter bands */ switch ( mc_ls_setup ) { diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index d861e31f35..f5321e5820 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -494,14 +494,10 @@ ivas_error ivas_param_mc_dec_reconfig( uint16_t config_index; MC_LS_SETUP mc_ls_setup; float frequency_axis[CLDFB_NO_CHANNELS_MAX]; - AUDIO_CONFIG output_config; int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_old; int16_t num_param_bands_old; - const PARAM_MC_ILD_MAPPING *ild_mapping_conf_old; - const PARAM_MC_ICC_MAPPING *icc_mapping_conf_old; - const float *ild_factors_old; PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping; int16_t band_grouping_old[20 + 1]; @@ -518,7 +514,6 @@ ivas_error ivas_param_mc_dec_reconfig( *-----------------------------------------------------------------*/ output_Fs = st_ivas->hDecoderConfig->output_Fs; - output_config = st_ivas->hDecoderConfig->output_config; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; hTransportSetup = st_ivas->hTransSetup; @@ -583,9 +578,6 @@ ivas_error ivas_param_mc_dec_reconfig( } } - ild_mapping_conf_old = hParamMC->hMetadataPMC->ild_mapping_conf; - icc_mapping_conf_old = hParamMC->hMetadataPMC->icc_mapping_conf; - ild_factors_old = hParamMC->hMetadataPMC->ild_factors; mvs2s( hParamMC->band_grouping, band_grouping_old, hParamMC->hMetadataPMC->num_parameter_bands + 1 ); ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 5be5813b04..bb46fbdea0 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -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,7 +646,7 @@ 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; + RENDERER_TYPE renderer_type_old; ivas_error error; MC_MODE mc_mode; error = IVAS_ERR_OK; @@ -951,7 +951,7 @@ ivas_error ivas_mc_dec_reconfig( 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 ( 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 ) { -- GitLab From 96187f63a4a7b2ddfafc7cc5f91416e1fefd7fd2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 10 Nov 2022 22:50:54 +0100 Subject: [PATCH 10/42] two // !!! comments --- lib_dec/init_dec.c | 2 +- lib_enc/ivas_init_enc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 92a3ae55f1..15f80f48e6 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -616,7 +616,7 @@ ivas_error init_decoder( } /* TCX config. data structure */ -#ifndef MC_BITRATE_SWITCHING +#ifndef MC_BITRATE_SWITCHING // !!! this does not seem to be correct for DFT/TD stereo; also why the MCT_CHAN_MODE_LFE channel is now included? /* for correct bit rate switching in MC we at least need the TcxCfg */ if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4768eb3b24..48848f9956 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -521,7 +521,7 @@ ivas_error ivas_init_encoder( hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels( hEncoderConfig->mc_input_setup ); #ifdef MC_BITRATE_SWITCHING - st_ivas->hLFE = NULL; + st_ivas->hLFE = NULL; // !!! already done in ivas_initialize_handles_enc() #else if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) { -- GitLab From 8835866f8b739b7dffa7811a20139ca16ac940a1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 10 Nov 2022 23:08:51 +0100 Subject: [PATCH 11/42] adding comments --- lib_com/ivas_mc_param_com.c | 7 +++++++ lib_com/ivas_prot.h | 22 ++++++---------------- lib_dec/ivas_mc_param_dec.c | 14 ++++++++++++++ lib_dec/ivas_mct_dec.c | 26 ++++++++++++++++++++++++-- lib_enc/ivas_cpe_enc.c | 6 +++--- lib_enc/ivas_mc_param_enc.c | 10 ++++++---- lib_enc/ivas_mct_enc.c | 19 +++++++++++++++---- 7 files changed, 75 insertions(+), 29 deletions(-) diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 29e7decb10..167eabb08b 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -329,7 +329,14 @@ void ivas_param_mc_default_icc_map( return; } + #ifdef MC_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_param_mc_get_num_param_bands() + * + * + *------------------------------------------------------------------------*/ + static int16_t ivas_param_mc_get_num_param_bands( const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 27b9d21c0d..18832dfef8 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -626,23 +626,10 @@ ivas_error ivas_mc_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef MC_BITRATE_SWITCHING -ivas_error ivas_mc_enc_reconfig( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i: last frame mc mode */ -); -#endif - ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx /* i : LS config. index */ ); -#ifdef MC_BITRATE_SWITCHING -ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i : last frame MC mode */ -); -#endif /*! r: MC format mode (MCT, McMASA, ParamMC) */ MC_MODE ivas_mc_mode_select( @@ -3506,11 +3493,13 @@ int16_t ivas_param_mc_getNumTransportChannels( ivas_error ivas_param_mc_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + #ifdef MC_BITRATE_SWITCHING -ivas_error ivas_param_mc_reconfig( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +ivas_error ivas_param_mc_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); #endif + void ivas_param_mc_enc_close( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -3526,9 +3515,10 @@ void ivas_param_mc_enc( ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); + #ifdef MC_BITRATE_SWITCHING ivas_error ivas_param_mc_dec_reconfig( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index f5321e5820..f2fbf03092 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -428,7 +428,14 @@ ivas_error ivas_param_mc_dec_open( return error; } + #ifdef MC_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_param_mc_get_param_band_mapping() + * + * + *-------------------------------------------------------------------------*/ + static void ivas_param_mc_get_param_band_mapping( const int16_t n_target_bands, const int16_t *target_band_grouping, @@ -479,6 +486,13 @@ static void ivas_param_mc_get_param_band_mapping( return; } + +/*------------------------------------------------------------------------- + * ivas_param_mc_dec_reconfig() + * + * Reconfiguration of ParamMC decoder + *-------------------------------------------------------------------------*/ + ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index bb46fbdea0..e00a54d496 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -48,6 +48,16 @@ #include "deb_out.h" #endif + +#ifdef MC_BITRATE_SWITCHING +/*-----------------------------------------------------------------------* + * Local function prototypes + *-----------------------------------------------------------------------*/ + +static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, const int16_t last_mc_mode ); +#endif + + /*--------------------------------------------------------------------------* * ivas_mct_dec() * @@ -638,8 +648,16 @@ ivas_error ivas_mc_dec_config( return error; } + + #ifdef MC_BITRATE_SWITCHING -ivas_error ivas_mc_dec_reconfig( +/*------------------------------------------------------------------------- + * ivas_mc_dec_reconfig() + * + * reconfigure the MC format decoder + *-------------------------------------------------------------------------*/ + +static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t last_mc_mode /* i : last frame MC mode */ ) @@ -924,7 +942,10 @@ ivas_error ivas_mc_dec_reconfig( } - /* renderers */ + /*-----------------------------------------------------------------* + * Renderers + *-----------------------------------------------------------------*/ + if ( renderer_type_old != st_ivas->renderer_type ) { AUDIO_CONFIG output_config; @@ -1009,6 +1030,7 @@ ivas_error ivas_mc_dec_reconfig( } #endif } + return error; } #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 15e3dcd6ba..0c1ac5055e 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -817,11 +817,11 @@ ivas_error create_cpe_enc( *-----------------------------------------------------------------*/ -#ifdef MC_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING // !!! what is this for? /* we need the meta data handle also if we init as MC_FORMAT/MCT since it might be needed at a bit rate switch to ParamMC or McMASA and the metadata index list is only really reachable in the ivas_init_encoder() function and has to be connected to the MD handle there */ - if ( cpe_id == ( st_ivas->nCPE - 1 )) + if ( cpe_id == ( st_ivas->nCPE - 1 ) ) #else if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) && ( cpe_id == ( st_ivas->nCPE - 1 ) ) ) #endif @@ -888,7 +888,7 @@ ivas_error create_cpe_enc( #ifdef DEBUGGING if ( hEncoderConfig->Opt_DTX_ON && ( hCPE->element_mode == IVAS_CPE_TD || hEncoderConfig->stereo_mode_cmdl == 1 ) && !( ivas_format == MASA_FORMAT && element_mode_init == IVAS_CPE_MDCT ) ) #else -if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) + if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) #endif { for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 8de7f442f5..1fc03c936e 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -75,6 +75,7 @@ static void ivas_param_mc_encode_parameter( int16_t *idx_in, HANDLE_IVAS_PARAM_M static void ivas_param_mc_range_encoder( const int16_t *seq_in, const int16_t num_symbols, const uint16_t *cum_freq, const uint16_t *sym_freq, const uint16_t tot_shift, const int16_t max_nb_bits, uint16_t *bit_buffer, int16_t *bit_pos ); + /*------------------------------------------------------------------------- * ivas_param_mc_enc_open() * @@ -218,14 +219,15 @@ ivas_error ivas_param_mc_enc_open( return error; } + #ifdef MC_BITRATE_SWITCHING /*------------------------------------------------------------------------- - * ivas_param_mc_enc_open() + * ivas_param_mc_enc_reconfig() * - * Initialize Parametric MC encoder handle + * Reconfigure Parametric MC encoder *------------------------------------------------------------------------*/ -ivas_error ivas_param_mc_reconfig( +ivas_error ivas_param_mc_enc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { @@ -282,7 +284,7 @@ ivas_error ivas_param_mc_reconfig( #ifdef DEBUGGING assert( hParamMC->hMetadataPMC.icc_map_full[i] != NULL ); #endif - if (hParamMC->hMetadataPMC.icc_map_full[i] != NULL) + if ( hParamMC->hMetadataPMC.icc_map_full[i] != NULL ) { count_free( hParamMC->hMetadataPMC.icc_map_full[i] ); hParamMC->hMetadataPMC.icc_map_full[i] = NULL; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f4f8e6b8ee..ad67efb9a7 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -44,6 +44,15 @@ #include "wmops.h" +#ifdef MC_BITRATE_SWITCHING +/*-----------------------------------------------------------------------* + * Local function prototypes + *-----------------------------------------------------------------------*/ + +static ivas_error ivas_mc_enc_reconfig( Encoder_Struct *st_ivas, const int16_t last_mc_mode ); +#endif + + /*-------------------------------------------------------------------* * ivas_mct_enc() * @@ -589,13 +598,15 @@ ivas_error ivas_mc_enc_config( return error; } + #ifdef MC_BITRATE_SWITCHING /*------------------------------------------------------------------------- * ivas_mc_enc_reconfig() - * - reconfigure the MC format encoder + * + * Reconfigure the MC format encoder *-------------------------------------------------------------------------*/ -ivas_error ivas_mc_enc_reconfig( +static ivas_error ivas_mc_enc_reconfig( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t last_mc_mode /* i: last frame mc mode */ ) @@ -660,7 +671,7 @@ ivas_error ivas_mc_enc_reconfig( } else { - ivas_param_mc_reconfig( st_ivas ); + ivas_param_mc_enc_reconfig( st_ivas ); } /* De-allocate McMasa-related handles */ @@ -797,4 +808,4 @@ ivas_error ivas_mc_enc_reconfig( return error; } -#endif \ No newline at end of file +#endif -- GitLab From 9efdc66356ae4d3f8422ba5078bfc135ef85a01a Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 11 Nov 2022 10:35:32 +0100 Subject: [PATCH 12/42] comments, formatting --- lib_dec/ivas_mct_dec.c | 31 ++++++++++++++++++++----------- lib_enc/ivas_mct_enc.c | 23 ++++++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index e00a54d496..e3456a5d4e 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -685,10 +685,9 @@ static ivas_error ivas_mc_dec_reconfig( /* 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->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; @@ -766,6 +765,7 @@ static ivas_error ivas_mc_dec_reconfig( ivas_mct_dec_close( &st_ivas->hMCT ); st_ivas->hMCT = NULL; } + /* LFE handle */ if ( st_ivas->hLFE != NULL ) { @@ -810,6 +810,7 @@ static ivas_error ivas_mc_dec_reconfig( ivas_mct_dec_close( &st_ivas->hMCT ); st_ivas->hMCT = NULL; } + /* LFE handle */ if ( st_ivas->hLFE != NULL ) { @@ -828,8 +829,10 @@ static ivas_error ivas_mc_dec_reconfig( st_ivas->element_mode_init = IVAS_CPE_MDCT; } + /*-----------------------------------------------------------------* + * Reconfigure core coder + *-----------------------------------------------------------------*/ - /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 and might have IGF static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem @@ -837,6 +840,7 @@ static ivas_error ivas_mc_dec_reconfig( if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + if ( st_ivas->nchan_transport == 3 ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; @@ -862,8 +866,7 @@ static ivas_error ivas_mc_dec_reconfig( #ifdef DEBUGGING assert( st_ivas->hCPE[1] != NULL ); #endif - Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; - st->mct_chan_mode = MCT_CHAN_MODE_LFE; + st_ivas->hCPE[1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_LFE; } if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) @@ -924,10 +927,12 @@ static ivas_error ivas_mc_dec_reconfig( } } - /* Allocat the LFE handle that is coded seperately after the allocation of the core coders*/ + /*-----------------------------------------------------------------* + * Allocate the LFE handle that is coded seperately after the allocation of the core coders + *-----------------------------------------------------------------*/ + if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL ) { - if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtf != NULL ? st_ivas->hHrtf->latency_s : 0 ) ) != IVAS_ERR_OK ) { return error; @@ -941,9 +946,8 @@ static ivas_error ivas_mc_dec_reconfig( set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k ); } - /*-----------------------------------------------------------------* - * Renderers + * Reconfigure renderers *-----------------------------------------------------------------*/ if ( renderer_type_old != st_ivas->renderer_type ) @@ -951,6 +955,7 @@ static ivas_error ivas_mc_dec_reconfig( 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 ) { @@ -959,18 +964,22 @@ static ivas_error ivas_mc_dec_reconfig( { 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 ) ) { @@ -1009,7 +1018,7 @@ static ivas_error ivas_mc_dec_reconfig( } } } - /* stereo */ + /* mono/stereo */ else if ( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) { /* nothing should happen here... */ @@ -1025,7 +1034,7 @@ static ivas_error ivas_mc_dec_reconfig( 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 */ + /* Nothing to do, renderer is always RENDERER_SBA_LINEAR_ENC */ assert( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC && renderer_type_old == RENDERER_SBA_LINEAR_ENC ); } #endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index ad67efb9a7..49daafed5f 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -620,6 +620,10 @@ static ivas_error ivas_mc_enc_reconfig( nSCE_old = st_ivas->nSCE; nCPE_old = st_ivas->nCPE; + /*-----------------------------------------------------------------* + * Reconfigure MC modules + *-----------------------------------------------------------------*/ + if ( st_ivas->mc_mode == MC_MODE_MCT ) { st_ivas->nSCE = 0; @@ -634,6 +638,7 @@ static ivas_error ivas_mc_enc_reconfig( { return error; } + /*De-allocate handles for other MC modes*/ if ( st_ivas->hParamMC != NULL ) { @@ -647,6 +652,7 @@ static ivas_error ivas_mc_enc_reconfig( ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hMcMasa = NULL; } + if ( st_ivas->hMasa != NULL ) { ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); @@ -698,6 +704,7 @@ static ivas_error ivas_mc_enc_reconfig( ivas_mct_enc_close( st_ivas->hMCT ); st_ivas->hMCT = NULL; } + if ( last_mc_mode == MC_MODE_MCT && st_ivas->hLFE != NULL ) { /* LFE handle */ @@ -732,6 +739,7 @@ static ivas_error ivas_mc_enc_reconfig( ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); st_ivas->hParamMC = NULL; } + if ( last_mc_mode == MC_MODE_MCT ) { /* LFE handle */ @@ -757,7 +765,10 @@ static ivas_error ivas_mc_enc_reconfig( st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } - /* re-configure core coder*/ + /*-----------------------------------------------------------------* + * Reconfigure core coder + *-----------------------------------------------------------------*/ + /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 and might have IGF and TranDet static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem @@ -765,6 +776,7 @@ static ivas_error ivas_mc_enc_reconfig( if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + if ( st_ivas->nchan_transport == 3 ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; @@ -773,15 +785,17 @@ static ivas_error ivas_mc_enc_reconfig( { st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } + if ( st->hTranDet == NULL ) { - if ( ( st->hTranDet = (TRAN_DET_HANDLE) count_malloc( sizeof( TRAN_DET_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } + InitTransientDetection( (int16_t) ( st->input_Fs / FRAMES_PER_SEC ), NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); } + if ( st->hIGFEnc == NULL ) { if ( ( st->hIGFEnc = (IGF_ENC_INSTANCE_HANDLE) count_malloc( sizeof( IGF_ENC_INSTANCE ) ) ) == NULL ) @@ -789,6 +803,7 @@ static ivas_error ivas_mc_enc_reconfig( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } } + st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode, st->mct_chan_mode ); } else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) @@ -796,11 +811,9 @@ static ivas_error ivas_mc_enc_reconfig( #ifdef DEBUGGING assert( st_ivas->hCPE[1] != NULL ); #endif - Encoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; - st->mct_chan_mode = MCT_CHAN_MODE_LFE; + st_ivas->hCPE[1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_LFE; } - if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ) ) != IVAS_ERR_OK ) { return error; -- GitLab From 602dfad2ec2f209ff874bf408571798e6e35fe22 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 24 Nov 2022 10:32:00 +0200 Subject: [PATCH 13/42] Implements bitrate switching within McMASA and partially to other MC modes. --- lib_com/ivas_mcmasa_com.c | 37 +++ lib_com/ivas_prot.h | 47 +++ lib_com/options.h | 6 +- lib_com/swb_tbe_com.c | 4 + lib_dec/ivas_core_dec.c | 1 - lib_dec/ivas_corecoder_dec_reconfig.c | 221 +++++++++++++- lib_dec/ivas_cpe_dec.c | 5 + lib_dec/ivas_init_dec.c | 29 +- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_mcmasa_dec.c | 148 ++++++++++ lib_dec/ivas_mct_dec.c | 144 +++++++++- lib_dec/ivas_sba_dec.c | 4 + lib_dec/ivas_sce_dec.c | 5 + lib_enc/igf_enc.c | 0 lib_enc/ivas_corecoder_enc_reconfig.c | 398 +++++++++++++++++++++++++- lib_enc/ivas_cpe_enc.c | 8 +- lib_enc/ivas_init_enc.c | 24 ++ lib_enc/ivas_mc_param_enc.c | 2 +- lib_enc/ivas_mcmasa_enc.c | 114 ++++++++ lib_enc/ivas_mct_enc.c | 48 ++++ lib_enc/ivas_sba_enc.c | 4 + lib_enc/ivas_sce_enc.c | 4 + 22 files changed, 1237 insertions(+), 18 deletions(-) create mode 100644 lib_dec/ivas_mcmasa_dec.c mode change 100755 => 100644 lib_enc/igf_enc.c diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c index 2441cf7973..a080befbaa 100644 --- a/lib_com/ivas_mcmasa_com.c +++ b/lib_com/ivas_mcmasa_com.c @@ -91,6 +91,7 @@ void ivas_mcmasa_set_separate_channel_mode( return; } +#ifndef MCMASA_BITRATE_SWITCHING /*--------------------------------------------------------------------------* * ivas_mcmasa_mono_brate() * @@ -112,3 +113,39 @@ int32_t ivas_mcmasa_mono_brate( return ( const int32_t )( MCMASA_MONOBITRATIO * ivas_total_brate ); } } +#else +/*--------------------------------------------------------------------------* + * ivas_mcmasa_split_brate() + * + * Split the total bitrate to elements in McMASA + *--------------------------------------------------------------------------*/ +void ivas_mcmasa_split_brate( + const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */ + const int32_t ivas_total_brate, /* i : Total bitrate available to be split */ + const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */ + const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */ + int32_t *brate_sce, /* o : Pointer to SCE element bitrate */ + int32_t *brate_cpe /* o : Pointer to CPE element bitrate */ +) +{ + if ( separateChannelEnabled ) + { + /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */ + if ( ivas_total_brate < IVAS_96k ) + { + *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO_64k * ivas_total_brate ); + } + else + { + *brate_sce = (int32_t) ( MCMASA_MONOBITRATIO * ivas_total_brate ); + } + + *brate_cpe = ivas_total_brate - *brate_sce; + } + else + { + *brate_sce = nSCE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0; + *brate_cpe = nCPE > 0 ? ivas_total_brate / ( nCPE + nSCE ) : 0; + } +} +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 27b9d21c0d..170c8eafa2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -128,7 +128,14 @@ ivas_error ivas_corecoder_enc_reconfig( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ +#ifdef MCMASA_BITRATE_SWITCHING + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ + const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ +#else const int16_t nchan_transport_old /* i : number of TCs in previous frame */ +#endif ); #endif @@ -333,11 +340,21 @@ void ivas_mct_dec_close( #ifdef CORECODER_BITRATE_SWITCHING ivas_error ivas_corecoder_dec_reconfig( +#ifdef MCMASA_BITRATE_SWITCHING + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + const int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs      */ + const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ +#else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old /* i : signal stereo output for SBA DirAC in previous frame */ +#endif ); ivas_error ivas_hp20_dec_reconfig( @@ -4779,6 +4796,16 @@ void ivas_mcmasa_enc_close( const int32_t input_Fs /* i : input sampling rate */ ); +#ifdef MCMASA_BITRATE_SWITCHING +ivas_error ivas_mcmasa_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +ivas_error ivas_mcmasa_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); +#endif + void ivas_mcmasa_setNumTransportChannels( int16_t* nchan_transport, /* o : Pointer to number of transport channels to be set */ int16_t* element_mode, /* o : Pointer to element mode to be set */ @@ -4791,10 +4818,21 @@ void ivas_mcmasa_set_separate_channel_mode( const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ ); +#ifndef MCMASA_BITRATE_SWITCHING /*! r: McMASA SCE bitrate */ int32_t ivas_mcmasa_mono_brate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); +#else +void ivas_mcmasa_split_brate( + const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */ + const int32_t ivas_total_brate, /* i : Total bitrate available to be split */ + const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */ + const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */ + int32_t *brate_sce, /* o : Pointer to SCE element bitrate */ + int32_t *brate_cpe /* o : Pointer to CPE element bitrate */ +); +#endif void ivas_mcmasa_enc( MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */ @@ -4819,6 +4857,15 @@ void ivas_mcmasa_param_est_enc( const int16_t nchan_inp /* i : Number of input channels */ ); +#ifdef MCMASA_BITRATE_SWITCHING +void ivas_mcmasa_dmx_modify( + const int16_t n_samples, /* i : input frame length in samples */ + float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ + const uint8_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ + const uint8_t n_chnls_dmx_new /* i : number of downmix channels in the target format */ +); +#endif + void v_multc_acc( const float x[], /* i : Input vector */ const float c, /* i : Constant */ diff --git a/lib_com/options.h b/lib_com/options.h index 28fb60c2e9..6b63e63f71 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define MEM_COUNT_DETAILS /* RAM counting tool: print per sub-structure details */ +/*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ /*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO @@ -159,7 +159,9 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ - +#ifdef MC_BITRATE_SWITCHING +#define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ +#endif /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 4291feaed9..c8961f88dd 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1891,6 +1891,10 @@ void tbe_celp_exc( return; } +#ifdef MCMASA_BITRATE_SWITCHING + assert( bwe_exc != NULL && "BWE excitation is NULL" ); +#endif + if ( L_frame == L_FRAME ) { offset = tbe_celp_exc_offset( T0, T0_frac ); diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index ad350f4e30..12274f8762 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -442,7 +442,6 @@ ivas_error ivas_core_dec( } } #endif - } /*---------------------------------------------------------------------* diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 8f0ba78857..479ed862af 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -50,15 +50,25 @@ /*-------------------------------------------------------------------* * ivas_corecoder_dec_reconfig() * - * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching + * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_dec_reconfig( +#ifdef MCMASA_BITRATE_SWITCHING + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + const int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs      */ + const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ +#else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old /* i : signal stereo output for SBA DirAC in previous frame */ +#endif ) { int16_t n, sce_id, cpe_id, output_frame; @@ -82,7 +92,12 @@ ivas_error ivas_corecoder_dec_reconfig( *-----------------------------------------------------------------*/ /* remove dummy CPE element for DFT stereo-like upmix */ +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) || + ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && sba_dirac_stereo_flag_old ) ) +#else if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) +#endif { st_ivas->hCPE[0]->hCoreCoder[0] = NULL; st_ivas->hCPE[0]->hCoreCoder[1] = NULL; @@ -99,6 +114,204 @@ ivas_error ivas_corecoder_dec_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) ) + { + float *save_synth, *save_hb_synth; + save_synth = NULL; + save_hb_synth = NULL; + + /* McMASA specific handling: delete anything old and create completely new ones. + * sba_dirac_stereo_flag: STEREO rendering from 1 transport channel with low delay using DFT stereo */ + if ( ( nSCE_old > 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag ) + { + /* save the old buffers, if they exist */ + save_synth = st_ivas->hSCE[0]->save_synth; + save_hb_synth = st_ivas->hSCE[0]->save_hb_synth; + st_ivas->hSCE[0]->save_synth = NULL; + st_ivas->hSCE[0]->save_hb_synth = NULL; + } + + for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) + { + destroy_sce_dec( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + } + for ( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ( sce_id == 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag ) + { + /* replace the newly created buffers with the old ones */ + if ( st_ivas->hSCE[0]->save_synth != NULL ) + { + count_free( st_ivas->hSCE[0]->save_synth ); + st_ivas->hSCE[0]->save_synth = NULL; + } + if ( st_ivas->hSCE[0]->save_hb_synth != NULL ) + { + count_free( st_ivas->hSCE[0]->save_hb_synth ); + st_ivas->hSCE[0]->save_hb_synth = NULL; + } + st_ivas->hSCE[0]->save_synth = save_synth; + st_ivas->hSCE[0]->save_hb_synth = save_hb_synth; + } + } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + /* non-McMASA */ + if ( ( st_ivas->nSCE == nSCE_old ) && ( st_ivas->nCPE == nCPE_old ) ) + { + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + } + + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + + // VE: TBV - try to reuse the CoreCoder + /* destroy superfluous core coder elements */ + for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + { + destroy_sce_dec( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + } + + for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + { + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) + { + ivas_mct_dec_close( &st_ivas->hMCT ); + } + + /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ + if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) + { + count_free( st_ivas->hCPE[0]->hStereoMdct ); + st_ivas->hCPE[0]->hStereoMdct = NULL; + } + + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + { + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + for ( ; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + } + for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) + { + if ( nCPE_old == 1 ) + { + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; + } + } + + if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) + { + if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ + if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) + { + if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + /* reset mct_chan_mode */ + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + } + } + } +#else if ( st_ivas->nchan_transport == nchan_transport_old ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) @@ -233,9 +446,15 @@ ivas_error ivas_corecoder_dec_reconfig( } } } +#endif /* create dummy CPE element for DFT stereo-like upmix */ +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) || + ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag ) ) +#else if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) +#endif { if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index e8c0493ad1..e8da2b8e48 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -535,8 +535,13 @@ ivas_error ivas_cpe_dec( for ( i = 0; i < n; i++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate.cpe", 0, cpe_id, DEC ) ); + dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode.cpe", 0, cpe_id, DEC ) ); +#else dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) ); dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) ); +#endif for ( int16_t j = 0; j < CPE_CHANNELS; j++ ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e183eda8e0..3d4fc869fe 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -272,7 +272,7 @@ ivas_error ivas_dec_setup( { if ( ( error = doSanityChecks_IVAS( st_ivas ) ) != IVAS_ERR_OK ) { - return IVAS_ERROR( error, "Sanitiy checks failed" ); + return IVAS_ERROR( error, "Sanity checks failed" ); } if ( ( error = ivas_init_decoder( st_ivas ) ) != IVAS_ERR_OK ) @@ -724,7 +724,7 @@ ivas_error ivas_init_decoder( } /*-----------------------------------------------------------------* - * Allocate and initalize SCE/CPE and other handles + * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ if ( st_ivas->ivas_format == MONO_FORMAT ) @@ -1056,6 +1056,10 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef MCMASA_BITRATE_SWITCHING + int32_t brate_sce, brate_cpe; +#endif + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) @@ -1092,8 +1096,18 @@ ivas_error ivas_init_decoder( } } +#ifdef MCMASA_BITRATE_SWITCHING + ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#endif + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( st_ivas->hOutSetup.separateChannelEnabled ) { if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_mcmasa_mono_brate( ivas_total_brate ) ) ) != IVAS_ERR_OK ) @@ -1108,15 +1122,23 @@ ivas_error ivas_init_decoder( return error; } } +#endif reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ + if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( st_ivas->hOutSetup.separateChannelEnabled ) { - st_ivas->element_mode_init = IVAS_CPE_MDCT; + st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate - st_ivas->hSCE[0]->element_brate ) ) != IVAS_ERR_OK ) { @@ -1132,6 +1154,7 @@ ivas_error ivas_init_decoder( return error; } } +#endif for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b4aa18f2a1..3d30ba2071 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1063,7 +1063,7 @@ ivas_error ivas_masa_dec_reconfigure( last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; /*-----------------------------------------------------------------* - * Allocate and initalize SCE/CPE and other handles + * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ bit_stream = st_ivas->hSCE[0] != NULL ? st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream : st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream; diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c new file mode 100644 index 0000000000..7b7cf935a4 --- /dev/null +++ b/lib_dec/ivas_mcmasa_dec.c @@ -0,0 +1,148 @@ +/****************************************************************************************************** + +(C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository. All Rights Reserved. + +This software is protected by copyright law and by international treaties. +The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository retain full ownership rights in their respective contributions in +the software. This notice grants no license of any kind, including but not limited to patent +license, nor is any license granted by implication, estoppel or otherwise. + +Contributors are required to enter into the IVAS codec Public Collaboration agreement before making +contributions. + +This software is provided "AS IS", without any express or implied warranties. The software is in the +development stage. It is intended exclusively for experts who have experience with such software and +solely for the purpose of inspection. All implied warranties of non-infringement, merchantability +and fitness for a particular purpose are hereby disclaimed and excluded. + +Any dispute, controversy or claim arising under or in relation to providing this software shall be +submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in +accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and +the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ +#include + +#include "ivas_cnst.h" +#include "ivas_prot.h" +#include "options.h" +#include "prot.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "wmops.h" + +#ifdef MCMASA_BITRATE_SWITCHING + +/*------------------------------------------------------------------------- + * Local constants + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------- + * Local function prototypes + *------------------------------------------------------------------------*/ + +/*------------------------------------------------------------------------- + * ivas_mcmasa_dec_reconfig() + * + * Reconfigure McMASA decoder + *------------------------------------------------------------------------*/ +ivas_error ivas_mcmasa_dec_reconfig( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + ivas_error error; + int32_t ivas_total_brate; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + /* close the old MASA instance */ + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_dec_close( st_ivas->hMasa ); + } + + /* get new McMASA settings */ + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); + ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); + + /* renderer might change as an effect from the transport mode change */ + ivas_renderer_select( st_ivas ); + + /* side effect of the renderer selection can be a changed internal config. this is also needed when switching from non-McMASA */ + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); + + if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && st_ivas->hOutSetup.output_config == AUDIO_CONFIG_STEREO ); + + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) + { + if ( st_ivas->hDirAC == NULL ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + /*-------------------------------------------------------------------* + * Close binaural rendering handles and re-allocate proper ones + * in McMASA renderer_type can be only RENDERER_BINAURAL_PARAMETRIC, RENDERER_BINAURAL_PARAMETRIC_ROOM + *--------------------------------------------------------------------*/ + if ( st_ivas->hBinRenderer != NULL ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + /* 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 ) + { + if ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + /* close unneeded renderer */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + else + { + /* the decision for useTdDecorr is done in ivas_dirac_dec_init_binaural_data(). here, comparing against the same condition. */ + if ( st_ivas->hDiracDecBin->useTdDecorr != ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_48k && st_ivas->nchan_transport == 1 ) ) + { + /* st_ivas->hDiracDecBin->useTdDecorr will change => close and re-open. */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } + return error; +} +#endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index bb46fbdea0..e91062ecc2 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -644,11 +644,18 @@ ivas_error ivas_mc_dec_reconfig( const int16_t last_mc_mode /* i : last frame MC mode */ ) { +#ifdef MCMASA_BITRATE_SWITCHING + int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; +#else int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old; +#endif int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i; RENDERER_TYPE renderer_type_old; ivas_error error; MC_MODE mc_mode; +#ifdef MCMASA_BITRATE_SWITCHING + int32_t new_brate_SCE, new_brate_CPE; +#endif error = IVAS_ERR_OK; nchan_transport_old = st_ivas->nchan_transport; @@ -664,13 +671,23 @@ ivas_error ivas_mc_dec_reconfig( nCPE_old = st_ivas->nCPE; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; +#ifdef MCMASA_BITRATE_SWITCHING + /* special handling needed for the hp20 buffers for McMASA */ + if ( last_mc_mode == MC_MODE_MCMASA ) + { + nchan_hp20_old = getNumChanSynthesis( st_ivas ); + } + else + { + nchan_hp20_old = nchan_transport_old; + } +#endif /* 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->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; @@ -758,8 +775,10 @@ ivas_error ivas_mc_dec_reconfig( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef MCMASA_BITRATE_SWITCHING ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), st_ivas->hDecoderConfig->ivas_total_brate ); +#endif if ( last_mc_mode != MC_MODE_MCMASA ) { if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) @@ -767,12 +786,19 @@ ivas_error ivas_mc_dec_reconfig( return error; } +#ifndef MCMASA_BITRATE_SWITCHING if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - +#else + } + if ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif /* ls conversion */ if ( st_ivas->hLsSetUpConversion != NULL ) { @@ -801,6 +827,19 @@ ivas_error ivas_mc_dec_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode != MC_MODE_MCMASA ) + { + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + } +#else if ( st_ivas->nchan_transport == 1 ) { st_ivas->element_mode_init = IVAS_SCE; @@ -809,7 +848,7 @@ ivas_error ivas_mc_dec_reconfig( { st_ivas->element_mode_init = IVAS_CPE_MDCT; } - +#endif /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 @@ -848,13 +887,33 @@ ivas_error ivas_mc_dec_reconfig( st->mct_chan_mode = MCT_CHAN_MODE_LFE; } +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + uint8_t separateChannelEnabled; + int16_t separateChannelIndex; + ivas_mcmasa_set_separate_channel_mode( &separateChannelEnabled, &separateChannelIndex, st_ivas->hDecoderConfig->ivas_total_brate ); + ivas_mcmasa_split_brate( separateChannelEnabled, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); + } + else + { + new_brate_SCE = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; + new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + } + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) +#endif { return error; } /* re-configure hp20 memories */ +#ifdef MCMASA_BITRATE_SWITCHING + ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); +#else ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); +#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -884,6 +943,25 @@ ivas_error ivas_mc_dec_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( last_mc_mode == MC_MODE_MCMASA ) && ( nchan_transport_old == 1 ) && ( ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM ) || ( renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) ) + { + /* cldfbAnaDec[1] might be modified by DirAC (ivas_dirac_dec_binaural_internal) -> re-instantiate it */ + if ( ( numCldfbAnalyses_old > 1 ) && ( numCldfbAnalyses > 1 ) ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); + st_ivas->cldfbAnaDec[1] = NULL; + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[1] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + for ( i = 0; i < numCldfbAnalyses; i++ ) + { + cldfb_reset_memory( st_ivas->cldfbAnaDec[i] ); + } +#endif /* Synthesis */ if ( numCldfbSyntheses_old > numCldfbSyntheses ) { @@ -905,8 +983,14 @@ ivas_error ivas_mc_dec_reconfig( } } } +#ifdef MCMASA_BITRATE_SWITCHING + for ( i = 0; i < numCldfbSyntheses; i++ ) + { + cldfb_reset_memory( st_ivas->cldfbSynDec[i] ); + } +#endif - /* Allocat the LFE handle that is coded seperately after the allocation of the core coders*/ + /* Allocate the LFE handle that is coded separately after the allocation of the core coders */ if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL ) { @@ -923,8 +1007,37 @@ ivas_error ivas_mc_dec_reconfig( set_zero( st_ivas->hLFE->prior_out_buffer, L_FRAME48k ); } - /* renderers */ +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + if ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + /* reconfigure existing DirAC dec */ + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + /* init a new DirAC dec */ + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( ( st_ivas->renderer_type == RENDERER_DISABLE ) && ( st_ivas->hDirAC != NULL ) ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + } +#endif + if ( renderer_type_old != st_ivas->renderer_type ) { AUDIO_CONFIG output_config; @@ -946,10 +1059,29 @@ ivas_error ivas_mc_dec_reconfig( { ivas_td_binaural_close( &st_ivas->hBinRendererTd ); } +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( 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 ); + } + else + { + /* useTdDecorr may change => close and re-open */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + 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 ) ) { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } +#endif /* init necessary new renderers */ if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index bd02907991..08d263e8ac 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -605,7 +605,11 @@ ivas_error ivas_sba_dec_reconfigure( *-----------------------------------------------------------------*/ #ifdef CORECODER_BITRATE_SWITCHING +#ifdef MCMASA_BITRATE_SWITCHING + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); +#else ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); +#endif /*-----------------------------------------------------------------* * HP20 memories diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 1eadd39cb0..fcc5cc8985 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -285,8 +285,13 @@ ivas_error ivas_sce_dec( for ( i = 0; i < n; i++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate.sce", 0, sce_id, DEC ) ); + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode.sce", 0, sce_id, DEC ) ); +#else dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, sce_id, DEC ) ); dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); +#endif dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); tmpF = 0; diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c old mode 100755 new mode 100644 diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f4b302eefd..e76a73046a 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -51,10 +51,20 @@ *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_enc_reconfig( +#ifdef MCMASA_BITRATE_SWITCHING + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + const int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ + const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */ +#else Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old /* i : number of TCs in previous frame */ +#endif ) { int16_t n, sce_id, cpe_id; @@ -63,7 +73,9 @@ ivas_error ivas_corecoder_enc_reconfig( BSTR_ENC_HANDLE hBstr, hMetaData; Indice *ind_list, *ind_list_metadata; int16_t nb_bits_tot, next_ind, last_ind; +#ifndef MCMASA_BITRATE_SWITCHING int32_t ivas_total_brate; +#endif ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; @@ -72,7 +84,9 @@ ivas_error ivas_corecoder_enc_reconfig( *-----------------------------------------------------------------*/ hEncoderConfig = st_ivas->hEncoderConfig; +#ifndef MCMASA_BITRATE_SWITCHING ivas_total_brate = hEncoderConfig->ivas_total_brate; +#endif error = IVAS_ERR_OK; len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC ); @@ -85,18 +99,31 @@ ivas_error ivas_corecoder_enc_reconfig( * Switching between SCE(s)/CPE(s)/MCT *-----------------------------------------------------------------*/ +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( st_ivas->nSCE == nSCE_old ) && ( st_ivas->nCPE == nCPE_old ) && ( st_ivas->mc_mode == last_mc_mode ) ) +#else if ( st_ivas->nchan_transport == nchan_transport_old ) +#endif { + /* transport layout (and mode) stays the same -> take a shortcut in reconfig */ for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; +#else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; +#endif st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; +#else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; +#endif /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) @@ -117,11 +144,23 @@ ivas_error ivas_corecoder_enc_reconfig( } else { +#ifdef MCMASA_BITRATE_SWITCHING + /* transport layout changes */ ind_list = NULL; + ind_list_metadata = NULL; +#else + ind_list = NULL; +#endif hBstr = NULL; hMetaData = NULL; +#ifdef MCMASA_BITRATE_SWITCHING + /* get the index list pointers + * taking the hBstr from the first active element gets the start of ind_list + * the same for the hMetaData */ +#else /* get the index list pointers */ +#endif if ( nSCE_old ) { hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; @@ -140,12 +179,368 @@ ivas_error ivas_corecoder_enc_reconfig( #endif /* save bitstream information */ +#ifdef MCMASA_BITRATE_SWITCHING + ind_list = hBstr->ind_list; /* pointer to the beginning of the global list */ +#else ind_list = hBstr->ind_list; +#endif nb_bits_tot = hBstr->nb_bits_tot; next_ind = hBstr->next_ind; last_ind = hBstr->last_ind; - ind_list_metadata = hMetaData->ind_list; + ind_list_metadata = hMetaData->ind_list; /* pointer to the beginning of the global list */ + +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + int16_t buff_len; + buff_len = L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ); + + if ( last_mc_mode == MC_MODE_MCMASA ) + { + /* copy earlier dmx buffers */ + if ( nSCE_old > 0 ) + { + set_zero( input_buff[0], buff_len ); + mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); + } + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + set_zero( input_buff[n + 1], buff_len ); + if ( nCPE_old > 0 ) + { + mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + } + } + + /* modify the dmx format to match the new one */ + ivas_mcmasa_dmx_modify( buff_len, input_buff, nSCE_old + 2 * nCPE_old, st_ivas->nSCE + 2 * st_ivas->nCPE ); + } + + for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) + { + destroy_sce_enc( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + } + for ( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + if ( st_ivas->nSCE ) + { + if ( ( error = create_sce_enc( st_ivas, 0, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + /* restore information of the bitstream already written */ + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list + 0 * MAX_NUM_INDICES; + + /* only SCE in use => update bitstream info */ + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->last_ind = last_ind; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->next_ind = next_ind; + + /* in case of 2+1, this is not really used, but let's keep it for compatibility */ + st_ivas->hSCE[0]->hMetaData->ind_list = ind_list_metadata + 0 * MAX_BITS_METADATA; + reset_indices_enc( st_ivas->hSCE[0]->hMetaData, MAX_BITS_METADATA ); + + if ( last_mc_mode == MC_MODE_MCMASA ) + { + /* restore input buffer */ + mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + } + + if ( st_ivas->nCPE ) + { + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + if ( ( error = create_cpe_enc( st_ivas, 0, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( 0 * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; + + if ( ( st_ivas->nSCE > 0 ) || ( n > 0 ) ) /* the started bitstream is in SCE or in the first core channel of CPE => reset here */ + { + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + else + { + /* restore the beginning of the bitstream */ + st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->last_ind = last_ind; + st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->next_ind = next_ind; + } + if ( hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + } + + if ( last_mc_mode == MC_MODE_MCMASA ) + { + /* restore input buffer */ + mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + } + } + st_ivas->hCPE[0]->hMetaData->ind_list = ind_list_metadata + st_ivas->nSCE * MAX_NUM_INDICES; + reset_indices_enc( st_ivas->hCPE[0]->hMetaData, MAX_BITS_METADATA ); + } + } /* end of McMASA special handling */ + else + { + n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old ); + + /* destroy superfluous core-coder elements */ + for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) + { + /* save input audio buffers */ + if ( n_CoreCoder_existing > sce_id ) + { + mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + } + + destroy_sce_enc( st_ivas->hSCE[sce_id] ); + st_ivas->hSCE[sce_id] = NULL; + } + + for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) + { + /* save input audio buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) + { + mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ + } + } + + destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + + if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) + { + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } + + /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ + if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) + { + count_free( st_ivas->hCPE[0]->hStereoMdct ); + st_ivas->hCPE[0]->hStereoMdct = NULL; + } + + /* create missing core coder elements and set element bitrates for already existing ones */ + if ( st_ivas->nSCE > 0 ) + { + nSCE_existing = min( nSCE_old, st_ivas->nSCE ); + + for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) + { + copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + + for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* propagate input audio buffers */ + if ( n_CoreCoder_existing > sce_id ) + { + mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + + /* prepare bitstream buffers */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; + + /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ + if ( sce_id > 0 ) + { + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); + } + else + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind; + } + + st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA; + reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); + } + } + + if ( st_ivas->nCPE > 0 ) + { + nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + } + } + + for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* propagate input audio buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) + { + mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ + } + } + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES; + if ( cpe_id * CPE_CHANNELS + n > 0 ) + { + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + else + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; + } + + if ( hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + } + } + + if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) + { + if ( nCPE_old == 1 ) + { + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); + + if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) + { + IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, + st_ivas->hCPE[0]->element_brate, + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + } + } + } + + if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) + { + if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* metadata handling for CPEs */ + if ( st_ivas->nCPE > 0 ) + { + if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) + { + if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); + } + } + + st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata; + reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA ); + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) + { + if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL ) + { + count_free( st_ivas->hCPE[cpe_id]->hMetaData ); + st_ivas->hCPE[cpe_id]->hMetaData = NULL; + } + } + } + + /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ + if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) + { + if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + + /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; + + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); + + if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) + { + IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, + st_ivas->hCPE[0]->element_brate, + st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, + st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, + st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); + } + + /* reset mct_chan_mode */ + st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + } + + initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); + } + } + } +#else n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old ); /* destroy superfluous core-coder elements */ @@ -390,6 +785,7 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } +#endif return error; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 15e3dcd6ba..dbc5f44a25 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -420,7 +420,11 @@ ivas_error ivas_cpe_enc( { dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, fname( debug_dir, "input_DMX", n, sts[n]->id_element, ENC ) ); } +#ifdef MCMASA_BITRATE_SWITCHING + dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode.cpe", 0, sts[0]->id_element, ENC ) ); +#else dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, sts[0]->id_element, ENC ) ); +#endif #endif /*----------------------------------------------------------------* @@ -821,7 +825,7 @@ ivas_error create_cpe_enc( /* we need the meta data handle also if we init as MC_FORMAT/MCT since it might be needed at a bit rate switch to ParamMC or McMASA and the metadata index list is only really reachable in the ivas_init_encoder() function and has to be connected to the MD handle there */ - if ( cpe_id == ( st_ivas->nCPE - 1 )) + if ( cpe_id == ( st_ivas->nCPE - 1 ) ) #else if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) && ( cpe_id == ( st_ivas->nCPE - 1 ) ) ) #endif @@ -888,7 +892,7 @@ ivas_error create_cpe_enc( #ifdef DEBUGGING if ( hEncoderConfig->Opt_DTX_ON && ( hCPE->element_mode == IVAS_CPE_TD || hEncoderConfig->stereo_mode_cmdl == 1 ) && !( ivas_format == MASA_FORMAT && element_mode_init == IVAS_CPE_MDCT ) ) #else -if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) + if ( hEncoderConfig->Opt_DTX_ON && element_mode_init != IVAS_CPE_MDCT ) #endif { for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 4768eb3b24..e64c4e058b 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -617,6 +617,10 @@ ivas_error ivas_init_encoder( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef MCMASA_BITRATE_SWITCHING + int32_t brate_sce, brate_cpe; +#endif + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) @@ -634,8 +638,18 @@ ivas_error ivas_init_encoder( return error; } +#ifdef MCMASA_BITRATE_SWITCHING + ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#endif + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( st_ivas->hMcMasa->separateChannelEnabled ) { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_mcmasa_mono_brate( ivas_total_brate ) ) ) != IVAS_ERR_OK ) @@ -650,6 +664,7 @@ ivas_error ivas_init_encoder( return error; } } +#endif /* prepare bitstream buffers */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; @@ -661,6 +676,14 @@ ivas_error ivas_init_encoder( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + + if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( st_ivas->hMcMasa->separateChannelEnabled ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; @@ -677,6 +700,7 @@ ivas_error ivas_init_encoder( return error; } } +#endif /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 8de7f442f5..238a58109b 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -282,7 +282,7 @@ ivas_error ivas_param_mc_reconfig( #ifdef DEBUGGING assert( hParamMC->hMetadataPMC.icc_map_full[i] != NULL ); #endif - if (hParamMC->hMetadataPMC.icc_map_full[i] != NULL) + if ( hParamMC->hMetadataPMC.icc_map_full[i] != NULL ) { count_free( hParamMC->hMetadataPMC.icc_map_full[i] ); hParamMC->hMetadataPMC.icc_map_full[i] = NULL; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index a281ec4760..e79ac261ca 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -395,6 +395,50 @@ ivas_error ivas_mcmasa_enc_open( return error; } +#ifdef MCMASA_BITRATE_SWITCHING +/*------------------------------------------------------------------------- + * ivas_mcmasa_enc_reconfig() + * + * Reconfigure McMASA encoder + *------------------------------------------------------------------------*/ +ivas_error ivas_mcmasa_enc_reconfig( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int32_t ivas_total_brate; + ivas_error error; + + error = IVAS_ERR_OK; + + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + + if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) + { + /* bitrate changed, may need to do something */ + + /* brute-force solution: close McMASA and re-instantiate with new settings */ + ivas_masa_enc_close( st_ivas->hMasa, st_ivas->nchan_transport, st_ivas->hEncoderConfig->ivas_format ); + ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); + + /* Determine if to separate some channels from the analysis */ + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), ivas_total_brate ); + + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* core SCE, CPE reconfiguration happens later */ + } + + return error; +} +#endif /*--------------------------------------------------------------------------* * ivas_mcmasa_enc_close() @@ -1145,7 +1189,77 @@ void ivas_mcmasa_param_est_enc( return; } +#ifdef MCMASA_BITRATE_SWITCHING +void ivas_mcmasa_dmx_modify( + const int16_t n_samples, /* i : input frame length in samples */ + float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format. TODO: buffer size into define? */ + const uint8_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ + const uint8_t n_chnls_dmx_new ) /* i : number of downmix channels in the target format */ +{ + /* assumed data ordering in **dmx: [sce][cpe_chnl0][cpe_chnl1], i.e., [c][l][r] */ + int16_t i; + + assert( ( n_chnls_dmx_old == 1 || n_chnls_dmx_old == 2 || n_chnls_dmx_old == 3 ) && "Input downmix may contain only 1-3 channels." ); + assert( ( n_chnls_dmx_new == 1 || n_chnls_dmx_new == 2 || n_chnls_dmx_new == 3 ) && "Output downmix may contain only 1-3 channels." ); + if ( n_chnls_dmx_old == n_chnls_dmx_new ) + { + /* same dmx layout -> nothing to do */ + return; + } + if ( n_chnls_dmx_old == 1 ) + { + /* split mono energy into identical channels */ + for ( i = 0; i < n_samples; i++ ) + { + if ( n_chnls_dmx_new == 2 ) + { + dmx[1][i] = dmx[0][i] * INV_SQRT2; + dmx[2][i] = dmx[1][i]; + } + else if ( n_chnls_dmx_new == 3 ) + { + dmx[0][i] = dmx[0][i] * INV_SQRT3; + } + } + } + else if ( n_chnls_dmx_old == 2 ) + { + for ( i = 0; i < n_samples; i++ ) + { + if ( n_chnls_dmx_new == 1 ) + { + /* sum l and r */ + dmx[0][i] = dmx[1][i] + dmx[2][i]; + } + else if ( n_chnls_dmx_new == 3 ) + { + dmx[0][i] = 0.5f * ( dmx[1][i] + dmx[2][i] ); + dmx[1][i] = dmx[1][i] - dmx[0][i]; + dmx[2][i] = dmx[2][i] - dmx[0][i]; + } + } + } + else if ( n_chnls_dmx_old == 3 ) + { + for ( i = 0; i < n_samples; i++ ) + { + if ( n_chnls_dmx_new == 1 ) + { + /* sum all channels */ + dmx[0][i] = dmx[0][i] + dmx[1][i] + dmx[2][i]; + } + else if ( n_chnls_dmx_new == 2 ) + { + /* mix center into sides */ + dmx[0][i] *= INV_SQRT2; + dmx[1][i] += dmx[0][i]; + dmx[2][i] += dmx[0][i]; + } + } + } +} +#endif /*--------------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f4f8e6b8ee..0f2f2d4f01 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -602,6 +602,9 @@ ivas_error ivas_mc_enc_reconfig( { int16_t nchan_transport_old, nSCE_old, nCPE_old; ivas_error error; +#ifdef MCMASA_BITRATE_SWITCHING + int32_t new_brate_SCE, new_brate_CPE; +#endif error = IVAS_ERR_OK; @@ -696,10 +699,17 @@ ivas_error ivas_mc_enc_reconfig( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( last_mc_mode != MC_MODE_MCMASA ) + { + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); + +#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); if ( last_mc_mode != MC_MODE_MCMASA ) { +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -716,6 +726,17 @@ ivas_error ivas_mc_enc_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + else + { + /* reconfigure McMASA instance */ + if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + if ( st_ivas->hParamMC != NULL ) { ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); @@ -737,6 +758,19 @@ ivas_error ivas_mc_enc_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode != MC_MODE_MCMASA ) + { + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } +#else if ( st_ivas->nchan_transport == 1 ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; @@ -745,6 +779,7 @@ ivas_error ivas_mc_enc_reconfig( { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } +#endif /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 @@ -789,8 +824,21 @@ ivas_error ivas_mc_enc_reconfig( st->mct_chan_mode = MCT_CHAN_MODE_LFE; } +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); + } + else + { + new_brate_SCE = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; + new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + } + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index e3564725f5..397a04e4a4 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -272,7 +272,11 @@ ivas_error ivas_sba_enc_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ +#ifdef MCMASA_BITRATE_SWITCHING + ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); +#else ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); +#endif #else if ( hEncoderConfig->nchan_transport == nchan_transport_old ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 651ba3b9e5..bd460c038c 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -178,7 +178,11 @@ ivas_error ivas_sce_enc( #ifdef DEBUG_MODE_INFO dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); +#ifdef MCMASA_BITRATE_SWITCHING + dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode.sce", 0, st->id_element, ENC ) ); +#else dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); +#endif #endif /*----------------------------------------------------------------* -- GitLab From 0b60f877dad9d8fdb6ff0f61d35d5b7b4d7d0575 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 28 Nov 2022 13:28:55 +0100 Subject: [PATCH 14/42] added missing new source file lib_dec/ivas_mcmasa_dec.c to the VS project --- Workspace_msvc/lib_dec.vcxproj | 1 + Workspace_msvc/lib_dec.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 5860b0a970..2b44db88b2 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -291,6 +291,7 @@ + diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 5476cf5588..df6c4bb090 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -584,6 +584,9 @@ dec_ivas_c + + dec_ivas_c + -- GitLab From 939dc7fca7d6399e3cc5bc81a33a89dad17b784a Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 6 Dec 2022 09:23:49 +0100 Subject: [PATCH 15/42] - removed cldfb analysis/synthesis reset after MC reconfig - removed special handling of McMASA in corecoder bitrate switching and merged the operations more in the common flow --- lib_dec/ivas_corecoder_dec_reconfig.c | 235 ++----------- lib_dec/ivas_mct_dec.c | 13 +- lib_enc/ivas_corecoder_enc_reconfig.c | 457 ++++++-------------------- 3 files changed, 132 insertions(+), 573 deletions(-) diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 479ed862af..f2f37e1180 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -60,7 +60,7 @@ ivas_error ivas_corecoder_dec_reconfig( const int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ - const int32_t brate_SCE, /* i : bitrate to be set for the SCEs      */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ #else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -93,8 +93,8 @@ ivas_error ivas_corecoder_dec_reconfig( /* remove dummy CPE element for DFT stereo-like upmix */ #ifdef MCMASA_BITRATE_SWITCHING - if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) || - ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && sba_dirac_stereo_flag_old ) ) + if ( ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) || + ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ) #else if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) #endif @@ -115,215 +115,28 @@ ivas_error ivas_corecoder_dec_reconfig( } #ifdef MCMASA_BITRATE_SWITCHING - if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) ) - { - float *save_synth, *save_hb_synth; - save_synth = NULL; - save_hb_synth = NULL; - - /* McMASA specific handling: delete anything old and create completely new ones. - * sba_dirac_stereo_flag: STEREO rendering from 1 transport channel with low delay using DFT stereo */ - if ( ( nSCE_old > 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag ) - { - /* save the old buffers, if they exist */ - save_synth = st_ivas->hSCE[0]->save_synth; - save_hb_synth = st_ivas->hSCE[0]->save_hb_synth; - st_ivas->hSCE[0]->save_synth = NULL; - st_ivas->hSCE[0]->save_hb_synth = NULL; - } - - for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) - { - destroy_sce_dec( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - for ( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) - { - destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) - { - return error; - } - if ( ( sce_id == 0 ) && sba_dirac_stereo_flag_old && st_ivas->sba_dirac_stereo_flag ) - { - /* replace the newly created buffers with the old ones */ - if ( st_ivas->hSCE[0]->save_synth != NULL ) - { - count_free( st_ivas->hSCE[0]->save_synth ); - st_ivas->hSCE[0]->save_synth = NULL; - } - if ( st_ivas->hSCE[0]->save_hb_synth != NULL ) - { - count_free( st_ivas->hSCE[0]->save_hb_synth ); - st_ivas->hSCE[0]->save_hb_synth = NULL; - } - st_ivas->hSCE[0]->save_synth = save_synth; - st_ivas->hSCE[0]->save_hb_synth = save_hb_synth; - } - } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - else - { - /* non-McMASA */ - if ( ( st_ivas->nSCE == nSCE_old ) && ( st_ivas->nCPE == nCPE_old ) ) - { - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - st_ivas->hSCE[sce_id]->element_brate = brate_SCE; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - - if ( st_ivas->nCPE > 1 ) - { - if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - else - { - nSCE_existing = min( nSCE_old, st_ivas->nSCE ); - nCPE_existing = min( nCPE_old, st_ivas->nCPE ); - - // VE: TBV - try to reuse the CoreCoder - /* destroy superfluous core coder elements */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) - { - destroy_sce_dec( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - - for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) - { - destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } - - if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) - { - ivas_mct_dec_close( &st_ivas->hMCT ); - } - - /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/ - if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) - { - count_free( st_ivas->hCPE[0]->hStereoMdct ); - st_ivas->hCPE[0]->hStereoMdct = NULL; - } - - for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) - { - st_ivas->hSCE[sce_id]->element_brate = brate_SCE; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - for ( ; sce_id < st_ivas->nSCE; sce_id++ ) - { - if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) - { - if ( nCPE_old == 1 ) - { - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; - } - } - - if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) - { - if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ - if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } - - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->use_itd = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->reverse_dmx = 0; - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->smooth_ratio = 1.f; - - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - /* reset mct_chan_mode */ - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - } - } - } + if ( st_ivas->nchan_transport == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) #else if ( st_ivas->nchan_transport == nchan_transport_old ) +#endif { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; +#else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; +#endif st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; +#else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - +#endif /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -372,12 +185,20 @@ ivas_error ivas_corecoder_dec_reconfig( for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; +#else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; +#endif st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } for ( ; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) +#else if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -385,8 +206,11 @@ ivas_error ivas_corecoder_dec_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; +#else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - +#endif /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -395,7 +219,11 @@ ivas_error ivas_corecoder_dec_reconfig( } for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) +#else if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -446,12 +274,11 @@ ivas_error ivas_corecoder_dec_reconfig( } } } -#endif /* create dummy CPE element for DFT stereo-like upmix */ #ifdef MCMASA_BITRATE_SWITCHING - if ( ( ( st_ivas->ivas_format == SBA_FORMAT ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) || - ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag ) ) + if ( ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) || + ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ) #else if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index e91062ecc2..0c75a1ca65 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -681,6 +681,7 @@ ivas_error ivas_mc_dec_reconfig( { nchan_hp20_old = nchan_transport_old; } + st_ivas->sba_dirac_stereo_flag = 0; /* needs to be after getNumChanSynthesis() */ #endif /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; @@ -777,8 +778,8 @@ ivas_error ivas_mc_dec_reconfig( { #ifdef MCMASA_BITRATE_SWITCHING ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), st_ivas->hDecoderConfig->ivas_total_brate ); - #endif + if ( last_mc_mode != MC_MODE_MCMASA ) { if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) @@ -957,10 +958,6 @@ ivas_error ivas_mc_dec_reconfig( } } } - for ( i = 0; i < numCldfbAnalyses; i++ ) - { - cldfb_reset_memory( st_ivas->cldfbAnaDec[i] ); - } #endif /* Synthesis */ if ( numCldfbSyntheses_old > numCldfbSyntheses ) @@ -983,12 +980,6 @@ ivas_error ivas_mc_dec_reconfig( } } } -#ifdef MCMASA_BITRATE_SWITCHING - for ( i = 0; i < numCldfbSyntheses; i++ ) - { - cldfb_reset_memory( st_ivas->cldfbSynDec[i] ); - } -#endif /* Allocate the LFE handle that is coded separately after the allocation of the core coders */ if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL ) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index e76a73046a..371a376007 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -98,14 +98,12 @@ ivas_error ivas_corecoder_enc_reconfig( /*-----------------------------------------------------------------* * Switching between SCE(s)/CPE(s)/MCT *-----------------------------------------------------------------*/ - #ifdef MCMASA_BITRATE_SWITCHING - if ( ( st_ivas->nSCE == nSCE_old ) && ( st_ivas->nCPE == nCPE_old ) && ( st_ivas->mc_mode == last_mc_mode ) ) + if ( st_ivas->nchan_transport == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) /* in McMASA, nchan_transport may be the same, but nSCE/nCPE differs */ #else if ( st_ivas->nchan_transport == nchan_transport_old ) #endif { - /* transport layout (and mode) stays the same -> take a shortcut in reconfig */ for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); @@ -124,7 +122,6 @@ ivas_error ivas_corecoder_enc_reconfig( #else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; #endif - /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -145,7 +142,26 @@ ivas_error ivas_corecoder_enc_reconfig( else { #ifdef MCMASA_BITRATE_SWITCHING - /* transport layout changes */ + int16_t nchan_transport_real, nchan_transport_old_real; + if ( last_mc_mode == MC_MODE_MCMASA ) + { + /* in SCE+CPE McMASA nchan_transport is still 2 */ + nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old; + } + else + { + nchan_transport_old_real = nchan_transport_old; + } + if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE; + } + else + { + nchan_transport_real = st_ivas->nchan_transport; + } + + /* something in transport changes */ ind_list = NULL; ind_list_metadata = NULL; #else @@ -154,13 +170,7 @@ ivas_error ivas_corecoder_enc_reconfig( hBstr = NULL; hMetaData = NULL; -#ifdef MCMASA_BITRATE_SWITCHING - /* get the index list pointers - * taking the hBstr from the first active element gets the start of ind_list - * the same for the hMetaData */ -#else /* get the index list pointers */ -#endif if ( nSCE_old ) { hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; @@ -179,369 +189,41 @@ ivas_error ivas_corecoder_enc_reconfig( #endif /* save bitstream information */ -#ifdef MCMASA_BITRATE_SWITCHING ind_list = hBstr->ind_list; /* pointer to the beginning of the global list */ -#else - ind_list = hBstr->ind_list; -#endif nb_bits_tot = hBstr->nb_bits_tot; next_ind = hBstr->next_ind; last_ind = hBstr->last_ind; ind_list_metadata = hMetaData->ind_list; /* pointer to the beginning of the global list */ #ifdef MCMASA_BITRATE_SWITCHING - if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) { - int16_t buff_len; - buff_len = L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ); - - if ( last_mc_mode == MC_MODE_MCMASA ) + /* within McMASA we can modify the transport signals when switching */ + /* copy earlier dmx buffers */ + if ( nSCE_old > 0 ) { - /* copy earlier dmx buffers */ - if ( nSCE_old > 0 ) - { - set_zero( input_buff[0], buff_len ); - mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); - } - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - set_zero( input_buff[n + 1], buff_len ); - if ( nCPE_old > 0 ) - { - mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); - } - } - - /* modify the dmx format to match the new one */ - ivas_mcmasa_dmx_modify( buff_len, input_buff, nSCE_old + 2 * nCPE_old, st_ivas->nSCE + 2 * st_ivas->nCPE ); + set_zero( input_buff[0], len_inp_memory ); + mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); } - - for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) - { - destroy_sce_enc( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - for ( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) - { - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } - - if ( st_ivas->nSCE ) + for ( n = 0; n < CPE_CHANNELS; n++ ) { - if ( ( error = create_sce_enc( st_ivas, 0, brate_SCE ) ) != IVAS_ERR_OK ) + set_zero( input_buff[n + 1], len_inp_memory ); + if ( nCPE_old > 0 ) { - return error; - } - /* restore information of the bitstream already written */ - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list + 0 * MAX_NUM_INDICES; - - /* only SCE in use => update bitstream info */ - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->last_ind = last_ind; - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->next_ind = next_ind; - - /* in case of 2+1, this is not really used, but let's keep it for compatibility */ - st_ivas->hSCE[0]->hMetaData->ind_list = ind_list_metadata + 0 * MAX_BITS_METADATA; - reset_indices_enc( st_ivas->hSCE[0]->hMetaData, MAX_BITS_METADATA ); - - if ( last_mc_mode == MC_MODE_MCMASA ) - { - /* restore input buffer */ - mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); } } + ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); - if ( st_ivas->nCPE ) - { - if ( st_ivas->hMcMasa->separateChannelEnabled ) - { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; - } - - if ( ( error = create_cpe_enc( st_ivas, 0, brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( 0 * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; - - if ( ( st_ivas->nSCE > 0 ) || ( n > 0 ) ) /* the started bitstream is in SCE or in the first core channel of CPE => reset here */ - { - reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } - else - { - /* restore the beginning of the bitstream */ - st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->last_ind = last_ind; - st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->next_ind = next_ind; - } - if ( hEncoderConfig->Opt_DTX_ON ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; - } - - if ( last_mc_mode == MC_MODE_MCMASA ) - { - /* restore input buffer */ - mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); - } - } - st_ivas->hCPE[0]->hMetaData->ind_list = ind_list_metadata + st_ivas->nSCE * MAX_NUM_INDICES; - reset_indices_enc( st_ivas->hCPE[0]->hMetaData, MAX_BITS_METADATA ); - } - } /* end of McMASA special handling */ + n_CoreCoder_existing = 0; + } else { - n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old ); - - /* destroy superfluous core-coder elements */ - for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) - { - /* save input audio buffers */ - if ( n_CoreCoder_existing > sce_id ) - { - mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); - } - - destroy_sce_enc( st_ivas->hSCE[sce_id] ); - st_ivas->hSCE[sce_id] = NULL; - } - - for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ ) - { - /* save input audio buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) - { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ - } - } - - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); - st_ivas->hCPE[cpe_id] = NULL; - } - - if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) - { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; - } - - /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ - if ( st_ivas->nCPE > 1 && nCPE_old == 1 ) - { - count_free( st_ivas->hCPE[0]->hStereoMdct ); - st_ivas->hCPE[0]->hStereoMdct = NULL; - } - - /* create missing core coder elements and set element bitrates for already existing ones */ - if ( st_ivas->nSCE > 0 ) - { - nSCE_existing = min( nSCE_old, st_ivas->nSCE ); - - for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) - { - copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); - st_ivas->hSCE[sce_id]->element_brate = brate_SCE; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - - for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) - { - if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* propagate input audio buffers */ - if ( n_CoreCoder_existing > sce_id ) - { - mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); - } - - /* prepare bitstream buffers */ - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; - - /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ - if ( sce_id > 0 ) - { - reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - } - else - { - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind; - } - - st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA; - reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); - } - } - - if ( st_ivas->nCPE > 0 ) - { - nCPE_existing = min( nCPE_old, st_ivas->nCPE ); - - for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) - { - st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - } - } - - for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) - { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* propagate input audio buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) - { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ - } - } - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES; - if ( cpe_id * CPE_CHANNELS + n > 0 ) - { - reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } - else - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; - } - - if ( hEncoderConfig->Opt_DTX_ON ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; - } - } - } - } - - if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) - { - if ( nCPE_old == 1 ) - { - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); - - if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) - { - IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, - st_ivas->hCPE[0]->element_brate, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); - } - } - } - - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 ) - { - if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - /* metadata handling for CPEs */ - if ( st_ivas->nCPE > 0 ) - { - if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) ); - } - } - - st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata; - reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA ); - - for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) - { - if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL ) - { - count_free( st_ivas->hCPE[cpe_id]->hMetaData ); - st_ivas->hCPE[cpe_id]->hMetaData = NULL; - } - } - } - - /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */ - if ( st_ivas->nCPE == 1 && nCPE_old > 1 ) - { - if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); - } - - /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; - - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode ); - - if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf ) - { - IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, - st_ivas->hCPE[0]->element_brate, - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); - } - - /* reset mct_chan_mode */ - st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; - } - - initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); - st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); - } + n_CoreCoder_existing = min( nchan_transport_real, nchan_transport_old_real ); } - } #else n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old ); +#endif /* destroy superfluous core-coder elements */ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) @@ -563,7 +245,7 @@ ivas_error ivas_corecoder_enc_reconfig( { if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ } } @@ -592,13 +274,21 @@ ivas_error ivas_corecoder_enc_reconfig( for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hSCE[sce_id]->element_brate = brate_SCE; +#else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; +#endif st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) +#else if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -635,19 +325,44 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; +#else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; - +#endif /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; + if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) + { + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + else + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind; + } +#endif } } for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) +#else if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -657,15 +372,20 @@ ivas_error ivas_corecoder_enc_reconfig( { if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory ); /* TODO VoiceAge: Please check if this should be hCoreCoder[n] */ } } /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; + if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) +#else st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES; if ( cpe_id * CPE_CHANNELS + n > 0 ) +#endif { reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); } @@ -684,6 +404,24 @@ ivas_error ivas_corecoder_enc_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) + { + /* restore modified transport signal */ + if ( st_ivas->nSCE ) + { + mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + } + if ( st_ivas->nCPE ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory ); + } + } + } +#endif + if ( st_ivas->nCPE > 1 && nCPE_old <= 1 ) { if ( nCPE_old == 1 ) @@ -735,7 +473,11 @@ ivas_error ivas_corecoder_enc_reconfig( } } +#ifdef MCMASA_BITRATE_SWITCHING + st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata + st_ivas->nSCE * MAX_NUM_INDICES; +#else st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata; +#endif reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA ); for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ ) @@ -785,7 +527,6 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } -#endif return error; } -- GitLab From 83b9a8514499d5dc6c4e8aa18d6da1e87083b835 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 6 Dec 2022 13:29:29 +0100 Subject: [PATCH 16/42] fix: re-instantiate CPE when bitrate switching McMASA<->non-McMASA as the internal settings depend from the MC-mode. clean-up DFT-stereo dummy-CPE --- lib_com/ivas_prot.h | 15 ++++++++------- lib_dec/ivas_corecoder_dec_reconfig.c | 22 ++++++++++++++++++---- lib_dec/ivas_mct_dec.c | 2 +- lib_dec/ivas_sba_dec.c | 2 +- lib_enc/ivas_mct_enc.c | 2 +- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 170c8eafa2..d6b64c8203 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -341,13 +341,14 @@ void ivas_mct_dec_close( #ifdef CORECODER_BITRATE_SWITCHING ivas_error ivas_corecoder_dec_reconfig( #ifdef MCMASA_BITRATE_SWITCHING - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nSCE_old, /* i : number of SCEs in previous frame */ - const int16_t nCPE_old, /* i : number of CPEs in previous frame */ - const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ - const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ - const int32_t brate_SCE, /* i : bitrate to be set for the SCEs      */ - const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ + int16_t nCPE_old, /* i : number of CPEs in previous frame */ + const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ + const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ + const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : MC mode in the previous frame */ #else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index f2f37e1180..811b7211ad 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -50,18 +50,19 @@ /*-------------------------------------------------------------------* * ivas_corecoder_dec_reconfig() * - * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching + * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_dec_reconfig( #ifdef MCMASA_BITRATE_SWITCHING Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ - const int16_t nCPE_old, /* i : number of CPEs in previous frame */ + int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ - const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ + const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ + const MC_MODE last_mc_mode /* i : MC mode in the previous frame */ #else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -94,7 +95,7 @@ ivas_error ivas_corecoder_dec_reconfig( /* remove dummy CPE element for DFT stereo-like upmix */ #ifdef MCMASA_BITRATE_SWITCHING if ( ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) || - ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ) + ( st_ivas->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ) #else if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) #endif @@ -171,6 +172,19 @@ ivas_error ivas_corecoder_dec_reconfig( st_ivas->hCPE[cpe_id] = NULL; } +#ifdef MCMASA_BITRATE_SWITCHING + /* the CPE-internal settings depend from ivas_format and mc_mode, so clean-up when switching between mc_modes */ + if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != last_mc_mode && ( st_ivas->mc_mode == MC_MODE_MCMASA || last_mc_mode == MC_MODE_MCMASA ) ) + { + for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) + { + destroy_cpe_dec( st_ivas->hCPE[cpe_id] ); + st_ivas->hCPE[cpe_id] = NULL; + } + nCPE_old = 0; + nCPE_existing = min( nCPE_old, st_ivas->nCPE ); + } +#endif if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) { ivas_mct_dec_close( &st_ivas->hMCT ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 0c75a1ca65..eed6452a4d 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -901,7 +901,7 @@ ivas_error ivas_mc_dec_reconfig( new_brate_SCE = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 08d263e8ac..0897393ca8 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -606,7 +606,7 @@ ivas_error ivas_sba_dec_reconfigure( #ifdef CORECODER_BITRATE_SWITCHING #ifdef MCMASA_BITRATE_SWITCHING - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); #else ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); #endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 0f2f2d4f01..0abc613a8c 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -845,4 +845,4 @@ ivas_error ivas_mc_enc_reconfig( return error; } -#endif \ No newline at end of file +#endif -- GitLab From d8029bc0864eb471e30667b59feee6b5682775f3 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Wed, 7 Dec 2022 05:48:50 +0100 Subject: [PATCH 17/42] added MC rate switch modes to ivas_modes.json --- scripts/config/ivas_modes.json | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/scripts/config/ivas_modes.json b/scripts/config/ivas_modes.json index b6039efdf4..ba0bc4143a 100644 --- a/scripts/config/ivas_modes.json +++ b/scripts/config/ivas_modes.json @@ -1639,6 +1639,161 @@ 512000 ] } + }, + "MC_5_1_b{bitrate}_{bandwidth}_rs": { + "encmodeoption": [ + "-mc", + "5_1" + ], + "encoptions": [ + "-max_band", + "{bandwidth}" + ], + "dec": { + "5_1": [] + }, + "in_config": "5_1", + "table_name": "MC 5_1@{table_bitrate} kbps RS {bandwidth}", + "nummetadata": 0, + "metadatafilenames": [], + "rs": true, + "amr": false, + "mono": false, + "bitrates": { + "wb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "swb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "fb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + } + } + }, + "MC_7_1_b{bitrate}_{bandwidth}_rs": { + "encmodeoption": [ + "-mc", + "7_1" + ], + "encoptions": [ + "-max_band", + "{bandwidth}" + ], + "dec": { + "7_1": [] + }, + "in_config": "7_1", + "table_name": "MC 7_1@{table_bitrate} kbps RS {bandwidth}", + "nummetadata": 0, + "metadatafilenames": [], + "rs": true, + "amr": false, + "mono": false, + "bitrates": { + "wb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "swb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "fb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + } + } + }, + "MC_5_1_2_b{bitrate}_{bandwidth}_rs": { + "encmodeoption": [ + "-mc", + "5_1_2" + ], + "encoptions": [ + "-max_band", + "{bandwidth}" + ], + "dec": { + "5_1_2": [] + }, + "in_config": "5_1_2", + "table_name": "MC 5_1_2@{table_bitrate} kbps RS {bandwidth}", + "nummetadata": 0, + "metadatafilenames": [], + "rs": true, + "amr": false, + "mono": false, + "bitrates": { + "wb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "swb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "fb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + } + } + }, + "MC_5_1_4_b{bitrate}_{bandwidth}_rs": { + "encmodeoption": [ + "-mc", + "5_1_4" + ], + "encoptions": [ + "-max_band", + "{bandwidth}" + ], + "dec": { + "5_1_4": [] + }, + "in_config": "5_1_4", + "table_name": "MC 5_1_4@{table_bitrate} kbps RS {bandwidth}", + "nummetadata": 0, + "metadatafilenames": [], + "rs": true, + "amr": false, + "mono": false, + "bitrates": { + "wb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "swb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "fb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + } + } + }, + "MC_7_1_4_b{bitrate}_{bandwidth}_rs": { + "encmodeoption": [ + "-mc", + "7_1_4" + ], + "encoptions": [ + "-max_band", + "{bandwidth}" + ], + "dec": { + "7_1_4": [] + }, + "in_config": "7_1_4", + "table_name": "MC 7_1_4@{table_bitrate} kbps RS {bandwidth}", + "nummetadata": 0, + "metadatafilenames": [], + "rs": true, + "amr": false, + "mono": false, + "bitrates": { + "wb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "swb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + }, + "fb": { + "all": "{sw_files_path}/sw_13k2_512k.bin" + } + } } }, "ISM1": { -- GitLab From 472db4b91d2bfa1d99555e9d82db9a718525862a Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Wed, 7 Dec 2022 07:30:21 +0100 Subject: [PATCH 18/42] fix setting of new_rate_CPE in the MC reconfiguration, was wrong for MC_MODE_MCT --- lib_dec/ivas_mct_dec.c | 7 ++++++- lib_enc/ivas_mct_enc.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index eed6452a4d..e015bfb008 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -896,9 +896,14 @@ ivas_error ivas_mc_dec_reconfig( ivas_mcmasa_set_separate_channel_mode( &separateChannelEnabled, &separateChannelIndex, st_ivas->hDecoderConfig->ivas_total_brate ); ivas_mcmasa_split_brate( separateChannelEnabled, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); } + else if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + new_brate_SCE = 0; + new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + } else { - new_brate_SCE = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; + new_brate_SCE = 0; /*st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 0abc613a8c..fde460e738 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -829,9 +829,14 @@ ivas_error ivas_mc_enc_reconfig( { ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); } + else if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + new_brate_SCE = 0; + new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / (st_ivas->nchan_transport -1)) * CPE_CHANNELS; + } else { - new_brate_SCE = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; + new_brate_SCE = 0; /*st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } -- GitLab From 98dd68ae73cb82104b93c6367833b371b0820dac Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 7 Dec 2022 16:24:22 +0100 Subject: [PATCH 19/42] removed delivering last_mc_mode as an argument across function calls and it is determined when needed using current LS config and earlier bitrate --- lib_com/ivas_prot.h | 6 ++---- lib_dec/ivas_corecoder_dec_reconfig.c | 17 ++++++++++++++--- lib_dec/ivas_mct_dec.c | 9 +++++---- lib_dec/ivas_sba_dec.c | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d6b64c8203..00ac8d5662 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -347,8 +347,7 @@ ivas_error ivas_corecoder_dec_reconfig( const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ - const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ - const MC_MODE last_mc_mode /* i : MC mode in the previous frame */ + const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ #else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -657,8 +656,7 @@ ivas_error ivas_mc_dec_config( ); #ifdef MC_BITRATE_SWITCHING ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i : last frame MC mode */ + Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); #endif diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 811b7211ad..ef5dcc5771 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -61,8 +61,7 @@ ivas_error ivas_corecoder_dec_reconfig( const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ - const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ - const MC_MODE last_mc_mode /* i : MC mode in the previous frame */ + const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ #else Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -75,6 +74,9 @@ ivas_error ivas_corecoder_dec_reconfig( int16_t n, sce_id, cpe_id, output_frame; int16_t nSCE_existing, nCPE_existing; int32_t ivas_total_brate; +#ifdef MCMASA_BITRATE_SWITCHING + MC_MODE last_mc_mode; +#endif DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; @@ -87,7 +89,16 @@ ivas_error ivas_corecoder_dec_reconfig( error = IVAS_ERR_OK; output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); - +#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->ivas_format == MC_FORMAT ) + { + last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ + } + else + { + last_mc_mode = MC_MODE_NONE; + } +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index e015bfb008..cbea498d79 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -626,7 +626,7 @@ ivas_error ivas_mc_dec_config( if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) { #ifdef MC_BITRATE_SWITCHING - ivas_mc_dec_reconfig( st_ivas, last_mc_mode ); + ivas_mc_dec_reconfig( st_ivas ); #else return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: MC format switching not supported yet!!!\n\n" ); #endif @@ -640,12 +640,12 @@ ivas_error ivas_mc_dec_config( } #ifdef MC_BITRATE_SWITCHING ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t last_mc_mode /* i : last frame MC mode */ + Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { #ifdef MCMASA_BITRATE_SWITCHING int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; + MC_MODE last_mc_mode; /* last frame MC mode */ #else int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old; #endif @@ -655,6 +655,7 @@ ivas_error ivas_mc_dec_reconfig( MC_MODE mc_mode; #ifdef MCMASA_BITRATE_SWITCHING int32_t new_brate_SCE, new_brate_CPE; + last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ #endif error = IVAS_ERR_OK; @@ -906,7 +907,7 @@ ivas_error ivas_mc_dec_reconfig( new_brate_SCE = 0; /*st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 0897393ca8..08d263e8ac 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -606,7 +606,7 @@ ivas_error ivas_sba_dec_reconfigure( #ifdef CORECODER_BITRATE_SWITCHING #ifdef MCMASA_BITRATE_SWITCHING - ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); + ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); #else ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); #endif -- GitLab From 78da1cef3b76c785534b0cd9334a27672ab70fd7 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 7 Dec 2022 17:03:38 +0100 Subject: [PATCH 20/42] merged preprocessor flag MCMASA_BITRATE_SWITCHING into MC_BITRATE_SWITCHING --- lib_com/ivas_mcmasa_com.c | 2 +- lib_com/ivas_prot.h | 10 ++--- lib_com/options.h | 4 +- lib_com/swb_tbe_com.c | 2 +- lib_dec/ivas_corecoder_dec_reconfig.c | 28 ++++++------ lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_init_dec.c | 8 ++-- lib_dec/ivas_mcmasa_dec.c | 2 +- lib_dec/ivas_mct_dec.c | 61 ++++----------------------- lib_dec/ivas_sba_dec.c | 2 +- lib_dec/ivas_sce_dec.c | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 32 +++++++------- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_init_enc.c | 8 ++-- lib_enc/ivas_mcmasa_enc.c | 4 +- lib_enc/ivas_mct_enc.c | 27 ------------ lib_enc/ivas_sba_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 2 +- 18 files changed, 64 insertions(+), 136 deletions(-) diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c index a080befbaa..2b758167e1 100644 --- a/lib_com/ivas_mcmasa_com.c +++ b/lib_com/ivas_mcmasa_com.c @@ -91,7 +91,7 @@ void ivas_mcmasa_set_separate_channel_mode( return; } -#ifndef MCMASA_BITRATE_SWITCHING +#ifndef MC_BITRATE_SWITCHING /*--------------------------------------------------------------------------* * ivas_mcmasa_mono_brate() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 00ac8d5662..09102a77d1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -128,7 +128,7 @@ ivas_error ivas_corecoder_enc_reconfig( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */ @@ -340,7 +340,7 @@ void ivas_mct_dec_close( #ifdef CORECODER_BITRATE_SWITCHING ivas_error ivas_corecoder_dec_reconfig( -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ int16_t nCPE_old, /* i : number of CPEs in previous frame */ @@ -4795,7 +4795,7 @@ void ivas_mcmasa_enc_close( const int32_t input_Fs /* i : input sampling rate */ ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_error ivas_mcmasa_enc_reconfig( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); @@ -4817,7 +4817,7 @@ void ivas_mcmasa_set_separate_channel_mode( const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ ); -#ifndef MCMASA_BITRATE_SWITCHING +#ifndef MC_BITRATE_SWITCHING /*! r: McMASA SCE bitrate */ int32_t ivas_mcmasa_mono_brate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -4856,7 +4856,7 @@ void ivas_mcmasa_param_est_enc( const int16_t nchan_inp /* i : Number of input channels */ ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ diff --git a/lib_com/options.h b/lib_com/options.h index 6b63e63f71..a5f837cacb 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,9 +159,7 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ -#ifdef MC_BITRATE_SWITCHING -#define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ -#endif + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index c8961f88dd..6ccb694517 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1891,7 +1891,7 @@ void tbe_celp_exc( return; } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING assert( bwe_exc != NULL && "BWE excitation is NULL" ); #endif diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index ef5dcc5771..8cf0dc6f52 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -50,11 +50,11 @@ /*-------------------------------------------------------------------* * ivas_corecoder_dec_reconfig() * - * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching + * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_dec_reconfig( -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ int16_t nCPE_old, /* i : number of CPEs in previous frame */ @@ -74,7 +74,7 @@ ivas_error ivas_corecoder_dec_reconfig( int16_t n, sce_id, cpe_id, output_frame; int16_t nSCE_existing, nCPE_existing; int32_t ivas_total_brate; -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING MC_MODE last_mc_mode; #endif DECODER_CONFIG_HANDLE hDecoderConfig; @@ -89,7 +89,7 @@ ivas_error ivas_corecoder_dec_reconfig( error = IVAS_ERR_OK; output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( st_ivas->ivas_format == MC_FORMAT ) { last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ @@ -104,7 +104,7 @@ ivas_error ivas_corecoder_dec_reconfig( *-----------------------------------------------------------------*/ /* remove dummy CPE element for DFT stereo-like upmix */ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) || ( st_ivas->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag ) ) #else @@ -126,7 +126,7 @@ ivas_error ivas_corecoder_dec_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( st_ivas->nchan_transport == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) #else if ( st_ivas->nchan_transport == nchan_transport_old ) @@ -134,7 +134,7 @@ ivas_error ivas_corecoder_dec_reconfig( { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hSCE[sce_id]->element_brate = brate_SCE; #else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; @@ -144,7 +144,7 @@ ivas_error ivas_corecoder_dec_reconfig( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; #else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -183,7 +183,7 @@ ivas_error ivas_corecoder_dec_reconfig( st_ivas->hCPE[cpe_id] = NULL; } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING /* the CPE-internal settings depend from ivas_format and mc_mode, so clean-up when switching between mc_modes */ if ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != last_mc_mode && ( st_ivas->mc_mode == MC_MODE_MCMASA || last_mc_mode == MC_MODE_MCMASA ) ) { @@ -210,7 +210,7 @@ ivas_error ivas_corecoder_dec_reconfig( for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hSCE[sce_id]->element_brate = brate_SCE; #else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; @@ -219,7 +219,7 @@ ivas_error ivas_corecoder_dec_reconfig( } for ( ; sce_id < st_ivas->nSCE; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) #else if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) @@ -231,7 +231,7 @@ ivas_error ivas_corecoder_dec_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; #else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -244,7 +244,7 @@ ivas_error ivas_corecoder_dec_reconfig( } for ( ; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) #else if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) @@ -301,7 +301,7 @@ ivas_error ivas_corecoder_dec_reconfig( } /* create dummy CPE element for DFT stereo-like upmix */ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ) #else diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index e8da2b8e48..4bdac66dcd 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -535,7 +535,7 @@ ivas_error ivas_cpe_dec( for ( i = 0; i < n; i++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate.cpe", 0, cpe_id, DEC ) ); dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode.cpe", 0, cpe_id, DEC ) ); #else diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 3d4fc869fe..8e7e87422d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1056,7 +1056,7 @@ ivas_error ivas_init_decoder( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING int32_t brate_sce, brate_cpe; #endif @@ -1096,13 +1096,13 @@ ivas_error ivas_init_decoder( } } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #endif for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { return error; @@ -1129,7 +1129,7 @@ ivas_error ivas_init_decoder( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 7b7cf935a4..6cb09653f3 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -40,7 +40,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. #endif #include "wmops.h" -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING /*------------------------------------------------------------------------- * Local constants diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index cbea498d79..5e8d9a73b6 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -643,20 +643,15 @@ ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { -#ifdef MCMASA_BITRATE_SWITCHING int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; - MC_MODE last_mc_mode; /* last frame MC mode */ -#else - int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old; -#endif int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i; + int32_t new_brate_SCE, new_brate_CPE; RENDERER_TYPE renderer_type_old; ivas_error error; - MC_MODE mc_mode; -#ifdef MCMASA_BITRATE_SWITCHING - int32_t new_brate_SCE, new_brate_CPE; + MC_MODE mc_mode, last_mc_mode; + last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ -#endif + error = IVAS_ERR_OK; nchan_transport_old = st_ivas->nchan_transport; @@ -672,7 +667,6 @@ ivas_error ivas_mc_dec_reconfig( nCPE_old = st_ivas->nCPE; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; -#ifdef MCMASA_BITRATE_SWITCHING /* special handling needed for the hp20 buffers for McMASA */ if ( last_mc_mode == MC_MODE_MCMASA ) { @@ -683,7 +677,7 @@ ivas_error ivas_mc_dec_reconfig( nchan_hp20_old = nchan_transport_old; } st_ivas->sba_dirac_stereo_flag = 0; /* needs to be after getNumChanSynthesis() */ -#endif + /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); @@ -777,9 +771,7 @@ ivas_error ivas_mc_dec_reconfig( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { -#ifdef MCMASA_BITRATE_SWITCHING ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), st_ivas->hDecoderConfig->ivas_total_brate ); -#endif if ( last_mc_mode != MC_MODE_MCMASA ) { @@ -787,20 +779,12 @@ ivas_error ivas_mc_dec_reconfig( { return error; } - -#ifndef MCMASA_BITRATE_SWITCHING - if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#else } if ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#endif + /* ls conversion */ if ( st_ivas->hLsSetUpConversion != NULL ) { @@ -829,7 +813,6 @@ ivas_error ivas_mc_dec_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING if ( st_ivas->mc_mode != MC_MODE_MCMASA ) { if ( st_ivas->nchan_transport == 1 ) @@ -841,16 +824,6 @@ ivas_error ivas_mc_dec_reconfig( st_ivas->element_mode_init = IVAS_CPE_MDCT; } } -#else - if ( st_ivas->nchan_transport == 1 ) - { - st_ivas->element_mode_init = IVAS_SCE; - } - else - { - st_ivas->element_mode_init = IVAS_CPE_MDCT; - } -#endif /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 @@ -889,7 +862,6 @@ ivas_error ivas_mc_dec_reconfig( st->mct_chan_mode = MCT_CHAN_MODE_LFE; } -#ifdef MCMASA_BITRATE_SWITCHING if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { uint8_t separateChannelEnabled; @@ -908,19 +880,12 @@ ivas_error ivas_mc_dec_reconfig( new_brate_CPE = ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; } if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ) ) != IVAS_ERR_OK ) -#endif { return error; } /* re-configure hp20 memories */ -#ifdef MCMASA_BITRATE_SWITCHING ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); -#else - ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); -#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -950,7 +915,6 @@ ivas_error ivas_mc_dec_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING if ( ( last_mc_mode == MC_MODE_MCMASA ) && ( nchan_transport_old == 1 ) && ( ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM ) || ( renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) ) { /* cldfbAnaDec[1] might be modified by DirAC (ivas_dirac_dec_binaural_internal) -> re-instantiate it */ @@ -964,7 +928,7 @@ ivas_error ivas_mc_dec_reconfig( } } } -#endif + /* Synthesis */ if ( numCldfbSyntheses_old > numCldfbSyntheses ) { @@ -1005,7 +969,6 @@ ivas_error ivas_mc_dec_reconfig( } /* renderers */ -#ifdef MCMASA_BITRATE_SWITCHING if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { if ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) ) @@ -1033,7 +996,6 @@ ivas_error ivas_mc_dec_reconfig( st_ivas->hDirAC = NULL; } } -#endif if ( renderer_type_old != st_ivas->renderer_type ) { @@ -1056,7 +1018,7 @@ ivas_error ivas_mc_dec_reconfig( { ivas_td_binaural_close( &st_ivas->hBinRendererTd ); } -#ifdef MCMASA_BITRATE_SWITCHING + if ( st_ivas->hDiracDecBin != NULL ) { if ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) @@ -1073,12 +1035,7 @@ ivas_error ivas_mc_dec_reconfig( } } } -#else - 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 ); - } -#endif + /* init necessary new renderers */ if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 08d263e8ac..e9236eb4a5 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -605,7 +605,7 @@ ivas_error ivas_sba_dec_reconfigure( *-----------------------------------------------------------------*/ #ifdef CORECODER_BITRATE_SWITCHING -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); #else ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old ); diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index fcc5cc8985..25299bfbeb 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -285,7 +285,7 @@ ivas_error ivas_sce_dec( for ( i = 0; i < n; i++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate.sce", 0, sce_id, DEC ) ); dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode.sce", 0, sce_id, DEC ) ); #else diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 371a376007..38f6a0c34a 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -51,7 +51,7 @@ *-------------------------------------------------------------------*/ ivas_error ivas_corecoder_enc_reconfig( -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ const int16_t nCPE_old, /* i : number of CPEs in previous frame */ @@ -73,7 +73,7 @@ ivas_error ivas_corecoder_enc_reconfig( BSTR_ENC_HANDLE hBstr, hMetaData; Indice *ind_list, *ind_list_metadata; int16_t nb_bits_tot, next_ind, last_ind; -#ifndef MCMASA_BITRATE_SWITCHING +#ifndef MC_BITRATE_SWITCHING int32_t ivas_total_brate; #endif ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -84,7 +84,7 @@ ivas_error ivas_corecoder_enc_reconfig( *-----------------------------------------------------------------*/ hEncoderConfig = st_ivas->hEncoderConfig; -#ifndef MCMASA_BITRATE_SWITCHING +#ifndef MC_BITRATE_SWITCHING ivas_total_brate = hEncoderConfig->ivas_total_brate; #endif error = IVAS_ERR_OK; @@ -98,7 +98,7 @@ ivas_error ivas_corecoder_enc_reconfig( /*-----------------------------------------------------------------* * Switching between SCE(s)/CPE(s)/MCT *-----------------------------------------------------------------*/ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( st_ivas->nchan_transport == nchan_transport_old && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) /* in McMASA, nchan_transport may be the same, but nSCE/nCPE differs */ #else if ( st_ivas->nchan_transport == nchan_transport_old ) @@ -107,7 +107,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hSCE[sce_id]->element_brate = brate_SCE; #else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; @@ -117,7 +117,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; #else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -141,7 +141,7 @@ ivas_error ivas_corecoder_enc_reconfig( } else { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING int16_t nchan_transport_real, nchan_transport_old_real; if ( last_mc_mode == MC_MODE_MCMASA ) { @@ -195,7 +195,7 @@ ivas_error ivas_corecoder_enc_reconfig( last_ind = hBstr->last_ind; ind_list_metadata = hMetaData->ind_list; /* pointer to the beginning of the global list */ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) { /* within McMASA we can modify the transport signals when switching */ @@ -274,7 +274,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hSCE[sce_id]->element_brate = brate_SCE; #else st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; @@ -284,7 +284,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) #else if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) @@ -325,7 +325,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->element_brate = brate_CPE; #else st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; @@ -336,7 +336,7 @@ ivas_error ivas_corecoder_enc_reconfig( copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) { @@ -354,7 +354,7 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; @@ -379,7 +379,7 @@ ivas_error ivas_corecoder_enc_reconfig( /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) #else @@ -404,7 +404,7 @@ ivas_error ivas_corecoder_enc_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) { /* restore modified transport signal */ @@ -473,7 +473,7 @@ ivas_error ivas_corecoder_enc_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata + st_ivas->nSCE * MAX_NUM_INDICES; #else st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index dbc5f44a25..566452cac9 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -420,7 +420,7 @@ ivas_error ivas_cpe_enc( { dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, fname( debug_dir, "input_DMX", n, sts[n]->id_element, ENC ) ); } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode.cpe", 0, sts[0]->id_element, ENC ) ); #else dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, sts[0]->id_element, ENC ) ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index e64c4e058b..a29ee297cb 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -617,7 +617,7 @@ ivas_error ivas_init_encoder( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING int32_t brate_sce, brate_cpe; #endif @@ -638,13 +638,13 @@ ivas_error ivas_init_encoder( return error; } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #endif for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { return error; @@ -676,7 +676,7 @@ ivas_error ivas_init_encoder( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index e79ac261ca..40f2ec4478 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -395,7 +395,7 @@ ivas_error ivas_mcmasa_enc_open( return error; } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING /*------------------------------------------------------------------------- * ivas_mcmasa_enc_reconfig() * @@ -1189,7 +1189,7 @@ void ivas_mcmasa_param_est_enc( return; } -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format. TODO: buffer size into define? */ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index fde460e738..d21241f92e 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -602,9 +602,7 @@ ivas_error ivas_mc_enc_reconfig( { int16_t nchan_transport_old, nSCE_old, nCPE_old; ivas_error error; -#ifdef MCMASA_BITRATE_SWITCHING int32_t new_brate_SCE, new_brate_CPE; -#endif error = IVAS_ERR_OK; @@ -699,17 +697,10 @@ ivas_error ivas_mc_enc_reconfig( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { -#ifdef MCMASA_BITRATE_SWITCHING if ( last_mc_mode != MC_MODE_MCMASA ) { ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); -#else - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); - - if ( last_mc_mode != MC_MODE_MCMASA ) - { -#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -725,8 +716,6 @@ ivas_error ivas_mc_enc_reconfig( return error; } } - -#ifdef MCMASA_BITRATE_SWITCHING else { /* reconfigure McMASA instance */ @@ -735,7 +724,6 @@ ivas_error ivas_mc_enc_reconfig( return error; } } -#endif if ( st_ivas->hParamMC != NULL ) { @@ -758,7 +746,6 @@ ivas_error ivas_mc_enc_reconfig( } } -#ifdef MCMASA_BITRATE_SWITCHING if ( st_ivas->mc_mode != MC_MODE_MCMASA ) { if ( st_ivas->nchan_transport == 1 ) @@ -770,16 +757,6 @@ ivas_error ivas_mc_enc_reconfig( st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } } -#else - if ( st_ivas->nchan_transport == 1 ) - { - st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; - } - else - { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; - } -#endif /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 @@ -824,7 +801,6 @@ ivas_error ivas_mc_enc_reconfig( st->mct_chan_mode = MCT_CHAN_MODE_LFE; } -#ifdef MCMASA_BITRATE_SWITCHING if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); @@ -841,9 +817,6 @@ ivas_error ivas_mc_enc_reconfig( } if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 397a04e4a4..f704205690 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -272,7 +272,7 @@ ivas_error ivas_sba_enc_reconfigure( * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ); #else ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index bd460c038c..cb987263be 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -178,7 +178,7 @@ ivas_error ivas_sce_enc( #ifdef DEBUG_MODE_INFO dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" ); -#ifdef MCMASA_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode.sce", 0, st->id_element, ENC ) ); #else dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) ); -- GitLab From 9bf05375da7cb9c13bcefc94eaf70cad42ba24e9 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 8 Dec 2022 11:31:57 +0100 Subject: [PATCH 21/42] make sure the check for the eid-xor binary also works on Windows --- scripts/pyivastest/IvasScriptsCommon.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/pyivastest/IvasScriptsCommon.py b/scripts/pyivastest/IvasScriptsCommon.py index 46e6a2f4a8..b8dba704e8 100644 --- a/scripts/pyivastest/IvasScriptsCommon.py +++ b/scripts/pyivastest/IvasScriptsCommon.py @@ -546,7 +546,10 @@ def runner_setup(runner, args): if "fer_file" in args.keys() or "ber_file" in args.keys(): # assert that the eid-xor tool is there - eid_xor_path = os.path.join(runner.config["utilPath"], "eid-xor") + bin_ext="" + if platform.system() == "Windows": + bin_ext=".exe" + eid_xor_path = os.path.join(runner.config["utilPath"], "".join(["eid-xor", bin_ext])) if not os.path.isfile(eid_xor_path): raise FileNotFoundError(f"Could not find {eid_xor_path} (needed for error pattern insertion)") -- GitLab From f37006699e545f98b35f1a5aaaf30d0e8cee3a96 Mon Sep 17 00:00:00 2001 From: knj Date: Thu, 8 Dec 2022 12:38:44 +0100 Subject: [PATCH 22/42] add allocation handling for FD-CNG handle in MC bitrate switching --- lib_com/ivas_prot.h | 4 ++++ lib_com/options.h | 4 ++++ lib_dec/ivas_cpe_dec.c | 4 ++++ lib_dec/ivas_mct_dec.c | 3 +++ lib_dec/ivas_stat_dec.h | 3 +++ lib_dec/ivas_stereo_switching_dec.c | 33 +++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 15011077be..e36b1050fc 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2605,6 +2605,10 @@ ivas_error stereo_memory_dec( const int16_t nb_bits_metadata, /* i : number of metadata bits */ const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + const MC_MODE mc_mode, + const MC_MODE last_mc_mode, +#endif const int16_t nchan_transport /* i : number of transport channels */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 65819774ab..9e65dacc1f 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -161,6 +161,10 @@ #define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ +#ifdef MC_BITRATE_SWITCHING +#define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ +#endif +#define FIX_MC_BR_SW_TCX_PLC_FADEOUT /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index c6db847e8c..1ba39580c2 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -103,7 +103,11 @@ ivas_error ivas_cpe_dec( * dynamically allocate data structures depending on the actual stereo mode *----------------------------------------------------------------*/ +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->last_mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) +#else if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 5e8d9a73b6..9f5aea4aa8 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -606,6 +606,9 @@ ivas_error ivas_mc_dec_config( /* store last frame MC mode */ last_mc_mode = st_ivas->mc_mode; +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + st_ivas->last_mc_mode = last_mc_mode; +#endif if ( !st_ivas->bfi ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a18f826921..b5a1d16c28 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1946,6 +1946,9 @@ typedef struct Decoder_Struct ISM_MODE ism_mode; /* ISM format mode */ SBA_MODE sba_mode; /* SBA format mode */ MC_MODE mc_mode; /* MC format mode */ +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + MC_MODE last_mc_mode; +#endif int16_t sba_order; /* Ambisonic (SBA) order */ int16_t sba_planar; /* Ambisonic (SBA) planar flag */ int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 56c1cfef54..15056d5d0a 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -342,6 +342,10 @@ ivas_error stereo_memory_dec( const int16_t nb_bits_metadata, /* i : number of metadata bits */ const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + const MC_MODE mc_mode, + const MC_MODE last_mc_mode, +#endif const int16_t nchan_transport /* i : number of transport channels*/ ) { @@ -859,6 +863,35 @@ ivas_error stereo_memory_dec( } } +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + if ( ivas_format == MC_FORMAT && hCPE->element_mode == IVAS_CPE_MDCT && ( mc_mode != last_mc_mode ) ) + { + if ( mc_mode == MC_MODE_MCT ) + { + /* deallocate the FdCNG handle */ + for ( i = 0; i < CPE_CHANNELS; ++i ) + { + deleteFdCngDec( &hCPE->hCoreCoder[0]->hFdCngDec ); + } + } + else + { + /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ + for ( i = 0; i < CPE_CHANNELS; ++i ) + { + if ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) + { + if ( ( error = createFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ) ) != IVAS_ERR_OK ) + { + return error; + } + initFdCngDec( hCPE->hCoreCoder[i] ); + } + } + } + } +#endif + /*--------------------------------------------------------------* * Bitrate switching in MASA format *---------------------------------------------------------------*/ -- GitLab From 419faaf98dbbcab0f6f8a95e0cc82732416f24cf Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Fri, 9 Dec 2022 10:23:54 +0100 Subject: [PATCH 23/42] fixed FdCng handling fixed some problems when going from MCT->ParamMC with 4 TCs --- lib_com/options.h | 1 + lib_com/prot.h | 7 +++-- lib_dec/ivas_mct_dec.c | 47 ++++++++++++++++++++++++++++- lib_dec/ivas_stereo_switching_dec.c | 17 +++++++++-- lib_enc/amr_wb_enc.c | 6 ++++ lib_enc/evs_enc.c | 5 +++ lib_enc/ivas_core_enc.c | 18 ++++++++--- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_mct_enc.c | 8 ++++- lib_enc/updt_enc.c | 8 +++-- 10 files changed, 105 insertions(+), 14 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9e65dacc1f..0e88d45eb0 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,6 +165,7 @@ #define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ #endif #define FIX_MC_BR_SW_TCX_PLC_FADEOUT +#define FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 973f15ef5a..8d2561afe0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3916,8 +3916,11 @@ void updt_enc( ); void updt_enc_common( - Encoder_State *st, /* i/o: encoder state structure */ - const float Etot /* i : total energy */ + Encoder_State *st /* i/o: encoder state structure */ +#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + , + const float Etot /* i : total energy */ +#endif ); void updt_IO_switch_enc( diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 9f5aea4aa8..6fe468d954 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -643,7 +643,7 @@ ivas_error ivas_mc_dec_config( } #ifdef MC_BITRATE_SWITCHING ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; @@ -855,6 +855,34 @@ ivas_error ivas_mc_dec_reconfig( st->igf = 0; init_igf_dec( st->hIGFDec ); } + + if ( st->hHQ_core == NULL ) + { + + if ( ( st->hHQ_core = (HQ_DEC_HANDLE) count_malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); + } + + /* HQ core initialization */ + HQ_core_dec_init( st->hHQ_core ); + } + +#if 0 + if ( st->element_mode == EVS_MONO ) + { + /* HQ NB FEC initialization */ + if ( ( st->hHQ_nbfec = (HQ_NBFEC_HANDLE) count_malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); + } + HQ_nbfec_init( st->hHQ_nbfec ); + } + else + { + st->hHQ_nbfec = NULL; + } +#endif } else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) { @@ -887,6 +915,23 @@ ivas_error ivas_mc_dec_reconfig( return error; } + if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) + { + Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + +#if 1 + /* TCX-LTP */ + if ( st->hTcxLtpDec == NULL ) + { + if ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) count_malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TCX-LTP handle\n" ) ); + } + tcxltp_dec_init( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); + } +#endif + } + /* re-configure hp20 memories */ ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ); diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 15056d5d0a..823cf6455c 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -346,7 +346,7 @@ ivas_error stereo_memory_dec( const MC_MODE mc_mode, const MC_MODE last_mc_mode, #endif - const int16_t nchan_transport /* i : number of transport channels*/ + const int16_t nchan_transport /* i : number of transport channels*/ ) { DEC_CORE_HANDLE st; @@ -871,7 +871,12 @@ ivas_error stereo_memory_dec( /* deallocate the FdCNG handle */ for ( i = 0; i < CPE_CHANNELS; ++i ) { - deleteFdCngDec( &hCPE->hCoreCoder[0]->hFdCngDec ); + deleteFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ); + /* deallocate CLDFB synthesis for LFE channel */ + if ( hCPE->hCoreCoder[i]->mct_chan_mode == MCT_CHAN_MODE_LFE ) + { + deleteCldfb( &hCPE->hCoreCoder[i]->cldfbSyn ); + } } } else @@ -879,6 +884,14 @@ ivas_error stereo_memory_dec( /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ for ( i = 0; i < CPE_CHANNELS; ++i ) { + if ( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ + { + if ( ( error = openCldfb( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + if ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) { if ( ( error = createFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index c73e5a8949..2f8077ee45 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -536,7 +536,13 @@ void amr_wb_enc( updt_enc( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec paramaters */ +#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + st->hNoiseEst->Etot_last = Etot; + updt_enc_common( st ); +#else updt_enc_common( st, Etot ); +#endif + #ifdef DEBUG_MODE_INFO dbgwrite( &st->codec_mode, sizeof( int16_t ), 1, input_frame, "res/codec" ); diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index 29b610db79..9f54a68fd3 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -509,7 +509,12 @@ ivas_error evs_enc( * Updates *---------------------------------------------------------------------*/ +#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + st->hNoiseEst->Etot_last = Etot; + updt_enc_common( st ); +#else updt_enc_common( st, Etot ); +#endif if ( st->mdct_sw == MODE1 ) { diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index dc3247cbfb..2b87a966cd 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -405,11 +405,19 @@ ivas_error ivas_core_enc( signaling_enc_rf( st ); - /*---------------------------------------------------------------------* - * Common updates - *---------------------------------------------------------------------*/ - - updt_enc_common( st, Etot[n] ); +/*---------------------------------------------------------------------* + * Common updates + *---------------------------------------------------------------------*/ +#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ + if ( !MCT_flag ) + { + st->hNoiseEst->Etot_last = Etot[n]; + updt_enc_common( st ); + } +#else + updt_enc_common( st, Etot ); +#endif } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c3a4c194bd..0f29155095 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -52,7 +52,7 @@ *-------------------------------------------------------------------*/ ivas_error ivas_cpe_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ const float data_f_ch0[], /* i : input signal for channel 0 */ const float data_f_ch1[], /* i : input signal for channel 1 */ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index bff607e1d3..756d99d501 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -189,6 +189,10 @@ ivas_error ivas_mct_enc( for ( n = 0; n < CPE_CHANNELS; n++ ) { mvr2r( hCPE->hCoreCoder[n]->input, hCPE->hCoreCoder[n]->old_input_signal, input_frame ); +#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + /* common encoder updates */ + updt_enc_common( hCPE->hCoreCoder[n] ); +#endif } } @@ -772,6 +776,8 @@ ivas_error ivas_mc_enc_reconfig( } } st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode, st->mct_chan_mode ); + /* set last core to TCX20 */ + st->last_core = TCX_20_CORE; } else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) { @@ -789,7 +795,7 @@ ivas_error ivas_mc_enc_reconfig( else if ( st_ivas->mc_mode == MC_MODE_MCT ) { new_brate_SCE = 0; - new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / (st_ivas->nchan_transport -1)) * CPE_CHANNELS; + new_brate_CPE = ( st_ivas->hEncoderConfig->ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; } else { diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index c6663895e0..9d68deb68d 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -297,8 +297,10 @@ void updt_IO_switch_enc( *-------------------------------------------------------------------*/ void updt_enc_common( - Encoder_State *st, /* i/o: encoder state structure */ - const float Etot /* i : total energy */ + Encoder_State *st /* i/o: encoder state structure */ +#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + ,const float Etot /* i : total energy */ +#endif ) { /*---------------------------------------------------------------------* @@ -316,7 +318,9 @@ void updt_enc_common( st->last_extl = st->extl; st->last_input_bwidth = st->input_bwidth; st->last_bwidth = st->bwidth; +#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON st->hNoiseEst->Etot_last = Etot; +#endif st->last_coder_type_raw = st->coder_type_raw; if ( st->core_brate > SID_2k40 && st->hDtxEnc != NULL ) -- GitLab From 6f134ab774a9cfb02db90c0305cc0c14560c14c6 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 12 Dec 2022 13:51:32 +0100 Subject: [PATCH 24/42] small fix for the MCT encoder common update fix fix MCT->ParamMC switch, TNS flag in the decoder TCX cfg was not set correctly --- lib_dec/ivas_mct_dec.c | 23 ++++------------------- lib_enc/ivas_core_enc.c | 2 +- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 6fe468d954..154275eba4 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -831,8 +831,7 @@ ivas_error ivas_mc_dec_reconfig( /* re-configure core coder*/ /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 and might have IGF static memory not allocated and the bit stream index list not set, - set correct mct_chan_mode and init missing static mem - do it here since it is _very_ MC specific */ + set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ if ( last_mc_mode == MC_MODE_MCT && st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->nchan_transport > CPE_CHANNELS ) { Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; @@ -868,21 +867,8 @@ ivas_error ivas_mc_dec_reconfig( HQ_core_dec_init( st->hHQ_core ); } -#if 0 - if ( st->element_mode == EVS_MONO ) - { - /* HQ NB FEC initialization */ - if ( ( st->hHQ_nbfec = (HQ_NBFEC_HANDLE) count_malloc( sizeof( HQ_NBFEC_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ NB FEC\n" ) ); - } - HQ_nbfec_init( st->hHQ_nbfec ); - } - else - { - st->hHQ_nbfec = NULL; - } -#endif + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st_ivas->hDecoderConfig->ivas_total_brate, st->igf, st->element_mode, st->mct_chan_mode ); + } else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) { @@ -891,6 +877,7 @@ ivas_error ivas_mc_dec_reconfig( #endif Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; st->mct_chan_mode = MCT_CHAN_MODE_LFE; + st->hTcxCfg->fIsTNSAllowed = 0; } if ( st_ivas->mc_mode == MC_MODE_MCMASA ) @@ -919,7 +906,6 @@ ivas_error ivas_mc_dec_reconfig( { Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; -#if 1 /* TCX-LTP */ if ( st->hTcxLtpDec == NULL ) { @@ -929,7 +915,6 @@ ivas_error ivas_mc_dec_reconfig( } tcxltp_dec_init( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); } -#endif } /* re-configure hp20 memories */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 2b87a966cd..b7d228c4ac 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -410,9 +410,9 @@ ivas_error ivas_core_enc( *---------------------------------------------------------------------*/ #ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ + st->hNoiseEst->Etot_last = Etot[n]; if ( !MCT_flag ) { - st->hNoiseEst->Etot_last = Etot[n]; updt_enc_common( st ); } #else -- GitLab From 994b719b30191cf68e5c0ec298ae7a46a6244bf0 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Mon, 12 Dec 2022 16:15:55 +0100 Subject: [PATCH 25/42] fix LS conversion --- lib_dec/ivas_mct_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 154275eba4..36d9319b93 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -684,6 +684,7 @@ ivas_error ivas_mc_dec_reconfig( /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); if ( st_ivas->mc_mode == MC_MODE_MCT ) { -- GitLab From ff4d60eef601360be01c2a03ec3fab544604554a Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Mon, 12 Dec 2022 16:36:57 +0100 Subject: [PATCH 26/42] force internal config re-init in MC bitrate switching. this fixes crashes with BINAURAL output --- lib_dec/ivas_mcmasa_dec.c | 6 ------ lib_dec/ivas_mct_dec.c | 4 +++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 6cb09653f3..78201baa2d 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -73,12 +73,6 @@ ivas_error ivas_mcmasa_dec_reconfig( /* get new McMASA settings */ ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); - - /* renderer might change as an effect from the transport mode change */ - ivas_renderer_select( st_ivas ); - - /* side effect of the renderer selection can be a changed internal config. this is also needed when switching from non-McMASA */ - ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 154275eba4..eef2aed46f 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -681,9 +681,11 @@ ivas_error ivas_mc_dec_reconfig( } st_ivas->sba_dirac_stereo_flag = 0; /* needs to be after getNumChanSynthesis() */ - /* renderer might have changed, reselect */ + /* renderer might change as an effect from the transport mode change, reselect */ renderer_type_old = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); + /* side effect of the renderer selection can be a changed internal config */ + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); if ( st_ivas->mc_mode == MC_MODE_MCT ) { -- GitLab From e0b88d2f412fbdb0d731f504fe55b23a1d6d9c06 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 14:24:07 +0100 Subject: [PATCH 27/42] editorial changes + fix MSVC compilation warnings --- lib_com/ivas_prot.h | 12 +++--------- lib_com/options.h | 2 -- lib_dec/ivas_ism_param_dec.c | 4 ++-- lib_dec/ivas_mct_dec.c | 5 +++-- lib_enc/ivas_corecoder_enc_reconfig.c | 2 ++ lib_enc/ivas_mcmasa_enc.c | 4 ++-- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8ad76d303a..28f14bdd58 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -346,8 +346,8 @@ void ivas_mct_dec_close( ivas_error ivas_corecoder_dec_reconfig( #ifdef MC_BITRATE_SWITCHING - const int16_t nSCE_old, /* i : number of SCEs in previous frame */ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSCE_old, /* i : number of SCEs in previous frame */ int16_t nCPE_old, /* i : number of CPEs in previous frame */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ const int16_t sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ @@ -650,12 +650,6 @@ ivas_error ivas_mc_dec_config( const int16_t idx /* i : LS config. index */ ); -#ifdef MC_BITRATE_SWITCHING -ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); -#endif - /*! r: MC format mode (MCT, McMASA, ParamMC) */ MC_MODE ivas_mc_mode_select( const MC_LS_SETUP mc_ls_setup, /* i : loudspeaker setup (CICP) */ @@ -4906,8 +4900,8 @@ void ivas_mcmasa_param_est_enc( void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ - const uint8_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ - const uint8_t n_chnls_dmx_new /* i : number of downmix channels in the target format */ + const int16_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ + const int16_t n_chnls_dmx_new /* i : number of downmix channels in the target format */ ); #endif diff --git a/lib_com/options.h b/lib_com/options.h index 0e88d45eb0..6b0fcbd217 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,9 +158,7 @@ -#define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ - #ifdef MC_BITRATE_SWITCHING #define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ #endif diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 9a75eed42e..aa2fcaed6b 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1025,7 +1025,7 @@ static ivas_error ivas_ism_bitrate_switching( error = IVAS_ERR_OK; - #ifdef MC_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; #endif @@ -1033,7 +1033,7 @@ static ivas_error ivas_ism_bitrate_switching( ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); st_ivas->nSCE = st_ivas->nchan_transport; - #ifdef MC_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, 0, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ); #else ivas_corecoder_dec_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old, 0 ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 58b1bfeaa3..3f3fdcd6d4 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -54,7 +54,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, const int16_t last_mc_mode ); +static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas ); #endif @@ -900,7 +900,8 @@ static ivas_error ivas_mc_dec_reconfig( #ifdef DEBUGGING assert( st_ivas->hCPE[1] != NULL ); #endif - st_ivas->hCPE[1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_LFE; + Decoder_State *st = st_ivas->hCPE[1]->hCoreCoder[1]; + st->mct_chan_mode = MCT_CHAN_MODE_LFE; st->hTcxCfg->fIsTNSAllowed = 0; } diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 243e2b9278..0e89a6fbaa 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -199,6 +199,7 @@ ivas_error ivas_corecoder_enc_reconfig( set_zero( input_buff[0], len_inp_memory ); mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); } + for ( n = 0; n < CPE_CHANNELS; n++ ) { set_zero( input_buff[n + 1], len_inp_memory ); @@ -207,6 +208,7 @@ ivas_error ivas_corecoder_enc_reconfig( mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); } } + ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); n_CoreCoder_existing = 0; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 2179e15cb4..e0d9bb970c 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -1207,8 +1207,8 @@ void ivas_mcmasa_param_est_enc( void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format. TODO: buffer size into define? */ - const uint8_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ - const uint8_t n_chnls_dmx_new ) /* i : number of downmix channels in the target format */ + const int16_t n_chnls_dmx_old, /* i : number of downmix channels in the old format */ + const int16_t n_chnls_dmx_new ) /* i : number of downmix channels in the target format */ { /* assumed data ordering in **dmx: [sce][cpe_chnl0][cpe_chnl1], i.e., [c][l][r] */ int16_t i; -- GitLab From 8e4d31c0bea704b59fb5a470e1047eb61d059630 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 14:48:57 +0100 Subject: [PATCH 28/42] clang-format --- lib_com/ivas_mcmasa_com.c | 4 ++-- lib_dec/ivas_mc_param_dec.c | 2 +- lib_enc/ivas_mcmasa_enc.c | 2 +- lib_enc/updt_enc.c | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c index fdf28c3be5..4c0f014bb0 100644 --- a/lib_com/ivas_mcmasa_com.c +++ b/lib_com/ivas_mcmasa_com.c @@ -107,11 +107,11 @@ int32_t ivas_mcmasa_mono_brate( /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */ if ( ivas_total_brate < IVAS_96k ) { - return (const int32_t) ( MCMASA_MONOBITRATIO_64k * ivas_total_brate ); + return (int32_t) ( MCMASA_MONOBITRATIO_64k * ivas_total_brate ); } else { - return (const int32_t) ( MCMASA_MONOBITRATIO * ivas_total_brate ); + return (int32_t) ( MCMASA_MONOBITRATIO * ivas_total_brate ); } } #else diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4a48e311de..2aff668e02 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -433,7 +433,7 @@ ivas_error ivas_param_mc_dec_open( /*------------------------------------------------------------------------- * ivas_param_mc_get_param_band_mapping() * - * + * *-------------------------------------------------------------------------*/ static void ivas_param_mc_get_param_band_mapping( diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index e0d9bb970c..4622864e08 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -1200,7 +1200,7 @@ void ivas_mcmasa_param_est_enc( /*--------------------------------------------------------------------------* * ivas_mcmasa_dmx_modify() * - * + * *--------------------------------------------------------------------------*/ #ifdef MC_BITRATE_SWITCHING diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index 9d68deb68d..cd9b3b0ef0 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -299,7 +299,8 @@ void updt_IO_switch_enc( void updt_enc_common( Encoder_State *st /* i/o: encoder state structure */ #ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON - ,const float Etot /* i : total energy */ + , + const float Etot /* i : total energy */ #endif ) { -- GitLab From 0efede34d95b583ea7c110cf2d4e35c930518111 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 15:04:21 +0100 Subject: [PATCH 29/42] more VE: comments --- lib_dec/ivas_stat_dec.h | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index b5a1d16c28..2380601584 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1947,7 +1947,7 @@ typedef struct Decoder_Struct SBA_MODE sba_mode; /* SBA format mode */ MC_MODE mc_mode; /* MC format mode */ #ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - MC_MODE last_mc_mode; + MC_MODE last_mc_mode; // !!! VE: could it be removed and get from ivas_mc_mode_select() in ivas_cpe_dec() ? #endif int16_t sba_order; /* Ambisonic (SBA) order */ int16_t sba_planar; /* Ambisonic (SBA) planar flag */ diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 0e89a6fbaa..ce32840095 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -353,7 +353,7 @@ ivas_error ivas_corecoder_enc_reconfig( #ifdef MC_BITRATE_SWITCHING if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled ) { - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; // !!! VE: can it be set in McMASA config module rather than here? } if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) #else -- GitLab From 61121c63a1ba1144afc15ca41bdf5ea1f76018f4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 15:56:52 +0100 Subject: [PATCH 30/42] - add MC_BITRATE_SWITCHING_CLDFB --- lib_com/options.h | 2 ++ lib_dec/ivas_mct_dec.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index a0472513c9..8e746f2e15 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,10 +169,12 @@ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ #ifdef MC_BITRATE_SWITCHING #define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ +#define MC_BITRATE_SWITCHING_CLDFB #endif #define FIX_MC_BR_SW_TCX_PLC_FADEOUT #define FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 3f3fdcd6d4..55acccdb03 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -665,7 +665,11 @@ static ivas_error ivas_mc_dec_reconfig( ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; +#ifdef MC_BITRATE_SWITCHING_CLDFB + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; +#else int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i; +#endif int32_t new_brate_SCE, new_brate_CPE; RENDERER_TYPE renderer_type_old; ivas_error error; @@ -949,6 +953,30 @@ static ivas_error ivas_mc_dec_reconfig( * CLDFB instances *-----------------------------------------------------------------*/ +#ifdef MC_BITRATE_SWITCHING_CLDFB + ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); + + // !!! VE: what is the following block needed for? + if ( last_mc_mode == MC_MODE_MCMASA && nchan_transport_old == 1 && ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM || renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) + { + int16_t numCldfbAnalyses, numCldfbSyntheses; + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); + + /* cldfbAnaDec[1] might be modified by DirAC (ivas_dirac_dec_binaural_internal) -> re-instantiate it */ + if ( numCldfbAnalyses_old > 1 && numCldfbAnalyses > 1 ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); + st_ivas->cldfbAnaDec[1] = NULL; + + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[1] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#else + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); /* Analysis*/ @@ -1008,6 +1036,7 @@ static ivas_error ivas_mc_dec_reconfig( } } } +#endif /*-----------------------------------------------------------------* * Allocate the LFE handle that is coded seperately after the allocation of the core coders -- GitLab From c2f0326cfa9898c3ccd82f67e01c11e18e5254e0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 16:04:38 +0100 Subject: [PATCH 31/42] remove leftover in options.h --- lib_com/options.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8e746f2e15..32cc5cdad1 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,10 +167,7 @@ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ -#ifdef MC_BITRATE_SWITCHING -#define MCMASA_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format: sub-part of McMASA modes */ #define MC_BITRATE_SWITCHING_CLDFB -#endif #define FIX_MC_BR_SW_TCX_PLC_FADEOUT #define FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON -- GitLab From 5d3931b70ee7aae9a3bbcebe74171c6ae4ee2893 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Dec 2022 16:23:15 +0100 Subject: [PATCH 32/42] remove parameter 'st_ivas->last_mc_mode' which was obsolete and uninitialized in non-MC cases anyway --- lib_com/ivas_prot.h | 3 +- lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_mct_dec.c | 6 +- lib_dec/ivas_stat_dec.h | 3 - lib_dec/ivas_stereo_switching_dec.c | 92 +++++++++++++++-------------- 5 files changed, 51 insertions(+), 55 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5872003cd8..7f3005d077 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2594,8 +2594,7 @@ ivas_error stereo_memory_dec( const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ #ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - const MC_MODE mc_mode, - const MC_MODE last_mc_mode, + const MC_MODE mc_mode, /* i : MC mode */ #endif const int16_t nchan_transport /* i : number of transport channels */ ); diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index c8adbeb7cc..8212ccac62 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -104,7 +104,7 @@ ivas_error ivas_cpe_dec( *----------------------------------------------------------------*/ #ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->last_mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) #else if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 55acccdb03..d1c074381d 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -616,9 +616,6 @@ ivas_error ivas_mc_dec_config( /* store last frame MC mode */ last_mc_mode = st_ivas->mc_mode; -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - st_ivas->last_mc_mode = last_mc_mode; -#endif if ( !st_ivas->bfi ) { @@ -957,7 +954,7 @@ static ivas_error ivas_mc_dec_reconfig( ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); // !!! VE: what is the following block needed for? - if ( last_mc_mode == MC_MODE_MCMASA && nchan_transport_old == 1 && ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM || renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) + if ( ( last_mc_mode == MC_MODE_MCMASA ) && ( nchan_transport_old == 1 ) && ( ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM ) || ( renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) ) { int16_t numCldfbAnalyses, numCldfbSyntheses; @@ -976,7 +973,6 @@ static ivas_error ivas_mc_dec_reconfig( } } #else - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); /* Analysis*/ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2380601584..a18f826921 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1946,9 +1946,6 @@ typedef struct Decoder_Struct ISM_MODE ism_mode; /* ISM format mode */ SBA_MODE sba_mode; /* SBA format mode */ MC_MODE mc_mode; /* MC format mode */ -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - MC_MODE last_mc_mode; // !!! VE: could it be removed and get from ivas_mc_mode_select() in ivas_cpe_dec() ? -#endif int16_t sba_order; /* Ambisonic (SBA) order */ int16_t sba_planar; /* Ambisonic (SBA) planar flag */ int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 823cf6455c..a9f24a707a 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -343,8 +343,7 @@ ivas_error stereo_memory_dec( const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ #ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - const MC_MODE mc_mode, - const MC_MODE last_mc_mode, + const MC_MODE mc_mode, /* i : MC mode */ #endif const int16_t nchan_transport /* i : number of transport channels*/ ) @@ -863,48 +862,6 @@ ivas_error stereo_memory_dec( } } -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT - if ( ivas_format == MC_FORMAT && hCPE->element_mode == IVAS_CPE_MDCT && ( mc_mode != last_mc_mode ) ) - { - if ( mc_mode == MC_MODE_MCT ) - { - /* deallocate the FdCNG handle */ - for ( i = 0; i < CPE_CHANNELS; ++i ) - { - deleteFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ); - /* deallocate CLDFB synthesis for LFE channel */ - if ( hCPE->hCoreCoder[i]->mct_chan_mode == MCT_CHAN_MODE_LFE ) - { - deleteCldfb( &hCPE->hCoreCoder[i]->cldfbSyn ); - } - } - } - else - { - /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ - for ( i = 0; i < CPE_CHANNELS; ++i ) - { - if ( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ - { - if ( ( error = openCldfb( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) - { - if ( ( error = createFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ) ) != IVAS_ERR_OK ) - { - return error; - } - initFdCngDec( hCPE->hCoreCoder[i] ); - } - } - } - } -#endif - /*--------------------------------------------------------------* * Bitrate switching in MASA format *---------------------------------------------------------------*/ @@ -990,6 +947,53 @@ ivas_error stereo_memory_dec( } } +#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT + /*--------------------------------------------------------------* + * Bitrate switching in MASA format + *---------------------------------------------------------------*/ + + if ( ivas_format == MC_FORMAT && hCPE->element_mode == IVAS_CPE_MDCT ) + { + if ( mc_mode == MC_MODE_MCT ) + { + /* deallocate the FdCNG handle */ + for ( i = 0; i < CPE_CHANNELS; ++i ) + { + deleteFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ); + + /* deallocate CLDFB synthesis for LFE channel */ + if ( hCPE->hCoreCoder[i]->mct_chan_mode == MCT_CHAN_MODE_LFE ) + { + deleteCldfb( &hCPE->hCoreCoder[i]->cldfbSyn ); + } + } + } + else + { + /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ + for ( i = 0; i < CPE_CHANNELS; ++i ) + { + if ( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ + { + if ( ( error = openCldfb( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) + { + if ( ( error = createFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ) ) != IVAS_ERR_OK ) + { + return error; + } + initFdCngDec( hCPE->hCoreCoder[i] ); + } + } + } + } +#endif + return error; } -- GitLab From 91c18871f84bfcaa54f1a69b25a76286398503be Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Tue, 13 Dec 2022 17:21:58 +0100 Subject: [PATCH 33/42] fix MSAN error at encoder side --- lib_enc/ivas_corecoder_enc_reconfig.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index ce32840095..668eea8318 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -519,6 +519,9 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } +#ifdef DEBUGGING + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl; +#endif initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } -- GitLab From dc15b13ac8cfc3279c36161d3841c0b6709cc319 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 14 Dec 2022 10:07:38 +0100 Subject: [PATCH 34/42] remove unnecessary cldfbAnaDec[1] reinstantiation under certain McMASA conditions as this is now handled by ivas_cldfb_dec_reconfig(). bugfix: McMASA reconfig needs to run renderer selection and internal config init extra since they depend from transport settings modified in the function. --- lib_dec/ivas_mcmasa_dec.c | 4 ++++ lib_dec/ivas_mct_dec.c | 19 ------------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 9df6756de7..83e226f0a0 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -66,6 +66,10 @@ ivas_error ivas_mcmasa_dec_reconfig( /* get new McMASA settings */ ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); + /* transport channel settings may affect renderer */ + ivas_renderer_select( st_ivas ); + /* renderer change may affect internal config */ + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index d1c074381d..b5476574cc 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -953,25 +953,6 @@ static ivas_error ivas_mc_dec_reconfig( #ifdef MC_BITRATE_SWITCHING_CLDFB ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); - // !!! VE: what is the following block needed for? - if ( ( last_mc_mode == MC_MODE_MCMASA ) && ( nchan_transport_old == 1 ) && ( ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC ) || ( renderer_type_old == RENDERER_BINAURAL_PARAMETRIC_ROOM ) || ( renderer_type_old == RENDERER_STEREO_PARAMETRIC ) ) ) - { - int16_t numCldfbAnalyses, numCldfbSyntheses; - - ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); - - /* cldfbAnaDec[1] might be modified by DirAC (ivas_dirac_dec_binaural_internal) -> re-instantiate it */ - if ( numCldfbAnalyses_old > 1 && numCldfbAnalyses > 1 ) - { - deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); - st_ivas->cldfbAnaDec[1] = NULL; - - if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[1] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } #else ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); -- GitLab From 5dae3704ac8707a3d4f4736952a5a9980cf36fbb Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Wed, 14 Dec 2022 11:07:53 +0100 Subject: [PATCH 35/42] address VE comment in init_dec.c, only allocate additional TcxCfg for the LFE channel in MCT, and not for the second channel in DFT/TD stereo --- lib_dec/init_dec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 205e76765d..b311c109c2 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -613,22 +613,23 @@ ivas_error init_decoder( } /* TCX config. data structure */ -#ifndef MC_BITRATE_SWITCHING // !!! VE: this does not seem to be correct for DFT/TD stereo; also why the MCT_CHAN_MODE_LFE channel is now included? - /* for correct bit rate switching in MC we at least need the TcxCfg */ +#ifdef MC_BITRATE_SWITCHING + /* for correct bit rate switching in MC we at least need the TcxCfg for the LFE channel in MCT */ + if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) ) +#else if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) - { #endif + { + if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); } -#ifndef MC_BITRATE_SWITCHING } else { st->hTcxCfg = NULL; } -#endif /* Tonal MDCT concealment data structure */ if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) -- GitLab From fa1b0e11f0423e0bb7ce4995b8180a9dd8ea9e5e Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Wed, 14 Dec 2022 11:16:53 +0100 Subject: [PATCH 36/42] apply clang format patch --- lib_dec/init_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index b311c109c2..ebeb9926af 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -613,7 +613,7 @@ ivas_error init_decoder( } /* TCX config. data structure */ -#ifdef MC_BITRATE_SWITCHING +#ifdef MC_BITRATE_SWITCHING /* for correct bit rate switching in MC we at least need the TcxCfg for the LFE channel in MCT */ if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) ) #else -- GitLab From 0bd96bd1533c0c81bc7e16d8e8682609d90d5308 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 15 Dec 2022 11:52:54 +0100 Subject: [PATCH 37/42] Change the logic for the hTcxCfg handle of the MCT LFE channel when switching from MCT to ParamMC with 4TC, reestablishes the old memory foot print for MCT only MC coding and resolves a msan problem --- lib_dec/init_dec.c | 6 ------ lib_dec/ivas_cpe_dec.c | 8 ++++++++ lib_dec/ivas_dec.c | 11 +++++++---- lib_dec/ivas_init_dec.c | 6 +----- lib_dec/ivas_mct_dec.c | 9 +++++++++ 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index ebeb9926af..4b74ccebb9 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -613,14 +613,8 @@ ivas_error init_decoder( } /* TCX config. data structure */ -#ifdef MC_BITRATE_SWITCHING - /* for correct bit rate switching in MC we at least need the TcxCfg for the LFE channel in MCT */ - if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) ) -#else if ( ( idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) && st->mct_chan_mode != MCT_CHAN_MODE_LFE ) -#endif { - if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index f84808fa8a..a02ca28488 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -850,6 +850,14 @@ void destroy_cpe_dec( int16_t n; Decoder_State *st; +#ifdef MC_BITRATE_SWITCHING + /* make sure we deallocate a potential distinct hTcxCfg for a MCT LFE channel (can only happen in rs) */ + if ( hCPE->hCoreCoder[1]->mct_chan_mode == MCT_CHAN_MODE_LFE && hCPE->hCoreCoder[1]->hTcxCfg != hCPE->hCoreCoder[0]->hTcxCfg ) + { + hCPE->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } +#endif + for ( n = 0; n < CPE_CHANNELS; n++ ) { st = hCPE->hCoreCoder[n]; diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index e651015ce1..7ca555a1bf 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -354,10 +354,13 @@ ivas_error ivas_dec( /* LFE channel decoder */ if ( st_ivas->mc_mode == MC_MODE_MCT ) { -#ifndef MC_BITRATE_SWITCHING - /* bay: this really killed the MC bitrate switching and took me one day to find it, at least a comment here why the messing with this pointers - happens would have been nice */ - st_ivas->hCPE[1]->hCoreCoder[1]->hTcxCfg = st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg; +#ifdef MC_BITRATE_SWITCHING + if ( st_ivas->hCPE[1]->hCoreCoder[1]->hTcxCfg == NULL ) + { +#endif + st_ivas->hCPE[1]->hCoreCoder[1]->hTcxCfg = st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg; +#ifdef MC_BITRATE_SWITCHING + } #endif ivas_lfe_dec( st_ivas->hLFE, st, output_frame, st_ivas->bfi, output_lfe_ch ); } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index bee8be6749..50ea8c069a 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1422,11 +1422,7 @@ void destroy_core_dec( hCoreCoder->hTcxDec = NULL; } - if ( hCoreCoder->hTcxCfg != NULL -#ifndef MC_BITRATE_SWITCHING - && hCoreCoder->mct_chan_mode != MCT_CHAN_MODE_LFE -#endif - ) + if ( hCoreCoder->hTcxCfg != NULL && hCoreCoder->mct_chan_mode != MCT_CHAN_MODE_LFE ) { count_free( hCoreCoder->hTcxCfg ); hCoreCoder->hTcxCfg = NULL; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index b5476574cc..931f1dc33d 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -894,6 +894,15 @@ static ivas_error ivas_mc_dec_reconfig( HQ_core_dec_init( st->hHQ_core ); } + /* check if we have a doubly used hTxcCfg, if so, allocate a distint one for the old MCT LFE channel */ + if ( st->hTcxCfg == st_ivas->hCPE[1]->hCoreCoder[0]->hTcxCfg ) + { + if ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxCfg\n" ) ); + } + } + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st_ivas->hDecoderConfig->ivas_total_brate, st->igf, st->element_mode, st->mct_chan_mode ); } else if ( last_mc_mode == MC_MODE_PARAMMC && st_ivas->mc_mode == MC_MODE_MCT && nchan_transport_old > 2 ) -- GitLab From d49c0a53236bb99851d9becbf18a8f0f063e597a Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 15 Dec 2022 12:34:33 +0100 Subject: [PATCH 38/42] fix problem in CPE deallocation with the new MC rs MCT LFE channel handling --- lib_dec/ivas_cpe_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index a02ca28488..a9536312d1 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -852,7 +852,7 @@ void destroy_cpe_dec( #ifdef MC_BITRATE_SWITCHING /* make sure we deallocate a potential distinct hTcxCfg for a MCT LFE channel (can only happen in rs) */ - if ( hCPE->hCoreCoder[1]->mct_chan_mode == MCT_CHAN_MODE_LFE && hCPE->hCoreCoder[1]->hTcxCfg != hCPE->hCoreCoder[0]->hTcxCfg ) + if ( hCPE->hCoreCoder[1] != NULL && hCPE->hCoreCoder[1]->mct_chan_mode == MCT_CHAN_MODE_LFE && hCPE->hCoreCoder[1]->hTcxCfg != hCPE->hCoreCoder[0]->hTcxCfg ) { hCPE->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } -- GitLab From e8db19197b05582b2ef949df74a34c1f2164915c Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 15 Dec 2022 16:04:52 +0100 Subject: [PATCH 39/42] fix asan problem with MONO/STEREO output caused by a missing update of the SFB tables in the LS conversion at a bit rate switch within ParamMC --- lib_dec/ivas_mc_param_dec.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 2aff668e02..3e49aca706 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -686,25 +686,27 @@ ivas_error ivas_param_mc_dec_reconfig( /* prototype signal computation */ - if ( ( nchan_transport_old != nchan_transport ) && hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { - - if ( st_ivas->hLsSetUpConversion != NULL ) + if ( nchan_transport_old != nchan_transport ) { - ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); - } + if ( st_ivas->hLsSetUpConversion != NULL ) + { + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + } - if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ - count_free( hParamMC->ls_conv_dmx_matrix ); - hParamMC->ls_conv_dmx_matrix = (float *) count_malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); - for ( k = 0; k < nchan_out_transport; k++ ) - { - mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); + /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ + count_free( hParamMC->ls_conv_dmx_matrix ); + hParamMC->ls_conv_dmx_matrix = (float *) count_malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ); + for ( k = 0; k < nchan_out_transport; k++ ) + { + mvr2r( st_ivas->hLsSetUpConversion->dmxMtx[k], &hParamMC->ls_conv_dmx_matrix[k * nchan_out_cov], nchan_out_cov ); + } } /* convert ParamMC parameter bands to SFB */ @@ -713,6 +715,10 @@ ivas_error ivas_param_mc_dec_reconfig( { st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; } + for ( ; k < MAX_SFB + 2; k++ ) + { + st_ivas->hLsSetUpConversion->sfbOffset[k] = 0; + } } if ( nchan_transport_old != nchan_transport ) -- GitLab From fbec58d32eaa9d8bec2e6fdcd9033c38ff717079 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Thu, 15 Dec 2022 17:34:41 +0100 Subject: [PATCH 40/42] fix the wrong nchan_transport_real when coming from non-McMASA to 3-ch McM -> fix MSAN error --- lib_enc/ivas_corecoder_enc_reconfig.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 668eea8318..50d8e4faf8 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -143,16 +143,17 @@ ivas_error ivas_corecoder_enc_reconfig( { #ifdef MC_BITRATE_SWITCHING int16_t nchan_transport_real, nchan_transport_old_real; - if ( last_mc_mode == MC_MODE_MCMASA ) + + nchan_transport_old_real = nchan_transport_old; + nchan_transport_real = st_ivas->nchan_transport; + /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */ + if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA ) { - /* in SCE+CPE McMASA nchan_transport is still 2 */ nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old; - nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE; } - else + if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) { - nchan_transport_old_real = nchan_transport_old; - nchan_transport_real = st_ivas->nchan_transport; + nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE; } /* something in transport changes */ @@ -190,7 +191,7 @@ ivas_error ivas_corecoder_enc_reconfig( ind_list_metadata = hMetaData->ind_list; /* pointer to the beginning of the global list */ #ifdef MC_BITRATE_SWITCHING - if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) + if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA ) { /* within McMASA we can modify the transport signals when switching */ /* copy earlier dmx buffers */ -- GitLab From de0a7356cc5894adad9180c09cd61d5f1e7fc2e8 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 15 Dec 2022 22:07:20 +0100 Subject: [PATCH 41/42] merge all changes under define MC_BITRATE_SWITCHING --- lib_com/ivas_prot.h | 2 +- lib_com/options.h | 2 -- lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_mct_dec.c | 4 ++-- lib_dec/ivas_stereo_switching_dec.c | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index aa968848cb..a7af4878c9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2604,7 +2604,7 @@ ivas_error stereo_memory_dec( const int16_t nb_bits_metadata, /* i : number of metadata bits */ const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT +#ifdef MC_BITRATE_SWITCHING const MC_MODE mc_mode, /* i : MC mode */ #endif const int16_t nchan_transport /* i : number of transport channels */ diff --git a/lib_com/options.h b/lib_com/options.h index 26ec07f301..7c3b498d4b 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,8 +167,6 @@ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ -#define MC_BITRATE_SWITCHING_CLDFB -#define FIX_MC_BR_SW_TCX_PLC_FADEOUT #define FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index a9536312d1..17062e8373 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -103,7 +103,7 @@ ivas_error ivas_cpe_dec( * dynamically allocate data structures depending on the actual stereo mode *----------------------------------------------------------------*/ -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT +#ifdef MC_BITRATE_SWITCHING if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) #else if ( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 931f1dc33d..0283d7778d 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -662,7 +662,7 @@ static ivas_error ivas_mc_dec_reconfig( ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; -#ifdef MC_BITRATE_SWITCHING_CLDFB +#ifdef MC_BITRATE_SWITCHING int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; #else int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i; @@ -959,7 +959,7 @@ static ivas_error ivas_mc_dec_reconfig( * CLDFB instances *-----------------------------------------------------------------*/ -#ifdef MC_BITRATE_SWITCHING_CLDFB +#ifdef MC_BITRATE_SWITCHING ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ); #else diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 5d96960312..3b9fb19727 100755 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -342,7 +342,7 @@ ivas_error stereo_memory_dec( const int16_t nb_bits_metadata, /* i : number of metadata bits */ const int32_t output_Fs, /* i : output sampling rate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT +#ifdef MC_BITRATE_SWITCHING const MC_MODE mc_mode, /* i : MC mode */ #endif const int16_t nchan_transport /* i : number of transport channels*/ @@ -958,7 +958,7 @@ ivas_error stereo_memory_dec( } } -#ifdef FIX_MC_BR_SW_TCX_PLC_FADEOUT +#ifdef MC_BITRATE_SWITCHING /*--------------------------------------------------------------* * Bitrate switching in MASA format *---------------------------------------------------------------*/ -- GitLab From 8cf9ef3c7891129df4fad50fcf80ebaf238e84d2 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 16 Dec 2022 10:47:09 +0100 Subject: [PATCH 42/42] merge FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON define under MC_BITRATE_SWITCHING --- lib_com/options.h | 1 - lib_com/prot.h | 2 +- lib_enc/amr_wb_enc.c | 2 +- lib_enc/evs_enc.c | 2 +- lib_enc/ivas_core_enc.c | 2 +- lib_enc/ivas_mct_enc.c | 2 +- lib_enc/updt_enc.c | 4 ++-- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a89a9f8e1f..d71d9de23a 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,7 +153,6 @@ #define MC_BITRATE_SWITCHING /* Issue 116: support bitrate switching in MC format */ -#define FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d1d3b0344f..a6b660f8a1 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3915,7 +3915,7 @@ void updt_enc( void updt_enc_common( Encoder_State *st /* i/o: encoder state structure */ -#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifndef MC_BITRATE_SWITCHING , const float Etot /* i : total energy */ #endif diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index 185ba05e51..5bbc890b52 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -531,7 +531,7 @@ void amr_wb_enc( updt_enc( st, old_exc, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec paramaters */ -#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifdef MC_BITRATE_SWITCHING st->hNoiseEst->Etot_last = Etot; updt_enc_common( st ); #else diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index 9f54a68fd3..8eb9bd9623 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -509,7 +509,7 @@ ivas_error evs_enc( * Updates *---------------------------------------------------------------------*/ -#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifdef MC_BITRATE_SWITCHING st->hNoiseEst->Etot_last = Etot; updt_enc_common( st ); #else diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index b7d228c4ac..edef26a6c2 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -408,7 +408,7 @@ ivas_error ivas_core_enc( /*---------------------------------------------------------------------* * Common updates *---------------------------------------------------------------------*/ -#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifdef MC_BITRATE_SWITCHING /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ st->hNoiseEst->Etot_last = Etot[n]; if ( !MCT_flag ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index a8485310e9..3fa3ad04bd 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -195,7 +195,7 @@ ivas_error ivas_mct_enc( for ( n = 0; n < CPE_CHANNELS; n++ ) { mvr2r( hCPE->hCoreCoder[n]->input, hCPE->hCoreCoder[n]->old_input_signal, input_frame ); -#ifdef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifdef MC_BITRATE_SWITCHING /* common encoder updates */ updt_enc_common( hCPE->hCoreCoder[n] ); #endif diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index cd9b3b0ef0..37f50c8cef 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -298,7 +298,7 @@ void updt_IO_switch_enc( void updt_enc_common( Encoder_State *st /* i/o: encoder state structure */ -#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifndef MC_BITRATE_SWITCHING , const float Etot /* i : total energy */ #endif @@ -319,7 +319,7 @@ void updt_enc_common( st->last_extl = st->extl; st->last_input_bwidth = st->input_bwidth; st->last_bwidth = st->bwidth; -#ifndef FIX_MC_BR_SW_MCT_UPDT_ENC_COMMON +#ifndef MC_BITRATE_SWITCHING st->hNoiseEst->Etot_last = Etot; #endif st->last_coder_type_raw = st->coder_type_raw; -- GitLab