Index: /mppenc/branches/r2d/libmpcenc/Makefile.am
===================================================================
--- /mppenc/branches/r2d/libmpcenc/Makefile.am	(revision 75)
+++ /mppenc/branches/r2d/libmpcenc/Makefile.am	(revision 76)
@@ -2,6 +2,5 @@
 METASOURCES = AUTO
 lib_LIBRARIES = libmpcenc.a
-libmpcenc_a_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c quant.c \
-	tools.c
+libmpcenc_a_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c quant.c
 
 
Index: /mppenc/branches/r2d/libmpcenc/huffsv7.c
===================================================================
--- /mppenc/branches/r2d/libmpcenc/huffsv7.c	(revision 75)
+++ /mppenc/branches/r2d/libmpcenc/huffsv7.c	(revision 76)
@@ -332,12 +332,57 @@
 #endif
 
-
-// FIXME : remove the functions from tools.c
-void Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, mpc_size_t len );
-void Resort_HuffTable ( Huffman_t* const Table, const mpc_size_t elements, mpc_int_t offset );
-void Make_LookupTable ( mpc_uint8_t* LUT, mpc_size_t LUT_len, const Huffman_t* const Table, const mpc_size_t elements );
+/*
+ *  Fills out the items Code and Length (but not Value) of a Huffman table
+ *  from a bit packed Huffman table 'src'. Table is not sorted, so this is
+ *  the table which is suitable for an encoder. Be careful: To get a table
+ *  usable for a decoder you must use Resort_HuffTable() after this
+ *  function. It's a little bit dangerous to divide the functionality, maybe
+ *  there is a more secure and handy solution to this problem.
+ */
+
+void Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, mpc_size_t len )
+{
+	mpc_size_t  i;
+
+	for ( i = 0; i < len; i++,src++,dst++ ) {
+		dst->Code   = src->Code  ;
+		dst->Length = src->Length;
+	}
+}
+
+
+/*
+ *  Generates a Lookup table for quick Huffman decoding. This table must
+ *  have a size of a power of 2. Input is the pre-sorted Huffman table,
+ *  sorted by Resort_HuffTable() and its length, and the length of the
+ *  lookup table. Output is the Lookup table. It can be used for table based
+ *  decoding (Huffman_decode_fastest) which fully decodes by means of the
+ *  LUT. This is only handy for small huffman codes up to 9...10 bit
+ *  maximum length. For longer codes partial lookup is possible with
+ *  Huffman_decode_faster() which first estimates possible codes by means
+ *  of LUT and then searches the exact code like the tableless version
+ *  Huffman_decode().
+ */
+
+void Make_LookupTable ( mpc_uint8_t* LUT,
+						mpc_size_t LUT_len,
+						const Huffman_t* const Table,
+						const mpc_size_t elements )
+{
+	mpc_size_t    i;
+	mpc_size_t    idx  = elements;
+	mpc_uint32_t  dval = (mpc_uint32_t)0x80000000L / LUT_len * 2;
+	mpc_uint32_t  val  = dval - 1;
+
+	for ( i = 0; i < LUT_len; i++, val += dval ) {
+		while ( idx > 0  &&  val >= Table[idx-1].Code )
+			idx--;
+		*LUT++ = (mpc_uint8_t)idx;
+	}
+
+	return;
+}
 
 #define MAKE(d,s)     Make_HuffTable   ( (d), (s), sizeof(s)/sizeof(*(s)) )
-#define SORT(x,o)     Resort_HuffTable ( (x), sizeof(x)/sizeof(*(x)), -(Int)(o) )
 #define LOOKUP(x,q)   Make_LookupTable ( (q), sizeof(q), (x), sizeof(x)/sizeof(*(x)) )
 
Index: penc/branches/r2d/libmpcenc/tools.c
===================================================================
--- /mppenc/branches/r2d/libmpcenc/tools.c	(revision 75)
+++ 	(revision )
@@ -1,199 +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
- */
-
-/*
- *  A list of different mixed tools
- *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- *  Read_LittleEndians()
- *      Portable file handling
- *  Requantize_MidSideStereo(), Requantize_IntensityStereo()
- *      Requantisation of quantized samples for synthesis filter
- *  Resort_HuffTable(), Make_HuffTable(), Make_LookupTable()
- *      Generating and sorting Huffman tables, making fast lookup tables
- */
-
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-
-// FIXME : not sure if it's a good idea
-#include <fpu_control.h>
-
-#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
-
-mpc_size_t
-complete_read ( int fd, void* dest, mpc_size_t bytes )
-{
-    mpc_size_t  bytesread = 0;
-    mpc_size_t  ret;
-
-    while ( bytes > 0 ) {
-        ret = read ( fd, dest, bytes );
-        if ( ret == 0  ||  ret == (mpc_size_t)-1 )
-            break;
-        dest       = (void*)(((char*)dest) + ret);
-        bytes     -= ret;
-        bytesread += ret;
-    }
-    return bytesread;
-}
-
-#endif
-
-
-/*
- *  Change_Endian32() changes the endianess of a 32-bit memory block in-place
- *  by swapping the byte order. This is a little bit tricky, but a well
- *  known method which is much much faster than byte picking, especially on modern CPUs,
- *  because it avoids memory aliasing. Note that this method
- *  is poison for old 16-bit compilers!
- */
-
-#if ENDIAN == HAVE_BIG_ENDIAN
-
-static void
-Change_Endian32 ( mpc_uint32_t* dst, mpc_size_t words32bit )
-{
-
-    for ( ; words32bit--; dst++ ) {
-# if  INT_MAX >= 2147483647L
-        mpc_uint32_t  tmp = *dst;
-        tmp  = ((tmp << 0x10) & 0xFFFF0000) | ((tmp >> 0x10) & 0x0000FFFF);
-        tmp  = ((tmp << 0x08) & 0xFF00FF00) | ((tmp >> 0x08) & 0x00FF00FF);
-        *dst = tmp;
-# else
-        mpc_uint8_t  tmp;
-        tmp                = ((mpc_uint8_t*)dst)[0];
-        ((mpc_uint8_t*)dst)[0] = ((mpc_uint8_t*)dst)[3];
-        ((mpc_uint8_t*)dst)[3] = tmp;
-        tmp                = ((mpc_uint8_t*)dst)[1];
-        ((mpc_uint8_t*)dst)[1] = ((mpc_uint8_t*)dst)[2];
-        ((mpc_uint8_t*)dst)[2] = tmp;
-# endif
-    }
-    return;
-}
-
-#endif /* ENDIAN == HAVE_BIG_ENDIAN */
-
-
-/*
- *  Read_LittleEndians() reads little endian 32-bit ints from the stream
- *  'fp'.  Quantities are selected in 32-bit items. On big endian machines
- *  the byte order is changed in-place after reading the data, so all is
- *  okay.
- */
-
-mpc_size_t
-Read_LittleEndians ( FILE* fp, mpc_uint32_t* dst, mpc_size_t words32bit )
-{
-    mpc_size_t  wordsread;
-    wordsread = READ ( fp, dst, words32bit * sizeof(*dst) ) / sizeof(*dst);
-
-#if ENDIAN == HAVE_BIG_ENDIAN
-    Change_Endian32 ( dst, wordsread );
-#endif
-
-    return wordsread;
-}
-
-/*
- *  Fills out the items Code and Length (but not Value) of a Huffman table
- *  from a bit packed Huffman table 'src'. Table is not sorted, so this is
- *  the table which is suitable for an encoder. Be careful: To get a table
- *  usable for a decoder you must use Resort_HuffTable() after this
- *  function. It's a little bit dangerous to divide the functionality, maybe
- *  there is a more secure and handy solution to this problem.
- */
-
-void
-Make_HuffTable ( Huffman_t* dst, const HuffSrc_t* src, mpc_size_t len )
-{
-    mpc_size_t  i;
-
-    for ( i = 0; i < len; i++,src++,dst++ ) {
-        dst->Code   = src->Code  ;
-        dst->Length = src->Length;
-    }
-}
-
-
-/*
- *  Generates a Lookup table for quick Huffman decoding. This table must
- *  have a size of a power of 2. Input is the pre-sorted Huffman table,
- *  sorted by Resort_HuffTable() and its length, and the length of the
- *  lookup table. Output is the Lookup table. It can be used for table based
- *  decoding (Huffman_decode_fastest) which fully decodes by means of the
- *  LUT. This is only handy for small huffman codes up to 9...10 bit
- *  maximum length. For longer codes partial lookup is possible with
- *  Huffman_decode_faster() which first estimates possible codes by means
- *  of LUT and then searches the exact code like the tableless version
- *  Huffman_decode().
- */
-
-void
-Make_LookupTable ( mpc_uint8_t* LUT, mpc_size_t LUT_len, const Huffman_t* const Table, const mpc_size_t elements )
-{
-    mpc_size_t    i;
-    mpc_size_t    idx  = elements;
-    mpc_uint32_t  dval = (mpc_uint32_t)0x80000000L / LUT_len * 2;
-    mpc_uint32_t  val  = dval - 1;
-
-    for ( i = 0; i < LUT_len; i++, val += dval ) {
-        while ( idx > 0  &&  val >= Table[idx-1].Code )
-            idx--;
-        *LUT++ = (mpc_uint8_t)idx;
-    }
-
-    return;
-}
-
-
-void
-Init_FPU ( void )
-{
-    mpc_uint16_t  cw;
-
-#if   defined __i386__  &&  defined _FPU_GETCW  &&  defined _FPU_SETCW
-    _FPU_GETCW ( cw );
-    cw  &=  ~0x300;
-    _FPU_SETCW ( cw );
-#elif defined __i386__  &&  defined  FPU_GETCW  &&  defined  FPU_SETCW
-    FPU_GETCW ( cw );
-    cw  &=  ~0x300;
-    FPU_SETCW ( cw );
-#elif defined __MINGW32__
-    __asm__ ("fnstcw %0" : "=m" (*&cw));
-    cw  &=  ~0x300;
-    __asm__ ("fldcw %0" : : "m" (*&cw));
-#elif defined(_WIN32) && !defined(_WIN64)
-    _asm { fstcw cw };
-    cw  &=  ~0x300;
-    _asm { fldcw cw };
-#else
-    ;
-#endif
-}
-
-
Index: /mppenc/branches/r2d/libmpcpsy/psy.c
===================================================================
--- /mppenc/branches/r2d/libmpcpsy/psy.c	(revision 75)
+++ /mppenc/branches/r2d/libmpcpsy/psy.c	(revision 76)
@@ -124,4 +124,6 @@
 void   Cepstrum2048  ( float* cep, const int );
 
+void   Init_ANS   ( void );
+
 // Resets Arrays
 void Init_Psychoakustik ( PsyModel* m)
@@ -154,4 +156,6 @@
 	Init_FFT (m);
 
+	Init_ANS ();
+
 	Init_Psychoakustiktabellen (m);
 
@@ -304,18 +308,4 @@
     float         e1;
 
-
-#if 000000
-    for ( n = 0; n < PART_LONG; n++ ) {
-        k  = wh[n] - wl[n];
-        e0 = *spec0++;
-        e1 = *spec1++;
-        while ( k-- ) {
-            e0 += *spec0++;
-            e1 += *spec1++;
-        }
-        *erg0++ = e0;
-        *erg1++ = e1;
-    }
-#else
     n = 0;
 
@@ -355,8 +345,4 @@
         *erg1++ = e1;
     }
-
-#endif
-
-    return;
 }
 
@@ -377,18 +363,4 @@
     float         e1;
 
-
-#if 000000
-    for ( n = 0; n < PART_LONG; n++ ) {
-        e0 = *spec0++ * *cw0++;
-        e1 = *spec1++ * *cw1++;
-        k  = wh[n] - wl[n];
-        while ( k-- ) {
-            e0 += *spec0++ * *cw0++;
-            e1 += *spec1++ * *cw1++;
-        }
-        *erg0++ = e0;
-        *erg1++ = e1;
-    }
-#else
     n = 0;
 
@@ -428,7 +400,4 @@
         *erg1++ = e1;
     }
-#endif
-
-    return;
 }
 
@@ -824,9 +793,4 @@
     for ( n = 0; n < PART_LONG; n++ ) {
         for ( k = wl[n]; k <= wh[n]; k++, thr0++, thr1++ ) {    // threshold in quiet (Partition)
-#if 0
-            ltq   = AdaptedLTQ * fftLtq [k];
-            *thr0 = maxf ( partThr0 [n], ltq );
-            *thr1 = maxf ( partThr1 [n], ltq );
-#else
             // Applies a much more gentle ATH rolloff + 6 dB more dynamic
             ltq   = sqrt (ms * fftLtq [k]);
@@ -835,5 +799,4 @@
             tmp   = sqrt (partThr1 [n]) + ltq;
             *thr1 = tmp * tmp;
-#endif
         }
     }
@@ -878,51 +841,4 @@
 // output: masking threshold *thr in short partitions
 //         Energy of the last short block *preerg in short partitions
-#if 0
-static void
-CalcShortThreshold ( const float  erg [] [128],
-                     const float  PreechoFac,
-                     float*       thr,
-                     float        preerg[2][PART_SHORT],
-                     int*         transient )
-{
-    const int*    lo     = wl_short; // lower FFT-index
-    const int*    hi     = wh_short; // upper FFT-index
-    const float*  iwidth = iw_short; // inverse partition-width
-    int           k;
-    int           n;
-    int           m;
-    float         tmp;
-    float         enrg;
-    float         th;
-    const float*  ep;
-
-    for ( k = 0; k < PART_SHORT; k++, lo++, hi++ ) {
-        transient[k] = 0;
-        th           = 1.e20f;
-        for ( n = 0; n < 4; n++ ) {
-            ep   = erg[n] + *lo;
-            m    = *hi - *lo;
-            enrg = *ep++;
-            while (m--)
-                enrg += *ep++;
-
-            // preecho prevention
-            tmp     = enrg;
-            if (preerg[0][k] < enrg)
-                enrg = preerg[0][k];
-            preerg[0][k] = tmp;
-
-            // is signal transient?
-            if (tmp > TransDetect*enrg) transient[k] = 1;
-
-            // assume short threshold = engr*PreechoFac
-            th    = minf (th, enrg*PreechoFac);
-        }
-        thr[k] = th * *iwidth++;
-    }
-
-    return;
-}
-#else
 static void
 CalcShortThreshold ( PsyModel* m,
@@ -972,6 +888,4 @@
     return;
 }
-
-#endif
 
 // input : previous simultaneous masking threshold *preThr,
Index: /mppenc/branches/r2d/mppenc.kdevelop
===================================================================
--- /mppenc/branches/r2d/mppenc.kdevelop	(revision 75)
+++ /mppenc/branches/r2d/mppenc.kdevelop	(revision 76)
@@ -18,6 +18,6 @@
   <kdevautoproject>
     <general>
-      <activetarget>src/mppenc</activetarget>
-      <useconfiguration>optimized</useconfiguration>
+      <activetarget>libmpcpsy/libmpcpsy.a</activetarget>
+      <useconfiguration>debug</useconfiguration>
     </general>
     <run>
@@ -41,13 +41,13 @@
         <cflags>-O3 -fomit-frame-pointer -pipe -Wall -ffast-math</cflags>
         <envvars/>
-        <configargs></configargs>
-        <topsourcedir></topsourcedir>
+        <configargs/>
+        <topsourcedir/>
         <cppflags>-DMPP_ENCODER=1 -DTRUE=1 -DFALSE=0</cppflags>
-        <ldflags></ldflags>
-        <ccompilerbinary></ccompilerbinary>
-        <cxxcompilerbinary></cxxcompilerbinary>
-        <f77compilerbinary></f77compilerbinary>
-        <cxxflags></cxxflags>
-        <f77flags></f77flags>
+        <ldflags/>
+        <ccompilerbinary/>
+        <cxxcompilerbinary/>
+        <f77compilerbinary/>
+        <cxxflags/>
+        <f77flags/>
       </optimized>
       <debug>
Index: /mppenc/branches/r2d/src/mppdec.h
===================================================================
--- /mppenc/branches/r2d/src/mppdec.h	(revision 75)
+++ /mppenc/branches/r2d/src/mppdec.h	(revision 76)
@@ -356,9 +356,9 @@
 # define INVALID_FILEDESC       (-1)
 # define CLOSE(fd)              close (fd)                   // CLOSE   returns -1 on error, otherwise 0
-# if defined HAVE_INCOMPLETE_READ
-#  define READ(fd,ptr,len)      complete_read (fd, ptr, len) // READ    returns -1 or 0 on error/EOF, otherwise > 0
-# else
-#  define READ(fd,ptr,len)      (size_t)read   (fd, ptr, len)// READ    returns -1 or 0 on error/EOF, otherwise > 0
-# endif
+// # if defined HAVE_INCOMPLETE_READ
+// #  define READ(fd,ptr,len)      complete_read (fd, ptr, len) // READ    returns -1 or 0 on error/EOF, otherwise > 0
+// # else
+// #  define READ(fd,ptr,len)      (size_t)read   (fd, ptr, len)// READ    returns -1 or 0 on error/EOF, otherwise > 0
+// # endif
 # define READ1(fd,ptr)          (size_t)read   (fd, ptr, 1)  // READ    returns -1 or 0 on error/EOF, otherwise > 0
 # define WRITE(fd,ptr,len)      (size_t)write  (fd, ptr, len)// WRITE   returns -1 or 0 on error/EOF, otherwise > 0
@@ -1051,12 +1051,4 @@
 
 // tools.c
-// size_t     Read_LittleEndians         ( FILE_T fp, Uint32_t* dst, size_t words32bit );
-// 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 );
-// size_t     complete_read              ( int fd, void* dest, size_t bytes );
-// int        isdir                      ( const char* Name );
 // FIXME : what is this ? where does it go ?
 void       Init_FPU                   ( void );
Index: /mppenc/branches/r2d/src/mppenc.c
===================================================================
--- /mppenc/branches/r2d/src/mppenc.c	(revision 75)
+++ /mppenc/branches/r2d/src/mppenc.c	(revision 76)
@@ -1560,4 +1560,31 @@
 }
 
+// FIXME : not sure if it's a good idea
+#include <fpu_control.h>
+
+void Init_FPU ( void )
+{
+	mpc_uint16_t  cw;
+
+#if   defined __i386__  &&  defined _FPU_GETCW  &&  defined _FPU_SETCW
+    _FPU_GETCW ( cw );
+    cw  &=  ~0x300;
+	_FPU_SETCW ( cw );
+#elif defined __i386__  &&  defined  FPU_GETCW  &&  defined  FPU_SETCW
+    FPU_GETCW ( cw );
+    cw  &=  ~0x300;
+	FPU_SETCW ( cw );
+#elif defined __MINGW32__
+    __asm__ ("fnstcw %0" : "=m" (*&cw));
+    cw  &=  ~0x300;
+	__asm__ ("fldcw %0" : : "m" (*&cw));
+#elif defined(_WIN32) && !defined(_WIN64)
+    _asm { fstcw cw };
+    cw  &=  ~0x300;
+	_asm { fldcw cw };
+#else
+    ;
+#endif
+}
 
 static int
@@ -1597,5 +1624,4 @@
 	Init_Psychoakustik (&m);
 	Init_FPU ();
-	Init_ANS ();
 	Klemm    ();
 
Index: /mppenc/branches/r2d/src/mppenc.h
===================================================================
--- /mppenc/branches/r2d/src/mppenc.h	(revision 75)
+++ /mppenc/branches/r2d/src/mppenc.h	(revision 76)
@@ -73,5 +73,4 @@
 void   Init_Psychoakustiktabellen ( PsyModel* );
 
-void   Init_ANS   ( void );
 void   NS_Analyse (PsyModel*, const int, const unsigned char* MS, const SMRTyp, const int* Transient );
 
