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