FFmpeg
Loading...
Searching...
No Matches
af_aiir.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Paul B Mahol
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <float.h>
22
23#include "libavutil/avstring.h"
25#include "libavutil/mem.h"
26#include "libavutil/opt.h"
28#include "audio.h"
29#include "avfilter.h"
30#include "filters.h"
31#include "formats.h"
32#include "video.h"
33
34typedef struct ThreadData {
35 AVFrame *in, *out;
37
38typedef struct Pair {
39 int a, b;
40} Pair;
41
42typedef struct BiquadContext {
43 double a[3];
44 double b[3];
45 double w1, w2;
47
48typedef struct IIRChannel {
49 int nb_ab[2];
50 double *ab[2];
51 double g;
52 double *cache[2];
53 double fir;
57
58typedef struct AudioIIRContext {
59 const AVClass *class;
60 char *a_str, *b_str, *g_str;
62 double mix;
64 int format;
68 int w, h;
71
73
77
78 int (*iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs);
80
82 AVFilterFormatsConfig **cfg_in,
83 AVFilterFormatsConfig **cfg_out)
84{
85 const AudioIIRContext *s = ctx->priv;
90 };
91 static const enum AVPixelFormat pix_fmts[] = {
94 };
95 int ret;
96
97 if (s->response) {
99 if ((ret = ff_formats_ref(formats, &cfg_out[1]->formats)) < 0)
100 return ret;
101 }
102
103 sample_fmts[0] = s->sample_format;
104 ret = ff_set_sample_formats_from_list2(ctx, cfg_in, cfg_out, sample_fmts);
105 if (ret < 0)
106 return ret;
107
108 return 0;
109}
110
111#define IIR_CH(name, type, min, max, need_clipping) \
112static int iir_ch_## name(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) \
113{ \
114 AudioIIRContext *s = ctx->priv; \
115 const double ig = s->dry_gain; \
116 const double og = s->wet_gain; \
117 const double mix = s->mix; \
118 ThreadData *td = arg; \
119 AVFrame *in = td->in, *out = td->out; \
120 const type *src = (const type *)in->extended_data[ch]; \
121 double *oc = (double *)s->iir[ch].cache[0]; \
122 double *ic = (double *)s->iir[ch].cache[1]; \
123 const int nb_a = s->iir[ch].nb_ab[0]; \
124 const int nb_b = s->iir[ch].nb_ab[1]; \
125 const double *a = s->iir[ch].ab[0]; \
126 const double *b = s->iir[ch].ab[1]; \
127 const double g = s->iir[ch].g; \
128 int *clippings = &s->iir[ch].clippings; \
129 type *dst = (type *)out->extended_data[ch]; \
130 int n; \
131 \
132 for (n = 0; n < in->nb_samples; n++) { \
133 double sample = 0.; \
134 int x; \
135 \
136 memmove(&ic[1], &ic[0], (nb_b - 1) * sizeof(*ic)); \
137 memmove(&oc[1], &oc[0], (nb_a - 1) * sizeof(*oc)); \
138 ic[0] = src[n] * ig; \
139 for (x = 0; x < nb_b; x++) \
140 sample += b[x] * ic[x]; \
141 \
142 for (x = 1; x < nb_a; x++) \
143 sample -= a[x] * oc[x]; \
144 \
145 oc[0] = sample; \
146 sample *= og * g; \
147 sample = sample * mix + ic[0] * (1. - mix); \
148 if (need_clipping && sample < min) { \
149 (*clippings)++; \
150 dst[n] = min; \
151 } else if (need_clipping && sample > max) { \
152 (*clippings)++; \
153 dst[n] = max; \
154 } else { \
155 dst[n] = sample; \
156 } \
157 } \
158 \
159 return 0; \
160}
161
162IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
163IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
164IIR_CH(fltp, float, -1., 1., 0)
165IIR_CH(dblp, double, -1., 1., 0)
166
167#define SERIAL_IIR_CH(name, type, min, max, need_clipping) \
168static int iir_ch_serial_## name(AVFilterContext *ctx, void *arg, \
169 int ch, int nb_jobs) \
170{ \
171 AudioIIRContext *s = ctx->priv; \
172 const double ig = s->dry_gain; \
173 const double og = s->wet_gain; \
174 const double mix = s->mix; \
175 const double imix = 1. - mix; \
176 ThreadData *td = arg; \
177 AVFrame *in = td->in, *out = td->out; \
178 const type *src = (const type *)in->extended_data[ch]; \
179 type *dst = (type *)out->extended_data[ch]; \
180 IIRChannel *iir = &s->iir[ch]; \
181 const double g = iir->g; \
182 int *clippings = &iir->clippings; \
183 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
184 int n, i; \
185 \
186 for (i = nb_biquads - 1; i >= 0; i--) { \
187 const double a1 = -iir->biquads[i].a[1]; \
188 const double a2 = -iir->biquads[i].a[2]; \
189 const double b0 = iir->biquads[i].b[0]; \
190 const double b1 = iir->biquads[i].b[1]; \
191 const double b2 = iir->biquads[i].b[2]; \
192 double w1 = iir->biquads[i].w1; \
193 double w2 = iir->biquads[i].w2; \
194 \
195 for (n = 0; n < in->nb_samples; n++) { \
196 double i0 = ig * (i ? dst[n] : src[n]); \
197 double o0 = i0 * b0 + w1; \
198 \
199 w1 = b1 * i0 + w2 + a1 * o0; \
200 w2 = b2 * i0 + a2 * o0; \
201 o0 *= og * g; \
202 \
203 o0 = o0 * mix + imix * i0; \
204 if (need_clipping && o0 < min) { \
205 (*clippings)++; \
206 dst[n] = min; \
207 } else if (need_clipping && o0 > max) { \
208 (*clippings)++; \
209 dst[n] = max; \
210 } else { \
211 dst[n] = o0; \
212 } \
213 } \
214 iir->biquads[i].w1 = w1; \
215 iir->biquads[i].w2 = w2; \
216 } \
217 \
218 return 0; \
219}
220
221SERIAL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
222SERIAL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
223SERIAL_IIR_CH(fltp, float, -1., 1., 0)
224SERIAL_IIR_CH(dblp, double, -1., 1., 0)
225
226#define PARALLEL_IIR_CH(name, type, min, max, need_clipping) \
227static int iir_ch_parallel_## name(AVFilterContext *ctx, void *arg, \
228 int ch, int nb_jobs) \
229{ \
230 AudioIIRContext *s = ctx->priv; \
231 const double ig = s->dry_gain; \
232 const double og = s->wet_gain; \
233 const double mix = s->mix; \
234 const double imix = 1. - mix; \
235 ThreadData *td = arg; \
236 AVFrame *in = td->in, *out = td->out; \
237 const type *src = (const type *)in->extended_data[ch]; \
238 type *dst = (type *)out->extended_data[ch]; \
239 IIRChannel *iir = &s->iir[ch]; \
240 const double g = iir->g; \
241 const double fir = iir->fir; \
242 int *clippings = &iir->clippings; \
243 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2; \
244 int n, i; \
245 \
246 for (i = 0; i < nb_biquads; i++) { \
247 const double a1 = -iir->biquads[i].a[1]; \
248 const double a2 = -iir->biquads[i].a[2]; \
249 const double b1 = iir->biquads[i].b[1]; \
250 const double b2 = iir->biquads[i].b[2]; \
251 double w1 = iir->biquads[i].w1; \
252 double w2 = iir->biquads[i].w2; \
253 \
254 for (n = 0; n < in->nb_samples; n++) { \
255 double i0 = ig * src[n]; \
256 double o0 = w1; \
257 \
258 w1 = b1 * i0 + w2 + a1 * o0; \
259 w2 = b2 * i0 + a2 * o0; \
260 o0 *= og * g; \
261 o0 += dst[n]; \
262 \
263 if (need_clipping && o0 < min) { \
264 (*clippings)++; \
265 dst[n] = min; \
266 } else if (need_clipping && o0 > max) { \
267 (*clippings)++; \
268 dst[n] = max; \
269 } else { \
270 dst[n] = o0; \
271 } \
272 } \
273 iir->biquads[i].w1 = w1; \
274 iir->biquads[i].w2 = w2; \
275 } \
276 \
277 for (n = 0; n < in->nb_samples; n++) { \
278 dst[n] += fir * src[n]; \
279 dst[n] = dst[n] * mix + imix * src[n]; \
280 } \
281 \
282 return 0; \
283}
284
285PARALLEL_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
286PARALLEL_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
287PARALLEL_IIR_CH(fltp, float, -1., 1., 0)
288PARALLEL_IIR_CH(dblp, double, -1., 1., 0)
289
290#define LATTICE_IIR_CH(name, type, min, max, need_clipping) \
291static int iir_ch_lattice_## name(AVFilterContext *ctx, void *arg, \
292 int ch, int nb_jobs) \
293{ \
294 AudioIIRContext *s = ctx->priv; \
295 const double ig = s->dry_gain; \
296 const double og = s->wet_gain; \
297 const double mix = s->mix; \
298 ThreadData *td = arg; \
299 AVFrame *in = td->in, *out = td->out; \
300 const type *src = (const type *)in->extended_data[ch]; \
301 double n0, n1, p0, *x = (double *)s->iir[ch].cache[0]; \
302 const int nb_stages = s->iir[ch].nb_ab[1]; \
303 const double *v = s->iir[ch].ab[0]; \
304 const double *k = s->iir[ch].ab[1]; \
305 const double g = s->iir[ch].g; \
306 int *clippings = &s->iir[ch].clippings; \
307 type *dst = (type *)out->extended_data[ch]; \
308 int n; \
309 \
310 for (n = 0; n < in->nb_samples; n++) { \
311 const double in = src[n] * ig; \
312 double out = 0.; \
313 \
314 n1 = in; \
315 for (int i = nb_stages - 1; i >= 0; i--) { \
316 n0 = n1 - k[i] * x[i]; \
317 p0 = n0 * k[i] + x[i]; \
318 out += p0 * v[i+1]; \
319 x[i] = p0; \
320 n1 = n0; \
321 } \
322 \
323 out += n1 * v[0]; \
324 memmove(&x[1], &x[0], nb_stages * sizeof(*x)); \
325 x[0] = n1; \
326 out *= og * g; \
327 out = out * mix + in * (1. - mix); \
328 if (need_clipping && out < min) { \
329 (*clippings)++; \
330 dst[n] = min; \
331 } else if (need_clipping && out > max) { \
332 (*clippings)++; \
333 dst[n] = max; \
334 } else { \
335 dst[n] = out; \
336 } \
337 } \
338 \
339 return 0; \
340}
341
342LATTICE_IIR_CH(s16p, int16_t, INT16_MIN, INT16_MAX, 1)
343LATTICE_IIR_CH(s32p, int32_t, INT32_MIN, INT32_MAX, 1)
344LATTICE_IIR_CH(fltp, float, -1., 1., 0)
345LATTICE_IIR_CH(dblp, double, -1., 1., 0)
346
347static void count_coefficients(char *item_str, int *nb_items)
348{
349 char *p;
350
351 if (!item_str)
352 return;
353
354 *nb_items = 1;
355 for (p = item_str; *p && *p != '|'; p++) {
356 if (*p == ' ')
357 (*nb_items)++;
358 }
359}
360
361static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items)
362{
363 AudioIIRContext *s = ctx->priv;
364 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
365 int i;
366
367 p = old_str = av_strdup(item_str);
368 if (!p)
369 return AVERROR(ENOMEM);
370 for (i = 0; i < nb_items; i++) {
371 if (!(arg = av_strtok(p, "|", &saveptr)))
372 arg = prev_arg;
373
374 if (!arg) {
375 av_freep(&old_str);
376 return AVERROR(EINVAL);
377 }
378
379 p = NULL;
380 if (av_sscanf(arg, "%lf", &s->iir[i].g) != 1 || !isfinite(s->iir[i].g)) {
381 av_log(ctx, AV_LOG_ERROR, "Invalid gains supplied: %s\n", arg);
382 av_freep(&old_str);
383 return AVERROR(EINVAL);
384 }
385
386 prev_arg = arg;
387 }
388
389 av_freep(&old_str);
390
391 return 0;
392}
393
394static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst)
395{
396 char *p, *arg, *old_str, *saveptr = NULL;
397 int i;
398
399 p = old_str = av_strdup(item_str);
400 if (!p)
401 return AVERROR(ENOMEM);
402 for (i = 0; i < nb_items; i++) {
403 if (!(arg = av_strtok(p, " ", &saveptr)))
404 break;
405
406 p = NULL;
407 if (av_sscanf(arg, "%lf", &dst[i]) != 1 || !isfinite(dst[i])) {
408 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
409 av_freep(&old_str);
410 return AVERROR(EINVAL);
411 }
412 }
413
414 av_freep(&old_str);
415
416 return 0;
417}
418
419static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
420{
421 char *p, *arg, *old_str, *saveptr = NULL;
422 int i;
423
424 p = old_str = av_strdup(item_str);
425 if (!p)
426 return AVERROR(ENOMEM);
427 for (i = 0; i < nb_items; i++) {
428 if (!(arg = av_strtok(p, " ", &saveptr)))
429 break;
430
431 p = NULL;
432 if (av_sscanf(arg, format, &dst[i*2], &dst[i*2+1]) != 2 ||
433 !isfinite(dst[i*2]) || !isfinite(dst[i*2+1])) {
434 av_log(ctx, AV_LOG_ERROR, "Invalid coefficients supplied: %s\n", arg);
435 av_freep(&old_str);
436 return AVERROR(EINVAL);
437 }
438 }
439
440 av_freep(&old_str);
441
442 return 0;
443}
444
445static const char *const format[] = { "%lf", "%lf %lfi", "%lf %lfr", "%lf %lfd", "%lf %lfi" };
446
447static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab)
448{
449 AudioIIRContext *s = ctx->priv;
450 char *p, *arg, *old_str, *prev_arg = NULL, *saveptr = NULL;
451 int i, ret;
452
453 p = old_str = av_strdup(item_str);
454 if (!p)
455 return AVERROR(ENOMEM);
456 for (i = 0; i < channels; i++) {
457 IIRChannel *iir = &s->iir[i];
458
459 if (!(arg = av_strtok(p, "|", &saveptr)))
460 arg = prev_arg;
461
462 if (!arg) {
463 av_freep(&old_str);
464 return AVERROR(EINVAL);
465 }
466
467 count_coefficients(arg, &iir->nb_ab[ab]);
468
469 p = NULL;
470 iir->cache[ab] = av_calloc(iir->nb_ab[ab] + 1, sizeof(double));
471 iir->ab[ab] = av_calloc(iir->nb_ab[ab] * (!!s->format + 1), sizeof(double));
472 if (!iir->ab[ab] || !iir->cache[ab]) {
473 av_freep(&old_str);
474 return AVERROR(ENOMEM);
475 }
476
477 if (s->format > 0) {
478 ret = read_zp_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab], format[s->format]);
479 } else {
480 ret = read_tf_coefficients(ctx, arg, iir->nb_ab[ab], iir->ab[ab]);
481 }
482 if (ret < 0) {
483 av_freep(&old_str);
484 return ret;
485 }
486 prev_arg = arg;
487 }
488
489 av_freep(&old_str);
490
491 return 0;
492}
493
494static void cmul(double re, double im, double re2, double im2, double *RE, double *IM)
495{
496 *RE = re * re2 - im * im2;
497 *IM = re * im2 + re2 * im;
498}
499
500static int expand(AVFilterContext *ctx, double *pz, int n, double *coefs)
501{
502 coefs[2 * n] = 1.0;
503
504 for (int i = 1; i <= n; i++) {
505 for (int j = n - i; j < n; j++) {
506 double re, im;
507
508 cmul(coefs[2 * (j + 1)], coefs[2 * (j + 1) + 1],
509 pz[2 * (i - 1)], pz[2 * (i - 1) + 1], &re, &im);
510
511 coefs[2 * j] -= re;
512 coefs[2 * j + 1] -= im;
513 }
514 }
515
516 for (int i = 0; i < n + 1; i++) {
517 if (fabs(coefs[2 * i + 1]) > FLT_EPSILON) {
518 av_log(ctx, AV_LOG_ERROR, "coefs: %f of z^%d is not real; poles/zeros are not complex conjugates.\n",
519 coefs[2 * i + 1], i);
520 return AVERROR(EINVAL);
521 }
522 }
523
524 return 0;
525}
526
528{
529 AudioIIRContext *s = ctx->priv;
530 IIRChannel *iir = &s->iir[ch];
531 double sum_den = 0.;
532
533 if (!s->normalize)
534 return;
535
536 for (int i = 0; i < iir->nb_ab[1]; i++) {
537 sum_den += iir->ab[1][i];
538 }
539
540 if (sum_den > 1e-6) {
541 double factor, sum_num = 0.;
542
543 for (int i = 0; i < iir->nb_ab[0]; i++) {
544 sum_num += iir->ab[0][i];
545 }
546
547 factor = sum_num / sum_den;
548
549 for (int i = 0; i < iir->nb_ab[1]; i++) {
550 iir->ab[1][i] *= factor;
551 }
552 }
553}
554
556{
557 AudioIIRContext *s = ctx->priv;
558 int ch, i, j, ret = 0;
559
560 for (ch = 0; ch < channels; ch++) {
561 IIRChannel *iir = &s->iir[ch];
562 double *topc, *botc;
563
564 topc = av_calloc((iir->nb_ab[1] + 1) * 2, sizeof(*topc));
565 botc = av_calloc((iir->nb_ab[0] + 1) * 2, sizeof(*botc));
566 if (!topc || !botc) {
567 ret = AVERROR(ENOMEM);
568 goto fail;
569 }
570
571 ret = expand(ctx, iir->ab[0], iir->nb_ab[0], botc);
572 if (ret < 0) {
573 goto fail;
574 }
575
576 ret = expand(ctx, iir->ab[1], iir->nb_ab[1], topc);
577 if (ret < 0) {
578 goto fail;
579 }
580
581 for (j = 0, i = iir->nb_ab[1]; i >= 0; j++, i--) {
582 iir->ab[1][j] = topc[2 * i];
583 }
584 iir->nb_ab[1]++;
585
586 for (j = 0, i = iir->nb_ab[0]; i >= 0; j++, i--) {
587 iir->ab[0][j] = botc[2 * i];
588 }
589 iir->nb_ab[0]++;
590
592
593fail:
594 av_free(topc);
595 av_free(botc);
596 if (ret < 0)
597 break;
598 }
599
600 return ret;
601}
602
604{
605 AudioIIRContext *s = ctx->priv;
606 int ch, ret;
607
608 for (ch = 0; ch < channels; ch++) {
609 IIRChannel *iir = &s->iir[ch];
610 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2;
611 int current_biquad = 0;
612
613 iir->biquads = av_calloc(nb_biquads, sizeof(BiquadContext));
614 if (!iir->biquads)
615 return AVERROR(ENOMEM);
616
617 while (nb_biquads--) {
618 Pair outmost_pole = { -1, -1 };
619 Pair nearest_zero = { -1, -1 };
620 double zeros[4] = { 0 };
621 double poles[4] = { 0 };
622 double b[6] = { 0 };
623 double a[6] = { 0 };
624 double min_distance = DBL_MAX;
625 double max_mag = 0;
626 double factor;
627 int i;
628
629 for (i = 0; i < iir->nb_ab[0]; i++) {
630 double mag;
631
632 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
633 continue;
634 mag = hypot(iir->ab[0][2 * i], iir->ab[0][2 * i + 1]);
635
636 if (mag > max_mag) {
637 max_mag = mag;
638 outmost_pole.a = i;
639 }
640 }
641
642 for (i = 0; i < iir->nb_ab[0]; i++) {
643 if (isnan(iir->ab[0][2 * i]) || isnan(iir->ab[0][2 * i + 1]))
644 continue;
645
646 if (iir->ab[0][2 * i ] == iir->ab[0][2 * outmost_pole.a ] &&
647 iir->ab[0][2 * i + 1] == -iir->ab[0][2 * outmost_pole.a + 1]) {
648 outmost_pole.b = i;
649 break;
650 }
651 }
652
653 av_log(ctx, AV_LOG_VERBOSE, "outmost_pole is %d.%d\n", outmost_pole.a, outmost_pole.b);
654
655 if (outmost_pole.a < 0 || outmost_pole.b < 0)
656 return AVERROR(EINVAL);
657
658 for (i = 0; i < iir->nb_ab[1]; i++) {
659 double distance;
660
661 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
662 continue;
663 distance = hypot(iir->ab[0][2 * outmost_pole.a ] - iir->ab[1][2 * i ],
664 iir->ab[0][2 * outmost_pole.a + 1] - iir->ab[1][2 * i + 1]);
665
666 if (distance < min_distance) {
667 min_distance = distance;
668 nearest_zero.a = i;
669 }
670 }
671
672 for (i = 0; i < iir->nb_ab[1]; i++) {
673 if (isnan(iir->ab[1][2 * i]) || isnan(iir->ab[1][2 * i + 1]))
674 continue;
675
676 if (iir->ab[1][2 * i ] == iir->ab[1][2 * nearest_zero.a ] &&
677 iir->ab[1][2 * i + 1] == -iir->ab[1][2 * nearest_zero.a + 1]) {
678 nearest_zero.b = i;
679 break;
680 }
681 }
682
683 av_log(ctx, AV_LOG_VERBOSE, "nearest_zero is %d.%d\n", nearest_zero.a, nearest_zero.b);
684
685 if (nearest_zero.a < 0 || nearest_zero.b < 0)
686 return AVERROR(EINVAL);
687
688 poles[0] = iir->ab[0][2 * outmost_pole.a ];
689 poles[1] = iir->ab[0][2 * outmost_pole.a + 1];
690
691 zeros[0] = iir->ab[1][2 * nearest_zero.a ];
692 zeros[1] = iir->ab[1][2 * nearest_zero.a + 1];
693
694 if (nearest_zero.a == nearest_zero.b && outmost_pole.a == outmost_pole.b) {
695 zeros[2] = 0;
696 zeros[3] = 0;
697
698 poles[2] = 0;
699 poles[3] = 0;
700 } else {
701 poles[2] = iir->ab[0][2 * outmost_pole.b ];
702 poles[3] = iir->ab[0][2 * outmost_pole.b + 1];
703
704 zeros[2] = iir->ab[1][2 * nearest_zero.b ];
705 zeros[3] = iir->ab[1][2 * nearest_zero.b + 1];
706 }
707
708 ret = expand(ctx, zeros, 2, b);
709 if (ret < 0)
710 return ret;
711
712 ret = expand(ctx, poles, 2, a);
713 if (ret < 0)
714 return ret;
715
716 iir->ab[0][2 * outmost_pole.a] = iir->ab[0][2 * outmost_pole.a + 1] = NAN;
717 iir->ab[0][2 * outmost_pole.b] = iir->ab[0][2 * outmost_pole.b + 1] = NAN;
718 iir->ab[1][2 * nearest_zero.a] = iir->ab[1][2 * nearest_zero.a + 1] = NAN;
719 iir->ab[1][2 * nearest_zero.b] = iir->ab[1][2 * nearest_zero.b + 1] = NAN;
720
721 iir->biquads[current_biquad].a[0] = 1.;
722 iir->biquads[current_biquad].a[1] = a[2] / a[4];
723 iir->biquads[current_biquad].a[2] = a[0] / a[4];
724 iir->biquads[current_biquad].b[0] = b[4] / a[4];
725 iir->biquads[current_biquad].b[1] = b[2] / a[4];
726 iir->biquads[current_biquad].b[2] = b[0] / a[4];
727
728 if (s->normalize &&
729 fabs(iir->biquads[current_biquad].b[0] +
730 iir->biquads[current_biquad].b[1] +
731 iir->biquads[current_biquad].b[2]) > 1e-6) {
732 factor = (iir->biquads[current_biquad].a[0] +
733 iir->biquads[current_biquad].a[1] +
734 iir->biquads[current_biquad].a[2]) /
735 (iir->biquads[current_biquad].b[0] +
736 iir->biquads[current_biquad].b[1] +
737 iir->biquads[current_biquad].b[2]);
738
739 av_log(ctx, AV_LOG_VERBOSE, "factor=%f\n", factor);
740
741 iir->biquads[current_biquad].b[0] *= factor;
742 iir->biquads[current_biquad].b[1] *= factor;
743 iir->biquads[current_biquad].b[2] *= factor;
744 }
745
746 iir->biquads[current_biquad].b[0] *= (current_biquad ? 1.0 : iir->g);
747 iir->biquads[current_biquad].b[1] *= (current_biquad ? 1.0 : iir->g);
748 iir->biquads[current_biquad].b[2] *= (current_biquad ? 1.0 : iir->g);
749
750 av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n",
751 iir->biquads[current_biquad].a[0],
752 iir->biquads[current_biquad].a[1],
753 iir->biquads[current_biquad].a[2],
754 iir->biquads[current_biquad].b[0],
755 iir->biquads[current_biquad].b[1],
756 iir->biquads[current_biquad].b[2]);
757
758 current_biquad++;
759 }
760 }
761
762 return 0;
763}
764
765static void biquad_process(double *x, double *y, int length,
766 double b0, double b1, double b2,
767 double a1, double a2)
768{
769 double w1 = 0., w2 = 0.;
770
771 a1 = -a1;
772 a2 = -a2;
773
774 for (int n = 0; n < length; n++) {
775 double out, in = x[n];
776
777 y[n] = out = in * b0 + w1;
778 w1 = b1 * in + w2 + a1 * out;
779 w2 = b2 * in + a2 * out;
780 }
781}
782
783static void solve(double *matrix, double *vector, int n, double *y, double *x, double *lu)
784{
785 double sum = 0.;
786
787 for (int i = 0; i < n; i++) {
788 for (int j = i; j < n; j++) {
789 sum = 0.;
790 for (int k = 0; k < i; k++)
791 sum += lu[i * n + k] * lu[k * n + j];
792 lu[i * n + j] = matrix[j * n + i] - sum;
793 }
794 for (int j = i + 1; j < n; j++) {
795 sum = 0.;
796 for (int k = 0; k < i; k++)
797 sum += lu[j * n + k] * lu[k * n + i];
798 lu[j * n + i] = (1. / lu[i * n + i]) * (matrix[i * n + j] - sum);
799 }
800 }
801
802 for (int i = 0; i < n; i++) {
803 sum = 0.;
804 for (int k = 0; k < i; k++)
805 sum += lu[i * n + k] * y[k];
806 y[i] = vector[i] - sum;
807 }
808
809 for (int i = n - 1; i >= 0; i--) {
810 sum = 0.;
811 for (int k = i + 1; k < n; k++)
812 sum += lu[i * n + k] * x[k];
813 x[i] = (1 / lu[i * n + i]) * (y[i] - sum);
814 }
815}
816
818{
819 AudioIIRContext *s = ctx->priv;
820
821 for (int ch = 0; ch < channels; ch++) {
822 IIRChannel *iir = &s->iir[ch];
823 int nb_biquads = (FFMAX(iir->nb_ab[0], iir->nb_ab[1]) + 1) / 2;
824 int length = nb_biquads * 2 + 1;
825 double *impulse = av_calloc(length, sizeof(*impulse));
826 double *y = av_calloc(length, sizeof(*y));
827 double *resp = av_calloc(length, sizeof(*resp));
828 double *M = av_calloc((length - 1) * nb_biquads, 2 * 2 * sizeof(*M));
829 double *W;
830
831 if (!impulse || !y || !resp || !M) {
832 av_free(impulse);
833 av_free(y);
834 av_free(resp);
835 av_free(M);
836 return AVERROR(ENOMEM);
837 }
838 W = M + (length - 1) * 2 * nb_biquads;
839
840 impulse[0] = 1.;
841
842 for (int n = 0; n < nb_biquads; n++) {
843 BiquadContext *biquad = &iir->biquads[n];
844
845 biquad_process(n ? y : impulse, y, length,
846 biquad->b[0], biquad->b[1], biquad->b[2],
847 biquad->a[1], biquad->a[2]);
848 }
849
850 for (int n = 0; n < nb_biquads; n++) {
851 BiquadContext *biquad = &iir->biquads[n];
852
853 biquad_process(impulse, resp, length - 1,
854 1., 0., 0., biquad->a[1], biquad->a[2]);
855
856 memcpy(M + n * 2 * (length - 1), resp, sizeof(*resp) * (length - 1));
857 memcpy(M + n * 2 * (length - 1) + length, resp, sizeof(*resp) * (length - 2));
858 memset(resp, 0, length * sizeof(*resp));
859 }
860
861 solve(M, &y[1], length - 1, &impulse[1], resp, W);
862
863 iir->fir = y[0];
864
865 for (int n = 0; n < nb_biquads; n++) {
866 BiquadContext *biquad = &iir->biquads[n];
867
868 biquad->b[0] = 0.;
869 biquad->b[1] = resp[n * 2 + 0];
870 biquad->b[2] = resp[n * 2 + 1];
871 }
872
873 av_free(impulse);
874 av_free(y);
875 av_free(resp);
876 av_free(M);
877 }
878
879 return 0;
880}
881
883{
884 AudioIIRContext *s = ctx->priv;
885 int ch;
886
887 for (ch = 0; ch < channels; ch++) {
888 IIRChannel *iir = &s->iir[ch];
889 int n;
890
891 for (n = 0; n < iir->nb_ab[0]; n++) {
892 double r = iir->ab[0][2*n];
893 double angle = iir->ab[0][2*n+1];
894
895 iir->ab[0][2*n] = r * cos(angle);
896 iir->ab[0][2*n+1] = r * sin(angle);
897 }
898
899 for (n = 0; n < iir->nb_ab[1]; n++) {
900 double r = iir->ab[1][2*n];
901 double angle = iir->ab[1][2*n+1];
902
903 iir->ab[1][2*n] = r * cos(angle);
904 iir->ab[1][2*n+1] = r * sin(angle);
905 }
906 }
907}
908
910{
911 AudioIIRContext *s = ctx->priv;
912 int ch;
913
914 for (ch = 0; ch < channels; ch++) {
915 IIRChannel *iir = &s->iir[ch];
916 int n;
917
918 for (n = 0; n < iir->nb_ab[0]; n++) {
919 double sr = iir->ab[0][2*n];
920 double si = iir->ab[0][2*n+1];
921
922 iir->ab[0][2*n] = exp(sr) * cos(si);
923 iir->ab[0][2*n+1] = exp(sr) * sin(si);
924 }
925
926 for (n = 0; n < iir->nb_ab[1]; n++) {
927 double sr = iir->ab[1][2*n];
928 double si = iir->ab[1][2*n+1];
929
930 iir->ab[1][2*n] = exp(sr) * cos(si);
931 iir->ab[1][2*n+1] = exp(sr) * sin(si);
932 }
933 }
934}
935
936static double fact(double i)
937{
938 if (i <= 0.)
939 return 1.;
940 return i * fact(i - 1.);
941}
942
943static double coef_sf2zf(double *a, int N, int n)
944{
945 double z = 0.;
946
947 for (int i = 0; i <= N; i++) {
948 double acc = 0.;
949
950 for (int k = FFMAX(n - N + i, 0); k <= FFMIN(i, n); k++) {
951 acc += ((fact(i) * fact(N - i)) /
952 (fact(k) * fact(i - k) * fact(n - k) * fact(N - i - n + k))) *
953 ((k & 1) ? -1. : 1.);
954 }
955
956 z += a[i] * pow(2., i) * acc;
957 }
958
959 return z;
960}
961
963{
964 AudioIIRContext *s = ctx->priv;
965 int ch;
966
967 for (ch = 0; ch < channels; ch++) {
968 IIRChannel *iir = &s->iir[ch];
969 double *temp0 = av_calloc(iir->nb_ab[0], sizeof(*temp0));
970 double *temp1 = av_calloc(iir->nb_ab[1], sizeof(*temp1));
971
972 if (!temp0 || !temp1)
973 goto next;
974
975 memcpy(temp0, iir->ab[0], iir->nb_ab[0] * sizeof(*temp0));
976 memcpy(temp1, iir->ab[1], iir->nb_ab[1] * sizeof(*temp1));
977
978 for (int n = 0; n < iir->nb_ab[0]; n++)
979 iir->ab[0][n] = coef_sf2zf(temp0, iir->nb_ab[0] - 1, n);
980
981 for (int n = 0; n < iir->nb_ab[1]; n++)
982 iir->ab[1][n] = coef_sf2zf(temp1, iir->nb_ab[1] - 1, n);
983
984next:
985 av_free(temp0);
986 av_free(temp1);
987 }
988}
989
991{
992 AudioIIRContext *s = ctx->priv;
993 int ch;
994
995 for (ch = 0; ch < channels; ch++) {
996 IIRChannel *iir = &s->iir[ch];
997 int n;
998
999 for (n = 0; n < iir->nb_ab[0]; n++) {
1000 double r = iir->ab[0][2*n];
1001 double angle = M_PI*iir->ab[0][2*n+1]/180.;
1002
1003 iir->ab[0][2*n] = r * cos(angle);
1004 iir->ab[0][2*n+1] = r * sin(angle);
1005 }
1006
1007 for (n = 0; n < iir->nb_ab[1]; n++) {
1008 double r = iir->ab[1][2*n];
1009 double angle = M_PI*iir->ab[1][2*n+1]/180.;
1010
1011 iir->ab[1][2*n] = r * cos(angle);
1012 iir->ab[1][2*n+1] = r * sin(angle);
1013 }
1014 }
1015}
1016
1018{
1019 AudioIIRContext *s = ctx->priv;
1020 int ch;
1021
1022 for (ch = 0; ch < channels; ch++) {
1023 IIRChannel *iir = &s->iir[ch];
1024
1025 for (int n = 0; n < iir->nb_ab[0]; n++) {
1026 double pr = hypot(iir->ab[0][2*n], iir->ab[0][2*n+1]);
1027
1028 if (pr >= 1.) {
1029 av_log(ctx, AV_LOG_WARNING, "pole %d at channel %d is unstable\n", n, ch);
1030 break;
1031 }
1032 }
1033 }
1034}
1035
1036static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
1037{
1038 const uint8_t *font;
1039 int font_height;
1040 int i;
1041
1042 font = avpriv_cga_font_get(), font_height = 8;
1043
1044 for (i = 0; txt[i]; i++) {
1045 int char_y, mask;
1046
1047 uint8_t *p = pic->data[0] + y * pic->linesize[0] + (x + i * 8) * 4;
1048 for (char_y = 0; char_y < font_height; char_y++) {
1049 for (mask = 0x80; mask; mask >>= 1) {
1050 if (font[txt[i] * font_height + char_y] & mask)
1051 AV_WL32(p, color);
1052 p += 4;
1053 }
1054 p += pic->linesize[0] - 8 * 4;
1055 }
1056 }
1057}
1058
1059static void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t color)
1060{
1061 int dx = FFABS(x1-x0);
1062 int dy = FFABS(y1-y0), sy = y0 < y1 ? 1 : -1;
1063 int err = (dx>dy ? dx : -dy) / 2, e2;
1064
1065 for (;;) {
1066 AV_WL32(out->data[0] + y0 * out->linesize[0] + x0 * 4, color);
1067
1068 if (x0 == x1 && y0 == y1)
1069 break;
1070
1071 e2 = err;
1072
1073 if (e2 >-dx) {
1074 err -= dy;
1075 x0--;
1076 }
1077
1078 if (e2 < dy) {
1079 err += dx;
1080 y0 += sy;
1081 }
1082 }
1083}
1084
1085static double distance(double x0, double x1, double y0, double y1)
1086{
1087 return hypot(x0 - x1, y0 - y1);
1088}
1089
1090static void get_response(int channel, int format, double w,
1091 const double *b, const double *a,
1092 int nb_b, int nb_a, double *magnitude, double *phase)
1093{
1094 double realz, realp;
1095 double imagz, imagp;
1096 double real, imag;
1097 double div;
1098
1099 if (format == 0) {
1100 realz = 0., realp = 0.;
1101 imagz = 0., imagp = 0.;
1102 for (int x = 0; x < nb_a; x++) {
1103 realz += cos(-x * w) * a[x];
1104 imagz += sin(-x * w) * a[x];
1105 }
1106
1107 for (int x = 0; x < nb_b; x++) {
1108 realp += cos(-x * w) * b[x];
1109 imagp += sin(-x * w) * b[x];
1110 }
1111
1112 div = realp * realp + imagp * imagp;
1113 real = (realz * realp + imagz * imagp) / div;
1114 imag = (imagz * realp - imagp * realz) / div;
1115
1116 *magnitude = hypot(real, imag);
1117 *phase = atan2(imag, real);
1118 } else {
1119 double p = 1., z = 1.;
1120 double acc = 0.;
1121
1122 for (int x = 0; x < nb_a; x++) {
1123 z *= distance(cos(w), a[2 * x], sin(w), a[2 * x + 1]);
1124 acc += atan2(sin(w) - a[2 * x + 1], cos(w) - a[2 * x]);
1125 }
1126
1127 for (int x = 0; x < nb_b; x++) {
1128 p *= distance(cos(w), b[2 * x], sin(w), b[2 * x + 1]);
1129 acc -= atan2(sin(w) - b[2 * x + 1], cos(w) - b[2 * x]);
1130 }
1131
1132 *magnitude = z / p;
1133 *phase = acc;
1134 }
1135}
1136
1137static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate)
1138{
1139 AudioIIRContext *s = ctx->priv;
1140 double *mag, *phase, *temp, *delay, min = DBL_MAX, max = -DBL_MAX;
1141 double min_delay = DBL_MAX, max_delay = -DBL_MAX, min_phase, max_phase;
1142 int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
1143 char text[32];
1144 int ch, i;
1145
1146 memset(out->data[0], 0, s->h * out->linesize[0]);
1147
1148 phase = av_malloc_array(s->w, sizeof(*phase));
1149 temp = av_malloc_array(s->w, sizeof(*temp));
1150 mag = av_malloc_array(s->w, sizeof(*mag));
1151 delay = av_malloc_array(s->w, sizeof(*delay));
1152 if (!mag || !phase || !delay || !temp)
1153 goto end;
1154
1155 ch = av_clip(s->ir_channel, 0, s->channels - 1);
1156 for (i = 0; i < s->w; i++) {
1157 const double *b = s->iir[ch].ab[0];
1158 const double *a = s->iir[ch].ab[1];
1159 const int nb_b = s->iir[ch].nb_ab[0];
1160 const int nb_a = s->iir[ch].nb_ab[1];
1161 double w = i * M_PI / (s->w - 1);
1162 double m, p;
1163
1164 get_response(ch, s->format, w, b, a, nb_b, nb_a, &m, &p);
1165
1166 mag[i] = s->iir[ch].g * m;
1167 phase[i] = p;
1168 min = fmin(min, mag[i]);
1169 max = fmax(max, mag[i]);
1170 }
1171
1172 temp[0] = 0.;
1173 for (i = 0; i < s->w - 1; i++) {
1174 double d = phase[i] - phase[i + 1];
1175 temp[i + 1] = ceil(fabs(d) / (2. * M_PI)) * 2. * M_PI * ((d > M_PI) - (d < -M_PI));
1176 }
1177
1178 min_phase = phase[0];
1179 max_phase = phase[0];
1180 for (i = 1; i < s->w; i++) {
1181 temp[i] += temp[i - 1];
1182 phase[i] += temp[i];
1183 min_phase = fmin(min_phase, phase[i]);
1184 max_phase = fmax(max_phase, phase[i]);
1185 }
1186
1187 for (i = 0; i < s->w - 1; i++) {
1188 double div = s->w / (double)sample_rate;
1189
1190 delay[i + 1] = -(phase[i] - phase[i + 1]) / div;
1191 min_delay = fmin(min_delay, delay[i + 1]);
1192 max_delay = fmax(max_delay, delay[i + 1]);
1193 }
1194 delay[0] = delay[1];
1195
1196 for (i = 0; i < s->w; i++) {
1197 int ymag = mag[i] / max * (s->h - 1);
1198 int ydelay = (delay[i] - min_delay) / (max_delay - min_delay) * (s->h - 1);
1199 int yphase = (phase[i] - min_phase) / (max_phase - min_phase) * (s->h - 1);
1200
1201 ymag = s->h - 1 - av_clip(ymag, 0, s->h - 1);
1202 yphase = s->h - 1 - av_clip(yphase, 0, s->h - 1);
1203 ydelay = s->h - 1 - av_clip(ydelay, 0, s->h - 1);
1204
1205 if (prev_ymag < 0)
1206 prev_ymag = ymag;
1207 if (prev_yphase < 0)
1208 prev_yphase = yphase;
1209 if (prev_ydelay < 0)
1210 prev_ydelay = ydelay;
1211
1212 draw_line(out, i, ymag, FFMAX(i - 1, 0), prev_ymag, 0xFFFF00FF);
1213 draw_line(out, i, yphase, FFMAX(i - 1, 0), prev_yphase, 0xFF00FF00);
1214 draw_line(out, i, ydelay, FFMAX(i - 1, 0), prev_ydelay, 0xFF00FFFF);
1215
1216 prev_ymag = ymag;
1217 prev_yphase = yphase;
1218 prev_ydelay = ydelay;
1219 }
1220
1221 if (s->w > 400 && s->h > 100) {
1222 drawtext(out, 2, 2, "Max Magnitude:", 0xDDDDDDDD);
1223 snprintf(text, sizeof(text), "%.2f", max);
1224 drawtext(out, 15 * 8 + 2, 2, text, 0xDDDDDDDD);
1225
1226 drawtext(out, 2, 12, "Min Magnitude:", 0xDDDDDDDD);
1227 snprintf(text, sizeof(text), "%.2f", min);
1228 drawtext(out, 15 * 8 + 2, 12, text, 0xDDDDDDDD);
1229
1230 drawtext(out, 2, 22, "Max Phase:", 0xDDDDDDDD);
1231 snprintf(text, sizeof(text), "%.2f", max_phase);
1232 drawtext(out, 15 * 8 + 2, 22, text, 0xDDDDDDDD);
1233
1234 drawtext(out, 2, 32, "Min Phase:", 0xDDDDDDDD);
1235 snprintf(text, sizeof(text), "%.2f", min_phase);
1236 drawtext(out, 15 * 8 + 2, 32, text, 0xDDDDDDDD);
1237
1238 drawtext(out, 2, 42, "Max Delay:", 0xDDDDDDDD);
1239 snprintf(text, sizeof(text), "%.2f", max_delay);
1240 drawtext(out, 11 * 8 + 2, 42, text, 0xDDDDDDDD);
1241
1242 drawtext(out, 2, 52, "Min Delay:", 0xDDDDDDDD);
1243 snprintf(text, sizeof(text), "%.2f", min_delay);
1244 drawtext(out, 11 * 8 + 2, 52, text, 0xDDDDDDDD);
1245 }
1246
1247end:
1248 av_free(delay);
1249 av_free(temp);
1250 av_free(phase);
1251 av_free(mag);
1252}
1253
1254static int config_output(AVFilterLink *outlink)
1255{
1256 AVFilterContext *ctx = outlink->src;
1257 AudioIIRContext *s = ctx->priv;
1258 AVFilterLink *inlink = ctx->inputs[0];
1259 int ch, ret, i;
1260
1261 s->channels = inlink->ch_layout.nb_channels;
1262 s->iir = av_calloc(s->channels, sizeof(*s->iir));
1263 if (!s->iir)
1264 return AVERROR(ENOMEM);
1265
1266 ret = read_gains(ctx, s->g_str, inlink->ch_layout.nb_channels);
1267 if (ret < 0)
1268 return ret;
1269
1270 ret = read_channels(ctx, inlink->ch_layout.nb_channels, s->a_str, 0);
1271 if (ret < 0)
1272 return ret;
1273
1274 ret = read_channels(ctx, inlink->ch_layout.nb_channels, s->b_str, 1);
1275 if (ret < 0)
1276 return ret;
1277
1278 if (s->format == -1) {
1280 s->format = 0;
1281 } else if (s->format == 2) {
1283 } else if (s->format == 3) {
1285 } else if (s->format == 4) {
1287 }
1288 if (s->format > 0) {
1290 }
1291
1292 av_frame_free(&s->video);
1293 if (s->response) {
1294 s->video = ff_get_video_buffer(ctx->outputs[1], s->w, s->h);
1295 if (!s->video)
1296 return AVERROR(ENOMEM);
1297
1298 draw_response(ctx, s->video, inlink->sample_rate);
1299 }
1300
1301 if (s->format == 0)
1302 av_log(ctx, AV_LOG_WARNING, "transfer function coefficients format is not recommended for too high number of zeros/poles.\n");
1303
1304 if (s->format > 0 && s->process == 0) {
1305 av_log(ctx, AV_LOG_WARNING, "Direct processing is not recommended for zp coefficients format.\n");
1306
1307 ret = convert_zp2tf(ctx, inlink->ch_layout.nb_channels);
1308 if (ret < 0)
1309 return ret;
1310 } else if (s->format == -2 && s->process > 0) {
1311 av_log(ctx, AV_LOG_ERROR, "Only direct processing is implemented for lattice-ladder function.\n");
1312 return AVERROR_PATCHWELCOME;
1313 } else if (s->format <= 0 && s->process == 1) {
1314 av_log(ctx, AV_LOG_ERROR, "Serial processing is not implemented for transfer function.\n");
1315 return AVERROR_PATCHWELCOME;
1316 } else if (s->format <= 0 && s->process == 2) {
1317 av_log(ctx, AV_LOG_ERROR, "Parallel processing is not implemented for transfer function.\n");
1318 return AVERROR_PATCHWELCOME;
1319 } else if (s->format > 0 && s->process == 1) {
1321 if (ret < 0)
1322 return ret;
1323 } else if (s->format > 0 && s->process == 2) {
1324 if (s->precision > 1)
1325 av_log(ctx, AV_LOG_WARNING, "Parallel processing is not recommended for fixed-point precisions.\n");
1327 if (ret < 0)
1328 return ret;
1330 if (ret < 0)
1331 return ret;
1332 }
1333
1334 for (ch = 0; s->format == -2 && ch < inlink->ch_layout.nb_channels; ch++) {
1335 IIRChannel *iir = &s->iir[ch];
1336
1337 if (iir->nb_ab[0] != iir->nb_ab[1] + 1) {
1338 av_log(ctx, AV_LOG_ERROR, "Number of ladder coefficients must be one more than number of reflection coefficients.\n");
1339 return AVERROR(EINVAL);
1340 }
1341 }
1342
1343 for (ch = 0; s->format == 0 && ch < inlink->ch_layout.nb_channels; ch++) {
1344 IIRChannel *iir = &s->iir[ch];
1345
1346 for (i = 1; i < iir->nb_ab[0]; i++) {
1347 iir->ab[0][i] /= iir->ab[0][0];
1348 }
1349
1350 iir->ab[0][0] = 1.0;
1351 for (i = 0; i < iir->nb_ab[1]; i++) {
1352 iir->ab[1][i] *= iir->g;
1353 }
1354
1355 normalize_coeffs(ctx, ch);
1356 }
1357
1358 switch (inlink->format) {
1359 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;
1360 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;
1361 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;
1362 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;
1363 }
1364
1365 if (s->format == -2) {
1366 switch (inlink->format) {
1367 case AV_SAMPLE_FMT_DBLP: s->iir_channel = iir_ch_lattice_dblp; break;
1368 case AV_SAMPLE_FMT_FLTP: s->iir_channel = iir_ch_lattice_fltp; break;
1369 case AV_SAMPLE_FMT_S32P: s->iir_channel = iir_ch_lattice_s32p; break;
1370 case AV_SAMPLE_FMT_S16P: s->iir_channel = iir_ch_lattice_s16p; break;
1371 }
1372 }
1373
1374 return 0;
1375}
1376
1377static int filter_frame(AVFilterLink *inlink, AVFrame *in)
1378{
1379 AVFilterContext *ctx = inlink->dst;
1380 AudioIIRContext *s = ctx->priv;
1381 AVFilterLink *outlink = ctx->outputs[0];
1382 ThreadData td;
1383 AVFrame *out;
1384 int ch, ret;
1385
1386 if (av_frame_is_writable(in) && s->process != 2) {
1387 out = in;
1388 } else {
1389 out = ff_get_audio_buffer(outlink, in->nb_samples);
1390 if (!out) {
1391 av_frame_free(&in);
1392 return AVERROR(ENOMEM);
1393 }
1395 }
1396
1397 td.in = in;
1398 td.out = out;
1399 ff_filter_execute(ctx, s->iir_channel, &td, NULL, outlink->ch_layout.nb_channels);
1400
1401 for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) {
1402 if (s->iir[ch].clippings > 0)
1403 av_log(ctx, AV_LOG_WARNING, "Channel %d clipping %d times. Please reduce gain.\n",
1404 ch, s->iir[ch].clippings);
1405 s->iir[ch].clippings = 0;
1406 }
1407
1408 if (in != out)
1409 av_frame_free(&in);
1410
1411 if (s->response) {
1412 AVFilterLink *outlink = ctx->outputs[1];
1413 int64_t old_pts = s->video->pts;
1414 int64_t new_pts = av_rescale_q(out->pts, ctx->inputs[0]->time_base, outlink->time_base);
1415
1416 if (new_pts > old_pts) {
1417 AVFrame *clone;
1418
1419 s->video->pts = new_pts;
1420 clone = av_frame_clone(s->video);
1421 if (!clone)
1422 return AVERROR(ENOMEM);
1423 ret = ff_filter_frame(outlink, clone);
1424 if (ret < 0)
1425 return ret;
1426 }
1427 }
1428
1429 return ff_filter_frame(outlink, out);
1430}
1431
1432static int config_video(AVFilterLink *outlink)
1433{
1434 FilterLink *l = ff_filter_link(outlink);
1435 AVFilterContext *ctx = outlink->src;
1436 AudioIIRContext *s = ctx->priv;
1437
1438 outlink->sample_aspect_ratio = (AVRational){1,1};
1439 outlink->w = s->w;
1440 outlink->h = s->h;
1441 l->frame_rate = s->rate;
1442 outlink->time_base = av_inv_q(l->frame_rate);
1443
1444 return 0;
1445}
1446
1448{
1449 AudioIIRContext *s = ctx->priv;
1450 AVFilterPad pad, vpad;
1451 int ret;
1452
1453 if (!s->a_str || !s->b_str || !s->g_str) {
1454 av_log(ctx, AV_LOG_ERROR, "Valid coefficients are mandatory.\n");
1455 return AVERROR(EINVAL);
1456 }
1457
1458 switch (s->precision) {
1459 case 0: s->sample_format = AV_SAMPLE_FMT_DBLP; break;
1460 case 1: s->sample_format = AV_SAMPLE_FMT_FLTP; break;
1461 case 2: s->sample_format = AV_SAMPLE_FMT_S32P; break;
1462 case 3: s->sample_format = AV_SAMPLE_FMT_S16P; break;
1463 default: return AVERROR_BUG;
1464 }
1465
1466 pad = (AVFilterPad){
1467 .name = "default",
1468 .type = AVMEDIA_TYPE_AUDIO,
1469 .config_props = config_output,
1470 };
1471
1472 ret = ff_append_outpad(ctx, &pad);
1473 if (ret < 0)
1474 return ret;
1475
1476 if (s->response) {
1477 vpad = (AVFilterPad){
1478 .name = "filter_response",
1479 .type = AVMEDIA_TYPE_VIDEO,
1480 .config_props = config_video,
1481 };
1482
1483 ret = ff_append_outpad(ctx, &vpad);
1484 if (ret < 0)
1485 return ret;
1486 }
1487
1488 return 0;
1489}
1490
1492{
1493 AudioIIRContext *s = ctx->priv;
1494 int ch;
1495
1496 if (s->iir) {
1497 for (ch = 0; ch < s->channels; ch++) {
1498 IIRChannel *iir = &s->iir[ch];
1499 av_freep(&iir->ab[0]);
1500 av_freep(&iir->ab[1]);
1501 av_freep(&iir->cache[0]);
1502 av_freep(&iir->cache[1]);
1503 av_freep(&iir->biquads);
1504 }
1505 }
1506 av_freep(&s->iir);
1507
1508 av_frame_free(&s->video);
1509}
1510
1511static const AVFilterPad inputs[] = {
1512 {
1513 .name = "default",
1514 .type = AVMEDIA_TYPE_AUDIO,
1515 .filter_frame = filter_frame,
1516 },
1517};
1518
1519#define OFFSET(x) offsetof(AudioIIRContext, x)
1520#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1521#define VF AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
1522
1523static const AVOption aiir_options[] = {
1524 { "zeros", "set B/numerator/zeros/reflection coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1525 { "z", "set B/numerator/zeros/reflection coefficients", OFFSET(b_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1526 { "poles", "set A/denominator/poles/ladder coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1527 { "p", "set A/denominator/poles/ladder coefficients", OFFSET(a_str), AV_OPT_TYPE_STRING, {.str="1+0i 1-0i"}, 0, 0, AF },
1528 { "gains", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF },
1529 { "k", "set channels gains", OFFSET(g_str), AV_OPT_TYPE_STRING, {.str="1|1"}, 0, 0, AF },
1530 { "dry", "set dry gain", OFFSET(dry_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1531 { "wet", "set wet gain", OFFSET(wet_gain), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1532 { "format", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, -2, 4, AF, .unit = "format" },
1533 { "f", "set coefficients format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=1}, -2, 4, AF, .unit = "format" },
1534 { "ll", "lattice-ladder function", 0, AV_OPT_TYPE_CONST, {.i64=-2}, 0, 0, AF, .unit = "format" },
1535 { "sf", "analog transfer function", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, AF, .unit = "format" },
1536 { "tf", "digital transfer function", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "format" },
1537 { "zp", "Z-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "format" },
1538 { "pr", "Z-plane zeros/poles (polar radians)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "format" },
1539 { "pd", "Z-plane zeros/poles (polar degrees)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, .unit = "format" },
1540 { "sp", "S-plane zeros/poles", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, .unit = "format" },
1541 { "process", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, .unit = "process" },
1542 { "r", "set kind of processing", OFFSET(process), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, .unit = "process" },
1543 { "d", "direct", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "process" },
1544 { "s", "serial", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "process" },
1545 { "p", "parallel", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "process" },
1546 { "precision", "set filtering precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, .unit = "precision" },
1547 { "e", "set precision", OFFSET(precision),AV_OPT_TYPE_INT, {.i64=0}, 0, 3, AF, .unit = "precision" },
1548 { "dbl", "double-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, .unit = "precision" },
1549 { "flt", "single-precision floating-point", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, .unit = "precision" },
1550 { "i32", "32-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, .unit = "precision" },
1551 { "i16", "16-bit integers", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, .unit = "precision" },
1552 { "normalize", "normalize coefficients", OFFSET(normalize),AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AF },
1553 { "n", "normalize coefficients", OFFSET(normalize),AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, AF },
1554 { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, AF },
1555 { "response", "show IR frequency response", OFFSET(response), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, VF },
1556 { "channel", "set IR channel to display frequency response", OFFSET(ir_channel), AV_OPT_TYPE_INT, {.i64=0}, 0, 1024, VF },
1557 { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "hd720"}, 0, 0, VF },
1558 { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT32_MAX, VF },
1559 { NULL },
1560};
1561
1563
1565 .p.name = "aiir",
1566 .p.description = NULL_IF_CONFIG_SMALL("Apply Infinite Impulse Response filter with supplied coefficients."),
1567 .p.priv_class = &aiir_class,
1570 .priv_size = sizeof(AudioIIRContext),
1571 .init = init,
1572 .uninit = uninit,
1575};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static enum AVSampleFormat sample_fmts[]
Definition adpcmenc.c:933
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static const AVFilterPad inputs[]
Definition af_aap.c:299
#define AF
#define LATTICE_IIR_CH(name, type, min, max, need_clipping)
Definition af_aiir.c:290
#define PARALLEL_IIR_CH(name, type, min, max, need_clipping)
Definition af_aiir.c:226
static void check_stability(AVFilterContext *ctx, int channels)
Definition af_aiir.c:1017
static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
Definition af_aiir.c:1036
static int read_zp_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst, const char *format)
Definition af_aiir.c:419
static void convert_sf2tf(AVFilterContext *ctx, int channels)
Definition af_aiir.c:962
static int config_video(AVFilterLink *outlink)
Definition af_aiir.c:1432
static int read_tf_coefficients(AVFilterContext *ctx, char *item_str, int nb_items, double *dst)
Definition af_aiir.c:394
static double distance(double x0, double x1, double y0, double y1)
Definition af_aiir.c:1085
static void draw_response(AVFilterContext *ctx, AVFrame *out, int sample_rate)
Definition af_aiir.c:1137
static void convert_pr2zp(AVFilterContext *ctx, int channels)
Definition af_aiir.c:882
static void convert_pd2zp(AVFilterContext *ctx, int channels)
Definition af_aiir.c:990
static const AVOption aiir_options[]
Definition af_aiir.c:1523
static int expand(AVFilterContext *ctx, double *pz, int n, double *coefs)
Definition af_aiir.c:500
static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
Definition af_aiir.c:603
static void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t color)
Definition af_aiir.c:1059
static double fact(double i)
Definition af_aiir.c:936
#define IIR_CH(name, type, min, max, need_clipping)
Definition af_aiir.c:111
static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, int ab)
Definition af_aiir.c:447
static void normalize_coeffs(AVFilterContext *ctx, int ch)
Definition af_aiir.c:527
static int read_gains(AVFilterContext *ctx, char *item_str, int nb_items)
Definition af_aiir.c:361
static const char *const format[]
Definition af_aiir.c:445
#define SERIAL_IIR_CH(name, type, min, max, need_clipping)
Definition af_aiir.c:167
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition af_aiir.c:1377
static void convert_sp2zp(AVFilterContext *ctx, int channels)
Definition af_aiir.c:909
static int convert_serial2parallel(AVFilterContext *ctx, int channels)
Definition af_aiir.c:817
static int convert_zp2tf(AVFilterContext *ctx, int channels)
Definition af_aiir.c:555
static void biquad_process(double *x, double *y, int length, double b0, double b1, double b2, double a1, double a2)
Definition af_aiir.c:765
static void count_coefficients(char *item_str, int *nb_items)
Definition af_aiir.c:347
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition af_aiir.c:81
static double coef_sf2zf(double *a, int N, int n)
Definition af_aiir.c:943
static av_cold void uninit(AVFilterContext *ctx)
Definition af_aiir.c:1491
static void get_response(int channel, int format, double w, const double *b, const double *a, int nb_b, int nb_a, double *magnitude, double *phase)
Definition af_aiir.c:1090
static void cmul(double re, double im, double re2, double im2, double *RE, double *IM)
Definition af_aiir.c:494
#define OFFSET(x)
Definition af_aiir.c:1519
static int config_output(AVFilterLink *outlink)
Definition af_aiir.c:1254
static void solve(double *matrix, double *vector, int n, double *y, double *x, double *lu)
Definition af_aiir.c:783
const FFFilter ff_af_aiir
Definition af_aiir.c:1564
@ biquad
Definition af_biquads.c:79
#define N
Definition af_mcompand.c:54
static FILE * out
static AVFormatContext * ctx
channels
Definition aptx.h:31
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition audio.c:74
int32_t
#define IM(x, ch)
#define RE(x, ch)
int ff_append_outpad(AVFilterContext *f, AVFilterPad *p)
Definition avfilter.c:138
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
Main libavfilter public API header.
int av_sscanf(const char *string, const char *format,...)
Definition avsscanf.c:962
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define av_clip
Definition common.h:100
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float ceil(float a)
static __device__ float fabs(float a)
#define min(a, b)
#define max(a, b)
double fmin(double, double)
double fmax(double, double)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition ebur128.h:39
int8_t exp
Definition eval.c:76
#define M(chr)
Definition exr.c:177
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:756
int ff_set_sample_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVSampleFormat *fmts)
Definition formats.c:1154
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
#define fail
Definition test.h:479
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition opt.h:314
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition avfilter.h:161
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR(e)
Definition error.h:45
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition frame.c:535
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:483
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition rational.h:159
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition samplefmt.h:66
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition samplefmt.h:67
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition avstring.c:179
int a
#define r
Definition input.c:42
#define b
Definition input.c:43
#define AV_WL32(p, v)
#define W(a, i, v)
Definition jpegls.h:119
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
static int mix(int c0, int c1)
Definition 4xm.c:717
const char * arg
Definition jacosubdec.c:65
#define VF
Definition af_afir.c:733
#define FILTER_INPUTS(array)
Definition filters.h:264
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
static const int factor[16]
Definition vf_pp7.c:98
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
#define isfinite(x)
Definition libm.h:361
#define isnan(x)
Definition libm.h:342
static av_const double hypot(double x, double y)
Definition libm.h:368
uint8_t w
Definition llvidencdsp.c:39
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define NAN
#define M_PI
Definition mathematics.h:67
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
static float distance(float x, float y, int band)
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition pixfmt.h:263
formats
Definition signature.h:47
#define snprintf
Definition snprintf.h:34
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A list of supported formats for one end of a filter link.
Definition formats.h:64
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int nb_samples
number of audio samples (per channel) described by this frame
Definition frame.h:552
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
AVOption.
Definition opt.h:428
Rational number (pair of numerator and denominator).
Definition rational.h:58
char * a_str
Definition af_aiir.c:60
double wet_gain
Definition af_aiir.c:61
int(* iir_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition af_aiir.c:78
char * b_str
Definition af_aiir.c:60
IIRChannel * iir
Definition af_aiir.c:74
AVRational rate
Definition af_aiir.c:70
double dry_gain
Definition af_aiir.c:61
AVFrame * video
Definition af_aiir.c:72
char * g_str
Definition af_aiir.c:60
enum AVSampleFormat sample_format
Definition af_aiir.c:76
double a[3]
Definition af_aiir.c:43
double w1
Definition af_aiir.c:45
double b[3]
Definition af_aiir.c:44
double w2
Definition af_aiir.c:45
int nb_ab[2]
Definition af_aiir.c:49
BiquadContext * biquads
Definition af_aiir.c:54
double * cache[2]
Definition af_aiir.c:52
double fir
Definition af_aiir.c:53
double * ab[2]
Definition af_aiir.c:50
int clippings
Definition af_aiir.c:55
double g
Definition af_aiir.c:51
Definition af_aiir.c:38
int b
Definition af_aiir.c:39
int a
Definition af_aiir.c:39
Used for passing data between threads.
Definition dsddec.c:71
AVFrame * out
#define av_free(p)
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_log(a,...)
else temp
Definition vf_mcdeint.c:275
static void process(NormalizeContext *s, AVFrame *in, AVFrame *out)
static double b1(void *priv, double x, double y)
Definition vf_xfade.c:2034
static double b2(void *priv, double x, double y)
Definition vf_xfade.c:2035
static double b0(void *priv, double x, double y)
Definition vf_xfade.c:2033
static double a2(void *priv, double x, double y)
Definition vf_xfade.c:2030
static double a1(void *priv, double x, double y)
Definition vf_xfade.c:2029
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89
const uint8_t * avpriv_cga_font_get(void)
CGA/EGA/VGA ROM font data.