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/intreadwrite.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/xga_font_data.h"
32 typedef struct ThreadData {
40 typedef struct BiquadContext {
46 typedef struct IIRChannel {
52 BiquadContext *biquads;
56 typedef struct AudioIIRContext {
58 char *a_str, *b_str, *g_str;
59 double dry_gain, wet_gain;
74 enum AVSampleFormat sample_format;
76 int (*iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs);
79 static int query_formats(AVFilterContext *ctx)
81 AudioIIRContext *s = ctx->priv;
82 AVFilterFormats *formats;
83 AVFilterChannelLayouts *layouts;
84 enum AVSampleFormat sample_fmts[] = {
88 static const enum AVPixelFormat pix_fmts[] = {
95 AVFilterLink *videolink = ctx->outputs[1];
97 formats = ff_make_format_list(pix_fmts);
98 if ((ret = ff_formats_ref(formats, &videolink->incfg.formats)) < 0)
102 layouts = ff_all_channel_counts();
104 return AVERROR(ENOMEM);
105 ret = ff_set_common_channel_layouts(ctx, layouts);
109 sample_fmts[0] = s->sample_format;
110 formats = ff_make_format_list(sample_fmts);
112 return AVERROR(ENOMEM);
113 ret = ff_set_common_formats(ctx, formats);
117 formats = ff_all_samplerates();
119 return AVERROR(ENOMEM);
120 return ff_set_common_samplerates(ctx, formats);
123 #define IIR_CH(name, type, min, max, need_clipping) \
124 static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
126 AudioIIRContext *s = ctx->priv; \
127 const double ig = s->dry_gain; \
128 const double og = s->wet_gain; \
129 const double mix = s->mix; \
130 ThreadData *td = arg; \
131 AVFrame *in = td->in, *out = td->out; \
132 const type *src = (const type *)in->extended_data[ch]; \
133 double *oc = (double *)s->iir[ch].cache[0]; \
134 double *ic = (double *)s->iir[ch].cache[1]; \
135 const int nb_a = s->iir[ch].nb_ab[0]; \
136 const int nb_b = s->iir[ch].nb_ab[1]; \
137 const double *a = s->iir[ch].ab[0]; \
138 const double *b = s->iir[ch].ab[1]; \
139 const double g = s->iir[ch].g; \
140 int *clippings = &s->iir[ch].clippings; \
141 type *dst = (type *)out->extended_data[ch]; \
144 for (n = 0; n < in->nb_samples; n++) { \
145 double sample = 0.; \
148 memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \
149 memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \
150 ic[0] = src[n] * ig; \
151 for (x = 0; x < nb_b; x++) \
152 sample += b[x] * ic[x]; \
154 for (x = 1; x < nb_a; x++) \
155 sample -= a[x] * oc[x]; \
159 sample = sample * mix + ic[0] * (1. - mix); \
160 if (need_clipping && sample < min) { \
163 } else if (need_clipping && sample > max) { \
174 IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
175 IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
176 IIR_CH(fltp, float, -1., 1., 0)
177 IIR_CH(dblp, double, -1., 1., 0)
179 #define SERIAL_IIR_CH(name, type, min, max, need_clipping) \
180 static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, \
181 int ch, int nb_jobs) \
183 AudioIIRContext *s = ctx->priv; \
184 const double ig = s->dry_gain; \
185 const double og = s->wet_gain; \
186 const double mix = s->mix; \
187 const double imix = 1. - mix; \
188 ThreadData *td = arg; \
189 AVFrame *in = td->in, *out = td->out; \
190 const type *src = (const type *)in->extended_data[ch]; \
191 type *dst = (type *)out->extended_data[ch]; \
192 IIRChannel *iir = &s->iir[ch]; \
193 const double g = iir->g; \
194 int *clippings = &iir->clippings; \
195 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
198 for (i = nb_biquads - 1; i >= 0; i--) { \
199 const double a1 = -iir->biquads[i].a[1]; \
200 const double a2 = -iir->biquads[i].a[2]; \
201 const double b0 = iir->biquads[i].b[0]; \
202 const double b1 = iir->biquads[i].b[1]; \
203 const double b2 = iir->biquads[i].b[2]; \
204 double w1 = iir->biquads[i].w1; \
205 double w2 = iir->biquads[i].w2; \
207 for (n = 0; n < in->nb_samples; n++) { \
208 double i0 = ig * (i ? dst[n] : src[n]); \
209 double o0 = i0 * b0 + w1; \
211 w1 = b1 * i0 + w2 + a1 * o0; \
212 w2 = b2 * i0 + a2 * o0; \
215 o0 = o0 * mix + imix * i0; \
216 if (need_clipping && o0 < min) { \
219 } else if (need_clipping && o0 > max) { \
226 iir->biquads[i].w1 = w1; \
227 iir->biquads[i].w2 = w2; \
233 SERIAL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
234 SERIAL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
235 SERIAL_IIR_CH(fltp, float, -1., 1., 0)
236 SERIAL_IIR_CH(dblp, double, -1., 1., 0)
238 #define PARALLEL_IIR_CH(name, type, min, max, need_clipping) \
239 static int iir_ch_parallel_## name(AVFilterContext *ctx, void *arg, \
240 int ch, int nb_jobs) \
242 AudioIIRContext *s = ctx->priv; \
243 const double ig = s->dry_gain; \
244 const double og = s->wet_gain; \
245 const double mix = s->mix; \
246 const double imix = 1. - mix; \
247 ThreadData *td = arg; \
248 AVFrame *in = td->in, *out = td->out; \
249 const type *src = (const type *)in->extended_data[ch]; \
250 type *dst = (type *)out->extended_data[ch]; \
251 IIRChannel *iir = &s->iir[ch]; \
252 const double g = iir->g; \
253 const double fir = iir->fir; \
254 int *clippings = &iir->clippings; \
255 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
258 for (i = 0; i < nb_biquads; i++) { \
259 const double a1 = -iir->biquads[i].a[1]; \
260 const double a2 = -iir->biquads[i].a[2]; \
261 const double b1 = iir->biquads[i].b[1]; \
262 const double b2 = iir->biquads[i].b[2]; \
263 double w1 = iir->biquads[i].w1; \
264 double w2 = iir->biquads[i].w2; \
266 for (n = 0; n < in->nb_samples; n++) { \
267 double i0 = ig * src[n]; \
270 w1 = b1 * i0 + w2 + a1 * o0; \
271 w2 = b2 * i0 + a2 * o0; \
275 if (need_clipping && o0 < min) { \
278 } else if (need_clipping && o0 > max) { \
285 iir->biquads[i].w1 = w1; \
286 iir->biquads[i].w2 = w2; \
289 for (n = 0; n < in->nb_samples; n++) { \
290 dst[n] += fir * src[n]; \
291 dst[n] = dst[n] * mix + imix * src[n]; \
297 PARALLEL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
298 PARALLEL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
299 PARALLEL_IIR_CH(fltp, float, -1., 1., 0)
300 PARALLEL_IIR_CH(dblp, double, -1., 1., 0)
302 static void count_coefficients(char *item_str, int *nb_items)
310 for (p = item_str; *p && *p != '|'; p++) {
316 static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items)
318 AudioIIRContext *s = ctx->priv;
319 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
322 p = old_str = av_strdup(item_str);
324 return AVERROR(ENOMEM);
325 for (i = 0; i < nb_items; i++) {
326 if (!(arg = av_strtok(p, "|", &saveptr)))
331 return AVERROR(EINVAL);
335 if (av_sscanf(arg, "%lf", &s->iir[i].g) != 1) {
336 av_log(ctx, AV_LOG_ERROR, "Invalid gains supplied: %s\n", arg);
338 return AVERROR(EINVAL);
349 static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst)
351 char *p, *arg, *old_str, *saveptr = NULL;
354 p = old_str = av_strdup(item_str);
356 return AVERROR(ENOMEM);
357 for (i = 0; i < nb_items; i++) {
358 if (!(arg = av_strtok(p, " ", &saveptr)))
362 if (av_sscanf(arg, "%lf", &dst[i]) != 1) {
363 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
365 return AVERROR(EINVAL);
374 static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
376 char *p, *arg, *old_str, *saveptr = NULL;
379 p = old_str = av_strdup(item_str);
381 return AVERROR(ENOMEM);
382 for (i = 0; i < nb_items; i++) {
383 if (!(arg = av_strtok(p, " ", &saveptr)))
387 if (av_sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2) {
388 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
390 return AVERROR(EINVAL);
399 static const char *format[] = { "%lf", "%lf %lfi", "%lf %lfr", "%lf %lfd", "%lf %lfi" };
401 static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab)
403 AudioIIRContext *s = ctx->priv;
404 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
407 p = old_str = av_strdup(item_str);
409 return AVERROR(ENOMEM);
410 for (i = 0; i < channels; i++) {
411 IIRChannel *iir = &s->iir[i];
413 if (!(arg = av_strtok(p, "|", &saveptr)))
418 return AVERROR(EINVAL);
421 count_coefficients(arg, &iir->nb_ab[ab]);
424 iir->cache[ab] = av_calloc(iir->nb_ab[ab] + 1, sizeof(double));
425 iir->ab[ab] = av_calloc(iir->nb_ab[ab] * (!!s->format + 1), sizeof(double));
426 if (!iir->ab[ab] || !iir->cache[ab]) {
428 return AVERROR(ENOMEM);
432 ret = read_zp_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab], format[s->format]);
434 ret = read_tf_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab]);
448 static void cmul(double re, double im, double re2, double im2, double *RE, double *IM)
450 *RE = re * re2 - im * im2;
451 *IM = re * im2 + re2 * im;
454 static int expand(AVFilterContext *ctx, double *pz, int n, double *coefs)
458 for (int i = 1; i <= n; i++) {
459 for (int j = n - i; j < n; j++) {
462 cmul(coefs[2 * (j + 1)], coefs[2 * (j + 1) + 1],
463 pz[2 * (i - 1)], pz[2 * (i - 1) + 1], &re, &im);
466 coefs[2 * j + 1] -= im;
470 for (int i = 0; i < n + 1; i++) {
471 if (fabs(coefs[2 * i + 1]) > FLT_EPSILON) {
472 av_log(ctx, AV_LOG_ERROR, "coefs: %f of z^%d is not real; poles/zeros are not complex conjugates.\n",
473 coefs[2 * i + 1], i);
474 return AVERROR(EINVAL);
481 static void normalize_coeffs(AVFilterContext *ctx, int ch)
483 AudioIIRContext *s = ctx->priv;
484 IIRChannel *iir = &s->iir[ch];
490 for (int i = 0; i < iir->nb_ab[1]; i++) {
491 sum_den += iir->ab[1][i];
494 if (sum_den > 1e-6) {
495 double factor, sum_num = 0.;
497 for (int i = 0; i < iir->nb_ab[0]; i++) {
498 sum_num += iir->ab[0][i];
501 factor = sum_num / sum_den;
503 for (int i = 0; i < iir->nb_ab[1]; i++) {
504 iir->ab[1][i] *= factor;
509 static int convert_zp2tf(AVFilterContext *ctx, int channels)
511 AudioIIRContext *s = ctx->priv;
512 int ch, i, j, ret = 0;
514 for (ch = 0; ch < channels; ch++) {
515 IIRChannel *iir = &s->iir[ch];
518 topc = av_calloc((iir->nb_ab[1] + 1) * 2, sizeof(*topc));
519 botc = av_calloc((iir->nb_ab[0] + 1) * 2, sizeof(*botc));
520 if (!topc || !botc) {
521 ret = AVERROR(ENOMEM);
525 ret = expand(ctx, iir->ab[0], iir->nb_ab[0], botc);
530 ret = expand(ctx, iir->ab[1], iir->nb_ab[1], topc);
535 for (j = 0, i = iir->nb_ab[1]; i >= 0; j++, i--) {
536 iir->ab[1][j] = topc[2 * i];
540 for (j = 0, i = iir->nb_ab[0]; i >= 0; j++, i--) {
541 iir->ab[0][j] = botc[2 * i];
545 normalize_coeffs(ctx, ch);
557 static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
559 AudioIIRContext *s = ctx->priv;
562 for (ch = 0; ch < channels; ch++) {
563 IIRChannel *iir = &s->iir[ch];
564 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2;
565 int current_biquad = 0;
567 iir->biquads = av_calloc(nb_biquads, sizeof(BiquadContext));
569 return AVERROR(ENOMEM);
571 while (nb_biquads--) {
572 Pair outmost_pole = { -1, -1 };
573 Pair nearest_zero = { -1, -1 };
574 double zeros[4] = { 0 };
575 double poles[4] = { 0 };
578 double min_distance = DBL_MAX;
583 for (i = 0; i < iir->nb_ab[0]; i++) {
586 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
588 mag = hypot(iir->ab[0][2 * i], iir->ab[0][2 * i + 1]);
596 for (i = 0; i < iir->nb_ab[0]; i++) {
597 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
600 if (iir->ab[0][2 * i ] == iir->ab[0][2 * outmost_pole.a ] &&
601 iir->ab[0][2 * i + 1] == -iir->ab[0][2 * outmost_pole.a + 1]) {
607 av_log(ctx, AV_LOG_VERBOSE, "outmost_pole is %d.%d\n", outmost_pole.a, outmost_pole.b);
609 if (outmost_pole.a < 0 || outmost_pole.b < 0)
610 return AVERROR(EINVAL);
612 for (i = 0; i < iir->nb_ab[1]; i++) {
615 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
617 distance = hypot(iir->ab[0][2 * outmost_pole.a ] - iir->ab[1][2 * i ],
618 iir->ab[0][2 * outmost_pole.a + 1] - iir->ab[1][2 * i + 1]);
620 if (distance < min_distance) {
621 min_distance = distance;
626 for (i = 0; i < iir->nb_ab[1]; i++) {
627 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
630 if (iir->ab[1][2 * i ] == iir->ab[1][2 * nearest_zero.a ] &&
631 iir->ab[1][2 * i + 1] == -iir->ab[1][2 * nearest_zero.a + 1]) {
637 av_log(ctx, AV_LOG_VERBOSE, "nearest_zero is %d.%d\n", nearest_zero.a, nearest_zero.b);
639 if (nearest_zero.a < 0 || nearest_zero.b < 0)
640 return AVERROR(EINVAL);
642 poles[0] = iir->ab[0][2 * outmost_pole.a ];
643 poles[1] = iir->ab[0][2 * outmost_pole.a + 1];
645 zeros[0] = iir->ab[1][2 * nearest_zero.a ];
646 zeros[1] = iir->ab[1][2 * nearest_zero.a + 1];
648 if (nearest_zero.a == nearest_zero.b && outmost_pole.a == outmost_pole.b) {
655 poles[2] = iir->ab[0][2 * outmost_pole.b ];
656 poles[3] = iir->ab[0][2 * outmost_pole.b + 1];
658 zeros[2] = iir->ab[1][2 * nearest_zero.b ];
659 zeros[3] = iir->ab[1][2 * nearest_zero.b + 1];
662 ret = expand(ctx, zeros, 2, b);
666 ret = expand(ctx, poles, 2, a);
670 iir->ab[0][2 * outmost_pole.a] = iir->ab[0][2 * outmost_pole.a + 1] = NAN;
671 iir->ab[0][2 * outmost_pole.b] = iir->ab[0][2 * outmost_pole.b + 1] = NAN;
672 iir->ab[1][2 * nearest_zero.a] = iir->ab[1][2 * nearest_zero.a + 1] = NAN;
673 iir->ab[1][2 * nearest_zero.b] = iir->ab[1][2 * nearest_zero.b + 1] = NAN;
675 iir->biquads[current_biquad].a[0] = 1.;
676 iir->biquads[current_biquad].a[1] = a[2] / a[4];
677 iir->biquads[current_biquad].a[2] = a[0] / a[4];
678 iir->biquads[current_biquad].b[0] = b[4] / a[4];
679 iir->biquads[current_biquad].b[1] = b[2] / a[4];
680 iir->biquads[current_biquad].b[2] = b[0] / a[4];
683 fabs(iir->biquads[current_biquad].b[0] +
684 iir->biquads[current_biquad].b[1] +
685 iir->biquads[current_biquad].b[2]) > 1e-6) {
686 factor = (iir->biquads[current_biquad].a[0] +
687 iir->biquads[current_biquad].a[1] +
688 iir->biquads[current_biquad].a[2]) /
689 (iir->biquads[current_biquad].b[0] +
690 iir->biquads[current_biquad].b[1] +
691 iir->biquads[current_biquad].b[2]);
693 av_log(ctx, AV_LOG_VERBOSE, "factor=%f\n", factor);
695 iir->biquads[current_biquad].b[0] *= factor;
696 iir->biquads[current_biquad].b[1] *= factor;
697 iir->biquads[current_biquad].b[2] *= factor;
700 iir->biquads[current_biquad].b[0] *= (current_biquad ? 1.0 : iir->g);
701 iir->biquads[current_biquad].b[1] *= (current_biquad ? 1.0 : iir->g);
702 iir->biquads[current_biquad].b[2] *= (current_biquad ? 1.0 : iir->g);
704 av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n",
705 iir->biquads[current_biquad].a[0],
706 iir->biquads[current_biquad].a[1],
707 iir->biquads[current_biquad].a[2],
708 iir->biquads[current_biquad].b[0],
709 iir->biquads[current_biquad].b[1],
710 iir->biquads[current_biquad].b[2]);
719 static void biquad_process(double *x, double *y, int length,
720 double b0, double b1, double b2,
721 double a1, double a2)
723 double w1 = 0., w2 = 0.;
728 for (int n = 0; n < length; n++) {
729 double out, in = x[n];
731 y[n] = out = in * b0 + w1;
732 w1 = b1 * in + w2 + a1 * out;
733 w2 = b2 * in + a2 * out;
737 static void solve(double *matrix, double *vector, int n, double *y, double *x, double *lu)
741 for (int i = 0; i < n; i++) {
742 for (int j = i; j < n; j++) {
744 for (int k = 0; k < i; k++)
745 sum += lu[i * n + k] * lu[k * n + j];
746 lu[i * n + j] = matrix[j * n + i] - sum;
748 for (int j = i + 1; j < n; j++) {
750 for (int k = 0; k < i; k++)
751 sum += lu[j * n + k] * lu[k * n + i];
752 lu[j * n + i] = (1. / lu[i * n + i]) * (matrix[i * n + j] - sum);
756 for (int i = 0; i < n; i++) {
758 for (int k = 0; k < i; k++)
759 sum += lu[i * n + k] * y[k];
760 y[i] = vector[i] - sum;
763 for (int i = n - 1; i >= 0; i--) {
765 for (int k = i + 1; k < n; k++)
766 sum += lu[i * n + k] * x[k];
767 x[i] = (1 / lu[i * n + i]) * (y[i] - sum);
771 static int convert_serial2parallel(AVFilterContext *ctx, int channels)
773 AudioIIRContext *s = ctx->priv;
776 for (int ch = 0; ch < channels; ch++) {
777 IIRChannel *iir = &s->iir[ch];
778 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2;
779 int length = nb_biquads * 2 + 1;
780 double *impulse = av_calloc(length, sizeof(*impulse));
781 double *y = av_calloc(length, sizeof(*y));
782 double *resp = av_calloc(length, sizeof(*resp));
783 double *M = av_calloc((length - 1) * 2 * nb_biquads, sizeof(*M));
784 double *W = av_calloc((length - 1) * 2 * nb_biquads, sizeof(*W));
786 if (!impulse || !y || !resp || !M) {
792 return AVERROR(ENOMEM);
797 for (int n = 0; n < nb_biquads; n++) {
798 BiquadContext *biquad = &iir->biquads[n];
800 biquad_process(n ? y : impulse, y, length,
801 biquad->b[0], biquad->b[1], biquad->b[2],
802 biquad->a[1], biquad->a[2]);
805 for (int n = 0; n < nb_biquads; n++) {
806 BiquadContext *biquad = &iir->biquads[n];
808 biquad_process(impulse, resp, length - 1,
809 1., 0., 0., biquad->a[1], biquad->a[2]);
811 memcpy(M + n * 2 * (length - 1), resp, sizeof(*resp) * (length - 1));
812 memcpy(M + n * 2 * (length - 1) + length, resp, sizeof(*resp) * (length - 2));
813 memset(resp, 0, length * sizeof(*resp));
816 solve(M, &y[1], length - 1, &impulse[1], resp, W);
820 for (int n = 0; n < nb_biquads; n++) {
821 BiquadContext *biquad = &iir->biquads[n];
824 biquad->b[1] = resp[n * 2 + 0];
825 biquad->b[2] = resp[n * 2 + 1];
841 static void convert_pr2zp(AVFilterContext *ctx, int channels)
843 AudioIIRContext *s = ctx->priv;
846 for (ch = 0; ch < channels; ch++) {
847 IIRChannel *iir = &s->iir[ch];
850 for (n = 0; n < iir->nb_ab[0]; n++) {
851 double r = iir->ab[0][2*n];
852 double angle = iir->ab[0][2*n+1];
854 iir->ab[0][2*n] = r * cos(angle);
855 iir->ab[0][2*n+1] = r * sin(angle);
858 for (n = 0; n < iir->nb_ab[1]; n++) {
859 double r = iir->ab[1][2*n];
860 double angle = iir->ab[1][2*n+1];
862 iir->ab[1][2*n] = r * cos(angle);
863 iir->ab[1][2*n+1] = r * sin(angle);
868 static void convert_sp2zp(AVFilterContext *ctx, int channels)
870 AudioIIRContext *s = ctx->priv;
873 for (ch = 0; ch < channels; ch++) {
874 IIRChannel *iir = &s->iir[ch];
877 for (n = 0; n < iir->nb_ab[0]; n++) {
878 double sr = iir->ab[0][2*n];
879 double si = iir->ab[0][2*n+1];
881 iir->ab[0][2*n] = exp(sr) * cos(si);
882 iir->ab[0][2*n+1] = exp(sr) * sin(si);
885 for (n = 0; n < iir->nb_ab[1]; n++) {
886 double sr = iir->ab[1][2*n];
887 double si = iir->ab[1][2*n+1];
889 iir->ab[1][2*n] = exp(sr) * cos(si);
890 iir->ab[1][2*n+1] = exp(sr) * sin(si);
895 static double fact(double i)
899 return i * fact(i - 1.);
902 static double coef_sf2zf(double *a, int N, int n)
906 for (int i = 0; i <= N; i++) {
909 for (int k = FFMAX(n - N + i, 0); k <= FFMIN(i, n); k++) {
910 acc += ((fact(i) * fact(N - i)) /
911 (fact(k) * fact(i - k) * fact(n - k) * fact(N - i - n + k))) *
912 ((k & 1) ? -1. : 1.);;
915 z += a[i] * pow(2., i) * acc;
921 static void convert_sf2tf(AVFilterContext *ctx, int channels)
923 AudioIIRContext *s = ctx->priv;
926 for (ch = 0; ch < channels; ch++) {
927 IIRChannel *iir = &s->iir[ch];
928 double *temp0 = av_calloc(iir->nb_ab[0], sizeof(*temp0));
929 double *temp1 = av_calloc(iir->nb_ab[1], sizeof(*temp1));
931 if (!temp0 || !temp1)
934 memcpy(temp0, iir->ab[0], iir->nb_ab[0] * sizeof(*temp0));
935 memcpy(temp1, iir->ab[1], iir->nb_ab[1] * sizeof(*temp1));
937 for (int n = 0; n < iir->nb_ab[0]; n++)
938 iir->ab[0][n] = coef_sf2zf(temp0, iir->nb_ab[0] - 1, n);
940 for (int n = 0; n < iir->nb_ab[1]; n++)
941 iir->ab[1][n] = coef_sf2zf(temp1, iir->nb_ab[1] - 1, n);
949 static void convert_pd2zp(AVFilterContext *ctx, int channels)
951 AudioIIRContext *s = ctx->priv;
954 for (ch = 0; ch < channels; ch++) {
955 IIRChannel *iir = &s->iir[ch];
958 for (n = 0; n < iir->nb_ab[0]; n++) {
959 double r = iir->ab[0][2*n];
960 double angle = M_PI*iir->ab[0][2*n+1]/180.;
962 iir->ab[0][2*n] = r * cos(angle);
963 iir->ab[0][2*n+1] = r * sin(angle);
966 for (n = 0; n < iir->nb_ab[1]; n++) {
967 double r = iir->ab[1][2*n];
968 double angle = M_PI*iir->ab[1][2*n+1]/180.;
970 iir->ab[1][2*n] = r * cos(angle);
971 iir->ab[1][2*n+1] = r * sin(angle);
976 static void check_stability(AVFilterContext *ctx, int channels)
978 AudioIIRContext *s = ctx->priv;
981 for (ch = 0; ch < channels; ch++) {
982 IIRChannel *iir = &s->iir[ch];
984 for (int n = 0; n < iir->nb_ab[0]; n++) {
985 double pr = hypot(iir->ab[0][2*n], iir->ab[0][2*n+1]);
988 av_log(ctx, AV_LOG_WARNING, "pole %d at channel %d is unstable\n", n, ch);
995 static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
1001 font = avpriv_cga_font, font_height = 8;
1003 for (i = 0; txt[i]; i++) {
1006 uint8_t *p = pic->data[0] + y * pic->linesize[0] + (x + i * 8) * 4;
1007 for (char_y = 0; char_y < font_height; char_y++) {
1008 for (mask = 0x80; mask; mask >>= 1) {
1009 if (font[txt[i] * font_height + char_y] & mask)
1013 p += pic->linesize[0] - 8 * 4;
1018 static void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t color)
1020 int dx = FFABS(x1-x0);
1021 int dy = FFABS(y1-y0), sy = y0 < y1 ? 1 : -1;
1022 int err = (dx>dy ? dx : -dy) / 2, e2;
1025 AV_WL32(out->data[0] + y0 * out->linesize[0] + x0 * 4, color);
1027 if (x0 == x1 && y0 == y1)
1044 static double distance(double x0, double x1, double y0, double y1)
1046 return hypot(x0 - x1, y0 - y1);
1049 static void get_response(int channel, int format, double w,
1050 const double *b, const double *a,
1051 int nb_b, int nb_a, double *magnitude, double *phase)
1053 double realz, realp;
1054 double imagz, imagp;
1059 realz = 0., realp = 0.;
1060 imagz = 0., imagp = 0.;
1061 for (int x = 0; x < nb_a; x++) {
1062 realz += cos(-x * w) * a[x];
1063 imagz += sin(-x * w) * a[x];
1066 for (int x = 0; x < nb_b; x++) {
1067 realp += cos(-x * w) * b[x];
1068 imagp += sin(-x * w) * b[x];
1071 div = realp * realp + imagp * imagp;
1072 real = (realz * realp + imagz * imagp) / div;
1073 imag = (imagz * realp - imagp * realz) / div;
1075 *magnitude = hypot(real, imag);
1076 *phase = atan2(imag, real);
1078 double p = 1., z = 1.;
1081 for (int x = 0; x < nb_a; x++) {
1082 z *= distance(cos(w), a[2 * x], sin(w), a[2 * x + 1]);
1083 acc += atan2(sin(w) - a[2 * x + 1], cos(w) - a[2 * x]);
1086 for (int x = 0; x < nb_b; x++) {
1087 p *= distance(cos(w), b[2 * x], sin(w), b[2 * x + 1]);
1088 acc -= atan2(sin(w) - b[2 * x + 1], cos(w) - b[2 * x]);
1096 static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate)
1098 AudioIIRContext *s = ctx->priv;
1099 double *mag, *phase, *temp, *delay, min = DBL_MAX, max = -DBL_MAX;
1100 double min_delay = DBL_MAX, max_delay = -DBL_MAX, min_phase, max_phase;
1101 int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
1105 memset(out->data[0], 0, s->h * out->linesize[0]);
1107 phase = av_malloc_array(s->w, sizeof(*phase));
1108 temp = av_malloc_array(s->w, sizeof(*temp));
1109 mag = av_malloc_array(s->w, sizeof(*mag));
1110 delay = av_malloc_array(s->w, sizeof(*delay));
1111 if (!mag || !phase || !delay || !temp)
1114 ch = av_clip(s->ir_channel, 0, s->channels - 1);
1115 for (i = 0; i < s->w; i++) {
1116 const double *b = s->iir[ch].ab[0];
1117 const double *a = s->iir[ch].ab[1];
1118 const int nb_b = s->iir[ch].nb_ab[0];
1119 const int nb_a = s->iir[ch].nb_ab[1];
1120 double w = i * M_PI / (s->w - 1);
1123 get_response(ch, s->format, w, b, a, nb_b, nb_a, &m, &p);
1125 mag[i] = s->iir[ch].g * m;
1127 min = fmin(min, mag[i]);
1128 max = fmax(max, mag[i]);
1132 for (i = 0; i < s->w - 1; i++) {
1133 double d = phase[i] - phase[i + 1];
1134 temp[i + 1] = ceil(fabs(d) / (2. * M_PI)) * 2. * M_PI * ((d > M_PI) - (d < -M_PI));
1137 min_phase = phase[0];
1138 max_phase = phase[0];
1139 for (i = 1; i < s->w; i++) {
1140 temp[i] += temp[i - 1];
1141 phase[i] += temp[i];
1142 min_phase = fmin(min_phase, phase[i]);
1143 max_phase = fmax(max_phase, phase[i]);
1146 for (i = 0; i < s->w - 1; i++) {
1147 double div = s->w / (double)sample_rate;
1149 delay[i + 1] = -(phase[i] - phase[i + 1]) / div;
1150 min_delay = fmin(min_delay, delay[i + 1]);
1151 max_delay = fmax(max_delay, delay[i + 1]);
1153 delay[0] = delay[1];
1155 for (i = 0; i < s->w; i++) {
1156 int ymag = mag[i] / max * (s->h - 1);
1157 int ydelay = (delay[i] - min_delay) / (max_delay - min_delay) * (s->h - 1);
1158 int yphase = (phase[i] - min_phase) / (max_phase - min_phase) * (s->h - 1);
1160 ymag = s->h - 1 - av_clip(ymag, 0, s->h - 1);
1161 yphase = s->h - 1 - av_clip(yphase, 0, s->h - 1);
1162 ydelay = s->h - 1 - av_clip(ydelay, 0, s->h - 1);
1166 if (prev_yphase < 0)
1167 prev_yphase = yphase;
1168 if (prev_ydelay < 0)
1169 prev_ydelay = ydelay;
1171 draw_line(out, i, ymag, FFMAX(i - 1, 0), prev_ymag, 0xFFFF00FF);
1172 draw_line(out, i, yphase, FFMAX(i - 1, 0), prev_yphase, 0xFF00FF00);
1173 draw_line(out, i, ydelay, FFMAX(i - 1, 0), prev_ydelay, 0xFF00FFFF);
1176 prev_yphase = yphase;
1177 prev_ydelay = ydelay;
1180 if (s->w > 400 && s->h > 100) {
1181 drawtext(out, 2, 2, "Max Magnitude:", 0xDDDDDDDD);
1182 snprintf(text, sizeof(text), "%.2f", max);
1183 drawtext(out, 15 * 8 + 2, 2, text, 0xDDDDDDDD);
1185 drawtext(out, 2, 12, "Min Magnitude:", 0xDDDDDDDD);
1186 snprintf(text, sizeof(text), "%.2f", min);
1187 drawtext(out, 15 * 8 + 2, 12, text, 0xDDDDDDDD);
1189 drawtext(out, 2, 22, "Max Phase:", 0xDDDDDDDD);
1190 snprintf(text, sizeof(text), "%.2f", max_phase);
1191 drawtext(out, 15 * 8 + 2, 22, text, 0xDDDDDDDD);
1193 drawtext(out, 2, 32, "Min Phase:", 0xDDDDDDDD);
1194 snprintf(text, sizeof(text), "%.2f", min_phase);
1195 drawtext(out, 15 * 8 + 2, 32, text, 0xDDDDDDDD);
1197 drawtext(out, 2, 42, "Max Delay:", 0xDDDDDDDD);
1198 snprintf(text, sizeof(text), "%.2f", max_delay);
1199 drawtext(out, 11 * 8 + 2, 42, text, 0xDDDDDDDD);
1201 drawtext(out, 2, 52, "Min Delay:", 0xDDDDDDDD);
1202 snprintf(text, sizeof(text), "%.2f", min_delay);
1203 drawtext(out, 11 * 8 + 2, 52, text, 0xDDDDDDDD);
1213 static int config_output(AVFilterLink *outlink)
1215 AVFilterContext *ctx = outlink->src;
1216 AudioIIRContext *s = ctx->priv;
1217 AVFilterLink *inlink = ctx->inputs[0];
1220 s->channels = inlink->channels;
1221 s->iir = av_calloc(s->channels, sizeof(*s->iir));
1223 return AVERROR(ENOMEM);
1225 ret = read_gains(ctx, s->g_str, inlink->channels);
1229 ret = read_channels(ctx, inlink->channels, s->a_str, 0);
1233 ret = read_channels(ctx, inlink->channels, s->b_str, 1);
1237 if (s->format == -1) {
1238 convert_sf2tf(ctx, inlink->channels);
1240 } else if (s->format == 2) {
1241 convert_pr2zp(ctx, inlink->channels);
1242 } else if (s->format == 3) {
1243 convert_pd2zp(ctx, inlink->channels);
1244 } else if (s->format == 4) {
1245 convert_sp2zp(ctx, inlink->channels);
1247 if (s->format > 0) {
1248 check_stability(ctx, inlink->channels);
1251 av_frame_free(&s->video);
1253 s->video = ff_get_video_buffer(ctx->outputs[1], s->w, s->h);
1255 return AVERROR(ENOMEM);
1257 draw_response(ctx, s->video, inlink->sample_rate);
1261 av_log(ctx, AV_LOG_WARNING, "transfer function coefficients format is not recommended for too high number of zeros/poles.\n");
1263 if (s->format > 0 && s->process == 0) {
1264 av_log(ctx, AV_LOG_WARNING, "Direct processsing is not recommended for zp coefficients format.\n");
1266 ret = convert_zp2tf(ctx, inlink->channels);
1269 } else if (s->format <= 0 && s->process == 1) {
1270 av_log(ctx, AV_LOG_ERROR, "Serial processing is not implemented for transfer function.\n");
1271 return AVERROR_PATCHWELCOME;
1272 } else if (s->format <= 0 && s->process == 2) {
1273 av_log(ctx, AV_LOG_ERROR, "Parallel processing is not implemented for transfer function.\n");
1274 return AVERROR_PATCHWELCOME;
1275 } else if (s->format > 0 && s->process == 1) {
1276 ret = decompose_zp2biquads(ctx, inlink->channels);
1279 } else if (s->format > 0 && s->process == 2) {
1280 if (s->precision > 1)
1281 av_log(ctx, AV_LOG_WARNING, "Parallel processing is not recommended for fixed-point precisions.\n");
1282 ret = decompose_zp2biquads(ctx, inlink->channels);
1285 ret = convert_serial2parallel(ctx, inlink->channels);
1290 for (ch = 0; s->format == 0 && ch < inlink->channels; ch++) {
1291 IIRChannel *iir = &s->iir[ch];
1293 for (i = 1; i < iir->nb_ab[0]; i++) {
1294 iir->ab[0][i] /= iir->ab[0][0];
1297 iir->ab[0][0] = 1.0;
1298 for (i = 0; i < iir->nb_ab[1]; i++) {
1299 iir->ab[1][i] *= iir->g;
1302 normalize_coeffs(ctx, ch);
1305 switch (inlink->format) {
1306 case AV_SAMPLE_FMT_DBLP: s->iir_channel = s->process == 2 ? iir_ch_parallel_dblp : s->process == 1 ? iir_ch_serial_dblp : iir_ch_dblp; break;
1307 case AV_SAMPLE_FMT_FLTP: s->iir_channel = s->process == 2 ? iir_ch_parallel_fltp : s->process == 1 ? iir_ch_serial_fltp : iir_ch_fltp; break;
1308 case AV_SAMPLE_FMT_S32P: s->iir_channel = s->process == 2 ? iir_ch_parallel_s32p : s->process == 1 ? iir_ch_serial_s32p : iir_ch_s32p; break;
1309 case AV_SAMPLE_FMT_S16P: s->iir_channel = s->process == 2 ? iir_ch_parallel_s16p : s->process == 1 ? iir_ch_serial_s16p : iir_ch_s16p; break;
1315 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
1317 AVFilterContext *ctx = inlink->dst;
1318 AudioIIRContext *s = ctx->priv;
1319 AVFilterLink *outlink = ctx->outputs[0];
1324 if (av_frame_is_writable(in) && s->process != 2) {
1327 out = ff_get_audio_buffer(outlink, in->nb_samples);
1330 return AVERROR(ENOMEM);
1332 av_frame_copy_props(out, in);
1337 ctx->internal->execute(ctx, s->iir_channel, &td, NULL, outlink->channels);
1339 for (ch = 0; ch < outlink->channels; ch++) {
1340 if (s->iir[ch].clippings > 0)
1341 av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
1342 ch, s->iir[ch].clippings);
1343 s->iir[ch].clippings = 0;
1350 AVFilterLink *outlink = ctx->outputs[1];
1351 int64_t old_pts = s->video->pts;
1352 int64_t new_pts = av_rescale_q(out->pts, ctx->inputs[0]->time_base, outlink->time_base);
1354 if (new_pts > old_pts) {
1357 s->video->pts = new_pts;
1358 clone = av_frame_clone(s->video);
1360 return AVERROR(ENOMEM);
1361 ret = ff_filter_frame(outlink, clone);
1367 return ff_filter_frame(outlink, out);
1370 static int config_video(AVFilterLink *outlink)
1372 AVFilterContext *ctx = outlink->src;
1373 AudioIIRContext *s = ctx->priv;
1375 outlink->sample_aspect_ratio = (AVRational){1,1};
1378 outlink->frame_rate = s->rate;
1379 outlink->time_base = av_inv_q(outlink->frame_rate);
1384 static av_cold int init(AVFilterContext *ctx)
1386 AudioIIRContext *s = ctx->priv;
1387 AVFilterPad pad, vpad;
1390 if (!s->a_str || !s->b_str || !s->g_str) {
1391 av_log(ctx, AV_LOG_ERROR, "Valid coefficients are mandatory.\n");
1392 return AVERROR(EINVAL);
1395 switch (s->precision) {
1396 case 0: s->sample_format = AV_SAMPLE_FMT_DBLP; break;
1397 case 1: s->sample_format = AV_SAMPLE_FMT_FLTP; break;
1398 case 2: s->sample_format = AV_SAMPLE_FMT_S32P; break;
1399 case 3: s->sample_format = AV_SAMPLE_FMT_S16P; break;
1400 default: return AVERROR_BUG;
1403 pad = (AVFilterPad){
1405 .type = AVMEDIA_TYPE_AUDIO,
1406 .config_props = config_output,
1409 ret = ff_insert_outpad(ctx, 0, &pad);
1414 vpad = (AVFilterPad){
1415 .name = "filter_response",
1416 .type = AVMEDIA_TYPE_VIDEO,
1417 .config_props = config_video,
1420 ret = ff_insert_outpad(ctx, 1, &vpad);
1428 static av_cold void uninit(AVFilterContext *ctx)
1430 AudioIIRContext *s = ctx->priv;
1434 for (ch = 0; ch < s->channels; ch++) {
1435 IIRChannel *iir = &s->iir[ch];
1436 av_freep(&iir->ab[0]);
1437 av_freep(&iir->ab[1]);
1438 av_freep(&iir->cache[0]);
1439 av_freep(&iir->cache[1]);
1440 av_freep(&iir->biquads);
1445 av_frame_free(&s->video);
1448 static const AVFilterPad inputs[] = {
1451 .type = AVMEDIA_TYPE_AUDIO,
1452 .filter_frame = filter_frame,
1457 #define OFFSET(x) offsetof(AudioIIRContext, x)
1458 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1459 #define VF AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1461 static const AVOption aiir_options[] = {
1462 { "zeros", "set B/numerator/zeros coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1463 { "z", "set B/numerator/zeros coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1464 { "poles", "set A/denominator/poles coefficients", OFFSET(a_str),AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1465 { "p", "set A/denominator/poles coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1466 { "gains", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF },
1467 { "k", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF },
1468 { "dry", "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1469 { "wet", "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1470 { "format", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, -1, 4, AF, "format" },
1471 { "f", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, -1, 4, AF, "format" },
1472 { "sf", "analog transfer function", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, "format" },
1473 { "tf", "digital transfer function", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "format" },
1474 { "zp", "Z-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "format" },
1475 { "pr", "Z-plane zeros/poles (polar radians)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "format" },
1476 { "pd", "Z-plane zeros/poles (polar degrees)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "format" },
1477 { "sp", "S-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "format" },
1478 { "process", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, "process" },
1479 { "r", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, "process" },
1480 { "d", "direct", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "process" },
1481 { "s", "serial", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "process" },
1482 { "p", "parallel", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "process" },
1483 { "precision", "set filtering precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, "precision" },
1484 { "e", "set precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, "precision" },
1485 { "dbl", "double-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "precision" },
1486 { "flt", "single-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "precision" },
1487 { "i32", "32-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "precision" },
1488 { "i16", "16-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "precision" },
1489 { "normalize", "normalize coefficients", OFFSET(normalize),AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AF },
1490 { "n", "normalize coefficients", OFFSET(normalize),AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AF },
1491 { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1492 { "response", "show IR frequency response", OFFSET(response), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, VF },
1493 { "channel", "set IR channel to display frequency response", OFFSET(ir_channel), AV_OPT_TYPE_INT, {.i64=0}, 0, 1024, VF },
1494 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "hd720"}, 0, 0, VF },
1495 { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT32_MAX, VF },
1499 AVFILTER_DEFINE_CLASS(aiir);
1501 AVFilter ff_af_aiir = {
1503 .description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."),
1504 .priv_size = sizeof(AudioIIRContext),
1505 .priv_class = &aiir_class,
1508 .query_formats = query_formats,
1510 .flags = AVFILTER_FLAG_DYNAMIC_OUTPUTS |
1511 AVFILTER_FLAG_SLICE_THREADS,