FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_sidechaincompress.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen and others
3  * Copyright (c) 2015 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Audio (Sidechain) Compressor filter
25  */
26 
27 #include "libavutil/audio_fifo.h"
28 #include "libavutil/avassert.h"
30 #include "libavutil/common.h"
31 #include "libavutil/opt.h"
32 
33 #include "audio.h"
34 #include "avfilter.h"
35 #include "filters.h"
36 #include "formats.h"
37 #include "hermite.h"
38 #include "internal.h"
39 
40 typedef struct SidechainCompressContext {
41  const AVClass *class;
42 
43  double level_in;
44  double level_sc;
47  double lin_slope;
48  double ratio;
49  double threshold;
50  double makeup;
51  double mix;
52  double thres;
53  double knee;
54  double knee_start;
55  double knee_stop;
59  int link;
60  int detection;
61 
63  int64_t pts;
65 
66 #define OFFSET(x) offsetof(SidechainCompressContext, x)
67 #define A AV_OPT_FLAG_AUDIO_PARAM
68 #define F AV_OPT_FLAG_FILTERING_PARAM
69 
70 static const AVOption options[] = {
71  { "level_in", "set input gain", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
72  { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F },
73  { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F },
74  { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F },
75  { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F },
76  { "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 64, A|F },
77  { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F },
78  { "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" },
79  { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" },
80  { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" },
81  { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" },
82  { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" },
83  { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" },
84  { "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
85  { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F },
86  { NULL }
87 };
88 
89 #define sidechaincompress_options options
90 AVFILTER_DEFINE_CLASS(sidechaincompress);
91 
92 // A fake infinity value (because real infinity may break some hosts)
93 #define FAKE_INFINITY (65536.0 * 65536.0)
94 
95 // Check for infinity (with appropriate-ish tolerance)
96 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
97 
98 static double output_gain(double lin_slope, double ratio, double thres,
99  double knee, double knee_start, double knee_stop,
100  double compressed_knee_stop, int detection)
101 {
102  double slope = log(lin_slope);
103  double gain = 0.0;
104  double delta = 0.0;
105 
106  if (detection)
107  slope *= 0.5;
108 
109  if (IS_FAKE_INFINITY(ratio)) {
110  gain = thres;
111  delta = 0.0;
112  } else {
113  gain = (slope - thres) / ratio + thres;
114  delta = 1.0 / ratio;
115  }
116 
117  if (knee > 1.0 && slope < knee_stop)
118  gain = hermite_interpolation(slope, knee_start, knee_stop,
119  knee_start, compressed_knee_stop,
120  1.0, delta);
121 
122  return exp(gain - slope);
123 }
124 
126 {
127  AVFilterContext *ctx = outlink->src;
129 
130  s->thres = log(s->threshold);
131  s->lin_knee_start = s->threshold / sqrt(s->knee);
133  s->knee_start = log(s->lin_knee_start);
134  s->knee_stop = log(s->threshold * sqrt(s->knee));
135  s->compressed_knee_stop = (s->knee_stop - s->thres) / s->ratio + s->thres;
136 
137  s->attack_coeff = FFMIN(1., 1. / (s->attack * outlink->sample_rate / 4000.));
138  s->release_coeff = FFMIN(1., 1. / (s->release * outlink->sample_rate / 4000.));
139 
140  return 0;
141 }
142 
144  const double *src, double *dst, const double *scsrc, int nb_samples,
145  double level_in, double level_sc,
146  AVFilterLink *inlink, AVFilterLink *sclink)
147 {
148  const double makeup = s->makeup;
149  const double mix = s->mix;
150  int i, c;
151 
152  for (i = 0; i < nb_samples; i++) {
153  double abs_sample, gain = 1.0;
154 
155  abs_sample = fabs(scsrc[0] * level_sc);
156 
157  if (s->link == 1) {
158  for (c = 1; c < sclink->channels; c++)
159  abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
160  } else {
161  for (c = 1; c < sclink->channels; c++)
162  abs_sample += fabs(scsrc[c] * level_sc);
163 
164  abs_sample /= sclink->channels;
165  }
166 
167  if (s->detection)
168  abs_sample *= abs_sample;
169 
170  s->lin_slope += (abs_sample - s->lin_slope) * (abs_sample > s->lin_slope ? s->attack_coeff : s->release_coeff);
171 
172  if (s->lin_slope > 0.0 && s->lin_slope > (s->detection ? s->adj_knee_start : s->lin_knee_start))
173  gain = output_gain(s->lin_slope, s->ratio, s->thres, s->knee,
174  s->knee_start, s->knee_stop,
176 
177  for (c = 0; c < inlink->channels; c++)
178  dst[c] = src[c] * level_in * (gain * makeup * mix + (1. - mix));
179 
180  src += inlink->channels;
181  dst += inlink->channels;
182  scsrc += sclink->channels;
183  }
184 }
185 
186 #if CONFIG_SIDECHAINCOMPRESS_FILTER
187 static int activate(AVFilterContext *ctx)
188 {
190  AVFrame *out = NULL, *in[2] = { NULL };
191  int ret, i, nb_samples;
192  double *dst;
193 
195  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) {
196  av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data,
197  in[0]->nb_samples);
198  av_frame_free(&in[0]);
199  }
200  if (ret < 0)
201  return ret;
202  if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) {
203  av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data,
204  in[1]->nb_samples);
205  av_frame_free(&in[1]);
206  }
207  if (ret < 0)
208  return ret;
209 
210  nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1]));
211  if (nb_samples) {
212  out = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
213  if (!out)
214  return AVERROR(ENOMEM);
215  for (i = 0; i < 2; i++) {
216  in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
217  if (!in[i]) {
218  av_frame_free(&in[0]);
219  av_frame_free(&in[1]);
220  av_frame_free(&out);
221  return AVERROR(ENOMEM);
222  }
223  av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
224  }
225 
226  dst = (double *)out->data[0];
227  out->pts = s->pts;
228  s->pts += nb_samples;
229 
230  compressor(s, (double *)in[0]->data[0], dst,
231  (double *)in[1]->data[0], nb_samples,
232  s->level_in, s->level_sc,
233  ctx->inputs[0], ctx->inputs[1]);
234 
235  av_frame_free(&in[0]);
236  av_frame_free(&in[1]);
237 
238  ret = ff_filter_frame(ctx->outputs[0], out);
239  if (ret < 0)
240  return ret;
241  }
242  FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
243  FF_FILTER_FORWARD_STATUS(ctx->inputs[1], ctx->outputs[0]);
244  /* TODO reindent */
245  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
246  if (!av_audio_fifo_size(s->fifo[0]))
248  if (!av_audio_fifo_size(s->fifo[1]))
250  }
251  return 0;
252 }
253 
254 static int query_formats(AVFilterContext *ctx)
255 {
258  static const enum AVSampleFormat sample_fmts[] = {
261  };
262  int ret, i;
263 
264  if (!ctx->inputs[0]->in_channel_layouts ||
266  av_log(ctx, AV_LOG_WARNING,
267  "No channel layout for input 1\n");
268  return AVERROR(EAGAIN);
269  }
270 
271  if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0])) < 0 ||
272  (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
273  return ret;
274 
275  for (i = 0; i < 2; i++) {
276  layouts = ff_all_channel_counts();
277  if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
278  return ret;
279  }
280 
281  formats = ff_make_format_list(sample_fmts);
282  if ((ret = ff_set_common_formats(ctx, formats)) < 0)
283  return ret;
284 
285  formats = ff_all_samplerates();
286  return ff_set_common_samplerates(ctx, formats);
287 }
288 
289 static int config_output(AVFilterLink *outlink)
290 {
291  AVFilterContext *ctx = outlink->src;
292  SidechainCompressContext *s = ctx->priv;
293 
294  if (ctx->inputs[0]->sample_rate != ctx->inputs[1]->sample_rate) {
295  av_log(ctx, AV_LOG_ERROR,
296  "Inputs must have the same sample rate "
297  "%d for in0 vs %d for in1\n",
298  ctx->inputs[0]->sample_rate, ctx->inputs[1]->sample_rate);
299  return AVERROR(EINVAL);
300  }
301 
302  outlink->sample_rate = ctx->inputs[0]->sample_rate;
303  outlink->time_base = ctx->inputs[0]->time_base;
304  outlink->channel_layout = ctx->inputs[0]->channel_layout;
305  outlink->channels = ctx->inputs[0]->channels;
306 
307  s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
308  s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
309  if (!s->fifo[0] || !s->fifo[1])
310  return AVERROR(ENOMEM);
311 
312  compressor_config_output(outlink);
313 
314  return 0;
315 }
316 
317 static av_cold void uninit(AVFilterContext *ctx)
318 {
319  SidechainCompressContext *s = ctx->priv;
320 
321  av_audio_fifo_free(s->fifo[0]);
322  av_audio_fifo_free(s->fifo[1]);
323 }
324 
325 static const AVFilterPad sidechaincompress_inputs[] = {
326  {
327  .name = "main",
328  .type = AVMEDIA_TYPE_AUDIO,
329  },{
330  .name = "sidechain",
331  .type = AVMEDIA_TYPE_AUDIO,
332  },
333  { NULL }
334 };
335 
336 static const AVFilterPad sidechaincompress_outputs[] = {
337  {
338  .name = "default",
339  .type = AVMEDIA_TYPE_AUDIO,
340  .config_props = config_output,
341  },
342  { NULL }
343 };
344 
345 AVFilter ff_af_sidechaincompress = {
346  .name = "sidechaincompress",
347  .description = NULL_IF_CONFIG_SMALL("Sidechain compressor."),
348  .priv_size = sizeof(SidechainCompressContext),
349  .priv_class = &sidechaincompress_class,
351  .activate = activate,
352  .uninit = uninit,
353  .inputs = sidechaincompress_inputs,
354  .outputs = sidechaincompress_outputs,
355 };
356 #endif /* CONFIG_SIDECHAINCOMPRESS_FILTER */
357 
358 #if CONFIG_ACOMPRESSOR_FILTER
359 static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *in)
360 {
361  const double *src = (const double *)in->data[0];
362  AVFilterContext *ctx = inlink->dst;
363  SidechainCompressContext *s = ctx->priv;
364  AVFilterLink *outlink = ctx->outputs[0];
365  AVFrame *out;
366  double *dst;
367 
368  if (av_frame_is_writable(in)) {
369  out = in;
370  } else {
371  out = ff_get_audio_buffer(inlink, in->nb_samples);
372  if (!out) {
373  av_frame_free(&in);
374  return AVERROR(ENOMEM);
375  }
376  av_frame_copy_props(out, in);
377  }
378  dst = (double *)out->data[0];
379 
380  compressor(s, src, dst, src, in->nb_samples,
381  s->level_in, s->level_in,
382  inlink, inlink);
383 
384  if (out != in)
385  av_frame_free(&in);
386  return ff_filter_frame(outlink, out);
387 }
388 
389 static int acompressor_query_formats(AVFilterContext *ctx)
390 {
393  static const enum AVSampleFormat sample_fmts[] = {
396  };
397  int ret;
398 
399  layouts = ff_all_channel_counts();
400  if (!layouts)
401  return AVERROR(ENOMEM);
402  ret = ff_set_common_channel_layouts(ctx, layouts);
403  if (ret < 0)
404  return ret;
405 
406  formats = ff_make_format_list(sample_fmts);
407  if (!formats)
408  return AVERROR(ENOMEM);
409  ret = ff_set_common_formats(ctx, formats);
410  if (ret < 0)
411  return ret;
412 
413  formats = ff_all_samplerates();
414  if (!formats)
415  return AVERROR(ENOMEM);
416  return ff_set_common_samplerates(ctx, formats);
417 }
418 
419 #define acompressor_options options
420 AVFILTER_DEFINE_CLASS(acompressor);
421 
422 static const AVFilterPad acompressor_inputs[] = {
423  {
424  .name = "default",
425  .type = AVMEDIA_TYPE_AUDIO,
426  .filter_frame = acompressor_filter_frame,
427  },
428  { NULL }
429 };
430 
431 static const AVFilterPad acompressor_outputs[] = {
432  {
433  .name = "default",
434  .type = AVMEDIA_TYPE_AUDIO,
435  .config_props = compressor_config_output,
436  },
437  { NULL }
438 };
439 
440 AVFilter ff_af_acompressor = {
441  .name = "acompressor",
442  .description = NULL_IF_CONFIG_SMALL("Audio compressor."),
443  .priv_size = sizeof(SidechainCompressContext),
444  .priv_class = &acompressor_class,
445  .query_formats = acompressor_query_formats,
446  .inputs = acompressor_inputs,
447  .outputs = acompressor_outputs,
448 };
449 #endif /* CONFIG_ACOMPRESSOR_FILTER */
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1542
#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
const char * s
Definition: avisynth_c.h:768
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static double output_gain(double lin_slope, double ratio, double thres, double knee, double knee_start, double knee_stop, double compressed_knee_stop, int detection)
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:192
Main libavfilter public API header.
#define F
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
#define src
Definition: vp8dsp.c:254
static int compressor_config_output(AVFilterLink *outlink)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1663
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: filters.h:152
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
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1151
static int activate(AVFilterContext *ctx)
Definition: af_amix.c:404
#define av_cold
Definition: attributes.h:82
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
float delta
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:294
#define A
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
#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
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
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:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void * priv
private data for use by the filter
Definition: avfilter.h:353
uint64_t * channel_layouts
list of channel layouts
Definition: formats.h:86
static int config_output(AVFilterLink *outlink)
Definition: af_aecho.c:232
#define OFFSET(x)
simple assert() macros that are a bit more flexible than ISO C assert().
#define FFMAX(a, b)
Definition: common.h:94
AVFILTER_DEFINE_CLASS(sidechaincompress)
int8_t exp
Definition: eval.c:65
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
audio channel layout utility functions
static double hermite_interpolation(double x, double x0, double x1, double p0, double p1, double m0, double m1)
Definition: hermite.h:22
#define FFMIN(a, b)
Definition: common.h:96
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
A list of supported channel layouts.
Definition: formats.h:85
static void compressor(SidechainCompressContext *s, const double *src, double *dst, const double *scsrc, int nb_samples, double level_in, double level_sc, AVFilterLink *inlink, AVFilterLink *sclink)
int nb_samples
number of samples currently in the FIFO
Definition: audio_fifo.c:37
#define IS_FAKE_INFINITY(value)
static int mix(int c0, int c1)
Definition: 4xm.c:707
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:543
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
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
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
Definition: filters.h:206
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
static const AVOption options[]
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
static double c[64]
Audio FIFO Buffer.
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
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
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603