]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_biquads.c
Merge commit 'c93e92f2b25f4174350ded3f59ad117ec8eb1fe4'
[ffmpeg] / libavfilter / af_biquads.c
1 /*
2  * Copyright (c) 2013 Paul B Mahol
3  * Copyright (c) 2006-2008 Rob Sykes <robs@users.sourceforge.net>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 /*
23  * 2-pole filters designed by Robert Bristow-Johnson <rbj@audioimagination.com>
24  *   see http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
25  *
26  * 1-pole filters based on code (c) 2000 Chris Bagwell <cbagwell@sprynet.com>
27  *   Algorithms: Recursive single pole low/high pass filter
28  *   Reference: The Scientist and Engineer's Guide to Digital Signal Processing
29  *
30  *   low-pass: output[N] = input[N] * A + output[N-1] * B
31  *     X = exp(-2.0 * pi * Fc)
32  *     A = 1 - X
33  *     B = X
34  *     Fc = cutoff freq / sample rate
35  *
36  *     Mimics an RC low-pass filter:
37  *
38  *     ---/\/\/\/\----------->
39  *                   |
40  *                  --- C
41  *                  ---
42  *                   |
43  *                   |
44  *                   V
45  *
46  *   high-pass: output[N] = A0 * input[N] + A1 * input[N-1] + B1 * output[N-1]
47  *     X  = exp(-2.0 * pi * Fc)
48  *     A0 = (1 + X) / 2
49  *     A1 = -(1 + X) / 2
50  *     B1 = X
51  *     Fc = cutoff freq / sample rate
52  *
53  *     Mimics an RC high-pass filter:
54  *
55  *         || C
56  *     ----||--------->
57  *         ||    |
58  *               <
59  *               > R
60  *               <
61  *               |
62  *               V
63  */
64
65 #include "libavutil/avassert.h"
66 #include "libavutil/ffmath.h"
67 #include "libavutil/opt.h"
68 #include "audio.h"
69 #include "avfilter.h"
70 #include "internal.h"
71
72 enum FilterType {
73     biquad,
74     equalizer,
75     bass,
76     treble,
77     bandpass,
78     bandreject,
79     allpass,
80     highpass,
81     lowpass,
82     lowshelf,
83     highshelf,
84 };
85
86 enum WidthType {
87     NONE,
88     HERTZ,
89     OCTAVE,
90     QFACTOR,
91     SLOPE,
92     KHERTZ,
93     NB_WTYPE,
94 };
95
96 typedef struct ChanCache {
97     double i1, i2;
98     double o1, o2;
99     int clippings;
100 } ChanCache;
101
102 typedef struct BiquadsContext {
103     const AVClass *class;
104
105     enum FilterType filter_type;
106     int width_type;
107     int poles;
108     int csg;
109
110     double gain;
111     double frequency;
112     double width;
113     uint64_t channels;
114
115     double a0, a1, a2;
116     double b0, b1, b2;
117
118     ChanCache *cache;
119     int block_align;
120
121     void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
122                    double *i1, double *i2, double *o1, double *o2,
123                    double b0, double b1, double b2, double a1, double a2, int *clippings,
124                    int disabled);
125 } BiquadsContext;
126
127 static av_cold int init(AVFilterContext *ctx)
128 {
129     BiquadsContext *s = ctx->priv;
130
131     if (s->filter_type != biquad) {
132         if (s->frequency <= 0 || s->width <= 0) {
133             av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
134                    s->frequency, s->width);
135             return AVERROR(EINVAL);
136         }
137     }
138
139     return 0;
140 }
141
142 static int query_formats(AVFilterContext *ctx)
143 {
144     AVFilterFormats *formats;
145     AVFilterChannelLayouts *layouts;
146     static const enum AVSampleFormat sample_fmts[] = {
147         AV_SAMPLE_FMT_S16P,
148         AV_SAMPLE_FMT_S32P,
149         AV_SAMPLE_FMT_FLTP,
150         AV_SAMPLE_FMT_DBLP,
151         AV_SAMPLE_FMT_NONE
152     };
153     int ret;
154
155     layouts = ff_all_channel_counts();
156     if (!layouts)
157         return AVERROR(ENOMEM);
158     ret = ff_set_common_channel_layouts(ctx, layouts);
159     if (ret < 0)
160         return ret;
161
162     formats = ff_make_format_list(sample_fmts);
163     if (!formats)
164         return AVERROR(ENOMEM);
165     ret = ff_set_common_formats(ctx, formats);
166     if (ret < 0)
167         return ret;
168
169     formats = ff_all_samplerates();
170     if (!formats)
171         return AVERROR(ENOMEM);
172     return ff_set_common_samplerates(ctx, formats);
173 }
174
175 #define BIQUAD_FILTER(name, type, min, max, need_clipping)                    \
176 static void biquad_## name (BiquadsContext *s,                                \
177                             const void *input, void *output, int len,         \
178                             double *in1, double *in2,                         \
179                             double *out1, double *out2,                       \
180                             double b0, double b1, double b2,                  \
181                             double a1, double a2, int *clippings,             \
182                             int disabled)                                     \
183 {                                                                             \
184     const type *ibuf = input;                                                 \
185     type *obuf = output;                                                      \
186     double i1 = *in1;                                                         \
187     double i2 = *in2;                                                         \
188     double o1 = *out1;                                                        \
189     double o2 = *out2;                                                        \
190     int i;                                                                    \
191     a1 = -a1;                                                                 \
192     a2 = -a2;                                                                 \
193                                                                               \
194     for (i = 0; i+1 < len; i++) {                                             \
195         o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1;            \
196         i2 = ibuf[i];                                                         \
197         if (disabled) {                                                       \
198             obuf[i] = i2;                                                     \
199         } else if (need_clipping && o2 < min) {                               \
200             (*clippings)++;                                                   \
201             obuf[i] = min;                                                    \
202         } else if (need_clipping && o2 > max) {                               \
203             (*clippings)++;                                                   \
204             obuf[i] = max;                                                    \
205         } else {                                                              \
206             obuf[i] = o2;                                                     \
207         }                                                                     \
208         i++;                                                                  \
209         o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1;            \
210         i1 = ibuf[i];                                                         \
211         if (disabled) {                                                       \
212             obuf[i] = i1;                                                     \
213         } else if (need_clipping && o1 < min) {                               \
214             (*clippings)++;                                                   \
215             obuf[i] = min;                                                    \
216         } else if (need_clipping && o1 > max) {                               \
217             (*clippings)++;                                                   \
218             obuf[i] = max;                                                    \
219         } else {                                                              \
220             obuf[i] = o1;                                                     \
221         }                                                                     \
222     }                                                                         \
223     if (i < len) {                                                            \
224         double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2;     \
225         i2 = i1;                                                              \
226         i1 = ibuf[i];                                                         \
227         o2 = o1;                                                              \
228         o1 = o0;                                                              \
229         if (disabled) {                                                       \
230             obuf[i] = i1;                                                     \
231         } else if (need_clipping && o0 < min) {                               \
232             (*clippings)++;                                                   \
233             obuf[i] = min;                                                    \
234         } else if (need_clipping && o0 > max) {                               \
235             (*clippings)++;                                                   \
236             obuf[i] = max;                                                    \
237         } else {                                                              \
238             obuf[i] = o0;                                                     \
239         }                                                                     \
240     }                                                                         \
241     *in1  = i1;                                                               \
242     *in2  = i2;                                                               \
243     *out1 = o1;                                                               \
244     *out2 = o2;                                                               \
245 }
246
247 BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
248 BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
249 BIQUAD_FILTER(flt, float,   -1., 1., 0)
250 BIQUAD_FILTER(dbl, double,  -1., 1., 0)
251
252 static int config_filter(AVFilterLink *outlink, int reset)
253 {
254     AVFilterContext *ctx    = outlink->src;
255     BiquadsContext *s       = ctx->priv;
256     AVFilterLink *inlink    = ctx->inputs[0];
257     double A = ff_exp10(s->gain / 40);
258     double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
259     double alpha, beta;
260
261     if (w0 > M_PI) {
262         av_log(ctx, AV_LOG_ERROR,
263                "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
264                s->frequency, inlink->sample_rate);
265         return AVERROR(EINVAL);
266     }
267
268     switch (s->width_type) {
269     case NONE:
270         alpha = 0.0;
271         break;
272     case HERTZ:
273         alpha = sin(w0) / (2 * s->frequency / s->width);
274         break;
275     case KHERTZ:
276         alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
277         break;
278     case OCTAVE:
279         alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
280         break;
281     case QFACTOR:
282         alpha = sin(w0) / (2 * s->width);
283         break;
284     case SLOPE:
285         alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
286         break;
287     default:
288         av_assert0(0);
289     }
290
291     beta = 2 * sqrt(A);
292
293     switch (s->filter_type) {
294     case biquad:
295         break;
296     case equalizer:
297         s->a0 =   1 + alpha / A;
298         s->a1 =  -2 * cos(w0);
299         s->a2 =   1 - alpha / A;
300         s->b0 =   1 + alpha * A;
301         s->b1 =  -2 * cos(w0);
302         s->b2 =   1 - alpha * A;
303         break;
304     case bass:
305         beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
306     case lowshelf:
307         s->a0 =          (A + 1) + (A - 1) * cos(w0) + beta * alpha;
308         s->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
309         s->a2 =          (A + 1) + (A - 1) * cos(w0) - beta * alpha;
310         s->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
311         s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
312         s->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
313         break;
314     case treble:
315         beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
316     case highshelf:
317         s->a0 =          (A + 1) - (A - 1) * cos(w0) + beta * alpha;
318         s->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
319         s->a2 =          (A + 1) - (A - 1) * cos(w0) - beta * alpha;
320         s->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
321         s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
322         s->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
323         break;
324     case bandpass:
325         if (s->csg) {
326             s->a0 =  1 + alpha;
327             s->a1 = -2 * cos(w0);
328             s->a2 =  1 - alpha;
329             s->b0 =  sin(w0) / 2;
330             s->b1 =  0;
331             s->b2 = -sin(w0) / 2;
332         } else {
333             s->a0 =  1 + alpha;
334             s->a1 = -2 * cos(w0);
335             s->a2 =  1 - alpha;
336             s->b0 =  alpha;
337             s->b1 =  0;
338             s->b2 = -alpha;
339         }
340         break;
341     case bandreject:
342         s->a0 =  1 + alpha;
343         s->a1 = -2 * cos(w0);
344         s->a2 =  1 - alpha;
345         s->b0 =  1;
346         s->b1 = -2 * cos(w0);
347         s->b2 =  1;
348         break;
349     case lowpass:
350         if (s->poles == 1) {
351             s->a0 = 1;
352             s->a1 = -exp(-w0);
353             s->a2 = 0;
354             s->b0 = 1 + s->a1;
355             s->b1 = 0;
356             s->b2 = 0;
357         } else {
358             s->a0 =  1 + alpha;
359             s->a1 = -2 * cos(w0);
360             s->a2 =  1 - alpha;
361             s->b0 = (1 - cos(w0)) / 2;
362             s->b1 =  1 - cos(w0);
363             s->b2 = (1 - cos(w0)) / 2;
364         }
365         break;
366     case highpass:
367         if (s->poles == 1) {
368             s->a0 = 1;
369             s->a1 = -exp(-w0);
370             s->a2 = 0;
371             s->b0 = (1 - s->a1) / 2;
372             s->b1 = -s->b0;
373             s->b2 = 0;
374         } else {
375             s->a0 =   1 + alpha;
376             s->a1 =  -2 * cos(w0);
377             s->a2 =   1 - alpha;
378             s->b0 =  (1 + cos(w0)) / 2;
379             s->b1 = -(1 + cos(w0));
380             s->b2 =  (1 + cos(w0)) / 2;
381         }
382         break;
383     case allpass:
384         s->a0 =  1 + alpha;
385         s->a1 = -2 * cos(w0);
386         s->a2 =  1 - alpha;
387         s->b0 =  1 - alpha;
388         s->b1 = -2 * cos(w0);
389         s->b2 =  1 + alpha;
390         break;
391     default:
392         av_assert0(0);
393     }
394
395     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);
396
397     s->a1 /= s->a0;
398     s->a2 /= s->a0;
399     s->b0 /= s->a0;
400     s->b1 /= s->a0;
401     s->b2 /= s->a0;
402     s->a0 /= s->a0;
403
404     s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
405     if (!s->cache)
406         return AVERROR(ENOMEM);
407     if (reset)
408         memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
409
410     switch (inlink->format) {
411     case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
412     case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
413     case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
414     case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
415     default: av_assert0(0);
416     }
417
418     s->block_align = av_get_bytes_per_sample(inlink->format);
419
420     return 0;
421 }
422
423 static int config_output(AVFilterLink *outlink)
424 {
425     return config_filter(outlink, 1);
426 }
427
428 typedef struct ThreadData {
429     AVFrame *in, *out;
430 } ThreadData;
431
432 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
433 {
434     AVFilterLink *inlink = ctx->inputs[0];
435     ThreadData *td = arg;
436     AVFrame *buf = td->in;
437     AVFrame *out_buf = td->out;
438     BiquadsContext *s = ctx->priv;
439     const int start = (buf->channels * jobnr) / nb_jobs;
440     const int end = (buf->channels * (jobnr+1)) / nb_jobs;
441     int ch;
442
443     for (ch = start; ch < end; ch++) {
444         if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
445             if (buf != out_buf)
446                 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
447                        buf->nb_samples * s->block_align);
448             continue;
449         }
450
451         s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
452                   &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
453                   s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings, ctx->is_disabled);
454     }
455
456     return 0;
457 }
458
459 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
460 {
461     AVFilterContext  *ctx = inlink->dst;
462     BiquadsContext *s     = ctx->priv;
463     AVFilterLink *outlink = ctx->outputs[0];
464     AVFrame *out_buf;
465     ThreadData td;
466     int ch;
467
468     if (av_frame_is_writable(buf)) {
469         out_buf = buf;
470     } else {
471         out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
472         if (!out_buf) {
473             av_frame_free(&buf);
474             return AVERROR(ENOMEM);
475         }
476         av_frame_copy_props(out_buf, buf);
477     }
478
479     td.in = buf;
480     td.out = out_buf;
481     ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
482
483     for (ch = 0; ch < outlink->channels; ch++) {
484         if (s->cache[ch].clippings > 0)
485             av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
486                    ch, s->cache[ch].clippings);
487         s->cache[ch].clippings = 0;
488     }
489
490     if (buf != out_buf)
491         av_frame_free(&buf);
492
493     return ff_filter_frame(outlink, out_buf);
494 }
495
496 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
497                            char *res, int res_len, int flags)
498 {
499     BiquadsContext *s = ctx->priv;
500     AVFilterLink *outlink = ctx->outputs[0];
501
502     if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
503         (s->filter_type == equalizer ||
504          s->filter_type == lowshelf  ||
505          s->filter_type == highshelf ||
506          s->filter_type == bass      ||
507          s->filter_type == treble    ||
508          s->filter_type == bandpass  ||
509          s->filter_type == bandreject||
510          s->filter_type == lowpass   ||
511          s->filter_type == highpass  ||
512          s->filter_type == allpass)) {
513         double freq;
514
515         if (sscanf(args, "%lf", &freq) != 1) {
516             av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
517             return AVERROR(EINVAL);
518         }
519
520         s->frequency = freq;
521     } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
522         (s->filter_type == equalizer ||
523          s->filter_type == lowshelf  ||
524          s->filter_type == highshelf ||
525          s->filter_type == bass      ||
526          s->filter_type == treble)) {
527         double gain;
528
529         if (sscanf(args, "%lf", &gain) != 1) {
530             av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
531             return AVERROR(EINVAL);
532         }
533
534         s->gain = gain;
535     } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
536         (s->filter_type == equalizer ||
537          s->filter_type == lowshelf  ||
538          s->filter_type == highshelf ||
539          s->filter_type == bass      ||
540          s->filter_type == treble    ||
541          s->filter_type == bandpass  ||
542          s->filter_type == bandreject||
543          s->filter_type == lowpass   ||
544          s->filter_type == highpass  ||
545          s->filter_type == allpass)) {
546         double width;
547
548         if (sscanf(args, "%lf", &width) != 1) {
549             av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
550             return AVERROR(EINVAL);
551         }
552
553         s->width = width;
554     } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
555         (s->filter_type == equalizer ||
556          s->filter_type == lowshelf  ||
557          s->filter_type == highshelf ||
558          s->filter_type == bass      ||
559          s->filter_type == treble    ||
560          s->filter_type == bandpass  ||
561          s->filter_type == bandreject||
562          s->filter_type == lowpass   ||
563          s->filter_type == highpass  ||
564          s->filter_type == allpass)) {
565         char width_type;
566
567         if (sscanf(args, "%c", &width_type) != 1) {
568             av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
569             return AVERROR(EINVAL);
570         }
571
572         switch (width_type) {
573         case 'h': width_type = HERTZ;   break;
574         case 'q': width_type = QFACTOR; break;
575         case 'o': width_type = OCTAVE;  break;
576         case 's': width_type = SLOPE;   break;
577         case 'k': width_type = KHERTZ;  break;
578         default:
579             av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
580             return AVERROR(EINVAL);
581         }
582
583         s->width_type = width_type;
584     } else if ((!strcmp(cmd, "a0") ||
585                 !strcmp(cmd, "a1") ||
586                 !strcmp(cmd, "a2") ||
587                 !strcmp(cmd, "b0") ||
588                 !strcmp(cmd, "b1") ||
589                 !strcmp(cmd, "b2")) &&
590                s->filter_type == biquad) {
591         double value;
592
593         if (sscanf(args, "%lf", &value) != 1) {
594             av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
595             return AVERROR(EINVAL);
596         }
597
598         if (!strcmp(cmd, "a0"))
599             s->a0 = value;
600         else if (!strcmp(cmd, "a1"))
601             s->a1 = value;
602         else if (!strcmp(cmd, "a2"))
603             s->a2 = value;
604         else if (!strcmp(cmd, "b0"))
605             s->b0 = value;
606         else if (!strcmp(cmd, "b1"))
607             s->b1 = value;
608         else if (!strcmp(cmd, "b2"))
609             s->b2 = value;
610     }
611
612     return config_filter(outlink, 0);
613 }
614
615 static av_cold void uninit(AVFilterContext *ctx)
616 {
617     BiquadsContext *s = ctx->priv;
618
619     av_freep(&s->cache);
620 }
621
622 static const AVFilterPad inputs[] = {
623     {
624         .name         = "default",
625         .type         = AVMEDIA_TYPE_AUDIO,
626         .filter_frame = filter_frame,
627     },
628     { NULL }
629 };
630
631 static const AVFilterPad outputs[] = {
632     {
633         .name         = "default",
634         .type         = AVMEDIA_TYPE_AUDIO,
635         .config_props = config_output,
636     },
637     { NULL }
638 };
639
640 #define OFFSET(x) offsetof(BiquadsContext, x)
641 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
642
643 #define DEFINE_BIQUAD_FILTER(name_, description_)                       \
644 AVFILTER_DEFINE_CLASS(name_);                                           \
645 static av_cold int name_##_init(AVFilterContext *ctx) \
646 {                                                                       \
647     BiquadsContext *s = ctx->priv;                                      \
648     s->class = &name_##_class;                                          \
649     s->filter_type = name_;                                             \
650     return init(ctx);                                             \
651 }                                                                       \
652                                                          \
653 AVFilter ff_af_##name_ = {                         \
654     .name          = #name_,                             \
655     .description   = NULL_IF_CONFIG_SMALL(description_), \
656     .priv_size     = sizeof(BiquadsContext),             \
657     .init          = name_##_init,                       \
658     .uninit        = uninit,                             \
659     .query_formats = query_formats,                      \
660     .inputs        = inputs,                             \
661     .outputs       = outputs,                            \
662     .priv_class    = &name_##_class,                     \
663     .process_command = process_command,                  \
664     .flags         = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \
665 }
666
667 #if CONFIG_EQUALIZER_FILTER
668 static const AVOption equalizer_options[] = {
669     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
670     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
671     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
672     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
673     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
674     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
675     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
676     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
677     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
678     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
679     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
680     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
681     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
682     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
683     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
684     {NULL}
685 };
686
687 DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
688 #endif  /* CONFIG_EQUALIZER_FILTER */
689 #if CONFIG_BASS_FILTER
690 static const AVOption bass_options[] = {
691     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
692     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
693     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
694     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
695     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
696     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
697     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
698     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
699     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
700     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
701     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
702     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
703     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
704     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
705     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
706     {NULL}
707 };
708
709 DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
710 #endif  /* CONFIG_BASS_FILTER */
711 #if CONFIG_TREBLE_FILTER
712 static const AVOption treble_options[] = {
713     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
714     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
715     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
716     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
717     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
718     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
719     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
720     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
721     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
722     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
723     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
724     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
725     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
726     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
727     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
728     {NULL}
729 };
730
731 DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
732 #endif  /* CONFIG_TREBLE_FILTER */
733 #if CONFIG_BANDPASS_FILTER
734 static const AVOption bandpass_options[] = {
735     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
736     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
737     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
738     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
739     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
740     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
741     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
742     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
743     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
744     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
745     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
746     {"csg",   "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
747     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
748     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
749     {NULL}
750 };
751
752 DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
753 #endif  /* CONFIG_BANDPASS_FILTER */
754 #if CONFIG_BANDREJECT_FILTER
755 static const AVOption bandreject_options[] = {
756     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
757     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
758     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
759     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
760     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
761     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
762     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
763     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
764     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
765     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
766     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
767     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
768     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
769     {NULL}
770 };
771
772 DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
773 #endif  /* CONFIG_BANDREJECT_FILTER */
774 #if CONFIG_LOWPASS_FILTER
775 static const AVOption lowpass_options[] = {
776     {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
777     {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
778     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
779     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
780     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
781     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
782     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
783     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
784     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
785     {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
786     {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
787     {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
788     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
789     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
790     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
791     {NULL}
792 };
793
794 DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
795 #endif  /* CONFIG_LOWPASS_FILTER */
796 #if CONFIG_HIGHPASS_FILTER
797 static const AVOption highpass_options[] = {
798     {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
799     {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
800     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
801     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
802     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
803     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
804     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
805     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
806     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
807     {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
808     {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
809     {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
810     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
811     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
812     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
813     {NULL}
814 };
815
816 DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
817 #endif  /* CONFIG_HIGHPASS_FILTER */
818 #if CONFIG_ALLPASS_FILTER
819 static const AVOption allpass_options[] = {
820     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
821     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
822     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
823     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
824     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
825     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
826     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
827     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
828     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
829     {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
830     {"w",     "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
831     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
832     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
833     {NULL}
834 };
835
836 DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
837 #endif  /* CONFIG_ALLPASS_FILTER */
838 #if CONFIG_LOWSHELF_FILTER
839 static const AVOption lowshelf_options[] = {
840     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
841     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
842     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
843     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
844     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
845     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
846     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
847     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
848     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
849     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
850     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
851     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
852     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
853     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
854     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
855     {NULL}
856 };
857
858 DEFINE_BIQUAD_FILTER(lowshelf, "Apply a low shelf filter.");
859 #endif  /* CONFIG_LOWSHELF_FILTER */
860 #if CONFIG_HIGHSHELF_FILTER
861 static const AVOption highshelf_options[] = {
862     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
863     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
864     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
865     {"t",          "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, NB_WTYPE-1, FLAGS, "width_type"},
866     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
867     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
868     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
869     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
870     {"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
871     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
872     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
873     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
874     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
875     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
876     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
877     {NULL}
878 };
879
880 DEFINE_BIQUAD_FILTER(highshelf, "Apply a high shelf filter.");
881 #endif  /* CONFIG_HIGHSHELF_FILTER */
882 #if CONFIG_BIQUAD_FILTER
883 static const AVOption biquad_options[] = {
884     {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT32_MIN, INT32_MAX, FLAGS},
885     {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
886     {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
887     {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
888     {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
889     {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
890     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
891     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
892     {NULL}
893 };
894
895 DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
896 #endif  /* CONFIG_BIQUAD_FILTER */