diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj
index 3bde19ca477629259cb331c6220c55f063e40eb1..5860b0a9708d869b8a4f66c31a0022ea33a2e12e 100644
--- a/Workspace_msvc/lib_dec.vcxproj
+++ b/Workspace_msvc/lib_dec.vcxproj
@@ -267,6 +267,7 @@
+
diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters
index 155b8dfc458ebc9e0526b83aab251c90a792f1ac..5476cf558887abd6d7b549246ce9da5696876e3b 100644
--- a/Workspace_msvc/lib_dec.vcxproj.filters
+++ b/Workspace_msvc/lib_dec.vcxproj.filters
@@ -581,6 +581,9 @@
dec_ivas_c
+
+ dec_ivas_c
+
diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj
index 40302c56cd09ea3191d637279e5627b487c5afb0..c1144daf310d41455179ea56895d8a361d7e902b 100644
--- a/Workspace_msvc/lib_enc.vcxproj
+++ b/Workspace_msvc/lib_enc.vcxproj
@@ -206,6 +206,7 @@
+
diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters
index 471a5f9a640c236fff4c2a4df8c28a569de7c245..1d7ee5594f55b6ea9cb21e9bbd5e7056cabbe882 100644
--- a/Workspace_msvc/lib_enc.vcxproj.filters
+++ b/Workspace_msvc/lib_enc.vcxproj.filters
@@ -581,6 +581,9 @@
enc_ivas_c
+
+ enc_ivas_c
+
diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h
index 0c44e89b7e73a9e07a9071403f5f331486b7e819..dea7c84ecbf68b45541ff1889057e5d9056a51dd 100644
--- a/lib_com/ivas_prot.h
+++ b/lib_com/ivas_prot.h
@@ -119,6 +119,19 @@ void destroy_cpe_enc(
CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */
);
+void ivas_mct_enc_close(
+ MCT_ENC_HANDLE hMCT /* i/o: MCT encoder structure */
+);
+
+#ifdef CORECODER_BITRATE_SWITCHING
+ivas_error ivas_corecoder_enc_reconfig(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ const int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old /* i : number of TCs in previous frame */
+);
+#endif
+
ivas_error ivas_sce_enc(
Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
const int16_t sce_id, /* i : SCE # identifier */
@@ -191,6 +204,9 @@ ivas_error pre_proc_ivas(
Encoder_State *st, /* i/o: encoder state structure */
const int16_t last_element_mode, /* i : last element mode */
const int32_t element_brate, /* i : element bitrate */
+#ifdef CORECODER_BITRATE_SWITCHING
+ const int32_t last_element_brate, /* i : last element bitrate */
+#endif
const int16_t input_frame, /* i : frame length */
float old_inp_12k8[], /* i/o: buffer of old input signal */
float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
@@ -315,6 +331,21 @@ void ivas_mct_dec_close(
MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */
);
+#ifdef CORECODER_BITRATE_SWITCHING
+ivas_error ivas_corecoder_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ const int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
+ const int16_t sba_dirac_stereo_flag_old /* i : signal stereo output for SBA DirAC in previous frame */
+);
+
+ivas_error ivas_hp20_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame*/
+);
+#endif
+
ivas_error ivas_sce_dec(
Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
const int16_t sce_id, /* i : SCE # identifier */
@@ -385,6 +416,9 @@ ivas_error ivas_core_enc(
float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */
const int16_t tdm_SM_flag, /* i : channel combination scheme flag */
+#ifdef CORECODER_BITRATE_SWITCHING
+ const int16_t ivas_format, /* i : IVAS format */
+#endif
const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
);
@@ -2737,10 +2771,6 @@ void mctStereoIGF_dec(
const int16_t bfi /* i : bad frame flag */
);
-void ivas_mct_enc_close(
- MCT_ENC_HANDLE hMCT /* i/o: MCT encoder structure */
-);
-
void ivas_mdct_tcx10_bit_distribution(
int16_t target_bitsTCX10[NB_DIV], /* o : target bit distribution */
const int16_t bits_frame_channel, /* i : bits frame channel */
diff --git a/lib_com/options.h b/lib_com/options.h
index f040d6b10d4eac75b63f3d468d951670c7502c96..ca5c1c133037494c4fb4b3b0d90e3336911b50ba 100755
--- a/lib_com/options.h
+++ b/lib_com/options.h
@@ -147,6 +147,9 @@
/*#define FIX_I1_113*/ /* under review : MCT bit distribution optimization for SBA high bitrates*/
#define FIX_I13_TCX_TNS_ISSUE /* Issue 13: Fix reported artifacts. Bug in TNS with TCX5 */
+#define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */
+
+
/* ################## End DEVELOPMENT switches ######################### */
diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c
new file mode 100644
index 0000000000000000000000000000000000000000..4ea39c6e763c399d9a3647ec1181cc98a82eff5d
--- /dev/null
+++ b/lib_dec/ivas_corecoder_dec_reconfig.c
@@ -0,0 +1,399 @@
+/******************************************************************************************************
+
+ (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include "options.h"
+#include "ivas_cnst.h"
+#include "ivas_prot.h"
+#include "ivas_rom_com.h"
+#include "ivas_stat_enc.h"
+#include "lib_dec.h"
+#include "prot.h"
+#include
+#include
+#include
+#ifdef DEBUGGING
+#include "debug.h"
+#endif
+#include "wmops.h"
+
+
+#ifdef CORECODER_BITRATE_SWITCHING
+/*-------------------------------------------------------------------*
+ * ivas_corecoder_dec_reconfig()
+ *
+ * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching
+ *-------------------------------------------------------------------*/
+
+ivas_error ivas_corecoder_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ const int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
+ const int16_t sba_dirac_stereo_flag_old /* i : signal stereo output for SBA DirAC in previous frame */
+)
+{
+ int16_t n, sce_id, cpe_id, output_frame;
+ int16_t nSCE_existing, nCPE_existing;
+ int32_t ivas_total_brate;
+ DECODER_CONFIG_HANDLE hDecoderConfig;
+ ivas_error error;
+
+ /*-----------------------------------------------------------------*
+ * Initialization
+ *-----------------------------------------------------------------*/
+
+ hDecoderConfig = st_ivas->hDecoderConfig;
+ ivas_total_brate = hDecoderConfig->ivas_total_brate;
+ error = IVAS_ERR_OK;
+
+ output_frame = (int16_t) ( hDecoderConfig->output_Fs / FRAMES_PER_SEC );
+
+ /*-----------------------------------------------------------------*
+ * Allocate, initalize, and configure SCE/CPE/MCT handles
+ *-----------------------------------------------------------------*/
+
+ /* remove dummy CPE element for DFT stereo-like upmix */
+ if ( st_ivas->ivas_format == SBA_FORMAT && sba_dirac_stereo_flag_old && !st_ivas->sba_dirac_stereo_flag )
+ {
+ st_ivas->hCPE[0]->hCoreCoder[0] = NULL;
+ st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
+ destroy_cpe_dec( st_ivas->hCPE[0] );
+ st_ivas->hCPE[0] = NULL;
+
+ if ( st_ivas->hSCE[0] != NULL )
+ {
+ count_free( st_ivas->hSCE[0]->save_synth );
+ st_ivas->hSCE[0]->save_synth = NULL;
+
+ count_free( st_ivas->hSCE[0]->save_hb_synth );
+ st_ivas->hSCE[0]->save_hb_synth = NULL;
+ }
+ }
+
+ if ( st_ivas->nchan_transport == nchan_transport_old )
+ {
+ for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+
+ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
+
+ /* prepare bitstream buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+ }
+
+ if ( st_ivas->nCPE > 1 )
+ {
+ if ( ( error = mct_dec_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ }
+ else
+ {
+ nSCE_existing = min( nSCE_old, st_ivas->nSCE );
+ nCPE_existing = min( nCPE_old, st_ivas->nCPE );
+
+ // VE: TBV - try to reuse the CoreCoder
+ /* destroy superfluous core coder elements */
+ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
+ {
+ destroy_sce_dec( st_ivas->hSCE[sce_id] );
+ st_ivas->hSCE[sce_id] = NULL;
+ }
+
+ for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
+ {
+ destroy_cpe_dec( st_ivas->hCPE[cpe_id] );
+ st_ivas->hCPE[cpe_id] = NULL;
+ }
+
+ if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
+ {
+ ivas_mct_dec_close( &st_ivas->hMCT );
+ }
+
+ /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles from the first CPE*/
+ if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
+ {
+ count_free( st_ivas->hCPE[0]->hStereoMdct );
+ st_ivas->hCPE[0]->hStereoMdct = NULL;
+ }
+
+ for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
+ {
+ st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+ for ( ; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
+ {
+ st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
+
+ /* prepare bitstream buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+ }
+ for ( ; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
+ {
+ if ( nCPE_old == 1 )
+ {
+ /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
+ st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
+ st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0;
+ }
+ }
+
+ if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
+ {
+ if ( ( error = mct_dec_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
+ if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
+ {
+ if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
+ }
+
+ 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;
+
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ /* reset mct_chan_mode */
+ st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
+ }
+ }
+ }
+
+ /* create dummy CPE element for DFT stereo-like upmix */
+ if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old )
+ {
+ if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ // VE: TBV - just reset for now
+ set_f( st_ivas->hCPE[0]->hStereoDft->buff_LBTCX_mem, 0, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ) );
+
+ st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
+ st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
+
+ if ( st_ivas->hSCE[0]->save_synth == NULL )
+ {
+ if ( ( st_ivas->hSCE[0]->save_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo output\n" ) );
+ }
+ set_zero( st_ivas->hSCE[0]->save_synth, output_frame );
+ }
+
+ if ( st_ivas->hSCE[0]->save_hb_synth == NULL )
+ {
+ if ( ( st_ivas->hSCE[0]->save_hb_synth = (float *) count_malloc( sizeof( float ) * output_frame ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate HB memory for stereo output\n" ) );
+ }
+ set_zero( st_ivas->hSCE[0]->save_hb_synth, output_frame );
+ }
+ }
+
+ /*-----------------------------------------------------------------*
+ * Set CNA/CNG flags
+ *-----------------------------------------------------------------*/
+
+ /// VE: this could be merged with part of ivas_init_decoder()
+ if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 )
+ {
+ /* skip as done in init function */
+ }
+ else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
+ {
+ st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
+ st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
+ }
+ else if ( st_ivas->nchan_transport == 2 )
+ {
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0;
+ st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1;
+ }
+ }
+ else
+ {
+ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0;
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0;
+ }
+ }
+ }
+
+ /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */
+ if ( hDecoderConfig->last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 )
+ {
+ if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ return error;
+}
+
+
+/*-------------------------------------------------------------------*
+ * ivas_hp20_dec_reconfig()
+ *
+ * Allocate, initalize, and configure HP20 memory handles in case of bitrate switching
+ *-------------------------------------------------------------------*/
+
+ivas_error ivas_hp20_dec_reconfig(
+ Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
+ const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame */
+)
+{
+ int16_t i, nchan_hp20;
+ float **old_mem_hp20_out;
+ ivas_error error;
+
+ error = IVAS_ERR_OK;
+
+ /*-----------------------------------------------------------------*
+ * HP20 memories
+ *-----------------------------------------------------------------*/
+
+ nchan_hp20 = getNumChanSynthesis( st_ivas );
+
+ if ( nchan_hp20 > nchan_hp20_old )
+ {
+ /* save old mem_hp_20 pointer */
+ old_mem_hp20_out = st_ivas->mem_hp20_out;
+ st_ivas->mem_hp20_out = NULL;
+
+ if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
+ }
+
+ for ( i = 0; i < nchan_hp20_old; i++ )
+ {
+ st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
+ old_mem_hp20_out[i] = NULL;
+ }
+ /* create additional hp20 memories */
+ for ( ; i < nchan_hp20; i++ )
+ {
+ if ( ( st_ivas->mem_hp20_out[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
+ }
+
+ set_f( st_ivas->mem_hp20_out[i], 0.0f, L_HP20_MEM );
+ }
+
+ count_free( old_mem_hp20_out );
+ old_mem_hp20_out = NULL;
+ }
+ else if ( nchan_hp20 < nchan_hp20_old )
+ {
+ /* save old mem_hp_20 pointer */
+ old_mem_hp20_out = st_ivas->mem_hp20_out;
+ st_ivas->mem_hp20_out = NULL;
+
+ if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
+ }
+
+ for ( i = 0; i < nchan_hp20; i++ )
+ {
+ st_ivas->mem_hp20_out[i] = old_mem_hp20_out[i];
+ old_mem_hp20_out[i] = NULL;
+ }
+ /* remove superfluous hp20 memories */
+ for ( ; i < nchan_hp20_old; i++ )
+ {
+ count_free( old_mem_hp20_out[i] );
+ old_mem_hp20_out[i] = NULL;
+ }
+
+ count_free( old_mem_hp20_out );
+ old_mem_hp20_out = NULL;
+ }
+
+ return error;
+}
+#endif
diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c
index 8e5ec212aaf3d3dcad6c2f9ade78c75dccab822b..b008c687894dea6db3e274187a8a2cc1a14a942f 100644
--- a/lib_dec/ivas_cpe_dec.c
+++ b/lib_dec/ivas_cpe_dec.c
@@ -496,7 +496,7 @@ ivas_error ivas_cpe_dec(
#ifdef DEBUG_MODE_INFO
{
- float tmpF = ivas_total_brate / 1000.0f;
+ float tmpF = hCPE->element_brate / 1000.0f;
n = 1;
if ( st_ivas->ini_frame == 0 && frame > 0 )
@@ -508,12 +508,15 @@ ivas_error ivas_cpe_dec(
for ( i = 0; i < n; i++ )
{
dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) );
- dbgwrite( &hCPE->element_mode, 2, 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) );
+ dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, cpe_id, DEC ) );
for ( int16_t j = 0; j < CPE_CHANNELS; j++ )
{
dbgwrite( output[j], sizeof( float ), output_frame, 1, fname( debug_dir, "output.cpe", j, cpe_id, DEC ) );
}
+ tmpF = 0;
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) );
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) );
}
}
#endif
diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c
index 911de57d7ee910f73f738b75724b1772f077a414..e3849dfbe090ca8d8e305af266eb324b2064b5eb 100644
--- a/lib_dec/ivas_init_dec.c
+++ b/lib_dec/ivas_init_dec.c
@@ -887,6 +887,9 @@ ivas_error ivas_init_decoder(
}
st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
+#ifdef CORECODER_BITRATE_SWITCHING
+ st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
+#endif
}
if ( st_ivas->nCPE > 1 )
@@ -1084,6 +1087,9 @@ ivas_error ivas_init_decoder(
}
st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */
+#ifdef CORECODER_BITRATE_SWITCHING
+ st_ivas->hCPE[0]->hCoreCoder[1] = NULL;
+#endif
}
/* set CNA/CNG flags */
diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c
index 31f32084291d8ddf9239f5a10c592e474f95ce34..b4a4da3e3c0acbbcdb06facb2d12856a8c4aabe6 100644
--- a/lib_dec/ivas_mct_dec.c
+++ b/lib_dec/ivas_mct_dec.c
@@ -250,6 +250,19 @@ ivas_error ivas_mct_dec(
#endif
}
+#ifdef DEBUG_MODE_INFO
+ for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
+ {
+ float tmpF = st_ivas->hCPE[cpe_id]->element_brate / 1000.0f;
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, cpe_id, DEC ) );
+
+ dbgwrite( output[0], sizeof( float ), output_frame, 1, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) );
+ tmpF = 0;
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) );
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, cpe_id, DEC ) );
+ }
+#endif
+
wmops_sub_end();
return error;
}
diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c
index ac056971e22fb1d6460d1ff03dc86c9f35eeb2c7..2180cb79a31b039e4ee6bde871dc6068b9fa5a86 100644
--- a/lib_dec/ivas_sba_dec.c
+++ b/lib_dec/ivas_sba_dec.c
@@ -347,20 +347,18 @@ ivas_error ivas_sba_dec_reconfigure(
Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
)
{
- int16_t n;
- int16_t sce_id, cpe_id;
- int16_t nchan_transport;
- int16_t nchan_transport_old;
- int32_t sba_total_brate;
- int16_t nSCE_old;
- int16_t nCPE_old;
+#ifdef CORECODER_BITRATE_SWITCHING
+ int16_t i;
+ int16_t nchan_transport, nchan_transport_old;
+ int16_t nSCE_old, nCPE_old, nchan_hp20_old;
+#else
+ int16_t i, n, sce_id, cpe_id;
+ int16_t nchan_transport, nchan_transport_old;
+ int16_t nSCE_old, nCPE_old;
+#endif
AUDIO_CONFIG intern_config_old;
- int16_t numCldfbAnalyses_old;
- int16_t numCldfbAnalyses;
- int16_t numCldfbSyntheses;
- int16_t numCldfbSyntheses_old;
+ int16_t numCldfbAnalyses_old, numCldfbAnalyses, numCldfbSyntheses, numCldfbSyntheses_old;
int16_t sba_dirac_stereo_flag_old;
- uint16_t i;
int32_t ivas_total_brate, last_ivas_total_brate;
ivas_error error;
@@ -375,7 +373,10 @@ ivas_error ivas_sba_dec_reconfigure(
ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
numCldfbAnalyses = 0;
- sba_total_brate = ivas_total_brate;
+
+#ifdef CORECODER_BITRATE_SWITCHING
+ nchan_hp20_old = getNumChanSynthesis( st_ivas );
+#endif
nSCE_old = st_ivas->nSCE;
nCPE_old = st_ivas->nCPE;
@@ -384,7 +385,7 @@ 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( sba_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init );
+ ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport, st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init );
st_ivas->nchan_transport = nchan_transport;
@@ -451,11 +452,20 @@ ivas_error ivas_sba_dec_reconfigure(
}
}
-
/*-----------------------------------------------------------------*
* Allocate, initalize, and configure SCE/CPE/MCT handles
*-----------------------------------------------------------------*/
+#ifdef CORECODER_BITRATE_SWITCHING
+ ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old );
+
+ /*-----------------------------------------------------------------*
+ * HP20 memories
+ *-----------------------------------------------------------------*/
+
+ ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old );
+#else
+
if ( nchan_transport == nchan_transport_old )
{
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
@@ -698,6 +708,7 @@ ivas_error ivas_sba_dec_reconfigure(
old_mem_hp20_out = NULL;
}
}
+#endif
/*-----------------------------------------------------------------*
* CLDFB instances
@@ -758,6 +769,7 @@ ivas_error ivas_sba_dec_reconfigure(
}
}
+#ifndef CORECODER_BITRATE_SWITCHING
/*-----------------------------------------------------------------*
* Set CNA/CNG flags
*-----------------------------------------------------------------*/
@@ -799,6 +811,7 @@ ivas_error ivas_sba_dec_reconfigure(
return error;
}
}
+#endif
/*-------------------------------------------------------------------*
* Reallocate and initialize binaural rendering handles
diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c
index 5756e1bef723cd35d665b2d6face14f3e6d480f3..1aa3e083f081c19f57f5b61ef1458e6b12c77a9c 100644
--- a/lib_dec/ivas_sce_dec.c
+++ b/lib_dec/ivas_sce_dec.c
@@ -274,13 +274,17 @@ ivas_error ivas_sce_dec(
for ( i = 0; i < n; i++ )
{
dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "element_brate", 0, sce_id, DEC ) );
- dbgwrite( &st->element_mode, 2, 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) );
+ dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) );
dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) );
+ tmpF = 0;
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) );
+ dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) );
}
}
#endif
+
wmops_sub_end();
return error;
}
diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c
index 42a17cb9cbefa40eb58b1e9d246f9c48fc1292a7..3f9cb84b513639571362b8b36a04b0b4dce90519 100644
--- a/lib_enc/ivas_core_enc.c
+++ b/lib_enc/ivas_core_enc.c
@@ -79,7 +79,10 @@ ivas_error ivas_core_enc(
float enerBuffer[CPE_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : energy buffer */
float fft_buff[CPE_CHANNELS][2 * L_FFT], /* i : FFT buffer */
const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */
- const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
+#ifdef CORECODER_BITRATE_SWITCHING
+ const int16_t ivas_format, /* i : IVAS format */
+#endif
+ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */
)
{
int16_t n, input_frame;
@@ -101,7 +104,11 @@ ivas_error ivas_core_enc(
int16_t unbits[CPE_CHANNELS];
float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M];
int16_t last_element_mode, tdm_Pitch_reuse_flag;
+#ifdef CORECODER_BITRATE_SWITCHING
+ int32_t element_brate, last_element_brate, input_Fs;
+#else
int32_t element_brate, input_Fs;
+#endif
ivas_error error;
wmops_sub_start( "ivas_core_enc" );
@@ -120,6 +127,9 @@ ivas_error ivas_core_enc(
hStereoTD = NULL;
hStereoICBWE = NULL;
element_brate = hSCE->element_brate;
+#ifdef CORECODER_BITRATE_SWITCHING
+ last_element_brate = hSCE->last_element_brate;
+#endif
last_element_mode = IVAS_SCE;
tdm_Pitch_reuse_flag = -1;
}
@@ -134,6 +144,9 @@ ivas_error ivas_core_enc(
sts = hCPE->hCoreCoder;
hStereoICBWE = hCPE->hStereoICBWE;
element_brate = hCPE->element_brate;
+#ifdef CORECODER_BITRATE_SWITCHING
+ last_element_brate = hCPE->last_element_brate;
+#endif
last_element_mode = hCPE->last_element_mode;
if ( hCPE->hStereoTD != NULL )
@@ -174,7 +187,11 @@ ivas_error ivas_core_enc(
* Pre-processing, incl. Decision matrix
*---------------------------------------------------------------------*/
+#ifdef CORECODER_BITRATE_SWITCHING
+ if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, ivas_format == SBA_FORMAT ? last_element_brate : element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK )
+#else
if ( ( error = pre_proc_ivas( st, last_element_mode, element_brate, input_frame, old_inp_12k8[n], old_inp_16k[n], &inp[n], &ener[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], new_inp_resamp16k[n], &Voicing_flag[n], old_wsp[n], loc_harm[n], cor_map_sum[n], vad_flag_dtx[n], enerBuffer[n], fft_buff[n], is_MCT, vad_hover_flag[n], flag_16k_smc ) ) != IVAS_ERR_OK )
+#endif
{
return error;
}
diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c
index 4ae384d5ffa33b96a8e82e208edc14baa8635dff..ded3df223549afc866267441c90093e34577d099 100644
--- a/lib_enc/ivas_core_pre_proc.c
+++ b/lib_enc/ivas_core_pre_proc.c
@@ -52,9 +52,12 @@
*--------------------------------------------------------------------*/
ivas_error pre_proc_ivas(
- Encoder_State *st, /* i/o: encoder state structure */
- const int16_t last_element_mode, /* i : last element mode */
- const int32_t element_brate, /* i : element bitrate */
+ Encoder_State *st, /* i/o: encoder state structure */
+ const int16_t last_element_mode, /* i : last element mode */
+ const int32_t element_brate, /* i : element bitrate */
+#ifdef CORECODER_BITRATE_SWITCHING
+ const int32_t last_element_brate, /* i : last element bitrate */
+#endif
const int16_t input_frame, /* i : frame length */
float old_inp_12k8[], /* i/o: buffer of old input signal */
float old_inp_16k[], /* i/o: buffer of old input signal @ 16kHz */
@@ -275,6 +278,13 @@ ivas_error pre_proc_ivas(
{
st->hTcxEnc->tfm_mem = 0.75f;
}
+#ifdef CORECODER_BITRATE_SWITCHING
+ else if ( element_brate != last_element_brate )
+ {
+ SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, is_mct );
+ }
+#endif
+
/*-----------------------------------------------------------------*
* Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps)
diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c
new file mode 100644
index 0000000000000000000000000000000000000000..f4b302eefd69a6f0b04dab44d94d2141e3271551
--- /dev/null
+++ b/lib_enc/ivas_corecoder_enc_reconfig.c
@@ -0,0 +1,396 @@
+/******************************************************************************************************
+
+ (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository. All Rights Reserved.
+
+ This software is protected by copyright law and by international treaties.
+ The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
+ Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
+ Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
+ Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
+ contributors to this repository retain full ownership rights in their respective contributions in
+ the software. This notice grants no license of any kind, including but not limited to patent
+ license, nor is any license granted by implication, estoppel or otherwise.
+
+ Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
+ contributions.
+
+ This software is provided "AS IS", without any express or implied warranties. The software is in the
+ development stage. It is intended exclusively for experts who have experience with such software and
+ solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
+ and fitness for a particular purpose are hereby disclaimed and excluded.
+
+ Any dispute, controversy or claim arising under or in relation to providing this software shall be
+ submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
+ accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
+ the United Nations Convention on Contracts on the International Sales of Goods.
+
+*******************************************************************************************************/
+
+#include
+#include
+#include "options.h"
+#include "ivas_cnst.h"
+#include "prot.h"
+#include "ivas_prot.h"
+#include "ivas_stat_enc.h"
+#ifdef DEBUGGING
+#include "debug.h"
+#endif
+#include "wmops.h"
+
+
+#ifdef CORECODER_BITRATE_SWITCHING
+/*-------------------------------------------------------------------*
+ * ivas_corecoder_enc_reconfig()
+ *
+ * Allocate, initalize, and configure SCE/CPE/MCT handles in case of bitrate switching
+ *-------------------------------------------------------------------*/
+
+ivas_error ivas_corecoder_enc_reconfig(
+ Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
+ const int16_t nSCE_old, /* i : number of SCEs in previous frame */
+ const int16_t nCPE_old, /* i : number of CPEs in previous frame */
+ const int16_t nchan_transport_old /* i : number of TCs in previous frame */
+)
+{
+ int16_t n, sce_id, cpe_id;
+ int16_t len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing;
+ float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )];
+ BSTR_ENC_HANDLE hBstr, hMetaData;
+ Indice *ind_list, *ind_list_metadata;
+ int16_t nb_bits_tot, next_ind, last_ind;
+ int32_t ivas_total_brate;
+ ENCODER_CONFIG_HANDLE hEncoderConfig;
+ ivas_error error;
+
+ /*-----------------------------------------------------------------*
+ * Initialization
+ *-----------------------------------------------------------------*/
+
+ hEncoderConfig = st_ivas->hEncoderConfig;
+ ivas_total_brate = hEncoderConfig->ivas_total_brate;
+ error = IVAS_ERR_OK;
+
+ len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
+ if ( hEncoderConfig->ivas_format == SBA_FORMAT )
+ {
+ len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
+ }
+
+ /*-----------------------------------------------------------------*
+ * Switching between SCE(s)/CPE(s)/MCT
+ *-----------------------------------------------------------------*/
+
+ if ( st_ivas->nchan_transport == nchan_transport_old )
+ {
+ for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
+ st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+
+ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
+
+ /* prepare bitstream buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
+
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+ }
+
+ if ( st_ivas->nCPE > 1 )
+ {
+ if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ }
+ else
+ {
+ ind_list = NULL;
+ hBstr = NULL;
+ hMetaData = NULL;
+
+ /* get the index list pointers */
+ if ( nSCE_old )
+ {
+ hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
+ hMetaData = st_ivas->hSCE[0]->hMetaData;
+ }
+ else if ( nCPE_old )
+ {
+ hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
+ hMetaData = st_ivas->hCPE[nCPE_old - 1]->hMetaData;
+ }
+#ifdef DEBUGGING
+ else
+ {
+ assert( 0 && "At least one SCE or one CPE should have existed before!\n" );
+ }
+#endif
+
+ /* save bitstream information */
+ ind_list = hBstr->ind_list;
+ nb_bits_tot = hBstr->nb_bits_tot;
+ next_ind = hBstr->next_ind;
+ last_ind = hBstr->last_ind;
+ ind_list_metadata = hMetaData->ind_list;
+
+ n_CoreCoder_existing = min( st_ivas->nchan_transport, nchan_transport_old );
+
+ /* destroy superfluous core-coder elements */
+ for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
+ {
+ /* save input audio buffers */
+ if ( n_CoreCoder_existing > sce_id )
+ {
+ mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
+ }
+
+ destroy_sce_enc( st_ivas->hSCE[sce_id] );
+ st_ivas->hSCE[sce_id] = NULL;
+ }
+
+ for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
+ {
+ /* save input audio buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
+ {
+ mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
+ }
+ }
+
+ destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
+ st_ivas->hCPE[cpe_id] = NULL;
+ }
+
+ if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
+ {
+ ivas_mct_enc_close( st_ivas->hMCT );
+ st_ivas->hMCT = NULL;
+ }
+
+ /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */
+ if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
+ {
+ count_free( st_ivas->hCPE[0]->hStereoMdct );
+ st_ivas->hCPE[0]->hStereoMdct = NULL;
+ }
+
+ /* create missing core coder elements and set element bitrates for alrady existing ones */
+ if ( st_ivas->nSCE > 0 )
+ {
+ nSCE_existing = min( nSCE_old, st_ivas->nSCE );
+
+ for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
+ {
+ copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
+ st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+
+ for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ /* propagate input audio buffers */
+ if ( n_CoreCoder_existing > sce_id )
+ {
+ mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory );
+ }
+
+ /* prepare bitstream buffers */
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES;
+
+ /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
+ if ( sce_id > 0 )
+ {
+ reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES );
+ }
+ else
+ {
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->last_ind = last_ind;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
+ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->next_ind = next_ind;
+ }
+
+ st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + sce_id * MAX_BITS_METADATA;
+ reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA );
+ }
+ }
+
+ if ( st_ivas->nCPE > 0 )
+ {
+ nCPE_existing = min( nCPE_old, st_ivas->nCPE );
+
+ for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
+ {
+ st_ivas->hCPE[cpe_id]->element_brate = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS;
+
+ /* prepare bitstream buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
+ }
+ }
+
+ for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+
+ /* propagate input audio buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
+ {
+ mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[0]->input_buff, len_inp_memory );
+ }
+ }
+
+ /* prepare bitstream buffers */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n ) * MAX_NUM_INDICES;
+ if ( cpe_id * CPE_CHANNELS + n > 0 )
+ {
+ reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES );
+ }
+ else
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->last_ind = last_ind;
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_bits_tot = nb_bits_tot;
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->next_ind = next_ind;
+ }
+
+ if ( hEncoderConfig->Opt_DTX_ON )
+ {
+ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
+ }
+ }
+ }
+ }
+
+ if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
+ {
+ if ( nCPE_old == 1 )
+ {
+ /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
+
+ st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
+ st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
+ st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode );
+
+ if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf )
+ {
+ IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc,
+ st_ivas->hCPE[0]->element_brate,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
+ st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
+ }
+ }
+ }
+
+ if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+ else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
+ {
+ if ( ( error = mct_enc_reconfigure( st_ivas, st_ivas->nchan_transport != nchan_transport_old ) ) != IVAS_ERR_OK )
+ {
+ return error;
+ }
+ }
+
+ /* metadata handling for CPEs */
+ if ( st_ivas->nCPE > 0 )
+ {
+ if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
+ {
+ if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData = (BSTR_ENC_HANDLE) count_malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) );
+ }
+ }
+
+ st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->ind_list = ind_list_metadata;
+ reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, MAX_BITS_METADATA );
+
+ for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
+ {
+ if ( st_ivas->hCPE[cpe_id]->hMetaData != NULL )
+ {
+ count_free( st_ivas->hCPE[cpe_id]->hMetaData );
+ st_ivas->hCPE[cpe_id]->hMetaData = NULL;
+ }
+ }
+ }
+
+ /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
+ if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
+ {
+ if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) count_malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
+ {
+ return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
+ }
+
+ /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */
+ for ( n = 0; n < CPE_CHANNELS; n++ )
+ {
+ st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
+
+ st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
+ st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
+ st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode );
+
+ if ( st_ivas->hCPE[0]->hCoreCoder[n]->igf )
+ {
+ IGFEncSetMode( st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc,
+ st_ivas->hCPE[0]->element_brate,
+ st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
+ st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
+ st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
+ }
+
+ /* reset mct_chan_mode */
+ st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
+ }
+
+ initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 );
+ st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
+ }
+ }
+
+ return error;
+}
+#endif
diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c
index d56916a200a391afd2141a56b677692c4e93d37d..491a9ab3586fa620fb63e12027a890e25baed9c8 100644
--- a/lib_enc/ivas_cpe_enc.c
+++ b/lib_enc/ivas_cpe_enc.c
@@ -413,9 +413,11 @@ ivas_error ivas_cpe_enc(
}
#ifdef DEBUG_MODE_INFO
- dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" );
- dbgwrite( sts[1]->input - NS2SA( sts[1]->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX.ch2" );
- dbgwrite( &hCPE->element_mode, 2, 1, input_frame, "res/element_mode" );
+ for ( n = 0; n < n_CoreChannels; n++ )
+ {
+ dbgwrite( sts[0]->input - NS2SA( sts[0]->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, fname( debug_dir, "input_DMX", n, sts[n]->id_element, ENC ) );
+ }
+ dbgwrite( &hCPE->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, sts[0]->id_element, ENC ) );
#endif
/*----------------------------------------------------------------*
@@ -610,7 +612,11 @@ ivas_error ivas_cpe_enc(
* Core Encoder
*----------------------------------------------------------------*/
+#ifdef CORECODER_BITRATE_SWITCHING
+ if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ) != IVAS_ERR_OK )
+#else
if ( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, tdm_SM_or_LRTD_Pri, 0 ) ) != IVAS_ERR_OK )
+#endif
{
return error;
}
diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c
index 9d3b6131e1de170103d09105a141b328522d41cd..9484aa273737299fd0a5114551abaedf47db7dfa 100644
--- a/lib_enc/ivas_dirac_enc.c
+++ b/lib_enc/ivas_dirac_enc.c
@@ -453,6 +453,36 @@ void ivas_dirac_enc_spar_delay_synchro(
int16_t ch_idx;
float tmp_buffer[L_FRAME48k];
+#ifdef CORECODER_BITRATE_SWITCHING
+ /* check last sba_mode */
+ if ( ivas_sba_mode_select( st_ivas->hEncoderConfig->last_ivas_total_brate ) == SBA_MODE_SPAR )
+ {
+ Encoder_State *sts[MCT_MAX_BLOCKS];
+ int16_t i_chan = 0;
+
+ /* initializations */
+ for ( int16_t sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
+ {
+ sts[sce_id] = st_ivas->hSCE[sce_id]->hCoreCoder[0];
+ i_chan++;
+ }
+
+ for ( int16_t cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
+ {
+ for ( int16_t ch = 0; ch < CPE_CHANNELS; ch++ )
+ {
+ sts[i_chan] = st_ivas->hCPE[cpe_id]->hCoreCoder[ch];
+ i_chan++;
+ }
+ }
+
+ for ( ch_idx = 0; ch_idx < i_chan; ch_idx++ )
+ {
+ mvr2r( sts[ch_idx]->input, st_ivas->hDirAC->sba_synchro_buffer[ch_idx], st_ivas->hDirAC->num_samples_synchro_delay );
+ }
+ }
+#endif
+
for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ )
{
mvr2r( data_f[ch_idx], tmp_buffer, input_frame );
diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c
index 33d552bb27f913e758fd74ddafb5d36bc025dc39..2122dcf87416d4ee3737895a0a0038d67a871bcf 100644
--- a/lib_enc/ivas_ism_enc.c
+++ b/lib_enc/ivas_ism_enc.c
@@ -262,7 +262,11 @@ ivas_error ivas_ism_enc(
* Encoder
*----------------------------------------------------------------*/
+#ifdef CORECODER_BITRATE_SWITCHING
+ if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, ISM_FORMAT, 0 ) ) != IVAS_ERR_OK )
+#else
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8[sce_id], old_inp_16k[sce_id], Etot[sce_id], ener[sce_id], A[sce_id], Aw[sce_id], epsP[sce_id], lsp_new[sce_id], lsp_mid[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer[sce_id], imagBuffer[sce_id], old_wsp[sce_id], loc_harm[sce_id], cor_map_sum[sce_id], vad_flag_dtx[sce_id], enerBuffer[sce_id], fft_buff[sce_id], 0, 0 ) ) != IVAS_ERR_OK )
+#endif
{
return error;
}
diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c
index b8f06f72d2f74cfc30d152adc8cf8304b8c2ddce..d4c7c70b2187eff07bbc58daccca0228300699fc 100644
--- a/lib_enc/ivas_sba_enc.c
+++ b/lib_enc/ivas_sba_enc.c
@@ -104,14 +104,11 @@ ivas_error ivas_sba_enc_reconfigure(
Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
)
{
- int16_t ntransport;
- int16_t ntransport_old;
- int16_t nSCE_old;
- int16_t nCPE_old;
- int16_t sce_id;
- int16_t cpe_id;
- int16_t n;
+ int16_t nSCE_old, nCPE_old, nchan_transport_old;
+#ifndef CORECODER_BITRATE_SWITCHING
+ int16_t n, sce_id, cpe_id;
Indice *ind_list_metadata;
+#endif
int32_t ivas_total_brate;
ivas_error error;
@@ -121,18 +118,27 @@ ivas_error ivas_sba_enc_reconfigure(
if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate )
{
- ntransport = st_ivas->nchan_transport;
- ntransport_old = st_ivas->nchan_transport;
+ nchan_transport_old = st_ivas->nchan_transport;
nCPE_old = st_ivas->nCPE;
nSCE_old = st_ivas->nSCE;
+#ifndef CORECODER_BITRATE_SWITCHING
ind_list_metadata = NULL;
+#endif
st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
ivas_dirac_enc_reconfigure( st_ivas );
- ntransport = st_ivas->nchan_transport;
- if ( ntransport == ntransport_old )
+
+#ifdef CORECODER_BITRATE_SWITCHING
+ /*-----------------------------------------------------------------*
+ * Allocate, initalize, and configure SCE/CPE/MCT handles
+ *-----------------------------------------------------------------*/
+
+ ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old );
+#else
+
+ if ( hEncoderConfig->nchan_transport == nchan_transport_old )
{
for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
{
@@ -409,6 +415,7 @@ ivas_error ivas_sba_enc_reconfigure(
st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
}
}
+#endif
}
return error;
diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c
index 8b65c188d943562b27f4a2f0c06a81b70582ca67..2592b578f680c36a3af687a072f39b523e391633 100644
--- a/lib_enc/ivas_sce_enc.c
+++ b/lib_enc/ivas_sce_enc.c
@@ -165,11 +165,21 @@ ivas_error ivas_sce_enc(
/* set "total_brate" */
st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC;
-#ifdef DEBUG_MODE_INFO
- dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" );
-#endif
/* set flag for sampling rate of OL S/M classifier */
+#ifdef CORECODER_BITRATE_SWITCHING // VE2EF: TBV whether it can be done more efficiently
+ flag_16k_smc = 0;
+ if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) && hSCE->element_brate == hSCE->last_element_brate )
+ {
+ flag_16k_smc = 1;
+ }
+#else
flag_16k_smc = ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT && ( st_ivas->hEncoderConfig->ivas_total_brate == IVAS_24k4 || st_ivas->hEncoderConfig->ivas_total_brate == IVAS_32k ) );
+#endif
+
+#ifdef DEBUG_MODE_INFO
+ dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), sizeof( float ), input_frame, 1, "res/input_DMX" );
+ dbgwrite( &st->element_mode, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "element_mode", 0, st->id_element, ENC ) );
+#endif
/*----------------------------------------------------------------*
* Front Pre-processing
@@ -204,6 +214,7 @@ ivas_error ivas_sce_enc(
/*----------------------------------------------------------------*
* Write IVAS format signaling in SID frames
*----------------------------------------------------------------*/
+
if ( st->core_brate == SID_2k40 )
{
ivas_write_format_sid( ivas_format, IVAS_SCE, st->hBstr );
@@ -230,7 +241,11 @@ ivas_error ivas_sce_enc(
* Encoder
*----------------------------------------------------------------*/
+#ifdef CORECODER_BITRATE_SWITCHING
+ if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK )
+#else
if ( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8, old_inp_16k, Etot, ener, A, Aw, epsP, lsp_new, lsp_mid, vad_hover_flag, attack_flag, realBuffer, imagBuffer, old_wsp, loc_harm, cor_map_sum, vad_flag_dtx, enerBuffer, fft_buff, 0, flag_16k_smc ) ) != IVAS_ERR_OK )
+#endif
{
return error;
}
@@ -242,6 +257,17 @@ ivas_error ivas_sce_enc(
/* update input samples buffer */
mvr2r( st->input, st->old_input_signal, input_frame );
+#ifdef CORECODER_BITRATE_SWITCHING
+ hSCE->last_element_brate = hSCE->element_brate;
+#endif
+
+#ifdef DEBUG_MODE_INFO
+ {
+ float tmpF = hSCE->element_brate / 1000.0f;
+ dbgwrite( &tmpF, sizeof( float ), 1, input_frame, fname( debug_dir, "element_brate", 0, sce_id, ENC ) );
+ }
+#endif
+
wmops_sub_end();
return error;
@@ -281,6 +307,9 @@ ivas_error create_sce_enc(
hSCE->sce_id = sce_id;
hSCE->element_brate = element_brate;
+#ifdef CORECODER_BITRATE_SWITCHING
+ hSCE->last_element_brate = hSCE->element_brate;
+#endif
/*-----------------------------------------------------------------*
* Metadata: allocate and initialize
diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h
index 1dc541f0038aa1254256f3fbe3a88dc362b5aa71..0ec6c21eea332c19930b397aa319b20726bcb25c 100644
--- a/lib_enc/ivas_stat_enc.h
+++ b/lib_enc/ivas_stat_enc.h
@@ -842,6 +842,9 @@ typedef struct sce_enc_data_structure
{
int16_t sce_id; /* SCE # identifier */
int32_t element_brate; /* SCE element total bitrate in bps */
+#ifdef CORECODER_BITRATE_SWITCHING
+ int32_t last_element_brate; /* last SCE element bitrate in bps */
+#endif
BSTR_ENC_HANDLE hMetaData; /* Metadata bitstream handle */