115 double *i1,
double *i2,
double *o1,
double *o2,
116 double b0,
double b1,
double b2,
double a1,
double a2);
167 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
168 static void biquad_## name (const void *input, void *output, int len, \
169 double *in1, double *in2, \
170 double *out1, double *out2, \
171 double b0, double b1, double b2, \
172 double a1, double a2) \
174 const type *ibuf = input; \
175 type *obuf = output; \
184 for (i = 0; i+1 < len; i++) { \
185 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
187 if (need_clipping && o2 < min) { \
188 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
190 } else if (need_clipping && o2 > max) { \
191 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
197 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
199 if (need_clipping && o1 < min) { \
200 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
202 } else if (need_clipping && o1 > max) { \
203 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
210 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
215 if (need_clipping && o0 < min) { \
216 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
218 } else if (need_clipping && o0 > max) { \
219 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
241 double A = exp(s->
gain / 40 * log(10.));
247 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
260 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
263 alpha = sin(w0) / (2 * s->
width);
266 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
276 s->
a0 = 1 + alpha /
A;
277 s->
a1 = -2 * cos(w0);
278 s->
a2 = 1 - alpha /
A;
279 s->
b0 = 1 + alpha *
A;
280 s->
b1 = -2 * cos(w0);
281 s->
b2 = 1 - alpha *
A;
284 s->
a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
285 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
286 s->
a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
287 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
288 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
289 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
292 s->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
293 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
294 s->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
295 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
296 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
297 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
302 s->
a1 = -2 * cos(w0);
306 s->
b2 = -sin(w0) / 2;
309 s->
a1 = -2 * cos(w0);
318 s->
a1 = -2 * cos(w0);
321 s->
b1 = -2 * cos(w0);
334 s->
a1 = -2 * cos(w0);
336 s->
b0 = (1 - cos(w0)) / 2;
338 s->
b2 = (1 - cos(w0)) / 2;
346 s->
b0 = (1 - s->
a1) / 2;
351 s->
a1 = -2 * cos(w0);
353 s->
b0 = (1 + cos(w0)) / 2;
354 s->
b1 = -(1 + cos(w0));
355 s->
b2 = (1 + cos(w0)) / 2;
360 s->
a1 = -2 * cos(w0);
363 s->
b1 = -2 * cos(w0);
447 #define OFFSET(x) offsetof(BiquadsContext, x)
448 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
450 #define DEFINE_BIQUAD_FILTER(name_, description_) \
451 AVFILTER_DEFINE_CLASS(name_); \
452 static av_cold int name_##_init(AVFilterContext *ctx) \
454 BiquadsContext *s = ctx->priv; \
455 s->class = &name_##_class; \
456 s->filter_type = name_; \
460 AVFilter ff_af_##name_ = { \
462 .description = NULL_IF_CONFIG_SMALL(description_), \
463 .priv_size = sizeof(BiquadsContext), \
464 .init = name_##_init, \
466 .query_formats = query_formats, \
468 .outputs = outputs, \
469 .priv_class = &name_##_class, \
472 #if CONFIG_EQUALIZER_FILTER
473 static const AVOption equalizer_options[] = {
490 #if CONFIG_BASS_FILTER
491 static const AVOption bass_options[] = {
508 #if CONFIG_TREBLE_FILTER
509 static const AVOption treble_options[] = {
526 #if CONFIG_BANDPASS_FILTER
527 static const AVOption bandpass_options[] = {
543 #if CONFIG_BANDREJECT_FILTER
544 static const AVOption bandreject_options[] = {
559 #if CONFIG_LOWPASS_FILTER
560 static const AVOption lowpass_options[] = {
577 #if CONFIG_HIGHPASS_FILTER
578 static const AVOption highpass_options[] = {
595 #if CONFIG_ALLPASS_FILTER
596 static const AVOption allpass_options[] = {
611 #if CONFIG_BIQUAD_FILTER
612 static const AVOption biquad_options[] = {
This structure describes decoded (raw) audio or video data.
#define av_realloc_f(p, o, n)
Main libavfilter public API header.
static const AVFilterPad inputs[]
static enum AVSampleFormat formats[]
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const AVFilterPad outputs[]
A filter pad used for either input or output.
static av_cold int init(AVFilterContext *ctx)
A link between two filters.
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void * priv
private data for use by the filter
simple assert() macros that are a bit more flexible than ISO C assert().
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int format
agreed upon media format
A list of supported channel layouts.
#define BIQUAD_FILTER(name, type, min, max, need_clipping)
AVSampleFormat
Audio sample formats.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static int config_output(AVFilterLink *outlink)
Describe the class of an AVClass context structure.
int av_frame_get_channels(const AVFrame *frame)
#define DEFINE_BIQUAD_FILTER(name_, description_)
static int query_formats(AVFilterContext *ctx)
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
static av_cold void uninit(AVFilterContext *ctx)
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
int channels
Number of channels.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
void(* filter)(const void *ibuf, void *obuf, int len, double *i1, double *i2, double *o1, double *o2, double b0, double b1, double b2, double a1, double a2)
uint8_t ** extended_data
pointers to the data planes/channels.
enum FilterType filter_type
int nb_samples
number of audio samples (per channel) described by this frame
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.