History

avfilter/window_func: Use av_bessel_i0()

Old code needed about 6 times as long as new with defaults in afftfilt

Michael Niedermayer committed 3 years ago

Commit 0c7a0511 parent 1e9c3371 file · +4 −15Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/window_func.h+4−15
@@ -59,19 +59,6 @@ enum WindowFunc { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, · 58 unmodified lines
59 { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, flag, "win_func" }, \59 { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, flag, "win_func" }, \
60 { "kaiser", "Kaiser", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_KAISER}, 0, 0, flag, "win_func" }60 { "kaiser", "Kaiser", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_KAISER}, 0, 0, flag, "win_func" }
61 61
62static inline double get_i0(double x)
63{
64 double y = 1.0, prev = 1.0, i = 1.0;
65
66 while (fabs(prev) > 1e-20) {
67 double summand = prev * x * x / (4 * i * i);
68 y += summand;
69 prev = summand;
70 i++;
71 }
72
73 return y;
74}
75 62
76static inline void generate_window_func(float *lut, int N, int win_func,63static inline void generate_window_func(float *lut, int N, int win_func,
77 float *overlap)64 float *overlap)
@@ -232,13 +219,15 @@ static inline void generate_window_func(float *lut, int N, int win_func, · 154 unmodified lines
232 *overlap = 0.75;219 *overlap = 0.75;
233 break;220 break;
234 case WFUNC_KAISER:221 case WFUNC_KAISER:
222 {
223 double scale = 1.0 / av_bessel_i0(12.);
235 for (n = 0; n < N; n++) {224 for (n = 0; n < N; n++) {
236 double x = 2.0 / (double)(N - 1);225 double x = 2.0 / (double)(N - 1);
237 226 lut[n] = av_bessel_i0(12. * sqrt(1. - SQR(n * x - 1.))) * scale;
238 lut[n] = get_i0(12. * sqrt(1. - SQR(n * x - 1.))) / get_i0(12.);
239 }227 }
240 *overlap = 0.75;228 *overlap = 0.75;
241 break;229 break;
230 }
242 default:231 default:
243 av_assert0(0);232 av_assert0(0);
244 }233 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t