Stereo DMX: Usage of BASOP_Util_Divide3232_Scale_newton() to calculate hPHA->fad_g_prc_fx
# Basic info <!--- Add commit SHA used to reproduce--> - Float reference: - Encoder (float): b63c033f6c392878104cf9af73b00159945c7d32 - Decoder (float): b63c033f6c392878104cf9af73b00159945c7d32 - Fixed point: - Encoder (fixed): 8d9f712dcae2d9f14e574875745b661e410b4137 - Decoder (fixed): n/a # Bug description This is a follow-up on !1376: When trying to replace `BASOP_Util_Divide3232_Scale_cadence()` by `BASOP_Util_Divide3232_Scale_newton()` in ivas_stereo_dmx_evs_fx.c, line 2540, we observe relatively big outliers in the STV stvST32c.wav at 13.2 kbit/s: **BASOP, using `BASOP_Util_Divide3232_Scale_newton():`** ![Bildschirmfoto 2025-04-11 um 15.33.36.png](/uploads/ae74f0bc134eca9f456dbe48c2102fa9/Bildschirmfoto_2025-04-11_um_15.33.36.png) **BASOP, using `BASOP_Util_Divide3232_Scale_cadence():`** ![Bildschirmfoto 2025-04-11 um 15.33.42.png](/uploads/b044f0df9d7131e437a77886ccfadcd1/Bildschirmfoto_2025-04-11_um_15.33.42.png) **Float:** ![Bildschirmfoto 2025-04-11 um 15.33.48.png](/uploads/2d79fb4f8fe92a651859f73f5b6edd0c/Bildschirmfoto_2025-04-11_um_15.33.48.png) The following change was applied to the code: ``` diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index 625ff8ee..2e76c973 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -2537,7 +2537,13 @@ ivas_error stereo_dmx_evs_init_encoder_fx( move16(); fad_g = hStereoDmxEVS->hPHA->fad_g_prc_fx; // fad_r = 1.0f / (float) ( fad_len + 1 ); +#if 1 + fad_r = BASOP_Util_Divide3232_Scale_newton( 1, add( fad_len, 1 ), &tmp_e ); + fprintf(stderr, "\nfad_r: %d\n", fad_r); +#else fad_r = BASOP_Util_Divide3232_Scale_cadence( 1, add( fad_len, 1 ), &tmp_e ); + fprintf(stderr, "\nfad_r: %d\n", fad_r); +#endif fad_r = L_shl_r( fad_r, tmp_e ); fad_len2 = shr( fad_len, 1 ); FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len2; ( n++, m-- ) ) ``` The output of the division itself only differs by 1 bit: `BASOP_Util_Divide3232_Scale_newton()`: fad_r = 857653376 `BASOP_Util_Divide3232_Scale_cadence()`: fad_r: 857653375 With the following code, an potential error is amplified: ``` fad_r = L_shl_r( fad_r, tmp_e ); fad_len2 = shr( fad_len, 1 ); FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len2; ( n++, m-- ) ) { fad_g[n] = imult3216( fad_r, add( n, 1 ) ); move32(); fad_g[m] = L_sub( MAX_32, fad_g[n] ); move32(); } ``` I'm not exactly sure about the actual reason for this big outlier, but it's a bit concerning that this one bit of difference in precision causes such a big outlier. # Ways to reproduce <!--Commandline or script--> ```bash IVAS_cod -stereo_dmx_evs 13200 32 ivas-codec/scripts/testv/stvST32c.wav out.192 IVAS_dec 32 out.192 out.wav ``` <!--- Below are labels that will be added but are not shown in description. This is a template to help fill them. Add further information to the first row and remove and add labels as necessary.-->
issue