From 4e8ce65641ebe809d95ae551a72f24f2b2852c89 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 4 Dec 2025 09:54:42 +0100 Subject: [PATCH] Add FIX_1461_CNG_BW_SWITCHING to address BW switching in Stereo CNG --- lib_com/options.h | 1 + lib_enc/ivas_cpe_enc.c | 8 ++++++++ lib_enc/ivas_stereo_dft_enc.c | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 11f9b1f26e..df11300aec 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -173,6 +173,7 @@ #define FIX_1435_MOVE_STEREO_PANNING /* VA: issue 1435: do the EVS stereo panning in the renderer */ #define FIX_1454_FIX_STEREO_TO_FOA_JBM /* VA: issue 1454: fix buggy stereo to FOA in JBM */ +#define FIX_1461_CNG_BW_SWITCHING /* Eri: issue 1461: Stereo parameters are not updated when SID/NODATA forces BW to stay the same */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index ebd5bb1281..01b13ba269 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -112,6 +112,9 @@ ivas_error ivas_cpe_enc( int32_t cpe_brate; int32_t element_brate_ref; int16_t last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ +#ifdef FIX_1461_CNG_BW_SWITCHING + int16_t NFFT_inner; +#endif error = IVAS_ERR_OK; push_wmops( "ivas_cpe_enc" ); @@ -628,6 +631,11 @@ ivas_error ivas_cpe_enc( if ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) { /* Reconfigure DFT Stereo for inactive frames */ +#ifdef FIX_1461_CNG_BW_SWITCHING + /* -- nbands may need to be updated here in case the bandwidth was changed due to inactive frames */ + NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[sts[0]->bwidth] / L_FRAME48k; + hCPE->hStereoDft->nbands = stereo_dft_band_config( hCPE->hStereoDft->band_limits, hCPE->hStereoDft->hConfig->band_res, NFFT_inner, ENC ); +#endif if ( sts[0]->core_brate == SID_2k40 ) { stereo_dft_config( hConfigDft, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 26b2ad7b4d..49f7c33d47 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -2879,6 +2879,15 @@ static void stereo_dft_enc_compute_prm( hStereoDft->nrg_past_pos = ( pos + 1 ) % STEREO_DFT_NRG_PAST_LEN; +#ifdef FIX_1461_CNG_BW_SWITCHING + /* Replicate last band for remaining bands in case the bandwidth is higher after SID/NODATA is considered */ + for ( i = hStereoDft->nbands; i < STEREO_DFT_BAND_MAX; i++ ) + { + pPredGain[i] = pPredGain[i - 1]; + pSideGain[i] = pSideGain[i - 1]; + } +#endif + #ifdef DEBUG_MODE_DFT { float tmp_f; -- GitLab