140 double *
i1,
double *
i2,
double *
o1,
double *
o2,
203 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \ 204 static void biquad_## name (BiquadsContext *s, \ 205 const void *input, void *output, int len, \ 206 double *in1, double *in2, \ 207 double *out1, double *out2, \ 208 double b0, double b1, double b2, \ 209 double a1, double a2, int *clippings, \ 212 const type *ibuf = input; \ 213 type *obuf = output; \ 218 double wet = s->mix; \ 219 double dry = 1. - wet; \ 225 for (i = 0; i+1 < len; i++) { \ 226 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \ 228 out = o2 * wet + i2 * dry; \ 231 } else if (need_clipping && out < min) { \ 234 } else if (need_clipping && out > max) { \ 241 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \ 243 out = o1 * wet + i1 * dry; \ 246 } else if (need_clipping && out < min) { \ 249 } else if (need_clipping && out > max) { \ 257 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ 262 out = o0 * wet + i1 * dry; \ 265 } else if (need_clipping && out < min) { \ 268 } else if (need_clipping && out > max) { \ 286 #define BIQUAD_DII_FILTER(name, type, min, max, need_clipping) \ 287 static void biquad_dii_## name (BiquadsContext *s, \ 288 const void *input, void *output, int len, \ 289 double *z1, double *z2, \ 290 double *unused1, double *unused2, \ 291 double b0, double b1, double b2, \ 292 double a1, double a2, int *clippings, \ 295 const type *ibuf = input; \ 296 type *obuf = output; \ 299 double wet = s->mix; \ 300 double dry = 1. - wet; \ 301 double in, out, w0; \ 306 for (int i = 0; i < len; i++) { \ 308 w0 = in + a1 * w1 + a2 * w2; \ 309 out = b0 * w0 + b1 * w1 + b2 * w2; \ 312 out = out * wet + in * dry; \ 315 } else if (need_clipping && out < min) { \ 318 } else if (need_clipping && out > max) { \ 334 #define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping) \ 335 static void biquad_tdii_## name (BiquadsContext *s, \ 336 const void *input, void *output, int len, \ 337 double *z1, double *z2, \ 338 double *unused1, double *unused2, \ 339 double b0, double b1, double b2, \ 340 double a1, double a2, int *clippings, \ 343 const type *ibuf = input; \ 344 type *obuf = output; \ 347 double wet = s->mix; \ 348 double dry = 1. - wet; \ 354 for (int i = 0; i < len; i++) { \ 356 out = b0 * in + w1; \ 357 w1 = b1 * in + w2 + a1 * out; \ 358 w2 = b2 * in + a2 * out; \ 359 out = out * wet + in * dry; \ 362 } else if (need_clipping && out < min) { \ 365 } else if (need_clipping && out > max) { \ 381 #define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping) \ 382 static void biquad_latt_## name (BiquadsContext *s, \ 383 const void *input, void *output, int len, \ 384 double *z1, double *z2, \ 385 double *unused1, double *unused2, \ 386 double v0, double v1, double v2, \ 387 double k0, double k1, int *clippings, \ 390 const type *ibuf = input; \ 391 type *obuf = output; \ 394 double wet = s->mix; \ 395 double dry = 1. - wet; \ 399 for (int i = 0; i < len; i++) { \ 414 out = out * wet + in * dry; \ 417 } else if (need_clipping && out < min) { \ 420 } else if (need_clipping && out > max) { \ 438 double k0, k1,
v0, v1, v2;
441 k0 = s->a1 / (1. + k1);
443 v1 = s->b1 - v2 * s->a1;
444 v0 = s->b0 - v1 * k0 - v2 * k1;
460 double K = tan(w0 / 2.);
483 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
486 alpha = sin(w0) / (2 * s->
width);
489 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
507 s->
a0 = 1 + alpha /
A;
508 s->
a1 = -2 * cos(w0);
509 s->
a2 = 1 - alpha /
A;
510 s->
b0 = 1 + alpha *
A;
511 s->
b1 = -2 * cos(w0);
512 s->
b2 = 1 - alpha *
A;
515 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
519 double ro = -sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
520 double n = (A + 1) / (A - 1);
521 double alpha1 = A == 1. ? 0. : n -
FFSIGN(n) * sqrt(n * n - 1);
522 double beta0 = ((1 +
A) + (1 - A) * alpha1) * 0.5;
523 double beta1 = ((1 -
A) + (1 + A) * alpha1) * 0.5;
525 s->
a0 = 1 + ro * alpha1;
526 s->
a1 = -ro - alpha1;
528 s->
b0 = beta0 + ro * beta1;
529 s->
b1 = -beta1 - ro * beta0;
532 s->
a0 = (A + 1) + (A - 1) * cos(w0) + beta *
alpha;
533 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
534 s->
a2 = (A + 1) + (A - 1) * cos(w0) - beta *
alpha;
535 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta *
alpha);
536 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
537 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta *
alpha);
541 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
545 double ro = sin(w0 / 2. - M_PI_4) / sin(w0 / 2. + M_PI_4);
546 double n = (A + 1) / (A - 1);
547 double alpha1 = A == 1. ? 0. : n -
FFSIGN(n) * sqrt(n * n - 1);
548 double beta0 = ((1 +
A) + (1 - A) * alpha1) * 0.5;
549 double beta1 = ((1 -
A) + (1 + A) * alpha1) * 0.5;
551 s->
a0 = 1 + ro * alpha1;
554 s->
b0 = beta0 + ro * beta1;
555 s->
b1 = beta1 + ro * beta0;
558 s->
a0 = (A + 1) - (A - 1) * cos(w0) + beta *
alpha;
559 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
560 s->
a2 = (A + 1) - (A - 1) * cos(w0) - beta *
alpha;
561 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta *
alpha);
562 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
563 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta *
alpha);
569 s->
a1 = -2 * cos(w0);
573 s->
b2 = -sin(w0) / 2;
576 s->
a1 = -2 * cos(w0);
585 s->
a1 = -2 * cos(w0);
588 s->
b1 = -2 * cos(w0);
601 s->
a1 = -2 * cos(w0);
603 s->
b0 = (1 - cos(w0)) / 2;
605 s->
b2 = (1 - cos(w0)) / 2;
613 s->
b0 = (1 - s->
a1) / 2;
618 s->
a1 = -2 * cos(w0);
620 s->
b0 = (1 + cos(w0)) / 2;
621 s->
b1 = -(1 + cos(w0));
622 s->
b2 = (1 + cos(w0)) / 2;
629 s->
a1 = -(1. - K) / (1. + K);
637 s->
a1 = -2 * cos(w0);
640 s->
b1 = -2 * cos(w0);
693 s->
filter = biquad_dii_s16;
696 s->
filter = biquad_dii_s32;
699 s->
filter = biquad_dii_flt;
702 s->
filter = biquad_dii_dbl;
710 s->
filter = biquad_tdii_s16;
713 s->
filter = biquad_tdii_s32;
716 s->
filter = biquad_tdii_flt;
719 s->
filter = biquad_tdii_dbl;
727 s->
filter = biquad_latt_s16;
730 s->
filter = biquad_latt_s32;
733 s->
filter = biquad_latt_flt;
736 s->
filter = biquad_latt_dbl;
769 const int start = (buf->
channels * jobnr) / nb_jobs;
770 const int end = (buf->
channels * (jobnr+1)) / nb_jobs;
773 for (ch = start; ch < end; ch++) {
816 for (ch = 0; ch < outlink->
channels; ch++) {
830 char *res,
int res_len,
int flags)
867 #define OFFSET(x) offsetof(BiquadsContext, x) 868 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM 869 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 871 #define DEFINE_BIQUAD_FILTER(name_, description_) \ 872 AVFILTER_DEFINE_CLASS(name_); \ 873 static av_cold int name_##_init(AVFilterContext *ctx) \ 875 BiquadsContext *s = ctx->priv; \ 876 s->filter_type = name_; \ 880 AVFilter ff_af_##name_ = { \ 882 .description = NULL_IF_CONFIG_SMALL(description_), \ 883 .priv_size = sizeof(BiquadsContext), \ 884 .init = name_##_init, \ 886 .query_formats = query_formats, \ 888 .outputs = outputs, \ 889 .priv_class = &name_##_class, \ 890 .process_command = process_command, \ 891 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \ 894 #if CONFIG_EQUALIZER_FILTER 895 static const AVOption equalizer_options[] = {
921 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
933 #if CONFIG_BASS_FILTER || CONFIG_LOWSHELF_FILTER 934 static const AVOption bass_lowshelf_options[] = {
962 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
972 #if CONFIG_BASS_FILTER 973 #define bass_options bass_lowshelf_options 977 #if CONFIG_LOWSHELF_FILTER 978 #define lowshelf_options bass_lowshelf_options 982 #if CONFIG_TREBLE_FILTER || CONFIG_HIGHSHELF_FILTER 983 static const AVOption treble_highshelf_options[] = {
1011 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1021 #if CONFIG_TREBLE_FILTER 1022 #define treble_options treble_highshelf_options 1026 #if CONFIG_HIGHSHELF_FILTER 1027 #define highshelf_options treble_highshelf_options 1031 #if CONFIG_BANDPASS_FILTER 1032 static const AVOption bandpass_options[] = {
1057 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1069 #if CONFIG_BANDREJECT_FILTER 1070 static const AVOption bandreject_options[] = {
1094 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1106 #if CONFIG_LOWPASS_FILTER 1107 static const AVOption lowpass_options[] = {
1133 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1145 #if CONFIG_HIGHPASS_FILTER 1146 static const AVOption highpass_options[] = {
1172 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1184 #if CONFIG_ALLPASS_FILTER 1185 static const AVOption allpass_options[] = {
1211 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
1223 #if CONFIG_BIQUAD_FILTER 1224 static const AVOption biquad_options[] = {
1243 {
"precision",
"set filtering precision",
OFFSET(precision),
AV_OPT_TYPE_INT, {.i64=-1}, -1, 3,
AF,
"precision"},
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[]
int is_disabled
the enabled state from the last expression evaluation
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.
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, int disabled)
#define AV_LOG_VERBOSE
Detailed information.
#define BIQUAD_LATT_FILTER(name, type, min, max, need_clipping)
static const AVFilterPad outputs[]
A filter pad used for either input or output.
A link between two filters.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
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.
static __device__ float fabs(float a)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options...
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)
static double b0(void *priv, double x, double y)
AVFilterContext * src
source filter
#define BIQUAD_DII_FILTER(name, type, min, max, need_clipping)
int format
agreed upon media format
A list of supported channel layouts.
static double b1(void *priv, double x, double y)
static int mix(int c0, int c1)
#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[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
#define BIQUAD_TDII_FILTER(name, type, min, max, need_clipping)
#define DEFINE_BIQUAD_FILTER(name_, description_)
static const int factor[16]
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.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
internal math functions header
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.
avfilter_execute_func * execute
static int config_filter(AVFilterLink *outlink, int reset)
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static void convert_dir2latt(BiquadsContext *s)
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)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
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.
static double b2(void *priv, double x, double y)