Go to the documentation of this file.
93 #define OFFSET(x) offsetof(MCompandContext, x)
94 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
97 {
"args",
"set parameters for each band",
OFFSET(args),
AV_OPT_TYPE_STRING, { .str =
"0.005,0.1 6 -47/-40,-34/-34,-17/-33 100 | 0.003,0.05 6 -47/-40,-34/-34,-17/-33 400 | 0.000625,0.0125 6 -47/-40,-34/-34,-15/-33 1600 | 0.0001,0.025 6 -47/-40,-34/-34,-31/-31,-0/-30 6400 | 0,0.025 6 -38/-31,-28/-28,-0/-25 22000" }, 0, 0,
A },
113 for (
i = 0;
i <
s->nb_bands;
i++) {
125 static void count_items(
char *item_str,
int *nb_items,
char delimiter)
130 for (p = item_str; *p; p++) {
138 double delta = in -
cb->volume[ch];
141 cb->volume[ch] +=
delta *
cb->attack_rate[ch];
143 cb->volume[ch] +=
delta *
cb->decay_rate[ch];
149 double in_log, out_log;
152 if (in_lin <= s->in_min_lin)
153 return s->out_min_lin;
155 in_log =
log(in_lin);
157 for (
i = 1;
i <
s->nb_segments;
i++)
158 if (in_log <= s->segments[
i].x)
160 cs = &
s->segments[
i - 1];
162 out_log = cs->
y + in_log * (cs->
a * in_log + cs->
b);
170 int new_nb_items, num;
171 char *saveptr =
NULL;
175 #define S(x) s->segments[2 * ((x) + 1)]
176 for (
i = 0, new_nb_items = 0;
i < nb_points;
i++) {
177 char *tstr =
av_strtok(p,
",", &saveptr);
179 if (!tstr || sscanf(tstr,
"%lf/%lf", &
S(
i).x, &
S(
i).y) != 2) {
181 "Invalid and/or missing input/output value.\n");
184 if (
i &&
S(
i - 1).x >
S(
i).x) {
186 "Transfer function input values must be increasing.\n");
196 if (num == 0 ||
S(num - 1).x)
200 #define S(x) s->segments[2 * (x)]
202 S(0).x =
S(1).x - 2 *
s->curve_dB;
207 for (
i = 2;
i < num;
i++) {
208 double g1 = (
S(
i - 1).y -
S(
i - 2).y) * (
S(
i - 0).x -
S(
i - 1).x);
209 double g2 = (
S(
i - 0).y -
S(
i - 1).y) * (
S(
i - 1).x -
S(
i - 2).x);
215 for (j = --
i; j < num; j++)
219 for (
i = 0;
i <
s->nb_segments;
i += 2) {
220 s->segments[
i].y +=
s->gain_dB;
225 #define L(x) s->segments[i - (x)]
226 for (
i = 4;
i <
s->nb_segments;
i += 2) {
227 double x, y, cx, cy, in1, in2, out1, out2, theta,
len,
r;
230 L(4).b = (
L(2).y -
L(4).y) / (
L(2).x -
L(4).x);
233 L(2).b = (
L(0).y -
L(2).y) / (
L(0).x -
L(2).x);
235 theta = atan2(
L(2).y -
L(4).y,
L(2).x -
L(4).x);
238 L(3).x =
L(2).x -
r * cos(theta);
239 L(3).y =
L(2).y -
r * sin(theta);
241 theta = atan2(
L(0).y -
L(2).y,
L(0).x -
L(2).x);
244 x =
L(2).x +
r * cos(theta);
245 y =
L(2).y +
r * sin(theta);
247 cx = (
L(3).x +
L(2).x + x) / 3;
248 cy = (
L(3).y +
L(2).y + y) / 3;
255 in2 =
L(2).x -
L(3).x;
256 out2 =
L(2).y -
L(3).y;
257 L(3).a = (out2 / in2 - out1 / in1) / (in2 - in1);
258 L(3).b = out1 / in1 -
L(3).a * in1;
263 s->in_min_lin =
exp(
s->segments[1].x);
264 s->out_min_lin =
exp(
s->segments[1].y);
272 y[1] = 2 * x[0] * x[1];
273 y[2] = 2 * x[0] * x[2] + x[1] * x[1];
274 y[3] = 2 * x[1] * x[2];
281 double Q = sqrt(.5),
alpha = sin(w0) / (2*Q);
288 x[0] = (1 - cos(w0))/2;
290 x[2] = (1 - cos(w0))/2;
291 x[3] = (1 + cos(w0))/2;
292 x[4] = -(1 + cos(w0));
293 x[5] = (1 + cos(w0))/2;
298 for (norm = x[6],
i = 0;
i < 9; ++
i)
316 int ret, ch,
i, k, new_nb_items, nb_bands;
317 char *p =
s->args, *saveptr =
NULL;
318 int max_delay_size = 0;
321 s->nb_bands =
FFMAX(1, nb_bands);
327 for (
i = 0, new_nb_items = 0;
i < nb_bands;
i++) {
328 int nb_points, nb_attacks, nb_items = 0;
329 char *tstr2, *tstr =
av_strtok(p,
"|", &saveptr);
330 char *p2, *p3, *saveptr2 =
NULL, *saveptr3 =
NULL;
348 if (!nb_attacks || nb_attacks & 1) {
356 if (!
s->bands[
i].attack_rate || !
s->bands[
i].decay_rate || !
s->bands[
i].volume)
360 char *tstr3 =
av_strtok(p3,
",", &saveptr3);
363 sscanf(tstr3,
"%lf", &
s->bands[
i].attack_rate[k]);
365 sscanf(tstr3,
"%lf", &
s->bands[
i].decay_rate[k]);
367 if (
s->bands[
i].attack_rate[k] > 1.0 / outlink->
sample_rate) {
368 s->bands[
i].attack_rate[k] = 1.0 -
exp(-1.0 / (outlink->
sample_rate *
s->bands[
i].attack_rate[k]));
370 s->bands[
i].attack_rate[k] = 1.0;
373 if (
s->bands[
i].decay_rate[k] > 1.0 / outlink->
sample_rate) {
374 s->bands[
i].decay_rate[k] = 1.0 -
exp(-1.0 / (outlink->
sample_rate *
s->bands[
i].decay_rate[k]));
376 s->bands[
i].decay_rate[k] = 1.0;
381 s->bands[
i].attack_rate[ch] =
s->bands[
i].attack_rate[k - 1];
382 s->bands[
i].decay_rate[ch] =
s->bands[
i].decay_rate[k - 1];
390 sscanf(tstr2,
"%lf", &
s->bands[
i].transfer_fn.curve_dB);
392 radius =
s->bands[
i].transfer_fn.curve_dB *
M_LN10 / 20.0;
401 s->bands[
i].transfer_fn.nb_segments = (nb_points + 4) * 2;
402 s->bands[
i].transfer_fn.segments =
av_calloc(
s->bands[
i].transfer_fn.nb_segments,
404 if (!
s->bands[
i].transfer_fn.segments)
419 new_nb_items += sscanf(tstr2,
"%lf", &
s->bands[
i].topfreq) == 1;
420 if (
s->bands[
i].topfreq < 0 ||
s->bands[
i].topfreq >= outlink->
sample_rate / 2) {
425 if (
s->bands[
i].topfreq != 0) {
433 sscanf(tstr2,
"%lf", &
s->bands[
i].delay);
438 double initial_volume;
440 sscanf(tstr2,
"%lf", &initial_volume);
441 initial_volume = pow(10.0, initial_volume / 20);
444 s->bands[
i].volume[k] = initial_volume;
449 sscanf(tstr2,
"%lf", &
s->bands[
i].transfer_fn.gain_dB);
454 s->nb_bands = new_nb_items;
456 for (
i = 0; max_delay_size > 0 &&
i <
s->nb_bands;
i++) {
458 if (!
s->bands[
i].delay_buf)
461 s->delay_buf_size = max_delay_size;
466 #define CONVOLVE _ _ _ _
469 double *ibuf,
double *obuf_low,
470 double *obuf_high,
size_t len)
472 double out_low, out_high;
476 #define _ out_low += p->coefs[j] * p->previous[ch][p->pos + j].in \
477 - p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_low, j++;
480 out_low = p->
coefs[0] * *ibuf;
482 *obuf_low++ = out_low;
485 #define _ out_high += p->coefs[j+N+1] * p->previous[ch][p->pos + j].in \
486 - p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_high, j++;
489 out_high = p->
coefs[
N+1] * *ibuf;
491 *obuf_high++ = out_high;
503 for (
i = 0;
i <
len;
i++) {
504 double level_in_lin, level_out_lin, checkbuf;
509 level_in_lin = l->
volume[ch];
512 if (
c->delay_buf_size <= 0) {
513 checkbuf = ibuf[
i] * level_out_lin;
535 l->
delay_size) %
c->delay_buf_size] * level_out_lin;
578 double *
a, *dst = (
double *)
out->extended_data[ch];
580 for (band = 0, abuf = in, bbuf =
s->band_buf2, cbuf =
s->band_buf1; band < s->nb_bands; band++) {
639 "Multiband Compress or expand audio dynamic range."),
641 .priv_class = &mcompand_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
static int request_frame(AVFilterLink *outlink)
static const AVFilterPad mcompand_outputs[]
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 double cb(void *priv, double x, double y)
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.
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 const AVFilterPad mcompand_inputs[]
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
AVFILTER_DEFINE_CLASS(mcompand)
static int config_output(AVFilterLink *outlink)
A filter pad used for either input or output.
#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_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define FILTER_INPUTS(array)
static double get_volume(CompandT *s, double in_lin)
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
static void crossover(int ch, Crossover *p, double *ibuf, double *obuf_low, double *obuf_high, size_t len)
static int crossover_setup(AVFilterLink *outlink, Crossover *p, double frequency)
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
static void square_quadratic(double const *x, double *y)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_const double hypot(double x, double y)
static av_cold void uninit(AVFilterContext *ctx)
CompandSegment * segments
AVFilterContext * src
source filter
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int parse_points(char *points, int nb_points, double radius, CompandT *s, AVFilterContext *ctx)
int sample_rate
samples per second
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
static const AVOption mcompand_options[]
static void count_items(char *item_str, int *nb_items, char delimiter)
uint8_t ** extended_data
pointers to the data planes/channels.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
#define FFSWAP(type, a, b)
@ AV_SAMPLE_FMT_DBLP
double, planar
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
const AVFilter ff_af_mcompand
static const int16_t alpha[]
#define FILTER_OUTPUTS(array)
static int mcompand_channel(MCompandContext *c, CompBand *l, double *ibuf, double *obuf, int len, int ch)
static void update_volume(CompBand *cb, double in, int ch)