From fe8df88d8f97fb733bc7e63ca9d948746fea0bd7 Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Mon, 22 Jun 2026 13:04:20 +0200 Subject: [PATCH] use double -prec sin() and cos() to fix 1-2 ULP precision issue --- lib_com/ivas_agc_com.c | 4 ++++ lib_com/ivas_fb_mixer.c | 12 ++++++++++++ lib_com/options.h | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_agc_com.c b/lib_com/ivas_agc_com.c index 12b098869..cd4441b74 100644 --- a/lib_com/ivas_agc_com.c +++ b/lib_com/ivas_agc_com.c @@ -71,7 +71,11 @@ void ivas_agc_initWindowFunc( for ( i = 0; i < length; i++ ) { +#ifdef FIX_ISSUE_1603_SINF_COSF_PRECISION_XTENSA + pWinFunc[i] = 1.f + a * ( (float) cos( (double) ( EVS_PI * i / N ) ) - 1.f ); +#else pWinFunc[i] = 1.f + a * ( cosf( EVS_PI * i / N ) - 1.f ); +#endif } return; diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 1e9fe1eb3..4dcf14993 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -1220,7 +1220,11 @@ static void ivas_get_hanning_win( for ( i = 0; i < len; i++ ) { +#ifdef FIX_ISSUE_1603_SINF_COSF_PRECISION_XTENSA + pH_win[i] = 0.5f * ( 1.0f - (float) cos( (double) ( PI2 * ( i + 1 ) ) / (double) ( ( 2 * len ) + 1 ) ) ); +#else pH_win[i] = 0.5f * ( 1.0f - cosf( ( PI2 * ( i + 1 ) ) / ( ( 2 * len ) + 1 ) ) ); +#endif } return; @@ -1320,12 +1324,20 @@ static void ivas_get_ld_fb_resp( /* apply final window*/ for ( s = 0; s < delay; s++ ) { +#ifdef FIX_ISSUE_1603_SINF_COSF_PRECISION_XTENSA + scratch1[s] = scratch1[s] * (float) sin( (double) ( EVS_PI * ( s + 1 ) ) / (double) ( 2 * delay ) ); +#else scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( s + 1 ) ) / ( 2 * delay ) ); +#endif } for ( s = 2 * delay; s < frame_len + 1; s++ ) { +#ifdef FIX_ISSUE_1603_SINF_COSF_PRECISION_XTENSA + scratch1[s] = scratch1[s] * (float) sin( (double) ( EVS_PI * ( frame_len - s ) ) / (double) ( 2 * ( frame_len + 1 - ( 2 * delay ) ) ) ); +#else scratch1[s] = scratch1[s] * sinf( ( EVS_PI * ( frame_len - s ) ) / ( 2 * ( frame_len + 1 - ( 2 * delay ) ) ) ); +#endif } for ( ; s < 2 * frame_len; s++ ) diff --git a/lib_com/options.h b/lib_com/options.h index a33f3986f..422d0a8b4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -170,7 +170,8 @@ /* any switch which is non-be wrt. TS 26.258 V3.0 */ #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_FLOAT_1600_OMASA_WRONG_RENDER_PATH /* Nokia: float issue 1600: fix initialization condition of stereo type detection for OMASA */ +#define FIX_FLOAT_1600_OMASA_WRONG_RENDER_PATH /* Nokia: float issue 1600: fix initialization condition of stereo type detection for OMASA */ +#define FIX_ISSUE_1603_SINF_COSF_PRECISION_XTENSA /* Dolby: use double-precision cos()/sin() in place of cosf()/sinf() in fb_mixer and agc_com to eliminate 1-2 ULP variance */ /* ##################### End NON-BE switches ########################### */ -- GitLab