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

Michael Niedermayer git at videolan.org
Mon May 29 02:00:55 EEST 2023


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue May 23 01:19:32 2023 +0200| [988fd5743d3a286e490e1860ddef169cf8174a1b] | committer: Michael Niedermayer

avcodec/kbdwin: Remove low precision intermediate in ff_kbd_window_init_fixed()

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 at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=988fd5743d3a286e490e1860ddef169cf8174a1b
---

 libavcodec/kbdwin.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

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);
 }



More information about the ffmpeg-cvslog mailing list