2 * Copyright (c) 2013 Paul B Mahol
3 * Copyright (c) 2006-2008 Rob Sykes <robs@users.sourceforge.net>
5 * This file is part of FFmpeg.
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.
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.
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
23 * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
24 * see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
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
30 * low-pass: output[N] = input[N] * A + output[N-1] * B
31 * X = exp(-2.0 * pi * Fc)
34 * Fc = cutoff freq / sample rate
36 * Mimics an RC low-pass filter:
38 * ---/\/\/\/\----------->
46 * high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
47 * X = exp(-2.0 * pi * Fc)
51 * Fc = cutoff freq / sample rate
53 * Mimics an RC high-pass filter:
65 #include "libavutil/avassert.h"
66 #include "libavutil/opt.h"
92 typedef struct ChanCache {
97 typedef struct BiquadsContext {
100 enum FilterType filter_type;
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);
122 static av_cold int init(AVFilterContext *ctx)
124 BiquadsContext *s = ctx->priv;
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);
137 static int query_formats(AVFilterContext *ctx)
139 AVFilterFormats *formats;
140 AVFilterChannelLayouts *layouts;
141 static const enum AVSampleFormat sample_fmts[] = {
150 layouts = ff_all_channel_counts();
152 return AVERROR(ENOMEM);
153 ret = ff_set_common_channel_layouts(ctx, layouts);
157 formats = ff_make_format_list(sample_fmts);
159 return AVERROR(ENOMEM);
160 ret = ff_set_common_formats(ctx, formats);
164 formats = ff_all_samplerates();
166 return AVERROR(ENOMEM);
167 return ff_set_common_samplerates(ctx, formats);
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) \
178 const type *ibuf = input; \
179 type *obuf = output; \
188 for (i = 0; i+1 < len; i++) { \
189 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
191 if (need_clipping && o2 < min) { \
194 } else if (need_clipping && o2 > max) { \
201 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
203 if (need_clipping && o1 < min) { \
206 } else if (need_clipping && o1 > max) { \
214 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
219 if (need_clipping && o0 < min) { \
222 } else if (need_clipping && o0 > max) { \
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)
240 static int config_output(AVFilterLink *outlink)
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;
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);
256 switch (s->width_type) {
261 alpha = sin(w0) / (2 * s->frequency / s->width);
264 alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
267 alpha = sin(w0) / (2 * s->width);
270 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
276 switch (s->filter_type) {
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;
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);
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);
306 s->a1 = -2 * cos(w0);
310 s->b2 = -sin(w0) / 2;
313 s->a1 = -2 * cos(w0);
322 s->a1 = -2 * cos(w0);
325 s->b1 = -2 * cos(w0);
338 s->a1 = -2 * cos(w0);
340 s->b0 = (1 - cos(w0)) / 2;
342 s->b2 = (1 - cos(w0)) / 2;
350 s->b0 = (1 - s->a1) / 2;
355 s->a1 = -2 * cos(w0);
357 s->b0 = (1 + cos(w0)) / 2;
358 s->b1 = -(1 + cos(w0));
359 s->b2 = (1 + cos(w0)) / 2;
364 s->a1 = -2 * cos(w0);
367 s->b1 = -2 * cos(w0);
380 s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
382 return AVERROR(ENOMEM);
383 memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
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);
393 s->block_align = av_get_bytes_per_sample(inlink->format);
398 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
400 AVFilterContext *ctx = inlink->dst;
401 BiquadsContext *s = ctx->priv;
402 AVFilterLink *outlink = ctx->outputs[0];
404 int nb_samples = buf->nb_samples;
407 if (av_frame_is_writable(buf)) {
410 out_buf = ff_get_audio_buffer(inlink, nb_samples);
413 return AVERROR(ENOMEM);
415 av_frame_copy_props(out_buf, buf);
418 for (ch = 0; ch < buf->channels; ch++) {
419 if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
421 memcpy(out_buf->extended_data[ch], buf->extended_data[ch], nb_samples * s->block_align);
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);
431 if (s->clippings > 0)
432 av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
438 return ff_filter_frame(outlink, out_buf);
441 static av_cold void uninit(AVFilterContext *ctx)
443 BiquadsContext *s = ctx->priv;
448 static const AVFilterPad inputs[] = {
451 .type = AVMEDIA_TYPE_AUDIO,
452 .filter_frame = filter_frame,
457 static const AVFilterPad outputs[] = {
460 .type = AVMEDIA_TYPE_AUDIO,
461 .config_props = config_output,
466 #define OFFSET(x) offsetof(BiquadsContext, x)
467 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
469 #define DEFINE_BIQUAD_FILTER(name_, description_) \
470 AVFILTER_DEFINE_CLASS(name_); \
471 static av_cold int name_##_init(AVFilterContext *ctx) \
473 BiquadsContext *s = ctx->priv; \
474 s->class = &name_##_class; \
475 s->filter_type = name_; \
479 AVFilter ff_af_##name_ = { \
481 .description = NULL_IF_CONFIG_SMALL(description_), \
482 .priv_size = sizeof(BiquadsContext), \
483 .init = name_##_init, \
485 .query_formats = query_formats, \
487 .outputs = outputs, \
488 .priv_class = &name_##_class, \
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},
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},
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},
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},
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},
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},
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},
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},
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},
667 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
668 #endif /* CONFIG_BIQUAD_FILTER */