Signed-off-by: Paul B Mahol <onemda@gmail.com>
Paul B Mahol authored on 2015/11/30 20:16:57... | ... |
@@ -350,6 +350,9 @@ hard edge at the threshold in the range of the chosen decibels. |
350 | 350 |
The filter accepts the following options: |
351 | 351 |
|
352 | 352 |
@table @option |
353 |
+@item level_in |
|
354 |
+Set input gain. Default is 1. Range is between 0.015625 and 64. |
|
355 |
+ |
|
353 | 356 |
@item threshold |
354 | 357 |
If a signal of second stream rises above this level it will affect the gain |
355 | 358 |
reduction of the first stream. |
... | ... |
@@ -2479,6 +2482,9 @@ processing. See @ref{pan} and @ref{amerge} filter. |
2479 | 2479 |
The filter accepts the following options: |
2480 | 2480 |
|
2481 | 2481 |
@table @option |
2482 |
+@item level_in |
|
2483 |
+Set input gain. Default is 1. Range is between 0.015625 and 64. |
|
2484 |
+ |
|
2482 | 2485 |
@item threshold |
2483 | 2486 |
If a signal of second stream raises above this level it will affect the gain |
2484 | 2487 |
reduction of first stream. |
... | ... |
@@ -2514,6 +2520,9 @@ reduction. Default is @code{average}. |
2514 | 2514 |
Should the exact signal be taken in case of @code{peak} or an RMS one in case |
2515 | 2515 |
of @code{rms}. Default is @code{rms} which is mainly smoother. |
2516 | 2516 |
|
2517 |
+@item level_sc |
|
2518 |
+Set sidechain gain. Default is 1. Range is between 0.015625 and 64. |
|
2519 |
+ |
|
2517 | 2520 |
@item mix |
2518 | 2521 |
How much to use compressed signal in output. Default is 1. |
2519 | 2522 |
Range is between 0 and 1. |
... | ... |
@@ -38,6 +38,8 @@ |
38 | 38 |
typedef struct SidechainCompressContext { |
39 | 39 |
const AVClass *class; |
40 | 40 |
|
41 |
+ double level_in; |
|
42 |
+ double level_sc; |
|
41 | 43 |
double attack, attack_coeff; |
42 | 44 |
double release, release_coeff; |
43 | 45 |
double lin_slope; |
... | ... |
@@ -63,19 +65,21 @@ typedef struct SidechainCompressContext { |
63 | 63 |
#define F AV_OPT_FLAG_FILTERING_PARAM |
64 | 64 |
|
65 | 65 |
static const AVOption options[] = { |
66 |
- { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F }, |
|
67 |
- { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F }, |
|
68 |
- { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F }, |
|
69 |
- { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F }, |
|
70 |
- { "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 64, A|F }, |
|
71 |
- { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F }, |
|
72 |
- { "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" }, |
|
73 |
- { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" }, |
|
74 |
- { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" }, |
|
75 |
- { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" }, |
|
76 |
- { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" }, |
|
77 |
- { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" }, |
|
78 |
- { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F }, |
|
66 |
+ { "level_in", "set input gain", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F }, |
|
67 |
+ { "threshold", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=0.125}, 0.000976563, 1, A|F }, |
|
68 |
+ { "ratio", "set ratio", OFFSET(ratio), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 20, A|F }, |
|
69 |
+ { "attack", "set attack", OFFSET(attack), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 0.01, 2000, A|F }, |
|
70 |
+ { "release", "set release", OFFSET(release), AV_OPT_TYPE_DOUBLE, {.dbl=250}, 0.01, 9000, A|F }, |
|
71 |
+ { "makeup", "set make up gain", OFFSET(makeup), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 64, A|F }, |
|
72 |
+ { "knee", "set knee", OFFSET(knee), AV_OPT_TYPE_DOUBLE, {.dbl=2.82843}, 1, 8, A|F }, |
|
73 |
+ { "link", "set link type", OFFSET(link), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A|F, "link" }, |
|
74 |
+ { "average", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "link" }, |
|
75 |
+ { "maximum", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "link" }, |
|
76 |
+ { "detection", "set detection", OFFSET(detection), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, A|F, "detection" }, |
|
77 |
+ { "peak", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A|F, "detection" }, |
|
78 |
+ { "rms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A|F, "detection" }, |
|
79 |
+ { "level_sc", "set sidechain gain", OFFSET(level_sc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A|F }, |
|
80 |
+ { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, A|F }, |
|
79 | 81 |
{ NULL } |
80 | 82 |
}; |
81 | 83 |
|
... | ... |
@@ -142,6 +146,7 @@ static int compressor_config_output(AVFilterLink *outlink) |
142 | 142 |
|
143 | 143 |
static void compressor(SidechainCompressContext *s, |
144 | 144 |
double *sample, const double *scsrc, int nb_samples, |
145 |
+ double level_in, double level_sc, |
|
145 | 146 |
AVFilterLink *inlink, AVFilterLink *sclink) |
146 | 147 |
{ |
147 | 148 |
const double makeup = s->makeup; |
... | ... |
@@ -151,14 +156,14 @@ static void compressor(SidechainCompressContext *s, |
151 | 151 |
for (i = 0; i < nb_samples; i++) { |
152 | 152 |
double abs_sample, gain = 1.0; |
153 | 153 |
|
154 |
- abs_sample = fabs(scsrc[0]); |
|
154 |
+ abs_sample = fabs(scsrc[0] * level_sc); |
|
155 | 155 |
|
156 | 156 |
if (s->link == 1) { |
157 | 157 |
for (c = 1; c < sclink->channels; c++) |
158 |
- abs_sample = FFMAX(fabs(scsrc[c]), abs_sample); |
|
158 |
+ abs_sample = FFMAX(fabs(scsrc[c] * level_sc), abs_sample); |
|
159 | 159 |
} else { |
160 | 160 |
for (c = 1; c < sclink->channels; c++) |
161 |
- abs_sample += fabs(scsrc[c]); |
|
161 |
+ abs_sample += fabs(scsrc[c] * level_sc); |
|
162 | 162 |
|
163 | 163 |
abs_sample /= sclink->channels; |
164 | 164 |
} |
... | ... |
@@ -174,7 +179,7 @@ static void compressor(SidechainCompressContext *s, |
174 | 174 |
s->compressed_knee_stop, s->detection); |
175 | 175 |
|
176 | 176 |
for (c = 0; c < inlink->channels; c++) |
177 |
- sample[c] *= (gain * makeup * mix + (1. - mix)); |
|
177 |
+ sample[c] *= level_in * (gain * makeup * mix + (1. - mix)); |
|
178 | 178 |
|
179 | 179 |
sample += inlink->channels; |
180 | 180 |
scsrc += sclink->channels; |
... | ... |
@@ -208,6 +213,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *frame) |
208 | 208 |
scsrc = (const double *)s->input_frame[1]->data[0]; |
209 | 209 |
|
210 | 210 |
compressor(s, sample, scsrc, nb_samples, |
211 |
+ s->level_in, s->level_sc, |
|
211 | 212 |
ctx->inputs[0], ctx->inputs[1]); |
212 | 213 |
ret = ff_filter_frame(outlink, s->input_frame[0]); |
213 | 214 |
|
... | ... |
@@ -343,6 +349,7 @@ static int acompressor_filter_frame(AVFilterLink *inlink, AVFrame *frame) |
343 | 343 |
|
344 | 344 |
sample = (double *)frame->data[0]; |
345 | 345 |
compressor(s, sample, sample, frame->nb_samples, |
346 |
+ s->level_in, s->level_in, |
|
346 | 347 |
inlink, inlink); |
347 | 348 |
|
348 | 349 |
return ff_filter_frame(outlink, frame); |