Go to the documentation of this file.
27 #include "config_components.h"
71 #define OFFSET(x) offsetof(SidechainCompressContext, x)
72 #define A AV_OPT_FLAG_AUDIO_PARAM
73 #define F AV_OPT_FLAG_FILTERING_PARAM
74 #define R AV_OPT_FLAG_RUNTIME_PARAM
99 "acompressor/sidechaincompress",
103 #define FAKE_INFINITY (65536.0 * 65536.0)
106 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
108 static double output_gain(
double lin_slope,
double ratio,
double thres,
109 double knee,
double knee_start,
double knee_stop,
110 double compressed_knee_start,
111 double compressed_knee_stop,
112 int detection,
int mode)
114 double slope = log(lin_slope);
125 gain = (slope - thres) / ratio + thres;
130 if (knee > 1.0 && slope > knee_start)
132 knee_stop, compressed_knee_start,
135 if (knee > 1.0 && slope < knee_stop)
137 knee_start, compressed_knee_stop,
141 return exp(gain - slope);
149 s->thres = log(
s->threshold);
150 s->lin_knee_start =
s->threshold / sqrt(
s->knee);
151 s->lin_knee_stop =
s->threshold * sqrt(
s->knee);
152 s->adj_knee_start =
s->lin_knee_start *
s->lin_knee_start;
153 s->adj_knee_stop =
s->lin_knee_stop *
s->lin_knee_stop;
154 s->knee_start = log(
s->lin_knee_start);
155 s->knee_stop = log(
s->lin_knee_stop);
156 s->compressed_knee_start = (
s->knee_start -
s->thres) /
s->ratio +
s->thres;
157 s->compressed_knee_stop = (
s->knee_stop -
s->thres) /
s->ratio +
s->thres;
166 const double *
src,
double *dst,
const double *scsrc,
int nb_samples,
167 double level_in,
double level_sc,
170 const double makeup =
s->makeup;
171 const double mix =
s->mix;
174 for (
i = 0;
i < nb_samples;
i++) {
175 double abs_sample, gain = 1.0;
179 abs_sample =
fabs(scsrc[0] * level_sc);
183 abs_sample =
FFMAX(
fabs(scsrc[
c] * level_sc), abs_sample);
186 abs_sample +=
fabs(scsrc[
c] * level_sc);
192 abs_sample *= abs_sample;
194 s->lin_slope += (abs_sample -
s->lin_slope) * (abs_sample >
s->lin_slope ?
s->attack_coeff :
s->release_coeff);
197 detector = (
s->detection ?
s->adj_knee_stop :
s->lin_knee_stop);
198 detected =
s->lin_slope < detector;
200 detector = (
s->detection ?
s->adj_knee_start :
s->lin_knee_start);
201 detected =
s->lin_slope > detector;
204 if (
s->lin_slope > 0.0 && detected)
206 s->knee_start,
s->knee_stop,
207 s->compressed_knee_start,
208 s->compressed_knee_stop,
209 s->detection,
s->mode);
211 for (
c = 0;
c <
inlink->ch_layout.nb_channels;
c++)
212 dst[
c] =
src[
c] * level_in * (gain * makeup *
mix + (1. -
mix));
215 dst +=
inlink->ch_layout.nb_channels;
221 char *res,
int res_len,
int flags)
234 #if CONFIG_SIDECHAINCOMPRESS_FILTER
239 int ret,
i, nb_samples;
263 for (
i = 0;
i < 2;
i++) {
274 dst = (
double *)
out->data[0];
279 (
double *)in[1]->
data[0], nb_samples,
280 s->level_in,
s->level_sc,
281 ctx->inputs[0],
ctx->inputs[1]);
308 &
ctx->inputs[1]->outcfg.channel_layouts);
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[]
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
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.
This structure describes decoded (raw) audio or video data.
#define FILTER_QUERY_FUNC(func)
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 const AVOption options[]
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)
static int config_output(AVFilterLink *outlink)
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)
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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_INPUTS(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 NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
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.
const char * name
Pad name.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
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)
#define FILTER_OUTPUTS(array)
#define IS_FAKE_INFINITY(value)
static int query_formats(AVFilterContext *ctx)
#define flags(name, subs,...)
static av_cold int uninit(AVCodecContext *avctx)
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