FFmpeg
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 
105 AVFILTER_DEFINE_CLASS(acrossover);
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  }
135 
136  for (; i < MAX_BANDS; i++)
137  s->gains[i] = 1.f;
138 
139  return ret;
140 }
141 
143 {
144  AudioCrossoverContext *s = ctx->priv;
145  char *p, *arg, *saveptr = NULL;
146  int i, ret = 0;
147 
148  s->fdsp = avpriv_float_dsp_alloc(0);
149  if (!s->fdsp)
150  return AVERROR(ENOMEM);
151 
152  p = s->splits_str;
153  for (i = 0; i < MAX_SPLITS; i++) {
154  float freq;
155 
156  if (!(arg = av_strtok(p, " |", &saveptr)))
157  break;
158 
159  p = NULL;
160 
161  if (av_sscanf(arg, "%f", &freq) != 1) {
162  av_log(ctx, AV_LOG_ERROR, "Invalid syntax for frequency[%d].\n", i);
163  return AVERROR(EINVAL);
164  }
165  if (freq <= 0) {
166  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be positive number.\n", freq);
167  return AVERROR(EINVAL);
168  }
169 
170  if (i > 0 && freq <= s->splits[i-1]) {
171  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be in increasing order.\n", freq);
172  return AVERROR(EINVAL);
173  }
174 
175  s->splits[i] = freq;
176  }
177 
178  s->nb_splits = i;
179 
180  ret = parse_gains(ctx);
181  if (ret < 0)
182  return ret;
183 
184  for (i = 0; i <= s->nb_splits; i++) {
185  AVFilterPad pad = { 0 };
186  char *name;
187 
188  pad.type = AVMEDIA_TYPE_AUDIO;
189  name = av_asprintf("out%d", ctx->nb_outputs);
190  if (!name)
191  return AVERROR(ENOMEM);
192  pad.name = name;
193 
194  if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
195  av_freep(&pad.name);
196  return ret;
197  }
198  }
199 
200  return ret;
201 }
202 
203 static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
204 {
205  double omega = 2. * M_PI * fc / sr;
206  double cosine = cos(omega);
207  double alpha = sin(omega) / (2. * q);
208 
209  double b0 = (1. - cosine) / 2.;
210  double b1 = 1. - cosine;
211  double b2 = (1. - cosine) / 2.;
212  double a0 = 1. + alpha;
213  double a1 = -2. * cosine;
214  double a2 = 1. - alpha;
215 
216  b->cd[B0] = b0 / a0;
217  b->cd[B1] = b1 / a0;
218  b->cd[B2] = b2 / a0;
219  b->cd[A1] = -a1 / a0;
220  b->cd[A2] = -a2 / a0;
221 
222  b->cf[B0] = b->cd[B0];
223  b->cf[B1] = b->cd[B1];
224  b->cf[B2] = b->cd[B2];
225  b->cf[A1] = b->cd[A1];
226  b->cf[A2] = b->cd[A2];
227 }
228 
229 static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
230 {
231  double omega = 2. * M_PI * fc / sr;
232  double cosine = cos(omega);
233  double alpha = sin(omega) / (2. * q);
234 
235  double b0 = (1. + cosine) / 2.;
236  double b1 = -1. - cosine;
237  double b2 = (1. + cosine) / 2.;
238  double a0 = 1. + alpha;
239  double a1 = -2. * cosine;
240  double a2 = 1. - alpha;
241 
242  b->cd[B0] = b0 / a0;
243  b->cd[B1] = b1 / a0;
244  b->cd[B2] = b2 / a0;
245  b->cd[A1] = -a1 / a0;
246  b->cd[A2] = -a2 / a0;
247 
248  b->cf[B0] = b->cd[B0];
249  b->cf[B1] = b->cd[B1];
250  b->cf[B2] = b->cd[B2];
251  b->cf[A1] = b->cd[A1];
252  b->cf[A2] = b->cd[A2];
253 }
254 
255 static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
256 {
257  double omega = 2. * M_PI * fc / sr;
258  double cosine = cos(omega);
259  double alpha = sin(omega) / (2. * q);
260 
261  double a0 = 1. + alpha;
262  double a1 = -2. * cosine;
263  double a2 = 1. - alpha;
264  double b0 = a2;
265  double b1 = a1;
266  double b2 = a0;
267 
268  b->cd[B0] = b0 / a0;
269  b->cd[B1] = b1 / a0;
270  b->cd[B2] = b2 / a0;
271  b->cd[A1] = -a1 / a0;
272  b->cd[A2] = -a2 / a0;
273 
274  b->cf[B0] = b->cd[B0];
275  b->cf[B1] = b->cd[B1];
276  b->cf[B2] = b->cd[B2];
277  b->cf[A1] = b->cd[A1];
278  b->cf[A2] = b->cd[A2];
279 }
280 
281 static void set_ap1(BiquadCoeffs *b, double fc, double sr)
282 {
283  double omega = 2. * M_PI * fc / sr;
284 
285  b->cd[A1] = exp(-omega);
286  b->cd[A2] = 0.;
287  b->cd[B0] = -b->cd[A1];
288  b->cd[B1] = 1.;
289  b->cd[B2] = 0.;
290 
291  b->cf[B0] = b->cd[B0];
292  b->cf[B1] = b->cd[B1];
293  b->cf[B2] = b->cd[B2];
294  b->cf[A1] = b->cd[A1];
295  b->cf[A2] = b->cd[A2];
296 }
297 
298 static void calc_q_factors(int order, double *q)
299 {
300  double n = order / 2.;
301 
302  for (int i = 0; i < n / 2; i++)
303  q[i] = 1. / (-2. * cos(M_PI * (2. * (i + 1) + n - 1.) / (2. * n)));
304 }
305 
307 {
310  static const enum AVSampleFormat sample_fmts[] = {
313  };
314  int ret;
315 
317  if (!layouts)
318  return AVERROR(ENOMEM);
320  if (ret < 0)
321  return ret;
322 
324  if (!formats)
325  return AVERROR(ENOMEM);
327  if (ret < 0)
328  return ret;
329 
331  if (!formats)
332  return AVERROR(ENOMEM);
334 }
335 
336 #define BIQUAD_PROCESS(name, type) \
337 static void biquad_process_## name(const type *const c, \
338  type *b, \
339  type *dst, const type *src, \
340  int nb_samples) \
341 { \
342  const type b0 = c[B0]; \
343  const type b1 = c[B1]; \
344  const type b2 = c[B2]; \
345  const type a1 = c[A1]; \
346  const type a2 = c[A2]; \
347  type z1 = b[0]; \
348  type z2 = b[1]; \
349  \
350  for (int n = 0; n + 1 < nb_samples; n++) { \
351  type in = src[n]; \
352  type out; \
353  \
354  out = in * b0 + z1; \
355  z1 = b1 * in + z2 + a1 * out; \
356  z2 = b2 * in + a2 * out; \
357  dst[n] = out; \
358  \
359  n++; \
360  in = src[n]; \
361  out = in * b0 + z1; \
362  z1 = b1 * in + z2 + a1 * out; \
363  z2 = b2 * in + a2 * out; \
364  dst[n] = out; \
365  } \
366  \
367  if (nb_samples & 1) { \
368  const int n = nb_samples - 1; \
369  const type in = src[n]; \
370  type out; \
371  \
372  out = in * b0 + z1; \
373  z1 = b1 * in + z2 + a1 * out; \
374  z2 = b2 * in + a2 * out; \
375  dst[n] = out; \
376  } \
377  \
378  b[0] = z1; \
379  b[1] = z2; \
380 }
381 
382 BIQUAD_PROCESS(fltp, float)
383 BIQUAD_PROCESS(dblp, double)
384 
385 #define XOVER_PROCESS(name, type, one, ff) \
386 static int filter_channels_## name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
387 { \
388  AudioCrossoverContext *s = ctx->priv; \
389  AVFrame *in = s->input_frame; \
390  AVFrame **frames = s->frames; \
391  const int start = (in->channels * jobnr) / nb_jobs; \
392  const int end = (in->channels * (jobnr+1)) / nb_jobs; \
393  const int nb_samples = in->nb_samples; \
394  const int nb_outs = ctx->nb_outputs; \
395  const int first_order = s->first_order; \
396  \
397  for (int ch = start; ch < end; ch++) { \
398  const type *src = (const type *)in->extended_data[ch]; \
399  type *xover = (type *)s->xover->extended_data[ch]; \
400  \
401  s->fdsp->vector_## ff ##mul_scalar((type *)frames[0]->extended_data[ch], src, \
402  s->level_in, FFALIGN(nb_samples, sizeof(type))); \
403  \
404  for (int band = 0; band < nb_outs; band++) { \
405  for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
406  const type *prv = (const type *)frames[band]->extended_data[ch]; \
407  type *dst = (type *)frames[band + 1]->extended_data[ch]; \
408  const type *hsrc = f == 0 ? prv : dst; \
409  type *hp = xover + nb_outs * 20 + band * 20 + f * 2; \
410  const type *const hpc = (type *)&s->hp[band][f].c ## ff; \
411  \
412  biquad_process_## name(hpc, hp, dst, hsrc, nb_samples); \
413  } \
414  \
415  for (int f = 0; band + 1 < nb_outs && f < s->filter_count; f++) { \
416  type *dst = (type *)frames[band]->extended_data[ch]; \
417  const type *lsrc = dst; \
418  type *lp = xover + band * 20 + f * 2; \
419  const type *const lpc = (type *)&s->lp[band][f].c ## ff; \
420  \
421  biquad_process_## name(lpc, lp, dst, lsrc, nb_samples); \
422  } \
423  \
424  for (int aband = band + 1; aband + 1 < nb_outs; aband++) { \
425  if (first_order) { \
426  const type *asrc = (const type *)frames[band]->extended_data[ch]; \
427  type *dst = (type *)frames[band]->extended_data[ch]; \
428  type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20; \
429  const type *const apc = (type *)&s->ap[aband][0].c ## ff; \
430  \
431  biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
432  } \
433  \
434  for (int f = first_order; f < s->ap_filter_count; f++) { \
435  const type *asrc = (const type *)frames[band]->extended_data[ch]; \
436  type *dst = (type *)frames[band]->extended_data[ch]; \
437  type *ap = xover + nb_outs * 40 + (aband * nb_outs + band) * 20 + f * 2;\
438  const type *const apc = (type *)&s->ap[aband][f].c ## ff; \
439  \
440  biquad_process_## name(apc, ap, dst, asrc, nb_samples); \
441  } \
442  } \
443  } \
444  \
445  for (int band = 0; band < nb_outs; band++) { \
446  const type gain = s->gains[band] * ((band & 1 && first_order) ? -one : one); \
447  type *dst = (type *)frames[band]->extended_data[ch]; \
448  \
449  s->fdsp->vector_## ff ##mul_scalar(dst, dst, gain, \
450  FFALIGN(nb_samples, sizeof(type))); \
451  } \
452  } \
453  \
454  return 0; \
455 }
456 
457 XOVER_PROCESS(fltp, float, 1.f, f)
458 XOVER_PROCESS(dblp, double, 1.0, d)
459 
461 {
462  AVFilterContext *ctx = inlink->dst;
463  AudioCrossoverContext *s = ctx->priv;
464  int sample_rate = inlink->sample_rate;
465  double q[16];
466 
467  s->order = (s->order_opt + 1) * 2;
468  s->filter_count = s->order / 2;
469  s->first_order = s->filter_count & 1;
470  s->ap_filter_count = s->filter_count / 2 + s->first_order;
471  calc_q_factors(s->order, q);
472 
473  for (int band = 0; band <= s->nb_splits; band++) {
474  if (s->first_order) {
475  set_lp(&s->lp[band][0], s->splits[band], 0.5, sample_rate);
476  set_hp(&s->hp[band][0], s->splits[band], 0.5, sample_rate);
477  }
478 
479  for (int n = s->first_order; n < s->filter_count; n++) {
480  const int idx = s->filter_count / 2 - ((n + s->first_order) / 2 - s->first_order) - 1;
481 
482  set_lp(&s->lp[band][n], s->splits[band], q[idx], sample_rate);
483  set_hp(&s->hp[band][n], s->splits[band], q[idx], sample_rate);
484  }
485 
486  if (s->first_order)
487  set_ap1(&s->ap[band][0], s->splits[band], sample_rate);
488 
489  for (int n = s->first_order; n < s->ap_filter_count; n++) {
490  const int idx = (s->filter_count / 2 - ((n * 2 + s->first_order) / 2 - s->first_order) - 1);
491 
492  set_ap(&s->ap[band][n], s->splits[band], q[idx], sample_rate);
493  }
494  }
495 
496  switch (inlink->format) {
497  case AV_SAMPLE_FMT_FLTP: s->filter_channels = filter_channels_fltp; break;
498  case AV_SAMPLE_FMT_DBLP: s->filter_channels = filter_channels_dblp; break;
499  }
500 
501  s->xover = ff_get_audio_buffer(inlink, 2 * (ctx->nb_outputs * 10 + ctx->nb_outputs * 10 +
502  ctx->nb_outputs * ctx->nb_outputs * 10));
503  if (!s->xover)
504  return AVERROR(ENOMEM);
505 
506  return 0;
507 }
508 
510 {
511  AVFilterContext *ctx = inlink->dst;
512  AudioCrossoverContext *s = ctx->priv;
513  AVFrame **frames = s->frames;
514  int i, ret = 0;
515 
516  for (i = 0; i < ctx->nb_outputs; i++) {
517  frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
518 
519  if (!frames[i]) {
520  ret = AVERROR(ENOMEM);
521  break;
522  }
523 
524  frames[i]->pts = in->pts;
525  }
526 
527  if (ret < 0)
528  goto fail;
529 
530  s->input_frame = in;
531  ctx->internal->execute(ctx, s->filter_channels, NULL, NULL, FFMIN(inlink->channels,
533 
534  for (i = 0; i < ctx->nb_outputs; i++) {
535  ret = ff_filter_frame(ctx->outputs[i], frames[i]);
536  frames[i] = NULL;
537  if (ret < 0)
538  break;
539  }
540 
541 fail:
542  for (i = 0; i < ctx->nb_outputs; i++)
544  av_frame_free(&in);
545  s->input_frame = NULL;
546 
547  return ret;
548 }
549 
551 {
552  AudioCrossoverContext *s = ctx->priv;
553  int i;
554 
555  av_freep(&s->fdsp);
556  av_frame_free(&s->xover);
557 
558  for (i = 0; i < ctx->nb_outputs; i++)
559  av_freep(&ctx->output_pads[i].name);
560 }
561 
562 static const AVFilterPad inputs[] = {
563  {
564  .name = "default",
565  .type = AVMEDIA_TYPE_AUDIO,
566  .filter_frame = filter_frame,
567  .config_props = config_input,
568  },
569  { NULL }
570 };
571 
573  .name = "acrossover",
574  .description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
575  .priv_size = sizeof(AudioCrossoverContext),
576  .priv_class = &acrossover_class,
577  .init = init,
578  .uninit = uninit,
580  .inputs = inputs,
581  .outputs = NULL,
584 };
formats
formats
Definition: signature.h:48
ff_get_audio_buffer
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
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:86
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
OFFSET
#define OFFSET(x)
Definition: af_acrossover.c:84
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
BiquadCoeffs::cf
float cf[5]
Definition: af_acrossover.c:50
AudioCrossoverContext::lp
BiquadCoeffs lp[MAX_BANDS][20]
Definition: af_acrossover.c:70
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1094
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:926
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
AudioCrossoverContext::hp
BiquadCoeffs hp[MAX_BANDS][20]
Definition: af_acrossover.c:71
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:204
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:436
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:324
AVOption
AVOption.
Definition: opt.h:248
b
#define b
Definition: input.c:41
MAX_SPLITS
#define MAX_SPLITS
Definition: af_acrossover.c:39
expf
#define expf(x)
Definition: libm.h:283
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(acrossover)
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:551
B2
#define B2
Definition: af_acrossover.c:44
BIQUAD_PROCESS
#define BIQUAD_PROCESS(name, type)
Definition: af_acrossover.c:336
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
AudioCrossoverContext::frames
AVFrame * frames[MAX_BANDS]
Definition: af_acrossover.c:77
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1698
sample_rate
sample_rate
Definition: ffmpeg_filter.c:158
AudioCrossoverContext::filter_channels
int(* filter_channels)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_acrossover.c:79
AudioCrossoverContext::input_frame
AVFrame * input_frame
Definition: af_acrossover.c:76
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
AF
#define AF
Definition: af_acrossover.c:85
BiquadCoeffs
Definition: af_acrossover.c:48
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1665
acrossover_options
static const AVOption acrossover_options[]
Definition: af_acrossover.c:87
fail
#define fail()
Definition: checkasm.h:133
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
AudioCrossoverContext::xover
AVFrame * xover
Definition: af_acrossover.c:74
parse_gains
static int parse_gains(AVFilterContext *ctx)
Definition: af_acrossover.c:107
set_hp
static void set_hp(BiquadCoeffs *b, double fc, double q, double sr)
Definition: af_acrossover.c:229
AudioCrossoverContext
Definition: af_acrossover.c:53
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
B1
#define B1
Definition: af_acrossover.c:43
a1
#define a1
Definition: regdef.h:47
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
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
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_strtok
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
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AudioCrossoverContext::first_order
int first_order
Definition: af_acrossover.c:63
ctx
AVFormatContext * ctx
Definition: movenc.c:48
A2
#define A2
Definition: af_acrossover.c:46
f
#define f(width, name)
Definition: cbs_vp9.c:255
arg
const char * arg
Definition: jacosubdec.c:66
av_sscanf
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
B0
#define B0
Definition: af_acrossover.c:42
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_acrossover.c:509
AudioCrossoverContext::nb_splits
int nb_splits
Definition: af_acrossover.c:65
exp
int8_t exp
Definition: eval.c:72
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AudioCrossoverContext::ap
BiquadCoeffs ap[MAX_BANDS][20]
Definition: af_acrossover.c:72
float_dsp.h
AVFILTER_FLAG_DYNAMIC_OUTPUTS
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:112
eval.h
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_acrossover.c:306
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_acrossover.c:550
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AudioCrossoverContext::splits
float splits[MAX_SPLITS]
Definition: af_acrossover.c:66
AVFloatDSPContext
Definition: float_dsp.h:24
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:1666
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
calc_q_factors
static void calc_q_factors(int order, double *q)
Definition: af_acrossover.c:298
attributes.h
AudioCrossoverContext::order
int order
Definition: af_acrossover.c:61
a0
#define a0
Definition: regdef.h:46
M_PI
#define M_PI
Definition: mathematics.h:52
ff_af_acrossover
AVFilter ff_af_acrossover
Definition: af_acrossover.c:572
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
in
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
Definition: audio_convert.c:326
AudioCrossoverContext::filter_count
int filter_count
Definition: af_acrossover.c:62
i
int i
Definition: input.c:407
internal.h
a2
#define a2
Definition: regdef.h:48
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
set_lp
static void set_lp(BiquadCoeffs *b, double fc, double q, double sr)
Definition: af_acrossover.c:203
inputs
static const AVFilterPad inputs[]
Definition: af_acrossover.c:562
AudioCrossoverContext::ap_filter_count
int ap_filter_count
Definition: af_acrossover.c:64
AVFilter
Filter definition.
Definition: avfilter.h:145
set_ap
static void set_ap(BiquadCoeffs *b, double fc, double q, double sr)
Definition: af_acrossover.c:255
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
set_ap1
static void set_ap1(BiquadCoeffs *b, double fc, double sr)
Definition: af_acrossover.c:281
AudioCrossoverContext::gains_str
char * gains_str
Definition: af_acrossover.c:57
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_acrossover.c:142
channel_layout.h
ff_insert_outpad
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:248
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
MAX_BANDS
#define MAX_BANDS
Definition: af_acrossover.c:40
AudioCrossoverContext::fdsp
AVFloatDSPContext * fdsp
Definition: af_acrossover.c:81
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
A1
#define A1
Definition: af_acrossover.c:45
AudioCrossoverContext::gains
float gains[MAX_BANDS]
Definition: af_acrossover.c:68
audio.h
M_LN10
#define M_LN10
Definition: mathematics.h:43
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_acrossover.c:460
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
d
d
Definition: ffmpeg_filter.c:158
XOVER_PROCESS
#define XOVER_PROCESS(name, type, one, ff)
Definition: af_acrossover.c:385
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AudioCrossoverContext::level_in
float level_in
Definition: af_acrossover.c:59
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:1664
AudioCrossoverContext::order_opt
int order_opt
Definition: af_acrossover.c:58
BiquadCoeffs::cd
double cd[5]
Definition: af_acrossover.c:49
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
int
int
Definition: ffmpeg_filter.c:158
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
AudioCrossoverContext::splits_str
char * splits_str
Definition: af_acrossover.c:56
ff_set_common_channel_layouts
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