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/internal.h"
31 #include "libavutil/opt.h"
32 
33 #include "audio.h"
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "internal.h"
37 
38 #define MAX_SPLITS 16
39 #define MAX_BANDS MAX_SPLITS + 1
40 
41 typedef struct BiquadContext {
42  double a0, a1, a2;
43  double b1, b2;
44  double i1, i2;
45  double o1, o2;
47 
48 typedef struct CrossoverChannel {
52 
53 typedef struct AudioCrossoverContext {
54  const AVClass *class;
55 
56  char *splits_str;
57  int order;
58 
60  int nb_splits;
61  float *splits;
62 
64 
68 
69 #define OFFSET(x) offsetof(AudioCrossoverContext, x)
70 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
71 
72 static const AVOption acrossover_options[] = {
73  { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
74  { "order", "set order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, "m" },
75  { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
76  { "4th", "4th order", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
77  { "8th", "8th order", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
78  { NULL }
79 };
80 
81 AVFILTER_DEFINE_CLASS(acrossover);
82 
84 {
86  char *p, *arg, *saveptr = NULL;
87  int i, ret = 0;
88 
89  s->splits = av_calloc(MAX_SPLITS, sizeof(*s->splits));
90  if (!s->splits)
91  return AVERROR(ENOMEM);
92 
93  p = s->splits_str;
94  for (i = 0; i < MAX_SPLITS; i++) {
95  float freq;
96 
97  if (!(arg = av_strtok(p, " |", &saveptr)))
98  break;
99 
100  p = NULL;
101 
102  av_sscanf(arg, "%f", &freq);
103  if (freq <= 0) {
104  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be positive number.\n", freq);
105  return AVERROR(EINVAL);
106  }
107 
108  if (i > 0 && freq <= s->splits[i-1]) {
109  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be in increasing order.\n", freq);
110  return AVERROR(EINVAL);
111  }
112 
113  s->splits[i] = freq;
114  }
115 
116  s->nb_splits = i;
117 
118  for (i = 0; i <= s->nb_splits; i++) {
119  AVFilterPad pad = { 0 };
120  char *name;
121 
122  pad.type = AVMEDIA_TYPE_AUDIO;
123  name = av_asprintf("out%d", ctx->nb_outputs);
124  if (!name)
125  return AVERROR(ENOMEM);
126  pad.name = name;
127 
128  if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
129  av_freep(&pad.name);
130  return ret;
131  }
132  }
133 
134  return ret;
135 }
136 
137 static void set_lp(BiquadContext *b, double fc, double q, double sr)
138 {
139  double omega = 2.0 * M_PI * fc / sr;
140  double sn = sin(omega);
141  double cs = cos(omega);
142  double alpha = sn / (2. * q);
143  double inv = 1.0 / (1.0 + alpha);
144 
145  b->a0 = (1. - cs) * 0.5 * inv;
146  b->a1 = (1. - cs) * inv;
147  b->a2 = b->a0;
148  b->b1 = -2. * cs * inv;
149  b->b2 = (1. - alpha) * inv;
150 }
151 
152 static void set_hp(BiquadContext *b, double fc, double q, double sr)
153 {
154  double omega = 2 * M_PI * fc / sr;
155  double sn = sin(omega);
156  double cs = cos(omega);
157  double alpha = sn / (2 * q);
158  double inv = 1.0 / (1.0 + alpha);
159 
160  b->a0 = inv * (1. + cs) / 2.;
161  b->a1 = -2. * b->a0;
162  b->a2 = b->a0;
163  b->b1 = -2. * cs * inv;
164  b->b2 = (1. - alpha) * inv;
165 }
166 
168 {
169  AVFilterContext *ctx = inlink->dst;
170  AudioCrossoverContext *s = ctx->priv;
171  int ch, band, sample_rate = inlink->sample_rate;
172  double q;
173 
174  s->xover = av_calloc(inlink->channels, sizeof(*s->xover));
175  if (!s->xover)
176  return AVERROR(ENOMEM);
177 
178  switch (s->order) {
179  case 0:
180  q = 0.5;
181  s->filter_count = 1;
182  break;
183  case 1:
184  q = M_SQRT1_2;
185  s->filter_count = 2;
186  break;
187  case 2:
188  q = 0.54;
189  s->filter_count = 4;
190  break;
191  }
192 
193  for (ch = 0; ch < inlink->channels; ch++) {
194  for (band = 0; band <= s->nb_splits; band++) {
195  set_lp(&s->xover[ch].lp[band][0], s->splits[band], q, sample_rate);
196  set_hp(&s->xover[ch].hp[band][0], s->splits[band], q, sample_rate);
197 
198  if (s->order > 1) {
199  set_lp(&s->xover[ch].lp[band][1], s->splits[band], 1.34, sample_rate);
200  set_hp(&s->xover[ch].hp[band][1], s->splits[band], 1.34, sample_rate);
201  set_lp(&s->xover[ch].lp[band][2], s->splits[band], q, sample_rate);
202  set_hp(&s->xover[ch].hp[band][2], s->splits[band], q, sample_rate);
203  set_lp(&s->xover[ch].lp[band][3], s->splits[band], 1.34, sample_rate);
204  set_hp(&s->xover[ch].hp[band][3], s->splits[band], 1.34, sample_rate);
205  } else {
206  set_lp(&s->xover[ch].lp[band][1], s->splits[band], q, sample_rate);
207  set_hp(&s->xover[ch].hp[band][1], s->splits[band], q, sample_rate);
208  }
209  }
210  }
211 
212  return 0;
213 }
214 
216 {
219  static const enum AVSampleFormat sample_fmts[] = {
222  };
223  int ret;
224 
225  layouts = ff_all_channel_counts();
226  if (!layouts)
227  return AVERROR(ENOMEM);
228  ret = ff_set_common_channel_layouts(ctx, layouts);
229  if (ret < 0)
230  return ret;
231 
232  formats = ff_make_format_list(sample_fmts);
233  if (!formats)
234  return AVERROR(ENOMEM);
235  ret = ff_set_common_formats(ctx, formats);
236  if (ret < 0)
237  return ret;
238 
239  formats = ff_all_samplerates();
240  if (!formats)
241  return AVERROR(ENOMEM);
242  return ff_set_common_samplerates(ctx, formats);
243 }
244 
245 static double biquad_process(BiquadContext *b, double in)
246 {
247  double out = in * b->a0 + b->i1 * b->a1 + b->i2 * b->a2 - b->o1 * b->b1 - b->o2 * b->b2;
248 
249  b->i2 = b->i1;
250  b->o2 = b->o1;
251  b->i1 = in;
252  b->o1 = out;
253 
254  return out;
255 }
256 
257 static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
258 {
259  AudioCrossoverContext *s = ctx->priv;
260  AVFrame *in = s->input_frame;
261  AVFrame **frames = s->frames;
262  const int start = (in->channels * jobnr) / nb_jobs;
263  const int end = (in->channels * (jobnr+1)) / nb_jobs;
264  int f, band;
265 
266  for (int ch = start; ch < end; ch++) {
267  const double *src = (const double *)in->extended_data[ch];
268  CrossoverChannel *xover = &s->xover[ch];
269 
270  for (int i = 0; i < in->nb_samples; i++) {
271  double sample = src[i], lo, hi;
272 
273  for (band = 0; band < ctx->nb_outputs; band++) {
274  double *dst = (double *)frames[band]->extended_data[ch];
275 
276  lo = sample;
277  hi = sample;
278  for (f = 0; band + 1 < ctx->nb_outputs && f < s->filter_count; f++) {
279  BiquadContext *lp = &xover->lp[band][f];
280  lo = biquad_process(lp, lo);
281  }
282 
283  for (f = 0; band + 1 < ctx->nb_outputs && f < s->filter_count; f++) {
284  BiquadContext *hp = &xover->hp[band][f];
285  hi = biquad_process(hp, hi);
286  }
287 
288  dst[i] = lo;
289 
290  sample = hi;
291  }
292  }
293  }
294 
295  return 0;
296 }
297 
299 {
300  AVFilterContext *ctx = inlink->dst;
301  AudioCrossoverContext *s = ctx->priv;
302  AVFrame **frames = s->frames;
303  int i, ret = 0;
304 
305  for (i = 0; i < ctx->nb_outputs; i++) {
306  frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
307 
308  if (!frames[i]) {
309  ret = AVERROR(ENOMEM);
310  break;
311  }
312 
313  frames[i]->pts = in->pts;
314  }
315 
316  if (ret < 0)
317  goto fail;
318 
319  s->input_frame = in;
320  ctx->internal->execute(ctx, filter_channels, NULL, NULL, FFMIN(inlink->channels,
322 
323  for (i = 0; i < ctx->nb_outputs; i++) {
324  ret = ff_filter_frame(ctx->outputs[i], frames[i]);
325  frames[i] = NULL;
326  if (ret < 0)
327  break;
328  }
329 
330 fail:
331  for (i = 0; i < ctx->nb_outputs; i++)
332  av_frame_free(&frames[i]);
333  av_frame_free(&in);
334  s->input_frame = NULL;
335 
336  return ret;
337 }
338 
340 {
341  AudioCrossoverContext *s = ctx->priv;
342  int i;
343 
344  av_freep(&s->splits);
345  av_freep(&s->xover);
346 
347  for (i = 0; i < ctx->nb_outputs; i++)
348  av_freep(&ctx->output_pads[i].name);
349 }
350 
351 static const AVFilterPad inputs[] = {
352  {
353  .name = "default",
354  .type = AVMEDIA_TYPE_AUDIO,
355  .filter_frame = filter_frame,
356  .config_props = config_input,
357  },
358  { NULL }
359 };
360 
362  .name = "acrossover",
363  .description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
364  .priv_size = sizeof(AudioCrossoverContext),
365  .priv_class = &acrossover_class,
366  .init = init,
367  .uninit = uninit,
369  .inputs = inputs,
370  .outputs = NULL,
373 };
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:550
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
static av_cold int init(AVFilterContext *ctx)
Definition: af_acrossover.c:83
AVOption.
Definition: opt.h:246
AVFrame * frames[MAX_BANDS]
Definition: af_acrossover.c:66
static int config_input(AVFilterLink *inlink)
static const AVFilterPad inputs[]
Main libavfilter public API header.
#define M_SQRT1_2
Definition: mathematics.h:58
double, planar
Definition: samplefmt.h:70
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
#define src
Definition: vp8dsp.c:254
#define sample
if it could not because there are no more frames
Macro definitions for various function/variable attributes.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:349
#define av_cold
Definition: attributes.h:82
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
BiquadContext lp[MAX_BANDS][4]
Definition: af_acrossover.c:49
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
Definition: avfilter.h:111
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:554
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:569
CrossoverChannel * xover
Definition: af_acrossover.c:63
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
unsigned nb_outputs
number of output pads
Definition: avfilter.h:351
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
const char * arg
Definition: jacosubdec.c:66
#define fail()
Definition: checkasm.h:122
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
BiquadContext hp[MAX_BANDS][4]
Definition: af_acrossover.c:50
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
common internal API header
static double biquad_process(BiquadContext *b, double in)
int channels
number of audio channels, only used for audio.
Definition: frame.h:601
audio channel layout utility functions
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:784
static void set_hp(BiquadContext *b, double fc, double q, double sr)
#define FFMIN(a, b)
Definition: common.h:96
static int query_formats(AVFilterContext *ctx)
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
static void set_lp(BiquadContext *b, double fc, double q, double sr)
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
A list of supported channel layouts.
Definition: formats.h:85
sample_rate
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static const int16_t alpha[]
Definition: ilbcdata.h:55
AVFILTER_DEFINE_CLASS(acrossover)
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
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63)))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){int planes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:394
#define flags(name, subs,...)
Definition: cbs_av1.c:564
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
AVFilter ff_af_acrossover
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
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:184
static av_cold void uninit(AVFilterContext *ctx)
avfilter_execute_func * execute
Definition: internal.h:144
#define AF
Definition: af_acrossover.c:70
double b[3]
Definition: af_aiir.c:42
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define OFFSET(x)
Definition: af_acrossover.c:69
An instance of a filter.
Definition: avfilter.h:338
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
FILE * out
Definition: movenc.c:54
#define MAX_SPLITS
Definition: af_acrossover.c:38
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:766
#define M_PI
Definition: mathematics.h:52
formats
Definition: signature.h:48
internal API functions
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
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:409
static const AVOption acrossover_options[]
Definition: af_acrossover.c:72
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:342
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:274
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:361
for(j=16;j >0;--j)
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:557
simple arithmetic expression evaluator
const char * name
Definition: opengl_enc.c:102
#define MAX_BANDS
Definition: af_acrossover.c:39