Index: mppenc/branches/r2d/common/datatypes.h
===================================================================
--- mppenc/branches/r2d/common/datatypes.h	(revision 64)
+++ mppenc/branches/r2d/common/datatypes.h	(revision 65)
@@ -17,4 +17,5 @@
  */
 
+#pragma once
 
 // mppenc.h
Index: mppenc/branches/r2d/common/minimax.h
===================================================================
--- mppenc/branches/r2d/common/minimax.h	(revision 65)
+++ mppenc/branches/r2d/common/minimax.h	(revision 65)
@@ -0,0 +1,64 @@
+/*
+ * 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
+ */
+
+#ifndef MPP_MINIMAX_H
+#define MPP_MINIMAX_H
+
+#if   defined __GNUC__  &&  defined __cplusplus
+
+# define maxi(A,B)  ( (A) >? (B) )
+# define mini(A,B)  ( (A) <? (B) )
+# define maxd(A,B)  ( (A) >? (B) )
+# define mind(A,B)  ( (A) <? (B) )
+# define maxf(A,B)  ( (A) >? (B) )
+# define minf(A,B)  ( (A) <? (B) )
+
+# define absi(A)    abs   (A)
+# define absf(A)    fabsf (A)
+# define absd(A)    fabs  (A)
+
+#elif defined __GNUC__
+
+# define maxi(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
+# define mini(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
+# define maxd(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
+# define mind(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
+# define maxf(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
+# define minf(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
+
+# define absi(A)    abs   (A)
+# define absf(A)    fabsf (A)
+# define absd(A)    fabs  (A)
+
+#else
+
+# define maxi(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
+# define mini(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
+# define maxd(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
+# define mind(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
+# define maxf(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
+# define minf(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
+
+# define absi(A)    ( (A) >= 0    ?  (A)  : -(A) )
+# define absf(A)    ( (A) >= 0.f  ?  (A)  : -(A) )
+# define absd(A)    ( (A) >= 0.   ?  (A)  : -(A) )
+
+#endif /* GNUC && C++ */
+
+#endif /* MPP_MINIMAX_H */
Index: mppenc/branches/r2d/libmpcenc/bitstream.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/bitstream.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/bitstream.c	(revision 65)
@@ -125,5 +125,5 @@
 
 
-void WriteBits (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits )
+void WriteBits (mpc_encoder_t * e, const mpc_uint32_t input, const unsigned int bits )
 {
     e->BufferedBits += bits;
@@ -147,5 +147,5 @@
 // Bits in the original stream have to be 0, maximum X bits allowed to be set in input
 // Actual bitstream must have already written ptr[0] and ptr[1]
-void WriteBitsAt (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits, BitstreamPos const pos )
+void WriteBitsAt (mpc_encoder_t * e, const mpc_uint32_t input, const unsigned int bits, BitstreamPos const pos )
 {
     mpc_uint32_t*     ptr    = pos.ptr;
@@ -171,5 +171,5 @@
 
 
-void GetBitstreamPos (mpc_encoder * e, BitstreamPos* const pos )
+void GetBitstreamPos (mpc_encoder_t * e, BitstreamPos* const pos )
 {
     pos -> ptr = e->Buffer + e->Zaehler;
Index: mppenc/branches/r2d/libmpcenc/encode_sv7.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/encode_sv7.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/encode_sv7.c	(revision 65)
@@ -110,5 +110,5 @@
 
 void
-FinishBitstream ( mpc_encoder* e )
+FinishBitstream ( mpc_encoder_t* e )
 {
     e->Buffer [e->Zaehler++] = e->dword;         // Assigning the "last" word
@@ -169,5 +169,5 @@
 // formatting and writing SV7-bitstream for one frame
 void
-WriteBitstream_SV7 ( mpc_encoder* e,
+WriteBitstream_SV7 ( mpc_encoder_t* e,
 					 const int               MaxBand,
                      const SubbandQuantTyp*  Q )
Index: mppenc/branches/r2d/libmpcenc/libmpcenc.h
===================================================================
--- mppenc/branches/r2d/libmpcenc/libmpcenc.h	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/libmpcenc.h	(revision 65)
@@ -60,5 +60,5 @@
 // TODO : match with mpc_decoder_t
 // FIXME : add init code
-typedef struct mpc_encoder_t {
+typedef struct {
 	mpc_uint32_t	Buffer [BUFFER_FULL];    // Buffer for bitstream-file
 	mpc_uint32_t	dword; //         =  0;      // 32-bit-Word for Bitstream-I/O
@@ -69,4 +69,4 @@
 	unsigned int  MS_Channelmode;
 	unsigned int  Overflows; //       = 0;      // number of internal (filterbank) clippings
-} mpc_encoder;
+} mpc_encoder_t;
 
Index: mppenc/branches/r2d/libmpcenc/minimax.h
===================================================================
--- mppenc/branches/r2d/libmpcenc/minimax.h	(revision 64)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/*
- * 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
- */
-
-#ifndef MPP_MINIMAX_H
-#define MPP_MINIMAX_H
-
-#if   defined __GNUC__  &&  defined __cplusplus
-
-# define maxi(A,B)  ( (A) >? (B) )
-# define mini(A,B)  ( (A) <? (B) )
-# define maxd(A,B)  ( (A) >? (B) )
-# define mind(A,B)  ( (A) <? (B) )
-# define maxf(A,B)  ( (A) >? (B) )
-# define minf(A,B)  ( (A) <? (B) )
-
-# define absi(A)    abs   (A)
-# define absf(A)    fabsf (A)
-# define absd(A)    fabs  (A)
-
-#elif defined __GNUC__
-
-# define maxi(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
-# define mini(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
-# define maxd(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
-# define mind(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
-# define maxf(A,B)  ( (A) > (B)  ?  (A)  :  (B) )
-# define minf(A,B)  ( (A) < (B)  ?  (A)  :  (B) )
-
-# define absi(A)    abs   (A)
-# define absf(A)    fabsf (A)
-# define absd(A)    fabs  (A)
-
-#else
-
-# define maxi(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
-# define mini(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
-# define maxd(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
-# define mind(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
-# define maxf(A,B)  ( (A) >  (B)  ?  (A)  :  (B) )
-# define minf(A,B)  ( (A) <  (B)  ?  (A)  :  (B) )
-
-# define absi(A)    ( (A) >= 0    ?  (A)  : -(A) )
-# define absf(A)    ( (A) >= 0.f  ?  (A)  : -(A) )
-# define absd(A)    ( (A) >= 0.   ?  (A)  : -(A) )
-
-#endif /* GNUC && C++ */
-
-#endif /* MPP_MINIMAX_H */
Index: mppenc/branches/r2d/libmpcenc/quant.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/quant.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/quant.c	(revision 65)
@@ -18,7 +18,8 @@
  */
 
+#include <math.h>
+
 #include "libmpcenc.h"
-
-#include <math.h>
+#include "minimax.h"
 
 /* V A R I A B L E S */
Index: mppenc/branches/r2d/libmpcenc/tools.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/tools.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/tools.c	(revision 65)
@@ -34,4 +34,7 @@
 
 #include "libmpcenc.h"
+
+// READ    returns -1 or 0 on error/EOF, otherwise > 0
+#define READ(fp,ptr,len)       fread  (ptr, 1, len, fp)
 
 #if defined HAVE_INCOMPLETE_READ  &&  FILEIO != 1
Index: mppenc/branches/r2d/libmpcpsy/fft4g.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 64)
+++ mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 65)
@@ -18,5 +18,8 @@
  */
 
+#include <math.h>
+
 #include "libmpcpsy.h"
+#include "fastmath.h"
 #include "mpcmath.h"
 
Index: mppenc/branches/r2d/libmpcpsy/fft_routines.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fft_routines.c	(revision 64)
+++ mppenc/branches/r2d/libmpcpsy/fft_routines.c	(revision 65)
@@ -174,5 +174,5 @@
 // generates FFT lookup-tables
 void
-Init_FFT ( void )
+Init_FFT ( PsyModel* m )
 {
     int     n;
@@ -181,6 +181,6 @@
 
     // normalized hann functions
-    Window ( Hann_256 ,  256, KBD1 );
-    Window ( Hann_1024, 1024, KBD2 );
+    Window ( Hann_256 ,  256, m->KBD1 );
+    Window ( Hann_1024, 1024, m->KBD2 );
     scale = 0.25 / sqrt (2048.);
     for ( n = 0; n < 800; n++ )
Index: mppenc/branches/r2d/libmpcpsy/libmpcpsy.h
===================================================================
--- mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 64)
+++ mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 65)
@@ -42,8 +42,4 @@
 #define MS2SPAT3             0.125f
 #define MS2SPAT4             0.0625f
-
-
-#define KBD1	2.
-#define KBD2	-1.
 
 typedef struct {
@@ -96,7 +92,7 @@
 	float  Ltq_offset;                         // Offset for threshold in quiet
 	float  Ltq_max;                            // maximum level for threshold in quiet
-	float  TMN;
-	float  NMT;
-	float  TransDetect;
+	float        TMN;                        // Offset for purely sinusoid components
+	float        NMT;                        // Offset for purely noisy components
+	float        TransDetect;                // minimum slewrate for transient detection
 	unsigned int    EarModelFlag;
 	int    MinValChoice;
@@ -115,4 +111,7 @@
 	float         SNR_comp_R [32];             // SNR-compensation after SCF-combination and ANS-gain
 
+	float KBD1; // = 2.
+	float KBD2; // = -1.
+
 	// FIXME : remove this :
 	int            SCF_Index_L [32] [3];
@@ -121,17 +120,2 @@
 } 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 64)
+++ mppenc/branches/r2d/libmpcpsy/psy.c	(revision 65)
@@ -58,4 +58,13 @@
 #include "fastmath.h"
 #include "datatypes.h"
+#include "minimax.h"
+
+
+extern const float  iw        [PART_LONG];      // inverse partition-width for long
+extern const float  iw_short  [PART_SHORT];     // inverse partition-width for short
+extern const int    wl        [PART_LONG];      // w_low  for long
+extern const int    wl_short  [PART_SHORT];     // w_low  for short
+extern const int    wh        [PART_LONG];      // w_high for long
+extern const int    wh_short  [PART_SHORT];     // w_high for short
 
 
Index: mppenc/branches/r2d/libmpcpsy/psy_tab.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/psy_tab.c	(revision 64)
+++ mppenc/branches/r2d/libmpcpsy/psy_tab.c	(revision 65)
@@ -19,4 +19,6 @@
 
 #include "libmpcpsy.h"
+#include "minimax.h"
+#include "fastmath.h"
 
 #include <math.h>
@@ -28,4 +30,21 @@
  *  ATH is not good even if it's theoretically inaudible).
  */
+
+// FIXME : move this in a struct, to eliminate multiple declarations
+// 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 };
+
 
 static float
Index: mppenc/branches/r2d/mppenc.kdevelop
===================================================================
--- mppenc/branches/r2d/mppenc.kdevelop	(revision 64)
+++ mppenc/branches/r2d/mppenc.kdevelop	(revision 65)
@@ -18,5 +18,5 @@
   <kdevautoproject>
     <general>
-      <activetarget>libmpcenc/libmpcenc.a</activetarget>
+      <activetarget>src/mppenc</activetarget>
       <useconfiguration>debug</useconfiguration>
     </general>
Index: mppenc/branches/r2d/src/Makefile.am
===================================================================
--- mppenc/branches/r2d/src/Makefile.am	(revision 64)
+++ mppenc/branches/r2d/src/Makefile.am	(revision 65)
@@ -3,9 +3,11 @@
 
 # set the include path found by configure
-INCLUDES= $(all_includes)
+INCLUDES = -I$(top_srcdir)/libmpcenc -I$(top_srcdir)/libmpcpsy -I../../common \
+	$(all_includes)
 
 # the library search path.
 mppenc_LDFLAGS = $(all_libraries) 
-mppenc_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c keyboard.c \
-	mppenc.c pipeopen.c quant.c stderr.c tags.c tools.c wave_in.c winmsg.c
-mppenc_LDADD = -lm
+mppenc_SOURCES = keyboard.c mppenc.c pipeopen.c stderr.c tags.c wave_in.c \
+	winmsg.c
+mppenc_LDADD = $(top_builddir)/libmpcpsy/libmpcpsy.a \
+	$(top_builddir)/libmpcenc/libmpcenc.a -lm
Index: mppenc/branches/r2d/src/mppdec.h
===================================================================
--- mppenc/branches/r2d/src/mppdec.h	(revision 64)
+++ mppenc/branches/r2d/src/mppdec.h	(revision 65)
@@ -920,40 +920,34 @@
 extern size_t             InputCnt;             // current offset in this buffer
 
-// huffsv7.c
-extern Huffman_t          HuffHdr    [10];
-extern Huffman_t          HuffSCFI   [ 4];
-extern Huffman_t          HuffDSCF   [16];
-extern Huffman_t          HuffQ1 [2] [ 3*3*3];
-extern Huffman_t          HuffQ2 [2] [ 5*5];
-extern Huffman_t          HuffQ3 [2] [ 7];
-extern Huffman_t          HuffN3 [2] [ 7*7];
-extern Huffman_t          HuffQ4 [2] [ 9];
-extern Huffman_t          HuffQ5 [2] [15];
-extern Huffman_t          HuffQ6 [2] [31];
-extern Huffman_t          HuffQ7 [2] [63];
-extern Huffman_t          HuffN8 [2][127];
-extern const Huffman_t*   HuffQ  [2] [ 8];
-extern const Huffman_t*   HuffN  [2] [ 9];
-extern Uint8_t            LUT1_0  [1<< 6];
-extern Uint8_t            LUT1_1  [1<< 9];
-extern Uint8_t            LUT2_0  [1<< 7];
-extern Uint8_t            LUT2_1  [1<<10];
-extern Uint8_t            LUT3_0  [1<< 4];
-extern Uint8_t            LUT3_1  [1<< 5];
-extern Uint8_t            LUT4_0  [1<< 4];
-extern Uint8_t            LUT4_1  [1<< 5];
-extern Uint8_t            LUT5_0  [1<< 6];
-extern Uint8_t            LUT5_1  [1<< 8];
-extern Uint8_t            LUT6_0  [1<< 7];
-extern Uint8_t            LUT6_1  [1<< 7];
-extern Uint8_t            LUT7_0  [1<< 8];
-extern Uint8_t            LUT7_1  [1<< 8];
-extern Uint8_t            LUTDSCF [1<< 6];
-
-// huffsv46.c
-extern const Huffman_t*   Entropie      [18];
-extern const Huffman_t*   Region        [32];
-extern Huffman_t          SCFI_Bundle   [ 8];
-extern Huffman_t          DSCF_Entropie [13];
+// // huffsv7.c
+// extern Huffman_t          HuffHdr    [10];
+// extern Huffman_t          HuffSCFI   [ 4];
+// extern Huffman_t          HuffDSCF   [16];
+// extern Huffman_t          HuffQ1 [2] [ 3*3*3];
+// extern Huffman_t          HuffQ2 [2] [ 5*5];
+// extern Huffman_t          HuffQ3 [2] [ 7];
+// extern Huffman_t          HuffN3 [2] [ 7*7];
+// extern Huffman_t          HuffQ4 [2] [ 9];
+// extern Huffman_t          HuffQ5 [2] [15];
+// extern Huffman_t          HuffQ6 [2] [31];
+// extern Huffman_t          HuffQ7 [2] [63];
+// extern Huffman_t          HuffN8 [2][127];
+// extern const Huffman_t*   HuffQ  [2] [ 8];
+// extern const Huffman_t*   HuffN  [2] [ 9];
+// extern Uint8_t            LUT1_0  [1<< 6];
+// extern Uint8_t            LUT1_1  [1<< 9];
+// extern Uint8_t            LUT2_0  [1<< 7];
+// extern Uint8_t            LUT2_1  [1<<10];
+// extern Uint8_t            LUT3_0  [1<< 4];
+// extern Uint8_t            LUT3_1  [1<< 5];
+// extern Uint8_t            LUT4_0  [1<< 4];
+// extern Uint8_t            LUT4_1  [1<< 5];
+// extern Uint8_t            LUT5_0  [1<< 6];
+// extern Uint8_t            LUT5_1  [1<< 8];
+// extern Uint8_t            LUT6_0  [1<< 7];
+// extern Uint8_t            LUT6_1  [1<< 7];
+// extern Uint8_t            LUT7_0  [1<< 8];
+// extern Uint8_t            LUT7_1  [1<< 8];
+// extern Uint8_t            LUTDSCF [1<< 6];
 
 // mppdec.c
@@ -984,5 +978,4 @@
 extern Uint               Bitrate;
 extern Int                Min_Band;
-extern Int                Max_Band;
 extern Float              __Cc          [1 + 18];
 extern const Uint         __Dc          [1 + 18];
@@ -1054,5 +1047,5 @@
 
 void       Init_Dither                ( Int bits, int shapingtype, Double dither );
-void       OverdriveReport            ( void );
+// void       OverdriveReport            ( void );
 SyntheseFilter16_t
            Get_Synthese_Filter        ( void );
@@ -1062,7 +1055,7 @@
 void       Requantize_MidSideStereo   ( Int Stop_Band, const Bool_t* used_MS );
 void       Requantize_IntensityStereo ( Int Start_Band, Int Stop_Band );
-void       Resort_HuffTable           ( Huffman_t* const Table, const size_t elements, Int offset );
-void       Make_HuffTable             ( Huffman_t* dst, const HuffSrc_t* src, size_t len );
-void       Make_LookupTable           ( Uint8_t* LUT, size_t LUT_len, const Huffman_t* const Table, const size_t elements );
+// void       Resort_HuffTable           ( Huffman_t* const Table, const size_t elements, Int offset );
+// void       Make_HuffTable             ( Huffman_t* dst, const HuffSrc_t* src, size_t len );
+// void       Make_LookupTable           ( Uint8_t* LUT, size_t LUT_len, const Huffman_t* const Table, const size_t elements );
 size_t     complete_read              ( int fd, void* dest, size_t bytes );
 int        isdir                      ( const char* Name );
Index: mppenc/branches/r2d/src/mppenc.c
===================================================================
--- mppenc/branches/r2d/src/mppenc.c	(revision 64)
+++ mppenc/branches/r2d/src/mppenc.c	(revision 65)
@@ -31,5 +31,4 @@
 
 /* MS-Coding */
-unsigned int  MS_Channelmode;              // global flag for enhanced functionality
 int           PredictionBands =  0;
 int           CombPenalities  = -1;
@@ -130,5 +129,5 @@
 
 static void
-longhelp ( void )
+longhelp ( PsyModel * m )
 {
     stderr_printf (
@@ -245,7 +244,7 @@
              "  --quality x      set Quality to x (dflt: 5)\n" );
     stderr_printf (
-             "  --nmt x          set NMT value to x dB (dflt: %4.1f)\n", NMT );
-    stderr_printf (
-             "  --tmn x          set TMN value to x dB (dflt: %4.1f)\n", TMN );
+             "  --nmt x          set NMT value to x dB (dflt: %4.1f)\n", m->NMT );
+    stderr_printf (
+             "  --tmn x          set TMN value to x dB (dflt: %4.1f)\n", m->TMN );
     stderr_printf (
              "  --pns x          set PNS value to x dB (dflt: %4.1f)\n", PNS );
@@ -253,7 +252,7 @@
              "==ATH/Bandwidth settings==\n" );
     stderr_printf (
-             "  --bw x           maximum bandwidth in Hz (dflt: %4.1f kHz)\n", (Max_Band+1)*(SampleFreq/32000.) );
-    stderr_printf (
-             "  --minSMR x       minimum SMR of x dB over encoded bandwidth (dflt: %2.1f)\n",  minSMR );
+             "  --bw x           maximum bandwidth in Hz (dflt: %4.1f kHz)\n", (m->Max_Band+1)*(m->SampleFreq/32000.) );
+    stderr_printf (
+             "  --minSMR x       minimum SMR of x dB over encoded bandwidth (dflt: %2.1f)\n",  m->minSMR );
     stderr_printf (
              "  --ltq xyy        x=0: ISO threshold in quiet (not recommended)\n"
@@ -265,11 +264,11 @@
              "                   y=00...99: HF roll-off (00:+30 dB, 99:-30 dB @20 kHz\n" );
     stderr_printf (
-             "  --ltq_gain x     add offset of x dB to chosen ltq (dflt: %+4.1f)\n",       Ltq_offset   );
-    stderr_printf (
-             "  --ltq_max x      maximum level for ltq (dflt: %4.1f dB)\n",                Ltq_max      );
-    stderr_printf (
-             "  --ltq_var x      adaptive threshold in quiet: 0: off, >0: on (dflt: %g)\n",varLtq       );
-    stderr_printf (
-             "  --tmpMask x      exploit postmasking: 0: off, 1: on (dflt: %i)\n",         tmpMask_used );
+             "  --ltq_gain x     add offset of x dB to chosen ltq (dflt: %+4.1f)\n",       m->Ltq_offset   );
+    stderr_printf (
+             "  --ltq_max x      maximum level for ltq (dflt: %4.1f dB)\n",                m->Ltq_max      );
+    stderr_printf (
+			"  --ltq_var x      adaptive threshold in quiet: 0: off, >0: on (dflt: %g)\n", m->varLtq    );
+    stderr_printf (
+			"  --tmpMask x      exploit postmasking: 0: off, 1: on (dflt: %i)\n",         m->tmpMask_used );
     stderr_printf (
              "==Stuff settings==========\n" );
@@ -277,13 +276,13 @@
              "  --ms x           Mid/Side Stereo, 0: off, 1: reduced, 2: on, 3: decoupled,\n"
              "                   10: enhanced 1.5/3 dB, 11: 2/6 dB, 12: 2.5/9 dB,\n"
-             "                   13: 3/12 dB, 15: 3/oo dB (dflt: %i)\n",                        MS_Channelmode );
-    stderr_printf (
-             "  --ans x          Adaptive Noise Shaping Order: 0: off, 1...6: on (dflt: %i)\n", NS_Order );
-    stderr_printf (
-             "  --cvd x          ClearVoiceDetection, 0: off, 1: on, 2: dual (dflt: %i)\n",     CVD_used );
-    stderr_printf (
-             "  --shortthr x     short FFT threshold (dflt: %4.1f)\n",                          ShortThr );
-    stderr_printf (
-             "  --transdet x     slewrate for transient detection (dflt: %3.1f)\n",             TransDetect );
+             "                   13: 3/12 dB, 15: 3/oo dB (dflt: %i)\n",                        m->MS_Channelmode );
+    stderr_printf (
+			"  --ans x          Adaptive Noise Shaping Order: 0: off, 1...6: on (dflt: %i)\n", m->NS_Order );
+    stderr_printf (
+			"  --cvd x          ClearVoiceDetection, 0: off, 1: on, 2: dual (dflt: %i)\n",     m->CVD_used );
+    stderr_printf (
+			"  --shortthr x     short FFT threshold (dflt: %4.1f)\n",                          m->ShortThr );
+    stderr_printf (
+             "  --transdet x     slewrate for transient detection (dflt: %3.1f)\n",             m->TransDetect );
     stderr_printf (
              "  --minval x       calculation of MinVal (1:Buschmann, 2,3:Klemm)\n" );
@@ -458,5 +457,5 @@
 
 static void
-SCF_Extraktion ( const int MaxBand, SubbandFloatTyp* x )
+SCF_Extraktion ( PsyModel*m, mpc_encoder_t* e, const int MaxBand, SubbandFloatTyp* x )
 {
     int    Band;
@@ -606,6 +605,6 @@
         tmp_R [1]         = invSCF [comp_R[1] - scfR[1]];
         tmp_R [2]         = invSCF [comp_R[2] - scfR[2]];
-        SNR_comp_L [Band] = (tmp_L[0]*tmp_L[0] + tmp_L[1]*tmp_L[1] + tmp_L[2]*tmp_L[2]) * 0.3333333333f;
-        SNR_comp_R [Band] = (tmp_R[0]*tmp_R[0] + tmp_R[1]*tmp_R[1] + tmp_R[2]*tmp_R[2]) * 0.3333333333f;
+        m->SNR_comp_L [Band] = (tmp_L[0]*tmp_L[0] + tmp_L[1]*tmp_L[1] + tmp_L[2]*tmp_L[2]) * 0.3333333333f;
+        m->SNR_comp_R [Band] = (tmp_R[0]*tmp_R[0] + tmp_R[1]*tmp_R[1] + tmp_R[2]*tmp_R[2]) * 0.3333333333f;
 
         // normalize the subband samples
@@ -633,10 +632,10 @@
             for ( n = 0; n < 36; n++ ) {
                 if      (x[Band].L[n] > +32767.f) {
-                    Overflows++;
+                    e->Overflows++;
                     MaxOverFlow = maxf (MaxOverFlow,  x[Band].L[n]);
                     x[Band].L[n] = 32767.f;
                 }
                 else if (x[Band].L[n] < -32767.f) {
-                    Overflows++;
+					e->Overflows++;
                     MaxOverFlow = maxf (MaxOverFlow, -x[Band].L[n]);
                     x[Band].L[n] = -32767.f;
@@ -646,10 +645,10 @@
             for ( n = 0; n < 36; n++ ) {
                 if      (x[Band].R[n] > +32767.f) {
-                    Overflows++;
+					e->Overflows++;
                     MaxOverFlow = maxf (MaxOverFlow,  x[Band].R[n]);
                     x[Band].R[n] = 32767.f;
                 }
                 else if (x[Band].R[n] < -32767.f) {
-                    Overflows++;
+					e->Overflows++;
                     MaxOverFlow = maxf (MaxOverFlow, -x[Band].R[n]);
                     x[Band].R[n] = -32767.f;
@@ -662,5 +661,6 @@
 
 static void
-Quantisierung ( const int               MaxBand,
+Quantisierung ( PsyModel * m,
+				const int               MaxBand,
                 const int*              resL,
                 const int*              resR,
@@ -676,6 +676,6 @@
 
         if ( *resL > 0 ) {
-            if ( NS_Order_L [Band] > 0 ) {
-                QuantizeSubbandWithNoiseShaping ( subq[Band].L, subx[Band].L, *resL, errorL [Band], FIR_L [Band] );
+            if ( m->NS_Order_L [Band] > 0 ) {
+                QuantizeSubbandWithNoiseShaping ( subq[Band].L, subx[Band].L, *resL, errorL [Band], m->FIR_L [Band] );
                 memcpy ( errorL [Band], errorL[Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             } else {
@@ -687,6 +687,6 @@
 
         if ( *resR > 0 ) {
-            if ( NS_Order_R [Band] > 0 ) {
-                QuantizeSubbandWithNoiseShaping ( subq[Band].R, subx[Band].R, *resR, errorR [Band], FIR_R [Band] );
+            if ( m->NS_Order_R [Band] > 0 ) {
+                QuantizeSubbandWithNoiseShaping ( subq[Band].R, subx[Band].R, *resR, errorR [Band], m->FIR_R [Band] );
                 memcpy ( errorR [Band], errorR [Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             } else {
@@ -793,27 +793,23 @@
 }
 
-
-
-
 typedef struct {
-    float            ShortThr;
-    unsigned char    MinValChoice;
-    unsigned int     EarModelFlag;
-    signed char      Ltq_offset;
-    float            TMN;
-    float            NMT;
-    signed char      minSMR;
-    signed char      Ltq_max;
-    unsigned short   BandWidth;
-    unsigned char    tmpMask_used;
-    unsigned char    CVD_used;
-    float            varLtq;
-    unsigned char    MS_Channelmode;
-    unsigned char    CombPenalities;
-    unsigned char    NS_Order;
-    float            PNS;
-    float            TransDetect;
+	float            ShortThr;
+	unsigned char    MinValChoice;
+	unsigned int     EarModelFlag;
+	signed char      Ltq_offset;
+	float            TMN;
+	float            NMT;
+	signed char      minSMR;
+	signed char      Ltq_max;
+	unsigned short   BandWidth;
+	unsigned char    tmpMask_used;
+	unsigned char    CVD_used;
+	float            varLtq;
+	unsigned char    MS_Channelmode;
+	unsigned char    CombPenalities;
+	unsigned char    NS_Order;
+	float            PNS;
+	float            TransDetect;
 } Profile_Setting_t;
-
 
 #define PROFILE_PRE2_TELEPHONE   5      // --quality  0
@@ -853,5 +849,5 @@
 
 static int
-TestProfileParams ( void )
+TestProfileParams ( PsyModel* m )
 {   //                                       0    1    2    3    4   5   6  7 8 9  10  11  12  13 14  15
     static signed char  TMNStereoAdj [] = { -6, -18, -15, -18, -12, -9, -6, 0,0,0, +1, +1, +1, +1, 0, +1 };  // Penalties for TMN
@@ -862,19 +858,19 @@
 
     for ( i = PROFILE_PRE2_TELEPHONE; i <= PROFILE_POST2_BRAINDEAD; i++ ) {
-        if ( ShortThr     > Profiles [i].ShortThr     ) continue;
-        if ( MinValChoice < Profiles [i].MinValChoice ) continue;
-        if ( EarModelFlag < Profiles [i].EarModelFlag ) continue;
-        if ( Ltq_offset   > Profiles [i].Ltq_offset   ) continue;
-        if ( Ltq_max      > Profiles [i].Ltq_max      ) continue;                     // offset should normally be considered here
-        if ( TMN + TMNStereoAdj [MS_Channelmode] <
+        if ( m->ShortThr     > Profiles [i].ShortThr     ) continue;
+        if ( m->MinValChoice < Profiles [i].MinValChoice ) continue;
+        if ( m->EarModelFlag < Profiles [i].EarModelFlag ) continue;
+        if ( m->Ltq_offset   > Profiles [i].Ltq_offset   ) continue;
+        if ( m->Ltq_max      > Profiles [i].Ltq_max      ) continue;                     // offset should normally be considered here
+        if ( m->TMN + TMNStereoAdj [m->MS_Channelmode] <
              Profiles [i].TMN + TMNStereoAdj [Profiles [i].MS_Channelmode] )
                                                         continue;
-        if ( NMT + NMTStereoAdj [MS_Channelmode] <
+        if ( m->NMT + NMTStereoAdj [m->MS_Channelmode] <
              Profiles [i].NMT + NMTStereoAdj [Profiles [i].MS_Channelmode] )
                                                         continue;
-        if ( minSMR       < Profiles [i].minSMR       ) continue;
-        if ( Bandwidth    < Profiles [i].BandWidth    ) continue;
-        if ( tmpMask_used < Profiles [i].tmpMask_used ) continue;
-        if ( CVD_used     < Profiles [i].CVD_used     ) continue;
+		if ( m->minSMR       < Profiles [i].minSMR       ) continue;
+        if ( m->Bandwidth    < Profiles [i].BandWidth    ) continue;
+		if ( m->tmpMask_used < Profiles [i].tmpMask_used ) continue;
+		if ( m->CVD_used     < Profiles [i].CVD_used     ) continue;
      // if ( varLtq       > Profiles [i].varLtq       ) continue;
      // if ( NS_Order     < Profiles [i].NS_Order     ) continue;
@@ -887,5 +883,5 @@
 
 static void
-SetQualityParams ( float qual )
+SetQualityParams (PsyModel * m, float qual )
 {
     int    i;
@@ -908,21 +904,21 @@
 
     MainQual       = i;
-    ShortThr       = Profiles [i].ShortThr   * (1-mix) + Profiles [i+1].ShortThr   * mix;
-    MinValChoice   = Profiles [i].MinValChoice  ;
-    EarModelFlag   = Profiles [i].EarModelFlag  ;
-    Ltq_offset     = Profiles [i].Ltq_offset * (1-mix) + Profiles [i+1].Ltq_offset * mix;
-    varLtq         = Profiles [i].varLtq     * (1-mix) + Profiles [i+1].varLtq     * mix;
-    Ltq_max        = Profiles [i].Ltq_max    * (1-mix) + Profiles [i+1].Ltq_max    * mix;
-    TMN            = Profiles [i].TMN        * (1-mix) + Profiles [i+1].TMN        * mix;
-    NMT            = Profiles [i].NMT        * (1-mix) + Profiles [i+1].NMT        * mix;
-    minSMR         = Profiles [i].minSMR        ;
-    Bandwidth      = Profiles [i].BandWidth  * (1-mix) + Profiles [i+1].BandWidth  * mix;
-    tmpMask_used   = Profiles [i].tmpMask_used  ;
-    CVD_used       = Profiles [i].CVD_used      ;
-    MS_Channelmode = Profiles [i].MS_Channelmode;
+    m->ShortThr       = Profiles [i].ShortThr   * (1-mix) + Profiles [i+1].ShortThr   * mix;
+    m->MinValChoice   = Profiles [i].MinValChoice  ;
+    m->EarModelFlag   = Profiles [i].EarModelFlag  ;
+    m->Ltq_offset     = Profiles [i].Ltq_offset * (1-mix) + Profiles [i+1].Ltq_offset * mix;
+    m->varLtq         = Profiles [i].varLtq     * (1-mix) + Profiles [i+1].varLtq     * mix;
+    m->Ltq_max        = Profiles [i].Ltq_max    * (1-mix) + Profiles [i+1].Ltq_max    * mix;
+    m->TMN            = Profiles [i].TMN        * (1-mix) + Profiles [i+1].TMN        * mix;
+    m->NMT            = Profiles [i].NMT        * (1-mix) + Profiles [i+1].NMT        * mix;
+    m->minSMR         = Profiles [i].minSMR        ;
+    m->Bandwidth      = Profiles [i].BandWidth  * (1-mix) + Profiles [i+1].BandWidth  * mix;
+    m->tmpMask_used   = Profiles [i].tmpMask_used  ;
+    m->CVD_used       = Profiles [i].CVD_used      ;
+    m->MS_Channelmode = Profiles [i].MS_Channelmode;
     CombPenalities = Profiles [i].CombPenalities;
-    NS_Order       = Profiles [i].NS_Order      ;
+    m->NS_Order       = Profiles [i].NS_Order      ;
     PNS            = Profiles [i].PNS        * (1-mix) + Profiles [i+1].PNS        * mix;
-    TransDetect    = Profiles [i].TransDetect* (1-mix) + Profiles [i+1].TransDetect* mix;
+    m->TransDetect    = Profiles [i].TransDetect* (1-mix) + Profiles [i+1].TransDetect* mix;
 }
 
@@ -931,5 +927,5 @@
 
 static int
-EvalParameters ( int argc, char** argv, char** InputFile, char** OutputFile, int onlyfilenames )
+EvalParameters (PsyModel * m, int argc, char** argv, char** InputFile, char** OutputFile, int onlyfilenames )
 {
     int          k;
@@ -989,27 +985,27 @@
         }
         else if ( 0 == strcmp ( arg, "telephone" ) ) {                                   // MainQual
-            SetQualityParams (2.0);
+            SetQualityParams (m, 2.0);
         }
         else if ( 0 == strcmp ( arg, "thumb" ) ) {                                       // MainQual
-            SetQualityParams (3.0);
+            SetQualityParams (m, 3.0);
         }
         else if ( 0 == strcmp ( arg, "radio"   ) ) {
-            SetQualityParams (4.0);
+            SetQualityParams (m, 4.0);
         }
         else if ( 0 == strcmp ( arg, "standard")  ||  0 == strcmp ( arg, "normal") ) {
-            SetQualityParams (5.0);
+            SetQualityParams (m, 5.0);
         }
         else if ( 0 == strcmp ( arg, "xtreme")  ||  0 == strcmp ( arg, "extreme") ) {
-            SetQualityParams (6.0);
+            SetQualityParams (m, 6.0);
         }
         else if ( 0 == strcmp ( arg, "insane") ) {
-            SetQualityParams (7.0);
+            SetQualityParams (m, 7.0);
         }
         else if ( 0 == strcmp ( arg, "braindead") ) {
-            SetQualityParams (8.0);
+            SetQualityParams (m, 8.0);
         }
         else if ( 0 == strcmp ( arg, "quality") ) {                                      // Quality
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            SetQualityParams (atof (argv[k]) );
+            SetQualityParams (m, atof (argv[k]) );
         }
         else if ( 0 == strcmp ( arg, "neveroverwrite") ) {                              // NeverOverWrite
@@ -1037,5 +1033,5 @@
         else if ( 0 == strcmp ( arg, "kbd") ) {                                       // ScalingFactor
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            if ( 2 != sscanf ( argv[k], "%f,%f", &KBD1, &KBD2 ))
+			if ( 2 != sscanf ( argv[k], "%f,%f", &(m->KBD1), &(m->KBD2) ))
                 { stderr_printf ( "%s: missing two arguments", arg ); return -1; }
             Init_FFT ();
@@ -1073,6 +1069,6 @@
         else if ( 0 == strcmp ( arg, "ans") ) {                                         // AdaptiveNoiseShaping
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            NS_Order = atoi (argv[k]);
-            NS_Order = mini ( NS_Order, MAX_NS_ORDER );
+            m->NS_Order = atoi (argv[k]);
+            m->NS_Order = mini ( m->NS_Order, MAX_NS_ORDER );
         }
         else if ( 0 == strcmp ( arg, "predict") ) {                                     // AdaptiveNoiseShaping
@@ -1083,5 +1079,5 @@
         else if ( 0 == strcmp ( arg, "ltq_var")  ||  0 == strcmp ( arg, "ath_var") ) {  // ltq_var
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            varLtq = atof (argv[k]);
+            m->varLtq = atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "pns") ) {                                         // pns
@@ -1091,13 +1087,13 @@
         else if ( 0 == strcmp ( arg, "minval") ) {                                      // MinValChoice
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            MinValChoice = atoi (argv[k]);
+            m->MinValChoice = atoi (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "transdet") ) {                                    // TransDetect
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            TransDetect = (float) atof (argv[k]);
+            m->TransDetect = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "shortthr") ) {                                    // ShortThr
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            ShortThr = (float) atof (argv[k]);
+            m->ShortThr = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "noxlevel") ) {                                      // Xlevel
@@ -1109,37 +1105,37 @@
         else if ( 0 == strcmp ( arg, "nmt") ) {                                         // NMT
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg );  return -1; }
-            NMT = (float) atof (argv[k]);
+            m->NMT = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "tmn") ) {                                         // TMN
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg );  return -1; }
-            TMN = (float) atof (argv[k]);
+            m->TMN = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "cvd") ) {                                         // ClearVoiceDetection
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            CVD_used = atoi (argv[k]);
-            if ( CVD_used == 0 )
+            m->CVD_used = atoi (argv[k]);
+            if ( m->CVD_used == 0 )
                 stderr_printf ( "\nDisabling CVD always reduces quality!\a\n" );
         }
         else if ( 0 == strcmp ( arg, "ms") ) {                                          // Mid/Side Stereo
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            MS_Channelmode = atoi (argv[k]);
+            m->MS_Channelmode = atoi (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "minSMR") ) {                                      // minimum SMR
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            if ( minSMR > (float) atof (argv[k]) )
+            if ( m->minSMR > (float) atof (argv[k]) )
                 stderr_printf ( "This option usage may reduces quality!\a\n" );
-            minSMR = (float) atof (argv[k]);
+            m->minSMR = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "tmpMask") ) {                                     // temporal post-masking
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            tmpMask_used = atoi (argv[k]);
+            m->tmpMask_used = atoi (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "ltq_max")  ||  0 == strcmp ( arg, "ath_max") ) {  // Maximum for threshold in quiet
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg );  return -1; }
-            Ltq_max = (float) atof (argv[k]);
+			m->Ltq_max = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "ltq_gain")  ||  0 == strcmp ( arg, "ath_gain") ) {// Offset for threshold in quiet
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            Ltq_offset = (float) atof (argv[k]);
+			m->Ltq_offset = (float) atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "silent")  ||  0 == strcmp ( arg, "quiet") ) {
@@ -1152,5 +1148,5 @@
         else if ( 0 == strcmp ( arg, "ltq")  ||  0 == strcmp ( arg, "ath") ) {          // threshold in quiet
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            EarModelFlag = atoi (argv[k]);
+            m->EarModelFlag = atoi (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "noco") ) {
@@ -1178,5 +1174,5 @@
         else if ( 0 == strcmp ( arg, "bw")  ||  0 == strcmp ( arg, "lowpass") ) {       // bandwidth
             if ( ++k >= argc ) { stderr_printf ( errmsg, arg ); return -1; }
-            Bandwidth = atof (argv[k]);
+			m->Bandwidth = atof (argv[k]);
         }
         else if ( 0 == strcmp ( arg, "displayupdatetime") ) {
@@ -1353,5 +1349,5 @@
     }
 
-    TestProfileParams ();
+    TestProfileParams (m);
     return 0;
 }
@@ -1359,5 +1355,5 @@
 
 static void
-ShowParameters ( char* inDatei, char* outDatei )
+ShowParameters (PsyModel * m, char* inDatei, char* outDatei )
 {
     static const char        unk      []       = "???";
@@ -1399,26 +1395,26 @@
         if ( ScalingFactorr != 1.  ||  ScalingFactorl != 1.  ||  verbose > 1 )
             stderr_printf ( " Scaling input by         : left %.5f, right: %.5f\n", ScalingFactorl, ScalingFactorr );
-        stderr_printf ( " Maximum encoded bandwidth: %4.1f kHz\n", (Max_Band+1) * (SampleFreq/32./2000.) );
-        stderr_printf ( " Adaptive Noise Shaping   : max. %s order\n", th [NS_Order] );
-        stderr_printf ( " Clear Voice Detection    : %s\n", able [CVD_used] );
-        stderr_printf ( " Mid/Side Stereo          : %s\n", stereo [MS_Channelmode] );
+        stderr_printf ( " Maximum encoded bandwidth: %4.1f kHz\n", (m->Max_Band+1) * (m->SampleFreq/32./2000.) );
+        stderr_printf ( " Adaptive Noise Shaping   : max. %s order\n", th [m->NS_Order] );
+        stderr_printf ( " Clear Voice Detection    : %s\n", able [m->CVD_used] );
+        stderr_printf ( " Mid/Side Stereo          : %s\n", stereo [m->MS_Channelmode] );
         stderr_printf ( " Threshold of Hearing     : Model %3u: %s, Max ATH: %2.0f dB, Offset: %+1.0f dB, +Offset@20 kHz:%3.0f dB\n",
-                        EarModelFlag,
-                        EarModelFlag/100 < sizeof(EarModel)/sizeof(*EarModel) ? EarModel [EarModelFlag/100] : unk,
-                        Ltq_max,
-                        Ltq_offset,
-                        -0.6 * (int) (EarModelFlag % 100 - 50) );
-        if ( NMT !=  6.5 || verbose > 1 )
-            stderr_printf ( " Noise masks Tone Ratio   : %4.1f dB\n", NMT );
-        if ( TMN != 18.0 || verbose > 1 )
-            stderr_printf ( " Tone masks Noise Ratio   : %4.1f dB\n", TMN );
+                        m->EarModelFlag,
+						m->EarModelFlag/100 < sizeof(EarModel)/sizeof(*EarModel) ? EarModel [m->EarModelFlag/100] : unk,
+                        m->Ltq_max,
+                        m->Ltq_offset,
+                        -0.6 * (int) (m->EarModelFlag % 100 - 50) );
+		if ( m->NMT !=  6.5 || verbose > 1 )
+			stderr_printf ( " Noise masks Tone Ratio   : %4.1f dB\n", m->NMT );
+		if ( m->TMN != 18.0 || verbose > 1 )
+			stderr_printf ( " Tone masks Noise Ratio   : %4.1f dB\n", m->TMN );
         if ( PNS > 0 )
             stderr_printf ( " PNS Threshold            : %4.2f\n", PNS );
-        if ( !tmpMask_used )
+		if ( !m->tmpMask_used )
             stderr_printf ( " No exploitation of temporal post masking\n" );
         else if ( verbose > 1 )
             stderr_printf ( " Exploitation of temporal post masking\n" );
-        if ( minSMR > 0. )
-            stderr_printf ( " Minimum Signal-to-Mask   : %4.1f dB\n", minSMR );
+		if ( m->minSMR > 0. )
+			stderr_printf ( " Minimum Signal-to-Mask   : %4.1f dB\n", m->minSMR );
         else if ( verbose > 1 )
             stderr_printf ( " No minimum SMR (psycho model controlled filtering)\n" );
@@ -1440,8 +1436,8 @@
 
 static const char*
-PrintTime ( UintMax_t samples, int sign )
+PrintTime ( PsyModel* m, UintMax_t samples, int sign )
 {
     static char  ret [32];
-    Ulong        tmp  = (Ulong) ( UintMAX_FP(samples) * 100. / SampleFreq );
+	Ulong        tmp  = (Ulong) ( UintMAX_FP(samples) * 100. / m->SampleFreq );
     Uint         hour = (Uint)  ( tmp / 360000     );
     Uint         min  = (Uint)  ( tmp / 6000 %  60 );
@@ -1450,5 +1446,5 @@
 
 
-    if ( UintMAX_FP(samples) >= SampleFreq * 360000. )
+	if ( UintMAX_FP(samples) >= m->SampleFreq * 360000. )
         return "            ";
     else if ( hour > 9 )
@@ -1467,5 +1463,6 @@
 
 static void
-ShowProgress ( UintMax_t  samples,
+ShowProgress ( PsyModel* m,
+			   UintMax_t  samples,
                UintMax_t  total_samples,
                UintMax_t  databits )
@@ -1491,6 +1488,6 @@
 
     percent     = 100.f    * UintMAX_FP(samples) / UintMAX_FP(total_samples);
-    kbps        =   1.e-3f * UintMAX_FP(databits) * SampleFreq / UintMAX_FP(samples);
-    speed       =   1.f    * UintMAX_FP(samples) * (CLOCKS_PER_SEC / SampleFreq) / (unsigned long)(curr - start) ;
+	kbps        =   1.e-3f * UintMAX_FP(databits) * m->SampleFreq / UintMAX_FP(samples);
+	speed       =   1.f    * UintMAX_FP(samples) * (CLOCKS_PER_SEC / m->SampleFreq) / (unsigned long)(curr - start) ;
     total_estim =   1.f    * UintMAX_FP(total_samples) / UintMAX_FP(samples) * (unsigned long)(curr - start);
 
@@ -1508,13 +1505,13 @@
 
     // 2x duration in WAVE file time (encoded/total)
-    stderr_printf ("%10.10s" , PrintTime ( samples      , (char)' ')+1 );
-    stderr_printf ("%10.10s ", PrintTime ( total_samples, (char)' ')+1 );
+    stderr_printf ("%10.10s" , PrintTime ( m, samples      , (char)' ')+1 );
+    stderr_printf ("%10.10s ", PrintTime ( m, total_samples, (char)' ')+1 );
 
     // 2x coding time (encoded/total)
-    stderr_printf ("%10.10s" , PrintTime ( (curr - start) * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );
-    stderr_printf ("%10.10s ", PrintTime ( total_estim    * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );
+	stderr_printf ("%10.10s" , PrintTime ( m, (curr - start) * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );
+	stderr_printf ("%10.10s ", PrintTime ( m, total_estim    * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1 );
 
     // ETA
-    stderr_printf ( "%10.10s\r", samples < total_samples  ?  PrintTime ((total_estim - curr + start) * (SampleFreq/CLOCKS_PER_SEC), (char)' ')+1  :  "" );
+	stderr_printf ( "%10.10s\r", samples < total_samples  ?  PrintTime (m, (total_estim - curr + start) * (m->SampleFreq/CLOCKS_PER_SEC), (char)' ')+1  :  "" );
     fflush ( stderr );
 
@@ -1542,4 +1539,27 @@
 	unsigned n;
 	for(n=0;n<count;n++) buffer[n] = val;
+}
+
+
+void
+		OverdriveReport ( mpc_encoder_t * e )
+{
+	if ( e->Overflows > 0 ) {                                                // report internal clippings
+		if ( XLevel == 0 ) {
+			stderr_printf ( "\n"
+					"\033[1m\rWARNING:\n"
+					"\033[0m\r  There occured %u internal clippings due to a restriction of StreamVersion 7.\n"
+					"  Re-encode with '--scale %.3f', or use option '--xlevel', which normally can\n"
+					"  handle this situation but don't work well with old decoders.\a\n\n",
+			e->Overflows, ScalingFactorl * 32767. / MaxOverFlow - 0.0005f );
+		}
+		else {
+			stderr_printf ( "\n"
+					"\033[1m\rWARNING:\n"
+					"\033[0m\r  There still occured %u SCF clippings due to a restriction of StreamVersion 7.\n"
+					"  Use the '--scale' method to avoid additional distortions. Note that this\n"
+					"  file already has annoying distortions due to slovenly CD mastering.\a\n\n", e->Overflows );
+		}
+	}
 }
 
@@ -1569,5 +1589,18 @@
     int              TransientR [PART_SHORT];   // Flag of transient detection
     int              Transient  [32];           // Flag of transient detection
-
+	PsyModel         m;
+	mpc_encoder_t    e;
+
+    // initialize tables which must be initialized once and only once
+#ifdef FAST_MATH
+    Init_FastMath ();                           // check if something has to be done for each file !!
+#endif
+    Init_SV7 ();
+    Init_Psychoakustiktabellen (&m);
+	Init_Skalenfaktoren ();
+	Init_Psychoakustik (&m);
+	Init_FPU ();
+	Init_ANS ();
+	Klemm    ();
 
     // initialize PCM-data
@@ -1575,5 +1608,5 @@
 
     // open WAV file
-    if ( EvalParameters ( argc, argv, &InputName, &OutputName, 1 ) < 0 )
+    if ( EvalParameters (&m,  argc, argv, &InputName, &OutputName, 1 ) < 0 )
         return 1;
     if ( Open_WAV_Header ( &Wave, InputName ) < 0 ) {
@@ -1590,5 +1623,5 @@
     }
 
-    SampleFreq    = Wave.SampleFreq;
+    m.SampleFreq    = Wave.SampleFreq;
     SamplesInWAVE = Wave.PCMSamples;
 
@@ -1617,7 +1650,7 @@
     }
 
-    SetQualityParams (5.0);
-
-    if ( EvalParameters ( argc, argv, &InputName, &OutputName, 0 ) < 0 )
+    SetQualityParams (&m, 5.0);
+
+    if ( EvalParameters (&m, argc, argv, &InputName, &OutputName, 0 ) < 0 )
         return 1;
 
@@ -1626,5 +1659,5 @@
     }
 
-    Init_Psychoakustiktabellen ();              // must be done AFTER decoding command line parameters
+    Init_Psychoakustiktabellen (&m);              // must be done AFTER decoding command line parameters
 
     // check fade-length
@@ -1684,10 +1717,10 @@
 #endif
 
-    ShowParameters ( InputName, OutputName );
+    ShowParameters (&m, InputName, OutputName );
     if ( WIN32_MESSAGES  &&  FrontendPresent )
         SendModeMessage (MainQual);
 
     if ( SkipTime > 0. ) {
-        unsigned long  SkipSamples = SampleFreq * SkipTime;
+        unsigned long  SkipSamples = m.SampleFreq * SkipTime;
         ssize_t        read;
 
@@ -1701,11 +1734,11 @@
     }
 
-    BufferedBits     = 0;
+    e.BufferedBits     = 0;
     LastValidFrame   = (SamplesInWAVE + BLOCK - 1) / BLOCK;
     LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1;
-    WriteHeader_SV7 ( Max_Band, MainQual, MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, SampleFreq );
+    WriteHeader_SV7 ( m.Max_Band, MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, m.SampleFreq );
 
     // initialize timer
-    ShowProgress ( 0, SamplesInWAVE, BufferedBits );
+    ShowProgress (&m, 0, SamplesInWAVE, e.BufferedBits );
     T            = time ( NULL );
 
@@ -1722,10 +1755,10 @@
 	}
 
-	Analyse_Init ( Main.L[CENTER], Main.R[CENTER], X, Max_Band );
+	Analyse_Init ( Main.L[CENTER], Main.R[CENTER], X, m.Max_Band );
 
     // adapt SamplesInWAVE to the real number of contained samples
     if ( myfeof (Wave.fp) ) {
         stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s    \n",
-                        UintMAX_FP(AllSamplesRead) / SampleFreq, UintMAX_FP(SamplesInWAVE) / SampleFreq );
+						UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq );
         SamplesInWAVE = AllSamplesRead;
 
@@ -1766,37 +1799,37 @@
 
         if ( !Silence  ||  !OldSilence ) {
-            Analyse_Filter ( &Main, X, Max_Band );                      // Analysis-Filterbank (Main -> X)
-            SMR = Psychoakustisches_Modell ( Max_Band*0+31, &Main, TransientL, TransientR );    // Psychoacoustics return SMRs for input data 'Main'
-            if ( minSMR > 0 )
-                RaiseSMR ( Max_Band, &SMR );                            // Minimum-operation on SBRs (full bandwidth)
-            if ( MS_Channelmode > 0 )
-                MS_LR_Entscheidung ( Max_Band, MS_Flag, &SMR, X );      // Selection of M/S- or L/R-Coding
-            SCF_Extraktion ( Max_Band, X );                             // Extraction of the scalefactors and normalization of the subband samples
+            Analyse_Filter ( &Main, X, m.Max_Band );                      // Analysis-Filterbank (Main -> X)
+			SMR = Psychoakustisches_Modell (&m, m.Max_Band*0+31, &Main, TransientL, TransientR );    // Psychoacoustics return SMRs for input data 'Main'
+            if ( m.minSMR > 0 )
+				RaiseSMR (&m, m.Max_Band, &SMR );                            // Minimum-operation on SBRs (full bandwidth)
+			if ( m.MS_Channelmode > 0 )
+				MS_LR_Entscheidung ( m.Max_Band, MS_Flag, &SMR, X );      // Selection of M/S- or L/R-Coding
+			SCF_Extraktion (&m, &e, m.Max_Band, X );                             // Extraction of the scalefactors and normalization of the subband samples
             TransientenCalc ( Transient, TransientL, TransientR );
-            if ( NS_Order > 0 ) {
-                NS_Analyse ( Max_Band, MS_Flag, SMR, Transient );                  // calculate possible ANS-Filter and the expected gain
+			if ( m.NS_Order > 0 ) {
+				NS_Analyse (&m, m.Max_Band, MS_Flag, SMR, Transient );                  // calculate possible ANS-Filter and the expected gain
             }
 
-            Allocate ( Max_Band, Res_L, X[0].L, SCF_Index_L[0], SNR_comp_L, SMR.L, Power_L, Transient );   // allocate bits for left + right channel
-            Allocate ( Max_Band, Res_R, X[0].R, SCF_Index_R[0], SNR_comp_R, SMR.R, Power_R, Transient );
-
-            Quantisierung ( Max_Band, Res_L, Res_R, X, Q );             // quantize samples
-        }
-
-        if ( Zaehler >= BUFFER_ALMOST_FULL  ||  LowDelay ) {
-            FlushBitstream ( OutputFile, Buffer, Zaehler );
-            Zaehler = 0;
+            Allocate ( m.Max_Band, Res_L, X[0].L, SCF_Index_L[0], m.SNR_comp_L, SMR.L, Power_L, Transient );   // allocate bits for left + right channel
+			Allocate ( m.Max_Band, Res_R, X[0].R, SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient );
+
+			Quantisierung (&m, m.Max_Band, Res_L, Res_R, X, Q );             // quantize samples
+        }
+
+        if ( e.Zaehler >= BUFFER_ALMOST_FULL  ||  LowDelay ) {
+            FlushBitstream ( OutputFile, e.Buffer, e.Zaehler );
+            e.Zaehler = 0;
          }
 
         OldSilence      = Silence;
-        OldBufferedBits = BufferedBits;
+        OldBufferedBits = e.BufferedBits;
         GetBitstreamPos    ( &bitstreampos );
         WriteBits          ( 0, 20 );                                                      // Reserve 20 bits for jump-information
-        WriteBitstream_SV7 ( Max_Band, Q );                                                // write SV7-Bitstream
-        WriteBitsAt        ( (Uint32_t)(BufferedBits - OldBufferedBits - 20), 20, bitstreampos );      // Patch 20 bits for jump-information to the right value
+        WriteBitstream_SV7 ( m.Max_Band, Q );                                                // write SV7-Bitstream
+        WriteBitsAt        ( (Uint32_t)(e.BufferedBits - OldBufferedBits - 20), 20, bitstreampos );      // Patch 20 bits for jump-information to the right value
 
         if ( (Int)(time (NULL) - T) >= 0 ) {                            // output
             T += labs (DisplayUpdateTime);
-            ShowProgress ( (UintMax_t)(N+1) * BLOCK, SamplesInWAVE, BufferedBits );
+            ShowProgress (&m, (UintMax_t)(N+1) * BLOCK, SamplesInWAVE, e.BufferedBits );
         }
 
@@ -1821,5 +1854,5 @@
         if ( myfeof (Wave.fp) ) {
             stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s    \n",
-                            UintMAX_FP(AllSamplesRead) / SampleFreq, UintMAX_FP(SamplesInWAVE) / SampleFreq );
+							UintMAX_FP(AllSamplesRead) / m.SampleFreq, UintMAX_FP(SamplesInWAVE) / m.SampleFreq );
             SamplesInWAVE = AllSamplesRead;
 
@@ -1843,8 +1876,8 @@
     // write the last incomplete word to buffer, so it's written during the next flush
     FinishBitstream();
-    ShowProgress ( SamplesInWAVE, SamplesInWAVE, BufferedBits );
-
-    FlushBitstream ( OutputFile, Buffer, Zaehler );
-    Zaehler = 0;
+    ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.BufferedBits );
+
+    FlushBitstream ( OutputFile, e.Buffer, e.Zaehler );
+    e.Zaehler = 0;
 
     UpdateHeader ( OutputFile, LastValidFrame, LastValidSamples );
@@ -1862,28 +1895,8 @@
 
     stderr_printf ( "\n" );
+
+	OverdriveReport (&e);                         // output a report if clipping was necessary
+
     return 0;
-}
-
-
-void
-OverdriveReport ( void )
-{
-    if ( Overflows > 0 ) {                                                // report internal clippings
-        if ( XLevel == 0 ) {
-            stderr_printf ( "\n"
-                            "\033[1m\rWARNING:\n"
-                            "\033[0m\r  There occured %u internal clippings due to a restriction of StreamVersion 7.\n"
-                            "  Re-encode with '--scale %.3f', or use option '--xlevel', which normally can\n"
-                            "  handle this situation but don't work well with old decoders.\a\n\n",
-                            Overflows, ScalingFactorl * 32767. / MaxOverFlow - 0.0005f );
-        }
-        else {
-            stderr_printf ( "\n"
-                            "\033[1m\rWARNING:\n"
-                            "\033[0m\r  There still occured %u SCF clippings due to a restriction of StreamVersion 7.\n"
-                            "  Use the '--scale' method to avoid additional distortions. Note that this\n"
-                            "  file already has annoying distortions due to slovenly CD mastering.\a\n\n", Overflows );
-        }
-    }
 }
 
@@ -1915,5 +1928,6 @@
     // no arguments or call for help
     if ( argc < 2  ||  0==strcmp (argv[1],"-h")  ||  0==strcmp (argv[1],"-?")  ||  0==strcmp (argv[1],"--help") ) {
-        SetQualityParams (5.0);
+		PsyModel m;
+        SetQualityParams (&m, 5.0);
         dup2 ( 1, 2 );
         shorthelp ();
@@ -1922,25 +1936,12 @@
 
     if ( 0==strcmp (argv[1],"--longhelp")  ||  0==strcmp (argv[1],"-??") ) {
-        SetQualityParams (5.0);
+		PsyModel m;
+        SetQualityParams (&m, 5.0);
         dup2 ( 1, 2 );
-        longhelp ();
+        longhelp (&m);
         return 1;
     }
 
-    // initialize tables which must be initialized once and only once
-#ifdef FAST_MATH
-    Init_FastMath ();                           // check if something has to be done for each file !!
-#endif
-    Init_SV7 ();
-    Init_Psychoakustiktabellen ();
-    Init_Skalenfaktoren ();
-    Init_Psychoakustik ();
-    Init_FPU ();
-    Init_ANS ();
-    Klemm    ();
-
     ret = mainloop ( argc, argv );              // analyze command line and do the requested work
-
-    OverdriveReport ();                         // output a report if clipping was necessary
 
     if(IsEndBeep)
Index: mppenc/branches/r2d/src/mppenc.h
===================================================================
--- mppenc/branches/r2d/src/mppenc.h	(revision 64)
+++ mppenc/branches/r2d/src/mppenc.h	(revision 65)
@@ -26,6 +26,10 @@
 #endif
 
+#include "libmpcenc.h"
+#include "libmpcpsy.h"
+#include "datatypes.h"
+#include "minimax.h"
+
 #include "mppdec.h"
-#include "minimax.h"
 
 //#define IO_BUFFERING                          // activates IO-buffer (default: off)
@@ -53,29 +57,20 @@
 } wave_t;
 
-// analy_filter.c
-void   Analyse_Filter(const PCMDataTyp*, SubbandFloatTyp*, const int);
-void   Analyse_Init ( float Left, float Right, SubbandFloatTyp* out, const int MaxBand );
-
-void   Klemm ( void );
-
 // ans.c
-extern unsigned int  NS_Order;                          // global Flag for Noise Shaping
-extern unsigned int  NS_Order_L [32];
-extern unsigned int  NS_Order_R [32];                   // order of the Adaptive Noiseshaping (0: off, 1...5: on)
-extern float         FIR_L     [32] [MAX_NS_ORDER];
-extern float         FIR_R     [32] [MAX_NS_ORDER];     // contains FIR-Filter for NoiseShaping
-extern float         ANSspec_L [MAX_ANS_LINES];
-extern float         ANSspec_R [MAX_ANS_LINES];         // L/R-masking threshold for ANS
-extern float         ANSspec_M [MAX_ANS_LINES];
-extern float         ANSspec_S [MAX_ANS_LINES];         // M/S-masking threshold for ANS
-
-void   Init_ANS   ( void );
-void   NS_Analyse ( const int, const unsigned char* MS, const SMRTyp, const int* Transient );
-
-
-extern Uint32_t      Buffer [BUFFER_FULL];      // buffer for bitstream file (128 KB)
-extern Uint32_t      dword;                     // 32 bit-Word for Bitstream-I/O
-extern unsigned int  Zaehler;                   // position counter for processed bitstream word (32 bit)
-extern UintMax_t     BufferedBits;              // counter for the number of written bits in the bitstream
+// extern unsigned int  NS_Order;                          // global Flag for Noise Shaping
+// extern unsigned int  NS_Order_L [32];
+// extern unsigned int  NS_Order_R [32];                   // order of the Adaptive Noiseshaping (0: off, 1...5: on)
+// extern float         FIR_L     [32] [MAX_NS_ORDER];
+// extern float         FIR_R     [32] [MAX_NS_ORDER];     // contains FIR-Filter for NoiseShaping
+// extern float         ANSspec_L [MAX_ANS_LINES];
+// extern float         ANSspec_R [MAX_ANS_LINES];         // L/R-masking threshold for ANS
+// extern float         ANSspec_M [MAX_ANS_LINES];
+// extern float         ANSspec_S [MAX_ANS_LINES];         // M/S-masking threshold for ANS
+
+
+// extern Uint32_t      Buffer [BUFFER_FULL];      // buffer for bitstream file (128 KB)
+// extern Uint32_t      dword;                     // 32 bit-Word for Bitstream-I/O
+// extern unsigned int  Zaehler;                   // position counter for processed bitstream word (32 bit)
+// extern UintMax_t     BufferedBits;              // counter for the number of written bits in the bitstream
 
 void  FlushBitstream    ( FILE* fp, const Uint32_t* buffer, size_t words32bit );
@@ -101,34 +96,20 @@
 void   Generate_FFT_Tables ( const int, int*, float* );
 
-
-// mppenc.c
-extern float         SNR_comp_L [32];
-extern float         SNR_comp_R [32];   // SNR-compensation after SCF-combination and ANS-gain
-extern unsigned int  MS_Channelmode;    // global flag for enhanced functionality
-extern unsigned int  Overflows;
-extern float         SampleFreq;
-extern float         Bandwidth;
-extern float         KBD1;
-extern float         KBD2;
-
-// psy.c
-extern unsigned int  CVD_used;          // global flag for ClearVoiceDetection (more switches for the psychoacoustic model)
-extern float         varLtq;            // variable threshold in quiet
-extern unsigned int  tmpMask_used;      // global flag for temporal masking
-extern float         ShortThr;          // factor for calculation masking threshold with transients
-extern float         minSMR;            // minimum SMR for all subbands
-
-void   Init_Psychoakustik       ( void );
-SMRTyp Psychoakustisches_Modell ( const int, const PCMDataTyp*, int* TransientL, int* TransientR );
+// FIXME : put in lib header
+void   Init_Psychoakustik       ( PsyModel* );
+SMRTyp Psychoakustisches_Modell ( PsyModel *, const int, const PCMDataTyp*, int* TransientL, int* TransientR );
 void   TransientenCalc          ( int* Transient, const int* TransientL, const int* TransientR );
-void   RaiseSMR                 ( const int, SMRTyp* );
+void   RaiseSMR                 ( PsyModel*, const int, SMRTyp* );
 void   MS_LR_Entscheidung       ( const int, unsigned char* MS, SMRTyp*, SubbandFloatTyp* );
-
+void   Init_Psychoakustiktabellen ( PsyModel* );
+
+void   Init_ANS   ( void );
+void   NS_Analyse (PsyModel*, const int, const unsigned char* MS, const SMRTyp, const int* Transient );
+
+void   Analyse_Filter(const PCMDataTyp*, SubbandFloatTyp*, const int);
+void   Analyse_Init ( float Left, float Right, SubbandFloatTyp* out, const int MaxBand );
+void   Klemm ( void );
 
 // psy_tab.c
-extern int          MinValChoice;               // Flag for calculation of MinVal-values
-extern unsigned int EarModelFlag;               // Flag for threshold in quiet
-extern float        Ltq_offset;                 // Offset for threshold in quiet
-extern float        Ltq_max;                    // maximum level for threshold in quiet
 extern float        fftLtq   [512];             // threshold in quiet (FFT)
 extern float        partLtq  [PART_LONG];       // threshold in quiet (Partitions)
@@ -137,7 +118,4 @@
 extern float        MinVal   [PART_LONG];       // minimum quality that's adapted to the model, minval for long
 extern float        SPRD     [PART_LONG] [PART_LONG]; // tabulated spreading function
-extern float        TMN;                        // Offset for purely sinusoid components
-extern float        NMT;                        // Offset for purely noisy components
-extern float        TransDetect;                // minimum slewrate for transient detection
 extern float        O_MAX;
 extern float        O_MIN;
@@ -153,6 +131,4 @@
 extern const int    wh        [PART_LONG];      // w_high for long
 extern const int    wh_short  [PART_SHORT];     // w_high for short
-
-void   Init_Psychoakustiktabellen ( void );
 
 
Index: mppenc/branches/r2d/src/tags.c
===================================================================
--- mppenc/branches/r2d/src/tags.c	(revision 64)
+++ mppenc/branches/r2d/src/tags.c	(revision 65)
@@ -2,5 +2,5 @@
  *  Encoder tag handling
  *
- *  (C) Frank Klemm 2002. Janne Hyvärinen 2002. All rights reserved.
+ *  (C) Frank Klemm 2002. Janne Hyvï¿œinen 2002. All rights reserved.
  *
  *  Principles:
@@ -1245,5 +1245,5 @@
 
 #ifndef STFU
-    stderr_printf ( "\n  »%s«\n", src );
+    stderr_printf ( "\n  %s\n", src );
 #endif
 
@@ -1272,10 +1272,10 @@
 
             stderr_printf ("\n");
-            stderr_printf ("Artist = »%s«\n", tmp[0] );
-            stderr_printf ("CD     = »%s«\n", merge  );
-            stderr_printf ("Title  = »%s«\n", tmp[2] );
-            stderr_printf ("No#    = »%s«\n", tmp[4] );
-            stderr_printf ("Extent = »%s«\n", tmp[5] );
-            stderr_printf ("Year   = »%s«\n", q  ?  q  :  "????" );
+            stderr_printf ("Artist = %s\n", tmp[0] );
+            stderr_printf ("CD     = %s\n", merge  );
+            stderr_printf ("Title  = %s\n", tmp[2] );
+            stderr_printf ("No#    = %s\n", tmp[4] );
+            stderr_printf ("Extent = %s\n", tmp[5] );
+            stderr_printf ("Year   = %s\n", q  ?  q  :  "????" );
 #if 1
             if ( tmp[0][0]  &&  ! TagKeyExists ( "Artist", 0 ) ) addtag ( "Artist", 0, tmp[0], strlen (tmp[0]), 5, 0 );
