Go to the documentation of this file.
71 #define OFFSET(x) offsetof(CompandContext, x)
72 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
75 {
"attacks",
"set time over which increase of volume is determined",
OFFSET(attacks),
AV_OPT_TYPE_STRING, { .str =
"0" }, 0, 0,
A },
76 {
"decays",
"set time over which decrease of volume is determined",
OFFSET(decays),
AV_OPT_TYPE_STRING, { .str =
"0.8" }, 0, 0,
A },
77 {
"points",
"set points of transfer function",
OFFSET(points),
AV_OPT_TYPE_STRING, { .str =
"-70/-70|-60/-20|1/0" }, 0, 0,
A },
81 {
"delay",
"set delay for samples before sending them to volume adjuster",
OFFSET(delay),
AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, 20,
A },
108 for (p = item_str; *p; p++) {
109 if (*p ==
' ' || *p ==
'|')
127 double in_log, out_log;
130 if (in_lin < s->in_min_lin)
131 return s->out_min_lin;
133 in_log = log(in_lin);
135 for (
i = 1;
i <
s->nb_segments;
i++)
136 if (in_log <= s->segments[
i].x)
138 cs = &
s->segments[
i - 1];
140 out_log = cs->
y + in_log * (cs->
a * in_log + cs->
b);
150 const int nb_samples =
frame->nb_samples;
171 for (chan = 0; chan <
channels; chan++) {
172 const double *
src = (
double *)
frame->extended_data[chan];
176 for (
i = 0;
i < nb_samples;
i++) {
183 if (
frame != out_frame)
189 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a))
196 const int nb_samples =
frame->nb_samples;
207 for (chan = 0; chan <
channels; chan++) {
208 AVFrame *delay_frame =
s->delay_frame;
209 const double *
src = (
double *)
frame->extended_data[chan];
214 count =
s->delay_count;
215 dindex =
s->delay_index;
216 for (
i = 0, oindex = 0;
i < nb_samples;
i++) {
217 const double in =
src[
i];
220 if (count >=
s->delay_samples) {
233 out_frame->
pts =
s->pts;
246 dindex =
MOD(dindex + 1,
s->delay_samples);
250 s->delay_count = count;
251 s->delay_index = dindex;
280 for (chan = 0; chan <
channels; chan++) {
281 AVFrame *delay_frame =
s->delay_frame;
283 double *dst = (
double *)
frame->extended_data[chan];
286 dindex =
s->delay_index;
287 for (
i = 0;
i <
frame->nb_samples;
i++) {
289 dindex =
MOD(dindex + 1,
s->delay_samples);
292 s->delay_count -=
frame->nb_samples;
293 s->delay_index = dindex;
303 double radius =
s->curve_dB *
M_LN10 / 20.0;
304 char *p, *saveptr =
NULL;
306 int nb_attacks, nb_decays, nb_points;
307 int new_nb_items, num;
323 "Number of attacks/decays bigger than number of channels. Ignoring rest of entries.\n");
331 s->nb_segments = (nb_points + 4) * 2;
332 s->segments =
av_calloc(
s->nb_segments,
sizeof(*
s->segments));
334 if (!
s->channels || !
s->segments) {
340 for (
i = 0, new_nb_items = 0;
i < nb_attacks;
i++) {
341 char *tstr =
av_strtok(p,
" |", &saveptr);
347 new_nb_items += sscanf(tstr,
"%lf", &
s->channels[
i].attack) == 1;
348 if (
s->channels[
i].attack < 0) {
353 nb_attacks = new_nb_items;
356 for (
i = 0, new_nb_items = 0;
i < nb_decays;
i++) {
357 char *tstr =
av_strtok(p,
" |", &saveptr);
363 new_nb_items += sscanf(tstr,
"%lf", &
s->channels[
i].decay) == 1;
364 if (
s->channels[
i].decay < 0) {
369 nb_decays = new_nb_items;
371 if (nb_attacks != nb_decays) {
373 "Number of attacks %d differs from number of decays %d.\n",
374 nb_attacks, nb_decays);
380 s->channels[
i].attack =
s->channels[nb_decays - 1].attack;
381 s->channels[
i].decay =
s->channels[nb_decays - 1].decay;
384 #define S(x) s->segments[2 * ((x) + 1)]
386 for (
i = 0, new_nb_items = 0;
i < nb_points;
i++) {
387 char *tstr =
av_strtok(p,
" |", &saveptr);
389 if (!tstr || sscanf(tstr,
"%lf/%lf", &
S(
i).x, &
S(
i).y) != 2) {
391 "Invalid and/or missing input/output value.\n");
395 if (
i &&
S(
i - 1).x >
S(
i).x) {
397 "Transfer function input values must be increasing.\n");
408 if (num == 0 ||
S(num - 1).x)
412 #define S(x) s->segments[2 * (x)]
414 S(0).x =
S(1).x - 2 *
s->curve_dB;
419 for (
i = 2;
i < num;
i++) {
420 double g1 = (
S(
i - 1).y -
S(
i - 2).y) * (
S(
i - 0).x -
S(
i - 1).x);
421 double g2 = (
S(
i - 0).y -
S(
i - 1).y) * (
S(
i - 1).x -
S(
i - 2).x);
427 for (j = --
i; j < num; j++)
431 for (
i = 0;
i <
s->nb_segments;
i += 2) {
432 s->segments[
i].y +=
s->gain_dB;
437 #define L(x) s->segments[i - (x)]
438 for (
i = 4;
i <
s->nb_segments;
i += 2) {
439 double x, y, cx, cy, in1, in2, out1, out2, theta,
len,
r;
442 L(4).b = (
L(2).y -
L(4).y) / (
L(2).x -
L(4).x);
445 L(2).b = (
L(0).y -
L(2).y) / (
L(0).x -
L(2).x);
447 theta = atan2(
L(2).y -
L(4).y,
L(2).x -
L(4).x);
450 L(3).x =
L(2).x -
r * cos(theta);
451 L(3).y =
L(2).y -
r * sin(theta);
453 theta = atan2(
L(0).y -
L(2).y,
L(0).x -
L(2).x);
456 x =
L(2).x +
r * cos(theta);
457 y =
L(2).y +
r * sin(theta);
459 cx = (
L(3).x +
L(2).x + x) / 3;
460 cy = (
L(3).y +
L(2).y + y) / 3;
467 in2 =
L(2).x -
L(3).x;
468 out2 =
L(2).y -
L(3).y;
469 L(3).a = (out2 / in2 - out1 / in1) / (in2 - in1);
470 L(3).b = out1 / in1 -
L(3).a * in1;
475 s->in_min_lin =
exp(
s->segments[1].x);
476 s->out_min_lin =
exp(
s->segments[1].y);
493 if (
s->delay_samples <= 0) {
499 if (!
s->delay_frame) {
504 s->delay_frame->format = outlink->
format;
505 s->delay_frame->nb_samples =
s->delay_samples;
559 "Compress or expand audio dynamic range."),
561 .priv_class = &compand_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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 int compand_delay(AVFilterContext *ctx, AVFrame *frame)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVFilter ff_af_compand
#define AVERROR_EOF
End of file.
#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.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static av_cold int init(AVFilterContext *ctx)
const char * name
Filter name.
A link between two filters.
int channels
Number of channels.
AVFILTER_DEFINE_CLASS(compand)
static int request_frame(AVFilterLink *outlink)
static int config_output(AVFilterLink *outlink)
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static const AVOption compand_options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int compand_nodelay(AVFilterContext *ctx, AVFrame *frame)
static const AVFilterPad compand_inputs[]
#define FILTER_INPUTS(array)
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).
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static double get_volume(CompandContext *s, double in_lin)
static void update_volume(ChanParam *cp, double in)
int(* compand)(AVFilterContext *ctx, AVFrame *frame)
CompandSegment * segments
static int compand_drain(AVFilterLink *outlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int format
agreed upon media format
static av_const double hypot(double x, double y)
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
int sample_rate
samples per second
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static av_cold void uninit(AVFilterContext *ctx)
@ AV_SAMPLE_FMT_DBLP
double, planar
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static void count_items(char *item_str, int *nb_items)
#define FILTER_OUTPUTS(array)
static const AVFilterPad compand_outputs[]