Go to the documentation of this file.
64 #define OFFSET(x) offsetof(AudioGateContext, x)
65 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
95 double lin_threshold =
s->threshold;
96 double lin_knee_sqrt = sqrt(
s->knee);
99 lin_threshold *= lin_threshold;
101 s->attack_coeff =
FFMIN(1., 1. / (
s->attack *
inlink->sample_rate / 4000.));
102 s->release_coeff =
FFMIN(1., 1. / (
s->release *
inlink->sample_rate / 4000.));
103 s->lin_knee_stop = lin_threshold * lin_knee_sqrt;
104 s->lin_knee_start = lin_threshold / lin_knee_sqrt;
105 s->thres = log(lin_threshold);
106 s->knee_start = log(
s->lin_knee_start);
107 s->knee_stop = log(
s->lin_knee_stop);
113 #define FAKE_INFINITY (65536.0 * 65536.0)
116 #define IS_FAKE_INFINITY(value) (fabs(value-FAKE_INFINITY) < 1.0)
118 static double output_gain(
double lin_slope,
double ratio,
double thres,
119 double knee,
double knee_start,
double knee_stop,
120 double range,
int mode)
122 double slope = log(lin_slope);
123 double tratio = ratio;
129 gain = (slope - thres) * tratio + thres;
133 if (knee > 1. && slope < knee_stop)
136 if (knee > 1. && slope > knee_start)
139 return FFMAX(range,
exp(gain - slope));
143 const double *
src,
double *dst,
const double *scsrc,
144 int nb_samples,
double level_in,
double level_sc,
148 const double makeup =
s->makeup;
149 const double attack_coeff =
s->attack_coeff;
150 const double release_coeff =
s->release_coeff;
153 for (n = 0; n < nb_samples; n++,
src +=
inlink->channels, dst +=
inlink->channels, scsrc += sclink->
channels) {
154 double abs_sample =
fabs(scsrc[0] * level_sc), gain = 1.0;
160 abs_sample =
FFMAX(
fabs(scsrc[
c] * level_sc), abs_sample);
163 abs_sample +=
fabs(scsrc[
c] * level_sc);
169 abs_sample *= abs_sample;
171 s->lin_slope += (abs_sample -
s->lin_slope) * (abs_sample >
s->lin_slope ? attack_coeff : release_coeff);
174 detected =
s->lin_slope >
s->lin_knee_start;
176 detected =
s->lin_slope <
s->lin_knee_stop;
178 if (
s->lin_slope > 0.0 && detected)
180 s->knee,
s->knee_start,
s->knee_stop,
183 factor =
ctx->is_disabled ? 1.f : level_in * gain * makeup;
189 #if CONFIG_AGATE_FILTER
193 const double *
src = (
const double *)in->
data[0];
210 dst = (
double *)
out->data[0];
239 .priv_class = &agate_sidechaingate_class,
250 #if CONFIG_SIDECHAINGATE_FILTER
256 int ret,
i, nb_samples;
280 for (
i = 0;
i < 2;
i++) {
291 dst = (
double *)
out->data[0];
296 (
double *)in[1]->
data[0], nb_samples,
297 s->level_in,
s->level_sc,
298 ctx->inputs[0],
ctx->inputs[1]);
325 &
ctx->inputs[1]->outcfg.channel_layouts);
349 if (!
s->fifo[0] || !
s->fifo[1])
366 static const AVFilterPad sidechaingate_inputs[] = {
376 static const AVFilterPad sidechaingate_outputs[] = {
380 .config_props = scconfig_output,
385 .
name =
"sidechaingate",
387 .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[]
#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
A link between two filters.
int channels
Number of channels.
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)
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
static const AVFilterPad outputs[]
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[]
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_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 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
#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]
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)