FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/af_biquads.c
Date: 2026-05-01 13:04:54
Exec Total Coverage
Lines: 0 729 0.0%
Functions: 0 53 0.0%
Branches: 0 450 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2013 Paul B Mahol
3 * Copyright (c) 2006-2008 Rob Sykes <robs@users.sourceforge.net>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /*
23 * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
24 * see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
25 *
26 * 1-pole filters based on code (c) 2000 Chris Bagwell <cbagwell@sprynet.com>
27 * Algorithms: Recursive single pole low/high pass filter
28 * Reference: The Scientist and Engineer's Guide to Digital Signal Processing
29 *
30 * low-pass: output[N] = input[N] * A + output[N-1] * B
31 * X = exp(-2.0 * pi * Fc)
32 * A = 1 - X
33 * B = X
34 * Fc = cutoff freq / sample rate
35 *
36 * Mimics an RC low-pass filter:
37 *
38 * ---/\/\/\/\----------->
39 * |
40 * --- C
41 * ---
42 * |
43 * |
44 * V
45 *
46 * high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
47 * X = exp(-2.0 * pi * Fc)
48 * A0 = (1 + X) / 2
49 * A1 = -(1 + X) / 2
50 * B1 = X
51 * Fc = cutoff freq / sample rate
52 *
53 * Mimics an RC high-pass filter:
54 *
55 * || C
56 * ----||--------->
57 * || |
58 * <
59 * > R
60 * <
61 * |
62 * V
63 */
64
65 #include "config_components.h"
66
67 #include "libavutil/attributes.h"
68 #include "libavutil/avassert.h"
69 #include "libavutil/channel_layout.h"
70 #include "libavutil/ffmath.h"
71 #include "libavutil/mem.h"
72 #include "libavutil/opt.h"
73 #include "audio.h"
74 #include "avfilter.h"
75 #include "filters.h"
76 #include "formats.h"
77
78 enum FilterType {
79 biquad,
80 equalizer,
81 bass,
82 treble,
83 bandpass,
84 bandreject,
85 allpass,
86 highpass,
87 lowpass,
88 lowshelf,
89 highshelf,
90 tiltshelf,
91 };
92
93 enum WidthType {
94 NONE,
95 HERTZ,
96 OCTAVE,
97 QFACTOR,
98 SLOPE,
99 KHERTZ,
100 NB_WTYPE,
101 };
102
103 enum TransformType {
104 DI,
105 DII,
106 TDI,
107 TDII,
108 LATT,
109 SVF,
110 ZDF,
111 NB_TTYPE,
112 };
113
114 typedef struct BiquadsContext {
115 const AVClass *class;
116
117 enum FilterType filter_type;
118 int width_type;
119 int poles;
120 int csg;
121 int transform_type;
122 int precision;
123 int block_samples;
124
125 int bypass;
126
127 double gain;
128 double frequency;
129 double width;
130 double mix;
131 char *ch_layout_str;
132 AVChannelLayout ch_layout;
133 int normalize;
134 int order;
135
136 double a_double[3];
137 double b_double[3];
138
139 float a_float[3];
140 float b_float[3];
141
142 double oa[3];
143 double ob[3];
144
145 AVFrame *block[3];
146
147 int *clip;
148 AVFrame *cache[2];
149 int block_align;
150
151 int64_t pts;
152 int nb_samples;
153
154 void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
155 void *cache, int *clip, int disabled);
156 } BiquadsContext;
157
158 static int query_formats(const AVFilterContext *ctx,
159 AVFilterFormatsConfig **cfg_in,
160 AVFilterFormatsConfig **cfg_out)
161 {
162 const BiquadsContext *s = ctx->priv;
163 static const enum AVSampleFormat auto_sample_fmts[] = {
164 AV_SAMPLE_FMT_S16P,
165 AV_SAMPLE_FMT_S32P,
166 AV_SAMPLE_FMT_FLTP,
167 AV_SAMPLE_FMT_DBLP,
168 AV_SAMPLE_FMT_NONE
169 };
170 enum AVSampleFormat sample_fmts[] = {
171 AV_SAMPLE_FMT_S16P,
172 AV_SAMPLE_FMT_NONE
173 };
174 const enum AVSampleFormat *sample_fmts_list = sample_fmts;
175 int ret;
176
177 switch (s->precision) {
178 case 0:
179 sample_fmts[0] = AV_SAMPLE_FMT_S16P;
180 break;
181 case 1:
182 sample_fmts[0] = AV_SAMPLE_FMT_S32P;
183 break;
184 case 2:
185 sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
186 break;
187 case 3:
188 sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
189 break;
190 default:
191 sample_fmts_list = auto_sample_fmts;
192 break;
193 }
194 ret = ff_set_sample_formats_from_list2(ctx, cfg_in, cfg_out, sample_fmts_list);
195 if (ret < 0)
196 return ret;
197
198 return 0;
199 }
200
201 #define BIQUAD_FILTER(name, type, ftype, min, max, need_clipping) \
202 static void biquad_## name (BiquadsContext *s, \
203 const void *input, void *output, int len, \
204 void *cache, int *clippings, int disabled) \
205 { \
206 const type *ibuf = input; \
207 type *obuf = output; \
208 ftype *fcache = cache; \
209 ftype i1 = fcache[0], i2 = fcache[1], o1 = fcache[2], o2 = fcache[3]; \
210 ftype *a = s->a_##ftype; \
211 ftype *b = s->b_##ftype; \
212 ftype a1 = -a[1]; \
213 ftype a2 = -a[2]; \
214 ftype b0 = b[0]; \
215 ftype b1 = b[1]; \
216 ftype b2 = b[2]; \
217 ftype wet = s->mix; \
218 ftype dry = 1. - wet; \
219 ftype out; \
220 int i; \
221 \
222 for (i = 0; i+1 < len; i++) { \
223 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
224 i2 = ibuf[i]; \
225 out = o2 * wet + i2 * dry; \
226 if (disabled) { \
227 obuf[i] = i2; \
228 } else if (need_clipping && out < min) { \
229 (*clippings)++; \
230 obuf[i] = min; \
231 } else if (need_clipping && out > max) { \
232 (*clippings)++; \
233 obuf[i] = max; \
234 } else { \
235 obuf[i] = out; \
236 } \
237 i++; \
238 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
239 i1 = ibuf[i]; \
240 out = o1 * wet + i1 * dry; \
241 if (disabled) { \
242 obuf[i] = i1; \
243 } else if (need_clipping && out < min) { \
244 (*clippings)++; \
245 obuf[i] = min; \
246 } else if (need_clipping && out > max) { \
247 (*clippings)++; \
248 obuf[i] = max; \
249 } else { \
250 obuf[i] = out; \
251 } \
252 } \
253 if (i < len) { \
254 ftype o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
255 i2 = i1; \
256 i1 = ibuf[i]; \
257 o2 = o1; \
258 o1 = o0; \
259 out = o0 * wet + i1 * dry; \
260 if (disabled) { \
261 obuf[i] = i1; \
262 } else if (need_clipping && out < min) { \
263 (*clippings)++; \
264 obuf[i] = min; \
265 } else if (need_clipping && out > max) { \
266 (*clippings)++; \
267 obuf[i] = max; \
268 } else { \
269 obuf[i] = out; \
270 } \
271 } \
272 fcache[0] = i1; \
273 fcache[1] = i2; \
274 fcache[2] = o1; \
275 fcache[3] = o2; \
276 }
277
278 BIQUAD_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
279 BIQUAD_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
280 BIQUAD_FILTER(flt, float, float, -1.f, 1.f, 0)
281 BIQUAD_FILTER(dbl, double, double, -1., 1., 0)
282
283 #define BIQUAD_DII_FILTER(name, type, ftype, min, max, need_clipping) \
284 static void biquad_dii_## name (BiquadsContext *s, \
285 const void *input, void *output, int len, \
286 void *cache, int *clippings, int disabled) \
287 { \
288 const type *ibuf = input; \
289 type *obuf = output; \
290 ftype *fcache = cache; \
291 ftype *a = s->a_##ftype; \
292 ftype *b = s->b_##ftype; \
293 ftype a1 = -a[1]; \
294 ftype a2 = -a[2]; \
295 ftype b0 = b[0]; \
296 ftype b1 = b[1]; \
297 ftype b2 = b[2]; \
298 ftype w1 = fcache[0]; \
299 ftype w2 = fcache[1]; \
300 ftype wet = s->mix; \
301 ftype dry = 1. - wet; \
302 ftype in, out, w0; \
303 \
304 for (int i = 0; i < len; i++) { \
305 in = ibuf[i]; \
306 w0 = in + a1 * w1 + a2 * w2; \
307 out = b0 * w0 + b1 * w1 + b2 * w2; \
308 w2 = w1; \
309 w1 = w0; \
310 out = out * wet + in * dry; \
311 if (disabled) { \
312 obuf[i] = in; \
313 } else if (need_clipping && out < min) { \
314 (*clippings)++; \
315 obuf[i] = min; \
316 } else if (need_clipping && out > max) { \
317 (*clippings)++; \
318 obuf[i] = max; \
319 } else { \
320 obuf[i] = out; \
321 } \
322 } \
323 fcache[0] = w1; \
324 fcache[1] = w2; \
325 }
326
327 BIQUAD_DII_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
328 BIQUAD_DII_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
329 BIQUAD_DII_FILTER(flt, float, float, -1.f, 1.f, 0)
330 BIQUAD_DII_FILTER(dbl, double, double, -1., 1., 0)
331
332 #define BIQUAD_TDI_FILTER(name, type, ftype, min, max, need_clipping) \
333 static void biquad_tdi_## name (BiquadsContext *s, \
334 const void *input, void *output, int len, \
335 void *cache, int *clippings, int disabled) \
336 { \
337 const type *ibuf = input; \
338 type *obuf = output; \
339 ftype *fcache = cache; \
340 ftype *a = s->a_##ftype; \
341 ftype *b = s->b_##ftype; \
342 ftype a1 = -a[1]; \
343 ftype a2 = -a[2]; \
344 ftype b0 = b[0]; \
345 ftype b1 = b[1]; \
346 ftype b2 = b[2]; \
347 ftype s1 = fcache[0]; \
348 ftype s2 = fcache[1]; \
349 ftype s3 = fcache[2]; \
350 ftype s4 = fcache[3]; \
351 ftype wet = s->mix; \
352 ftype dry = 1. - wet; \
353 ftype in, out; \
354 \
355 for (int i = 0; i < len; i++) { \
356 ftype t1, t2, t3, t4; \
357 in = ibuf[i] + s1; \
358 t1 = in * a1 + s2; \
359 t2 = in * a2; \
360 t3 = in * b1 + s4; \
361 t4 = in * b2; \
362 out = b0 * in + s3; \
363 out = out * wet + in * dry; \
364 s1 = t1; s2 = t2; s3 = t3; s4 = t4; \
365 if (disabled) { \
366 obuf[i] = in; \
367 } else if (need_clipping && out < min) { \
368 (*clippings)++; \
369 obuf[i] = min; \
370 } else if (need_clipping && out > max) { \
371 (*clippings)++; \
372 obuf[i] = max; \
373 } else { \
374 obuf[i] = out; \
375 } \
376 } \
377 \
378 fcache[0] = s1; \
379 fcache[1] = s2; \
380 fcache[2] = s3; \
381 fcache[3] = s4; \
382 }
383
384 BIQUAD_TDI_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
385 BIQUAD_TDI_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
386 BIQUAD_TDI_FILTER(flt, float, float, -1.f, 1.f, 0)
387 BIQUAD_TDI_FILTER(dbl, double, double, -1., 1., 0)
388
389 #define BIQUAD_TDII_FILTER(name, type, ftype, min, max, need_clipping) \
390 static void biquad_tdii_## name (BiquadsContext *s, \
391 const void *input, void *output, int len, \
392 void *cache, int *clippings, int disabled) \
393 { \
394 const type *ibuf = input; \
395 type *obuf = output; \
396 ftype *fcache = cache; \
397 ftype *a = s->a_##ftype; \
398 ftype *b = s->b_##ftype; \
399 ftype a1 = -a[1]; \
400 ftype a2 = -a[2]; \
401 ftype b0 = b[0]; \
402 ftype b1 = b[1]; \
403 ftype b2 = b[2]; \
404 ftype w1 = fcache[0]; \
405 ftype w2 = fcache[1]; \
406 ftype wet = s->mix; \
407 ftype dry = 1. - wet; \
408 ftype in, out; \
409 \
410 for (int i = 0; i < len; i++) { \
411 in = ibuf[i]; \
412 out = b0 * in + w1; \
413 w1 = b1 * in + w2 + a1 * out; \
414 w2 = b2 * in + a2 * out; \
415 out = out * wet + in * dry; \
416 if (disabled) { \
417 obuf[i] = in; \
418 } else if (need_clipping && out < min) { \
419 (*clippings)++; \
420 obuf[i] = min; \
421 } else if (need_clipping && out > max) { \
422 (*clippings)++; \
423 obuf[i] = max; \
424 } else { \
425 obuf[i] = out; \
426 } \
427 } \
428 fcache[0] = w1; \
429 fcache[1] = w2; \
430 }
431
432 BIQUAD_TDII_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
433 BIQUAD_TDII_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
434 BIQUAD_TDII_FILTER(flt, float, float, -1.f, 1.f, 0)
435 BIQUAD_TDII_FILTER(dbl, double, double, -1., 1., 0)
436
437 #define BIQUAD_LATT_FILTER(name, type, ftype, min, max, need_clipping) \
438 static void biquad_latt_## name (BiquadsContext *s, \
439 const void *input, void *output, int len, \
440 void *cache, int *clippings, int disabled) \
441 { \
442 const type *ibuf = input; \
443 type *obuf = output; \
444 ftype *fcache = cache; \
445 ftype *a = s->a_##ftype; \
446 ftype *b = s->b_##ftype; \
447 ftype k0 = a[1]; \
448 ftype k1 = a[2]; \
449 ftype v0 = b[0]; \
450 ftype v1 = b[1]; \
451 ftype v2 = b[2]; \
452 ftype s0 = fcache[0]; \
453 ftype s1 = fcache[1]; \
454 ftype wet = s->mix; \
455 ftype dry = 1. - wet; \
456 ftype in, out; \
457 ftype t0, t1; \
458 \
459 for (int i = 0; i < len; i++) { \
460 out = 0.; \
461 in = ibuf[i]; \
462 t0 = in - k1 * s0; \
463 t1 = t0 * k1 + s0; \
464 out += t1 * v2; \
465 \
466 t0 = t0 - k0 * s1; \
467 t1 = t0 * k0 + s1; \
468 out += t1 * v1; \
469 \
470 out += t0 * v0; \
471 s0 = t1; \
472 s1 = t0; \
473 \
474 out = out * wet + in * dry; \
475 if (disabled) { \
476 obuf[i] = in; \
477 } else if (need_clipping && out < min) { \
478 (*clippings)++; \
479 obuf[i] = min; \
480 } else if (need_clipping && out > max) { \
481 (*clippings)++; \
482 obuf[i] = max; \
483 } else { \
484 obuf[i] = out; \
485 } \
486 } \
487 fcache[0] = s0; \
488 fcache[1] = s1; \
489 }
490
491 BIQUAD_LATT_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
492 BIQUAD_LATT_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
493 BIQUAD_LATT_FILTER(flt, float, float, -1.f, 1.f, 0)
494 BIQUAD_LATT_FILTER(dbl, double, double, -1., 1., 0)
495
496 #define BIQUAD_SVF_FILTER(name, type, ftype, min, max, need_clipping) \
497 static void biquad_svf_## name (BiquadsContext *s, \
498 const void *input, void *output, int len, \
499 void *cache, int *clippings, int disabled) \
500 { \
501 const type *ibuf = input; \
502 type *obuf = output; \
503 ftype *fcache = cache; \
504 ftype *a = s->a_##ftype; \
505 ftype *b = s->b_##ftype; \
506 ftype a1 = a[1]; \
507 ftype a2 = a[2]; \
508 ftype b0 = b[0]; \
509 ftype b1 = b[1]; \
510 ftype b2 = b[2]; \
511 ftype s0 = fcache[0]; \
512 ftype s1 = fcache[1]; \
513 ftype wet = s->mix; \
514 ftype dry = 1. - wet; \
515 ftype in, out; \
516 ftype t0, t1; \
517 \
518 for (int i = 0; i < len; i++) { \
519 in = ibuf[i]; \
520 out = b2 * in + s0; \
521 t0 = b0 * in + a1 * s0 + s1; \
522 t1 = b1 * in + a2 * s0; \
523 s0 = t0; \
524 s1 = t1; \
525 \
526 out = out * wet + in * dry; \
527 if (disabled) { \
528 obuf[i] = in; \
529 } else if (need_clipping && out < min) { \
530 (*clippings)++; \
531 obuf[i] = min; \
532 } else if (need_clipping && out > max) { \
533 (*clippings)++; \
534 obuf[i] = max; \
535 } else { \
536 obuf[i] = out; \
537 } \
538 } \
539 fcache[0] = s0; \
540 fcache[1] = s1; \
541 }
542
543 BIQUAD_SVF_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1)
544 BIQUAD_SVF_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1)
545 BIQUAD_SVF_FILTER(flt, float, float, -1.f, 1.f, 0)
546 BIQUAD_SVF_FILTER(dbl, double, double, -1., 1., 0)
547
548 #define BIQUAD_ZDF_FILTER(name, type, ftype, min, max, need_clipping, two) \
549 static void biquad_zdf_## name (BiquadsContext *s, \
550 const void *input, void *output, int len, \
551 void *cache, int *clippings, int disabled) \
552 { \
553 const type *ibuf = input; \
554 type *obuf = output; \
555 ftype *fcache = cache; \
556 ftype *a = s->a_##ftype; \
557 ftype *b = s->b_##ftype; \
558 ftype m0 = b[0]; \
559 ftype m1 = b[1]; \
560 ftype m2 = b[2]; \
561 ftype a0 = a[0]; \
562 ftype a1 = a[1]; \
563 ftype a2 = a[2]; \
564 ftype b0 = fcache[0]; \
565 ftype b1 = fcache[1]; \
566 ftype wet = s->mix; \
567 ftype dry = 1. - wet; \
568 ftype out; \
569 \
570 for (int i = 0; i < len; i++) { \
571 const ftype in = ibuf[i]; \
572 const ftype v0 = in; \
573 const ftype v3 = v0 - b1; \
574 const ftype v1 = a0 * b0 + a1 * v3; \
575 const ftype v2 = b1 + a1 * b0 + a2 * v3; \
576 \
577 b0 = two * v1 - b0; \
578 b1 = two * v2 - b1; \
579 \
580 out = m0 * v0 + m1 * v1 + m2 * v2; \
581 out = out * wet + in * dry; \
582 if (disabled) { \
583 obuf[i] = in; \
584 } else if (need_clipping && out < min) { \
585 (*clippings)++; \
586 obuf[i] = min; \
587 } else if (need_clipping && out > max) { \
588 (*clippings)++; \
589 obuf[i] = max; \
590 } else { \
591 obuf[i] = out; \
592 } \
593 } \
594 fcache[0] = b0; \
595 fcache[1] = b1; \
596 }
597
598 BIQUAD_ZDF_FILTER(s16, int16_t, float, INT16_MIN, INT16_MAX, 1, 2.f)
599 BIQUAD_ZDF_FILTER(s32, int32_t, double, INT32_MIN, INT32_MAX, 1, 2.0)
600 BIQUAD_ZDF_FILTER(flt, float, float, -1.f, 1.f, 0, 2.f)
601 BIQUAD_ZDF_FILTER(dbl, double, double, -1., 1., 0, 2.0)
602
603 static void convert_dir2latt(BiquadsContext *s)
604 {
605 double k0, k1, v0, v1, v2;
606
607 k1 = s->a_double[2];
608 k0 = s->a_double[1] / (1. + k1);
609 v2 = s->b_double[2];
610 v1 = s->b_double[1] - v2 * s->a_double[1];
611 v0 = s->b_double[0] - v1 * k0 - v2 * k1;
612
613 s->a_double[1] = k0;
614 s->a_double[2] = k1;
615 s->b_double[0] = v0;
616 s->b_double[1] = v1;
617 s->b_double[2] = v2;
618 }
619
620 static void convert_dir2svf(BiquadsContext *s)
621 {
622 double a[2];
623 double b[3];
624
625 a[0] = -s->a_double[1];
626 a[1] = -s->a_double[2];
627 b[0] = s->b_double[1] - s->a_double[1] * s->b_double[0];
628 b[1] = s->b_double[2] - s->a_double[2] * s->b_double[0];
629 b[2] = s->b_double[0];
630
631 s->a_double[1] = a[0];
632 s->a_double[2] = a[1];
633 s->b_double[0] = b[0];
634 s->b_double[1] = b[1];
635 s->b_double[2] = b[2];
636 }
637
638 static double convert_width2qfactor(double width,
639 double frequency,
640 double gain,
641 double sample_rate,
642 int width_type)
643 {
644 double w0 = 2. * M_PI * frequency / sample_rate;
645 double A = ff_exp10(gain / 40.);
646 double ret;
647
648 switch (width_type) {
649 case NONE:
650 case QFACTOR:
651 ret = width;
652 break;
653 case HERTZ:
654 ret = frequency / width;
655 break;
656 case KHERTZ:
657 ret = frequency / (width * 1000.);
658 break;
659 case OCTAVE:
660 ret = 1. / (2. * sinh(log(2.) / 2. * width * w0 / sin(w0)));
661 break;
662 case SLOPE:
663 ret = 1. / sqrt((A + 1. / A) * (1. / width - 1.) + 2.);
664 break;
665 default:
666 av_assert0(0);
667 break;
668 }
669
670 return ret;
671 }
672
673 static void convert_dir2zdf(BiquadsContext *s, int sample_rate)
674 {
675 double Q = convert_width2qfactor(s->width, s->frequency, s->gain, sample_rate, s->width_type);
676 double g, k, A;
677 double a[3];
678 double m[3];
679
680 switch (s->filter_type) {
681 case biquad:
682 a[0] = s->oa[0];
683 a[1] = s->oa[1];
684 a[2] = s->oa[2];
685 m[0] = s->ob[0];
686 m[1] = s->ob[1];
687 m[2] = s->ob[2];
688 break;
689 case equalizer:
690 A = ff_exp10(s->gain / 40.);
691 g = tan(M_PI * s->frequency / sample_rate);
692 k = 1. / (Q * A);
693 a[0] = 1. / (1. + g * (g + k));
694 a[1] = g * a[0];
695 a[2] = g * a[1];
696 m[0] = 1.;
697 m[1] = k * (A * A - 1.);
698 m[2] = 0.;
699 break;
700 case bass:
701 case lowshelf:
702 A = ff_exp10(s->gain / 40.);
703 g = tan(M_PI * s->frequency / sample_rate) / sqrt(A);
704 k = 1. / Q;
705 a[0] = 1. / (1. + g * (g + k));
706 a[1] = g * a[0];
707 a[2] = g * a[1];
708 m[0] = 1.;
709 m[1] = k * (A - 1.);
710 m[2] = A * A - 1.;
711 break;
712 case tiltshelf:
713 A = ff_exp10(s->gain / 20.);
714 g = tan(M_PI * s->frequency / sample_rate) / sqrt(A);
715 k = 1. / Q;
716 a[0] = 1. / (1. + g * (g + k));
717 a[1] = g * a[0];
718 a[2] = g * a[1];
719 m[0] = 1./ A;
720 m[1] = k * (A - 1.) / A;
721 m[2] = (A * A - 1.) / A;
722 break;
723 case treble:
724 case highshelf:
725 A = ff_exp10(s->gain / 40.);
726 g = tan(M_PI * s->frequency / sample_rate) * sqrt(A);
727 k = 1. / Q;
728 a[0] = 1. / (1. + g * (g + k));
729 a[1] = g * a[0];
730 a[2] = g * a[1];
731 m[0] = A * A;
732 m[1] = k * (1. - A) * A;
733 m[2] = 1. - A * A;
734 break;
735 case bandpass:
736 g = tan(M_PI * s->frequency / sample_rate);
737 k = 1. / Q;
738 a[0] = 1. / (1. + g * (g + k));
739 a[1] = g * a[0];
740 a[2] = g * a[1];
741 m[0] = 0.;
742 m[1] = s->csg ? 1. : k;
743 m[2] = 0.;
744 break;
745 case bandreject:
746 g = tan(M_PI * s->frequency / sample_rate);
747 k = 1. / Q;
748 a[0] = 1. / (1. + g * (g + k));
749 a[1] = g * a[0];
750 a[2] = g * a[1];
751 m[0] = 1.;
752 m[1] = -k;
753 m[2] = 0.;
754 break;
755 case lowpass:
756 g = tan(M_PI * s->frequency / sample_rate);
757 k = 1. / Q;
758 a[0] = 1. / (1. + g * (g + k));
759 a[1] = g * a[0];
760 a[2] = g * a[1];
761 m[0] = 0.;
762 m[1] = 0.;
763 m[2] = 1.;
764 break;
765 case highpass:
766 g = tan(M_PI * s->frequency / sample_rate);
767 k = 1. / Q;
768 a[0] = 1. / (1. + g * (g + k));
769 a[1] = g * a[0];
770 a[2] = g * a[1];
771 m[0] = 1.;
772 m[1] = -k;
773 m[2] = -1.;
774 break;
775 case allpass:
776 g = tan(M_PI * s->frequency / sample_rate);
777 k = 1. / Q;
778 a[0] = 1. / (1. + g * (g + k));
779 a[1] = g * a[0];
780 a[2] = g * a[1];
781 m[0] = 1.;
782 m[1] = -2. * k;
783 m[2] = 0.;
784 break;
785 default:
786 av_assert0(0);
787 }
788
789 s->a_double[0] = a[0];
790 s->a_double[1] = a[1];
791 s->a_double[2] = a[2];
792 s->b_double[0] = m[0];
793 s->b_double[1] = m[1];
794 s->b_double[2] = m[2];
795 }
796
797 static int config_filter(AVFilterLink *outlink, int reset)
798 {
799 AVFilterContext *ctx = outlink->src;
800 BiquadsContext *s = ctx->priv;
801 AVFilterLink *inlink = ctx->inputs[0];
802 double gain = s->gain * ((s->filter_type == tiltshelf) + 1.);
803 double A = ff_exp10(gain / 40);
804 double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
805 double K = tan(w0 / 2.);
806 double alpha, beta;
807
808 s->bypass = (((w0 > M_PI || w0 <= 0.) && reset) || (s->width <= 0.)) && (s->filter_type != biquad);
809 if (s->bypass) {
810 av_log(ctx, AV_LOG_WARNING, "Invalid frequency and/or width!\n");
811 return 0;
812 }
813
814 if ((w0 > M_PI || w0 <= 0.) && (s->filter_type != biquad))
815 return AVERROR(EINVAL);
816
817 switch (s->width_type) {
818 case NONE:
819 alpha = 0.0;
820 break;
821 case HERTZ:
822 alpha = sin(w0) / (2 * s->frequency / s->width);
823 break;
824 case KHERTZ:
825 alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
826 break;
827 case OCTAVE:
828 alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
829 break;
830 case QFACTOR:
831 alpha = sin(w0) / (2 * s->width);
832 break;
833 case SLOPE:
834 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
835 break;
836 default:
837 av_assert0(0);
838 }
839
840 beta = 2 * sqrt(A);
841
842 switch (s->filter_type) {
843 case biquad:
844 s->a_double[0] = s->oa[0];
845 s->a_double[1] = s->oa[1];
846 s->a_double[2] = s->oa[2];
847 s->b_double[0] = s->ob[0];
848 s->b_double[1] = s->ob[1];
849 s->b_double[2] = s->ob[2];
850 break;
851 case equalizer:
852 s->a_double[0] = 1 + alpha / A;
853 s->a_double[1] = -2 * cos(w0);
854 s->a_double[2] = 1 - alpha / A;
855 s->b_double[0] = 1 + alpha * A;
856 s->b_double[1] = -2 * cos(w0);
857 s->b_double[2] = 1 - alpha * A;
858 break;
859 case bass:
860 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
861 av_fallthrough;
862 case tiltshelf:
863 case lowshelf:
864 if (s->poles == 1) {
865 double A = ff_exp10(gain / 20);
866 double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
867 double n = (A + 1) / (A - 1);
868 double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
869 double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
870 double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
871
872 s->a_double[0] = 1 + ro * alpha1;
873 s->a_double[1] = -ro - alpha1;
874 s->a_double[2] = 0;
875 s->b_double[0] = beta0 + ro * beta1;
876 s->b_double[1] = -beta1 - ro * beta0;
877 s->b_double[2] = 0;
878 } else {
879 s->a_double[0] = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
880 s->a_double[1] = -2 * ((A - 1) + (A + 1) * cos(w0));
881 s->a_double[2] = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
882 s->b_double[0] = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
883 s->b_double[1] = 2 * A * ((A - 1) - (A + 1) * cos(w0));
884 s->b_double[2] = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
885 }
886 break;
887 case treble:
888 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
889 av_fallthrough;
890 case highshelf:
891 if (s->poles == 1) {
892 double A = ff_exp10(gain / 20);
893 double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
894 double n = (A + 1) / (A - 1);
895 double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
896 double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
897 double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
898
899 s->a_double[0] = 1 + ro * alpha1;
900 s->a_double[1] = ro + alpha1;
901 s->a_double[2] = 0;
902 s->b_double[0] = beta0 + ro * beta1;
903 s->b_double[1] = beta1 + ro * beta0;
904 s->b_double[2] = 0;
905 } else {
906 s->a_double[0] = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
907 s->a_double[1] = 2 * ((A - 1) - (A + 1) * cos(w0));
908 s->a_double[2] = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
909 s->b_double[0] = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
910 s->b_double[1] =-2 * A * ((A - 1) + (A + 1) * cos(w0));
911 s->b_double[2] = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
912 }
913 break;
914 case bandpass:
915 if (s->csg) {
916 s->a_double[0] = 1 + alpha;
917 s->a_double[1] = -2 * cos(w0);
918 s->a_double[2] = 1 - alpha;
919 s->b_double[0] = sin(w0) / 2;
920 s->b_double[1] = 0;
921 s->b_double[2] = -sin(w0) / 2;
922 } else {
923 s->a_double[0] = 1 + alpha;
924 s->a_double[1] = -2 * cos(w0);
925 s->a_double[2] = 1 - alpha;
926 s->b_double[0] = alpha;
927 s->b_double[1] = 0;
928 s->b_double[2] = -alpha;
929 }
930 break;
931 case bandreject:
932 s->a_double[0] = 1 + alpha;
933 s->a_double[1] = -2 * cos(w0);
934 s->a_double[2] = 1 - alpha;
935 s->b_double[0] = 1;
936 s->b_double[1] = -2 * cos(w0);
937 s->b_double[2] = 1;
938 break;
939 case lowpass:
940 if (s->poles == 1) {
941 s->a_double[0] = 1;
942 s->a_double[1] = -exp(-w0);
943 s->a_double[2] = 0;
944 s->b_double[0] = 1 + s->a_double[1];
945 s->b_double[1] = 0;
946 s->b_double[2] = 0;
947 } else {
948 s->a_double[0] = 1 + alpha;
949 s->a_double[1] = -2 * cos(w0);
950 s->a_double[2] = 1 - alpha;
951 s->b_double[0] = (1 - cos(w0)) / 2;
952 s->b_double[1] = 1 - cos(w0);
953 s->b_double[2] = (1 - cos(w0)) / 2;
954 }
955 break;
956 case highpass:
957 if (s->poles == 1) {
958 s->a_double[0] = 1;
959 s->a_double[1] = -exp(-w0);
960 s->a_double[2] = 0;
961 s->b_double[0] = (1 - s->a_double[1]) / 2;
962 s->b_double[1] = -s->b_double[0];
963 s->b_double[2] = 0;
964 } else {
965 s->a_double[0] = 1 + alpha;
966 s->a_double[1] = -2 * cos(w0);
967 s->a_double[2] = 1 - alpha;
968 s->b_double[0] = (1 + cos(w0)) / 2;
969 s->b_double[1] = -(1 + cos(w0));
970 s->b_double[2] = (1 + cos(w0)) / 2;
971 }
972 break;
973 case allpass:
974 switch (s->order) {
975 case 1:
976 s->a_double[0] = 1.;
977 s->a_double[1] = -(1. - K) / (1. + K);
978 s->a_double[2] = 0.;
979 s->b_double[0] = s->a_double[1];
980 s->b_double[1] = s->a_double[0];
981 s->b_double[2] = 0.;
982 break;
983 case 2:
984 s->a_double[0] = 1 + alpha;
985 s->a_double[1] = -2 * cos(w0);
986 s->a_double[2] = 1 - alpha;
987 s->b_double[0] = 1 - alpha;
988 s->b_double[1] = -2 * cos(w0);
989 s->b_double[2] = 1 + alpha;
990 break;
991 }
992 break;
993 default:
994 av_assert0(0);
995 }
996
997 av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n",
998 s->a_double[0], s->a_double[1], s->a_double[2],
999 s->b_double[0], s->b_double[1], s->b_double[2]);
1000
1001 s->a_double[1] /= s->a_double[0];
1002 s->a_double[2] /= s->a_double[0];
1003 s->b_double[0] /= s->a_double[0];
1004 s->b_double[1] /= s->a_double[0];
1005 s->b_double[2] /= s->a_double[0];
1006 s->a_double[0] /= s->a_double[0];
1007
1008 if (s->normalize && fabs(s->b_double[0] + s->b_double[1] + s->b_double[2]) > 1e-6) {
1009 double factor = (s->a_double[0] + s->a_double[1] + s->a_double[2]) /
1010 (s->b_double[0] + s->b_double[1] + s->b_double[2]);
1011
1012 s->b_double[0] *= factor;
1013 s->b_double[1] *= factor;
1014 s->b_double[2] *= factor;
1015 }
1016
1017 switch (s->filter_type) {
1018 case tiltshelf:
1019 s->b_double[0] /= A;
1020 s->b_double[1] /= A;
1021 s->b_double[2] /= A;
1022 break;
1023 }
1024
1025 if (!s->cache[0])
1026 s->cache[0] = ff_get_audio_buffer(outlink, 4 * sizeof(double));
1027 if (!s->clip)
1028 s->clip = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->clip));
1029 if (!s->cache[0] || !s->clip)
1030 return AVERROR(ENOMEM);
1031 if (reset) {
1032 av_samples_set_silence(s->cache[0]->extended_data, 0, s->cache[0]->nb_samples,
1033 s->cache[0]->ch_layout.nb_channels, s->cache[0]->format);
1034 }
1035
1036 if (reset && s->block_samples > 0) {
1037 if (!s->cache[1])
1038 s->cache[1] = ff_get_audio_buffer(outlink, 4 * sizeof(double));
1039 if (!s->cache[1])
1040 return AVERROR(ENOMEM);
1041 av_samples_set_silence(s->cache[1]->extended_data, 0, s->cache[1]->nb_samples,
1042 s->cache[1]->ch_layout.nb_channels, s->cache[1]->format);
1043 for (int i = 0; i < 3; i++) {
1044 if (!s->block[i])
1045 s->block[i] = ff_get_audio_buffer(outlink, s->block_samples * 2);
1046 if (!s->block[i])
1047 return AVERROR(ENOMEM);
1048 av_samples_set_silence(s->block[i]->extended_data, 0, s->block_samples * 2,
1049 s->block[i]->ch_layout.nb_channels, s->block[i]->format);
1050 }
1051 }
1052
1053 switch (s->transform_type) {
1054 case DI:
1055 switch (inlink->format) {
1056 case AV_SAMPLE_FMT_S16P:
1057 s->filter = biquad_s16;
1058 break;
1059 case AV_SAMPLE_FMT_S32P:
1060 s->filter = biquad_s32;
1061 break;
1062 case AV_SAMPLE_FMT_FLTP:
1063 s->filter = biquad_flt;
1064 break;
1065 case AV_SAMPLE_FMT_DBLP:
1066 s->filter = biquad_dbl;
1067 break;
1068 default: av_assert0(0);
1069 }
1070 break;
1071 case DII:
1072 switch (inlink->format) {
1073 case AV_SAMPLE_FMT_S16P:
1074 s->filter = biquad_dii_s16;
1075 break;
1076 case AV_SAMPLE_FMT_S32P:
1077 s->filter = biquad_dii_s32;
1078 break;
1079 case AV_SAMPLE_FMT_FLTP:
1080 s->filter = biquad_dii_flt;
1081 break;
1082 case AV_SAMPLE_FMT_DBLP:
1083 s->filter = biquad_dii_dbl;
1084 break;
1085 default: av_assert0(0);
1086 }
1087 break;
1088 case TDI:
1089 switch (inlink->format) {
1090 case AV_SAMPLE_FMT_S16P:
1091 s->filter = biquad_tdi_s16;
1092 break;
1093 case AV_SAMPLE_FMT_S32P:
1094 s->filter = biquad_tdi_s32;
1095 break;
1096 case AV_SAMPLE_FMT_FLTP:
1097 s->filter = biquad_tdi_flt;
1098 break;
1099 case AV_SAMPLE_FMT_DBLP:
1100 s->filter = biquad_tdi_dbl;
1101 break;
1102 default: av_assert0(0);
1103 }
1104 break;
1105 case TDII:
1106 switch (inlink->format) {
1107 case AV_SAMPLE_FMT_S16P:
1108 s->filter = biquad_tdii_s16;
1109 break;
1110 case AV_SAMPLE_FMT_S32P:
1111 s->filter = biquad_tdii_s32;
1112 break;
1113 case AV_SAMPLE_FMT_FLTP:
1114 s->filter = biquad_tdii_flt;
1115 break;
1116 case AV_SAMPLE_FMT_DBLP:
1117 s->filter = biquad_tdii_dbl;
1118 break;
1119 default: av_assert0(0);
1120 }
1121 break;
1122 case LATT:
1123 switch (inlink->format) {
1124 case AV_SAMPLE_FMT_S16P:
1125 s->filter = biquad_latt_s16;
1126 break;
1127 case AV_SAMPLE_FMT_S32P:
1128 s->filter = biquad_latt_s32;
1129 break;
1130 case AV_SAMPLE_FMT_FLTP:
1131 s->filter = biquad_latt_flt;
1132 break;
1133 case AV_SAMPLE_FMT_DBLP:
1134 s->filter = biquad_latt_dbl;
1135 break;
1136 default: av_assert0(0);
1137 }
1138 break;
1139 case SVF:
1140 switch (inlink->format) {
1141 case AV_SAMPLE_FMT_S16P:
1142 s->filter = biquad_svf_s16;
1143 break;
1144 case AV_SAMPLE_FMT_S32P:
1145 s->filter = biquad_svf_s32;
1146 break;
1147 case AV_SAMPLE_FMT_FLTP:
1148 s->filter = biquad_svf_flt;
1149 break;
1150 case AV_SAMPLE_FMT_DBLP:
1151 s->filter = biquad_svf_dbl;
1152 break;
1153 default: av_assert0(0);
1154 }
1155 break;
1156 case ZDF:
1157 switch (inlink->format) {
1158 case AV_SAMPLE_FMT_S16P:
1159 s->filter = biquad_zdf_s16;
1160 break;
1161 case AV_SAMPLE_FMT_S32P:
1162 s->filter = biquad_zdf_s32;
1163 break;
1164 case AV_SAMPLE_FMT_FLTP:
1165 s->filter = biquad_zdf_flt;
1166 break;
1167 case AV_SAMPLE_FMT_DBLP:
1168 s->filter = biquad_zdf_dbl;
1169 break;
1170 default: av_assert0(0);
1171 }
1172 break;
1173 default:
1174 av_assert0(0);
1175 }
1176
1177 s->block_align = av_get_bytes_per_sample(inlink->format);
1178
1179 if (s->transform_type == LATT)
1180 convert_dir2latt(s);
1181 else if (s->transform_type == SVF)
1182 convert_dir2svf(s);
1183 else if (s->transform_type == ZDF)
1184 convert_dir2zdf(s, inlink->sample_rate);
1185
1186 s->a_float[0] = s->a_double[0];
1187 s->a_float[1] = s->a_double[1];
1188 s->a_float[2] = s->a_double[2];
1189 s->b_float[0] = s->b_double[0];
1190 s->b_float[1] = s->b_double[1];
1191 s->b_float[2] = s->b_double[2];
1192
1193 return 0;
1194 }
1195
1196 static int config_output(AVFilterLink *outlink)
1197 {
1198 return config_filter(outlink, 1);
1199 }
1200
1201 typedef struct ThreadData {
1202 AVFrame *in, *out;
1203 int eof;
1204 } ThreadData;
1205
1206 static void reverse_samples(AVFrame *out, AVFrame *in, int p,
1207 int oo, int io, int nb_samples)
1208 {
1209 switch (out->format) {
1210 case AV_SAMPLE_FMT_S16P: {
1211 const int16_t *src = ((const int16_t *)in->extended_data[p]) + io;
1212 int16_t *dst = ((int16_t *)out->extended_data[p]) + oo;
1213 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1214 dst[i] = src[j];
1215 }
1216 break;
1217 case AV_SAMPLE_FMT_S32P: {
1218 const int32_t *src = ((const int32_t *)in->extended_data[p]) + io;
1219 int32_t *dst = ((int32_t *)out->extended_data[p]) + oo;
1220 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1221 dst[i] = src[j];
1222 }
1223 break;
1224 case AV_SAMPLE_FMT_FLTP: {
1225 const float *src = ((const float *)in->extended_data[p]) + io;
1226 float *dst = ((float *)out->extended_data[p]) + oo;
1227 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1228 dst[i] = src[j];
1229 }
1230 break;
1231 case AV_SAMPLE_FMT_DBLP: {
1232 const double *src = ((const double *)in->extended_data[p]) + io;
1233 double *dst = ((double *)out->extended_data[p]) + oo;
1234 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1235 dst[i] = src[j];
1236 }
1237 break;
1238 }
1239 }
1240
1241 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1242 {
1243 AVFilterLink *inlink = ctx->inputs[0];
1244 ThreadData *td = arg;
1245 AVFrame *buf = td->in;
1246 AVFrame *out_buf = td->out;
1247 BiquadsContext *s = ctx->priv;
1248 const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
1249 const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1250 int ch;
1251
1252 for (ch = start; ch < end; ch++) {
1253 enum AVChannel channel = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
1254
1255 if (av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0) {
1256 if (buf != out_buf)
1257 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
1258 buf->nb_samples * s->block_align);
1259 continue;
1260 }
1261
1262 if (!s->block_samples) {
1263 s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
1264 s->cache[0]->extended_data[ch], s->clip+ch, ctx->is_disabled);
1265 } else if (td->eof) {
1266 memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch] + s->block_align * s->block_samples,
1267 s->nb_samples * s->block_align);
1268 } else {
1269 memcpy(s->block[0]->extended_data[ch] + s->block_align * s->block_samples, buf->extended_data[ch],
1270 buf->nb_samples * s->block_align);
1271 memset(s->block[0]->extended_data[ch] + s->block_align * (s->block_samples + buf->nb_samples),
1272 0, (s->block_samples - buf->nb_samples) * s->block_align);
1273 s->filter(s, s->block[0]->extended_data[ch], s->block[1]->extended_data[ch], s->block_samples,
1274 s->cache[0]->extended_data[ch], s->clip+ch, ctx->is_disabled);
1275 av_samples_copy(s->cache[1]->extended_data, s->cache[0]->extended_data, 0, 0,
1276 s->cache[0]->nb_samples, s->cache[0]->ch_layout.nb_channels,
1277 s->cache[0]->format);
1278 s->filter(s, s->block[0]->extended_data[ch] + s->block_samples * s->block_align,
1279 s->block[1]->extended_data[ch] + s->block_samples * s->block_align,
1280 s->block_samples, s->cache[1]->extended_data[ch], s->clip+ch,
1281 ctx->is_disabled);
1282 reverse_samples(s->block[2], s->block[1], ch, 0, 0, 2 * s->block_samples);
1283 av_samples_set_silence(s->cache[1]->extended_data, 0, s->cache[1]->nb_samples,
1284 s->cache[1]->ch_layout.nb_channels, s->cache[1]->format);
1285 s->filter(s, s->block[2]->extended_data[ch], s->block[2]->extended_data[ch], 2 * s->block_samples,
1286 s->cache[1]->extended_data[ch], s->clip+ch, ctx->is_disabled);
1287 reverse_samples(s->block[1], s->block[2], ch, 0, 0, 2 * s->block_samples);
1288 memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch],
1289 s->block_samples * s->block_align);
1290 memmove(s->block[0]->extended_data[ch], s->block[0]->extended_data[ch] + s->block_align * s->block_samples,
1291 s->block_samples * s->block_align);
1292 }
1293 }
1294
1295 return 0;
1296 }
1297
1298 static int filter_frame(AVFilterLink *inlink, AVFrame *buf, int eof)
1299 {
1300 AVFilterContext *ctx = inlink->dst;
1301 BiquadsContext *s = ctx->priv;
1302 AVFilterLink *outlink = ctx->outputs[0];
1303 AVFrame *out_buf;
1304 ThreadData td;
1305 int ch, ret, drop = 0;
1306
1307 if (s->bypass)
1308 return ff_filter_frame(outlink, buf);
1309
1310 ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout);
1311 if (ret < 0) {
1312 av_frame_free(&buf);
1313 return ret;
1314 }
1315 if (strcmp(s->ch_layout_str, "all"))
1316 av_channel_layout_from_string(&s->ch_layout,
1317 s->ch_layout_str);
1318
1319 if (av_frame_is_writable(buf) && s->block_samples == 0) {
1320 out_buf = buf;
1321 } else {
1322 out_buf = ff_get_audio_buffer(outlink, s->block_samples > 0 ? s->block_samples : buf->nb_samples);
1323 if (!out_buf) {
1324 av_frame_free(&buf);
1325 return AVERROR(ENOMEM);
1326 }
1327 av_frame_copy_props(out_buf, buf);
1328 }
1329
1330 if (s->block_samples > 0 && s->pts == AV_NOPTS_VALUE)
1331 drop = 1;
1332 td.in = buf;
1333 td.out = out_buf;
1334 td.eof = eof;
1335 ff_filter_execute(ctx, filter_channel, &td, NULL,
1336 FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
1337
1338 for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
1339 if (s->clip[ch] > 0)
1340 av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
1341 ch, s->clip[ch]);
1342 s->clip[ch] = 0;
1343 }
1344
1345 if (s->block_samples > 0) {
1346 int nb_samples = buf->nb_samples;
1347 int64_t pts = buf->pts;
1348
1349 out_buf->pts = s->pts;
1350 out_buf->nb_samples = s->nb_samples;
1351 s->pts = pts;
1352 s->nb_samples = nb_samples;
1353 }
1354
1355 if (buf != out_buf)
1356 av_frame_free(&buf);
1357
1358 if (!drop)
1359 return ff_filter_frame(outlink, out_buf);
1360 else {
1361 av_frame_free(&out_buf);
1362 ff_filter_set_ready(ctx, 10);
1363 return 0;
1364 }
1365 }
1366
1367 static int activate(AVFilterContext *ctx)
1368 {
1369 AVFilterLink *inlink = ctx->inputs[0];
1370 AVFilterLink *outlink = ctx->outputs[0];
1371 BiquadsContext *s = ctx->priv;
1372 AVFrame *in = NULL;
1373 int64_t pts;
1374 int status;
1375 int ret;
1376
1377 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
1378
1379 if (s->block_samples > 0) {
1380 ret = ff_inlink_consume_samples(inlink, s->block_samples, s->block_samples, &in);
1381 } else {
1382 ret = ff_inlink_consume_frame(inlink, &in);
1383 }
1384 if (ret < 0)
1385 return ret;
1386 if (ret > 0)
1387 return filter_frame(inlink, in, 0);
1388
1389 if (s->block_samples > 0 && ff_inlink_queued_samples(inlink) >= s->block_samples) {
1390 ff_filter_set_ready(ctx, 10);
1391 return 0;
1392 }
1393
1394 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1395 if (s->block_samples > 0) {
1396 AVFrame *in = ff_get_audio_buffer(outlink, s->block_samples);
1397 if (!in)
1398 return AVERROR(ENOMEM);
1399
1400 ret = filter_frame(inlink, in, 1);
1401 }
1402
1403 ff_outlink_set_status(outlink, status, pts);
1404
1405 return ret;
1406 }
1407
1408 FF_FILTER_FORWARD_WANTED(outlink, inlink);
1409
1410 return FFERROR_NOT_READY;
1411 }
1412
1413 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1414 char *res, int res_len, int flags)
1415 {
1416 AVFilterLink *outlink = ctx->outputs[0];
1417 int ret;
1418
1419 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1420 if (ret < 0)
1421 return ret;
1422
1423 return config_filter(outlink, 0);
1424 }
1425
1426 static av_cold void uninit(AVFilterContext *ctx)
1427 {
1428 BiquadsContext *s = ctx->priv;
1429
1430 for (int i = 0; i < 3; i++)
1431 av_frame_free(&s->block[i]);
1432 av_frame_free(&s->cache[0]);
1433 av_frame_free(&s->cache[1]);
1434 av_freep(&s->clip);
1435 av_channel_layout_uninit(&s->ch_layout);
1436 }
1437
1438 static const AVFilterPad outputs[] = {
1439 {
1440 .name = "default",
1441 .type = AVMEDIA_TYPE_AUDIO,
1442 .config_props = config_output,
1443 },
1444 };
1445
1446 #define OFFSET(x) offsetof(BiquadsContext, x)
1447 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1448 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1449
1450 #define DEFINE_BIQUAD_FILTER_2(name_, description_, priv_class_) \
1451 static av_cold int name_##_init(AVFilterContext *ctx) \
1452 { \
1453 BiquadsContext *s = ctx->priv; \
1454 s->filter_type = name_; \
1455 s->pts = AV_NOPTS_VALUE; \
1456 return 0; \
1457 } \
1458 \
1459 const FFFilter ff_af_##name_ = { \
1460 .p.name = #name_, \
1461 .p.description = NULL_IF_CONFIG_SMALL(description_), \
1462 .p.priv_class = &priv_class_##_class, \
1463 .p.flags = AVFILTER_FLAG_SLICE_THREADS | \
1464 AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
1465 .priv_size = sizeof(BiquadsContext), \
1466 .init = name_##_init, \
1467 .activate = activate, \
1468 .uninit = uninit, \
1469 FILTER_INPUTS(ff_audio_default_filterpad), \
1470 FILTER_OUTPUTS(outputs), \
1471 FILTER_QUERY_FUNC2(query_formats), \
1472 .process_command = process_command, \
1473 }
1474
1475 #define DEFINE_BIQUAD_FILTER(name, description) \
1476 AVFILTER_DEFINE_CLASS(name); \
1477 DEFINE_BIQUAD_FILTER_2(name, description, name)
1478
1479 #define WIDTH_OPTION(x) \
1480 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 99999, FLAGS}, \
1481 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 99999, FLAGS}
1482
1483 #define WIDTH_TYPE_OPTION(x) \
1484 {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=x}, HERTZ, NB_WTYPE-1, FLAGS, .unit = "width_type"}, \
1485 {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=x}, HERTZ, NB_WTYPE-1, FLAGS, .unit = "width_type"}, \
1486 {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, .unit = "width_type"}, \
1487 {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, .unit = "width_type"}, \
1488 {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, .unit = "width_type"}, \
1489 {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, .unit = "width_type"}, \
1490 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, .unit = "width_type"}
1491
1492 #define MIX_CHANNELS_NORMALIZE_OPTION(x, y, z) \
1493 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 1, FLAGS}, \
1494 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 1, FLAGS}, \
1495 {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str=y}, 0, 0, FLAGS}, \
1496 {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str=y}, 0, 0, FLAGS}, \
1497 {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=z}, 0, 1, FLAGS}, \
1498 {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=z}, 0, 1, FLAGS}
1499
1500 #define TRANSFORM_OPTION(x) \
1501 {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=x}, 0, NB_TTYPE-1, AF, .unit = "transform_type"}, \
1502 {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=x}, 0, NB_TTYPE-1, AF, .unit = "transform_type"}, \
1503 {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, .unit = "transform_type"}, \
1504 {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, .unit = "transform_type"}, \
1505 {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, .unit = "transform_type"}, \
1506 {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, .unit = "transform_type"}, \
1507 {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, .unit = "transform_type"}, \
1508 {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, .unit = "transform_type"}, \
1509 {"zdf", "zero-delay filter form", 0, AV_OPT_TYPE_CONST, {.i64=ZDF}, 0, 0, AF, .unit = "transform_type"}
1510
1511 #define PRECISION_OPTION(x) \
1512 {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=x}, -1, 3, AF, .unit = "precision"}, \
1513 {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=x}, -1, 3, AF, .unit = "precision"}, \
1514 {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, .unit = "precision"}, \
1515 {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "precision"}, \
1516 {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "precision"}, \
1517 {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "precision"}, \
1518 {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, .unit = "precision"}
1519
1520 #define BLOCKSIZE_OPTION(x) \
1521 {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=x}, 0, 32768, AF}, \
1522 {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=x}, 0, 32768, AF}
1523
1524 #if CONFIG_EQUALIZER_FILTER
1525 static const AVOption equalizer_options[] = {
1526 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
1527 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
1528 WIDTH_TYPE_OPTION(QFACTOR),
1529 WIDTH_OPTION(1.0),
1530 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1531 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1532 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1533 TRANSFORM_OPTION(DI),
1534 PRECISION_OPTION(-1),
1535 BLOCKSIZE_OPTION(0),
1536 {NULL}
1537 };
1538
1539 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
1540 #endif /* CONFIG_EQUALIZER_FILTER */
1541 #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER
1542 static const AVOption bass_lowshelf_options[] = {
1543 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1544 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1545 WIDTH_TYPE_OPTION(QFACTOR),
1546 WIDTH_OPTION(0.5),
1547 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1548 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1549 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1550 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1551 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1552 TRANSFORM_OPTION(DI),
1553 PRECISION_OPTION(-1),
1554 BLOCKSIZE_OPTION(0),
1555 {NULL}
1556 };
1557
1558 AVFILTER_DEFINE_CLASS_EXT(bass_lowshelf, "bass/lowshelf", bass_lowshelf_options);
1559 #if CONFIG_BASS_FILTER
1560 DEFINE_BIQUAD_FILTER_2(bass, "Boost or cut lower frequencies.", bass_lowshelf);
1561 #endif /* CONFIG_BASS_FILTER */
1562
1563 #if CONFIG_LOWSHELF_FILTER
1564 DEFINE_BIQUAD_FILTER_2(lowshelf, "Apply a low shelf filter.", bass_lowshelf);
1565 #endif /* CONFIG_LOWSHELF_FILTER */
1566 #endif /* CONFIG_BASS_FILTER || CONFIG LOWSHELF_FILTER */
1567 #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER || CONFIG_TILTSHELF_FILTER
1568 static const AVOption treble_highshelf_options[] = {
1569 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1570 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1571 WIDTH_TYPE_OPTION(QFACTOR),
1572 WIDTH_OPTION(0.5),
1573 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1574 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1575 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1576 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1577 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1578 TRANSFORM_OPTION(DI),
1579 PRECISION_OPTION(-1),
1580 BLOCKSIZE_OPTION(0),
1581 {NULL}
1582 };
1583
1584 AVFILTER_DEFINE_CLASS_EXT(treble_highshelf, "treble/high/tiltshelf",
1585 treble_highshelf_options);
1586
1587 #if CONFIG_TREBLE_FILTER
1588 DEFINE_BIQUAD_FILTER_2(treble, "Boost or cut upper frequencies.", treble_highshelf);
1589 #endif /* CONFIG_TREBLE_FILTER */
1590
1591 #if CONFIG_HIGHSHELF_FILTER
1592 DEFINE_BIQUAD_FILTER_2(highshelf, "Apply a high shelf filter.", treble_highshelf);
1593 #endif /* CONFIG_HIGHSHELF_FILTER */
1594
1595 #if CONFIG_TILTSHELF_FILTER
1596 DEFINE_BIQUAD_FILTER_2(tiltshelf, "Apply a tilt shelf filter.", treble_highshelf);
1597 #endif
1598 #endif /* CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER || CONFIG_TILTSHELF_FILTER */
1599
1600 #if CONFIG_BANDPASS_FILTER
1601 static const AVOption bandpass_options[] = {
1602 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1603 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1604 WIDTH_TYPE_OPTION(QFACTOR),
1605 WIDTH_OPTION(0.5),
1606 {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1607 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1608 TRANSFORM_OPTION(DI),
1609 PRECISION_OPTION(-1),
1610 BLOCKSIZE_OPTION(0),
1611 {NULL}
1612 };
1613
1614 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
1615 #endif /* CONFIG_BANDPASS_FILTER */
1616 #if CONFIG_BANDREJECT_FILTER
1617 static const AVOption bandreject_options[] = {
1618 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1619 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1620 WIDTH_TYPE_OPTION(QFACTOR),
1621 WIDTH_OPTION(0.5),
1622 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1623 TRANSFORM_OPTION(DI),
1624 PRECISION_OPTION(-1),
1625 BLOCKSIZE_OPTION(0),
1626 {NULL}
1627 };
1628
1629 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
1630 #endif /* CONFIG_BANDREJECT_FILTER */
1631 #if CONFIG_LOWPASS_FILTER
1632 static const AVOption lowpass_options[] = {
1633 {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1634 {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1635 WIDTH_TYPE_OPTION(QFACTOR),
1636 WIDTH_OPTION(0.707),
1637 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1638 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1639 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1640 TRANSFORM_OPTION(DI),
1641 PRECISION_OPTION(-1),
1642 BLOCKSIZE_OPTION(0),
1643 {NULL}
1644 };
1645
1646 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
1647 #endif /* CONFIG_LOWPASS_FILTER */
1648 #if CONFIG_HIGHPASS_FILTER
1649 static const AVOption highpass_options[] = {
1650 {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1651 {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1652 WIDTH_TYPE_OPTION(QFACTOR),
1653 WIDTH_OPTION(0.707),
1654 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1655 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1656 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1657 TRANSFORM_OPTION(DI),
1658 PRECISION_OPTION(-1),
1659 BLOCKSIZE_OPTION(0),
1660 {NULL}
1661 };
1662
1663 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
1664 #endif /* CONFIG_HIGHPASS_FILTER */
1665 #if CONFIG_ALLPASS_FILTER
1666 static const AVOption allpass_options[] = {
1667 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1668 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1669 WIDTH_TYPE_OPTION(QFACTOR),
1670 WIDTH_OPTION(0.707),
1671 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1672 {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1673 {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1674 TRANSFORM_OPTION(DI),
1675 PRECISION_OPTION(-1),
1676 {NULL}
1677 };
1678
1679 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
1680 #endif /* CONFIG_ALLPASS_FILTER */
1681 #if CONFIG_BIQUAD_FILTER
1682 static const AVOption biquad_options[] = {
1683 {"a0", NULL, OFFSET(oa[0]), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
1684 {"a1", NULL, OFFSET(oa[1]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1685 {"a2", NULL, OFFSET(oa[2]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1686 {"b0", NULL, OFFSET(ob[0]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1687 {"b1", NULL, OFFSET(ob[1]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1688 {"b2", NULL, OFFSET(ob[2]), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1689 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1690 TRANSFORM_OPTION(DI),
1691 PRECISION_OPTION(-1),
1692 BLOCKSIZE_OPTION(0),
1693 {NULL}
1694 };
1695
1696 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
1697 #endif /* CONFIG_BIQUAD_FILTER */
1698