diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 90930b07312add9762c284d8184403dd52901c99..9b3e52ed80a160332133f9b91f2454e6c2a073c5 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2716,7 +2716,9 @@ void ivas_mct_core_enc( CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ const int16_t nChannels, /* i : number of channels to be coded */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ +#ifndef DISABLE_BWD_MCT const int16_t switch_bw, /* i : flag bandwidth switch occurance */ +#endif const int16_t lfe_bits, /* i : bits spent for LFE */ const int16_t sba_order /* i : Ambisonic (SBA) order */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 1c133b109bc9d96141e3dfdbc656f866abcfbdae..96361e3b899eef9802fce442a467ff0cbc20f26e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,6 +159,7 @@ #endif #define FIX_380_BFI_PARAMISM /* VA: issue 380 - fix metadata recovery in ParamISM BFI */ +#define FIX_MDCT_BASED_BWD /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index de6c521048fb8447092692f47dadcff654004420..fc1dcad992ae4c7794d6b80f6887d605e529c6e0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3827,8 +3827,13 @@ void bw_detect( const float signal_in[], /* i : input signal */ float *spectrum, /* i : MDCT spectrum */ const float *enerBuffer /* i : energy buffer */ +#ifdef FIX_MDCT_BASED_BWD + , + const int16_t mct_on /* i : flag MCT mode */ +#endif ); + void set_bw( const int16_t element_mode, /* i : element mode */ const int32_t element_brate, /* i : element bitrate */ diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c old mode 100644 new mode 100755 index 80520d4c38d37b99a347b7262506eee0c39eb7ed..88b3faa5d6c16ffafa834706a7631fd915cf44fa --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -342,7 +342,12 @@ void amr_wb_enc( * WB, SWB and FB bandwidth detector *----------------------------------------------------------------*/ - bw_detect( st, st->input, NULL, NULL ); + bw_detect( st, st->input, NULL, NULL +#ifdef FIX_MDCT_BASED_BWD + , + 0 +#endif + ); /* in AMR_WB IO, limit the maximum band-width to WB */ if ( st->bwidth > WB ) diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c old mode 100644 new mode 100755 index 5f46910c57076190a267f7e8f8785b2460431e5b..8ca63d28f2629a9ac8f5019b3768c00795261158 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -57,6 +57,9 @@ #define BWD_COUNT_MAX 100 #define BWD_COUNT_WIDER_BW 10 +#ifdef FIX_MDCT_BASED_BWD +#define BWD_COUNT_WIDER_BW_MDCT 0 +#endif #define CLDFB_ENER_OFFSET 1.6f @@ -71,6 +74,10 @@ void bw_detect( const float signal_in[], /* i : input signal */ float *spectrum, /* i : MDCT spectrum */ const float *enerBuffer /* i : energy buffer */ +#ifdef FIX_MDCT_BASED_BWD + , + const int16_t mct_on /* i : flag MCT mode */ +#endif ) { int16_t i, j, k, bw_max, bin_width, n_bins; @@ -80,6 +87,15 @@ void bw_detect( const float *pt, *pt1; float max_NB, max_WB, max_SWB, max_FB, mean_NB, mean_WB, mean_SWB, mean_FB; int16_t cldfb_bin_width = 4; +#ifdef FIX_MDCT_BASED_BWD + int16_t bwd_count_wider_bw, l_frame; + + bwd_count_wider_bw = BWD_COUNT_WIDER_BW; + if ( st->element_mode == IVAS_CPE_MDCT && ( st->element_brate > IVAS_64k || mct_on ) ) + { + bwd_count_wider_bw = BWD_COUNT_WIDER_BW_MDCT; + } +#endif if ( st->input_Fs > 8000 ) { @@ -173,8 +189,19 @@ void bw_detect( } else { +#ifndef FIX_MDCT_BASED_BWD bin_width *= (int16_t) ( ( st->input_Fs / FRAMES_PER_SEC ) / BWD_TOTAL_WIDTH ); mvr2r( spectrum, spect, (int16_t) ( st->input_Fs / FRAMES_PER_SEC ) ); +#else + l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); + if ( st->core == TCX_10_CORE ) + { + l_frame /= 2; + } + + bin_width *= ( l_frame / BWD_TOTAL_WIDTH ); + mvr2r( spectrum, spect, l_frame ); +#endif } /*---------------------------------------------------------------------* * compute energy per spectral bins @@ -392,17 +419,29 @@ void bw_detect( /* switching to a higher BW */ if ( st->last_input_bwidth == NB ) { +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_WB > bwd_count_wider_bw ) +#else if ( st->count_WB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = WB; st->count_WB = BWD_COUNT_MAX; +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_SWB > bwd_count_wider_bw ) +#else if ( st->count_SWB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = SWB; st->count_SWB = BWD_COUNT_MAX; +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_FB > bwd_count_wider_bw ) +#else if ( st->count_FB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = FB; st->count_FB = BWD_COUNT_MAX; @@ -413,12 +452,20 @@ void bw_detect( if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) { +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_SWB > bwd_count_wider_bw ) +#else if ( st->count_SWB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = SWB; st->count_SWB = BWD_COUNT_MAX; +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_FB > bwd_count_wider_bw ) +#else if ( st->count_FB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = FB; st->count_FB = BWD_COUNT_MAX; @@ -428,7 +475,11 @@ void bw_detect( if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) { +#ifdef FIX_MDCT_BASED_BWD + if ( st->count_FB > bwd_count_wider_bw ) +#else if ( st->count_FB > BWD_COUNT_WIDER_BW ) +#endif { st->input_bwidth = FB; st->count_FB = BWD_COUNT_MAX; diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c old mode 100644 new mode 100755 index 6e2f6b6db2e1cf38298085f9fa7e38edf8de9af6..85eba72f006b477315f626931811aceb8c5443f3 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -486,7 +486,12 @@ ivas_error pre_proc_front_ivas( if ( st->idchan == 0 && element_mode != IVAS_CPE_MDCT ) { - bw_detect( st, st->input, NULL, enerBuffer ); + bw_detect( st, st->input, NULL, enerBuffer +#ifdef FIX_MDCT_BASED_BWD + , + 0 +#endif + ); } if ( element_mode != IVAS_CPE_MDCT ) /* in MDCT stereo, set_bw_stereo() is used instead */ diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 5cbcb57daf4e789f8f308808c5c26b9875083d34..c442882107d88c34d2e94a787503b75c49b7c869 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -194,9 +194,11 @@ void ivas_mct_core_enc( CPE_ENC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE encoder structures */ const int16_t nChannels, /* i : number of channels to be coded */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t switch_bw, /* i : flag bandwidth switch occurance */ - const int16_t lfe_bits, /* i : bits spent for LFE */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ +#ifndef DISABLE_BWD_MCT + const int16_t switch_bw, /* i : flag bandwidth switch occurance */ +#endif + const int16_t lfe_bits, /* i : bits spent for LFE */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ ) { int16_t ch, ch_core, nSubframes, L_subframeTCX; @@ -278,12 +280,13 @@ void ivas_mct_core_enc( { ch_core = ch * CPE_CHANNELS; +#ifndef DISABLE_BWD_MCT if ( switch_bw ) { initMdctStereoEncData( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); } - +#endif if ( sts[ch_core]->igf ) { /* calculate the igf start band from the igf start line */ diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index a9ce8e3abadf881568199f415d8a55ea28fb7909..b66a2c5733c4622d6315b87d01e16f8a051fede5 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -173,8 +173,7 @@ ivas_error ivas_mct_enc( } /* joint MCT encoding */ - ivas_mct_core_enc( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE + hMCT->num_lfe, ivas_total_brate, switch_bw, - ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) ? (int16_t) st_ivas->hLFE->lfe_bits : 0, st_ivas->hEncoderConfig->sba_order ); + ivas_mct_core_enc( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE + hMCT->num_lfe, ivas_total_brate, switch_bw, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCT ) ? (int16_t) st_ivas->hLFE->lfe_bits : 0, st_ivas->hEncoderConfig->sba_order ); /* Spectrum quantization and coding */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c old mode 100644 new mode 100755 index 626dcf2631cee1f65518558caaa04e9a58a22919..ef9264d5df2feffbad446ea5bf010bb368a1f64d --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -686,6 +686,7 @@ void ivas_mdct_core_whitening_enc( core_signal_analysis_high_bitrate( new_samples[ch] + L_INP_MEM, T_op[ch], NULL, NULL, st, mdst_spectrum[ch], tnsSize[ch], tnsBits[ch], param_core[ch], <pBits[ch], windowedSignal[ch], st->L_frame, st->hTcxEnc->L_frameTCX, hCPE->last_element_mode, 0 ); /* BWD in MDCT domain */ +#ifndef FIX_MDCT_BASED_BWD if ( st->hTcxEnc->transform_type[0] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) { if ( st->mct_chan_mode != MCT_CHAN_MODE_LFE ) @@ -693,6 +694,22 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[0], NULL ); } } +#else + if ( st->mct_chan_mode != MCT_CHAN_MODE_LFE && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) + { + nSubframes = ( st->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV; + + for ( n = 0; n < nSubframes; n++ ) + { + bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, mct_on ); + + if ( nSubframes == NB_DIV && n == 0 ) + { + st->last_input_bwidth = st->input_bwidth; + } + } + } +#endif if ( st->last_core == ACELP_CORE ) /* reset past kernel info */ { diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c old mode 100644 new mode 100755 index 300cb79787d08451ccd6734198d38938badce4ed..bbeba48a1649f2ad69b4be4ef38cb45a7b6be101 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -219,7 +219,12 @@ void pre_proc( * NB/WB/SWB/FB bandwidth detector *----------------------------------------------------------------*/ - bw_detect( st, st->input, NULL, enerBuffer ); + bw_detect( st, st->input, NULL, enerBuffer +#ifdef FIX_MDCT_BASED_BWD + , + 0 +#endif + ); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation