LCOV - code coverage report
Current view: top level - src/libavfilter - af_biquads.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 186 0.0 %
Date: 2017-05-26 21:11:57 Functions: 0 18 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             :     band,
      77             :     bandpass,
      78             :     bandreject,
      79             :     allpass,
      80             :     highpass,
      81             :     lowpass,
      82             : };
      83             : 
      84             : enum WidthType {
      85             :     NONE,
      86             :     HERTZ,
      87             :     OCTAVE,
      88             :     QFACTOR,
      89             :     SLOPE,
      90             : };
      91             : 
      92             : typedef struct ChanCache {
      93             :     double i1, i2;
      94             :     double o1, o2;
      95             : } ChanCache;
      96             : 
      97             : typedef struct BiquadsContext {
      98             :     const AVClass *class;
      99             : 
     100             :     enum FilterType filter_type;
     101             :     int width_type;
     102             :     int poles;
     103             :     int csg;
     104             : 
     105             :     double gain;
     106             :     double frequency;
     107             :     double width;
     108             :     uint64_t channels;
     109             : 
     110             :     double a0, a1, a2;
     111             :     double b0, b1, b2;
     112             : 
     113             :     ChanCache *cache;
     114             :     int clippings;
     115             :     int block_align;
     116             : 
     117             :     void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
     118             :                    double *i1, double *i2, double *o1, double *o2,
     119             :                    double b0, double b1, double b2, double a1, double a2);
     120             : } BiquadsContext;
     121             : 
     122           0 : static av_cold int init(AVFilterContext *ctx)
     123             : {
     124           0 :     BiquadsContext *s = ctx->priv;
     125             : 
     126           0 :     if (s->filter_type != biquad) {
     127           0 :         if (s->frequency <= 0 || s->width <= 0) {
     128           0 :             av_log(ctx, AV_LOG_ERROR, "Invalid frequency %f and/or width %f <= 0\n",
     129             :                    s->frequency, s->width);
     130           0 :             return AVERROR(EINVAL);
     131             :         }
     132             :     }
     133             : 
     134           0 :     return 0;
     135             : }
     136             : 
     137           0 : static int query_formats(AVFilterContext *ctx)
     138             : {
     139             :     AVFilterFormats *formats;
     140             :     AVFilterChannelLayouts *layouts;
     141             :     static const enum AVSampleFormat sample_fmts[] = {
     142             :         AV_SAMPLE_FMT_S16P,
     143             :         AV_SAMPLE_FMT_S32P,
     144             :         AV_SAMPLE_FMT_FLTP,
     145             :         AV_SAMPLE_FMT_DBLP,
     146             :         AV_SAMPLE_FMT_NONE
     147             :     };
     148             :     int ret;
     149             : 
     150           0 :     layouts = ff_all_channel_counts();
     151           0 :     if (!layouts)
     152           0 :         return AVERROR(ENOMEM);
     153           0 :     ret = ff_set_common_channel_layouts(ctx, layouts);
     154           0 :     if (ret < 0)
     155           0 :         return ret;
     156             : 
     157           0 :     formats = ff_make_format_list(sample_fmts);
     158           0 :     if (!formats)
     159           0 :         return AVERROR(ENOMEM);
     160           0 :     ret = ff_set_common_formats(ctx, formats);
     161           0 :     if (ret < 0)
     162           0 :         return ret;
     163             : 
     164           0 :     formats = ff_all_samplerates();
     165           0 :     if (!formats)
     166           0 :         return AVERROR(ENOMEM);
     167           0 :     return ff_set_common_samplerates(ctx, formats);
     168             : }
     169             : 
     170             : #define BIQUAD_FILTER(name, type, min, max, need_clipping)                    \
     171             : static void biquad_## name (BiquadsContext *s,                                \
     172             :                             const void *input, void *output, int len,         \
     173             :                             double *in1, double *in2,                         \
     174             :                             double *out1, double *out2,                       \
     175             :                             double b0, double b1, double b2,                  \
     176             :                             double a1, double a2)                             \
     177             : {                                                                             \
     178             :     const type *ibuf = input;                                                 \
     179             :     type *obuf = output;                                                      \
     180             :     double i1 = *in1;                                                         \
     181             :     double i2 = *in2;                                                         \
     182             :     double o1 = *out1;                                                        \
     183             :     double o2 = *out2;                                                        \
     184             :     int i;                                                                    \
     185             :     a1 = -a1;                                                                 \
     186             :     a2 = -a2;                                                                 \
     187             :                                                                               \
     188             :     for (i = 0; i+1 < len; i++) {                                             \
     189             :         o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1;            \
     190             :         i2 = ibuf[i];                                                         \
     191             :         if (need_clipping && o2 < min) {                                      \
     192             :             s->clippings++;                                                   \
     193             :             obuf[i] = min;                                                    \
     194             :         } else if (need_clipping && o2 > max) {                               \
     195             :             s->clippings++;                                                   \
     196             :             obuf[i] = max;                                                    \
     197             :         } else {                                                              \
     198             :             obuf[i] = o2;                                                     \
     199             :         }                                                                     \
     200             :         i++;                                                                  \
     201             :         o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1;            \
     202             :         i1 = ibuf[i];                                                         \
     203             :         if (need_clipping && o1 < min) {                                      \
     204             :             s->clippings++;                                                   \
     205             :             obuf[i] = min;                                                    \
     206             :         } else if (need_clipping && o1 > max) {                               \
     207             :             s->clippings++;                                                   \
     208             :             obuf[i] = max;                                                    \
     209             :         } else {                                                              \
     210             :             obuf[i] = o1;                                                     \
     211             :         }                                                                     \
     212             :     }                                                                         \
     213             :     if (i < len) {                                                            \
     214             :         double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2;     \
     215             :         i2 = i1;                                                              \
     216             :         i1 = ibuf[i];                                                         \
     217             :         o2 = o1;                                                              \
     218             :         o1 = o0;                                                              \
     219             :         if (need_clipping && o0 < min) {                                      \
     220             :             s->clippings++;                                                   \
     221             :             obuf[i] = min;                                                    \
     222             :         } else if (need_clipping && o0 > max) {                               \
     223             :             s->clippings++;                                                   \
     224             :             obuf[i] = max;                                                    \
     225             :         } else {                                                              \
     226             :             obuf[i] = o0;                                                     \
     227             :         }                                                                     \
     228             :     }                                                                         \
     229             :     *in1  = i1;                                                               \
     230             :     *in2  = i2;                                                               \
     231             :     *out1 = o1;                                                               \
     232             :     *out2 = o2;                                                               \
     233             : }
     234             : 
     235           0 : BIQUAD_FILTER(s16, int16_t, INT16_MIN, INT16_MAX, 1)
     236           0 : BIQUAD_FILTER(s32, int32_t, INT32_MIN, INT32_MAX, 1)
     237           0 : BIQUAD_FILTER(flt, float,   -1., 1., 0)
     238           0 : BIQUAD_FILTER(dbl, double,  -1., 1., 0)
     239             : 
     240           0 : static int config_output(AVFilterLink *outlink)
     241             : {
     242           0 :     AVFilterContext *ctx    = outlink->src;
     243           0 :     BiquadsContext *s       = ctx->priv;
     244           0 :     AVFilterLink *inlink    = ctx->inputs[0];
     245           0 :     double A = exp(s->gain / 40 * log(10.));
     246           0 :     double w0 = 2 * M_PI * s->frequency / inlink->sample_rate;
     247             :     double alpha;
     248             : 
     249           0 :     if (w0 > M_PI) {
     250           0 :         av_log(ctx, AV_LOG_ERROR,
     251             :                "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
     252             :                s->frequency, inlink->sample_rate);
     253           0 :         return AVERROR(EINVAL);
     254             :     }
     255             : 
     256           0 :     switch (s->width_type) {
     257             :     case NONE:
     258           0 :         alpha = 0.0;
     259           0 :         break;
     260             :     case HERTZ:
     261           0 :         alpha = sin(w0) / (2 * s->frequency / s->width);
     262           0 :         break;
     263             :     case OCTAVE:
     264           0 :         alpha = sin(w0) * sinh(log(2.) / 2 * s->width * w0 / sin(w0));
     265           0 :         break;
     266             :     case QFACTOR:
     267           0 :         alpha = sin(w0) / (2 * s->width);
     268           0 :         break;
     269             :     case SLOPE:
     270           0 :         alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->width - 1) + 2);
     271           0 :         break;
     272             :     default:
     273           0 :         av_assert0(0);
     274             :     }
     275             : 
     276           0 :     switch (s->filter_type) {
     277             :     case biquad:
     278           0 :         break;
     279             :     case equalizer:
     280           0 :         s->a0 =   1 + alpha / A;
     281           0 :         s->a1 =  -2 * cos(w0);
     282           0 :         s->a2 =   1 - alpha / A;
     283           0 :         s->b0 =   1 + alpha * A;
     284           0 :         s->b1 =  -2 * cos(w0);
     285           0 :         s->b2 =   1 - alpha * A;
     286           0 :         break;
     287             :     case bass:
     288           0 :         s->a0 =          (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
     289           0 :         s->a1 =    -2 * ((A - 1) + (A + 1) * cos(w0));
     290           0 :         s->a2 =          (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
     291           0 :         s->b0 =     A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
     292           0 :         s->b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
     293           0 :         s->b2 =     A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
     294           0 :         break;
     295             :     case treble:
     296           0 :         s->a0 =          (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) * alpha;
     297           0 :         s->a1 =     2 * ((A - 1) - (A + 1) * cos(w0));
     298           0 :         s->a2 =          (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) * alpha;
     299           0 :         s->b0 =     A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) * alpha);
     300           0 :         s->b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
     301           0 :         s->b2 =     A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) * alpha);
     302           0 :         break;
     303             :     case bandpass:
     304           0 :         if (s->csg) {
     305           0 :             s->a0 =  1 + alpha;
     306           0 :             s->a1 = -2 * cos(w0);
     307           0 :             s->a2 =  1 - alpha;
     308           0 :             s->b0 =  sin(w0) / 2;
     309           0 :             s->b1 =  0;
     310           0 :             s->b2 = -sin(w0) / 2;
     311             :         } else {
     312           0 :             s->a0 =  1 + alpha;
     313           0 :             s->a1 = -2 * cos(w0);
     314           0 :             s->a2 =  1 - alpha;
     315           0 :             s->b0 =  alpha;
     316           0 :             s->b1 =  0;
     317           0 :             s->b2 = -alpha;
     318             :         }
     319           0 :         break;
     320             :     case bandreject:
     321           0 :         s->a0 =  1 + alpha;
     322           0 :         s->a1 = -2 * cos(w0);
     323           0 :         s->a2 =  1 - alpha;
     324           0 :         s->b0 =  1;
     325           0 :         s->b1 = -2 * cos(w0);
     326           0 :         s->b2 =  1;
     327           0 :         break;
     328             :     case lowpass:
     329           0 :         if (s->poles == 1) {
     330           0 :             s->a0 = 1;
     331           0 :             s->a1 = -exp(-w0);
     332           0 :             s->a2 = 0;
     333           0 :             s->b0 = 1 + s->a1;
     334           0 :             s->b1 = 0;
     335           0 :             s->b2 = 0;
     336             :         } else {
     337           0 :             s->a0 =  1 + alpha;
     338           0 :             s->a1 = -2 * cos(w0);
     339           0 :             s->a2 =  1 - alpha;
     340           0 :             s->b0 = (1 - cos(w0)) / 2;
     341           0 :             s->b1 =  1 - cos(w0);
     342           0 :             s->b2 = (1 - cos(w0)) / 2;
     343             :         }
     344           0 :         break;
     345             :     case highpass:
     346           0 :         if (s->poles == 1) {
     347           0 :             s->a0 = 1;
     348           0 :             s->a1 = -exp(-w0);
     349           0 :             s->a2 = 0;
     350           0 :             s->b0 = (1 - s->a1) / 2;
     351           0 :             s->b1 = -s->b0;
     352           0 :             s->b2 = 0;
     353             :         } else {
     354           0 :             s->a0 =   1 + alpha;
     355           0 :             s->a1 =  -2 * cos(w0);
     356           0 :             s->a2 =   1 - alpha;
     357           0 :             s->b0 =  (1 + cos(w0)) / 2;
     358           0 :             s->b1 = -(1 + cos(w0));
     359           0 :             s->b2 =  (1 + cos(w0)) / 2;
     360             :         }
     361           0 :         break;
     362             :     case allpass:
     363           0 :         s->a0 =  1 + alpha;
     364           0 :         s->a1 = -2 * cos(w0);
     365           0 :         s->a2 =  1 - alpha;
     366           0 :         s->b0 =  1 - alpha;
     367           0 :         s->b1 = -2 * cos(w0);
     368           0 :         s->b2 =  1 + alpha;
     369           0 :         break;
     370             :     default:
     371           0 :         av_assert0(0);
     372             :     }
     373             : 
     374           0 :     s->a1 /= s->a0;
     375           0 :     s->a2 /= s->a0;
     376           0 :     s->b0 /= s->a0;
     377           0 :     s->b1 /= s->a0;
     378           0 :     s->b2 /= s->a0;
     379             : 
     380           0 :     s->cache = av_realloc_f(s->cache, sizeof(ChanCache), inlink->channels);
     381           0 :     if (!s->cache)
     382           0 :         return AVERROR(ENOMEM);
     383           0 :     memset(s->cache, 0, sizeof(ChanCache) * inlink->channels);
     384             : 
     385           0 :     switch (inlink->format) {
     386           0 :     case AV_SAMPLE_FMT_S16P: s->filter = biquad_s16; break;
     387           0 :     case AV_SAMPLE_FMT_S32P: s->filter = biquad_s32; break;
     388           0 :     case AV_SAMPLE_FMT_FLTP: s->filter = biquad_flt; break;
     389           0 :     case AV_SAMPLE_FMT_DBLP: s->filter = biquad_dbl; break;
     390           0 :     default: av_assert0(0);
     391             :     }
     392             : 
     393           0 :     s->block_align = av_get_bytes_per_sample(inlink->format);
     394             : 
     395           0 :     return 0;
     396             : }
     397             : 
     398           0 : static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     399             : {
     400           0 :     AVFilterContext  *ctx = inlink->dst;
     401           0 :     BiquadsContext *s     = ctx->priv;
     402           0 :     AVFilterLink *outlink = ctx->outputs[0];
     403             :     AVFrame *out_buf;
     404           0 :     int nb_samples = buf->nb_samples;
     405             :     int ch;
     406             : 
     407           0 :     if (av_frame_is_writable(buf)) {
     408           0 :         out_buf = buf;
     409             :     } else {
     410           0 :         out_buf = ff_get_audio_buffer(inlink, nb_samples);
     411           0 :         if (!out_buf) {
     412           0 :             av_frame_free(&buf);
     413           0 :             return AVERROR(ENOMEM);
     414             :         }
     415           0 :         av_frame_copy_props(out_buf, buf);
     416             :     }
     417             : 
     418           0 :     for (ch = 0; ch < buf->channels; ch++) {
     419           0 :         if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
     420           0 :             if (buf != out_buf)
     421           0 :                 memcpy(out_buf->extended_data[ch], buf->extended_data[ch], nb_samples * s->block_align);
     422           0 :             continue;
     423             :         }
     424           0 :         s->filter(s, buf->extended_data[ch],
     425           0 :                   out_buf->extended_data[ch], nb_samples,
     426           0 :                   &s->cache[ch].i1, &s->cache[ch].i2,
     427           0 :                   &s->cache[ch].o1, &s->cache[ch].o2,
     428             :                   s->b0, s->b1, s->b2, s->a1, s->a2);
     429             :     }
     430             : 
     431           0 :     if (s->clippings > 0)
     432           0 :         av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
     433           0 :     s->clippings = 0;
     434             : 
     435           0 :     if (buf != out_buf)
     436           0 :         av_frame_free(&buf);
     437             : 
     438           0 :     return ff_filter_frame(outlink, out_buf);
     439             : }
     440             : 
     441           0 : static av_cold void uninit(AVFilterContext *ctx)
     442             : {
     443           0 :     BiquadsContext *s = ctx->priv;
     444             : 
     445           0 :     av_freep(&s->cache);
     446           0 : }
     447             : 
     448             : static const AVFilterPad inputs[] = {
     449             :     {
     450             :         .name         = "default",
     451             :         .type         = AVMEDIA_TYPE_AUDIO,
     452             :         .filter_frame = filter_frame,
     453             :     },
     454             :     { NULL }
     455             : };
     456             : 
     457             : static const AVFilterPad outputs[] = {
     458             :     {
     459             :         .name         = "default",
     460             :         .type         = AVMEDIA_TYPE_AUDIO,
     461             :         .config_props = config_output,
     462             :     },
     463             :     { NULL }
     464             : };
     465             : 
     466             : #define OFFSET(x) offsetof(BiquadsContext, x)
     467             : #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
     468             : 
     469             : #define DEFINE_BIQUAD_FILTER(name_, description_)                       \
     470             : AVFILTER_DEFINE_CLASS(name_);                                           \
     471             : static av_cold int name_##_init(AVFilterContext *ctx) \
     472             : {                                                                       \
     473             :     BiquadsContext *s = ctx->priv;                                      \
     474             :     s->class = &name_##_class;                                          \
     475             :     s->filter_type = name_;                                             \
     476             :     return init(ctx);                                             \
     477             : }                                                                       \
     478             :                                                          \
     479             : AVFilter ff_af_##name_ = {                         \
     480             :     .name          = #name_,                             \
     481             :     .description   = NULL_IF_CONFIG_SMALL(description_), \
     482             :     .priv_size     = sizeof(BiquadsContext),             \
     483             :     .init          = name_##_init,                       \
     484             :     .uninit        = uninit,                             \
     485             :     .query_formats = query_formats,                      \
     486             :     .inputs        = inputs,                             \
     487             :     .outputs       = outputs,                            \
     488             :     .priv_class    = &name_##_class,                     \
     489             : }
     490             : 
     491             : #if CONFIG_EQUALIZER_FILTER
     492             : static const AVOption equalizer_options[] = {
     493             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
     494             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 999999, FLAGS},
     495             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     496             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     497             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     498             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     499             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     500             :     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
     501             :     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
     502             :     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     503             :     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     504             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     505             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     506             :     {NULL}
     507             : };
     508             : 
     509           0 : DEFINE_BIQUAD_FILTER(equalizer, "Apply two-pole peaking equalization (EQ) filter.");
     510             : #endif  /* CONFIG_EQUALIZER_FILTER */
     511             : #if CONFIG_BASS_FILTER
     512             : static const AVOption bass_options[] = {
     513             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
     514             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=100}, 0, 999999, FLAGS},
     515             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     516             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     517             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     518             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     519             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     520             :     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     521             :     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     522             :     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     523             :     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     524             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     525             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     526             :     {NULL}
     527             : };
     528             : 
     529           0 : DEFINE_BIQUAD_FILTER(bass, "Boost or cut lower frequencies.");
     530             : #endif  /* CONFIG_BASS_FILTER */
     531             : #if CONFIG_TREBLE_FILTER
     532             : static const AVOption treble_options[] = {
     533             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     534             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     535             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     536             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     537             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     538             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     539             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     540             :     {"width", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     541             :     {"w",     "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
     542             :     {"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     543             :     {"g",    "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
     544             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     545             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     546             :     {NULL}
     547             : };
     548             : 
     549           0 : DEFINE_BIQUAD_FILTER(treble, "Boost or cut upper frequencies.");
     550             : #endif  /* CONFIG_TREBLE_FILTER */
     551             : #if CONFIG_BANDPASS_FILTER
     552             : static const AVOption bandpass_options[] = {
     553             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     554             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     555             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     556             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     557             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     558             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     559             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     560             :     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
     561             :     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
     562             :     {"csg",   "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
     563             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     564             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     565             :     {NULL}
     566             : };
     567             : 
     568           0 : DEFINE_BIQUAD_FILTER(bandpass, "Apply a two-pole Butterworth band-pass filter.");
     569             : #endif  /* CONFIG_BANDPASS_FILTER */
     570             : #if CONFIG_BANDREJECT_FILTER
     571             : static const AVOption bandreject_options[] = {
     572             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     573             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     574             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     575             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     576             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     577             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     578             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     579             :     {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
     580             :     {"w",     "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
     581             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     582             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     583             :     {NULL}
     584             : };
     585             : 
     586           0 : DEFINE_BIQUAD_FILTER(bandreject, "Apply a two-pole Butterworth band-reject filter.");
     587             : #endif  /* CONFIG_BANDREJECT_FILTER */
     588             : #if CONFIG_LOWPASS_FILTER
     589             : static const AVOption lowpass_options[] = {
     590             :     {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
     591             :     {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=500}, 0, 999999, FLAGS},
     592             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     593             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     594             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     595             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     596             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     597             :     {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
     598             :     {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
     599             :     {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
     600             :     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
     601             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     602             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     603             :     {NULL}
     604             : };
     605             : 
     606           0 : DEFINE_BIQUAD_FILTER(lowpass, "Apply a low-pass filter with 3dB point frequency.");
     607             : #endif  /* CONFIG_LOWPASS_FILTER */
     608             : #if CONFIG_HIGHPASS_FILTER
     609             : static const AVOption highpass_options[] = {
     610             :     {"frequency", "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     611             :     {"f",         "set frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     612             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=QFACTOR}, HERTZ, SLOPE, FLAGS, "width_type"},
     613             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     614             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     615             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     616             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     617             :     {"width", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
     618             :     {"w",     "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
     619             :     {"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
     620             :     {"p",     "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
     621             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     622             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     623             :     {NULL}
     624             : };
     625             : 
     626           0 : DEFINE_BIQUAD_FILTER(highpass, "Apply a high-pass filter with 3dB point frequency.");
     627             : #endif  /* CONFIG_HIGHPASS_FILTER */
     628             : #if CONFIG_ALLPASS_FILTER
     629             : static const AVOption allpass_options[] = {
     630             :     {"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     631             :     {"f",         "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
     632             :     {"width_type", "set filter-width type", OFFSET(width_type), AV_OPT_TYPE_INT, {.i64=HERTZ}, HERTZ, SLOPE, FLAGS, "width_type"},
     633             :     {"h", "Hz", 0, AV_OPT_TYPE_CONST, {.i64=HERTZ}, 0, 0, FLAGS, "width_type"},
     634             :     {"q", "Q-Factor", 0, AV_OPT_TYPE_CONST, {.i64=QFACTOR}, 0, 0, FLAGS, "width_type"},
     635             :     {"o", "octave", 0, AV_OPT_TYPE_CONST, {.i64=OCTAVE}, 0, 0, FLAGS, "width_type"},
     636             :     {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
     637             :     {"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
     638             :     {"w",     "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
     639             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     640             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     641             :     {NULL}
     642             : };
     643             : 
     644           0 : DEFINE_BIQUAD_FILTER(allpass, "Apply a two-pole all-pass filter.");
     645             : #endif  /* CONFIG_ALLPASS_FILTER */
     646             : #if CONFIG_BIQUAD_FILTER
     647             : static const AVOption biquad_options[] = {
     648             :     {"a0", NULL, OFFSET(a0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     649             :     {"a1", NULL, OFFSET(a1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     650             :     {"a2", NULL, OFFSET(a2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     651             :     {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     652             :     {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     653             :     {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
     654             :     {"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     655             :     {"c",        "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
     656             :     {NULL}
     657             : };
     658             : 
     659           0 : DEFINE_BIQUAD_FILTER(biquad, "Apply a biquad IIR filter with the given coefficients.");
     660             : #endif  /* CONFIG_BIQUAD_FILTER */

Generated by: LCOV version 1.13