From 6de27e94ed1017c79fc1bac763145ab1065d8fd4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 27 Sep 2022 14:59:27 +0200 Subject: [PATCH 1/2] Issue 133: support bitrate switching in core-coder; under CORECODER_BITRATE_SWITCHING --- Workspace_msvc/lib_dec.vcxproj | 1 + Workspace_msvc/lib_dec.vcxproj.filters | 3 + Workspace_msvc/lib_enc.vcxproj | 1 + Workspace_msvc/lib_enc.vcxproj.filters | 3 + lib_com/ivas_prot.h | 41 ++- lib_com/options.h | 4 + lib_dec/ivas_corecoder_dec_reconfig.c | 403 +++++++++++++++++++++++++ lib_dec/ivas_init_dec.c | 6 + lib_dec/ivas_sba_dec.c | 43 ++- lib_enc/ivas_core_enc.c | 19 +- lib_enc/ivas_core_pre_proc.c | 16 +- lib_enc/ivas_corecoder_enc_reconfig.c | 396 ++++++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 4 + lib_enc/ivas_dirac_enc.c | 31 ++ lib_enc/ivas_init_enc.c | 1 - lib_enc/ivas_ism_enc.c | 4 + lib_enc/ivas_sba_enc.c | 29 +- lib_enc/ivas_sce_enc.c | 28 +- lib_enc/ivas_stat_enc.h | 3 + 19 files changed, 994 insertions(+), 42 deletions(-) create mode 100644 lib_dec/ivas_corecoder_dec_reconfig.c create mode 100644 lib_enc/ivas_corecoder_enc_reconfig.c diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 3bde19ca47..5860b0a970 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 155b8dfc45..5476cf5588 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 40302c56cd..c1144daf31 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 471a5f9a64..1d7ee5594f 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 6996e4a298..bd587c1e68 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 */ @@ -317,6 +333,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 */ @@ -387,6 +418,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 */ ); @@ -2736,10 +2770,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 */ @@ -5469,8 +5499,7 @@ float rand_triangular_signed( #ifdef ALIGN_SID_SIZE void dtx_read_padding_bits( DEC_CORE_HANDLE st, - int16_t num_bits -); + int16_t num_bits ); #endif #endif /* IVAS_PROT_H */ diff --git a/lib_com/options.h b/lib_com/options.h index 222333bc33..7556ecb139 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,10 @@ #define ALIGN_SID_SIZE /* Issue 111: make all DTX modes use one SID frame bitrate (5.2 kbps) */ + +#define CORECODER_BITRATE_SWITCHING /* Issue 133: support bitrate switching in core-coder */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c new file mode 100644 index 0000000000..8f0ba78857 --- /dev/null +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -0,0 +1,403 @@ +/****************************************************************************************************** + + (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 */ +#ifdef ALIGN_SID_SIZE + if ( hDecoderConfig->last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 ) +#else + if ( hDecoderConfig->last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) +#endif + { + 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_init_dec.c b/lib_dec/ivas_init_dec.c index d0f4e7ceb1..c587f69f8d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -988,6 +988,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 ) @@ -1184,6 +1187,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_sba_dec.c b/lib_dec/ivas_sba_dec.c index 204b91b89d..f1eb494e34 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -451,20 +451,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; @@ -479,7 +477,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; @@ -488,7 +489,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, st_ivas->sba_mode ); + 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->sba_mode ); st_ivas->nchan_transport = nchan_transport; /* renderer might have changed */ @@ -558,11 +559,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++ ) @@ -805,6 +815,7 @@ ivas_error ivas_sba_dec_reconfigure( old_mem_hp20_out = NULL; } } +#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -865,6 +876,7 @@ ivas_error ivas_sba_dec_reconfigure( } } +#ifndef CORECODER_BITRATE_SWITCHING /*-----------------------------------------------------------------* * Set CNA/CNG flags *-----------------------------------------------------------------*/ @@ -910,6 +922,7 @@ ivas_error ivas_sba_dec_reconfigure( return error; } } +#endif /*-------------------------------------------------------------------* * Reallocate and initialize binaural rendering handles diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 42a17cb9cb..3f9cb84b51 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 4ae384d5ff..ded3df2235 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 0000000000..f4b302eefd --- /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 df94fe44ab..0d229f3306 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -644,7 +644,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 754aa6d57c..c89aa0eea7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -461,6 +461,37 @@ 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 < st_ivas->hEncoderConfig->nchan_inp; ch_idx++ ) { mvr2r( data_f[ch_idx], tmp_buffer, input_frame ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 8d9f7e445e..6ac7f76649 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1054,4 +1054,3 @@ void ivas_destroy_enc( return; } - diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2433c01802..5d51a6b39b 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -266,7 +266,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 62fc6d0667..665d7900fd 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -216,14 +216,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; @@ -233,18 +230,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++ ) { @@ -521,6 +527,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 1657665f99..095f88976e 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -165,12 +165,20 @@ 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 ), 4, input_frame, 1, "res/input_DMX" ); +#endif /*----------------------------------------------------------------* * Front Pre-processing *----------------------------------------------------------------*/ @@ -238,8 +246,11 @@ ivas_error ivas_sce_enc( * Encoder *----------------------------------------------------------------*/ - 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 ) +#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; } @@ -252,6 +263,10 @@ 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 + wmops_sub_end(); return error; @@ -291,6 +306,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 2ed6a0ff91..7fcc35ea9e 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -841,6 +841,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 */ -- GitLab From c664f7059cd0a763c0fb32d0b1bc61246498d057 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 27 Sep 2022 15:04:29 +0200 Subject: [PATCH 2/2] updates within DEBUG_MODE_INFO to correctly output core-decoder synthesis in case of SCE/CPE/MCT switching --- lib_dec/ivas_cpe_dec.c | 7 +++++-- lib_dec/ivas_mct_dec.c | 13 +++++++++++++ lib_dec/ivas_sce_dec.c | 6 +++++- lib_enc/ivas_cpe_enc.c | 8 +++++--- lib_enc/ivas_sce_enc.c | 12 +++++++++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 313e0d6172..f34df44936 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -524,7 +524,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 ) @@ -536,12 +536,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_mct_dec.c b/lib_dec/ivas_mct_dec.c index 31f3208429..b4a4da3e3c 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_sce_dec.c b/lib_dec/ivas_sce_dec.c index b3a73706df..bebb0f4cf5 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -286,13 +286,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_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 0d229f3306..4c7daa3e03 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -425,9 +425,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 /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 095f88976e..07879852b3 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -177,8 +177,10 @@ ivas_error ivas_sce_enc( #endif #ifdef DEBUG_MODE_INFO - dbgwrite( st->input - NS2SA( st->input_Fs, ACELP_LOOK_NS ), 4, input_frame, 1, "res/input_DMX" ); + 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 *----------------------------------------------------------------*/ @@ -216,6 +218,7 @@ ivas_error ivas_sce_enc( /*----------------------------------------------------------------* * Write IVAS format signaling in SID frames *----------------------------------------------------------------*/ + #ifdef ALIGN_SID_SIZE if ( st->core_brate == SID_2k40 ) #else @@ -267,6 +270,13 @@ ivas_error ivas_sce_enc( 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; -- GitLab