diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 40a4710579dd35f964601e1becd5fa77e89dd6a6..ae476a02eccc338036772a4dcaba51fa5f164a53 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -798,6 +798,9 @@ typedef enum #define BWD_COUNT_MAX 100 /* maximum value of BWD counter */ #define BWD_N_BINS_MAX 13 /* maximum number of BWD bins */ #define BWS_TRAN_PERIOD 5 /* BWS - number of frames for transition period */ +#ifdef FIX_I2_BWD +#define BWD_HIGH_BRATE_THR IVAS_256k /* BWD - threshold from which the bitrate sets bws_high_rate_flag = 1 */ +#endif #define PREEMPH_FAC 0.68f /* preemphasis factor at 12.8kHz */ #define PREEMPH_FAC_16k 0.72f diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 88e83ded121acb2d37bcdd4722570f317a5bf34a..0016a77f66be8903b95d323adb719c61e0b532bf 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3721,8 +3721,9 @@ void ivas_sba_upmixer_renderer( ); void ivas_sba_mix_matrix_determiner( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - float in_out[][L_FRAME48k], /* i/o: transport/output audio channels */ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + float output[][L_FRAME48k], /* i/o: transport/output audio channels */ + const int16_t bfi, /* i : BFI flag */ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ const int16_t output_frame /* i : output frame length */ ); diff --git a/lib_com/options.h b/lib_com/options.h index bce8d45d0293f13862e880afac4e19d33ba4a593..9a564035bf0ad7fdd765c89230a7f83e939d6109 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -147,9 +147,10 @@ /*#define FIX_I1_113*/ /* under review : MCT bit distribution optimization for SBA high bitrates*/ #define FIX_ADAP_STEFI_SHIFT /* Issue 89: fix bug in parameter shift of adaptive stereo filling */ -#define SPAR_SCALING_HARMONIZATION /* issue 80: Changes to harmonize scaling in spar */ +#define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ +#define FIX_I2_BWD /* Issue 2: BWD fix to more quickly react to WB -> SWB/FB change */ - - /* ################## End DEVELOPMENT switches ######################### */ + +/* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_crend.c b/lib_dec/ivas_crend.c index 8eec61d70934679875c0ab62a11fb7895c2af068..8048d8106f7924915aaacba6dabdc9da4e93063a 100644 --- a/lib_dec/ivas_crend.c +++ b/lib_dec/ivas_crend.c @@ -1115,5 +1115,7 @@ ivas_error ivas_crend_process( mvr2r( pcm_tmp[i], output[i], output_frame ); } + wmops_sub_end(); + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index cf49ae135252772b082f2bc9eb9d956a99622b45..22f841728edc1f64d2f9dba56fd1bf75159f6405 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -309,7 +309,7 @@ ivas_error ivas_dec( if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { - ivas_sba_mix_matrix_determiner( st_ivas, output, nchan_remapped, output_frame ); + ivas_sba_mix_matrix_determiner( st_ivas->hSpar, output, st_ivas->bfi, nchan_remapped, output_frame ); } } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 2bdaec1b7bd5763bbebd3bc5b45e9e3e065f2438..d8c14257bd195704ebf65ca429b0a120a184a1e0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -511,29 +511,6 @@ ivas_error ivas_init_decoder_front( error = IVAS_ERR_OK; -#ifdef DEBUGGING - st_ivas->noClipping = 0; -#endif - - /* Custom loudspeaker layout structure */ - st_ivas->hLsSetupCustom = NULL; - - /* TD renderer HRTF data structure */ - st_ivas->hHrtfTD = NULL; - - /* Head track data structure */ - st_ivas->hHeadTrackData = NULL; - - /* Renderer configuration structure */ - st_ivas->hRenderConfig = NULL; - - /* HRTF binauralization latency in ns */ - st_ivas->binaural_latency_ns = 0; - -#ifdef DEBUGGING - st_ivas->hDecoderConfig->force_rend = -1; -#endif - /*-----------------------------------------------------------------* * Resets *-----------------------------------------------------------------*/ @@ -546,9 +523,16 @@ ivas_error ivas_init_decoder_front( st_ivas->mc_mode = MC_MODE_NONE; st_ivas->sba_mode = SBA_MODE_NONE; - st_ivas->hLimiter = NULL; - st_ivas->hoa_dec_mtx = NULL; + st_ivas->sba_dirac_stereo_flag = 0; + + /* HRTF binauralization latency in ns */ + st_ivas->binaural_latency_ns = 0; +#ifdef DEBUGGING + st_ivas->noClipping = 0; + + st_ivas->hDecoderConfig->force_rend = -1; +#endif /*-------------------------------------------------------------------* * Allocate and initialize Custom loudspeaker layout handle @@ -695,6 +679,7 @@ ivas_error ivas_init_decoder( } } +#if 0 /*-----------------------------------------------------------------* * Dummy pointers to decoder handles *-----------------------------------------------------------------*/ @@ -746,6 +731,7 @@ ivas_error ivas_init_decoder( st_ivas->hMonoDmxRenderer = NULL; /* Mono downmix renderer */ st_ivas->hHrtf = NULL; /* Crend hrtf data */ st_ivas->hCrend = NULL; /* Crend renderer */ +#endif /*-----------------------------------------------------------------* * Allocate and initalize SCE/CPE and other handles @@ -1335,9 +1321,8 @@ ivas_error ivas_init_decoder( * Allocate and initialize limiter struct *-----------------------------------------------------------------*/ - { - st_ivas->hLimiter = ivas_limiter_open( hDecoderConfig->nchan_out, output_Fs ); - } + st_ivas->hLimiter = ivas_limiter_open( hDecoderConfig->nchan_out, output_Fs ); + return error; } @@ -1550,11 +1535,13 @@ void ivas_initialize_handles_dec( st_ivas->hMonoDmxRenderer = NULL; st_ivas->hCrend = NULL; st_ivas->hHrtf = NULL; + st_ivas->hoa_dec_mtx = NULL; st_ivas->hHeadTrackData = NULL; st_ivas->hHrtfTD = NULL; st_ivas->hLimiter = NULL; st_ivas->hLsSetupCustom = NULL; + st_ivas->hRenderConfig = NULL; return; } diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e1df8f2a7dbf6f9f53c2c9758ce3882d3b458b83..29e2ce40025443b0b0384dfb80cb7e23733e1478 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -263,7 +263,6 @@ ivas_error ivas_param_mc_dec_open( return error; } - /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { @@ -297,6 +296,7 @@ ivas_error ivas_param_mc_dec_open( matrix_product( hParamMC->ls_conv_dmx_matrix, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac, nchan_out_transport, nchan_transport, 0, proto_matrix ); + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { proto_mtx_norm = 1.f; diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index c8008fa12976d821b6662e509157efa40f408623..9ed27e56c3d21f63d1d14675ffcb76bc8c47a52a 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -312,8 +312,6 @@ ivas_error ivas_ls_setup_conversion_open( int32_t output_Fs; int16_t nchan_out; - wmops_sub_start( "LS_Renderer" ); - output_Fs = st_ivas->hDecoderConfig->output_Fs; nchan_out = st_ivas->hDecoderConfig->nchan_out; output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); @@ -1072,8 +1070,6 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( } } - wmops_sub_end(); - return; } diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 5f451a5d55c5b25918588e469e302921d46f25d1..49f3555c6f9289d0123d64926eac700946a65d4c 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -47,7 +47,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_in, IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); +static void ivas_sba_mtx_mult( float output_f[][L_FRAME48k], const int16_t output_frame, const int16_t nchan_in, const IVAS_OUTPUT_SETUP output_setup, const float *mtx_hoa_decoder ); /*-------------------------------------------------------------------* @@ -143,11 +143,11 @@ ivas_error ivas_sba_linear_renderer( *-------------------------------------------------------------------*/ static void ivas_sba_mtx_mult( - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ - const int16_t output_frame, /* i : output frame length per channel */ - const int16_t nchan_in, /* i : Number of ambisonic channels */ - IVAS_OUTPUT_SETUP output_setup, /* i : Output configuration */ - const float *mtx_hoa_decoder /* i : HOA decoding mtx */ + float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + const int16_t output_frame, /* i : output frame length per channel */ + const int16_t nchan_in, /* i : Number of ambisonic channels */ + const IVAS_OUTPUT_SETUP output_setup, /* i : Output configuration */ + const float *mtx_hoa_decoder /* i : HOA decoding mtx */ ) { int16_t i, k, ch_idx; @@ -291,19 +291,17 @@ void ivas_sba_upmixer_renderer( *-------------------------------------------------------------------*/ void ivas_sba_mix_matrix_determiner( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ float output[][L_FRAME48k], /* i/o: transport/output audio channels */ + const int16_t bfi, /* i : BFI flag */ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ const int16_t output_frame /* i : output frame length */ ) { int16_t i, ch; float temp; - SPAR_DEC_HANDLE hSpar; int16_t num_bands_out, nchan_transport, nchan_out; - hSpar = st_ivas->hSpar; - /* Convert numeric range */ for ( ch = 0; ch < nchan_remapped; ch++ ) { @@ -341,9 +339,7 @@ void ivas_sba_mix_matrix_determiner( /* Mixing matrix determiner */ num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi ); - - wmops_sub_end(); + ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi ); return; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index 3d4c38f272439cc8ee4368d6d4e418f737044bbd..d626d1ca6abc26ae8625f16978e0ea92df91727e 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -381,8 +381,7 @@ void stereo_mdct_core_dec( ivas_mdct_core_tns_ns( hCPE, 0, fUseTns, tnsData, x, Aq, 0 ); - if ( - st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ) ) + if ( st_ivas->renderer_type == RENDERER_MC_PARAMMC && ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ) ) { ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index d3fa68ced72e02d9f80fa1953892ace88fb02dab..78b9f901aaf2d9d1ec8800d70234e89f7d2c66fa 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -146,9 +146,12 @@ ivas_error IVAS_DEC_Open( hIvasDec->prev_ft_speech = 1; /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ + /* initialize pointers to handles */ + ivas_initialize_handles_dec( hIvasDec->st_ivas ); + + /* high-level set parameters */ if ( mode == IVAS_DEC_MODE_EVS ) { - /* EVS - do alloc etc. */ hIvasDec->st_ivas->codec_mode = 0; /* unknown before first frame */ hIvasDec->st_ivas->element_mode_init = EVS_MONO; hIvasDec->st_ivas->ivas_format = MONO_FORMAT; @@ -170,9 +173,6 @@ ivas_error IVAS_DEC_Open( hIvasDec->st_ivas->ini_active_frame = 0; hIvasDec->st_ivas->writeFECoffset = 0; - /*initialize pointers*/ - ivas_initialize_handles_dec( hIvasDec->st_ivas ); - hIvasDec->st_ivas->ism_mode = ISM_MODE_NONE; hIvasDec->st_ivas->sba_mode = SBA_MODE_NONE; hIvasDec->st_ivas->mc_mode = MC_MODE_NONE; diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index c1357a7f7470346a038bfbd316f75d589c0e4e7b..1f5a90673381e512c6a3c34edcfb2f2db7c0c451 100644 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -486,6 +486,44 @@ void bw_detect( } } } +#ifdef FIX_I2_BWD + else if ( st->localVAD == 0 && st->bwd_high_brate_flag == 1 && st->input_bwidth == WB ) /* applies in IVAS only */ + { + if( st->count_SWB > 0 ) + { + st->count_SWB++; + } + + if ( st->count_FB > 0 ) + { + st->count_FB++; + } + + if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) + { + if ( st->count_SWB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = SWB; + st->count_SWB = BWD_COUNT_MAX; + + if ( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + } + + if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) + { + if ( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + } +#endif } /* verify that maximum encoded bandwidth (specified on the command line) is not exceeded */ diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 1ae2f48c66cd2a6c0af1b76c4765d7594a3b03f5..2a15da648800e5dd9e19d2a28b55fd8a04039249 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -398,6 +398,9 @@ ivas_error init_encoder( st->last_bwidth = st->bwidth; st->last_bwidth_cng = st->bwidth; st->bwidth_sw_cnt = 0; +#ifdef FIX_I2_BWD + st->bwd_high_brate_flag = 0; +#endif /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 42a17cb9cbefa40eb58b1e9d246f9c48fc1292a7..27b05ef6a1929d9884f068fca9d170642aefdace 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -443,6 +443,9 @@ ivas_error ivas_core_enc( dbgwrite( &st->count_WB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_WB", n, id, ENC ) ); dbgwrite( &st->count_SWB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_SWB", n, id, ENC ) ); +#ifdef FIX_I2_BWD + dbgwrite( &st->count_FB, sizeof( int16_t ), 1, input_frame, fname( debug_dir, "count_FB", n, id, ENC ) ); +#endif #ifdef DEBUG_MODE_ACELP dbgwrite( snr_[n], sizeof( float ), 320, 1, fname( debug_dir, "snr", n, id, ENC ) ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b543761491bd57c201045f9c42280183bda1feaa..2c1022920e3ed134cb6e80da01d7e23f1ee09d8a 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -148,6 +148,9 @@ ivas_error ivas_cpe_enc( sts[n]->bwidth = sts[n]->last_bwidth; /* updated in BWD */ } sts[n]->rate_switching_reset = 0; +#ifdef FIX_I2_BWD + sts[n]->bwd_high_brate_flag = ivas_total_brate >= BWD_HIGH_BRATE_THR ? 1 : 0; +#endif #ifdef DEBUGGING sts[n]->force = hEncoderConfig->force; sts[n]->id_element = cpe_id + st_ivas->nSCE; diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 942dd14c999b07d44c2e8608ce33633d630a90ea..e648484808f03cf754c3fc9898431b85021bd6f1 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -118,6 +118,9 @@ ivas_error ivas_sce_enc( st->input_bwidth = st->last_input_bwidth; /* updated in BWD */ st->bwidth = st->last_bwidth; /* updated in BWD */ st->rate_switching_reset = 0; +#ifdef FIX_I2_BWD + st->bwd_high_brate_flag = st_ivas->hEncoderConfig->ivas_total_brate >= BWD_HIGH_BRATE_THR ? 1 : 0; +#endif #ifdef DEBUGGING st->force = st_ivas->hEncoderConfig->force; st->id_element = sce_id; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 803e9518fec55a19b6c4de4596538df931d741b5..104a8ca388a363a73eafda5c32b31b00a6cef0d0 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -845,7 +845,7 @@ static ivas_error configureEncoder( } } - if ( hEncoderConfig->ivas_total_brate == 13200 && hEncoderConfig->Opt_RF_ON == 1 ) + if ( hEncoderConfig->ivas_total_brate == IVAS_13k2 && hEncoderConfig->Opt_RF_ON == 1 ) { st_ivas->codec_mode = MODE2; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index de0451d3bc63d17a62bf119c6059203aed678ab0..e1016c7cf432007d2f2a7b852fe42855258328f2 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1389,6 +1389,9 @@ typedef struct enc_core_structure int16_t count_WB; int16_t count_SWB; int16_t count_FB; +#ifdef FIX_I2_BWD + int16_t bwd_high_brate_flag; +#endif /*----------------------------------------------------------------------------------* * Channel-aware mode