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