Browse code

lavfi/af_aemphasis: remove unnecessary complex number usage

complex is not available on all platforms. Furthermore, it is trivial to
rewrite complex number expressions to real arithmetic, and in fact
sometimes advantageous for performance reasons: by wrapping as a complex,
one forces a particular Cartesian representation that is not necessarily optimal for the purpose.

Configure dependencies also removed, and aemphasis is now available across
all platforms.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>

Ganesh Ajjanagadde authored on 2015/12/22 10:12:04
Showing 2 changed files
... ...
@@ -2836,7 +2836,6 @@ unix_protocol_deps="sys_un_h"
2836 2836
 unix_protocol_select="network"
2837 2837
 
2838 2838
 # filters
2839
-aemphasis_filter_deps="cabs cexp"
2840 2839
 amovie_filter_deps="avcodec avformat"
2841 2840
 aresample_filter_deps="swresample"
2842 2841
 ass_filter_deps="libass"
... ...
@@ -18,8 +18,6 @@
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 19
  */
20 20
 
21
-#include <complex.h>
22
-
23 21
 #include "libavutil/opt.h"
24 22
 #include "avfilter.h"
25 23
 #include "internal.h"
... ...
@@ -189,14 +187,15 @@ static inline void set_lp_rbj(BiquadD2 *bq, double fc, double q, double sr, doub
189 189
 
190 190
 static double freq_gain(BiquadCoeffs *c, double freq, double sr)
191 191
 {
192
-    double complex z, w;
192
+    double zr, zi;
193 193
 
194 194
     freq *= 2.0 * M_PI / sr;
195
-    w = 0 + I * freq;
196
-    z = 1.0 / cexp(w);
195
+    zr = cos(freq);
196
+    zi = -sin(freq);
197 197
 
198
-    return cabs(((double complex)c->a0 + c->a1 * z + c->a2 * z*z) /
199
-                ((double complex)1.0 + c->b1 * z + c->b2 * z*z));
198
+    /* |(a0 + a1*z + a2*z^2)/(1 + b1*z + b2*z^2)| */
199
+    return hypot(c->a0 + c->a1*zr + c->a2*(zr*zr-zi*zi), c->a1*zi + 2*c->a2*zr*zi) /
200
+           hypot(1 + c->b1*zr + c->b2*(zr*zr-zi*zi), c->b1*zi + 2*c->b2*zr*zi);
200 201
 }
201 202
 
202 203
 static int config_input(AVFilterLink *inlink)