118 double *i1,
double *i2,
double *o1,
double *o2,
119 double b0,
double b1,
double b2,
double a1,
double a2);
170 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
171 static void biquad_## name (BiquadsContext *s, \
172 const void *input, void *output, int len, \
173 double *in1, double *in2, \
174 double *out1, double *out2, \
175 double b0, double b1, double b2, \
176 double a1, double a2) \
178 const type *ibuf = input; \
179 type *obuf = output; \
188 for (i = 0; i+1 < len; i++) { \
189 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
191 if (need_clipping && o2 < min) { \
194 } else if (need_clipping && o2 > max) { \
201 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
203 if (need_clipping && o1 < min) { \
206 } else if (need_clipping && o1 > max) { \
214 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
219 if (need_clipping && o0 < min) { \
222 } else if (need_clipping && o0 > max) { \
245 double A =
exp(s->
gain / 40 * log(10.));
251 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
264 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
267 alpha = sin(w0) / (2 * s->
width);
270 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
280 s->
a0 = 1 + alpha /
A;
281 s->
a1 = -2 * cos(w0);
282 s->
a2 = 1 - alpha /
A;
283 s->
b0 = 1 + alpha *
A;
284 s->
b1 = -2 * cos(w0);
285 s->
b2 = 1 - alpha *
A;
288 s->
a0 = (A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
289 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
290 s->
a2 = (A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
291 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
292 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
293 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
296 s->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
297 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
298 s->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
299 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
300 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
301 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
306 s->
a1 = -2 * cos(w0);
310 s->
b2 = -sin(w0) / 2;
313 s->
a1 = -2 * cos(w0);
322 s->
a1 = -2 * cos(w0);
325 s->
b1 = -2 * cos(w0);
338 s->
a1 = -2 * cos(w0);
340 s->
b0 = (1 - cos(w0)) / 2;
342 s->
b2 = (1 - cos(w0)) / 2;
350 s->
b0 = (1 - s->
a1) / 2;
355 s->
a1 = -2 * cos(w0);
357 s->
b0 = (1 + cos(w0)) / 2;
358 s->
b1 = -(1 + cos(w0));
359 s->
b2 = (1 + cos(w0)) / 2;
364 s->
a1 = -2 * cos(w0);
367 s->
b1 = -2 * cos(w0);
418 for (ch = 0; ch < buf->
channels; ch++) {
466 #define OFFSET(x) offsetof(BiquadsContext, x)
467 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
469 #define DEFINE_BIQUAD_FILTER(name_, description_) \
470 AVFILTER_DEFINE_CLASS(name_); \
471 static av_cold int name_##_init(AVFilterContext *ctx) \
473 BiquadsContext *s = ctx->priv; \
474 s->class = &name_##_class; \
475 s->filter_type = name_; \
479 AVFilter ff_af_##name_ = { \
481 .description = NULL_IF_CONFIG_SMALL(description_), \
482 .priv_size = sizeof(BiquadsContext), \
483 .init = name_##_init, \
485 .query_formats = query_formats, \
487 .outputs = outputs, \
488 .priv_class = &name_##_class, \
491 #if CONFIG_EQUALIZER_FILTER
492 static const AVOption equalizer_options[] = {
512 #if CONFIG_BASS_FILTER
513 static const AVOption bass_options[] = {
533 #if CONFIG_TREBLE_FILTER
534 static const AVOption treble_options[] = {
554 #if CONFIG_BANDPASS_FILTER
555 static const AVOption bandpass_options[] = {
574 #if CONFIG_BANDREJECT_FILTER
575 static const AVOption bandreject_options[] = {
593 #if CONFIG_LOWPASS_FILTER
594 static const AVOption lowpass_options[] = {
614 #if CONFIG_HIGHPASS_FILTER
615 static const AVOption highpass_options[] = {
635 #if CONFIG_ALLPASS_FILTER
636 static const AVOption allpass_options[] = {
654 #if CONFIG_BIQUAD_FILTER
655 static const AVOption biquad_options[] = {
static float alpha(float a)
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.
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(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32),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_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_X86ASM &&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
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.
#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().
int channels
number of audio channels, only used for audio.
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.
#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)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
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.