/* * This file was stolen from ffmpeg and modified for usability here. * The original does not have a "copyright by" line. * * This version is a derivative work of that version. It is not free * software; it is licensed under the GNU Lesser General Public * License version 2.1, which places nontrivial restrictions on what * may be done with it. (I'm not terribly happy about that, but for * my purposes accepting LGPL-infected code is a lower price than * reimplementing it all myself.) * * The LGPL v2.1 as distributed with ffmpeg is in the accompanying file * `LGPL-v2.1'. */ #include #include #include "kbdwin.h" #include "avutil-attributes.h" #define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation 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); assert(n <= FF_KBD_WINDOW_MAX); for (i = 0; i < n; i++) { tmp = i * (n - i) * alpha2; bessel = 1.0; for (j = BESSEL_I0_ITER; j > 0; j--) bessel = bessel * tmp / (j * j) + 1; sum += bessel; local_window[i] = sum; } sum++; for (i = 0; i < n; i++) window[i] = sqrt(local_window[i] / sum); }