2 * Copyright (c) 2018 Paul B Mahol
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "libavutil/avassert.h"
24 #include "libavutil/avstring.h"
25 #include "libavutil/opt.h"
30 typedef struct ThreadData {
38 typedef struct BiquadContext {
45 typedef struct IIRChannel {
50 BiquadContext *biquads;
54 typedef struct AudioIIRContext {
56 char *a_str, *b_str, *g_str;
57 double dry_gain, wet_gain;
64 enum AVSampleFormat sample_format;
66 int (*iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs);
69 static int query_formats(AVFilterContext *ctx)
71 AudioIIRContext *s = ctx->priv;
72 AVFilterFormats *formats;
73 AVFilterChannelLayouts *layouts;
74 enum AVSampleFormat sample_fmts[] = {
80 layouts = ff_all_channel_counts();
82 return AVERROR(ENOMEM);
83 ret = ff_set_common_channel_layouts(ctx, layouts);
87 sample_fmts[0] = s->sample_format;
88 formats = ff_make_format_list(sample_fmts);
90 return AVERROR(ENOMEM);
91 ret = ff_set_common_formats(ctx, formats);
95 formats = ff_all_samplerates();
97 return AVERROR(ENOMEM);
98 return ff_set_common_samplerates(ctx, formats);
101 #define IIR_CH(name, type, min, max, need_clipping) \
102 static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
104 AudioIIRContext *s = ctx->priv; \
105 const double ig = s->dry_gain; \
106 const double og = s->wet_gain; \
107 ThreadData *td = arg; \
108 AVFrame *in = td->in, *out = td->out; \
109 const type *src = (const type *)in->extended_data[ch]; \
110 double *ic = (double *)s->iir[ch].cache[0]; \
111 double *oc = (double *)s->iir[ch].cache[1]; \
112 const int nb_a = s->iir[ch].nb_ab[0]; \
113 const int nb_b = s->iir[ch].nb_ab[1]; \
114 const double *a = s->iir[ch].ab[0]; \
115 const double *b = s->iir[ch].ab[1]; \
116 int *clippings = &s->iir[ch].clippings; \
117 type *dst = (type *)out->extended_data[ch]; \
120 for (n = 0; n < in->nb_samples; n++) { \
121 double sample = 0.; \
124 memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \
125 memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \
126 ic[0] = src[n] * ig; \
127 for (x = 0; x < nb_b; x++) \
128 sample += b[x] * ic[x]; \
130 for (x = 1; x < nb_a; x++) \
131 sample -= a[x] * oc[x]; \
135 if (need_clipping && sample < min) { \
138 } else if (need_clipping && sample > max) { \
149 IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
150 IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
151 IIR_CH(fltp, float, -1., 1., 0)
152 IIR_CH(dblp, double, -1., 1., 0)
154 #define SERIAL_IIR_CH(name, type, min, max, need_clipping) \
155 static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
157 AudioIIRContext *s = ctx->priv; \
158 const double ig = s->dry_gain; \
159 const double og = s->wet_gain; \
160 ThreadData *td = arg; \
161 AVFrame *in = td->in, *out = td->out; \
162 const type *src = (const type *)in->extended_data[ch]; \
163 type *dst = (type *)out->extended_data[ch]; \
164 IIRChannel *iir = &s->iir[ch]; \
165 int *clippings = &iir->clippings; \
166 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
169 for (i = 0; i < nb_biquads; i++) { \
170 const double a1 = -iir->biquads[i].a1; \
171 const double a2 = -iir->biquads[i].a2; \
172 const double b0 = iir->biquads[i].b0; \
173 const double b1 = iir->biquads[i].b1; \
174 const double b2 = iir->biquads[i].b2; \
175 double i1 = iir->biquads[i].i1; \
176 double i2 = iir->biquads[i].i2; \
177 double o1 = iir->biquads[i].o1; \
178 double o2 = iir->biquads[i].o2; \
180 for (n = 0; n < in->nb_samples; n++) { \
181 double sample = ig * (i ? dst[n] : src[n]); \
182 double o0 = sample * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
190 if (need_clipping && o0 < min) { \
193 } else if (need_clipping && o0 > max) { \
200 iir->biquads[i].i1 = i1; \
201 iir->biquads[i].i2 = i2; \
202 iir->biquads[i].o1 = o1; \
203 iir->biquads[i].o2 = o2; \
209 SERIAL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
210 SERIAL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
211 SERIAL_IIR_CH(fltp, float, -1., 1., 0)
212 SERIAL_IIR_CH(dblp, double, -1., 1., 0)
214 static void count_coefficients(char *item_str, int *nb_items)
222 for (p = item_str; *p && *p != '|'; p++) {
228 static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items)
230 AudioIIRContext *s = ctx->priv;
231 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
234 p = old_str = av_strdup(item_str);
236 return AVERROR(ENOMEM);
237 for (i = 0; i < nb_items; i++) {
238 if (!(arg = av_strtok(p, "|", &saveptr)))
243 return AVERROR(EINVAL);
247 if (sscanf(arg, "%lf", &s->iir[i].g) != 1) {
248 av_log(ctx, AV_LOG_ERROR, "Invalid gains supplied: %s\n", arg);
250 return AVERROR(EINVAL);
261 static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst)
263 char *p, *arg, *old_str, *saveptr = NULL;
266 p = old_str = av_strdup(item_str);
268 return AVERROR(ENOMEM);
269 for (i = 0; i < nb_items; i++) {
270 if (!(arg = av_strtok(p, " ", &saveptr)))
274 if (sscanf(arg, "%lf", &dst[i]) != 1) {
275 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
277 return AVERROR(EINVAL);
286 static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
288 char *p, *arg, *old_str, *saveptr = NULL;
291 p = old_str = av_strdup(item_str);
293 return AVERROR(ENOMEM);
294 for (i = 0; i < nb_items; i++) {
295 if (!(arg = av_strtok(p, " ", &saveptr)))
299 if (sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2) {
300 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
302 return AVERROR(EINVAL);
311 static const char *format[] = { "%lf", "%lf %lfi", "%lf %lfr", "%lf %lfd" };
313 static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab)
315 AudioIIRContext *s = ctx->priv;
316 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
319 p = old_str = av_strdup(item_str);
321 return AVERROR(ENOMEM);
322 for (i = 0; i < channels; i++) {
323 IIRChannel *iir = &s->iir[i];
325 if (!(arg = av_strtok(p, "|", &saveptr)))
330 return AVERROR(EINVAL);
333 count_coefficients(arg, &iir->nb_ab[ab]);
336 iir->cache[ab] = av_calloc(iir->nb_ab[ab] + 1, sizeof(double));
337 iir->ab[ab] = av_calloc(iir->nb_ab[ab] * (!!s->format + 1), sizeof(double));
338 if (!iir->ab[ab] || !iir->cache[ab]) {
340 return AVERROR(ENOMEM);
344 ret = read_zp_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab], format[s->format]);
346 ret = read_tf_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab]);
360 static void multiply(double wre, double wim, int npz, double *coeffs)
362 double nwre = -wre, nwim = -wim;
366 for (i = npz; i >= 1; i--) {
367 cre = coeffs[2 * i + 0];
368 cim = coeffs[2 * i + 1];
370 coeffs[2 * i + 0] = (nwre * cre - nwim * cim) + coeffs[2 * (i - 1) + 0];
371 coeffs[2 * i + 1] = (nwre * cim + nwim * cre) + coeffs[2 * (i - 1) + 1];
376 coeffs[0] = nwre * cre - nwim * cim;
377 coeffs[1] = nwre * cim + nwim * cre;
380 static int expand(AVFilterContext *ctx, double *pz, int nb, double *coeffs)
387 for (i = 0; i < nb; i++) {
388 coeffs[2 * (i + 1) ] = 0.0;
389 coeffs[2 * (i + 1) + 1] = 0.0;
392 for (i = 0; i < nb; i++)
393 multiply(pz[2 * i], pz[2 * i + 1], nb, coeffs);
395 for (i = 0; i < nb + 1; i++) {
396 if (fabs(coeffs[2 * i + 1]) > FLT_EPSILON) {
397 av_log(ctx, AV_LOG_ERROR, "coeff: %lf of z^%d is not real; poles/zeros are not complex conjugates.\n",
398 coeffs[2 * i + 1], i);
399 return AVERROR(EINVAL);
406 static int convert_zp2tf(AVFilterContext *ctx, int channels)
408 AudioIIRContext *s = ctx->priv;
409 int ch, i, j, ret = 0;
411 for (ch = 0; ch < channels; ch++) {
412 IIRChannel *iir = &s->iir[ch];
415 topc = av_calloc((iir->nb_ab[0] + 1) * 2, sizeof(*topc));
416 botc = av_calloc((iir->nb_ab[1] + 1) * 2, sizeof(*botc));
417 if (!topc || !botc) {
418 ret = AVERROR(ENOMEM);
422 ret = expand(ctx, iir->ab[0], iir->nb_ab[0], botc);
427 ret = expand(ctx, iir->ab[1], iir->nb_ab[1], topc);
432 for (j = 0, i = iir->nb_ab[1]; i >= 0; j++, i--) {
433 iir->ab[1][j] = topc[2 * i];
437 for (j = 0, i = iir->nb_ab[0]; i >= 0; j++, i--) {
438 iir->ab[0][j] = botc[2 * i];
452 static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
454 AudioIIRContext *s = ctx->priv;
457 for (ch = 0; ch < channels; ch++) {
458 IIRChannel *iir = &s->iir[ch];
459 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2;
460 int current_biquad = 0;
462 iir->biquads = av_calloc(nb_biquads, sizeof(BiquadContext));
464 return AVERROR(ENOMEM);
466 while (nb_biquads--) {
467 Pair outmost_pole = { -1, -1 };
468 Pair nearest_zero = { -1, -1 };
469 double zeros[4] = { 0 };
470 double poles[4] = { 0 };
473 double min_distance = DBL_MAX;
477 for (i = 0; i < iir->nb_ab[0]; i++) {
480 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
482 mag = hypot(iir->ab[0][2 * i], iir->ab[0][2 * i + 1]);
490 for (i = 0; i < iir->nb_ab[1]; i++) {
491 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
494 if (iir->ab[0][2 * i ] == iir->ab[0][2 * outmost_pole.a ] &&
495 iir->ab[0][2 * i + 1] == -iir->ab[0][2 * outmost_pole.a + 1]) {
501 av_log(ctx, AV_LOG_VERBOSE, "outmost_pole is %d.%d\n", outmost_pole.a, outmost_pole.b);
503 if (outmost_pole.a < 0 || outmost_pole.b < 0)
504 return AVERROR(EINVAL);
506 for (i = 0; i < iir->nb_ab[1]; i++) {
509 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
511 distance = hypot(iir->ab[0][2 * outmost_pole.a ] - iir->ab[1][2 * i ],
512 iir->ab[0][2 * outmost_pole.a + 1] - iir->ab[1][2 * i + 1]);
514 if (distance < min_distance) {
515 min_distance = distance;
520 for (i = 0; i < iir->nb_ab[1]; i++) {
521 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
524 if (iir->ab[1][2 * i ] == iir->ab[1][2 * nearest_zero.a ] &&
525 iir->ab[1][2 * i + 1] == -iir->ab[1][2 * nearest_zero.a + 1]) {
531 av_log(ctx, AV_LOG_VERBOSE, "nearest_zero is %d.%d\n", nearest_zero.a, nearest_zero.b);
533 if (nearest_zero.a < 0 || nearest_zero.b < 0)
534 return AVERROR(EINVAL);
536 poles[0] = iir->ab[0][2 * outmost_pole.a ];
537 poles[1] = iir->ab[0][2 * outmost_pole.a + 1];
539 zeros[0] = iir->ab[1][2 * nearest_zero.a ];
540 zeros[1] = iir->ab[1][2 * nearest_zero.a + 1];
542 if (nearest_zero.a == nearest_zero.b && outmost_pole.a == outmost_pole.b) {
549 poles[2] = iir->ab[0][2 * outmost_pole.b ];
550 poles[3] = iir->ab[0][2 * outmost_pole.b + 1];
552 zeros[2] = iir->ab[1][2 * nearest_zero.b ];
553 zeros[3] = iir->ab[1][2 * nearest_zero.b + 1];
556 ret = expand(ctx, zeros, 2, b);
560 ret = expand(ctx, poles, 2, a);
564 iir->ab[0][2 * outmost_pole.a] = iir->ab[0][2 * outmost_pole.a + 1] = NAN;
565 iir->ab[0][2 * outmost_pole.b] = iir->ab[0][2 * outmost_pole.b + 1] = NAN;
566 iir->ab[1][2 * nearest_zero.a] = iir->ab[1][2 * nearest_zero.a + 1] = NAN;
567 iir->ab[1][2 * nearest_zero.b] = iir->ab[1][2 * nearest_zero.b + 1] = NAN;
569 iir->biquads[current_biquad].a0 = 1.0;
570 iir->biquads[current_biquad].a1 = a[2] / a[4];
571 iir->biquads[current_biquad].a2 = a[0] / a[4];
572 iir->biquads[current_biquad].b0 = b[4] / a[4] * (current_biquad ? 1.0 : iir->g);
573 iir->biquads[current_biquad].b1 = b[2] / a[4] * (current_biquad ? 1.0 : iir->g);
574 iir->biquads[current_biquad].b2 = b[0] / a[4] * (current_biquad ? 1.0 : iir->g);
576 av_log(ctx, AV_LOG_VERBOSE, "a=%lf %lf %lf:b=%lf %lf %lf\n",
577 iir->biquads[current_biquad].a0,
578 iir->biquads[current_biquad].a1,
579 iir->biquads[current_biquad].a2,
580 iir->biquads[current_biquad].b0,
581 iir->biquads[current_biquad].b1,
582 iir->biquads[current_biquad].b2);
591 static void convert_pr2zp(AVFilterContext *ctx, int channels)
593 AudioIIRContext *s = ctx->priv;
596 for (ch = 0; ch < channels; ch++) {
597 IIRChannel *iir = &s->iir[ch];
600 for (n = 0; n < iir->nb_ab[0]; n++) {
601 double r = iir->ab[0][2*n];
602 double angle = iir->ab[0][2*n+1];
604 iir->ab[0][2*n] = r * cos(angle);
605 iir->ab[0][2*n+1] = r * sin(angle);
608 for (n = 0; n < iir->nb_ab[1]; n++) {
609 double r = iir->ab[1][2*n];
610 double angle = iir->ab[1][2*n+1];
612 iir->ab[1][2*n] = r * cos(angle);
613 iir->ab[1][2*n+1] = r * sin(angle);
618 static void convert_pd2zp(AVFilterContext *ctx, int channels)
620 AudioIIRContext *s = ctx->priv;
623 for (ch = 0; ch < channels; ch++) {
624 IIRChannel *iir = &s->iir[ch];
627 for (n = 0; n < iir->nb_ab[0]; n++) {
628 double r = iir->ab[0][2*n];
629 double angle = M_PI*iir->ab[0][2*n+1]/180.;
631 iir->ab[0][2*n] = r * cos(angle);
632 iir->ab[0][2*n+1] = r * sin(angle);
635 for (n = 0; n < iir->nb_ab[1]; n++) {
636 double r = iir->ab[1][2*n];
637 double angle = M_PI*iir->ab[1][2*n+1]/180.;
639 iir->ab[1][2*n] = r * cos(angle);
640 iir->ab[1][2*n+1] = r * sin(angle);
645 static int config_output(AVFilterLink *outlink)
647 AVFilterContext *ctx = outlink->src;
648 AudioIIRContext *s = ctx->priv;
649 AVFilterLink *inlink = ctx->inputs[0];
652 s->channels = inlink->channels;
653 s->iir = av_calloc(s->channels, sizeof(*s->iir));
655 return AVERROR(ENOMEM);
657 ret = read_gains(ctx, s->g_str, inlink->channels);
661 ret = read_channels(ctx, inlink->channels, s->a_str, 0);
665 ret = read_channels(ctx, inlink->channels, s->b_str, 1);
669 if (s->format == 2) {
670 convert_pr2zp(ctx, inlink->channels);
671 } else if (s->format == 3) {
672 convert_pd2zp(ctx, inlink->channels);
676 av_log(ctx, AV_LOG_WARNING, "tf coefficients format is not recommended for too high number of zeros/poles.\n");
678 if (s->format > 0 && s->process == 0) {
679 av_log(ctx, AV_LOG_WARNING, "Direct processsing is not recommended for zp coefficients format.\n");
681 ret = convert_zp2tf(ctx, inlink->channels);
684 } else if (s->format == 0 && s->process == 1) {
685 av_log(ctx, AV_LOG_ERROR, "Serial cascading is not implemented for transfer function.\n");
686 return AVERROR_PATCHWELCOME;
687 } else if (s->format > 0 && s->process == 1) {
688 if (inlink->format == AV_SAMPLE_FMT_S16P)
689 av_log(ctx, AV_LOG_WARNING, "Serial cascading is not recommended for i16 precision.\n");
691 ret = decompose_zp2biquads(ctx, inlink->channels);
696 for (ch = 0; ch < inlink->channels; ch++) {
697 IIRChannel *iir = &s->iir[ch];
699 for (i = 1; i < iir->nb_ab[0]; i++) {
700 iir->ab[0][i] /= iir->ab[0][0];
703 for (i = 0; i < iir->nb_ab[1]; i++) {
704 iir->ab[1][i] *= iir->g / iir->ab[0][0];
708 switch (inlink->format) {
709 case AV_SAMPLE_FMT_DBLP: s->iir_channel = s->process == 1 ? iir_ch_serial_dblp : iir_ch_dblp; break;
710 case AV_SAMPLE_FMT_FLTP: s->iir_channel = s->process == 1 ? iir_ch_serial_fltp : iir_ch_fltp; break;
711 case AV_SAMPLE_FMT_S32P: s->iir_channel = s->process == 1 ? iir_ch_serial_s32p : iir_ch_s32p; break;
712 case AV_SAMPLE_FMT_S16P: s->iir_channel = s->process == 1 ? iir_ch_serial_s16p : iir_ch_s16p; break;
718 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
720 AVFilterContext *ctx = inlink->dst;
721 AudioIIRContext *s = ctx->priv;
722 AVFilterLink *outlink = ctx->outputs[0];
727 if (av_frame_is_writable(in)) {
730 out = ff_get_audio_buffer(outlink, in->nb_samples);
733 return AVERROR(ENOMEM);
735 av_frame_copy_props(out, in);
740 ctx->internal->execute(ctx, s->iir_channel, &td, NULL, outlink->channels);
742 for (ch = 0; ch < outlink->channels; ch++) {
743 if (s->iir[ch].clippings > 0)
744 av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
745 ch, s->iir[ch].clippings);
746 s->iir[ch].clippings = 0;
752 return ff_filter_frame(outlink, out);
755 static av_cold int init(AVFilterContext *ctx)
757 AudioIIRContext *s = ctx->priv;
759 if (!s->a_str || !s->b_str || !s->g_str) {
760 av_log(ctx, AV_LOG_ERROR, "Valid coefficients are mandatory.\n");
761 return AVERROR(EINVAL);
764 switch (s->precision) {
765 case 0: s->sample_format = AV_SAMPLE_FMT_DBLP; break;
766 case 1: s->sample_format = AV_SAMPLE_FMT_FLTP; break;
767 case 2: s->sample_format = AV_SAMPLE_FMT_S32P; break;
768 case 3: s->sample_format = AV_SAMPLE_FMT_S16P; break;
769 default: return AVERROR_BUG;
775 static av_cold void uninit(AVFilterContext *ctx)
777 AudioIIRContext *s = ctx->priv;
781 for (ch = 0; ch < s->channels; ch++) {
782 IIRChannel *iir = &s->iir[ch];
783 av_freep(&iir->ab[0]);
784 av_freep(&iir->ab[1]);
785 av_freep(&iir->cache[0]);
786 av_freep(&iir->cache[1]);
787 av_freep(&iir->biquads);
793 static const AVFilterPad inputs[] = {
796 .type = AVMEDIA_TYPE_AUDIO,
797 .filter_frame = filter_frame,
802 static const AVFilterPad outputs[] = {
805 .type = AVMEDIA_TYPE_AUDIO,
806 .config_props = config_output,
811 #define OFFSET(x) offsetof(AudioIIRContext, x)
812 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
814 static const AVOption aiir_options[] = {
815 { "z", "set B/numerator/zeros coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
816 { "p", "set A/denominator/poles coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
817 { "k", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF },
818 { "dry", "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
819 { "wet", "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
820 { "f", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, 0, 3, AF, "format" },
821 { "tf", "transfer function", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "format" },
822 { "zp", "Z-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "format" },
823 { "pr", "Z-plane zeros/poles (polar radians)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "format" },
824 { "pd", "Z-plane zeros/poles (polar degrees)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "format" },
825 { "r", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, AF, "process" },
826 { "d", "direct", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "process" },
827 { "s", "serial cascading", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "process" },
828 { "e", "set precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, "precision" },
829 { "dbl", "double-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision" },
830 { "flt", "single-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision" },
831 { "i32", "32-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision" },
832 { "i16", "16-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision" },
836 AVFILTER_DEFINE_CLASS(aiir);
838 AVFilter ff_af_aiir = {
840 .description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."),
841 .priv_size = sizeof(AudioIIRContext),
842 .priv_class = &aiir_class,
845 .query_formats = query_formats,
848 .flags = AVFILTER_FLAG_SLICE_THREADS,