History

avfilter: add asuperpass and asuperstop filter

Paul B Mahol committed 5 years ago

Commit b607f191 parent 628d02a6 files · +185 −5Browse files

Unified · Split

6 files
  1. Changelog +1 −0
  2. doc/filters.texi +50 −0
  3. libavfilter/Makefile +2 −0
  4. libavfilter/af_asupercut.c +129 −4
  5. libavfilter/allfilters.c +2 −0
  6. libavfilter/version.h +1 −1
Changelog+1−0
@@ -52,6 +52,7 @@ version <next>: · 51 unmodified lines
52- Microsoft Paint (MSP) version 2 decoder52- Microsoft Paint (MSP) version 2 decoder
53- Microsoft Paint (MSP) demuxer53- Microsoft Paint (MSP) demuxer
54- AV1 monochrome encoding support via libaom >= 2.0.154- AV1 monochrome encoding support via libaom >= 2.0.1
55- asuperpass and asuperstop filter
55 56
56 57
57version 4.3:58version 4.3:
doc/filters.texi+50−0
@@ -2733,6 +2733,56 @@ Set input gain level. Allowed range is from 0 to 1. Default value is 1. · 2732 unmodified lines
2733 2733
2734This filter supports the all above options as @ref{commands}.2734This filter supports the all above options as @ref{commands}.
2735 2735
2736@section asuperpass
2737Apply high order Butterworth band-pass filter.
2738
2739The filter accepts the following options:
2740
2741@table @option
2742@item centerf
2743Set center frequency in Hertz. Allowed range is 2 to 999999.
2744Default value is 1000.
2745
2746@item order
2747Set filter order. Available values are from 4 to 20.
2748Default value is 4.
2749
2750@item qfactor
2751Set Q-factor. Allowed range is from 0.01 to 100. Default value is 1.
2752
2753@item level
2754Set input gain level. Allowed range is from 0 to 2. Default value is 1.
2755@end table
2756
2757@subsection Commands
2758
2759This filter supports the all above options as @ref{commands}.
2760
2761@section asuperstop
2762Apply high order Butterworth band-stop filter.
2763
2764The filter accepts the following options:
2765
2766@table @option
2767@item centerf
2768Set center frequency in Hertz. Allowed range is 2 to 999999.
2769Default value is 1000.
2770
2771@item order
2772Set filter order. Available values are from 4 to 20.
2773Default value is 4.
2774
2775@item qfactor
2776Set Q-factor. Allowed range is from 0.01 to 100. Default value is 1.
2777
2778@item level
2779Set input gain level. Allowed range is from 0 to 2. Default value is 1.
2780@end table
2781
2782@subsection Commands
2783
2784This filter supports the all above options as @ref{commands}.
2785
2736@section atempo2786@section atempo
2737 2787
2738Adjust audio tempo.2788Adjust audio tempo.
libavfilter/Makefile+2−0
@@ -92,6 +92,8 @@ OBJS-$(CONFIG_ASTREAMSELECT_FILTER) += f_streamselect.o framesync.o · 91 unmodified lines
92OBJS-$(CONFIG_ASUBBOOST_FILTER) += af_asubboost.o92OBJS-$(CONFIG_ASUBBOOST_FILTER) += af_asubboost.o
93OBJS-$(CONFIG_ASUBCUT_FILTER) += af_asupercut.o93OBJS-$(CONFIG_ASUBCUT_FILTER) += af_asupercut.o
94OBJS-$(CONFIG_ASUPERCUT_FILTER) += af_asupercut.o94OBJS-$(CONFIG_ASUPERCUT_FILTER) += af_asupercut.o
95OBJS-$(CONFIG_ASUPERPASS_FILTER) += af_asupercut.o
96OBJS-$(CONFIG_ASUPERSTOP_FILTER) += af_asupercut.o
95OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o97OBJS-$(CONFIG_ATEMPO_FILTER) += af_atempo.o
96OBJS-$(CONFIG_ATRIM_FILTER) += trim.o98OBJS-$(CONFIG_ATRIM_FILTER) += trim.o
97OBJS-$(CONFIG_AXCORRELATE_FILTER) += af_axcorrelate.o99OBJS-$(CONFIG_AXCORRELATE_FILTER) += af_axcorrelate.o
libavfilter/af_asupercut.c+129−4
@@ -1,4 +1,7 @@
1/*1/*
2 * Copyright (c) 2005 Boðaç Topaktaþ
3 * Copyright (c) 2020 Paul B Mahol
4 *
2 * This file is part of FFmpeg.5 * This file is part of FFmpeg.
3 *6 *
4 * FFmpeg is free software; you can redistribute it and/or7 * FFmpeg is free software; you can redistribute it and/or
@@ -33,6 +36,7 @@ typedef struct ASuperCutContext { · 28 unmodified lines
33 36
34 double cutoff;37 double cutoff;
35 double level;38 double level;
39 double qfactor;
36 int order;40 int order;
37 41
38 int filter_count;42 int filter_count;
@@ -93,10 +97,11 @@ static int get_coeffs(AVFilterContext *ctx) · 54 unmodified lines
93 if (s->bypass)97 if (s->bypass)
94 return 0;98 return 0;
95 99
96 s->filter_count = s->order / 2 + (s->order & 1);
97 calc_q_factors(s->order, q);
98
99 if (!strcmp(ctx->filter->name, "asubcut")) {100 if (!strcmp(ctx->filter->name, "asubcut")) {
101 s->filter_count = s->order / 2 + (s->order & 1);
102
103 calc_q_factors(s->order, q);
104
100 if (s->order & 1) {105 if (s->order & 1) {
101 BiquadCoeffs *coeffs = &s->coeffs[0];106 BiquadCoeffs *coeffs = &s->coeffs[0];
102 double omega = 2. * tan(M_PI * w0);107 double omega = 2. * tan(M_PI * w0);
@@ -119,7 +124,11 @@ static int get_coeffs(AVFilterContext *ctx) · 16 unmodified lines
119 coeffs->a1 = -2.0 * (K * K - 1.0) * norm;124 coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
120 coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;125 coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;
121 }126 }
122 } else {127 } else if (!strcmp(ctx->filter->name, "asupercut")) {
128 s->filter_count = s->order / 2 + (s->order & 1);
129
130 calc_q_factors(s->order, q);
131
123 if (s->order & 1) {132 if (s->order & 1) {
124 BiquadCoeffs *coeffs = &s->coeffs[0];133 BiquadCoeffs *coeffs = &s->coeffs[0];
125 double omega = 2. * tan(M_PI * w0);134 double omega = 2. * tan(M_PI * w0);
@@ -142,6 +151,74 @@ static int get_coeffs(AVFilterContext *ctx) · 16 unmodified lines
142 coeffs->a1 = -2.0 * (K * K - 1.0) * norm;151 coeffs->a1 = -2.0 * (K * K - 1.0) * norm;
143 coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;152 coeffs->a2 = -(1.0 - K / q[idx] + K * K) * norm;
144 }153 }
154 } else if (!strcmp(ctx->filter->name, "asuperpass")) {
155 double alpha, beta, gamma, theta;
156 double theta_0 = 2. * M_PI * (s->cutoff / inlink->sample_rate);
157 double d_E;
158
159 s->filter_count = s->order / 2;
160 d_E = (2. * tan(theta_0 / (2. * s->qfactor))) / sin(theta_0);
161
162 for (int b = 0; b < s->filter_count; b += 2) {
163 double D = 2. * sin(((b + 1) * M_PI) / (2. * s->filter_count));
164 double A = (1. + pow((d_E / 2.), 2)) / (D * d_E / 2.);
165 double d = sqrt((d_E * D) / (A + sqrt(A * A - 1.)));
166 double B = D * (d_E / 2.) / d;
167 double W = B + sqrt(B * B - 1.);
168
169 for (int j = 0; j < 2; j++) {
170 BiquadCoeffs *coeffs = &s->coeffs[b + j];
171
172 if (j == 1)
173 theta = 2. * atan(tan(theta_0 / 2.) / W);
174 else
175 theta = 2. * atan(W * tan(theta_0 / 2.));
176
177 beta = 0.5 * ((1. - (d / 2.) * sin(theta)) / (1. + (d / 2.) * sin(theta)));
178 gamma = (0.5 + beta) * cos(theta);
179 alpha = 0.5 * (0.5 - beta) * sqrt(1. + pow((W - (1. / W)) / d, 2.));
180
181 coeffs->a1 = 2. * gamma;
182 coeffs->a2 = -2. * beta;
183 coeffs->b0 = 2. * alpha;
184 coeffs->b1 = 0.;
185 coeffs->b2 = -2. * alpha;
186 }
187 }
188 } else if (!strcmp(ctx->filter->name, "asuperstop")) {
189 double alpha, beta, gamma, theta;
190 double theta_0 = 2. * M_PI * (s->cutoff / inlink->sample_rate);
191 double d_E;
192
193 s->filter_count = s->order / 2;
194 d_E = (2. * tan(theta_0 / (2. * s->qfactor))) / sin(theta_0);
195
196 for (int b = 0; b < s->filter_count; b += 2) {
197 double D = 2. * sin(((b + 1) * M_PI) / (2. * s->filter_count));
198 double A = (1. + pow((d_E / 2.), 2)) / (D * d_E / 2.);
199 double d = sqrt((d_E * D) / (A + sqrt(A * A - 1.)));
200 double B = D * (d_E / 2.) / d;
201 double W = B + sqrt(B * B - 1.);
202
203 for (int j = 0; j < 2; j++) {
204 BiquadCoeffs *coeffs = &s->coeffs[b + j];
205
206 if (j == 1)
207 theta = 2. * atan(tan(theta_0 / 2.) / W);
208 else
209 theta = 2. * atan(W * tan(theta_0 / 2.));
210
211 beta = 0.5 * ((1. - (d / 2.) * sin(theta)) / (1. + (d / 2.) * sin(theta)));
212 gamma = (0.5 + beta) * cos(theta);
213 alpha = 0.5 * (0.5 + beta) * ((1. - cos(theta)) / (1. - cos(theta_0)));
214
215 coeffs->a1 = 2. * gamma;
216 coeffs->a2 = -2. * beta;
217 coeffs->b0 = 2. * alpha;
218 coeffs->b1 = -4. * alpha * cos(theta_0);
219 coeffs->b2 = 2. * alpha;
220 }
221 }
145 }222 }
146 223
147 return 0;224 return 0;
@@ -327,3 +404,51 @@ AVFilter ff_af_asubcut = { · 179 unmodified lines
327 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |404 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
328 AVFILTER_FLAG_SLICE_THREADS,405 AVFILTER_FLAG_SLICE_THREADS,
329};406};
407
408static const AVOption asuperpass_options[] = {
409 { "centerf","set center frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=1000}, 2, 999999, FLAGS },
410 { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=4}, 4, 20, FLAGS },
411 { "qfactor","set Q-factor", OFFSET(qfactor),AV_OPT_TYPE_DOUBLE, {.dbl=1.},0.01, 100., FLAGS },
412 { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 2., FLAGS },
413 { NULL }
414};
415
416AVFILTER_DEFINE_CLASS(asuperpass);
417
418AVFilter ff_af_asuperpass = {
419 .name = "asuperpass",
420 .description = NULL_IF_CONFIG_SMALL("Apply high order Butterworth band-pass filter."),
421 .query_formats = query_formats,
422 .priv_size = sizeof(ASuperCutContext),
423 .priv_class = &asuperpass_class,
424 .uninit = uninit,
425 .inputs = inputs,
426 .outputs = outputs,
427 .process_command = process_command,
428 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
429 AVFILTER_FLAG_SLICE_THREADS,
430};
431
432static const AVOption asuperstop_options[] = {
433 { "centerf","set center frequency", OFFSET(cutoff), AV_OPT_TYPE_DOUBLE, {.dbl=1000}, 2, 999999, FLAGS },
434 { "order", "set filter order", OFFSET(order), AV_OPT_TYPE_INT, {.i64=4}, 4, 20, FLAGS },
435 { "qfactor","set Q-factor", OFFSET(qfactor),AV_OPT_TYPE_DOUBLE, {.dbl=1.},0.01, 100., FLAGS },
436 { "level", "set input level", OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1.}, 0., 2., FLAGS },
437 { NULL }
438};
439
440AVFILTER_DEFINE_CLASS(asuperstop);
441
442AVFilter ff_af_asuperstop = {
443 .name = "asuperstop",
444 .description = NULL_IF_CONFIG_SMALL("Apply high order Butterworth band-stop filter."),
445 .query_formats = query_formats,
446 .priv_size = sizeof(ASuperCutContext),
447 .priv_class = &asuperstop_class,
448 .uninit = uninit,
449 .inputs = inputs,
450 .outputs = outputs,
451 .process_command = process_command,
452 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC |
453 AVFILTER_FLAG_SLICE_THREADS,
454};
libavfilter/allfilters.c+2−0
@@ -85,6 +85,8 @@ extern AVFilter ff_af_astreamselect; · 84 unmodified lines
85extern AVFilter ff_af_asubboost;85extern AVFilter ff_af_asubboost;
86extern AVFilter ff_af_asubcut;86extern AVFilter ff_af_asubcut;
87extern AVFilter ff_af_asupercut;87extern AVFilter ff_af_asupercut;
88extern AVFilter ff_af_asuperpass;
89extern AVFilter ff_af_asuperstop;
88extern AVFilter ff_af_atempo;90extern AVFilter ff_af_atempo;
89extern AVFilter ff_af_atrim;91extern AVFilter ff_af_atrim;
90extern AVFilter ff_af_axcorrelate;92extern AVFilter ff_af_axcorrelate;
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 9233#define LIBAVFILTER_VERSION_MINOR 93
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