You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-11 14:30:22 +02:00
avfilter/af_aiir: factor out response calculation
This commit is contained in:
@ -737,41 +737,24 @@ static void draw_line(AVFrame *out, int x0, int y0, int x1, int y1, uint32_t col
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_response(AVFilterContext *ctx, AVFrame *out)
|
static void get_response(int channel, int format, double w,
|
||||||
|
const double *b, const double *a,
|
||||||
|
int nb_b, int nb_a, double *r, double *i)
|
||||||
{
|
{
|
||||||
AudioIIRContext *s = ctx->priv;
|
|
||||||
float *mag, *phase, *delay, min = FLT_MAX, max = FLT_MIN;
|
|
||||||
float min_delay = FLT_MAX, max_delay = FLT_MIN;
|
|
||||||
int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
|
|
||||||
char text[32];
|
|
||||||
int ch, i, x;
|
|
||||||
|
|
||||||
memset(out->data[0], 0, s->h * out->linesize[0]);
|
|
||||||
|
|
||||||
phase = av_malloc_array(s->w, sizeof(*phase));
|
|
||||||
mag = av_malloc_array(s->w, sizeof(*mag));
|
|
||||||
delay = av_malloc_array(s->w, sizeof(*delay));
|
|
||||||
if (!mag || !phase || !delay)
|
|
||||||
goto end;
|
|
||||||
|
|
||||||
ch = av_clip(s->ir_channel, 0, s->channels - 1);
|
|
||||||
for (i = 0; i < s->w; i++) {
|
|
||||||
const double *b = s->iir[ch].ab[0];
|
|
||||||
const double *a = s->iir[ch].ab[1];
|
|
||||||
double w = i * M_PI / (s->w - 1);
|
|
||||||
double realz, realp;
|
double realz, realp;
|
||||||
double imagz, imagp;
|
double imagz, imagp;
|
||||||
double real, imag, div;
|
double real, imag;
|
||||||
|
double div;
|
||||||
|
|
||||||
if (s->format == 0) {
|
if (format == 0) {
|
||||||
realz = 0., realp = 0.;
|
realz = 0., realp = 0.;
|
||||||
imagz = 0., imagp = 0.;
|
imagz = 0., imagp = 0.;
|
||||||
for (x = 0; x < s->iir[ch].nb_ab[1]; x++) {
|
for (int x = 0; x < nb_a; x++) {
|
||||||
realz += cos(-x * w) * a[x];
|
realz += cos(-x * w) * a[x];
|
||||||
imagz += sin(-x * w) * a[x];
|
imagz += sin(-x * w) * a[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < s->iir[ch].nb_ab[0]; x++) {
|
for (int x = 0; x < nb_b; x++) {
|
||||||
realp += cos(-x * w) * b[x];
|
realp += cos(-x * w) * b[x];
|
||||||
imagp += sin(-x * w) * b[x];
|
imagp += sin(-x * w) * b[x];
|
||||||
}
|
}
|
||||||
@ -782,7 +765,7 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
|
|||||||
} else {
|
} else {
|
||||||
real = 1;
|
real = 1;
|
||||||
imag = 0;
|
imag = 0;
|
||||||
for (x = 0; x < s->iir[ch].nb_ab[1]; x++) {
|
for (int x = 0; x < nb_a; x++) {
|
||||||
double ore, oim, re, im;
|
double ore, oim, re, im;
|
||||||
|
|
||||||
re = cos(w) - a[2 * x];
|
re = cos(w) - a[2 * x];
|
||||||
@ -795,7 +778,7 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
|
|||||||
imag = ore * im + oim * re;
|
imag = ore * im + oim * re;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < s->iir[ch].nb_ab[0]; x++) {
|
for (int x = 0; x < nb_b; x++) {
|
||||||
double ore, oim, re, im;
|
double ore, oim, re, im;
|
||||||
|
|
||||||
re = cos(w) - b[2 * x];
|
re = cos(w) - b[2 * x];
|
||||||
@ -810,6 +793,38 @@ static void draw_response(AVFilterContext *ctx, AVFrame *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*r = real;
|
||||||
|
*i = imag;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_response(AVFilterContext *ctx, AVFrame *out)
|
||||||
|
{
|
||||||
|
AudioIIRContext *s = ctx->priv;
|
||||||
|
float *mag, *phase, *delay, min = FLT_MAX, max = FLT_MIN;
|
||||||
|
float min_delay = FLT_MAX, max_delay = FLT_MIN;
|
||||||
|
int prev_ymag = -1, prev_yphase = -1, prev_ydelay = -1;
|
||||||
|
char text[32];
|
||||||
|
int ch, i;
|
||||||
|
|
||||||
|
memset(out->data[0], 0, s->h * out->linesize[0]);
|
||||||
|
|
||||||
|
phase = av_malloc_array(s->w, sizeof(*phase));
|
||||||
|
mag = av_malloc_array(s->w, sizeof(*mag));
|
||||||
|
delay = av_malloc_array(s->w, sizeof(*delay));
|
||||||
|
if (!mag || !phase || !delay)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
ch = av_clip(s->ir_channel, 0, s->channels - 1);
|
||||||
|
for (i = 0; i < s->w; i++) {
|
||||||
|
const double *b = s->iir[ch].ab[0];
|
||||||
|
const double *a = s->iir[ch].ab[1];
|
||||||
|
const int nb_b = s->iir[ch].nb_ab[0];
|
||||||
|
const int nb_a = s->iir[ch].nb_ab[1];
|
||||||
|
double w = i * M_PI / (s->w - 1);
|
||||||
|
double real, imag;
|
||||||
|
|
||||||
|
get_response(ch, s->format, w, b, a, nb_b, nb_a, &real, &imag);
|
||||||
|
|
||||||
mag[i] = s->iir[ch].g * hypot(real, imag);
|
mag[i] = s->iir[ch].g * hypot(real, imag);
|
||||||
phase[i] = atan2(imag, real);
|
phase[i] = atan2(imag, real);
|
||||||
min = fminf(min, mag[i]);
|
min = fminf(min, mag[i]);
|
||||||
|
Reference in New Issue
Block a user