avfilter/af_biquads: implement mix option to all filters

This commit is contained in:
Paul B Mahol 2019-07-08 16:20:57 +02:00
parent 019d729039
commit 7b2d39fc27
2 changed files with 115 additions and 9 deletions

View File

@ -1523,6 +1523,10 @@ kHz
@item width, w
Specify the band-width of a filter in width_type units.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -1542,6 +1546,10 @@ Syntax for the command is : "@var{width_type}"
@item width, w
Change allpass width.
Syntax for the command is : "@var{width}"
@item mix, m
Change allpass mix.
Syntax for the command is : "@var{mix}"
@end table
@section aloop
@ -2460,6 +2468,10 @@ kHz
@item width, w
Specify the band-width of a filter in width_type units.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -2479,6 +2491,10 @@ Syntax for the command is : "@var{width_type}"
@item width, w
Change bandpass width.
Syntax for the command is : "@var{width}"
@item mix, m
Change bandpass mix.
Syntax for the command is : "@var{mix}"
@end table
@section bandreject
@ -2511,6 +2527,10 @@ kHz
@item width, w
Specify the band-width of a filter in width_type units.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -2530,6 +2550,10 @@ Syntax for the command is : "@var{width_type}"
@item width, w
Change bandreject width.
Syntax for the command is : "@var{width}"
@item mix, m
Change bandreject mix.
Syntax for the command is : "@var{mix}"
@end table
@section bass, lowshelf
@ -2569,6 +2593,10 @@ kHz
@item width, w
Determine how steep is the filter's shelf transition.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -2592,6 +2620,10 @@ Syntax for the command is : "@var{width}"
@item gain, g
Change bass gain.
Syntax for the command is : "@var{gain}"
@item mix, m
Change bass mix.
Syntax for the command is : "@var{mix}"
@end table
@section biquad
@ -2614,6 +2646,10 @@ This filter supports the following commands:
@item b2
Change biquad parameter.
Syntax for the command is : "@var{value}"
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@end table
@section bs2b
@ -3303,6 +3339,10 @@ Specify the band-width of a filter in width_type units.
Set the required gain or attenuation in dB.
Beware of clipping when using a positive gain.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -3341,6 +3381,10 @@ Syntax for the command is : "@var{width}"
@item gain, g
Change equalizer gain.
Syntax for the command is : "@var{gain}"
@item mix, m
Change equalizer mix.
Syntax for the command is : "@var{mix}"
@end table
@section extrastereo
@ -3764,6 +3808,10 @@ Specify the band-width of a filter in width_type units.
Applies only to double-pole filter.
The default is 0.707q and gives a Butterworth response.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -3783,6 +3831,10 @@ Syntax for the command is : "@var{width_type}"
@item width, w
Change highpass width.
Syntax for the command is : "@var{width}"
@item mix, m
Change highpass mix.
Syntax for the command is : "@var{mix}"
@end table
@section join
@ -4072,6 +4124,10 @@ Specify the band-width of a filter in width_type units.
Applies only to double-pole filter.
The default is 0.707q and gives a Butterworth response.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -4100,6 +4156,10 @@ Syntax for the command is : "@var{width_type}"
@item width, w
Change lowpass width.
Syntax for the command is : "@var{width}"
@item mix, m
Change lowpass mix.
Syntax for the command is : "@var{mix}"
@end table
@section lv2
@ -5140,6 +5200,10 @@ kHz
@item width, w
Determine how steep is the filter's shelf transition.
@item mix, m
How much to use filtered signal in output. Default is 1.
Range is between 0 and 1.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table
@ -5163,6 +5227,10 @@ Syntax for the command is : "@var{width}"
@item gain, g
Change treble gain.
Syntax for the command is : "@var{gain}"
@item mix, m
Change treble mix.
Syntax for the command is : "@var{mix}"
@end table
@section tremolo

View File

@ -110,6 +110,7 @@ typedef struct BiquadsContext {
double gain;
double frequency;
double width;
double mix;
uint64_t channels;
double a0, a1, a2;
@ -187,6 +188,9 @@ static void biquad_## name (BiquadsContext *s, \
double i2 = *in2; \
double o1 = *out1; \
double o2 = *out2; \
double wet = s->mix; \
double dry = 1. - wet; \
double out; \
int i; \
a1 = -a1; \
a2 = -a2; \
@ -194,30 +198,32 @@ static void biquad_## name (BiquadsContext *s, \
for (i = 0; i+1 < len; i++) { \
o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
i2 = ibuf[i]; \
out = o2 * wet + i2 * dry; \
if (disabled) { \
obuf[i] = i2; \
} else if (need_clipping && o2 < min) { \
} else if (need_clipping && out < min) { \
(*clippings)++; \
obuf[i] = min; \
} else if (need_clipping && o2 > max) { \
} else if (need_clipping && out > max) { \
(*clippings)++; \
obuf[i] = max; \
} else { \
obuf[i] = o2; \
obuf[i] = out; \
} \
i++; \
o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
i1 = ibuf[i]; \
out = o1 * wet + i1 * dry; \
if (disabled) { \
obuf[i] = i1; \
} else if (need_clipping && o1 < min) { \
} else if (need_clipping && out < min) { \
(*clippings)++; \
obuf[i] = min; \
} else if (need_clipping && o1 > max) { \
} else if (need_clipping && out > max) { \
(*clippings)++; \
obuf[i] = max; \
} else { \
obuf[i] = o1; \
obuf[i] = out; \
} \
} \
if (i < len) { \
@ -226,16 +232,17 @@ static void biquad_## name (BiquadsContext *s, \
i1 = ibuf[i]; \
o2 = o1; \
o1 = o0; \
out = o0 * wet + i1 * dry; \
if (disabled) { \
obuf[i] = i1; \
} else if (need_clipping && o0 < min) { \
} else if (need_clipping && out < min) { \
(*clippings)++; \
obuf[i] = min; \
} else if (need_clipping && o0 > max) { \
} else if (need_clipping && out > max) { \
(*clippings)++; \
obuf[i] = max; \
} else { \
obuf[i] = o0; \
obuf[i] = out; \
} \
} \
*in1 = i1; \
@ -532,6 +539,15 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
}
s->gain = gain;
} else if (!strcmp(cmd, "mix") || !strcmp(cmd, "m")) {
double mix;
if (sscanf(args, "%lf", &mix) != 1) {
av_log(ctx, AV_LOG_ERROR, "Invalid mix value.\n");
return AVERROR(EINVAL);
}
s->mix = av_clipd(mix, 0, 1);
} else if ((!strcmp(cmd, "width") || !strcmp(cmd, "w")) &&
(s->filter_type == equalizer ||
s->filter_type == lowshelf ||
@ -679,6 +695,8 @@ static const AVOption equalizer_options[] = {
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 99999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -701,6 +719,8 @@ static const AVOption bass_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -723,6 +743,8 @@ static const AVOption treble_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -744,6 +766,8 @@ static const AVOption bandpass_options[] = {
{"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -764,6 +788,8 @@ static const AVOption bandreject_options[] = {
{"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
{"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -786,6 +812,8 @@ static const AVOption lowpass_options[] = {
{"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
{"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
{"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -808,6 +836,8 @@ static const AVOption highpass_options[] = {
{"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS},
{"poles", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
{"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -828,6 +858,8 @@ static const AVOption allpass_options[] = {
{"k", "kHz", 0, AV_OPT_TYPE_CONST, {.i64=KHERTZ}, 0, 0, FLAGS, "width_type"},
{"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
{"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -850,6 +882,8 @@ static const AVOption lowshelf_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -872,6 +906,8 @@ static const AVOption highshelf_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}
@ -887,6 +923,8 @@ static const AVOption biquad_options[] = {
{"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
{"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
{"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=0}, INT32_MIN, INT32_MAX, FLAGS},
{"mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"m", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS},
{"channels", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{"c", "set channels to filter", OFFSET(channels), AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64=-1}, INT64_MIN, INT64_MAX, FLAGS},
{NULL}