[FFmpeg-devel] [PATCH] lavfi/af_aemphasis: remove unnecessary complex number usage
Ganesh Ajjanagadde
gajjanagadde at gmail.com
Tue Dec 22 02:17:49 CET 2015
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 tests are also removed, and aemphasis is now available across
all platforms.
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
configure | 26 --------------------------
libavfilter/af_aemphasis.c | 13 ++++++-------
2 files changed, 6 insertions(+), 33 deletions(-)
diff --git a/configure b/configure
index 0227540..46021c4 100755
--- a/configure
+++ b/configure
@@ -1070,21 +1070,6 @@ int main(void){ $func(); }
EOF
}
-check_complexfunc(){
- log check_complexfunc "$@"
- func=$1
- narg=$2
- shift 2
- test $narg = 2 && args="f, g" || args="f * I"
- disable $func
- check_ld "cc" "$@" <<EOF && enable $func
-#include <complex.h>
-#include <math.h>
-float foo(complex float f, complex float g) { return $func($args); }
-int main(void){ return (int) foo; }
-EOF
-}
-
check_mathfunc(){
log check_mathfunc "$@"
func=$1
@@ -1803,11 +1788,6 @@ INTRINSICS_LIST="
intrinsics_neon
"
-COMPLEX_FUNCS="
- cabs
- cexp
-"
-
MATH_FUNCS="
atanf
atan2f
@@ -1944,7 +1924,6 @@ HAVE_LIST="
$ARCH_FEATURES
$ATOMICS_LIST
$BUILTIN_LIST
- $COMPLEX_FUNCS
$HAVE_LIST_CMDLINE
$HAVE_LIST_PUB
$HEADERS_LIST
@@ -2835,7 +2814,6 @@ unix_protocol_deps="sys_un_h"
unix_protocol_select="network"
# filters
-aemphasis_filter_deps="cabs cexp"
amovie_filter_deps="avcodec avformat"
aresample_filter_deps="swresample"
ass_filter_deps="libass"
@@ -5379,10 +5357,6 @@ for func in $MATH_FUNCS; do
eval check_mathfunc $func \${${func}_args:-1}
done
-for func in $COMPLEX_FUNCS; do
- eval check_complexfunc $func \${${func}_args:-1}
-done
-
# these are off by default, so fail if requested and not available
enabled avfoundation_indev && { check_header_objcc AVFoundation/AVFoundation.h || disable avfoundation_indev; }
enabled avfoundation_indev && { check_lib2 CoreGraphics/CoreGraphics.h CGGetActiveDisplayList -framework CoreGraphics ||
diff --git a/libavfilter/af_aemphasis.c b/libavfilter/af_aemphasis.c
index 2966f77..a5b8e30 100644
--- a/libavfilter/af_aemphasis.c
+++ b/libavfilter/af_aemphasis.c
@@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <complex.h>
-
#include "libavutil/opt.h"
#include "avfilter.h"
#include "internal.h"
@@ -189,14 +187,15 @@ static inline void set_lp_rbj(BiquadD2 *bq, double fc, double q, double sr, doub
static double freq_gain(BiquadCoeffs *c, double freq, double sr)
{
- double complex z, w;
+ double zr, zi;
freq *= 2.0 * M_PI / sr;
- w = 0 + I * freq;
- z = 1.0 / cexp(w);
+ zr = cos(freq);
+ zi = -sin(freq);
- return cabs(((double complex)c->a0 + c->a1 * z + c->a2 * z*z) /
- ((double complex)1.0 + c->b1 * z + c->b2 * z*z));
+ /* |(a0 + a1*z + a2*z^2)/(1 + b1*z + b2*z^2)| */
+ return hypot(c->a0 + c->a1*zr + c->a2*(zr*zr-zi*zi), c->a1*zi + 2*c->a2*zr*zi) /
+ hypot(1 + c->b1*zr + c->b2*(zr*zr-zi*zi), c->b1*zi + 2*c->b2*zr*zi);
}
static int config_input(AVFilterLink *inlink)
--
2.6.4
More information about the ffmpeg-devel
mailing list