Go to the documentation of this file.
64 #define OFFSET(x) offsetof(AudioLimiterContext, x)
65 #define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
89 s->asc_coeff = pow(0.5,
s->asc_coeff - 0.5) * 2 * -1;
95 double peak,
double limit,
double patt,
int asc)
99 if (asc &&
s->auto_release &&
s->asc_c > 0) {
100 double a_att =
limit / (
s->asc_coeff *
s->asc) * (
double)
s->asc_c;
118 const double *
src = (
const double *)in->
data[0];
120 const int buffer_size =
s->buffer_size;
121 double *dst, *
buffer =
s->buffer;
122 const double release =
s->release;
123 const double limit =
s->limit;
124 double *nextdelta =
s->nextdelta;
126 const double level_out =
s->level_out;
127 const double level_in =
s->level_in;
128 int *nextpos =
s->nextpos;
143 dst = (
double *)
out->data[0];
155 if (
s->auto_release && peak >
limit) {
167 if (delta < s->
delta) {
171 nextdelta[0] = rdelta;
175 for (
i =
s->nextiter; i < s->nextiter +
s->nextlen;
i++) {
176 int j =
i % buffer_size;
177 double ppeak, pdelta;
181 pdelta = (
limit / peak -
limit / ppeak) / (((buffer_size - nextpos[j] +
s->pos) % buffer_size) /
channels);
182 if (pdelta < nextdelta[j]) {
183 nextdelta[j] = pdelta;
189 s->nextlen =
i -
s->nextiter + 1;
190 nextpos[(
s->nextiter +
s->nextlen) % buffer_size] =
s->pos;
191 nextdelta[(
s->nextiter +
s->nextlen) % buffer_size] = rdelta;
192 nextpos[(
s->nextiter +
s->nextlen + 1) % buffer_size] = -1;
198 buf = &
s->buffer[(
s->pos +
channels) % buffer_size];
206 if (
s->pos ==
s->asc_pos && !
s->asc_changed)
209 if (
s->auto_release &&
s->asc_pos == -1 && peak >
limit) {
217 dst[
c] = buf[
c] *
s->att;
219 if ((
s->pos +
channels) % buffer_size == nextpos[
s->nextiter]) {
220 if (
s->auto_release) {
223 if (
s->nextlen > 1) {
224 int pnextpos = nextpos[(
s->nextiter + 1) % buffer_size];
228 double pdelta = (
limit / ppeak -
s->att) /
229 (((buffer_size + pnextpos -
232 if (pdelta < s->
delta)
236 s->delta = nextdelta[
s->nextiter];
241 nextpos[
s->nextiter] = -1;
242 s->nextiter = (
s->nextiter + 1) % buffer_size;
254 s->att = 0.0000000000001;
255 s->delta = (1.0 -
s->att) / (
inlink->sample_rate * release);
258 if (
s->att != 1. && (1. -
s->att) < 0.0000000000001)
261 if (
s->delta != 0. &&
fabs(
s->delta) < 0.00000000000001)
284 obuffer_size =
inlink->sample_rate *
inlink->channels * 100 / 1000. +
inlink->channels;
285 if (obuffer_size < inlink->
channels)
288 s->buffer =
av_calloc(obuffer_size,
sizeof(*
s->buffer));
289 s->nextdelta =
av_calloc(obuffer_size,
sizeof(*
s->nextdelta));
291 if (!
s->buffer || !
s->nextdelta || !
s->nextpos)
294 memset(
s->nextpos, -1, obuffer_size *
sizeof(*
s->nextpos));
295 s->buffer_size =
inlink->sample_rate *
s->attack *
inlink->channels;
296 s->buffer_size -=
s->buffer_size %
inlink->channels;
298 if (
s->buffer_size <= 0) {
335 .priv_class = &alimiter_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static const AVOption alimiter_options[]
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
static av_cold int init(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#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.
static const AVFilterPad alimiter_inputs[]
static const AVFilterPad alimiter_outputs[]
const AVFilter ff_af_alimiter
const char * name
Filter name.
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold void uninit(AVFilterContext *ctx)
#define FILTER_INPUTS(array)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
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.
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.
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.
#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)
#define av_malloc_array(a, b)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
static double limit(double x)
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
static const int8_t patt[4]
static double get_rdelta(AudioLimiterContext *s, double release, int sample_rate, double peak, double limit, double patt, int asc)
AVFILTER_DEFINE_CLASS(alimiter)
#define FILTER_OUTPUTS(array)
static int config_input(AVFilterLink *inlink)
@ AV_SAMPLE_FMT_DBL
double