FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/internal.h"
30 #include "libavutil/opt.h"
31 
32 #include "audio.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 
37 #define MAX_SPLITS 16
38 #define MAX_BANDS MAX_SPLITS + 1
39 
40 typedef struct BiquadContext {
41  double a0, a1, a2;
42  double b1, b2;
43  double i1, i2;
44  double o1, o2;
46 
47 typedef struct CrossoverChannel {
51 
52 typedef struct AudioCrossoverContext {
53  const AVClass *class;
54 
55  char *splits_str;
56  int order;
57 
59  int nb_splits;
60  float *splits;
61 
64 
65 #define OFFSET(x) offsetof(AudioCrossoverContext, x)
66 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
67 
68 static const AVOption acrossover_options[] = {
69  { "split", "set split frequencies", OFFSET(splits_str), AV_OPT_TYPE_STRING, {.str="500"}, 0, 0, AF },
70  { "order", "set order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=1}, 0, 2, AF, "m" },
71  { "2nd", "2nd order", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
72  { "4th", "4th order", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
73  { "8th", "8th order", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, AF, "m" },
74  { NULL }
75 };
76 
77 AVFILTER_DEFINE_CLASS(acrossover);
78 
80 {
82  char *p, *arg, *saveptr = NULL;
83  int i, ret = 0;
84 
85  s->splits = av_calloc(MAX_SPLITS, sizeof(*s->splits));
86  if (!s->splits)
87  return AVERROR(ENOMEM);
88 
89  p = s->splits_str;
90  for (i = 0; i < MAX_SPLITS; i++) {
91  float freq;
92 
93  if (!(arg = av_strtok(p, " |", &saveptr)))
94  break;
95 
96  p = NULL;
97 
98  ret = sscanf(arg, "%f", &freq);
99 
100  if (freq <= 0) {
101  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be positive number.\n", freq);
102  return AVERROR(EINVAL);
103  }
104 
105  if (i > 0 && freq <= s->splits[i-1]) {
106  av_log(ctx, AV_LOG_ERROR, "Frequency %f must be in increasing order.\n", freq);
107  return AVERROR(EINVAL);
108  }
109 
110  s->splits[i] = freq;
111  }
112 
113  s->nb_splits = i;
114 
115  for (i = 0; i <= s->nb_splits; i++) {
116  AVFilterPad pad = { 0 };
117  char *name;
118 
119  pad.type = AVMEDIA_TYPE_AUDIO;
120  name = av_asprintf("out%d", ctx->nb_outputs);
121  if (!name)
122  return AVERROR(ENOMEM);
123  pad.name = name;
124 
125  if ((ret = ff_insert_outpad(ctx, i, &pad)) < 0) {
126  av_freep(&pad.name);
127  return ret;
128  }
129  }
130 
131  return ret;
132 }
133 
134 static void set_lp(BiquadContext *b, float fc, float q, float sr)
135 {
136  double omega = (2.0 * M_PI * fc / sr);
137  double sn = sin(omega);
138  double cs = cos(omega);
139  double alpha = (sn / (2 * q));
140  double inv = (1.0 / (1.0 + alpha));
141 
142  b->a2 = b->a0 = (inv * (1.0 - cs) * 0.5);
143  b->a1 = b->a0 + b->a0;
144  b->b1 = -2. * cs * inv;
145  b->b2 = (1. - alpha) * inv;
146 }
147 
148 static void set_hp(BiquadContext *b, float fc, float q, float sr)
149 {
150  double omega = 2 * M_PI * fc / sr;
151  double sn = sin(omega);
152  double cs = cos(omega);
153  double alpha = sn / (2 * q);
154  double inv = 1.0 / (1.0 + alpha);
155 
156  b->a0 = inv * (1. + cs) / 2.;
157  b->a1 = -2. * b->a0;
158  b->a2 = b->a0;
159  b->b1 = -2. * cs * inv;
160  b->b2 = (1. - alpha) * inv;
161 }
162 
163 static int config_input(AVFilterLink *inlink)
164 {
165  AVFilterContext *ctx = inlink->dst;
166  AudioCrossoverContext *s = ctx->priv;
167  int ch, band, sample_rate = inlink->sample_rate;
168  double q;
169 
170  s->xover = av_calloc(inlink->channels, sizeof(*s->xover));
171  if (!s->xover)
172  return AVERROR(ENOMEM);
173 
174  switch (s->order) {
175  case 0:
176  q = 0.5;
177  s->filter_count = 1;
178  break;
179  case 1:
180  q = M_SQRT1_2;
181  s->filter_count = 2;
182  break;
183  case 2:
184  q = 0.54;
185  s->filter_count = 4;
186  break;
187  }
188 
189  for (ch = 0; ch < inlink->channels; ch++) {
190  for (band = 0; band <= s->nb_splits; band++) {
191  set_lp(&s->xover[ch].lp[band][0], s->splits[band], q, sample_rate);
192  set_hp(&s->xover[ch].hp[band][0], s->splits[band], q, sample_rate);
193 
194  if (s->order > 1) {
195  set_lp(&s->xover[ch].lp[band][1], s->splits[band], 1.34, sample_rate);
196  set_hp(&s->xover[ch].hp[band][1], s->splits[band], 1.34, sample_rate);
197  set_lp(&s->xover[ch].lp[band][2], s->splits[band], q, sample_rate);
198  set_hp(&s->xover[ch].hp[band][2], s->splits[band], q, sample_rate);
199  set_lp(&s->xover[ch].lp[band][3], s->splits[band], 1.34, sample_rate);
200  set_hp(&s->xover[ch].hp[band][3], s->splits[band], 1.34, sample_rate);
201  } else {
202  set_lp(&s->xover[ch].lp[band][1], s->splits[band], q, sample_rate);
203  set_hp(&s->xover[ch].hp[band][1], s->splits[band], q, sample_rate);
204  }
205  }
206  }
207 
208  return 0;
209 }
210 
212 {
215  static const enum AVSampleFormat sample_fmts[] = {
218  };
219  int ret;
220 
221  layouts = ff_all_channel_counts();
222  if (!layouts)
223  return AVERROR(ENOMEM);
224  ret = ff_set_common_channel_layouts(ctx, layouts);
225  if (ret < 0)
226  return ret;
227 
228  formats = ff_make_format_list(sample_fmts);
229  if (!formats)
230  return AVERROR(ENOMEM);
231  ret = ff_set_common_formats(ctx, formats);
232  if (ret < 0)
233  return ret;
234 
235  formats = ff_all_samplerates();
236  if (!formats)
237  return AVERROR(ENOMEM);
238  return ff_set_common_samplerates(ctx, formats);
239 }
240 
241 static double biquad_process(BiquadContext *b, double in)
242 {
243  double out = in * b->a0 + b->i1 * b->a1 + b->i2 * b->a2 - b->o1 * b->b1 - b->o2 * b->b2;
244 
245  b->i2 = b->i1;
246  b->o2 = b->o1;
247  b->i1 = in;
248  b->o1 = out;
249 
250  return out;
251 }
252 
253 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
254 {
255  AVFilterContext *ctx = inlink->dst;
256  AudioCrossoverContext *s = ctx->priv;
257  AVFrame *frames[MAX_BANDS] = { NULL };
258  int i, f, ch, band, ret = 0;
259 
260  for (i = 0; i < ctx->nb_outputs; i++) {
261  frames[i] = ff_get_audio_buffer(ctx->outputs[i], in->nb_samples);
262 
263  if (!frames[i]) {
264  ret = AVERROR(ENOMEM);
265  break;
266  }
267 
268  frames[i]->pts = in->pts;
269  }
270 
271  if (ret < 0)
272  goto fail;
273 
274  for (ch = 0; ch < inlink->channels; ch++) {
275  const double *src = (const double *)in->extended_data[ch];
276  CrossoverChannel *xover = &s->xover[ch];
277 
278  for (band = 0; band < ctx->nb_outputs; band++) {
279  double *dst = (double *)frames[band]->extended_data[ch];
280 
281  for (i = 0; i < in->nb_samples; i++) {
282  dst[i] = src[i];
283 
284  for (f = 0; f < s->filter_count; f++) {
285  if (band + 1 < ctx->nb_outputs) {
286  BiquadContext *lp = &xover->lp[band][f];
287  dst[i] = biquad_process(lp, dst[i]);
288  }
289 
290  if (band - 1 >= 0) {
291  BiquadContext *hp = &xover->hp[band - 1][f];
292  dst[i] = biquad_process(hp, dst[i]);
293  }
294  }
295  }
296  }
297  }
298 
299  for (i = 0; i < ctx->nb_outputs; i++) {
300  ret = ff_filter_frame(ctx->outputs[i], frames[i]);
301  if (ret < 0)
302  break;
303  }
304 
305 fail:
306  av_frame_free(&in);
307 
308  return ret;
309 }
310 
312 {
313  AudioCrossoverContext *s = ctx->priv;
314  int i;
315 
316  av_freep(&s->splits);
317 
318  for (i = 0; i < ctx->nb_outputs; i++)
319  av_freep(&ctx->output_pads[i].name);
320 }
321 
322 static const AVFilterPad inputs[] = {
323  {
324  .name = "default",
325  .type = AVMEDIA_TYPE_AUDIO,
326  .filter_frame = filter_frame,
327  .config_props = config_input,
328  },
329  { NULL }
330 };
331 
333  .name = "acrossover",
334  .description = NULL_IF_CONFIG_SMALL("Split audio into per-bands streams."),
335  .priv_size = sizeof(AudioCrossoverContext),
336  .priv_class = &acrossover_class,
337  .init = init,
338  .uninit = uninit,
340  .inputs = inputs,
341  .outputs = NULL,
343 };
#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:549
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
static av_cold int init(AVFilterContext *ctx)
Definition: af_acrossover.c:79
AVOption.
Definition: opt.h:246
static int config_input(AVFilterLink *inlink)
static const AVFilterPad inputs[]
Main libavfilter public API header.
#define M_SQRT1_2
Definition: mathematics.h:58
const char * b
Definition: vf_curves.c:116
double, planar
Definition: samplefmt.h:70
static void set_lp(BiquadContext *b, float fc, float q, float sr)
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
#define src
Definition: vp8dsp.c:254
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:1080
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
BiquadContext lp[MAX_BANDS][4]
Definition: af_acrossover.c:48
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:319
#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:586
#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:568
CrossoverChannel * xover
Definition: af_acrossover.c:62
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
#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:202
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
const char * arg
Definition: jacosubdec.c:66
#define fail()
Definition: checkasm.h:117
BiquadContext hp[MAX_BANDS][4]
Definition: af_acrossover.c:49
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
common internal API header
static double biquad_process(BiquadContext *b, double in)
audio channel layout utility functions
static int query_formats(AVFilterContext *ctx)
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
int frames
Definition: movenc.c:65
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
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
AVFILTER_DEFINE_CLASS(acrossover)
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
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
#define flags(name, subs,...)
Definition: cbs_av1.c:596
AVFilter ff_af_acrossover
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)
static void set_hp(BiquadContext *b, float fc, float q, float sr)
#define AF
Definition: af_acrossover.c:66
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define OFFSET(x)
Definition: af_acrossover.c:65
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:37
#define av_freep(p)
#define M_PI
Definition: mathematics.h:52
formats
Definition: signature.h:48
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
static const AVOption acrossover_options[]
Definition: af_acrossover.c:68
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:273
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
Definition: internal.h:285
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:292
for(j=16;j >0;--j)
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8: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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
const char * name
Definition: opengl_enc.c:103
#define MAX_BANDS
Definition: af_acrossover.c:38