LCOV - code coverage report
Current view: top level - libavfilter - af_biquads.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 320 0.0 %
Date: 2018-05-20 11:54:08 Functions: 0 23 0.0 %

          Line data    Source code
       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           0 : static av_cold int init(AVFilterContext *ctx)
     126             : {
     127           0 :     BiquadsContext *s = ctx->priv;
     128             : 
     129           0 :     if (s->filter_type != biquad) {
     130           0 :         if (s->frequency <= 0 || s->width <= 0) {
     131           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
     132             :                    s->frequency, s->width);
     133           0 :             return AVERROR(EINVAL);
     134             :         }
     135             :     }
     136             : 
     137           0 :     return 0;
     138             : }
     139             : 
     140           0 : 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           0 :     layouts = ff_all_channel_counts();
     154           0 :     if (!layouts)
     155           0 :         return AVERROR(ENOMEM);
     156           0 :     ret = ff_set_common_channel_layouts(ctx, layouts);
     157           0 :     if (ret < 0)
     158           0 :         return ret;
     159             : 
     160           0 :     formats = ff_make_format_list(sample_fmts);
     161           0 :     if (!formats)
     162           0 :         return AVERROR(ENOMEM);
     163           0 :     ret = ff_set_common_formats(ctx, formats);
     164           0 :     if (ret < 0)
     165           0 :         return ret;
     166             : 
     167           0 :     formats = ff_all_samplerates();
     168           0 :     if (!formats)
     169           0 :         return AVERROR(ENOMEM);
     170           0 :     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           0 : BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
     239           0 : BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
     240           0 : BIQUAD_FILTER(flt, float,   -1., 1., 0)
     241           0 : BIQUAD_FILTER(dbl, double,  -1., 1., 0)
     242             : 
     243           0 : static int config_filter(AVFilterLink *outlink, int reset)
     244             : {
     245           0 :     AVFilterContext *ctx    = outlink->src;
     246           0 :     BiquadsContext *s       = ctx->priv;
     247           0 :     AVFilterLink *inlink    = ctx->inputs[0];
     248           0 :     double A = exp(s->gain / 40 * log(10.));
     249           0 :     double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
     250             :     double alpha, beta;
     251             : 
     252           0 :     if (w0 > M_PI) {
     253           0 :         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           0 :         return AVERROR(EINVAL);
     257             :     }
     258             : 
     259           0 :     switch (s->width_type) {
     260           0 :     case NONE:
     261           0 :         alpha = 0.0;
     262           0 :         break;
     263           0 :     case HERTZ:
     264           0 :         alpha = sin(w0) / (2 * s->frequency / s->width);
     265           0 :         break;
     266           0 :     case KHERTZ:
     267           0 :         alpha = sin(w0) / (2 * s->frequency / (s->width * 1000));
     268           0 :         break;
     269           0 :     case OCTAVE:
     270           0 :         alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
     271           0 :         break;
     272           0 :     case QFACTOR:
     273           0 :         alpha = sin(w0) / (2 * s->width);
     274           0 :         break;
     275           0 :     case SLOPE:
     276           0 :         alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
     277           0 :         break;
     278           0 :     default:
     279           0 :         av_assert0(0);
     280             :     }
     281             : 
     282           0 :     beta = 2 * sqrt(A);
     283             : 
     284           0 :     switch (s->filter_type) {
     285           0 :     case biquad:
     286           0 :         break;
     287           0 :     case equalizer:
     288           0 :         s->a0 =   1 + alpha / A;
     289           0 :         s->a1 =  -2 * cos(w0);
     290           0 :         s->a2 =   1 - alpha / A;
     291           0 :         s->b0 =   1 + alpha * A;
     292           0 :         s->b1 =  -2 * cos(w0);
     293           0 :         s->b2 =   1 - alpha * A;
     294           0 :         break;
     295           0 :     case bass:
     296           0 :         beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
     297           0 :     case lowshelf:
     298           0 :         s->a0 =          (A + 1) + (A - 1) * cos(w0) + beta * alpha;
     299           0 :         s->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
     300           0 :         s->a2 =          (A + 1) + (A - 1) * cos(w0) - beta * alpha;
     301           0 :         s->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + beta * alpha);
     302           0 :         s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
     303           0 :         s->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - beta * alpha);
     304           0 :         break;
     305           0 :     case treble:
     306           0 :         beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
     307           0 :     case highshelf:
     308           0 :         s->a0 =          (A + 1) - (A - 1) * cos(w0) + beta * alpha;
     309           0 :         s->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
     310           0 :         s->a2 =          (A + 1) - (A - 1) * cos(w0) - beta * alpha;
     311           0 :         s->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + beta * alpha);
     312           0 :         s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
     313           0 :         s->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - beta * alpha);
     314           0 :         break;
     315           0 :     case bandpass:
     316           0 :         if (s->csg) {
     317           0 :             s->a0 =  1 + alpha;
     318           0 :             s->a1 = -2 * cos(w0);
     319           0 :             s->a2 =  1 - alpha;
     320           0 :             s->b0 =  sin(w0) / 2;
     321           0 :             s->b1 =  0;
     322           0 :             s->b2 = -sin(w0) / 2;
     323             :         } else {
     324           0 :             s->a0 =  1 + alpha;
     325           0 :             s->a1 = -2 * cos(w0);
     326           0 :             s->a2 =  1 - alpha;
     327           0 :             s->b0 =  alpha;
     328           0 :             s->b1 =  0;
     329           0 :             s->b2 = -alpha;
     330             :         }
     331           0 :         break;
     332           0 :     case bandreject:
     333           0 :         s->a0 =  1 + alpha;
     334           0 :         s->a1 = -2 * cos(w0);
     335           0 :         s->a2 =  1 - alpha;
     336           0 :         s->b0 =  1;
     337           0 :         s->b1 = -2 * cos(w0);
     338           0 :         s->b2 =  1;
     339           0 :         break;
     340           0 :     case lowpass:
     341           0 :         if (s->poles == 1) {
     342           0 :             s->a0 = 1;
     343           0 :             s->a1 = -exp(-w0);
     344           0 :             s->a2 = 0;
     345           0 :             s->b0 = 1 + s->a1;
     346           0 :             s->b1 = 0;
     347           0 :             s->b2 = 0;
     348             :         } else {
     349           0 :             s->a0 =  1 + alpha;
     350           0 :             s->a1 = -2 * cos(w0);
     351           0 :             s->a2 =  1 - alpha;
     352           0 :             s->b0 = (1 - cos(w0)) / 2;
     353           0 :             s->b1 =  1 - cos(w0);
     354           0 :             s->b2 = (1 - cos(w0)) / 2;
     355             :         }
     356           0 :         break;
     357           0 :     case highpass:
     358           0 :         if (s->poles == 1) {
     359           0 :             s->a0 = 1;
     360           0 :             s->a1 = -exp(-w0);
     361           0 :             s->a2 = 0;
     362           0 :             s->b0 = (1 - s->a1) / 2;
     363           0 :             s->b1 = -s->b0;
     364           0 :             s->b2 = 0;
     365             :         } else {
     366           0 :             s->a0 =   1 + alpha;
     367           0 :             s->a1 =  -2 * cos(w0);
     368           0 :             s->a2 =   1 - alpha;
     369           0 :             s->b0 =  (1 + cos(w0)) / 2;
     370           0 :             s->b1 = -(1 + cos(w0));
     371           0 :             s->b2 =  (1 + cos(w0)) / 2;
     372             :         }
     373           0 :         break;
     374           0 :     case allpass:
     375           0 :         s->a0 =  1 + alpha;
     376           0 :         s->a1 = -2 * cos(w0);
     377           0 :         s->a2 =  1 - alpha;
     378           0 :         s->b0 =  1 - alpha;
     379           0 :         s->b1 = -2 * cos(w0);
     380           0 :         s->b2 =  1 + alpha;
     381           0 :         break;
     382           0 :     default:
     383           0 :         av_assert0(0);
     384             :     }
     385             : 
     386           0 :     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           0 :     s->a1 /= s->a0;
     389           0 :     s->a2 /= s->a0;
     390           0 :     s->b0 /= s->a0;
     391           0 :     s->b1 /= s->a0;
     392           0 :     s->b2 /= s->a0;
     393           0 :     s->a0 /= s->a0;
     394             : 
     395           0 :     s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
     396           0 :     if (!s->cache)
     397           0 :         return AVERROR(ENOMEM);
     398           0 :     if (reset)
     399           0 :         memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
     400             : 
     401           0 :     switch (inlink->format) {
     402           0 :     case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
     403           0 :     case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
     404           0 :     case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
     405           0 :     case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
     406           0 :     default: av_assert0(0);
     407             :     }
     408             : 
     409           0 :     s->block_align = av_get_bytes_per_sample(inlink->format);
     410             : 
     411           0 :     return 0;
     412             : }
     413             : 
     414           0 : static int config_output(AVFilterLink *outlink)
     415             : {
     416           0 :     return config_filter(outlink, 1);
     417             : }
     418             : 
     419             : typedef struct ThreadData {
     420             :     AVFrame *in, *out;
     421             : } ThreadData;
     422             : 
     423           0 : static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
     424             : {
     425           0 :     AVFilterLink *inlink = ctx->inputs[0];
     426           0 :     ThreadData *td = arg;
     427           0 :     AVFrame *buf = td->in;
     428           0 :     AVFrame *out_buf = td->out;
     429           0 :     BiquadsContext *s = ctx->priv;
     430           0 :     const int start = (buf->channels * jobnr) / nb_jobs;
     431           0 :     const int end = (buf->channels * (jobnr+1)) / nb_jobs;
     432             :     int ch;
     433             : 
     434           0 :     for (ch = start; ch < end; ch++) {
     435           0 :         if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
     436           0 :             if (buf != out_buf)
     437           0 :                 memcpy(out_buf->extended_data[ch], buf->extended_data[ch],
     438           0 :                        buf->nb_samples * s->block_align);
     439           0 :             continue;
     440             :         }
     441             : 
     442           0 :         s->filter(s, buf->extended_data[ch], out_buf->extended_data[ch], buf->nb_samples,
     443           0 :                   &s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].o1, &s->cache[ch].o2,
     444           0 :                   s->b0, s->b1, s->b2, s->a1, s->a2, &s->cache[ch].clippings);
     445             :     }
     446             : 
     447           0 :     return 0;
     448             : }
     449             : 
     450           0 : static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     451             : {
     452           0 :     AVFilterContext  *ctx = inlink->dst;
     453           0 :     BiquadsContext *s     = ctx->priv;
     454           0 :     AVFilterLink *outlink = ctx->outputs[0];
     455             :     AVFrame *out_buf;
     456             :     ThreadData td;
     457             :     int ch;
     458             : 
     459           0 :     if (av_frame_is_writable(buf)) {
     460           0 :         out_buf = buf;
     461             :     } else {
     462           0 :         out_buf = ff_get_audio_buffer(outlink, buf->nb_samples);
     463           0 :         if (!out_buf) {
     464           0 :             av_frame_free(&buf);
     465           0 :             return AVERROR(ENOMEM);
     466             :         }
     467           0 :         av_frame_copy_props(out_buf, buf);
     468             :     }
     469             : 
     470           0 :     td.in = buf;
     471           0 :     td.out = out_buf;
     472           0 :     ctx->internal->execute(ctx, filter_channel, &td, NULL, FFMIN(outlink->channels, ff_filter_get_nb_threads(ctx)));
     473             : 
     474           0 :     for (ch = 0; ch < outlink->channels; ch++) {
     475           0 :         if (s->cache[ch].clippings > 0)
     476           0 :             av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
     477           0 :                    ch, s->cache[ch].clippings);
     478           0 :         s->cache[ch].clippings = 0;
     479             :     }
     480             : 
     481           0 :     if (buf != out_buf)
     482           0 :         av_frame_free(&buf);
     483             : 
     484           0 :     return ff_filter_frame(outlink, out_buf);
     485             : }
     486             : 
     487           0 : static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
     488             :                            char *res, int res_len, int flags)
     489             : {
     490           0 :     BiquadsContext *s = ctx->priv;
     491           0 :     AVFilterLink *outlink = ctx->outputs[0];
     492             : 
     493           0 :     if ((!strcmp(cmd, "frequency") || !strcmp(cmd, "f")) &&
     494           0 :         (s->filter_type == equalizer ||
     495           0 :          s->filter_type == lowshelf  ||
     496           0 :          s->filter_type == highshelf ||
     497           0 :          s->filter_type == bass      ||
     498           0 :          s->filter_type == treble    ||
     499           0 :          s->filter_type == bandpass  ||
     500           0 :          s->filter_type == bandreject||
     501           0 :          s->filter_type == lowpass   ||
     502           0 :          s->filter_type == highpass  ||
     503           0 :          s->filter_type == allpass)) {
     504             :         double freq;
     505             : 
     506           0 :         if (sscanf(args, "%lf", &freq) != 1) {
     507           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid frequency value.\n");
     508           0 :             return AVERROR(EINVAL);
     509             :         }
     510             : 
     511           0 :         s->frequency = freq;
     512           0 :     } else if ((!strcmp(cmd, "gain") || !strcmp(cmd, "g")) &&
     513           0 :         (s->filter_type == equalizer ||
     514           0 :          s->filter_type == lowshelf  ||
     515           0 :          s->filter_type == highshelf ||
     516           0 :          s->filter_type == bass      ||
     517           0 :          s->filter_type == treble)) {
     518             :         double gain;
     519             : 
     520           0 :         if (sscanf(args, "%lf", &gain) != 1) {
     521           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid gain value.\n");
     522           0 :             return AVERROR(EINVAL);
     523             :         }
     524             : 
     525           0 :         s->gain = gain;
     526           0 :     } else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
     527           0 :         (s->filter_type == equalizer ||
     528           0 :          s->filter_type == lowshelf  ||
     529           0 :          s->filter_type == highshelf ||
     530           0 :          s->filter_type == bass      ||
     531           0 :          s->filter_type == treble    ||
     532           0 :          s->filter_type == bandpass  ||
     533           0 :          s->filter_type == bandreject||
     534           0 :          s->filter_type == lowpass   ||
     535           0 :          s->filter_type == highpass  ||
     536           0 :          s->filter_type == allpass)) {
     537             :         double width;
     538             : 
     539           0 :         if (sscanf(args, "%lf", &width) != 1) {
     540           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid width value.\n");
     541           0 :             return AVERROR(EINVAL);
     542             :         }
     543             : 
     544           0 :         s->width = width;
     545           0 :     } else if ((!strcmp(cmd, "width_type") || !strcmp(cmd, "t")) &&
     546           0 :         (s->filter_type == equalizer ||
     547           0 :          s->filter_type == lowshelf  ||
     548           0 :          s->filter_type == highshelf ||
     549           0 :          s->filter_type == bass      ||
     550           0 :          s->filter_type == treble    ||
     551           0 :          s->filter_type == bandpass  ||
     552           0 :          s->filter_type == bandreject||
     553           0 :          s->filter_type == lowpass   ||
     554           0 :          s->filter_type == highpass  ||
     555           0 :          s->filter_type == allpass)) {
     556             :         char width_type;
     557             : 
     558           0 :         if (sscanf(args, "%c", &width_type) != 1) {
     559           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid width_type value.\n");
     560           0 :             return AVERROR(EINVAL);
     561             :         }
     562             : 
     563           0 :         switch (width_type) {
     564           0 :         case 'h': width_type = HERTZ;   break;
     565           0 :         case 'q': width_type = QFACTOR; break;
     566           0 :         case 'o': width_type = OCTAVE;  break;
     567           0 :         case 's': width_type = SLOPE;   break;
     568           0 :         case 'k': width_type = KHERTZ;  break;
     569           0 :         default:
     570           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid width_type value: %c\n", width_type);
     571           0 :             return AVERROR(EINVAL);
     572             :         }
     573             : 
     574           0 :         s->width_type = width_type;
     575           0 :     } else if ((!strcmp(cmd, "a0") ||
     576           0 :                 !strcmp(cmd, "a1") ||
     577           0 :                 !strcmp(cmd, "a2") ||
     578           0 :                 !strcmp(cmd, "b0") ||
     579           0 :                 !strcmp(cmd, "b1") ||
     580           0 :                 !strcmp(cmd, "b2")) &&
     581           0 :                s->filter_type == biquad) {
     582             :         double value;
     583             : 
     584           0 :         if (sscanf(args, "%lf", &value) != 1) {
     585           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid biquad value.\n");
     586           0 :             return AVERROR(EINVAL);
     587             :         }
     588             : 
     589           0 :         if (!strcmp(cmd, "a0"))
     590           0 :             s->a0 = value;
     591           0 :         else if (!strcmp(cmd, "a1"))
     592           0 :             s->a1 = value;
     593           0 :         else if (!strcmp(cmd, "a2"))
     594           0 :             s->a2 = value;
     595           0 :         else if (!strcmp(cmd, "b0"))
     596           0 :             s->b0 = value;
     597           0 :         else if (!strcmp(cmd, "b1"))
     598           0 :             s->b1 = value;
     599           0 :         else if (!strcmp(cmd, "b2"))
     600           0 :             s->b2 = value;
     601             :     }
     602             : 
     603           0 :     return config_filter(outlink, 0);
     604             : }
     605             : 
     606           0 : static av_cold void uninit(AVFilterContext *ctx)
     607             : {
     608           0 :     BiquadsContext *s = ctx->priv;
     609             : 
     610           0 :     av_freep(&s->cache);
     611           0 : }
     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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : 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           0 : DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
     887             : #endif  /* CONFIG_BIQUAD_FILTER */

Generated by: LCOV version 1.13