64 #define OFFSET(x) offsetof(CompandContext, x)
65 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
68 {
"attacks",
"set time over which increase of volume is determined",
OFFSET(attacks),
AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0,
A },
69 {
"decays",
"set time over which decrease of volume is determined",
OFFSET(decays),
AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0,
A },
74 {
"delay",
"set delay for samples before sending them to volume adjuster",
OFFSET(delay),
AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 20,
A },
135 for (p = item_str; *p; p++) {
155 double in_log, out_log;
158 if (in_lin < s->in_min_lin)
161 in_log = log(in_lin);
164 if (in_log <= s->segments[i + 1].x)
169 out_log = cs->
y + in_log * (cs->
a * in_log + cs->
b);
178 const int channels = inlink->
channels;
192 for (chan = 0; chan < channels; chan++) {
197 for (i = 0; i < nb_samples; i++) {
204 if (frame != out_frame)
210 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a))
216 const int channels = inlink->
channels;
223 for (chan = 0; chan < channels; chan++) {
225 double *dbuf = (
double *)s->
delayptrs[chan];
231 for (i = 0, oindex = 0; i < nb_samples; i++) {
232 const double in = src[i];
267 const int channels = outlink->
channels;
277 for (chan = 0; chan < channels; chan++) {
278 double *dbuf = (
double *)
s->delayptrs[chan];
282 dindex =
s->delay_index;
285 dindex =
MOD(dindex + 1,
s->delay_samples);
289 s->delay_index = dindex;
300 int nb_attacks, nb_decays, nb_points;
301 char *p, *saveptr = NULL;
302 int new_nb_items, num;
310 av_log(ctx,
AV_LOG_ERROR,
"Number of attacks/decays bigger than number of channels.\n");
323 for (i = 0, new_nb_items = 0; i < nb_attacks; i++) {
324 char *tstr =
av_strtok(p,
" ", &saveptr);
330 nb_attacks = new_nb_items;
333 for (i = 0, new_nb_items = 0; i < nb_decays; i++) {
334 char *tstr =
av_strtok(p,
" ", &saveptr);
336 new_nb_items += sscanf(tstr,
"%lf", &s->
channels[i].
decay) == 1;
340 nb_decays = new_nb_items;
342 if (nb_attacks != nb_decays) {
343 av_log(ctx,
AV_LOG_ERROR,
"Number of attacks %d differs from number of decays %d.\n", nb_attacks, nb_decays);
347 #define S(x) s->segments[2 * ((x) + 1)]
349 for (i = 0, new_nb_items = 0; i < nb_points; i++) {
350 char *tstr =
av_strtok(p,
" ", &saveptr);
352 if (sscanf(tstr,
"%lf/%lf", &
S(i).x, &
S(i).
y) != 2) {
356 if (i &&
S(i - 1).x >
S(i).x) {
367 if (num == 0 ||
S(num - 1).x)
371 #define S(x) s->segments[2 * (x)]
378 for (i = 2; i < num; i++) {
379 double g1 = (
S(i - 1).y -
S(i - 2).y) * (
S(i - 0).x -
S(i - 1).x);
380 double g2 = (
S(i - 0).y -
S(i - 1).y) * (
S(i - 1).x -
S(i - 2).x);
386 for (j = --i; j < num; j++)
390 for (i = 0; !i || s->
segments[i - 2].
x; i += 2) {
396 #define L(x) s->segments[i - (x)]
397 for (i = 4; s->
segments[i - 2].
x; i += 2) {
398 double x,
y, cx, cy, in1, in2, out1, out2, theta,
len,
r;
401 L(4).b = (
L(2).y -
L(4).y) / (
L(2).x -
L(4).x);
404 L(2).b = (
L(0).y -
L(2).y) / (
L(0).x -
L(2).x);
406 theta = atan2(
L(2).y -
L(4).y,
L(2).x -
L(4).x);
407 len = sqrt(pow(
L(2).x -
L(4).x, 2.) + pow(
L(2).y -
L(4).y, 2.));
408 r =
FFMIN(radius, len);
409 L(3).x =
L(2).x - r * cos(theta);
410 L(3).y =
L(2).y - r * sin(theta);
412 theta = atan2(
L(0).y -
L(2).y,
L(0).x -
L(2).x);
413 len = sqrt(pow(
L(0).x -
L(2).x, 2.) + pow(
L(0).y -
L(2).y, 2.));
414 r =
FFMIN(radius, len / 2);
415 x =
L(2).x + r * cos(theta);
416 y =
L(2).y + r * sin(theta);
418 cx = (
L(3).x +
L(2).x + x) / 3;
419 cy = (
L(3).y +
L(2).y +
y) / 3;
426 in2 =
L(2).x -
L(3).x;
427 out2 =
L(2).y -
L(3).y;
428 L(3).a = (out2 / in2 - out1 / in1) / (in2-in1);
429 L(3).b = out1 / in1 -
L(3).a * in1;
437 for (i = 0; i < outlink->
channels; i++) {
440 if (cp->
attack > 1.0 / sample_rate)
441 cp->
attack = 1.0 - exp(-1.0 / (sample_rate * cp->
attack));
444 if (cp->
decay > 1.0 / sample_rate)
445 cp->
decay = 1.0 - exp(-1.0 / (sample_rate * cp->
decay));
513 .priv_class = &compand_class,