diff --git a/lib_com/options.h b/lib_com/options.h index 314b872e7d62d13981efcd5df282e01f227816d3..3ce2968c0203337401a226c47be53f49f6981018 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,12 +152,10 @@ #define SBA_CLEANING /* SBA maintenance related to ticket #45 */ #define DIRAC_DRCT_GAIN_TUNING - #define FIX_34 /* Nokia: Fix bug in MASA format EXT output spherical indexing */ - #define FIX_I68_MC_REVERB_FOR_514 /* Fix HRTF processing for Jot reverb in case of 5.1.4 input format */ - #define FIX_I54_LS_CONVERSION /* FhG: fix incorrect downmix matrix for 5_1_4 to 5_1_2 and upmix matrix for 7_1 to 7_1_4 */ +#define FIX_I25_FBE_FB_BITS /* issue 25: properly skip reading of TBE FB bits when decoder output sampling rate is not 48 kHz */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d7e42cec54bf396a969c110865a51f636de416b8..9e8ba73407103882cca3e7d52d42e1f72ecdba0b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2777,6 +2777,11 @@ void fb_tbe_dec( const float fb_exc[], /* i : FB excitation from the SWB part */ float *hb_synth, /* i/o: high-band synthesis */ float *fb_synth_ref /* o : high-band synthesis 16-20 kHz */ +#ifdef FIX_I25_FBE_FB_BITS + , + const int16_t output_frame /* i: output frame length */ +#endif + ); void calc_tilt_bwe( diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 9943ca9b980953a6857a3e4a102edacf2c6b3bf5..6d9f5a37e1c698d4d023ed1c1e1a3495fe97b4c7 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -103,7 +103,7 @@ ivas_error evs_dec( st->extl = -1; } - output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); + output_frame = ( int16_t )( st->output_Fs / FRAMES_PER_SEC ); core_switching_flag = 0; sharpFlag = 0; @@ -319,7 +319,11 @@ ivas_error evs_dec( /* FB TBE decoder */ if ( output_frame == L_FRAME48k && st->extl == FB_TBE ) { +#ifdef FIX_I25_FBE_FB_BITS + fb_tbe_dec( st, fb_exc, hb_synth, NULL, L_FRAME48k ); +#else fb_tbe_dec( st, fb_exc, hb_synth, NULL ); +#endif } } else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( st->output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) @@ -410,7 +414,7 @@ ivas_error evs_dec( if ( ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) ) { /* switching between BWE and TBE technologies */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( tmps + 0.5f ) ); for ( i = 0; i < tmps; i++ ) { hb_synth[i] *= sin_table256[i * incr]; @@ -421,7 +425,7 @@ ivas_error evs_dec( else if ( tmps < st->old_bwe_delay ) { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( tmps + 0.5f ) ); for ( i = 0; i < tmps; i++ ) { tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + @@ -433,7 +437,7 @@ ivas_error evs_dec( else if ( tmps > st->old_bwe_delay ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); for ( i = 0; i < st->old_bwe_delay; i++ ) { tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; @@ -600,7 +604,11 @@ ivas_error evs_dec( if ( st->extl == FB_TBE && output_frame == L_FRAME48k ) { +#ifdef FIX_I25_FBE_FB_BITS + fb_tbe_dec( st, fb_exc, hb_synth, NULL, L_FRAME48k ); +#else fb_tbe_dec( st, fb_exc, hb_synth, NULL ); +#endif } } mvr2r( hb_synth, st->hBWE_TD->old_hb_synth, output_frame ); @@ -833,7 +841,7 @@ ivas_error evs_dec( { if ( !st->bfi && st->core == ACELP_CORE && ( st->tec_flag || st->tfa_flag ) && st->output_Fs > 8000 && st->hTECDec != NULL ) { - procTecTfa_TBE( hb_synth, st->hTECDec->pGainTemp, st->tfa_flag, st->last_core, (int16_t) ( output_frame / N_TEC_TFA_SUBFR ), st->tec_flag == 2 ? 1 : 0 ); + procTecTfa_TBE( hb_synth, st->hTECDec->pGainTemp, st->tfa_flag, st->last_core, ( int16_t )( output_frame / N_TEC_TFA_SUBFR ), st->tec_flag == 2 ? 1 : 0 ); } if ( ( ( ( !st->bfi || st->last_core == ACELP_CORE ) && st->core == ACELP_CORE ) || diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 6a3f588f9bd78ca0978913e857a6d863fe72747a..a30813e3f72052cccd92aa552ae12c99fa87d489 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -142,7 +142,7 @@ ivas_error ivas_core_dec( } output_Fs = sts[0]->output_Fs; - output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); + output_frame = ( int16_t )( output_Fs / FRAMES_PER_SEC ); for ( n = 0; n < n_channels; n++ ) { @@ -269,10 +269,10 @@ ivas_error ivas_core_dec( } if ( sts[0]->L_frame != L_FRAME16k ) { - ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + ovl = ( int16_t )( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); lerp( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); - fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + fade_len = ( int16_t )( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); lerp( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); } } @@ -531,10 +531,17 @@ ivas_error ivas_core_dec( swb_tbe_dec( st, hStereoICBWE, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], tmp_buffer /*fb_exc*/, hb_synth[n], pitch_buf[n] ); /* FB TBE decoder */ +#ifdef FIX_I25_FBE_FB_BITS + if ( st->extl == FB_TBE ) + { + fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); + } +#else if ( output_frame == L_FRAME48k && st->extl == FB_TBE ) { fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/ ); } +#endif } else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) { @@ -622,7 +629,7 @@ ivas_error ivas_core_dec( ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) && ( st->element_mode != IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) ) { /* switching between BWE and TBE technologies */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( tmps + 0.5f ) ); for ( i = 0; i < tmps; i++ ) { hb_synth[n][i] *= sin_table256[i * incr]; @@ -633,7 +640,7 @@ ivas_error ivas_core_dec( else if ( tmps < st->old_bwe_delay ) { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( tmps + 0.5f ) ); for ( i = 0; i < tmps; i++ ) { tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + @@ -645,7 +652,7 @@ ivas_error ivas_core_dec( else if ( tmps > st->old_bwe_delay ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); + incr = ( int16_t )( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); for ( i = 0; i < st->old_bwe_delay; i++ ) { tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index a0c863cc4b2568bcb2b88af7f415e701a82a4573..d3e43a3d359fc9da013e3417cabe33e0581190dd 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1015,11 +1015,11 @@ void swb_tbe_dec( lpc_shb[0] = 1.0; if ( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 ) { - vind = (int16_t) ( mixFactors * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); + vind = ( int16_t )( mixFactors * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) ); } else { - vind = (int16_t) ( mixFactors * ( 1 << NUM_BITS_SHB_VF ) ); + vind = ( int16_t )( mixFactors * ( 1 << NUM_BITS_SHB_VF ) ); } /* Determine formant PF strength */ @@ -1977,6 +1977,10 @@ void fb_tbe_dec( const float fb_exc[], /* i : FB excitation from the SWB part */ float *hb_synth, /* o : high-band synthesis */ float *fb_synth_ref /* o : high-band synthesis 16-20 kHz */ +#ifdef FIX_I25_FBE_FB_BITS + , + const int16_t output_frame /* i: output frame length */ +#endif ) { int16_t i; @@ -1986,23 +1990,40 @@ void fb_tbe_dec( hBWE_TD = st->hBWE_TD; - /* decode FB slope information */ - if ( st->extl == FB_TBE && !st->bfi ) +#ifdef FIX_I25_FBE_FB_BITS + if ( output_frame == L_FRAME48k ) { - if ( st->codec_mode == MODE2 ) +#endif + /* decode FB slope information */ + if ( st->extl == FB_TBE && !st->bfi ) { - i = hBWE_TD->idxGain; + if ( st->codec_mode == MODE2 ) + { + i = hBWE_TD->idxGain; + } + else + { + i = get_next_indice( st, NUM_BITS_FB_FRAMEGAIN_TBE ); + } + ratio = (float) ( 1 << i ); } - else + else if ( st->extl == FB_TBE && st->bfi ) { - i = get_next_indice( st, NUM_BITS_FB_FRAMEGAIN_TBE ); + ratio = hBWE_TD->prev_fbbwe_ratio; } - ratio = (float) ( 1 << i ); +#ifdef FIX_I25_FBE_FB_BITS } - else if ( st->extl == FB_TBE && st->bfi ) + else { - ratio = hBWE_TD->prev_fbbwe_ratio; + /* update the position in the bitstream - needed in IVAS */ + if ( !st->bfi ) + { + st->next_bit_pos += NUM_BITS_FB_FRAMEGAIN; + } + + return; } +#endif fb_exc_energy = sum2_f( fb_exc, L_FRAME16k );