From ddd110c7ad299a0d808b5513acec1791305a5e87 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 17 Mar 2023 15:40:15 +0100 Subject: [PATCH 1/6] turn off bandwidth detection for MCT under DISABLE_BWD_MCT --- lib_com/ivas_prot.h | 2 ++ lib_com/options.h | 1 + lib_enc/bw_detect.c | 3 ++- lib_enc/ivas_mct_core_enc.c | 11 +++++++---- lib_enc/ivas_mct_enc.c | 9 ++++++++- lib_enc/ivas_mdct_core_enc.c | 14 +++++++++++++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8ec50b98a0..273e2ae434 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2713,7 +2713,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 1dd2d2e218..d82a439c99 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,7 @@ #define FIX_372_LIB_REND_VALIDATE_IO /* FhG: Issue 372: IVAS_rend segfaults with unsupported I/O configs - add validation checks of I/O config */ #define FIX_376_SBA_ROTATE /*DLB: Fix for issue 376*/ #define TD5 /* Eri: Contribution 17: Extended metadata for 6 DoF rendering in TD renderer */ +#define DISABLE_BWD_MCT /* FhG: Disable bandwidth detection for MCT*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index 5f46910c57..c23741adf9 100644 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -647,7 +647,7 @@ void set_bw_stereo( return; } - +#ifndef DISABLE_BWD_MCT /*-------------------------------------------------------------------* * set_bw_mct() * @@ -698,3 +698,4 @@ int16_t set_bw_mct( return bw_changed; } +#endif \ No newline at end of file diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 5cbcb57daf..c442882107 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 707e74e329..4a4505f786 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -109,7 +109,9 @@ ivas_error ivas_mct_enc( CPE_ENC_HANDLE hCPE; float mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; float orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; +#ifndef DISABLE_BWD_MCT int16_t switch_bw; +#endif IVAS_FORMAT ivas_format; int16_t max_bwidth; int32_t ivas_total_brate; @@ -160,8 +162,10 @@ ivas_error ivas_mct_enc( } } +#ifndef DISABLE_BWD_MCT /* set coded audio band-width */ switch_bw = set_bw_mct( st_ivas->hCPE, st_ivas->nCPE ); +#endif /* pre-processing */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -173,7 +177,10 @@ 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_mct_core_enc( ivas_format, hMCT, st_ivas->hCPE, hMCT->nchan_out_woLFE + hMCT->num_lfe, ivas_total_brate, +#ifndef DISABLE_BWD_MCT + switch_bw, +#endif ( 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 */ diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 626dcf2631..7287537c72 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -685,7 +685,8 @@ 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 */ +/* BWD in MDCT domain */ +#ifndef DISABLE_BWD_MCT 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,17 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[0], NULL ); } } +#else + if ( ( st->hTcxEnc->transform_type[0] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) && !mct_on ) + { + + bw_detect( st, NULL, st->hTcxEnc->spectrum[0], NULL ); + } + else if ( mct_on ) + { + st->bwidth = st->max_bwidth; + } +#endif if ( st->last_core == ACELP_CORE ) /* reset past kernel info */ { -- GitLab From c15a98c88cb005d59f21532efdf6b2e379f91f47 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 17 Mar 2023 16:14:48 +0100 Subject: [PATCH 2/6] fix end of line issue --- lib_enc/bw_detect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index c23741adf9..c709cc3b2f 100644 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -698,4 +698,4 @@ int16_t set_bw_mct( return bw_changed; } -#endif \ No newline at end of file +#endif -- GitLab From 9a1a78818ccb112a8d62ef7ce8f161391239fec0 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Tue, 21 Mar 2023 18:57:39 +0100 Subject: [PATCH 3/6] proposed fix for FIX_MDCT_STEREO_BWD_TCX10 --- lib_com/options.h | 6 ++++-- lib_enc/bw_detect.c | 6 ++++++ lib_enc/ivas_mdct_core_enc.c | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index b20e6db5d1..13af4a7942 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -153,9 +153,11 @@ #define TD5_FIX_INVALID_MEMORY_ACCESS /* FhG: Resolves segfault in case IVAS_REND_InitConfig gets initialized with rendererConfigEnabled:=false && ISM are being rendered */ #ifdef FIX_I109_ORIENTATION_TRACKING -#define OTR_REFERENCE_VECTOR_TRACKING /* FhG: enables the reference position orientation tracking mode */ +#define OTR_REFERENCE_VECTOR_TRACKING /* FhG: enables the reference position orientation tracking mode */ #endif -#define DISABLE_BWD_MCT /* FhG: Disable bandwidth detection for MCT*/ +//#define DISABLE_BWD_MCT /* FhG: Disable bandwidth detection for MCT*/ +#define FIX_MDCT_STEREO_BWD_TCX10 /* FhG: enables bw detection also for TCX10 frames */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index c709cc3b2f..a212048bae 100644 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -173,8 +173,14 @@ void bw_detect( } else { +#ifndef FIX_MDCT_STEREO_BWD_TCX10 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 + assert( st->core != ACELP_CORE ); + bin_width *= (int16_t) ( ( st->input_Fs / ( FRAMES_PER_SEC * st->core ) ) / BWD_TOTAL_WIDTH ); + mvr2r( spectrum, spect, (int16_t) ( st->input_Fs / ( FRAMES_PER_SEC * st->core ) ) ); +#endif } /*---------------------------------------------------------------------* * compute energy per spectral bins diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 7287537c72..c3a75784b5 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -687,6 +687,7 @@ void ivas_mdct_core_whitening_enc( /* BWD in MDCT domain */ #ifndef DISABLE_BWD_MCT +#ifndef FIX_MDCT_STEREO_BWD_TCX10 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 ) @@ -695,15 +696,20 @@ void ivas_mdct_core_whitening_enc( } } #else - if ( ( st->hTcxEnc->transform_type[0] == TCX_20 && st->hTcxCfg->tcx_last_overlap_mode != TRANSITION_OVERLAP ) && !mct_on ) + 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; - bw_detect( st, NULL, st->hTcxEnc->spectrum[0], NULL ); - } - else if ( mct_on ) - { - st->bwidth = st->max_bwidth; + for ( n = 0; n < nSubframes; n++ ) + { + bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL ); + if ( nSubframes == NB_DIV && n == 0 ) + { + st->last_input_bwidth = st->input_bwidth; + } + } } +#endif #endif if ( st->last_core == ACELP_CORE ) /* reset past kernel info */ -- GitLab From 6f3c26e1dae98b3e42d4230e2be4af5b25d6ebb9 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Thu, 23 Mar 2023 11:05:28 +0100 Subject: [PATCH 4/6] fix for BWD and transients under BWD_COUNT_FIX --- lib_com/options.h | 2 +- lib_com/prot.h | 5 ++ lib_enc/amr_wb_enc.c | 7 ++- lib_enc/bw_detect.c | 99 ++++++++++++++++++++++++------ lib_enc/ivas_core_pre_proc_front.c | 7 ++- lib_enc/ivas_mdct_core_enc.c | 7 ++- lib_enc/pre_proc.c | 7 ++- 7 files changed, 110 insertions(+), 24 deletions(-) mode change 100644 => 100755 lib_enc/amr_wb_enc.c mode change 100644 => 100755 lib_enc/bw_detect.c mode change 100644 => 100755 lib_enc/ivas_core_pre_proc_front.c mode change 100644 => 100755 lib_enc/ivas_mdct_core_enc.c mode change 100644 => 100755 lib_enc/pre_proc.c diff --git a/lib_com/options.h b/lib_com/options.h index 13af4a7942..3bbf378873 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,7 +157,7 @@ #endif //#define DISABLE_BWD_MCT /* FhG: Disable bandwidth detection for MCT*/ #define FIX_MDCT_STEREO_BWD_TCX10 /* FhG: enables bw detection also for TCX10 frames */ - +#define BWD_COUNT_FIX /* FhG/Dolby: fix for issue of reacting to sudden transiensts in SBA/MCT modes */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 69cc4e0d32..cf67c188fc 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3828,8 +3828,13 @@ void bw_detect( const float signal_in[], /* i : input signal */ float *spectrum, /* i : MDCT spectrum */ const float *enerBuffer /* i : energy buffer */ +#ifdef BWD_COUNT_FIX + , + 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 80520d4c38..8e9879b0ef --- 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 BWD_COUNT_FIX + , + 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 a212048bae..40dd0e180d --- 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 BWD_COUNT_FIX +#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 BWD_COUNT_FIX + , + const int16_t mct_on /* i : flag MCT mode */ +#endif ) { int16_t i, j, k, bw_max, bin_width, n_bins; @@ -396,50 +403,104 @@ void bw_detect( *---------------------------------------------------------------------*/ /* switching to a higher BW */ - if ( st->last_input_bwidth == NB ) +#ifdef BWD_COUNT_FIX + if ( st->element_mode == IVAS_CPE_MDCT && ( st->element_brate > IVAS_64k || mct_on ) ) { - if ( st->count_WB > BWD_COUNT_WIDER_BW ) + if ( st->last_input_bwidth == NB ) { - st->input_bwidth = WB; - st->count_WB = BWD_COUNT_MAX; + if ( st->count_WB > BWD_COUNT_WIDER_BW_MDCT ) + { + st->input_bwidth = WB; + st->count_WB = BWD_COUNT_MAX; - if ( st->count_SWB > BWD_COUNT_WIDER_BW ) + if ( st->count_SWB > BWD_COUNT_WIDER_BW_MDCT ) + { + st->input_bwidth = SWB; + st->count_SWB = BWD_COUNT_MAX; + + if ( st->count_FB > BWD_COUNT_WIDER_BW_MDCT ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } + } + } + } + + if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) + { + if ( st->count_SWB > BWD_COUNT_WIDER_BW_MDCT ) { st->input_bwidth = SWB; st->count_SWB = BWD_COUNT_MAX; - if ( st->count_FB > BWD_COUNT_WIDER_BW ) + if ( st->count_FB > BWD_COUNT_WIDER_BW_MDCT ) { st->input_bwidth = FB; st->count_FB = BWD_COUNT_MAX; } } } - } - if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) - { - if ( st->count_SWB > BWD_COUNT_WIDER_BW ) + if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) { - st->input_bwidth = SWB; - st->count_SWB = BWD_COUNT_MAX; - - if ( st->count_FB > BWD_COUNT_WIDER_BW ) + if ( st->count_FB > BWD_COUNT_WIDER_BW_MDCT ) { st->input_bwidth = FB; st->count_FB = BWD_COUNT_MAX; } } } - - if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) + else { - if ( st->count_FB > BWD_COUNT_WIDER_BW ) +#endif + if ( st->last_input_bwidth == NB ) + { + if ( st->count_WB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = WB; + st->count_WB = BWD_COUNT_MAX; + + 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 == 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 ) { - st->input_bwidth = FB; - st->count_FB = BWD_COUNT_MAX; + if ( st->count_FB > BWD_COUNT_WIDER_BW ) + { + st->input_bwidth = FB; + st->count_FB = BWD_COUNT_MAX; + } } +#ifdef BWD_COUNT_FIX } +#endif /* switching to a lower BW */ if ( st->last_input_bwidth == FB ) 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 6e2f6b6db2..33587035ec --- 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 BWD_COUNT_FIX + , + 0 +#endif + ); } if ( element_mode != IVAS_CPE_MDCT ) /* in MDCT stereo, set_bw_stereo() is used instead */ 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 c3a75784b5..d9f5f7225a --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -702,7 +702,12 @@ void ivas_mdct_core_whitening_enc( for ( n = 0; n < nSubframes; n++ ) { - bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL ); + bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL +#ifdef BWD_COUNT_FIX + , + mct_on +#endif + ); if ( nSubframes == NB_DIV && n == 0 ) { st->last_input_bwidth = st->input_bwidth; diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c old mode 100644 new mode 100755 index 300cb79787..eb9099be00 --- 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 BWD_COUNT_FIX + , + 0 +#endif + ); /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation -- GitLab From 0ec50da40610b0536b94e299fa9237593c67b4a1 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 24 Mar 2023 14:03:27 +0100 Subject: [PATCH 5/6] cleanup and merge fixes under define FIX_MDCT_BASED_BWD --- lib_com/options.h | 4 +--- lib_com/prot.h | 2 +- lib_enc/amr_wb_enc.c | 2 +- lib_enc/bw_detect.c | 13 ++++++------- lib_enc/ivas_core_pre_proc_front.c | 2 +- lib_enc/ivas_mct_enc.c | 10 +--------- lib_enc/ivas_mdct_core_enc.c | 6 ++---- lib_enc/pre_proc.c | 2 +- 8 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0bccd3b107..96361e3b89 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,11 +157,9 @@ #ifdef FIX_I109_ORIENTATION_TRACKING #define OTR_REFERENCE_VECTOR_TRACKING /* FhG: enables the reference position orientation tracking mode */ #endif -//#define DISABLE_BWD_MCT /* FhG: Disable bandwidth detection for MCT*/ -#define FIX_MDCT_STEREO_BWD_TCX10 /* FhG: enables bw detection also for TCX10 frames */ -#define BWD_COUNT_FIX /* FhG/Dolby: fix for issue of reacting to sudden transiensts in SBA/MCT modes */ #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 8d625fde56..fc1dcad992 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3827,7 +3827,7 @@ void bw_detect( const float signal_in[], /* i : input signal */ float *spectrum, /* i : MDCT spectrum */ const float *enerBuffer /* i : energy buffer */ -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , const int16_t mct_on /* i : flag MCT mode */ #endif diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index 8e9879b0ef..88b3faa5d6 100755 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -343,7 +343,7 @@ void amr_wb_enc( *----------------------------------------------------------------*/ bw_detect( st, st->input, NULL, NULL -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , 0 #endif diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index 40dd0e180d..c08a703c42 100755 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -57,7 +57,7 @@ #define BWD_COUNT_MAX 100 #define BWD_COUNT_WIDER_BW 10 -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD #define BWD_COUNT_WIDER_BW_MDCT 0 #endif @@ -74,7 +74,7 @@ void bw_detect( const float signal_in[], /* i : input signal */ float *spectrum, /* i : MDCT spectrum */ const float *enerBuffer /* i : energy buffer */ -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , const int16_t mct_on /* i : flag MCT mode */ #endif @@ -180,7 +180,7 @@ void bw_detect( } else { -#ifndef FIX_MDCT_STEREO_BWD_TCX10 +#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 @@ -403,7 +403,7 @@ void bw_detect( *---------------------------------------------------------------------*/ /* switching to a higher BW */ -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD if ( st->element_mode == IVAS_CPE_MDCT && ( st->element_brate > IVAS_64k || mct_on ) ) { if ( st->last_input_bwidth == NB ) @@ -498,7 +498,7 @@ void bw_detect( st->count_FB = BWD_COUNT_MAX; } } -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD } #endif @@ -714,7 +714,7 @@ void set_bw_stereo( return; } -#ifndef DISABLE_BWD_MCT + /*-------------------------------------------------------------------* * set_bw_mct() * @@ -765,4 +765,3 @@ int16_t set_bw_mct( return bw_changed; } -#endif diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 33587035ec..85eba72f00 100755 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -487,7 +487,7 @@ ivas_error pre_proc_front_ivas( if ( st->idchan == 0 && element_mode != IVAS_CPE_MDCT ) { bw_detect( st, st->input, NULL, enerBuffer -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , 0 #endif diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 746b1cae4e..b66a2c5733 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -109,9 +109,7 @@ ivas_error ivas_mct_enc( CPE_ENC_HANDLE hCPE; float mdst_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; float orig_spectrum_long[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; -#ifndef DISABLE_BWD_MCT int16_t switch_bw; -#endif IVAS_FORMAT ivas_format; int16_t max_bwidth; int32_t ivas_total_brate; @@ -162,10 +160,8 @@ ivas_error ivas_mct_enc( } } -#ifndef DISABLE_BWD_MCT /* set coded audio band-width */ switch_bw = set_bw_mct( st_ivas->hCPE, st_ivas->nCPE ); -#endif /* pre-processing */ for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -177,11 +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, -#ifndef DISABLE_BWD_MCT - switch_bw, -#endif - ( 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 index d9f5f7225a..152f264295 100755 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -686,8 +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 DISABLE_BWD_MCT -#ifndef FIX_MDCT_STEREO_BWD_TCX10 +#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 ) @@ -703,7 +702,7 @@ void ivas_mdct_core_whitening_enc( for ( n = 0; n < nSubframes; n++ ) { bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , mct_on #endif @@ -714,7 +713,6 @@ void ivas_mdct_core_whitening_enc( } } } -#endif #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 index eb9099be00..bbeba48a16 100755 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -220,7 +220,7 @@ void pre_proc( *----------------------------------------------------------------*/ bw_detect( st, st->input, NULL, enerBuffer -#ifdef BWD_COUNT_FIX +#ifdef FIX_MDCT_BASED_BWD , 0 #endif -- GitLab From d9f3c80a1dad5ecb9e08dd15fe62495925fa0755 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 24 Mar 2023 16:11:17 +0100 Subject: [PATCH 6/6] reduction of code size --- lib_enc/bw_detect.c | 124 +++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 72 deletions(-) diff --git a/lib_enc/bw_detect.c b/lib_enc/bw_detect.c index 40dd0e180d..f815e7d67b 100755 --- a/lib_enc/bw_detect.c +++ b/lib_enc/bw_detect.c @@ -87,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 BWD_COUNT_FIX + int16_t bwd_count_wider_bw; + + 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 ) { @@ -403,104 +412,75 @@ void bw_detect( *---------------------------------------------------------------------*/ /* switching to a higher BW */ -#ifdef BWD_COUNT_FIX - if ( st->element_mode == IVAS_CPE_MDCT && ( st->element_brate > IVAS_64k || mct_on ) ) - { - if ( st->last_input_bwidth == NB ) - { - if ( st->count_WB > BWD_COUNT_WIDER_BW_MDCT ) - { - st->input_bwidth = WB; - st->count_WB = BWD_COUNT_MAX; - - if ( st->count_SWB > BWD_COUNT_WIDER_BW_MDCT ) - { - st->input_bwidth = SWB; - st->count_SWB = BWD_COUNT_MAX; - - if ( st->count_FB > BWD_COUNT_WIDER_BW_MDCT ) - { - st->input_bwidth = FB; - st->count_FB = BWD_COUNT_MAX; - } - } - } - } - - if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) - { - if ( st->count_SWB > BWD_COUNT_WIDER_BW_MDCT ) - { - st->input_bwidth = SWB; - st->count_SWB = BWD_COUNT_MAX; - - if ( st->count_FB > BWD_COUNT_WIDER_BW_MDCT ) - { - 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_MDCT ) - { - st->input_bwidth = FB; - st->count_FB = BWD_COUNT_MAX; - } - } - } - else + if ( st->last_input_bwidth == NB ) { +#ifdef BWD_COUNT_FIX + if ( st->count_WB > bwd_count_wider_bw ) +#else + if ( st->count_WB > BWD_COUNT_WIDER_BW ) #endif - if ( st->last_input_bwidth == NB ) { - if ( st->count_WB > BWD_COUNT_WIDER_BW ) - { - st->input_bwidth = WB; - st->count_WB = BWD_COUNT_MAX; - - 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; - } - } - } - } + st->input_bwidth = WB; + st->count_WB = BWD_COUNT_MAX; - if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) - { +#ifdef BWD_COUNT_FIX + 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 BWD_COUNT_FIX + 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; } } } + } - if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) + if ( st->last_input_bwidth == WB && st->input_Fs > 16000 ) + { +#ifdef BWD_COUNT_FIX + 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 BWD_COUNT_FIX + 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; } } -#ifdef BWD_COUNT_FIX } + + if ( st->last_input_bwidth == SWB && st->input_Fs > 32000 ) + { +#ifdef BWD_COUNT_FIX + 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; + } + } + /* switching to a lower BW */ if ( st->last_input_bwidth == FB ) -- GitLab