FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_agate.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen, Damien Zammit
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * Audio (Sidechain) Gate filter
24  */
25 
26 #include "libavutil/audio_fifo.h"
27 #include "libavutil/avassert.h"
29 #include "libavutil/opt.h"
30 #include "avfilter.h"
31 #include "audio.h"
32 #include "filters.h"
33 #include "formats.h"
34 #include "hermite.h"
35 
36 typedef struct AudioGateContext {
37  const AVClass *class;
38 
39  double level_in;
40  double level_sc;
41  double attack;
42  double release;
43  double threshold;
44  double ratio;
45  double knee;
46  double makeup;
47  double range;
48  int link;
49  int detection;
50 
51  double thres;
52  double knee_start;
53  double lin_knee_stop;
54  double knee_stop;
55  double lin_slope;
56  double attack_coeff;
57  double release_coeff;
58 
60  int64_t pts;
62 
63 #define OFFSET(x) offsetof(AudioGateContext, x)
64 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
65 
66 static const AVOption options[] = {
67  { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
68  { "range", "set max gain reduction", OFFSET(range), AV_OPT_TYPE_DOUBLE, {.dbl=0.06125}, 0, 1, A },
69  { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0, 1, A },
70  { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 9000, A },
71  { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 9000, A },
72  { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A },
73  { "makeup", "set makeup gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 64, A },
74  { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.828427125}, 1, 8, A },
75  { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A, "detection" },
76  { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "detection" },
77  { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "detection" },
78  { "link", "set link", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A, "link" },
79  { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "link" },
80  { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "link" },
81  { "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
82  { NULL }
83 };
84 
85 static int agate_config_input(AVFilterLink *inlink)
86 {
87  AVFilterContext *ctx = inlink->dst;
88  AudioGateContext *s = ctx->priv;
89  double lin_threshold = s->threshold;
90  double lin_knee_sqrt = sqrt(s->knee);
91  double lin_knee_start;
92 
93  if (s->detection)
94  lin_threshold *= lin_threshold;
95 
96  s->attack_coeff = FFMIN(1., 1. / (s->attack * inlink->sample_rate / 4000.));
97  s->release_coeff = FFMIN(1., 1. / (s->release * inlink->sample_rate / 4000.));
98  s->lin_knee_stop = lin_threshold * lin_knee_sqrt;
99  lin_knee_start = lin_threshold / lin_knee_sqrt;
100  s->thres = log(lin_threshold);
101  s->knee_start = log(lin_knee_start);
102  s->knee_stop = log(s->lin_knee_stop);
103 
104  return 0;
105 }
106 
107 // A fake infinity value (because real infinity may break some hosts)
108 #define FAKE_INFINITY (65536.0 * 65536.0)
109 
110 // Check for infinity (with appropriate-ish tolerance)
111 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
112 
113 static double output_gain(double lin_slope, double ratio, double thres,
114  double knee, double knee_start, double knee_stop,
115  double lin_knee_stop, double range)
116 {
117  if (lin_slope < lin_knee_stop) {
118  double slope = log(lin_slope);
119  double tratio = ratio;
120  double gain = 0.;
121  double delta = 0.;
122 
123  if (IS_FAKE_INFINITY(ratio))
124  tratio = 1000.;
125  gain = (slope - thres) * tratio + thres;
126  delta = tratio;
127 
128  if (knee > 1. && slope > knee_start) {
129  gain = hermite_interpolation(slope, knee_start, knee_stop, ((knee_start - thres) * tratio + thres), knee_stop, delta, 1.);
130  }
131  return FFMAX(range, exp(gain - slope));
132  }
133 
134  return 1.;
135 }
136 
137 static void gate(AudioGateContext *s,
138  const double *src, double *dst, const double *scsrc,
139  int nb_samples, double level_in, double level_sc,
140  AVFilterLink *inlink, AVFilterLink *sclink)
141 {
142  const double makeup = s->makeup;
143  const double attack_coeff = s->attack_coeff;
144  const double release_coeff = s->release_coeff;
145  int n, c;
146 
147  for (n = 0; n < nb_samples; n++, src += inlink->channels, dst += inlink->channels, scsrc += sclink->channels) {
148  double abs_sample = fabs(scsrc[0] * level_sc), gain = 1.0;
149 
150  if (s->link == 1) {
151  for (c = 1; c < sclink->channels; c++)
152  abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
153  } else {
154  for (c = 1; c < sclink->channels; c++)
155  abs_sample += fabs(scsrc[c] * level_sc);
156 
157  abs_sample /= sclink->channels;
158  }
159 
160  if (s->detection)
161  abs_sample *= abs_sample;
162 
163  s->lin_slope += (abs_sample - s->lin_slope) * (abs_sample > s->lin_slope ? attack_coeff : release_coeff);
164  if (s->lin_slope > 0.0)
165  gain = output_gain(s->lin_slope, s->ratio, s->thres,
166  s->knee, s->knee_start, s->knee_stop,
167  s->lin_knee_stop, s->range);
168 
169  for (c = 0; c < inlink->channels; c++)
170  dst[c] = src[c] * level_in * gain * makeup;
171  }
172 }
173 
174 #if CONFIG_AGATE_FILTER
175 
176 #define agate_options options
177 AVFILTER_DEFINE_CLASS(agate);
178 
179 static int query_formats(AVFilterContext *ctx)
180 {
183  int ret;
184 
185  if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBL)) < 0)
186  return ret;
187  ret = ff_set_common_formats(ctx, formats);
188  if (ret < 0)
189  return ret;
190 
191  layouts = ff_all_channel_counts();
192  if (!layouts)
193  return AVERROR(ENOMEM);
194  ret = ff_set_common_channel_layouts(ctx, layouts);
195  if (ret < 0)
196  return ret;
197 
198  formats = ff_all_samplerates();
199  if (!formats)
200  return AVERROR(ENOMEM);
201 
202  return ff_set_common_samplerates(ctx, formats);
203 }
204 
205 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
206 {
207  const double *src = (const double *)in->data[0];
208  AVFilterContext *ctx = inlink->dst;
209  AVFilterLink *outlink = ctx->outputs[0];
210  AudioGateContext *s = ctx->priv;
211  AVFrame *out;
212  double *dst;
213 
214  if (av_frame_is_writable(in)) {
215  out = in;
216  } else {
217  out = ff_get_audio_buffer(outlink, in->nb_samples);
218  if (!out) {
219  av_frame_free(&in);
220  return AVERROR(ENOMEM);
221  }
223  }
224  dst = (double *)out->data[0];
225 
226  gate(s, src, dst, src, in->nb_samples,
227  s->level_in, s->level_in, inlink, inlink);
228 
229  if (out != in)
230  av_frame_free(&in);
231  return ff_filter_frame(outlink, out);
232 }
233 
234 static const AVFilterPad inputs[] = {
235  {
236  .name = "default",
237  .type = AVMEDIA_TYPE_AUDIO,
238  .filter_frame = filter_frame,
239  .config_props = agate_config_input,
240  },
241  { NULL }
242 };
243 
244 static const AVFilterPad outputs[] = {
245  {
246  .name = "default",
247  .type = AVMEDIA_TYPE_AUDIO,
248  },
249  { NULL }
250 };
251 
253  .name = "agate",
254  .description = NULL_IF_CONFIG_SMALL("Audio gate."),
255  .query_formats = query_formats,
256  .priv_size = sizeof(AudioGateContext),
257  .priv_class = &agate_class,
258  .inputs = inputs,
259  .outputs = outputs,
260 };
261 
262 #endif /* CONFIG_AGATE_FILTER */
263 
264 #if CONFIG_SIDECHAINGATE_FILTER
265 
266 #define sidechaingate_options options
267 AVFILTER_DEFINE_CLASS(sidechaingate);
268 
269 static int activate(AVFilterContext *ctx)
270 {
271  AudioGateContext *s = ctx->priv;
272  AVFrame *out = NULL, *in[2] = { NULL };
273  int ret, i, nb_samples;
274  double *dst;
275 
277  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) {
278  av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data,
279  in[0]->nb_samples);
280  av_frame_free(&in[0]);
281  }
282  if (ret < 0)
283  return ret;
284  if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) {
285  av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data,
286  in[1]->nb_samples);
287  av_frame_free(&in[1]);
288  }
289  if (ret < 0)
290  return ret;
291 
292  nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1]));
293  if (nb_samples) {
294  out = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
295  if (!out)
296  return AVERROR(ENOMEM);
297  for (i = 0; i < 2; i++) {
298  in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
299  if (!in[i]) {
300  av_frame_free(&in[0]);
301  av_frame_free(&in[1]);
302  av_frame_free(&out);
303  return AVERROR(ENOMEM);
304  }
305  av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
306  }
307 
308  dst = (double *)out->data[0];
309  out->pts = s->pts;
310  s->pts += nb_samples;
311 
312  gate(s, (double *)in[0]->data[0], dst,
313  (double *)in[1]->data[0], nb_samples,
314  s->level_in, s->level_sc,
315  ctx->inputs[0], ctx->inputs[1]);
316 
317  av_frame_free(&in[0]);
318  av_frame_free(&in[1]);
319 
320  ret = ff_filter_frame(ctx->outputs[0], out);
321  if (ret < 0)
322  return ret;
323  }
324  FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
325  FF_FILTER_FORWARD_STATUS(ctx->inputs[1], ctx->outputs[0]);
326  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
327  if (!av_audio_fifo_size(s->fifo[0]))
329  if (!av_audio_fifo_size(s->fifo[1]))
331  }
332  return 0;
333 }
334 
335 static int scquery_formats(AVFilterContext *ctx)
336 {
338  AVFilterChannelLayouts *layouts = NULL;
339  static const enum AVSampleFormat sample_fmts[] = {
342  };
343  int ret, i;
344 
345  if (!ctx->inputs[0]->in_channel_layouts ||
347  av_log(ctx, AV_LOG_WARNING,
348  "No channel layout for input 1\n");
349  return AVERROR(EAGAIN);
350  }
351 
352  if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0])) < 0 ||
353  (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
354  return ret;
355 
356  for (i = 0; i < 2; i++) {
357  layouts = ff_all_channel_counts();
358  if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
359  return ret;
360  }
361 
362  formats = ff_make_format_list(sample_fmts);
363  if ((ret = ff_set_common_formats(ctx, formats)) < 0)
364  return ret;
365 
366  formats = ff_all_samplerates();
367  return ff_set_common_samplerates(ctx, formats);
368 }
369 
370 static int scconfig_output(AVFilterLink *outlink)
371 {
372  AVFilterContext *ctx = outlink->src;
373  AudioGateContext *s = ctx->priv;
374 
375  if (ctx->inputs[0]->sample_rate != ctx->inputs[1]->sample_rate) {
376  av_log(ctx, AV_LOG_ERROR,
377  "Inputs must have the same sample rate "
378  "%d for in0 vs %d for in1\n",
379  ctx->inputs[0]->sample_rate, ctx->inputs[1]->sample_rate);
380  return AVERROR(EINVAL);
381  }
382 
383  outlink->sample_rate = ctx->inputs[0]->sample_rate;
384  outlink->time_base = ctx->inputs[0]->time_base;
385  outlink->channel_layout = ctx->inputs[0]->channel_layout;
386  outlink->channels = ctx->inputs[0]->channels;
387 
388  s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
389  s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
390  if (!s->fifo[0] || !s->fifo[1])
391  return AVERROR(ENOMEM);
392 
393 
394  agate_config_input(ctx->inputs[0]);
395 
396  return 0;
397 }
398 
399 static av_cold void uninit(AVFilterContext *ctx)
400 {
401  AudioGateContext *s = ctx->priv;
402 
403  av_audio_fifo_free(s->fifo[0]);
404  av_audio_fifo_free(s->fifo[1]);
405 }
406 
407 static const AVFilterPad sidechaingate_inputs[] = {
408  {
409  .name = "main",
410  .type = AVMEDIA_TYPE_AUDIO,
411  },{
412  .name = "sidechain",
413  .type = AVMEDIA_TYPE_AUDIO,
414  },
415  { NULL }
416 };
417 
418 static const AVFilterPad sidechaingate_outputs[] = {
419  {
420  .name = "default",
421  .type = AVMEDIA_TYPE_AUDIO,
422  .config_props = scconfig_output,
423  },
424  { NULL }
425 };
426 
428  .name = "sidechaingate",
429  .description = NULL_IF_CONFIG_SMALL("Audio sidechain gate."),
430  .priv_size = sizeof(AudioGateContext),
431  .priv_class = &sidechaingate_class,
432  .query_formats = scquery_formats,
433  .activate = activate,
434  .uninit = uninit,
435  .inputs = sidechaingate_inputs,
436  .outputs = sidechaingate_outputs,
437 };
438 #endif /* CONFIG_SIDECHAINGATE_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:1481
#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
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:226
static int activate(AVFilterContext *ctx)
Definition: af_adelay.c:237
double lin_slope
Definition: af_agate.c:55
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#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:212
Main libavfilter public API header.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
static int agate_config_input(AVFilterLink *inlink)
Definition: af_agate.c:85
static void gate(AudioGateContext *s, const double *src, double *dst, const double *scsrc, int nb_samples, double level_in, double level_sc, AVFilterLink *inlink, AVFilterLink *sclink)
Definition: af_agate.c:137
#define src
Definition: vp8dsp.c:254
double level_in
Definition: af_agate.c:39
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1607
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
Definition: filters.h:172
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
double release
Definition: af_agate.c:42
double ratio
Definition: af_agate.c:44
const char * name
Pad name.
Definition: internal.h:60
#define IS_FAKE_INFINITY(value)
Definition: af_agate.c:111
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:1080
#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:319
double knee_start
Definition: af_agate.c:52
double makeup
Definition: af_agate.c:46
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
#define OFFSET(x)
Definition: af_agate.c:63
#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:202
#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
uint64_t * channel_layouts
list of channel layouts
Definition: formats.h:86
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
#define FFMAX(a, b)
Definition: common.h:94
int8_t exp
Definition: eval.c:72
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
double level_sc
Definition: af_agate.c:40
#define FFMIN(a, b)
Definition: common.h:96
AVFilter ff_af_sidechaingate
double lin_knee_stop
Definition: af_agate.c:53
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:684
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
double attack_coeff
Definition: af_agate.c:56
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
A list of supported channel layouts.
Definition: formats.h:85
int nb_samples
number of samples currently in the FIFO
Definition: audio_fifo.c:37
int64_t pts
Definition: af_agate.c:60
static const AVOption options[]
Definition: af_agate.c:66
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:594
double release_coeff
Definition: af_agate.c:57
double thres
Definition: af_agate.c:51
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
double threshold
Definition: af_agate.c:43
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:226
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
static int filter_frame(DBEContext *s, AVFrame *frame)
Definition: dolby_e.c:565
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
double knee_stop
Definition: af_agate.c:54
AVAudioFifo * fifo[2]
Definition: af_agate.c:59
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
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.
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:334
double range
Definition: af_agate.c:47
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
AVFilter ff_af_agate
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
static double output_gain(double lin_slope, double ratio, double thres, double knee, double knee_start, double knee_stop, double lin_knee_stop, double range)
Definition: af_agate.c:113
#define A
Definition: af_agate.c:64
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:292
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:654
double attack
Definition: af_agate.c:41