Index: mppenc/branches/r2d/libmpcpsy/ans.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/ans.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/ans.c	(revision 60)
@@ -28,5 +28,8 @@
  */
 
-#include "mppenc.h"
+#include "libmpcpsy.h"
+
+#include <math.h>
+#include <string.h>
 
 
@@ -34,13 +37,4 @@
 static float  Cos_Tab    [16] [MAX_NS_ORDER + 1];
 static float  Sin_Tab    [16] [MAX_NS_ORDER + 1];
-unsigned int  NS_Order;                         // Maximum order for ANS
-unsigned int  NS_Order_L [32];
-unsigned int  NS_Order_R [32];                  // frame-wise order of the Noiseshaping (0: off, 1...5: on)
-float         FIR_L      [32] [MAX_NS_ORDER];
-float         FIR_R      [32] [MAX_NS_ORDER];   // contains FIR-Filter for NoiseShaping
-float         ANSspec_L  [MAX_ANS_LINES];
-float         ANSspec_R  [MAX_ANS_LINES];       // L/R-masking thresholds for ANS
-float         ANSspec_M  [MAX_ANS_LINES];
-float         ANSspec_S  [MAX_ANS_LINES];       // M/S-masking thresholds for ANS
 
 
@@ -184,5 +178,4 @@
     const float*  tmp;
 
-    ENTER(235);
     for ( Band = 0; Band <= MaxBand  &&  maxANSOrder[Band]; Band++ ) {
 
@@ -275,5 +268,4 @@
     }
 
-    LEAVE(235);
     return;
 }
@@ -282,22 +274,21 @@
 // perform ANS-analysis (calculation of FIR-filter and gain)
 void
-NS_Analyse ( const int             MaxBand,
+NS_Analyse ( PsyModel* m,
+			 const int             MaxBand,
              const unsigned char*  MSflag,
              const SMRTyp          smr,
              const int*            Transient )
 {
-    ENTER(10);
 
     // for L or M, respectively
-    memset ( FIR_L,      0, sizeof FIR_L      );         // reset FIR
-    memset ( NS_Order_L, 0, sizeof NS_Order_L );         // reset Flags
-    FindOptimalANS ( MaxBand, MSflag, ANSspec_L, ANSspec_M, NS_Order_L, SNR_comp_L, FIR_L, smr.L, smr.M, SCF_Index_L, Transient );
+    memset ( m->FIR_L,      0, sizeof m->FIR_L      );         // reset FIR
+    memset ( m->NS_Order_L, 0, sizeof m->NS_Order_L );         // reset Flags
+	FindOptimalANS ( MaxBand, MSflag, m->ANSspec_L, m->ANSspec_M, m->NS_Order_L, m->SNR_comp_L, m->FIR_L, smr.L, smr.M, m->SCF_Index_L, Transient );
 
     // for R or S, respectively
-    memset ( FIR_R,      0, sizeof FIR_R      );         // reset FIR
-    memset ( NS_Order_R, 0, sizeof NS_Order_R );         // reset Flags
-    FindOptimalANS ( MaxBand, MSflag, ANSspec_R, ANSspec_S, NS_Order_R, SNR_comp_R, FIR_R, smr.R, smr.S, SCF_Index_R, Transient );
-
-    LEAVE(10);
+	memset ( m->FIR_R,      0, sizeof m->FIR_R      );         // reset FIR
+	memset ( m->NS_Order_R, 0, sizeof m->NS_Order_R );         // reset Flags
+	FindOptimalANS ( MaxBand, MSflag, m->ANSspec_R, m->ANSspec_S, m->NS_Order_R, m->SNR_comp_R, m->FIR_R, smr.R, smr.S, m->SCF_Index_R, Transient );
+
     return;
 }
Index: mppenc/branches/r2d/libmpcpsy/cvd.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/cvd.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/cvd.c	(revision 60)
@@ -18,5 +18,9 @@
  */
 
-#include "mppenc.h"
+#include "libmpcpsy.h"
+
+#include <math.h>
+#include <string.h>
+
 
 /* C O N S T A N T S */
@@ -72,5 +76,6 @@
 // Analyze the Cepstrum, search for the basic harmonic
 static void
-CEP_Analyse2048 ( float* res1,
+CEP_Analyse2048 ( PsyModel* m,
+				  float* res1,
                   float* res2,
                   float* qual1,
@@ -163,5 +168,5 @@
         *res1 = line_sum / sum;
 
-    if ( CVD_used < 2 )
+    if ( m->CVD_used < 2 )
         return;
 
@@ -231,5 +236,5 @@
 // output: Array *vocal contains information if the FFT-Line is a harmonic component
 int
-CVD2048 ( const float* spec, int* vocal )
+CVD2048 ( PsyModel* m, const float* spec, int* vocal )
 {
     static float  cep [4096];     // cep[4096] -- array, which is also used for the 2048 FFT
@@ -241,5 +246,4 @@
     int           n;
 
-    ENTER(20);
     // Calculating logarithmated, windowed spectrum cep[]
     // cep[512...1024] = 0 -- cep[1025...2047] doesn't matter, because the first have to be filled by fft
@@ -255,13 +259,11 @@
 
     // search the harmonic
-    CEP_Analyse2048 ( &res1, &res2, &qual1, &qual2, cep );
+	CEP_Analyse2048 ( m, &res1, &res2, &qual1, &qual2, cep );
 //#include "cvd.h"
     if ( res1 > 0.f  ||  res2 > 0.f ) {
         if ( res1 > 0. ) SetVoiceLines ( vocal, res1, 100 );
         if ( res2 > 0. ) SetVoiceLines ( vocal, res2,  20 );
-        LEAVE(20);
         return 1;
     }
-    LEAVE(20);
     return 0;
 }
Index: mppenc/branches/r2d/libmpcpsy/fastmath.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fastmath.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/fastmath.c	(revision 60)
@@ -17,6 +17,4 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
-#include "mppenc.h"
 
 #ifdef FAST_MATH
Index: mppenc/branches/r2d/libmpcpsy/fastmath.h
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fastmath.h	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/fastmath.h	(revision 60)
@@ -17,4 +17,45 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
+
+// fast but maybe more inaccurate, use if you need speed
+#if defined(__GNUC__) && !defined(__APPLE__)
+#  define SIN(x)      sinf ((float)(x))
+#  define COS(x)      cosf ((float)(x))
+#  define ATAN2(x,y)  atan2f ((float)(x), (float)(y))
+#  define SQRT(x)     sqrtf ((float)(x))
+#  define LOG(x)      logf ((float)(x))
+#  define LOG10(x)    log10f ((float)(x))
+#  define POW(x,y)    expf (logf(x) * (y))
+#  define POW10(x)    expf (M_LN10 * (x))
+#  define FLOOR(x)    floorf ((float)(x))
+#  define IFLOOR(x)   (int) floorf ((float)(x))
+#  define FABS(x)     fabsf ((float)(x))
+#else
+# define SIN(x)      (float) sin (x)
+# define COS(x)      (float) cos (x)
+# define ATAN2(x,y)  (float) atan2 (x, y)
+# define SQRT(x)     (float) sqrt (x)
+# define LOG(x)      (float) log (x)
+# define LOG10(x)    (float) log10 (x)
+# define POW(x,y)    (float) pow (x,y)
+# define POW10(x)    (float) pow (10., (x))
+# define FLOOR(x)    (float) floor (x)
+# define IFLOOR(x)   (int)   floor (x)
+# define FABS(x)     (float) fabs (x)
+#endif
+
+#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))
+#else
+# undef  TABSTEP
+# define COSF(x)      COS (x)
+# define ATAN2F(x,y)  ATAN2 (x,y)
+# define IFLOORF(x)   IFLOOR (x)
+#endif
 
 #if 1
Index: mppenc/branches/r2d/libmpcpsy/fft4g.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 60)
@@ -18,5 +18,5 @@
  */
 
-#include "mppenc.h"
+#include "libmpcpsy.h"
 
 /* F U N C T I O N S */
@@ -57,5 +57,4 @@
     float  xi;
 
-    ENTER(30);
     if ( n > 4) {
         bitrv2  ( n, ip + 2, a );
@@ -69,5 +68,4 @@
     a[0] += a[1];
     a[1]  = xi;
-    LEAVE(30);
     return;
 }
@@ -84,5 +82,4 @@
     double  delta;
 
-    ENTER(31);
     ip[0] = nw;
     ip[1] = 1;
@@ -106,5 +103,4 @@
         }
     }
-    LEAVE(31);
     return;
 }
@@ -118,5 +114,4 @@
     double  delta;
 
-    ENTER(32);
     ip[1] = nc;
     if ( nc > 1 ) {
@@ -130,5 +125,4 @@
         }
     }
-    LEAVE(32);
     return;
 }
@@ -142,5 +136,4 @@
     float  xr, xi, yr, yi;
 
-    ENTER(33);
     ip[0] = 0;
     l     = n;
@@ -235,5 +228,4 @@
         }
     }
-    LEAVE(33);
     return;
 }
@@ -246,5 +238,4 @@
     float  x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
 
-    ENTER(34);
     l = 2;
     if ( n > 8 ) {
@@ -291,5 +282,4 @@
         } while ( j += 2, j < l );
     }
-    LEAVE(34);
     return;
 }
@@ -303,5 +293,4 @@
     float  x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
 
-    ENTER(35);
     x0r   = a[ 0] + a[ 2];
     x0i   = a[ 1] + a[ 3];
@@ -401,10 +390,9 @@
         a[j + 15] = wk3r * x0i + wk3i * x0r;
     } while ( j += 16, j < n );
-    LEAVE(35);
-    return;
-}
-
-extern void Cdecl cftmdl_3DNow_1 ( const int n, const int l, float* a, float* w );
-extern void Cdecl cftmdl_3DNow_2 ( const int n, const int l, float* a, float* w );
+    return;
+}
+
+// extern void Cdecl cftmdl_3DNow_1 ( const int n, const int l, float* a, float* w );
+// extern void Cdecl cftmdl_3DNow_2 ( const int n, const int l, float* a, float* w );
 
 
@@ -416,5 +404,4 @@
     float  x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
 
-    ENTER(36);
     m = l << 2;
 
@@ -467,7 +454,5 @@
         a[j3 + 1] = wk1r * (x0i + x0r);
     }
-    LEAVE(36);
-
-    ENTER(39);
+
     k1 = 0;
     m2 = 2 * m;
@@ -542,97 +527,92 @@
         } while ( j += 2, j < l+k+m );
     }
-    LEAVE(39);
-    return;
-}
-
-
-static void
-cftmdl_3DNow ( const int n, const int l, float* a, float* w )
-{
-    int    j, j1, j2, j3, k, k1, m, m2;
-    float  wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
-    float  x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
-
-    ENTER(36);
-    cftmdl_3DNow_1 (n,l,a,w);
-    LEAVE(36);
-
-    ENTER(39);
-    m  = l << 2;
-    k1 = 0;
-    m2 = 2 * m;
-    for ( k = m2; k < n; k += m2 ) {
-        k1  += 2;
-        wk2r = w[k1];
-        wk2i = w[k1 + 1];
-        wk1r = w[2*k1];
-        wk1i = w[2*k1 + 1];
-        wk3r = wk1r - 2 * wk2i * wk1i;
-        wk3i = 2 * wk2i * wk1r - wk1i;
-        j    = k;
-        do {
-            j1        = j  + l;
-            j2        = j1 + l;
-            j3        = j2 + l;
-            x0r       = a[j]      + a[j1];
-            x0i       = a[j + 1]  + a[j1 + 1];
-            x1r       = a[j]      - a[j1];
-            x1i       = a[j + 1]  - a[j1 + 1];
-            x2r       = a[j2]     + a[j3];
-            x2i       = a[j2 + 1] + a[j3 + 1];
-            x3r       = a[j2]     - a[j3];
-            x3i       = a[j2 + 1] - a[j3 + 1];
-            a[j]      = x0r + x2r;
-            a[j + 1]  = x0i + x2i;
-            x0r      -= x2r;
-            x0i      -= x2i;
-            a[j2]     = wk2r * x0r - wk2i * x0i;
-            a[j2 + 1] = wk2r * x0i + wk2i * x0r;
-            x0r       = x1r - x3i;
-            x0i       = x1i + x3r;
-            a[j1]     = wk1r * x0r - wk1i * x0i;
-            a[j1 + 1] = wk1r * x0i + wk1i * x0r;
-            x0r       = x1r + x3i;
-            x0i       = x1i - x3r;
-            a[j3]     = wk3r * x0r - wk3i * x0i;
-            a[j3 + 1] = wk3r * x0i + wk3i * x0r;
-        } while ( j += 2, j < l + k );
-
-        wk1r = w[2*k1 + 2];
-        wk1i = w[2*k1 + 3];
-        wk3r = wk1r - 2 * wk2r * wk1i;
-        wk3i = 2 * wk2r * wk1r - wk1i;
-        j    = k + m;
-        do {
-            j1        = j + l;
-            j2        = j1 + l;
-            j3        = j2 + l;
-            x0r       = a[j]      + a[j1];
-            x0i       = a[j + 1]  + a[j1 + 1];
-            x1r       = a[j]      - a[j1];
-            x1i       = a[j + 1]  - a[j1 + 1];
-            x2r       = a[j2]     + a[j3];
-            x2i       = a[j2 + 1] + a[j3 + 1];
-            x3r       = a[j2]     - a[j3];
-            x3i       = a[j2 + 1] - a[j3 + 1];
-            a[j]      = x0r + x2r;
-            a[j + 1]  = x0i + x2i;
-            x0r      -= x2r;
-            x0i      -= x2i;
-            a[j2]     = -wk2i * x0r - wk2r * x0i;
-            a[j2 + 1] = -wk2i * x0i + wk2r * x0r;
-            x0r       = x1r - x3i;
-            x0i       = x1i + x3r;
-            a[j1]     = wk1r * x0r - wk1i * x0i;
-            a[j1 + 1] = wk1r * x0i + wk1i * x0r;
-            x0r       = x1r + x3i;
-            x0i       = x1i - x3r;
-            a[j3]     = wk3r * x0r - wk3i * x0i;
-            a[j3 + 1] = wk3r * x0i + wk3i * x0r;
-        } while ( j += 2, j < l+k+m );
-    }
-    LEAVE(39);
-    return;
-}
+    return;
+}
+
+
+// static void
+// cftmdl_3DNow ( const int n, const int l, float* a, float* w )
+// {
+//     int    j, j1, j2, j3, k, k1, m, m2;
+//     float  wk1r, wk1i, wk2r, wk2i, wk3r, wk3i;
+//     float  x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+//
+//     cftmdl_3DNow_1 (n,l,a,w);
+//
+//     m  = l << 2;
+//     k1 = 0;
+//     m2 = 2 * m;
+//     for ( k = m2; k < n; k += m2 ) {
+//         k1  += 2;
+//         wk2r = w[k1];
+//         wk2i = w[k1 + 1];
+//         wk1r = w[2*k1];
+//         wk1i = w[2*k1 + 1];
+//         wk3r = wk1r - 2 * wk2i * wk1i;
+//         wk3i = 2 * wk2i * wk1r - wk1i;
+//         j    = k;
+//         do {
+//             j1        = j  + l;
+//             j2        = j1 + l;
+//             j3        = j2 + l;
+//             x0r       = a[j]      + a[j1];
+//             x0i       = a[j + 1]  + a[j1 + 1];
+//             x1r       = a[j]      - a[j1];
+//             x1i       = a[j + 1]  - a[j1 + 1];
+//             x2r       = a[j2]     + a[j3];
+//             x2i       = a[j2 + 1] + a[j3 + 1];
+//             x3r       = a[j2]     - a[j3];
+//             x3i       = a[j2 + 1] - a[j3 + 1];
+//             a[j]      = x0r + x2r;
+//             a[j + 1]  = x0i + x2i;
+//             x0r      -= x2r;
+//             x0i      -= x2i;
+//             a[j2]     = wk2r * x0r - wk2i * x0i;
+//             a[j2 + 1] = wk2r * x0i + wk2i * x0r;
+//             x0r       = x1r - x3i;
+//             x0i       = x1i + x3r;
+//             a[j1]     = wk1r * x0r - wk1i * x0i;
+//             a[j1 + 1] = wk1r * x0i + wk1i * x0r;
+//             x0r       = x1r + x3i;
+//             x0i       = x1i - x3r;
+//             a[j3]     = wk3r * x0r - wk3i * x0i;
+//             a[j3 + 1] = wk3r * x0i + wk3i * x0r;
+//         } while ( j += 2, j < l + k );
+//
+//         wk1r = w[2*k1 + 2];
+//         wk1i = w[2*k1 + 3];
+//         wk3r = wk1r - 2 * wk2r * wk1i;
+//         wk3i = 2 * wk2r * wk1r - wk1i;
+//         j    = k + m;
+//         do {
+//             j1        = j + l;
+//             j2        = j1 + l;
+//             j3        = j2 + l;
+//             x0r       = a[j]      + a[j1];
+//             x0i       = a[j + 1]  + a[j1 + 1];
+//             x1r       = a[j]      - a[j1];
+//             x1i       = a[j + 1]  - a[j1 + 1];
+//             x2r       = a[j2]     + a[j3];
+//             x2i       = a[j2 + 1] + a[j3 + 1];
+//             x3r       = a[j2]     - a[j3];
+//             x3i       = a[j2 + 1] - a[j3 + 1];
+//             a[j]      = x0r + x2r;
+//             a[j + 1]  = x0i + x2i;
+//             x0r      -= x2r;
+//             x0i      -= x2i;
+//             a[j2]     = -wk2i * x0r - wk2r * x0i;
+//             a[j2 + 1] = -wk2i * x0i + wk2r * x0r;
+//             x0r       = x1r - x3i;
+//             x0i       = x1i + x3r;
+//             a[j1]     = wk1r * x0r - wk1i * x0i;
+//             a[j1 + 1] = wk1r * x0i + wk1i * x0r;
+//             x0r       = x1r + x3i;
+//             x0i       = x1i - x3r;
+//             a[j3]     = wk3r * x0r - wk3i * x0i;
+//             a[j3 + 1] = wk3r * x0i + wk3i * x0r;
+//         } while ( j += 2, j < l+k+m );
+//     }
+//     return;
+// }
 
 
@@ -643,5 +623,4 @@
     float  wkr, wki, xr, xi, yr, yi;
 
-    ENTER(37);
     m  = n >> 1;
     ks = 2 * nc / m;
@@ -664,5 +643,4 @@
         kk       += ks;
     } while ( j += 2, j < m );
-    LEAVE(37);
     return;
 }
Index: mppenc/branches/r2d/libmpcpsy/fft_routines.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fft_routines.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/fft_routines.c	(revision 60)
@@ -18,5 +18,8 @@
  */
 
-#include "mppenc.h"
+#include "libmpcpsy.h"
+
+#include <math.h>
+#include <string.h>
 
 #define CX0     -1.
@@ -196,5 +199,4 @@
     int           i;
 
-    ENTER(40);
     // windowing
     i = 256;
@@ -212,5 +214,4 @@
         aix += 2;
     }
-    LEAVE(40);
 }
 
@@ -224,5 +225,4 @@
     int           i;
 
-    ENTER(41);
     i = 1024;                   // windowing
     while (i--)
@@ -246,5 +246,4 @@
         aix += 2;
     }
-    LEAVE(41);
 }
 
@@ -258,5 +257,4 @@
     int           i;
 
-    ENTER(42);
     // windowing (only 1600 samples available -> centered in 2048!)
     memset ( a     , 0, 224*sizeof(*a) );
@@ -275,5 +273,4 @@
         aix += 2;
     }
-    LEAVE(42);
 }
 
@@ -289,5 +286,4 @@
     int           i;
 
-    ENTER(43);
     i = 1024;                   // windowing
     while (i--)
@@ -304,5 +300,4 @@
         aix += 2;
     }
-    LEAVE(43);
 }
 
@@ -316,5 +311,4 @@
     int     i;
 
-    ENTER(44);
     // generate real, even spectrum (symmetric around 1024, cep[2048-i] = cep[i])
     for ( i = 0; i < 1024; i++ )
@@ -334,4 +328,3 @@
         bix += 2;
     }
-    LEAVE(44);
-}
+}
Index: mppenc/branches/r2d/libmpcpsy/libmpcpsy.h
===================================================================
--- mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 60)
+++ mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 60)
@@ -0,0 +1,164 @@
+/*
+ * Musepack audio compression
+ *
+ * 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
+ */
+
+// psy_tab.h
+#define PART_LONG          57                   // number of partitions for long
+#define PART_SHORT     (PART_LONG / 3)          // number of partitions for short
+#define MAX_SPL            20                   // maximum assumed Sound Pressure Level
+
+// psy.c
+#define SHORTFFT_OFFSET   168                   // fft-offset for short FFT's
+#define PREFAC_LONG        10                   // preecho-factor for long partitions
+
+
+#define MAX_CVD_LINE      300                   // maximum FFT-Index for CVD
+#define CVD_UNPRED          0.040f              // unpredictability (cw) for CVD-detected bins, e33 (04)
+#define MIN_ANALYZED_IDX   12                   // maximum base-frequency = 44100/MIN_ANALYZED_IDX ^^^^^^
+#define MED_ANALYZED_IDX   50                   // maximum base-frequency = 44100/MED_ANALYZED_IDX ^^^^^^
+#define MAX_ANALYZED_IDX  900                   // minimum base-frequency = 44100/MAX_ANALYZED_IDX  (816 for Amnesia)
+
+
+#define MAX_NS_ORDER        6                   // maximum order of the Adaptive Noise Shaping Filter (IIR)
+#define MAX_ANS_BANDS      16
+#define MAX_ANS_LINES    (32 * MAX_ANS_BANDS)   // maximum number of noiseshaped FFT-lines
+///////// 16 * MAX_ANS_BANDS not sufficient? //////////////////
+#define MS2SPAT1             0.5f
+#define MS2SPAT2             0.25f
+#define MS2SPAT3             0.125f
+#define MS2SPAT4             0.0625f
+
+// common ?
+#ifndef M_PI
+# define M_PI            3.1415926535897932384626433832795029     // 4*atan(1)
+# define M_PIl           3.1415926535897932384626433832795029L
+# define M_LN2           0.6931471805599453094172321214581766     // ln(2)
+# define M_LN2l          0.6931471805599453094172321214581766L
+# define M_LN10          2.3025850929940456840179914546843642     // ln 10 */
+# define M_LN10l         2.3025850929940456840179914546843642L
+#endif
+
+// mppenc.h
+#define CENTER            448                   // offset for centering current data in Main-array
+#define BLOCK            1152                   // blocksize
+#define ANABUFFER    (BLOCK + CENTER)           // size of PCM-data array for analysis
+
+
+#define KBD1	2.
+#define KBD2	-1.
+
+typedef struct {
+    float  L [32];
+	float  R [32];
+	float  M [32];
+	float  S [32];
+} SMRTyp;
+
+typedef struct {
+	float  L [36];
+	float  R [36];
+} SubbandFloatTyp;
+
+typedef struct {
+	float  L [ANABUFFER];
+	float  R [ANABUFFER];
+	float  M [ANABUFFER];
+	float  S [ANABUFFER];
+} PCMDataTyp;
+
+typedef struct {
+	int           Max_Band;                    // maximum bandwidth
+	float         SampleFreq;
+	float         Bandwidth;
+
+	/* further switches for the psymodel */
+	unsigned int  CVD_used;         // global flag for ClearVoiceDetection
+	float         varLtq;           // variable threshold in quiet
+	unsigned int  tmpMask_used;     // global flag for temporal masking
+	float         ShortThr;         // Factor to calculate the masking threshold with transients
+	float         minSMR;           // minimum SMR for all subbands
+
+	unsigned int  MS_Channelmode;
+
+	float         a          [PART_LONG];
+	float         b          [PART_LONG];
+	float         c          [PART_LONG];
+	float         d          [PART_LONG];           // Integrations for tmpMask
+	float         T_L        [PART_LONG];
+	float         T_R        [PART_LONG];           // time-constants for tmpMask
+	float         pre_erg_L[2][PART_SHORT];
+	float         pre_erg_R[2][PART_SHORT];          // Preecho-control short
+	float         PreThr_L   [PART_LONG];
+	float         PreThr_R   [PART_LONG];           // for Pre-Echo-control L/R
+	float         tmp_Mask_L [PART_LONG];
+	float         tmp_Mask_R [PART_LONG];           // for Post-Masking L/R
+	int           Vocal_L    [MAX_CVD_LINE + 4];
+	int           Vocal_R    [MAX_CVD_LINE + 4];    // FFT-Line belongs to harmonic?
+
+	/* V A R I A B L E S */
+	float  MinVal   [PART_LONG];               // contains minimum tonality soffsets
+	float  Loudness [PART_LONG];               // weighting factors for loudness calculation
+	float  SPRD     [PART_LONG] [PART_LONG];   // tabulated spreading function
+	float  O_MAX;
+	float  O_MIN;
+	float  FAC1;
+	float  FAC2;                               // constants for offset calculation
+	float  partLtq  [PART_LONG];               // threshold in quiet (partitions)
+	float  invLtq   [PART_LONG];               // inverse threshold in quiet (partitions, long)
+	float  fftLtq   [512];                     // threshold in quiet (FFT)
+	float  Ltq_offset;                         // Offset for threshold in quiet
+	float  Ltq_max;                            // maximum level for threshold in quiet
+	float  TMN;
+	float  NMT;
+	float  TransDetect;
+	unsigned int    EarModelFlag;
+	int    MinValChoice;
+
+	// ans.h
+	unsigned int  NS_Order;                         // Maximum order for ANS
+	unsigned int  NS_Order_L [32];
+	unsigned int  NS_Order_R [32];                  // frame-wise order of the Noiseshaping (0: off, 1...5: on)
+	float         FIR_L      [32] [MAX_NS_ORDER];
+	float         FIR_R      [32] [MAX_NS_ORDER];   // contains FIR-Filter for NoiseShaping
+	float         ANSspec_L  [MAX_ANS_LINES];
+	float         ANSspec_R  [MAX_ANS_LINES];       // L/R-masking thresholds for ANS
+	float         ANSspec_M  [MAX_ANS_LINES];
+	float         ANSspec_S  [MAX_ANS_LINES];       // M/S-masking thresholds for ANS
+	float         SNR_comp_L [32];
+	float         SNR_comp_R [32];             // SNR-compensation after SCF-combination and ANS-gain
+
+	// FIXME : remove this :
+	int            SCF_Index_L [32] [3];
+	int            SCF_Index_R [32] [3];              // Scalefactor-index for Bitstream
+
+} PsyModel;
+
+
+// w_low for long               0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56
+const int   wl [PART_LONG] = {  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  13,  15,  17,  19,  21,  23,  25,  27,  29,  31,  33,  35,  38,  41,  44,  47,  50,  54,  58,  62,  67,  72,  78,  84,  91,  98, 106, 115, 124, 134, 145, 157, 170, 184, 199, 216, 234, 254, 276, 301, 329, 360, 396, 437, 485 };
+const int   wh [PART_LONG] = {  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  12,  14,  16,  18,  20,  22,  24,  26,  28,  30,  32,  34,  37,  40,  43,  46,  49,  53,  57,  61,  66,  71,  77,  83,  90,  97, 105, 114, 123, 133, 144, 156, 169, 183, 198, 215, 233, 253, 275, 300, 328, 359, 395, 436, 484, 511 };
+// Width:                       1    1    1    1    1    1    1    1    1    1    1    2    2    2    2    2    2    2    2    2    2    2    2    3    3    3    3    3    4    4    4    5    5    6    6    7    7    8    9    9   10   11   12   13   14   15   17   18   20   22   25   28   31   36   41   48   27
+
+// inverse partition-width for long
+const float iw [PART_LONG] = { 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/4, 1.f/4, 1.f/4, 1.f/5, 1.f/5, 1.f/6, 1.f/6, 1.f/7, 1.f/7, 1.f/8, 1.f/9, 1.f/9, 1.f/10, 1.f/11, 1.f/12, 1.f/13, 1.f/14, 1.f/15, 1.f/17, 1.f/18, 1.f/20, 1.f/22, 1.f/25, 1.f/28, 1.f/31, 1.f/36, 1.f/41, 1.f/48, 1.f/27 };
+
+// w_low for short                    0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17   18
+const int   wl_short [PART_SHORT] = { 0,  1,  2,  3,  4,  5,  6,  8, 10, 12, 15, 18, 23, 29, 36, 46, 59, 75,  99 };
+const int   wh_short [PART_SHORT] = { 0,  1,  2,  3,  5,  6,  7,  9, 12, 14, 18, 23, 29, 36, 46, 58, 75, 99, 127 };
+
+// inverse partition-width for short
+const float iw_short [PART_SHORT] = { 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/4, 1.f/6, 1.f/7, 1.f/8, 1.f/11, 1.f/13, 1.f/17, 1.f/25, 1.f/29 };
Index: mppenc/branches/r2d/libmpcpsy/psy.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/psy.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/psy.c	(revision 60)
@@ -51,41 +51,40 @@
  */
 
-#include "mppenc.h"
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "libmpcpsy.h"
+#include "fastmath.h"
+
+
+// Antialiasing for calculation of the subband power
+const float  Butfly    [7] = { 0.5f, 0.2776f, 0.1176f, 0.0361f, 0.0075f, 0.000948f, 0.0000598f };
+
+// Antialiasing for calculation of the masking thresholds
+const float  InvButfly [7] = { 2.f, 3.6023f, 8.5034f, 27.701f, 133.33f, 1054.852f, 16722.408f };
 
 /* V A R I A B L E S */
-/* further switches for the psymodel */
-unsigned int  CVD_used;         // global flag for ClearVoiceDetection
-float         varLtq;           // variable threshold in quiet
-unsigned int  tmpMask_used;     // global flag for temporal masking
-float         ShortThr;         // Factor to calculate the masking threshold with transients
-float         minSMR;           // minimum SMR for all subbands
-
-float         a          [PART_LONG];
-float         b          [PART_LONG];
-float         c          [PART_LONG];
-float         d          [PART_LONG];           // Integrations for tmpMask
+
 static float  Xsave_L    [3 * 512];
 static float  Xsave_R    [3 * 512];             // FFT-Amplitudes L/R
 static float  Ysave_L    [3 * 512];
 static float  Ysave_R    [3 * 512];             // FFT-Phases L/R
-float         T_L        [PART_LONG];
-float         T_R        [PART_LONG];           // time-constants for tmpMask
-float         pre_erg_L[2][PART_SHORT];
-float         pre_erg_R[2][PART_SHORT];          // Preecho-control short
-float         PreThr_L   [PART_LONG];
-float         PreThr_R   [PART_LONG];           // for Pre-Echo-control L/R
-float         tmp_Mask_L [PART_LONG];
-float         tmp_Mask_R [PART_LONG];           // for Post-Masking L/R
-int           Vocal_L    [MAX_CVD_LINE + 4];
-int           Vocal_R    [MAX_CVD_LINE + 4];    // FFT-Line belongs to harmonic?
 
 /* F U N C T I O N S */
+
+// fft_routines.c
+void   Init_FFT      ( void );
+void   PowSpec256    ( const float*, float* );
+void   PowSpec1024   ( const float*, float* );
+void   PowSpec2048   ( const float*, float* );
+void   PolarSpec1024 ( const float*, float*, float* );
+void   Cepstrum2048  ( float* cep, const int );
+
 // Resets Arrays
-void
-Init_Psychoakustik ( void )
+void Init_Psychoakustik ( PsyModel* m)
 {
     int  i;
 
-    ENTER(200);
     // generate FFT lookup-tables with largest FFT-size of 1024
     Init_FFT ();
@@ -93,25 +92,27 @@
     // setting pre-echo variables to Ltq
     for ( i = 0; i < PART_LONG; i++ ) {
-        pre_erg_L  [0][i/3] = pre_erg_R  [0][i/3] =
-        pre_erg_L  [1][i/3] = pre_erg_R  [1][i/3] =
-        tmp_Mask_L [i]   = tmp_Mask_R [i]   =
-        PreThr_L   [i]   = PreThr_R   [i]   = partLtq [i];
+		m->pre_erg_L  [0][i/3] = m->pre_erg_R  [0][i/3] =
+				m->pre_erg_L  [1][i/3] = m->pre_erg_R  [1][i/3] =
+				m->tmp_Mask_L [i]   = m->tmp_Mask_R [i]   =
+				m->PreThr_L   [i]   = m->PreThr_R   [i]   = m->partLtq [i];
     }
 
     // initializing arrays with zero
-    memset ( Xsave_L,   0, sizeof Xsave_L );
-    memset ( Xsave_R,   0, sizeof Xsave_R );
-    memset ( Ysave_L,   0, sizeof Ysave_L );
-    memset ( Ysave_R,   0, sizeof Ysave_R );
-    memset ( a,         0, sizeof a       );
-    memset ( b,         0, sizeof b       );
-    memset ( c,         0, sizeof c       );
-    memset ( d,         0, sizeof d       );
-    memset ( T_L,       0, sizeof T_L     );
-    memset ( T_R,       0, sizeof T_R     );
-    memset ( Vocal_L,   0, sizeof Vocal_L );
-    memset ( Vocal_R,   0, sizeof Vocal_R );
-
-    LEAVE(200);
+	memset ( Xsave_L,   0, sizeof Xsave_L );
+	memset ( Xsave_R,   0, sizeof Xsave_R );
+	memset ( Ysave_L,   0, sizeof Ysave_L );
+	memset ( Ysave_R,   0, sizeof Ysave_R );
+	memset ( m->a,         0, sizeof m->a       );
+	memset ( m->b,         0, sizeof m->b       );
+	memset ( m->c,         0, sizeof m->c       );
+	memset ( m->d,         0, sizeof m->d       );
+	memset ( m->T_L,       0, sizeof m->T_L     );
+	memset ( m->T_R,       0, sizeof m->T_R     );
+	memset ( m->Vocal_L,   0, sizeof m->Vocal_L );
+	memset ( m->Vocal_R,   0, sizeof m->Vocal_R );
+
+	m->SampleFreq = 0.;
+	m->Bandwidth = 0.;
+
     return;
 }
@@ -134,10 +135,8 @@
 
 
-void
-RaiseSMR ( const int MaxBand, SMRTyp* smr )
-{
-    float  tmp = POW10 ( 0.1 * minSMR );
-
-    ENTER(201);
+void RaiseSMR (PsyModel* m, const int MaxBand, SMRTyp* smr )
+{
+    float  tmp = POW10 ( 0.1 * m->minSMR );
+
     RaiseSMR_Signal ( MaxBand, smr->L, tmp );
     RaiseSMR_Signal ( MaxBand, smr->R, tmp );
@@ -145,5 +144,4 @@
     RaiseSMR_Signal ( MaxBand, smr->S, 0.5 * tmp );
 
-    LEAVE(201);
     return;
 }
@@ -166,5 +164,4 @@
     float*  r;
 
-    ENTER(202);
 
     for ( Band = 0; Band <= MaxBand; Band++ ) {        // calculate perceptual entropy
@@ -197,5 +194,4 @@
     }
 
-    LEAVE(202);
     return;
 }
@@ -203,5 +199,5 @@
 // input : FFT-spectrums *spec0 und *spec1
 // output: energy in the individual subbands *erg0 and *erg1
-// With Butfly[], you can calculate the results of aliasing during calculation 
+// With Butfly[], you can calculate the results of aliasing during calculation
 // of subband energy from the FFT-spectrums.
 static void
@@ -218,5 +214,4 @@
     float  tmp1;
 
-    ENTER(203);
 
     // Is this here correct for FFT-based data or is this calculation rule only for MDCTs???
@@ -244,5 +239,4 @@
     }
 
-    LEAVE(203);
     return;
 }
@@ -261,5 +255,4 @@
     float         e1;
 
-    ENTER(204);
 
 #if 000000
@@ -314,8 +307,6 @@
     }
 
-
 #endif
 
-    LEAVE(204);
     return;
 }
@@ -337,5 +328,4 @@
     float         e1;
 
-    ENTER(205);
 
 #if 000000
@@ -391,5 +381,4 @@
 #endif
 
-    LEAVE(205);
     return;
 }
@@ -413,5 +402,4 @@
     float         tmp1;
 
-    ENTER(206);
 
     // should be able to optimize it with coasting.  [ 9 ] + n * [ 7 + 7 + 2 ] + [ 7 ]
@@ -440,9 +428,7 @@
     }
 
-    LEAVE(206);
-    return;
-}
-
-#include "fastmath.h"
+    return;
+}
+
 
 // input : current spectrum in the form of power *spec and phase *phase,
@@ -452,11 +438,12 @@
 // output: current amplitude *amp and unpredictability *cw
 static void
-CalcUnpred ( const int     MaxLine,
-             const float*  spec,
-             const float*  phase,
-             const int*    vocal,
-             float*        amp0,
-             float*        phs0,
-             float*        cw )
+CalcUnpred (PsyModel* m,
+			const int     MaxLine,
+			const float*  spec,
+			const float*  phase,
+			const int*    vocal,
+			float*        amp0,
+			float*        phs0,
+			float*        cw )
 {
     int     n;
@@ -468,5 +455,4 @@
 #define phs2  ((phs0) + 1024)           // phs[1024...1535] contains data of frame-2
 
-    ENTER(207);
 
     for ( n = 0; n < MaxLine; n++ ) {
@@ -480,5 +466,5 @@
 
     // postprocessing of harmonic FFT-lines (*cw is set to CVD_UNPRED)
-    if ( CVD_used  &&  vocal != NULL ) {
+	if ( m->CVD_used  &&  vocal != NULL ) {
         for ( n = 0; n < MAX_CVD_LINE; n++, cw++, vocal++ )
             if ( *vocal != 0  &&  *cw > CVD_UNPRED * 0.01 * *vocal )
@@ -486,5 +472,4 @@
     }
 
-    LEAVE(207);
     return;
 }
@@ -499,5 +484,6 @@
 // SPRD describes the spreading function as calculated in psy_tab.c
 static void
-SpreadingSignal ( const float* erg, const float* werg, float* res, float* wres )
+SpreadingSignal ( PsyModel* m, const float* erg, const float* werg, float* res,
+				  float* wres )
 {
     int           n;
@@ -509,10 +495,9 @@
     float         ew;
 
-    ENTER(208);
 
     for (k=0; k<PART_LONG; ++k, ++erg, ++werg) { // Source (masking partition)
         start = maxi(k-5, 0);           // minimum affected partition
         stop  = mini(k+7, PART_LONG-1); // maximum affected partition
-        sprd  = SPRD[k] + start;         // load vector
+        sprd  = m->SPRD[k] + start;         // load vector
         e     = *erg;
         ew    = *werg;
@@ -524,5 +509,4 @@
     }
 
-    LEAVE(208);
     return;
 }
@@ -531,5 +515,5 @@
 // output: masking threshold *erg after applying the tonality-offset
 static void
-ApplyTonalityOffset ( float* erg0, float* erg1, const float* werg0, const float* werg1 )
+ApplyTonalityOffset ( PsyModel* m, float* erg0, float* erg1, const float* werg0, const float* werg1 )
 {
     int    n;
@@ -537,22 +521,20 @@
     float  quot;
 
-    ENTER(230);
 
     // calculation of the masked threshold in the partition range
     for ( n = 0; n < PART_LONG; n++ ) {
         quot = *werg0++ / *erg0;
-        if      (quot <= 0.05737540597f) Offset = O_MAX;
-        else if (quot <  0.5871011603f ) Offset = FAC1 * POW (quot, FAC2);
-        else                             Offset = O_MIN;
-        *erg0++ *= iw[n] * minf(MinVal[n], Offset);
+        if      (quot <= 0.05737540597f) Offset = m->O_MAX;
+        else if (quot <  0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);
+        else                             Offset = m->O_MIN;
+        *erg0++ *= iw[n] * minf(m->MinVal[n], Offset);
 
         quot = *werg1++ / *erg1;
-        if      (quot <= 0.05737540597f) Offset = O_MAX;
-        else if (quot <  0.5871011603f ) Offset = FAC1 * POW (quot, FAC2);
-        else                             Offset = O_MIN;
-        *erg1++ *= iw[n] * minf(MinVal[n], Offset);
-    }
-
-    LEAVE(230);
+        if      (quot <= 0.05737540597f) Offset = m->O_MAX;
+        else if (quot <  0.5871011603f ) Offset = m->FAC1 * POW (quot, m->FAC2);
+        else                             Offset = m->O_MIN;
+		*erg1++ *= iw[n] * minf(m->MinVal[n], Offset);
+    }
+
     return;
 }
@@ -561,8 +543,8 @@
 // output: tracked loudness *loud, adapted threshold in quiet <Return value>
 static float
-AdaptLtq ( const float* erg0, const float* erg1 )
+AdaptLtq ( PsyModel* m, const float* erg0, const float* erg1 )
 {
     static float  loud   = 0.f;
-    float*        weight = Loudness;
+	float*        weight = m->Loudness;
     float         sum    = 0.f;
     int           n;
@@ -577,5 +559,5 @@
 
     // calculate dynamic offset for threshold in quiet, 0...+20 dB, at 96 dB loudness, an offset of 20 dB is assumed
-    return 1.f + varLtq * loud * 5.023772e-08f;
+    return 1.f + m->varLtq * loud * 5.023772e-08f;
 }
 
@@ -585,15 +567,14 @@
 // output: tracked Integrations *a and *b, time constant *tau
 static void
-CalcTemporalThreshold ( float* a, float* b, float* tau, float* frqthr, float* tmpthr )
+CalcTemporalThreshold ( PsyModel* m, float* a, float* b, float* tau, float* frqthr, float* tmpthr )
 {
     int    n;
     float  tmp;
 
-    ENTER(220);
 
     for ( n = 0; n < PART_LONG; n++ ) {
         // following calculations relative to threshold in quiet
-        frqthr[n] *= invLtq[n];
-        tmpthr[n] *= invLtq[n];
+        frqthr[n] *= m->invLtq[n];
+		tmpthr[n] *= m->invLtq[n];
 
         // new post-masking 'tmp' via time constant tau, if old post-masking  > Ltq (=1)
@@ -608,8 +589,7 @@
 
         // use post-masking of (Re-Normalization)
-        tmpthr[n] = maxf (frqthr[n], tmp) * partLtq[n];
-    }
-
-    LEAVE(220);
+		tmpthr[n] = maxf (frqthr[n], tmp) * m->partLtq[n];
+    }
+
     return;
 }
@@ -620,5 +600,6 @@
 // output: M/S-Masking thresholds in Partitions *thrM, *thrS
 static void
-CalcMSThreshold ( const float*  const ergL,
+CalcMSThreshold ( PsyModel* m,
+				  const float*  const ergL,
                   const float*  const ergR,
                   const float*  const ergM,
@@ -640,5 +621,5 @@
         thrS[n] = thrM[n] = maxf (ergM[n], ergS[n]) / maxf (ergL[n], ergR[n]) * minf (thrL[n], thrR[n]);
 
-        switch ( MS_Channelmode ) { // preserve 'near-mid' signal components
+        switch ( m->MS_Channelmode ) { // preserve 'near-mid' signal components
         case 3:
             if ( n > 0 ) {
@@ -760,9 +741,9 @@
                     tmp = ergS[n] * norm;
                     if ( thrS[n] > tmp )
-                        thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025);              // +/- 1.414°
+                        thrS[n] = maxf (tmp, ergM[n]*iw[n]*0.025);              // +/- 1.414
                 } else if ( ergS[n] > ergM[n] ) {
                     tmp = ergM[n] * norm;
                     if ( thrM[n] > tmp )
-                        thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025);              // +/- 1.414°
+                        thrM[n] = maxf (tmp, ergS[n]*iw[n]*0.025);              // +/- 1.414
                 }
             }
@@ -779,5 +760,6 @@
 // inline, because it's called 4x
 static void
-ApplyLtq ( float*        thr0,
+ApplyLtq ( PsyModel* m,
+		   float*        thr0,
            float*        thr1,
            const float*  partThr0,
@@ -800,5 +782,5 @@
 #else
             // Applies a much more gentle ATH rolloff + 6 dB more dynamic
-            ltq   = sqrt (ms * fftLtq [k]);
+            ltq   = sqrt (ms * m->fftLtq [k]);
             tmp   = sqrt (partThr0 [n]) + ltq;
             *thr0 = tmp * tmp;
@@ -896,5 +878,6 @@
 #else
 static void
-CalcShortThreshold ( const float  erg [4] [128],
+CalcShortThreshold ( PsyModel* m,
+					 const float  erg [4] [128],
                      const float  ShortThr,
                      float*       thr,
@@ -907,5 +890,5 @@
     int           k;
     int           n;
-    int           m;
+    int           l;
     float         new_erg;
     float         th;
@@ -917,14 +900,14 @@
         for ( n = 0; n < 4; n++ ) {
             ep   = erg[n] + index_lo [k];
-            m    = index_hi [k] - index_lo [k];
+            l    = index_hi [k] - index_lo [k];
 
             new_erg = *ep++;
-            while (m--)
+            while (l--)
                 new_erg += *ep++;               // e = Short_Partition-energy in piece n
 
             if ( new_erg > old_erg [0][k] ) {           // bigger than the old?
 
-                if ( new_erg > old_erg [0][k] * TransDetect  ||
-                     new_erg > old_erg [1][k] * TransDetect*2 )  // is signal transient?
+                if ( new_erg > old_erg [0][k] * m->TransDetect  ||
+					 new_erg > old_erg [1][k] * m->TransDetect*2 )  // is signal transient?
                     transient [k] = 1;
             }
@@ -992,5 +975,9 @@
 // output: SMRs for the input data
 SMRTyp
-Psychoakustisches_Modell ( const int MaxBand, const PCMDataTyp* data, int* TransientL, int* TransientR )
+Psychoakustisches_Modell ( PsyModel* m,
+						   const int MaxBand,
+						   const PCMDataTyp* data,
+						   int* TransientL,
+						   int* TransientR )
 {
     float      Xi_L[32],     Xi_R[32];                          // acoustic pressure per Subband L/R
@@ -1019,16 +1006,15 @@
     float    factorLTQ  = 1.f;                                  // Offset after variable LTQ
 
-    ENTER(50);
     // 'ClearVocalDetection'-Process
-    if ( CVD_used ) {
-        memset ( Vocal_L, 0, sizeof Vocal_L );
-        memset ( Vocal_R, 0, sizeof Vocal_R );
+    if ( m->CVD_used ) {
+        memset ( m->Vocal_L, 0, sizeof m->Vocal_L );
+        memset ( m->Vocal_R, 0, sizeof m->Vocal_R );
 
         // left channel
         PowSpec2048 ( &data->L[0], Xerg );
-        isvoc_L = CVD2048 ( Xerg, Vocal_L );
+        isvoc_L = CVD2048 ( Xerg, m->Vocal_L );
         // right channel
         PowSpec2048 ( &data->R[0], Xerg );
-        isvoc_R = CVD2048 ( Xerg, Vocal_R );
+        isvoc_R = CVD2048 ( Xerg, m->Vocal_R );
     }
 
@@ -1047,9 +1033,9 @@
     memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) );
     memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
+    CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
     // right
     memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) );
     memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
+    CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
 
     // calculation of the weighted acoustic pressures per each partition
@@ -1060,12 +1046,12 @@
     memset ( clow_L    , 0, sizeof clow_L );
     memset ( sim_Mask_L, 0, sizeof sim_Mask_L );
-    SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );
+    SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L );
     // right
     memset ( clow_R    , 0, sizeof clow_R );
     memset ( sim_Mask_R, 0, sizeof sim_Mask_R );
-    SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );
+    SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R );
 
     // Offset depending on tonality
-    ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );
+    ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R );
 
     // handling of transient signals
@@ -1076,5 +1062,5 @@
     PowSpec256 ( &data->L[432+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_L, pre_erg_L, TransientL );
+    CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );
 
     // calculate four short FFTs (right)
@@ -1084,16 +1070,16 @@
     PowSpec256 ( &data->R[432+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_R, pre_erg_R, TransientR );
+    CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );
 
     // dynamic adjustment of the threshold in quiet to the loudness of the current sequence
-    if ( varLtq > 0. )
-        factorLTQ = AdaptLtq ( Ls_L, Ls_R );
+    if ( m->varLtq > 0. )
+        factorLTQ = AdaptLtq (m, Ls_L, Ls_R );
 
     // utilization of the temporal post-masking
-    if ( tmpMask_used ) {
-        CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L );
-        CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R );
-        memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L );
-        memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R );
+    if ( m->tmpMask_used ) {
+		CalcTemporalThreshold (m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );
+		CalcTemporalThreshold (m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );
+		memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );
+		memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );
     }
 
@@ -1113,8 +1099,8 @@
 
     // Pre-Echo control
-    PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R );
+	PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );
 
     // utilization of the threshold in quiet
-    ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
+    ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
 
     // Consideration of aliasing between the subbands (noise is smeared)
@@ -1129,5 +1115,5 @@
     /***************************************************************************************/
     /***************************************************************************************/
-    if ( MS_Channelmode > 0 ) {
+	if ( m->MS_Channelmode > 0 ) {
         // calculation of the spectral energy via FFT
         PowSpec1024 ( &data->M[0], erg0 );      // mid
@@ -1141,6 +1127,6 @@
 
         // calculate masking thresholds for M/S
-        CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
-        ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
+        CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
+        ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
 
         // Consideration of aliasing between the subbands (noise is smeared)
@@ -1154,9 +1140,9 @@
     }
 
-    if ( NS_Order > 0 ) {       // providing the Noise Shaping thresholds
-        memcpy ( ANSspec_L, Thr_L, sizeof ANSspec_L );
-        memcpy ( ANSspec_R, Thr_R, sizeof ANSspec_R );
-        memcpy ( ANSspec_M, Thr_M, sizeof ANSspec_M );
-        memcpy ( ANSspec_S, Thr_S, sizeof ANSspec_S );
+	if ( m->NS_Order > 0 ) {       // providing the Noise Shaping thresholds
+		memcpy ( m->ANSspec_L, Thr_L, sizeof m->ANSspec_L );
+		memcpy ( m->ANSspec_R, Thr_R, sizeof m->ANSspec_R );
+		memcpy ( m->ANSspec_M, Thr_M, sizeof m->ANSspec_M );
+		memcpy ( m->ANSspec_S, Thr_S, sizeof m->ANSspec_S );
     }
     /***************************************************************************************/
@@ -1180,9 +1166,9 @@
     memmove ( Xsave_L+512, Xsave_L, 1024*sizeof(float) );
     memmove ( Ysave_L+512, Ysave_L, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg0, phs0, isvoc_L ? Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
+	CalcUnpred ( m, MaxLine, erg0, phs0, isvoc_L ? m->Vocal_L : NULL, Xsave_L, Ysave_L, cw_L );
     // right
     memmove ( Xsave_R+512, Xsave_R, 1024*sizeof(float) );
     memmove ( Ysave_R+512, Ysave_R, 1024*sizeof(float) );
-    CalcUnpred ( MaxLine, erg1, phs1, isvoc_R ? Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
+	CalcUnpred ( m, MaxLine, erg1, phs1, isvoc_R ? m->Vocal_R : NULL, Xsave_R, Ysave_R, cw_R );
 
     // calculation of the weighted acoustic pressure per each partition
@@ -1193,12 +1179,12 @@
     memset ( clow_L    , 0, sizeof clow_L );
     memset ( sim_Mask_L, 0, sizeof sim_Mask_L );
-    SpreadingSignal ( Ls_L, cLs_L, sim_Mask_L, clow_L );
+    SpreadingSignal ( m, Ls_L, cLs_L, sim_Mask_L, clow_L );
     // right
     memset ( clow_R    , 0, sizeof clow_R );
     memset ( sim_Mask_R, 0, sizeof sim_Mask_R );
-    SpreadingSignal ( Ls_R, cLs_R, sim_Mask_R, clow_R );
+    SpreadingSignal ( m, Ls_R, cLs_R, sim_Mask_R, clow_R );
 
     // Offset depending on tonality
-    ApplyTonalityOffset ( sim_Mask_L, sim_Mask_R, clow_L, clow_R );
+    ApplyTonalityOffset ( m, sim_Mask_L, sim_Mask_R, clow_L, clow_R );
 
     // Handling of transient signals
@@ -1209,5 +1195,5 @@
     PowSpec256 ( &data->L[1008+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_L, pre_erg_L, TransientL );
+	CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_L, m->pre_erg_L, TransientL );
 
     // calculate four short FFTs (right)
@@ -1217,16 +1203,16 @@
     PowSpec256 ( &data->R[1008+SHORTFFT_OFFSET], F_256[3] );
     // calculate short Threshold
-    CalcShortThreshold ( F_256, ShortThr, shortThr_R, pre_erg_R, TransientR );
+	CalcShortThreshold ( m, F_256, m->ShortThr, shortThr_R, m->pre_erg_R, TransientR );
 
     // dynamic adjustment of threshold in quiet to loudness of the current sequence
-    if ( varLtq > 0. )
-        factorLTQ = AdaptLtq ( Ls_L, Ls_R );
+	if ( m->varLtq > 0. )
+        factorLTQ = AdaptLtq ( m, Ls_L, Ls_R );
 
     // utilization of temporal post-masking
-    if (tmpMask_used) {
-        CalcTemporalThreshold ( a, b, T_L, sim_Mask_L, tmp_Mask_L );
-        CalcTemporalThreshold ( c, d, T_R, sim_Mask_R, tmp_Mask_R );
-        memcpy ( sim_Mask_L, tmp_Mask_L, sizeof sim_Mask_L );
-        memcpy ( sim_Mask_R, tmp_Mask_R, sizeof sim_Mask_R );
+	if (m->tmpMask_used) {
+		CalcTemporalThreshold ( m, m->a, m->b, m->T_L, sim_Mask_L, m->tmp_Mask_L );
+		CalcTemporalThreshold ( m, m->c, m->d, m->T_R, sim_Mask_R, m->tmp_Mask_R );
+		memcpy ( sim_Mask_L, m->tmp_Mask_L, sizeof sim_Mask_L );
+		memcpy ( sim_Mask_R, m->tmp_Mask_R, sizeof sim_Mask_R );
     }
 
@@ -1246,8 +1232,8 @@
 
     // Pre-Echo control
-    PreechoControl ( PartThr_L, PreThr_L, sim_Mask_L, PartThr_R, PreThr_R, sim_Mask_R );
+	PreechoControl ( PartThr_L, m->PreThr_L, sim_Mask_L, PartThr_R, m->PreThr_R, sim_Mask_R );
 
     // utilization of threshold in quiet
-    ApplyLtq ( Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
+    ApplyLtq ( m, Thr_L, Thr_R, PartThr_L, PartThr_R, factorLTQ, 0 );
 
     // Consideration of aliasing between the subbands (noise is smeared)
@@ -1262,5 +1248,5 @@
     /***************************************************************************************/
     /***************************************************************************************/
-    if ( MS_Channelmode > 0 ) {
+	if ( m->MS_Channelmode > 0 ) {
         // calculation of the spectral energy via FFT
         PowSpec1024 ( &data->M[576], erg0 );    // mid
@@ -1274,6 +1260,6 @@
 
         // calculate masking thresholds for M/S
-        CalcMSThreshold ( Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
-        ApplyLtq ( Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
+        CalcMSThreshold ( m, Ls_L, Ls_R, Ls_M, Ls_S, PartThr_L, PartThr_R, PartThr_M, PartThr_S );
+        ApplyLtq ( m, Thr_M, Thr_S, PartThr_M, PartThr_S, factorLTQ, 1 );
 
         // Consideration of aliasing between the subbands (noise is smeared)
@@ -1289,10 +1275,10 @@
     /***************************************************************************************/
 
-    if ( NS_Order > 0 ) {
+	if ( m->NS_Order > 0 ) {
         for ( n = 0; n < MAX_ANS_LINES; n++ ) {                 // providing Noise Shaping thresholds
-            ANSspec_L [n] = minf ( ANSspec_L [n], Thr_L [n] );
-            ANSspec_R [n] = minf ( ANSspec_R [n], Thr_R [n] );
-            ANSspec_M [n] = minf ( ANSspec_M [n], Thr_M [n] );
-            ANSspec_S [n] = minf ( ANSspec_S [n], Thr_S [n] );
+			m->ANSspec_L [n] = minf ( m->ANSspec_L [n], Thr_L [n] );
+			m->ANSspec_R [n] = minf ( m->ANSspec_R [n], Thr_R [n] );
+			m->ANSspec_M [n] = minf ( m->ANSspec_M [n], Thr_M [n] );
+			m->ANSspec_S [n] = minf ( m->ANSspec_S [n], Thr_S [n] );
         }
     }
@@ -1304,6 +1290,4 @@
         SMR0.S[n] = maxf ( SMR0.S[n], SMR1.S[n] );
     }
-
-    LEAVE(50);
     return SMR0;
 }
Index: mppenc/branches/r2d/libmpcpsy/psy_tab.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/psy_tab.c	(revision 59)
+++ mppenc/branches/r2d/libmpcpsy/psy_tab.c	(revision 60)
@@ -18,126 +18,7 @@
  */
 
-#include "mppenc.h"
-
-// Antialiasing for calculation of the subband power
-const float  Butfly    [7] = { 0.5f, 0.2776f, 0.1176f, 0.0361f, 0.0075f, 0.000948f, 0.0000598f };
-
-// Antialiasing for calculation of the masking thresholds
-const float  InvButfly [7] = { 2.f, 3.6023f, 8.5034f, 27.701f, 133.33f, 1054.852f, 16722.408f };
-
-// w_low for long               0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56
-const int   wl [PART_LONG] = {  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  13,  15,  17,  19,  21,  23,  25,  27,  29,  31,  33,  35,  38,  41,  44,  47,  50,  54,  58,  62,  67,  72,  78,  84,  91,  98, 106, 115, 124, 134, 145, 157, 170, 184, 199, 216, 234, 254, 276, 301, 329, 360, 396, 437, 485 };
-const int   wh [PART_LONG] = {  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  12,  14,  16,  18,  20,  22,  24,  26,  28,  30,  32,  34,  37,  40,  43,  46,  49,  53,  57,  61,  66,  71,  77,  83,  90,  97, 105, 114, 123, 133, 144, 156, 169, 183, 198, 215, 233, 253, 275, 300, 328, 359, 395, 436, 484, 511 };
-// Width:                       1    1    1    1    1    1    1    1    1    1    1    2    2    2    2    2    2    2    2    2    2    2    2    3    3    3    3    3    4    4    4    5    5    6    6    7    7    8    9    9   10   11   12   13   14   15   17   18   20   22   25   28   31   36   41   48   27
-
-// inverse partition-width for long
-const float iw [PART_LONG] = { 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/3, 1.f/4, 1.f/4, 1.f/4, 1.f/5, 1.f/5, 1.f/6, 1.f/6, 1.f/7, 1.f/7, 1.f/8, 1.f/9, 1.f/9, 1.f/10, 1.f/11, 1.f/12, 1.f/13, 1.f/14, 1.f/15, 1.f/17, 1.f/18, 1.f/20, 1.f/22, 1.f/25, 1.f/28, 1.f/31, 1.f/36, 1.f/41, 1.f/48, 1.f/27 };
-
-// w_low for short                    0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17   18
-const int   wl_short [PART_SHORT] = { 0,  1,  2,  3,  4,  5,  6,  8, 10, 12, 15, 18, 23, 29, 36, 46, 59, 75,  99 };
-const int   wh_short [PART_SHORT] = { 0,  1,  2,  3,  5,  6,  7,  9, 12, 14, 18, 23, 29, 36, 46, 58, 75, 99, 127 };
-
-// inverse partition-width for short
-const float iw_short [PART_SHORT] = { 1.f, 1.f, 1.f, 1.f, 1.f/2, 1.f/2, 1.f/2, 1.f/2, 1.f/3, 1.f/3, 1.f/4, 1.f/6, 1.f/7, 1.f/8, 1.f/11, 1.f/13, 1.f/17, 1.f/25, 1.f/29 };
-
-/*
-Nr.   wl  wh     fl    fh     bl         bh         bm        Nr.   wl  wh     fl    fh     bl         bh         bm
- 0:    0   0      0     0   0.000000   0.000000   0.000000
- 1:    1   1     43    43   0.425460   0.425460   0.425460     0:   0   0      0     0   0.000000   0.000000     0.000000
- 2:    2   2     86    86   0.850241   0.850241   0.850241
-
- 3:    3   3    129   129   1.273448   1.273448   1.273448
- 4:    4   4    172   172   1.694205   1.694205   1.694205     1:   1   1    172   172   1.694205   1.694205     1.694205
- 5:    5   5    215   215   2.111672   2.111672   2.111672
-
- 6:    6   6    258   258   2.525051   2.525051   2.525051
- 7:    7   7    301   301   2.933594   2.933594   2.933594     2:   2   2    345   345   3.336612   3.336612     3.336612
- 8:    8   8    345   345   3.336612   3.336612   3.336612
-
- 9:    9   9    388   388   3.733479   3.733479   3.733479
-10:   10  10    431   431   4.123635   4.123635   4.123635     3:   3   3    517   517   4.881924   4.881924     4.881924
-11-   11  12    474   517   4.506591   4.881924   4.695234
-
-12:   13  14    560   603   5.249283   5.608381   5.429880
-13:   15  16    646   689   5.958998   6.300971   6.131073     4:   4   5    689   861   6.300971   7.581073     6.958618
-14:   17  18    732   775   6.634195   6.958618   6.797509
-
-15:   19  20    818   861   7.274232   7.581073   7.428745
-16:   21  22    904   947   7.879211   8.168753   8.025049     5:   5   6    861  1034   7.581073   8.722594     8.168753
-17:   23  24    991  1034   8.449828   8.722594   8.587239
-
-18:   25  26   1077  1120   8.987223   9.243908   9.116546
-19:   27  28   1163  1206   9.492850   9.734263   9.614484     6:   6   7   1034  1206   8.722594   9.734263     9.243908
-20:   29  30   1249  1292   9.968365  10.195382  10.082745
-
-21:   31  32   1335  1378  10.415539  10.629064  10.523116
-22:   33  34   1421  1464  10.836184  11.037125  10.937413     7:   8   9   1378  1550  10.629064  11.421352    11.037125
-23:   35  37   1507  1593  11.232108  11.605071  11.421352
-
-24:   38  40   1637  1723  11.783474  12.125139  11.956764
-25:   41  43   1766  1852  12.288791  12.602659  12.447904     8:  10  12   1723  2067  12.125139  13.316883    12.753228
-26:   44  46   1895  1981  12.753228  13.042468  12.899777
-
-27:   47  49   2024  2110  13.181453  13.448898  13.316883
-28:   50  53   2153  2283  13.577635  13.945465  13.764881     9:  12  14   2067  2412  13.316883  14.288198    13.825796
-29:   54  57   2326  2455  14.062349  14.397371  14.232693
-
-30:   58  61   2498  2627  14.504172  14.811258  14.660130
-31:   62  66   2670  2842  14.909464  15.283564  15.100115    10:  15  18   2584  3101  14.711029  15.795819    15.283564
-32:   67  71   2885  3058  15.372757  15.714074  15.546390
-
-33:   72  77   3101  3316  15.795819  16.185532  15.994471
-34:   78  83   3359  3575  16.259980  16.616871  16.441494    11:  18  23   3101  3962  15.795819  17.204658    16.547424
-35:   84  90   3618  3876  16.685418  17.079349  16.885941
-
-36:   91  97   3919  4177  17.142352  17.506445  17.327264
-37:   98 105   4221  4522  17.564981  17.959646  17.765487    12:  23  29   3962  4996  17.204658  18.533945    17.904788
-38:  106 114   4565  4910  18.014031  18.433233  18.227034
-
-39:  115 123   4953  5297  18.483782  18.874805  18.682185
-40:  124 133   5340  5728  18.922095  19.332992  19.130789    13:  29  36   4996  6202  18.533945  19.801451    19.198897
-41:  134 144   5771  6202  19.377073  19.801451  19.592946
-
-42:  145 156   6245  6718  19.842285  20.272889  20.061808
-43:  157 169   6761  7278  20.310373  20.739167  20.529583    14:  36  46   6202  7924  19.801451  21.222342    20.565177
-44:  170 183   7321  7881  20.773175  21.191895  20.987911
-
-45:  184 198   7924  8527  21.222342  21.623344  21.428652
-46:  199 215   8570  9259  21.650236  22.050787  21.857360    15:  46  58   7924  9991  21.222342  22.420001    21.882271
-47:  216 233   9302 10034  22.074042  22.440072  22.263795
-
-48-  234 253  10078 10896  22.459969  22.807140  22.640652
-49:  254 275  10939 11843  22.823891  23.144847  22.991444    16:  59  75  10164 12920  22.499251  23.461146    23.044078
-50:  276 300  11886 12920  23.158772  23.461146  23.317264
-
-51:  301 328  12963 14126  23.472530  23.748999  23.617861
-52:  329 359  14169 15461  23.758199  24.005540  23.888450    17:  75  99  12920 17054  23.461146  24.248491    23.920884
-53:  360 395  15504 17011  24.012922  24.242660  24.134368
-
-54:  396 436  17054 18777  24.248491  24.454928  24.357873
-55:  437 484  18820 20844  24.459492  24.647977  24.559711    18:  99 127  17054 21878  24.248491  24.727775    24.524955
-56:  485 511  20887 22007  24.651498  24.737100  24.695685
-*/
-
-
-/* V A R I A B L E S */
-float  MinVal   [PART_LONG];               // contains minimum tonality soffsets
-float  Loudness [PART_LONG];               // weighting factors for loudness calculation
-float  SPRD     [PART_LONG] [PART_LONG];   // tabulated spreading function
-float  O_MAX;
-float  O_MIN;
-float  FAC1;
-float  FAC2;                               // constants for offset calculation
-float  partLtq  [PART_LONG];               // threshold in quiet (partitions)
-float  invLtq   [PART_LONG];               // inverse threshold in quiet (partitions, long)
-float  fftLtq   [512];                     // threshold in quiet (FFT)
-float  Ltq_offset;                         // Offset for threshold in quiet
-float  Ltq_max;                            // maximum level for threshold in quiet
-float  TMN;
-float  NMT;
-float  TransDetect;
-unsigned int    EarModelFlag;
-int    MinValChoice;
-
+#include "libmpcpsy.h"
+
+#include <math.h>
 
 /*
@@ -156,5 +37,5 @@
      * third = 1/12
      * octave = 1/40 decade
-     * rest is linear interpolated, values are currently in millibel rel. 20 µPa
+     * rest is linear interpolated, values are currently in millibel rel. 20 Pa
      */
     static short tab [] = {
@@ -216,5 +97,6 @@
 // calculation of the threshold in quiet in FFT-resolution
 static void
-Ruhehoerschwelle ( unsigned int  EarModelFlag,
+Ruhehoerschwelle ( PsyModel* m,
+				   unsigned int  EarModelFlag,
                    int           Ltq_offset,
                    int           Ltq_max )
@@ -228,5 +110,5 @@
 
     for ( n = 0; n < 512; n++ ) {
-        f = (float) ( (n+1) * (float)(SampleFreq / 2000.) / 512 );   // Frequency in kHz
+		f = (float) ( (n+1) * (float)(m->SampleFreq / 2000.) / 512 );   // Frequency in kHz
 
         switch ( EarModelFlag / 100 ) {
@@ -235,8 +117,8 @@
             break;
         default:
-        case 1:         // measured threshold in quiet (Nick Berglmeir, Andree Buschmann, Kopfhörer)
+        case 1:         // measured threshold in quiet (Nick Berglmeir, Andree Buschmann, Kopfhï¿œer)
             tmp  = 3.00*pow (f,-0.8) -  5.0*exp (-0.1*(f-3.0)*(f-3.0)) + 0.0000015022693846297*pow (f, 6.0) + 10.*exp (-(f-0.1)*(f-0.1));
             break;
-        case 2:         // measured threshold in quiet (Filburt, Kopfhörer)
+        case 2:         // measured threshold in quiet (Filburt, Kopfhï¿œer)
             tmp  = 9.00*pow (f,-0.5) - 15.0*exp (-0.1*(f-4.0)*(f-4.0)) + 0.0341796875*pow (f, 2.5)          + 15.*exp (-(f-0.1)*(f-0.1)) - 18;
             tmp  = mind ( tmp, Ltq_max - 18 );
@@ -264,5 +146,5 @@
         tmp       = mind ( tmp, Ltq_max );              // Limit ATH
         tmp      += Ltq_offset - 23;                    // Add chosen Offset
-        fftLtq[n] = absLtq[n] = POW10 ( 0.1 * tmp);     // conversion into power
+        m->fftLtq[n] = absLtq[n] = POW10 ( 0.1 * tmp);     // conversion into power
     }
 
@@ -273,6 +155,6 @@
             erg = minf (erg, absLtq[k]);
 
-        partLtq[n] = erg;               // threshold in quiet
-        invLtq [n] = 1.f / partLtq[n];  // Inverse
+		m->partLtq[n] = erg;               // threshold in quiet
+		m->invLtq [n] = 1.f / m->partLtq[n];  // Inverse
     }
 }
@@ -300,12 +182,12 @@
 
 static double
-LongPart2Bark ( int Part )
-{
-    return Freq2Bark ((wl [Part] + wh [Part]) * SampleFreq / 2048.);
+LongPart2Bark ( PsyModel* m, int Part )
+{
+	return Freq2Bark ((wl [Part] + wh [Part]) * m->SampleFreq / 2048.);
 }
 
 // calculating the table for loudness calculation based on absLtq = ank
 static void
-Loudness_Tabelle (void)
+Loudness_Tabelle (PsyModel* m)
 {
     int    n;
@@ -315,8 +197,8 @@
     // ca. dB(A)
     for ( n = 0; n < PART_LONG; n++ ){
-        midfreq      = (wh[n] + wl[n] + 3) * (0.25 * SampleFreq / 512);     // center frequency in kHz, why +3 ???
+		midfreq      = (wh[n] + wl[n] + 3) * (0.25 * m->SampleFreq / 512);     // center frequency in kHz, why +3 ???
         tmp          = LOG10 (midfreq) - 3.5f;                                  // dB(A)
         tmp          = -10 * tmp * tmp + 3 - midfreq/3000;
-        Loudness [n] = POW10 ( 0.1 * tmp );                                     // conversion into power
+		m->Loudness [n] = POW10 ( 0.1 * tmp );                                     // conversion into power
     }
 }
@@ -370,5 +252,5 @@
 // calculating the coefficient for utilization of the tonality offset, depending on TMN und NMT
 static void
-Tonalitaetskoeffizienten ( void )
+Tonalitaetskoeffizienten ( PsyModel* m )
 {
     double                tmp;
@@ -376,21 +258,21 @@
     float                 bass;
 
-    bass = 0.1/8 * NMT;
-    if ( MinValChoice <= 2  &&  bass > 0.1 )
+	bass = 0.1/8 * m->NMT;
+	if ( m->MinValChoice <= 2  &&  bass > 0.1 )
         bass = 0.1f;
-    if ( MinValChoice <= 1 )
+	if ( m->MinValChoice <= 1 )
         bass = 0.0f;
 
     // alternative: calculation of the minval-values dependent on TMN and TMN
     for ( n = 0; n < PART_LONG; n++ ) {
-        tmp        = Bass ( (wl [n] + wh [n]) / 2048. * SampleFreq, TMN, NMT, bass );
-        MinVal [n] = POW10 ( -0.1 * tmp );                      // conversion into power
+		tmp        = Bass ( (wl [n] + wh [n]) / 2048. * m->SampleFreq, m->TMN, m->NMT, bass );
+		m->MinVal [n] = POW10 ( -0.1 * tmp );                      // conversion into power
     }
 
     // calculation of the constants for "tonality offset"
-    O_MAX = POW10 ( -0.1 * TMN );
-    O_MIN = POW10 ( -0.1 * NMT );
-    FAC1  = POW10 ( -0.1 * (NMT - (TMN - NMT) * 0.229) ) ;
-    FAC2  = (TMN - NMT) * (0.99011159 * 0.1);
+	m->O_MAX = POW10 ( -0.1 * m->TMN );
+	m->O_MIN = POW10 ( -0.1 * m->NMT );
+	m->FAC1  = POW10 ( -0.1 * (m->NMT - (m->TMN - m->NMT) * 0.229) ) ;
+	m->FAC2  = (m->TMN - m->NMT) * (0.99011159 * 0.1);
 }
 
@@ -398,5 +280,5 @@
 // calculation of the spreading function
 static void
-Spread ( void )
+Spread ( PsyModel* m )
 {
     int    i;
@@ -410,5 +292,5 @@
     for ( i = 0; i < PART_LONG; i++ ) {                 // i is masking Partition, Source
         for ( j = 0; j < PART_LONG; j++ ) {             // j is masking Partition, Target
-            tmpx = LongPart2Bark (j) - LongPart2Bark (i);// Difference of the partitions in Bark
+            tmpx = LongPart2Bark (m, j) - LongPart2Bark (m, i);// Difference of the partitions in Bark
             tmpy = tmpz = 0.;                           // tmpz = 0: no dip
 
@@ -422,5 +304,5 @@
 #else
                 x  = i  ?  wl[i]+wh[i]  :  1;
-                x *= SampleFreq / 1000. / 2048;         // center frequency in kHz
+                x *= m->SampleFreq / 1000. / 2048;         // center frequency in kHz
 #endif
                 // dB/Bark
@@ -432,5 +314,5 @@
 
             // calculate coefficient
-            SPRD[i][j] = POW10 ( -0.1 * (tmpy+tmpz) );  // [Source] [Target]
+			m->SPRD[i][j] = POW10 ( -0.1 * (tmpy+tmpz) );  // [Source] [Target]
         }
     }
@@ -440,7 +322,7 @@
         float  norm = 0.f;
         for ( j = 0; j < PART_LONG; j++ )               // j is masking Partition
-            norm += SPRD [j] [i];
+			norm += m->SPRD [j] [i];
         for ( j = 0; j < PART_LONG; j++ )               // j is masking Partition
-            SPRD [j] [i] /= norm;
+			m->SPRD [j] [i] /= norm;
     }
 }
@@ -448,14 +330,14 @@
 // call all initialisation procedures
 void
-Init_Psychoakustiktabellen ( void )
-{
-    Max_Band = (int) ( Bandwidth * 64. / SampleFreq );
-    if ( Max_Band <  1 ) Max_Band =  1;
-    if ( Max_Band > 31 ) Max_Band = 31;
-
-    Tonalitaetskoeffizienten ();
-    Ruhehoerschwelle ( EarModelFlag, Ltq_offset, Ltq_max );
-    Loudness_Tabelle ();
-    Spread ();
+Init_Psychoakustiktabellen ( PsyModel* m )
+{
+	m->Max_Band = (int) ( m->Bandwidth * 64. / m->SampleFreq );
+	if ( m->Max_Band <  1 ) m->Max_Band =  1;
+	if ( m->Max_Band > 31 ) m->Max_Band = 31;
+
+    Tonalitaetskoeffizienten (m);
+	Ruhehoerschwelle ( m, m->EarModelFlag, m->Ltq_offset, m->Ltq_max );
+    Loudness_Tabelle (m);
+    Spread (m);
 }
 
