Index: /libmpc/branches/r2d/include/mpc/mpcmath.h
===================================================================
--- /libmpc/branches/r2d/include/mpc/mpcmath.h	(revision 155)
+++ /libmpc/branches/r2d/include/mpc/mpcmath.h	(revision 156)
@@ -17,4 +17,5 @@
  */
 
+#include <mpc/mpc_types.h>
 
 #ifndef M_PI
@@ -58,2 +59,21 @@
 #define ATAN2F(x,y)  ATAN2 (x,y)
 #define IFLOORF(x)   IFLOOR (x)
+
+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;
+}
+
+static mpc_inline float mpc_nearbyintf(float fVal)
+{
+	return (float) mpc_lrintf(fVal);
+}
+
Index: /libmpc/branches/r2d/libmpc.kdevelop
===================================================================
--- /libmpc/branches/r2d/libmpc.kdevelop	(revision 155)
+++ /libmpc/branches/r2d/libmpc.kdevelop	(revision 156)
@@ -3,5 +3,5 @@
   <general>
     <author>Nicolas Botti</author>
-    <email/>
+    <email></email>
     <version>0.1</version>
     <projectmanagement>KDevAutoProject</projectmanagement>
@@ -14,20 +14,20 @@
     <projectdirectory>.</projectdirectory>
     <absoluteprojectpath>false</absoluteprojectpath>
-    <description/>
+    <description></description>
   </general>
   <kdevautoproject>
     <general>
-      <activetarget>libmpcdec/libmpcdec.la</activetarget>
+      <activetarget>mppenc/mppenc</activetarget>
       <useconfiguration>debug</useconfiguration>
     </general>
     <run>
-      <mainprogram>/usr/bin/xmms</mainprogram>
+      <mainprogram>mppenc/mppenc</mainprogram>
       <terminal>true</terminal>
-      <directoryradio>custom</directoryradio>
+      <directoryradio>executable</directoryradio>
       <runarguments>
         <mppenc/>
       </runarguments>
       <customdirectory>/</customdirectory>
-      <programargs/>
+      <programargs></programargs>
       <autocompile>true</autocompile>
       <envvars/>
@@ -39,15 +39,15 @@
         <cxxcompiler>kdevgppoptions</cxxcompiler>
         <f77compiler>kdevg77options</f77compiler>
-        <cflags>-O3 -fomit-frame-pointer -pipe -Wall -ffast-math</cflags>
+        <cflags>-O3 -fomit-frame-pointer -pipe -Wall</cflags>
         <envvars/>
-        <configargs/>
-        <topsourcedir/>
+        <configargs></configargs>
+        <topsourcedir></topsourcedir>
         <cppflags>-DMPP_ENCODER=1 -DTRUE=1 -DFALSE=0</cppflags>
-        <ldflags/>
-        <ccompilerbinary/>
-        <cxxcompilerbinary/>
-        <f77compilerbinary/>
-        <cxxflags/>
-        <f77flags/>
+        <ldflags></ldflags>
+        <ccompilerbinary></ccompilerbinary>
+        <cxxcompilerbinary></cxxcompilerbinary>
+        <f77compilerbinary></f77compilerbinary>
+        <cxxflags></cxxflags>
+        <f77flags></f77flags>
       </optimized>
       <debug>
@@ -77,5 +77,5 @@
       <numberofjobs>1</numberofjobs>
       <dontact>false</dontact>
-      <makebin/>
+      <makebin></makebin>
       <prio>0</prio>
     </make>
@@ -139,6 +139,4 @@
       <group pattern="*.h" name="Header files" />
       <group pattern="*.c" name="Source files" />
-      <hidenonprojectfiles>false</hidenonprojectfiles>
-      <hidenonlocation>false</hidenonlocation>
     </groups>
     <tree>
@@ -184,5 +182,5 @@
     </codecompletion>
     <creategettersetter>
-      <prefixGet/>
+      <prefixGet></prefixGet>
       <prefixSet>set</prefixSet>
       <prefixVariable>m_,_</prefixVariable>
@@ -200,10 +198,10 @@
   <kdevdebugger>
     <general>
-      <programargs>~/08\ -\ Jimmy\ Jimmy.mpc</programargs>
-      <gdbpath/>
+      <programargs>--overwrite /home/nico/08\ -\ Jimmy\ Jimmy.wav</programargs>
+      <gdbpath></gdbpath>
       <dbgshell>libtool</dbgshell>
-      <configGdbScript/>
-      <runShellScript/>
-      <runGdbScript/>
+      <configGdbScript></configGdbScript>
+      <runShellScript></runShellScript>
+      <runGdbScript></runGdbScript>
       <breakonloadinglibs>true</breakonloadinglibs>
       <separatetty>false</separatetty>
Index: /libmpc/branches/r2d/libmpcenc/quant.c
===================================================================
--- /libmpc/branches/r2d/libmpcenc/quant.c	(revision 155)
+++ /libmpc/branches/r2d/libmpcenc/quant.c	(revision 156)
@@ -22,4 +22,5 @@
 #include "libmpcenc.h"
 #include <mpc/minimax.h>
+#include <mpc/mpcmath.h>
 
 /* V A R I A B L E S */
@@ -158,22 +159,21 @@
 {
     int    k;
-    float  fac    = A [res];
-    float  invfac = C [res];
-    float  Signal = 1.e-30f;
-    float  Fehler = 1.e-30f;
-    float  tmp ;
-    float  tmp2;
+    const float  fac    = A [res];
+	const float  invfac = C [res];
+    float  signal = 1.e-30f;
+    float  error = 1.e-30f;
+    float  sig, err;
 
     // Summation of the absolute power and the quadratic error
     for ( k = 0; k < 36; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-		tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
+        err = input[k] * NoiseInjectionCompensation1D [res];
+		sig = mpc_nearbyintf(err * fac) * invfac - err;
+
+        error += sig * sig;
+        signal += err * err;
     }
 
     // Utilization of SNRcomp only if SNR > 1 !!!
-    return Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
+    return signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
 }
 
@@ -185,45 +185,39 @@
     float  fac    = A [res];
     float  invfac = C [res];
-    float  Signal;
-    float  Fehler;
-    float  ret ;
-    float  tmp ;
-    float  tmp2;
+	float  signal, error, ret, sig, err;
 
     // Summation of the absolute power and the quadratic error
-    k = 0;
-    Signal = Fehler = 1.e-30f;
+	k = 0;
+	signal = error = 1.e-30f;
     for ( ; k < 12; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-		tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    ret = tmp;
-    Signal = Fehler = 1.e-30f;
+        err = input[k] * NoiseInjectionCompensation1D [res];
+		sig = mpc_nearbyintf(err * fac) * invfac - err;
+
+        error += sig * sig;
+        signal += err * err;
+    }
+    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
+    ret = sig;
+    signal = error = 1.e-30f;
     for ( ; k < 24; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-		tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    if ( tmp > ret ) ret = tmp;
-    //ret += tmp;
-    Signal = Fehler = 1.e-30f;
+        err = input[k] * NoiseInjectionCompensation1D [res];
+		sig = mpc_nearbyintf(err * fac) * invfac - err;
+
+        error += sig * sig;
+        signal += err * err;
+    }
+    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
+	ret = maxf(ret, sig);
+
+    signal = error = 1.e-30f;
     for ( ; k < 36; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-		tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    if ( tmp > ret ) ret = tmp;
-    //ret += tmp;
-    //ret *= 0.33333333333f;
+        err = input[k] * NoiseInjectionCompensation1D [res];
+		sig = mpc_nearbyintf(err * fac) * invfac - err;
+
+        error += sig * sig;
+        signal += err * err;
+    }
+    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
+	ret = maxf(ret, sig);
 
     return ret;
@@ -235,25 +229,24 @@
 QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder )
 {
-    int    n;
+	int    n, quant;
     int    offset  = D [res];
     float  mult    = A [res] * NoiseInjectionCompensation1D [res];
     float  invmult = C [res];
-    int    quant;
     float  signal;
 
-	for ( n = 0; n < 36 - maxNsOrder; n++, input++, qu_output++ ) {
-		quant = (unsigned int)(__builtin_lrintf(*input * mult) + offset);
+	for ( n = 0; n < 36 - maxNsOrder; n++) {
+		quant = (unsigned int)(mpc_lrintf(input[n] * mult) + offset);
 
         // limitation to 0...2D
-        if ((unsigned int)quant > (unsigned int)2*offset ) {
-            quant = mini ( quant, 2*offset );
-            quant = maxi ( quant,        0 );
+        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
+            quant = mini ( quant, offset * 2 );
+            quant = maxi ( quant, 0 );
         }
-        *qu_output  = quant;
-    }
-
-    for ( ; n < 36; n++, input++, qu_output++ ) {
-        signal = *input * mult;
-		quant = (unsigned int)(__builtin_lrintf(signal) + offset);
+        qu_output[n] = quant;
+    }
+
+    for ( ; n < 36; n++) {
+        signal = input[n] * mult;
+		quant = (unsigned int)(mpc_lrintf(signal) + offset);
 
         // calculate the current error and save it for error refeeding
@@ -261,9 +254,9 @@
 
         // limitation to 0...2D
-        if ((unsigned int)quant > (unsigned int)2*offset ) {
-            quant = mini ( quant, 2*offset );
-            quant = maxi ( quant,        0 );
+        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
+            quant = mini ( quant, offset * 2 );
+            quant = maxi ( quant, 0 );
         }
-        *qu_output  = quant;
+        qu_output[n] = quant;
     }
 }
@@ -274,18 +267,15 @@
 QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR )
 {
-#define E(x) *((int*)errors+(x))
-
     float  signal;
     float  mult    = A [res];
     float  invmult = C [res];
     int    offset  = D [res];
-    int    n;
-    int    quant;
-
-    E(0) = E(1) = E(2) = E(3) = E(4) = E(5) = 0;       // arghh, it produces pops on each frame boundary!
-
-    for ( n = 0; n < 36; n++, input++, qu_output++ ) {
-        signal = *input * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
-		quant = __builtin_lrintf(signal * mult);
+    int    n, quant;
+
+	memset(errors, 0, 6 * sizeof *errors);       // arghh, it produces pops on each frame boundary!
+
+    for ( n = 0; n < 36; n++) {
+        signal = input[n] * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
+		quant = mpc_lrintf(signal * mult);
 
         // calculate the current error and save it for error refeeding
@@ -296,5 +286,5 @@
         quant = maxf ( quant, -offset );
 
-        *qu_output = (unsigned int)(quant + offset);
+        qu_output[n] = (unsigned int)(quant + offset);
     }
 }
