FFmpeg  4.0
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 {
81 };
82 
83 enum WidthType {
91 };
92 
93 typedef struct ChanCache {
94  double i1, i2;
95  double o1, o2;
96 } ChanCache;
97 
98 typedef struct BiquadsContext {
99  const AVClass *class;
100 
101  enum FilterType filter_type;
103  int poles;
104  int csg;
105 
106  double gain;
107  double frequency;
108  double width;
109  uint64_t channels;
110 
111  double a0, a1, a2;
112  double b0, b1, b2;
113 
117 
118  void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
119  double *i1, double *i2, double *o1, double *o2,
120  double b0, double b1, double b2, double a1, double a2);
122 
124 {
125  BiquadsContext *s = ctx->priv;
126 
127  if (s->filter_type != biquad) {
128  if (s->frequency <= 0 || s->width <= 0) {
129  av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
130  s->frequency, s->width);
131  return AVERROR(EINVAL);
132  }
133  }
134 
135  return 0;
136 }
137 
139 {
142  static const enum AVSampleFormat sample_fmts[] = {
148  };
149  int ret;
150 
151  layouts = ff_all_channel_counts();
152  if (!layouts)
153  return AVERROR(ENOMEM);
154  ret = ff_set_common_channel_layouts(ctx, layouts);
155  if (ret < 0)
156  return ret;
157 
158  formats = ff_make_format_list(sample_fmts);
159  if (!formats)
160  return AVERROR(ENOMEM);
161  ret = ff_set_common_formats(ctx, formats);
162  if (ret < 0)
163  return ret;
164 
165  formats = ff_all_samplerates();
166  if (!formats)
167  return AVERROR(ENOMEM);
168  return ff_set_common_samplerates(ctx, formats);
169 }
170 
171 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
172 static void biquad_## name (BiquadsContext *s, \
173  const void *input, void *output, int len, \
174  double *in1, double *in2, \
175  double *out1, double *out2, \
176  double b0, double b1, double b2, \
177  double a1, double a2) \
178 { \
179  const type *ibuf = input; \
180  type *obuf = output; \
181  double i1 = *in1; \
182  double i2 = *in2; \
183  double o1 = *out1; \
184  double o2 = *out2; \
185  int i; \
186  a1 = -a1; \
187  a2 = -a2; \
188  \
189  for (i = 0; i+1 < len; i++) { \
190  o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
191  i2 = ibuf[i]; \
192  if (need_clipping && o2 < min) { \
193  s->clippings++; \
194  obuf[i] = min; \
195  } else if (need_clipping && o2 > max) { \
196  s->clippings++; \
197  obuf[i] = max; \
198  } else { \
199  obuf[i] = o2; \
200  } \
201  i++; \
202  o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
203  i1 = ibuf[i]; \
204  if (need_clipping && o1 < min) { \
205  s->clippings++; \
206  obuf[i] = min; \
207  } else if (need_clipping && o1 > max) { \
208  s->clippings++; \
209  obuf[i] = max; \
210  } else { \
211  obuf[i] = o1; \
212  } \
213  } \
214  if (i < len) { \
215  double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
216  i2 = i1; \
217  i1 = ibuf[i]; \
218  o2 = o1; \
219  o1 = o0; \
220  if (need_clipping && o0 < min) { \
221  s->clippings++; \
222  obuf[i] = min; \
223  } else if (need_clipping && o0 > max) { \
224  s->clippings++; \
225  obuf[i] = max; \
226  } else { \
227  obuf[i] = o0; \
228  } \
229  } \
230  *in1 = i1; \
231  *in2 = i2; \
232  *out1 = o1; \
233  *out2 = o2; \
234 }
235 
236 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
237 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
238 BIQUAD_FILTER(flt, float, -1., 1., 0)
239 BIQUAD_FILTER(dbl, double, -1., 1., 0)
240 
241 static int config_filter(AVFilterLink *outlink, int reset)
242 {
243  AVFilterContext *ctx = outlink->src;
244  BiquadsContext *s = ctx->priv;
245  AVFilterLink *inlink = ctx->inputs[0];
246  double A = exp(s->gain / 40 * log(10.));
247  double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
248  double alpha;
249 
250  if (w0 > M_PI) {
251  av_log(ctx, AV_LOG_ERROR,
252  "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
253  s->frequency, inlink->sample_rate);
254  return AVERROR(EINVAL);
255  }
256 
257  switch (s->width_type) {
258  case NONE:
259  alpha = 0.0;
260  break;
261  case HERTZ:
262  alpha = sin(w0) / (2 * s->frequency / s->width);
263  break;
264  case KHERTZ:
265  alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
266  break;
267  case OCTAVE:
268  alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
269  break;
270  case QFACTOR:
271  alpha = sin(w0) / (2 * s->width);
272  break;
273  case SLOPE:
274  alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
275  break;
276  default:
277  av_assert0(0);
278  }
279 
280  switch (s->filter_type) {
281  case biquad:
282  break;
283  case equalizer:
284  s->a0 = 1 + alpha / A;
285  s->a1 = -2 * cos(w0);
286  s->a2 = 1 - alpha / A;
287  s->b0 = 1 + alpha * A;
288  s->b1 = -2 * cos(w0);
289  s->b2 = 1 - alpha * A;
290  break;
291  case bass:
292  s->a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
293  s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
294  s->a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
295  s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
296  s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
297  s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
298  break;
299  case treble:
300  s->a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
301  s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
302  s->a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
303  s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
304  s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
305  s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
306  break;
307  case bandpass:
308  if (s->csg) {
309  s->a0 = 1 + alpha;
310  s->a1 = -2 * cos(w0);
311  s->a2 = 1 - alpha;
312  s->b0 = sin(w0) / 2;
313  s->b1 = 0;
314  s->b2 = -sin(w0) / 2;
315  } else {
316  s->a0 = 1 + alpha;
317  s->a1 = -2 * cos(w0);
318  s->a2 = 1 - alpha;
319  s->b0 = alpha;
320  s->b1 = 0;
321  s->b2 = -alpha;
322  }
323  break;
324  case bandreject:
325  s->a0 = 1 + alpha;
326  s->a1 = -2 * cos(w0);
327  s->a2 = 1 - alpha;
328  s->b0 = 1;
329  s->b1 = -2 * cos(w0);
330  s->b2 = 1;
331  break;
332  case lowpass:
333  if (s->poles == 1) {
334  s->a0 = 1;
335  s->a1 = -exp(-w0);
336  s->a2 = 0;
337  s->b0 = 1 + s->a1;
338  s->b1 = 0;
339  s->b2 = 0;
340  } else {
341  s->a0 = 1 + alpha;
342  s->a1 = -2 * cos(w0);
343  s->a2 = 1 - alpha;
344  s->b0 = (1 - cos(w0)) / 2;
345  s->b1 = 1 - cos(w0);
346  s->b2 = (1 - cos(w0)) / 2;
347  }
348  break;
349  case highpass:
350  if (s->poles == 1) {
351  s->a0 = 1;
352  s->a1 = -exp(-w0);
353  s->a2 = 0;
354  s->b0 = (1 - s->a1) / 2;
355  s->b1 = -s->b0;
356  s->b2 = 0;
357  } else {
358  s->a0 = 1 + alpha;
359  s->a1 = -2 * cos(w0);
360  s->a2 = 1 - alpha;
361  s->b0 = (1 + cos(w0)) / 2;
362  s->b1 = -(1 + cos(w0));
363  s->b2 = (1 + cos(w0)) / 2;
364  }
365  break;
366  case allpass:
367  s->a0 = 1 + alpha;
368  s->a1 = -2 * cos(w0);
369  s->a2 = 1 - alpha;
370  s->b0 = 1 - alpha;
371  s->b1 = -2 * cos(w0);
372  s->b2 = 1 + alpha;
373  break;
374  default:
375  av_assert0(0);
376  }
377 
378  av_log(ctx, AV_LOG_VERBOSE, "a=%lf %lf %lf:b=%lf %lf %lf\n", s->a0, s->a1, s->a2, s->b0, s->b1, s->b2);
379 
380  s->a1 /= s->a0;
381  s->a2 /= s->a0;
382  s->b0 /= s->a0;
383  s->b1 /= s->a0;
384  s->b2 /= s->a0;
385  s->a0 /= s->a0;
386 
387  s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
388  if (!s->cache)
389  return AVERROR(ENOMEM);
390  if (reset)
391  memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
392 
393  switch (inlink->format) {
394  case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
395  case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
396  case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
397  case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
398  default: av_assert0(0);
399  }
400 
402 
403  return 0;
404 }
405 
406 static int config_output(AVFilterLink *outlink)
407 {
408  return config_filter(outlink, 1);
409 }
410 
411 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
412 {
413  AVFilterContext *ctx = inlink->dst;
414  BiquadsContext *s = ctx->priv;
415  AVFilterLink *outlink = ctx->outputs[0];
416  AVFrame *out_buf;
417  int nb_samples = buf->nb_samples;
418  int ch;
419 
420  if (av_frame_is_writable(buf)) {
421  out_buf = buf;
422  } else {
423  out_buf = ff_get_audio_buffer(outlink, nb_samples);
424  if (!out_buf) {
425  av_frame_free(&buf);
426  return AVERROR(ENOMEM);
427  }
428  av_frame_copy_props(out_buf, buf);
429  }
430 
431  for (ch = 0; ch < buf->channels; ch++) {
432  if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
433  if (buf != out_buf)
434  memcpy(out_buf->extended_data[ch], buf->extended_data[ch], nb_samples * s->block_align);
435  continue;
436  }
437  s->filter(s, buf->extended_data[ch],
438  out_buf->extended_data[ch], nb_samples,
439  &s->cache[ch].i1, &s->cache[ch].i2,
440  &s->cache[ch].o1, &s->cache[ch].o2,
441  s->b0, s->b1, s->b2, s->a1, s->a2);
442  }
443 
444  if (s->clippings > 0)
445  av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
446  s->clippings = 0;
447 
448  if (buf != out_buf)
449  av_frame_free(&buf);
450 
451  return ff_filter_frame(outlink, out_buf);
452 }
453 
454 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
455  char *res, int res_len, int flags)
456 {
457  BiquadsContext *s = ctx->priv;
458  AVFilterLink *outlink = ctx->outputs[0];
459 
460  if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
461  (s->filter_type == equalizer ||
462  s->filter_type == bass ||
463  s->filter_type == treble ||
464  s->filter_type == bandpass ||
465  s->filter_type == bandreject||
466  s->filter_type == lowpass ||
467  s->filter_type == highpass ||
468  s->filter_type == allpass)) {
469  double freq;
470 
471  if (sscanf(args, "%lf", &freq) != 1) {
472  av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
473  return AVERROR(EINVAL);
474  }
475 
476  s->frequency = freq;
477  } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
478  (s->filter_type == equalizer ||
479  s->filter_type == bass ||
480  s->filter_type == treble)) {
481  double gain;
482 
483  if (sscanf(args, "%lf", &gain) != 1) {
484  av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
485  return AVERROR(EINVAL);
486  }
487 
488  s->gain = gain;
489  } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
490  (s->filter_type == equalizer ||
491  s->filter_type == bass ||
492  s->filter_type == treble ||
493  s->filter_type == bandpass ||
494  s->filter_type == bandreject||
495  s->filter_type == lowpass ||
496  s->filter_type == highpass ||
497  s->filter_type == allpass)) {
498  double width;
499 
500  if (sscanf(args, "%lf", &width) != 1) {
501  av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
502  return AVERROR(EINVAL);
503  }
504 
505  s->width = width;
506  } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
507  (s->filter_type == equalizer ||
508  s->filter_type == bass ||
509  s->filter_type == treble ||
510  s->filter_type == bandpass ||
511  s->filter_type == bandreject||
512  s->filter_type == lowpass ||
513  s->filter_type == highpass ||
514  s->filter_type == allpass)) {
515  char width_type;
516 
517  if (sscanf(args, "%c", &width_type) != 1) {
518  av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
519  return AVERROR(EINVAL);
520  }
521 
522  switch (width_type) {
523  case 'h': width_type = HERTZ; break;
524  case 'q': width_type = QFACTOR; break;
525  case 'o': width_type = OCTAVE; break;
526  case 's': width_type = SLOPE; break;
527  case 'k': width_type = KHERTZ; break;
528  default:
529  av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
530  return AVERROR(EINVAL);
531  }
532 
533  s->width_type = width_type;
534  } else if ((!strcmp(cmd, "a0") ||
535  !strcmp(cmd, "a1") ||
536  !strcmp(cmd, "a2") ||
537  !strcmp(cmd, "b0") ||
538  !strcmp(cmd, "b1") ||
539  !strcmp(cmd, "b2")) &&
540  s->filter_type == biquad) {
541  double value;
542 
543  if (sscanf(args, "%lf", &value) != 1) {
544  av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
545  return AVERROR(EINVAL);
546  }
547 
548  if (!strcmp(cmd, "a0"))
549  s->a0 = value;
550  else if (!strcmp(cmd, "a1"))
551  s->a1 = value;
552  else if (!strcmp(cmd, "a2"))
553  s->a2 = value;
554  else if (!strcmp(cmd, "b0"))
555  s->b0 = value;
556  else if (!strcmp(cmd, "b1"))
557  s->b1 = value;
558  else if (!strcmp(cmd, "b2"))
559  s->b2 = value;
560  }
561 
562  return config_filter(outlink, 0);
563 }
564 
566 {
567  BiquadsContext *s = ctx->priv;
568 
569  av_freep(&s->cache);
570 }
571 
572 static const AVFilterPad inputs[] = {
573  {
574  .name = "default",
575  .type = AVMEDIA_TYPE_AUDIO,
576  .filter_frame = filter_frame,
577  },
578  { NULL }
579 };
580 
581 static const AVFilterPad outputs[] = {
582  {
583  .name = "default",
584  .type = AVMEDIA_TYPE_AUDIO,
585  .config_props = config_output,
586  },
587  { NULL }
588 };
589 
590 #define OFFSET(x) offsetof(BiquadsContext, x)
591 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
592 
593 #define DEFINE_BIQUAD_FILTER(name_, description_) \
594 AVFILTER_DEFINE_CLASS(name_); \
595 static av_cold int name_##_init(AVFilterContext *ctx) \
596 { \
597  BiquadsContext *s = ctx->priv; \
598  s->class = &name_##_class; \
599  s->filter_type = name_; \
600  return init(ctx); \
601 } \
602  \
603 AVFilter ff_af_##name_ = { \
604  .name = #name_, \
605  .description = NULL_IF_CONFIG_SMALL(description_), \
606  .priv_size = sizeof(BiquadsContext), \
607  .init = name_##_init, \
608  .uninit = uninit, \
609  .query_formats = query_formats, \
610  .inputs = inputs, \
611  .outputs = outputs, \
612  .priv_class = &name_##_class, \
613  .process_command = process_command, \
614 }
615 
616 #if CONFIG_EQUALIZER_FILTER
617 static const AVOption equalizer_options[] = {
618  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
619  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
620  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
621  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
622  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
623  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
624  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
625  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
626  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
627  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
628  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
629  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
630  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
631  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
632  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
633  {NULL}
634 };
635 
636 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
637 #endif /* CONFIG_EQUALIZER_FILTER */
638 #if CONFIG_BASS_FILTER
639 static const AVOption bass_options[] = {
640  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
641  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
642  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
643  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
644  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
645  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
646  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
647  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
648  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
649  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
650  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
651  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
652  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
653  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
654  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
655  {NULL}
656 };
657 
658 DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
659 #endif /* CONFIG_BASS_FILTER */
660 #if CONFIG_TREBLE_FILTER
661 static const AVOption treble_options[] = {
662  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
663  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
664  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
665  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
666  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
667  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
668  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
669  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
670  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
671  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
672  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
673  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
674  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
675  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
676  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
677  {NULL}
678 };
679 
680 DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
681 #endif /* CONFIG_TREBLE_FILTER */
682 #if CONFIG_BANDPASS_FILTER
683 static const AVOption bandpass_options[] = {
684  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
685  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
686  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
687  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
688  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
689  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
690  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
691  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
692  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
693  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
694  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
695  {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
696  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
697  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
698  {NULL}
699 };
700 
701 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
702 #endif /* CONFIG_BANDPASS_FILTER */
703 #if CONFIG_BANDREJECT_FILTER
704 static const AVOption bandreject_options[] = {
705  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
706  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
707  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
708  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
709  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
710  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
711  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
712  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
713  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
714  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
715  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
716  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
717  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
718  {NULL}
719 };
720 
721 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
722 #endif /* CONFIG_BANDREJECT_FILTER */
723 #if CONFIG_LOWPASS_FILTER
724 static const AVOption lowpass_options[] = {
725  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
726  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
727  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
728  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
729  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
730  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
731  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
732  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
733  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
734  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
735  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
736  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
737  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, 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(lowpass, "Apply a low-pass filter with 3dB point frequency.");
744 #endif /* CONFIG_LOWPASS_FILTER */
745 #if CONFIG_HIGHPASS_FILTER
746 static const AVOption highpass_options[] = {
747  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
748  {"f", "set 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 width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
757  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
758  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
759  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
760  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
761  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
762  {NULL}
763 };
764 
765 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
766 #endif /* CONFIG_HIGHPASS_FILTER */
767 #if CONFIG_ALLPASS_FILTER
768 static const AVOption allpass_options[] = {
769  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
770  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
771  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
772  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
773  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
774  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
775  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
776  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
777  {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
778  {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
779  {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, 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(allpass, "Apply a two-pole all-pass filter.");
786 #endif /* CONFIG_ALLPASS_FILTER */
787 #if CONFIG_BIQUAD_FILTER
788 static const AVOption biquad_options[] = {
789  {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
790  {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
791  {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
792  {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
793  {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
794  {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
795  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
796  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
797  {NULL}
798 };
799 
800 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
801 #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
const char * s
Definition: avisynth_c.h:768
static float alpha(float a)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
#define av_realloc_f(p, o, n)
AVOption.
Definition: opt.h:246
ChanCache * cache
Definition: af_biquads.c:114
#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:94
#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:572
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:114
#define OFFSET(x)
Definition: af_biquads.c:590
#define av_cold
Definition: attributes.h:82
AVOptions.
static int flags
Definition: log.c:55
#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:581
A filter pad used for either input or output.
Definition: internal.h:54
static av_cold int init(AVFilterContext *ctx)
Definition: af_biquads.c:123
#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 FLAGS
Definition: af_biquads.c:591
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
uint16_t width
Definition: gdv.c:47
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t channels
Definition: af_biquads.c:109
int8_t exp
Definition: eval.c:72
double o1
Definition: af_biquads.c:95
int channels
number of audio channels, only used for audio.
Definition: frame.h:523
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)
Definition: af_biquads.c:118
signed 32 bits, planar
Definition: samplefmt.h:68
const char AVS_Value args
Definition: avisynth_c.h:780
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
#define a2
Definition: regdef.h:48
A list of supported channel layouts.
Definition: formats.h:85
#define BIQUAD_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:171
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
typedef void(RENAME(mix_any_func_type))
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:592
static int config_output(AVFilterLink *outlink)
Definition: af_biquads.c:406
void * buf
Definition: avisynth_c.h:690
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:593
static int query_formats(AVFilterContext *ctx)
Definition: af_biquads.c:138
double o2
Definition: af_biquads.c:95
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
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_biquads.c:565
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
static int config_filter(AVFilterLink *outlink, int reset)
Definition: af_biquads.c:241
WidthType
Definition: af_biquads.c:83
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_biquads.c:411
int len
double i1
Definition: af_biquads.c:94
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:454
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:67
double frequency
Definition: af_biquads.c:107
#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:265
enum FilterType filter_type
Definition: af_biquads.c:101
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:284
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:652