FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_biquads.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Paul B Mahol
3  * Copyright (c) 2006-2008 Rob Sykes <robs@users.sourceforge.net>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /*
23  * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
24  * see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
25  *
26  * 1-pole filters based on code (c) 2000 Chris Bagwell <cbagwell@sprynet.com>
27  * Algorithms: Recursive single pole low/high pass filter
28  * Reference: The Scientist and Engineer's Guide to Digital Signal Processing
29  *
30  * low-pass: output[N] = input[N] * A + output[N-1] * B
31  * X = exp(-2.0 * pi * Fc)
32  * A = 1 - X
33  * B = X
34  * Fc = cutoff freq / sample rate
35  *
36  * Mimics an RC low-pass filter:
37  *
38  * ---/\/\/\/\----------->
39  * |
40  * --- C
41  * ---
42  * |
43  * |
44  * V
45  *
46  * high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
47  * X = exp(-2.0 * pi * Fc)
48  * A0 = (1 + X) / 2
49  * A1 = -(1 + X) / 2
50  * B1 = X
51  * Fc = cutoff freq / sample rate
52  *
53  * Mimics an RC high-pass filter:
54  *
55  * || C
56  * ----||--------->
57  * || |
58  * <
59  * > R
60  * <
61  * |
62  * V
63  */
64 
65 #include "libavutil/avassert.h"
66 #include "libavutil/opt.h"
67 #include "audio.h"
68 #include "avfilter.h"
69 #include "internal.h"
70 
71 enum FilterType {
82 };
83 
84 enum WidthType {
90 };
91 
92 typedef struct ChanCache {
93  double i1, i2;
94  double o1, o2;
95 } ChanCache;
96 
97 typedef struct BiquadsContext {
98  const AVClass *class;
99 
102  int poles;
103  int csg;
104 
105  double gain;
106  double frequency;
107  double width;
108  uint64_t channels;
109 
110  double a0, a1, a2;
111  double b0, b1, b2;
112 
116 
117  void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
118  double *i1, double *i2, double *o1, double *o2,
119  double b0, double b1, double b2, double a1, double a2);
121 
123 {
124  BiquadsContext *s = ctx->priv;
125 
126  if (s->filter_type != biquad) {
127  if (s->frequency <= 0 || s->width <= 0) {
128  av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
129  s->frequency, s->width);
130  return AVERROR(EINVAL);
131  }
132  }
133 
134  return 0;
135 }
136 
138 {
141  static const enum AVSampleFormat sample_fmts[] = {
147  };
148  int ret;
149 
150  layouts = ff_all_channel_counts();
151  if (!layouts)
152  return AVERROR(ENOMEM);
153  ret = ff_set_common_channel_layouts(ctx, layouts);
154  if (ret < 0)
155  return ret;
156 
157  formats = ff_make_format_list(sample_fmts);
158  if (!formats)
159  return AVERROR(ENOMEM);
160  ret = ff_set_common_formats(ctx, formats);
161  if (ret < 0)
162  return ret;
163 
164  formats = ff_all_samplerates();
165  if (!formats)
166  return AVERROR(ENOMEM);
167  return ff_set_common_samplerates(ctx, formats);
168 }
169 
170 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
171 static void biquad_## name (BiquadsContext *s, \
172  const void *input, void *output, int len, \
173  double *in1, double *in2, \
174  double *out1, double *out2, \
175  double b0, double b1, double b2, \
176  double a1, double a2) \
177 { \
178  const type *ibuf = input; \
179  type *obuf = output; \
180  double i1 = *in1; \
181  double i2 = *in2; \
182  double o1 = *out1; \
183  double o2 = *out2; \
184  int i; \
185  a1 = -a1; \
186  a2 = -a2; \
187  \
188  for (i = 0; i+1 < len; i++) { \
189  o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
190  i2 = ibuf[i]; \
191  if (need_clipping && o2 < min) { \
192  s->clippings++; \
193  obuf[i] = min; \
194  } else if (need_clipping && o2 > max) { \
195  s->clippings++; \
196  obuf[i] = max; \
197  } else { \
198  obuf[i] = o2; \
199  } \
200  i++; \
201  o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
202  i1 = ibuf[i]; \
203  if (need_clipping && o1 < min) { \
204  s->clippings++; \
205  obuf[i] = min; \
206  } else if (need_clipping && o1 > max) { \
207  s->clippings++; \
208  obuf[i] = max; \
209  } else { \
210  obuf[i] = o1; \
211  } \
212  } \
213  if (i < len) { \
214  double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
215  i2 = i1; \
216  i1 = ibuf[i]; \
217  o2 = o1; \
218  o1 = o0; \
219  if (need_clipping && o0 < min) { \
220  s->clippings++; \
221  obuf[i] = min; \
222  } else if (need_clipping && o0 > max) { \
223  s->clippings++; \
224  obuf[i] = max; \
225  } else { \
226  obuf[i] = o0; \
227  } \
228  } \
229  *in1 = i1; \
230  *in2 = i2; \
231  *out1 = o1; \
232  *out2 = o2; \
233 }
234 
235 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
236 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
237 BIQUAD_FILTER(flt, float, -1., 1., 0)
238 BIQUAD_FILTER(dbl, double, -1., 1., 0)
239 
240 static int config_output(AVFilterLink *outlink)
241 {
242  AVFilterContext *ctx = outlink->src;
243  BiquadsContext *s = ctx->priv;
244  AVFilterLink *inlink = ctx->inputs[0];
245  double A = exp(s->gain / 40 * log(10.));
246  double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
247  double alpha;
248 
249  if (w0 > M_PI) {
250  av_log(ctx, AV_LOG_ERROR,
251  "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
252  s->frequency, inlink->sample_rate);
253  return AVERROR(EINVAL);
254  }
255 
256  switch (s->width_type) {
257  case NONE:
258  alpha = 0.0;
259  break;
260  case HERTZ:
261  alpha = sin(w0) / (2 * s->frequency / s->width);
262  break;
263  case OCTAVE:
264  alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
265  break;
266  case QFACTOR:
267  alpha = sin(w0) / (2 * s->width);
268  break;
269  case SLOPE:
270  alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
271  break;
272  default:
273  av_assert0(0);
274  }
275 
276  switch (s->filter_type) {
277  case biquad:
278  break;
279  case equalizer:
280  s->a0 = 1 + alpha / A;
281  s->a1 = -2 * cos(w0);
282  s->a2 = 1 - alpha / A;
283  s->b0 = 1 + alpha * A;
284  s->b1 = -2 * cos(w0);
285  s->b2 = 1 - alpha * A;
286  break;
287  case bass:
288  s->a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
289  s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
290  s->a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
291  s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
292  s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
293  s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
294  break;
295  case treble:
296  s->a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
297  s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
298  s->a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
299  s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
300  s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
301  s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
302  break;
303  case bandpass:
304  if (s->csg) {
305  s->a0 = 1 + alpha;
306  s->a1 = -2 * cos(w0);
307  s->a2 = 1 - alpha;
308  s->b0 = sin(w0) / 2;
309  s->b1 = 0;
310  s->b2 = -sin(w0) / 2;
311  } else {
312  s->a0 = 1 + alpha;
313  s->a1 = -2 * cos(w0);
314  s->a2 = 1 - alpha;
315  s->b0 = alpha;
316  s->b1 = 0;
317  s->b2 = -alpha;
318  }
319  break;
320  case bandreject:
321  s->a0 = 1 + alpha;
322  s->a1 = -2 * cos(w0);
323  s->a2 = 1 - alpha;
324  s->b0 = 1;
325  s->b1 = -2 * cos(w0);
326  s->b2 = 1;
327  break;
328  case lowpass:
329  if (s->poles == 1) {
330  s->a0 = 1;
331  s->a1 = -exp(-w0);
332  s->a2 = 0;
333  s->b0 = 1 + s->a1;
334  s->b1 = 0;
335  s->b2 = 0;
336  } else {
337  s->a0 = 1 + alpha;
338  s->a1 = -2 * cos(w0);
339  s->a2 = 1 - alpha;
340  s->b0 = (1 - cos(w0)) / 2;
341  s->b1 = 1 - cos(w0);
342  s->b2 = (1 - cos(w0)) / 2;
343  }
344  break;
345  case highpass:
346  if (s->poles == 1) {
347  s->a0 = 1;
348  s->a1 = -exp(-w0);
349  s->a2 = 0;
350  s->b0 = (1 - s->a1) / 2;
351  s->b1 = -s->b0;
352  s->b2 = 0;
353  } else {
354  s->a0 = 1 + alpha;
355  s->a1 = -2 * cos(w0);
356  s->a2 = 1 - alpha;
357  s->b0 = (1 + cos(w0)) / 2;
358  s->b1 = -(1 + cos(w0));
359  s->b2 = (1 + cos(w0)) / 2;
360  }
361  break;
362  case allpass:
363  s->a0 = 1 + alpha;
364  s->a1 = -2 * cos(w0);
365  s->a2 = 1 - alpha;
366  s->b0 = 1 - alpha;
367  s->b1 = -2 * cos(w0);
368  s->b2 = 1 + alpha;
369  break;
370  default:
371  av_assert0(0);
372  }
373 
374  s->a1 /= s->a0;
375  s->a2 /= s->a0;
376  s->b0 /= s->a0;
377  s->b1 /= s->a0;
378  s->b2 /= s->a0;
379 
380  s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
381  if (!s->cache)
382  return AVERROR(ENOMEM);
383  memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
384 
385  switch (inlink->format) {
386  case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
387  case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
388  case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
389  case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
390  default: av_assert0(0);
391  }
392 
394 
395  return 0;
396 }
397 
398 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
399 {
400  AVFilterContext *ctx = inlink->dst;
401  BiquadsContext *s = ctx->priv;
402  AVFilterLink *outlink = ctx->outputs[0];
403  AVFrame *out_buf;
404  int nb_samples = buf->nb_samples;
405  int ch;
406 
407  if (av_frame_is_writable(buf)) {
408  out_buf = buf;
409  } else {
410  out_buf = ff_get_audio_buffer(inlink, nb_samples);
411  if (!out_buf) {
412  av_frame_free(&buf);
413  return AVERROR(ENOMEM);
414  }
415  av_frame_copy_props(out_buf, buf);
416  }
417 
418  for (ch = 0; ch < buf->channels; ch++) {
419  if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
420  if (buf != out_buf)
421  memcpy(out_buf->extended_data[ch], buf->extended_data[ch], nb_samples * s->block_align);
422  continue;
423  }
424  s->filter(s, buf->extended_data[ch],
425  out_buf->extended_data[ch], nb_samples,
426  &s->cache[ch].i1, &s->cache[ch].i2,
427  &s->cache[ch].o1, &s->cache[ch].o2,
428  s->b0, s->b1, s->b2, s->a1, s->a2);
429  }
430 
431  if (s->clippings > 0)
432  av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
433  s->clippings = 0;
434 
435  if (buf != out_buf)
436  av_frame_free(&buf);
437 
438  return ff_filter_frame(outlink, out_buf);
439 }
440 
442 {
443  BiquadsContext *s = ctx->priv;
444 
445  av_freep(&s->cache);
446 }
447 
448 static const AVFilterPad inputs[] = {
449  {
450  .name = "default",
451  .type = AVMEDIA_TYPE_AUDIO,
452  .filter_frame = filter_frame,
453  },
454  { NULL }
455 };
456 
457 static const AVFilterPad outputs[] = {
458  {
459  .name = "default",
460  .type = AVMEDIA_TYPE_AUDIO,
461  .config_props = config_output,
462  },
463  { NULL }
464 };
465 
466 #define OFFSET(x) offsetof(BiquadsContext, x)
467 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
468 
469 #define DEFINE_BIQUAD_FILTER(name_, description_) \
470 AVFILTER_DEFINE_CLASS(name_); \
471 static av_cold int name_##_init(AVFilterContext *ctx) \
472 { \
473  BiquadsContext *s = ctx->priv; \
474  s->class = &name_##_class; \
475  s->filter_type = name_; \
476  return init(ctx); \
477 } \
478  \
479 AVFilter ff_af_##name_ = { \
480  .name = #name_, \
481  .description = NULL_IF_CONFIG_SMALL(description_), \
482  .priv_size = sizeof(BiquadsContext), \
483  .init = name_##_init, \
484  .uninit = uninit, \
485  .query_formats = query_formats, \
486  .inputs = inputs, \
487  .outputs = outputs, \
488  .priv_class = &name_##_class, \
489 }
490 
491 #if CONFIG_EQUALIZER_FILTER
492 static const AVOption equalizer_options[] = {
493  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
494  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
495  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
496  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
497  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
498  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
499  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
500  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
501  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
502  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
503  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
504  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
505  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
506  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
507  {NULL}
508 };
509 
510 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
511 #endif /* CONFIG_EQUALIZER_FILTER */
512 #if CONFIG_BASS_FILTER
513 static const AVOption bass_options[] = {
514  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
515  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
516  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
517  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
518  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
519  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
520  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
521  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
522  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
523  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
524  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
525  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
526  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
527  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
528  {NULL}
529 };
530 
531 DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
532 #endif /* CONFIG_BASS_FILTER */
533 #if CONFIG_TREBLE_FILTER
534 static const AVOption treble_options[] = {
535  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
536  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
537  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
538  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
539  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
540  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
541  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
542  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
543  {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
544  {"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
545  {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
546  {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
547  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
548  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
549  {NULL}
550 };
551 
552 DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
553 #endif /* CONFIG_TREBLE_FILTER */
554 #if CONFIG_BANDPASS_FILTER
555 static const AVOption bandpass_options[] = {
556  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
557  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
558  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
559  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
560  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
561  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
562  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
563  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
564  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
565  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
566  {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
567  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
568  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
569  {NULL}
570 };
571 
572 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
573 #endif /* CONFIG_BANDPASS_FILTER */
574 #if CONFIG_BANDREJECT_FILTER
575 static const AVOption bandreject_options[] = {
576  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
577  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
578  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
579  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
580  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
581  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
582  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
583  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
584  {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
585  {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
586  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
587  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
588  {NULL}
589 };
590 
591 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
592 #endif /* CONFIG_BANDREJECT_FILTER */
593 #if CONFIG_LOWPASS_FILTER
594 static const AVOption lowpass_options[] = {
595  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
596  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
597  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
598  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
599  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
600  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
601  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
602  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
603  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
604  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
605  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
606  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
607  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
608  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
609  {NULL}
610 };
611 
612 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
613 #endif /* CONFIG_LOWPASS_FILTER */
614 #if CONFIG_HIGHPASS_FILTER
615 static const AVOption highpass_options[] = {
616  {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
617  {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
618  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
619  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
620  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
621  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
622  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
623  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
624  {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
625  {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
626  {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
627  {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
628  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
629  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
630  {NULL}
631 };
632 
633 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
634 #endif /* CONFIG_HIGHPASS_FILTER */
635 #if CONFIG_ALLPASS_FILTER
636 static const AVOption allpass_options[] = {
637  {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
638  {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
639  {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, SLOPE, FLAGS, "width_type"},
640  {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, SLOPE, FLAGS, "width_type"},
641  {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
642  {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
643  {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
644  {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
645  {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
646  {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
647  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
648  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
649  {NULL}
650 };
651 
652 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
653 #endif /* CONFIG_ALLPASS_FILTER */
654 #if CONFIG_BIQUAD_FILTER
655 static const AVOption biquad_options[] = {
656  {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
657  {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
658  {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
659  {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
660  {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
661  {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
662  {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
663  {"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
664  {NULL}
665 };
666 
667 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
668 #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:201
#define av_realloc_f(p, o, n)
AVOption.
Definition: opt.h:246
ChanCache * cache
Definition: af_biquads.c:113
#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:93
#define a0
Definition: regdef.h:46
double, planar
Definition: samplefmt.h:70
#define a1
Definition: regdef.h:47
static const AVFilterPad inputs[]
Definition: af_biquads.c:448
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:1151
#define OFFSET(x)
Definition: af_biquads.c:466
#define av_cold
Definition: attributes.h:82
AVOptions.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
#define A(x)
Definition: vp56_arith.h:28
#define av_log(a,...)
static const AVFilterPad outputs[]
Definition: af_biquads.c:457
A filter pad used for either input or output.
Definition: internal.h:54
static av_cold int init(AVFilterContext *ctx)
Definition: af_biquads.c:122
#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:467
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:163
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:108
int8_t exp
Definition: eval.c:65
double o1
Definition: af_biquads.c:94
int channels
number of audio channels, only used for audio.
Definition: frame.h:506
signed 32 bits, planar
Definition: samplefmt.h:68
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
#define a2
Definition: regdef.h:48
A list of supported channel layouts.
Definition: formats.h:85
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:117
#define BIQUAD_FILTER(name, type, min, max, need_clipping)
Definition: af_biquads.c:170
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:543
static int config_output(AVFilterLink *outlink)
Definition: af_biquads.c:240
void * buf
Definition: avisynth_c.h:690
Describe the class of an AVClass context structure.
Definition: log.h:67
#define DEFINE_BIQUAD_FILTER(name_, description_)
Definition: af_biquads.c:469
static int query_formats(AVFilterContext *ctx)
Definition: af_biquads.c:137
double o2
Definition: af_biquads.c:94
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:441
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.
WidthType
Definition: af_biquads.c:84
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_biquads.c:398
int len
double i1
Definition: af_biquads.c:93
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
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:67
double frequency
Definition: af_biquads.c:106
#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:248
enum FilterType filter_type
Definition: af_biquads.c:100
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
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:603