Go to the documentation of this file.
31 #define FILTER_ORDER 4
75 #define OFFSET(x) offsetof(AudioNEqualizerContext, x)
76 #define A AV_OPT_FLAG_AUDIO_PARAM
77 #define V AV_OPT_FLAG_VIDEO_PARAM
78 #define F AV_OPT_FLAG_FILTERING_PARAM
88 {
"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 },
104 memset(
out->data[0], 0,
s->h *
out->linesize[0]);
107 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
115 for (
f = 0;
f <
s->w;
f++) {
116 double zr, zi, zr2, zi2;
122 w =
M_PI * (
s->fscale ? pow(
s->w - 1,
f /
s->w) :
f) / (
s->w - 1);
128 for (
n = 0;
n <
s->nb_filters;
n++) {
129 if (
s->filters[
n].channel !=
ch ||
130 s->filters[
n].ignore)
139 Hr =
S->b4*(1-8*zr2*zi2) +
S->b2*(zr2-zi2) + zr*(
S->b1+
S->b3*(zr2-3*zi2))+
S->b0;
140 Hi = zi*(
S->b3*(3*zr2-zi2) +
S->b1 + 2*zr*(2*
S->b4*(zr2-zi2) +
S->b2));
141 Hmag *=
hypot(Hr, Hi);
142 Hr =
S->a4*(1-8*zr2*zi2) +
S->a2*(zr2-zi2) + zr*(
S->a1+
S->a3*(zr2-3*zi2))+
S->a0;
143 Hi = zi*(
S->a3*(3*zr2-zi2) +
S->a1 + 2*zr*(2*
S->a4*(zr2-zi2) +
S->a2));
144 Hmag /=
hypot(Hr, Hi);
148 v = av_clip((1. + -20 * log10(Hmag) /
s->mag) *
s->h / 2, 0,
s->h - 1);
153 for (y = v; y <= prev_v; y++)
156 for (y = prev_v; y <= v; y++)
202 if (
s->draw_curves) {
218 if (
s->draw_curves) {
243 if (
s->draw_curves) {
272 for (
int i = 0;
i <
ctx->nb_outputs;
i++)
281 double si,
double g,
double g0,
284 if (c0 == 1 || c0 == -1) {
285 S->b0 = (
g*
g*beta*beta + 2*
g*g0*si*beta + g0*g0)/
D;
286 S->b1 = 2*c0*(
g*
g*beta*beta - g0*g0)/
D;
287 S->b2 = (
g*
g*beta*beta - 2*g0*
g*beta*si + g0*g0)/
D;
292 S->a1 = 2*c0*(beta*beta - 1)/
D;
293 S->a2 = (beta*beta - 2*beta*si + 1)/
D;
297 S->b0 = (
g*
g*beta*beta + 2*
g*g0*si*beta + g0*g0)/
D;
298 S->b1 = -4*c0*(g0*g0 +
g*g0*si*beta)/
D;
299 S->b2 = 2*(g0*g0*(1 + 2*c0*c0) -
g*
g*beta*beta)/
D;
300 S->b3 = -4*c0*(g0*g0 -
g*g0*si*beta)/
D;
301 S->b4 = (
g*
g*beta*beta - 2*
g*g0*si*beta + g0*g0)/
D;
304 S->a1 = -4*c0*(1 + si*beta)/
D;
305 S->a2 = 2*(1 + 2*c0*c0 - beta*beta)/
D;
306 S->a3 = -4*c0*(1 - si*beta)/
D;
307 S->a4 = (beta*beta - 2*si*beta + 1)/
D;
312 int N,
double w0,
double wb,
313 double G,
double Gb,
double G0)
315 double g, c0, g0, beta;
321 if (
G == 0 && G0 == 0) {
322 f->section[0].a0 = 1;
323 f->section[0].b0 = 1;
324 f->section[1].a0 = 1;
325 f->section[1].b0 = 1;
333 epsilon = sqrt((
G *
G - Gb * Gb) / (Gb * Gb - G0 * G0));
335 g0 = pow(G0, 1.0 /
N);
336 beta = pow(epsilon, -1.0 /
N) * tan(wb/2);
339 for (
i = 1;
i <=
L;
i++) {
340 double ui = (2.0 *
i - 1) /
N;
341 double si = sin(
M_PI *
ui / 2.0);
342 double Di = beta * beta + 2 * si * beta + 1;
349 double c,
double tetta_b,
350 double g0,
double si,
double b,
353 if (c0 == 1 || c0 == -1) {
354 S->b0 = (tetta_b*tetta_b*(
b*
b+g0*g0*
c*
c) + 2*g0*
b*si*tetta_b*tetta_b + g0*g0)/
D;
355 S->b1 = 2*c0*(tetta_b*tetta_b*(
b*
b+g0*g0*
c*
c) - g0*g0)/
D;
356 S->b2 = (tetta_b*tetta_b*(
b*
b+g0*g0*
c*
c) - 2*g0*
b*si*tetta_b + g0*g0)/
D;
361 S->a1 = 2*c0*(tetta_b*tetta_b*(
a*
a+
c*
c) - 1)/
D;
362 S->a2 = (tetta_b*tetta_b*(
a*
a+
c*
c) - 2*
a*si*tetta_b + 1)/
D;
366 S->b0 = ((
b*
b + g0*g0*
c*
c)*tetta_b*tetta_b + 2*g0*
b*si*tetta_b + g0*g0)/
D;
367 S->b1 = -4*c0*(g0*g0 + g0*
b*si*tetta_b)/
D;
368 S->b2 = 2*(g0*g0*(1 + 2*c0*c0) - (
b*
b + g0*g0*
c*
c)*tetta_b*tetta_b)/
D;
369 S->b3 = -4*c0*(g0*g0 - g0*
b*si*tetta_b)/
D;
370 S->b4 = ((
b*
b + g0*g0*
c*
c)*tetta_b*tetta_b - 2*g0*
b*si*tetta_b + g0*g0)/
D;
373 S->a1 = -4*c0*(1 +
a*si*tetta_b)/
D;
374 S->a2 = 2*(1 + 2*c0*c0 - (
a*
a +
c*
c)*tetta_b*tetta_b)/
D;
375 S->a3 = -4*c0*(1 -
a*si*tetta_b)/
D;
376 S->a4 = ((
a*
a +
c*
c)*tetta_b*tetta_b - 2*
a*si*tetta_b + 1)/
D;
381 int N,
double w0,
double wb,
382 double G,
double Gb,
double G0)
384 double a,
b, c0, g0, alfa, beta, tetta_b;
390 if (
G == 0 && G0 == 0) {
391 f->section[0].a0 = 1;
392 f->section[0].b0 = 1;
393 f->section[1].a0 = 1;
394 f->section[1].b0 = 1;
402 epsilon = sqrt((
G*
G - Gb*Gb) / (Gb*Gb - G0*G0));
404 alfa = pow(1.0/epsilon + sqrt(1 + 1/(epsilon*epsilon)), 1.0/
N);
405 beta = pow(
G/epsilon + Gb * sqrt(1 + 1/(epsilon*epsilon)), 1.0/
N);
406 a = 0.5 * (alfa - 1.0/alfa);
407 b = 0.5 * (beta - g0*g0*(1/beta));
411 for (
i = 1;
i <=
L;
i++) {
412 double ui = (2.0*
i-1.0)/
N;
413 double ci = cos(
M_PI*
ui/2.0);
414 double si = sin(
M_PI*
ui/2.0);
415 double Di = (
a*
a + ci*ci)*tetta_b*tetta_b + 2.0*
a*si*tetta_b + 1;
422 double c,
double tetta_b,
423 double g,
double si,
double b,
426 if (c0 == 1 || c0 == -1) {
427 S->b0 = (
g*
g*tetta_b*tetta_b + 2*tetta_b*
g*
b*si +
b*
b +
g*
g*
c*
c)/
D;
428 S->b1 = 2*c0*(
g*
g*tetta_b*tetta_b -
b*
b -
g*
g*
c*
c)/
D;
429 S->b2 = (
g*
g*tetta_b*tetta_b - 2*tetta_b*
g*
b*si +
b*
b +
g*
g*
c*
c)/
D;
434 S->a1 = 2*c0*(tetta_b*tetta_b -
a*
a -
c*
c)/
D;
435 S->a2 = (tetta_b*tetta_b - 2*tetta_b*
a*si +
a*
a +
c*
c)/
D;
439 S->b0 = (
g*
g*tetta_b*tetta_b + 2*
g*
b*si*tetta_b +
b*
b +
g*
g*
c*
c)/
D;
440 S->b1 = -4*c0*(
b*
b +
g*
g*
c*
c +
g*
b*si*tetta_b)/
D;
441 S->b2 = 2*((
b*
b +
g*
g*
c*
c)*(1 + 2*c0*c0) -
g*
g*tetta_b*tetta_b)/
D;
442 S->b3 = -4*c0*(
b*
b +
g*
g*
c*
c -
g*
b*si*tetta_b)/
D;
443 S->b4 = (
g*
g*tetta_b*tetta_b - 2*
g*
b*si*tetta_b +
b*
b +
g*
g*
c*
c)/
D;
446 S->a1 = -4*c0*(
a*
a +
c*
c +
a*si*tetta_b)/
D;
447 S->a2 = 2*((
a*
a +
c*
c)*(1 + 2*c0*c0) - tetta_b*tetta_b)/
D;
448 S->a3 = -4*c0*(
a*
a +
c*
c -
a*si*tetta_b)/
D;
449 S->a4 = (tetta_b*tetta_b - 2*
a*si*tetta_b +
a*
a +
c*
c)/
D;
454 int N,
double w0,
double wb,
455 double G,
double Gb,
double G0)
457 double a,
b, c0, tetta_b;
458 double epsilon,
g, eu, ew;
463 if (
G == 0 && G0 == 0) {
464 f->section[0].a0 = 1;
465 f->section[0].b0 = 1;
466 f->section[1].a0 = 1;
467 f->section[1].b0 = 1;
475 epsilon = sqrt((
G*
G - Gb*Gb) / (Gb*Gb - G0*G0));
477 eu = pow(epsilon + sqrt(1 + epsilon*epsilon), 1.0/
N);
478 ew = pow(G0*epsilon + Gb*sqrt(1 + epsilon*epsilon), 1.0/
N);
479 a = (eu - 1.0/eu)/2.0;
480 b = (ew -
g*
g/ew)/2.0;
484 for (
i = 1;
i <=
L;
i++) {
485 double ui = (2.0 *
i - 1.0)/
N;
486 double ci = cos(
M_PI *
ui / 2.0);
487 double si = sin(
M_PI *
ui / 2.0);
488 double Di = tetta_b*tetta_b + 2*
a*si*tetta_b +
a*
a + ci*ci;
500 else if(gain > -6 && gain < 6)
501 bw_gain = gain * 0.5;
514 else if(gain > -6 && gain < 6)
515 bw_gain = gain * 0.9;
528 else if(gain > -6 && gain < 6)
529 bw_gain = gain * 0.3;
567 if (
s->nb_filters >=
s->nb_allocated) {
573 memcpy(
filters,
s->filters,
sizeof(*
s->filters) *
s->nb_allocated);
576 s->nb_allocated *= 2;
588 char *saveptr =
NULL;
594 s->nb_allocated = 32 *
inlink->channels;
608 s->filters[
s->nb_filters].type = 0;
609 if (sscanf(
arg,
"c%d f=%lf w=%lf g=%lf t=%d", &
s->filters[
s->nb_filters].channel,
610 &
s->filters[
s->nb_filters].freq,
611 &
s->filters[
s->nb_filters].width,
612 &
s->filters[
s->nb_filters].gain,
613 &
s->filters[
s->nb_filters].type) != 5 &&
614 sscanf(
arg,
"c%d f=%lf w=%lf g=%lf", &
s->filters[
s->nb_filters].channel,
615 &
s->filters[
s->nb_filters].freq,
616 &
s->filters[
s->nb_filters].width,
617 &
s->filters[
s->nb_filters].gain) != 4 ) {
622 if (
s->filters[
s->nb_filters].freq < 0 ||
623 s->filters[
s->nb_filters].freq >
inlink->sample_rate / 2.0)
624 s->filters[
s->nb_filters].ignore = 1;
626 if (
s->filters[
s->nb_filters].channel < 0 ||
627 s->filters[
s->nb_filters].channel >=
inlink->channels)
628 s->filters[
s->nb_filters].ignore = 1;
630 s->filters[
s->nb_filters].type = av_clip(
s->filters[
s->nb_filters].type, 0,
NB_TYPES - 1);
642 char *res,
int res_len,
int flags)
648 if (!strcmp(cmd,
"change")) {
649 double freq,
width, gain;
652 if (sscanf(
args,
"%d|f=%lf|w=%lf|g=%lf", &
filter, &freq, &
width, &gain) != 4)
655 if (filter < 0 || filter >=
s->nb_filters)
658 if (freq < 0 || freq >
inlink->sample_rate / 2.0)
661 s->filters[
filter].freq = freq;
663 s->filters[
filter].gain = gain;
679 out+=
S->b1 *
S->num[0] -
S->denum[0] *
S->a1;
680 out+=
S->b2 *
S->num[1] -
S->denum[1] *
S->a2;
681 out+=
S->b3 *
S->num[2] -
S->denum[2] *
S->a3;
682 out+=
S->b4 *
S->num[3] -
S->denum[3] *
S->a4;
684 S->num[3] =
S->num[2];
685 S->num[2] =
S->num[1];
686 S->num[1] =
S->num[0];
689 S->denum[3] =
S->denum[2];
690 S->denum[2] =
S->denum[1];
691 S->denum[1] =
S->denum[0];
718 for (
i = 0;
i <
s->nb_filters;
i++) {
721 if (
f->gain == 0. ||
f->ignore)
724 bptr = (
double *)
buf->extended_data[
f->channel];
733 if (
s->draw_curves) {
734 const int64_t
pts =
buf->pts +
760 .
name =
"anequalizer",
763 .priv_class = &anequalizer_class,
static int config_video(AVFilterLink *outlink)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
A list of supported channel layouts.
AVPixelFormat
Pixel format.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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
struct AVFilterChannelLayouts * in_channel_layouts
static void butterworth_fo_section(FoSection *S, double beta, double si, double g, double g0, double D, double c0)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
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.
static const struct PPFilter filters[]
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
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(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_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_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 &&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);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
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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)
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
const char * name
Filter name.
A link between two filters.
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
static void chebyshev2_bp_filter(EqualizatorFilter *f, int N, double w0, double wb, double G, double Gb, double G0)
static const AVOption anequalizer_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
static int config_input(AVFilterLink *inlink)
AVFILTER_DEFINE_CLASS(anequalizer)
A filter pad used for either input or output.
static void equalizer(EqualizatorFilter *f, double sample_rate)
static void chebyshev2_fo_section(FoSection *S, double a, double c, double tetta_b, double g, double si, double b, double D, double c0)
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().
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
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 int query_formats(AVFilterContext *ctx)
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static double hz_2_rad(double x, double fs)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
static av_cold void uninit(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
#define fs(width, name, subs,...)
static const AVFilterPad inputs[]
Rational number (pair of numerator and denominator).
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
static void draw_curves(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *out)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_const double hypot(double x, double y)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
AVFilter ff_af_anequalizer
AVFilterContext * src
source filter
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int add_filter(AudioNEqualizerContext *s, AVFilterLink *inlink)
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
#define i(width, name, range_min, range_max)
int w
agreed upon image width
AVSampleFormat
Audio sample formats.
static double section_process(FoSection *S, double in)
const char AVS_Value args
static double chebyshev1_compute_bw_gain_db(double gain)
const char * name
Pad name.
static double chebyshev2_compute_bw_gain_db(double gain)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int h
agreed upon image height
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
static void butterworth_bp_filter(EqualizatorFilter *f, int N, double w0, double wb, double G, double Gb, double G0)
@ AV_SAMPLE_FMT_DBLP
double, planar
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
char * av_strdup(const char *s)
Duplicate a string.
static double process_sample(FoSection *s1, double in)
EqualizatorFilter * filters
#define flags(name, subs,...)
static av_cold int init(AVFilterContext *ctx)
static double butterworth_compute_bw_gain_db(double gain)