From 46c0e60b3785c192b2f96a61cd125f6e46b33328 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 13:22:53 +0100 Subject: [PATCH 1/7] fix MSVC Warning C4244 'function': conversion from 'float' to 'const int32_t', possible loss of data lib_dec ..\lib_dec\ivas_mct_dec.c 1033 --- lib_dec/ivas_mct_dec.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 0283d7778d..a43272ae58 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1030,7 +1030,29 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->mc_mode == MC_MODE_MCT && st_ivas->hLFE == NULL ) { +#ifdef FIX_I59_LFE_TD_DELAY + int32_t binauralization_delay_ns = st_ivas->binaural_latency_ns; + + if ( st_ivas->hBinRenderer != NULL ) + { +#ifdef FIX_I59_LFE_CLDFB + if ( st_ivas->hBinRenderer->render_lfe ) + { + /* Account for filterbank delay */ + binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; + } + else + { + binauralization_delay_ns = 0; + } +#else + binauralization_delay_ns = 0; +#endif + } + if ( ( error = ivas_create_lfe_dec( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) +#else 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 ) +#endif { return error; } -- GitLab From fb3f2f7e84da03a6932b14da8f194277d2471057 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 13:26:00 +0100 Subject: [PATCH 2/7] remove debugging changes to DEBUG_MODE_INFO --- lib_dec/ivas_cpe_dec.c | 5 ----- lib_dec/ivas_sce_dec.c | 5 ----- lib_enc/ivas_cpe_enc.c | 4 ---- lib_enc/ivas_sce_enc.c | 4 ---- 4 files changed, 18 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index f06b658604..cb5b9f4e0b 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -512,13 +512,8 @@ ivas_error ivas_cpe_dec( for ( i = 0; i < n; i++ ) { -#ifdef MC_BITRATE_SWITCHING // !!! VE: Can it be removed? - 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_sce_dec.c b/lib_dec/ivas_sce_dec.c index 9ac0a1c528..97ee2e8336 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -273,13 +273,8 @@ ivas_error ivas_sce_dec( for ( i = 0; i < n; i++ ) { -#ifdef MC_BITRATE_SWITCHING // !!! VE: Can it be removed? - 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/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 008599e36b..c5fb6800f9 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -417,11 +417,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 MC_BITRATE_SWITCHING // !!! VE: Can it be removed? - 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 /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index cdd37d8ece..428dbb95c1 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -174,11 +174,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 MC_BITRATE_SWITCHING // !!! VE: Can it be removed? - 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 ae6058c6fc8bf131bf292469ea589d1f357b570f Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 13:30:12 +0100 Subject: [PATCH 3/7] remove doubled allocation to hLFE = NULL --- lib_enc/ivas_init_enc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 41a071aab3..7c9253a35e 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -526,9 +526,7 @@ 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; // !!! VE: already done in ivas_initialize_handles_enc() -#else +#ifndef MC_BITRATE_SWITCHING if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK ) { return error; -- GitLab From 341d9459b91fda75258c4ebaa503b04a45e14386 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 13:35:49 +0100 Subject: [PATCH 4/7] remove unnecessary assignment - CPE should be always with element_mode_init = IVAS_CPE_MDCT; --- lib_enc/ivas_corecoder_enc_reconfig.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 50d8e4faf8..e9b5f73508 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -352,10 +352,6 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) { #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; // !!! 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 if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) -- GitLab From 1a6b2dee57e60e028bac5ac73643ed726d41bb03 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 13:50:42 +0100 Subject: [PATCH 5/7] move "element_mode_init = IVAS_CPE_MDCT;" into ivas_mc_enc_reconfig --- lib_enc/ivas_mct_enc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 3fa3ad04bd..6ba818b0d9 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -725,6 +725,13 @@ static ivas_error ivas_mc_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; + } +#endif + if ( st_ivas->hParamMC != NULL ) { ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -- GitLab From 31d931b9ebd3786edd8fdb152ab75a445e34663d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 14:01:35 +0100 Subject: [PATCH 6/7] - formatting - introduce "ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;" in order to minimize spaghetti-like calls --- lib_dec/ivas_mct_dec.c | 26 ++++++++++++++++---------- lib_enc/ivas_mct_enc.c | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index a43272ae58..cf348ff15d 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -667,17 +667,18 @@ static ivas_error ivas_mc_dec_reconfig( #else int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old, i; #endif - int32_t new_brate_SCE, new_brate_CPE; + int32_t new_brate_SCE, new_brate_CPE, ivas_total_brate; RENDERER_TYPE renderer_type_old; ivas_error error; 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 */ - error = IVAS_ERR_OK; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; + 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 */ + /* 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; @@ -703,6 +704,7 @@ static ivas_error ivas_mc_dec_reconfig( /* renderer might have changed, 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 ); @@ -755,6 +757,7 @@ static ivas_error ivas_mc_dec_reconfig( { ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); } + if ( ( error = ivas_param_mc_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -796,7 +799,7 @@ static ivas_error ivas_mc_dec_reconfig( } 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 ); + ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); if ( last_mc_mode != MC_MODE_MCMASA ) { @@ -805,6 +808,7 @@ static ivas_error ivas_mc_dec_reconfig( return error; } } + if ( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -903,7 +907,7 @@ static ivas_error ivas_mc_dec_reconfig( } } - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st_ivas->hDecoderConfig->ivas_total_brate, st->igf, st->element_mode, st->mct_chan_mode ); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( 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 ) { @@ -919,19 +923,20 @@ static ivas_error ivas_mc_dec_reconfig( { 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 ); + ivas_mcmasa_set_separate_channel_mode( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); + ivas_mcmasa_split_brate( separateChannelEnabled, 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; + new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; } else { - 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; + new_brate_SCE = 0; /* ivas_total_brate / st_ivas->nchan_transport;*/ + new_brate_CPE = ( 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 ) { return error; @@ -1132,6 +1137,7 @@ static ivas_error ivas_mc_dec_reconfig( { /* 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; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 6ba818b0d9..0102207a9b 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -746,6 +746,7 @@ static ivas_error ivas_mc_enc_reconfig( ivas_lfe_enc_close( st_ivas->hLFE ); st_ivas->hLFE = NULL; } + if ( st_ivas->hMCT != NULL ) { ivas_mct_enc_close( st_ivas->hMCT ); -- GitLab From 6dfad9d5933219887e10355c28d4ad8da8002122 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 19 Dec 2022 15:54:05 +0100 Subject: [PATCH 7/7] revert past change around "element_mode_init = IVAS_CPE_MDCT" --- lib_enc/ivas_corecoder_enc_reconfig.c | 5 +++++ lib_enc/ivas_mct_enc.c | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index e9b5f73508..dfa7ed9ffa 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -352,6 +352,11 @@ ivas_error ivas_corecoder_enc_reconfig( for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ ) { #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; + } + 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 ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 0102207a9b..a5751b7e29 100755 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -725,13 +725,6 @@ static ivas_error ivas_mc_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; - } -#endif - if ( st_ivas->hParamMC != NULL ) { ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); -- GitLab