Go to the documentation of this file.
26 #include "config_components.h"
66 #define OFFSET(x) offsetof(AudioGateContext, x)
67 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
97 double lin_threshold =
s->threshold;
98 double lin_knee_sqrt = sqrt(
s->knee);
101 lin_threshold *= lin_threshold;
103 s->attack_coeff =
FFMIN(1., 1. / (
s->attack *
inlink->sample_rate / 4000.));
104 s->release_coeff =
FFMIN(1., 1. / (
s->release *
inlink->sample_rate / 4000.));
105 s->lin_knee_stop = lin_threshold * lin_knee_sqrt;
106 s->lin_knee_start = lin_threshold / lin_knee_sqrt;
107 s->thres =
log(lin_threshold);
108 s->knee_start =
log(
s->lin_knee_start);
109 s->knee_stop =
log(
s->lin_knee_stop);
115 #define FAKE_INFINITY (65536.0 * 65536.0)
118 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
120 static double output_gain(
double lin_slope,
double ratio,
double thres,
121 double knee,
double knee_start,
double knee_stop,
124 double slope =
log(lin_slope);
125 double tratio = ratio;
131 gain = (slope - thres) * tratio + thres;
135 if (knee > 1. && slope < knee_stop)
138 if (knee > 1. && slope > knee_start)
145 const double *
src,
double *dst,
const double *scsrc,
146 int nb_samples,
double level_in,
double level_sc,
150 const double makeup =
s->makeup;
151 const double attack_coeff =
s->attack_coeff;
152 const double release_coeff =
s->release_coeff;
156 double abs_sample =
fabs(scsrc[0] * level_sc), gain = 1.0;
162 abs_sample =
FFMAX(
fabs(scsrc[
c] * level_sc), abs_sample);
165 abs_sample +=
fabs(scsrc[
c] * level_sc);
171 abs_sample *= abs_sample;
173 s->lin_slope += (abs_sample -
s->lin_slope) * (abs_sample >
s->lin_slope ? attack_coeff : release_coeff);
176 detected =
s->lin_slope >
s->lin_knee_start;
178 detected =
s->lin_slope <
s->lin_knee_stop;
180 if (
s->lin_slope > 0.0 && detected)
182 s->knee,
s->knee_start,
s->knee_stop,
185 factor =
ctx->is_disabled ? 1.f : level_in * gain * makeup;
186 for (
c = 0;
c <
inlink->ch_layout.nb_channels;
c++)
191 #if CONFIG_AGATE_FILTER
195 const double *
src = (
const double *)in->
data[0];
212 dst = (
double *)
out->data[0];
234 .priv_class = &agate_sidechaingate_class,
245 #if CONFIG_SIDECHAINGATE_FILTER
251 int ret,
i, nb_samples;
275 for (
i = 0;
i < 2;
i++) {
286 dst = (
double *)
out->data[0];
291 (
double *)in[1]->
data[0], nb_samples,
292 s->level_in,
s->level_sc,
293 ctx->inputs[0],
ctx->inputs[1]);
320 &
ctx->inputs[1]->outcfg.channel_layouts);
344 if (!
s->fifo[0] || !
s->fifo[1])
361 static const AVFilterPad sidechaingate_inputs[] = {
371 static const AVFilterPad sidechaingate_outputs[] = {
375 .config_props = scconfig_output,
380 .
name =
"sidechaingate",
382 .priv_class = &agate_sidechaingate_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.
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.
#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)
const char * name
Filter name.
const AVFilter ff_af_agate
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.
AVFILTER_DEFINE_CLASS_EXT(agate_sidechaingate, "agate/sidechaingate", options)
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.
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)
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
static double output_gain(double lin_slope, double ratio, double thres, double knee, double knee_start, double knee_stop, double range, int mode)
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
static const AVOption options[]
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
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
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_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.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
#define IS_FAKE_INFINITY(value)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
AVSampleFormat
Audio sample formats.
const AVFilter ff_af_sidechaingate
const char * name
Pad name.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static const int factor[16]
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define FILTER_OUTPUTS(array)
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)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
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
static int agate_config_input(AVFilterLink *inlink)