78#define OFFSET(x) offsetof(AudioLimiterContext, x)
79#define AF AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
104 s->asc_coeff = pow(0.5,
s->asc_coeff - 0.5) * 2 * -1;
110 double peak,
double limit,
double patt,
int asc)
112 double rdelta = (1.0 -
patt) / (sample_rate * release);
114 if (asc &&
s->auto_release &&
s->asc_c > 0) {
115 double a_att =
limit / (
s->asc_coeff *
s->asc) * (
double)
s->asc_c;
118 double delta =
FFMAX((a_att -
patt) / (sample_rate * release), rdelta / 10);
133 const double *
src = (
const double *)in->
data[0];
135 const int buffer_size =
s->buffer_size;
137 const double release =
s->release;
138 const double limit =
s->limit;
139 double *nextdelta =
s->nextdelta;
141 const double level_out =
s->level_out;
142 const double level_in =
s->level_in;
143 int *nextpos =
s->nextpos;
163 dst = (
double *)
out->data[0];
175 if (
s->auto_release && peak >
limit) {
191 nextdelta[0] = rdelta;
195 for (
i =
s->nextiter;
i < s->nextiter +
s->nextlen;
i++) {
196 int j =
i % buffer_size;
197 double ppeak = 0, pdelta;
203 pdelta = (
limit / peak -
limit / ppeak) / (((buffer_size - nextpos[j] +
s->pos) % buffer_size) /
channels);
204 if (pdelta < nextdelta[j]) {
205 nextdelta[j] = pdelta;
211 s->nextlen =
i -
s->nextiter + 1;
212 nextpos[(
s->nextiter +
s->nextlen) % buffer_size] =
s->pos;
213 nextdelta[(
s->nextiter +
s->nextlen) % buffer_size] = rdelta;
214 nextpos[(
s->nextiter +
s->nextlen + 1) % buffer_size] = -1;
220 buf = &
s->buffer[(
s->pos +
channels) % buffer_size];
228 if (
s->pos ==
s->asc_pos && !
s->asc_changed)
231 if (
s->auto_release &&
s->asc_pos == -1 && peak >
limit) {
241 if ((
s->pos +
channels) % buffer_size == nextpos[
s->nextiter]) {
242 if (
s->auto_release) {
245 if (
s->nextlen > 1) {
246 double ppeak = 0, pdelta;
247 int pnextpos = nextpos[(
s->nextiter + 1) % buffer_size];
252 pdelta = (
limit / ppeak -
s->att) /
253 (((buffer_size + pnextpos -
256 if (pdelta < s->
delta)
260 s->delta = nextdelta[
s->nextiter];
265 nextpos[
s->nextiter] = -1;
266 s->nextiter = (
s->nextiter + 1) % buffer_size;
278 s->att = 0.0000000000001;
282 if (
s->att != 1. && (1. -
s->att) < 0.0000000000001)
285 if (
s->delta != 0. &&
fabs(
s->delta) < 0.00000000000001)
303 new_out_samples =
out->nb_samples;
304 if (
s->in_trim > 0) {
305 int trim =
FFMIN(new_out_samples,
s->in_trim);
306 new_out_samples -= trim;
310 if (new_out_samples <= 0) {
313 }
else if (new_out_samples < out->nb_samples) {
314 int offset =
out->nb_samples - new_out_samples;
315 memmove(
out->extended_data[0],
out->extended_data[0] +
sizeof(
double) *
offset *
out->ch_layout.nb_channels,
316 sizeof(
double) * new_out_samples *
out->ch_layout.nb_channels);
317 out->nb_samples = new_out_samples;
329 out->pts =
s->next_out_pts;
333 s->next_in_pts = in_pts + in_duration;
334 s->next_out_pts =
out->pts + out_duration;
352 s->out_pad -=
frame->nb_samples;
353 frame->pts =
s->next_in_pts;
366 if (obuffer_size < inlink->ch_layout.nb_channels)
369 s->buffer =
av_calloc(obuffer_size,
sizeof(*
s->buffer));
370 s->nextdelta =
av_calloc(obuffer_size,
sizeof(*
s->nextdelta));
372 if (!
s->buffer || !
s->nextdelta || !
s->nextpos)
375 memset(
s->nextpos, -1, obuffer_size *
sizeof(*
s->nextpos));
388 if (
s->buffer_size <= 0) {
425 .p.name =
"alimiter",
427 .p.priv_class = &alimiter_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad alimiter_inputs[]
static double get_rdelta(AudioLimiterContext *s, double release, int sample_rate, double peak, double limit, double patt, int asc)
static int config_input(AVFilterLink *inlink)
static const AVFilterPad alimiter_outputs[]
static int request_frame(AVFilterLink *outlink)
static const AVOption alimiter_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_cold void uninit(AVFilterContext *ctx)
const FFFilter ff_af_alimiter
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next 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 ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
static __device__ float fabs(float a)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVERROR_EOF
End of file.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_SAMPLE_FMT_DBL
double
#define AV_NOPTS_VALUE
Undefined timestamp value.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int sample_rate
Sample rate of the audio data.
#define av_malloc_array(a, b)
static AVFormatContext * ctx
static const int8_t patt[4]
static double limit(double x)