FFmpeg  4.4.9
af_acrossover.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * Crossover filter
22  *
23  * Split an audio stream into several bands.
24  */
25 
26 #include "libavutil/attributes.h"
27 #include "libavutil/avstring.h"
29 #include "libavutil/eval.h"
30 #include "libavutil/float_dsp.h"
31 #include "libavutil/internal.h"
32 #include "libavutil/opt.h"
33 
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "formats.h"
37 #include "internal.h"
38 
39 #define MAX_SPLITS 16
40 #define MAX_BANDS MAX_SPLITS + 1
41 
42 #define B0 0
43 #define B1 1
44 #define B2 2
45 #define A1 3
46 #define A2 4
47 
48 typedef struct BiquadCoeffs {
49  double cd[5];
50  float cf[5];
51 } BiquadCoeffs;
52 
53 typedef struct AudioCrossoverContext {
54  const AVClass *class;
55 
56  char *splits_str;
57  char *gains_str;
58  int order_opt;
59  float level_in;
60 
61  int order;
65  int nb_splits;
67 
68  float gains[MAX_BANDS];
69 
73 
75 
78 
79  int (*filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
80 
83 
84 #define OFFSET(x) offsetof(AudioCrossoverContext, x)
85 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
86 
87 static const AVOption acrossover_options[] = {
88  { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
89  { "order", "set filter order", OFFSET(order_opt), AV_OPT_TYPE_INT, {.i64=1}, 0, 9, AF, "m" },
90  { "2nd", "2nd order (12 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
91  { "4th", "4th order (24 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
92  { "6th", "6th order (36 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
93  { "8th", "8th order (48 dB/8ve)", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, AF, "m" },
94  { "10th", "10th order (60 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, AF, "m" },
95  { "12th", "12th order (72 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, AF, "m" },
96  { "14th", "14th order (84 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, AF, "m" },
97  { "16th", "16th order (96 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, AF, "m" },
98  { "18th", "18th order (108 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, AF, "m" },
99  { "20th", "20th order (120 dB/8ve)",0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, AF, "m" },
100  { "level", "set input gain", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, AF },
101  { "gain", "set output bands gain", OFFSET(gains_str), AV_OPT_TYPE_STRING, {.str="1.f"}, 0, 0, AF },
102  { NULL }
103 };
104 
106 
108 {
109  AudioCrossoverContext *s = ctx->priv;
110  char *p, *arg, *saveptr = NULL;
111  int i, ret = 0;
112 
113  saveptr = NULL;
114  p = s->gains_str;
115  for (i = 0; i < MAX_BANDS; i++) {
116  float gain;
117  char c[3] = { 0 };
118 
119  if (!(arg = av_strtok(p, " |", &saveptr)))
120  break;
121 
122  p = NULL;
123 
124  if (av_sscanf(arg, "%f%2s", &gain, c) < 1) {
125  av_log(ctx, AV_LOG_ERROR, "Invalid syntax for gain[%d].\n", i);
126  ret = AVERROR(EINVAL);
127  break;
128  }
129 
130  if (c[0] == 'd' && c[1] == 'B')
131  s->gains[i] = expf(gain * M_LN10 / 20.f);
132  else
133  s->gains[i] = gain;
134  if (!isfinite(s->gains[i])) {
135  av_log(ctx, AV_LOG_ERROR, "Gain %f must be finite.\n", gain);
136  return AVERROR(EINVAL);
137  }
138  }
139 
140  for (; i < MAX_BANDS; i++)
141  s->gains[i] = 1.f;
142 
143  return ret;
144 }
145 
147 {
148  AudioCrossoverContext *s = ctx->priv;
149  char *p, *arg, *saveptr = NULL;
150  int i, ret = 0;
151 
152  s->fdsp = avpriv_float_dsp_alloc(0);
153  if (!s->fdsp)
154  return AVERROR(ENOMEM);
155 
156  p = s->splits_str;
157  for (i = 0; i < MAX_SPLITS; i++) {
158  float freq;
159 
160  if (!(arg = av_strtok(p, " |", &saveptr)))
161  break;
162 
163  p = NULL;
164 
165  if (av_sscanf(arg, "%f", &freq) != 1) {
166  av_log(ctx, AV_LOG_ERROR, "Invalid syntax for frequency[%d].\n", i);
167  return AVERROR(EINVAL);
168  }
169  if (!isfinite(freq) || freq <= 0) {
170  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be a positive finite number.\n", freq);
171  return AVERROR(EINVAL);
172  }
173 
174  if (i > 0 && freq <= s->splits[i-1]) {
175  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be in increasing order.\n", freq);
176  return AVERROR(EINVAL);
177  }
178 
179  s->splits[i] = freq;
180  }
181 
182  s->nb_splits = i;
183 
184  ret = parse_gains(ctx);
185  if (ret < 0)
186  return ret;
187 
188  for (i = 0; i <= s->nb_splits; i++) {
189  AVFilterPad pad = { 0 };
190  char *name;
191 
192  pad.type = AVMEDIA_TYPE_AUDIO;
193  name = av_asprintf("out%d", ctx->nb_outputs);
194  if (!name)
195  return AVERROR(ENOMEM);
196  pad.name = name;
197 
198  if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
199  av_freep(&pad.name);
200  return ret;
201  }
202  }
203 
204  return ret;
205 }
206 
207 static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
208 {
209  double omega = 2. * M_PI * fc / sr;
210  double cosine = cos(omega);
211  double alpha = sin(omega) / (2. * q);
212 
213  double b0 = (1. - cosine) / 2.;
214  double b1 = 1. - cosine;
215  double b2 = (1. - cosine) / 2.;
216  double a0 = 1. + alpha;
217  double a1 = -2. * cosine;
218  double a2 = 1. - alpha;
219 
220  b->cd[B0] = b0 / a0;
221  b->cd[B1] = b1 / a0;
222  b->cd[B2] = b2 / a0;
223  b->cd[A1] = -a1 / a0;
224  b->cd[A2] = -a2 / a0;
225 
226  b->cf[B0] = b->cd[B0];
227  b->cf[B1] = b->cd[B1];
228  b->cf[B2] = b->cd[B2];
229  b->cf[A1] = b->cd[A1];
230  b->cf[A2] = b->cd[A2];
231 }
232 
233 static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
234 {
235  double omega = 2. * M_PI * fc / sr;
236  double cosine = cos(omega);
237  double alpha = sin(omega) / (2. * q);
238 
239  double b0 = (1. + cosine) / 2.;
240  double b1 = -1. - cosine;
241  double b2 = (1. + cosine) / 2.;
242  double a0 = 1. + alpha;
243  double a1 = -2. * cosine;
244  double a2 = 1. - alpha;
245 
246  b->cd[B0] = b0 / a0;
247  b->cd[B1] = b1 / a0;
248  b->cd[B2] = b2 / a0;
249  b->cd[A1] = -a1 / a0;
250  b->cd[A2] = -a2 / a0;
251 
252  b->cf[B0] = b->cd[B0];
253  b->cf[B1] = b->cd[B1];
254  b->cf[B2] = b->cd[B2];
255  b->cf[A1] = b->cd[A1];
256  b->cf[A2] = b->cd[A2];
257 }
258 
259 static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
260 {
261  double omega = 2. * M_PI * fc / sr;
262  double cosine = cos(omega);
263  double alpha = sin(omega) / (2. * q);
264 
265  double a0 = 1. + alpha;
266  double a1 = -2. * cosine;
267  double a2 = 1. - alpha;
268  double b0 = a2;
269  double b1 = a1;
270  double b2 = a0;
271 
272  b->cd[B0] = b0 / a0;
273  b->cd[B1] = b1 / a0;
274  b->cd[B2] = b2 / a0;
275  b->cd[A1] = -a1 / a0;
276  b->cd[A2] = -a2 / a0;
277 
278  b->cf[B0] = b->cd[B0];
279  b->cf[B1] = b->cd[B1];
280  b->cf[B2] = b->cd[B2];
281  b->cf[A1] = b->cd[A1];
282  b->cf[A2] = b->cd[A2];
283 }
284 
285 static void set_ap1(BiquadCoeffs *b, double fc, double sr)
286 {
287  double omega = 2. * M_PI * fc / sr;
288 
289  b->cd[A1] = exp(-omega);
290  b->cd[A2] = 0.;
291  b->cd[B0] = -b->cd[A1];
292  b->cd[B1] = 1.;
293  b->cd[B2] = 0.;
294 
295  b->cf[B0] = b->cd[B0];
296  b->cf[B1] = b->cd[B1];
297  b->cf[B2] = b->cd[B2];
298  b->cf[A1] = b->cd[A1];
299  b->cf[A2] = b->cd[A2];
300 }
301 
302 static void calc_q_factors(int order, double *q)
303 {
304  double n = order / 2.;
305 
306  for (int i = 0; i < n / 2; i++)
307  q[i] = 1. / (-2. * cos(M_PI * (2. * (i + 1) + n - 1.) / (2. * n)));
308 }
309 
311 {
314  static const enum AVSampleFormat sample_fmts[] = {
317  };
318  int ret;
319 
321  if (!layouts)
322  return AVERROR(ENOMEM);
324  if (ret < 0)
325  return ret;
326 
328  if (!formats)
329  return AVERROR(ENOMEM);
331  if (ret < 0)
332  return ret;
333 
335  if (!formats)
336  return AVERROR(ENOMEM);
338 }
339 
340 #define BIQUAD_PROCESS(name, type) \
341 static void biquad_process_## name(const type *const c, \
342  type *b, \
343  type *dst, const type *src, \
344  int nb_samples) \
345 { \
346  const type b0 = c[B0]; \
347  const type b1 = c[B1]; \
348  const type b2 = c[B2]; \
349  const type a1 = c[A1]; \
350  const type a2 = c[A2]; \
351  type z1 = b[0]; \
352  type z2 = b[1]; \
353  \
354  for (int n = 0; n + 1 < nb_samples; n++) { \
355  type in = src[n]; \
356  type out; \
357  \
358  out = in * b0 + z1; \
359  z1 = b1 * in + z2 + a1 * out; \
360  z2 = b2 * in + a2 * out; \
361  dst[n] = out; \
362  \
363  n++; \
364  in = src[n]; \
365  out = in * b0 + z1; \
366  z1 = b1 * in + z2 + a1 * out; \
367  z2 = b2 * in + a2 * out; \
368  dst[n] = out; \
369  } \
370  \
371  if (nb_samples & 1) { \
372  const int n = nb_samples - 1; \
373  const type in = src[n]; \
374  type out; \
375  \
376  out = in * b0 + z1; \
377  z1 = b1 * in + z2 + a1 * out; \
378  z2 = b2 * in + a2 * out; \
379  dst[n] = out; \
380  } \
381  \
382  b[0] = z1; \
383  b[1] = z2; \
384 }
385 
386 BIQUAD_PROCESS(fltp, float)
387 BIQUAD_PROCESS(dblp, double)
388 
389 #define XOVER_PROCESS(name, type, one, ff) \
390 static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
391 { \
392  AudioCrossoverContext *s = ctx->priv; \
393  AVFrame *in = s->input_frame; \
394  AVFrame **frames = s->frames; \
395  const int start = (in->channels * jobnr) / nb_jobs; \
396  const int end = (in->channels * (jobnr+1)) / nb_jobs; \
397  const int nb_samples = in->nb_samples; \
398  const int nb_outs = ctx->nb_outputs; \
399  const int first_order = s->first_order; \
400  \
401  for (int ch = start; ch < end; ch++) { \
402  const type *src = (const type *)in->extended_data[ch]; \
403  type *xover = (type *)s->xover->extended_data[ch]; \
404  \
405  s->fdsp->vector_## ff ##mul_scalar((type *)frames[0]->extended_data[ch], src, \
406  s->level_in, FFALIGN(nb_samples, sizeof(type))); \
407  \
408  for (int band = 0; band < nb_outs; band++) { \
409  for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
410  const type *prv = (const type *)frames[band]->extended_data[ch]; \
411  type *dst = (type *)frames[band + 1]->extended_data[ch]; \
412  const type *hsrc = f == 0 ? prv : dst; \
413  type *hp = xover + nb_outs * 20 + band * 20 + f * 2; \
414  const type *const hpc = (type *)&s->hp[band][f].c ## ff; \
415  \
416  biquad_process_## name(hpc, hp, dst, hsrc, nb_samples); \
417  } \
418  \
419  for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
420  type *dst = (type *)frames[band]->extended_data[ch]; \
421  const type *lsrc = dst; \
422  type *lp = xover + band * 20 + f * 2; \
423  const type *const lpc = (type *)&s->lp[band][f].c ## ff; \
424  \
425  biquad_process_## name(lpc, lp, dst, lsrc, nb_samples); \
426  } \
427  \
428  for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \
429  if (first_order) { \
430  const type *asrc = (const type *)frames[band]->extended_data[ch]; \
431  type *dst = (type *)frames[band]->extended_data[ch]; \
432  type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \
433  const type *const apc = (type *)&s->ap[aband][0].c ## ff; \
434  \
435  biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
436  } \
437  \
438  for (int f = first_order; f < s->ap_filter_count; f++) { \
439  const type *asrc = (const type *)frames[band]->extended_data[ch]; \
440  type *dst = (type *)frames[band]->extended_data[ch]; \
441  type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\
442  const type *const apc = (type *)&s->ap[aband][f].c ## ff; \
443  \
444  biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
445  } \
446  } \
447  } \
448  \
449  for (int band = 0; band < nb_outs; band++) { \
450  const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \
451  type *dst = (type *)frames[band]->extended_data[ch]; \
452  \
453  s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \
454  FFALIGN(nb_samples, sizeof(type))); \
455  } \
456  } \
457  \
458  return 0; \
459 }
460 
461 XOVER_PROCESS(fltp, float, 1.f, f)
462 XOVER_PROCESS(dblp, double, 1.0, d)
463 
464 static int config_input(AVFilterLink *inlink)
465 {
466  AVFilterContext *ctx = inlink->dst;
467  AudioCrossoverContext *s = ctx->priv;
468  int sample_rate = inlink->sample_rate;
469  double q[16];
470 
471  s->order = (s->order_opt + 1) * 2;
472  s->filter_count = s->order / 2;
473  s->first_order = s->filter_count & 1;
474  s->ap_filter_count = s->filter_count / 2 + s->first_order;
475  calc_q_factors(s->order, q);
476 
477  for (int band = 0; band <= s->nb_splits; band++) {
478  if (s->first_order) {
479  set_lp(&s->lp[band][0], s->splits[band], 0.5, sample_rate);
480  set_hp(&s->hp[band][0], s->splits[band], 0.5, sample_rate);
481  }
482 
483  for (int n = s->first_order; n < s->filter_count; n++) {
484  const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1;
485 
486  set_lp(&s->lp[band][n], s->splits[band], q[idx], sample_rate);
487  set_hp(&s->hp[band][n], s->splits[band], q[idx], sample_rate);
488  }
489 
490  if (s->first_order)
491  set_ap1(&s->ap[band][0], s->splits[band], sample_rate);
492 
493  for (int n = s->first_order; n < s->ap_filter_count; n++) {
494  const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1);
495 
496  set_ap(&s->ap[band][n], s->splits[band], q[idx], sample_rate);
497  }
498  }
499 
500  switch (inlink->format) {
501  case AV_SAMPLE_FMT_FLTP: s->filter_channels = filter_channels_fltp; break;
502  case AV_SAMPLE_FMT_DBLP: s->filter_channels = filter_channels_dblp; break;
503  default: return AVERROR_BUG;
504  }
505 
506  s->xover = ff_get_audio_buffer(inlink, 2 * (ctx->nb_outputs * 10 + ctx->nb_outputs * 10 +
507  ctx->nb_outputs * ctx->nb_outputs * 10));
508  if (!s->xover)
509  return AVERROR(ENOMEM);
510 
511  return 0;
512 }
513 
514 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
515 {
516  AVFilterContext *ctx = inlink->dst;
517  AudioCrossoverContext *s = ctx->priv;
518  AVFrame **frames = s->frames;
519  int i, ret = 0;
520 
521  for (i = 0; i < ctx->nb_outputs; i++) {
522  frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
523 
524  if (!frames[i]) {
525  ret = AVERROR(ENOMEM);
526  break;
527  }
528 
529  frames[i]->pts = in->pts;
530  }
531 
532  if (ret < 0)
533  goto fail;
534 
535  s->input_frame = in;
536  ctx->internal->execute(ctx, s->filter_channels, NULL, NULL, FFMIN(inlink->channels,
538 
539  for (i = 0; i < ctx->nb_outputs; i++) {
540  ret = ff_filter_frame(ctx->outputs[i], frames[i]);
541  frames[i] = NULL;
542  if (ret < 0)
543  break;
544  }
545 
546 fail:
547  for (i = 0; i < ctx->nb_outputs; i++)
549  av_frame_free(&in);
550  s->input_frame = NULL;
551 
552  return ret;
553 }
554 
556 {
557  AudioCrossoverContext *s = ctx->priv;
558  int i;
559 
560  av_freep(&s->fdsp);
561  av_frame_free(&s->xover);
562 
563  for (i = 0; i < ctx->nb_outputs; i++)
564  av_freep(&ctx->output_pads[i].name);
565 }
566 
567 static const AVFilterPad inputs[] = {
568  {
569  .name = "default",
570  .type = AVMEDIA_TYPE_AUDIO,
571  .filter_frame = filter_frame,
572  .config_props = config_input,
573  },
574  { NULL }
575 };
576 
578  .name = "acrossover",
579  .description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
580  .priv_size = sizeof(AudioCrossoverContext),
581  .priv_class = &acrossover_class,
582  .init = init,
583  .uninit = uninit,
585  .inputs = inputs,
586  .outputs = NULL,
589 };
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:925
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define MAX_BANDS
Definition: af_acrossover.c:40
#define MAX_SPLITS
Definition: af_acrossover.c:39
static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
#define A2
Definition: af_acrossover.c:46
static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
static int query_formats(AVFilterContext *ctx)
AVFilter ff_af_acrossover
static int config_input(AVFilterLink *inlink)
static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
#define B2
Definition: af_acrossover.c:44
static const AVFilterPad inputs[]
#define AF
Definition: af_acrossover.c:85
#define B1
Definition: af_acrossover.c:43
#define B0
Definition: af_acrossover.c:42
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static const AVOption acrossover_options[]
Definition: af_acrossover.c:87
AVFILTER_DEFINE_CLASS(acrossover)
static void set_ap1(BiquadCoeffs *b, double fc, double sr)
static av_cold int init(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
#define XOVER_PROCESS(name, type, one, ff)
#define A1
Definition: af_acrossover.c:45
#define OFFSET(x)
Definition: af_acrossover.c:84
#define BIQUAD_PROCESS(name, type)
static void calc_q_factors(int order, double *q)
static int parse_gains(AVFilterContext *ctx)
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:88
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:805
Main libavfilter public API header.
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:562
#define s(width, name)
Definition: cbs_vp9.c:257
#define f(width, name)
Definition: cbs_vp9.c:255
audio channel layout utility functions
#define fail()
Definition: checkasm.h:133
#define FFMIN(a, b)
Definition: common.h:105
#define NULL
Definition: coverity.c:32
int8_t exp
Definition: eval.c:74
simple arithmetic expression evaluator
int
sample_rate
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:436
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:568
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:112
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
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:186
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
static const int16_t alpha[]
Definition: ilbcdata.h:55
int i
Definition: input.c:407
const char * arg
Definition: jacosubdec.c:67
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:248
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define isfinite(x)
Definition: libm.h:359
#define expf(x)
Definition: libm.h:283
#define M_LN10
Definition: mathematics.h:43
#define M_PI
Definition: mathematics.h:52
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVOptions.
const char * name
Definition: qsvenc.c:46
#define a2
Definition: regdef.h:48
#define a0
Definition: regdef.h:46
#define a1
Definition: regdef.h:47
formats
Definition: signature.h:48
Describe the class of an AVClass context structure.
Definition: log.h:67
A list of supported channel layouts.
Definition: formats.h:86
An instance of a filter.
Definition: avfilter.h:341
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AVOption.
Definition: opt.h:248
BiquadCoeffs lp[MAX_BANDS][20]
Definition: af_acrossover.c:70
BiquadCoeffs hp[MAX_BANDS][20]
Definition: af_acrossover.c:71
int(* filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_acrossover.c:79
float gains[MAX_BANDS]
Definition: af_acrossover.c:68
BiquadCoeffs ap[MAX_BANDS][20]
Definition: af_acrossover.c:72
float splits[MAX_SPLITS]
Definition: af_acrossover.c:66
AVFrame * frames[MAX_BANDS]
Definition: af_acrossover.c:77
AVFloatDSPContext * fdsp
Definition: af_acrossover.c:81
float cf[5]
Definition: af_acrossover.c:50
double cd[5]
Definition: af_acrossover.c:49
#define av_freep(p)
#define av_log(a,...)
int frames
Definition: movenc.c:66
AVFormatContext * ctx
Definition: movenc.c:48
const char * b
Definition: vf_curves.c:119
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1668
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:1669
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:1667
static double c[64]