diff --git a/ci/run_scheduled_sanitizer_test.py b/ci/run_scheduled_sanitizer_test.py index 3c677cea940646247797dd2f777e5bc410b84639..b63c76cac504760576faba7e3b5b980635b23c00 100644 --- a/ci/run_scheduled_sanitizer_test.py +++ b/ci/run_scheduled_sanitizer_test.py @@ -48,9 +48,6 @@ def get_modes(in_format: str) -> list: in_format = "MC_" + in_format + "_b" mode_list = [m for m in output.splitlines() if in_format in m] - if "SBA" in in_format: - # rate switching not implemented yet - mode_list = [m for m in mode_list if not "_rs" in m] return mode_list diff --git a/ci/smoke_test.sh b/ci/smoke_test.sh index b8c4bdd3f0ebf8703bc76dd78b0fc7dac5df6351..e3caac3533d9e9be04427f10e5c01701b713f03a 100755 --- a/ci/smoke_test.sh +++ b/ci/smoke_test.sh @@ -8,8 +8,5 @@ fi make clean make all -j 8 -# get all modes except SBA rate switching (which is broken currently) -list=$(./scripts/runIvasCodec.py -l | grep -v "SBA.*rs") -./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -m $list -U 1 | tee smoke_test_output.txt - -./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -m $list -U 1 -D="-fec 15" --decoder_only | tee smoke_test_output_plc.txt +./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -U 1 | tee smoke_test_output.txt +./scripts/runIvasCodec.py -p ./scripts/config/ci_linux.json -U 1 -D="-fec 15" --decoder_only | tee smoke_test_output_plc.txt diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index fe0786f02330677360f032208e5eb1ee889e8933..39d9d237c01468d6f441dcf42caefbce9737c18a 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -105,7 +105,17 @@ ivas_error mct_enc_reconfigure( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ ); - +#ifdef SBA_BR_SWITCHING +ivas_error ivas_sba_enc_reinit( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +#endif +#ifdef SBA_BR_SWITCHING +int16_t get_sba_reinit_flag( + int32_t ivas_total_bitrate, /* i: current bitrate */ + int32_t last_ivas_total_brate /* i: previous bitrate */ +); +#endif ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -3038,7 +3048,11 @@ void ivas_sba_config( int16_t *nCPE, /* o : number of CPEs */ int16_t *element_mode /* o : element mode of the core coder */ ); - +#ifdef SBA_BR_SWITCHING +ivas_error ivas_sba_dec_reinit( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -3992,7 +4006,8 @@ void ivas_spar_get_parameters( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ); void ivas_spar_md_dec_process( diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 29c0ca6617d18532e49845a19699f0e8213b14ad..4e01960085093010db727f82e0e199232be8191f 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -71,8 +71,26 @@ SBA_MODE ivas_sba_mode_select( return sba_mode; } - - +#ifdef SBA_BR_SWITCHING +/*-------------------------------------------------------------------* + * get_sba_reinit_flag() + * + * Get SBA reinitialisation flag + *-------------------------------------------------------------------*/ +int16_t get_sba_reinit_flag( + int32_t ivas_total_bitrate, /* i : Current bitrate */ + int32_t last_ivas_total_brate /* i : Previous bitrate */ +) +{ + int16_t sba_reinit_flag; + sba_reinit_flag = 0; + if ( ivas_total_bitrate != last_ivas_total_brate && ( last_ivas_total_brate > IVAS_SID_5k2 ) && ( ivas_total_bitrate > IVAS_SID_5k2 ) ) + { + sba_reinit_flag = 1; + } + return sba_reinit_flag; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_config() * diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index fa5e65460eab83d197a4b3e103b1ae288092e4ec..630497e14cedc0c50b3d4c0f111d9cd6ff9b6917 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2131,7 +2131,7 @@ void ivas_spar_set_bitrate_config( ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; sba_order = ivas_spar_br_table_consts[table_idx].sba_order; - ivas_get_spar_table_idx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &code, &length ); + ivas_get_spar_table_idx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code ); for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { diff --git a/lib_com/options.h b/lib_com/options.h index 8c9e60ab79b87c2e61ba827ddc39690e0f084f76..db4c245a05bcbc77a90bedd0380240d146da7de1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,6 +154,7 @@ #define FIX_TCX_DEC_RECONF_BFI #define FIX_SBA_DTX_DECODE_ERROR /* Issue 176: SBA decoder error with DTX at 80kbps SWB, Issue 21: SBA front-VAD threshold (203) */ #define FIX_MSAN_ERROR_STEREO_RATE_SWITCHING /* addresses Issue 177 */ +#define SBA_BR_SWITCHING /* Issue 114: Changes for sba bit rate switching*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index b12639ae3fcb3e100477cab505ba97e378bc1e7a..ca4832399fa4708b45e0da4ef4274ba31aaf5dd3 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -93,8 +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 SBA_BR_SWITCHING +#define MAX_INFO_RECORDS 8000 +#else #define MAX_INFO_RECORDS 3000 - +#endif /* This is the length after which the function name will be truncated when the summary is printed. */ #define MAX_FUNCTION_NAME_LENGTH 18 diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 30b96a25c823febddf1ebd26fe95ecc1fb148626..751958ecd9c97eba49409fb7f4929c04b6e52c40 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -69,7 +69,6 @@ ivas_error ivas_dec_setup( Decoder_State *st; int32_t ivas_total_brate; ivas_error error; - error = IVAS_ERR_OK; num_bits_read = 0; @@ -128,10 +127,24 @@ ivas_error ivas_dec_setup( num_bits_read += SBA_ORDER_BITS; if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { - if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#ifdef SBA_BR_SWITCHING + if ( get_sba_reinit_flag( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { - return error; + if ( ( error = ivas_sba_dec_reinit( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } + else + { +#endif + if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef SBA_BR_SWITCHING + } +#endif } else { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 3d91d6834de503faafa4bbf5616ca71a7132de9a..b027dcff774b7be16a886349a2f49860c016c625 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -335,7 +335,499 @@ void ivas_ism2sba( return; } +#ifdef SBA_BR_SWITCHING +/*-------------------------------------------------------------------* + * ivas_sba_dec_reinit() + * + * Reinitialisation of IVAS SBA decoder + *-------------------------------------------------------------------*/ + +ivas_error ivas_sba_dec_reinit( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t i, k, n; + int16_t sce_id, cpe_id; + int16_t numCldfbAnalyses; + int16_t numCldfbSyntheses; + int32_t output_Fs, ivas_total_brate; + AUDIO_CONFIG output_config; + DECODER_CONFIG_HANDLE hDecoderConfig; + ivas_error error; + + error = IVAS_ERR_OK; + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + hDecoderConfig = st_ivas->hDecoderConfig; + output_config = hDecoderConfig->output_config; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + + hDecoderConfig->last_ivas_total_brate = ivas_total_brate; + /*------------------------------------------------------------------------------------------* + * Closing Decoder handles before Reinitialisation + *------------------------------------------------------------------------------------------*/ + /* Qmetadata handle */ + ivas_qmetadata_close( &st_ivas->hQMetaData ); + + /* DirAC handle */ + if ( st_ivas->hDirAC != NULL ) + { + if ( st_ivas->ivas_format == ISM_FORMAT ) + { + ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); + } + else + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + } + st_ivas->hDirAC = NULL; + } + + /* Spar handle */ + if ( st_ivas->hSpar != NULL ) + { + ivas_spar_dec_close( st_ivas->hSpar, st_ivas->hDecoderConfig->output_Fs ); + st_ivas->hSpar = NULL; + } + + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_dec( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } + + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) + { + /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + st_ivas->hCPE[i]->hCoreCoder[0] = NULL; + st_ivas->hCPE[i]->hCoreCoder[1] = NULL; + } + destroy_cpe_dec( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } + + /* MCT handle */ + ivas_mct_dec_close( &st_ivas->hMCT ); + + /* HP20 filter handles */ + if ( st_ivas->mem_hp20_out != NULL ) + { + for ( i = 0; i < getNumChanSynthesis( st_ivas ); i++ ) + { + count_free( st_ivas->mem_hp20_out[i] ); + st_ivas->mem_hp20_out[i] = NULL; + } + count_free( st_ivas->mem_hp20_out ); + st_ivas->mem_hp20_out = NULL; + } + + /* HOA decoder matrix */ + if ( st_ivas->hoa_dec_mtx != NULL ) + { + count_free( st_ivas->hoa_dec_mtx ); + st_ivas->hoa_dec_mtx = NULL; + } + + /* Parametric MC handle */ + ivas_param_mc_dec_close( &st_ivas->hParamMC ); + + /* EFAP handle */ + efap_free_data( &st_ivas->hEFAPdata ); + + /* VBAP handle */ + vbap_free_data( &( st_ivas->hVBAPdata ) ); + + /* Fastconv binaural renderer handle */ + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + + /* Parametric binaural renderer handle */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + + /* Crend handle */ + ivas_crend_close( st_ivas ); + + /* LS config converter handle */ + ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); + + /* Custom LS configuration handle */ + if ( st_ivas->hLsSetupCustom != NULL ) + { + count_free( st_ivas->hLsSetupCustom ); + st_ivas->hLsSetupCustom = NULL; + } + + /* MASA decoder structure */ + if ( st_ivas->hMasa != NULL ) + { + ivas_masa_dec_close( st_ivas->hMasa ); + st_ivas->hMasa = NULL; + } + + /* Downmix structure */ + if ( st_ivas->hMonoDmxRenderer != NULL ) + { + count_free( st_ivas->hMonoDmxRenderer ); + st_ivas->hMonoDmxRenderer = NULL; + } + + /* Head track data handle */ + if ( st_ivas->hHeadTrackData != NULL ) + { + count_free( st_ivas->hHeadTrackData ); + st_ivas->hHeadTrackData = NULL; + } + + /* Time Domain binaural renderer handle */ + if ( st_ivas->hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + } + else if ( st_ivas->hHrtfTD != NULL ) + { + /* Case when HRTF filter is mistakenly specified but TD renderer was not active */ + if ( st_ivas->hHrtfTD->ModelParams.UseItdModel && !st_ivas->hHrtfTD->ModelParams.modelROM ) + { + BSplineModelEvalITDDealloc( &st_ivas->hHrtfTD->ModelParamsITD ); + } + + BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); + ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); + } + + /* Config. Renderer */ + ivas_render_config_close( &( st_ivas->hRenderConfig ) ); + + for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) + { + if ( st_ivas->cldfbAnaDec[i] != NULL ) + { + deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); + st_ivas->cldfbAnaDec[i] = NULL; + } + } + + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + if ( st_ivas->cldfbSynDec[i] != NULL ) + { + deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); + st_ivas->cldfbSynDec[i] = NULL; + } + } + + /*------------------------------------------------------------------------------------------* + * Reopening Decoder handles for Reinitialisation + *------------------------------------------------------------------------------------------*/ + + /* Allocate and initialize Custom loudspeaker layout handle */ + if ( st_ivas->hDecoderConfig->Opt_LsCustom ) + { + if ( ( error = ivas_ls_custom_open( &( st_ivas->hLsSetupCustom ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* Allocate and initialize Head-Tracking handle */ + if ( st_ivas->hDecoderConfig->Opt_Headrotation ) + { + if ( ( error = ivas_headTrack_open( &( st_ivas->hHeadTrackData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* Allocate HRTF binary handle */ + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + { + if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->sba_dirac_stereo_flag = 0; + /*Reconfigure output paramaters*/ + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + ivas_renderer_select( st_ivas ); + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) + { + if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) + { + st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; + } + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + else + { + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; + + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + } + } + else + { + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && output_config == AUDIO_CONFIG_STEREO ); + + if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) && st_ivas->hOutSetup.is_loudspeaker_setup ) + { + int16_t ambisonics_order; + + ambisonics_order = ivas_sba_get_order_transport( st_ivas->nchan_transport ); // VE: is it needed ? + + if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) && !st_ivas->hIntSetup.is_loudspeaker_setup ) + { + IVAS_OUTPUT_SETUP out_setup; + + ivas_output_init( &out_setup, AUDIO_CONFIG_7_1_4 ); + if ( ( error = ivas_sba_get_hoa_dec_matrix( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + if ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && + st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + + reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); + } + } + + /* create CPE element for DFT Stereo like upmix */ + if ( st_ivas->sba_dirac_stereo_flag ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ + } + + /* set CNA/CNG flags */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; /* Todo: Check if these can be enabled */ + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; + } + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; /* Todo: Check if these can be enabled */ + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + + if ( st_ivas->nCPE > 1 ) + { + if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* set number of output channels used for synthesis/decoding */ + n = getNumChanSynthesis( st_ivas ); + + if ( n > 0 ) + { + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + else + { + st_ivas->mem_hp20_out = NULL; + } + + for ( i = 0; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM ); + } + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_ROOM ) + { + if ( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( ivas_render_config_init_from_rom( &st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_ROOM ) != IVAS_ERR_OK ) + { + return IVAS_ERR_INTERNAL_FATAL; + } + } + if ( 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->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->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + { + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( 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->renderer_type == RENDERER_MC ) + { + if ( ( error = ivas_ls_setup_conversion_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( 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" ); + } + } + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses, &numCldfbSyntheses ); + + for ( i = 0; i < numCldfbAnalyses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( ; i < MAX_INTERN_CHANNELS; i++ ) + { + st_ivas->cldfbAnaDec[i] = NULL; + } + + for ( i = 0; i < numCldfbSyntheses; i++ ) + { + if ( ( error = openCldfb( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + for ( ; i < MAX_OUTPUT_CHANNELS; i++ ) + { + st_ivas->cldfbSynDec[i] = NULL; + } + + /* CLDFB Interpolation weights */ + if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } + return error; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_dec_decoder() diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 444a14457e633a15f47a9e5ef613b02bb1b89c0c..116d1f1926e2ea17013c3d7e73d037a5b5545859 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -659,7 +659,7 @@ static void ivas_spar_dec_MD( hSpar->hMdDec->table_idx = table_idx; hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; - ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels ); + ivas_spar_md_dec_init( hSpar->hMdDec, hDecoderConfig, num_channels, sba_order ); } } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 5d39aee9a01da10c64dcbd2e9490a79de6d5c753..b345674c99a55ba07232c2b9809d26d2b36aef49 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -249,9 +249,8 @@ static ivas_error ivas_spar_md_dec_matrix_open( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ - , - const int16_t sba_order /* i : SBA order */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -269,10 +268,9 @@ ivas_error ivas_spar_md_dec_open( return error; } - hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); hMdDec->table_idx = 0; /* just to initialize state variables*/ - if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels, sba_order ) ) != IVAS_ERR_OK ) { return error; } @@ -433,7 +431,8 @@ void ivas_spar_md_dec_close( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t num_channels /* i : number of internal channels */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ ) { int16_t i, j, k; @@ -442,6 +441,7 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_md_cfg.gen_bs = 1; // VE2DB : always 1 - can it be removed? + hMdDec->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate ); hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); ivas_spar_set_bitrate_config( &hMdDec->spar_md_cfg, hMdDec->table_idx, diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 75ffc5212d31b145d2b447f752d908364fb6efed..7be1f11c497e9df75593038c42be91d6d6fff351 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -65,7 +65,9 @@ ivas_error ivas_enc( float data_f[MAX_INPUT_CHANNELS][L_FRAME48k]; /* IVAS_fmToDo: buffer can be allocated dynamically based on the number of analysed channels */ int32_t ivas_total_brate; ivas_error error; - +#ifdef SBA_BR_SWITCHING + int16_t sba_reinit_flag; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ivas_enc" ); @@ -85,6 +87,20 @@ ivas_error ivas_enc( n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE ); +#ifdef SBA_BR_SWITCHING + sba_reinit_flag = 0; + if ( ivas_format == SBA_FORMAT ) + { + sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ); + if ( sba_reinit_flag ) + { + if ( ( error = ivas_sba_enc_reinit( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif /*----------------------------------------------------------------* * convert 'short' input data to 'float' @@ -189,7 +205,11 @@ ivas_error ivas_enc( /* SBA/MASA configuration */ if ( ivas_format == SBA_FORMAT ) { +#ifndef SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) +#else + if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( !sba_reinit_flag ) ) +#endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index ed51037dcfdff417f08fc8a364930c29deb40fdc..aca565b64d04c40b11683d6f61feabad2b458820 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -93,7 +93,226 @@ void ivas_sba_getTCs( return; } +#ifdef SBA_BR_SWITCHING +/*-------------------------------------------------------------------* + * ivas_sba_enc_reinit() + * + * Reinitialise IVAS SBA encoder + *-------------------------------------------------------------------*/ + +ivas_error ivas_sba_enc_reinit( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t nSCE_old; + int16_t nCPE_old; + int16_t sce_id; + int16_t cpe_id; + int16_t n; + Indice *ind_list_metadata; + int32_t ivas_total_brate; + int16_t i, nchan_inp; + ivas_error error; + ENCODER_CONFIG_HANDLE hEncoderConfig; + + Indice *ind_list; + BSTR_ENC_HANDLE hBstr; + BSTR_ENC_HANDLE hMetaData; + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + error = IVAS_ERR_OK; + nchan_inp = st_ivas->hEncoderConfig->nchan_inp; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + + nCPE_old = st_ivas->nCPE; + nSCE_old = st_ivas->nSCE; + ind_list_metadata = NULL; + + + ind_list = NULL; + hBstr = NULL; + hMetaData = NULL; + + /* get the index list pointers */ + if ( nSCE_old ) + { + hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr; + hMetaData = st_ivas->hSCE[0]->hMetaData; + } + else if ( nCPE_old ) + { + hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + hMetaData = st_ivas->hCPE[nCPE_old - 1]->hMetaData; + } + + /* save bitstream information */ + ind_list = hBstr->ind_list; + ind_list_metadata = hMetaData->ind_list; + + /*------------------------------------------------------------------------------------------* + * Closing Encoder handles before Reinitialisation + *------------------------------------------------------------------------------------------*/ + + /* Q Metadata handle */ + ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); + /* DirAC handle */ + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); + + st_ivas->hDirAC = NULL; + } + /* SPAR handle */ + if ( st_ivas->hSpar != NULL ) + { + ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp ); + st_ivas->hSpar = NULL; + } + /* SCE handles */ + for ( i = 0; i < MAX_SCE; i++ ) + { + if ( st_ivas->hSCE[i] != NULL ) + { + destroy_sce_enc( st_ivas->hSCE[i] ); + st_ivas->hSCE[i] = NULL; + } + } + + /* CPE handles */ + for ( i = 0; i < MAX_CPE; i++ ) + { + if ( st_ivas->hCPE[i] != NULL ) + { + destroy_cpe_enc( st_ivas->hCPE[i] ); + st_ivas->hCPE[i] = NULL; + } + } + /* MCT handle */ + if ( st_ivas->hMCT != NULL ) + { + ivas_mct_enc_close( st_ivas->hMCT ); + st_ivas->hMCT = NULL; + } + if ( st_ivas->mem_hp20_in != NULL ) + { + n = getNumChanAnalysis( st_ivas ); + + for ( i = 0; i < n; i++ ) + { + count_free( st_ivas->mem_hp20_in[i] ); + st_ivas->mem_hp20_in[i] = NULL; + } + count_free( st_ivas->mem_hp20_in ); + st_ivas->mem_hp20_in = NULL; + } + + /*------------------------------------------------------------------------------------------* + * Reopening Encoder handles for Reinitialisation + *------------------------------------------------------------------------------------------*/ + + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); + + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* prepare bitstream buffers */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); + + 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->sba_mode == SBA_MODE_SPAR && st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + } + } + + 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->nchan_transport ) * CPE_CHANNELS ) ) != 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 ) * MAX_NUM_INDICES; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + + if ( hEncoderConfig->Opt_DTX_ON ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + + /* 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 + sce_id * MAX_BITS_METADATA; + 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; + } + } + n = getNumChanAnalysis( st_ivas ); + + if ( n > 0 ) + { + if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + } + else + { + st_ivas->mem_hp20_in = NULL; + } + + for ( i = 0; i < n; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + return error; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_enc_reconfigure() * diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 4bd23dee47a9b403a450c82acbaf2f9dcb65c06c..1fa39f13bf010b09b78f1060d2da95173e2f33e1 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -121,8 +121,6 @@ ivas_error ivas_spar_md_enc_open( num_channels = 2 * sba_order + 2; - hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); - if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); @@ -317,6 +315,7 @@ static ivas_error ivas_spar_md_enc_init( float PR_minmax[2]; int16_t num_channels, i, j, k; + hMdEnc->spar_hoa_md_flag = ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate ); num_channels = ivas_sba_get_nchan_metadata( sba_order ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); @@ -601,24 +600,17 @@ ivas_error ivas_spar_md_enc_process( for ( j = 0; j < nchan_inp; j++ ) { cov_real[i][j] = cov_dtx_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = 0; - } } } } - else + + for ( i = 0; i < nchan_inp; i++ ) { - for ( i = 0; i < nchan_inp; i++ ) + for ( j = 0; j < nchan_inp; j++ ) { - for ( j = 0; j < nchan_inp; j++ ) + for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) { - cov_real[i][j] = cov_real[i][j]; - for ( k = num_bands_bw; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = 0; - } + cov_real[i][j][k] = 0; } } }