Commit 63702014 authored by Ganesh Ajjanagadde's avatar Ganesh Ajjanagadde

lavfi/af_anequalizer: remove cabs, cexp dependencies

Replaces by real arithmetic. Tested the validity of these transformations separately.
Numerical differences are ~1e-15, and should not matter: it is not even
clear which is more precise mathematically.
Reviewed-by: 's avatarPaul B Mahol <onemda@gmail.com>
Signed-off-by: 's avatarGanesh Ajjanagadde <gajjanagadde@gmail.com>
parent a7bf5f41
......@@ -2839,7 +2839,6 @@ unix_protocol_select="network"
# filters
amovie_filter_deps="avcodec avformat"
anequalizer_filter_deps="cabs cexp"
aresample_filter_deps="swresample"
ass_filter_deps="libass"
asyncts_filter_deps="avresample"
......
......@@ -19,8 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <complex.h>
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
......@@ -114,13 +112,17 @@ static void draw_curves(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *out
av_parse_color(fg, color, -1, ctx);
for (f = 0; f < s->w; f++) {
double complex z;
double complex H = 1;
double zr, zi, zr2, zi2;
double Hr, Hi;
double Hmag = 1;
double w;
int v, y, x;
w = M_PI * (s->fscale ? pow(s->w - 1, f / s->w) : f) / (s->w - 1);
z = 1. / cexp(I * w);
zr = cos(w);
zr2 = zr * zr;
zi = -sin(w);
zi2 = zi * zi;
for (n = 0; n < s->nb_filters; n++) {
if (s->filters[n].channel != ch ||
......@@ -130,12 +132,19 @@ static void draw_curves(AVFilterContext *ctx, AVFilterLink *inlink, AVFrame *out
for (i = 0; i < FILTER_ORDER / 2; i++) {
FoSection *S = &s->filters[n].section[i];
H *= (((((S->b4 * z + S->b3) * z + S->b2) * z + S->b1) * z + S->b0) /
((((S->a4 * z + S->a3) * z + S->a2) * z + S->a1) * z + S->a0));
/* H *= (((((S->b4 * z + S->b3) * z + S->b2) * z + S->b1) * z + S->b0) /
((((S->a4 * z + S->a3) * z + S->a2) * z + S->a1) * z + S->a0)); */
Hr = S->b4*(1-8*zr2*zi2) + S->b2*(zr2-zi2) + zr*(S->b1+S->b3*(zr2-3*zi2))+ S->b0;
Hi = zi*(S->b3*(3*zr2-zi2) + S->b1 + 2*zr*(2*S->b4*(zr2-zi2) + S->b2));
Hmag *= hypot(Hr, Hi);
Hr = S->a4*(1-8*zr2*zi2) + S->a2*(zr2-zi2) + zr*(S->a1+S->a3*(zr2-3*zi2))+ S->a0;
Hi = zi*(S->a3*(3*zr2-zi2) + S->a1 + 2*zr*(2*S->a4*(zr2-zi2) + S->a2));
Hmag /= hypot(Hr, Hi);
}
}
v = av_clip((1. + -20 * log10(cabs(H)) / s->mag) * s->h / 2, 0, s->h - 1);
v = av_clip((1. + -20 * log10(Hmag) / s->mag) * s->h / 2, 0, s->h - 1);
x = lrint(f);
if (prev_v == -1)
prev_v = v;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment