From 0ab6da1c832872b0b604a92dcc9e74ea24bb3d5d Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Mon, 28 Nov 2022 13:40:30 +0530 Subject: [PATCH 1/6] Made modifications for SBA bitrate switching [x] Added reconfiguration changes for switching bitrates with same transport channels [x] Changes under the switch SBA_BR_SWITCHING_2 --- lib_com/ivas_cnst.h | 4 ++ lib_com/ivas_prot.h | 15 +++- lib_com/ivas_sba_config.c | 25 ++++++- lib_com/options.h | 1 + lib_dec/ivas_dec.c | 3 + lib_dec/ivas_dirac_dec.c | 17 ++++- lib_dec/ivas_init_dec.c | 12 ++++ lib_dec/ivas_sba_dec.c | 140 ++++++++++++++++++++++++++++++++++-- lib_dec/ivas_stat_dec.h | 4 +- lib_enc/ivas_enc.c | 13 ++++ lib_enc/ivas_init_enc.c | 4 +- lib_enc/ivas_sba_enc.c | 52 +++++++++++++- lib_enc/ivas_spar_encoder.c | 16 ++++- lib_enc/ivas_spar_md_enc.c | 20 +++--- lib_enc/ivas_stat_enc.h | 4 +- 15 files changed, 305 insertions(+), 25 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 0074be76d2..4a40921268 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -923,6 +923,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 7b2ad0a798..348640389e 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 64635577b4..133bf3886d 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 73a346c809..de8b01e9ff 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -151,6 +151,7 @@ #define FIX_EFAP_MATH /* fix for EFAP: remove angle quantization and a bug in polygon lookup causing incorrect gains. minor tweak for ALLRAD. non-BE for modes using EFAP */ #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 FIX_MCT_PLC_RECOVERY /* Issue 184: scale the old synthesis part correctly in the first good frame after lost frames in MCT modes - to be activated after previous switch is merged */ +#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_AGC_WINFUNC_MEMORY /* Issue 62: lower agc_com.winFunc memory consumption */ #define REMOVE_SID_HARM_LEFTOVERS /* Issue 192: remove leftovers from the SID bitrate harmonization */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 5d3a5a10f9..c3deb7103f 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 5f9e908481..990e5607fd 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -129,8 +129,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; @@ -149,7 +153,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; @@ -277,6 +285,9 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifdef SBA_BR_SWITCHING_2 + st_ivas->nchan_transport = nchan_transport_orig; +#endif return IVAS_ERR_OK; } @@ -661,7 +672,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 e51b46779c..9f42ccb99f 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 975fb60480..86fa059209 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,13 +601,94 @@ 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; ivas_renderer_select( st_ivas ); @@ -606,7 +698,6 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } - #ifdef BRATE_SWITCHING_RENDERING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles @@ -638,11 +729,47 @@ ivas_error ivas_sba_dec_reconfigure( 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 +822,7 @@ ivas_error ivas_sba_dec_reconfigure( vbap_free_data( &( st_ivas->hVBAPdata ) ); } } - +#endif /*-----------------------------------------------------------------* * Allocate, initalize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ @@ -736,7 +863,6 @@ ivas_error ivas_sba_dec_reconfigure( } } #endif - /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2393a41f2f..5338d4e8bc 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1965,7 +1965,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 7be1f11c49..61faee23a4 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 18280a60e2..8d3f78d154 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 003baa0fa0..04aba97747 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 b08eeb5e4b..e0365b6055 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -547,7 +547,21 @@ 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 } 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 09c766b581..11893eff81 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 0644fcd918..542c52b19a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1030,7 +1030,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 */ -- GitLab From bfc59e741fdc487a92dbe2238424b9e3dde289f6 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Tue, 29 Nov 2022 13:18:37 +0530 Subject: [PATCH 2/6] Modified ivas_sba_dec_reconfigure() [x] Added a conditional check to avoid reinitialisastion of parametric binaural renderer if renderer type remains the same --- lib_dec/ivas_sba_dec.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 86fa059209..44066333fd 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -691,6 +691,10 @@ ivas_error ivas_sba_dec_reconfigure( *-----------------------------------------------------------------*/ /* 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 */ @@ -715,15 +719,21 @@ 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 ); -- GitLab From ddbf0485ab45baa28728a95244f4b45fc65603a0 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Thu, 1 Dec 2022 14:37:06 +0530 Subject: [PATCH 3/6] Fix for gap while switching from 24.4 to 32 Kbps --- lib_enc/ivas_spar_encoder.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index e0365b6055..989f7a0a9e 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -523,21 +523,6 @@ static ivas_error ivas_spar_enc_process( } } - /*-----------------------------------------------------------------------------------------* - * 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 ); - /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ @@ -563,6 +548,21 @@ static ivas_error ivas_spar_enc_process( } #endif } + + /*-----------------------------------------------------------------------------------------* + * 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 ); nchan_transport = st_ivas->nchan_transport; -- GitLab From 5a93958896c594d39f1c6b8b386aa967186a92a0 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Thu, 1 Dec 2022 14:54:12 +0530 Subject: [PATCH 4/6] Moved the previous fix under the switch [x] moved the fix into the switch SBA_BR_SWITCHING_2 --- lib_enc/ivas_spar_encoder.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 989f7a0a9e..207958b1eb 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -522,7 +522,22 @@ static ivas_error ivas_spar_enc_process( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } } +#ifndef 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 /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates *-----------------------------------------------------------------------------------------*/ @@ -548,7 +563,7 @@ static ivas_error ivas_spar_enc_process( } #endif } - +#ifdef SBA_BR_SWITCHING_2 /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ @@ -563,7 +578,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 nchan_transport = st_ivas->nchan_transport; /*-----------------------------------------------------------------------------------------* -- GitLab From 5ce6f76ebe7f2f7d876d75dff0aca0a0e8edac1a Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Fri, 2 Dec 2022 11:39:56 +0530 Subject: [PATCH 5/6] Clang formatting done --- lib_dec/ivas_sba_dec.c | 30 ++++++++++++++++-------------- lib_enc/ivas_spar_encoder.c | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 44066333fd..4e96c041bd 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -702,6 +702,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } + #ifdef BRATE_SWITCHING_RENDERING /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles @@ -720,13 +721,13 @@ ivas_error ivas_sba_dec_reconfigure( ivas_binRenderer_close( &st_ivas->hBinRenderer ); } #ifdef SBA_BR_SWITCHING_2 - if (st_ivas->renderer_type != old_renderer_type) + if ( st_ivas->renderer_type != old_renderer_type ) { #endif - if (st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { /* open parametric binaural renderer */ - if ((error = ivas_dirac_dec_init_binaural_data(st_ivas)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -740,40 +741,40 @@ ivas_error ivas_sba_dec_reconfigure( } #endif #ifdef SBA_BR_SWITCHING_2 - if ((st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC)) + if ( ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) { - if (st_ivas->hDirAC != NULL) + if ( st_ivas->hDirAC != NULL ) { - if ((error = ivas_dirac_dec_config(st_ivas, DIRAC_RECONFIGURE)) != IVAS_ERR_OK) + 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) + 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)) + 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) + if ( st_ivas->hDirAC != NULL ) { - ivas_dirac_dec_close(st_ivas->hDirAC); + ivas_dirac_dec_close( st_ivas->hDirAC ); st_ivas->hDirAC = NULL; } - if (st_ivas->hVBAPdata != NULL) + if ( st_ivas->hVBAPdata != NULL ) { - vbap_free_data(&(st_ivas->hVBAPdata)); + vbap_free_data( &( st_ivas->hVBAPdata ) ); } } - if (st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR) + 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); + 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 @@ -873,6 +874,7 @@ ivas_error ivas_sba_dec_reconfigure( } } #endif + /* Analysis*/ if ( numCldfbAnalyses_old > numCldfbAnalyses ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 207958b1eb..dc6b5f7c73 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -523,7 +523,7 @@ static ivas_error ivas_spar_enc_process( } } #ifndef SBA_BR_SWITCHING_2 - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ -- GitLab From a6b31d63b7b4b9558f8e7e4fc25dddf6aaf6c710 Mon Sep 17 00:00:00 2001 From: Vidhya V P <100825@ittiam.com> Date: Mon, 5 Dec 2022 10:21:12 +0530 Subject: [PATCH 6/6] Removed a line of code --- lib_dec/ivas_dirac_dec.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 990e5607fd..dbdf0870e8 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -285,9 +285,6 @@ ivas_error ivas_dirac_dec_config( /* band config needed only for SPAR with FOA output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->sba_mode == SBA_MODE_SPAR ) { -#ifdef SBA_BR_SWITCHING_2 - st_ivas->nchan_transport = nchan_transport_orig; -#endif return IVAS_ERR_OK; } -- GitLab