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
5959 { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, flag, "win_func" }, \
6060 { "kaiser", "Kaiser", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_KAISER}, 0, 0, flag, "win_func" }
6161
62−static 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−}
7562
7663 static inline void generate_window_func(float *lut, int N, int win_func,
7764 float *overlap)
@@ -232,13 +219,15 @@ static inline void generate_window_func(float *lut, int N, int win_func, · 154 unmodified lines
232219 *overlap = 0.75;
233220 break;
234221 case WFUNC_KAISER:
222+ {
223+ double scale = 1.0 / av_bessel_i0(12.);
235224 for (n = 0; n < N; n++) {
236225 double x = 2.0 / (double)(N - 1);
237−
238− lut[n] = get_i0(12. * sqrt(1. - SQR(n * x - 1.))) / get_i0(12.);
226+ lut[n] = av_bessel_i0(12. * sqrt(1. - SQR(n * x - 1.))) * scale;
239227 }
240228 *overlap = 0.75;
241229 break;
230+ }
242231 default:
243232 av_assert0(0);
244233 }

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