avfilter: add peakpass audio filter

This commit is contained in:
Paul B Mahol 2024-10-10 10:50:46 +02:00
parent 7cff2a1148
commit 19d655a4a3
3 changed files with 37 additions and 0 deletions

View File

@ -176,6 +176,7 @@ OBJS-$(CONFIG_LOWSHELF_FILTER) += af_biquads.o
OBJS-$(CONFIG_LV2_FILTER) += af_lv2.o OBJS-$(CONFIG_LV2_FILTER) += af_lv2.o
OBJS-$(CONFIG_MCOMPAND_FILTER) += af_mcompand.o OBJS-$(CONFIG_MCOMPAND_FILTER) += af_mcompand.o
OBJS-$(CONFIG_PAN_FILTER) += af_pan.o OBJS-$(CONFIG_PAN_FILTER) += af_pan.o
OBJS-$(CONFIG_PEAKPASS_FILTER) += af_biquads.o
OBJS-$(CONFIG_REPLAYGAIN_FILTER) += af_replaygain.o OBJS-$(CONFIG_REPLAYGAIN_FILTER) += af_replaygain.o
OBJS-$(CONFIG_RUBBERBAND_FILTER) += af_rubberband.o OBJS-$(CONFIG_RUBBERBAND_FILTER) += af_rubberband.o
OBJS-$(CONFIG_SILENCEDETECT_FILTER) += af_silencedetect.o OBJS-$(CONFIG_SILENCEDETECT_FILTER) += af_silencedetect.o

View File

@ -49,6 +49,7 @@ enum FilterType {
highshelf, highshelf,
tiltshelf, tiltshelf,
transform, transform,
peakpass,
}; };
enum WidthType { enum WidthType {
@ -400,6 +401,16 @@ static void convert_dir2zdf(BiquadsContext *s, int sample_rate)
m[1] = -k; m[1] = -k;
m[2] = -1.; m[2] = -1.;
break; break;
case peakpass:
g = tan(M_PI * s->frequency / sample_rate);
k = 1. / Q;
a[0] = 1. / (1. + g * (g + k));
a[1] = g * a[0];
a[2] = g * a[1];
m[0] = -1.;
m[1] = k;
m[2] = 2.;
break;
case allpass: case allpass:
g = tan(M_PI * s->frequency / sample_rate); g = tan(M_PI * s->frequency / sample_rate);
k = 1. / Q; k = 1. / Q;
@ -549,6 +560,14 @@ static int config_filter(AVFilterLink *outlink, int reset)
s->b[1] = -2.0 * cos_w0; s->b[1] = -2.0 * cos_w0;
s->b[2] = 1.0; s->b[2] = 1.0;
break; break;
case peakpass:
s->a[0] = 1.0 + alpha;
s->a[1] = -2.0 * cos_w0;
s->a[2] = 1.0 - alpha;
s->b[0] = -cos_w0;
s->b[1] = 2.0;
s->b[2] = -cos_w0;
break;
case lowpass: case lowpass:
if (s->order == 1) { if (s->order == 1) {
s->a[0] = sin_w0 + 1.0 + cos_w0; s->a[0] = sin_w0 + 1.0 + cos_w0;
@ -1365,3 +1384,19 @@ static const AVOption transform_options[] = {
DEFINE_BIQUAD_FILTER(transform, "Apply a Linkwitz transform IIR filter with the given Hz/Q."); DEFINE_BIQUAD_FILTER(transform, "Apply a Linkwitz transform IIR filter with the given Hz/Q.");
#endif /* CONFIG_TRANSFORM_FILTER */ #endif /* CONFIG_TRANSFORM_FILTER */
#if CONFIG_PEAKPASS_FILTER
static const AVOption peakpass_options[] = {
{"frequency", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
{"f", "set central frequency", OFFSET(frequency), AV_OPT_TYPE_DOUBLE, {.dbl=3000}, 0, 999999, FLAGS},
WIDTH_TYPE_OPTION(QFACTOR),
WIDTH_OPTION(0.5),
MIX_CHANNELS_NORMALIZE_OPTION(1, "24c", 0),
TRANSFORM_OPTION(DI),
PRECISION_OPTION(-1),
BLOCKSIZE_OPTION(0),
{NULL}
};
DEFINE_BIQUAD_FILTER(peakpass, "Apply a peak-pass filter.");
#endif /* CONFIG_PEAKPASS_FILTER */

View File

@ -163,6 +163,7 @@ extern const AVFilter ff_af_lowshelf;
extern const AVFilter ff_af_lv2; extern const AVFilter ff_af_lv2;
extern const AVFilter ff_af_mcompand; extern const AVFilter ff_af_mcompand;
extern const AVFilter ff_af_pan; extern const AVFilter ff_af_pan;
extern const AVFilter ff_af_peakpass;
extern const AVFilter ff_af_replaygain; extern const AVFilter ff_af_replaygain;
extern const AVFilter ff_af_rubberband; extern const AVFilter ff_af_rubberband;
extern const AVFilter ff_af_silencedetect; extern const AVFilter ff_af_silencedetect;