Go to the documentation of this file.
94 #define OFFSET(x) offsetof(MCompandContext, x)
95 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
98 {
"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 },
114 for (
i = 0;
i <
s->nb_bands;
i++) {
126 static void count_items(
char *item_str,
int *nb_items,
char delimiter)
131 for (p = item_str; *p; p++) {
139 double delta = in -
cb->volume[ch];
142 cb->volume[ch] +=
delta *
cb->attack_rate[ch];
144 cb->volume[ch] +=
delta *
cb->decay_rate[ch];
150 double in_log, out_log;
153 if (in_lin <= s->in_min_lin)
154 return s->out_min_lin;
156 in_log =
log(in_lin);
158 for (
i = 1;
i <
s->nb_segments;
i++)
159 if (in_log <= s->segments[
i].x)
161 cs = &
s->segments[
i - 1];
163 out_log = cs->
y + in_log * (cs->
a * in_log + cs->
b);
171 int new_nb_items, num;
172 char *saveptr =
NULL;
176 #define S(x) s->segments[2 * ((x) + 1)]
177 for (
i = 0, new_nb_items = 0;
i < nb_points;
i++) {
178 char *tstr =
av_strtok(p,
",", &saveptr);
180 if (!tstr || sscanf(tstr,
"%lf/%lf", &
S(
i).x, &
S(
i).y) != 2) {
182 "Invalid and/or missing input/output value.\n");
185 if (
i &&
S(
i - 1).x >
S(
i).x) {
187 "Transfer function input values must be increasing.\n");
197 if (num == 0 ||
S(num - 1).x)
201 #define S(x) s->segments[2 * (x)]
203 S(0).x =
S(1).x - 2 *
s->curve_dB;
208 for (
i = 2;
i < num;
i++) {
209 double g1 = (
S(
i - 1).y -
S(
i - 2).y) * (
S(
i - 0).x -
S(
i - 1).x);
210 double g2 = (
S(
i - 0).y -
S(
i - 1).y) * (
S(
i - 1).x -
S(
i - 2).x);
216 for (j = --
i; j < num; j++)
220 for (
i = 0;
i <
s->nb_segments;
i += 2) {
221 s->segments[
i].y +=
s->gain_dB;
226 #define L(x) s->segments[i - (x)]
227 for (
i = 4;
i <
s->nb_segments;
i += 2) {
228 double x, y, cx, cy, in1, in2, out1, out2, theta,
len,
r;
231 L(4).b = (
L(2).y -
L(4).y) / (
L(2).x -
L(4).x);
234 L(2).b = (
L(0).y -
L(2).y) / (
L(0).x -
L(2).x);
236 theta = atan2(
L(2).y -
L(4).y,
L(2).x -
L(4).x);
239 L(3).x =
L(2).x -
r * cos(theta);
240 L(3).y =
L(2).y -
r * sin(theta);
242 theta = atan2(
L(0).y -
L(2).y,
L(0).x -
L(2).x);
245 x =
L(2).x +
r * cos(theta);
246 y =
L(2).y +
r * sin(theta);
248 cx = (
L(3).x +
L(2).x + x) / 3;
249 cy = (
L(3).y +
L(2).y + y) / 3;
256 in2 =
L(2).x -
L(3).x;
257 out2 =
L(2).y -
L(3).y;
258 L(3).a = (out2 / in2 - out1 / in1) / (in2 - in1);
259 L(3).b = out1 / in1 -
L(3).a * in1;
264 s->in_min_lin =
exp(
s->segments[1].x);
265 s->out_min_lin =
exp(
s->segments[1].y);
273 y[1] = 2 * x[0] * x[1];
274 y[2] = 2 * x[0] * x[2] + x[1] * x[1];
275 y[3] = 2 * x[1] * x[2];
282 double Q = sqrt(.5),
alpha = sin(w0) / (2*
Q);
289 x[0] = (1 - cos(w0))/2;
291 x[2] = (1 - cos(w0))/2;
292 x[3] = (1 + cos(w0))/2;
293 x[4] = -(1 + cos(w0));
294 x[5] = (1 + cos(w0))/2;
299 for (norm = x[6],
i = 0;
i < 9; ++
i)
317 int ret, ch,
i, k, new_nb_items, nb_bands;
318 char *p =
s->args, *saveptr =
NULL;
319 int max_delay_size = 0;
322 s->nb_bands =
FFMAX(1, nb_bands);
328 for (
i = 0, new_nb_items = 0;
i < nb_bands;
i++) {
329 int nb_points, nb_attacks, nb_items = 0;
330 char *tstr2, *tstr =
av_strtok(p,
"|", &saveptr);
331 char *p2, *p3, *saveptr2 =
NULL, *saveptr3 =
NULL;
349 if (!nb_attacks || nb_attacks & 1) {
357 if (!
s->bands[
i].attack_rate || !
s->bands[
i].decay_rate || !
s->bands[
i].volume)
361 char *tstr3 =
av_strtok(p3,
",", &saveptr3);
364 sscanf(tstr3,
"%lf", &
s->bands[
i].attack_rate[k]);
366 sscanf(tstr3,
"%lf", &
s->bands[
i].decay_rate[k]);
368 if (
s->bands[
i].attack_rate[k] > 1.0 / outlink->
sample_rate) {
369 s->bands[
i].attack_rate[k] = 1.0 -
exp(-1.0 / (outlink->
sample_rate *
s->bands[
i].attack_rate[k]));
371 s->bands[
i].attack_rate[k] = 1.0;
374 if (
s->bands[
i].decay_rate[k] > 1.0 / outlink->
sample_rate) {
375 s->bands[
i].decay_rate[k] = 1.0 -
exp(-1.0 / (outlink->
sample_rate *
s->bands[
i].decay_rate[k]));
377 s->bands[
i].decay_rate[k] = 1.0;
382 s->bands[
i].attack_rate[ch] =
s->bands[
i].attack_rate[k - 1];
383 s->bands[
i].decay_rate[ch] =
s->bands[
i].decay_rate[k - 1];
391 sscanf(tstr2,
"%lf", &
s->bands[
i].transfer_fn.curve_dB);
393 radius =
s->bands[
i].transfer_fn.curve_dB *
M_LN10 / 20.0;
402 s->bands[
i].transfer_fn.nb_segments = (nb_points + 4) * 2;
403 s->bands[
i].transfer_fn.segments =
av_calloc(
s->bands[
i].transfer_fn.nb_segments,
405 if (!
s->bands[
i].transfer_fn.segments)
420 new_nb_items += sscanf(tstr2,
"%lf", &
s->bands[
i].topfreq) == 1;
421 if (
s->bands[
i].topfreq < 0 ||
s->bands[
i].topfreq >= outlink->
sample_rate / 2.0) {
426 if (
s->bands[
i].topfreq != 0) {
434 sscanf(tstr2,
"%lf", &
s->bands[
i].delay);
439 double initial_volume;
441 sscanf(tstr2,
"%lf", &initial_volume);
442 initial_volume = pow(10.0, initial_volume / 20);
445 s->bands[
i].volume[k] = initial_volume;
450 sscanf(tstr2,
"%lf", &
s->bands[
i].transfer_fn.gain_dB);
455 s->nb_bands = new_nb_items;
457 for (
i = 0; max_delay_size > 0 &&
i <
s->nb_bands;
i++) {
459 if (!
s->bands[
i].delay_buf)
462 s->delay_buf_size = max_delay_size;
467 #define CONVOLVE _ _ _ _
470 double *ibuf,
double *obuf_low,
471 double *obuf_high,
size_t len)
473 double out_low, out_high;
477 #define _ out_low += p->coefs[j] * p->previous[ch][p->pos + j].in \
478 - p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_low, j++;
481 out_low = p->
coefs[0] * *ibuf;
483 *obuf_low++ = out_low;
486 #define _ out_high += p->coefs[j+N+1] * p->previous[ch][p->pos + j].in \
487 - p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_high, j++;
490 out_high = p->
coefs[
N+1] * *ibuf;
492 *obuf_high++ = out_high;
504 for (
i = 0;
i <
len;
i++) {
505 double level_in_lin, level_out_lin, checkbuf;
510 level_in_lin = l->
volume[ch];
513 if (
c->delay_buf_size <= 0) {
514 checkbuf = ibuf[
i] * level_out_lin;
536 l->
delay_size) %
c->delay_buf_size] * level_out_lin;
579 double *
a, *
dst = (
double *)
out->extended_data[ch];
581 for (band = 0, abuf = in, bbuf =
s->band_buf2, cbuf =
s->band_buf1; band < s->nb_bands; band++) {
640 "Multiband Compress or expand audio dynamic range."),
642 .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.
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.
#define FILTER_INPUTS(array)
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_OUTPUTS(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
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
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.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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[]
static int mcompand_channel(MCompandContext *c, CompBand *l, double *ibuf, double *obuf, int len, int ch)
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
static void update_volume(CompBand *cb, double in, int ch)