FFmpeg
af_biquads.c
Go to the documentation of this file.
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 "libavutil/avassert.h"
67 #include "libavutil/ffmath.h"
68 #include "libavutil/opt.h"
69 #include "audio.h"
70 #include "avfilter.h"
71 #include "internal.h"
72 
73 enum FilterType {
85 };
86 
87 enum WidthType {
95 };
96 
98  DI,
99  DII,
104 };
105 
106 typedef struct ChanCache {
107  double i1, i2;
108  double o1, o2;
110 } ChanCache;
111 
112 typedef struct BiquadsContext {
113  const AVClass *class;
114 
117  int poles;
118  int csg;
121 
122  int bypass;
123 
124  double gain;
125  double frequency;
126  double width;
127  double mix;
128  uint64_t channels;
130  int order;
131 
132  double a0, a1, a2;
133  double b0, b1, b2;
134 
135  double oa0, oa1, oa2;
136  double ob0, ob1, ob2;
137 
140 
141  void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
142  double *i1, double *i2, double *o1, double *o2,
143  double b0, double b1, double b2, double a1, double a2, int *clippings,
144  int disabled);
146 
148 {
149  BiquadsContext *s = ctx->priv;
150  static const enum AVSampleFormat auto_sample_fmts[] = {
156  };
157  enum AVSampleFormat sample_fmts[] = {
160  };
161  const enum AVSampleFormat *sample_fmts_list = sample_fmts;
163  if (ret < 0)
164  return ret;
165 
166  switch (s->precision) {
167  case 0:
169  break;
170  case 1:
172  break;
173  case 2:
175  break;
176  case 3:
178  break;
179  default:
180  sample_fmts_list = auto_sample_fmts;
181  break;
182  }
183  ret = ff_set_common_formats_from_list(ctx, sample_fmts_list);
184  if (ret < 0)
185  return ret;
186 
188 }
189 
190 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
191 static void biquad_## name (BiquadsContext *s, \
192  const void *input, void *output, int len, \
193  double *in1, double *in2, \
194  double *out1, double *out2, \
195  double b0, double b1, double b2, \
196  double a1, double a2, int *clippings, \
197  int disabled) \
198 { \
199  const type *ibuf = input; \
200  type *obuf = output; \
201  double i1 = *in1; \
202  double i2 = *in2; \
203  double o1 = *out1; \
204  double o2 = *out2; \
205  double wet = s->mix; \
206  double dry = 1. - wet; \
207  double out; \
208  int i; \
209  a1 = -a1; \
210  a2 = -a2; \
211  \
212  for (i = 0; i+1 < len; i++) { \
213  o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
214  i2 = ibuf[i]; \
215  out = o2 * wet + i2 * dry; \
216  if (disabled) { \
217  obuf[i] = i2; \
218  } else if (need_clipping && out < min) { \
219  (*clippings)++; \
220  obuf[i] = min; \
221  } else if (need_clipping && out > max) { \
222  (*clippings)++; \
223  obuf[i] = max; \
224  } else { \
225  obuf[i] = out; \
226  } \
227  i++; \
228  o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
229  i1 = ibuf[i]; \
230  out = o1 * wet + i1 * dry; \
231  if (disabled) { \
232  obuf[i] = i1; \
233  } else if (need_clipping && out < min) { \
234  (*clippings)++; \
235  obuf[i] = min; \
236  } else if (need_clipping && out > max) { \
237  (*clippings)++; \
238  obuf[i] = max; \
239  } else { \
240  obuf[i] = out; \
241  } \
242  } \
243  if (i < len) { \
244  double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
245  i2 = i1; \
246  i1 = ibuf[i]; \
247  o2 = o1; \
248  o1 = o0; \
249  out = o0 * wet + i1 * dry; \
250  if (disabled) { \
251  obuf[i] = i1; \
252  } else if (need_clipping && out < min) { \
253  (*clippings)++; \
254  obuf[i] = min; \
255  } else if (need_clipping && out > max) { \
256  (*clippings)++; \
257  obuf[i] = max; \
258  } else { \
259  obuf[i] = out; \
260  } \
261  } \
262  *in1 = i1; \
263  *in2 = i2; \
264  *out1 = o1; \
265  *out2 = o2; \
266 }
267 
268 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
269 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
270 BIQUAD_FILTER(flt, float, -1., 1., 0)
271 BIQUAD_FILTER(dbl, double, -1., 1., 0)
272 
273 #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \
274 static void biquad_dii_## name (BiquadsContext *s, \
275  const void *input, void *output, int len, \
276  double *z1, double *z2, \
277  double *unused1, double *unused2, \
278  double b0, double b1, double b2, \
279  double a1, double a2, int *clippings, \
280  int disabled) \
281 { \
282  const type *ibuf = input; \
283  type *obuf = output; \
284  double w1 = *z1; \
285  double w2 = *z2; \
286  double wet = s->mix; \
287  double dry = 1. - wet; \
288  double in, out, w0; \
289  \
290  a1 = -a1; \
291  a2 = -a2; \
292  \
293  for (int i = 0; i < len; i++) { \
294  in = ibuf[i]; \
295  w0 = in + a1 * w1 + a2 * w2; \
296  out = b0 * w0 + b1 * w1 + b2 * w2; \
297  w2 = w1; \
298  w1 = w0; \
299  out = out * wet + in * dry; \
300  if (disabled) { \
301  obuf[i] = in; \
302  } else if (need_clipping && out < min) { \
303  (*clippings)++; \
304  obuf[i] = min; \
305  } else if (need_clipping && out > max) { \
306  (*clippings)++; \
307  obuf[i] = max; \
308  } else { \
309  obuf[i] = out; \
310  } \
311  } \
312  *z1 = w1; \
313  *z2 = w2; \
314 }
315 
316 BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
317 BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
318 BIQUAD_DII_FILTER(flt, float, -1., 1., 0)
319 BIQUAD_DII_FILTER(dbl, double, -1., 1., 0)
320 
321 #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \
322 static void biquad_tdii_## name (BiquadsContext *s, \
323  const void *input, void *output, int len, \
324  double *z1, double *z2, \
325  double *unused1, double *unused2, \
326  double b0, double b1, double b2, \
327  double a1, double a2, int *clippings, \
328  int disabled) \
329 { \
330  const type *ibuf = input; \
331  type *obuf = output; \
332  double w1 = *z1; \
333  double w2 = *z2; \
334  double wet = s->mix; \
335  double dry = 1. - wet; \
336  double in, out; \
337  \
338  a1 = -a1; \
339  a2 = -a2; \
340  \
341  for (int i = 0; i < len; i++) { \
342  in = ibuf[i]; \
343  out = b0 * in + w1; \
344  w1 = b1 * in + w2 + a1 * out; \
345  w2 = b2 * in + a2 * out; \
346  out = out * wet + in * dry; \
347  if (disabled) { \
348  obuf[i] = in; \
349  } else if (need_clipping && out < min) { \
350  (*clippings)++; \
351  obuf[i] = min; \
352  } else if (need_clipping && out > max) { \
353  (*clippings)++; \
354  obuf[i] = max; \
355  } else { \
356  obuf[i] = out; \
357  } \
358  } \
359  *z1 = w1; \
360  *z2 = w2; \
361 }
362 
363 BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
364 BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
365 BIQUAD_TDII_FILTER(flt, float, -1., 1., 0)
366 BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0)
367 
368 #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \
369 static void biquad_latt_## name (BiquadsContext *s, \
370  const void *input, void *output, int len, \
371  double *z1, double *z2, \
372  double *unused1, double *unused2, \
373  double v0, double v1, double v2, \
374  double k0, double k1, int *clippings, \
375  int disabled) \
376 { \
377  const type *ibuf = input; \
378  type *obuf = output; \
379  double s0 = *z1; \
380  double s1 = *z2; \
381  double wet = s->mix; \
382  double dry = 1. - wet; \
383  double in, out; \
384  double t0, t1; \
385  \
386  for (int i = 0; i < len; i++) { \
387  out = 0.; \
388  in = ibuf[i]; \
389  t0 = in - k1 * s0; \
390  t1 = t0 * k1 + s0; \
391  out += t1 * v2; \
392  \
393  t0 = t0 - k0 * s1; \
394  t1 = t0 * k0 + s1; \
395  out += t1 * v1; \
396  \
397  out += t0 * v0; \
398  s0 = t1; \
399  s1 = t0; \
400  \
401  out = out * wet + in * dry; \
402  if (disabled) { \
403  obuf[i] = in; \
404  } else if (need_clipping && out < min) { \
405  (*clippings)++; \
406  obuf[i] = min; \
407  } else if (need_clipping && out > max) { \
408  (*clippings)++; \
409  obuf[i] = max; \
410  } else { \
411  obuf[i] = out; \
412  } \
413  } \
414  *z1 = s0; \
415  *z2 = s1; \
416 }
417 
418 BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
419 BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
420 BIQUAD_LATT_FILTER(flt, float, -1., 1., 0)
421 BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0)
422 
423 #define BIQUAD_SVF_FILTER(name, type, min, max, need_clipping) \
424 static void biquad_svf_## name (BiquadsContext *s, \
425  const void *input, void *output, int len, \
426  double *y0, double *y1, \
427  double *unused1, double *unused2, \
428  double b0, double b1, double b2, \
429  double a1, double a2, int *clippings, \
430  int disabled) \
431 { \
432  const type *ibuf = input; \
433  type *obuf = output; \
434  double s0 = *y0; \
435  double s1 = *y1; \
436  double wet = s->mix; \
437  double dry = 1. - wet; \
438  double in, out; \
439  double t0, t1; \
440  \
441  for (int i = 0; i < len; i++) { \
442  in = ibuf[i]; \
443  out = b2 * in + s0; \
444  t0 = b0 * in + a1 * s0 + s1; \
445  t1 = b1 * in + a2 * s0; \
446  s0 = t0; \
447  s1 = t1; \
448  \
449  out = out * wet + in * dry; \
450  if (disabled) { \
451  obuf[i] = in; \
452  } else if (need_clipping && out < min) { \
453  (*clippings)++; \
454  obuf[i] = min; \
455  } else if (need_clipping && out > max) { \
456  (*clippings)++; \
457  obuf[i] = max; \
458  } else { \
459  obuf[i] = out; \
460  } \
461  } \
462  *y0 = s0; \
463  *y1 = s1; \
464 }
465 
466 BIQUAD_SVF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
467 BIQUAD_SVF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
468 BIQUAD_SVF_FILTER(flt, float, -1., 1., 0)
469 BIQUAD_SVF_FILTER(dbl, double, -1., 1., 0)
470 
472 {
473  double k0, k1, v0, v1, v2;
474 
475  k1 = s->a2;
476  k0 = s->a1 / (1. + k1);
477  v2 = s->b2;
478  v1 = s->b1 - v2 * s->a1;
479  v0 = s->b0 - v1 * k0 - v2 * k1;
480 
481  s->a1 = k0;
482  s->a2 = k1;
483  s->b0 = v0;
484  s->b1 = v1;
485  s->b2 = v2;
486 }
487 
489 {
490  double a[2];
491  double b[3];
492 
493  a[0] = -s->a1;
494  a[1] = -s->a2;
495  b[0] = s->b1 - s->a1 * s->b0;
496  b[1] = s->b2 - s->a2 * s->b0;
497  b[2] = s->b0;
498 
499  s->a1 = a[0];
500  s->a2 = a[1];
501  s->b0 = b[0];
502  s->b1 = b[1];
503  s->b2 = b[2];
504 }
505 
506 static int config_filter(AVFilterLink *outlink, int reset)
507 {
508  AVFilterContext *ctx = outlink->src;
509  BiquadsContext *s = ctx->priv;
510  AVFilterLink *inlink = ctx->inputs[0];
511  double A = ff_exp10(s->gain / 40);
512  double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
513  double K = tan(w0 / 2.);
514  double alpha, beta;
515 
516  s->bypass = (((w0 > M_PI || w0 <= 0.) && reset) || (s->width <= 0.)) && (s->filter_type != biquad);
517  if (s->bypass) {
518  av_log(ctx, AV_LOG_WARNING, "Invalid frequency and/or width!\n");
519  return 0;
520  }
521 
522  if ((w0 > M_PI || w0 <= 0.) && (s->filter_type != biquad))
523  return AVERROR(EINVAL);
524 
525  switch (s->width_type) {
526  case NONE:
527  alpha = 0.0;
528  break;
529  case HERTZ:
530  alpha = sin(w0) / (2 * s->frequency / s->width);
531  break;
532  case KHERTZ:
533  alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
534  break;
535  case OCTAVE:
536  alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
537  break;
538  case QFACTOR:
539  alpha = sin(w0) / (2 * s->width);
540  break;
541  case SLOPE:
542  alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
543  break;
544  default:
545  av_assert0(0);
546  }
547 
548  beta = 2 * sqrt(A);
549 
550  switch (s->filter_type) {
551  case biquad:
552  s->a0 = s->oa0;
553  s->a1 = s->oa1;
554  s->a2 = s->oa2;
555  s->b0 = s->ob0;
556  s->b1 = s->ob1;
557  s->b2 = s->ob2;
558  break;
559  case equalizer:
560  s->a0 = 1 + alpha / A;
561  s->a1 = -2 * cos(w0);
562  s->a2 = 1 - alpha / A;
563  s->b0 = 1 + alpha * A;
564  s->b1 = -2 * cos(w0);
565  s->b2 = 1 - alpha * A;
566  break;
567  case bass:
568  beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
569  case lowshelf:
570  if (s->poles == 1) {
571  double A = ff_exp10(s->gain / 20);
572  double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
573  double n = (A + 1) / (A - 1);
574  double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
575  double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
576  double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
577 
578  s->a0 = 1 + ro * alpha1;
579  s->a1 = -ro - alpha1;
580  s->a2 = 0;
581  s->b0 = beta0 + ro * beta1;
582  s->b1 = -beta1 - ro * beta0;
583  s->b2 = 0;
584  } else {
585  s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
586  s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
587  s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
588  s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
589  s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
590  s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
591  }
592  break;
593  case treble:
594  beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
595  case highshelf:
596  if (s->poles == 1) {
597  double A = ff_exp10(s->gain / 20);
598  double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
599  double n = (A + 1) / (A - 1);
600  double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
601  double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
602  double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
603 
604  s->a0 = 1 + ro * alpha1;
605  s->a1 = ro + alpha1;
606  s->a2 = 0;
607  s->b0 = beta0 + ro * beta1;
608  s->b1 = beta1 + ro * beta0;
609  s->b2 = 0;
610  } else {
611  s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
612  s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
613  s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
614  s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
615  s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
616  s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
617  }
618  break;
619  case bandpass:
620  if (s->csg) {
621  s->a0 = 1 + alpha;
622  s->a1 = -2 * cos(w0);
623  s->a2 = 1 - alpha;
624  s->b0 = sin(w0) / 2;
625  s->b1 = 0;
626  s->b2 = -sin(w0) / 2;
627  } else {
628  s->a0 = 1 + alpha;
629  s->a1 = -2 * cos(w0);
630  s->a2 = 1 - alpha;
631  s->b0 = alpha;
632  s->b1 = 0;
633  s->b2 = -alpha;
634  }
635  break;
636  case bandreject:
637  s->a0 = 1 + alpha;
638  s->a1 = -2 * cos(w0);
639  s->a2 = 1 - alpha;
640  s->b0 = 1;
641  s->b1 = -2 * cos(w0);
642  s->b2 = 1;
643  break;
644  case lowpass:
645  if (s->poles == 1) {
646  s->a0 = 1;
647  s->a1 = -exp(-w0);
648  s->a2 = 0;
649  s->b0 = 1 + s->a1;
650  s->b1 = 0;
651  s->b2 = 0;
652  } else {
653  s->a0 = 1 + alpha;
654  s->a1 = -2 * cos(w0);
655  s->a2 = 1 - alpha;
656  s->b0 = (1 - cos(w0)) / 2;
657  s->b1 = 1 - cos(w0);
658  s->b2 = (1 - cos(w0)) / 2;
659  }
660  break;
661  case highpass:
662  if (s->poles == 1) {
663  s->a0 = 1;
664  s->a1 = -exp(-w0);
665  s->a2 = 0;
666  s->b0 = (1 - s->a1) / 2;
667  s->b1 = -s->b0;
668  s->b2 = 0;
669  } else {
670  s->a0 = 1 + alpha;
671  s->a1 = -2 * cos(w0);
672  s->a2 = 1 - alpha;
673  s->b0 = (1 + cos(w0)) / 2;
674  s->b1 = -(1 + cos(w0));
675  s->b2 = (1 + cos(w0)) / 2;
676  }
677  break;
678  case allpass:
679  switch (s->order) {
680  case 1:
681  s->a0 = 1.;
682  s->a1 = -(1. - K) / (1. + K);
683  s->a2 = 0.;
684  s->b0 = s->a1;
685  s->b1 = s->a0;
686  s->b2 = 0.;
687  break;
688  case 2:
689  s->a0 = 1 + alpha;
690  s->a1 = -2 * cos(w0);
691  s->a2 = 1 - alpha;
692  s->b0 = 1 - alpha;
693  s->b1 = -2 * cos(w0);
694  s->b2 = 1 + alpha;
695  break;
696  }
697  break;
698  default:
699  av_assert0(0);
700  }
701 
702  av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n", s->a0, s->a1, s->a2, s->b0, s->b1, s->b2);
703 
704  s->a1 /= s->a0;
705  s->a2 /= s->a0;
706  s->b0 /= s->a0;
707  s->b1 /= s->a0;
708  s->b2 /= s->a0;
709  s->a0 /= s->a0;
710 
711  if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) {
712  double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2);
713 
714  s->b0 *= factor;
715  s->b1 *= factor;
716  s->b2 *= factor;
717  }
718 
719  s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
720  if (!s->cache)
721  return AVERROR(ENOMEM);
722  if (reset)
723  memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
724 
725  switch (s->transform_type) {
726  case DI:
727  switch (inlink->format) {
728  case AV_SAMPLE_FMT_S16P:
729  s->filter = biquad_s16;
730  break;
731  case AV_SAMPLE_FMT_S32P:
732  s->filter = biquad_s32;
733  break;
734  case AV_SAMPLE_FMT_FLTP:
735  s->filter = biquad_flt;
736  break;
737  case AV_SAMPLE_FMT_DBLP:
738  s->filter = biquad_dbl;
739  break;
740  default: av_assert0(0);
741  }
742  break;
743  case DII:
744  switch (inlink->format) {
745  case AV_SAMPLE_FMT_S16P:
746  s->filter = biquad_dii_s16;
747  break;
748  case AV_SAMPLE_FMT_S32P:
749  s->filter = biquad_dii_s32;
750  break;
751  case AV_SAMPLE_FMT_FLTP:
752  s->filter = biquad_dii_flt;
753  break;
754  case AV_SAMPLE_FMT_DBLP:
755  s->filter = biquad_dii_dbl;
756  break;
757  default: av_assert0(0);
758  }
759  break;
760  case TDII:
761  switch (inlink->format) {
762  case AV_SAMPLE_FMT_S16P:
763  s->filter = biquad_tdii_s16;
764  break;
765  case AV_SAMPLE_FMT_S32P:
766  s->filter = biquad_tdii_s32;
767  break;
768  case AV_SAMPLE_FMT_FLTP:
769  s->filter = biquad_tdii_flt;
770  break;
771  case AV_SAMPLE_FMT_DBLP:
772  s->filter = biquad_tdii_dbl;
773  break;
774  default: av_assert0(0);
775  }
776  break;
777  case LATT:
778  switch (inlink->format) {
779  case AV_SAMPLE_FMT_S16P:
780  s->filter = biquad_latt_s16;
781  break;
782  case AV_SAMPLE_FMT_S32P:
783  s->filter = biquad_latt_s32;
784  break;
785  case AV_SAMPLE_FMT_FLTP:
786  s->filter = biquad_latt_flt;
787  break;
788  case AV_SAMPLE_FMT_DBLP:
789  s->filter = biquad_latt_dbl;
790  break;
791  default: av_assert0(0);
792  }
793  break;
794  case SVF:
795  switch (inlink->format) {
796  case AV_SAMPLE_FMT_S16P:
797  s->filter = biquad_svf_s16;
798  break;
799  case AV_SAMPLE_FMT_S32P:
800  s->filter = biquad_svf_s32;
801  break;
802  case AV_SAMPLE_FMT_FLTP:
803  s->filter = biquad_svf_flt;
804  break;
805  case AV_SAMPLE_FMT_DBLP:
806  s->filter = biquad_svf_dbl;
807  break;
808  default: av_assert0(0);
809  }
810  break;
811  default:
812  av_assert0(0);
813  }
814 
815  s->block_align = av_get_bytes_per_sample(inlink->format);
816 
817  if (s->transform_type == LATT)
819  else if (s->transform_type == SVF)
821 
822  return 0;
823 }
824 
825 static int config_output(AVFilterLink *outlink)
826 {
827  return config_filter(outlink, 1);
828 }
829 
830 typedef struct ThreadData {
831  AVFrame *in, *out;
832 } ThreadData;
833 
834 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
835 {
836  AVFilterLink *inlink = ctx->inputs[0];
837  ThreadData *td = arg;
838  AVFrame *buf = td->in;
839  AVFrame *out_buf = td->out;
840  BiquadsContext *s = ctx->priv;
841  const int start = (buf->channels * jobnr) / nb_jobs;
842  const int end = (buf->channels * (jobnr+1)) / nb_jobs;
843  int ch;
844 
845  for (ch = start; ch < end; ch++) {
846  if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
847  if (buf != out_buf)
848  memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
849  buf->nb_samples * s->block_align);
850  continue;
851  }
852 
853  s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
854  &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
855  s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
856  }
857 
858  return 0;
859 }
860 
862 {
863  AVFilterContext *ctx = inlink->dst;
864  BiquadsContext *s = ctx->priv;
865  AVFilterLink *outlink = ctx->outputs[0];
866  AVFrame *out_buf;
867  ThreadData td;
868  int ch;
869 
870  if (s->bypass)
871  return ff_filter_frame(outlink, buf);
872 
873  if (av_frame_is_writable(buf)) {
874  out_buf = buf;
875  } else {
876  out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
877  if (!out_buf) {
878  av_frame_free(&buf);
879  return AVERROR(ENOMEM);
880  }
881  av_frame_copy_props(out_buf, buf);
882  }
883 
884  td.in = buf;
885  td.out = out_buf;
888 
889  for (ch = 0; ch < outlink->channels; ch++) {
890  if (s->cache[ch].clippings > 0)
891  av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
892  ch, s->cache[ch].clippings);
893  s->cache[ch].clippings = 0;
894  }
895 
896  if (buf != out_buf)
897  av_frame_free(&buf);
898 
899  return ff_filter_frame(outlink, out_buf);
900 }
901 
902 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
903  char *res, int res_len, int flags)
904 {
905  AVFilterLink *outlink = ctx->outputs[0];
906  int ret;
907 
908  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
909  if (ret < 0)
910  return ret;
911 
912  return config_filter(outlink, 0);
913 }
914 
916 {
917  BiquadsContext *s = ctx->priv;
918 
919  av_freep(&s->cache);
920 }
921 
922 static const AVFilterPad inputs[] = {
923  {
924  .name = "default",
925  .type = AVMEDIA_TYPE_AUDIO,
926  .filter_frame = filter_frame,
927  },
928 };
929 
930 static const AVFilterPad outputs[] = {
931  {
932  .name = "default",
933  .type = AVMEDIA_TYPE_AUDIO,
934  .config_props = config_output,
935  },
936 };
937 
938 #define OFFSET(x) offsetof(BiquadsContext, x)
939 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
940 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
941 
942 #define DEFINE_BIQUAD_FILTER_2(name_, description_, priv_class_) \
943 static av_cold int name_##_init(AVFilterContext *ctx) \
944 { \
945  BiquadsContext *s = ctx->priv; \
946  s->filter_type = name_; \
947  return 0; \
948 } \
949  \
950 const AVFilter ff_af_##name_ = { \
951  .name = #name_, \
952  .description = NULL_IF_CONFIG_SMALL(description_), \
953  .priv_class = &priv_class_##_class, \
954  .priv_size = sizeof(BiquadsContext), \
955  .init = name_##_init, \
956  .uninit = uninit, \
957  FILTER_INPUTS(inputs), \
958  FILTER_OUTPUTS(outputs), \
959  FILTER_QUERY_FUNC(query_formats), \
960  .process_command = process_command, \
961  .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
962 }
963 
964 #define DEFINE_BIQUAD_FILTER(name, description) \
965  AVFILTER_DEFINE_CLASS(name); \
966  DEFINE_BIQUAD_FILTER_2(name, description, name)
967 
968 #if CONFIG_EQUALIZER_FILTER
969 static const AVOption equalizer_options[] = {
970  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
971  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
972  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
973  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
974  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
975  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
976  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
977  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
978  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
979  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
980  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
981  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
982  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
983  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
984  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
985  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
986  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
987  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
988  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
989  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
990  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
991  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
992  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
993  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
994  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
995  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
996  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
997  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
998  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
999  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1000  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1001  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1002  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1003  {NULL}
1004 };
1005 
1006 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
1007 #endif /* CONFIG_EQUALIZER_FILTER */
1008 #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER
1009 static const AVOption bass_lowshelf_options[] = {
1010  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1011  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1012  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1013  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1014  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1015  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1016  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1017  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1018  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1019  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1020  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1021  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1022  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1023  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1024  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1025  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1026  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1027  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1028  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1029  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1030  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1031  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1032  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1033  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1034  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1035  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1036  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1037  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1038  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1039  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1040  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1041  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1042  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1043  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1044  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1045  {NULL}
1046 };
1047 
1048 AVFILTER_DEFINE_CLASS_EXT(bass_lowshelf, "bass/lowshelf", bass_lowshelf_options);
1049 #if CONFIG_BASS_FILTER
1050 DEFINE_BIQUAD_FILTER_2(bass, "Boost or cut lower frequencies.", bass_lowshelf);
1051 #endif /* CONFIG_BASS_FILTER */
1052 
1053 #if CONFIG_LOWSHELF_FILTER
1054 DEFINE_BIQUAD_FILTER_2(lowshelf, "Apply a low shelf filter.", bass_lowshelf);
1055 #endif /* CONFIG_LOWSHELF_FILTER */
1056 #endif /* CONFIG_BASS_FILTER || CONFIG LOWSHELF_FILTER */
1057 #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER
1058 static const AVOption treble_highshelf_options[] = {
1059  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1060  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1061  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1062  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1063  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1064  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1065  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1066  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1067  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1068  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1069  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1070  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1071  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1072  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1073  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1074  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1075  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1076  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1077  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1078  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1079  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1080  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1081  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1082  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1083  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1084  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1085  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1086  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1087  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1088  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1089  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1090  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1091  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1092  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1093  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1094  {NULL}
1095 };
1096 
1097 AVFILTER_DEFINE_CLASS_EXT(treble_highshelf, "treble/highshelf",
1098  treble_highshelf_options);
1099 
1100 #if CONFIG_TREBLE_FILTER
1101 DEFINE_BIQUAD_FILTER_2(treble, "Boost or cut upper frequencies.", treble_highshelf);
1102 #endif /* CONFIG_TREBLE_FILTER */
1103 
1104 #if CONFIG_HIGHSHELF_FILTER
1105 DEFINE_BIQUAD_FILTER_2(highshelf, "Apply a high shelf filter.", treble_highshelf);
1106 #endif /* CONFIG_HIGHSHELF_FILTER */
1107 #endif /* CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER */
1108 #if CONFIG_BANDPASS_FILTER
1109 static const AVOption bandpass_options[] = {
1110  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1111  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1112  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1113  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1114  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1115  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1116  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1117  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1118  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1119  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1120  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1121  {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1122  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1123  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1124  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1125  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1126  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1127  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1128  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1129  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1130  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1131  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1132  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1133  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1134  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1135  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1136  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1137  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1138  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1139  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1140  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1141  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1142  {NULL}
1143 };
1144 
1145 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
1146 #endif /* CONFIG_BANDPASS_FILTER */
1147 #if CONFIG_BANDREJECT_FILTER
1148 static const AVOption bandreject_options[] = {
1149  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1150  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1151  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1152  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1153  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1154  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1155  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1156  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1157  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1158  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1159  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
1160  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1161  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1162  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1163  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1164  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1165  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1166  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1167  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1168  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1169  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1170  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1171  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1172  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1173  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1174  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1175  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1176  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1177  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1178  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1179  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1180  {NULL}
1181 };
1182 
1183 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
1184 #endif /* CONFIG_BANDREJECT_FILTER */
1185 #if CONFIG_LOWPASS_FILTER
1186 static const AVOption lowpass_options[] = {
1187  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1188  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1189  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1190  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1191  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1192  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1193  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1194  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1195  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1196  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
1197  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
1198  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1199  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1200  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1201  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1202  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1203  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1204  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1205  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1206  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1207  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1208  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1209  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1210  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1211  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1212  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1213  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1214  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1215  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1216  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1217  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1218  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1219  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1220  {NULL}
1221 };
1222 
1223 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
1224 #endif /* CONFIG_LOWPASS_FILTER */
1225 #if CONFIG_HIGHPASS_FILTER
1226 static const AVOption highpass_options[] = {
1227  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1228  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1229  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1230  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1231  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1232  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1233  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1234  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1235  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1236  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
1237  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
1238  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1239  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1240  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1241  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1242  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1243  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1244  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1245  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1246  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1247  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1248  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1249  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1250  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1251  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1252  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1253  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1254  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1255  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1256  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1257  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1258  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1259  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1260  {NULL}
1261 };
1262 
1263 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
1264 #endif /* CONFIG_HIGHPASS_FILTER */
1265 #if CONFIG_ALLPASS_FILTER
1266 static const AVOption allpass_options[] = {
1267  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1268  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1269  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1270  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
1271  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
1272  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
1273  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
1274  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
1275  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
1276  {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
1277  {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
1278  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1279  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1280  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1281  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1282  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1283  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1284  {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1285  {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1286  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1287  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1288  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1289  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1290  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1291  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1292  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1293  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1294  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1295  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1296  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1297  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1298  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1299  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1300  {NULL}
1301 };
1302 
1303 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
1304 #endif /* CONFIG_ALLPASS_FILTER */
1305 #if CONFIG_BIQUAD_FILTER
1306 static const AVOption biquad_options[] = {
1307  {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
1308  {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1309  {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1310  {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1311  {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1312  {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1313  {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1314  {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
1315  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1316  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
1317  {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1318  {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1319  {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1320  {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_TTYPE-1, AF, "transform_type"},
1321  {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"},
1322  {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"},
1323  {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"},
1324  {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"},
1325  {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"},
1326  {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1327  {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=-1}, -1, 3, AF, "precision"},
1328  {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"},
1329  {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"},
1330  {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"},
1331  {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"},
1332  {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"},
1333  {NULL}
1334 };
1335 
1336 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
1337 #endif /* CONFIG_BIQUAD_FILTER */
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:88
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
td
#define td
Definition: regdef.h:70
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
BiquadsContext::ob1
double ob1
Definition: af_biquads.c:136
mix
static int mix(int c0, int c1)
Definition: 4xm.c:716
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
BiquadsContext::b0
double b0
Definition: af_biquads.c:133
BiquadsContext::normalize
int normalize
Definition: af_biquads.c:129
DII
@ DII
Definition: af_biquads.c:99
BiquadsContext
Definition: af_biquads.c:112
BiquadsContext::block_align
int block_align
Definition: af_biquads.c:139
BiquadsContext::width_type
int width_type
Definition: af_biquads.c:116
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
BiquadsContext::a0
double a0
Definition: af_biquads.c:132
NB_TTYPE
@ NB_TTYPE
Definition: af_biquads.c:103
DEFINE_BIQUAD_FILTER
#define DEFINE_BIQUAD_FILTER(name, description)
Definition: af_biquads.c:964
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
SLOPE
@ SLOPE
Definition: af_biquads.c:92
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:310
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
BiquadsContext::csg
int csg
Definition: af_biquads.c:118
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:68
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:689
bandreject
@ bandreject
Definition: af_biquads.c:79
AVFILTER_DEFINE_CLASS_EXT
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
Definition: internal.h:318
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:473
A
#define A(x)
Definition: vp56_arith.h:28
ChanCache::i2
double i2
Definition: af_biquads.c:107
convert_dir2latt
static void convert_dir2latt(BiquadsContext *s)
Definition: af_biquads.c:471
v0
#define v0
Definition: regdef.h:26
outputs
static const AVFilterPad outputs[]
Definition: af_biquads.c:930
BiquadsContext::filter
void(* filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len, double *i1, double *i2, double *o1, double *o2, double b0, double b1, double b2, double a1, double a2, int *clippings, int disabled)
Definition: af_biquads.c:141
FFSIGN
#define FFSIGN(a)
Definition: common.h:66
BiquadsContext::transform_type
int transform_type
Definition: af_biquads.c:119
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
BiquadsContext::bypass
int bypass
Definition: af_biquads.c:122
BiquadsContext::channels
uint64_t channels
Definition: af_biquads.c:128
FilterType
FilterType
Definition: af_adenorm.c:26
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
TransformType
TransformType
Definition: webp.c:110
convert_dir2svf
static void convert_dir2svf(BiquadsContext *s)
Definition: af_biquads.c:488
AVFrame::channels
int channels
number of audio channels, only used for audio.
Definition: frame.h:621
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:705
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
BiquadsContext::oa0
double oa0
Definition: af_biquads.c:135
highpass
@ highpass
Definition: af_biquads.c:81
BiquadsContext::precision
int precision
Definition: af_biquads.c:120
NB_WTYPE
@ NB_WTYPE
Definition: af_biquads.c:94
BiquadsContext::a1
double a1
Definition: af_biquads.c:132
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:33
BiquadsContext::width
double width
Definition: af_biquads.c:126
BiquadsContext::poles
int poles
Definition: af_biquads.c:117
arg
const char * arg
Definition: jacosubdec.c:67
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
biquad
@ biquad
Definition: af_biquads.c:74
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
BiquadsContext::cache
ChanCache * cache
Definition: af_biquads.c:138
allpass
@ allpass
Definition: af_biquads.c:80
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_biquads.c:861
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:671
exp
int8_t exp
Definition: eval.c:72
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_biquads.c:902
BiquadsContext::order
int order
Definition: af_biquads.c:130
KHERTZ
@ KHERTZ
Definition: af_biquads.c:93
ChanCache::i1
double i1
Definition: af_biquads.c:107
BiquadsContext::oa1
double oa1
Definition: af_biquads.c:135
lowpass
@ lowpass
Definition: af_biquads.c:82
AF
#define AF
Definition: af_biquads.c:940
BiquadsContext::ob2
double ob2
Definition: af_biquads.c:136
filter_channel
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_biquads.c:834
BiquadsContext::b1
double b1
Definition: af_biquads.c:133
NONE
@ NONE
Definition: af_biquads.c:88
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
highshelf
@ highshelf
Definition: af_biquads.c:84
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:473
ChanCache::o2
double o2
Definition: af_biquads.c:108
bass
@ bass
Definition: af_biquads.c:76
AV_OPT_TYPE_CHANNEL_LAYOUT
@ AV_OPT_TYPE_CHANNEL_LAYOUT
Definition: opt.h:240
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:882
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_biquads.c:825
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
BIQUAD_LATT_FILTER
#define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:368
M_PI
#define M_PI
Definition: mathematics.h:52
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
LATT
@ LATT
Definition: af_biquads.c:101
internal.h
inputs
static const AVFilterPad inputs[]
Definition: af_biquads.c:922
BiquadsContext::mix
double mix
Definition: af_biquads.c:127
QFACTOR
@ QFACTOR
Definition: af_biquads.c:91
normalize
Definition: normalize.py:1
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:390
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
av_channel_layout_extract_channel
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
Definition: channel_layout.c:271
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:371
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:803
BIQUAD_DII_FILTER
#define BIQUAD_DII_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:273
BiquadsContext::ob0
double ob0
Definition: af_biquads.c:136
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
TDII
@ TDII
Definition: af_biquads.c:100
config_filter
static int config_filter(AVFilterLink *outlink, int reset)
Definition: af_biquads.c:506
len
int len
Definition: vorbis_enc_data.h:426
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
treble
@ treble
Definition: af_biquads.c:77
OFFSET
#define OFFSET(x)
Definition: af_biquads.c:938
ret
ret
Definition: filter_design.txt:187
WidthType
WidthType
Definition: af_biquads.c:87
BIQUAD_FILTER
#define BIQUAD_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:190
ChanCache
Definition: af_biquads.c:106
BiquadsContext::filter_type
enum FilterType filter_type
Definition: af_biquads.c:115
channel_layout.h
HERTZ
@ HERTZ
Definition: af_biquads.c:89
BiquadsContext::gain
double gain
Definition: af_biquads.c:124
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_biquads.c:147
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
DEFINE_BIQUAD_FILTER_2
#define DEFINE_BIQUAD_FILTER_2(name_, description_, priv_class_)
Definition: af_biquads.c:942
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_biquads.c:915
ffmath.h
ChanCache::o1
double o1
Definition: af_biquads.c:108
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
factor
static const int factor[16]
Definition: vf_pp7.c:76
FLAGS
#define FLAGS
Definition: af_biquads.c:939
BiquadsContext::b2
double b2
Definition: af_biquads.c:133
DI
@ DI
Definition: af_biquads.c:98
audio.h
BIQUAD_SVF_FILTER
#define BIQUAD_SVF_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:423
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:154
SVF
@ SVF
Definition: af_biquads.c:102
lowshelf
@ lowshelf
Definition: af_biquads.c:83
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
equalizer
@ equalizer
Definition: af_biquads.c:75
BIQUAD_TDII_FILTER
#define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:321
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ChanCache::clippings
int clippings
Definition: af_biquads.c:109
OCTAVE
@ OCTAVE
Definition: af_biquads.c:90
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:143
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
BiquadsContext::frequency
double frequency
Definition: af_biquads.c:125
BiquadsContext::a2
double a2
Definition: af_biquads.c:132
BiquadsContext::oa2
double oa2
Definition: af_biquads.c:135
bandpass
@ bandpass
Definition: af_biquads.c:78