From c7f9fef4a46b854e2096a9b9e35274285d0c883d Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 14 Sep 2022 10:52:55 +0200 Subject: [PATCH 1/6] Added SWB TBE target fix under FIX_I102_SWB_TBE_SWITCH --- lib_com/options.h | 1 + lib_dec/acelp_core_dec.c | 9 ++++- lib_enc/acelp_core_enc.c | 7 ++++ lib_enc/swb_pre_proc.c | 71 ++++++++++++++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 15 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index dede5c1480..263d5efc8e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,6 +149,7 @@ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ +//#define FIX_I102_SWB_TBE_SWITCH /* Issue 102: avoid IO->SWB switching code for IVAS, generate SHB ACB mem with lerp in case of switch */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 7951f10d54..b98312a133 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -701,7 +701,14 @@ ivas_error acelp_core_dec( mvr2r( old_exc_s + st->L_frame - M, st->mem_syn2, M ); residu( Aq, M, old_exc_s, old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame ); } - +#ifdef FIX_I102_SWB_TBE_SWITCH + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + + } +#endif /*-----------------------------------------------------------------* * FEC - first good frame after lost frame(s) (possibility to correct the ACB) *-----------------------------------------------------------------*/ diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 8420810339..e4ce289a9e 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -472,6 +472,13 @@ ivas_error acelp_core_enc( mvr2r( hLPDmem->old_exc + st->L_frame - M, hLPDmem->mem_syn, M ); residu( Aq, M, hLPDmem->old_exc, old_exc, st->L_frame ); } +#ifdef FIX_I102_SWB_TBE_SWITCH + if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + lerp( old_exc, old_bwe_exc, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } +#endif /*---------------------------------------------------------------* * Calculation of LP residual (filtering through A[z] filter) diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 99c410ed47..e4779d0920 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -288,6 +288,10 @@ void swb_pre_proc( int32_t inner_Fs, input_Fs; float old_input[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME48k]; float spchTmp[640]; +#ifdef FIX_I102_SWB_TBE_SWITCH + float spchTmp2[640]; + int16_t L_resamp; +#endif int16_t i, j; int16_t startB, endB; float *realBufferFlipped[CLDFB_NO_COL_MAX]; @@ -677,6 +681,7 @@ void swb_pre_proc( } else { +#ifndef FIX_I102_SWB_TBE_SWITCH if ( st->bwidth == FB || st->core == ACELP_CORE || ( st->element_mode == IVAS_CPE_DFT && input_Fs == 48000 ) ) { set_f( hBWE_TD->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k ); @@ -697,39 +702,77 @@ void swb_pre_proc( } else { - /* flip the spectrm */ +#else + if ( st->L_frame == L_FRAME ) + { + L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz band target -> 560 samples in 28 kHz sample rate */ + } + else + { + L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz band target -> 620 samples in 31 kHz sample rate */ + } + + /* Dirty downsampling to match Nyquist to upper frequency limit of target */ + lerp( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) ); + + /* flip the spectrum */ + mvr2r( new_swb_speech, spchTmp, L_resamp ); + for ( i = 0; i < L_resamp; i = i + 2 ) + { + spchTmp[i] = -spchTmp[i]; + } + + /* Dirty upsampling to match Nyquist to lower frequency limit of target (reversed spectrum)*/ + lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); + mvr2r( spchTmp2, spchTmp, L_FRAME32k ); +#endif +#ifndef FIX_I102_SWB_TBE_SWITCH + /* flip the spectrm */ mvr2r( new_swb_speech, spchTmp, L_FRAME32k ); for ( i = 0; i < L_FRAME32k; i = i + 2 ) { spchTmp[i] = -spchTmp[i]; } +#endif + Decimate_allpass_steep( spchTmp, hBWE_TD->state_ana_filt_shb, L_FRAME32k, shb_speech ); - Decimate_allpass_steep( spchTmp, hBWE_TD->state_ana_filt_shb, L_FRAME32k, shb_speech ); - mvr2r( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); + mvr2r( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); - /*Compute the past overlap for potential next iDFTs SHB*/ - if ( st->element_mode == IVAS_CPE_DFT ) + /*Compute the past overlap for potential next iDFTs SHB*/ + if ( st->element_mode == IVAS_CPE_DFT ) + { + for ( i = 0; i < STEREO_DFT_OVL_16k; i++ ) { - for ( i = 0; i < STEREO_DFT_OVL_16k; i++ ) - { - hCPE->hStereoDft->output_mem_dmx_16k_shb[i] = shb_speech[20 + i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i]; - } + hCPE->hStereoDft->output_mem_dmx_16k_shb[i] = shb_speech[20 + i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i]; } } +#ifndef FIX_I102_SWB_TBE_SWITCH + } +#endif - if ( st->element_mode != IVAS_CPE_DFT ) - { - /* Reset CLDFB synthesis buffer */ - set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length ); - } + if ( st->element_mode != IVAS_CPE_DFT ) + { + /* Reset CLDFB synthesis buffer */ + set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length ); + } +#ifdef FIX_I102_SWB_TBE_SWITCH + else + { + hCPE->hStereoDft->flip_sign = -hCPE->hStereoDft->flip_sign; /* Make sure sign is updated even if DFT SHB target is not generated */ } +#endif +} /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed; only when n = 1 start, it will be 9.6875/2.3125 in that case this reset is needed for IO->BWE.*/ +#ifdef FIX_I102_SWB_TBE_SWITCH + if ( st->last_extl == -1 && st->element_mode == EVS_MONO ) +#else /* IVAS_fmToDo: revisit for IVAS (the condition is currently entered for both TD and DFT stereo - is it desirable?) */ if ( st->last_extl == -1 ) +#endif { delay = NS2SA( input_Fs, DELAY_FIR_RESAMPL_NS ); for ( i = 0; i < delay; i++ ) -- GitLab From 999e2b00045a426d0747ad438daaf639a6bf8029 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 14 Sep 2022 16:39:37 +0200 Subject: [PATCH 2/6] Enable FIX_I102_SWB_TBE_SWITCH --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 263d5efc8e..eb92020943 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,7 +149,7 @@ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ -//#define FIX_I102_SWB_TBE_SWITCH /* Issue 102: avoid IO->SWB switching code for IVAS, generate SHB ACB mem with lerp in case of switch */ +#define FIX_I102_SWB_TBE_SWITCH /* Issue 102: avoid IO->SWB switching code for IVAS, generate SHB ACB mem with lerp in case of switch */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ -- GitLab From 7e124cb4e55d614ed3891f95c58ba65755c4f3fb Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 20 Sep 2022 14:05:37 +0200 Subject: [PATCH 3/6] Fix for EVS mono BE --- lib_com/options.h | 1 - lib_enc/swb_pre_proc.c | 103 +++++++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 46 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7e5be74f65..12464ed19e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -148,7 +148,6 @@ #define SPAR_SCALING_HARMONIZATION /* Issue 80: Changes to harmonize scaling in spar */ #define SBA_INTERN_CONFIG_FIX_HOA2 /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/ -#define FIX_I102_SWB_TBE_SWITCH /* Issue 102: avoid IO->SWB switching code for IVAS, generate SHB ACB mem with lerp in case of switch */ #define FIX_I98_HANDLES_TO_NULL /* Issue 98: do the setting of all handles to NULL in one place */ #define FIX_I102_SWB_TBE_SWITCH /* Issue 102: avoid IO->SWB switching code for IVAS, generate SHB ACB mem with lerp in case of switch */ diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index e4779d0920..3f2a47d2a5 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -681,8 +681,11 @@ void swb_pre_proc( } else { -#ifndef FIX_I102_SWB_TBE_SWITCH +#ifdef FIX_I102_SWB_TBE_SWITCH + if ( ( st->bwidth == FB || st->core == ACELP_CORE ) && ( st->element_mode == EVS_MONO ) ) +#else if ( st->bwidth == FB || st->core == ACELP_CORE || ( st->element_mode == IVAS_CPE_DFT && input_Fs == 48000 ) ) +#endif { set_f( hBWE_TD->old_speech_shb, 0, L_LOOK_16k + L_SUBFR16k ); set_f( shb_speech, 0, L_FRAME16k ); /* shb_speech for FB/SWB BWE_HIGHRATE is not used at 64kbps */ @@ -702,32 +705,44 @@ void swb_pre_proc( } else { -#else - if ( st->L_frame == L_FRAME ) - { - L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz band target -> 560 samples in 28 kHz sample rate */ - } - else - { - L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz band target -> 620 samples in 31 kHz sample rate */ - } +#ifdef FIX_I102_SWB_TBE_SWITCH + if ( st->element_mode == IVAS_CPE_DFT ) + { + if ( st->L_frame == L_FRAME ) + { + L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz band target -> 560 samples in 28 kHz sample rate */ + } + else + { + L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz band target -> 620 samples in 31 kHz sample rate */ + } - /* Dirty downsampling to match Nyquist to upper frequency limit of target */ - lerp( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) ); + /* Dirty downsampling to match Nyquist to upper frequency limit of target */ + lerp( st->input, new_swb_speech, L_resamp, (int16_t) ( input_Fs / 50 ) ); - /* flip the spectrum */ - mvr2r( new_swb_speech, spchTmp, L_resamp ); - for ( i = 0; i < L_resamp; i = i + 2 ) - { - spchTmp[i] = -spchTmp[i]; - } - - /* Dirty upsampling to match Nyquist to lower frequency limit of target (reversed spectrum)*/ - lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); - mvr2r( spchTmp2, spchTmp, L_FRAME32k ); -#endif -#ifndef FIX_I102_SWB_TBE_SWITCH - /* flip the spectrm */ + /* flip the spectrum */ + mvr2r( new_swb_speech, spchTmp, L_resamp ); + for ( i = 0; i < L_resamp; i = i + 2 ) + { + spchTmp[i] = -spchTmp[i]; + } + + /* Dirty upsampling to match Nyquist to lower frequency limit of target (reversed spectrum)*/ + lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); + mvr2r( spchTmp2, spchTmp, L_FRAME32k ); + } + else + { + /* flip the spectrum */ + mvr2r( new_swb_speech, spchTmp, L_FRAME32k ); + + for ( i = 0; i < L_FRAME32k; i = i + 2 ) + { + spchTmp[i] = -spchTmp[i]; + } + } +#else + /* flip the spectrm */ mvr2r( new_swb_speech, spchTmp, L_FRAME32k ); for ( i = 0; i < L_FRAME32k; i = i + 2 ) @@ -735,34 +750,32 @@ void swb_pre_proc( spchTmp[i] = -spchTmp[i]; } #endif - Decimate_allpass_steep( spchTmp, hBWE_TD->state_ana_filt_shb, L_FRAME32k, shb_speech ); + Decimate_allpass_steep( spchTmp, hBWE_TD->state_ana_filt_shb, L_FRAME32k, shb_speech ); - mvr2r( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); + mvr2r( shb_speech + L_FRAME16k - ( L_LOOK_16k + L_SUBFR16k ), hBWE_TD->old_speech_shb, L_LOOK_16k + L_SUBFR16k ); - /*Compute the past overlap for potential next iDFTs SHB*/ - if ( st->element_mode == IVAS_CPE_DFT ) - { - for ( i = 0; i < STEREO_DFT_OVL_16k; i++ ) + /*Compute the past overlap for potential next iDFTs SHB*/ + if ( st->element_mode == IVAS_CPE_DFT ) { - hCPE->hStereoDft->output_mem_dmx_16k_shb[i] = shb_speech[20 + i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i]; + for ( i = 0; i < STEREO_DFT_OVL_16k; i++ ) + { + hCPE->hStereoDft->output_mem_dmx_16k_shb[i] = shb_speech[20 + i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i] * hCPE->hStereoDft->win_ana_16k[STEREO_DFT_OVL_16k - 1 - i]; + } } } -#ifndef FIX_I102_SWB_TBE_SWITCH - } -#endif - if ( st->element_mode != IVAS_CPE_DFT ) - { - /* Reset CLDFB synthesis buffer */ - set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length ); - } + if ( st->element_mode != IVAS_CPE_DFT ) + { + /* Reset CLDFB synthesis buffer */ + set_f( st->cldfbSynTd->cldfb_state, 0.0f, st->cldfbSynTd->p_filter_length ); + } #ifdef FIX_I102_SWB_TBE_SWITCH - else - { - hCPE->hStereoDft->flip_sign = -hCPE->hStereoDft->flip_sign; /* Make sure sign is updated even if DFT SHB target is not generated */ - } + else + { + hCPE->hStereoDft->flip_sign = -hCPE->hStereoDft->flip_sign; /* Make sure sign is updated even if DFT SHB target is not generated */ + } #endif -} + } /* Memory reset to compensate for 0.9375 ms offset when transitioning from IO to SWB */ /* When switching from n >1 to n = 1, we keep the enc/dec delay as 8.75/3.25 and below code not needed; -- GitLab From e0c0125bb1c88b596dc844adabd34e58d1446392 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 27 Sep 2022 14:28:45 +0200 Subject: [PATCH 4/6] Minor cleanup: remove unreachable code --- lib_enc/swb_pre_proc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 3f2a47d2a5..5774395b00 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -697,11 +697,12 @@ void swb_pre_proc( st->hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; st->hBWE_TD->prev_mix_factor = 1.0f; st->hBWE_TD->prev_Env_error = 0.0f; - +#ifndef FIX_I102_SWB_TBE_SWITCH if ( st->element_mode == IVAS_CPE_DFT ) { set_f( hCPE->hStereoDft->output_mem_dmx_16k_shb, 0, STEREO_DFT_OVL_16k ); } +#endif } else { -- GitLab From d7a35bdfb53cbf594810bd00c5dc79d774b5fc9a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 27 Sep 2022 14:52:02 +0200 Subject: [PATCH 5/6] Editorial: corrected comment --- lib_enc/swb_pre_proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 5774395b00..04589e664f 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -728,7 +728,7 @@ void swb_pre_proc( spchTmp[i] = -spchTmp[i]; } - /* Dirty upsampling to match Nyquist to lower frequency limit of target (reversed spectrum)*/ + /* Dirty upsampling to match Nyquist/2 to lower frequency limit of target (reversed spectrum)*/ lerp( spchTmp, spchTmp2, L_FRAME32k, L_resamp ); mvr2r( spchTmp2, spchTmp, L_FRAME32k ); } -- GitLab From bb5ad452ac6079dab70a0f0f234d5af0928e9a8f Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 4 Oct 2022 09:01:27 +0200 Subject: [PATCH 6/6] Updated comment regarding SHB target --- lib_enc/swb_pre_proc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 04589e664f..52d3099c41 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -711,11 +711,11 @@ void swb_pre_proc( { if ( st->L_frame == L_FRAME ) { - L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz band target -> 560 samples in 28 kHz sample rate */ + L_resamp = 560; /* 6.4 kHz core -> 6 - 14 kHz SHB target. 20 ms is 560 samples in 28 kHz sample rate */ } else { - L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz band target -> 620 samples in 31 kHz sample rate */ + L_resamp = 620; /* 8 kHz core -> 7.5 - 15.5 kHz SHB target. 20 ms is 620 samples in 31 kHz sample rate */ } /* Dirty downsampling to match Nyquist to upper frequency limit of target */ -- GitLab