diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 4a9ce1e080d9b8237362f931a8dbec26ee7cbcae..95ce27095755e08fde807f7bd44c9d9e214be85a 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -926,6 +926,10 @@ typedef enum { DIRAC_OPEN, /* initialize to default value */ DIRAC_RECONFIGURE /* HOA3 */ +#ifdef SBA_BR_SWITCHING_2 + , + DIRAC_RECONFIGURE_MODE +#endif } DIRAC_CONFIG_FLAG; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 1757d1b8e2140f8ecbaec017dda39dc9cb8e3ef7..6cb365bfadc5c07b16acafb44ec64c62be5baa1b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -112,8 +112,19 @@ ivas_error ivas_sba_enc_reinit( #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 */ + int32_t ivas_total_bitrate, /* i : Current bitrate */ + int32_t last_ivas_total_brate /* i : Previous bitrate */ +#ifdef SBA_BR_SWITCHING_2 + , 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_enc_reconfigure( diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 64635577b446f98d9c13a07a2d45ab263890cd1e..133bf3886d901acab3b98b19b9cb4820d4739759 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -82,14 +82,37 @@ 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 + , + int16_t sba_order +#endif ) { 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 { - sba_reinit_flag = 1; +#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 ); + nchan_transport_old = ivas_get_sba_num_TCs( last_ivas_total_brate, min( sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); + last_sba_mode = ivas_sba_mode_select( last_ivas_total_brate ); + current_sba_mode = ivas_sba_mode_select( ivas_total_bitrate ); + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_bitrate, sba_order ); + 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; diff --git a/lib_com/options.h b/lib_com/options.h index 2011fb56b4ca1966da30353ef1154d8c7fdc87fe..d7d33c9ebc236d1677493e1a2728b78b905344b0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -146,6 +146,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define FIX_I1_113 /* under review : MCT bit distribution optimization for SBA high bitrates*/ #define FIX_124_DONT_ALLOC_PLCINFO_IN_IVAS /* Issue 124: do not allocate unused plc struct in IVAS modes which is only used in EVS mono */ +#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 FIX_ITD /* Contribution 16: TD renderer ITD improvement and code cleanup */ #define BRATE_SWITCHING_RENDERING /* Bitrate switching changes related to the renderers */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 5d3a5a10f943086dec40888bbf09247b6397af06..c3deb7103f872426d92b39a56614fab8fd6f843f 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -563,6 +563,9 @@ 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 + st_ivas->last_active_ivas_total_brate = ( ivas_total_brate <= IVAS_SID_5k2 ) ? st_ivas->last_active_ivas_total_brate : ivas_total_brate; +#endif } if ( st_ivas->ini_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index f2273de26d20bc8dd327c9aaef8161ecc8a67a10..03e0f5f6e034d918c5745375968fac6af872a483 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -125,8 +125,12 @@ ivas_error ivas_dirac_dec_open( *-------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef SBA_BR_SWITCHING_2 + 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 */ +#endif ) { DIRAC_DEC_HANDLE hDirAC; @@ -145,7 +149,11 @@ 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 + DIRAC_CONFIG_FLAG flag_config; + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; +#endif error = IVAS_ERR_OK; hDirAC = NULL; @@ -652,7 +660,11 @@ 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 + 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 ) ) +#endif { /* close and reopen the decorrelator */ ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e51b46779c33ea1a468d63af12ef4c8a16b6dac2..9f42ccb99f2f7af5bc40172f006a8f5f299eb02d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -125,10 +125,19 @@ 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 + 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 { #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 = 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 ) { @@ -624,6 +633,9 @@ 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 + st_ivas->last_active_ivas_total_brate = ivas_total_brate; +#endif if ( output_config == AUDIO_CONFIG_EXTERNAL ) { diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 975fb604805a3131d590896ca5fc0051359221c6..4e96c041bdddadc1e9559ba5a18aee65f949cd79 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -37,6 +37,9 @@ #include "ivas_cnst.h" #include "prot.h" #include "ivas_prot.h" +#ifdef SBA_BR_SWITCHING_2 +#include "ivas_rom_com.h" +#endif #include "ivas_rom_dec.h" #include #ifdef DEBUGGING @@ -73,6 +76,9 @@ 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 *------------------------------------------------------------------------------------------*/ @@ -561,7 +567,11 @@ 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 int32_t ivas_total_brate, last_ivas_total_brate; +#else + int32_t ivas_total_brate; +#endif DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; @@ -569,8 +579,9 @@ ivas_error ivas_sba_dec_reconfigure( hDecoderConfig = st_ivas->hDecoderConfig; ivas_total_brate = hDecoderConfig->ivas_total_brate; +#ifndef SBA_BR_SWITCHING_2 last_ivas_total_brate = hDecoderConfig->last_ivas_total_brate; - +#endif /*-----------------------------------------------------------------* * Set SBA high-level parameters * Save old SBA high-level parameters @@ -590,15 +601,100 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &st_ivas->nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); +#ifdef SBA_BR_SWITCHING_2 + /*-----------------------------------------------------------------* + * Allocate, initalize, and configure SBA handles + *-----------------------------------------------------------------*/ + + if ( st_ivas->sba_mode != SBA_MODE_SPAR ) + { + ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs ); + st_ivas->hSpar = NULL; + + 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 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); + } + else + { + int16_t sba_order_internal; + 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 ); + + /* PCA handle */ + if ( hSpar != NULL ) + { + if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) + { + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + ivas_pca_dec_init( hSpar->hPCA ); + } + else if ( hSpar->hPCA != NULL ) + { + count_free( st_ivas->hSpar->hPCA ); + hSpar->hPCA = NULL; + } + } + + st_ivas->sba_dirac_stereo_flag = 0; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); + + if ( hDirAC == NULL && st_ivas->sba_mode == SBA_MODE_DIRAC ) + { + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + hDirAC = st_ivas->hDirAC; + } + + if ( hDirAC != NULL ) + { + ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE_MODE ); + + 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; + } + + 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; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } +#else + 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 ); + +#endif /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ - /* renderer might have changed */ intern_config_old = st_ivas->intern_config; +#ifdef SBA_BR_SWITCHING_2 + RENDERER_TYPE old_renderer_type; + old_renderer_type = st_ivas->renderer_type; +#endif ivas_renderer_select( st_ivas ); /* side effect of the renderer selection can be a changed internal config */ @@ -624,25 +720,67 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_binRenderer_close( &st_ivas->hBinRenderer ); } - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) +#ifdef SBA_BR_SWITCHING_2 + if ( st_ivas->renderer_type != old_renderer_type ) { - /* open parametric binaural renderer */ - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) +#endif + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { - return error; + /* open parametric binaural renderer */ + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } +#ifdef SBA_BR_SWITCHING_2 } +#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 ) ) { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } #endif +#ifdef SBA_BR_SWITCHING_2 + if ( ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + 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->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) + { + if ( st_ivas->hDirAC != NULL ) + { + ivas_dirac_dec_close( st_ivas->hDirAC ); + st_ivas->hDirAC = NULL; + } + + if ( st_ivas->hVBAPdata != NULL ) + { + vbap_free_data( &( st_ivas->hVBAPdata ) ); + } + } + if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) + { + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } +#else /*-----------------------------------------------------------------* * hDirAC decoder handle configuration *-----------------------------------------------------------------*/ - if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { st_ivas->sba_dirac_stereo_flag = ( st_ivas->nchan_transport == 1 && hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ); @@ -695,7 +833,7 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } - +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a18f826921eac23410fd0d534d1f8ff80af15721..de79f876d6a34d458fac0d2a0914006c6df6732c 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1974,7 +1974,9 @@ typedef struct Decoder_Struct #ifdef DEBUGGING int32_t noClipping; /* number of clipped samples */ #endif - +#ifdef SBA_BR_SWITCHING_2 + int32_t last_active_ivas_total_brate; +#endif } Decoder_Struct; /* clang-format on */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 7be1f11c497e9df75593038c42be91d6d6fff351..61faee23a4320855fb763885cd1613a75e02847e 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -65,8 +65,10 @@ 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 int16_t sba_reinit_flag; +#endif #endif error = IVAS_ERR_OK; @@ -88,11 +90,18 @@ ivas_error ivas_enc( set_s( nb_bits_metadata, 0, MAX_SCE ); #ifdef SBA_BR_SWITCHING +#ifndef SBA_BR_SWITCHING_2 sba_reinit_flag = 0; +#endif 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 ) { @@ -208,7 +217,11 @@ ivas_error ivas_enc( #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 + if ( !st_ivas->sba_reinit_flag ) +#endif #endif { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 18280a60e2258262f799042a73963b71bbab9c2b..8d3f78d1541d9ed074a2eb7d5d7300ff7dc667f6 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -342,7 +342,9 @@ ivas_error ivas_init_encoder( st_ivas->sba_mode = SBA_MODE_NONE; st_ivas->nchan_transport = -1; - +#ifdef SBA_BR_SWITCHING_2 + st_ivas->sba_reinit_flag = 0; +#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 003baa0fa03e1573cabaada8765d68696ef558c9..04aba97747c614c2803259e837c93055247e8eca 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -332,18 +332,66 @@ ivas_error ivas_sba_enc_reconfigure( error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - +#ifdef SBA_BR_SWITCHING_2 + ENCODER_CONFIG_HANDLE hEncoderConfig; + hEncoderConfig = st_ivas->hEncoderConfig; +#endif if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) { +#ifdef SBA_BR_SWITCHING_2 + 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; st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#ifdef SBA_BR_SWITCHING_2 + st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); - ivas_dirac_enc_reconfigure( st_ivas ); + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + if ( st_ivas->hSpar == NULL ) + { + if ( ( error = ivas_spar_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + // VE: TBV - populate 'hSpar->hFrontVad' with 'hCoreCoder[0]' instead of resetting it to init-state? + } + ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), + &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); + } + else + { + ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp ); + st_ivas->hSpar = NULL; + } + hSpar = st_ivas->hSpar; + + if ( st_ivas->nchan_transport == 1 ) + { + hEncoderConfig->element_mode_init = IVAS_SCE; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + +#endif + ivas_dirac_enc_reconfigure( st_ivas ); + +#ifdef SBA_BR_SWITCHING_2 + if ( st_ivas->sba_mode == SBA_MODE_SPAR ) + { + 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 /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index b08eeb5e4bf26d821e54fd4e48cc46ec483520f1..dc6b5f7c73fc7496439c88137ef7a5b69f9bc261 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -522,7 +522,7 @@ static ivas_error ivas_spar_enc_process( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } } - +#ifndef SBA_BR_SWITCHING_2 /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ @@ -537,7 +537,7 @@ static ivas_error ivas_spar_enc_process( } ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det ); - +#endif /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ @@ -547,9 +547,38 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->table_idx != table_idx ) { hSpar->hMdEnc->table_idx = table_idx; - 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 + if ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate && !st_ivas->sba_reinit_flag ) + { + if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { +#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 + } +#endif + } +#ifdef SBA_BR_SWITCHING_2 + /*-----------------------------------------------------------------------------------------* + * Covariance process + *-----------------------------------------------------------------------------------------*/ + + for ( i = 0; i < nchan_inp; i++ ) + { + for ( j = 0; j < nchan_inp; j++ ) + { + cov_real[i][j] = hSpar->hMdEnc->cov_real[i][j]; + cov_dtx_real[i][j] = hSpar->hMdEnc->cov_dtx_real[i][j]; + } } + ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det ); +#endif nchan_transport = st_ivas->nchan_transport; /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 09c766b58106020f1f85a5cb8e320366021811a0..11893eff818fc43ea3df2332c8d621f2601188d2 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -83,9 +83,9 @@ 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 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 ); static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); @@ -306,12 +306,16 @@ void ivas_spar_md_enc_close( * * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ - -static 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 */ -) +#ifndef SBA_BR_SWITCHING_2 +static ivas_error ivas_spar_md_enc_init +#else +ivas_error ivas_spar_md_enc_init +#endif + ( + 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 */ + ) { float pFC[IVAS_MAX_NUM_BANDS]; int16_t table_idx; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index dfe32a9a020eeca01e09aeb4486ee5e1579e9b28..81b89a5edc1cba59249ba4bf945e29548e3e5b95 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1048,7 +1048,9 @@ 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 + int16_t sba_reinit_flag; /*flag indicating whether reinitialisation or reconfiguration function should be used*/ +#endif float **mem_hp20_in; /* input signals HP filter memories */ /* core-encoder modules */