65 #include "libavutil/avassert.h"
66 #include "libavutil/opt.h"
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) \
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; \
185 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
187 } else if (o2 > max) { \
188 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
194 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
197 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
199 } else if (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; \
213 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
215 } else if (o0 > max) { \
216 av_log(NULL, AV_LOG_WARNING, "clipping\n"); \
238 double A = exp(p->
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 * p->
width * w0 / sin(w0));
260 alpha = sin(w0) / (2 * p->
width);
263 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / p->
width - 1) + 2);
273 p->
a0 = 1 + alpha /
A;
274 p->
a1 = -2 * cos(w0);
275 p->
a2 = 1 - alpha /
A;
276 p->
b0 = 1 + alpha *
A;
277 p->
b1 = -2 * cos(w0);
278 p->
b2 = 1 - alpha *
A;
281 p->
a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
282 p->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
283 p->
a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
284 p->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
285 p->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
286 p->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
289 p->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
290 p->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
291 p->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
292 p->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
293 p->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
294 p->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
299 p->
a1 = -2 * cos(w0);
303 p->
b2 = -sin(w0) / 2;
306 p->
a1 = -2 * cos(w0);
315 p->
a1 = -2 * cos(w0);
318 p->
b1 = -2 * cos(w0);
331 p->
a1 = -2 * cos(w0);
333 p->
b0 = (1 - cos(w0)) / 2;
335 p->
b2 = (1 - cos(w0)) / 2;
343 p->
b0 = (1 - p->
a1) / 2;
348 p->
a1 = -2 * cos(w0);
350 p->
b0 = (1 + cos(w0)) / 2;
351 p->
b1 = -(1 + cos(w0));
352 p->
b2 = (1 + cos(w0)) / 2;
357 p->
a1 = -2 * cos(w0);
360 p->
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 *p = ctx->priv; \
452 p->class = &name_##_class; \
453 p->filter_type = name_; \
457 AVFilter avfilter_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[] = {
This structure describes decoded (raw) audio or video data.
void * priv
private data for use by the filter
#define BIQUAD_FILTER(name, type, min, max)
uint8_t ** extended_data
pointers to the data planes/channels.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static const AVFilterPad inputs[]
static enum AVSampleFormat formats[]
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
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.
int av_frame_get_channels(const AVFrame *frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
int format
agreed upon media format
A list of supported channel layouts.
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
AVSampleFormat
Audio Sample Formats.
enum WidthType width_type
typedef void(RENAME(mix_any_func_type))
static int config_output(AVFilterLink *outlink)
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate or reallocate a block of memory.
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
#define DEFINE_BIQUAD_FILTER(name_, description_)
static int query_formats(AVFilterContext *ctx)
AVFilterContext * dst
dest filter
enum MovChannelLayoutTag * layouts
static av_cold void uninit(AVFilterContext *ctx)
int channels
Number of channels.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static enum AVSampleFormat sample_fmts[]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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)
enum FilterType filter_type
int nb_samples
number of audio samples (per channel) described by this frame