From 849129d3e21a2ec5533846a1259b70ea617f1d0f Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 8 Jun 2026 15:02:27 +0200 Subject: [PATCH 1/4] Initialize q_lp_noise=23 so (lp_speech-lp_noise) Q23 diff is shifted to Q0 before <28 compare --- lib_com/options.h | 1 + lib_dec/ivas_stereo_cng_dec_fx.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index aebd87cb0..40b0dfd4a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,6 +99,7 @@ #define FIX_1576_LCLD_CRASH_DIFFERENT_CODEC_ISAR_FRAME_SIZE /* Dolby: float issue 1576: fix for crash in LCLD mode when codec frame size is less than isar frame size */ #define FIX_BASOP_2442_MASA2TC_TO_MONO_AND_AMBI /* Nokia: BASOP issue 2442: Increase accuracy of computations and add additional gain clamp for low energy decorrelated signal rendering. */ #define FIX_FMSW_DEC_EXT /* float issue 1566: fix EXT output in format switching */ +#define FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT /* FhG: BASOP #2621: stereo_dft_generate_comfort_noise_fx: initialize q_lp_noise=23 so (lp_speech-lp_noise) Q23 diff is shifted to Q0(dB) before <28 compare */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_stereo_cng_dec_fx.c b/lib_dec/ivas_stereo_cng_dec_fx.c index c7b506d4d..fd903a0fd 100644 --- a/lib_dec/ivas_stereo_cng_dec_fx.c +++ b/lib_dec/ivas_stereo_cng_dec_fx.c @@ -772,7 +772,11 @@ static void stereo_dft_generate_comfort_noise_fx( } ELSE IF( ( chan == 0 ) ) { +#ifdef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT + Word16 q_lp_noise = 23; /* lp_speech/lp_noise are Q23 */ +#else Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. +#endif move16(); Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) -- GitLab From 7f002eed30ae4ecf50310d06dbe311f8e9cd25a6 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 8 Jun 2026 15:45:11 +0200 Subject: [PATCH 2/4] Compare (lp_speech-lp_noise) with 28.0 in Q23 and remove local q_lp_noise. --- lib_com/options.h | 2 +- lib_dec/ivas_stereo_cng_dec_fx.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 40b0dfd4a..5f4f50038 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,7 +99,7 @@ #define FIX_1576_LCLD_CRASH_DIFFERENT_CODEC_ISAR_FRAME_SIZE /* Dolby: float issue 1576: fix for crash in LCLD mode when codec frame size is less than isar frame size */ #define FIX_BASOP_2442_MASA2TC_TO_MONO_AND_AMBI /* Nokia: BASOP issue 2442: Increase accuracy of computations and add additional gain clamp for low energy decorrelated signal rendering. */ #define FIX_FMSW_DEC_EXT /* float issue 1566: fix EXT output in format switching */ -#define FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT /* FhG: BASOP #2621: stereo_dft_generate_comfort_noise_fx: initialize q_lp_noise=23 so (lp_speech-lp_noise) Q23 diff is shifted to Q0(dB) before <28 compare */ +#define FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT /* FhG: BASOP #2621: stereo_dft_generate_comfort_noise_fx flag_noisy_speech: compare (lp_speech-lp_noise) Q23 diff against 28.0 in Q23 (was vs integer 28 with q_lp_noise=0) */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_stereo_cng_dec_fx.c b/lib_dec/ivas_stereo_cng_dec_fx.c index fd903a0fd..69fa7293c 100644 --- a/lib_dec/ivas_stereo_cng_dec_fx.c +++ b/lib_dec/ivas_stereo_cng_dec_fx.c @@ -772,12 +772,10 @@ static void stereo_dft_generate_comfort_noise_fx( } ELSE IF( ( chan == 0 ) ) { -#ifdef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT - Word16 q_lp_noise = 23; /* lp_speech/lp_noise are Q23 */ -#else +#ifndef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT Word16 q_lp_noise = 0; // st->hFdCngDec->q_lp_noise; // to be populated appropriately. -#endif move16(); +#endif Word32 log_lp_noise = L_add( L_shl( lp_noise_e, Q25 ), BASOP_Util_Log2( L_add( lp_noise, DELTA_FX ) ) ); /* Q25 */ // log10(x) is computed as log2(x) * log10(2) // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 @@ -787,7 +785,11 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); st->lp_noise = st->hFdCngDec->lp_noise; /* Q23 */ move32(); +#ifdef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT + st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), 234881024 /* 28.0f in Q23 */ ) ); /* Q0 */ +#else st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ +#endif move16(); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( 328 /* 0.01 in Q15 */, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q15 */ -- GitLab From 35a623c6cbc8ebe550b9501d062ab23ee665a19a Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 9 Jun 2026 08:36:11 +0200 Subject: [PATCH 3/4] also removed unused struct members q_lp_speech and q_lp_noise --- lib_dec/stat_dec.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 58056843e..885af0c03 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -137,10 +137,14 @@ typedef struct Word16 flag_dtx_mode; Word32 lp_speech; /* format: Q9.23 */ +#ifndef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT Word16 q_lp_speech; +#endif Word32 lp_noise; /* format: Q9.23 */ +#ifndef FIX_BASOP_2621_STEREO_CNG_NOISY_SPEECH_QSHIFT Word16 q_lp_noise; +#endif Word16 msPeriodogBuf[MSBUFLEN * NPART_SHAPING]; -- GitLab From 2c7e2e1831df4eca4bb55e63d540a3f6ca78b7c0 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 9 Jun 2026 08:39:22 +0200 Subject: [PATCH 4/4] fix comments --- lib_dec/fd_cng_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index dc24fc6f9..d11cceae0 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2128,7 +2128,7 @@ void noisy_speech_detection_fx( logTotalNoise = Mpy_32_16_1( L_add( logTotalNoise, logTotalNoiseExp ), 24660 /*0.75257498916 Q15*/ ); /*Q31 - logTotalNoiseExp*/ } - hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_noise*/ + hFdCngDec->lp_noise = L_add( Mpy_32_16_1( hFdCngDec->lp_noise, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logTotalNoise, 20972 /*0.64 Q15*/ ), 7 ) ); /*Q23*/ move32(); } ELSE @@ -2175,7 +2175,7 @@ void noisy_speech_detection_fx( } } - hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); /*hFdCngDec->q_lp_speech*/ + hFdCngDec->lp_speech = L_add( Mpy_32_16_1( hFdCngDec->lp_speech, 32604 /*0.995 Q15*/ ), L_shr( Mpy_32_16_1( logEtot, 20972 /*0.64 Q15*/ ), 7 ) ); /*Q23*/ move32(); } -- GitLab