115 double *i1,
double *i2,
double *o1,
double *o2,
116 double b0,
double b1,
double b2,
double a1,
double a2);
164 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
165 static void biquad_## name (const void *input, void *output, int len, \
166 double *in1, double *in2, \
167 double *out1, double *out2, \
168 double b0, double b1, double b2, \
169 double a1, double a2) \
171 const type *ibuf = input; \
172 type *obuf = output; \
181 for (i = 0; i+1 < len; i++) { \
182 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
184 if (need_clipping && o2 < min) { \
185 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
187 } else if (need_clipping && o2 > max) { \
188 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
194 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
196 if (need_clipping && o1 < min) { \
197 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
199 } else if (need_clipping && o1 > max) { \
200 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
207 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
212 if (need_clipping && o0 < min) { \
213 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
215 } else if (need_clipping && o0 > max) { \
216 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
238 double A = exp(s->
gain / 40 * log(10.));
244 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
257 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
260 alpha = sin(w0) / (2 * s->
width);
263 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
273 s->
a0 = 1 + alpha /
A;
274 s->
a1 = -2 * cos(w0);
275 s->
a2 = 1 - alpha /
A;
276 s->
b0 = 1 + alpha *
A;
277 s->
b1 = -2 * cos(w0);
278 s->
b2 = 1 - alpha *
A;
281 s->
a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
282 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
283 s->
a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
284 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
285 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
286 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
289 s->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
290 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
291 s->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
292 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
293 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
294 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
299 s->
a1 = -2 * cos(w0);
303 s->
b2 = -sin(w0) / 2;
306 s->
a1 = -2 * cos(w0);
315 s->
a1 = -2 * cos(w0);
318 s->
b1 = -2 * cos(w0);
331 s->
a1 = -2 * cos(w0);
333 s->
b0 = (1 - cos(w0)) / 2;
335 s->
b2 = (1 - cos(w0)) / 2;
343 s->
b0 = (1 - s->
a1) / 2;
348 s->
a1 = -2 * cos(w0);
350 s->
b0 = (1 + cos(w0)) / 2;
351 s->
b1 = -(1 + cos(w0));
352 s->
b2 = (1 + cos(w0)) / 2;
357 s->
a1 = -2 * cos(w0);
360 s->
b1 = -2 * cos(w0);
444 #define OFFSET(x) offsetof(BiquadsContext, x)
445 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
447 #define DEFINE_BIQUAD_FILTER(name_, description_) \
448 AVFILTER_DEFINE_CLASS(name_); \
449 static av_cold int name_##_init(AVFilterContext *ctx) \
451 BiquadsContext *s = ctx->priv; \
452 s->class = &name_##_class; \
453 s->filter_type = name_; \
457 AVFilter ff_af_##name_ = { \
459 .description = NULL_IF_CONFIG_SMALL(description_), \
460 .priv_size = sizeof(BiquadsContext), \
461 .init = name_##_init, \
463 .query_formats = query_formats, \
465 .outputs = outputs, \
466 .priv_class = &name_##_class, \
469 #if CONFIG_EQUALIZER_FILTER
470 static const AVOption equalizer_options[] = {
487 #if CONFIG_BASS_FILTER
488 static const AVOption bass_options[] = {
505 #if CONFIG_TREBLE_FILTER
506 static const AVOption treble_options[] = {
523 #if CONFIG_BANDPASS_FILTER
524 static const AVOption bandpass_options[] = {
540 #if CONFIG_BANDREJECT_FILTER
541 static const AVOption bandreject_options[] = {
556 #if CONFIG_LOWPASS_FILTER
557 static const AVOption lowpass_options[] = {
574 #if CONFIG_HIGHPASS_FILTER
575 static const AVOption highpass_options[] = {
592 #if CONFIG_ALLPASS_FILTER
593 static const AVOption allpass_options[] = {
608 #if CONFIG_BIQUAD_FILTER
609 static const AVOption biquad_options[] = {