diff mbox series

[FFmpeg-devel,6/6] avcodec/kbdwin: Remove low precision intermediate in ff_kbd_window_init_fixed()

Message ID 20230522233601.20552-6-michael@niedermayer.cc
State Accepted
Commit 988fd5743d3a286e490e1860ddef169cf8174a1b
Headers show
Series [FFmpeg-devel,1/6] Move bessel_i0() from swresample/resample to avutil/mathematics | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer May 22, 2023, 11:36 p.m. UTC
Previously floats where scaled up to 32bit int, but floats do not
have 32bits in their mantisse so a quarter of the bits where nonsense.

It seems no fate test is affected by this change, which is interresting

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/kbdwin.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index e2f6491124..163f9d5251 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -21,7 +21,7 @@ 
 #include "libavutil/attributes.h"
 #include "kbdwin.h"
 
-av_cold void ff_kbd_window_init(float *window, float alpha, int n)
+av_cold static void kbd_window_init(float *float_window, int *int_window, float alpha, int n)
 {
    int i;
    double sum = 0.0, tmp;
@@ -40,20 +40,22 @@  av_cold void ff_kbd_window_init(float *window, float alpha, int n)
 
    for (i = 0; i <= n / 2; i++) {
        sum += temp[i];
-       window[i] = sqrt(sum * scale);
+       if (float_window) float_window[i] = sqrt(sum * scale);
+       else                int_window[i] = lrint(2147483647 * sqrt(sum * scale));
    }
    for (; i < n; i++) {
        sum += temp[n - i];
-       window[i] = sqrt(sum * scale);
+       if (float_window) float_window[i] = sqrt(sum * scale);
+       else                int_window[i] = lrint(2147483647 * sqrt(sum * scale));
    }
 }
 
-av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
+av_cold void ff_kbd_window_init(float *window, float alpha, int n)
 {
-    int i;
-    float local_window[FF_KBD_WINDOW_MAX];
+    kbd_window_init(window, NULL, alpha, n);
+}
 
-    ff_kbd_window_init(local_window, alpha, n);
-    for (i = 0; i < n; i++)
-        window[i] = (int)floor(2147483647.0 * local_window[i] + 0.5);
+av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
+{
+    kbd_window_init(NULL, window, alpha, n);
 }