30 #define FILTER_ORDER 4
74 #define OFFSET(x) offsetof(AudioNEqualizerContext, x)
75 #define A AV_OPT_FLAG_AUDIO_PARAM
76 #define V AV_OPT_FLAG_VIDEO_PARAM
77 #define F AV_OPT_FLAG_FILTERING_PARAM
87 {
"colors",
"set channels curves colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
V|
F },
105 for (ch = 0; ch < inlink->
channels; ch++) {
106 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
114 for (f = 0; f < s->
w; f++) {
115 double zr, zi, zr2, zi2;
121 w =
M_PI * (s->
fscale ? pow(s->
w - 1, f / s->
w) : f) / (s->
w - 1);
138 Hr = S->
b4*(1-8*zr2*zi2) + S->
b2*(zr2-zi2) + zr*(S->
b1+S->
b3*(zr2-3*zi2))+ S->
b0;
139 Hi = zi*(S->
b3*(3*zr2-zi2) + S->
b1 + 2*zr*(2*S->
b4*(zr2-zi2) + S->
b2));
140 Hmag *=
hypot(Hr, Hi);
141 Hr = S->
a4*(1-8*zr2*zi2) + S->
a2*(zr2-zi2) + zr*(S->
a1+S->
a3*(zr2-3*zi2))+ S->
a0;
142 Hi = zi*(S->
a3*(3*zr2-zi2) + S->
a1 + 2*zr*(2*S->
a4*(zr2-zi2) + S->
a2));
143 Hmag /=
hypot(Hr, Hi);
147 v = av_clip((1. + -20 * log10(Hmag) / s->
mag) * s->
h / 2, 0, s->
h - 1);
152 for (y = v; y <= prev_v; y++)
155 for (y = prev_v; y <= v; y++)
271 double si,
double g,
double g0,
274 if (c0 == 1 || c0 == -1) {
275 S->
b0 = (g*g*beta*beta + 2*g*g0*si*beta + g0*g0)/D;
276 S->
b1 = 2*c0*(g*g*beta*beta - g0*g0)/D;
277 S->
b2 = (g*g*beta*beta - 2*g0*g*beta*si + g0*g0)/D;
282 S->
a1 = 2*c0*(beta*beta - 1)/D;
283 S->
a2 = (beta*beta - 2*beta*si + 1)/D;
287 S->
b0 = (g*g*beta*beta + 2*g*g0*si*beta + g0*g0)/D;
288 S->
b1 = -4*c0*(g0*g0 + g*g0*si*beta)/D;
289 S->
b2 = 2*(g0*g0*(1 + 2*c0*c0) - g*g*beta*beta)/
D;
290 S->
b3 = -4*c0*(g0*g0 - g*g0*si*beta)/D;
291 S->
b4 = (g*g*beta*beta - 2*g*g0*si*beta + g0*g0)/D;
294 S->
a1 = -4*c0*(1 + si*beta)/D;
295 S->
a2 = 2*(1 + 2*c0*c0 - beta*beta)/D;
296 S->
a3 = -4*c0*(1 - si*beta)/D;
297 S->
a4 = (beta*beta - 2*si*beta + 1)/D;
302 int N,
double w0,
double wb,
303 double G,
double Gb,
double G0)
305 double g, c0, g0, beta;
311 if (G == 0 && G0 == 0) {
323 epsilon = sqrt((G * G - Gb * Gb) / (Gb * Gb - G0 * G0));
325 g0 = pow(G0, 1.0 / N);
326 beta = pow(epsilon, -1.0 / N) * tan(wb/2);
329 for (i = 1; i <=
L; i++) {
330 double ui = (2.0 * i - 1) / N;
331 double si = sin(
M_PI * ui / 2.0);
332 double Di = beta * beta + 2 * si * beta + 1;
339 double c,
double tetta_b,
340 double g0,
double si,
double b,
343 if (c0 == 1 || c0 == -1) {
344 S->
b0 = (tetta_b*tetta_b*(b*b+g0*g0*c*
c) + 2*g0*b*si*tetta_b*tetta_b + g0*g0)/
D;
345 S->
b1 = 2*c0*(tetta_b*tetta_b*(b*b+g0*g0*c*
c) - g0*g0)/
D;
346 S->
b2 = (tetta_b*tetta_b*(b*b+g0*g0*c*
c) - 2*g0*b*si*tetta_b + g0*g0)/
D;
351 S->
a1 = 2*c0*(tetta_b*tetta_b*(a*a+c*
c) - 1)/
D;
352 S->
a2 = (tetta_b*tetta_b*(a*a+c*
c) - 2*a*si*tetta_b + 1)/
D;
356 S->
b0 = ((b*b + g0*g0*c*
c)*tetta_b*tetta_b + 2*g0*b*si*tetta_b + g0*g0)/
D;
357 S->
b1 = -4*c0*(g0*g0 + g0*b*si*tetta_b)/D;
358 S->
b2 = 2*(g0*g0*(1 + 2*c0*c0) - (b*b + g0*g0*c*c)*tetta_b*tetta_b)/D;
359 S->
b3 = -4*c0*(g0*g0 - g0*b*si*tetta_b)/D;
360 S->
b4 = ((b*b + g0*g0*c*
c)*tetta_b*tetta_b - 2*g0*b*si*tetta_b + g0*g0)/
D;
363 S->
a1 = -4*c0*(1 + a*si*tetta_b)/D;
364 S->
a2 = 2*(1 + 2*c0*c0 - (a*a + c*
c)*tetta_b*tetta_b)/
D;
365 S->
a3 = -4*c0*(1 - a*si*tetta_b)/D;
366 S->
a4 = ((a*a + c*
c)*tetta_b*tetta_b - 2*a*si*tetta_b + 1)/
D;
371 int N,
double w0,
double wb,
372 double G,
double Gb,
double G0)
374 double a,
b, c0, g0, alfa, beta, tetta_b;
380 if (G == 0 && G0 == 0) {
392 epsilon = sqrt((G*G - Gb*Gb) / (Gb*Gb - G0*G0));
394 alfa = pow(1.0/epsilon + sqrt(1 + 1/(epsilon*epsilon)), 1.0/N);
395 beta = pow(G/epsilon + Gb * sqrt(1 + 1/(epsilon*epsilon)), 1.0/N);
396 a = 0.5 * (alfa - 1.0/alfa);
397 b = 0.5 * (beta - g0*g0*(1/beta));
401 for (i = 1; i <=
L; i++) {
402 double ui = (2.0*i-1.0)/
N;
403 double ci = cos(
M_PI*ui/2.0);
404 double si = sin(
M_PI*ui/2.0);
405 double Di = (a*a + ci*ci)*tetta_b*tetta_b + 2.0*a*si*tetta_b + 1;
412 double c,
double tetta_b,
413 double g,
double si,
double b,
416 if (c0 == 1 || c0 == -1) {
417 S->
b0 = (g*g*tetta_b*tetta_b + 2*tetta_b*g*b*si + b*b + g*g*c*
c)/D;
418 S->
b1 = 2*c0*(g*g*tetta_b*tetta_b - b*b - g*g*c*
c)/D;
419 S->
b2 = (g*g*tetta_b*tetta_b - 2*tetta_b*g*b*si + b*b + g*g*c*
c)/D;
424 S->
a1 = 2*c0*(tetta_b*tetta_b - a*a - c*
c)/D;
425 S->
a2 = (tetta_b*tetta_b - 2*tetta_b*a*si + a*a + c*
c)/D;
429 S->
b0 = (g*g*tetta_b*tetta_b + 2*g*b*si*tetta_b + b*b + g*g*c*
c)/D;
430 S->
b1 = -4*c0*(b*b + g*g*c*c + g*b*si*tetta_b)/D;
431 S->
b2 = 2*((b*b + g*g*c*
c)*(1 + 2*c0*c0) - g*g*tetta_b*tetta_b)/D;
432 S->
b3 = -4*c0*(b*b + g*g*c*c - g*b*si*tetta_b)/D;
433 S->
b4 = (g*g*tetta_b*tetta_b - 2*g*b*si*tetta_b + b*b + g*g*c*
c)/D;
436 S->
a1 = -4*c0*(a*a + c*c + a*si*tetta_b)/D;
437 S->
a2 = 2*((a*a + c*
c)*(1 + 2*c0*c0) - tetta_b*tetta_b)/D;
438 S->
a3 = -4*c0*(a*a + c*c - a*si*tetta_b)/D;
439 S->
a4 = (tetta_b*tetta_b - 2*a*si*tetta_b + a*a + c*
c)/D;
444 int N,
double w0,
double wb,
445 double G,
double Gb,
double G0)
447 double a,
b, c0, tetta_b;
448 double epsilon,
g, eu, ew;
453 if (G == 0 && G0 == 0) {
465 epsilon = sqrt((G*G - Gb*Gb) / (Gb*Gb - G0*G0));
467 eu = pow(epsilon + sqrt(1 + epsilon*epsilon), 1.0/N);
468 ew = pow(G0*epsilon + Gb*sqrt(1 + epsilon*epsilon), 1.0/N);
469 a = (eu - 1.0/eu)/2.0;
470 b = (ew - g*g/ew)/2.0;
474 for (i = 1; i <=
L; i++) {
475 double ui = (2.0 * i - 1.0)/
N;
476 double ci = cos(
M_PI * ui / 2.0);
477 double si = sin(
M_PI * ui / 2.0);
478 double Di = tetta_b*tetta_b + 2*a*si*tetta_b + a*a + ci*ci;
490 else if(gain > -6 && gain < 6)
491 bw_gain = gain * 0.5;
504 else if(gain > -6 && gain < 6)
505 bw_gain = gain * 0.9;
518 else if(gain > -6 && gain < 6)
519 bw_gain = gain * 0.3;
528 return 2 *
M_PI * x / fs;
578 char *saveptr =
NULL;
632 char *res,
int res_len,
int flags)
638 if (!strcmp(cmd,
"change")) {
639 double freq,
width, gain;
642 if (sscanf(args,
"%d|f=%lf|w=%lf|g=%lf", &filter, &freq, &width, &gain) != 4)
724 const int64_t
pts = buf->
pts +
750 .
name =
"anequalizer",
753 .priv_class = &anequalizer_class,
static void chebyshev2_fo_section(FoSection *S, double a, double c, double tetta_b, double g, double si, double b, double D, double c0)
This structure describes decoded (raw) audio or video data.
static void chebyshev1_bp_filter(EqualizatorFilter *f, int N, double w0, double wb, double G, double Gb, double G0)
Main libavfilter public API header.
int h
agreed upon image height
static double butterworth_compute_bw_gain_db(double gain)
static int config_video(AVFilterLink *outlink)
static void butterworth_bp_filter(EqualizatorFilter *f, int N, double w0, double wb, double G, double Gb, double G0)
static void butterworth_fo_section(FoSection *S, double beta, double si, double g, double g0, double D, double c0)
static enum AVSampleFormat formats[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVFILTER_DEFINE_CLASS(anequalizer)
struct AVFilterChannelLayouts * in_channel_layouts
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFilterPad * output_pads
array of output pads
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static const AVOption anequalizer_options[]
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, uint8_t clip)
static void chebyshev2_bp_filter(EqualizatorFilter *f, int N, double w0, double wb, double G, double Gb, double G0)
static void chebyshev1_fo_section(FoSection *S, double a, double c, double tetta_b, double g0, double si, double b, double D, double c0)
static double hz_2_rad(double x, double fs)
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static int config_input(AVFilterLink *inlink)
int sample_rate
samples per second
static void equalizer(EqualizatorFilter *f, double sample_rate)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
struct AVFilterChannelLayouts * out_channel_layouts
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
static void draw_curves(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *out)
static int query_formats(AVFilterContext *ctx)
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int w
agreed upon image width
static av_const double hypot(double x, double y)
static const AVFilterPad inputs[]
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
AVFilterFormats * out_samplerates
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
static double process_sample(FoSection *s1, double in)
A list of supported channel layouts.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
AVSampleFormat
Audio sample formats.
static double chebyshev2_compute_bw_gain_db(double gain)
char * av_strdup(const char *s)
Duplicate the string s.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
AVFilter ff_af_anequalizer
Describe the class of an AVClass context structure.
rational number numerator/denominator
const char * name
Filter name.
static int add_filter(AudioNEqualizerContext *s, AVFilterLink *inlink)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
offset must point to two consecutive integers
AVFilterLink ** outputs
array of pointers to output links
enum MovChannelLayoutTag * layouts
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
static int64_t pts
Global timestamp for the audio frames.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
static double section_process(FoSection *S, double in)
static double chebyshev1_compute_bw_gain_db(double gain)
static av_cold int init(AVFilterContext *ctx)
int channels
Number of channels.
AVFilterContext * dst
dest filter
static const struct PPFilter filters[]
static enum AVSampleFormat sample_fmts[]
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
EqualizatorFilter * filters
uint8_t ** extended_data
pointers to the data planes/channels.
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
AVPixelFormat
Pixel format.
int nb_samples
number of audio samples (per channel) described by this frame
AVFilterFormats * out_formats