FFmpeg
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;
57  double lin_knee_stop;
59  double adj_knee_stop;
62  int link;
63  int detection;
64  int mode;
65 
67  int64_t pts;
69 
70 #define OFFSET(x) offsetof(SidechainCompressContext, x)
71 #define A AV_OPT_FLAG_AUDIO_PARAM
72 #define F AV_OPT_FLAG_FILTERING_PARAM
73 
74 static const AVOption options[] = {
75  { "level_in", "set input gain", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
76  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "mode" },
77  { "downward",0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "mode" },
78  { "upward", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "mode" },
79  { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F },
80  { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F },
81  { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F },
82  { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F },
83  { "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 64, A|F },
84  { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F },
85  { "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" },
86  { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" },
87  { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" },
88  { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" },
89  { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" },
90  { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" },
91  { "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
92  { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F },
93  { NULL }
94 };
95 
96 #define sidechaincompress_options options
97 AVFILTER_DEFINE_CLASS(sidechaincompress);
98 
99 // A fake infinity value (because real infinity may break some hosts)
100 #define FAKE_INFINITY (65536.0 * 65536.0)
101 
102 // Check for infinity (with appropriate-ish tolerance)
103 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
104 
105 static double output_gain(double lin_slope, double ratio, double thres,
106  double knee, double knee_start, double knee_stop,
107  double compressed_knee_start,
108  double compressed_knee_stop,
109  int detection, int mode)
110 {
111  double slope = log(lin_slope);
112  double gain = 0.0;
113  double delta = 0.0;
114 
115  if (detection)
116  slope *= 0.5;
117 
118  if (IS_FAKE_INFINITY(ratio)) {
119  gain = thres;
120  delta = 0.0;
121  } else {
122  gain = (slope - thres) / ratio + thres;
123  delta = 1.0 / ratio;
124  }
125 
126  if (mode) {
127  if (knee > 1.0 && slope > knee_start)
128  gain = hermite_interpolation(slope, knee_stop, knee_start,
129  knee_stop, compressed_knee_start,
130  1.0, delta);
131  } else {
132  if (knee > 1.0 && slope < knee_stop)
133  gain = hermite_interpolation(slope, knee_start, knee_stop,
134  knee_start, compressed_knee_stop,
135  1.0, delta);
136  }
137 
138  return exp(gain - slope);
139 }
140 
142 {
143  AVFilterContext *ctx = outlink->src;
144  SidechainCompressContext *s = ctx->priv;
145 
146  s->thres = log(s->threshold);
147  s->lin_knee_start = s->threshold / sqrt(s->knee);
148  s->lin_knee_stop = s->threshold * sqrt(s->knee);
149  s->adj_knee_start = s->lin_knee_start * s->lin_knee_start;
150  s->adj_knee_stop = s->lin_knee_stop * s->lin_knee_stop;
151  s->knee_start = log(s->lin_knee_start);
152  s->knee_stop = log(s->lin_knee_stop);
153  s->compressed_knee_start = (s->knee_start - s->thres) / s->ratio + s->thres;
154  s->compressed_knee_stop = (s->knee_stop - s->thres) / s->ratio + s->thres;
155 
156  s->attack_coeff = FFMIN(1., 1. / (s->attack * outlink->sample_rate / 4000.));
157  s->release_coeff = FFMIN(1., 1. / (s->release * outlink->sample_rate / 4000.));
158 
159  return 0;
160 }
161 
163  const double *src, double *dst, const double *scsrc, int nb_samples,
164  double level_in, double level_sc,
165  AVFilterLink *inlink, AVFilterLink *sclink)
166 {
167  const double makeup = s->makeup;
168  const double mix = s->mix;
169  int i, c;
170 
171  for (i = 0; i < nb_samples; i++) {
172  double abs_sample, gain = 1.0;
173  double detector;
174  int detected;
175 
176  abs_sample = fabs(scsrc[0] * level_sc);
177 
178  if (s->link == 1) {
179  for (c = 1; c < sclink->channels; c++)
180  abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
181  } else {
182  for (c = 1; c < sclink->channels; c++)
183  abs_sample += fabs(scsrc[c] * level_sc);
184 
185  abs_sample /= sclink->channels;
186  }
187 
188  if (s->detection)
189  abs_sample *= abs_sample;
190 
191  s->lin_slope += (abs_sample - s->lin_slope) * (abs_sample > s->lin_slope ? s->attack_coeff : s->release_coeff);
192 
193  if (s->mode) {
194  detector = (s->detection ? s->adj_knee_stop : s->lin_knee_stop);
195  detected = s->lin_slope < detector;
196  } else {
197  detector = (s->detection ? s->adj_knee_start : s->lin_knee_start);
198  detected = s->lin_slope > detector;
199  }
200 
201  if (s->lin_slope > 0.0 && detected)
202  gain = output_gain(s->lin_slope, s->ratio, s->thres, s->knee,
203  s->knee_start, s->knee_stop,
204  s->compressed_knee_start,
205  s->compressed_knee_stop,
206  s->detection, s->mode);
207 
208  for (c = 0; c < inlink->channels; c++)
209  dst[c] = src[c] * level_in * (gain * makeup * mix + (1. - mix));
210 
211  src += inlink->channels;
212  dst += inlink->channels;
213  scsrc += sclink->channels;
214  }
215 }
216 
217 #if CONFIG_SIDECHAINCOMPRESS_FILTER
218 static int activate(AVFilterContext *ctx)
219 {
220  SidechainCompressContext *s = ctx->priv;
221  AVFrame *out = NULL, *in[2] = { NULL };
222  int ret, i, nb_samples;
223  double *dst;
224 
226  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &in[0])) > 0) {
227  av_audio_fifo_write(s->fifo[0], (void **)in[0]->extended_data,
228  in[0]->nb_samples);
229  av_frame_free(&in[0]);
230  }
231  if (ret < 0)
232  return ret;
233  if ((ret = ff_inlink_consume_frame(ctx->inputs[1], &in[1])) > 0) {
234  av_audio_fifo_write(s->fifo[1], (void **)in[1]->extended_data,
235  in[1]->nb_samples);
236  av_frame_free(&in[1]);
237  }
238  if (ret < 0)
239  return ret;
240 
241  nb_samples = FFMIN(av_audio_fifo_size(s->fifo[0]), av_audio_fifo_size(s->fifo[1]));
242  if (nb_samples) {
243  out = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
244  if (!out)
245  return AVERROR(ENOMEM);
246  for (i = 0; i < 2; i++) {
247  in[i] = ff_get_audio_buffer(ctx->inputs[i], nb_samples);
248  if (!in[i]) {
249  av_frame_free(&in[0]);
250  av_frame_free(&in[1]);
251  av_frame_free(&out);
252  return AVERROR(ENOMEM);
253  }
254  av_audio_fifo_read(s->fifo[i], (void **)in[i]->data, nb_samples);
255  }
256 
257  dst = (double *)out->data[0];
258  out->pts = s->pts;
259  s->pts += nb_samples;
260 
261  compressor(s, (double *)in[0]->data[0], dst,
262  (double *)in[1]->data[0], nb_samples,
263  s->level_in, s->level_sc,
264  ctx->inputs[0], ctx->inputs[1]);
265 
266  av_frame_free(&in[0]);
267  av_frame_free(&in[1]);
268 
269  ret = ff_filter_frame(ctx->outputs[0], out);
270  if (ret < 0)
271  return ret;
272  }
273  FF_FILTER_FORWARD_STATUS(ctx->inputs[0], ctx->outputs[0]);
274  FF_FILTER_FORWARD_STATUS(ctx->inputs[1], ctx->outputs[0]);
275  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
276  if (!av_audio_fifo_size(s->fifo[0]))
277  ff_inlink_request_frame(ctx->inputs[0]);
278  if (!av_audio_fifo_size(s->fifo[1]))
279  ff_inlink_request_frame(ctx->inputs[1]);
280  }
281  return 0;
282 }
283 
284 static int query_formats(AVFilterContext *ctx)
285 {
288  static const enum AVSampleFormat sample_fmts[] = {
291  };
292  int ret, i;
293 
294  if (!ctx->inputs[0]->in_channel_layouts ||
295  !ctx->inputs[0]->in_channel_layouts->nb_channel_layouts) {
297  "No channel layout for input 1\n");
298  return AVERROR(EAGAIN);
299  }
300 
301  if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0])) < 0 ||
302  (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
303  return ret;
304 
305  for (i = 0; i < 2; i++) {
307  if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
308  return ret;
309  }
310 
312  if ((ret = ff_set_common_formats(ctx, formats)) < 0)
313  return ret;
314 
317 }
318 
319 static int config_output(AVFilterLink *outlink)
320 {
321  AVFilterContext *ctx = outlink->src;
322  SidechainCompressContext *s = ctx->priv;
323 
324  if (ctx->inputs[0]->sample_rate != ctx->inputs[1]->sample_rate) {
326  "Inputs must have the same sample rate "
327  "%d for in0 vs %d for in1\n",
328  ctx->inputs[0]->sample_rate, ctx->inputs[1]->sample_rate);
329  return AVERROR(EINVAL);
330  }
331 
332  outlink->sample_rate = ctx->inputs[0]->sample_rate;
333  outlink->time_base = ctx->inputs[0]->time_base;
334  outlink->channel_layout = ctx->inputs[0]->channel_layout;
335  outlink->channels = ctx->inputs[0]->channels;
336 
337  s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024);
338  s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);
339  if (!s->fifo[0] || !s->fifo[1])
340  return AVERROR(ENOMEM);
341 
342  compressor_config_output(outlink);
343 
344  return 0;
345 }
346 
347 static av_cold void uninit(AVFilterContext *ctx)
348 {
349  SidechainCompressContext *s = ctx->priv;
350 
351  av_audio_fifo_free(s->fifo[0]);
352  av_audio_fifo_free(s->fifo[1]);
353 }
354 
355 static const AVFilterPad sidechaincompress_inputs[] = {
356  {
357  .name = "main",
358  .type = AVMEDIA_TYPE_AUDIO,
359  },{
360  .name = "sidechain",
361  .type = AVMEDIA_TYPE_AUDIO,
362  },
363  { NULL }
364 };
365 
366 static const AVFilterPad sidechaincompress_outputs[] = {
367  {
368  .name = "default",
369  .type = AVMEDIA_TYPE_AUDIO,
370  .config_props = config_output,
371  },
372  { NULL }
373 };
374 
376  .name = "sidechaincompress",
377  .description = NULL_IF_CONFIG_SMALL("Sidechain compressor."),
378  .priv_size = sizeof(SidechainCompressContext),
379  .priv_class = &sidechaincompress_class,
381  .activate = activate,
382  .uninit = uninit,
383  .inputs = sidechaincompress_inputs,
384  .outputs = sidechaincompress_outputs,
385 };
386 #endif /* CONFIG_SIDECHAINCOMPRESS_FILTER */
387 
388 #if CONFIG_ACOMPRESSOR_FILTER
389 static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *in)
390 {
391  const double *src = (const double *)in->data[0];
392  AVFilterContext *ctx = inlink->dst;
393  SidechainCompressContext *s = ctx->priv;
394  AVFilterLink *outlink = ctx->outputs[0];
395  AVFrame *out;
396  double *dst;
397 
399  out = in;
400  } else {
401  out = ff_get_audio_buffer(outlink, in->nb_samples);
402  if (!out) {
403  av_frame_free(&in);
404  return AVERROR(ENOMEM);
405  }
407  }
408  dst = (double *)out->data[0];
409 
410  compressor(s, src, dst, src, in->nb_samples,
411  s->level_in, s->level_in,
412  inlink, inlink);
413 
414  if (out != in)
415  av_frame_free(&in);
416  return ff_filter_frame(outlink, out);
417 }
418 
419 static int acompressor_query_formats(AVFilterContext *ctx)
420 {
423  static const enum AVSampleFormat sample_fmts[] = {
426  };
427  int ret;
428 
430  if (!layouts)
431  return AVERROR(ENOMEM);
433  if (ret < 0)
434  return ret;
435 
437  if (!formats)
438  return AVERROR(ENOMEM);
440  if (ret < 0)
441  return ret;
442 
444  if (!formats)
445  return AVERROR(ENOMEM);
447 }
448 
449 #define acompressor_options options
450 AVFILTER_DEFINE_CLASS(acompressor);
451 
452 static const AVFilterPad acompressor_inputs[] = {
453  {
454  .name = "default",
455  .type = AVMEDIA_TYPE_AUDIO,
456  .filter_frame = acompressor_filter_frame,
457  },
458  { NULL }
459 };
460 
461 static const AVFilterPad acompressor_outputs[] = {
462  {
463  .name = "default",
464  .type = AVMEDIA_TYPE_AUDIO,
465  .config_props = compressor_config_output,
466  },
467  { NULL }
468 };
469 
471  .name = "acompressor",
472  .description = NULL_IF_CONFIG_SMALL("Audio compressor."),
473  .priv_size = sizeof(SidechainCompressContext),
474  .priv_class = &acompressor_class,
475  .query_formats = acompressor_query_formats,
476  .inputs = acompressor_inputs,
477  .outputs = acompressor_outputs,
478 };
479 #endif /* CONFIG_ACOMPRESSOR_FILTER */
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:85
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
mix
static int mix(int c0, int c1)
Definition: 4xm.c:714
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
out
FILE * out
Definition: movenc.c:54
ff_set_common_channel_layouts
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
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:686
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
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:202
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:410
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
SidechainCompressContext::adj_knee_stop
double adj_knee_stop
Definition: af_sidechaincompress.c:59
AVOption
AVOption.
Definition: opt.h:246
data
const char data[16]
Definition: mxf.c:91
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(sidechaincompress)
output_gain
static double output_gain(double lin_slope, double ratio, double thres, double knee, double knee_start, double knee_stop, double compressed_knee_start, double compressed_knee_stop, int detection, int mode)
Definition: af_sidechaincompress.c:105
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
A
#define A
Definition: af_sidechaincompress.c:71
SidechainCompressContext::lin_knee_stop
double lin_knee_stop
Definition: af_sidechaincompress.c:57
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:1481
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
SidechainCompressContext::adj_knee_start
double adj_knee_start
Definition: af_sidechaincompress.c:58
SidechainCompressContext::ratio
double ratio
Definition: af_sidechaincompress.c:48
SidechainCompressContext::release
double release
Definition: af_sidechaincompress.c:46
SidechainCompressContext::pts
int64_t pts
Definition: af_sidechaincompress.c:67
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_aecho.c:232
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
options
static const AVOption options[]
Definition: af_sidechaincompress.c:74
compressor
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)
Definition: af_sidechaincompress.c:162
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:84
SidechainCompressContext::level_in
double level_in
Definition: af_sidechaincompress.c:43
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:568
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1607
s
#define s(width, name)
Definition: cbs_vp9.c:257
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:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
SidechainCompressContext::knee_start
double knee_start
Definition: af_sidechaincompress.c:54
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
SidechainCompressContext::mix
double mix
Definition: af_sidechaincompress.c:51
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
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:654
SidechainCompressContext::thres
double thres
Definition: af_sidechaincompress.c:52
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
SidechainCompressContext::makeup
double makeup
Definition: af_sidechaincompress.c:50
ff_af_sidechaincompress
AVFilter ff_af_sidechaincompress
SidechainCompressContext::compressed_knee_stop
double compressed_knee_stop
Definition: af_sidechaincompress.c:61
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
OFFSET
#define OFFSET(x)
Definition: af_sidechaincompress.c:70
SidechainCompressContext::link
int link
Definition: af_sidechaincompress.c:62
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:188
hermite.h
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
SidechainCompressContext::mode
int mode
Definition: af_sidechaincompress.c:64
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
SidechainCompressContext::knee
double knee
Definition: af_sidechaincompress.c:53
SidechainCompressContext::compressed_knee_start
double compressed_knee_start
Definition: af_sidechaincompress.c:60
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
internal.h
SidechainCompressContext::detection
int detection
Definition: af_sidechaincompress.c:63
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
compressor_config_output
static int compressor_config_output(AVFilterLink *outlink)
Definition: af_sidechaincompress.c:141
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
SidechainCompressContext::attack_coeff
double attack_coeff
Definition: af_sidechaincompress.c:45
delta
float delta
Definition: vorbis_enc_data.h:457
SidechainCompressContext::level_sc
double level_sc
Definition: af_sidechaincompress.c:44
audio_fifo.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
SidechainCompressContext::lin_slope
double lin_slope
Definition: af_sidechaincompress.c:47
AVFilter
Filter definition.
Definition: avfilter.h:144
SidechainCompressContext::fifo
AVAudioFifo * fifo[2]
Definition: af_sidechaincompress.c:66
ret
ret
Definition: filter_design.txt:187
SidechainCompressContext
Definition: af_sidechaincompress.c:40
SidechainCompressContext::threshold
double threshold
Definition: af_sidechaincompress.c:49
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
F
#define F
Definition: af_sidechaincompress.c:72
channel_layout.h
ff_af_acompressor
AVFilter ff_af_acompressor
mode
mode
Definition: ebur128.h:83
SidechainCompressContext::knee_stop
double knee_stop
Definition: af_sidechaincompress.c:55
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
audio.h
SidechainCompressContext::lin_knee_start
double lin_knee_start
Definition: af_sidechaincompress.c:56
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
IS_FAKE_INFINITY
#define IS_FAKE_INFINITY(value)
Definition: af_sidechaincompress.c:103
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
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:556
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
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
SidechainCompressContext::attack
double attack
Definition: af_sidechaincompress.c:45
SidechainCompressContext::release_coeff
double release_coeff
Definition: af_sidechaincompress.c:46