Index: mppenc/branches/r2d/Makefile.am
===================================================================
--- mppenc/branches/r2d/Makefile.am	(revision 61)
+++ mppenc/branches/r2d/Makefile.am	(revision 64)
@@ -3,3 +3,3 @@
 AUTOMAKE_OPTIONS = foreign 1.4
 
-SUBDIRS = src libmpcpsy
+SUBDIRS = src libmpcpsy libmpcenc
Index: mppenc/branches/r2d/common/config_types.h
===================================================================
--- mppenc/branches/r2d/common/config_types.h	(revision 64)
+++ mppenc/branches/r2d/common/config_types.h	(revision 64)
@@ -0,0 +1,58 @@
+/*
+  Copyright (c) 2005, The Musepack Development Team
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions are
+  met:
+
+  * Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+
+  * Redistributions in binary form must reproduce the above
+  copyright notice, this list of conditions and the following
+  disclaimer in the documentation and/or other materials provided
+  with the distribution.
+
+  * Neither the name of the The Musepack Development Team nor the
+  names of its contributors may be used to endorse or promote
+  products derived from this software without specific prior
+  written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __MUSEPACK_CONFIG_TYPES_H__
+#define __MUSEPACK_CONFIG_TYPES_H__
+
+// FIXME : use config_types.h.in
+
+typedef unsigned char mpc_bool_t;
+#define TRUE  1
+#define FALSE 0
+
+typedef char mpc_int8_t;
+typedef unsigned char mpc_uint8_t;
+typedef short mpc_int16_t;
+typedef unsigned short mpc_uint16_t;
+typedef int mpc_int32_t;
+typedef unsigned int mpc_uint32_t;
+typedef long long mpc_int64_t;
+typedef unsigned long long mpc_uint64_t;
+typedef int mpc_size_t;
+// arch types
+typedef int mpc_int_t;
+typedef unsigned int mpc_uint_t;
+
+
+#endif // __MUSEPACK_CONFIG_TYPES_H__
Index: mppenc/branches/r2d/common/datatypes.h
===================================================================
--- mppenc/branches/r2d/common/datatypes.h	(revision 64)
+++ mppenc/branches/r2d/common/datatypes.h	(revision 64)
@@ -0,0 +1,37 @@
+/*
+ * 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
+ */
+
+
+// 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
+
+
+typedef struct {
+	float  L [36];
+	float  R [36];
+} SubbandFloatTyp;
+
+typedef struct {
+	float  L [ANABUFFER];
+	float  R [ANABUFFER];
+	float  M [ANABUFFER];
+	float  S [ANABUFFER];
+} PCMDataTyp;
+
Index: mppenc/branches/r2d/common/mpcmath.h
===================================================================
--- mppenc/branches/r2d/common/mpcmath.h	(revision 64)
+++ mppenc/branches/r2d/common/mpcmath.h	(revision 64)
@@ -0,0 +1,28 @@
+/*
+ * 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
+ */
+
+
+#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
+
Index: mppenc/branches/r2d/configure.in
===================================================================
--- mppenc/branches/r2d/configure.in	(revision 61)
+++ mppenc/branches/r2d/configure.in	(revision 64)
@@ -8,3 +8,3 @@
 AM_PROG_LIBTOOL
 
-AC_OUTPUT(Makefile src/Makefile libmpcpsy/Makefile)
+AC_OUTPUT(Makefile src/Makefile libmpcpsy/Makefile libmpcenc/Makefile)
Index: mppenc/branches/r2d/libmpcenc/Makefile.am
===================================================================
--- mppenc/branches/r2d/libmpcenc/Makefile.am	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/Makefile.am	(revision 64)
@@ -0,0 +1,8 @@
+INCLUDES = -I../../common
+METASOURCES = AUTO
+lib_LIBRARIES = libmpcenc.a
+libmpcenc_a_SOURCES = analy_filter.c bitstream.c encode_sv7.c huffsv7.c quant.c \
+	tools.c
+
+
+noinst_HEADERS = libmpcenc.h
Index: mppenc/branches/r2d/libmpcenc/analy_filter.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/analy_filter.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/analy_filter.c	(revision 64)
@@ -0,0 +1,344 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <string.h>
+#include <math.h>
+
+#include "mpcmath.h"
+#include "datatypes.h"
+
+#define FASTER
+
+/* C O N S T A N T S */
+
+#undef _
+#define _(value)  (float)(value##.##L / 0x200000)
+
+static float  Ci_opt [512] = {
+    _(   0), _(  213), _( 2037), _(  6574), _(75038), _( 6574), _(2037), _(213),
+    _(  -1), _(  218), _( 2000), _(  5959), _(74992), _( 7134), _(2063), _(208),
+    _(  -1), _(  222), _( 1952), _(  5288), _(74856), _( 7640), _(2080), _(202),
+    _(  -1), _(  225), _( 1893), _(  4561), _(74630), _( 8092), _(2087), _(196),
+    _(  -1), _(  227), _( 1822), _(  3776), _(74313), _( 8492), _(2085), _(190),
+    _(  -1), _(  228), _( 1739), _(  2935), _(73908), _( 8840), _(2075), _(183),
+    _(  -1), _(  228), _( 1644), _(  2037), _(73415), _( 9139), _(2057), _(176),
+    _(  -2), _(  227), _( 1535), _(  1082), _(72835), _( 9389), _(2032), _(169),
+    _(  -2), _(  224), _( 1414), _(    70), _(72169), _( 9592), _(2001), _(161),
+    _(  -2), _(  221), _( 1280), _(  -998), _(71420), _( 9750), _(1962), _(154),
+    _(  -2), _(  215), _( 1131), _( -2122), _(70590), _( 9863), _(1919), _(147),
+    _(  -3), _(  208), _(  970), _( -3300), _(69679), _( 9935), _(1870), _(139),
+    _(  -3), _(  200), _(  794), _( -4533), _(68692), _( 9966), _(1817), _(132),
+    _(  -4), _(  189), _(  605), _( -5818), _(67629), _( 9959), _(1759), _(125),
+    _(  -4), _(  177), _(  402), _( -7154), _(66494), _( 9916), _(1698), _(117),
+    _(  -5), _(  163), _(  185), _( -8540), _(65290), _( 9838), _(1634), _(111),
+    _(  -5), _(  146), _(  -45), _( -9975), _(64019), _( 9727), _(1567), _(104),
+    _(  -6), _(  127), _( -288), _(-11455), _(62684), _( 9585), _(1498), _( 97),
+    _(  -7), _(  106), _( -545), _(-12980), _(61289), _( 9416), _(1428), _( 91),
+    _(  -7), _(   83), _( -814), _(-14548), _(59838), _( 9219), _(1356), _( 85),
+    _(  -8), _(   57), _(-1095), _(-16155), _(58333), _( 8998), _(1283), _( 79),
+    _(  -9), _(   29), _(-1388), _(-17799), _(56778), _( 8755), _(1210), _( 73),
+    _( -10), _(   -2), _(-1692), _(-19478), _(55178), _( 8491), _(1137), _( 68),
+    _( -11), _(  -36), _(-2006), _(-21189), _(53534), _( 8209), _(1064), _( 63),
+    _( -13), _(  -72), _(-2330), _(-22929), _(51853), _( 7910), _( 991), _( 58),
+    _( -14), _( -111), _(-2663), _(-24694), _(50137), _( 7597), _( 919), _( 53),
+    _( -16), _( -153), _(-3004), _(-26482), _(48390), _( 7271), _( 848), _( 49),
+    _( -17), _( -197), _(-3351), _(-28289), _(46617), _( 6935), _( 779), _( 45),
+    _( -19), _( -244), _(-3705), _(-30112), _(44821), _( 6589), _( 711), _( 41),
+    _( -21), _( -294), _(-4063), _(-31947), _(43006), _( 6237), _( 645), _( 38),
+    _( -24), _( -347), _(-4425), _(-33791), _(41176), _( 5879), _( 581), _( 35),
+    _( -26), _( -401), _(-4788), _(-35640), _(39336), _( 5517), _( 519), _( 31),
+    _( -29), _( -459), _(-5153), _(-37489), _(37489), _( 5153), _( 459), _( 29),
+    _( -31), _( -519), _(-5517), _(-39336), _(35640), _( 4788), _( 401), _( 26),
+    _( -35), _( -581), _(-5879), _(-41176), _(33791), _( 4425), _( 347), _( 24),
+    _( -38), _( -645), _(-6237), _(-43006), _(31947), _( 4063), _( 294), _( 21),
+    _( -41), _( -711), _(-6589), _(-44821), _(30112), _( 3705), _( 244), _( 19),
+    _( -45), _( -779), _(-6935), _(-46617), _(28289), _( 3351), _( 197), _( 17),
+    _( -49), _( -848), _(-7271), _(-48390), _(26482), _( 3004), _( 153), _( 16),
+    _( -53), _( -919), _(-7597), _(-50137), _(24694), _( 2663), _( 111), _( 14),
+    _( -58), _( -991), _(-7910), _(-51853), _(22929), _( 2330), _(  72), _( 13),
+    _( -63), _(-1064), _(-8209), _(-53534), _(21189), _( 2006), _(  36), _( 11),
+    _( -68), _(-1137), _(-8491), _(-55178), _(19478), _( 1692), _(   2), _( 10),
+    _( -73), _(-1210), _(-8755), _(-56778), _(17799), _( 1388), _( -29), _(  9),
+    _( -79), _(-1283), _(-8998), _(-58333), _(16155), _( 1095), _( -57), _(  8),
+    _( -85), _(-1356), _(-9219), _(-59838), _(14548), _(  814), _( -83), _(  7),
+    _( -91), _(-1428), _(-9416), _(-61289), _(12980), _(  545), _(-106), _(  7),
+    _( -97), _(-1498), _(-9585), _(-62684), _(11455), _(  288), _(-127), _(  6),
+    _(-104), _(-1567), _(-9727), _(-64019), _( 9975), _(   45), _(-146), _(  5),
+    _(-111), _(-1634), _(-9838), _(-65290), _( 8540), _( -185), _(-163), _(  5),
+    _(-117), _(-1698), _(-9916), _(-66494), _( 7154), _( -402), _(-177), _(  4),
+    _(-125), _(-1759), _(-9959), _(-67629), _( 5818), _( -605), _(-189), _(  4),
+    _(-132), _(-1817), _(-9966), _(-68692), _( 4533), _( -794), _(-200), _(  3),
+    _(-139), _(-1870), _(-9935), _(-69679), _( 3300), _( -970), _(-208), _(  3),
+    _(-147), _(-1919), _(-9863), _(-70590), _( 2122), _(-1131), _(-215), _(  2),
+    _(-154), _(-1962), _(-9750), _(-71420), _(  998), _(-1280), _(-221), _(  2),
+    _(-161), _(-2001), _(-9592), _(-72169), _(  -70), _(-1414), _(-224), _(  2),
+    _(-169), _(-2032), _(-9389), _(-72835), _(-1082), _(-1535), _(-227), _(  2),
+    _(-176), _(-2057), _(-9139), _(-73415), _(-2037), _(-1644), _(-228), _(  1),
+    _(-183), _(-2075), _(-8840), _(-73908), _(-2935), _(-1739), _(-228), _(  1),
+    _(-190), _(-2085), _(-8492), _(-74313), _(-3776), _(-1822), _(-227), _(  1),
+    _(-196), _(-2087), _(-8092), _(-74630), _(-4561), _(-1893), _(-225), _(  1),
+    _(-202), _(-2080), _(-7640), _(-74856), _(-5288), _(-1952), _(-222), _(  1),
+    _(-208), _(-2063), _(-7134), _(-74992), _(-5959), _(-2000), _(-218), _(  1),
+};
+#undef _
+
+
+static float M [1024];
+
+void
+Klemm ( void )
+{
+    int    i;
+    int    k;
+    float  S [512];
+
+    for ( i=0; i<32; i++ ) {
+        for ( k=0; k<32; k++ ) {
+            M [i*32 + k] = (float) cos ( ((2*i+1)*k & 127) * M_PI/64 );
+        }
+    }
+
+#ifdef FASTER
+    for ( i = 0; i < 384; i++ )
+        S[i] = Ci_opt[i];
+    for ( i = 384; i < 392; i++ )
+        S[i] = 0;
+    for ( i = 392; i < 512; i++ )
+        S[i] = -Ci_opt[i];
+    for ( i = 0; i < 512; i++ )
+       Ci_opt[i] = S[i];
+    for ( i = 0; i < 128; i++ )
+       Ci_opt[i] = S[(i&7) + 120 - (i&120)];
+    for ( i = 128; i < 384; i++ )
+       Ci_opt[i] = S[i];
+    for ( i = 384; i < 512; i++ )
+       Ci_opt[i] = S[ 384 + (i&7) + 120 - (i&120)];
+#endif
+}
+
+ /* D E F I N E S */
+#define X_MEM    1152
+
+/* V A R I A B L E S */
+float  X_L [ X_MEM + 480 ];
+float  X_R [ X_MEM + 480 ];
+
+
+/* F U N C T I O N S */
+// vectoring & partial calculation
+
+static void
+Vectoring ( const float* x, float* y )
+{
+#ifdef FASTER
+    int           i = 0;
+    const float*  c1;
+    const float*  c2;
+    const float*  x1;
+    const float*  x2;
+
+# define EXPR(c,x)  (c[0]*x[0] + c[1]*x[64] + c[2]*x[128] + c[3]*x[192] + c[4]*x[256] + c[5]*x[320] + c[6]*x[384] + c[7]*x[448])
+
+    i++;
+    *y++ = EXPR ((Ci_opt+128),(x+31));
+
+    c1 = Ci_opt - 8;
+    c2 = Ci_opt + 128;
+    x1 = x + 16;
+    x2 = x + 31;
+    do {
+        x1--, x2--, i++;
+        c1 += 8, c2 += 8;
+        *y++ = EXPR (c1,x1) + EXPR (c2,x2);
+    } while ( i < 16 );
+
+    i++;
+    *y++ = EXPR ((Ci_opt+120),(x+0)) + EXPR ((Ci_opt+256),(x+32));
+
+    c1 = Ci_opt + 384 - 8;
+    c2 = Ci_opt + 256;
+    x1 = x + 47;
+    x2 = x + 32;
+
+    do {
+        x1++, x2++, i++;
+        c1 += 8, c2 += 8;
+        *y++ = EXPR (c1,x1) + EXPR (c2,x2);
+    } while ( i < 32 );
+#else
+    int           i;
+    const float*  c = Ci_opt;
+
+    for ( i = 0; i < 16; i++, c += 32, x += 4, y += 4 ) {
+        y[0] = c[ 0] * x[  0] + c[ 1] * x[ 64] + c[ 2] * x[128] + c[ 3] * x[192] + c[ 4] * x[256] + c[ 5] * x[320] + c[ 6] * x[384] + c[ 7] * x[448];
+        y[1] = c[ 8] * x[  1] + c[ 9] * x[ 65] + c[10] * x[129] + c[11] * x[193] + c[12] * x[257] + c[13] * x[321] + c[14] * x[385] + c[15] * x[449];
+        y[2] = c[16] * x[  2] + c[17] * x[ 66] + c[18] * x[130] + c[19] * x[194] + c[20] * x[258] + c[21] * x[322] + c[22] * x[386] + c[23] * x[450];
+        y[3] = c[24] * x[  3] + c[25] * x[ 67] + c[26] * x[131] + c[27] * x[195] + c[28] * x[259] + c[29] * x[323] + c[30] * x[387] + c[31] * x[451];
+    }
+#endif
+}
+
+// matrixing with Mi[32][32] = Mi[1024]
+
+static void
+Matrixing ( const int MaxBand, const float* mi, const float* y, float* samples )
+{
+    int  i;
+#ifdef FASTER
+    for ( i = 0; i <= MaxBand; i++, mi += 32, samples += 72 ) {                          // 144 = sizeof(SubbandFloatTyp)/sizeof(float)
+        samples[0] =          y[ 0] + mi[ 1] * y[ 1] + mi[ 2] * y[ 2] + mi[ 3] * y[ 3]
+                   + mi[ 4] * y[ 4] + mi[ 5] * y[ 5] + mi[ 6] * y[ 6] + mi[ 7] * y[ 7]
+                   + mi[ 8] * y[ 8] + mi[ 9] * y[ 9] + mi[10] * y[10] + mi[11] * y[11]
+                   + mi[12] * y[12] + mi[13] * y[13] + mi[14] * y[14] + mi[15] * y[15]
+                   + mi[16] * y[16] + mi[17] * y[17] + mi[18] * y[18] + mi[19] * y[19]
+                   + mi[20] * y[20] + mi[21] * y[21] + mi[22] * y[22] + mi[23] * y[23]
+                   + mi[24] * y[24] + mi[25] * y[25] + mi[26] * y[26] + mi[27] * y[27]
+                   + mi[28] * y[28] + mi[29] * y[29] + mi[30] * y[30] + mi[31] * y[31];
+    }
+#else
+    for ( i = 0; i <= MaxBand; i++, mi += 32, samples += 72 ) {                          // 144 = sizeof(SubbandFloatTyp)/sizeof(float)
+        samples[0] =           y[16]        + mi[ 1] * (y[15]+y[17])
+                   + mi[ 2] * (y[14]+y[18]) + mi[ 3] * (y[13]+y[19])
+                   + mi[ 4] * (y[12]+y[20]) + mi[ 5] * (y[11]+y[21])
+                   + mi[ 6] * (y[10]+y[22]) + mi[ 7] * (y[ 9]+y[23])
+                   + mi[ 8] * (y[ 8]+y[24]) + mi[ 9] * (y[ 7]+y[25])
+                   + mi[10] * (y[ 6]+y[26]) + mi[11] * (y[ 5]+y[27])
+                   + mi[12] * (y[ 4]+y[28]) + mi[13] * (y[ 3]+y[29])
+                   + mi[14] * (y[ 2]+y[30]) + mi[15] * (y[ 1]+y[31])
+                   + mi[16] * (y[ 0]+y[32])
+                   + mi[31] * (y[47]-y[49]) + mi[30] * (y[46]-y[50])
+                   + mi[29] * (y[45]-y[51]) + mi[28] * (y[44]-y[52])
+                   + mi[27] * (y[43]-y[53]) + mi[26] * (y[42]-y[54])
+                   + mi[25] * (y[41]-y[55]) + mi[24] * (y[40]-y[56])
+                   + mi[23] * (y[39]-y[57]) + mi[22] * (y[38]-y[58])
+                   + mi[21] * (y[37]-y[59]) + mi[20] * (y[36]-y[60])
+                   + mi[19] * (y[35]-y[61]) + mi[18] * (y[34]-y[62])
+                   + mi[17] * (y[33]-y[63]);
+    }
+#endif
+}
+
+// Analysis-Filterbank
+void
+Analyse_Filter ( const PCMDataTyp* in, SubbandFloatTyp* out, const int MaxBand )
+{
+#ifdef FASTER
+    float         Y_L [32];
+    float         Y_R [32];
+#else
+    float         Y_L [64];
+    float         Y_R [64];
+#endif
+    float*        x;
+    const float*  pcm;
+    int           n;
+    int           i;
+
+    /************************* calculate L-signal ***************************/
+    memcpy ( X_L + X_MEM, X_L, 480*sizeof(*X_L) );
+    x      = X_L + X_MEM;
+    pcm    = in->L + 479;                               // 479 = CENTER + 31
+    for ( n = 0; n < 36; n++, pcm += 64 ) {
+        x  -= 32;                                       // updating vector x
+#ifdef FASTER
+        for ( i = 0; i < 16; i++ )
+            x[i] = *pcm--;
+        for ( i = 31; i >= 16; i-- )
+            x[i] = *pcm--;
+#else
+        for ( i = 0; i < 32; i++ )
+            x[i] = *pcm--;
+#endif
+        Vectoring ( x, Y_L );                           // vectoring & partial calculation
+        Matrixing ( MaxBand, M, Y_L, &out[0].L[n] );    // matrixing
+    }
+
+    /************************* calculate R-signal ***************************/
+    memcpy ( X_R + X_MEM, X_R, 480*sizeof(*X_R) );
+    x      = X_R + X_MEM;
+    pcm    = in->R + 479;                               // 479 = CENTER + 31
+    for ( n = 0; n < 36; n++, pcm += 64 ) {
+        x  -= 32;                                       // updating vector x
+#ifdef FASTER
+        for ( i = 0; i < 16; i++ )
+            x[i] = *pcm--;
+        for ( i = 31; i >= 16; i-- )
+            x[i] = *pcm--;
+#else
+        for ( i = 0; i < 32; i++ )
+            x[i] = *pcm--;
+#endif
+        Vectoring ( x, Y_R );                           // vectoring & partial calculation
+        Matrixing ( MaxBand, M, Y_R, &out[0].R[n] );    // matrixing
+    }
+}
+
+void
+Analyse_Init ( float Left, float Right, SubbandFloatTyp* out, const int MaxBand )
+{
+#ifdef FASTER
+    float         Y_L [32];
+    float         Y_R [32];
+#else
+    float         Y_L [64];
+    float         Y_R [64];
+#endif
+    float*        x;
+    int           n;
+    int           i;
+
+    /************************* calculate L-signal ***************************/
+    memcpy ( X_L + X_MEM, X_L, 480*sizeof(*X_L) );
+    x      = X_L + X_MEM;
+
+    for ( n = 0; n < 36; n++ ) {
+        x  -= 32;                                       // updating vector x
+#ifdef FASTER
+        for ( i = 0; i < 16; i++ )
+            x[i] = Left;
+        for ( i = 31; i >= 16; i-- )
+            x[i] = Left;
+#else
+        for ( i = 0; i < 32; i++ )
+            x[i] = Left;
+#endif
+        Vectoring ( x, Y_L );                           // vectoring & partial calculation
+        Matrixing ( MaxBand, M, Y_L, &out[0].L[n] );    // matrixing
+    }
+
+    /************************* calculate R-signal ***************************/
+    memcpy ( X_R + X_MEM, X_R, 480*sizeof(*X_R) );
+    x      = X_R + X_MEM;
+    for ( n = 0; n < 36; n++ ) {
+        x  -= 32;                                       // updating vector x
+#ifdef FASTER
+        for ( i = 0; i < 16; i++ )
+            x[i] = Right;
+        for ( i = 31; i >= 16; i-- )
+            x[i] = Right;
+#else
+        for ( i = 0; i < 32; i++ )
+            x[i] = Right;
+#endif
+        Vectoring ( x, Y_R );                           // vectoring & partial calculation
+        Matrixing ( MaxBand, M, Y_R, &out[0].R[n] );    // matrixing
+    }
+}
+
+/* end of analy_filter.c */
Index: mppenc/branches/r2d/libmpcenc/bitstream.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/bitstream.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/bitstream.c	(revision 64)
@@ -0,0 +1,179 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "libmpcenc.h"
+#include "stdio.h"
+
+
+/*
+ *  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, especially on modern CPUs, than
+ *  byte picking, 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 ( unsigned int* dst, mpc_size_t words32bit )
+{
+    for ( ; words32bit--; dst++ ) {
+# if  INT_MAX >= 2147483647L
+        unsigned int  tmp = *dst;
+        tmp  = ((tmp << 0x10) & 0xFFFF0000) | ((tmp >> 0x10) & 0x0000FFFF);
+        tmp  = ((tmp << 0x08) & 0xFF00FF00) | ((tmp >> 0x08) & 0x00FF00FF);
+        *dst = tmp;
+# else
+        char  tmp;
+        tmp             = ((char*)dst)[0];
+        ((char*)dst)[0] = ((char*)dst)[3];
+        ((char*)dst)[3] = tmp;
+        tmp             = ((char*)dst)[1];
+        ((char*)dst)[1] = ((char*)dst)[2];
+        ((char*)dst)[2] = tmp;
+# endif
+    }
+    return;
+}
+
+#endif /* ENDIAN == HAVE_BIG_ENDIAN */
+
+
+void
+FlushBitstream ( FILE* fp, const mpc_uint32_t* buffer, mpc_size_t words32bit )
+{
+    mpc_size_t           WrittenDwords = 0;
+    const mpc_uint32_t*  p             = buffer;
+    mpc_size_t           CC            = words32bit;
+
+#if ENDIAN == HAVE_BIG_ENDIAN
+    Change_Endian32 ( (mpc_uint32_t*)buffer, CC );
+#endif
+
+    // Write e->Buffer
+    do {
+        WrittenDwords = fwrite ( p, sizeof(*buffer), words32bit, fp );
+        if ( WrittenDwords == 0 ) {
+            stderr_printf ( "\b\n WARNING: Disk full?, retry after 10 sec ...\a" );
+            sleep (10);
+        }
+        if ( WrittenDwords > 0 ) {
+            p          += WrittenDwords;
+            words32bit -= WrittenDwords;
+        }
+    } while ( words32bit != 0 );
+
+#if ENDIAN == HAVE_BIG_ENDIAN
+    Change_Endian32 ( (mpc_uint32_t*)buffer, CC );
+#endif
+}
+
+
+void
+UpdateHeader ( FILE* fp, mpc_uint32_t Frames, mpc_uint_t ValidSamples )
+{
+    mpc_uint8_t  buff [4];
+
+    // Write framecount to header
+    if ( fseek ( fp, 4L, SEEK_SET ) < 0 )
+        return;
+
+    buff [0] = (mpc_uint8_t)(Frames >>  0);
+    buff [1] = (mpc_uint8_t)(Frames >>  8);
+    buff [2] = (mpc_uint8_t)(Frames >> 16);
+    buff [3] = (mpc_uint8_t)(Frames >> 24);
+
+    fwrite ( buff, 1, 4, fp );
+
+    // Write ValidSamples to header
+    if ( fseek ( fp, 22L, SEEK_SET ) < 0 )
+        return;
+    fread ( buff, 1, 2, fp );
+    if ( ferror(fp) )
+        return;
+    if ( fseek ( fp, 22L, SEEK_SET ) < 0 )
+        return;
+
+    ValidSamples <<= 4;
+    ValidSamples  |= 0x800F & (((mpc_uint_t) buff[1] << 8) | buff[0]);
+    buff [0] = (mpc_uint8_t)(ValidSamples >>  0);
+    buff [1] = (mpc_uint8_t)(ValidSamples >>  8);
+
+    fwrite ( buff, 1, 2, fp );
+
+
+    // Set filepointer to end of file (dirty method, should be old position!!)
+    fseek ( fp, 0L, SEEK_END );
+}
+
+
+void WriteBits (mpc_encoder * e, const mpc_uint32_t input, const unsigned int bits )
+{
+    e->BufferedBits += bits;
+    e->filled       -= bits;
+
+    if      ( e->filled > 0 ) {
+        e->dword  |= input << e->filled;
+    }
+    else if ( e->filled < 0 ) {
+        e->Buffer [e->Zaehler++] = e->dword | ( input >> -e->filled );
+        e->filled += 32;
+        e->dword   = input << e->filled;
+    }
+    else {
+        e->Buffer [e->Zaehler++] = e->dword | input;
+        e->filled  = 32;
+        e->dword   =  0;
+    }
+}
+
+// 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 )
+{
+    mpc_uint32_t*     ptr    = pos.ptr;
+    int           filled = pos.bit - bits;
+
+//    fprintf ( stderr, "%5u %2u %08lX %2u\n", input, bits, pos.ptr, pos.bit );
+
+    e->Buffer [e->Zaehler] = e->dword;
+
+    if      ( filled > 0 ) {
+        ptr [0] |= input << (  +filled);
+    }
+    else if ( filled < 0 ) {
+        ptr [0] |= input >> (  -filled);
+        ptr [1] |= input << (32+filled);
+    }
+    else {
+        ptr [0] |= input;
+    }
+
+    e->dword = e->Buffer [e->Zaehler];
+}
+
+
+void GetBitstreamPos (mpc_encoder * e, BitstreamPos* const pos )
+{
+    pos -> ptr = e->Buffer + e->Zaehler;
+    pos -> bit = e->filled;
+}
+
+/* end of bitstream.c */
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 64)
@@ -0,0 +1,460 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdlib.h>
+
+#include "libmpcenc.h"
+
+// huffsv7.c
+extern Huffman_t         HuffHdr  [10];         // contains tables for SV7-header
+extern Huffman_t         HuffSCFI [ 4];         // contains tables for SV7-scalefactor select
+extern Huffman_t         HuffDSCF [16];         // contains tables for SV7-scalefactor coding
+extern const Huffman_t*  HuffQ [2] [8];         // points to tables for SV7-sample coding
+
+/*
+ *  SV1:   DATE 13.12.1998
+ *  SV2:   DATE 12.06.1999
+ *  SV3:   DATE 19.10.1999
+ *  SV4:   DATE 20.10.1999
+ *  SV5:   DATE 18.06.2000
+ *  SV6:   DATE 10.08.2000
+ *  SV7:   DATE 23.08.2000
+ *  SV7.f: DATE 20.07.2002
+ */
+
+unsigned char         MS_Flag     [32];         // Flag to save if Subband was MS- or LR-coded
+int                   SCF_Last_L  [32];
+int                   SCF_Last_R  [32];         // Last coded SCF value
+static unsigned char  DSCF_RLL_L  [32];
+static unsigned char  DSCF_RLL_R  [32];         // Duration of the differential SCF-coding for RLL (run length limitation)
+int                   Res_L       [32];
+int                   Res_R       [32];         // Quantization precision of the subbands
+int                   SCF_Index_L [32] [3];
+int                   SCF_Index_R [32] [3];     // Scalefactor index for quantized subband values
+
+
+// initialize SV7
+void
+Init_SV7 ( void )
+{
+    Init_Huffman_Encoder_SV7 ();
+}
+
+
+// writes SV7-header
+void
+WriteHeader_SV7 ( const unsigned int  MaxBand,
+                  const unsigned int  Profile,
+                  const unsigned int  MS_on,
+                  const mpc_uint32_t  TotalFrames,
+                  const unsigned int  SamplesRest,
+                  const unsigned int  StreamVersion,
+                  const unsigned int  SampleFreq )
+{
+    WriteBits ( StreamVersion,  8 );    // StreamVersion
+    WriteBits ( 0x2B504D     , 24 );    // Magic Number "MP+"
+
+    WriteBits ( TotalFrames  , 32 );    // # of frames
+
+    WriteBits ( 0            ,  1 );    // former IS-Flag (not supported anymore)
+    WriteBits ( MS_on        ,  1 );    // MS-Coding Flag
+    WriteBits ( MaxBand      ,  6 );    // Bandwidth
+
+#if 0
+    if ( MPPENC_VERSION [3] & 1 )
+        WriteBits ( 1        ,  4 );    // 1: Experimental profile
+    else
+#endif
+
+        WriteBits ( Profile  ,  4 );    // 5...15: below Telephone...above BrainDead
+    WriteBits ( 0            ,  2 );    // for future use
+    switch ( SampleFreq ) {
+        case 44100: WriteBits ( 0, 2 ); break;
+        case 48000: WriteBits ( 1, 2 ); break;
+        case 37800: WriteBits ( 2, 2 ); break;
+        case 32000: WriteBits ( 3, 2 ); break;
+        default   : stderr_printf ( "Internal error\n");
+                    exit (1);
+    }
+    WriteBits ( 0            , 16 );    // maximum input sample value, currently filled by replaygain
+
+    WriteBits ( 0            , 32 );    // title based gain controls, currently filled by replaygain
+
+    WriteBits ( 0            , 32 );    // album based gain controls, currently filled by replaygain
+
+    WriteBits ( 1            ,  1 );    // true gapless: used?
+    WriteBits ( SamplesRest  , 11 );    // true gapless: valid samples in last frame
+    WriteBits ( 1            , 1 );     // we now support fast seeking
+    WriteBits ( 0            , 19 );
+
+    WriteBits ( (MPPENC_VERSION[0]&15)*100 + (MPPENC_VERSION[2]&15)*10 + (MPPENC_VERSION[3]&15),
+                                8 );    // for future use
+}
+
+
+void
+FinishBitstream ( mpc_encoder* e )
+{
+    e->Buffer [e->Zaehler++] = e->dword;         // Assigning the "last" word
+}
+
+
+#define ENCODE_SCF1( new, old, rll )                         \
+        d = new - old + 7;                                   \
+        if ( d <= 14u  && rll < 32) {                        \
+            WriteBits ( Table[d].Code, Table[d].Length );    \
+        }                                                    \
+        else {                                               \
+            if ( new < 0 ) new = 0, e->Overflows++;          \
+            WriteBits ( Table[15].Code, Table[15].Length );  \
+            WriteBits ( (unsigned int)new, 6 );              \
+            rll = 0;                                         \
+        }
+
+#define ENCODE_SCFn( new, old, rll )                         \
+        d = new - old + 7;                                   \
+        if ( d <= 14u ) {                                    \
+            WriteBits ( Table[d].Code, Table[d].Length );    \
+        }                                                    \
+        else {                                               \
+            if ( new < 0 ) new = 0, e->Overflows++;          \
+            WriteBits ( Table[15].Code, Table[15].Length );  \
+            WriteBits ( (unsigned int)new, 6 );              \
+            rll = 0;                                         \
+        }
+
+
+static void
+test ( const unsigned int* const Res, const int* q )
+{
+#if 0
+    int  i;
+
+    switch ( *Res ) {
+    case 1:
+        for ( i = 0; i < 36; i ++ )
+            if ( q[i] != 1 )
+                return;
+        fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );
+        *Res = 0;
+        break;
+    case 2:
+        for ( i = 0; i < 36; i ++ )
+            if ( q[i] != 2 )
+                return;
+        fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );
+        *Res = 0;
+        break;
+    }
+#endif
+}
+
+
+// formatting and writing SV7-bitstream for one frame
+void
+WriteBitstream_SV7 ( mpc_encoder* e,
+					 const int               MaxBand,
+                     const SubbandQuantTyp*  Q )
+{
+    int                  n;
+    int                  k;
+    unsigned int         d;
+    unsigned int         idx;
+    unsigned int         book;
+    const Huffman_t*     Table;
+    const Huffman_t*     Table0;
+    const Huffman_t*     Table1;
+    int                  sum;
+    const unsigned int*  q;
+    unsigned char        SCFI_L [32];
+    unsigned char        SCFI_R [32];
+
+    /************************************ Resolution *********************************/
+    WriteBits ( (unsigned int)Res_L[0], 4 );                            // subband 0
+    WriteBits ( (unsigned int)Res_R[0], 4 );
+    if ( e->MS_Channelmode > 0  &&  !(Res_L[0]==0  &&  Res_R[0]==0) )
+         WriteBits ( MS_Flag[0] , 1 );
+
+    Table = HuffHdr;                                                    // subband 1...MaxBand
+    for ( n = 1; n <= MaxBand; n++ ) {
+        test ( Res_L+n, Q[n].L );
+
+        d = Res_L[n] - Res_L[n-1] + 5;
+        if ( d <= 8u ) {
+            WriteBits ( Table[d].Code, Table[d].Length );
+        }
+        else {
+            WriteBits ( Table[9].Code, Table[9].Length );
+            WriteBits ( Res_L[n]     , 4               );
+        }
+
+        test ( Res_R+n, Q[n].R );
+        d = Res_R[n] - Res_R[n-1] + 5;
+        if ( d <= 8u ) {
+            WriteBits ( Table[d].Code, Table[d].Length );
+        }
+        else {
+            WriteBits ( Table[9].Code, Table[9].Length );
+            WriteBits ( Res_R[n]     , 4               );
+        }
+        if ( e->MS_Channelmode > 0  &&  !(Res_L[n]==0 && Res_R[n]==0) )
+            WriteBits ( MS_Flag[n], 1 );
+    }
+
+    /************************************ SCF encoding type ***********************************/
+    Table = HuffSCFI;
+    for ( n = 0; n <= MaxBand; n++ ) {
+        if ( Res_L[n] ) {
+            SCFI_L[n] = 2 * (SCF_Index_L[n][0] == SCF_Index_L[n][1]) + (SCF_Index_L[n][1] == SCF_Index_L[n][2]);
+            WriteBits ( Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length );
+        }
+        if ( Res_R[n] ) {
+            SCFI_R[n] = 2 * (SCF_Index_R[n][0] == SCF_Index_R[n][1]) + (SCF_Index_R[n][1] == SCF_Index_R[n][2]);
+            WriteBits ( Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length );
+        }
+    }
+
+    /************************************* SCF **********************************/
+    Table = HuffDSCF;
+    for ( n = 0; n <= MaxBand; n++ ) {
+
+        if ( Res_L[n] ) {
+            switch ( SCFI_L[n] ) {
+            default:
+                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n]   , DSCF_RLL_L[n] );
+                ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] );
+                ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][1], DSCF_RLL_L[n] );
+                SCF_Last_L[n] = SCF_Index_L[n][2];
+                break;
+            case 1:
+                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n]   , DSCF_RLL_L[n] );
+                ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] );
+                SCF_Last_L[n] = SCF_Index_L[n][1];
+                break;
+            case 2:
+                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n]    , DSCF_RLL_L[n] );
+                ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][0], DSCF_RLL_L[n] );
+                SCF_Last_L[n] = SCF_Index_L[n][2];
+                break;
+            case 3:
+                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n]    , DSCF_RLL_L[n] );
+                SCF_Last_L[n] = SCF_Index_L[n][0];
+                break;
+            }
+        }
+        if (DSCF_RLL_L[n] <= 32)
+            DSCF_RLL_L[n]++;        // Increased counters for SCF that haven't been initialized again
+
+        if ( Res_R[n] ) {
+            switch ( SCFI_R[n] ) {
+            default:
+                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
+                ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] );
+                ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][1], DSCF_RLL_R[n] );
+                SCF_Last_R[n] = SCF_Index_R[n][2];
+                break;
+            case 1:
+                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
+                ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] );
+                SCF_Last_R[n] = SCF_Index_R[n][1];
+                break;
+            case 2:
+                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
+                ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][0], DSCF_RLL_R[n] );
+                SCF_Last_R[n] = SCF_Index_R[n][2];
+                break;
+            case 3:
+                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
+                SCF_Last_R[n] = SCF_Index_R[n][0];
+                break;
+            }
+        }
+        if (DSCF_RLL_R[n] <= 32)
+            DSCF_RLL_R[n]++;          // Increased counters for SCF that haven't been freshly initialized
+    }
+
+    /*********************************** Samples *********************************/
+    for ( n = 0; n <= MaxBand; n++ ) {
+
+        sum = 0;
+        q   = Q[n].L;
+
+        switch ( Res_L[n] ) {
+        case -1:
+        case  0:
+            break;
+        case  1:
+            Table0 = HuffQ [0][1];
+            Table1 = HuffQ [1][1];
+            for ( k = 0; k < 36; k += 3 ) {
+                idx  = q[k+0] + 3*q[k+1] + 9*q[k+2];
+                sum += Table0 [idx].Length;
+                sum -= Table1 [idx].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][1];
+            for ( k = 0; k < 36; k += 3 ) {
+                idx = q[k+0] + 3*q[k+1] + 9*q[k+2];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        case  2:
+            Table0 = HuffQ [0][2];
+            Table1 = HuffQ [1][2];
+            for ( k = 0; k < 36; k += 2 ) {
+                idx  = q[k+0] + 5*q[k+1];
+                sum += Table0 [idx].Length;
+                sum -= Table1 [idx].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][2];
+            for ( k = 0; k < 36; k += 2 ) {
+                idx = q[k+0] + 5*q[k+1];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        case  3:
+        case  4:
+        case  5:
+        case  6:
+        case  7:
+            Table0 = HuffQ [0][Res_L[n]];
+            Table1 = HuffQ [1][Res_L[n]];
+            for ( k = 0; k < 36; k++ ) {
+                sum += Table0 [q[k]].Length;
+                sum -= Table1 [q[k]].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][Res_L[n]];
+            for ( k = 0; k < 36; k++ ) {
+                idx = q[k];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        default:
+            for ( k = 0; k < 36; k++ )
+                WriteBits ( q[k], Res_L[n]-1 );
+            break;
+        }
+
+        sum = 0;
+        q   = Q[n].R;
+
+        switch ( Res_R[n] ) {
+        case -1:
+        case  0:
+            break;
+        case  1:
+            Table0 = HuffQ [0][1];
+            Table1 = HuffQ [1][1];
+            for ( k = 0; k < 36; k += 3 ) {
+                idx  = q[k+0] + 3*q[k+1] + 9*q[k+2];
+                sum += Table0 [idx].Length;
+                sum -= Table1 [idx].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][1];
+            for ( k = 0; k < 36; k += 3 ) {
+                idx = q[k+0] + 3*q[k+1] + 9*q[k+2];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        case  2:
+            Table0 = HuffQ [0][2];
+            Table1 = HuffQ [1][2];
+            for ( k = 0; k < 36; k += 2 ) {
+                idx  = q[k+0] + 5*q[k+1];
+                sum += Table0 [idx].Length;
+                sum -= Table1 [idx].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][2];
+            for ( k = 0; k < 36; k += 2 ) {
+                idx = q[k+0] + 5*q[k+1];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        case  3:
+        case  4:
+        case  5:
+        case  6:
+        case  7:
+            Table0 = HuffQ [0][Res_R[n]];
+            Table1 = HuffQ [1][Res_R[n]];
+            for ( k = 0; k < 36; k++ ) {
+                sum += Table0 [q[k]].Length;
+                sum -= Table1 [q[k]].Length;
+            }
+            book = sum >= 0;
+            WriteBits ( book, 1 );
+            Table = HuffQ [book][Res_R[n]];
+            for ( k = 0; k < 36; k++ ) {
+                idx = q[k];
+                WriteBits ( Table[idx].Code, Table[idx].Length );
+            }
+            break;
+        default:
+            for ( k = 0; k < 36; k++ )
+                WriteBits ( q[k], Res_R[n] - 1 );
+            break;
+        }
+
+    }
+    return;
+}
+
+#undef ENCODE_SCF1
+#undef ENCODE_SCFn
+
+
+#if 0
+void
+Dump ( const unsigned int* q, const int Res )
+{
+    switch ( Res ) {
+    case  1:
+        for ( k = 0; k < 36; k++, q++ )
+            printf ("%2d%c", *q-1, k==35?'\n':' ');
+        break;
+    case  2:
+        for ( k = 0; k < 36; k++, q++ )
+            printf ("%2d%c", *q-2, k==35?'\n':' ');
+        break;
+    case  3: case  4: case  5: case  6: case  7:
+        if ( Res == 5 )
+            for ( k = 0; k < 36; k++, q++ )
+                printf ("%2d%c", *q-7, k==35?'\n':' ');
+        break;
+    case  8: case  9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
+        printf ("%2u: ", Res-1 );
+        for ( k = 0; k < 36; k++, q++ ) {
+            printf ("%6d", *q - (1 << (Res-2)) );
+        }
+        printf ("\n");
+        break;
+    }
+}
+#endif
+
+/* end of encode_sv7.c */
Index: mppenc/branches/r2d/libmpcenc/huffsv7.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/huffsv7.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/huffsv7.c	(revision 64)
@@ -0,0 +1,444 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "libmpcenc.h"
+
+Huffman_t   HuffHdr    [10];            // 9 bit
+Huffman_t   HuffSCFI   [ 4];            // 3 bit
+Huffman_t   HuffDSCF   [16];            // 6 bit
+Huffman_t   HuffQ1 [2] [ 3*3*3];        // 6+ 9 bit
+Huffman_t   HuffQ2 [2] [ 5*5];          // 7+10 bit
+Huffman_t   HuffQ3 [2] [ 7];            // 4+ 5 bit
+Huffman_t   HuffQ4 [2] [ 9];            // 4+ 5 bit
+Huffman_t   HuffQ5 [2] [15];            // 6+ 8 bit
+Huffman_t   HuffQ6 [2] [31];            // 7+13 bit
+Huffman_t   HuffQ7 [2] [63];            // 8+14 bit
+                                        // 4608 Bytes
+mpc_uint8_t     LUT1_0  [1<< 6];
+mpc_uint8_t     LUT1_1  [1<< 9];            //  576 Bytes
+mpc_uint8_t     LUT2_0  [1<< 7];
+mpc_uint8_t     LUT2_1  [1<<10];            // 1152 Bytes
+mpc_uint8_t     LUT3_0  [1<< 4];
+mpc_uint8_t     LUT3_1  [1<< 5];            //   48 Bytes
+mpc_uint8_t     LUT4_0  [1<< 4];
+mpc_uint8_t     LUT4_1  [1<< 5];            //   48 Bytes
+mpc_uint8_t     LUT5_0  [1<< 6];
+mpc_uint8_t     LUT5_1  [1<< 8];            //  320 Bytes
+mpc_uint8_t     LUT6_0  [1<< 7];
+mpc_uint8_t     LUT6_1  [1<< 7];            //  256 Bytes
+mpc_uint8_t     LUT7_0  [1<< 8];
+mpc_uint8_t     LUT7_1  [1<< 8];            //  512 Bytes
+mpc_uint8_t     LUTDSCF [1<< 6];            //   64 Bytes = 2976 Bytes
+
+const Huffman_t* HuffQ [2] [8] = {
+    { NULL, HuffQ1[0], HuffQ2[0], HuffQ3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0] },
+    { NULL, HuffQ1[1], HuffQ2[1], HuffQ3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1] }
+};
+
+#ifdef USE_SV8
+Huffman_t   HuffN3 [2] [ 7*7];          // 8+ 9 bit
+Huffman_t   HuffN8 [2][127];            //13+12 bit
+
+const Huffman_t* HuffN [2] [9] = {
+    { NULL, HuffQ1[0], HuffQ2[0], HuffN3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0], HuffN8[0] },
+    { NULL, HuffQ1[1], HuffQ2[1], HuffN3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1], HuffN8[1] }
+};
+#endif
+
+static const HuffSrc_t   HuffSCFI_src [4] = {
+    { 2, 3 }, { 1, 1 }, { 3, 3 }, { 0, 2 }
+};
+
+static const HuffSrc_t   HuffDSCF_src [16] = {
+    { 32, 6 }, {  4, 5 }, { 17, 5 }, { 30, 5 }, { 13, 4 }, {  0, 3 }, {  3, 3 }, {  9, 4 },
+    {  5, 3 }, {  2, 3 }, { 14, 4 }, {  3, 4 }, { 31, 5 }, {  5, 5 }, { 33, 6 }, { 12, 4 }
+};
+
+static const HuffSrc_t   HuffHdr_src [10] = {
+    {  92, 8 }, {  47, 7 }, {  10, 5 }, {   4, 4 }, {   0, 2 },
+    {   1, 1 }, {   3, 3 }, {  22, 6 }, { 187, 9 }, { 186, 9 }
+};
+
+static const HuffSrc_t   HuffQ1_src [2] [3*3*3] = { {
+    { 54, 6 }, {  9, 5 }, { 32, 6 }, {  5, 5 }, { 10, 4 }, {  7, 5 }, { 52, 6 }, {  0, 5 }, { 35, 6 },
+    { 10, 5 }, {  6, 4 }, {  4, 5 }, { 11, 4 }, {  7, 3 }, { 12, 4 }, {  3, 5 }, {  7, 4 }, { 11, 5 },
+    { 34, 6 }, {  1, 5 }, { 53, 6 }, {  6, 5 }, {  9, 4 }, {  2, 5 }, { 33, 6 }, {  8, 5 }, { 55, 6 }
+}, {
+    { 103, 8 }, {  62, 7 }, { 225, 9 }, {  55, 7 }, {   3, 4 }, {  52, 7 }, { 101, 8 }, {  60, 7 }, { 227, 9 },
+    {  24, 6 }, {   0, 4 }, {  61, 7 }, {   4, 4 }, {   1, 1 }, {   5, 4 }, {  63, 7 }, {   1, 4 }, {  59, 7 },
+    { 226, 9 }, {  57, 7 }, { 100, 8 }, {  53, 7 }, {   2, 4 }, {  54, 7 }, { 224, 9 }, {  58, 7 }, { 102, 8 }
+} };
+
+static const HuffSrc_t   HuffQ2_src [2] [5*5] = { {
+    {  89,  7 }, {  47,  6 }, { 15, 5 }, {   0, 5 }, {  91,  7 },
+    {   4,  5 }, {   6,  4 }, { 13, 4 }, {   4, 4 }, {   5,  5 },
+    {  20,  5 }, {  12,  4 }, {  4, 3 }, {  15, 4 }, {  14,  5 },
+    {   3,  5 }, {   3,  4 }, { 14, 4 }, {   5, 4 }, {   1,  5 },
+    {  90,  7 }, {   2,  5 }, { 21, 5 }, {  46, 6 }, {  88,  7 }
+}, {
+    { 921, 10 }, { 113,  7 }, { 51, 6 }, { 231, 8 }, { 922, 10 },
+    { 104,  7 }, {  30,  5 }, {  0, 3 }, {  29, 5 }, { 105,  7 },
+    {  50,  6 }, {   1,  3 }, {  2, 2 }, {   3, 3 }, {  49,  6 },
+    { 107,  7 }, {  27,  5 }, {  2, 3 }, {  31, 5 }, { 112,  7 },
+    { 920, 10 }, { 106,  7 }, { 48, 6 }, { 114, 7 }, { 923, 10 }
+} };
+
+#ifdef USE_SV8
+static const HuffSrc_t   HuffN3_src [2] [7*7] = { {
+    {  78, 7 }, {  20, 6 }, {  36, 6 }, {  51, 6 }, {  21, 6 }, { 101, 7 }, { 255, 8 },
+    {  37, 6 }, {   0, 5 }, {  62, 6 }, {   7, 5 }, {  60, 6 }, {  49, 6 }, { 100, 7 },
+    {  30, 6 }, {  53, 6 }, {   8, 5 }, {  14, 5 }, {   5, 5 }, {  54, 6 }, {  26, 6 },
+    {  43, 6 }, {   1, 5 }, {  20, 5 }, {  14, 4 }, {  22, 5 }, {   9, 5 }, {  46, 6 },
+    {  47, 6 }, {  61, 6 }, {  17, 5 }, {  16, 5 }, {  11, 5 }, {   4, 5 }, {  38, 6 },
+    {   6, 6 }, {  52, 6 }, {   6, 5 }, {  12, 5 }, {   2, 5 }, {  55, 6 }, {  27, 6 },
+    { 254, 8 }, { 126, 7 }, {  31, 6 }, {  48, 6 }, {  42, 6 }, {   7, 6 }, {  79, 7 }
+}, {
+    {  65, 9 }, { 161, 8 }, { 109, 7 }, {  11, 6 }, { 116, 7 }, { 160, 8 }, {  71, 9 },
+    {  34, 8 }, {  97, 7 }, {  56, 6 }, {   8, 5 }, {  55, 6 }, {  85, 7 }, { 166, 8 },
+    {  84, 7 }, {  52, 6 }, {   3, 4 }, {  11, 4 }, {   5, 4 }, {  59, 6 }, {  86, 7 },
+    {  10, 6 }, {  13, 5 }, {   9, 4 }, {   0, 3 }, {   8, 4 }, {  12, 5 }, {   9, 6 },
+    {  98, 7 }, {  51, 6 }, {  31, 5 }, {   7, 4 }, {  30, 5 }, {  53, 6 }, {  99, 7 },
+    { 162, 8 }, { 108, 7 }, {  50, 6 }, {   9, 5 }, {  57, 6 }, {  82, 7 }, { 163, 8 },
+    {  64, 9 }, { 167, 8 }, {  87, 7 }, { 117, 7 }, {  96, 7 }, {  33, 8 }, {  70, 9 }
+} };
+#endif
+
+static const HuffSrc_t   HuffQ3_src [2] [ 7] = { {
+    { 12, 4 }, { 4, 3 }, { 0, 2 }, { 1, 2 }, { 7, 3 }, { 5, 3 }, { 13, 4 }
+}, {
+    {  4, 5 }, { 3, 4 }, { 2, 2 }, { 3, 2 }, { 1, 2 }, { 0, 3 }, {  5, 5 }
+} };
+
+static const HuffSrc_t   HuffQ4_src [2] [ 9] = { {
+    { 5, 4 }, {  0, 3 }, { 4, 3 }, { 6, 3 }, { 7, 3 }, { 5, 3 }, {  3, 3 }, { 1, 3 }, { 4, 4 }
+}, {
+    { 9, 5 }, { 12, 4 }, { 3, 3 }, { 0, 2 }, { 2, 2 }, { 7, 3 }, { 13, 4 }, { 5, 4 }, { 8, 5 }
+} };
+
+static const HuffSrc_t   HuffQ5_src [2] [15] = { {
+    {  57, 6 }, { 23, 5 }, {  8, 4 }, { 10, 4 }, { 13, 4 }, {   0, 3 }, {   2, 3 }, { 3, 3 },
+    {   1, 3 }, { 15, 4 }, { 12, 4 }, {  9, 4 }, { 29, 5 }, {  22, 5 }, {  56, 6 }
+}, {
+    { 229, 8 }, { 56, 6 }, {  7, 5 }, {  2, 4 }, {  0, 3 }, {   3, 3 }, {   5, 3 }, { 6, 3 },
+    {   4, 3 }, {  2, 3 }, { 15, 4 }, { 29, 5 }, {  6, 5 }, { 115, 7 }, { 228, 8 },
+} };
+
+static const HuffSrc_t   HuffQ6_src [2] [31] = { {
+    {   65,  7 }, {    6,  6 }, {  44,  6 }, {  45, 6 }, {   59,  6 }, {   13,  5 }, {   17,  5 }, { 19, 5 },
+    {   23,  5 }, {   21,  5 }, {  26,  5 }, {  30, 5 }, {    0,  4 }, {    2,  4 }, {    5,  4 }, {  7, 4 },
+    {    3,  4 }, {    4,  4 }, {  31,  5 }, {  28, 5 }, {   25,  5 }, {   27,  5 }, {   24,  5 }, { 20, 5 },
+    {   18,  5 }, {   12,  5 }, {   2,  5 }, {  58, 6 }, {   33,  6 }, {    7,  6 }, {   64,  7 },
+}, {
+    { 6472, 13 }, { 6474, 13 }, { 808, 10 }, { 405, 9 }, {  203,  8 }, {  102,  7 }, {   49,  6 }, {  9, 5 },
+    {   15,  5 }, {   31,  5 }, {   2,  4 }, {   6, 4 }, {    8,  4 }, {   11,  4 }, {   13,  4 }, {  0, 3 },
+    {   14,  4 }, {   10,  4 }, {   9,  4 }, {   5, 4 }, {    3,  4 }, {   30,  5 }, {   14,  5 }, {  8, 5 },
+    {   48,  6 }, {  103,  7 }, { 201,  8 }, { 200, 8 }, { 1619, 11 }, { 6473, 13 }, { 6475, 13 },
+} };
+
+static const HuffSrc_t   HuffQ7_src [2] [63] = { {
+    { 103, 8 },    // 0.3338   01100111
+    { 153, 8 },    // 0.3766   10011001
+    { 181, 8 },    // 0.4715   10110101
+    { 233, 8 },    // 0.5528   11101001
+    {  64, 7 },    // 0.6677    1000000
+    {  65, 7 },    // 0.7041    1000001
+    {  77, 7 },    // 0.7733    1001101
+    {  81, 7 },    // 0.8296    1010001
+    {  91, 7 },    // 0.9295    1011011
+    { 113, 7 },    // 1.0814    1110001
+    { 112, 7 },    // 1.0807    1110000
+    {  24, 6 },    // 1.2748     011000
+    {  29, 6 },    // 1.3390     011101
+    {  35, 6 },    // 1.4224     100011
+    {  37, 6 },    // 1.5201     100101
+    {  41, 6 },    // 1.6642     101001
+    {  44, 6 },    // 1.7292     101100
+    {  46, 6 },    // 1.8647     101110
+    {  51, 6 },    // 2.0473     110011
+    {  49, 6 },    // 2.0152     110001
+    {  54, 6 },    // 2.1315     110110
+    {  55, 6 },    // 2.1358     110111
+    {  57, 6 },    // 2.1700     111001
+    {  60, 6 },    // 2.2449     111100
+    {   0, 5 },    // 2.3063      00000
+    {   2, 5 },    // 2.3854      00010
+    {  10, 5 },    // 2.5481      01010
+    {   5, 5 },    // 2.4867      00101
+    {   9, 5 },    // 2.5352      01001
+    {   6, 5 },    // 2.5074      00110
+    {  13, 5 },    // 2.5745      01101
+    {   7, 5 },    // 2.5195      00111
+    {  11, 5 },    // 2.5502      01011
+    {  15, 5 },    // 2.6251      01111
+    {   8, 5 },    // 2.5260      01000
+    {   4, 5 },    // 2.4418      00100
+    {   3, 5 },    // 2.3983      00011
+    {   1, 5 },    // 2.3697      00001
+    {  63, 6 },    // 2.3041     111111
+    {  62, 6 },    // 2.2656     111110
+    {  61, 6 },    // 2.2549     111101
+    {  53, 6 },    // 2.1151     110101
+    {  59, 6 },    // 2.2042     111011
+    {  52, 6 },    // 2.0837     110100
+    {  48, 6 },    // 1.9446     110000
+    {  47, 6 },    // 1.9189     101111
+    {  43, 6 },    // 1.7177     101011
+    {  42, 6 },    // 1.7035     101010
+    {  39, 6 },    // 1.5287     100111
+    {  36, 6 },    // 1.4559     100100
+    {  33, 6 },    // 1.4117     100001
+    {  28, 6 },    // 1.2776     011100
+    { 117, 7 },    // 1.1107    1110101
+    { 101, 7 },    // 1.0636    1100101
+    { 100, 7 },    // 0.9751    1100100
+    {  80, 7 },    // 0.8132    1010000
+    {  69, 7 },    // 0.7091    1000101
+    {  68, 7 },    // 0.7084    1000100
+    {  50, 7 },    // 0.6277    0110010
+    { 232, 8 },    // 0.5386   11101000
+    { 180, 8 },    // 0.4408   10110100
+    { 152, 8 },    // 0.3759   10011000
+    { 102, 8 },    // 0.3160   01100110
+}, {
+    { 14244, 14 },    // 0.0059   11011110100100
+    { 14253, 14 },    // 0.0098   11011110101101
+    { 14246, 14 },    // 0.0078   11011110100110
+    { 14254, 14 },    // 0.0111   11011110101110
+    {  3562, 12 },    // 0.0320     110111101010
+    {   752, 10 },    // 0.0920       1011110000
+    {   753, 10 },    // 0.1057       1011110001
+    {   160,  9 },    // 0.1403        010100000
+    {   162,  9 },    // 0.1579        010100010
+    {   444,  9 },    // 0.2486        110111100
+    {   122,  8 },    // 0.3772         01111010
+    {   223,  8 },    // 0.5710         11011111
+    {    60,  7 },    // 0.6858          0111100
+    {    73,  7 },    // 0.8033          1001001
+    {   110,  7 },    // 0.9827          1101110
+    {    14,  6 },    // 1.2601           001110
+    {    24,  6 },    // 1.3194           011000
+    {    25,  6 },    // 1.3938           011001
+    {    34,  6 },    // 1.5693           100010
+    {    37,  6 },    // 1.7846           100101
+    {    54,  6 },    // 2.0078           110110
+    {     3,  5 },    // 2.2975            00011
+    {     9,  5 },    // 2.5631            01001
+    {    11,  5 },    // 2.7021            01011
+    {    16,  5 },    // 3.1465            10000
+    {    19,  5 },    // 3.4244            10011
+    {    21,  5 },    // 3.5921            10101
+    {    24,  5 },    // 3.7938            11000
+    {    26,  5 },    // 3.9595            11010
+    {    29,  5 },    // 4.1546            11101
+    {    31,  5 },    // 4.2623            11111
+    {     2,  4 },    // 4.5180             0010
+    {     0,  4 },    // 4.3151             0000
+    {    30,  5 },    // 4.2538            11110
+    {    28,  5 },    // 4.1422            11100
+    {    25,  5 },    // 3.9145            11001
+    {    22,  5 },    // 3.6691            10110
+    {    20,  5 },    // 3.4955            10100
+    {    14,  5 },    // 2.9155            01110
+    {    13,  5 },    // 2.7921            01101
+    {     8,  5 },    // 2.5553            01000
+    {     6,  5 },    // 2.3093            00110
+    {     2,  5 },    // 2.1200            00010
+    {    46,  6 },    // 1.8134           101110
+    {    35,  6 },    // 1.5824           100011
+    {    31,  6 },    // 1.4701           011111
+    {    21,  6 },    // 1.3187           010101
+    {    15,  6 },    // 1.2776           001111
+    {    95,  7 },    // 0.9664          1011111
+    {    72,  7 },    // 0.7922          1001000
+    {    41,  7 },    // 0.6838          0101001
+    {   189,  8 },    // 0.5024         10111101
+    {   123,  8 },    // 0.3830         01111011
+    {   377,  9 },    // 0.2232        101111001
+    {   161,  9 },    // 0.1566        010100001
+    {   891, 10 },    // 0.1383       1101111011
+    {   327, 10 },    // 0.0900       0101000111
+    {   326, 10 },    // 0.0790       0101000110
+    {  3560, 12 },    // 0.0254     110111101000
+    { 14255, 14 },    // 0.0117   11011110101111
+    { 14247, 14 },    // 0.0085   11011110100111
+    { 14252, 14 },    // 0.0085   11011110101100
+    { 14245, 14 },    // 0.0065   11011110100101
+} };
+
+#ifdef USE_SV8
+static const HuffSrc_t   HuffN8_src [2] [127] = { {
+    { 2426, 13 }, { 4943, 13 }, {  787, 12 }, { 2470, 12 }, { 7270, 13 }, { 1764, 12 },
+    { 3632, 12 }, { 3633, 12 }, { 2486, 12 }, {  395, 11 }, {  607, 11 }, { 1242, 11 },
+    {  108, 10 }, {  300, 10 }, {  199, 10 }, {  440, 10 }, {  442, 10 }, {  616, 10 },
+    {  909, 10 }, {  897, 10 }, {  178,  9 }, {  309,  9 }, {  311,  9 }, {  451,  9 },
+    {  449,  9 }, {   26,  8 }, {   74,  8 }, {   94,  8 }, {  122,  8 }, {  136,  8 },
+    {   12,  7 }, {   29,  7 }, {   28,  7 }, {   36,  7 }, {   39,  7 }, {   46,  7 },
+    {   60,  7 }, {   69,  7 }, {   76,  7 }, {   92,  7 }, {  126,  7 }, {   11,  6 },
+    {   15,  6 }, {   10,  6 }, {   16,  6 }, {   21,  6 }, {   25,  6 }, {   28,  6 },
+    {   32,  6 }, {   31,  6 }, {   37,  6 }, {   47,  6 }, {   43,  6 }, {   35,  6 },
+    {   45,  6 }, {   48,  6 }, {   52,  6 }, {   53,  6 }, {   54,  6 }, {   62,  6 },
+    {   59,  6 }, {    0,  5 }, {   61,  6 }, {   51,  6 }, {    2,  5 }, {    1,  5 },
+    {   60,  6 }, {   57,  6 }, {   58,  6 }, {   55,  6 }, {   50,  6 }, {   49,  6 },
+    {   42,  6 }, {   40,  6 }, {   44,  6 }, {   41,  6 }, {   39,  6 }, {   33,  6 },
+    {   29,  6 }, {   26,  6 }, {   24,  6 }, {   20,  6 }, {   17,  6 }, {   13,  6 },
+    {    8,  6 }, {    9,  6 }, {  127,  7 }, {   93,  7 }, {   73,  7 }, {   72,  7 },
+    {   54,  7 }, {   38,  7 }, {   45,  7 }, {   14,  7 }, {   25,  7 }, {   15,  7 },
+    {  226,  8 }, {  137,  8 }, {  111,  8 }, {   95,  8 }, {   88,  8 }, {   48,  8 },
+    {  455,  9 }, {  450,  9 }, {  246,  9 }, {  247,  9 }, {  179,  9 }, {   55,  9 },
+    {  896, 10 }, {  620, 10 }, {  443, 10 }, {  302, 10 }, {  301, 10 }, {  198, 10 },
+    {  109, 10 }, { 1234, 11 }, {  883, 11 }, {  392, 11 }, {  394, 11 }, { 3634, 12 },
+    { 2487, 12 }, {  786, 12 }, { 1765, 12 }, { 1212, 12 }, { 7271, 13 }, { 2427, 13 },
+    { 4942, 13 }
+}, {
+    { 3728, 12 }, { 4005, 12 }, {  264, 11 }, { 4004, 12 }, { 4044, 12 }, { 4045, 12 },
+    { 4046, 12 }, { 1424, 11 }, {  449, 11 }, {  448, 11 }, {  139, 10 }, {  231, 10 },
+    {  133, 10 }, {  719, 10 }, {  641, 10 }, {  676, 10 }, {  225, 10 }, {  677, 10 },
+    {  620, 10 }, {   72,  9 }, {   23,  9 }, {   67,  9 }, {   75,  9 }, {  113,  9 },
+    {  311,  9 }, {   68,  9 }, {  316,  9 }, {  467,  9 }, {   10,  8 }, {  468,  9 },
+    {   35,  8 }, {   27,  8 }, {  358,  9 }, {   32,  8 }, {   26,  8 }, {  501,  9 },
+    {   44,  8 }, {   45,  8 }, {  142,  8 }, {  173,  8 }, {  161,  8 }, {  188,  8 },
+    {  189,  8 }, {  190,  8 }, {  191,  8 }, {  254,  8 }, {  251,  8 }, {  255,  8 },
+    {   19,  7 }, {   26,  7 }, {   70,  7 }, {   76,  7 }, {   87,  7 }, {   85,  7 },
+    {  124,  7 }, {    7,  6 }, {   15,  6 }, {   41,  6 }, {   46,  6 }, {    2,  5 },
+    {   16,  5 }, {   28,  5 }, {   12,  4 }, {    1,  2 }, {   13,  4 }, {   30,  5 },
+    {   18,  5 }, {    0,  5 }, {   45,  6 }, {   34,  6 }, {   12,  6 }, {    3,  6 },
+    {  118,  7 }, {   88,  7 }, {   81,  7 }, {   29,  7 }, {   78,  7 }, {   23,  7 },
+    {   27,  7 }, {  253,  8 }, {   12,  7 }, {  232,  8 }, {  235,  8 }, {  159,  8 },
+    {  238,  8 }, {  172,  8 }, {  168,  8 }, {  143,  8 }, {  154,  8 }, {   40,  8 },
+    {    8,  8 }, {  478,  9 }, {    9,  8 }, {  479,  9 }, {  469,  9 }, {   42,  8 },
+    {   43,  8 }, {  504,  9 }, {  357,  9 }, {  321,  9 }, {  339,  9 }, {  317,  9 },
+    {  114,  9 }, {   82,  9 }, {   83,  9 }, {   73,  9 }, {   74,  9 }, { 1000, 10 },
+    {  933, 10 }, {  621, 10 }, {  718, 10 }, { 2003, 11 }, {  713, 10 }, { 2020, 11 },
+    {  230, 10 }, { 1865, 11 }, {   44, 10 }, {  138, 10 }, { 1280, 11 }, { 2021, 11 },
+    { 3729, 12 }, { 4047, 12 }, {   90, 11 }, {  265, 11 }, { 1281, 11 }, { 1425, 11 },
+    {   91, 11 }
+} };
+#endif
+
+#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)) )
+
+
+void
+Init_Huffman_Encoder_SV7 ( void )
+{
+    // Splitting of the 36 Samples
+    MAKE ( HuffSCFI, HuffSCFI_src );
+
+    // Differential Scalefactors
+    MAKE ( HuffDSCF, HuffDSCF_src );
+
+    // resolution, differential quantizer indizes
+    MAKE ( HuffHdr, HuffHdr_src );
+
+    // 3-step quantizer, 3 bundled samples
+    MAKE ( HuffQ1[0], HuffQ1_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ1[1], HuffQ1_src[1] );          // more shaped, book 1
+
+    // 5-step quantizer, 2 bundled samples
+    MAKE ( HuffQ2[0], HuffQ2_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ2[1], HuffQ2_src[1] );          // more shaped, book 1
+
+    // 7-step quantizer, single samples
+    MAKE ( HuffQ3[0], HuffQ3_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ3[1], HuffQ3_src[1] );          // more shaped, book 1
+
+#ifdef USE_SV8
+    // 7-step quantizer, 2 bundled samples
+    MAKE ( HuffN3[0], HuffN3_src[0] );          // less shaped, book 0
+    MAKE ( HuffN3[1], HuffN3_src[1] );          // more shaped, book 1
+#endif
+
+    // 9-step quantizer, single samples
+    MAKE ( HuffQ4[0], HuffQ4_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ4[1], HuffQ4_src[1] );          // more shaped, book 1
+
+    // 15-step quantizer, single samples
+    MAKE ( HuffQ5[0], HuffQ5_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ5[1], HuffQ5_src[1] );          // more shaped, book 1
+
+    // 31-step quantizer, single samples
+    MAKE ( HuffQ6[0], HuffQ6_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ6[1], HuffQ6_src[1] );          // more shaped, book 1
+
+    // 63-step quantizer, single samples
+    MAKE ( HuffQ7[0], HuffQ7_src[0] );          // less shaped, book 0
+    MAKE ( HuffQ7[1], HuffQ7_src[1] );          // more shaped, book 1
+
+#ifdef USE_SV8
+    // 127-step quantizer, single samples
+    MAKE ( HuffN8[0], HuffN8_src[0] );          // book 0
+    MAKE ( HuffN8[1], HuffN8_src[1] );          // book 1
+#endif
+}
+
+#ifndef MPP_ENCODER
+
+void
+Init_Huffman_Decoder_SV7 ( void )
+{
+    Init_Huffman_Encoder_SV7 ();
+
+    SORT ( HuffHdr  ,    5  );
+    SORT ( HuffSCFI ,    0  );
+    SORT ( HuffDSCF ,    7  );
+    SORT ( HuffQ1[0],    0  );
+    SORT ( HuffQ1[1],    0  );
+    SORT ( HuffQ2[0],    0  );
+    SORT ( HuffQ2[1],    0  );
+#ifdef USE_SV8
+    SORT ( HuffN3[0],    0  );
+    SORT ( HuffN3[1],    0  );
+#endif
+    SORT ( HuffQ3[0], Dc[3] );
+    SORT ( HuffQ3[1], Dc[3] );
+    SORT ( HuffQ4[0], Dc[4] );
+    SORT ( HuffQ4[1], Dc[4] );
+    SORT ( HuffQ5[0], Dc[5] );
+    SORT ( HuffQ5[1], Dc[5] );
+    SORT ( HuffQ6[0], Dc[6] );
+    SORT ( HuffQ6[1], Dc[6] );
+    SORT ( HuffQ7[0], Dc[7] );
+    SORT ( HuffQ7[1], Dc[7] );
+#ifdef USE_SV8
+    SORT ( HuffN8[0], Dc[8] );
+    SORT ( HuffN8[1], Dc[8] );
+#endif
+
+    LOOKUP ( HuffQ1[0], LUT1_0  );
+    LOOKUP ( HuffQ1[1], LUT1_1  );
+    LOOKUP ( HuffQ2[0], LUT2_0  );
+    LOOKUP ( HuffQ2[1], LUT2_1  );
+    LOOKUP ( HuffQ3[0], LUT3_0  );
+    LOOKUP ( HuffQ3[1], LUT3_1  );
+    LOOKUP ( HuffQ4[0], LUT4_0  );
+    LOOKUP ( HuffQ4[1], LUT4_1  );
+    LOOKUP ( HuffQ5[0], LUT5_0  );
+    LOOKUP ( HuffQ5[1], LUT5_1  );
+    LOOKUP ( HuffQ6[0], LUT6_0  );
+    LOOKUP ( HuffQ6[1], LUT6_1  );
+    LOOKUP ( HuffQ7[0], LUT7_0  );
+    LOOKUP ( HuffQ7[1], LUT7_1  );
+    LOOKUP ( HuffDSCF , LUTDSCF );
+}
+
+#endif
+
+/* end of huffsv7.c */
Index: mppenc/branches/r2d/libmpcenc/libmpcenc.h
===================================================================
--- mppenc/branches/r2d/libmpcenc/libmpcenc.h	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/libmpcenc.h	(revision 64)
@@ -0,0 +1,72 @@
+/*
+ * 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
+ */
+
+#pragma once
+
+#include "config_types.h"
+
+// FIXME : define this somewhere else
+#ifndef NULL
+#define NULL 0
+#endif
+
+// FIXME : remove MPPENC_VERSION from here
+#ifndef MPPENC_VERSION
+# define MPPENC_VERSION   "1.15w-6"
+#endif
+
+// bitstream.c
+#define BUFFER_ALMOST_FULL  8192
+#define BUFFER_FULL         (BUFFER_ALMOST_FULL + 4352)         // 34490 bit/frame  1320.3 kbps
+
+// bitstream.c
+typedef struct {
+	mpc_uint32_t*	ptr;
+	unsigned int	bit;
+} BitstreamPos;
+
+typedef struct {
+	unsigned int  L [36];
+	unsigned int  R [36];
+} SubbandQuantTyp;
+
+// TODO : enc/dec common struct
+// just the same struct as below, dup ?
+typedef struct {
+	mpc_uint16_t	Length;  // >=  4 bit
+	mpc_uint16_t	Code;  // >= 14 bit
+} HuffSrc_t ;
+
+typedef struct {
+	mpc_uint16_t	Length;      // >=  4 bit
+	mpc_uint16_t	Code;        // >= 14 bit
+} Huffman_t ;
+
+// TODO : match with mpc_decoder_t
+// FIXME : add init code
+typedef struct mpc_encoder_t {
+	mpc_uint32_t	Buffer [BUFFER_FULL];    // Buffer for bitstream-file
+	mpc_uint32_t	dword; //         =  0;      // 32-bit-Word for Bitstream-I/O
+	mpc_int32_t		filled; //        = 32;      // Position in the the 32-bit-word that's currently about to be filled
+	mpc_uint32_t	Zaehler; //       =  0;      // Position pointer for the processed bitstream-word (32 bit)
+	mpc_uint64_t	BufferedBits; //  =  0;      // Counter for the number of written bits in the bitstream
+
+	unsigned int  MS_Channelmode;
+	unsigned int  Overflows; //       = 0;      // number of internal (filterbank) clippings
+} mpc_encoder;
+
Index: mppenc/branches/r2d/libmpcenc/minimax.h
===================================================================
--- mppenc/branches/r2d/libmpcenc/minimax.h	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/minimax.h	(revision 64)
@@ -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/quant.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/quant.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/quant.c	(revision 64)
@@ -0,0 +1,323 @@
+/*
+ * Musepack audio compression
+ * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "libmpcenc.h"
+
+#include <math.h>
+
+/* V A R I A B L E S */
+float  __SCF    [128 + 6];   // tabulated scalefactors
+#define SCF             ( __SCF + 6 )
+float  __invSCF [128 + 6];   // inverted scalefactors
+#define invSCF  (__invSCF + 6)
+
+
+// Quantization-coefficients: step/65536 bzw. (2*D[Res]+1)/65536
+static const float  __A [1 + 18] = {
+    0.0000762939453125f,
+    0.0000000000000000f, 0.0000457763671875f, 0.0000762939453125f, 0.0001068115234375f,
+    0.0001373291015625f, 0.0002288818359375f, 0.0004730224609375f, 0.0009613037109375f,
+    0.0019378662109375f, 0.0038909912109375f, 0.0077972412109375f, 0.0156097412109375f,
+    0.0312347412109375f, 0.0624847412109375f, 0.1249847412109375f, 0.2499847412109375f,
+    0.4999847412109375f
+};
+
+
+// Requantization-coefficients: 65536/step bzw. 1/A[Res]
+static const float  __C [1 + 18] = {
+    13107.200000000001f,
+    65535.000000000000f, 21845.333333333332f, 13107.200000000001f, 9362.285714285713f,
+     7281.777777777777f,  4369.066666666666f,  2114.064516129032f, 1040.253968253968f,
+      516.031496062992f,   257.003921568627f,   128.250489236790f,   64.062561094819f,
+       32.015632633121f,    16.003907203907f,     8.000976681723f,    4.000244155527f,
+        2.000061037018f,     1.000015259022f
+};
+
+
+// Requantization-Offset: 2*D+1 = steps of quantizer
+static const int  __D [1 + 18] = {
+    2,
+    0,     1,     2,     3,     4,     7,    15,    31,    63,
+  127,   255,   511,  1023,  2047,  4095,  8191, 16383, 32767
+};
+
+#define A   (__A + 1)
+#define C   (__C + 1)
+#define D   (__D + 1)
+
+// Generation of the scalefactors and their inverses
+void
+Init_Skalenfaktoren ( void )
+{
+    int  n;
+
+    for ( n = -6; n < 128; n++ ) {
+        SCF[n]    = (float) ( pow(10.,-0.1*(n-1)/1.26) );
+        invSCF[n] = (float) ( pow(10., 0.1*(n-1)/1.26) );
+    }
+}
+
+#pragma warning ( disable : 4305 )
+
+static float  NoiseInjectionCompensation1D [18] = {
+#if 1
+    1.f,
+    0.884621,
+    0.935711,
+    0.970829,
+    0.987941,
+    0.994315,
+    0.997826,
+    0.999744,
+    1., 1., 1., 1., 1., 1., 1., 1., 1., 1.
+#else
+    1.,
+    0.907073,   //  -1...+1
+    0.946334,   //  -2...+2
+    0.974793,   //  -3...+3
+    0.987647,   //  -4...+4
+    0.994330,   //  -7...+7
+    0.997846,   // -15...+15
+    1.,         // -31...+31
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+    1.,
+#endif
+} ;
+
+#if 0
+static float  NoiseInjectionCompensation2D [18] [32] = {
+    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
+    { 0.931595, 0.891390, 0.852494, 0.872420, 0.904053, 0.933716, 0.958976, 0.977719, 0.993979, 1.009011, 1.020961, 1.029564, 1.026582, 1.026753, 1.035573, 1.053251, 1.073429, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344,  },
+    { 0.878264, 0.882351, 0.904261, 0.930843, 0.949243, 0.966741, 0.980500, 0.988182, 0.993361, 0.997112, 0.998918, 0.999501, 1.003179, 1.007445, 1.008678, 0.995890, 0.991015, 0.988019, 0.985479, 0.987646, 1.003605, 1.029301, 1.040511, 1.061531, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302,  },
+    { 0.866977, 0.943500, 0.941561, 0.953049, 0.967274, 0.980476, 0.988678, 0.993240, 0.996376, 0.998513, 0.999545, 0.999775, 1.000898, 1.003954, 1.006308, 1.004932, 1.002867, 1.002922, 1.003624, 1.005487, 1.003919, 1.008022, 0.987693, 1.000358, 1.017461, 1.039166, 1.056053, 1.068191, 1.068191, 1.068191, 1.068191, 1.068191,  },
+    { 0.880390, 0.976713, 0.976180, 0.976596, 0.982011, 0.988786, 0.993619, 0.996641, 0.998824, 1.000297, 1.001195, 1.001718, 1.002395, 1.003503, 1.005617, 1.005072, 1.002409, 1.003703, 1.003412, 1.003318, 1.005290, 1.007112, 1.014370, 1.010040, 1.000780, 1.005700, 1.020505, 1.030123, 1.030123, 1.030123, 1.030123, 1.030123,  },
+    { 0.916894, 0.987164, 0.988734, 0.992318, 0.995268, 0.996932, 0.998141, 0.999072, 0.999674, 1.000104, 1.000292, 1.000386, 1.000399, 1.000222, 1.000671, 1.002127, 1.000137, 1.000046, 0.999644, 0.999156, 1.000568, 1.000098, 0.993764, 0.993954, 0.998971, 1.002835, 1.002972, 0.995376, 1.001643, 1.001643, 1.001643, 1.001643,  },
+    { 0.982771, 0.995034, 0.997118, 0.998294, 0.998652, 0.999016, 0.999382, 0.999598, 0.999746, 0.999851, 0.999837, 0.999881, 0.999847, 1.000154, 0.999885, 1.000222, 0.999963, 1.000934, 0.999804, 0.999927, 1.000379, 0.997574, 0.997943, 0.998748, 0.998151, 0.997458, 1.000319, 1.001091, 0.998461, 0.996151, 1.005969, 1.005969,  },
+    { 0.997150, 0.999903, 0.999424, 0.999537, 0.999661, 0.999753, 0.999851, 0.999903, 0.999928, 0.999963, 0.999969, 0.999941, 0.999974, 0.999967, 0.999996, 0.999975, 0.999966, 0.999704, 0.999946, 0.999894, 0.999905, 1.000840, 1.000716, 1.000799, 1.000406, 0.999912, 1.000153, 0.999789, 1.000495, 1.000495, 1.001167, 1.001347,  },
+    { 0.995524, 0.999983, 1.000044, 0.999965, 0.999970, 0.999974, 0.999986, 0.999995, 0.999996, 1.000011, 0.999997, 1.000010, 1.000010, 1.000026, 1.000006, 1.000148, 1.000048, 0.999999, 1.000161, 1.000193, 0.999797, 1.000145, 0.999974, 1.000039, 0.999731, 0.999985, 1.000563, 1.000256, 1.000637, 1.000050, 1.002013, 1.001053,  },
+    { 0.994796, 0.999833, 1.000003, 1.000012, 0.999986, 0.999991, 0.999991, 1.000000, 1.000004, 0.999999, 1.000005, 1.000004, 1.000008, 0.999996, 1.000027, 1.000097, 0.999951, 0.999938, 0.999989, 1.000001, 1.000048, 0.999935, 1.000068, 1.000134, 0.999961, 1.000198, 0.999956, 0.999957, 0.999844, 1.000087, 0.999708, 1.000198,  },
+    { 0.996046, 0.999902, 1.000019, 1.000017, 0.999983, 0.999997, 1.000002, 0.999993, 0.999999, 1.000003, 1.000001, 1.000015, 1.000004, 1.000006, 0.999987, 0.999993, 0.999992, 1.000029, 1.000064, 0.999997, 1.000044, 1.000044, 0.999919, 0.999875, 1.000011, 0.999897, 0.999905, 0.999996, 0.999934, 0.999968, 1.000008, 0.999902,  },
+    { 0.998703, 0.999963, 1.000021, 1.000006, 1.000008, 1.000000, 1.000003, 0.999994, 0.999990, 0.999990, 1.000003, 1.000009, 1.000001, 0.999999, 1.000001, 1.000009, 0.999999, 0.999988, 1.000003, 0.999971, 1.000005, 1.000042, 0.999924, 0.999995, 0.999998, 0.999988, 0.999961, 0.999942, 1.000046, 1.000061, 1.000112, 1.000052,  },
+    { 0.999872, 1.000001, 1.000004, 0.999998, 0.999999, 0.999998, 0.999992, 0.999990, 0.999991, 1.000000, 1.000000, 1.000000, 1.000002, 0.999996, 1.000004, 1.000011, 0.999963, 1.000016, 1.000050, 0.999996, 0.999998, 1.000006, 0.999990, 0.999948, 0.999974, 1.000060, 1.000014, 0.999987, 0.999986, 0.999917, 0.999973, 1.000035,  },
+    { 1.000366, 1.000006, 0.999996, 0.999995, 0.999998, 0.999996, 0.999991, 1.000001, 0.999990, 0.999996, 1.000010, 0.999999, 1.000002, 1.000000, 0.999996, 0.999990, 1.000014, 0.999978, 1.000011, 0.999983, 0.999988, 0.999971, 0.999997, 0.999989, 0.999986, 0.999958, 1.000005, 0.999992, 0.999975, 0.999975, 0.999975, 0.999975,  },
+    { 0.999736, 0.999995, 1.000002, 1.000004, 0.999999, 1.000000, 1.000003, 1.000000, 1.000007, 0.999992, 0.999997, 0.999998, 0.999998, 0.999997, 1.000007, 1.000012, 1.000004, 0.999995, 0.999996, 1.000009, 1.000003, 1.000008, 1.000001, 1.000003, 1.000011, 1.000019, 0.999991, 0.999970, 0.999970, 0.999970, 0.999970, 0.999965,  },
+    { 0.999970, 1.000000, 1.000000, 1.000000, 1.000001, 1.000000, 1.000000, 0.999999, 1.000001, 1.000000, 0.999999, 0.999999, 0.999999, 1.000007, 1.000005, 1.000002, 0.999999, 0.999999, 1.000000, 0.999997, 0.999999, 1.000001, 1.000001, 0.999988, 0.999988, 0.999984, 0.999995, 0.999986, 0.999986, 0.999986, 0.999986, 0.999986,  },
+    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
+    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
+};
+#endif
+
+#pragma warning ( default : 4305 )
+
+
+void
+NoiseInjectionComp ( void )
+{
+    int  i;
+
+    for ( i = 0; i < sizeof(NoiseInjectionCompensation1D)/sizeof(*NoiseInjectionCompensation1D); i++ )
+        NoiseInjectionCompensation1D [i] = 1.f;
+#if 0
+    for ( i = 0; i < sizeof(NoiseInjectionCompensation2D)/sizeof(**NoiseInjectionCompensation2D); i++ )
+        NoiseInjectionCompensation2D [0][i] = 1.f;
+#endif
+}
+
+
+// Quantizes a subband and calculates iSNR
+float
+ISNR_Schaetzer ( const float* input, const float SNRcomp, const int res )
+{
+    int    k;
+    float  fac    = A [res];
+    float  invfac = C [res];
+    float  Signal = 1.e-30f;
+    float  Fehler = 1.e-30f;
+    float  tmp ;
+    float  tmp2;
+    float  tmp3;
+
+    // Summation of the absolute power and the quadratic error
+    for ( k = 0; k < 36; k++ ) {
+        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
+        // q = ftol(in), correct rounding
+        tmp  = tmp2 * fac + 0xFF8000;
+        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
+        tmp  = tmp3 - tmp2;
+
+        Fehler += tmp * tmp;
+        Signal += tmp2 * tmp2;
+    }
+
+    // Utilization of SNRcomp only if SNR > 1 !!!
+    return Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
+}
+
+
+float
+ISNR_Schaetzer_Trans ( const float* input, const float SNRcomp, const int res )
+{
+    int    k;
+    float  fac    = A [res];
+    float  invfac = C [res];
+    float  Signal;
+    float  Fehler;
+    float  ret ;
+    float  tmp ;
+    float  tmp2;
+    float  tmp3;
+
+    // Summation of the absolute power and the quadratic error
+    k = 0;
+    Signal = Fehler = 1.e-30f;
+    for ( ; k < 12; k++ ) {
+        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
+        // q = ftol(in), correct rounding
+        tmp  = tmp2 * fac + 0xFF8000;
+        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
+        tmp  = tmp3 - tmp2;
+
+        Fehler += tmp * tmp;
+        Signal += tmp2 * tmp2;
+    }
+    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
+    ret = tmp;
+    Signal = Fehler = 1.e-30f;
+    for ( ; k < 24; k++ ) {
+        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
+        // q = ftol(in), correct rounding
+        tmp  = tmp2 * fac + 0xFF8000;
+        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
+        tmp  = tmp3 - tmp2;
+
+        Fehler += tmp * tmp;
+        Signal += tmp2 * tmp2;
+    }
+    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
+    if ( tmp > ret ) ret = tmp;
+    //ret += tmp;
+    Signal = Fehler = 1.e-30f;
+    for ( ; k < 36; k++ ) {
+        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
+        // q = ftol(in), correct rounding
+        tmp  = tmp2 * fac + 0xFF8000;
+        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
+        tmp  = tmp3 - tmp2;
+
+        Fehler += tmp * tmp;
+        Signal += tmp2 * tmp2;
+    }
+    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
+    if ( tmp > ret ) ret = tmp;
+    //ret += tmp;
+    //ret *= 0.33333333333f;
+
+    return ret;
+}
+
+
+// Linear quantizer for a subband
+void
+QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder )
+{
+    int    n;
+    int    offset  = D [res];
+    float  mult    = A [res] * NoiseInjectionCompensation1D [res];
+    float  invmult = C [res];
+    float  tmp;
+    int    quant;
+    float  signal;
+
+	for ( n = 0; n < 36 - maxNsOrder; n++, input++, qu_output++ ) {
+        // q = ftol(in), correct rounding
+        tmp   = *input * mult + 0xFF8000;
+        quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
+
+        // limitation to 0...2D
+        if ((unsigned int)quant > (unsigned int)2*offset ) {
+            quant = mini ( quant, 2*offset );
+            quant = maxi ( quant,        0 );
+        }
+        *qu_output  = quant;
+    }
+
+    for ( ; n < 36; n++, input++, qu_output++ ) {
+        // q = ftol(in), correct rounding
+        signal = *input * mult;
+        tmp   =  signal + 0xFF8000;
+        quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
+
+        // calculate the current error and save it for error refeeding
+        errors [n + 6] = invmult * (quant - offset) - signal * NoiseInjectionCompensation1D [res];
+
+        // limitation to 0...2D
+        if ((unsigned int)quant > (unsigned int)2*offset ) {
+            quant = mini ( quant, 2*offset );
+            quant = maxi ( quant,        0 );
+        }
+        *qu_output  = quant;
+    }
+}
+
+
+// NoiseShaper for a subband
+void
+QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR )
+{
+#define E(x) *((int*)errors+(x))
+
+    float  signal;
+    float  tmp;
+    float  mult    = A [res];
+    float  invmult = C [res];
+    int    offset  = D [res];
+    int    n;
+    int    quant;
+
+    E(0) = E(1) = E(2) = E(3) = E(4) = E(5) = 0;       // arghh, it produces pops on each frame boundary!
+
+    for ( n = 0; n < 36; n++, input++, qu_output++ ) {
+        signal = *input * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
+
+        // quant = ftol(signal), correct rounding
+        tmp   = signal * mult + 0xFF8000;
+        quant = *(int*) & tmp - 0x4B7F8000;
+
+        // calculate the current error and save it for error refeeding
+        errors [n + 6] = invmult * quant - signal * NoiseInjectionCompensation1D [res];
+
+        // limitation to +/-D
+        quant = minf ( quant, +offset );
+        quant = maxf ( quant, -offset );
+
+        *qu_output = (unsigned int)(quant + offset);
+    }
+}
+
+/* end of quant.c */
+
+// pfk@schnecke.offl.uni-jena.de@EMAIL, Andree.Buschmann@web.de@EMAIL, BuschmannA@becker.de@EMAIL, miyaguch@eskimo.com@EMAIL, r3mix@irc.openprojects.net@EMAIL, dibrom@users.sourceforge.net@EMAIL, m.p.bakker-10@student.utwente.nl@EMAIL, djmrob@essex.ac.uk@EMAIL, dim@psytel-research.co.yu@EMAIL, lerch@zplane.de@EMAIL, takehiro@users.sourceforge.net@EMAIL, aleidinger@users.sourceforge.net@EMAIL, Robert.Hegemann@gmx.de@EMAIL, bouvigne@mp3-tech.org@EMAIL, monty@xiph.org@EMAIL, Pumpkinz99@aol.com@EMAIL, spase@outerspase.net@EMAIL, mt@wildpuppy.com@EMAIL, juha.laaksonheimo@tut.fi@EMAIL, speek@myrealbox.com@EMAIL, w.speek@12move.nl@EMAIL, martin@spueler.de@EMAIL, nicolaus.berglmeir@t-online.de@EMAIL, thomas.a.juerges@ruhr-uni-bochum.de@EMAIL, HelH@mpex.net@EMAIL, garf@roadum.demon.co.uk@EMAIL, gcp@sjeng.org@EMAIL, mike@naivesoftware.com@EMAIL, case@mobiili.net@EMAIL, steve.lhomme@free.fr@EMAIL, walter@binity.com@EMAIL
Index: mppenc/branches/r2d/libmpcenc/tools.c
===================================================================
--- mppenc/branches/r2d/libmpcenc/tools.c	(revision 64)
+++ mppenc/branches/r2d/libmpcenc/tools.c	(revision 64)
@@ -0,0 +1,572 @@
+/*
+ * 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>
+
+#include "libmpcenc.h"
+
+#if defined HAVE_INCOMPLETE_READ  &&  FILEIO != 1
+
+size_t
+complete_read ( int fd, void* dest, size_t bytes )
+{
+    size_t  bytesread = 0;
+    size_t  ret;
+
+    while ( bytes > 0 ) {
+#if defined _WIN32  &&  defined USE_HTTP  &&  !defined MPP_ENCODER
+        ret = fd & 0x4000  ?  recv ( fd & 0x3FFF, dest, bytes, 0)  :  read ( fd, dest, bytes );
+#else
+        ret = read ( fd, dest, bytes );
+#endif
+        if ( ret == 0  ||  ret == (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, 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.
+ */
+
+size_t
+Read_LittleEndians ( FILE* fp, mpc_uint32_t* dst, size_t words32bit )
+{
+    size_t  wordsread;
+    wordsread = READ ( fp, dst, words32bit * sizeof(*dst) ) / sizeof(*dst);
+
+#if ENDIAN == HAVE_BIG_ENDIAN
+    Change_Endian32 ( dst, wordsread );
+#endif
+
+    return wordsread;
+}
+
+#ifndef MPP_ENCODER
+
+/*
+ *  This is the main requantisation routine which does the following things:
+ *
+ *      - rescaling the quantized values (int) to their original value (float)
+ *      - recalculating both stereo channels for MS stereo
+ *
+ *  See also: Requantize_IntensityStereo()
+ *
+ *  For performance reasons all cases are programmed separately and the code
+ *  is unrolled.
+ *
+ *  Input is:
+ *      - Stop_Band:
+ *          the last band using MS or LR stereo
+ *      - used_MS[Band]:
+ *          MS or LR stereo flag for every band (0...Stop_Band), Value is 1
+ *          for MS and 0 for LR stereo.
+ *      - Res[Band].{L,R}:
+ *          Quantisation resolution for every band (0...Stop_Band) and
+ *          channels (L, R). Value is 0...17.
+ *      - SCF_Index[3][Band].{L,R}:
+ *          Scale factor for every band (0...Stop_Band), subframe (0...2)
+ *          and channel (L, R).
+ *      - Q[Band].{L,R}[36]
+ *          36 subband samples for every band (0...Stop_Band) and channel (L, R).
+ *      - SCF[64], Cc[18], Dc[18]:
+ *          Lookup tables for Scale factor and Quantisation resolution.
+ *
+ *   Output is:
+ *     - Y_L:  Left  channel subband signals
+ *     - Y_R:  Right channel subband signals
+ *
+ *   These signals are used for the synthesis filter in the synth*.[ch]
+ *   files to generate the PCM output signal.
+ */
+
+static const float ISMatrix [32] [2] = {
+    {  1.00000000f,  0.00000000f },
+    {  0.98078528f,  0.19509032f },
+    {  0.92387953f,  0.38268343f },
+    {  0.83146961f,  0.55557023f },
+    {  0.70710678f,  0.70710678f },
+    {  0.55557023f,  0.83146961f },
+    {  0.38268343f,  0.92387953f },
+    {  0.19509032f,  0.98078528f },
+    {  0.00000000f,  1.00000000f },
+    { -0.19509032f,  0.98078528f },
+    { -0.38268343f,  0.92387953f },
+    { -0.55557023f,  0.83146961f },
+    { -0.70710678f,  0.70710678f },
+    { -0.83146961f,  0.55557023f },
+    { -0.92387953f,  0.38268343f },
+    { -0.98078528f,  0.19509032f },
+    { -1.00000000f,  0.00000000f },
+    { -0.98078528f, -0.19509032f },
+    { -0.92387953f, -0.38268343f },
+    { -0.83146961f, -0.55557023f },
+    { -0.70710678f, -0.70710678f },
+    { -0.55557023f, -0.83146961f },
+    { -0.38268343f, -0.92387953f },
+    { -0.19509032f, -0.98078528f },
+    { -0.00000000f, -1.00000000f },
+    {  0.19509032f, -0.98078528f },
+    {  0.38268343f, -0.92387953f },
+    {  0.55557023f, -0.83146961f },
+    {  0.70710678f, -0.70710678f },
+    {  0.83146961f, -0.55557023f },
+    {  0.92387953f, -0.38268343f },
+    {  0.98078528f, -0.19509032f },
+};
+
+
+void
+Requantize_MidSideStereo ( Int Stop_Band, const Bool_t* used_MS )
+{
+    Int    Band;  // 0...Stop_Band
+    Uint   k;     // 0...35
+    Float  ML;
+    Float  MR;
+    Float  mid;
+    Float  side;
+
+    for ( Band = 0; Band <= Stop_Band; Band++ ) {
+
+        if ( used_MS[Band] )  // MidSide coded: left channel contains Mid signal, right channel Side signal
+            if      ( Res[Band].R < -1 ) {
+                k  = 0;
+                ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
+                do {
+                    mid = Q[Band].L[k] * ML;
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 12);
+                ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
+                do {
+                    mid = Q[Band].L[k] * ML;
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 24);
+                ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
+                do {
+                    mid = Q[Band].L[k] * ML;
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 36);
+            }
+            else if ( Res[Band].L < -1 ) {
+                k  = 0;
+                ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
+                do {
+                    mid = Q[Band].R[k] * ML;
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 12);
+                ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
+                do {
+                    mid = Q[Band].R[k] * ML;
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 24);
+                ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
+                do {
+                    mid = Q[Band].R[k] * ML;
+                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
+                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
+                } while (++k < 36);
+            }
+            else if ( Res[Band].L )
+                if ( Res[Band].R ) {     //  M!=0, S!=0
+                    k  = 0;
+                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
+                        Y_L[k][Band] = mid + side;
+                    } while (++k < 12);
+                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
+                        Y_L[k][Band] = mid + side;
+                    } while (++k < 24);
+                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
+                        Y_L[k][Band] = mid + side;
+                    } while (++k < 36);
+                } else {                 //  M!=0, S=0
+                    k  = 0;
+                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] =
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 12);
+                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] =
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 24);
+                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] =
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 36);
+                }
+            else
+                if ( Res[Band].R ) {     //  M==0, S!=0
+                    k  = 0;
+                    ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = - (
+                        Y_L[k][Band] = Q[Band].R[k] * ML );
+                    } while (++k < 12);
+                    ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = - (
+                        Y_L[k][Band] = Q[Band].R[k] * ML );
+                    } while (++k < 24);
+                    ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = - (
+                        Y_L[k][Band] = Q[Band].R[k] * ML );
+                    } while (++k < 36);
+                } else {                 //  M==0, S==0
+                    for (k=0; k<36; k++) {
+                        Y_R[k][Band] =
+                        Y_L[k][Band] = 0.f;
+                    }
+                }
+
+        else                  // Left/Right coded: left channel contains left, right the right signal
+
+            if ( Res[Band].L )
+                if ( Res[Band].R ) {     //  L!=0, R!=0
+                    k  = 0;
+                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 12);
+                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 24);
+                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
+                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 36);
+                } else {                 //  L!=0, R==0
+                    k  = 0;
+                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] = 0.f;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 12);
+                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] = 0.f;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 24);
+                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
+                    do {
+                        Y_R[k][Band] = 0.f;
+                        Y_L[k][Band] = Q[Band].L[k] * ML;
+                    } while (++k < 36);
+                }
+            else
+                if ( Res[Band].R ) {     //  L==0, R!=0
+                    k  = 0;
+                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = 0.f;
+                    } while (++k < 12);
+                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = 0.f;
+                    } while (++k < 24);
+                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
+                    do {
+                        Y_R[k][Band] = Q[Band].R[k] * MR;
+                        Y_L[k][Band] = 0.f;
+                    } while (++k < 36);
+                } else {                 //  L==0, R==0
+                    for (k=0; k<36; k++) {
+                        Y_R[k][Band] =
+                        Y_L[k][Band] = 0.f;
+                    }
+                }
+
+    }
+    return;
+}
+
+
+/*
+ *  This is the main requantisation routine for Intensity Stereo.
+ *  It does the same as Requantize_MidSideStereo() but for IS.
+ *
+ *  Input is:
+ *      - Stop_Band:
+ *          the last band using MS or LR stereo
+ *      - Res[Band].L:
+ *          Quantisation resolution for every band (0...Stop_Band) and
+ *          the left channel which is used for both channels. Value is 0...17.
+ *      - SCF_Index[3][Band].{L,R}:
+ *          Scale factor for every band (0...Stop_Band), subframe (0...2)
+ *          and channel (L, R).
+ *      - Q[Band].L[36]
+ *          36 subband samples for every band (0...Stop_Band), both channels use
+ *          the of the left channel
+ *      - SCF[64], Cc[18], Dc[18]:
+ *          Lookup tables for Scale factor and Quantisation resolution.
+ *
+ *   Output is:
+ *     - Y_L:  Left  channel subband signals
+ *     - Y_R:  Right channel subband signals
+ *
+ *   These signals are used for the synthesis filter in the synth*.[ch]
+ *   files to generate the PCM output signal.
+ */
+
+void
+Requantize_IntensityStereo ( Int Start_Band, Int Stop_Band )
+{
+    Int    Band;  // Start_Band...Stop_Band
+    Uint   k;     // 0...35
+    Float  ML;
+    Float  MR;
+
+    for ( Band = Start_Band; Band <= Stop_Band; Band++ ) {
+
+        if ( Res[Band].L ) {
+            k  = 0;
+            ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L] * SS05;
+            MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].L] * SS05;
+            do {
+                Y_R[k][Band] = Q[Band].L[k] * MR;
+                Y_L[k][Band] = Q[Band].L[k] * ML;
+            } while (++k < 12);
+            ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L] * SS05;
+            MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].L] * SS05;
+            do {
+                Y_R[k][Band] = Q[Band].L[k] * MR;
+                Y_L[k][Band] = Q[Band].L[k] * ML;
+            } while (++k < 24);
+            ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L] * SS05;
+            MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].L] * SS05;
+            do {
+                Y_R[k][Band] = Q[Band].L[k] * MR;
+                Y_L[k][Band] = Q[Band].L[k] * ML;
+            } while (++k < 36);
+        } else {
+            for (k=0; k<36; k++) {
+                Y_R[k][Band] =
+                Y_L[k][Band] = 0.f;
+            }
+        }
+
+    }
+    return;
+}
+
+
+/*
+ *  Helper function for the qsort() in Resort_HuffTable() to sort a Huffman table
+ *  by its codes.
+ */
+
+static int Cdecl
+cmp_fn ( const void* p1, const void* p2 )
+{
+    if ( ((const Huffman_t*)p1) -> Code < ((const Huffman_t*)p2) -> Code ) return +1;
+    if ( ((const Huffman_t*)p1) -> Code > ((const Huffman_t*)p2) -> Code ) return -1;
+    return 0;
+}
+
+
+/*
+ *  This functions sorts a Huffman table by its codes. It has also two other functions:
+ *
+ *    - The table contains LSB aligned codes, these are first MSB aligned.
+ *    - The value entry is filled by its position plus 'offset' (Note that
+ *      Make_HuffTable() don't fill this item. Offset can be used to offset
+ *      range for instance from 0...6 to -3...+3.
+ *
+ *  Note that this function generates trash if you call it twice!
+ */
+
+void
+Resort_HuffTable ( Huffman_t* const Table, const size_t elements, Int offset )
+{
+    size_t  i;
+
+    for ( i = 0; i < elements; i++ ) {
+        Table[i].Value  = i + offset;
+        Table[i].Code <<= (32 - Table[i].Length);
+    }
+
+    qsort ( Table, elements, sizeof(*Table), cmp_fn );
+    return;
+}
+
+#endif /* MPP_ENCODER */
+
+
+/*
+ *  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, size_t len )
+{
+    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, size_t LUT_len, const Huffman_t* const Table, const size_t elements )
+{
+    size_t    i;
+    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
+}
+
+/* end of tools.c */
Index: mppenc/branches/r2d/libmpcpsy/Makefile.am
===================================================================
--- mppenc/branches/r2d/libmpcpsy/Makefile.am	(revision 61)
+++ mppenc/branches/r2d/libmpcpsy/Makefile.am	(revision 64)
@@ -1,3 +1,3 @@
-INCLUDES = 
+INCLUDES = -I../../common
 METASOURCES = AUTO
 lib_LIBRARIES = libmpcpsy.a
Index: mppenc/branches/r2d/libmpcpsy/fft4g.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 61)
+++ mppenc/branches/r2d/libmpcpsy/fft4g.c	(revision 64)
@@ -19,4 +19,5 @@
 
 #include "libmpcpsy.h"
+#include "mpcmath.h"
 
 /* F U N C T I O N S */
Index: mppenc/branches/r2d/libmpcpsy/libmpcpsy.h
===================================================================
--- mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 61)
+++ mppenc/branches/r2d/libmpcpsy/libmpcpsy.h	(revision 64)
@@ -43,19 +43,4 @@
 #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.
@@ -68,16 +53,4 @@
 	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 {
Index: mppenc/branches/r2d/libmpcpsy/psy.c
===================================================================
--- mppenc/branches/r2d/libmpcpsy/psy.c	(revision 61)
+++ mppenc/branches/r2d/libmpcpsy/psy.c	(revision 64)
@@ -57,4 +57,5 @@
 #include "libmpcpsy.h"
 #include "fastmath.h"
+#include "datatypes.h"
 
 
Index: mppenc/branches/r2d/mppenc.kdevelop
===================================================================
--- mppenc/branches/r2d/mppenc.kdevelop	(revision 61)
+++ mppenc/branches/r2d/mppenc.kdevelop	(revision 64)
@@ -18,5 +18,5 @@
   <kdevautoproject>
     <general>
-      <activetarget>libmpcpsy/libmpcpsy.a</activetarget>
+      <activetarget>libmpcenc/libmpcenc.a</activetarget>
       <useconfiguration>debug</useconfiguration>
     </general>
Index: mppenc/branches/r2d/src/analy_filter.c
===================================================================
--- mppenc/branches/r2d/src/analy_filter.c	(revision 61)
+++ 	(revision )
@@ -1,341 +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
- */
-
-#include <string.h>
-#include "mppenc.h"
-
-#define FASTER
-
-/* C O N S T A N T S */
-
-#undef _
-#define _(value)  (float)(value##.##L / 0x200000)
-
-static float  Ci_opt [512] = {
-    _(   0), _(  213), _( 2037), _(  6574), _(75038), _( 6574), _(2037), _(213),
-    _(  -1), _(  218), _( 2000), _(  5959), _(74992), _( 7134), _(2063), _(208),
-    _(  -1), _(  222), _( 1952), _(  5288), _(74856), _( 7640), _(2080), _(202),
-    _(  -1), _(  225), _( 1893), _(  4561), _(74630), _( 8092), _(2087), _(196),
-    _(  -1), _(  227), _( 1822), _(  3776), _(74313), _( 8492), _(2085), _(190),
-    _(  -1), _(  228), _( 1739), _(  2935), _(73908), _( 8840), _(2075), _(183),
-    _(  -1), _(  228), _( 1644), _(  2037), _(73415), _( 9139), _(2057), _(176),
-    _(  -2), _(  227), _( 1535), _(  1082), _(72835), _( 9389), _(2032), _(169),
-    _(  -2), _(  224), _( 1414), _(    70), _(72169), _( 9592), _(2001), _(161),
-    _(  -2), _(  221), _( 1280), _(  -998), _(71420), _( 9750), _(1962), _(154),
-    _(  -2), _(  215), _( 1131), _( -2122), _(70590), _( 9863), _(1919), _(147),
-    _(  -3), _(  208), _(  970), _( -3300), _(69679), _( 9935), _(1870), _(139),
-    _(  -3), _(  200), _(  794), _( -4533), _(68692), _( 9966), _(1817), _(132),
-    _(  -4), _(  189), _(  605), _( -5818), _(67629), _( 9959), _(1759), _(125),
-    _(  -4), _(  177), _(  402), _( -7154), _(66494), _( 9916), _(1698), _(117),
-    _(  -5), _(  163), _(  185), _( -8540), _(65290), _( 9838), _(1634), _(111),
-    _(  -5), _(  146), _(  -45), _( -9975), _(64019), _( 9727), _(1567), _(104),
-    _(  -6), _(  127), _( -288), _(-11455), _(62684), _( 9585), _(1498), _( 97),
-    _(  -7), _(  106), _( -545), _(-12980), _(61289), _( 9416), _(1428), _( 91),
-    _(  -7), _(   83), _( -814), _(-14548), _(59838), _( 9219), _(1356), _( 85),
-    _(  -8), _(   57), _(-1095), _(-16155), _(58333), _( 8998), _(1283), _( 79),
-    _(  -9), _(   29), _(-1388), _(-17799), _(56778), _( 8755), _(1210), _( 73),
-    _( -10), _(   -2), _(-1692), _(-19478), _(55178), _( 8491), _(1137), _( 68),
-    _( -11), _(  -36), _(-2006), _(-21189), _(53534), _( 8209), _(1064), _( 63),
-    _( -13), _(  -72), _(-2330), _(-22929), _(51853), _( 7910), _( 991), _( 58),
-    _( -14), _( -111), _(-2663), _(-24694), _(50137), _( 7597), _( 919), _( 53),
-    _( -16), _( -153), _(-3004), _(-26482), _(48390), _( 7271), _( 848), _( 49),
-    _( -17), _( -197), _(-3351), _(-28289), _(46617), _( 6935), _( 779), _( 45),
-    _( -19), _( -244), _(-3705), _(-30112), _(44821), _( 6589), _( 711), _( 41),
-    _( -21), _( -294), _(-4063), _(-31947), _(43006), _( 6237), _( 645), _( 38),
-    _( -24), _( -347), _(-4425), _(-33791), _(41176), _( 5879), _( 581), _( 35),
-    _( -26), _( -401), _(-4788), _(-35640), _(39336), _( 5517), _( 519), _( 31),
-    _( -29), _( -459), _(-5153), _(-37489), _(37489), _( 5153), _( 459), _( 29),
-    _( -31), _( -519), _(-5517), _(-39336), _(35640), _( 4788), _( 401), _( 26),
-    _( -35), _( -581), _(-5879), _(-41176), _(33791), _( 4425), _( 347), _( 24),
-    _( -38), _( -645), _(-6237), _(-43006), _(31947), _( 4063), _( 294), _( 21),
-    _( -41), _( -711), _(-6589), _(-44821), _(30112), _( 3705), _( 244), _( 19),
-    _( -45), _( -779), _(-6935), _(-46617), _(28289), _( 3351), _( 197), _( 17),
-    _( -49), _( -848), _(-7271), _(-48390), _(26482), _( 3004), _( 153), _( 16),
-    _( -53), _( -919), _(-7597), _(-50137), _(24694), _( 2663), _( 111), _( 14),
-    _( -58), _( -991), _(-7910), _(-51853), _(22929), _( 2330), _(  72), _( 13),
-    _( -63), _(-1064), _(-8209), _(-53534), _(21189), _( 2006), _(  36), _( 11),
-    _( -68), _(-1137), _(-8491), _(-55178), _(19478), _( 1692), _(   2), _( 10),
-    _( -73), _(-1210), _(-8755), _(-56778), _(17799), _( 1388), _( -29), _(  9),
-    _( -79), _(-1283), _(-8998), _(-58333), _(16155), _( 1095), _( -57), _(  8),
-    _( -85), _(-1356), _(-9219), _(-59838), _(14548), _(  814), _( -83), _(  7),
-    _( -91), _(-1428), _(-9416), _(-61289), _(12980), _(  545), _(-106), _(  7),
-    _( -97), _(-1498), _(-9585), _(-62684), _(11455), _(  288), _(-127), _(  6),
-    _(-104), _(-1567), _(-9727), _(-64019), _( 9975), _(   45), _(-146), _(  5),
-    _(-111), _(-1634), _(-9838), _(-65290), _( 8540), _( -185), _(-163), _(  5),
-    _(-117), _(-1698), _(-9916), _(-66494), _( 7154), _( -402), _(-177), _(  4),
-    _(-125), _(-1759), _(-9959), _(-67629), _( 5818), _( -605), _(-189), _(  4),
-    _(-132), _(-1817), _(-9966), _(-68692), _( 4533), _( -794), _(-200), _(  3),
-    _(-139), _(-1870), _(-9935), _(-69679), _( 3300), _( -970), _(-208), _(  3),
-    _(-147), _(-1919), _(-9863), _(-70590), _( 2122), _(-1131), _(-215), _(  2),
-    _(-154), _(-1962), _(-9750), _(-71420), _(  998), _(-1280), _(-221), _(  2),
-    _(-161), _(-2001), _(-9592), _(-72169), _(  -70), _(-1414), _(-224), _(  2),
-    _(-169), _(-2032), _(-9389), _(-72835), _(-1082), _(-1535), _(-227), _(  2),
-    _(-176), _(-2057), _(-9139), _(-73415), _(-2037), _(-1644), _(-228), _(  1),
-    _(-183), _(-2075), _(-8840), _(-73908), _(-2935), _(-1739), _(-228), _(  1),
-    _(-190), _(-2085), _(-8492), _(-74313), _(-3776), _(-1822), _(-227), _(  1),
-    _(-196), _(-2087), _(-8092), _(-74630), _(-4561), _(-1893), _(-225), _(  1),
-    _(-202), _(-2080), _(-7640), _(-74856), _(-5288), _(-1952), _(-222), _(  1),
-    _(-208), _(-2063), _(-7134), _(-74992), _(-5959), _(-2000), _(-218), _(  1),
-};
-#undef _
-
-
-static float M [1024];
-
-void
-Klemm ( void )
-{
-    int    i;
-    int    k;
-    float  S [512];
-
-    for ( i=0; i<32; i++ ) {
-        for ( k=0; k<32; k++ ) {
-            M [i*32 + k] = (float) cos ( ((2*i+1)*k & 127) * M_PI/64 );
-        }
-    }
-
-#ifdef FASTER
-    for ( i = 0; i < 384; i++ )
-        S[i] = Ci_opt[i];
-    for ( i = 384; i < 392; i++ )
-        S[i] = 0;
-    for ( i = 392; i < 512; i++ )
-        S[i] = -Ci_opt[i];
-    for ( i = 0; i < 512; i++ )
-       Ci_opt[i] = S[i];
-    for ( i = 0; i < 128; i++ )
-       Ci_opt[i] = S[(i&7) + 120 - (i&120)];
-    for ( i = 128; i < 384; i++ )
-       Ci_opt[i] = S[i];
-    for ( i = 384; i < 512; i++ )
-       Ci_opt[i] = S[ 384 + (i&7) + 120 - (i&120)];
-#endif
-}
-
- /* D E F I N E S */
-#define X_MEM    1152
-
-/* V A R I A B L E S */
-float  X_L [ X_MEM + 480 ];
-float  X_R [ X_MEM + 480 ];
-
-
-/* F U N C T I O N S */
-// vectoring & partial calculation
-
-static void
-Vectoring ( const float* x, float* y )
-{
-#ifdef FASTER
-    int           i = 0;
-    const float*  c1;
-    const float*  c2;
-    const float*  x1;
-    const float*  x2;
-
-# define EXPR(c,x)  (c[0]*x[0] + c[1]*x[64] + c[2]*x[128] + c[3]*x[192] + c[4]*x[256] + c[5]*x[320] + c[6]*x[384] + c[7]*x[448])
-
-    i++;
-    *y++ = EXPR ((Ci_opt+128),(x+31));
-
-    c1 = Ci_opt - 8;
-    c2 = Ci_opt + 128;
-    x1 = x + 16;
-    x2 = x + 31;
-    do {
-        x1--, x2--, i++;
-        c1 += 8, c2 += 8;
-        *y++ = EXPR (c1,x1) + EXPR (c2,x2);
-    } while ( i < 16 );
-
-    i++;
-    *y++ = EXPR ((Ci_opt+120),(x+0)) + EXPR ((Ci_opt+256),(x+32));
-
-    c1 = Ci_opt + 384 - 8;
-    c2 = Ci_opt + 256;
-    x1 = x + 47;
-    x2 = x + 32;
-
-    do {
-        x1++, x2++, i++;
-        c1 += 8, c2 += 8;
-        *y++ = EXPR (c1,x1) + EXPR (c2,x2);
-    } while ( i < 32 );
-#else
-    int           i;
-    const float*  c = Ci_opt;
-
-    for ( i = 0; i < 16; i++, c += 32, x += 4, y += 4 ) {
-        y[0] = c[ 0] * x[  0] + c[ 1] * x[ 64] + c[ 2] * x[128] + c[ 3] * x[192] + c[ 4] * x[256] + c[ 5] * x[320] + c[ 6] * x[384] + c[ 7] * x[448];
-        y[1] = c[ 8] * x[  1] + c[ 9] * x[ 65] + c[10] * x[129] + c[11] * x[193] + c[12] * x[257] + c[13] * x[321] + c[14] * x[385] + c[15] * x[449];
-        y[2] = c[16] * x[  2] + c[17] * x[ 66] + c[18] * x[130] + c[19] * x[194] + c[20] * x[258] + c[21] * x[322] + c[22] * x[386] + c[23] * x[450];
-        y[3] = c[24] * x[  3] + c[25] * x[ 67] + c[26] * x[131] + c[27] * x[195] + c[28] * x[259] + c[29] * x[323] + c[30] * x[387] + c[31] * x[451];
-    }
-#endif
-}
-
-// matrixing with Mi[32][32] = Mi[1024]
-
-static void
-Matrixing ( const int MaxBand, const float* mi, const float* y, float* samples )
-{
-    int  i;
-#ifdef FASTER
-    for ( i = 0; i <= MaxBand; i++, mi += 32, samples += 72 ) {                          // 144 = sizeof(SubbandFloatTyp)/sizeof(float)
-        samples[0] =          y[ 0] + mi[ 1] * y[ 1] + mi[ 2] * y[ 2] + mi[ 3] * y[ 3]
-                   + mi[ 4] * y[ 4] + mi[ 5] * y[ 5] + mi[ 6] * y[ 6] + mi[ 7] * y[ 7]
-                   + mi[ 8] * y[ 8] + mi[ 9] * y[ 9] + mi[10] * y[10] + mi[11] * y[11]
-                   + mi[12] * y[12] + mi[13] * y[13] + mi[14] * y[14] + mi[15] * y[15]
-                   + mi[16] * y[16] + mi[17] * y[17] + mi[18] * y[18] + mi[19] * y[19]
-                   + mi[20] * y[20] + mi[21] * y[21] + mi[22] * y[22] + mi[23] * y[23]
-                   + mi[24] * y[24] + mi[25] * y[25] + mi[26] * y[26] + mi[27] * y[27]
-                   + mi[28] * y[28] + mi[29] * y[29] + mi[30] * y[30] + mi[31] * y[31];
-    }
-#else
-    for ( i = 0; i <= MaxBand; i++, mi += 32, samples += 72 ) {                          // 144 = sizeof(SubbandFloatTyp)/sizeof(float)
-        samples[0] =           y[16]        + mi[ 1] * (y[15]+y[17])
-                   + mi[ 2] * (y[14]+y[18]) + mi[ 3] * (y[13]+y[19])
-                   + mi[ 4] * (y[12]+y[20]) + mi[ 5] * (y[11]+y[21])
-                   + mi[ 6] * (y[10]+y[22]) + mi[ 7] * (y[ 9]+y[23])
-                   + mi[ 8] * (y[ 8]+y[24]) + mi[ 9] * (y[ 7]+y[25])
-                   + mi[10] * (y[ 6]+y[26]) + mi[11] * (y[ 5]+y[27])
-                   + mi[12] * (y[ 4]+y[28]) + mi[13] * (y[ 3]+y[29])
-                   + mi[14] * (y[ 2]+y[30]) + mi[15] * (y[ 1]+y[31])
-                   + mi[16] * (y[ 0]+y[32])
-                   + mi[31] * (y[47]-y[49]) + mi[30] * (y[46]-y[50])
-                   + mi[29] * (y[45]-y[51]) + mi[28] * (y[44]-y[52])
-                   + mi[27] * (y[43]-y[53]) + mi[26] * (y[42]-y[54])
-                   + mi[25] * (y[41]-y[55]) + mi[24] * (y[40]-y[56])
-                   + mi[23] * (y[39]-y[57]) + mi[22] * (y[38]-y[58])
-                   + mi[21] * (y[37]-y[59]) + mi[20] * (y[36]-y[60])
-                   + mi[19] * (y[35]-y[61]) + mi[18] * (y[34]-y[62])
-                   + mi[17] * (y[33]-y[63]);
-    }
-#endif
-}
-
-// Analysis-Filterbank
-void
-Analyse_Filter ( const PCMDataTyp* in, SubbandFloatTyp* out, const int MaxBand )
-{
-#ifdef FASTER
-    float         Y_L [32];
-    float         Y_R [32];
-#else
-    float         Y_L [64];
-    float         Y_R [64];
-#endif
-    float*        x;
-    const float*  pcm;
-    int           n;
-    int           i;
-
-    /************************* calculate L-signal ***************************/
-    memcpy ( X_L + X_MEM, X_L, 480*sizeof(*X_L) );
-    x      = X_L + X_MEM;
-    pcm    = in->L + 479;                               // 479 = CENTER + 31
-    for ( n = 0; n < 36; n++, pcm += 64 ) {
-        x  -= 32;                                       // updating vector x
-#ifdef FASTER
-        for ( i = 0; i < 16; i++ )
-            x[i] = *pcm--;
-        for ( i = 31; i >= 16; i-- )
-            x[i] = *pcm--;
-#else
-        for ( i = 0; i < 32; i++ )
-            x[i] = *pcm--;
-#endif
-        Vectoring ( x, Y_L );                           // vectoring & partial calculation
-        Matrixing ( MaxBand, M, Y_L, &out[0].L[n] );    // matrixing
-    }
-
-    /************************* calculate R-signal ***************************/
-    memcpy ( X_R + X_MEM, X_R, 480*sizeof(*X_R) );
-    x      = X_R + X_MEM;
-    pcm    = in->R + 479;                               // 479 = CENTER + 31
-    for ( n = 0; n < 36; n++, pcm += 64 ) {
-        x  -= 32;                                       // updating vector x
-#ifdef FASTER
-        for ( i = 0; i < 16; i++ )
-            x[i] = *pcm--;
-        for ( i = 31; i >= 16; i-- )
-            x[i] = *pcm--;
-#else
-        for ( i = 0; i < 32; i++ )
-            x[i] = *pcm--;
-#endif
-        Vectoring ( x, Y_R );                           // vectoring & partial calculation
-        Matrixing ( MaxBand, M, Y_R, &out[0].R[n] );    // matrixing
-    }
-}
-
-void
-Analyse_Init ( float Left, float Right, SubbandFloatTyp* out, const int MaxBand )
-{
-#ifdef FASTER
-    float         Y_L [32];
-    float         Y_R [32];
-#else
-    float         Y_L [64];
-    float         Y_R [64];
-#endif
-    float*        x;
-    int           n;
-    int           i;
-
-    /************************* calculate L-signal ***************************/
-    memcpy ( X_L + X_MEM, X_L, 480*sizeof(*X_L) );
-    x      = X_L + X_MEM;
-
-    for ( n = 0; n < 36; n++ ) {
-        x  -= 32;                                       // updating vector x
-#ifdef FASTER
-        for ( i = 0; i < 16; i++ )
-            x[i] = Left;
-        for ( i = 31; i >= 16; i-- )
-            x[i] = Left;
-#else
-        for ( i = 0; i < 32; i++ )
-            x[i] = Left;
-#endif
-        Vectoring ( x, Y_L );                           // vectoring & partial calculation
-        Matrixing ( MaxBand, M, Y_L, &out[0].L[n] );    // matrixing
-    }
-
-    /************************* calculate R-signal ***************************/
-    memcpy ( X_R + X_MEM, X_R, 480*sizeof(*X_R) );
-    x      = X_R + X_MEM;
-    for ( n = 0; n < 36; n++ ) {
-        x  -= 32;                                       // updating vector x
-#ifdef FASTER
-        for ( i = 0; i < 16; i++ )
-            x[i] = Right;
-        for ( i = 31; i >= 16; i-- )
-            x[i] = Right;
-#else
-        for ( i = 0; i < 32; i++ )
-            x[i] = Right;
-#endif
-        Vectoring ( x, Y_R );                           // vectoring & partial calculation
-        Matrixing ( MaxBand, M, Y_R, &out[0].R[n] );    // matrixing
-    }
-}
-
-/* end of analy_filter.c */
Index: mppenc/branches/r2d/src/bitstream.c
===================================================================
--- mppenc/branches/r2d/src/bitstream.c	(revision 61)
+++ 	(revision )
@@ -1,188 +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
- */
-
-#include "mppenc.h"
-
-
-Uint32_t      Buffer [BUFFER_FULL];    // Buffer for bitstream-file
-Uint32_t      dword         =  0;      // 32-bit-Word for Bitstream-I/O
-int           filled        = 32;      // Position in the the 32-bit-word that's currently about to be filled
-unsigned int  Zaehler       =  0;      // Position pointer for the processed bitstream-word (32 bit)
-UintMax_t     BufferedBits  =  0;      // Counter for the number of written bits in the bitstream
-
-
-/*
- *  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, especially on modern CPUs, than
- *  byte picking, 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 ( unsigned int* dst, size_t words32bit )
-{
-    for ( ; words32bit--; dst++ ) {
-# if  INT_MAX >= 2147483647L
-        unsigned int  tmp = *dst;
-        tmp  = ((tmp << 0x10) & 0xFFFF0000) | ((tmp >> 0x10) & 0x0000FFFF);
-        tmp  = ((tmp << 0x08) & 0xFF00FF00) | ((tmp >> 0x08) & 0x00FF00FF);
-        *dst = tmp;
-# else
-        char  tmp;
-        tmp             = ((char*)dst)[0];
-        ((char*)dst)[0] = ((char*)dst)[3];
-        ((char*)dst)[3] = tmp;
-        tmp             = ((char*)dst)[1];
-        ((char*)dst)[1] = ((char*)dst)[2];
-        ((char*)dst)[2] = tmp;
-# endif
-    }
-    return;
-}
-
-#endif /* ENDIAN == HAVE_BIG_ENDIAN */
-
-
-void
-FlushBitstream ( FILE* fp, const Uint32_t* buffer, size_t words32bit )
-{
-    size_t           WrittenDwords = 0;
-    const Uint32_t*  p             = buffer;
-    size_t           CC            = words32bit;
-
-#if ENDIAN == HAVE_BIG_ENDIAN
-    Change_Endian32 ( (Uint32_t*)buffer, CC );
-#endif
-
-    // Write Buffer
-    do {
-        WrittenDwords = fwrite ( p, sizeof(*buffer), words32bit, fp );
-        if ( WrittenDwords == 0 ) {
-            stderr_printf ( "\b\n WARNING: Disk full?, retry after 10 sec ...\a" );
-            sleep (10);
-        }
-        if ( WrittenDwords > 0 ) {
-            p          += WrittenDwords;
-            words32bit -= WrittenDwords;
-        }
-    } while ( words32bit != 0 );
-
-#if ENDIAN == HAVE_BIG_ENDIAN
-    Change_Endian32 ( (Uint32_t*)buffer, CC );
-#endif
-}
-
-
-void
-UpdateHeader ( FILE* fp, Uint32_t Frames, Uint ValidSamples )
-{
-    Uint8_t  buff [4];
-
-    // Write framecount to header
-    if ( fseek ( fp, 4L, SEEK_SET ) < 0 )
-        return;
-
-    buff [0] = (Uint8_t)(Frames >>  0);
-    buff [1] = (Uint8_t)(Frames >>  8);
-    buff [2] = (Uint8_t)(Frames >> 16);
-    buff [3] = (Uint8_t)(Frames >> 24);
-
-    fwrite ( buff, 1, 4, fp );
-
-    // Write ValidSamples to header
-    if ( fseek ( fp, 22L, SEEK_SET ) < 0 )
-        return;
-    fread ( buff, 1, 2, fp );
-    if ( ferror(fp) )
-        return;
-    if ( fseek ( fp, 22L, SEEK_SET ) < 0 )
-        return;
-
-    ValidSamples <<= 4;
-    ValidSamples  |= 0x800F & (((Uint) buff[1] << 8) | buff[0]);
-    buff [0] = (Uint8_t)(ValidSamples >>  0);
-    buff [1] = (Uint8_t)(ValidSamples >>  8);
-
-    fwrite ( buff, 1, 2, fp );
-
-
-    // Set filepointer to end of file (dirty method, should be old position!!)
-    fseek ( fp, 0L, SEEK_END );
-}
-
-
-void
-WriteBits ( const Uint32_t input, const unsigned int bits )
-{
-    BufferedBits += bits;
-    filled       -= bits;
-
-    if      ( filled > 0 ) {
-        dword  |= input << filled;
-    }
-    else if ( filled < 0 ) {
-        Buffer [Zaehler++] = dword | ( input >> -filled );
-        filled += 32;
-        dword   = input << filled;
-    }
-    else {
-        Buffer [Zaehler++] = dword | input;
-        filled  = 32;
-        dword   =  0;
-    }
-}
-
-// 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 ( const Uint32_t input, const unsigned int bits, BitstreamPos const pos )
-{
-    Uint32_t*     ptr    = pos.ptr;
-    int           filled = pos.bit - bits;
-
-//    fprintf ( stderr, "%5u %2u %08lX %2u\n", input, bits, pos.ptr, pos.bit );
-
-    Buffer [Zaehler] = dword;
-
-    if      ( filled > 0 ) {
-        ptr [0] |= input << (  +filled);
-    }
-    else if ( filled < 0 ) {
-        ptr [0] |= input >> (  -filled);
-        ptr [1] |= input << (32+filled);
-    }
-    else {
-        ptr [0] |= input;
-    }
-
-    dword = Buffer [Zaehler];
-}
-
-
-void
-GetBitstreamPos ( BitstreamPos* const pos )
-{
-    pos -> ptr = Buffer + Zaehler;
-    pos -> bit = filled;
-}
-
-/* end of bitstream.c */
Index: mppenc/branches/r2d/src/encode_sv7.c
===================================================================
--- mppenc/branches/r2d/src/encode_sv7.c	(revision 61)
+++ 	(revision )
@@ -1,451 +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
- */
-
-#include "mppenc.h"
-
-/*
- *  SV1:   DATE 13.12.1998
- *  SV2:   DATE 12.06.1999
- *  SV3:   DATE 19.10.1999
- *  SV4:   DATE 20.10.1999
- *  SV5:   DATE 18.06.2000
- *  SV6:   DATE 10.08.2000
- *  SV7:   DATE 23.08.2000
- *  SV7.f: DATE 20.07.2002
- */
-
-unsigned char         MS_Flag     [32];         // Flag to save if Subband was MS- or LR-coded
-int                   SCF_Last_L  [32];
-int                   SCF_Last_R  [32];         // Last coded SCF value
-static unsigned char  DSCF_RLL_L  [32];
-static unsigned char  DSCF_RLL_R  [32];         // Duration of the differential SCF-coding for RLL (run length limitation)
-int                   Res_L       [32];
-int                   Res_R       [32];         // Quantization precision of the subbands
-int                   SCF_Index_L [32] [3];
-int                   SCF_Index_R [32] [3];     // Scalefactor index for quantized subband values
-
-
-// initialize SV7
-void
-Init_SV7 ( void )
-{
-    Init_Huffman_Encoder_SV7 ();
-}
-
-
-// writes SV7-header
-void
-WriteHeader_SV7 ( const unsigned int  MaxBand,
-                  const unsigned int  Profile,
-                  const unsigned int  MS_on,
-                  const Uint32_t      TotalFrames,
-                  const unsigned int  SamplesRest,
-                  const unsigned int  StreamVersion,
-                  const unsigned int  SampleFreq )
-{
-    WriteBits ( StreamVersion,  8 );    // StreamVersion
-    WriteBits ( 0x2B504D     , 24 );    // Magic Number "MP+"
-
-    WriteBits ( TotalFrames  , 32 );    // # of frames
-
-    WriteBits ( 0            ,  1 );    // former IS-Flag (not supported anymore)
-    WriteBits ( MS_on        ,  1 );    // MS-Coding Flag
-    WriteBits ( MaxBand      ,  6 );    // Bandwidth
-
-#if 0
-    if ( MPPENC_VERSION [3] & 1 )
-        WriteBits ( 1        ,  4 );    // 1: Experimental profile
-    else
-#endif
-
-        WriteBits ( Profile  ,  4 );    // 5...15: below Telephone...above BrainDead
-    WriteBits ( 0            ,  2 );    // for future use
-    switch ( SampleFreq ) {
-        case 44100: WriteBits ( 0, 2 ); break;
-        case 48000: WriteBits ( 1, 2 ); break;
-        case 37800: WriteBits ( 2, 2 ); break;
-        case 32000: WriteBits ( 3, 2 ); break;
-        default   : stderr_printf ( "Internal error\n");
-                    exit (1);
-    }
-    WriteBits ( 0            , 16 );    // maximum input sample value, currently filled by replaygain
-
-    WriteBits ( 0            , 32 );    // title based gain controls, currently filled by replaygain
-
-    WriteBits ( 0            , 32 );    // album based gain controls, currently filled by replaygain
-
-    WriteBits ( 1            ,  1 );    // true gapless: used?
-    WriteBits ( SamplesRest  , 11 );    // true gapless: valid samples in last frame
-    WriteBits ( 1            , 1 );     // we now support fast seeking
-    WriteBits ( 0            , 19 );
-
-    WriteBits ( (MPPENC_VERSION[0]&15)*100 + (MPPENC_VERSION[2]&15)*10 + (MPPENC_VERSION[3]&15),
-                                8 );    // for future use
-}
-
-
-void
-FinishBitstream ( void )
-{
-    Buffer [Zaehler++] = dword;         // Assigning the "last" word
-}
-
-
-#define ENCODE_SCF1( new, old, rll )                         \
-        d = new - old + 7;                                   \
-        if ( d <= 14u  && rll < 32) {                        \
-            WriteBits ( Table[d].Code, Table[d].Length );    \
-        }                                                    \
-        else {                                               \
-            if ( new < 0 ) new = 0, Overflows++;             \
-            WriteBits ( Table[15].Code, Table[15].Length );  \
-            WriteBits ( (unsigned int)new, 6 );              \
-            rll = 0;                                         \
-        }
-
-#define ENCODE_SCFn( new, old, rll )                         \
-        d = new - old + 7;                                   \
-        if ( d <= 14u ) {                                    \
-            WriteBits ( Table[d].Code, Table[d].Length );    \
-        }                                                    \
-        else {                                               \
-            if ( new < 0 ) new = 0, Overflows++;             \
-            WriteBits ( Table[15].Code, Table[15].Length );  \
-            WriteBits ( (unsigned int)new, 6 );              \
-            rll = 0;                                         \
-        }
-
-
-static void
-test ( const unsigned int* const Res, const int* q )
-{
-#if 0
-    int  i;
-
-    switch ( *Res ) {
-    case 1:
-        for ( i = 0; i < 36; i ++ )
-            if ( q[i] != 1 )
-                return;
-        fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );
-        *Res = 0;
-        break;
-    case 2:
-        for ( i = 0; i < 36; i ++ )
-            if ( q[i] != 2 )
-                return;
-        fprintf ( stderr, "Alles Nullsamples, aber Auflï¿œung = %u\n", *Res );
-        *Res = 0;
-        break;
-    }
-#endif
-}
-
-
-// formatting and writing SV7-bitstream for one frame
-void
-WriteBitstream_SV7 ( const int               MaxBand,
-                     const SubbandQuantTyp*  Q )
-{
-    int                  n;
-    int                  k;
-    unsigned int         d;
-    unsigned int         idx;
-    unsigned int         book;
-    const Huffman_t*     Table;
-    const Huffman_t*     Table0;
-    const Huffman_t*     Table1;
-    int                  sum;
-    const unsigned int*  q;
-    unsigned char        SCFI_L [32];
-    unsigned char        SCFI_R [32];
-
-    /************************************ Resolution *********************************/
-    WriteBits ( (unsigned int)Res_L[0], 4 );                            // subband 0
-    WriteBits ( (unsigned int)Res_R[0], 4 );
-    if ( MS_Channelmode > 0  &&  !(Res_L[0]==0  &&  Res_R[0]==0) )
-         WriteBits ( MS_Flag[0] , 1 );
-
-    Table = HuffHdr;                                                    // subband 1...MaxBand
-    for ( n = 1; n <= MaxBand; n++ ) {
-        test ( Res_L+n, Q[n].L );
-
-        d = Res_L[n] - Res_L[n-1] + 5;
-        if ( d <= 8u ) {
-            WriteBits ( Table[d].Code, Table[d].Length );
-        }
-        else {
-            WriteBits ( Table[9].Code, Table[9].Length );
-            WriteBits ( Res_L[n]     , 4               );
-        }
-
-        test ( Res_R+n, Q[n].R );
-        d = Res_R[n] - Res_R[n-1] + 5;
-        if ( d <= 8u ) {
-            WriteBits ( Table[d].Code, Table[d].Length );
-        }
-        else {
-            WriteBits ( Table[9].Code, Table[9].Length );
-            WriteBits ( Res_R[n]     , 4               );
-        }
-        if ( MS_Channelmode > 0  &&  !(Res_L[n]==0 && Res_R[n]==0) )
-            WriteBits ( MS_Flag[n], 1 );
-    }
-
-    /************************************ SCF encoding type ***********************************/
-    Table = HuffSCFI;
-    for ( n = 0; n <= MaxBand; n++ ) {
-        if ( Res_L[n] ) {
-            SCFI_L[n] = 2 * (SCF_Index_L[n][0] == SCF_Index_L[n][1]) + (SCF_Index_L[n][1] == SCF_Index_L[n][2]);
-            WriteBits ( Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length );
-        }
-        if ( Res_R[n] ) {
-            SCFI_R[n] = 2 * (SCF_Index_R[n][0] == SCF_Index_R[n][1]) + (SCF_Index_R[n][1] == SCF_Index_R[n][2]);
-            WriteBits ( Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length );
-        }
-    }
-
-    /************************************* SCF **********************************/
-    Table = HuffDSCF;
-    for ( n = 0; n <= MaxBand; n++ ) {
-
-        if ( Res_L[n] ) {
-            switch ( SCFI_L[n] ) {
-            default:
-                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n]   , DSCF_RLL_L[n] );
-                ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] );
-                ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][1], DSCF_RLL_L[n] );
-                SCF_Last_L[n] = SCF_Index_L[n][2];
-                break;
-            case 1:
-                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n]   , DSCF_RLL_L[n] );
-                ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] );
-                SCF_Last_L[n] = SCF_Index_L[n][1];
-                break;
-            case 2:
-                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n]    , DSCF_RLL_L[n] );
-                ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][0], DSCF_RLL_L[n] );
-                SCF_Last_L[n] = SCF_Index_L[n][2];
-                break;
-            case 3:
-                ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n]    , DSCF_RLL_L[n] );
-                SCF_Last_L[n] = SCF_Index_L[n][0];
-                break;
-            }
-        }
-        if (DSCF_RLL_L[n] <= 32)
-            DSCF_RLL_L[n]++;        // Increased counters for SCF that haven't been initialized again
-
-        if ( Res_R[n] ) {
-            switch ( SCFI_R[n] ) {
-            default:
-                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
-                ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] );
-                ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][1], DSCF_RLL_R[n] );
-                SCF_Last_R[n] = SCF_Index_R[n][2];
-                break;
-            case 1:
-                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
-                ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] );
-                SCF_Last_R[n] = SCF_Index_R[n][1];
-                break;
-            case 2:
-                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
-                ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][0], DSCF_RLL_R[n] );
-                SCF_Last_R[n] = SCF_Index_R[n][2];
-                break;
-            case 3:
-                ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n]    , DSCF_RLL_R[n] );
-                SCF_Last_R[n] = SCF_Index_R[n][0];
-                break;
-            }
-        }
-        if (DSCF_RLL_R[n] <= 32)
-            DSCF_RLL_R[n]++;          // Increased counters for SCF that haven't been freshly initialized
-    }
-
-    /*********************************** Samples *********************************/
-    for ( n = 0; n <= MaxBand; n++ ) {
-
-        sum = 0;
-        q   = Q[n].L;
-
-        switch ( Res_L[n] ) {
-        case -1:
-        case  0:
-            break;
-        case  1:
-            Table0 = HuffQ [0][1];
-            Table1 = HuffQ [1][1];
-            for ( k = 0; k < 36; k += 3 ) {
-                idx  = q[k+0] + 3*q[k+1] + 9*q[k+2];
-                sum += Table0 [idx].Length;
-                sum -= Table1 [idx].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][1];
-            for ( k = 0; k < 36; k += 3 ) {
-                idx = q[k+0] + 3*q[k+1] + 9*q[k+2];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        case  2:
-            Table0 = HuffQ [0][2];
-            Table1 = HuffQ [1][2];
-            for ( k = 0; k < 36; k += 2 ) {
-                idx  = q[k+0] + 5*q[k+1];
-                sum += Table0 [idx].Length;
-                sum -= Table1 [idx].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][2];
-            for ( k = 0; k < 36; k += 2 ) {
-                idx = q[k+0] + 5*q[k+1];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        case  3:
-        case  4:
-        case  5:
-        case  6:
-        case  7:
-            Table0 = HuffQ [0][Res_L[n]];
-            Table1 = HuffQ [1][Res_L[n]];
-            for ( k = 0; k < 36; k++ ) {
-                sum += Table0 [q[k]].Length;
-                sum -= Table1 [q[k]].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][Res_L[n]];
-            for ( k = 0; k < 36; k++ ) {
-                idx = q[k];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        default:
-            for ( k = 0; k < 36; k++ )
-                WriteBits ( q[k], Res_L[n]-1 );
-            break;
-        }
-
-        sum = 0;
-        q   = Q[n].R;
-
-        switch ( Res_R[n] ) {
-        case -1:
-        case  0:
-            break;
-        case  1:
-            Table0 = HuffQ [0][1];
-            Table1 = HuffQ [1][1];
-            for ( k = 0; k < 36; k += 3 ) {
-                idx  = q[k+0] + 3*q[k+1] + 9*q[k+2];
-                sum += Table0 [idx].Length;
-                sum -= Table1 [idx].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][1];
-            for ( k = 0; k < 36; k += 3 ) {
-                idx = q[k+0] + 3*q[k+1] + 9*q[k+2];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        case  2:
-            Table0 = HuffQ [0][2];
-            Table1 = HuffQ [1][2];
-            for ( k = 0; k < 36; k += 2 ) {
-                idx  = q[k+0] + 5*q[k+1];
-                sum += Table0 [idx].Length;
-                sum -= Table1 [idx].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][2];
-            for ( k = 0; k < 36; k += 2 ) {
-                idx = q[k+0] + 5*q[k+1];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        case  3:
-        case  4:
-        case  5:
-        case  6:
-        case  7:
-            Table0 = HuffQ [0][Res_R[n]];
-            Table1 = HuffQ [1][Res_R[n]];
-            for ( k = 0; k < 36; k++ ) {
-                sum += Table0 [q[k]].Length;
-                sum -= Table1 [q[k]].Length;
-            }
-            book = sum >= 0;
-            WriteBits ( book, 1 );
-            Table = HuffQ [book][Res_R[n]];
-            for ( k = 0; k < 36; k++ ) {
-                idx = q[k];
-                WriteBits ( Table[idx].Code, Table[idx].Length );
-            }
-            break;
-        default:
-            for ( k = 0; k < 36; k++ )
-                WriteBits ( q[k], Res_R[n] - 1 );
-            break;
-        }
-
-    }
-    return;
-}
-
-#undef ENCODE_SCF1
-#undef ENCODE_SCFn
-
-
-#if 0
-void
-Dump ( const unsigned int* q, const int Res )
-{
-    switch ( Res ) {
-    case  1:
-        for ( k = 0; k < 36; k++, q++ )
-            printf ("%2d%c", *q-1, k==35?'\n':' ');
-        break;
-    case  2:
-        for ( k = 0; k < 36; k++, q++ )
-            printf ("%2d%c", *q-2, k==35?'\n':' ');
-        break;
-    case  3: case  4: case  5: case  6: case  7:
-        if ( Res == 5 )
-            for ( k = 0; k < 36; k++, q++ )
-                printf ("%2d%c", *q-7, k==35?'\n':' ');
-        break;
-    case  8: case  9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17:
-        printf ("%2u: ", Res-1 );
-        for ( k = 0; k < 36; k++, q++ ) {
-            printf ("%6d", *q - (1 << (Res-2)) );
-        }
-        printf ("\n");
-        break;
-    }
-}
-#endif
-
-/* end of encode_sv7.c */
Index: mppenc/branches/r2d/src/huffsv7.c
===================================================================
--- mppenc/branches/r2d/src/huffsv7.c	(revision 61)
+++ 	(revision )
@@ -1,444 +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
- */
-
-#include "mppdec.h"
-
-Huffman_t   HuffHdr    [10];            // 9 bit
-Huffman_t   HuffSCFI   [ 4];            // 3 bit
-Huffman_t   HuffDSCF   [16];            // 6 bit
-Huffman_t   HuffQ1 [2] [ 3*3*3];        // 6+ 9 bit
-Huffman_t   HuffQ2 [2] [ 5*5];          // 7+10 bit
-Huffman_t   HuffQ3 [2] [ 7];            // 4+ 5 bit
-Huffman_t   HuffQ4 [2] [ 9];            // 4+ 5 bit
-Huffman_t   HuffQ5 [2] [15];            // 6+ 8 bit
-Huffman_t   HuffQ6 [2] [31];            // 7+13 bit
-Huffman_t   HuffQ7 [2] [63];            // 8+14 bit
-                                        // 4608 Bytes
-Uint8_t     LUT1_0  [1<< 6];
-Uint8_t     LUT1_1  [1<< 9];            //  576 Bytes
-Uint8_t     LUT2_0  [1<< 7];
-Uint8_t     LUT2_1  [1<<10];            // 1152 Bytes
-Uint8_t     LUT3_0  [1<< 4];
-Uint8_t     LUT3_1  [1<< 5];            //   48 Bytes
-Uint8_t     LUT4_0  [1<< 4];
-Uint8_t     LUT4_1  [1<< 5];            //   48 Bytes
-Uint8_t     LUT5_0  [1<< 6];
-Uint8_t     LUT5_1  [1<< 8];            //  320 Bytes
-Uint8_t     LUT6_0  [1<< 7];
-Uint8_t     LUT6_1  [1<< 7];            //  256 Bytes
-Uint8_t     LUT7_0  [1<< 8];
-Uint8_t     LUT7_1  [1<< 8];            //  512 Bytes
-Uint8_t     LUTDSCF [1<< 6];            //   64 Bytes = 2976 Bytes
-
-const Huffman_t* HuffQ [2] [8] = {
-    { NULL, HuffQ1[0], HuffQ2[0], HuffQ3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0] },
-    { NULL, HuffQ1[1], HuffQ2[1], HuffQ3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1] }
-};
-
-#ifdef USE_SV8
-Huffman_t   HuffN3 [2] [ 7*7];          // 8+ 9 bit
-Huffman_t   HuffN8 [2][127];            //13+12 bit
-
-const Huffman_t* HuffN [2] [9] = {
-    { NULL, HuffQ1[0], HuffQ2[0], HuffN3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0], HuffN8[0] },
-    { NULL, HuffQ1[1], HuffQ2[1], HuffN3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1], HuffN8[1] }
-};
-#endif
-
-static const HuffSrc_t   HuffSCFI_src [4] = {
-    { 2, 3 }, { 1, 1 }, { 3, 3 }, { 0, 2 }
-};
-
-static const HuffSrc_t   HuffDSCF_src [16] = {
-    { 32, 6 }, {  4, 5 }, { 17, 5 }, { 30, 5 }, { 13, 4 }, {  0, 3 }, {  3, 3 }, {  9, 4 },
-    {  5, 3 }, {  2, 3 }, { 14, 4 }, {  3, 4 }, { 31, 5 }, {  5, 5 }, { 33, 6 }, { 12, 4 }
-};
-
-static const HuffSrc_t   HuffHdr_src [10] = {
-    {  92, 8 }, {  47, 7 }, {  10, 5 }, {   4, 4 }, {   0, 2 },
-    {   1, 1 }, {   3, 3 }, {  22, 6 }, { 187, 9 }, { 186, 9 }
-};
-
-static const HuffSrc_t   HuffQ1_src [2] [3*3*3] = { {
-    { 54, 6 }, {  9, 5 }, { 32, 6 }, {  5, 5 }, { 10, 4 }, {  7, 5 }, { 52, 6 }, {  0, 5 }, { 35, 6 },
-    { 10, 5 }, {  6, 4 }, {  4, 5 }, { 11, 4 }, {  7, 3 }, { 12, 4 }, {  3, 5 }, {  7, 4 }, { 11, 5 },
-    { 34, 6 }, {  1, 5 }, { 53, 6 }, {  6, 5 }, {  9, 4 }, {  2, 5 }, { 33, 6 }, {  8, 5 }, { 55, 6 }
-}, {
-    { 103, 8 }, {  62, 7 }, { 225, 9 }, {  55, 7 }, {   3, 4 }, {  52, 7 }, { 101, 8 }, {  60, 7 }, { 227, 9 },
-    {  24, 6 }, {   0, 4 }, {  61, 7 }, {   4, 4 }, {   1, 1 }, {   5, 4 }, {  63, 7 }, {   1, 4 }, {  59, 7 },
-    { 226, 9 }, {  57, 7 }, { 100, 8 }, {  53, 7 }, {   2, 4 }, {  54, 7 }, { 224, 9 }, {  58, 7 }, { 102, 8 }
-} };
-
-static const HuffSrc_t   HuffQ2_src [2] [5*5] = { {
-    {  89,  7 }, {  47,  6 }, { 15, 5 }, {   0, 5 }, {  91,  7 },
-    {   4,  5 }, {   6,  4 }, { 13, 4 }, {   4, 4 }, {   5,  5 },
-    {  20,  5 }, {  12,  4 }, {  4, 3 }, {  15, 4 }, {  14,  5 },
-    {   3,  5 }, {   3,  4 }, { 14, 4 }, {   5, 4 }, {   1,  5 },
-    {  90,  7 }, {   2,  5 }, { 21, 5 }, {  46, 6 }, {  88,  7 }
-}, {
-    { 921, 10 }, { 113,  7 }, { 51, 6 }, { 231, 8 }, { 922, 10 },
-    { 104,  7 }, {  30,  5 }, {  0, 3 }, {  29, 5 }, { 105,  7 },
-    {  50,  6 }, {   1,  3 }, {  2, 2 }, {   3, 3 }, {  49,  6 },
-    { 107,  7 }, {  27,  5 }, {  2, 3 }, {  31, 5 }, { 112,  7 },
-    { 920, 10 }, { 106,  7 }, { 48, 6 }, { 114, 7 }, { 923, 10 }
-} };
-
-#ifdef USE_SV8
-static const HuffSrc_t   HuffN3_src [2] [7*7] = { {
-    {  78, 7 }, {  20, 6 }, {  36, 6 }, {  51, 6 }, {  21, 6 }, { 101, 7 }, { 255, 8 },
-    {  37, 6 }, {   0, 5 }, {  62, 6 }, {   7, 5 }, {  60, 6 }, {  49, 6 }, { 100, 7 },
-    {  30, 6 }, {  53, 6 }, {   8, 5 }, {  14, 5 }, {   5, 5 }, {  54, 6 }, {  26, 6 },
-    {  43, 6 }, {   1, 5 }, {  20, 5 }, {  14, 4 }, {  22, 5 }, {   9, 5 }, {  46, 6 },
-    {  47, 6 }, {  61, 6 }, {  17, 5 }, {  16, 5 }, {  11, 5 }, {   4, 5 }, {  38, 6 },
-    {   6, 6 }, {  52, 6 }, {   6, 5 }, {  12, 5 }, {   2, 5 }, {  55, 6 }, {  27, 6 },
-    { 254, 8 }, { 126, 7 }, {  31, 6 }, {  48, 6 }, {  42, 6 }, {   7, 6 }, {  79, 7 }
-}, {
-    {  65, 9 }, { 161, 8 }, { 109, 7 }, {  11, 6 }, { 116, 7 }, { 160, 8 }, {  71, 9 },
-    {  34, 8 }, {  97, 7 }, {  56, 6 }, {   8, 5 }, {  55, 6 }, {  85, 7 }, { 166, 8 },
-    {  84, 7 }, {  52, 6 }, {   3, 4 }, {  11, 4 }, {   5, 4 }, {  59, 6 }, {  86, 7 },
-    {  10, 6 }, {  13, 5 }, {   9, 4 }, {   0, 3 }, {   8, 4 }, {  12, 5 }, {   9, 6 },
-    {  98, 7 }, {  51, 6 }, {  31, 5 }, {   7, 4 }, {  30, 5 }, {  53, 6 }, {  99, 7 },
-    { 162, 8 }, { 108, 7 }, {  50, 6 }, {   9, 5 }, {  57, 6 }, {  82, 7 }, { 163, 8 },
-    {  64, 9 }, { 167, 8 }, {  87, 7 }, { 117, 7 }, {  96, 7 }, {  33, 8 }, {  70, 9 }
-} };
-#endif
-
-static const HuffSrc_t   HuffQ3_src [2] [ 7] = { {
-    { 12, 4 }, { 4, 3 }, { 0, 2 }, { 1, 2 }, { 7, 3 }, { 5, 3 }, { 13, 4 }
-}, {
-    {  4, 5 }, { 3, 4 }, { 2, 2 }, { 3, 2 }, { 1, 2 }, { 0, 3 }, {  5, 5 }
-} };
-
-static const HuffSrc_t   HuffQ4_src [2] [ 9] = { {
-    { 5, 4 }, {  0, 3 }, { 4, 3 }, { 6, 3 }, { 7, 3 }, { 5, 3 }, {  3, 3 }, { 1, 3 }, { 4, 4 }
-}, {
-    { 9, 5 }, { 12, 4 }, { 3, 3 }, { 0, 2 }, { 2, 2 }, { 7, 3 }, { 13, 4 }, { 5, 4 }, { 8, 5 }
-} };
-
-static const HuffSrc_t   HuffQ5_src [2] [15] = { {
-    {  57, 6 }, { 23, 5 }, {  8, 4 }, { 10, 4 }, { 13, 4 }, {   0, 3 }, {   2, 3 }, { 3, 3 },
-    {   1, 3 }, { 15, 4 }, { 12, 4 }, {  9, 4 }, { 29, 5 }, {  22, 5 }, {  56, 6 }
-}, {
-    { 229, 8 }, { 56, 6 }, {  7, 5 }, {  2, 4 }, {  0, 3 }, {   3, 3 }, {   5, 3 }, { 6, 3 },
-    {   4, 3 }, {  2, 3 }, { 15, 4 }, { 29, 5 }, {  6, 5 }, { 115, 7 }, { 228, 8 },
-} };
-
-static const HuffSrc_t   HuffQ6_src [2] [31] = { {
-    {   65,  7 }, {    6,  6 }, {  44,  6 }, {  45, 6 }, {   59,  6 }, {   13,  5 }, {   17,  5 }, { 19, 5 },
-    {   23,  5 }, {   21,  5 }, {  26,  5 }, {  30, 5 }, {    0,  4 }, {    2,  4 }, {    5,  4 }, {  7, 4 },
-    {    3,  4 }, {    4,  4 }, {  31,  5 }, {  28, 5 }, {   25,  5 }, {   27,  5 }, {   24,  5 }, { 20, 5 },
-    {   18,  5 }, {   12,  5 }, {   2,  5 }, {  58, 6 }, {   33,  6 }, {    7,  6 }, {   64,  7 },
-}, {
-    { 6472, 13 }, { 6474, 13 }, { 808, 10 }, { 405, 9 }, {  203,  8 }, {  102,  7 }, {   49,  6 }, {  9, 5 },
-    {   15,  5 }, {   31,  5 }, {   2,  4 }, {   6, 4 }, {    8,  4 }, {   11,  4 }, {   13,  4 }, {  0, 3 },
-    {   14,  4 }, {   10,  4 }, {   9,  4 }, {   5, 4 }, {    3,  4 }, {   30,  5 }, {   14,  5 }, {  8, 5 },
-    {   48,  6 }, {  103,  7 }, { 201,  8 }, { 200, 8 }, { 1619, 11 }, { 6473, 13 }, { 6475, 13 },
-} };
-
-static const HuffSrc_t   HuffQ7_src [2] [63] = { {
-    { 103, 8 },    // 0.3338   01100111
-    { 153, 8 },    // 0.3766   10011001
-    { 181, 8 },    // 0.4715   10110101
-    { 233, 8 },    // 0.5528   11101001
-    {  64, 7 },    // 0.6677    1000000
-    {  65, 7 },    // 0.7041    1000001
-    {  77, 7 },    // 0.7733    1001101
-    {  81, 7 },    // 0.8296    1010001
-    {  91, 7 },    // 0.9295    1011011
-    { 113, 7 },    // 1.0814    1110001
-    { 112, 7 },    // 1.0807    1110000
-    {  24, 6 },    // 1.2748     011000
-    {  29, 6 },    // 1.3390     011101
-    {  35, 6 },    // 1.4224     100011
-    {  37, 6 },    // 1.5201     100101
-    {  41, 6 },    // 1.6642     101001
-    {  44, 6 },    // 1.7292     101100
-    {  46, 6 },    // 1.8647     101110
-    {  51, 6 },    // 2.0473     110011
-    {  49, 6 },    // 2.0152     110001
-    {  54, 6 },    // 2.1315     110110
-    {  55, 6 },    // 2.1358     110111
-    {  57, 6 },    // 2.1700     111001
-    {  60, 6 },    // 2.2449     111100
-    {   0, 5 },    // 2.3063      00000
-    {   2, 5 },    // 2.3854      00010
-    {  10, 5 },    // 2.5481      01010
-    {   5, 5 },    // 2.4867      00101
-    {   9, 5 },    // 2.5352      01001
-    {   6, 5 },    // 2.5074      00110
-    {  13, 5 },    // 2.5745      01101
-    {   7, 5 },    // 2.5195      00111
-    {  11, 5 },    // 2.5502      01011
-    {  15, 5 },    // 2.6251      01111
-    {   8, 5 },    // 2.5260      01000
-    {   4, 5 },    // 2.4418      00100
-    {   3, 5 },    // 2.3983      00011
-    {   1, 5 },    // 2.3697      00001
-    {  63, 6 },    // 2.3041     111111
-    {  62, 6 },    // 2.2656     111110
-    {  61, 6 },    // 2.2549     111101
-    {  53, 6 },    // 2.1151     110101
-    {  59, 6 },    // 2.2042     111011
-    {  52, 6 },    // 2.0837     110100
-    {  48, 6 },    // 1.9446     110000
-    {  47, 6 },    // 1.9189     101111
-    {  43, 6 },    // 1.7177     101011
-    {  42, 6 },    // 1.7035     101010
-    {  39, 6 },    // 1.5287     100111
-    {  36, 6 },    // 1.4559     100100
-    {  33, 6 },    // 1.4117     100001
-    {  28, 6 },    // 1.2776     011100
-    { 117, 7 },    // 1.1107    1110101
-    { 101, 7 },    // 1.0636    1100101
-    { 100, 7 },    // 0.9751    1100100
-    {  80, 7 },    // 0.8132    1010000
-    {  69, 7 },    // 0.7091    1000101
-    {  68, 7 },    // 0.7084    1000100
-    {  50, 7 },    // 0.6277    0110010
-    { 232, 8 },    // 0.5386   11101000
-    { 180, 8 },    // 0.4408   10110100
-    { 152, 8 },    // 0.3759   10011000
-    { 102, 8 },    // 0.3160   01100110
-}, {
-    { 14244, 14 },    // 0.0059   11011110100100
-    { 14253, 14 },    // 0.0098   11011110101101
-    { 14246, 14 },    // 0.0078   11011110100110
-    { 14254, 14 },    // 0.0111   11011110101110
-    {  3562, 12 },    // 0.0320     110111101010
-    {   752, 10 },    // 0.0920       1011110000
-    {   753, 10 },    // 0.1057       1011110001
-    {   160,  9 },    // 0.1403        010100000
-    {   162,  9 },    // 0.1579        010100010
-    {   444,  9 },    // 0.2486        110111100
-    {   122,  8 },    // 0.3772         01111010
-    {   223,  8 },    // 0.5710         11011111
-    {    60,  7 },    // 0.6858          0111100
-    {    73,  7 },    // 0.8033          1001001
-    {   110,  7 },    // 0.9827          1101110
-    {    14,  6 },    // 1.2601           001110
-    {    24,  6 },    // 1.3194           011000
-    {    25,  6 },    // 1.3938           011001
-    {    34,  6 },    // 1.5693           100010
-    {    37,  6 },    // 1.7846           100101
-    {    54,  6 },    // 2.0078           110110
-    {     3,  5 },    // 2.2975            00011
-    {     9,  5 },    // 2.5631            01001
-    {    11,  5 },    // 2.7021            01011
-    {    16,  5 },    // 3.1465            10000
-    {    19,  5 },    // 3.4244            10011
-    {    21,  5 },    // 3.5921            10101
-    {    24,  5 },    // 3.7938            11000
-    {    26,  5 },    // 3.9595            11010
-    {    29,  5 },    // 4.1546            11101
-    {    31,  5 },    // 4.2623            11111
-    {     2,  4 },    // 4.5180             0010
-    {     0,  4 },    // 4.3151             0000
-    {    30,  5 },    // 4.2538            11110
-    {    28,  5 },    // 4.1422            11100
-    {    25,  5 },    // 3.9145            11001
-    {    22,  5 },    // 3.6691            10110
-    {    20,  5 },    // 3.4955            10100
-    {    14,  5 },    // 2.9155            01110
-    {    13,  5 },    // 2.7921            01101
-    {     8,  5 },    // 2.5553            01000
-    {     6,  5 },    // 2.3093            00110
-    {     2,  5 },    // 2.1200            00010
-    {    46,  6 },    // 1.8134           101110
-    {    35,  6 },    // 1.5824           100011
-    {    31,  6 },    // 1.4701           011111
-    {    21,  6 },    // 1.3187           010101
-    {    15,  6 },    // 1.2776           001111
-    {    95,  7 },    // 0.9664          1011111
-    {    72,  7 },    // 0.7922          1001000
-    {    41,  7 },    // 0.6838          0101001
-    {   189,  8 },    // 0.5024         10111101
-    {   123,  8 },    // 0.3830         01111011
-    {   377,  9 },    // 0.2232        101111001
-    {   161,  9 },    // 0.1566        010100001
-    {   891, 10 },    // 0.1383       1101111011
-    {   327, 10 },    // 0.0900       0101000111
-    {   326, 10 },    // 0.0790       0101000110
-    {  3560, 12 },    // 0.0254     110111101000
-    { 14255, 14 },    // 0.0117   11011110101111
-    { 14247, 14 },    // 0.0085   11011110100111
-    { 14252, 14 },    // 0.0085   11011110101100
-    { 14245, 14 },    // 0.0065   11011110100101
-} };
-
-#ifdef USE_SV8
-static const HuffSrc_t   HuffN8_src [2] [127] = { {
-    { 2426, 13 }, { 4943, 13 }, {  787, 12 }, { 2470, 12 }, { 7270, 13 }, { 1764, 12 },
-    { 3632, 12 }, { 3633, 12 }, { 2486, 12 }, {  395, 11 }, {  607, 11 }, { 1242, 11 },
-    {  108, 10 }, {  300, 10 }, {  199, 10 }, {  440, 10 }, {  442, 10 }, {  616, 10 },
-    {  909, 10 }, {  897, 10 }, {  178,  9 }, {  309,  9 }, {  311,  9 }, {  451,  9 },
-    {  449,  9 }, {   26,  8 }, {   74,  8 }, {   94,  8 }, {  122,  8 }, {  136,  8 },
-    {   12,  7 }, {   29,  7 }, {   28,  7 }, {   36,  7 }, {   39,  7 }, {   46,  7 },
-    {   60,  7 }, {   69,  7 }, {   76,  7 }, {   92,  7 }, {  126,  7 }, {   11,  6 },
-    {   15,  6 }, {   10,  6 }, {   16,  6 }, {   21,  6 }, {   25,  6 }, {   28,  6 },
-    {   32,  6 }, {   31,  6 }, {   37,  6 }, {   47,  6 }, {   43,  6 }, {   35,  6 },
-    {   45,  6 }, {   48,  6 }, {   52,  6 }, {   53,  6 }, {   54,  6 }, {   62,  6 },
-    {   59,  6 }, {    0,  5 }, {   61,  6 }, {   51,  6 }, {    2,  5 }, {    1,  5 },
-    {   60,  6 }, {   57,  6 }, {   58,  6 }, {   55,  6 }, {   50,  6 }, {   49,  6 },
-    {   42,  6 }, {   40,  6 }, {   44,  6 }, {   41,  6 }, {   39,  6 }, {   33,  6 },
-    {   29,  6 }, {   26,  6 }, {   24,  6 }, {   20,  6 }, {   17,  6 }, {   13,  6 },
-    {    8,  6 }, {    9,  6 }, {  127,  7 }, {   93,  7 }, {   73,  7 }, {   72,  7 },
-    {   54,  7 }, {   38,  7 }, {   45,  7 }, {   14,  7 }, {   25,  7 }, {   15,  7 },
-    {  226,  8 }, {  137,  8 }, {  111,  8 }, {   95,  8 }, {   88,  8 }, {   48,  8 },
-    {  455,  9 }, {  450,  9 }, {  246,  9 }, {  247,  9 }, {  179,  9 }, {   55,  9 },
-    {  896, 10 }, {  620, 10 }, {  443, 10 }, {  302, 10 }, {  301, 10 }, {  198, 10 },
-    {  109, 10 }, { 1234, 11 }, {  883, 11 }, {  392, 11 }, {  394, 11 }, { 3634, 12 },
-    { 2487, 12 }, {  786, 12 }, { 1765, 12 }, { 1212, 12 }, { 7271, 13 }, { 2427, 13 },
-    { 4942, 13 }
-}, {
-    { 3728, 12 }, { 4005, 12 }, {  264, 11 }, { 4004, 12 }, { 4044, 12 }, { 4045, 12 },
-    { 4046, 12 }, { 1424, 11 }, {  449, 11 }, {  448, 11 }, {  139, 10 }, {  231, 10 },
-    {  133, 10 }, {  719, 10 }, {  641, 10 }, {  676, 10 }, {  225, 10 }, {  677, 10 },
-    {  620, 10 }, {   72,  9 }, {   23,  9 }, {   67,  9 }, {   75,  9 }, {  113,  9 },
-    {  311,  9 }, {   68,  9 }, {  316,  9 }, {  467,  9 }, {   10,  8 }, {  468,  9 },
-    {   35,  8 }, {   27,  8 }, {  358,  9 }, {   32,  8 }, {   26,  8 }, {  501,  9 },
-    {   44,  8 }, {   45,  8 }, {  142,  8 }, {  173,  8 }, {  161,  8 }, {  188,  8 },
-    {  189,  8 }, {  190,  8 }, {  191,  8 }, {  254,  8 }, {  251,  8 }, {  255,  8 },
-    {   19,  7 }, {   26,  7 }, {   70,  7 }, {   76,  7 }, {   87,  7 }, {   85,  7 },
-    {  124,  7 }, {    7,  6 }, {   15,  6 }, {   41,  6 }, {   46,  6 }, {    2,  5 },
-    {   16,  5 }, {   28,  5 }, {   12,  4 }, {    1,  2 }, {   13,  4 }, {   30,  5 },
-    {   18,  5 }, {    0,  5 }, {   45,  6 }, {   34,  6 }, {   12,  6 }, {    3,  6 },
-    {  118,  7 }, {   88,  7 }, {   81,  7 }, {   29,  7 }, {   78,  7 }, {   23,  7 },
-    {   27,  7 }, {  253,  8 }, {   12,  7 }, {  232,  8 }, {  235,  8 }, {  159,  8 },
-    {  238,  8 }, {  172,  8 }, {  168,  8 }, {  143,  8 }, {  154,  8 }, {   40,  8 },
-    {    8,  8 }, {  478,  9 }, {    9,  8 }, {  479,  9 }, {  469,  9 }, {   42,  8 },
-    {   43,  8 }, {  504,  9 }, {  357,  9 }, {  321,  9 }, {  339,  9 }, {  317,  9 },
-    {  114,  9 }, {   82,  9 }, {   83,  9 }, {   73,  9 }, {   74,  9 }, { 1000, 10 },
-    {  933, 10 }, {  621, 10 }, {  718, 10 }, { 2003, 11 }, {  713, 10 }, { 2020, 11 },
-    {  230, 10 }, { 1865, 11 }, {   44, 10 }, {  138, 10 }, { 1280, 11 }, { 2021, 11 },
-    { 3729, 12 }, { 4047, 12 }, {   90, 11 }, {  265, 11 }, { 1281, 11 }, { 1425, 11 },
-    {   91, 11 }
-} };
-#endif
-
-#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)) )
-
-
-void
-Init_Huffman_Encoder_SV7 ( void )
-{
-    // Splitting of the 36 Samples
-    MAKE ( HuffSCFI, HuffSCFI_src );
-
-    // Differential Scalefactors
-    MAKE ( HuffDSCF, HuffDSCF_src );
-
-    // resolution, differential quantizer indizes
-    MAKE ( HuffHdr, HuffHdr_src );
-
-    // 3-step quantizer, 3 bundled samples
-    MAKE ( HuffQ1[0], HuffQ1_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ1[1], HuffQ1_src[1] );          // more shaped, book 1
-
-    // 5-step quantizer, 2 bundled samples
-    MAKE ( HuffQ2[0], HuffQ2_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ2[1], HuffQ2_src[1] );          // more shaped, book 1
-
-    // 7-step quantizer, single samples
-    MAKE ( HuffQ3[0], HuffQ3_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ3[1], HuffQ3_src[1] );          // more shaped, book 1
-
-#ifdef USE_SV8
-    // 7-step quantizer, 2 bundled samples
-    MAKE ( HuffN3[0], HuffN3_src[0] );          // less shaped, book 0
-    MAKE ( HuffN3[1], HuffN3_src[1] );          // more shaped, book 1
-#endif
-
-    // 9-step quantizer, single samples
-    MAKE ( HuffQ4[0], HuffQ4_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ4[1], HuffQ4_src[1] );          // more shaped, book 1
-
-    // 15-step quantizer, single samples
-    MAKE ( HuffQ5[0], HuffQ5_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ5[1], HuffQ5_src[1] );          // more shaped, book 1
-
-    // 31-step quantizer, single samples
-    MAKE ( HuffQ6[0], HuffQ6_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ6[1], HuffQ6_src[1] );          // more shaped, book 1
-
-    // 63-step quantizer, single samples
-    MAKE ( HuffQ7[0], HuffQ7_src[0] );          // less shaped, book 0
-    MAKE ( HuffQ7[1], HuffQ7_src[1] );          // more shaped, book 1
-
-#ifdef USE_SV8
-    // 127-step quantizer, single samples
-    MAKE ( HuffN8[0], HuffN8_src[0] );          // book 0
-    MAKE ( HuffN8[1], HuffN8_src[1] );          // book 1
-#endif
-}
-
-#ifndef MPP_ENCODER
-
-void
-Init_Huffman_Decoder_SV7 ( void )
-{
-    Init_Huffman_Encoder_SV7 ();
-
-    SORT ( HuffHdr  ,    5  );
-    SORT ( HuffSCFI ,    0  );
-    SORT ( HuffDSCF ,    7  );
-    SORT ( HuffQ1[0],    0  );
-    SORT ( HuffQ1[1],    0  );
-    SORT ( HuffQ2[0],    0  );
-    SORT ( HuffQ2[1],    0  );
-#ifdef USE_SV8
-    SORT ( HuffN3[0],    0  );
-    SORT ( HuffN3[1],    0  );
-#endif
-    SORT ( HuffQ3[0], Dc[3] );
-    SORT ( HuffQ3[1], Dc[3] );
-    SORT ( HuffQ4[0], Dc[4] );
-    SORT ( HuffQ4[1], Dc[4] );
-    SORT ( HuffQ5[0], Dc[5] );
-    SORT ( HuffQ5[1], Dc[5] );
-    SORT ( HuffQ6[0], Dc[6] );
-    SORT ( HuffQ6[1], Dc[6] );
-    SORT ( HuffQ7[0], Dc[7] );
-    SORT ( HuffQ7[1], Dc[7] );
-#ifdef USE_SV8
-    SORT ( HuffN8[0], Dc[8] );
-    SORT ( HuffN8[1], Dc[8] );
-#endif
-
-    LOOKUP ( HuffQ1[0], LUT1_0  );
-    LOOKUP ( HuffQ1[1], LUT1_1  );
-    LOOKUP ( HuffQ2[0], LUT2_0  );
-    LOOKUP ( HuffQ2[1], LUT2_1  );
-    LOOKUP ( HuffQ3[0], LUT3_0  );
-    LOOKUP ( HuffQ3[1], LUT3_1  );
-    LOOKUP ( HuffQ4[0], LUT4_0  );
-    LOOKUP ( HuffQ4[1], LUT4_1  );
-    LOOKUP ( HuffQ5[0], LUT5_0  );
-    LOOKUP ( HuffQ5[1], LUT5_1  );
-    LOOKUP ( HuffQ6[0], LUT6_0  );
-    LOOKUP ( HuffQ6[1], LUT6_1  );
-    LOOKUP ( HuffQ7[0], LUT7_0  );
-    LOOKUP ( HuffQ7[1], LUT7_1  );
-    LOOKUP ( HuffDSCF , LUTDSCF );
-}
-
-#endif
-
-/* end of huffsv7.c */
Index: mppenc/branches/r2d/src/minimax.h
===================================================================
--- mppenc/branches/r2d/src/minimax.h	(revision 61)
+++ 	(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/src/mppdec.h
===================================================================
--- mppenc/branches/r2d/src/mppdec.h	(revision 61)
+++ mppenc/branches/r2d/src/mppdec.h	(revision 64)
@@ -420,12 +420,4 @@
 # define PCLOSE(fp)                     pclose(fp)
 #endif
-
-#if defined _WIN32
-# define STRUCT_STAT            struct _stat
-# define STAT_CMD(f,s)          _stat (f, s)
-#else
-# define STRUCT_STAT            struct stat
-# define STAT_CMD(f,s)          stat (f, s)
-#endif /* WIN32 */
 
 #ifndef S_ISDIR
@@ -883,30 +875,4 @@
 typedef CPair_t   CPairArray [32];
 typedef Float     SCFTriple   [3];
-typedef struct {
-#ifndef MPP_ENCODER
-    Uint32_t      Code;         // >=32 bit
-# ifdef USE_HUFF_PACK
-    Schar         Value;        // >= 7 bit
-    Uchar         Length;       // >= 4 bit
-# else
-    Int           Value;
-    Uint          Length;
-# endif
-#else
-# ifdef USE_HUFF_PACK
-    Uint8_t       Length;      // >=  4 bit
-    Uint8_t       ___;
-    Uint16_t      Code;        // >= 14 bit
-# else
-    Uint          Code;
-    Uint          Length;
-# endif
-#endif
-} Huffman_t ;
-
-typedef struct {
-    Uint          Code   : 16;  // >= 14 bit
-    Uint          Length :  8;  // >=  4 bit
-} HuffSrc_t ;
 
 typedef struct {
Index: mppenc/branches/r2d/src/mppenc.c
===================================================================
--- mppenc/branches/r2d/src/mppenc.c	(revision 61)
+++ mppenc/branches/r2d/src/mppenc.c	(revision 64)
@@ -51,5 +51,4 @@
 unsigned int  NoUnicode       = 1;      // console is unicode or not (tag translation)
 UintMax_t     SamplesInWAVE   = 0;      // number of samples per channel in the WAV file
-unsigned int  Overflows       = 0;      // number of internal (filterbank) clippings
 float         MaxOverFlow     = 0.f;    // maximum overflow
 float         ScalingFactorl  = 1.f;    // Scaling the input signal
Index: mppenc/branches/r2d/src/mppenc.h
===================================================================
--- mppenc/branches/r2d/src/mppenc.h	(revision 61)
+++ mppenc/branches/r2d/src/mppenc.h	(revision 64)
@@ -36,17 +36,8 @@
 #define X_MEM            1152
 
-// bitstream.c
-#define BUFFER_ALMOST_FULL  8192
-#define BUFFER_FULL         (BUFFER_ALMOST_FULL + 4352)         // 34490 bit/frame  1320.3 kbps
-
 // quant.h
 #define SCFfac              0.832980664785f     // = SCF[n-1]/SCF[n]
 
 // wave_in.h
-
-typedef struct {
-    unsigned int  L [36];
-    unsigned int  R [36];
-} SubbandQuantTyp;
 
 typedef struct {
@@ -81,11 +72,4 @@
 void   Init_ANS   ( void );
 void   NS_Analyse ( const int, const unsigned char* MS, const SMRTyp, const int* Transient );
-
-
-// bitstream.c
-typedef struct {
-    Uint32_t*     ptr;
-    unsigned int  bit;
-} BitstreamPos;
 
 
@@ -199,9 +183,5 @@
 
 
-// huffsv7.c
-extern Huffman_t         HuffHdr  [10];         // contains tables for SV7-header
-extern Huffman_t         HuffSCFI [ 4];         // contains tables for SV7-scalefactor select
-extern Huffman_t         HuffDSCF [16];         // contains tables for SV7-scalefactor coding
-extern const Huffman_t*  HuffQ [2] [8];         // points to tables for SV7-sample coding
+
 
 void    Huffman_SV7_Encoder ( void );
Index: mppenc/branches/r2d/src/quant.c
===================================================================
--- mppenc/branches/r2d/src/quant.c	(revision 61)
+++ 	(revision )
@@ -1,319 +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
- */
-
-#include "mppenc.h"
-
-/* V A R I A B L E S */
-float  __SCF    [128 + 6];   // tabulated scalefactors
-float  __invSCF [128 + 6];   // inverted scalefactors
-
-
-// Quantization-coefficients: step/65536 bzw. (2*D[Res]+1)/65536
-static const float  __A [1 + 18] = {
-    0.0000762939453125f,
-    0.0000000000000000f, 0.0000457763671875f, 0.0000762939453125f, 0.0001068115234375f,
-    0.0001373291015625f, 0.0002288818359375f, 0.0004730224609375f, 0.0009613037109375f,
-    0.0019378662109375f, 0.0038909912109375f, 0.0077972412109375f, 0.0156097412109375f,
-    0.0312347412109375f, 0.0624847412109375f, 0.1249847412109375f, 0.2499847412109375f,
-    0.4999847412109375f
-};
-
-
-// Requantization-coefficients: 65536/step bzw. 1/A[Res]
-static const float  __C [1 + 18] = {
-    13107.200000000001f,
-    65535.000000000000f, 21845.333333333332f, 13107.200000000001f, 9362.285714285713f,
-     7281.777777777777f,  4369.066666666666f,  2114.064516129032f, 1040.253968253968f,
-      516.031496062992f,   257.003921568627f,   128.250489236790f,   64.062561094819f,
-       32.015632633121f,    16.003907203907f,     8.000976681723f,    4.000244155527f,
-        2.000061037018f,     1.000015259022f
-};
-
-
-// Requantization-Offset: 2*D+1 = steps of quantizer
-static const int  __D [1 + 18] = {
-    2,
-    0,     1,     2,     3,     4,     7,    15,    31,    63,
-  127,   255,   511,  1023,  2047,  4095,  8191, 16383, 32767
-};
-
-#define A   (__A + 1)
-#define C   (__C + 1)
-#define D   (__D + 1)
-
-// Generation of the scalefactors and their inverses
-void
-Init_Skalenfaktoren ( void )
-{
-    int  n;
-
-    for ( n = -6; n < 128; n++ ) {
-        SCF[n]    = (float) ( pow(10.,-0.1*(n-1)/1.26) );
-        invSCF[n] = (float) ( pow(10., 0.1*(n-1)/1.26) );
-    }
-}
-
-#pragma warning ( disable : 4305 )
-
-static float  NoiseInjectionCompensation1D [18] = {
-#if 1
-    1.f,
-    0.884621,
-    0.935711,
-    0.970829,
-    0.987941,
-    0.994315,
-    0.997826,
-    0.999744,
-    1., 1., 1., 1., 1., 1., 1., 1., 1., 1.
-#else
-    1.,
-    0.907073,   //  -1...+1
-    0.946334,   //  -2...+2
-    0.974793,   //  -3...+3
-    0.987647,   //  -4...+4
-    0.994330,   //  -7...+7
-    0.997846,   // -15...+15
-    1.,         // -31...+31
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-    1.,
-#endif
-} ;
-
-#if 0
-static float  NoiseInjectionCompensation2D [18] [32] = {
-    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
-    { 0.931595, 0.891390, 0.852494, 0.872420, 0.904053, 0.933716, 0.958976, 0.977719, 0.993979, 1.009011, 1.020961, 1.029564, 1.026582, 1.026753, 1.035573, 1.053251, 1.073429, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344, 1.096344,  },
-    { 0.878264, 0.882351, 0.904261, 0.930843, 0.949243, 0.966741, 0.980500, 0.988182, 0.993361, 0.997112, 0.998918, 0.999501, 1.003179, 1.007445, 1.008678, 0.995890, 0.991015, 0.988019, 0.985479, 0.987646, 1.003605, 1.029301, 1.040511, 1.061531, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302, 1.083302,  },
-    { 0.866977, 0.943500, 0.941561, 0.953049, 0.967274, 0.980476, 0.988678, 0.993240, 0.996376, 0.998513, 0.999545, 0.999775, 1.000898, 1.003954, 1.006308, 1.004932, 1.002867, 1.002922, 1.003624, 1.005487, 1.003919, 1.008022, 0.987693, 1.000358, 1.017461, 1.039166, 1.056053, 1.068191, 1.068191, 1.068191, 1.068191, 1.068191,  },
-    { 0.880390, 0.976713, 0.976180, 0.976596, 0.982011, 0.988786, 0.993619, 0.996641, 0.998824, 1.000297, 1.001195, 1.001718, 1.002395, 1.003503, 1.005617, 1.005072, 1.002409, 1.003703, 1.003412, 1.003318, 1.005290, 1.007112, 1.014370, 1.010040, 1.000780, 1.005700, 1.020505, 1.030123, 1.030123, 1.030123, 1.030123, 1.030123,  },
-    { 0.916894, 0.987164, 0.988734, 0.992318, 0.995268, 0.996932, 0.998141, 0.999072, 0.999674, 1.000104, 1.000292, 1.000386, 1.000399, 1.000222, 1.000671, 1.002127, 1.000137, 1.000046, 0.999644, 0.999156, 1.000568, 1.000098, 0.993764, 0.993954, 0.998971, 1.002835, 1.002972, 0.995376, 1.001643, 1.001643, 1.001643, 1.001643,  },
-    { 0.982771, 0.995034, 0.997118, 0.998294, 0.998652, 0.999016, 0.999382, 0.999598, 0.999746, 0.999851, 0.999837, 0.999881, 0.999847, 1.000154, 0.999885, 1.000222, 0.999963, 1.000934, 0.999804, 0.999927, 1.000379, 0.997574, 0.997943, 0.998748, 0.998151, 0.997458, 1.000319, 1.001091, 0.998461, 0.996151, 1.005969, 1.005969,  },
-    { 0.997150, 0.999903, 0.999424, 0.999537, 0.999661, 0.999753, 0.999851, 0.999903, 0.999928, 0.999963, 0.999969, 0.999941, 0.999974, 0.999967, 0.999996, 0.999975, 0.999966, 0.999704, 0.999946, 0.999894, 0.999905, 1.000840, 1.000716, 1.000799, 1.000406, 0.999912, 1.000153, 0.999789, 1.000495, 1.000495, 1.001167, 1.001347,  },
-    { 0.995524, 0.999983, 1.000044, 0.999965, 0.999970, 0.999974, 0.999986, 0.999995, 0.999996, 1.000011, 0.999997, 1.000010, 1.000010, 1.000026, 1.000006, 1.000148, 1.000048, 0.999999, 1.000161, 1.000193, 0.999797, 1.000145, 0.999974, 1.000039, 0.999731, 0.999985, 1.000563, 1.000256, 1.000637, 1.000050, 1.002013, 1.001053,  },
-    { 0.994796, 0.999833, 1.000003, 1.000012, 0.999986, 0.999991, 0.999991, 1.000000, 1.000004, 0.999999, 1.000005, 1.000004, 1.000008, 0.999996, 1.000027, 1.000097, 0.999951, 0.999938, 0.999989, 1.000001, 1.000048, 0.999935, 1.000068, 1.000134, 0.999961, 1.000198, 0.999956, 0.999957, 0.999844, 1.000087, 0.999708, 1.000198,  },
-    { 0.996046, 0.999902, 1.000019, 1.000017, 0.999983, 0.999997, 1.000002, 0.999993, 0.999999, 1.000003, 1.000001, 1.000015, 1.000004, 1.000006, 0.999987, 0.999993, 0.999992, 1.000029, 1.000064, 0.999997, 1.000044, 1.000044, 0.999919, 0.999875, 1.000011, 0.999897, 0.999905, 0.999996, 0.999934, 0.999968, 1.000008, 0.999902,  },
-    { 0.998703, 0.999963, 1.000021, 1.000006, 1.000008, 1.000000, 1.000003, 0.999994, 0.999990, 0.999990, 1.000003, 1.000009, 1.000001, 0.999999, 1.000001, 1.000009, 0.999999, 0.999988, 1.000003, 0.999971, 1.000005, 1.000042, 0.999924, 0.999995, 0.999998, 0.999988, 0.999961, 0.999942, 1.000046, 1.000061, 1.000112, 1.000052,  },
-    { 0.999872, 1.000001, 1.000004, 0.999998, 0.999999, 0.999998, 0.999992, 0.999990, 0.999991, 1.000000, 1.000000, 1.000000, 1.000002, 0.999996, 1.000004, 1.000011, 0.999963, 1.000016, 1.000050, 0.999996, 0.999998, 1.000006, 0.999990, 0.999948, 0.999974, 1.000060, 1.000014, 0.999987, 0.999986, 0.999917, 0.999973, 1.000035,  },
-    { 1.000366, 1.000006, 0.999996, 0.999995, 0.999998, 0.999996, 0.999991, 1.000001, 0.999990, 0.999996, 1.000010, 0.999999, 1.000002, 1.000000, 0.999996, 0.999990, 1.000014, 0.999978, 1.000011, 0.999983, 0.999988, 0.999971, 0.999997, 0.999989, 0.999986, 0.999958, 1.000005, 0.999992, 0.999975, 0.999975, 0.999975, 0.999975,  },
-    { 0.999736, 0.999995, 1.000002, 1.000004, 0.999999, 1.000000, 1.000003, 1.000000, 1.000007, 0.999992, 0.999997, 0.999998, 0.999998, 0.999997, 1.000007, 1.000012, 1.000004, 0.999995, 0.999996, 1.000009, 1.000003, 1.000008, 1.000001, 1.000003, 1.000011, 1.000019, 0.999991, 0.999970, 0.999970, 0.999970, 0.999970, 0.999965,  },
-    { 0.999970, 1.000000, 1.000000, 1.000000, 1.000001, 1.000000, 1.000000, 0.999999, 1.000001, 1.000000, 0.999999, 0.999999, 0.999999, 1.000007, 1.000005, 1.000002, 0.999999, 0.999999, 1.000000, 0.999997, 0.999999, 1.000001, 1.000001, 0.999988, 0.999988, 0.999984, 0.999995, 0.999986, 0.999986, 0.999986, 0.999986, 0.999986,  },
-    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
-    { 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,  },
-};
-#endif
-
-#pragma warning ( default : 4305 )
-
-
-void
-NoiseInjectionComp ( void )
-{
-    int  i;
-
-    for ( i = 0; i < sizeof(NoiseInjectionCompensation1D)/sizeof(*NoiseInjectionCompensation1D); i++ )
-        NoiseInjectionCompensation1D [i] = 1.f;
-#if 0
-    for ( i = 0; i < sizeof(NoiseInjectionCompensation2D)/sizeof(**NoiseInjectionCompensation2D); i++ )
-        NoiseInjectionCompensation2D [0][i] = 1.f;
-#endif
-}
-
-
-// Quantizes a subband and calculates iSNR
-float
-ISNR_Schaetzer ( const float* input, const float SNRcomp, const int res )
-{
-    int    k;
-    float  fac    = A [res];
-    float  invfac = C [res];
-    float  Signal = 1.e-30f;
-    float  Fehler = 1.e-30f;
-    float  tmp ;
-    float  tmp2;
-    float  tmp3;
-
-    // Summation of the absolute power and the quadratic error
-    for ( k = 0; k < 36; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-        // q = ftol(in), correct rounding
-        tmp  = tmp2 * fac + 0xFF8000;
-        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
-        tmp  = tmp3 - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-
-    // Utilization of SNRcomp only if SNR > 1 !!!
-    return Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-}
-
-
-float
-ISNR_Schaetzer_Trans ( const float* input, const float SNRcomp, const int res )
-{
-    int    k;
-    float  fac    = A [res];
-    float  invfac = C [res];
-    float  Signal;
-    float  Fehler;
-    float  ret ;
-    float  tmp ;
-    float  tmp2;
-    float  tmp3;
-
-    // Summation of the absolute power and the quadratic error
-    k = 0;
-    Signal = Fehler = 1.e-30f;
-    for ( ; k < 12; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-        // q = ftol(in), correct rounding
-        tmp  = tmp2 * fac + 0xFF8000;
-        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
-        tmp  = tmp3 - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    ret = tmp;
-    Signal = Fehler = 1.e-30f;
-    for ( ; k < 24; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-        // q = ftol(in), correct rounding
-        tmp  = tmp2 * fac + 0xFF8000;
-        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
-        tmp  = tmp3 - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    if ( tmp > ret ) ret = tmp;
-    //ret += tmp;
-    Signal = Fehler = 1.e-30f;
-    for ( ; k < 36; k++ ) {
-        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
-        // q = ftol(in), correct rounding
-        tmp  = tmp2 * fac + 0xFF8000;
-        tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
-        tmp  = tmp3 - tmp2;
-
-        Fehler += tmp * tmp;
-        Signal += tmp2 * tmp2;
-    }
-    tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
-    if ( tmp > ret ) ret = tmp;
-    //ret += tmp;
-    //ret *= 0.33333333333f;
-
-    return ret;
-}
-
-
-// Linear quantizer for a subband
-void
-QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors )
-{
-    int    n;
-    int    offset  = D [res];
-    float  mult    = A [res] * NoiseInjectionCompensation1D [res];
-    float  invmult = C [res];
-    float  tmp;
-    int    quant;
-    float  signal;
-
-    for ( n = 0; n < 36 - MAX_NS_ORDER; n++, input++, qu_output++ ) {
-        // q = ftol(in), correct rounding
-        tmp   = *input * mult + 0xFF8000;
-        quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
-
-        // limitation to 0...2D
-        if ((unsigned int)quant > (unsigned int)2*offset ) {
-            quant = mini ( quant, 2*offset );
-            quant = maxi ( quant,        0 );
-        }
-        *qu_output  = quant;
-    }
-
-    for ( ; n < 36; n++, input++, qu_output++ ) {
-        // q = ftol(in), correct rounding
-        signal = *input * mult;
-        tmp   =  signal + 0xFF8000;
-        quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
-
-        // calculate the current error and save it for error refeeding
-        errors [n + 6] = invmult * (quant - offset) - signal * NoiseInjectionCompensation1D [res];
-
-        // limitation to 0...2D
-        if ((unsigned int)quant > (unsigned int)2*offset ) {
-            quant = mini ( quant, 2*offset );
-            quant = maxi ( quant,        0 );
-        }
-        *qu_output  = quant;
-    }
-}
-
-
-// NoiseShaper for a subband
-void
-QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR )
-{
-#define E(x) *((int*)errors+(x))
-
-    float  signal;
-    float  tmp;
-    float  mult    = A [res];
-    float  invmult = C [res];
-    int    offset  = D [res];
-    int    n;
-    int    quant;
-
-    E(0) = E(1) = E(2) = E(3) = E(4) = E(5) = 0;       // arghh, it produces pops on each frame boundary!
-
-    for ( n = 0; n < 36; n++, input++, qu_output++ ) {
-        signal = *input * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
-
-        // quant = ftol(signal), correct rounding
-        tmp   = signal * mult + 0xFF8000;
-        quant = *(int*) & tmp - 0x4B7F8000;
-
-        // calculate the current error and save it for error refeeding
-        errors [n + 6] = invmult * quant - signal * NoiseInjectionCompensation1D [res];
-
-        // limitation to +/-D
-        quant = minf ( quant, +offset );
-        quant = maxf ( quant, -offset );
-
-        *qu_output = (unsigned int)(quant + offset);
-    }
-}
-
-/* end of quant.c */
-
-// pfk@schnecke.offl.uni-jena.de@EMAIL, Andree.Buschmann@web.de@EMAIL, BuschmannA@becker.de@EMAIL, miyaguch@eskimo.com@EMAIL, r3mix@irc.openprojects.net@EMAIL, dibrom@users.sourceforge.net@EMAIL, m.p.bakker-10@student.utwente.nl@EMAIL, djmrob@essex.ac.uk@EMAIL, dim@psytel-research.co.yu@EMAIL, lerch@zplane.de@EMAIL, takehiro@users.sourceforge.net@EMAIL, aleidinger@users.sourceforge.net@EMAIL, Robert.Hegemann@gmx.de@EMAIL, bouvigne@mp3-tech.org@EMAIL, monty@xiph.org@EMAIL, Pumpkinz99@aol.com@EMAIL, spase@outerspase.net@EMAIL, mt@wildpuppy.com@EMAIL, juha.laaksonheimo@tut.fi@EMAIL, speek@myrealbox.com@EMAIL, w.speek@12move.nl@EMAIL, martin@spueler.de@EMAIL, nicolaus.berglmeir@t-online.de@EMAIL, thomas.a.juerges@ruhr-uni-bochum.de@EMAIL, HelH@mpex.net@EMAIL, garf@roadum.demon.co.uk@EMAIL, gcp@sjeng.org@EMAIL, mike@naivesoftware.com@EMAIL, case@mobiili.net@EMAIL, steve.lhomme@free.fr@EMAIL, walter@binity.com@EMAIL
Index: mppenc/branches/r2d/src/tools.c
===================================================================
--- mppenc/branches/r2d/src/tools.c	(revision 61)
+++ 	(revision )
@@ -1,586 +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 "mppdec.h"
-
-
-#if defined HAVE_INCOMPLETE_READ  &&  FILEIO != 1
-
-size_t
-complete_read ( int fd, void* dest, size_t bytes )
-{
-    size_t  bytesread = 0;
-    size_t  ret;
-
-    while ( bytes > 0 ) {
-#if defined _WIN32  &&  defined USE_HTTP  &&  !defined MPP_ENCODER
-        ret = fd & 0x4000  ?  recv ( fd & 0x3FFF, dest, bytes, 0)  :  read ( fd, dest, bytes );
-#else
-        ret = read ( fd, dest, bytes );
-#endif
-        if ( ret == 0  ||  ret == (size_t)-1 )
-            break;
-        dest       = (void*)(((char*)dest) + ret);
-        bytes     -= ret;
-        bytesread += ret;
-    }
-    return bytesread;
-}
-
-#endif
-
-
-int
-isdir ( const char* Name )
-{
-#if FILEIO == 1
-    return 1;
-#else
-    STRUCT_STAT  st;
-
-    if ( STAT_CMD ( Name, &st ) != 0 )
-        return 0;
-    return S_ISDIR ( st.st_mode );
-#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 ( Uint32_t* dst, size_t words32bit )
-{
-
-    for ( ; words32bit--; dst++ ) {
-# if  INT_MAX >= 2147483647L
-        Uint32_t  tmp = *dst;
-        tmp  = ((tmp << 0x10) & 0xFFFF0000) | ((tmp >> 0x10) & 0x0000FFFF);
-        tmp  = ((tmp << 0x08) & 0xFF00FF00) | ((tmp >> 0x08) & 0x00FF00FF);
-        *dst = tmp;
-# else
-        Uint8_t  tmp;
-        tmp                = ((Uint8_t*)dst)[0];
-        ((Uint8_t*)dst)[0] = ((Uint8_t*)dst)[3];
-        ((Uint8_t*)dst)[3] = tmp;
-        tmp                = ((Uint8_t*)dst)[1];
-        ((Uint8_t*)dst)[1] = ((Uint8_t*)dst)[2];
-        ((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.
- */
-
-size_t
-Read_LittleEndians ( FILE_T fp, Uint32_t* dst, size_t words32bit )
-{
-    size_t  wordsread;
-    wordsread = READ ( fp, dst, words32bit * sizeof(*dst) ) / sizeof(*dst);
-
-#if ENDIAN == HAVE_BIG_ENDIAN
-    Change_Endian32 ( dst, wordsread );
-#endif
-
-    return wordsread;
-}
-
-#ifndef MPP_ENCODER
-
-/*
- *  This is the main requantisation routine which does the following things:
- *
- *      - rescaling the quantized values (int) to their original value (float)
- *      - recalculating both stereo channels for MS stereo
- *
- *  See also: Requantize_IntensityStereo()
- *
- *  For performance reasons all cases are programmed separately and the code
- *  is unrolled.
- *
- *  Input is:
- *      - Stop_Band:
- *          the last band using MS or LR stereo
- *      - used_MS[Band]:
- *          MS or LR stereo flag for every band (0...Stop_Band), Value is 1
- *          for MS and 0 for LR stereo.
- *      - Res[Band].{L,R}:
- *          Quantisation resolution for every band (0...Stop_Band) and
- *          channels (L, R). Value is 0...17.
- *      - SCF_Index[3][Band].{L,R}:
- *          Scale factor for every band (0...Stop_Band), subframe (0...2)
- *          and channel (L, R).
- *      - Q[Band].{L,R}[36]
- *          36 subband samples for every band (0...Stop_Band) and channel (L, R).
- *      - SCF[64], Cc[18], Dc[18]:
- *          Lookup tables for Scale factor and Quantisation resolution.
- *
- *   Output is:
- *     - Y_L:  Left  channel subband signals
- *     - Y_R:  Right channel subband signals
- *
- *   These signals are used for the synthesis filter in the synth*.[ch]
- *   files to generate the PCM output signal.
- */
-
-static const float ISMatrix [32] [2] = {
-    {  1.00000000f,  0.00000000f },
-    {  0.98078528f,  0.19509032f },
-    {  0.92387953f,  0.38268343f },
-    {  0.83146961f,  0.55557023f },
-    {  0.70710678f,  0.70710678f },
-    {  0.55557023f,  0.83146961f },
-    {  0.38268343f,  0.92387953f },
-    {  0.19509032f,  0.98078528f },
-    {  0.00000000f,  1.00000000f },
-    { -0.19509032f,  0.98078528f },
-    { -0.38268343f,  0.92387953f },
-    { -0.55557023f,  0.83146961f },
-    { -0.70710678f,  0.70710678f },
-    { -0.83146961f,  0.55557023f },
-    { -0.92387953f,  0.38268343f },
-    { -0.98078528f,  0.19509032f },
-    { -1.00000000f,  0.00000000f },
-    { -0.98078528f, -0.19509032f },
-    { -0.92387953f, -0.38268343f },
-    { -0.83146961f, -0.55557023f },
-    { -0.70710678f, -0.70710678f },
-    { -0.55557023f, -0.83146961f },
-    { -0.38268343f, -0.92387953f },
-    { -0.19509032f, -0.98078528f },
-    { -0.00000000f, -1.00000000f },
-    {  0.19509032f, -0.98078528f },
-    {  0.38268343f, -0.92387953f },
-    {  0.55557023f, -0.83146961f },
-    {  0.70710678f, -0.70710678f },
-    {  0.83146961f, -0.55557023f },
-    {  0.92387953f, -0.38268343f },
-    {  0.98078528f, -0.19509032f },
-};
-
-
-void
-Requantize_MidSideStereo ( Int Stop_Band, const Bool_t* used_MS )
-{
-    Int    Band;  // 0...Stop_Band
-    Uint   k;     // 0...35
-    Float  ML;
-    Float  MR;
-    Float  mid;
-    Float  side;
-
-    for ( Band = 0; Band <= Stop_Band; Band++ ) {
-
-        if ( used_MS[Band] )  // MidSide coded: left channel contains Mid signal, right channel Side signal
-            if      ( Res[Band].R < -1 ) {
-                k  = 0;
-                ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
-                do {
-                    mid = Q[Band].L[k] * ML;
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 12);
-                ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
-                do {
-                    mid = Q[Band].L[k] * ML;
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 24);
-                ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
-                do {
-                    mid = Q[Band].L[k] * ML;
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 36);
-            }
-            else if ( Res[Band].L < -1 ) {
-                k  = 0;
-                ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
-                do {
-                    mid = Q[Band].R[k] * ML;
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 12);
-                ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
-                do {
-                    mid = Q[Band].R[k] * ML;
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 24);
-                ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
-                do {
-                    mid = Q[Band].R[k] * ML;
-                    Y_R[k][Band] = mid * ISMatrix [used_MS[Band]][0];
-                    Y_L[k][Band] = mid * ISMatrix [used_MS[Band]][1];
-                } while (++k < 36);
-            }
-            else if ( Res[Band].L )
-                if ( Res[Band].R ) {     //  M!=0, S!=0
-                    k  = 0;
-                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
-                        Y_L[k][Band] = mid + side;
-                    } while (++k < 12);
-                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
-                        Y_L[k][Band] = mid + side;
-                    } while (++k < 24);
-                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = (mid = Q[Band].L[k] * ML) - (side = Q[Band].R[k] * MR);
-                        Y_L[k][Band] = mid + side;
-                    } while (++k < 36);
-                } else {                 //  M!=0, S=0
-                    k  = 0;
-                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] =
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 12);
-                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] =
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 24);
-                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] =
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 36);
-                }
-            else
-                if ( Res[Band].R ) {     //  M==0, S!=0
-                    k  = 0;
-                    ML = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = - (
-                        Y_L[k][Band] = Q[Band].R[k] * ML );
-                    } while (++k < 12);
-                    ML = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = - (
-                        Y_L[k][Band] = Q[Band].R[k] * ML );
-                    } while (++k < 24);
-                    ML = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = - (
-                        Y_L[k][Band] = Q[Band].R[k] * ML );
-                    } while (++k < 36);
-                } else {                 //  M==0, S==0
-                    for (k=0; k<36; k++) {
-                        Y_R[k][Band] =
-                        Y_L[k][Band] = 0.f;
-                    }
-                }
-
-        else                  // Left/Right coded: left channel contains left, right the right signal
-
-            if ( Res[Band].L )
-                if ( Res[Band].R ) {     //  L!=0, R!=0
-                    k  = 0;
-                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 12);
-                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 24);
-                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
-                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 36);
-                } else {                 //  L!=0, R==0
-                    k  = 0;
-                    ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] = 0.f;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 12);
-                    ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] = 0.f;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 24);
-                    ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L];
-                    do {
-                        Y_R[k][Band] = 0.f;
-                        Y_L[k][Band] = Q[Band].L[k] * ML;
-                    } while (++k < 36);
-                }
-            else
-                if ( Res[Band].R ) {     //  L==0, R!=0
-                    k  = 0;
-                    MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = 0.f;
-                    } while (++k < 12);
-                    MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = 0.f;
-                    } while (++k < 24);
-                    MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].R];
-                    do {
-                        Y_R[k][Band] = Q[Band].R[k] * MR;
-                        Y_L[k][Band] = 0.f;
-                    } while (++k < 36);
-                } else {                 //  L==0, R==0
-                    for (k=0; k<36; k++) {
-                        Y_R[k][Band] =
-                        Y_L[k][Band] = 0.f;
-                    }
-                }
-
-    }
-    return;
-}
-
-
-/*
- *  This is the main requantisation routine for Intensity Stereo.
- *  It does the same as Requantize_MidSideStereo() but for IS.
- *
- *  Input is:
- *      - Stop_Band:
- *          the last band using MS or LR stereo
- *      - Res[Band].L:
- *          Quantisation resolution for every band (0...Stop_Band) and
- *          the left channel which is used for both channels. Value is 0...17.
- *      - SCF_Index[3][Band].{L,R}:
- *          Scale factor for every band (0...Stop_Band), subframe (0...2)
- *          and channel (L, R).
- *      - Q[Band].L[36]
- *          36 subband samples for every band (0...Stop_Band), both channels use
- *          the of the left channel
- *      - SCF[64], Cc[18], Dc[18]:
- *          Lookup tables for Scale factor and Quantisation resolution.
- *
- *   Output is:
- *     - Y_L:  Left  channel subband signals
- *     - Y_R:  Right channel subband signals
- *
- *   These signals are used for the synthesis filter in the synth*.[ch]
- *   files to generate the PCM output signal.
- */
-
-void
-Requantize_IntensityStereo ( Int Start_Band, Int Stop_Band )
-{
-    Int    Band;  // Start_Band...Stop_Band
-    Uint   k;     // 0...35
-    Float  ML;
-    Float  MR;
-
-    for ( Band = Start_Band; Band <= Stop_Band; Band++ ) {
-
-        if ( Res[Band].L ) {
-            k  = 0;
-            ML = SCF[SCF_Index[0][Band].L] * Cc[Res[Band].L] * SS05;
-            MR = SCF[SCF_Index[0][Band].R] * Cc[Res[Band].L] * SS05;
-            do {
-                Y_R[k][Band] = Q[Band].L[k] * MR;
-                Y_L[k][Band] = Q[Band].L[k] * ML;
-            } while (++k < 12);
-            ML = SCF[SCF_Index[1][Band].L] * Cc[Res[Band].L] * SS05;
-            MR = SCF[SCF_Index[1][Band].R] * Cc[Res[Band].L] * SS05;
-            do {
-                Y_R[k][Band] = Q[Band].L[k] * MR;
-                Y_L[k][Band] = Q[Band].L[k] * ML;
-            } while (++k < 24);
-            ML = SCF[SCF_Index[2][Band].L] * Cc[Res[Band].L] * SS05;
-            MR = SCF[SCF_Index[2][Band].R] * Cc[Res[Band].L] * SS05;
-            do {
-                Y_R[k][Band] = Q[Band].L[k] * MR;
-                Y_L[k][Band] = Q[Band].L[k] * ML;
-            } while (++k < 36);
-        } else {
-            for (k=0; k<36; k++) {
-                Y_R[k][Band] =
-                Y_L[k][Band] = 0.f;
-            }
-        }
-
-    }
-    return;
-}
-
-
-/*
- *  Helper function for the qsort() in Resort_HuffTable() to sort a Huffman table
- *  by its codes.
- */
-
-static int Cdecl
-cmp_fn ( const void* p1, const void* p2 )
-{
-    if ( ((const Huffman_t*)p1) -> Code < ((const Huffman_t*)p2) -> Code ) return +1;
-    if ( ((const Huffman_t*)p1) -> Code > ((const Huffman_t*)p2) -> Code ) return -1;
-    return 0;
-}
-
-
-/*
- *  This functions sorts a Huffman table by its codes. It has also two other functions:
- *
- *    - The table contains LSB aligned codes, these are first MSB aligned.
- *    - The value entry is filled by its position plus 'offset' (Note that
- *      Make_HuffTable() don't fill this item. Offset can be used to offset
- *      range for instance from 0...6 to -3...+3.
- *
- *  Note that this function generates trash if you call it twice!
- */
-
-void
-Resort_HuffTable ( Huffman_t* const Table, const size_t elements, Int offset )
-{
-    size_t  i;
-
-    for ( i = 0; i < elements; i++ ) {
-        Table[i].Value  = i + offset;
-        Table[i].Code <<= (32 - Table[i].Length);
-    }
-
-    qsort ( Table, elements, sizeof(*Table), cmp_fn );
-    return;
-}
-
-#endif /* MPP_ENCODER */
-
-
-/*
- *  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, size_t len )
-{
-    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 ( Uint8_t* LUT, size_t LUT_len, const Huffman_t* const Table, const size_t elements )
-{
-    size_t    i;
-    size_t    idx  = elements;
-    Uint32_t  dval = (Uint32_t)0x80000000L / LUT_len * 2;
-    Uint32_t  val  = dval - 1;
-
-    for ( i = 0; i < LUT_len; i++, val += dval ) {
-        while ( idx > 0  &&  val >= Table[idx-1].Code )
-            idx--;
-        *LUT++ = (Uint8_t)idx;
-    }
-
-    return;
-}
-
-
-void
-Init_FPU ( void )
-{
-    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
-}
-
-/* end of tools.c */
