Index: /libmpc/trunk/common/fastmath.c
===================================================================
--- /libmpc/trunk/common/fastmath.c	(revision 333)
+++ /libmpc/trunk/common/fastmath.c	(revision 333)
@@ -0,0 +1,77 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "mpc/mpcmath.h"
+
+#ifdef FAST_MATH
+
+const float  tabatan2   [ 2*TABSTEP+1] [2];
+const float  tabcos     [26*TABSTEP+1] [2];
+const float  tabsqrt_ex [256];
+const float  tabsqrt_m  [   TABSTEP+1] [2];
+
+
+void   Init_FastMath ( void )
+{
+    int i; mpc_floatint X, Y; double xm, x0, xp, x, y; float* p;
+
+    p = (float*) tabatan2;
+    for ( i = -TABSTEP; i <= TABSTEP; i++ ) {
+        xm = atan ((i-0.5)/TABSTEP);
+        x0 = atan ((i+0.0)/TABSTEP);
+        xp = atan ((i+0.5)/TABSTEP);
+        x  = x0/2 + (xm + xp)/4;
+        y  = xp - xm;
+        *p++ = x;
+        *p++ = y;
+    }
+
+    p = (float*) tabcos;
+    for ( i = -13*TABSTEP; i <= 13*TABSTEP; i++ ) {
+        xm = cos ((i-0.5)/TABSTEP);
+        x0 = cos ((i+0.0)/TABSTEP);
+        xp = cos ((i+0.5)/TABSTEP);
+        x  = x0/2 + (xm + xp)/4;
+        y  = xp - xm;
+        *p++ = x;
+        *p++ = y;
+    }
+
+    p = (float*) tabsqrt_ex;
+    for ( i = 0; i < 255; i++ ) {
+        X.n = (i << 23);
+        Y.n = (i << 23) + (1<<23) - 1;
+        *p++ = sqrt(X.f);
+    }
+    X.n  = (255 << 23) - 1;
+    *p++ = sqrt(X.f);
+
+    p = (float*) tabsqrt_m;
+    for ( i = 1*TABSTEP; i <= 2*TABSTEP; i++ ) {
+        xm = sqrt ((i-0.5)/TABSTEP);
+        x0 = sqrt ((i+0.0)/TABSTEP);
+        xp = sqrt ((i+0.5)/TABSTEP);
+        x  = x0/2 + (xm + xp)/4;
+        y  = xp - xm;
+        *p++ = x;
+        *p++ = y;
+    }
+}
+
+#endif
Index: /libmpc/trunk/include/mpc/mpcmath.h
===================================================================
--- /libmpc/trunk/include/mpc/mpcmath.h	(revision 332)
+++ /libmpc/trunk/include/mpc/mpcmath.h	(revision 333)
@@ -18,4 +18,21 @@
 
 #include <mpc/mpc_types.h>
+
+typedef union mpc_floatint
+{
+	float   f;
+	mpc_int32_t n;
+} mpc_floatint;
+
+static mpc_inline mpc_int32_t mpc_lrintf(float fVal)
+{
+	mpc_floatint tmp;
+	tmp.f = fVal  + 0x00FF8000;
+	return tmp.n - 0x4B7F8000;
+}
+
+#define mpc_round32		mpc_lrintf
+#define mpc_nearbyintf	mpc_lrintf
+
 
 #ifndef M_PI
@@ -55,25 +72,76 @@
 #endif
 
-#define SQRTF(x)     SQRT (x)
-#define COSF(x)      COS (x)
-#define ATAN2F(x,y)  ATAN2 (x,y)
-#define IFLOORF(x)   IFLOOR (x)
+#define SQRTF(x)      SQRT (x)
+#ifdef FAST_MATH
+# define TABSTEP      64
+# define COSF(x)      my_cos ((float)(x))
+# define ATAN2F(x,y)  my_atan2 ((float)(x), (float)(y))
+# define IFLOORF(x)   my_ifloor ((float)(x))
 
-typedef union mpc_floatint
+void   Init_FastMath ( void );
+extern const float  tabatan2   [] [2];
+extern const float  tabcos     [] [2];
+extern const float  tabsqrt_ex [];
+extern const float  tabsqrt_m  [] [2];
+
+static mpc_inline float my_atan2 ( float x, float y )
 {
-	float   f;
-	mpc_int32_t n;
-} mpc_floatint;
+	float t, ret; int i; mpc_floatint mx, my;
 
-static mpc_inline mpc_int32_t mpc_lrintf(float fVal)
-{
-	mpc_floatint tmp;
-	tmp.f = fVal  + 0x00FF8000;
-	return tmp.n - 0x4B7F8000;
+	mx.f = x;
+	my.f = y;
+	if ( (mx.n & 0x7FFFFFFF) < (my.n & 0x7FFFFFFF) ) {
+		i   = mpc_round32 (t = TABSTEP * (mx.f / my.f));
+		ret = tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (t-i);
+		if ( my.n < 0 )
+			ret = (float)(ret - M_PI);
+	}
+	else if ( mx.n < 0 ) {
+		i   = mpc_round32 (t = TABSTEP * (my.f / mx.f));
+		ret = - M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t);
+	}
+	else if ( mx.n > 0 ) {
+		i   = mpc_round32 (t = TABSTEP * (my.f / mx.f));
+		ret = + M_PI/2 - tabatan2 [1*TABSTEP+i][0] + tabatan2 [1*TABSTEP+i][1] * (i-t);
+	}
+	else {
+		ret = 0.;
+	}
+	return ret;
 }
 
-static mpc_inline float mpc_nearbyintf(float fVal)
+
+static mpc_inline float my_cos ( float x )
 {
-	return (float) mpc_lrintf(fVal);
+	float t, ret; int i;
+	i   = mpc_round32 (t = TABSTEP * x);
+	ret = tabcos [13*TABSTEP+i][0] + tabcos [13*TABSTEP+i][1] * (t-i);
+	return ret;
 }
 
+
+static mpc_inline int my_ifloor ( float x )
+{
+	mpc_floatint mx;
+	mx.f = (float) (x + (0x0C00000L + 0.500000001));
+	return mx.n - 1262485505;
+}
+
+
+static mpc_inline float my_sqrt ( float x )
+{
+	float  ret; int i, ex; mpc_floatint mx;
+	mx.f = x;
+	ex   = mx.n >> 23;                     // get the exponent
+	mx.n = (mx.n & 0x7FFFFF) | 0x42800000; // delete the exponent
+	i    = mpc_round32 (mx.f);             // Integer-part of the mantissa  (round ????????????)
+	ret  = tabsqrt_m [i-TABSTEP][0] + tabsqrt_m [i-TABSTEP][1] * (mx.f-i); // calculate value
+	ret *= tabsqrt_ex [ex];
+	return ret;
+}
+#else
+# define COSF(x)      COS (x)
+# define ATAN2F(x,y)  ATAN2 (x,y)
+# define IFLOORF(x)   IFLOOR (x)
+#endif
+
Index: /libmpc/trunk/mpcenc/Makefile.am
===================================================================
--- /libmpc/trunk/mpcenc/Makefile.am	(revision 332)
+++ /libmpc/trunk/mpcenc/Makefile.am	(revision 333)
@@ -2,5 +2,6 @@
 
 common_sources = ../common/crc32.c \
-		../common/huffman-bcl.c
+		../common/huffman-bcl.c \
+		../common/fastmath.c
 
 # set the include path found by configure
Index: /libmpc/trunk/mpcenc/config.h
===================================================================
--- /libmpc/trunk/mpcenc/config.h	(revision 332)
+++ /libmpc/trunk/mpcenc/config.h	(revision 333)
@@ -32,5 +32,5 @@
 
 #define MPCENC_MAJOR 1
-#define MPCENC_MINOR 23
+#define MPCENC_MINOR 25
 #define MPCENC_BUILD 0
 
Index: /libmpc/trunk/mpcenc/mpcenc.c
===================================================================
--- /libmpc/trunk/mpcenc/mpcenc.c	(revision 332)
+++ /libmpc/trunk/mpcenc/mpcenc.c	(revision 333)
@@ -1813,4 +1813,8 @@
         (void) stderr_printf ("\r\x1B[1m\r%s\n\x1B[0m\r     \r", About );
 
+#ifdef FAST_MATH
+    Init_FastMath ();
+#endif
+
     // no arguments or call for help
     if ( argc < 2  ||  0==strcmp (argv[1],"-h")  ||  0==strcmp (argv[1],"-?")  ||  0==strcmp (argv[1],"--help") ) {
