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
90OBJS-$(CONFIG_ASTATS_FILTER) += af_astats.o90OBJS-$(CONFIG_ASTATS_FILTER) += af_astats.o
91OBJS-$(CONFIG_ASTREAMSELECT_FILTER) += f_streamselect.o framesync.o91OBJS-$(CONFIG_ASTREAMSELECT_FILTER) += f_streamselect.o framesync.o
92OBJS-$(CONFIG_ASUBBOOST_FILTER) += af_asubboost.o92OBJS-$(CONFIG_ASUBBOOST_FILTER) += af_asubboost.o
93OBJS-$(CONFIG_ASUBCUT_FILTER) += af_asupercut.o
93OBJS-$(CONFIG_ASUPERCUT_FILTER) += af_asupercut.o94OBJS-$(CONFIG_ASUPERCUT_FILTER) += af_asupercut.o
94OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o95OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o
95OBJS-$(CONFIG_ATRIM_FILTER) += trim.o96OBJS-$(CONFIG_ATRIM_FILTER) += trim.o
libavfilter/af_asupercut.c+70−19
@@ -32,6 +32,7 @@ typedef struct ASuperCutContext { · 31 unmodified lines
32 const AVClass *class;32 const AVClass *class;
33 33
34 double cutoff;34 double cutoff;
35 double level;
35 int order;36 int order;
36 37
37 int filter_count;38 int filter_count;
@@ -95,27 +96,52 @@ static int get_coeffs(AVFilterContext *ctx) · 57 unmodified lines
95 s->filter_count = s->order / 2 + (s->order & 1);96 s->filter_count = s->order / 2 + (s->order & 1);
96 calc_q_factors(s->order, q);97 calc_q_factors(s->order, q);
97 98
98 if (s->order & 1) {99 if (!strcmp(ctx->filter->name, "asubcut")) {
99 BiquadCoeffs *coeffs = &s->coeffs[0];100 if (s->order & 1) {
100 double omega = 2. * tan(M_PI * w0);101 BiquadCoeffs *coeffs = &s->coeffs[0];
102 double omega = 2. * tan(M_PI * w0);
101 103
102 coeffs->b0 = omega / (2. + omega);104 coeffs->b0 = 2. / (2. + omega);
103 coeffs->b1 = coeffs->b0;105 coeffs->b1 = -coeffs->b0;
104 coeffs->b2 = 0.;106 coeffs->b2 = 0.;
105 coeffs->a1 = -(omega - 2.) / (2. + omega);107 coeffs->a1 = -(omega - 2.) / (2. + omega);
106 coeffs->a2 = 0.;108 coeffs->a2 = 0.;
107 }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);
108 115
109 for (int b = (s->order & 1); b < s->filter_count; b++) {116 coeffs->b0 = norm;
110 BiquadCoeffs *coeffs = &s->coeffs[b];117 coeffs->b1 = -2.0 * coeffs->b0;
111 const int idx = b - (s->order & 1);118 coeffs->b2 = coeffs->b0;
112 double norm = 1.0 / (1.0 + K / q[idx] + K * K);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 }
113 133
114 coeffs->b0 = K * K * norm;134 for (int b = (s->order & 1); b < s->filter_count; b++) {
115 coeffs->b1 = 2.0 * coeffs->b0;135 BiquadCoeffs *coeffs = &s->coeffs[b];
116 coeffs->b2 = coeffs->b0;136 const int idx = b - (s->order & 1);
117 coeffs->a1 = -2.0 * (K * K - 1.0) * norm;137 double norm = 1.0 / (1.0 + K / q[idx] + K * K);
118 coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;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 }
119 }145 }
120 146
121 return 0;147 return 0;
@@ -135,6 +161,7 @@ static int filter_channels_## name(AVFilterContext *ctx, void *arg, \ · 13 unmodified lines
135 AVFrame *in = td->in; \161 AVFrame *in = td->in; \
136 const int start = (in->channels * jobnr) / nb_jobs; \162 const int start = (in->channels * jobnr) / nb_jobs; \
137 const int end = (in->channels * (jobnr+1)) / nb_jobs; \163 const int end = (in->channels * (jobnr+1)) / nb_jobs; \
164 const double level = s->level; \
138 \165 \
139 for (int ch = start; ch < end; ch++) { \166 for (int ch = start; ch < end; ch++) { \
140 const type *src = (const type *)in->extended_data[ch]; \167 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
150 type *w = ((type *)s->w->extended_data[ch]) + b * 2; \177 type *w = ((type *)s->w->extended_data[ch]) + b * 2; \
151 \178 \
152 for (int n = 0; n < in->nb_samples; n++) { \179 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; \
154 type sout = sin * b0 + w[0]; \181 type sout = sin * b0 + w[0]; \
155 \182 \
156 w[0] = b1 * sin + w[1] + a1 * sout; \183 w[0] = b1 * sin + w[1] + a1 * sout; \
@@ -240,6 +267,7 @@ static av_cold void uninit(AVFilterContext *ctx) · 83 unmodified lines
240static const AVOption asupercut_options[] = {267static const AVOption asupercut_options[] = {
241 { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20000}, 20000, 192000, FLAGS },268 { "cutoff", "set cutoff frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=20000}, 20000, 192000, FLAGS },
242 { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=10}, 3, 20, FLAGS },269 { "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 },
243 { NULL }271 { NULL }
244};272};
245 273
@@ -276,3 +304,26 @@ AVFilter ff_af_asupercut = { · 30 unmodified lines
276 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |304 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
277 AVFILTER_FLAG_SLICE_THREADS,305 AVFILTER_FLAG_SLICE_THREADS,
278};306};
307
308static 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
315AVFILTER_DEFINE_CLASS(asubcut);
316
317AVFilter 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
83extern AVFilter ff_af_astats;83extern AVFilter ff_af_astats;
84extern AVFilter ff_af_astreamselect;84extern AVFilter ff_af_astreamselect;
85extern AVFilter ff_af_asubboost;85extern AVFilter ff_af_asubboost;
86extern AVFilter ff_af_asubcut;
86extern AVFilter ff_af_asupercut;87extern AVFilter ff_af_asupercut;
87extern AVFilter ff_af_atempo;88extern AVFilter ff_af_atempo;
88extern AVFilter ff_af_atrim;89extern AVFilter ff_af_atrim;
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/version.h"30#include "libavutil/version.h"
31 31
32#define LIBAVFILTER_VERSION_MAJOR 732#define LIBAVFILTER_VERSION_MAJOR 7
33#define LIBAVFILTER_VERSION_MINOR 9133#define LIBAVFILTER_VERSION_MINOR 92
34#define LIBAVFILTER_VERSION_MICRO 10034#define LIBAVFILTER_VERSION_MICRO 100
35 35
36 36

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