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 "config_components.h"
67 #include "libavutil/avassert.h"
68 #include "libavutil/channel_layout.h"
69 #include "libavutil/ffmath.h"
70 #include "libavutil/opt.h"
112 typedef struct ChanCache {
120 typedef struct BiquadsContext {
121 const AVClass *class;
123 enum FilterType filter_type;
138 AVChannelLayout ch_layout;
145 double oa0, oa1, oa2;
146 double ob0, ob1, ob2;
156 void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
157 double *i1, double *i2, double *o1, double *o2,
158 double b0, double b1, double b2, double a0, double a1, double a2, int *clippings,
162 static int query_formats(AVFilterContext *ctx)
164 BiquadsContext *s = ctx->priv;
165 static const enum AVSampleFormat auto_sample_fmts[] = {
172 enum AVSampleFormat sample_fmts[] = {
176 const enum AVSampleFormat *sample_fmts_list = sample_fmts;
177 int ret = ff_set_common_all_channel_counts(ctx);
181 switch (s->precision) {
183 sample_fmts[0] = AV_SAMPLE_FMT_S16P;
186 sample_fmts[0] = AV_SAMPLE_FMT_S32P;
189 sample_fmts[0] = AV_SAMPLE_FMT_FLTP;
192 sample_fmts[0] = AV_SAMPLE_FMT_DBLP;
195 sample_fmts_list = auto_sample_fmts;
198 ret = ff_set_common_formats_from_list(ctx, sample_fmts_list);
202 return ff_set_common_all_samplerates(ctx);
205 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
206 static void biquad_## name (BiquadsContext *s, \
207 const void *input, void *output, int len, \
208 double *in1, double *in2, \
209 double *out1, double *out2, \
210 double b0, double b1, double b2, \
211 double a0, double a1, double a2, int *clippings, \
214 const type *ibuf = input; \
215 type *obuf = output; \
220 double wet = s->mix; \
221 double dry = 1. - wet; \
227 for (i = 0; i+1 < len; i++) { \
228 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
230 out = o2 * wet + i2 * dry; \
233 } else if (need_clipping && out < min) { \
236 } else if (need_clipping && out > max) { \
243 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
245 out = o1 * wet + i1 * dry; \
248 } else if (need_clipping && out < min) { \
251 } else if (need_clipping && out > max) { \
259 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
264 out = o0 * wet + i1 * dry; \
267 } else if (need_clipping && out < min) { \
270 } else if (need_clipping && out > max) { \
283 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
284 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
285 BIQUAD_FILTER(flt, float, -1., 1., 0)
286 BIQUAD_FILTER(dbl, double, -1., 1., 0)
288 #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \
289 static void biquad_dii_## name (BiquadsContext *s, \
290 const void *input, void *output, int len, \
291 double *z1, double *z2, \
292 double *unused1, double *unused2, \
293 double b0, double b1, double b2, \
294 double a0, double a1, double a2, int *clippings, \
297 const type *ibuf = input; \
298 type *obuf = output; \
301 double wet = s->mix; \
302 double dry = 1. - wet; \
303 double in, out, w0; \
308 for (int i = 0; i < len; i++) { \
310 w0 = in + a1 * w1 + a2 * w2; \
311 out = b0 * w0 + b1 * w1 + b2 * w2; \
314 out = out * wet + in * dry; \
317 } else if (need_clipping && out < min) { \
320 } else if (need_clipping && out > max) { \
331 BIQUAD_DII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
332 BIQUAD_DII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
333 BIQUAD_DII_FILTER(flt, float, -1., 1., 0)
334 BIQUAD_DII_FILTER(dbl, double, -1., 1., 0)
336 #define BIQUAD_TDI_FILTER(name, type, min, max, need_clipping) \
337 static void biquad_tdi_## name (BiquadsContext *s, \
338 const void *input, void *output, int len, \
339 double *z1, double *z2, \
340 double *z3, double *z4, \
341 double b0, double b1, double b2, \
342 double a0, double a1, double a2, int *clippings, \
345 const type *ibuf = input; \
346 type *obuf = output; \
351 double wet = s->mix; \
352 double dry = 1. - wet; \
358 for (int i = 0; i < len; i++) { \
359 double t1, t2, t3, t4; \
365 out = b0 * in + s3; \
366 out = out * wet + in * dry; \
367 s1 = t1; s2 = t2; s3 = t3; s4 = t4; \
370 } else if (need_clipping && out < min) { \
373 } else if (need_clipping && out > max) { \
387 BIQUAD_TDI_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
388 BIQUAD_TDI_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
389 BIQUAD_TDI_FILTER(flt, float, -1., 1., 0)
390 BIQUAD_TDI_FILTER(dbl, double, -1., 1., 0)
392 #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \
393 static void biquad_tdii_## name (BiquadsContext *s, \
394 const void *input, void *output, int len, \
395 double *z1, double *z2, \
396 double *unused1, double *unused2, \
397 double b0, double b1, double b2, \
398 double a0, double a1, double a2, int *clippings, \
401 const type *ibuf = input; \
402 type *obuf = output; \
405 double wet = s->mix; \
406 double dry = 1. - wet; \
412 for (int i = 0; i < len; i++) { \
414 out = b0 * in + w1; \
415 w1 = b1 * in + w2 + a1 * out; \
416 w2 = b2 * in + a2 * out; \
417 out = out * wet + in * dry; \
420 } else if (need_clipping && out < min) { \
423 } else if (need_clipping && out > max) { \
434 BIQUAD_TDII_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
435 BIQUAD_TDII_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
436 BIQUAD_TDII_FILTER(flt, float, -1., 1., 0)
437 BIQUAD_TDII_FILTER(dbl, double, -1., 1., 0)
439 #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \
440 static void biquad_latt_## name (BiquadsContext *s, \
441 const void *input, void *output, int len, \
442 double *z1, double *z2, \
443 double *unused1, double *unused2, \
444 double v0, double v1, double v2, \
445 double unused, double k0, double k1, \
449 const type *ibuf = input; \
450 type *obuf = output; \
453 double wet = s->mix; \
454 double dry = 1. - wet; \
458 for (int i = 0; i < len; i++) { \
473 out = out * wet + in * dry; \
476 } else if (need_clipping && out < min) { \
479 } else if (need_clipping && out > max) { \
490 BIQUAD_LATT_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
491 BIQUAD_LATT_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
492 BIQUAD_LATT_FILTER(flt, float, -1., 1., 0)
493 BIQUAD_LATT_FILTER(dbl, double, -1., 1., 0)
495 #define BIQUAD_SVF_FILTER(name, type, min, max, need_clipping) \
496 static void biquad_svf_## name (BiquadsContext *s, \
497 const void *input, void *output, int len, \
498 double *y0, double *y1, \
499 double *unused1, double *unused2, \
500 double b0, double b1, double b2, \
501 double a0, double a1, double a2, int *clippings, \
504 const type *ibuf = input; \
505 type *obuf = output; \
508 double wet = s->mix; \
509 double dry = 1. - wet; \
513 for (int i = 0; i < len; i++) { \
515 out = b2 * in + s0; \
516 t0 = b0 * in + a1 * s0 + s1; \
517 t1 = b1 * in + a2 * s0; \
521 out = out * wet + in * dry; \
524 } else if (need_clipping && out < min) { \
527 } else if (need_clipping && out > max) { \
538 BIQUAD_SVF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
539 BIQUAD_SVF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
540 BIQUAD_SVF_FILTER(flt, float, -1., 1., 0)
541 BIQUAD_SVF_FILTER(dbl, double, -1., 1., 0)
543 #define BIQUAD_ZDF_FILTER(name, type, min, max, need_clipping) \
544 static void biquad_zdf_## name (BiquadsContext *s, \
545 const void *input, void *output, int len, \
546 double *y0, double *y1, \
547 double *unused1, double *unused2, \
548 double m0, double m1, double m2, \
549 double a0, double a1, double a2, int *clippings, \
552 const type *ibuf = input; \
553 type *obuf = output; \
556 double wet = s->mix; \
557 double dry = 1. - wet; \
560 for (int i = 0; i < len; i++) { \
561 const double in = ibuf[i]; \
562 const double v0 = in; \
563 const double v3 = v0 - b1; \
564 const double v1 = a0 * b0 + a1 * v3; \
565 const double v2 = b1 + a1 * b0 + a2 * v3; \
570 out = m0 * v0 + m1 * v1 + m2 * v2; \
571 out = out * wet + in * dry; \
574 } else if (need_clipping && out < min) { \
577 } else if (need_clipping && out > max) { \
588 BIQUAD_ZDF_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
589 BIQUAD_ZDF_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
590 BIQUAD_ZDF_FILTER(flt, float, -1., 1., 0)
591 BIQUAD_ZDF_FILTER(dbl, double, -1., 1., 0)
593 static void convert_dir2latt(BiquadsContext *s)
595 double k0, k1, v0, v1, v2;
598 k0 = s->a1 / (1. + k1);
600 v1 = s->b1 - v2 * s->a1;
601 v0 = s->b0 - v1 * k0 - v2 * k1;
610 static void convert_dir2svf(BiquadsContext *s)
617 b[0] = s->b1 - s->a1 * s->b0;
618 b[1] = s->b2 - s->a2 * s->b0;
628 static double convert_width2qfactor(double width,
634 double w0 = 2. * M_PI * frequency / sample_rate;
635 double A = ff_exp10(gain / 40.);
638 switch (width_type) {
644 ret = frequency / width;
647 ret = frequency / (width * 1000.);
650 ret = 1. / (2. * sinh(log(2.) / 2. * width * w0 / sin(w0)));
653 ret = 1. / sqrt((A + 1. / A) * (1. / width - 1.) + 2.);
663 static void convert_dir2zdf(BiquadsContext *s, int sample_rate)
665 double Q = convert_width2qfactor(s->width, s->frequency, s->gain, sample_rate, s->width_type);
670 switch (s->filter_type) {
680 A = ff_exp10(s->gain / 40.);
681 g = tan(M_PI * s->frequency / sample_rate);
683 a[0] = 1. / (1. + g * (g + k));
687 m[1] = k * (A * A - 1.);
692 A = ff_exp10(s->gain / 40.);
693 g = tan(M_PI * s->frequency / sample_rate) / sqrt(A);
695 a[0] = 1. / (1. + g * (g + k));
703 A = ff_exp10(s->gain / 20.);
704 g = tan(M_PI * s->frequency / sample_rate) / sqrt(A);
706 a[0] = 1. / (1. + g * (g + k));
710 m[1] = k * (A - 1.) / A;
711 m[2] = (A * A - 1.) / A;
715 A = ff_exp10(s->gain / 40.);
716 g = tan(M_PI * s->frequency / sample_rate) / sqrt(A);
718 a[0] = 1. / (1. + g * (g + k));
722 m[1] = k * (1. - A) * A;
726 g = tan(M_PI * s->frequency / sample_rate);
728 a[0] = 1. / (1. + g * (g + k));
732 m[1] = s->csg ? 1. : 2.;
736 g = tan(M_PI * s->frequency / sample_rate);
738 a[0] = 1. / (1. + g * (g + k));
746 g = tan(M_PI * s->frequency / sample_rate);
748 a[0] = 1. / (1. + g * (g + k));
756 g = tan(M_PI * s->frequency / sample_rate);
758 a[0] = 1. / (1. + g * (g + k));
766 g = tan(M_PI * s->frequency / sample_rate);
768 a[0] = 1. / (1. + g * (g + k));
787 static int config_filter(AVFilterLink *outlink, int reset)
789 AVFilterContext *ctx = outlink->src;
790 BiquadsContext *s = ctx->priv;
791 AVFilterLink *inlink = ctx->inputs[0];
792 double gain = s->gain * ((s->filter_type == tiltshelf) + 1.);
793 double A = ff_exp10(gain / 40);
794 double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
795 double K = tan(w0 / 2.);
798 s->bypass = (((w0 > M_PI || w0 <= 0.) && reset) || (s->width <= 0.)) && (s->filter_type != biquad);
800 av_log(ctx, AV_LOG_WARNING, "Invalid frequency and/or width!\n");
804 if ((w0 > M_PI || w0 <= 0.) && (s->filter_type != biquad))
805 return AVERROR(EINVAL);
807 switch (s->width_type) {
812 alpha = sin(w0) / (2 * s->frequency / s->width);
815 alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
818 alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
821 alpha = sin(w0) / (2 * s->width);
824 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
832 switch (s->filter_type) {
842 s->a0 = 1 + alpha / A;
843 s->a1 = -2 * cos(w0);
844 s->a2 = 1 - alpha / A;
845 s->b0 = 1 + alpha * A;
846 s->b1 = -2 * cos(w0);
847 s->b2 = 1 - alpha * A;
850 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
854 double A = ff_exp10(gain / 20);
855 double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
856 double n = (A + 1) / (A - 1);
857 double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
858 double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
859 double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
861 s->a0 = 1 + ro * alpha1;
862 s->a1 = -ro - alpha1;
864 s->b0 = beta0 + ro * beta1;
865 s->b1 = -beta1 - ro * beta0;
868 s->a0 = (A + 1) + (A - 1) * cos(w0) + beta * alpha;
869 s->a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
870 s->a2 = (A + 1) + (A - 1) * cos(w0) - beta * alpha;
871 s->b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
872 s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
873 s->b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
877 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
880 double A = ff_exp10(gain / 20);
881 double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
882 double n = (A + 1) / (A - 1);
883 double alpha1 = A == 1. ? 0. : n - FFSIGN(n) * sqrt(n * n - 1);
884 double beta0 = ((1 + A) + (1 - A) * alpha1) * 0.5;
885 double beta1 = ((1 - A) + (1 + A) * alpha1) * 0.5;
887 s->a0 = 1 + ro * alpha1;
890 s->b0 = beta0 + ro * beta1;
891 s->b1 = beta1 + ro * beta0;
894 s->a0 = (A + 1) - (A - 1) * cos(w0) + beta * alpha;
895 s->a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
896 s->a2 = (A + 1) - (A - 1) * cos(w0) - beta * alpha;
897 s->b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
898 s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
899 s->b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
905 s->a1 = -2 * cos(w0);
909 s->b2 = -sin(w0) / 2;
912 s->a1 = -2 * cos(w0);
921 s->a1 = -2 * cos(w0);
924 s->b1 = -2 * cos(w0);
937 s->a1 = -2 * cos(w0);
939 s->b0 = (1 - cos(w0)) / 2;
941 s->b2 = (1 - cos(w0)) / 2;
949 s->b0 = (1 - s->a1) / 2;
954 s->a1 = -2 * cos(w0);
956 s->b0 = (1 + cos(w0)) / 2;
957 s->b1 = -(1 + cos(w0));
958 s->b2 = (1 + cos(w0)) / 2;
965 s->a1 = -(1. - K) / (1. + K);
973 s->a1 = -2 * cos(w0);
976 s->b1 = -2 * cos(w0);
985 av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n", s->a0, s->a1, s->a2, s->b0, s->b1, s->b2);
994 if (s->normalize && fabs(s->b0 + s->b1 + s->b2) > 1e-6) {
995 double factor = (s->a0 + s->a1 + s->a2) / (s->b0 + s->b1 + s->b2);
1002 switch (s->filter_type) {
1010 s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->ch_layout.nb_channels);
1012 return AVERROR(ENOMEM);
1014 memset(s->cache, 0, sizeof(ChanCache) * inlink->ch_layout.nb_channels);
1016 if (reset && s->block_samples > 0) {
1017 for (int i = 0; i < 3; i++) {
1018 s->block[i] = ff_get_audio_buffer(outlink, s->block_samples * 2);
1020 return AVERROR(ENOMEM);
1021 av_samples_set_silence(s->block[i]->extended_data, 0, s->block_samples * 2,
1022 s->block[i]->ch_layout.nb_channels, s->block[i]->format);
1026 switch (s->transform_type) {
1028 switch (inlink->format) {
1029 case AV_SAMPLE_FMT_S16P:
1030 s->filter = biquad_s16;
1032 case AV_SAMPLE_FMT_S32P:
1033 s->filter = biquad_s32;
1035 case AV_SAMPLE_FMT_FLTP:
1036 s->filter = biquad_flt;
1038 case AV_SAMPLE_FMT_DBLP:
1039 s->filter = biquad_dbl;
1041 default: av_assert0(0);
1045 switch (inlink->format) {
1046 case AV_SAMPLE_FMT_S16P:
1047 s->filter = biquad_dii_s16;
1049 case AV_SAMPLE_FMT_S32P:
1050 s->filter = biquad_dii_s32;
1052 case AV_SAMPLE_FMT_FLTP:
1053 s->filter = biquad_dii_flt;
1055 case AV_SAMPLE_FMT_DBLP:
1056 s->filter = biquad_dii_dbl;
1058 default: av_assert0(0);
1062 switch (inlink->format) {
1063 case AV_SAMPLE_FMT_S16P:
1064 s->filter = biquad_tdi_s16;
1066 case AV_SAMPLE_FMT_S32P:
1067 s->filter = biquad_tdi_s32;
1069 case AV_SAMPLE_FMT_FLTP:
1070 s->filter = biquad_tdi_flt;
1072 case AV_SAMPLE_FMT_DBLP:
1073 s->filter = biquad_tdi_dbl;
1075 default: av_assert0(0);
1079 switch (inlink->format) {
1080 case AV_SAMPLE_FMT_S16P:
1081 s->filter = biquad_tdii_s16;
1083 case AV_SAMPLE_FMT_S32P:
1084 s->filter = biquad_tdii_s32;
1086 case AV_SAMPLE_FMT_FLTP:
1087 s->filter = biquad_tdii_flt;
1089 case AV_SAMPLE_FMT_DBLP:
1090 s->filter = biquad_tdii_dbl;
1092 default: av_assert0(0);
1096 switch (inlink->format) {
1097 case AV_SAMPLE_FMT_S16P:
1098 s->filter = biquad_latt_s16;
1100 case AV_SAMPLE_FMT_S32P:
1101 s->filter = biquad_latt_s32;
1103 case AV_SAMPLE_FMT_FLTP:
1104 s->filter = biquad_latt_flt;
1106 case AV_SAMPLE_FMT_DBLP:
1107 s->filter = biquad_latt_dbl;
1109 default: av_assert0(0);
1113 switch (inlink->format) {
1114 case AV_SAMPLE_FMT_S16P:
1115 s->filter = biquad_svf_s16;
1117 case AV_SAMPLE_FMT_S32P:
1118 s->filter = biquad_svf_s32;
1120 case AV_SAMPLE_FMT_FLTP:
1121 s->filter = biquad_svf_flt;
1123 case AV_SAMPLE_FMT_DBLP:
1124 s->filter = biquad_svf_dbl;
1126 default: av_assert0(0);
1130 switch (inlink->format) {
1131 case AV_SAMPLE_FMT_S16P:
1132 s->filter = biquad_zdf_s16;
1134 case AV_SAMPLE_FMT_S32P:
1135 s->filter = biquad_zdf_s32;
1137 case AV_SAMPLE_FMT_FLTP:
1138 s->filter = biquad_zdf_flt;
1140 case AV_SAMPLE_FMT_DBLP:
1141 s->filter = biquad_zdf_dbl;
1143 default: av_assert0(0);
1150 s->block_align = av_get_bytes_per_sample(inlink->format);
1152 if (s->transform_type == LATT)
1153 convert_dir2latt(s);
1154 else if (s->transform_type == SVF)
1156 else if (s->transform_type == ZDF)
1157 convert_dir2zdf(s, inlink->sample_rate);
1162 static int config_output(AVFilterLink *outlink)
1164 return config_filter(outlink, 1);
1167 typedef struct ThreadData {
1172 static void reverse_samples(AVFrame *out, AVFrame *in, int p,
1173 int oo, int io, int nb_samples)
1175 switch (out->format) {
1176 case AV_SAMPLE_FMT_S16P: {
1177 const int16_t *src = ((const int16_t *)in->extended_data[p]) + io;
1178 int16_t *dst = ((int16_t *)out->extended_data[p]) + oo;
1179 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1183 case AV_SAMPLE_FMT_S32P: {
1184 const int32_t *src = ((const int32_t *)in->extended_data[p]) + io;
1185 int32_t *dst = ((int32_t *)out->extended_data[p]) + oo;
1186 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1190 case AV_SAMPLE_FMT_FLTP: {
1191 const float *src = ((const float *)in->extended_data[p]) + io;
1192 float *dst = ((float *)out->extended_data[p]) + oo;
1193 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1197 case AV_SAMPLE_FMT_DBLP: {
1198 const double *src = ((const double *)in->extended_data[p]) + io;
1199 double *dst = ((double *)out->extended_data[p]) + oo;
1200 for (int i = 0, j = nb_samples - 1; i < nb_samples; i++, j--)
1207 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
1209 AVFilterLink *inlink = ctx->inputs[0];
1210 ThreadData *td = arg;
1211 AVFrame *buf = td->in;
1212 AVFrame *out_buf = td->out;
1213 BiquadsContext *s = ctx->priv;
1214 const int start = (buf->ch_layout.nb_channels * jobnr) / nb_jobs;
1215 const int end = (buf->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
1218 for (ch = start; ch < end; ch++) {
1219 enum AVChannel channel = av_channel_layout_channel_from_index(&inlink->ch_layout, ch);
1221 if (av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0) {
1223 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
1224 buf->nb_samples * s->block_align);
1228 if (!s->block_samples) {
1229 s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
1230 &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
1231 s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
1232 } else if (td->eof) {
1233 memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch] + s->block_align * s->block_samples,
1234 s->nb_samples * s->block_align);
1236 memcpy(s->block[0]->extended_data[ch] + s->block_align * s->block_samples, buf->extended_data[ch],
1237 buf->nb_samples * s->block_align);
1238 memset(s->block[0]->extended_data[ch] + s->block_align * (s->block_samples + buf->nb_samples),
1239 0, (s->block_samples - buf->nb_samples) * s->block_align);
1240 s->filter(s, s->block[0]->extended_data[ch], s->block[1]->extended_data[ch], s->block_samples,
1241 &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
1242 s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
1243 s->cache[ch].ri1 = s->cache[ch].i1;
1244 s->cache[ch].ri2 = s->cache[ch].i2;
1245 s->cache[ch].ro1 = s->cache[ch].o1;
1246 s->cache[ch].ro2 = s->cache[ch].o2;
1247 s->filter(s, s->block[0]->extended_data[ch] + s->block_samples * s->block_align,
1248 s->block[1]->extended_data[ch] + s->block_samples * s->block_align,
1250 &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2,
1251 s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
1252 reverse_samples(s->block[2], s->block[1], ch, 0, 0, 2 * s->block_samples);
1253 s->cache[ch].ri1 = 0.;
1254 s->cache[ch].ri2 = 0.;
1255 s->cache[ch].ro1 = 0.;
1256 s->cache[ch].ro2 = 0.;
1257 s->filter(s, s->block[2]->extended_data[ch], s->block[2]->extended_data[ch], 2 * s->block_samples,
1258 &s->cache[ch].ri1, &s->cache[ch].ri2, &s->cache[ch].ro1, &s->cache[ch].ro2,
1259 s->b0, s->b1, s->b2, s->a0, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
1260 reverse_samples(s->block[1], s->block[2], ch, 0, 0, 2 * s->block_samples);
1261 memcpy(out_buf->extended_data[ch], s->block[1]->extended_data[ch],
1262 s->block_samples * s->block_align);
1263 memmove(s->block[0]->extended_data[ch], s->block[0]->extended_data[ch] + s->block_align * s->block_samples,
1264 s->block_samples * s->block_align);
1271 static int filter_frame(AVFilterLink *inlink, AVFrame *buf, int eof)
1273 AVFilterContext *ctx = inlink->dst;
1274 BiquadsContext *s = ctx->priv;
1275 AVFilterLink *outlink = ctx->outputs[0];
1278 int ch, ret, drop = 0;
1281 return ff_filter_frame(outlink, buf);
1283 ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout);
1285 av_frame_free(&buf);
1288 if (strcmp(s->ch_layout_str, "all"))
1289 av_channel_layout_from_string(&s->ch_layout,
1292 if (av_frame_is_writable(buf) && s->block_samples == 0) {
1295 out_buf = ff_get_audio_buffer(outlink, s->block_samples > 0 ? s->block_samples : buf->nb_samples);
1297 av_frame_free(&buf);
1298 return AVERROR(ENOMEM);
1300 av_frame_copy_props(out_buf, buf);
1303 if (s->block_samples > 0 && s->pts == AV_NOPTS_VALUE)
1308 ff_filter_execute(ctx, filter_channel, &td, NULL,
1309 FFMIN(outlink->ch_layout.nb_channels, ff_filter_get_nb_threads(ctx)));
1311 for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
1312 if (s->cache[ch].clippings > 0)
1313 av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
1314 ch, s->cache[ch].clippings);
1315 s->cache[ch].clippings = 0;
1318 if (s->block_samples > 0) {
1319 int nb_samples = buf->nb_samples;
1320 int64_t pts = buf->pts;
1322 out_buf->pts = s->pts;
1323 out_buf->nb_samples = s->nb_samples;
1325 s->nb_samples = nb_samples;
1329 av_frame_free(&buf);
1332 return ff_filter_frame(outlink, out_buf);
1334 av_frame_free(&out_buf);
1335 ff_filter_set_ready(ctx, 10);
1340 static int activate(AVFilterContext *ctx)
1342 AVFilterLink *inlink = ctx->inputs[0];
1343 AVFilterLink *outlink = ctx->outputs[0];
1344 BiquadsContext *s = ctx->priv;
1350 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
1352 if (s->block_samples > 0) {
1353 ret = ff_inlink_consume_samples(inlink, s->block_samples, s->block_samples, &in);
1355 ret = ff_inlink_consume_frame(inlink, &in);
1360 return filter_frame(inlink, in, 0);
1362 if (s->block_samples > 0 && ff_inlink_queued_samples(inlink) >= s->block_samples) {
1363 ff_filter_set_ready(ctx, 10);
1367 if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
1368 if (s->block_samples > 0) {
1369 AVFrame *in = ff_get_audio_buffer(outlink, s->block_samples);
1371 return AVERROR(ENOMEM);
1373 ret = filter_frame(inlink, in, 1);
1376 ff_outlink_set_status(outlink, status, pts);
1381 FF_FILTER_FORWARD_WANTED(outlink, inlink);
1383 return FFERROR_NOT_READY;
1386 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1387 char *res, int res_len, int flags)
1389 AVFilterLink *outlink = ctx->outputs[0];
1392 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1396 return config_filter(outlink, 0);
1399 static av_cold void uninit(AVFilterContext *ctx)
1401 BiquadsContext *s = ctx->priv;
1403 for (int i = 0; i < 3; i++)
1404 av_frame_free(&s->block[i]);
1405 av_freep(&s->cache);
1406 av_channel_layout_uninit(&s->ch_layout);
1409 static const AVFilterPad inputs[] = {
1412 .type = AVMEDIA_TYPE_AUDIO,
1416 static const AVFilterPad outputs[] = {
1419 .type = AVMEDIA_TYPE_AUDIO,
1420 .config_props = config_output,
1424 #define OFFSET(x) offsetof(BiquadsContext, x)
1425 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
1426 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1428 #define DEFINE_BIQUAD_FILTER_2(name_, description_, priv_class_) \
1429 static av_cold int name_##_init(AVFilterContext *ctx) \
1431 BiquadsContext *s = ctx->priv; \
1432 s->filter_type = name_; \
1433 s->pts = AV_NOPTS_VALUE; \
1437 const AVFilter ff_af_##name_ = { \
1439 .description = NULL_IF_CONFIG_SMALL(description_), \
1440 .priv_class = &priv_class_##_class, \
1441 .priv_size = sizeof(BiquadsContext), \
1442 .init = name_##_init, \
1443 .activate = activate, \
1445 FILTER_INPUTS(inputs), \
1446 FILTER_OUTPUTS(outputs), \
1447 FILTER_QUERY_FUNC(query_formats), \
1448 .process_command = process_command, \
1449 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
1452 #define DEFINE_BIQUAD_FILTER(name, description) \
1453 AVFILTER_DEFINE_CLASS(name); \
1454 DEFINE_BIQUAD_FILTER_2(name, description, name)
1456 #define WIDTH_OPTION(x) \
1457 {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 99999, FLAGS}, \
1458 {"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 99999, FLAGS}
1460 #define WIDTH_TYPE_OPTION(x) \
1461 {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=x}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"}, \
1462 {"t", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=x}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"}, \
1463 {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"}, \
1464 {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"}, \
1465 {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"}, \
1466 {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"}, \
1467 {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"}
1469 #define MIX_CHANNELS_NORMALIZE_OPTION(x, y, z) \
1470 {"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 1, FLAGS}, \
1471 {"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=x}, 0, 1, FLAGS}, \
1472 {"channels", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str=y}, 0, 0, FLAGS}, \
1473 {"c", "set channels to filter", OFFSET(ch_layout_str), AV_OPT_TYPE_STRING, {.str=y}, 0, 0, FLAGS}, \
1474 {"normalize", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=z}, 0, 1, FLAGS}, \
1475 {"n", "normalize coefficients", OFFSET(normalize), AV_OPT_TYPE_BOOL, {.i64=z}, 0, 1, FLAGS}
1477 #define TRANSFORM_OPTION(x) \
1478 {"transform", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=x}, 0, NB_TTYPE-1, AF, "transform_type"}, \
1479 {"a", "set transform type", OFFSET(transform_type), AV_OPT_TYPE_INT, {.i64=x}, 0, NB_TTYPE-1, AF, "transform_type"}, \
1480 {"di", "direct form I", 0, AV_OPT_TYPE_CONST, {.i64=DI}, 0, 0, AF, "transform_type"}, \
1481 {"dii", "direct form II", 0, AV_OPT_TYPE_CONST, {.i64=DII}, 0, 0, AF, "transform_type"}, \
1482 {"tdi", "transposed direct form I", 0, AV_OPT_TYPE_CONST, {.i64=TDI}, 0, 0, AF, "transform_type"}, \
1483 {"tdii", "transposed direct form II", 0, AV_OPT_TYPE_CONST, {.i64=TDII}, 0, 0, AF, "transform_type"}, \
1484 {"latt", "lattice-ladder form", 0, AV_OPT_TYPE_CONST, {.i64=LATT}, 0, 0, AF, "transform_type"}, \
1485 {"svf", "state variable filter form", 0, AV_OPT_TYPE_CONST, {.i64=SVF}, 0, 0, AF, "transform_type"}, \
1486 {"zdf", "zero-delay filter form", 0, AV_OPT_TYPE_CONST, {.i64=ZDF}, 0, 0, AF, "transform_type"}
1488 #define PRECISION_OPTION(x) \
1489 {"precision", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=x}, -1, 3, AF, "precision"}, \
1490 {"r", "set filtering precision", OFFSET(precision), AV_OPT_TYPE_INT, {.i64=x}, -1, 3, AF, "precision"}, \
1491 {"auto", "automatic", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "precision"}, \
1492 {"s16", "signed 16-bit", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision"}, \
1493 {"s32", "signed 32-bit", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision"}, \
1494 {"f32", "floating-point single", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision"}, \
1495 {"f64", "floating-point double", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision"}
1497 #define BLOCKSIZE_OPTION(x) \
1498 {"blocksize", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=x}, 0, 32768, AF}, \
1499 {"b", "set the block size", OFFSET(block_samples), AV_OPT_TYPE_INT, {.i64=x}, 0, 32768, AF}
1501 #if CONFIG_EQUALIZER_FILTER
1502 static const AVOption equalizer_options[] = {
1503 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
1504 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
1505 WIDTH_TYPE_OPTION(QFACTOR),
1507 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1508 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1509 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1510 TRANSFORM_OPTION(DI),
1511 PRECISION_OPTION(-1),
1512 BLOCKSIZE_OPTION(0),
1516 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
1517 #endif /* CONFIG_EQUALIZER_FILTER */
1518 #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER
1519 static const AVOption bass_lowshelf_options[] = {
1520 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1521 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
1522 WIDTH_TYPE_OPTION(QFACTOR),
1524 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1525 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1526 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1527 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1528 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1529 TRANSFORM_OPTION(DI),
1530 PRECISION_OPTION(-1),
1531 BLOCKSIZE_OPTION(0),
1535 AVFILTER_DEFINE_CLASS_EXT(bass_lowshelf, "bass/lowshelf", bass_lowshelf_options);
1536 #if CONFIG_BASS_FILTER
1537 DEFINE_BIQUAD_FILTER_2(bass, "Boost or cut lower frequencies.", bass_lowshelf);
1538 #endif /* CONFIG_BASS_FILTER */
1540 #if CONFIG_LOWSHELF_FILTER
1541 DEFINE_BIQUAD_FILTER_2(lowshelf, "Apply a low shelf filter.", bass_lowshelf);
1542 #endif /* CONFIG_LOWSHELF_FILTER */
1543 #endif /* CONFIG_BASS_FILTER || CONFIG LOWSHELF_FILTER */
1544 #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER || CONFIG_TILTSHELF_FILTER
1545 static const AVOption treble_highshelf_options[] = {
1546 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1547 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1548 WIDTH_TYPE_OPTION(QFACTOR),
1550 {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1551 {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
1552 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1553 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1554 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1555 TRANSFORM_OPTION(DI),
1556 PRECISION_OPTION(-1),
1557 BLOCKSIZE_OPTION(0),
1561 AVFILTER_DEFINE_CLASS_EXT(treble_highshelf, "treble/high/tiltshelf",
1562 treble_highshelf_options);
1564 #if CONFIG_TREBLE_FILTER
1565 DEFINE_BIQUAD_FILTER_2(treble, "Boost or cut upper frequencies.", treble_highshelf);
1566 #endif /* CONFIG_TREBLE_FILTER */
1568 #if CONFIG_HIGHSHELF_FILTER
1569 DEFINE_BIQUAD_FILTER_2(highshelf, "Apply a high shelf filter.", treble_highshelf);
1570 #endif /* CONFIG_HIGHSHELF_FILTER */
1572 #if CONFIG_TILTSHELF_FILTER
1573 DEFINE_BIQUAD_FILTER_2(tiltshelf, "Apply a tilt shelf filter.", treble_highshelf);
1575 #endif /* CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER || CONFIG_TILTSHELF_FILTER */
1577 #if CONFIG_BANDPASS_FILTER
1578 static const AVOption bandpass_options[] = {
1579 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1580 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1581 WIDTH_TYPE_OPTION(QFACTOR),
1583 {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
1584 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1585 TRANSFORM_OPTION(DI),
1586 PRECISION_OPTION(-1),
1587 BLOCKSIZE_OPTION(0),
1591 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
1592 #endif /* CONFIG_BANDPASS_FILTER */
1593 #if CONFIG_BANDREJECT_FILTER
1594 static const AVOption bandreject_options[] = {
1595 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1596 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1597 WIDTH_TYPE_OPTION(QFACTOR),
1599 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1600 TRANSFORM_OPTION(DI),
1601 PRECISION_OPTION(-1),
1602 BLOCKSIZE_OPTION(0),
1606 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
1607 #endif /* CONFIG_BANDREJECT_FILTER */
1608 #if CONFIG_LOWPASS_FILTER
1609 static const AVOption lowpass_options[] = {
1610 {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1611 {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
1612 WIDTH_TYPE_OPTION(QFACTOR),
1613 WIDTH_OPTION(0.707),
1614 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1615 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1616 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1617 TRANSFORM_OPTION(DI),
1618 PRECISION_OPTION(-1),
1619 BLOCKSIZE_OPTION(0),
1623 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
1624 #endif /* CONFIG_LOWPASS_FILTER */
1625 #if CONFIG_HIGHPASS_FILTER
1626 static const AVOption highpass_options[] = {
1627 {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1628 {"f", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1629 WIDTH_TYPE_OPTION(QFACTOR),
1630 WIDTH_OPTION(0.707),
1631 {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1632 {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, AF},
1633 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1634 TRANSFORM_OPTION(DI),
1635 PRECISION_OPTION(-1),
1636 BLOCKSIZE_OPTION(0),
1640 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
1641 #endif /* CONFIG_HIGHPASS_FILTER */
1642 #if CONFIG_ALLPASS_FILTER
1643 static const AVOption allpass_options[] = {
1644 {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1645 {"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
1646 WIDTH_TYPE_OPTION(QFACTOR),
1647 WIDTH_OPTION(0.707),
1648 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1649 {"order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1650 {"o", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
1651 TRANSFORM_OPTION(DI),
1652 PRECISION_OPTION(-1),
1656 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
1657 #endif /* CONFIG_ALLPASS_FILTER */
1658 #if CONFIG_BIQUAD_FILTER
1659 static const AVOption biquad_options[] = {
1660 {"a0", NULL, OFFSET(oa0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
1661 {"a1", NULL, OFFSET(oa1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1662 {"a2", NULL, OFFSET(oa2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1663 {"b0", NULL, OFFSET(ob0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1664 {"b1", NULL, OFFSET(ob1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1665 {"b2", NULL, OFFSET(ob2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
1666 MIX_CHANNELS_NORMALIZE_OPTION(1, "all", 0),
1667 TRANSFORM_OPTION(DI),
1668 PRECISION_OPTION(-1),
1669 BLOCKSIZE_OPTION(0),
1673 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
1674 #endif /* CONFIG_BIQUAD_FILTER */