From 006a6d91c28a8d17faabc87ee984fc4c010b9f4c Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 5 Nov 2025 11:34:25 +0100 Subject: [PATCH 1/2] port MR 2318 from float Fix non-BE between optimization levels in dft stereo for Apple Clang - Alternative Version --- lib_com/options.h | 1 + lib_enc/ivas_stereo_dft_enc.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index a0932933c..7569cb250 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -196,6 +196,7 @@ #define FIX_1383_HEAD_TRACK_SANITIZER /* Nok: issue 1383: Fix head tracking struc values reading in renderer */ #define FIX_1411_IGF_CRASH_BW_SWITCHING /* FhG: Fix for issue 1411: fixes crash that can happen for IGF with BW switching and DTX*/ #define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */ +#define NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS /* FhG: fix non-BE in DFT stereo encoder between optimization levels */ // object-editing feature porting #define FIX_HRTF_LOAD_API // solves API conflicts between HRTF and object-editing features diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index f3800d0c6..b7f41f7af 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1318,12 +1318,24 @@ void stereo_dft_enc_process( if ( hStereoDft->hItd->deltaItd[k_offset] != 0 && hStereoDft->hConfig->dmx_active ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS + /* Note: this variable is used as an in-between step when passing the angle to the trig functions. + * this keeps the compilter from applying optimizations at higher optimizaton levels which can break bit-exactness */ + volatile float alpha_tmp; +#endif /*time shift channels*/ alpha = -2.0f * EVS_PI * hStereoDft->hItd->deltaItd[k_offset] / hStereoDft->NFFT; c = 1.f; /*cos(0)*/ s = 0.f; /*sin(0)*/ +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS + + alpha_tmp = alpha; + c1 = cosf( alpha_tmp ); + s1 = sinf( alpha_tmp ); +#else c1 = cosf( alpha ); s1 = sinf( alpha ); +#endif if ( alpha >= 0 ) { -- GitLab From b9ef3d7c890a79ea1f2becacecc40ea5919e6559 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 5 Nov 2025 11:38:25 +0100 Subject: [PATCH 2/2] port MR 2323 from float Apple Clang 16 release vs debug differences in stereo - second Part --- lib_com/edct.c | 24 ++++++++++++++++++++++++ lib_com/options.h | 1 + lib_dec/ivas_stereo_dft_dec.c | 16 ++++++++++++++++ lib_dec/ivas_stereo_dft_plc.c | 9 +++++++++ lib_enc/ivas_stereo_dft_enc.c | 8 ++++++++ lib_enc/ivas_stereo_dft_enc_itd.c | 9 +++++++++ 6 files changed, 67 insertions(+) diff --git a/lib_com/edct.c b/lib_com/edct.c index c336ccdd8..09e6a9976 100644 --- a/lib_com/edct.c +++ b/lib_com/edct.c @@ -275,8 +275,14 @@ void edxt( { for ( k = Nm1 >> 1; k > 0; k-- ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float angle_tmp = scale * k; + const float wRe = cosf( angle_tmp ); + const float wIm = sinf( angle_tmp ); +#else const float wRe = cosf( scale * k ); const float wIm = sinf( scale * k ); +#endif y[k] /*pt 1*/ = wRe * re[k] + wIm * im[k]; y[length - k] = wIm * re[k] - wRe * im[k]; @@ -287,8 +293,14 @@ void edxt( { for ( k = Nm1 >> 1; k > 0; k-- ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float angle_tmp = scale * k; + const float wRe = cosf( angle_tmp ); + const float wIm = sinf( angle_tmp ); +#else const float wRe = cosf( scale * k ); const float wIm = sinf( scale * k ); +#endif y[Nm1 - k] = wRe * re[k] + wIm * im[k]; y[k - 1] = wIm * re[k] - wRe * im[k]; @@ -304,8 +316,14 @@ void edxt( { for ( k = Nm1 >> 1; k > 0; k-- ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float angle_tmp = scale * k; + const float wRe = cosf( angle_tmp ) * 0.5f; + const float wIm = sinf( angle_tmp ) * 0.5f; +#else const float wRe = cosf( scale * k ) * 0.5f; const float wIm = sinf( scale * k ) * 0.5f; +#endif re[k] = wRe * x[k] + wIm * x[length - k]; im[k] = wRe * x[length - k] - wIm * x[k]; @@ -316,8 +334,14 @@ void edxt( { for ( k = Nm1 >> 1; k > 0; k-- ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float angle_tmp = scale * k; + const float wRe = cosf( angle_tmp ) * 0.5f; + const float wIm = sinf( angle_tmp ) * 0.5f; +#else const float wRe = cosf( scale * k ) * 0.5f; const float wIm = sinf( scale * k ) * 0.5f; +#endif re[k] = wRe * x[Nm1 - k] + wIm * x[k - 1]; im[k] = wRe * x[k - 1] - wIm * x[Nm1 - k]; diff --git a/lib_com/options.h b/lib_com/options.h index 7569cb250..86b55849f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -197,6 +197,7 @@ #define FIX_1411_IGF_CRASH_BW_SWITCHING /* FhG: Fix for issue 1411: fixes crash that can happen for IGF with BW switching and DTX*/ #define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */ #define NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS /* FhG: fix non-BE in DFT stereo encoder between optimization levels */ +#define NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 /* FhG: fix even more non-BEnesses */ // object-editing feature porting #define FIX_HRTF_LOAD_API // solves API conflicts between HRTF and object-editing features diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 47f880ded..7b8652887 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -1384,8 +1384,16 @@ void stereo_dft_dec( if ( pgIpd[0] != 0.f ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float pgIpd_tmp; + + pgIpd_tmp = pgIpd[0]; + c0 = cosf( pgIpd_tmp ); + s0 = sinf( pgIpd_tmp ); +#else c0 = cosf( pgIpd[0] ); s0 = sinf( pgIpd[0] ); +#endif for ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ @@ -1566,8 +1574,16 @@ void stereo_dft_dec( /* Active Upmix */ if ( pgIpd[0] != 0.f ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float pgIpd_tmp; + + pgIpd_tmp = pgIpd[0]; + c0 = cosf( pgIpd_tmp ); + s0 = sinf( pgIpd_tmp ); +#else c0 = cosf( pgIpd[0] ); s0 = sinf( pgIpd[0] ); +#endif for ( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ diff --git a/lib_dec/ivas_stereo_dft_plc.c b/lib_dec/ivas_stereo_dft_plc.c index 2186aa1b1..f311b60af 100644 --- a/lib_dec/ivas_stereo_dft_plc.c +++ b/lib_dec/ivas_stereo_dft_plc.c @@ -251,6 +251,9 @@ void stereo_dft_res_subst_spec( /* Apply phase adjustment of identified peaks, including Np=1 peak neighbors on each side */ for ( i = *num_plocs - 1; i >= 0; i-- ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float corr_phase_tmp; +#endif if ( k == 0 ) { /* For 1st subframe, apply reversed time ECU to get correct analysis window */ @@ -268,8 +271,14 @@ void stereo_dft_res_subst_spec( conj_sign = 1.0f; } +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + corr_phase_tmp = corr_phase; + cos_F = cosf( corr_phase_tmp ); + sin_F = sinf( corr_phase_tmp ); +#else cos_F = cosf( corr_phase ); sin_F = sinf( corr_phase ); +#endif idx = max( 0, plocs[i] - Np ); /* Iterate over plocs[i]-1:plocs[i]+1, considering the edges of the spectrum */ while ( ( idx < plocs[i] + Np + 1 ) && ( idx < L_res ) ) diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index b7f41f7af..d374aef6b 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1455,8 +1455,16 @@ void stereo_dft_enc_process( if ( pgIpd[0] != 0.f ) { +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float pgIpd_tmp; + + pgIpd_tmp = pgIpd[0]; + c = cosf( pgIpd_tmp ); + s = sinf( pgIpd_tmp ); +#else c = cosf( pgIpd[0] ); s = sinf( pgIpd[0] ); +#endif for ( i = hStereoDft->band_limits_dmx[b]; i < hStereoDft->band_limits_dmx[b + 1]; i++ ) { /*rotate L*/ diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index a095124f7..839cc3b10 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -869,9 +869,18 @@ void stereo_dft_enc_compute_itd( if ( hCPE->element_mode == IVAS_CPE_DFT && ( hItd->td_itd[k_offset] - hItd->td_itd[k_offset - 1] ) ) { float alphaD, c, s, c1, s1, ctmp, vtmp; +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + volatile float alphaD_tmp; +#endif alphaD = -2.f * EVS_PI * ( (float) hItd->td_itd[k_offset] - hItd->td_itd[k_offset - 1] ) / hStereoDft->NFFT; +#ifdef NONBE_FIX_NONBE_BETWEEN_OPTIMIZATION_LEVELS_2 + alphaD_tmp = alphaD; + c1 = cosf( alphaD_tmp ); + s1 = sinf( alphaD_tmp ); +#else c1 = cosf( alphaD ); s1 = sinf( alphaD ); +#endif c = 1.f; /* cos(0) */ s = 0.f; /* sin(0) */ -- GitLab