Commit 9d08c7bd authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_biquads: allow filtering only selected channels

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 59d219b9
...@@ -1040,6 +1040,9 @@ slope ...@@ -1040,6 +1040,9 @@ slope
@item width, w @item width, w
Specify the band-width of a filter in width_type units. Specify the band-width of a filter in width_type units.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section aloop @section aloop
...@@ -1767,6 +1770,9 @@ slope ...@@ -1767,6 +1770,9 @@ slope
@item width, w @item width, w
Specify the band-width of a filter in width_type units. Specify the band-width of a filter in width_type units.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section bandreject @section bandreject
...@@ -1796,6 +1802,9 @@ slope ...@@ -1796,6 +1802,9 @@ slope
@item width, w @item width, w
Specify the band-width of a filter in width_type units. Specify the band-width of a filter in width_type units.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section bass @section bass
...@@ -1832,6 +1841,9 @@ slope ...@@ -1832,6 +1841,9 @@ slope
@item width, w @item width, w
Determine how steep is the filter's shelf transition. Determine how steep is the filter's shelf transition.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section biquad @section biquad
...@@ -1839,6 +1851,8 @@ Determine how steep is the filter's shelf transition. ...@@ -1839,6 +1851,8 @@ Determine how steep is the filter's shelf transition.
Apply a biquad IIR filter with the given coefficients. Apply a biquad IIR filter with the given coefficients.
Where @var{b0}, @var{b1}, @var{b2} and @var{a0}, @var{a1}, @var{a2} Where @var{b0}, @var{b1}, @var{b2} and @var{a0}, @var{a1}, @var{a2}
are the numerator and denominator coefficients respectively. are the numerator and denominator coefficients respectively.
and @var{channels}, @var{c} specify which channels to filter, by default all
available are filtered.
@section bs2b @section bs2b
Bauer stereo to binaural transformation, which improves headphone listening of Bauer stereo to binaural transformation, which improves headphone listening of
...@@ -2417,6 +2431,9 @@ Specify the band-width of a filter in width_type units. ...@@ -2417,6 +2431,9 @@ Specify the band-width of a filter in width_type units.
@item gain, g @item gain, g
Set the required gain or attenuation in dB. Set the required gain or attenuation in dB.
Beware of clipping when using a positive gain. Beware of clipping when using a positive gain.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@subsection Examples @subsection Examples
...@@ -2718,6 +2735,9 @@ slope ...@@ -2718,6 +2735,9 @@ slope
Specify the band-width of a filter in width_type units. Specify the band-width of a filter in width_type units.
Applies only to double-pole filter. Applies only to double-pole filter.
The default is 0.707q and gives a Butterworth response. The default is 0.707q and gives a Butterworth response.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section join @section join
...@@ -2977,6 +2997,9 @@ slope ...@@ -2977,6 +2997,9 @@ slope
Specify the band-width of a filter in width_type units. Specify the band-width of a filter in width_type units.
Applies only to double-pole filter. Applies only to double-pole filter.
The default is 0.707q and gives a Butterworth response. The default is 0.707q and gives a Butterworth response.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@anchor{pan} @anchor{pan}
...@@ -3663,6 +3686,9 @@ slope ...@@ -3663,6 +3686,9 @@ slope
@item width, w @item width, w
Determine how steep is the filter's shelf transition. Determine how steep is the filter's shelf transition.
@item channels, c
Specify which channels to filter, by default all available are filtered.
@end table @end table
@section tremolo @section tremolo
......
...@@ -105,12 +105,14 @@ typedef struct BiquadsContext { ...@@ -105,12 +105,14 @@ typedef struct BiquadsContext {
double gain; double gain;
double frequency; double frequency;
double width; double width;
uint64_t channels;
double a0, a1, a2; double a0, a1, a2;
double b0, b1, b2; double b0, b1, b2;
ChanCache *cache; ChanCache *cache;
int clippings; int clippings;
int block_align;
void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len, void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
double *i1, double *i2, double *o1, double *o2, double *i1, double *i2, double *o1, double *o2,
...@@ -388,6 +390,8 @@ static int config_output(AVFilterLink *outlink) ...@@ -388,6 +390,8 @@ static int config_output(AVFilterLink *outlink)
default: av_assert0(0); default: av_assert0(0);
} }
s->block_align = av_get_bytes_per_sample(inlink->format);
return 0; return 0;
} }
...@@ -411,12 +415,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) ...@@ -411,12 +415,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
av_frame_copy_props(out_buf, buf); av_frame_copy_props(out_buf, buf);
} }
for (ch = 0; ch < buf->channels; ch++) for (ch = 0; ch < buf->channels; ch++) {
if (!((av_channel_layout_extract_channel(inlink->channel_layout, ch) & s->channels))) {
if (buf != out_buf)
memcpy(out_buf->extended_data[ch], buf->extended_data[ch], nb_samples * s->block_align);
continue;
}
s->filter(s, buf->extended_data[ch], s->filter(s, buf->extended_data[ch],
out_buf->extended_data[ch], nb_samples, out_buf->extended_data[ch], nb_samples,
&s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].i1, &s->cache[ch].i2,
&s->cache[ch].o1, &s->cache[ch].o2, &s->cache[ch].o1, &s->cache[ch].o2,
s->b0, s->b1, s->b2, s->a1, s->a2); s->b0, s->b1, s->b2, s->a1, s->a2);
}
if (s->clippings > 0) if (s->clippings > 0)
av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings); av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
...@@ -491,6 +501,8 @@ static const AVOption equalizer_options[] = { ...@@ -491,6 +501,8 @@ static const AVOption equalizer_options[] = {
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS}, {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 999, FLAGS},
{"gain", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, 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}, {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, 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} {NULL}
}; };
...@@ -509,6 +521,8 @@ static const AVOption bass_options[] = { ...@@ -509,6 +521,8 @@ static const AVOption bass_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS}, {"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}, {"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}, {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, 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} {NULL}
}; };
...@@ -527,6 +541,8 @@ static const AVOption treble_options[] = { ...@@ -527,6 +541,8 @@ static const AVOption treble_options[] = {
{"w", "set shelf transition steep", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 99999, FLAGS}, {"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}, {"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}, {"g", "set gain", OFFSET(gain), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -900, 900, 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} {NULL}
}; };
...@@ -544,6 +560,8 @@ static const AVOption bandpass_options[] = { ...@@ -544,6 +560,8 @@ static const AVOption bandpass_options[] = {
{"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS}, {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS}, {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
{"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS}, {"csg", "use constant skirt gain", OFFSET(csg), AV_OPT_TYPE_BOOL, {.i64=0}, 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} {NULL}
}; };
...@@ -560,6 +578,8 @@ static const AVOption bandreject_options[] = { ...@@ -560,6 +578,8 @@ static const AVOption bandreject_options[] = {
{"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"}, {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
{"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS}, {"width", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS},
{"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, FLAGS}, {"w", "set band-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.5}, 0, 999, 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} {NULL}
}; };
...@@ -578,6 +598,8 @@ static const AVOption lowpass_options[] = { ...@@ -578,6 +598,8 @@ static const AVOption lowpass_options[] = {
{"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS}, {"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}, {"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}, {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, 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} {NULL}
}; };
...@@ -596,6 +618,8 @@ static const AVOption highpass_options[] = { ...@@ -596,6 +618,8 @@ static const AVOption highpass_options[] = {
{"w", "set width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=0.707}, 0, 99999, FLAGS}, {"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}, {"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}, {"p", "set number of poles", OFFSET(poles), AV_OPT_TYPE_INT, {.i64=2}, 1, 2, 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} {NULL}
}; };
...@@ -612,6 +636,8 @@ static const AVOption allpass_options[] = { ...@@ -612,6 +636,8 @@ static const AVOption allpass_options[] = {
{"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"}, {"s", "slope", 0, AV_OPT_TYPE_CONST, {.i64=SLOPE}, 0, 0, FLAGS, "width_type"},
{"width", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, FLAGS}, {"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}, {"w", "set filter-width", OFFSET(width), AV_OPT_TYPE_DOUBLE, {.dbl=707.1}, 0, 99999, 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} {NULL}
}; };
...@@ -625,6 +651,8 @@ static const AVOption biquad_options[] = { ...@@ -625,6 +651,8 @@ static const AVOption biquad_options[] = {
{"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS}, {"b0", NULL, OFFSET(b0), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
{"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS}, {"b1", NULL, OFFSET(b1), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS},
{"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, FLAGS}, {"b2", NULL, OFFSET(b2), AV_OPT_TYPE_DOUBLE, {.dbl=1}, INT16_MIN, INT16_MAX, 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} {NULL}
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment