121 double *i1,
double *i2,
double *o1,
double *o2,
122 double b0,
double b1,
double b2,
double a1,
double a2,
int *clippings);
173 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
174 static void biquad_## name (BiquadsContext *s, \
175 const void *input, void *output, int len, \
176 double *in1, double *in2, \
177 double *out1, double *out2, \
178 double b0, double b1, double b2, \
179 double a1, double a2, int *clippings) \
181 const type *ibuf = input; \
182 type *obuf = output; \
191 for (i = 0; i+1 < len; i++) { \
192 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
194 if (need_clipping && o2 < min) { \
197 } else if (need_clipping && o2 > max) { \
204 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
206 if (need_clipping && o1 < min) { \
209 } else if (need_clipping && o1 > max) { \
217 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \
222 if (need_clipping && o0 < min) { \
225 } else if (need_clipping && o0 > max) { \
248 double A =
exp(s->
gain / 40 * log(10.));
254 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
270 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
273 alpha = sin(w0) / (2 * s->
width);
276 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
288 s->
a0 = 1 + alpha /
A;
289 s->
a1 = -2 * cos(w0);
290 s->
a2 = 1 - alpha /
A;
291 s->
b0 = 1 + alpha *
A;
292 s->
b1 = -2 * cos(w0);
293 s->
b2 = 1 - alpha *
A;
296 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
298 s->
a0 = (A + 1) + (A - 1) * cos(w0) + beta *
alpha;
299 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
300 s->
a2 = (A + 1) + (A - 1) * cos(w0) - beta *
alpha;
301 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta *
alpha);
302 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
303 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta *
alpha);
306 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
308 s->
a0 = (A + 1) - (A - 1) * cos(w0) + beta *
alpha;
309 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
310 s->
a2 = (A + 1) - (A - 1) * cos(w0) - beta *
alpha;
311 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta *
alpha);
312 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
313 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta *
alpha);
318 s->
a1 = -2 * cos(w0);
322 s->
b2 = -sin(w0) / 2;
325 s->
a1 = -2 * cos(w0);
334 s->
a1 = -2 * cos(w0);
337 s->
b1 = -2 * cos(w0);
350 s->
a1 = -2 * cos(w0);
352 s->
b0 = (1 - cos(w0)) / 2;
354 s->
b2 = (1 - cos(w0)) / 2;
362 s->
b0 = (1 - s->
a1) / 2;
367 s->
a1 = -2 * cos(w0);
369 s->
b0 = (1 + cos(w0)) / 2;
370 s->
b1 = -(1 + cos(w0));
371 s->
b2 = (1 + cos(w0)) / 2;
376 s->
a1 = -2 * cos(w0);
379 s->
b1 = -2 * cos(w0);
431 const int end = (buf->
channels * (jobnr+1)) / nb_jobs;
434 for (ch = start; ch <
end; ch++) {
474 for (ch = 0; ch < outlink->
channels; ch++) {
488 char *res,
int res_len,
int flags)
493 if ((!strcmp(cmd,
"frequency") || !strcmp(cmd,
"f")) &&
506 if (sscanf(args,
"%lf", &freq) != 1) {
512 }
else if ((!strcmp(cmd,
"gain") || !strcmp(cmd,
"g")) &&
520 if (sscanf(args,
"%lf", &gain) != 1) {
526 }
else if ((!strcmp(cmd,
"width") || !strcmp(cmd,
"w")) &&
539 if (sscanf(args,
"%lf", &width) != 1) {
545 }
else if ((!strcmp(cmd,
"width_type") || !strcmp(cmd,
"t")) &&
558 if (sscanf(args,
"%c", &width_type) != 1) {
563 switch (width_type) {
564 case 'h': width_type =
HERTZ;
break;
565 case 'q': width_type =
QFACTOR;
break;
566 case 'o': width_type =
OCTAVE;
break;
567 case 's': width_type =
SLOPE;
break;
568 case 'k': width_type =
KHERTZ;
break;
575 }
else if ((!strcmp(cmd,
"a0") ||
576 !strcmp(cmd,
"a1") ||
577 !strcmp(cmd,
"a2") ||
578 !strcmp(cmd,
"b0") ||
579 !strcmp(cmd,
"b1") ||
580 !strcmp(cmd,
"b2")) &&
584 if (sscanf(args,
"%lf", &value) != 1) {
589 if (!strcmp(cmd,
"a0"))
591 else if (!strcmp(cmd,
"a1"))
593 else if (!strcmp(cmd,
"a2"))
595 else if (!strcmp(cmd,
"b0"))
597 else if (!strcmp(cmd,
"b1"))
599 else if (!strcmp(cmd,
"b2"))
631 #define OFFSET(x) offsetof(BiquadsContext, x)
632 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
634 #define DEFINE_BIQUAD_FILTER(name_, description_) \
635 AVFILTER_DEFINE_CLASS(name_); \
636 static av_cold int name_##_init(AVFilterContext *ctx) \
638 BiquadsContext *s = ctx->priv; \
639 s->class = &name_##_class; \
640 s->filter_type = name_; \
644 AVFilter ff_af_##name_ = { \
646 .description = NULL_IF_CONFIG_SMALL(description_), \
647 .priv_size = sizeof(BiquadsContext), \
648 .init = name_##_init, \
650 .query_formats = query_formats, \
652 .outputs = outputs, \
653 .priv_class = &name_##_class, \
654 .process_command = process_command, \
655 .flags = AVFILTER_FLAG_SLICE_THREADS, \
658 #if CONFIG_EQUALIZER_FILTER
659 static const AVOption equalizer_options[] = {
680 #if CONFIG_BASS_FILTER
681 static const AVOption bass_options[] = {
702 #if CONFIG_TREBLE_FILTER
703 static const AVOption treble_options[] = {
724 #if CONFIG_BANDPASS_FILTER
725 static const AVOption bandpass_options[] = {
745 #if CONFIG_BANDREJECT_FILTER
746 static const AVOption bandreject_options[] = {
765 #if CONFIG_LOWPASS_FILTER
766 static const AVOption lowpass_options[] = {
787 #if CONFIG_HIGHPASS_FILTER
788 static const AVOption highpass_options[] = {
809 #if CONFIG_ALLPASS_FILTER
810 static const AVOption allpass_options[] = {
829 #if CONFIG_LOWSHELF_FILTER
830 static const AVOption lowshelf_options[] = {
851 #if CONFIG_HIGHSHELF_FILTER
852 static const AVOption highshelf_options[] = {
873 #if CONFIG_BIQUAD_FILTER
874 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 av_cold int end(AVCodecContext *avctx)
#define AV_LOG_VERBOSE
Detailed information.
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.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
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.
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Used for passing data between threads.
static int config_output(AVFilterLink *outlink)
static const int16_t alpha[]
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
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
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.
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, int *clippings)
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int channels
Number of channels.
avfilter_execute_func * execute
static int config_filter(AVFilterLink *outlink, int reset)
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
AVFilterContext * dst
dest filter
static enum AVSampleFormat sample_fmts[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
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.
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_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MT_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_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