From 836824fdda922f165ad6ca47051bc9347298c6bc Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 24 Mar 2025 10:45:20 +0100 Subject: [PATCH 01/12] Added FIX_732, still work in progress --- lib_com/options.h | 1 + lib_dec/fd_cng_dec_fx.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 76bfee2ae..988f46280 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -66,6 +66,7 @@ #ifndef BASOP_NOGLOB_DEV_USE_GLOBALS #define BASOP_NOGLOB_DECLARE_LOCAL #endif +#define FIX_732 /* Eri: Fix for precision issue in CNG generation -- still work in progress */ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ //#define OPT_STEREO_32KBPS_V1 /* Optimization made in stereo decoding path for 32kbps decoding */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index c1289b8a3..574b63ab2 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1625,8 +1625,11 @@ Word16 ApplyFdCng_ivas_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } - +#ifdef FIX_732 + s2 = ( sub( WORD32_BITS, 1 ) ); +#else s2 = -( ( WORD32_BITS - 1 ) ); +#endif move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1666,7 +1669,11 @@ Word16 ApplyFdCng_ivas_fx( facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } +#ifdef FIX_732 + s2 = s_min( s2, facTabExp[k] ); +#else s2 = s_max( s2, facTabExp[k] ); +#endif } if ( EQ_16( s2, -31 ) ) { @@ -1679,7 +1686,11 @@ Word16 ApplyFdCng_ivas_fx( s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { +#ifdef FIX_732 + cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#endif move32(); } } @@ -1701,7 +1712,11 @@ Word16 ApplyFdCng_ivas_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { +#ifdef FIX_732 + s2 = ( sub( WORD32_BITS, 1 ) ); +#else s2 = -( ( WORD32_BITS - 1 ) ); +#endif /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1740,7 +1755,11 @@ Word16 ApplyFdCng_ivas_fx( facTabExp[k] = -( WORD32_BITS - 1 ); move16(); } +#ifdef FIX_732 + s2 = s_min( s2, facTabExp[k] ); +#else s2 = s_max( s2, facTabExp[k] ); +#endif } IF( EQ_16( s2, -31 ) ) { @@ -1753,7 +1772,11 @@ Word16 ApplyFdCng_ivas_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { +#ifdef FIX_732 + cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#endif move32(); } } -- GitLab From ca88578e2454e6d793b55193dcb6e85f40a41f50 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:26:43 +0200 Subject: [PATCH 02/12] Change FIX_732 to only address noise floor in msPeriodog calculation --- lib_dec/fd_cng_dec_fx.c | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index a9965d601..ef4659552 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1117,11 +1117,7 @@ Word16 ApplyFdCng_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } -#ifdef FIX_732 - s2 = ( sub( WORD32_BITS, 1 ) ); -#else s2 = -( ( WORD32_BITS - 1 ) ); -#endif move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1161,11 +1157,7 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } -#ifdef FIX_732 - s2 = s_min( s2, facTabExp[k] ); -#else s2 = s_max( s2, facTabExp[k] ); -#endif } if ( EQ_16( s2, -31 ) ) { @@ -1178,11 +1170,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { -#ifdef FIX_732 - cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#endif move32(); } } @@ -1220,11 +1208,7 @@ Word16 ApplyFdCng_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { -#ifdef FIX_732 - s2 = ( sub( WORD32_BITS, 1 ) ); -#else s2 = -( ( WORD32_BITS - 1 ) ); -#endif /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1263,11 +1247,7 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( WORD32_BITS - 1 ); move16(); } -#ifdef FIX_732 - s2 = s_min( s2, facTabExp[k] ); -#else s2 = s_max( s2, facTabExp[k] ); -#endif } IF( EQ_16( s2, -31 ) ) { @@ -1280,11 +1260,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { -#ifdef FIX_732 - cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#endif move32(); } } @@ -1320,6 +1296,14 @@ Word16 ApplyFdCng_fx( } + dbgwrite( hFdCngDec->bandNoiseShape, sizeof( Word32 ), 320, 1, "bandNoiseShape.int" ); + dbgwrite( &hFdCngDec->bandNoiseShape_exp, sizeof( short ), 1, 1, "bandNoiseShape_exp.short" ); + + dbgwrite( cngNoiseLevel, sizeof( Word32 ), 340, 1, "cngNoiseLevel.int" ); + dbgwrite( cngNoiseLevel_exp, sizeof( short ), 1, 1, "cngNoiseLevel_exp.short" ); + dbgwrite( &frame, sizeof( int ), 1, 1, "frame.int" ); + + return 0; } @@ -1523,6 +1507,9 @@ void perform_noise_estimation_dec_ivas_fx( Word32 enr, enr_tot, enr_tot0; Word16 enr_e, enr_ratio, alpha; Word32 *msPeriodog; +#ifdef FIX_732 + Word32 msPeriodog_floor; +#endif Word32 *msNoiseEst; Word32 *reIter; Word32 rescale_fac = 0; @@ -1728,10 +1715,18 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); - +#ifdef FIX_732 + msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); + IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) +#else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) +#endif { +#ifdef FIX_732 + msPeriodog[p] = msPeriodog_floor; +#else msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ +#endif move32(); } } @@ -2105,6 +2100,13 @@ void perform_noise_estimation_dec_ivas_fx( /* Expand partitions into bins of power spectrum */ scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; + + dbgwrite( msNoiseEst, sizeof( int ), 62, 1, "msNoiseEst.int" ); + dbgwrite( &hFdCngDec->msNoiseEst_exp, sizeof( short ), 1, 1, "msNoiseEst_exp.short" ); + dbgwrite( msPeriodog, sizeof( int ), 62, 1, "msPeriodog.int" ); + dbgwrite( &hFdCngDec->msPeriodog_exp, sizeof( short ), 1, 1, "msPeriodog_exp.short" ); + + move16(); Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; @@ -4739,9 +4741,9 @@ void generate_masking_noise_ivas_fx( { #ifdef VEC_ARITH_OPT_v1 v_add_fixed_no_hdrm( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ -#else /* VEC_ARITH_OPT_v1 */ +#else /* VEC_ARITH_OPT_v1 */ v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ -#endif /* VEC_ARITH_OPT_v1 */ +#endif /* VEC_ARITH_OPT_v1 */ } return; -- GitLab From edbb3c704becbfa533e95a3995e342d323b01f55 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:34:38 +0200 Subject: [PATCH 03/12] Rename switch to FIX_732_MS_PERIODOG_FLOOR --- lib_com/options.h | 2 +- lib_dec/fd_cng_dec_fx.c | 26 ++++++-------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index db3dc4a20..5a25cca53 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -67,7 +67,7 @@ #ifndef BASOP_NOGLOB_DEV_USE_GLOBALS #define BASOP_NOGLOB_DECLARE_LOCAL #endif -#define FIX_732 /* Eri: Fix for precision issue in CNG generation -- still work in progress */ +#define FIX_732_MS_PERIODOG_FLOOR /* Eri: Issue-732: Dynamic range of msPeriodog leads to minimum value 1e-5 being truncated to zero. This uses the smallest non-zero value instead. */ #define FIX_867_CLDFB_NRG_SCALE diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index d9ffedf72..30164c404 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1117,6 +1117,7 @@ Word16 ApplyFdCng_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } + s2 = -( ( WORD32_BITS - 1 ) ); move16(); /* Shape the SID noise levels in each FFT bin */ @@ -1296,14 +1297,6 @@ Word16 ApplyFdCng_fx( } - dbgwrite( hFdCngDec->bandNoiseShape, sizeof( Word32 ), 320, 1, "bandNoiseShape.int" ); - dbgwrite( &hFdCngDec->bandNoiseShape_exp, sizeof( short ), 1, 1, "bandNoiseShape_exp.short" ); - - dbgwrite( cngNoiseLevel, sizeof( Word32 ), 340, 1, "cngNoiseLevel.int" ); - dbgwrite( cngNoiseLevel_exp, sizeof( short ), 1, 1, "cngNoiseLevel_exp.short" ); - dbgwrite( &frame, sizeof( int ), 1, 1, "frame.int" ); - - return 0; } @@ -1507,7 +1500,7 @@ void perform_noise_estimation_dec_ivas_fx( Word32 enr, enr_tot, enr_tot0; Word16 enr_e, enr_ratio, alpha; Word32 *msPeriodog; -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR Word32 msPeriodog_floor; #endif Word32 *msNoiseEst; @@ -1715,14 +1708,14 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) #else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) #endif { -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog[p] = msPeriodog_floor; #else msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ @@ -2100,13 +2093,6 @@ void perform_noise_estimation_dec_ivas_fx( /* Expand partitions into bins of power spectrum */ scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - - dbgwrite( msNoiseEst, sizeof( int ), 62, 1, "msNoiseEst.int" ); - dbgwrite( &hFdCngDec->msNoiseEst_exp, sizeof( short ), 1, 1, "msNoiseEst_exp.short" ); - dbgwrite( msPeriodog, sizeof( int ), 62, 1, "msPeriodog.int" ); - dbgwrite( &hFdCngDec->msPeriodog_exp, sizeof( short ), 1, 1, "msPeriodog_exp.short" ); - - move16(); Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; @@ -4752,9 +4738,9 @@ void generate_masking_noise_ivas_fx( { #ifdef VEC_ARITH_OPT_v1 v_add_fixed_no_hdrm( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ -#else /* VEC_ARITH_OPT_v1 */ +#else /* VEC_ARITH_OPT_v1 */ v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ -#endif /* VEC_ARITH_OPT_v1 */ +#endif /* VEC_ARITH_OPT_v1 */ } return; -- GitLab From eb884a3884a78139685c0a34fc966397775f04ee Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:50:04 +0200 Subject: [PATCH 04/12] Clang format --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 30164c404..de5aa20bb 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1718,7 +1718,7 @@ void perform_noise_estimation_dec_ivas_fx( #ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog[p] = msPeriodog_floor; #else - msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ #endif move32(); } -- GitLab From 9ee4902bc29e6b5785e5d222aca54663b880afd8 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:51:47 +0200 Subject: [PATCH 05/12] Add missing comment --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index de5aa20bb..4855ab00e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1709,7 +1709,7 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); #ifdef FIX_732_MS_PERIODOG_FLOOR - msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); + msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) #else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) -- GitLab From 9460d05ac40a28d5439df34f66024da665fb93d4 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 24 Mar 2025 10:45:20 +0100 Subject: [PATCH 06/12] Added FIX_732, still work in progress --- lib_com/options.h | 1 + lib_dec/fd_cng_dec_fx.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8bbd89e87..eb296b843 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -67,6 +67,7 @@ #ifndef BASOP_NOGLOB_DEV_USE_GLOBALS #define BASOP_NOGLOB_DECLARE_LOCAL #endif +#define FIX_732 /* Eri: Fix for precision issue in CNG generation -- still work in progress */ #define FIX_867_CLDFB_NRG_SCALE diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 1d8185601..017c656e9 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1117,8 +1117,11 @@ Word16 ApplyFdCng_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } - +#ifdef FIX_732 + s2 = ( sub( WORD32_BITS, 1 ) ); +#else s2 = -( ( WORD32_BITS - 1 ) ); +#endif move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1158,7 +1161,11 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } +#ifdef FIX_732 + s2 = s_min( s2, facTabExp[k] ); +#else s2 = s_max( s2, facTabExp[k] ); +#endif } if ( EQ_16( s2, -31 ) ) { @@ -1171,7 +1178,11 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { +#ifdef FIX_732 + cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#endif move32(); } } @@ -1209,7 +1220,11 @@ Word16 ApplyFdCng_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { +#ifdef FIX_732 + s2 = ( sub( WORD32_BITS, 1 ) ); +#else s2 = -( ( WORD32_BITS - 1 ) ); +#endif /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1248,7 +1263,11 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( WORD32_BITS - 1 ); move16(); } +#ifdef FIX_732 + s2 = s_min( s2, facTabExp[k] ); +#else s2 = s_max( s2, facTabExp[k] ); +#endif } IF( EQ_16( s2, -31 ) ) { @@ -1261,7 +1280,11 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { +#ifdef FIX_732 + cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ +#endif move32(); } } -- GitLab From 3b9fb3d1f7e4ea75dbbc2592eee7de246b34ad07 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:26:43 +0200 Subject: [PATCH 07/12] Change FIX_732 to only address noise floor in msPeriodog calculation --- lib_dec/fd_cng_dec_fx.c | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 017c656e9..d9ffedf72 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1117,11 +1117,7 @@ Word16 ApplyFdCng_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } -#ifdef FIX_732 - s2 = ( sub( WORD32_BITS, 1 ) ); -#else s2 = -( ( WORD32_BITS - 1 ) ); -#endif move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; @@ -1161,11 +1157,7 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( ( WORD32_BITS - 1 ) ); move16(); } -#ifdef FIX_732 - s2 = s_min( s2, facTabExp[k] ); -#else s2 = s_max( s2, facTabExp[k] ); -#endif } if ( EQ_16( s2, -31 ) ) { @@ -1178,11 +1170,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, ( WORD32_BITS - 1 ) ), -( ( WORD32_BITS - 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { -#ifdef FIX_732 - cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#endif move32(); } } @@ -1220,11 +1208,7 @@ Word16 ApplyFdCng_fx( { IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { -#ifdef FIX_732 - s2 = ( sub( WORD32_BITS, 1 ) ); -#else s2 = -( ( WORD32_BITS - 1 ) ); -#endif /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -1263,11 +1247,7 @@ Word16 ApplyFdCng_fx( facTabExp[k] = -( WORD32_BITS - 1 ); move16(); } -#ifdef FIX_732 - s2 = s_min( s2, facTabExp[k] ); -#else s2 = s_max( s2, facTabExp[k] ); -#endif } IF( EQ_16( s2, -31 ) ) { @@ -1280,11 +1260,7 @@ Word16 ApplyFdCng_fx( s = s_max( s_min( s, sub( WORD32_BITS, 1 ) ), negate( sub( WORD32_BITS, 1 ) ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { -#ifdef FIX_732 - cngNoiseLevel[j] = L_shl_sat( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#else cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#endif move32(); } } @@ -1320,6 +1296,14 @@ Word16 ApplyFdCng_fx( } + dbgwrite( hFdCngDec->bandNoiseShape, sizeof( Word32 ), 320, 1, "bandNoiseShape.int" ); + dbgwrite( &hFdCngDec->bandNoiseShape_exp, sizeof( short ), 1, 1, "bandNoiseShape_exp.short" ); + + dbgwrite( cngNoiseLevel, sizeof( Word32 ), 340, 1, "cngNoiseLevel.int" ); + dbgwrite( cngNoiseLevel_exp, sizeof( short ), 1, 1, "cngNoiseLevel_exp.short" ); + dbgwrite( &frame, sizeof( int ), 1, 1, "frame.int" ); + + return 0; } @@ -1523,6 +1507,9 @@ void perform_noise_estimation_dec_ivas_fx( Word32 enr, enr_tot, enr_tot0; Word16 enr_e, enr_ratio, alpha; Word32 *msPeriodog; +#ifdef FIX_732 + Word32 msPeriodog_floor; +#endif Word32 *msNoiseEst; Word32 *reIter; Word32 rescale_fac = 0; @@ -1728,10 +1715,18 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); - +#ifdef FIX_732 + msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); + IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) +#else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) +#endif { +#ifdef FIX_732 + msPeriodog[p] = msPeriodog_floor; +#else msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ +#endif move32(); } } @@ -2105,6 +2100,13 @@ void perform_noise_estimation_dec_ivas_fx( /* Expand partitions into bins of power spectrum */ scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; + + dbgwrite( msNoiseEst, sizeof( int ), 62, 1, "msNoiseEst.int" ); + dbgwrite( &hFdCngDec->msNoiseEst_exp, sizeof( short ), 1, 1, "msNoiseEst_exp.short" ); + dbgwrite( msPeriodog, sizeof( int ), 62, 1, "msPeriodog.int" ); + dbgwrite( &hFdCngDec->msPeriodog_exp, sizeof( short ), 1, 1, "msPeriodog_exp.short" ); + + move16(); Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; @@ -4750,9 +4752,9 @@ void generate_masking_noise_ivas_fx( { #ifdef VEC_ARITH_OPT_v1 v_add_fixed_no_hdrm( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ -#else /* VEC_ARITH_OPT_v1 */ +#else /* VEC_ARITH_OPT_v1 */ v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ -#endif /* VEC_ARITH_OPT_v1 */ +#endif /* VEC_ARITH_OPT_v1 */ } return; -- GitLab From 1b3a8fac486292448ee69a85582e65327dec648f Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:34:38 +0200 Subject: [PATCH 08/12] Rename switch to FIX_732_MS_PERIODOG_FLOOR --- lib_com/options.h | 2 +- lib_dec/fd_cng_dec_fx.c | 26 ++++++-------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index eb296b843..30044d7b7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -67,7 +67,7 @@ #ifndef BASOP_NOGLOB_DEV_USE_GLOBALS #define BASOP_NOGLOB_DECLARE_LOCAL #endif -#define FIX_732 /* Eri: Fix for precision issue in CNG generation -- still work in progress */ +#define FIX_732_MS_PERIODOG_FLOOR /* Eri: Issue-732: Dynamic range of msPeriodog leads to minimum value 1e-5 being truncated to zero. This uses the smallest non-zero value instead. */ #define FIX_867_CLDFB_NRG_SCALE diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index d9ffedf72..30164c404 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1117,6 +1117,7 @@ Word16 ApplyFdCng_fx( *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } + s2 = -( ( WORD32_BITS - 1 ) ); move16(); /* Shape the SID noise levels in each FFT bin */ @@ -1296,14 +1297,6 @@ Word16 ApplyFdCng_fx( } - dbgwrite( hFdCngDec->bandNoiseShape, sizeof( Word32 ), 320, 1, "bandNoiseShape.int" ); - dbgwrite( &hFdCngDec->bandNoiseShape_exp, sizeof( short ), 1, 1, "bandNoiseShape_exp.short" ); - - dbgwrite( cngNoiseLevel, sizeof( Word32 ), 340, 1, "cngNoiseLevel.int" ); - dbgwrite( cngNoiseLevel_exp, sizeof( short ), 1, 1, "cngNoiseLevel_exp.short" ); - dbgwrite( &frame, sizeof( int ), 1, 1, "frame.int" ); - - return 0; } @@ -1507,7 +1500,7 @@ void perform_noise_estimation_dec_ivas_fx( Word32 enr, enr_tot, enr_tot0; Word16 enr_e, enr_ratio, alpha; Word32 *msPeriodog; -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR Word32 msPeriodog_floor; #endif Word32 *msNoiseEst; @@ -1715,14 +1708,14 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) #else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) #endif { -#ifdef FIX_732 +#ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog[p] = msPeriodog_floor; #else msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ @@ -2100,13 +2093,6 @@ void perform_noise_estimation_dec_ivas_fx( /* Expand partitions into bins of power spectrum */ scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - - dbgwrite( msNoiseEst, sizeof( int ), 62, 1, "msNoiseEst.int" ); - dbgwrite( &hFdCngDec->msNoiseEst_exp, sizeof( short ), 1, 1, "msNoiseEst_exp.short" ); - dbgwrite( msPeriodog, sizeof( int ), 62, 1, "msPeriodog.int" ); - dbgwrite( &hFdCngDec->msPeriodog_exp, sizeof( short ), 1, 1, "msPeriodog_exp.short" ); - - move16(); Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ hFdCngDec->smoothed_psd_exp = hFdCngDec->bandNoiseShape_exp; @@ -4752,9 +4738,9 @@ void generate_masking_noise_ivas_fx( { #ifdef VEC_ARITH_OPT_v1 v_add_fixed_no_hdrm( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); /*Q31 - *exp_out*/ -#else /* VEC_ARITH_OPT_v1 */ +#else /* VEC_ARITH_OPT_v1 */ v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); /*Q31 - *exp_out*/ -#endif /* VEC_ARITH_OPT_v1 */ +#endif /* VEC_ARITH_OPT_v1 */ } return; -- GitLab From de4a8862055cb6d1c693348bd83b6c54347b51f4 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:50:04 +0200 Subject: [PATCH 09/12] Clang format --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 30164c404..de5aa20bb 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1718,7 +1718,7 @@ void perform_noise_estimation_dec_ivas_fx( #ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog[p] = msPeriodog_floor; #else - msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ #endif move32(); } -- GitLab From fe9bb29260994a1d31ffeadd2d97c06b7b8b150d Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 2 Jun 2025 13:51:47 +0200 Subject: [PATCH 10/12] Add missing comment --- lib_dec/fd_cng_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index de5aa20bb..4855ab00e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1709,7 +1709,7 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); #ifdef FIX_732_MS_PERIODOG_FLOOR - msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); + msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) #else IF( LT_32( msPeriodog[p], L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ) ) -- GitLab From 33610b0cd69859e3d83aa905dcb746b67d5944ba Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 16 Jun 2025 14:01:41 +0530 Subject: [PATCH 11/12] Fix for crash --- lib_dec/fd_cng_dec_fx.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 4855ab00e..d7ca74edb 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1500,18 +1500,20 @@ void perform_noise_estimation_dec_ivas_fx( Word32 enr, enr_tot, enr_tot0; Word16 enr_e, enr_ratio, alpha; Word32 *msPeriodog; + Word32 *msNoiseEst; #ifdef FIX_732_MS_PERIODOG_FLOOR Word32 msPeriodog_floor; #endif - Word32 *msNoiseEst; Word32 *reIter; Word32 rescale_fac = 0; Word64 W_tmp; Word16 tmp_s, tmp_q, min_q = 31; Word16 q_shift; Word32 max_l; - Word16 norm_shift; - +#ifdef FIX_732_MS_PERIODOG_FLOOR + Word16 norm_shift, check = 0; + move16(); +#endif /* pointer initialization */ periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ @@ -1708,6 +1710,7 @@ void perform_noise_estimation_dec_ivas_fx( msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); + #ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog_floor = L_max( 1, L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ) ); /*Q31 - hFdCngDec->msPeriodog_exp*/ IF( LT_32( msPeriodog[p], msPeriodog_floor ) ) @@ -1717,12 +1720,29 @@ void perform_noise_estimation_dec_ivas_fx( { #ifdef FIX_732_MS_PERIODOG_FLOOR msPeriodog[p] = msPeriodog_floor; + move32(); #else - msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ -#endif + msPeriodog[p] = L_shr( 21474 /*Q31*/, hFdCngDec->msPeriodog_exp ); /*Q31 - hFdCngDec->msPeriodog_exp*/ move32(); +#endif + } + } +#ifdef FIX_732_MS_PERIODOG_FLOOR + FOR( p = 0; p < npart; p++ ) + { + IF( GT_32( msPeriodog[p], 1 ) ) + { + check = 1; + move16(); + BREAK; } } + IF( check == 0 ) + { + hFdCngDec->msPeriodog_exp = 14; /* msPeriodog buffer will have minimum value as 1e-5f */ + move16(); + } +#endif } /* calculate total energy (short-term and long-term) */ -- GitLab From ae57ace8debbfb3d25e1c45045a2fa79037285a2 Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 17 Jun 2025 11:05:24 +0200 Subject: [PATCH 12/12] cleanup --- lib_dec/fd_cng_dec_fx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 1b30cb2e5..adf838f42 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1504,19 +1504,18 @@ void perform_noise_estimation_dec_ivas_fx( Word32 msPeriodog_floor; #endif Word32 *msNoiseEst; -#ifdef FIX_732_MS_PERIODOG_FLOOR - Word32 msPeriodog_floor; -#endif Word32 *reIter; Word32 rescale_fac = 0; Word64 W_tmp; Word16 tmp_s, tmp_q, min_q = 31; Word16 q_shift; Word32 max_l; + Word16 norm_shift; #ifdef FIX_732_MS_PERIODOG_FLOOR - Word16 norm_shift, check = 0; + Word16 check = 0; move16(); #endif + /* pointer initialization */ periodog = hFdCngDec->hFdCngCom->periodog; /*Q31 - hFdCngDec->hFdCngCom->periodog_exp*/ fftBuffer = hFdCngDec->hFdCngCom->fftBuffer; /*Q31 - hFdCngDec->hFdCngCom->fftBuffer_exp*/ -- GitLab