FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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"
66 #include "libavutil/opt.h"
67 #include "audio.h"
68 #include "avfilter.h"
69 #include "internal.h"
70 
71 enum FilterType {
83 };
84 
85 enum WidthType {
93 };
94 
95 typedef struct ChanCache {
96  double i1, i2;
97  double o1, o2;
98  int clippings;
99 } ChanCache;
100 
101 typedef struct BiquadsContext {
102  const AVClass *class;
103 
106  int poles;
107  int csg;
108 
109  double gain;
110  double frequency;
111  double width;
112  uint64_t channels;
113 
114  double a0, a1, a2;
115  double b0, b1, b2;
116 
119 
120  void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
121  double *i1, double *i2, double *o1, double *o2,
122  double b0, double b1, double b2, double a1, double a2, int *clippings);
124 
126 {
127  BiquadsContext *s = ctx->priv;
128 
129  if (s->filter_type != biquad) {
130  if (s->frequency <= 0 || s->width <= 0) {
131  av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
132  s->frequency, s->width);
133  return AVERROR(EINVAL);
134  }
135  }
136 
137  return 0;
138 }
139 
141 {
144  static const enum AVSampleFormat sample_fmts[] = {
150  };
151  int ret;
152 
153  layouts = ff_all_channel_counts();
154  if (!layouts)
155  return AVERROR(ENOMEM);
156  ret = ff_set_common_channel_layouts(ctx, layouts);
157  if (ret < 0)
158  return ret;
159 
160  formats = ff_make_format_list(sample_fmts);
161  if (!formats)
162  return AVERROR(ENOMEM);
163  ret = ff_set_common_formats(ctx, formats);
164  if (ret < 0)
165  return ret;
166 
167  formats = ff_all_samplerates();
168  if (!formats)
169  return AVERROR(ENOMEM);
170  return ff_set_common_samplerates(ctx, formats);
171 }
172 
173 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
174 static void biquad_## name (BiquadsContext *s, \
175  const void *input, void *output, int len, \
176  double *in1, double *in2, \
177  double *out1, double *out2, \
178  double b0, double b1, double b2, \
179  double a1, double a2, int *clippings) \
180 { \
181  const type *ibuf = input; \
182  type *obuf = output; \
183  double i1 = *in1; \
184  double i2 = *in2; \
185  double o1 = *out1; \
186  double o2 = *out2; \
187  int i; \
188  a1 = -a1; \
189  a2 = -a2; \
190  \
191  for (i = 0; i+1 < len; i++) { \
192  o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
193  i2 = ibuf[i]; \
194  if (need_clipping && o2 < min) { \
195  (*clippings)++; \
196  obuf[i] = min; \
197  } else if (need_clipping && o2 > max) { \
198  (*clippings)++; \
199  obuf[i] = max; \
200  } else { \
201  obuf[i] = o2; \
202  } \
203  i++; \
204  o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
205  i1 = ibuf[i]; \
206  if (need_clipping && o1 < min) { \
207  (*clippings)++; \
208  obuf[i] = min; \
209  } else if (need_clipping && o1 > max) { \
210  (*clippings)++; \
211  obuf[i] = max; \
212  } else { \
213  obuf[i] = o1; \
214  } \
215  } \
216  if (i < len) { \
217  double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
218  i2 = i1; \
219  i1 = ibuf[i]; \
220  o2 = o1; \
221  o1 = o0; \
222  if (need_clipping && o0 < min) { \
223  (*clippings)++; \
224  obuf[i] = min; \
225  } else if (need_clipping && o0 > max) { \
226  (*clippings)++; \
227  obuf[i] = max; \
228  } else { \
229  obuf[i] = o0; \
230  } \
231  } \
232  *in1 = i1; \
233  *in2 = i2; \
234  *out1 = o1; \
235  *out2 = o2; \
236 }
237 
238 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
239 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
240 BIQUAD_FILTER(flt, float, -1., 1., 0)
241 BIQUAD_FILTER(dbl, double, -1., 1., 0)
242 
243 static int config_filter(AVFilterLink *outlink, int reset)
244 {
245  AVFilterContext *ctx = outlink->src;
246  BiquadsContext *s = ctx->priv;
247  AVFilterLink *inlink = ctx->inputs[0];
248  double A = exp(s->gain / 40 * log(10.));
249  double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
250  double alpha, beta;
251 
252  if (w0 > M_PI) {
253  av_log(ctx, AV_LOG_ERROR,
254  "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
255  s->frequency, inlink->sample_rate);
256  return AVERROR(EINVAL);
257  }
258 
259  switch (s->width_type) {
260  case NONE:
261  alpha = 0.0;
262  break;
263  case HERTZ:
264  alpha = sin(w0) / (2 * s->frequency / s->width);
265  break;
266  case KHERTZ:
267  alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
268  break;
269  case OCTAVE:
270  alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
271  break;
272  case QFACTOR:
273  alpha = sin(w0) / (2 * s->width);
274  break;
275  case SLOPE:
276  alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
277  break;
278  default:
279  av_assert0(0);
280  }
281 
282  beta = 2 * sqrt(A);
283 
284  switch (s->filter_type) {
285  case biquad:
286  break;
287  case equalizer:
288  s->a0 = 1 + alpha / A;
289  s->a1 = -2 * cos(w0);
290  s->a2 = 1 - alpha / A;
291  s->b0 = 1 + alpha * A;
292  s->b1 = -2 * cos(w0);
293  s->b2 = 1 - alpha * A;
294  break;
295  case bass:
296  beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
297  case lowshelf:
298  s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
299  s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
300  s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
301  s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
302  s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
303  s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
304  break;
305  case treble:
306  beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
307  case highshelf:
308  s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
309  s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
310  s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
311  s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
312  s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
313  s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
314  break;
315  case bandpass:
316  if (s->csg) {
317  s->a0 = 1 + alpha;
318  s->a1 = -2 * cos(w0);
319  s->a2 = 1 - alpha;
320  s->b0 = sin(w0) / 2;
321  s->b1 = 0;
322  s->b2 = -sin(w0) / 2;
323  } else {
324  s->a0 = 1 + alpha;
325  s->a1 = -2 * cos(w0);
326  s->a2 = 1 - alpha;
327  s->b0 = alpha;
328  s->b1 = 0;
329  s->b2 = -alpha;
330  }
331  break;
332  case bandreject:
333  s->a0 = 1 + alpha;
334  s->a1 = -2 * cos(w0);
335  s->a2 = 1 - alpha;
336  s->b0 = 1;
337  s->b1 = -2 * cos(w0);
338  s->b2 = 1;
339  break;
340  case lowpass:
341  if (s->poles == 1) {
342  s->a0 = 1;
343  s->a1 = -exp(-w0);
344  s->a2 = 0;
345  s->b0 = 1 + s->a1;
346  s->b1 = 0;
347  s->b2 = 0;
348  } else {
349  s->a0 = 1 + alpha;
350  s->a1 = -2 * cos(w0);
351  s->a2 = 1 - alpha;
352  s->b0 = (1 - cos(w0)) / 2;
353  s->b1 = 1 - cos(w0);
354  s->b2 = (1 - cos(w0)) / 2;
355  }
356  break;
357  case highpass:
358  if (s->poles == 1) {
359  s->a0 = 1;
360  s->a1 = -exp(-w0);
361  s->a2 = 0;
362  s->b0 = (1 - s->a1) / 2;
363  s->b1 = -s->b0;
364  s->b2 = 0;
365  } else {
366  s->a0 = 1 + alpha;
367  s->a1 = -2 * cos(w0);
368  s->a2 = 1 - alpha;
369  s->b0 = (1 + cos(w0)) / 2;
370  s->b1 = -(1 + cos(w0));
371  s->b2 = (1 + cos(w0)) / 2;
372  }
373  break;
374  case allpass:
375  s->a0 = 1 + alpha;
376  s->a1 = -2 * cos(w0);
377  s->a2 = 1 - alpha;
378  s->b0 = 1 - alpha;
379  s->b1 = -2 * cos(w0);
380  s->b2 = 1 + alpha;
381  break;
382  default:
383  av_assert0(0);
384  }
385 
386  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);
387 
388  s->a1 /= s->a0;
389  s->a2 /= s->a0;
390  s->b0 /= s->a0;
391  s->b1 /= s->a0;
392  s->b2 /= s->a0;
393  s->a0 /= s->a0;
394 
395  s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
396  if (!s->cache)
397  return AVERROR(ENOMEM);
398  if (reset)
399  memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
400 
401  switch (inlink->format) {
402  case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
403  case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
404  case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
405  case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
406  default: av_assert0(0);
407  }
408 
410 
411  return 0;
412 }
413 
414 static int config_output(AVFilterLink *outlink)
415 {
416  return config_filter(outlink, 1);
417 }
418 
419 typedef struct ThreadData {
420  AVFrame *in, *out;
421 } ThreadData;
422 
423 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
424 {
425  AVFilterLink *inlink = ctx->inputs[0];
426  ThreadData *td = arg;
427  AVFrame *buf = td->in;
428  AVFrame *out_buf = td->out;
429  BiquadsContext *s = ctx->priv;
430  const int start = (buf->channels * jobnr) / nb_jobs;
431  const int end = (buf->channels * (jobnr+1)) / nb_jobs;
432  int ch;
433 
434  for (ch = start; ch < end; ch++) {
435  if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
436  if (buf != out_buf)
437  memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
438  buf->nb_samples * s->block_align);
439  continue;
440  }
441 
442  s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
443  &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
444  s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings);
445  }
446 
447  return 0;
448 }
449 
450 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
451 {
452  AVFilterContext *ctx = inlink->dst;
453  BiquadsContext *s = ctx->priv;
454  AVFilterLink *outlink = ctx->outputs[0];
455  AVFrame *out_buf;
456  ThreadData td;
457  int ch;
458 
459  if (av_frame_is_writable(buf)) {
460  out_buf = buf;
461  } else {
462  out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
463  if (!out_buf) {
464  av_frame_free(&buf);
465  return AVERROR(ENOMEM);
466  }
467  av_frame_copy_props(out_buf, buf);
468  }
469 
470  td.in = buf;
471  td.out = out_buf;
472  ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
473 
474  for (ch = 0; ch < outlink->channels; ch++) {
475  if (s->cache[ch].clippings > 0)
476  av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
477  ch, s->cache[ch].clippings);
478  s->cache[ch].clippings = 0;
479  }
480 
481  if (buf != out_buf)
482  av_frame_free(&buf);
483 
484  return ff_filter_frame(outlink, out_buf);
485 }
486 
487 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
488  char *res, int res_len, int flags)
489 {
490  BiquadsContext *s = ctx->priv;
491  AVFilterLink *outlink = ctx->outputs[0];
492 
493  if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
494  (s->filter_type == equalizer ||
495  s->filter_type == lowshelf ||
496  s->filter_type == highshelf ||
497  s->filter_type == bass ||
498  s->filter_type == treble ||
499  s->filter_type == bandpass ||
500  s->filter_type == bandreject||
501  s->filter_type == lowpass ||
502  s->filter_type == highpass ||
503  s->filter_type == allpass)) {
504  double freq;
505 
506  if (sscanf(args, "%lf", &freq) != 1) {
507  av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
508  return AVERROR(EINVAL);
509  }
510 
511  s->frequency = freq;
512  } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
513  (s->filter_type == equalizer ||
514  s->filter_type == lowshelf ||
515  s->filter_type == highshelf ||
516  s->filter_type == bass ||
517  s->filter_type == treble)) {
518  double gain;
519 
520  if (sscanf(args, "%lf", &gain) != 1) {
521  av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
522  return AVERROR(EINVAL);
523  }
524 
525  s->gain = gain;
526  } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
527  (s->filter_type == equalizer ||
528  s->filter_type == lowshelf ||
529  s->filter_type == highshelf ||
530  s->filter_type == bass ||
531  s->filter_type == treble ||
532  s->filter_type == bandpass ||
533  s->filter_type == bandreject||
534  s->filter_type == lowpass ||
535  s->filter_type == highpass ||
536  s->filter_type == allpass)) {
537  double width;
538 
539  if (sscanf(args, "%lf", &width) != 1) {
540  av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
541  return AVERROR(EINVAL);
542  }
543 
544  s->width = width;
545  } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
546  (s->filter_type == equalizer ||
547  s->filter_type == lowshelf ||
548  s->filter_type == highshelf ||
549  s->filter_type == bass ||
550  s->filter_type == treble ||
551  s->filter_type == bandpass ||
552  s->filter_type == bandreject||
553  s->filter_type == lowpass ||
554  s->filter_type == highpass ||
555  s->filter_type == allpass)) {
556  char width_type;
557 
558  if (sscanf(args, "%c", &width_type) != 1) {
559  av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
560  return AVERROR(EINVAL);
561  }
562 
563  switch (width_type) {
564  case 'h': width_type = HERTZ; break;
565  case 'q': width_type = QFACTOR; break;
566  case 'o': width_type = OCTAVE; break;
567  case 's': width_type = SLOPE; break;
568  case 'k': width_type = KHERTZ; break;
569  default:
570  av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
571  return AVERROR(EINVAL);
572  }
573 
574  s->width_type = width_type;
575  } else if ((!strcmp(cmd, "a0") ||
576  !strcmp(cmd, "a1") ||
577  !strcmp(cmd, "a2") ||
578  !strcmp(cmd, "b0") ||
579  !strcmp(cmd, "b1") ||
580  !strcmp(cmd, "b2")) &&
581  s->filter_type == biquad) {
582  double value;
583 
584  if (sscanf(args, "%lf", &value) != 1) {
585  av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
586  return AVERROR(EINVAL);
587  }
588 
589  if (!strcmp(cmd, "a0"))
590  s->a0 = value;
591  else if (!strcmp(cmd, "a1"))
592  s->a1 = value;
593  else if (!strcmp(cmd, "a2"))
594  s->a2 = value;
595  else if (!strcmp(cmd, "b0"))
596  s->b0 = value;
597  else if (!strcmp(cmd, "b1"))
598  s->b1 = value;
599  else if (!strcmp(cmd, "b2"))
600  s->b2 = value;
601  }
602 
603  return config_filter(outlink, 0);
604 }
605 
607 {
608  BiquadsContext *s = ctx->priv;
609 
610  av_freep(&s->cache);
611 }
612 
613 static const AVFilterPad inputs[] = {
614  {
615  .name = "default",
616  .type = AVMEDIA_TYPE_AUDIO,
617  .filter_frame = filter_frame,
618  },
619  { NULL }
620 };
621 
622 static const AVFilterPad outputs[] = {
623  {
624  .name = "default",
625  .type = AVMEDIA_TYPE_AUDIO,
626  .config_props = config_output,
627  },
628  { NULL }
629 };
630 
631 #define OFFSET(x) offsetof(BiquadsContext, x)
632 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
633 
634 #define DEFINE_BIQUAD_FILTER(name_, description_) \
635 AVFILTER_DEFINE_CLASS(name_); \
636 static av_cold int name_##_init(AVFilterContext *ctx) \
637 { \
638  BiquadsContext *s = ctx->priv; \
639  s->class = &name_##_class; \
640  s->filter_type = name_; \
641  return init(ctx); \
642 } \
643  \
644 AVFilter ff_af_##name_ = { \
645  .name = #name_, \
646  .description = NULL_IF_CONFIG_SMALL(description_), \
647  .priv_size = sizeof(BiquadsContext), \
648  .init = name_##_init, \
649  .uninit = uninit, \
650  .query_formats = query_formats, \
651  .inputs = inputs, \
652  .outputs = outputs, \
653  .priv_class = &name_##_class, \
654  .process_command = process_command, \
655  .flags = AVFILTER_FLAG_SLICE_THREADS, \
656 }
657 
658 #if CONFIG_EQUALIZER_FILTER
659 static const AVOption equalizer_options[] = {
660  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
661  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
662  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
663  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
664  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
665  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
666  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
667  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
668  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
669  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
670  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
671  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
672  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
673  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
674  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
675  {NULL}
676 };
677 
678 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
679 #endif /* CONFIG_EQUALIZER_FILTER */
680 #if CONFIG_BASS_FILTER
681 static const AVOption bass_options[] = {
682  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
683  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
684  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
685  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
686  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
687  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
688  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
689  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
690  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
691  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
692  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
693  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
694  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
695  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
696  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
697  {NULL}
698 };
699 
700 DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
701 #endif /* CONFIG_BASS_FILTER */
702 #if CONFIG_TREBLE_FILTER
703 static const AVOption treble_options[] = {
704  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
705  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
706  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
707  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
708  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
709  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
710  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
711  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
712  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
713  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
714  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
715  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
716  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
717  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
718  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
719  {NULL}
720 };
721 
722 DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
723 #endif /* CONFIG_TREBLE_FILTER */
724 #if CONFIG_BANDPASS_FILTER
725 static const AVOption bandpass_options[] = {
726  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
727  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
728  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
729  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
730  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
731  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
732  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
733  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
734  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
735  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
736  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
737  {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
738  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
739  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
740  {NULL}
741 };
742 
743 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
744 #endif /* CONFIG_BANDPASS_FILTER */
745 #if CONFIG_BANDREJECT_FILTER
746 static const AVOption bandreject_options[] = {
747  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
748  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
749  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
750  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
751  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
752  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
753  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
754  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
755  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
756  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
757  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
758  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
759  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
760  {NULL}
761 };
762 
763 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
764 #endif /* CONFIG_BANDREJECT_FILTER */
765 #if CONFIG_LOWPASS_FILTER
766 static const AVOption lowpass_options[] = {
767  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
768  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
769  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
770  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
771  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
772  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
773  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
774  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
775  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
776  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
777  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
778  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
779  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
780  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
781  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
782  {NULL}
783 };
784 
785 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
786 #endif /* CONFIG_LOWPASS_FILTER */
787 #if CONFIG_HIGHPASS_FILTER
788 static const AVOption highpass_options[] = {
789  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
790  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
791  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
792  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
793  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
794  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
795  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
796  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
797  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
798  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
799  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
800  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
801  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
802  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
803  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
804  {NULL}
805 };
806 
807 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
808 #endif /* CONFIG_HIGHPASS_FILTER */
809 #if CONFIG_ALLPASS_FILTER
810 static const AVOption allpass_options[] = {
811  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
812  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
813  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
814  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
815  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
816  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
817  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
818  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
819  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
820  {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
821  {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
822  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
823  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
824  {NULL}
825 };
826 
827 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
828 #endif /* CONFIG_ALLPASS_FILTER */
829 #if CONFIG_LOWSHELF_FILTER
830 static const AVOption lowshelf_options[] = {
831  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
832  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
833  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
834  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
835  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
836  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
837  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
838  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
839  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
840  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
841  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
842  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
843  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
844  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
845  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
846  {NULL}
847 };
848 
849 DEFINE_BIQUAD_FILTER(lowshelf, "Apply a low shelf filter.");
850 #endif /* CONFIG_LOWSHELF_FILTER */
851 #if CONFIG_HIGHSHELF_FILTER
852 static const AVOption highshelf_options[] = {
853  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
854  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
855  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
856  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
857  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
858  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
859  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
860  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
861  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
862  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
863  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
864  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
865  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
866  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
867  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
868  {NULL}
869 };
870 
871 DEFINE_BIQUAD_FILTER(highshelf, "Apply a high shelf filter.");
872 #endif /* CONFIG_HIGHSHELF_FILTER */
873 #if CONFIG_BIQUAD_FILTER
874 static const AVOption biquad_options[] = {
875  {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
876  {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
877  {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
878  {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
879  {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
880  {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
881  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
882  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
883  {NULL}
884 };
885 
886 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
887 #endif /* CONFIG_BIQUAD_FILTER */
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:549
AVFrame * out
Definition: af_adeclick.c:485
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
#define av_realloc_f(p, o, n)
AVOption.
Definition: opt.h:246
ChanCache * cache
Definition: af_biquads.c:117
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
double i2
Definition: af_biquads.c:96
#define a0
Definition: regdef.h:46
channels
Definition: aptx.c:30
double, planar
Definition: samplefmt.h:70
#define a1
Definition: regdef.h:47
static const AVFilterPad inputs[]
Definition: af_biquads.c:613
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
FilterType
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
AVFrame * in
Definition: af_afftdn.c:1082
#define OFFSET(x)
Definition: af_biquads.c:631
#define av_cold
Definition: attributes.h:82
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define A(x)
Definition: vp56_arith.h:28
#define av_log(a,...)
static const AVFilterPad outputs[]
Definition: af_biquads.c:622
A filter pad used for either input or output.
Definition: internal.h:54
static av_cold int init(AVFilterContext *ctx)
Definition: af_biquads.c:125
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
#define td
Definition: regdef.h:70
#define FLAGS
Definition: af_biquads.c:632
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
void * priv
private data for use by the filter
Definition: avfilter.h:353
const char * arg
Definition: jacosubdec.c:66
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t channels
Definition: af_biquads.c:112
int8_t exp
Definition: eval.c:72
double o1
Definition: af_biquads.c:97
int channels
number of audio channels, only used for audio.
Definition: frame.h:531
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
#define FFMIN(a, b)
Definition: common.h:96
signed 32 bits, planar
Definition: samplefmt.h:68
#define width
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
#define a2
Definition: regdef.h:48
#define s(width, name)
Definition: cbs_vp9.c:257
A list of supported channel layouts.
Definition: formats.h:85
#define BIQUAD_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:173
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_biquads.c:423
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
Used for passing data between threads.
Definition: af_adeclick.c:484
static int config_output(AVFilterLink *outlink)
Definition: af_biquads.c:414
static const int16_t alpha[]
Definition: ilbcdata.h:55
void * buf
Definition: avisynth_c.h:690
Describe the class of an AVClass context structure.
Definition: log.h:67
#define DEFINE_BIQUAD_FILTER(name_, description_)
Definition: af_biquads.c:634
static int query_formats(AVFilterContext *ctx)
Definition: af_biquads.c:140
double o2
Definition: af_biquads.c:97
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
#define flags(name, subs,...)
Definition: cbs_av1.c:596
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_biquads.c:606
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
int clippings
Definition: af_biquads.c:98
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
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)
Definition: af_biquads.c:120
avfilter_execute_func * execute
Definition: internal.h:155
static int config_filter(AVFilterLink *outlink, int reset)
Definition: af_biquads.c:243
WidthType
Definition: af_biquads.c:85
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_biquads.c:450
int len
double i1
Definition: af_biquads.c:96
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_biquads.c:487
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:690
signed 16 bits, planar
Definition: samplefmt.h:67
double frequency
Definition: af_biquads.c:110
#define M_PI
Definition: mathematics.h:52
formats
Definition: signature.h:48
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:273
enum FilterType filter_type
Definition: af_biquads.c:104
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:292
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56