Go to the documentation of this file.
27 #include "config_components.h"
70 #define OFFSET(x) offsetof(SidechainCompressContext, x)
71 #define A AV_OPT_FLAG_AUDIO_PARAM
72 #define F AV_OPT_FLAG_FILTERING_PARAM
73 #define R AV_OPT_FLAG_RUNTIME_PARAM
98 "acompressor/sidechaincompress",
102 #define FAKE_INFINITY (65536.0 * 65536.0)
105 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
107 static double output_gain(
double lin_slope,
double ratio,
double thres,
108 double knee,
double knee_start,
double knee_stop,
109 double compressed_knee_start,
110 double compressed_knee_stop,
111 int detection,
int mode)
113 double slope =
log(lin_slope);
124 gain = (slope - thres) / ratio + thres;
129 if (knee > 1.0 && slope > knee_start)
131 knee_stop, compressed_knee_start,
134 if (knee > 1.0 && slope < knee_stop)
136 knee_start, compressed_knee_stop,
140 return exp(gain - slope);
148 s->thres =
log(
s->threshold);
149 s->lin_knee_start =
s->threshold / sqrt(
s->knee);
150 s->lin_knee_stop =
s->threshold * sqrt(
s->knee);
151 s->adj_knee_start =
s->lin_knee_start *
s->lin_knee_start;
152 s->adj_knee_stop =
s->lin_knee_stop *
s->lin_knee_stop;
153 s->knee_start =
log(
s->lin_knee_start);
154 s->knee_stop =
log(
s->lin_knee_stop);
155 s->compressed_knee_start = (
s->knee_start -
s->thres) /
s->ratio +
s->thres;
156 s->compressed_knee_stop = (
s->knee_stop -
s->thres) /
s->ratio +
s->thres;
165 const double *
src,
double *
dst,
const double *scsrc,
int nb_samples,
166 double level_in,
double level_sc,
169 const double makeup =
s->makeup;
170 const double mix =
s->mix;
173 for (
i = 0;
i < nb_samples;
i++) {
174 double abs_sample, gain = 1.0;
178 abs_sample =
fabs(scsrc[0] * level_sc);
182 abs_sample =
FFMAX(
fabs(scsrc[
c] * level_sc), abs_sample);
185 abs_sample +=
fabs(scsrc[
c] * level_sc);
191 abs_sample *= abs_sample;
193 s->lin_slope += (abs_sample -
s->lin_slope) * (abs_sample >
s->lin_slope ?
s->attack_coeff :
s->release_coeff);
196 detector = (
s->detection ?
s->adj_knee_stop :
s->lin_knee_stop);
197 detected =
s->lin_slope < detector;
199 detector = (
s->detection ?
s->adj_knee_start :
s->lin_knee_start);
200 detected =
s->lin_slope > detector;
203 if (
s->lin_slope > 0.0 && detected)
205 s->knee_start,
s->knee_stop,
206 s->compressed_knee_start,
207 s->compressed_knee_stop,
208 s->detection,
s->mode);
210 for (
c = 0;
c <
inlink->ch_layout.nb_channels;
c++)
220 char *res,
int res_len,
int flags)
233 #if CONFIG_SIDECHAINCOMPRESS_FILTER
238 int ret,
i, nb_samples;
262 for (
i = 0;
i < 2;
i++) {
273 dst = (
double *)
out->data[0];
278 (
double *)in[1]->
data[0], nb_samples,
279 s->level_in,
s->level_sc,
280 ctx->inputs[0],
ctx->inputs[1]);
332 if (!
s->fifo[0] || !
s->fifo[1])
348 static const AVFilterPad sidechaincompress_inputs[] = {
358 static const AVFilterPad sidechaincompress_outputs[] = {
367 .
name =
"sidechaincompress",
369 .priv_class = &sidechaincompress_acompressor_class,
380 #if CONFIG_ACOMPRESSOR_FILTER
383 const double *
src = (
const double *)in->
data[0];
400 dst = (
double *)
out->data[0];
403 s->level_in,
s->level_in,
415 .filter_frame = acompressor_filter_frame,
428 .
name =
"acompressor",
430 .priv_class = &sidechaincompress_acompressor_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
const AVFilter ff_af_sidechaincompress
static int mix(int c0, int c1)
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
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)
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Context for an Audio FIFO Buffer.
A filter pad used for either input or output.
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)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static double hermite_interpolation(double x, double x0, double x1, double p0, double p1, double m0, double m1)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
const AVFilter ff_af_acompressor
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_OUTPUTS(array)
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
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
filter_frame For filters that do not use the activate() callback
double compressed_knee_stop
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
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_output(AVFilterLink *outlink)
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
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.
double compressed_knee_start
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int sample_rate
samples per second
static void uninit(AVBSFContext *ctx)
int nb_samples
number of audio samples (per channel) described by this frame
static int compressor_config_output(AVFilterLink *outlink)
#define i(width, name, range_min, range_max)
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
const char * name
Pad name.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
@ AV_OPT_TYPE_INT
Underlying C type is int.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFILTER_DEFINE_CLASS_EXT(sidechaincompress_acompressor, "acompressor/sidechaincompress", options)
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
static const uint16_t channel_layouts[7]
#define IS_FAKE_INFINITY(value)
#define flags(name, subs,...)
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
double
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)