116 double *i1,
double *i2,
double *o1,
double *o2,
117 double b0,
double b1,
double b2,
double a1,
double a2);
168 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
169 static void biquad_## name (BiquadsContext *s, \
170 const void *input, void *output, int len, \
171 double *in1, double *in2, \
172 double *out1, double *out2, \
173 double b0, double b1, double b2, \
174 double a1, double a2) \
176 const type *ibuf = input; \
177 type *obuf = output; \
186 for (i = 0; i+1 < len; i++) { \
187 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
189 if (need_clipping && o2 < min) { \
192 } else if (need_clipping && o2 > max) { \
199 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
201 if (need_clipping && o1 < min) { \
204 } else if (need_clipping && o1 > max) { \
212 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
217 if (need_clipping && o0 < min) { \
220 } else if (need_clipping && o0 > max) { \
243 double A =
exp(s->
gain / 40 * log(10.));
249 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
262 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
265 alpha = sin(w0) / (2 * s->
width);
268 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
278 s->
a0 = 1 + alpha /
A;
279 s->
a1 = -2 * cos(w0);
280 s->
a2 = 1 - alpha /
A;
281 s->
b0 = 1 + alpha *
A;
282 s->
b1 = -2 * cos(w0);
283 s->
b2 = 1 - alpha *
A;
286 s->
a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
287 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
288 s->
a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
289 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
290 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
291 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
294 s->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
295 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
296 s->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
297 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
298 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
299 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
304 s->
a1 = -2 * cos(w0);
308 s->
b2 = -sin(w0) / 2;
311 s->
a1 = -2 * cos(w0);
320 s->
a1 = -2 * cos(w0);
323 s->
b1 = -2 * cos(w0);
336 s->
a1 = -2 * cos(w0);
338 s->
b0 = (1 - cos(w0)) / 2;
340 s->
b2 = (1 - cos(w0)) / 2;
348 s->
b0 = (1 - s->
a1) / 2;
353 s->
a1 = -2 * cos(w0);
355 s->
b0 = (1 + cos(w0)) / 2;
356 s->
b1 = -(1 + cos(w0));
357 s->
b2 = (1 + cos(w0)) / 2;
362 s->
a1 = -2 * cos(w0);
365 s->
b1 = -2 * cos(w0);
456 #define OFFSET(x) offsetof(BiquadsContext, x)
457 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
459 #define DEFINE_BIQUAD_FILTER(name_, description_) \
460 AVFILTER_DEFINE_CLASS(name_); \
461 static av_cold int name_##_init(AVFilterContext *ctx) \
463 BiquadsContext *s = ctx->priv; \
464 s->class = &name_##_class; \
465 s->filter_type = name_; \
469 AVFilter ff_af_##name_ = { \
471 .description = NULL_IF_CONFIG_SMALL(description_), \
472 .priv_size = sizeof(BiquadsContext), \
473 .init = name_##_init, \
475 .query_formats = query_formats, \
477 .outputs = outputs, \
478 .priv_class = &name_##_class, \
481 #if CONFIG_EQUALIZER_FILTER
482 static const AVOption equalizer_options[] = {
499 #if CONFIG_BASS_FILTER
500 static const AVOption bass_options[] = {
517 #if CONFIG_TREBLE_FILTER
518 static const AVOption treble_options[] = {
535 #if CONFIG_BANDPASS_FILTER
536 static const AVOption bandpass_options[] = {
552 #if CONFIG_BANDREJECT_FILTER
553 static const AVOption bandreject_options[] = {
568 #if CONFIG_LOWPASS_FILTER
569 static const AVOption lowpass_options[] = {
586 #if CONFIG_HIGHPASS_FILTER
587 static const AVOption highpass_options[] = {
604 #if CONFIG_ALLPASS_FILTER
605 static const AVOption allpass_options[] = {
620 #if CONFIG_BIQUAD_FILTER
621 static const AVOption biquad_options[] = {
This structure describes decoded (raw) audio or video data.
#define av_realloc_f(p, o, n)
#define AV_LOG_WARNING
Something somehow does not look correct.
Main libavfilter public API header.
static const AVFilterPad inputs[]
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.
void(* filter)(struct BiquadsContext *s, 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)
#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)
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(A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AMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
int channels
Number of channels.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
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.