diff --git a/lib_com/options.h b/lib_com/options.h index 3c41d7d271c0d558ebbc19c1356d267ddc011055..612e6b1b499a478e09b0a9811f3bdcbca693e1c5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,6 +149,7 @@ #ifdef AGC_TUNING_IMPROVEMENT #define AGC_ENABLE_FOR_LBR /* Issue 168: Enable AGC for low bit rate (1 TC) */ #endif +#define FIX_TCX_DEC_RECONF_BFI /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 41196b6b0268c4925fc0dc38ac248e131542a2a5..8e56ed5ef78e8f53b9d5900e76858573414a9526 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -51,7 +51,14 @@ * Local prototypes *-------------------------------------------------------------*/ +#ifdef FIX_TCX_DEC_RECONF_BFI +static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, const int16_t last_element_mode, int16_t *bitsRead ); +#else static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, int16_t *bitsRead ); +#endif +#ifdef FIX_TCX_DEC_RECONF_BFI +static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t MCT_flag, const int16_t last_element_mode ); +#endif /*-------------------------------------------------------------* @@ -66,7 +73,9 @@ void stereo_tcx_init_dec( const int16_t last_element_mode /* i : element mode of previous frame */ ) { +#ifndef FIX_TCX_DEC_RECONF_BFI int16_t frame_size_index; +#endif TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -125,9 +134,19 @@ void stereo_tcx_init_dec( } } +#ifdef FIX_TCX_DEC_RECONF_BFI + if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || + ( st->bwidth != st->last_bwidth ) || + ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || + ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) +#else if ( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || ( st->bwidth != st->last_bwidth ) || ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) +#endif { /*re-initialization*/ +#ifdef FIX_TCX_DEC_RECONF_BFI + stereo_tcx_dec_mode_switch_reconf( st, MCT_flag, last_element_mode ); +#else st->rate_switching_init = 1; /* Identify frame type - TCX Reconfiguration */ @@ -151,6 +170,7 @@ void stereo_tcx_init_dec( /* Reconfigure Core */ mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode ); +#endif } return; @@ -284,7 +304,11 @@ void stereo_tcx_core_dec( tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; #endif +#ifdef FIX_TCX_DEC_RECONF_BFI + dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); +#else dec_prm_tcx( st, param, param_lpc, &total_nbbits, &bitsRead ); +#endif #ifdef FIX_IVAS_337 /*IVAS-337 consider BER */ if ( !st->rate_switching_init && st->BER_detect ) @@ -808,6 +832,9 @@ static void dec_prm_tcx( int16_t param[], /* o : decoded parameters */ int16_t param_lpc[], /* o : LPC parameters */ int16_t *total_nbbits, /* i/o: number of bits / decoded bits */ +#ifdef FIX_TCX_DEC_RECONF_BFI + const int16_t last_element_mode, +#endif int16_t *bitsRead /* o : number of read bits */ ) { @@ -861,6 +888,14 @@ static void dec_prm_tcx( st->prev_bfi = 1; } +#ifdef FIX_TCX_DEC_RECONF_BFI + /* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */ + if ( ( st->last_core != st->last_core_from_bs ) && ( st->last_core_from_bs != TCX_20_CORE && st->last_core_from_bs != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core_from_bs == ACELP_CORE && st->last_con_tcx == 1 ) ) ) + { + stereo_tcx_dec_mode_switch_reconf( st, 0, last_element_mode ); + } +#endif + st->last_core = st->last_core_from_bs; /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ @@ -923,3 +958,38 @@ static void dec_prm_tcx( return; } + +#ifdef FIX_TCX_DEC_RECONF_BFI +static void stereo_tcx_dec_mode_switch_reconf( + Decoder_State *st, + const int16_t MCT_flag, + const int16_t last_element_mode +) +{ + int16_t frame_size_index; + + st->rate_switching_init = 1; + + /* Identify frame type - TCX Reconfiguration */ + for ( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ ) + { + if ( frame_size_index < FRAME_SIZE_NB - 1 ) + { + if ( ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) && ( FrameSizeConfig[frame_size_index + 1].frame_bits > st->bits_frame_nominal ) ) + { + break; + } + } + else + { + if ( FrameSizeConfig[frame_size_index].frame_bits <= st->bits_frame_nominal ) + { + break; + } + } + } + + /* Reconfigure Core */ + mode_switch_decoder_LPD( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode ); +} +#endif