History

avfilter: add asubcut filter

Paul B Mahol committed 5 years ago

Commit 34773ee1 parent 4d97acf6 files · +103 −20Browse files

Showing the changes to libavfilter (4 of 6 files). Show all

Unified · Split

4 files
  1. libavfilter/Makefile +1 −0
  2. libavfilter/af_asupercut.c +70 −19
  3. libavfilter/allfilters.c +1 −0
  4. libavfilter/version.h +1 −1
libavfilter/Makefile+1−0
@@ -90,6 +90,7 @@ OBJS-$(CONFIG_ASR_FILTER) += af_asr.o · 89 unmodified lines
9090 OBJS-$(CONFIG_ASTATS_FILTER) += af_astats.o
9191 OBJS-$(CONFIG_ASTREAMSELECT_FILTER) += f_streamselect.o framesync.o
9292 OBJS-$(CONFIG_ASUBBOOST_FILTER) += af_asubboost.o
93+OBJS-$(CONFIG_ASUBCUT_FILTER) += af_asupercut.o
9394 OBJS-$(CONFIG_ASUPERCUT_FILTER) += af_asupercut.o
9495 OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o
9596 OBJS-$(CONFIG_ATRIM_FILTER) += trim.o
libavfilter/af_asupercut.c+70−19
@@ -32,6 +32,7 @@ typedef struct ASuperCutContext { · 31 unmodified lines
3232 const AVClass *class;
3333
3434 double cutoff;
35+ double level;
3536 int order;
3637
3738 int filter_count;
@@ -95,27 +96,52 @@ static int get_coeffs(AVFilterContext *ctx) · 57 unmodified lines
9596 s->filter_count = s->order / 2 + (s->order & 1);
9697 calc_q_factors(s->order, q);
9798
98− if (s->order & 1) {
99− BiquadCoeffs *coeffs = &s->coeffs[0];
100− double omega = 2. * tan(M_PI * w0);
99+ if (!strcmp(ctx->filter->name, "asubcut")) {
100+ if (s->order & 1) {
101+ BiquadCoeffs *coeffs = &s->coeffs[0];
102+ double omega = 2. * tan(M_PI * w0);
101103
102− coeffs->b0 = omega / (2. + omega);
103− coeffs->b1 = coeffs->b0;
104− coeffs->b2 = 0.;
105− coeffs->a1 = -(omega - 2.) / (2. + omega);
106− coeffs->a2 = 0.;
107− }
104+ coeffs->b0 = 2. / (2. + omega);
105+ coeffs->b1 = -coeffs->b0;
106+ coeffs->b2 = 0.;
107+ coeffs->a1 = -(omega - 2.) / (2. + omega);
108+ coeffs->a2 = 0.;
109+ }
110+
111+ for (int b = (s->order & 1); b < s->filter_count; b++) {
112+ BiquadCoeffs *coeffs = &s->coeffs[b];
113+ const int idx = b - (s->order & 1);
114+ double norm = 1.0 / (1.0 + K / q[idx] + K * K);
108115
109− for (int b = (s->order & 1); b < s->filter_count; b++) {
110− BiquadCoeffs *coeffs = &s->coeffs[b];
111− const int idx = b - (s->order & 1);
112− double norm = 1.0 / (1.0 + K / q[idx] + K * K);
116+ coeffs->b0 = norm;
117+ coeffs->b1 = -2.0 * coeffs->b0;
118+ coeffs->b2 = coeffs->b0;
119+ coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
120+ coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;
121+ }
122+ } else {
123+ if (s->order & 1) {
124+ BiquadCoeffs *coeffs = &s->coeffs[0];
125+ double omega = 2. * tan(M_PI * w0);
126+
127+ coeffs->b0 = omega / (2. + omega);
128+ coeffs->b1 = coeffs->b0;
129+ coeffs->b2 = 0.;
130+ coeffs->a1 = -(omega - 2.) / (2. + omega);
131+ coeffs->a2 = 0.;
132+ }
113133
114− coeffs->b0 = K * K * norm;
115− coeffs->b1 = 2.0 * coeffs->b0;
116− coeffs->b2 = coeffs->b0;
117− coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
118− coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;
134+ for (int b = (s->order & 1); b < s->filter_count; b++) {
135+ BiquadCoeffs *coeffs = &s->coeffs[b];
136+ const int idx = b - (s->order & 1);
137+ double norm = 1.0 / (1.0 + K / q[idx] + K * K);
138+
139+ coeffs->b0 = K * K * norm;
140+ coeffs->b1 = 2.0 * coeffs->b0;
141+ coeffs->b2 = coeffs->b0;
142+ coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
143+ coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;
144+ }
119145 }
120146
121147 return 0;
@@ -135,6 +161,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \ · 13 unmodified lines
135161 AVFrame *in = td->in; \
136162 const int start = (in->channels * jobnr) / nb_jobs; \
137163 const int end = (in->channels * (jobnr+1)) / nb_jobs; \
164+ const double level = s->level; \
138165 \
139166 for (int ch = start; ch < end; ch++) { \
140167 const type *src = (const type *)in->extended_data[ch]; \
@@ -150,7 +177,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \ · 9 unmodified lines
150177 type *w = ((type *)s->w->extended_data[ch]) + b * 2; \
151178 \
152179 for (int n = 0; n < in->nb_samples; n++) { \
153− type sin = b ? dst[n] : src[n]; \
180+ type sin = b ? dst[n] : src[n] * level; \
154181 type sout = sin * b0 + w[0]; \
155182 \
156183 w[0] = b1 * sin + w[1] + a1 * sout; \
@@ -240,6 +267,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 83 unmodified lines
240267 static const AVOption asupercut_options[] = {
241268 { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20000}, 20000, 192000, FLAGS },
242269 { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=10}, 3, 20, FLAGS },
270+ { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 1., FLAGS },
243271 { NULL }
244272 };
245273
@@ -276,3 +304,26 @@ AVFilter ff_af_asupercut = { · 30 unmodified lines
276304 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
277305 AVFILTER_FLAG_SLICE_THREADS,
278306 };
307+
308+static const AVOption asubcut_options[] = {
309+ { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 2, 200, FLAGS },
310+ { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=10}, 3, 20, FLAGS },
311+ { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 1., FLAGS },
312+ { NULL }
313+};
314+
315+AVFILTER_DEFINE_CLASS(asubcut);
316+
317+AVFilter ff_af_asubcut = {
318+ .name = "asubcut",
319+ .description = NULL_IF_CONFIG_SMALL("Cut subwoofer frequencies."),
320+ .query_formats = query_formats,
321+ .priv_size = sizeof(ASuperCutContext),
322+ .priv_class = &asubcut_class,
323+ .uninit = uninit,
324+ .inputs = inputs,
325+ .outputs = outputs,
326+ .process_command = process_command,
327+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
328+ AVFILTER_FLAG_SLICE_THREADS,
329+};
libavfilter/allfilters.c+1−0
@@ -83,6 +83,7 @@ extern AVFilter ff_af_asr; · 82 unmodified lines
8383 extern AVFilter ff_af_astats;
8484 extern AVFilter ff_af_astreamselect;
8585 extern AVFilter ff_af_asubboost;
86+extern AVFilter ff_af_asubcut;
8687 extern AVFilter ff_af_asupercut;
8788 extern AVFilter ff_af_atempo;
8889 extern AVFilter ff_af_atrim;
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/version.h"
3131
3232 #define LIBAVFILTER_VERSION_MAJOR 7
33−#define LIBAVFILTER_VERSION_MINOR 91
33+#define LIBAVFILTER_VERSION_MINOR 92
3434 #define LIBAVFILTER_VERSION_MICRO 100
3535
3636

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t