[FFmpeg-cvslog] avcodec/kbdwin: Avoid computing bessel values twice
Michael Niedermayer
git at videolan.org
Mon May 29 02:00:53 EEST 2023
ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Tue May 23 00:55:17 2023 +0200| [17ecb224e94a3c111017843afbc255303ed01474] | committer: Michael Niedermayer
avcodec/kbdwin: Avoid computing bessel values twice
Also reduce neeeded temporary storage by half
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=17ecb224e94a3c111017843afbc255303ed01474
---
libavcodec/kbdwin.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c
index 5dff334250..e2f6491124 100644
--- a/libavcodec/kbdwin.c
+++ b/libavcodec/kbdwin.c
@@ -23,23 +23,29 @@
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
{
- int i, j;
- double sum = 0.0, bessel, tmp;
- double local_window[FF_KBD_WINDOW_MAX];
- double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
+ int i;
+ double sum = 0.0, tmp;
+ double scale = 0.0;
+ double temp[FF_KBD_WINDOW_MAX / 2 + 1];
+ double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n);
av_assert0(n <= FF_KBD_WINDOW_MAX);
- for (i = 0; i < n; i++) {
+ for (i = 0; i <= n / 2; i++) {
tmp = i * (n - i) * alpha2;
- bessel = av_bessel_i0(sqrt(tmp) * 2);
- sum += bessel;
- local_window[i] = sum;
+ temp[i] = av_bessel_i0(sqrt(tmp));
+ scale += temp[i] * (1 + (i && i<n/2));
}
+ scale = 1.0/(scale + 1);
- sum++;
- for (i = 0; i < n; i++)
- window[i] = sqrt(local_window[i] / sum);
+ for (i = 0; i <= n / 2; i++) {
+ sum += temp[i];
+ window[i] = sqrt(sum * scale);
+ }
+ for (; i < n; i++) {
+ sum += temp[n - i];
+ window[i] = sqrt(sum * scale);
+ }
}
av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n)
More information about the ffmpeg-cvslog
mailing list