diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index fc3079c51f4c3faeef1b6311c67bc93a30bfd3c1..3e0ece839faf0755e98cea4bb33db07eba7ddb89 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -920,7 +920,7 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING , DIRAC_RECONFIGURE_MODE #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ec86280ebee847e6aa45b503c7f798a535efd4bd..45e4c4ba29fa36fa6a67c6bd9966b06ce6cd62ee 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -105,6 +105,30 @@ 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 */ ); +#ifndef SBA_BR_SWITCHING_RECONFIG +#ifdef SBA_BR_SWITCHING +ivas_error ivas_sba_enc_reinit( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); +#endif +#endif +#ifndef SBA_BR_SWITCHING_RECONFIG +#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 */ + , int16_t sba_order +); +#endif +#endif +#ifdef SBA_BR_SWITCHING +ivas_error ivas_spar_md_enc_init +( + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +); +#endif ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -3104,42 +3128,16 @@ void ivas_sba_config( int16_t *element_mode /* o : element mode of the core coder */ ); -ivas_error ivas_sba_enc_reconfigure( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); - -#ifdef SBA_BR_SWITCHING -ivas_error ivas_sba_enc_reinit( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); - -int16_t get_sba_reinit_flag( - int32_t ivas_total_bitrate, /* i : Current bitrate */ - int32_t last_ivas_total_brate /* i : Previous bitrate */ -#ifdef SBA_BR_SWITCHING_2 - , const int16_t sba_order -#endif -); -#endif -#ifdef SBA_BR_SWITCHING_2 -ivas_error ivas_spar_md_enc_init -( - ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ -); -#endif - ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); - +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING ivas_error ivas_sba_dec_reinit( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif - +#endif void ivas_init_dec_get_num_cldfb_instances( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index f9a8c2b6eff8eb9ab3dc3c909c1a3f434cae591f..26ae98c954485f505c02bda1a8e46c87c4dc3026 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -71,7 +71,7 @@ SBA_MODE ivas_sba_mode_select( return sba_mode; } - +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING /*-------------------------------------------------------------------* * get_sba_reinit_flag() @@ -80,24 +80,15 @@ SBA_MODE ivas_sba_mode_select( *-------------------------------------------------------------------*/ int16_t get_sba_reinit_flag( - int32_t ivas_total_bitrate, /* i : Current bitrate */ - int32_t last_ivas_total_brate /* i : Previous bitrate */ -#ifdef SBA_BR_SWITCHING_2 - , - const int16_t sba_order -#endif -) + int32_t ivas_total_bitrate, /* i : Current bitrate */ + int32_t last_ivas_total_brate, /* i : Previous bitrate */ + int16_t sba_order ) { int16_t sba_reinit_flag; sba_reinit_flag = 0; -#ifdef SBA_BR_SWITCHING_2 if ( ivas_total_bitrate != last_ivas_total_brate && ( ivas_total_bitrate > IVAS_SID_5k2 ) ) -#else - if ( ivas_total_bitrate != last_ivas_total_brate && ( last_ivas_total_brate > IVAS_SID_5k2 ) && ( ivas_total_bitrate > IVAS_SID_5k2 ) ) -#endif { -#ifdef SBA_BR_SWITCHING_2 int16_t sba_analysis_order, nchan_transport_old, nchan_transport_new; SBA_MODE last_sba_mode, current_sba_mode; sba_analysis_order = ivas_sba_get_analysis_order( last_ivas_total_brate, sba_order ); @@ -108,17 +99,14 @@ int16_t get_sba_reinit_flag( nchan_transport_new = ivas_get_sba_num_TCs( ivas_total_bitrate, min( sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); if ( ( current_sba_mode != last_sba_mode ) || ( nchan_transport_new != nchan_transport_old ) ) { -#endif sba_reinit_flag = 1; -#ifdef SBA_BR_SWITCHING_2 } -#endif } return sba_reinit_flag; } #endif - +#endif /*-------------------------------------------------------------------* * ivas_sba_config() * diff --git a/lib_com/options.h b/lib_com/options.h index 989143e5c6a61219c9a7b6e44aba6c68f691762f..c70b2c7141c31f90b9398fac8196ca7587af7ef3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -141,8 +141,10 @@ #define DISABLE_ADAP_RES_COD_TMP /* temporary fix for IVAS-403, disables adaptive residual coding */ /*#define ITD_WINNER_GAIN_MODIFY */ /* ITD optimization - WORK IN PROGRESS */ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ -#define SBA_BR_SWITCHING_2 /* Issue 114: Changes for sba bit rate switching with reconfigurations*/ -#define SBA_BR_SWITCHING /* Issue 114: Changes for sba bit rate switching*/ +#define SBA_BR_SWITCHING /* Issue 114: Changes for SBA bit rate switching with reconfiguration for bitrates with same number of transport channels*/ +#ifdef SBA_BR_SWITCHING +#define SBA_BR_SWITCHING_RECONFIG /* Issue 114: Changes for SBA bitrate switching with reconfiguration for bitrates with different number of transport channels*/ +#endif #define BRATE_SWITCHING_RENDERING /* Bitrate switching changes related to the renderers */ #define FIX_I59_DELAY_ROUNDING /* Issue 59: rounding in sample domain instead of nanosec for IVAS_ENC_GetDelay() and IVAS_DEC_GetDelay() */ #define FIX_FIX_I59 /* Issue 59: small fix concerning LFE delay rounding */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 8b29d9c7859afc9347415f920955b9c383a969f8..792d4cbd24634f8e7f0bf442ce81af37ada95dfe 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -296,7 +296,10 @@ ivas_error ivas_corecoder_dec_reconfig( 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; - +#ifdef SBA_BR_SWITCHING_RECONFIG + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[0] = -1; + st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->IGFStereoMode[1] = -1; +#endif for ( n = 0; n < CPE_CHANNELS; n++ ) { /* reset mct_chan_mode */ @@ -560,7 +563,13 @@ ivas_error ivas_cldfb_dec_reconfig( } } } - +#ifdef SBA_BR_SWITCHING_RECONFIG + /* CLDFB Interpolation weights */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) ) + { + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); + } +#endif return IVAS_ERR_OK; } #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 642d02315ab10d470b6794c18939f032dc97c9de..752bc587eb45751558da550aed2c64e962462333 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -574,7 +574,7 @@ ivas_error ivas_dec( if ( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */ { st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING st_ivas->last_active_ivas_total_brate = ( ivas_total_brate <= IVAS_SID_5k2 ) ? st_ivas->last_active_ivas_total_brate : ivas_total_brate; #endif } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index dc10bc8590a983d210d0d86c1ec1b65d01fe8f7a..6fe2b4d1c3d31556eba233097acbcc7ecc197c43 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -126,7 +126,7 @@ ivas_error ivas_dirac_dec_open( ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ #else const DIRAC_CONFIG_FLAG flag_config /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ @@ -149,7 +149,7 @@ ivas_error ivas_dirac_dec_config( int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING DIRAC_CONFIG_FLAG flag_config; flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; @@ -205,7 +205,11 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_RECONFIGURE && st_ivas->ivas_format == SBA_FORMAT ) { int16_t tmp1, tmp2, tmp3; +#ifdef SBA_BR_SWITCHING_RECONFIG + ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); +#else ivas_sba_config( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); +#endif } /*-----------------------------------------------------------------* @@ -660,7 +664,7 @@ ivas_error ivas_dirac_dec_config( } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) { -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) #else if ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 604953777f77b242c1e99ec9c6ea253bc125c7da..cea6a83d59d3014e340242bc2bdf311b917fb7a7 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -125,20 +125,16 @@ ivas_error ivas_dec_setup( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); num_bits_read += SBA_ORDER_BITS; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) #else if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) #endif { +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING -#ifndef SBA_BR_SWITCHING_2 - if ( get_sba_reinit_flag( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) -#else - int16_t sba_reinit_flag; - sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->last_active_ivas_total_brate, st_ivas->sba_order ); + int16_t sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->last_active_ivas_total_brate, st_ivas->sba_order ); if ( sba_reinit_flag ) -#endif { if ( ( error = ivas_sba_dec_reinit( st_ivas ) ) != IVAS_ERR_OK ) { @@ -147,13 +143,16 @@ ivas_error ivas_dec_setup( } else { +#endif #endif if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING } +#endif #endif } else @@ -634,7 +633,7 @@ ivas_error ivas_init_decoder( ivas_total_brate = hDecoderConfig->ivas_total_brate; hDecoderConfig->last_ivas_total_brate = ivas_total_brate; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING st_ivas->last_active_ivas_total_brate = ivas_total_brate; #endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index c2997eefc57d1d723a98000cebab9b15acee7f8b..89e72ee9f4343ab7f380449d637d455f27d32354 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -37,7 +37,7 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING #include "ivas_rom_com.h" #endif #include "ivas_rom_dec.h" @@ -47,7 +47,7 @@ #endif #include "wmc_auto.h" - +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING /*-------------------------------------------------------------------* * ivas_sba_dec_reinit() @@ -76,9 +76,8 @@ ivas_error ivas_sba_dec_reinit( ivas_total_brate = hDecoderConfig->ivas_total_brate; hDecoderConfig->last_ivas_total_brate = ivas_total_brate; -#ifdef SBA_BR_SWITCHING_2 st_ivas->last_active_ivas_total_brate = ivas_total_brate; -#endif + /*------------------------------------------------------------------------------------------* * Closing Decoder handles before Reinitialisation *------------------------------------------------------------------------------------------*/ @@ -522,7 +521,7 @@ ivas_error ivas_sba_dec_reinit( return error; } #endif - +#endif /*-------------------------------------------------------------------* * ivas_sba_dec_decoder() * @@ -545,10 +544,15 @@ ivas_error ivas_sba_dec_reconfigure( int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old; #endif int16_t sba_dirac_stereo_flag_old; -#ifndef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING_RECONFIG + SBA_MODE sba_mode_old; + int32_t ivas_total_brate, last_ivas_total_brate; +#else +#ifndef SBA_BR_SWITCHING int32_t ivas_total_brate, last_ivas_total_brate; #else int32_t ivas_total_brate; +#endif #endif DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; @@ -557,8 +561,15 @@ ivas_error ivas_sba_dec_reconfigure( hDecoderConfig = st_ivas->hDecoderConfig; ivas_total_brate = hDecoderConfig->ivas_total_brate; -#ifndef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING_RECONFIG + last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + sba_mode_old = ivas_sba_mode_select( last_ivas_total_brate ); + + st_ivas->sba_mode = sba_mode_old; +#else +#ifndef SBA_BR_SWITCHING last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; +#endif #endif /*-----------------------------------------------------------------* * Set SBA high-level parameters @@ -578,8 +589,10 @@ ivas_error ivas_sba_dec_reconfigure( sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING_RECONFIG + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); +#endif +#ifdef SBA_BR_SWITCHING /*-----------------------------------------------------------------* * Allocate, initalize, and configure SBA handles *-----------------------------------------------------------------*/ @@ -598,12 +611,78 @@ ivas_error ivas_sba_dec_reconfigure( } else { +#ifdef SBA_BR_SWITCHING_RECONFIG + int16_t i, sba_order_internal, nchan_internal; +#else int16_t sba_order_internal; +#endif DIRAC_DEC_HANDLE hDirAC = st_ivas->hDirAC; SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#ifdef SBA_BR_SWITCHING_RECONFIG + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + if ( hSpar != NULL && nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) + { + + // VE: dirty patch -> reconfiguration of SPAR modules should be used instead !! + IVAS_FB_CFG *fb_cfg; + int16_t active_w_mixing; + + /* MD handle */ + ivas_spar_md_dec_close( &hSpar->hMdDec ); + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, nchan_internal, sba_order_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + hSpar->hMdDec->td_decorr_flag = 1; + hSpar->hMdDec->table_idx = -1; + + /* TD decorr. */ + ivas_spar_td_decorr_dec_close( &hSpar->hTdDecorr ); + + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, hDecoderConfig->output_Fs, nchan_internal, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, hDecoderConfig->output_Fs ); + + /* set FB config. */ + active_w_mixing = -1; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, nchan_internal, active_w_mixing, hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->pcm_offset = NS2SA( hDecoderConfig->output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, hDecoderConfig->output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* mixer_mat intitialization */ + for ( i = 0; i < nchan_internal; i++ ) + { + for ( int16_t j = 0; j < nchan_internal; j++ ) + { + for ( int16_t b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + { + hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + } + } + } + } + hSpar->i_subframe = 0; + } +#endif /* PCA handle */ if ( hSpar != NULL ) { @@ -622,7 +701,17 @@ ivas_error ivas_sba_dec_reconfigure( hSpar->hPCA = NULL; } } +#ifdef SBA_BR_SWITCHING_RECONFIG + if ( hSpar == NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( ( error = ivas_spar_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + hSpar = st_ivas->hSpar; + } +#endif st_ivas->sba_dirac_stereo_flag = 0; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); @@ -637,21 +726,23 @@ ivas_error ivas_sba_dec_reconfigure( hDirAC = st_ivas->hDirAC; } - +#ifndef SBA_BR_SWITCHING_RECONFIG if ( hDirAC != NULL ) +#else + if ( ( hDirAC != NULL ) && ( sba_mode_old == st_ivas->sba_mode ) ) +#endif { ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); - +#ifndef SBA_BR_SWITCHING_RECONFIG mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; +#endif } - 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 ( st_ivas->nchan_transport == 1 ) { st_ivas->element_mode_init = IVAS_SCE; @@ -669,7 +760,7 @@ ivas_error ivas_sba_dec_reconfigure( *-----------------------------------------------------------------*/ /* renderer might have changed */ intern_config_old = st_ivas->intern_config; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING RENDERER_TYPE old_renderer_type; old_renderer_type = st_ivas->renderer_type; #endif @@ -698,7 +789,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_binRenderer_close( &st_ivas->hBinRenderer ); } -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING if ( st_ivas->renderer_type != old_renderer_type ) { #endif @@ -710,7 +801,7 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING } #endif 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 ) ) @@ -718,7 +809,28 @@ ivas_error ivas_sba_dec_reconfigure( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } #endif -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING_RECONFIG + if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( sba_mode_old != st_ivas->sba_mode ) ) + { + DIRAC_CONFIG_FLAG flag_config; + + flag_config = DIRAC_OPEN; + if ( st_ivas->hDirAC != NULL ) + { + flag_config = DIRAC_RECONFIGURE; + if ( sba_mode_old != st_ivas->sba_mode && st_ivas->sba_mode != SBA_MODE_SPAR ) + { + flag_config = DIRAC_RECONFIGURE_MODE; + } + } + + if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#else +#ifdef SBA_BR_SWITCHING if ( ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) { if ( st_ivas->hDirAC != NULL ) @@ -736,6 +848,9 @@ ivas_error ivas_sba_dec_reconfigure( } } } +#endif +#endif +#ifdef SBA_BR_SWITCHING else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) { if ( st_ivas->hDirAC != NULL ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4cfbc98ad60a8e4242ccf8bc21ff0ab1bad26198..c09629466df4ff09b69680a6e7bf946610edb701 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1900,7 +1900,7 @@ typedef struct Decoder_Struct #ifdef DEBUGGING int32_t noClipping; /* number of clipped samples */ #endif -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING int32_t last_active_ivas_total_brate; #endif } Decoder_Struct; diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 08b9ef7b07e620a7ccba9b010f88e92f1f40c3ef..e7741a10dac02accccc66b5f61da91a1c682da72 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -108,8 +108,7 @@ ivas_error pre_proc_front_ivas( const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const int32_t ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ - const int16_t ivas_format /* i : IVAS format */ -) + const int16_t ivas_format ) { float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ float *wsp; /* weighted input signal buffer */ @@ -457,7 +456,6 @@ ivas_error pre_proc_front_ivas( st->vad_flag = front_vad_flag; st->localVAD = front_vad_flag; } - if ( ( hCPE != NULL && !( lr_vad_enabled && st->idchan == 0 ) ) || hSCE != NULL ) { *vad_flag_dtx = dtx_hangover_addition( st, st->vad_flag, st->lp_speech - st->lp_noise, 0, vad_hover_flag, NULL, NULL, NULL ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c5708647992d73c7c281eae78dfd5879e96264d3..f8ced4ec311c60886c7d3530ba1a075a1d273e03 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -65,10 +65,8 @@ 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; -#ifndef SBA_BR_SWITCHING_2 -#ifdef SBA_BR_SWITCHING +#ifndef SBA_BR_SWITCHING int16_t sba_reinit_flag; -#endif #endif error = IVAS_ERR_OK; @@ -89,19 +87,15 @@ ivas_error ivas_enc( n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE ); -#ifdef SBA_BR_SWITCHING -#ifndef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING sba_reinit_flag = 0; #endif +#ifndef SBA_BR_SWITCHING_RECONFIG +#ifdef SBA_BR_SWITCHING if ( ivas_format == SBA_FORMAT ) { -#ifndef SBA_BR_SWITCHING_2 - sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ); - if ( sba_reinit_flag ) -#else st_ivas->sba_reinit_flag = get_sba_reinit_flag( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); if ( st_ivas->sba_reinit_flag ) -#endif { if ( ( error = ivas_sba_enc_reinit( st_ivas ) ) != IVAS_ERR_OK ) { @@ -110,7 +104,7 @@ ivas_error ivas_enc( } } #endif - +#endif /*----------------------------------------------------------------* * convert 'short' input data to 'float' *----------------------------------------------------------------*/ @@ -215,11 +209,9 @@ ivas_error ivas_enc( if ( ivas_format == SBA_FORMAT ) { #ifndef SBA_BR_SWITCHING - if ( st_ivas->sba_mode == SBA_MODE_DIRAC ) -#else -#ifndef SBA_BR_SWITCHING_2 if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( !sba_reinit_flag ) ) #else +#ifndef SBA_BR_SWITCHING_RECONFIG if ( !st_ivas->sba_reinit_flag ) #endif #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index ca8fd727c0aa9403bc0d6c0393b95a8f06072462..6f2d8e377cc3c60366e79b9a0f8d762d78cdda48 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -342,8 +342,10 @@ ivas_error ivas_init_encoder( st_ivas->sba_mode = SBA_MODE_NONE; st_ivas->nchan_transport = -1; -#ifdef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING_RECONFIG +#ifdef SBA_BR_SWITCHING st_ivas->sba_reinit_flag = 0; +#endif #endif /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index c6a65c8a4aa3b95eca107f69d3f413e4a533dcd1..71ad626a4a299d29f78a1ba1854dd84a5552de6c 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -92,7 +92,7 @@ void ivas_sba_getTCs( return; } - +#ifndef SBA_BR_SWITCHING_RECONFIG #ifdef SBA_BR_SWITCHING /*-------------------------------------------------------------------* * ivas_sba_enc_reinit() @@ -313,7 +313,7 @@ ivas_error ivas_sba_enc_reinit( return error; } #endif - +#endif /*-------------------------------------------------------------------* * ivas_sba_enc_reconfigure() @@ -337,17 +337,19 @@ ivas_error ivas_sba_enc_reconfigure( if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) { -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING DIRAC_ENC_HANDLE hDirAC = st_ivas->hDirAC; SPAR_ENC_HANDLE hSpar; #endif nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; - +#ifdef SBA_BR_SWITCHING_RECONFIG + SBA_MODE sba_mode_old; + sba_mode_old = st_ivas->sba_mode; +#endif st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); - -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); if ( st_ivas->sba_mode == SBA_MODE_SPAR ) @@ -382,10 +384,126 @@ ivas_error ivas_sba_enc_reconfigure( hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } +#endif +#ifdef SBA_BR_SWITCHING_RECONFIG + /*TODO : Verify if full SPAR close and open can be used instead of submodules close and open */ + if ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) + { + /* FB mixer handle */ + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + // VE: TBV whether 'hFbMixer' can be reused + if ( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs ); + hDirAC->hFbMixer = NULL; + } + + { + // VE: dirty patch -> reconfiguration of SPAR MD, TD_decorr, FbMixer modules should be used instead !! + + IVAS_FB_CFG *fb_cfg; + int16_t nchan_internal, sba_order_internal; + int16_t table_idx, active_w_mixing; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + nchan_internal = ivas_sba_get_nchan_metadata( sba_order_internal ); + + /* Covar. State handle */ + ivas_spar_covar_enc_close( &hSpar->hCovEnc, hSpar->hFbMixer->fb_cfg->num_in_chans ); + + /* MD handle */ + ivas_spar_md_enc_close( &hSpar->hMdEnc ); + + if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + /*Initialization*/ + hSpar->hMdEnc->table_idx = -1; + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, hEncoderConfig->input_Fs ); + + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_internal, st_ivas->nchan_transport, active_w_mixing, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + + if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Covar. State handle */ + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, hEncoderConfig->input_Fs, nchan_internal ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( hDirAC->hFbMixer == NULL ) + { + IVAS_FB_CFG *fb_cfg; + + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_DIRAC, DIRAC_MAX_ANA_CHANS, 0, 0, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Allocate and initialize FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* initalize delay for SPAR/DirAC delay synchronization */ + if ( ( st_ivas->sba_mode == SBA_MODE_DIRAC ) && ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) ) + { + int16_t n; + + if ( hDirAC->num_samples_synchro_delay == 0 ) + { + hDirAC->num_samples_synchro_delay = NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ); + + for ( n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( ( hDirAC->sba_synchro_buffer[n] = (float *) malloc( hDirAC->num_samples_synchro_delay * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hDirAC synchro buffer\n" ) ); + } + set_zero( hDirAC->sba_synchro_buffer[n], hDirAC->num_samples_synchro_delay ); + } + for ( ; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + } + else + { + for ( int16_t n = 0; n < DIRAC_MAX_ANA_CHANS; n++ ) + { + if ( hDirAC->sba_synchro_buffer[n] != NULL ) + { + free( hDirAC->sba_synchro_buffer[n] ); + hDirAC->sba_synchro_buffer[n] = NULL; + } + } + hDirAC->num_samples_synchro_delay = 0; + } + } + #endif ivas_dirac_enc_reconfigure( st_ivas ); -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { mvs2s( hDirAC->dirac_to_spar_md_bands, hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); @@ -401,6 +519,27 @@ ivas_error ivas_sba_enc_reconfigure( #else ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old ); #endif + +#ifdef SBA_BR_SWITCHING_RECONFIG + if ( st_ivas->hEncoderConfig->Opt_DTX_ON ) + { + if ( ( sba_mode_old != st_ivas->sba_mode ) || ( nchan_transport_old != st_ivas->nchan_transport ) ) + { + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + st_ivas->hSCE[sce_id]->hCoreCoder[0]->ini_frame = 1; + } + + for ( int16_t cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->ini_frame = 1; + } + } + } + } +#endif } return error; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index fe965ed7889e19f1aa11c96b602f3a9ad8cea804..8bdfbef0e1355c7abbf4a8f0024c2b71ccc00494 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -292,6 +292,39 @@ ivas_error ivas_spar_enc( error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; +#ifdef SBA_BR_SWITCHING_RECONFIG + // VE2DB: can hFbMixer->ppFilterbank_prior_input be replaced by st->input ? + + /* check last sba_mode */ + if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_DIRAC ) + { + Encoder_State *sts[MCT_MAX_BLOCKS]; + + /* initializations */ + for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0]; + } + + for ( int16_t cpe_id = 0, i = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch]; + i++; + } + } + + /* update FB prior input */ + // VE: last 1ms of 'ppFilterbank_prior_input' is not correct + for ( int16_t i = 0; i < st_ivas->nchan_transport; i++ ) + { + mvr2r( ( sts[i]->input_buff + NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS ) ), + ( st_ivas->hSpar->hFbMixer->ppFilterbank_prior_input[i] + st_ivas->hSpar->hFbMixer->fb_cfg->prior_input_length - input_frame ), input_frame ); + } + } +#endif + /* front VAD */ if ( ( error = front_vad_spar( st_ivas->hSpar, data_f[0], hEncoderConfig, input_frame ) ) != IVAS_ERR_OK ) { @@ -522,7 +555,7 @@ static ivas_error ivas_spar_enc_process( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } } -#ifndef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ @@ -547,8 +580,12 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING +#ifndef SBA_BR_SWITCHING_RECONFIG if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate && !st_ivas->sba_reinit_flag ) +#else + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) +#endif { if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) { @@ -559,11 +596,11 @@ static ivas_error ivas_spar_enc_process( { #endif ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND ); -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING } #endif } -#ifdef SBA_BR_SWITCHING_2 +#ifdef SBA_BR_SWITCHING /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index c4f724b9f42642f8c080699cdb38ca34f64aa15b..68c0d42b534bee5adc4a8e62f1a8b53b3f3d7677 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -83,7 +83,7 @@ static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi, const int16_t planarCP ); -#ifndef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, const ENCODER_CONFIG_HANDLE hEncoderConfig, const int16_t sba_order ); #endif static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); @@ -306,7 +306,7 @@ void ivas_spar_md_enc_close( * * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ -#ifndef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING static ivas_error ivas_spar_md_enc_init #else ivas_error ivas_spar_md_enc_init diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 465fa3b17a0fcb322511871915fd948200c5ccd5..11dd51104d3a8b6b29847075ee9b7364c113b9c3 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1038,8 +1038,10 @@ typedef struct int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ int16_t codec_mode; /* Mode1 or Mode2 of core codec */ int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ -#ifdef SBA_BR_SWITCHING_2 +#ifndef SBA_BR_SWITCHING_RECONFIG +#ifdef SBA_BR_SWITCHING int16_t sba_reinit_flag; /*flag indicating whether reinitialisation or reconfiguration function should be used*/ +#endif #endif float **mem_hp20_in; /* input signals HP filter memories */