125 double *
i1,
double *
i2,
double *
o1,
double *
o2,
178 #define BIQUAD_FILTER(name, type, min, max, need_clipping) \ 179 static void biquad_## name (BiquadsContext *s, \ 180 const void *input, void *output, int len, \ 181 double *in1, double *in2, \ 182 double *out1, double *out2, \ 183 double b0, double b1, double b2, \ 184 double a1, double a2, int *clippings, \ 187 const type *ibuf = input; \ 188 type *obuf = output; \ 193 double wet = s->mix; \ 194 double dry = 1. - wet; \ 200 for (i = 0; i+1 < len; i++) { \ 201 o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \ 203 out = o2 * wet + i2 * dry; \ 206 } else if (need_clipping && out < min) { \ 209 } else if (need_clipping && out > max) { \ 216 o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \ 218 out = o1 * wet + i1 * dry; \ 221 } else if (need_clipping && out < min) { \ 224 } else if (need_clipping && out > max) { \ 232 double o0 = ibuf[i] * b0 + i1 * b1 + i2 * b2 + o1 * a1 + o2 * a2; \ 237 out = o0 * wet + i1 * dry; \ 240 } else if (need_clipping && out < min) { \ 243 } else if (need_clipping && out > max) { \ 268 double K = tan(w0 / 2.);
273 "Invalid frequency %f. Frequency must be less than half the sample-rate %d.\n",
289 alpha = sin(w0) * sinh(log(2.) / 2 * s->
width * w0 / sin(w0));
292 alpha = sin(w0) / (2 * s->
width);
295 alpha = sin(w0) / 2 * sqrt((A + 1 / A) * (1 / s->
width - 1) + 2);
307 s->
a0 = 1 + alpha /
A;
308 s->
a1 = -2 * cos(w0);
309 s->
a2 = 1 - alpha /
A;
310 s->
b0 = 1 + alpha *
A;
311 s->
b1 = -2 * cos(w0);
312 s->
b2 = 1 - alpha *
A;
315 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
317 s->
a0 = (A + 1) + (A - 1) * cos(w0) + beta *
alpha;
318 s->
a1 = -2 * ((A - 1) + (A + 1) * cos(w0));
319 s->
a2 = (A + 1) + (A - 1) * cos(w0) - beta *
alpha;
320 s->
b0 = A * ((A + 1) - (A - 1) * cos(w0) + beta *
alpha);
321 s->
b1 = 2 * A * ((A - 1) - (A + 1) * cos(w0));
322 s->
b2 = A * ((A + 1) - (A - 1) * cos(w0) - beta *
alpha);
325 beta = sqrt((A * A + 1) - (A - 1) * (A - 1));
327 s->
a0 = (A + 1) - (A - 1) * cos(w0) + beta *
alpha;
328 s->
a1 = 2 * ((A - 1) - (A + 1) * cos(w0));
329 s->
a2 = (A + 1) - (A - 1) * cos(w0) - beta *
alpha;
330 s->
b0 = A * ((A + 1) + (A - 1) * cos(w0) + beta *
alpha);
331 s->
b1 =-2 * A * ((A - 1) + (A + 1) * cos(w0));
332 s->
b2 = A * ((A + 1) + (A - 1) * cos(w0) - beta *
alpha);
337 s->
a1 = -2 * cos(w0);
341 s->
b2 = -sin(w0) / 2;
344 s->
a1 = -2 * cos(w0);
353 s->
a1 = -2 * cos(w0);
356 s->
b1 = -2 * cos(w0);
369 s->
a1 = -2 * cos(w0);
371 s->
b0 = (1 - cos(w0)) / 2;
373 s->
b2 = (1 - cos(w0)) / 2;
381 s->
b0 = (1 - s->
a1) / 2;
386 s->
a1 = -2 * cos(w0);
388 s->
b0 = (1 + cos(w0)) / 2;
389 s->
b1 = -(1 + cos(w0));
390 s->
b2 = (1 + cos(w0)) / 2;
397 s->
a1 = -(1. - K) / (1. + K);
405 s->
a1 = -2 * cos(w0);
408 s->
b1 = -2 * cos(w0);
469 const int start = (buf->
channels * jobnr) / nb_jobs;
470 const int end = (buf->
channels * (jobnr+1)) / nb_jobs;
473 for (ch = start; ch <
end; ch++) {
513 for (ch = 0; ch < outlink->
channels; ch++) {
527 char *res,
int res_len,
int flags)
564 #define OFFSET(x) offsetof(BiquadsContext, x) 565 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM 566 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 568 #define DEFINE_BIQUAD_FILTER(name_, description_) \ 569 AVFILTER_DEFINE_CLASS(name_); \ 570 static av_cold int name_##_init(AVFilterContext *ctx) \ 572 BiquadsContext *s = ctx->priv; \ 573 s->class = &name_##_class; \ 574 s->filter_type = name_; \ 578 AVFilter ff_af_##name_ = { \ 580 .description = NULL_IF_CONFIG_SMALL(description_), \ 581 .priv_size = sizeof(BiquadsContext), \ 582 .init = name_##_init, \ 584 .query_formats = query_formats, \ 586 .outputs = outputs, \ 587 .priv_class = &name_##_class, \ 588 .process_command = process_command, \ 589 .flags = AVFILTER_FLAG_SLICE_THREADS | AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, \ 592 #if CONFIG_EQUALIZER_FILTER 593 static const AVOption equalizer_options[] = {
618 #if CONFIG_BASS_FILTER 619 static const AVOption bass_options[] = {
644 #if CONFIG_TREBLE_FILTER 645 static const AVOption treble_options[] = {
670 #if CONFIG_BANDPASS_FILTER 671 static const AVOption bandpass_options[] = {
695 #if CONFIG_BANDREJECT_FILTER 696 static const AVOption bandreject_options[] = {
719 #if CONFIG_LOWPASS_FILTER 720 static const AVOption lowpass_options[] = {
745 #if CONFIG_HIGHPASS_FILTER 746 static const AVOption highpass_options[] = {
771 #if CONFIG_ALLPASS_FILTER 772 static const AVOption allpass_options[] = {
797 #if CONFIG_LOWSHELF_FILTER 798 static const AVOption lowshelf_options[] = {
823 #if CONFIG_HIGHSHELF_FILTER 824 static const AVOption highshelf_options[] = {
849 #if CONFIG_BIQUAD_FILTER 850 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[]
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.
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)
static av_cold int end(AVCodecContext *avctx)
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.
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 av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#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.
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.
static double b0(void *priv, double x, double y)
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.
typedef void(RENAME(mix_any_func_type))
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)\", 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 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.
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)
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.
static double b2(void *priv, double x, double y)