avfilter/af_sidechaincompress: add level_in and level_sc options
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
a814f1d364
commit
376a3bdb7b
@ -350,6 +350,9 @@ hard edge at the threshold in the range of the chosen decibels.
|
|||||||
The filter accepts the following options:
|
The filter accepts the following options:
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
@item level_in
|
||||||
|
Set input gain. Default is 1. Range is between 0.015625 and 64.
|
||||||
|
|
||||||
@item threshold
|
@item threshold
|
||||||
If a signal of second stream rises above this level it will affect the gain
|
If a signal of second stream rises above this level it will affect the gain
|
||||||
reduction of the first stream.
|
reduction of the first stream.
|
||||||
@ -2479,6 +2482,9 @@ processing. See @ref{pan} and @ref{amerge} filter.
|
|||||||
The filter accepts the following options:
|
The filter accepts the following options:
|
||||||
|
|
||||||
@table @option
|
@table @option
|
||||||
|
@item level_in
|
||||||
|
Set input gain. Default is 1. Range is between 0.015625 and 64.
|
||||||
|
|
||||||
@item threshold
|
@item threshold
|
||||||
If a signal of second stream raises above this level it will affect the gain
|
If a signal of second stream raises above this level it will affect the gain
|
||||||
reduction of first stream.
|
reduction of first stream.
|
||||||
@ -2514,6 +2520,9 @@ reduction. Default is @code{average}.
|
|||||||
Should the exact signal be taken in case of @code{peak} or an RMS one in case
|
Should the exact signal be taken in case of @code{peak} or an RMS one in case
|
||||||
of @code{rms}. Default is @code{rms} which is mainly smoother.
|
of @code{rms}. Default is @code{rms} which is mainly smoother.
|
||||||
|
|
||||||
|
@item level_sc
|
||||||
|
Set sidechain gain. Default is 1. Range is between 0.015625 and 64.
|
||||||
|
|
||||||
@item mix
|
@item mix
|
||||||
How much to use compressed signal in output. Default is 1.
|
How much to use compressed signal in output. Default is 1.
|
||||||
Range is between 0 and 1.
|
Range is between 0 and 1.
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
typedef struct SidechainCompressContext {
|
typedef struct SidechainCompressContext {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
|
|
||||||
|
double level_in;
|
||||||
|
double level_sc;
|
||||||
double attack, attack_coeff;
|
double attack, attack_coeff;
|
||||||
double release, release_coeff;
|
double release, release_coeff;
|
||||||
double lin_slope;
|
double lin_slope;
|
||||||
@ -63,19 +65,21 @@ typedef struct SidechainCompressContext {
|
|||||||
#define F AV_OPT_FLAG_FILTERING_PARAM
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
||||||
|
|
||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
{ "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F },
|
{ "level_in", "set input gain", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
|
||||||
{ "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F },
|
{ "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F },
|
||||||
{ "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F },
|
{ "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F },
|
||||||
{ "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F },
|
{ "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F },
|
||||||
{ "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 64, A|F },
|
{ "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F },
|
||||||
{ "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F },
|
{ "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 64, A|F },
|
||||||
{ "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" },
|
{ "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F },
|
||||||
{ "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" },
|
{ "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" },
|
||||||
{ "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" },
|
{ "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" },
|
||||||
{ "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" },
|
{ "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" },
|
||||||
{ "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" },
|
{ "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" },
|
||||||
{ "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" },
|
{ "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" },
|
||||||
{ "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F },
|
{ "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" },
|
||||||
|
{ "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F },
|
||||||
|
{ "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -142,6 +146,7 @@ static int compressor_config_output(AVFilterLink *outlink)
|
|||||||
|
|
||||||
static void compressor(SidechainCompressContext *s,
|
static void compressor(SidechainCompressContext *s,
|
||||||
double *sample, const double *scsrc, int nb_samples,
|
double *sample, const double *scsrc, int nb_samples,
|
||||||
|
double level_in, double level_sc,
|
||||||
AVFilterLink *inlink, AVFilterLink *sclink)
|
AVFilterLink *inlink, AVFilterLink *sclink)
|
||||||
{
|
{
|
||||||
const double makeup = s->makeup;
|
const double makeup = s->makeup;
|
||||||
@ -151,14 +156,14 @@ static void compressor(SidechainCompressContext *s,
|
|||||||
for (i = 0; i < nb_samples; i++) {
|
for (i = 0; i < nb_samples; i++) {
|
||||||
double abs_sample, gain = 1.0;
|
double abs_sample, gain = 1.0;
|
||||||
|
|
||||||
abs_sample = fabs(scsrc[0]);
|
abs_sample = fabs(scsrc[0] * level_sc);
|
||||||
|
|
||||||
if (s->link == 1) {
|
if (s->link == 1) {
|
||||||
for (c = 1; c < sclink->channels; c++)
|
for (c = 1; c < sclink->channels; c++)
|
||||||
abs_sample = FFMAX(fabs(scsrc[c]), abs_sample);
|
abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample);
|
||||||
} else {
|
} else {
|
||||||
for (c = 1; c < sclink->channels; c++)
|
for (c = 1; c < sclink->channels; c++)
|
||||||
abs_sample += fabs(scsrc[c]);
|
abs_sample += fabs(scsrc[c] * level_sc);
|
||||||
|
|
||||||
abs_sample /= sclink->channels;
|
abs_sample /= sclink->channels;
|
||||||
}
|
}
|
||||||
@ -174,7 +179,7 @@ static void compressor(SidechainCompressContext *s,
|
|||||||
s->compressed_knee_stop, s->detection);
|
s->compressed_knee_stop, s->detection);
|
||||||
|
|
||||||
for (c = 0; c < inlink->channels; c++)
|
for (c = 0; c < inlink->channels; c++)
|
||||||
sample[c] *= (gain * makeup * mix + (1. - mix));
|
sample[c] *= level_in * (gain * makeup * mix + (1. - mix));
|
||||||
|
|
||||||
sample += inlink->channels;
|
sample += inlink->channels;
|
||||||
scsrc += sclink->channels;
|
scsrc += sclink->channels;
|
||||||
@ -208,6 +213,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame)
|
|||||||
scsrc = (const double *)s->input_frame[1]->data[0];
|
scsrc = (const double *)s->input_frame[1]->data[0];
|
||||||
|
|
||||||
compressor(s, sample, scsrc, nb_samples,
|
compressor(s, sample, scsrc, nb_samples,
|
||||||
|
s->level_in, s->level_sc,
|
||||||
ctx->inputs[0], ctx->inputs[1]);
|
ctx->inputs[0], ctx->inputs[1]);
|
||||||
ret = ff_filter_frame(outlink, s->input_frame[0]);
|
ret = ff_filter_frame(outlink, s->input_frame[0]);
|
||||||
|
|
||||||
@ -343,6 +349,7 @@ static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *frame)
|
|||||||
|
|
||||||
sample = (double *)frame->data[0];
|
sample = (double *)frame->data[0];
|
||||||
compressor(s, sample, sample, frame->nb_samples,
|
compressor(s, sample, sample, frame->nb_samples,
|
||||||
|
s->level_in, s->level_in,
|
||||||
inlink, inlink);
|
inlink, inlink);
|
||||||
|
|
||||||
return ff_filter_frame(outlink, frame);
|
return ff_filter_frame(outlink, frame);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user