FFmpeg
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  int mode;
51 
52  double thres;
53  double knee_start;
54  double knee_stop;
56  double lin_knee_stop;
57  double lin_slope;
58  double attack_coeff;
59  double release_coeff;
60 
62  int64_t pts;
64 
65 #define OFFSET(x) offsetof(AudioGateContext, x)
66 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
67 
68 static const AVOption options[] = {
69  { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
70  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A, "mode" },
71  { "downward",0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "mode" },
72  { "upward", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "mode" },
73  { "range", "set max gain reduction", OFFSET(range), AV_OPT_TYPE_DOUBLE, {.dbl=0.06125}, 0, 1, A },
74  { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0, 1, A },
75  { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 9000, A },
76  { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 9000, A },
77  { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A },
78  { "makeup", "set makeup gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 64, A },
79  { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.828427125}, 1, 8, A },
80  { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A, "detection" },
81  { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "detection" },
82  { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "detection" },
83  { "link", "set link", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A, "link" },
84  { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "link" },
85  { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "link" },
86  { "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
87  { NULL }
88 };
89 
91 {
92  AVFilterContext *ctx = inlink->dst;
93  AudioGateContext *s = ctx->priv;
94  double lin_threshold = s->threshold;
95  double lin_knee_sqrt = sqrt(s->knee);
96 
97  if (s->detection)
98  lin_threshold *= lin_threshold;
99 
100  s->attack_coeff = FFMIN(1., 1. / (s->attack * inlink->sample_rate / 4000.));
101  s->release_coeff = FFMIN(1., 1. / (s->release * inlink->sample_rate / 4000.));
102  s->lin_knee_stop = lin_threshold * lin_knee_sqrt;
103  s->lin_knee_start = lin_threshold / lin_knee_sqrt;
104  s->thres = log(lin_threshold);
105  s->knee_start = log(s->lin_knee_start);
106  s->knee_stop = log(s->lin_knee_stop);
107 
108  return 0;
109 }
110 
111 // A fake infinity value (because real infinity may break some hosts)
112 #define FAKE_INFINITY (65536.0 * 65536.0)
113 
114 // Check for infinity (with appropriate-ish tolerance)
115 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
116 
117 static double output_gain(double lin_slope, double ratio, double thres,
118  double knee, double knee_start, double knee_stop,
119  double range, int mode)
120 {
121  double slope = log(lin_slope);
122  double tratio = ratio;
123  double gain = 0.;
124  double delta = 0.;
125 
126  if (IS_FAKE_INFINITY(ratio))
127  tratio = 1000.;
128  gain = (slope - thres) * tratio + thres;
129  delta = tratio;
130 
131  if (mode) {
132  if (knee > 1. && slope < knee_stop)
133  gain = hermite_interpolation(slope, knee_stop, knee_start, ((knee_stop - thres) * tratio + thres), knee_start, delta, 1.);
134  } else {
135  if (knee > 1. && slope > knee_start)
136  gain = hermite_interpolation(slope, knee_start, knee_stop, ((knee_start - thres) * tratio + thres), knee_stop, delta, 1.);
137  }
138  return FFMAX(range, exp(gain - slope));
139 }
140 
141 static void gate(AudioGateContext *s,
142  const double *src, double *dst, const double *scsrc,
143  int nb_samples, double level_in, double level_sc,
144  AVFilterLink *inlink, AVFilterLink *sclink)
145 {
146  const double makeup = s->makeup;
147  const double attack_coeff = s->attack_coeff;
148  const double release_coeff = s->release_coeff;
149  int n, c;
150 
151  for (n = 0; n < nb_samples; n++, src += inlink->channels, dst += inlink->channels, scsrc += sclink->channels) {
152  double abs_sample = fabs(scsrc[0] * level_sc), gain = 1.0;
153  int detected;
154 
155  if (s->link == 1) {
156  for (c = 1; c < sclink->channels; c++)
157  abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
158  } else {
159  for (c = 1; c < sclink->channels; c++)
160  abs_sample += fabs(scsrc[c] * level_sc);
161 
162  abs_sample /= sclink->channels;
163  }
164 
165  if (s->detection)
166  abs_sample *= abs_sample;
167 
168  s->lin_slope += (abs_sample - s->lin_slope) * (abs_sample > s->lin_slope ? attack_coeff : release_coeff);
169 
170  if (s->mode)
171  detected = s->lin_slope > s->lin_knee_start;
172  else
173  detected = s->lin_slope < s->lin_knee_stop;
174 
175  if (s->lin_slope > 0.0 && detected)
176  gain = output_gain(s->lin_slope, s->ratio, s->thres,
177  s->knee, s->knee_start, s->knee_stop,
178  s->range, s->mode);
179 
180  for (c = 0; c < inlink->channels; c++)
181  dst[c] = src[c] * level_in * gain * makeup;
182  }
183 }
184 
185 #if CONFIG_AGATE_FILTER
186 
187 #define agate_options options
188 AVFILTER_DEFINE_CLASS(agate);
189 
190 static int query_formats(AVFilterContext *ctx)
191 {
194  int ret;
195 
197  return ret;
199  if (ret < 0)
200  return ret;
201 
203  if (!layouts)
204  return AVERROR(ENOMEM);
206  if (ret < 0)
207  return ret;
208 
210  if (!formats)
211  return AVERROR(ENOMEM);
212 
214 }
215 
217 {
218  const double *src = (const double *)in->data[0];
219  AVFilterContext *ctx = inlink->dst;
220  AVFilterLink *outlink = ctx->outputs[0];
221  AudioGateContext *s = ctx->priv;
222  AVFrame *out;
223  double *dst;
224 
226  out = in;
227  } else {
228  out = ff_get_audio_buffer(outlink, in->nb_samples);
229  if (!out) {
230  av_frame_free(&in);
231  return AVERROR(ENOMEM);
232  }
234  }
235  dst = (double *)out->data[0];
236 
237  gate(s, src, dst, src, in->nb_samples,
238  s->level_in, s->level_in, inlink, inlink);
239 
240  if (out != in)
241  av_frame_free(&in);
242  return ff_filter_frame(outlink, out);
243 }
244 
245 static const AVFilterPad inputs[] = {
246  {
247  .name = "default",
248  .type = AVMEDIA_TYPE_AUDIO,
249  .filter_frame = filter_frame,
250  .config_props = agate_config_input,
251  },
252  { NULL }
253 };
254 
255 static const AVFilterPad outputs[] = {
256  {
257  .name = "default",
258  .type = AVMEDIA_TYPE_AUDIO,
259  },
260  { NULL }
261 };
262 
264  .name = "agate",
265  .description = NULL_IF_CONFIG_SMALL("Audio gate."),
266  .query_formats = query_formats,
267  .priv_size = sizeof(AudioGateContext),
268  .priv_class = &agate_class,
269  .inputs = inputs,
270  .outputs = outputs,
273 };
274 
275 #endif /* CONFIG_AGATE_FILTER */
276 
277 #if CONFIG_SIDECHAINGATE_FILTER
278 
279 #define sidechaingate_options options
280 AVFILTER_DEFINE_CLASS(sidechaingate);
281 
282 static int activate(AVFilterContext *ctx)
283 {
284  AudioGateContext *s = ctx->priv;
285  AVFrame *out = NULL, *in[2] = { NULL };
286  int ret, i, nb_samples;
287  double *dst;
288 
290  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) {
291  av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data,
292  in[0]->nb_samples);
293  av_frame_free(&in[0]);
294  }
295  if (ret < 0)
296  return ret;
297  if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) {
298  av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data,
299  in[1]->nb_samples);
300  av_frame_free(&in[1]);
301  }
302  if (ret < 0)
303  return ret;
304 
305  nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1]));
306  if (nb_samples) {
307  out = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
308  if (!out)
309  return AVERROR(ENOMEM);
310  for (i = 0; i < 2; i++) {
311  in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
312  if (!in[i]) {
313  av_frame_free(&in[0]);
314  av_frame_free(&in[1]);
315  av_frame_free(&out);
316  return AVERROR(ENOMEM);
317  }
318  av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
319  }
320 
321  dst = (double *)out->data[0];
322  out->pts = s->pts;
323  s->pts += av_rescale_q(nb_samples, (AVRational){1, ctx->outputs[0]->sample_rate}, ctx->outputs[0]->time_base);
324 
325  gate(s, (double *)in[0]->data[0], dst,
326  (double *)in[1]->data[0], nb_samples,
327  s->level_in, s->level_sc,
328  ctx->inputs[0], ctx->inputs[1]);
329 
330  av_frame_free(&in[0]);
331  av_frame_free(&in[1]);
332 
333  ret = ff_filter_frame(ctx->outputs[0], out);
334  if (ret < 0)
335  return ret;
336  }
337  FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
338  FF_FILTER_FORWARD_STATUS(ctx->inputs[1], ctx->outputs[0]);
339  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
340  if (!av_audio_fifo_size(s->fifo[0]))
341  ff_inlink_request_frame(ctx->inputs[0]);
342  if (!av_audio_fifo_size(s->fifo[1]))
343  ff_inlink_request_frame(ctx->inputs[1]);
344  }
345  return 0;
346 }
347 
348 static int scquery_formats(AVFilterContext *ctx)
349 {
352  static const enum AVSampleFormat sample_fmts[] = {
355  };
356  int ret, i;
357 
358  if (!ctx->inputs[0]->incfg.channel_layouts ||
359  !ctx->inputs[0]->incfg.channel_layouts->nb_channel_layouts) {
361  "No channel layout for input 1\n");
362  return AVERROR(EAGAIN);
363  }
364 
365  if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->incfg.channel_layouts->channel_layouts[0])) < 0 ||
366  (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
367  return ret;
368 
369  for (i = 0; i < 2; i++) {
371  if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->outcfg.channel_layouts)) < 0)
372  return ret;
373  }
374 
376  if ((ret = ff_set_common_formats(ctx, formats)) < 0)
377  return ret;
378 
381 }
382 
383 static int scconfig_output(AVFilterLink *outlink)
384 {
385  AVFilterContext *ctx = outlink->src;
386  AudioGateContext *s = ctx->priv;
387 
388  if (ctx->inputs[0]->sample_rate != ctx->inputs[1]->sample_rate) {
390  "Inputs must have the same sample rate "
391  "%d for in0 vs %d for in1\n",
392  ctx->inputs[0]->sample_rate, ctx->inputs[1]->sample_rate);
393  return AVERROR(EINVAL);
394  }
395 
396  outlink->sample_rate = ctx->inputs[0]->sample_rate;
397  outlink->time_base = ctx->inputs[0]->time_base;
398  outlink->channel_layout = ctx->inputs[0]->channel_layout;
399  outlink->channels = ctx->inputs[0]->channels;
400 
401  s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
402  s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
403  if (!s->fifo[0] || !s->fifo[1])
404  return AVERROR(ENOMEM);
405 
406 
407  agate_config_input(ctx->inputs[0]);
408 
409  return 0;
410 }
411 
412 static av_cold void uninit(AVFilterContext *ctx)
413 {
414  AudioGateContext *s = ctx->priv;
415 
416  av_audio_fifo_free(s->fifo[0]);
417  av_audio_fifo_free(s->fifo[1]);
418 }
419 
420 static const AVFilterPad sidechaingate_inputs[] = {
421  {
422  .name = "main",
423  .type = AVMEDIA_TYPE_AUDIO,
424  },{
425  .name = "sidechain",
426  .type = AVMEDIA_TYPE_AUDIO,
427  },
428  { NULL }
429 };
430 
431 static const AVFilterPad sidechaingate_outputs[] = {
432  {
433  .name = "default",
434  .type = AVMEDIA_TYPE_AUDIO,
435  .config_props = scconfig_output,
436  },
437  { NULL }
438 };
439 
441  .name = "sidechaingate",
442  .description = NULL_IF_CONFIG_SMALL("Audio sidechain gate."),
443  .priv_size = sizeof(AudioGateContext),
444  .priv_class = &sidechaingate_class,
445  .query_formats = scquery_formats,
446  .activate = activate,
447  .uninit = uninit,
448  .inputs = sidechaingate_inputs,
449  .outputs = sidechaingate_outputs,
452 };
453 #endif /* CONFIG_SIDECHAINGATE_FILTER */
AudioGateContext::lin_slope
double lin_slope
Definition: af_agate.c:57
av_audio_fifo_free
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
formats
formats
Definition: signature.h:48
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:86
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
AudioGateContext::range
double range
Definition: af_agate.c:47
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AudioGateContext::attack
double attack
Definition: af_agate.c:41
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:925
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:461
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:436
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
AudioGateContext::level_in
double level_in
Definition: af_agate.c:39
AudioGateContext::knee
double knee
Definition: af_agate.c:45
AVOption
AVOption.
Definition: opt.h:248
AudioGateContext::ratio
double ratio
Definition: af_agate.c:44
data
const char data[16]
Definition: mxf.c:142
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
ff_inlink_consume_frame
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:1494
AudioGateContext::knee_start
double knee_start
Definition: af_agate.c:53
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:212
AVAudioFifo
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
ff_af_agate
AVFilter ff_af_agate
AudioGateContext::makeup
double makeup
Definition: af_agate.c:46
AudioGateContext::lin_knee_start
double lin_knee_start
Definition: af_agate.c:55
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:587
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:338
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1620
s
#define s(width, name)
Definition: cbs_vp9.c:257
AudioGateContext::mode
int mode
Definition: af_agate.c:50
hermite_interpolation
static double hermite_interpolation(double x, double x0, double x1, double p0, double p1, double m0, double m1)
Definition: hermite.h:22
av_audio_fifo_write
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioGateContext::release
double release
Definition: af_agate.c:42
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
link
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 link
Definition: filter_design.txt:23
if
if(ret)
Definition: filter_design.txt:179
output_gain
static double output_gain(double lin_slope, double ratio, double thres, double knee, double knee_start, double knee_stop, double range, int mode)
Definition: af_agate.c:117
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
A
#define A
Definition: af_agate.c:66
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_audio_fifo_alloc
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
activate
filter_frame For filters that do not use the activate() callback
src
#define src
Definition: vp8dsp.c:255
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:332
options
static const AVOption options[]
Definition: af_agate.c:68
AudioGateContext::thres
double thres
Definition: af_agate.c:52
filter_frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition: dolby_e.c:1049
AudioGateContext
Definition: af_agate.c:36
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
exp
int8_t exp
Definition: eval.c:72
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AudioGateContext::attack_coeff
double attack_coeff
Definition: af_agate.c:58
OFFSET
#define OFFSET(x)
Definition: af_agate.c:65
ff_af_sidechaingate
AVFilter ff_af_sidechaingate
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AudioGateContext::level_sc
double level_sc
Definition: af_agate.c:40
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_acrusher.c:336
hermite.h
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
AudioGateContext::lin_knee_stop
double lin_knee_stop
Definition: af_agate.c:56
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:882
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
AudioGateContext::fifo
AVAudioFifo * fifo[2]
Definition: af_agate.c:61
av_audio_fifo_size
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
IS_FAKE_INFINITY
#define IS_FAKE_INFINITY(value)
Definition: af_agate.c:115
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:126
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:288
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
av_audio_fifo_read
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
AudioGateContext::release_coeff
double release_coeff
Definition: af_agate.c:59
i
int i
Definition: input.c:407
AudioGateContext::pts
int64_t pts
Definition: af_agate.c:62
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
delta
float delta
Definition: vorbis_enc_data.h:457
AudioGateContext::knee_stop
double knee_stop
Definition: af_agate.c:54
audio_fifo.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AudioGateContext::link
int link
Definition: af_agate.c:48
AudioGateContext::threshold
double threshold
Definition: af_agate.c:43
AVFilter
Filter definition.
Definition: avfilter.h:145
ret
ret
Definition: filter_design.txt:187
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
channel_layout.h
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
audio.h
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
gate
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:141
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:243
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AudioGateContext::detection
int detection
Definition: af_agate.c:49
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
agate_config_input
static int agate_config_input(AVFilterLink *inlink)
Definition: af_agate.c:90
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
ff_set_common_channel_layouts
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:568