119 double *
i1,
double *
i2,
double *
o1,
double *
o2,
120 double b0,
double b1,
double b2,
double a1,
double a2);
171 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \ 172 static void biquad_## name (BiquadsContext *s, \ 173 const void *input, void *output, int len, \ 174 double *in1, double *in2, \ 175 double *out1, double *out2, \ 176 double b0, double b1, double b2, \ 177 double a1, double a2) \ 179 const type *ibuf = input; \ 180 type *obuf = output; \ 189 for (i = 0; i+1 < len; i++) { \ 190 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \ 192 if (need_clipping && o2 < min) { \ 195 } else if (need_clipping && o2 > max) { \ 202 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \ 204 if (need_clipping && o1 < min) { \ 207 } else if (need_clipping && o1 > max) { \ 215 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ 220 if (need_clipping && o0 < min) { \ 223 } else if (need_clipping && o0 > max) { \ 246 double A =
exp(s->
gain / 40 * log(10.));
252 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
268 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
271 alpha = sin(w0) / (2 * s->
width);
274 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
284 s->
a0 = 1 + alpha /
A;
285 s->
a1 = -2 * cos(w0);
286 s->
a2 = 1 - alpha /
A;
287 s->
b0 = 1 + alpha *
A;
288 s->
b1 = -2 * cos(w0);
289 s->
b2 = 1 - alpha *
A;
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);
300 s->
a0 = (A + 1) - (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha;
301 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
302 s->
a2 = (A + 1) - (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha;
303 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + 2 * sqrt(A) *
alpha);
304 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
305 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - 2 * sqrt(A) *
alpha);
310 s->
a1 = -2 * cos(w0);
314 s->
b2 = -sin(w0) / 2;
317 s->
a1 = -2 * cos(w0);
326 s->
a1 = -2 * cos(w0);
329 s->
b1 = -2 * cos(w0);
342 s->
a1 = -2 * cos(w0);
344 s->
b0 = (1 - cos(w0)) / 2;
346 s->
b2 = (1 - cos(w0)) / 2;
354 s->
b0 = (1 - s->
a1) / 2;
359 s->
a1 = -2 * cos(w0);
361 s->
b0 = (1 + cos(w0)) / 2;
362 s->
b1 = -(1 + cos(w0));
363 s->
b2 = (1 + cos(w0)) / 2;
368 s->
a1 = -2 * cos(w0);
371 s->
b1 = -2 * cos(w0);
431 for (ch = 0; ch < buf->
channels; ch++) {
455 char *res,
int res_len,
int flags)
460 if ((!strcmp(cmd,
"frequency") || !strcmp(cmd,
"f")) &&
471 if (sscanf(args,
"%lf", &freq) != 1) {
477 }
else if ((!strcmp(cmd,
"gain") || !strcmp(cmd,
"g")) &&
483 if (sscanf(args,
"%lf", &gain) != 1) {
489 }
else if ((!strcmp(cmd,
"width") || !strcmp(cmd,
"w")) &&
500 if (sscanf(args,
"%lf", &width) != 1) {
506 }
else if ((!strcmp(cmd,
"width_type") || !strcmp(cmd,
"t")) &&
517 if (sscanf(args,
"%c", &width_type) != 1) {
522 switch (width_type) {
523 case 'h': width_type =
HERTZ;
break;
524 case 'q': width_type =
QFACTOR;
break;
525 case 'o': width_type =
OCTAVE;
break;
526 case 's': width_type =
SLOPE;
break;
527 case 'k': width_type =
KHERTZ;
break;
534 }
else if ((!strcmp(cmd,
"a0") ||
535 !strcmp(cmd,
"a1") ||
536 !strcmp(cmd,
"a2") ||
537 !strcmp(cmd,
"b0") ||
538 !strcmp(cmd,
"b1") ||
539 !strcmp(cmd,
"b2")) &&
543 if (sscanf(args,
"%lf", &value) != 1) {
548 if (!strcmp(cmd,
"a0"))
550 else if (!strcmp(cmd,
"a1"))
552 else if (!strcmp(cmd,
"a2"))
554 else if (!strcmp(cmd,
"b0"))
556 else if (!strcmp(cmd,
"b1"))
558 else if (!strcmp(cmd,
"b2"))
590 #define OFFSET(x) offsetof(BiquadsContext, x) 591 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 593 #define DEFINE_BIQUAD_FILTER(name_, description_) \ 594 AVFILTER_DEFINE_CLASS(name_); \ 595 static av_cold int name_##_init(AVFilterContext *ctx) \ 597 BiquadsContext *s = ctx->priv; \ 598 s->class = &name_##_class; \ 599 s->filter_type = name_; \ 603 AVFilter ff_af_##name_ = { \ 605 .description = NULL_IF_CONFIG_SMALL(description_), \ 606 .priv_size = sizeof(BiquadsContext), \ 607 .init = name_##_init, \ 609 .query_formats = query_formats, \ 611 .outputs = outputs, \ 612 .priv_class = &name_##_class, \ 613 .process_command = process_command, \ 616 #if CONFIG_EQUALIZER_FILTER 617 static const AVOption equalizer_options[] = {
638 #if CONFIG_BASS_FILTER 639 static const AVOption bass_options[] = {
660 #if CONFIG_TREBLE_FILTER 661 static const AVOption treble_options[] = {
682 #if CONFIG_BANDPASS_FILTER 683 static const AVOption bandpass_options[] = {
703 #if CONFIG_BANDREJECT_FILTER 704 static const AVOption bandreject_options[] = {
723 #if CONFIG_LOWPASS_FILTER 724 static const AVOption lowpass_options[] = {
745 #if CONFIG_HIGHPASS_FILTER 746 static const AVOption highpass_options[] = {
767 #if CONFIG_ALLPASS_FILTER 768 static const AVOption allpass_options[] = {
787 #if CONFIG_BIQUAD_FILTER 788 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.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_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(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SAMPLE_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), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { 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) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;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)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) 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);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=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) { int planes=out->planar ? out->ch_count :1;unsigned m=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){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
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 void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, int clip)
#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.
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)
const char AVS_Value args
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.
typedef void(RENAME(mix_any_func_type))
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 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.