58 #define OFFSET(x) offsetof(SidechainCompressContext, x)
59 #define A AV_OPT_FLAG_AUDIO_PARAM
60 #define F AV_OPT_FLAG_FILTERING_PARAM
97 float width = x1 - x0;
98 float t = (x - x0) / width;
100 float ct0, ct1, ct2, ct3;
110 ct2 = -3 * p0 - 2 * m0 + 3 * p1 - m1;
111 ct3 = 2 * p0 + m0 - 2 * p1 + m1;
113 return ct3 * t3 + ct2 * t2 + ct1 * t + ct0;
117 #define FAKE_INFINITY (65536.0 * 65536.0)
120 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
122 static double output_gain(
double lin_slope,
double ratio,
double thres,
123 double knee,
double knee_start,
double knee_stop,
124 double compressed_knee_stop,
int detection)
126 double slope = log(lin_slope);
137 gain = (slope - thres) / ratio + thres;
141 if (knee > 1.0 && slope < knee_stop)
143 knee_start, compressed_knee_stop,
146 return exp(gain - slope);
155 const double makeup = s->
makeup;
161 for (i = 0; i < 2; i++)
162 if (link == ctx->
inputs[i])
176 for (i = 0; i < nb_samples; i++) {
177 double abs_sample, gain = 1.0;
179 abs_sample =
FFABS(scsrc[0]);
182 for (c = 1; c < sclink->
channels; c++)
183 abs_sample =
FFMAX(
FFABS(scsrc[c]), abs_sample);
185 for (c = 1; c < sclink->
channels; c++)
186 abs_sample +=
FFABS(scsrc[c]);
192 abs_sample *= abs_sample;
201 for (c = 0; c < outlink->
channels; c++)
202 sample[c] *= gain * makeup;
223 for (i = 0; i < 2; i++) {
250 "No channel layout for input 1\n");
259 for (i = 0; i < 2; i++) {
286 "Inputs must have the same sample rate "
287 "%d for in0 vs %d for in1\n",
330 .
name =
"sidechaincompress",
333 .priv_class = &sidechaincompress_class,
336 .
inputs = sidechaincompress_inputs,
337 .
outputs = sidechaincompress_outputs,
static const AVFilterPad sidechaincompress_outputs[]
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_stop, int detection)
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
Main libavfilter public API header.
static int filter_frame(AVFilterLink *link, AVFrame *frame)
int request_samples
Audio only, the destination filter sets this to a non-zero value to request that buffers with the giv...
static enum AVSampleFormat formats[]
struct AVFilterChannelLayouts * in_channel_layouts
static int query_formats(AVFilterContext *ctx)
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int request_frame(AVFilterLink *outlink)
int sample_rate
samples per second
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
uint64_t * channel_layouts
list of channel layouts
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
struct AVFilterChannelLayouts * out_channel_layouts
static const AVOption sidechaincompress_options[]
AVFILTER_DEFINE_CLASS(sidechaincompress)
static const AVFilterPad sidechaincompress_inputs[]
audio channel layout utility functions
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
AVFilterContext * src
source filter
static float hermite_interpolation(float x, float x0, float x1, float p0, float p1, float m0, float m1)
A list of supported channel layouts.
#define IS_FAKE_INFINITY(value)
AVSampleFormat
Audio sample formats.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal and external API header
int nb_channel_layouts
number of channel layouts
double compressed_knee_stop
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
AVFilterContext * dst
dest filter
AVFilter ff_af_sidechaincompress
static av_cold int init(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static enum AVSampleFormat sample_fmts[]
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int nb_samples
number of audio samples (per channel) described by this frame