Index: mppenc/branches/r2d/src/mppenc.c
===================================================================
--- mppenc/branches/r2d/src/mppenc.c	(revision 65)
+++ mppenc/branches/r2d/src/mppenc.c	(revision 66)
@@ -680,5 +680,5 @@
                 memcpy ( errorL [Band], errorL[Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             } else {
-                QuantizeSubband                 ( subq[Band].L, subx[Band].L, *resL, errorL [Band] );
+				QuantizeSubband                 ( subq[Band].L, subx[Band].L, *resL, errorL [Band], MAX_NS_ORDER );
                 memcpy ( errorL [Band], errorL[Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             }
@@ -691,5 +691,5 @@
                 memcpy ( errorR [Band], errorR [Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             } else {
-                QuantizeSubband                 ( subq[Band].R, subx[Band].R, *resR, errorL [Band] );
+				QuantizeSubband                 ( subq[Band].R, subx[Band].R, *resR, errorL [Band], MAX_NS_ORDER);
                 memcpy ( errorR [Band], errorR [Band] + 36, MAX_NS_ORDER * sizeof (**errorL) );
             }
@@ -1542,6 +1542,5 @@
 
 
-void
-		OverdriveReport ( mpc_encoder_t * e )
+void OverdriveReport ( mpc_encoder_t * e )
 {
 	if ( e->Overflows > 0 ) {                                                // report internal clippings
@@ -1603,4 +1602,10 @@
 	Init_ANS ();
 	Klemm    ();
+
+	e.dword = 0;
+	e.filled = 32;
+	e.Zaehler = 0;
+	e.BufferedBits = 0;
+	e.Overflows = 0;
 
     // initialize PCM-data
@@ -1734,8 +1739,9 @@
     }
 
+	e.MS_Channelmode = m.MS_Channelmode;
     e.BufferedBits     = 0;
     LastValidFrame   = (SamplesInWAVE + BLOCK - 1) / BLOCK;
     LastValidSamples = (SamplesInWAVE + BLOCK - 1) - BLOCK * LastValidFrame + 1;
-    WriteHeader_SV7 ( m.Max_Band, MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, m.SampleFreq );
+    WriteHeader_SV7 ( &e, m.Max_Band, MainQual, m.MS_Channelmode > 0, LastValidFrame, LastValidSamples, PNS > 0 ? 0x17 : 0x07, m.SampleFreq );
 
     // initialize timer
@@ -1824,8 +1830,8 @@
         OldSilence      = Silence;
         OldBufferedBits = e.BufferedBits;
-        GetBitstreamPos    ( &bitstreampos );
-        WriteBits          ( 0, 20 );                                                      // Reserve 20 bits for jump-information
-        WriteBitstream_SV7 ( m.Max_Band, Q );                                                // write SV7-Bitstream
-        WriteBitsAt        ( (Uint32_t)(e.BufferedBits - OldBufferedBits - 20), 20, bitstreampos );      // Patch 20 bits for jump-information to the right value
+        GetBitstreamPos    ( &e, &bitstreampos );
+        WriteBits          ( &e, 0, 20 );                                                      // Reserve 20 bits for jump-information
+        WriteBitstream_SV7 ( &e, m.Max_Band, Q );                                                // write SV7-Bitstream
+        WriteBitsAt        ( &e, (Uint32_t)(e.BufferedBits - OldBufferedBits - 20), 20, bitstreampos );      // Patch 20 bits for jump-information to the right value
 
         if ( (Int)(time (NULL) - T) >= 0 ) {                            // output
@@ -1865,5 +1871,5 @@
 
         if ( N == LastValidFrame - 1 ) {
-            WriteBits ( LastValidSamples, 11 );
+            WriteBits ( &e, LastValidSamples, 11 );
             // fprintf ( stderr, "\nGltige Samples im letzten Frame: %4u   \n", LastValidSamples );
         }
@@ -1875,5 +1881,5 @@
 
     // write the last incomplete word to buffer, so it's written during the next flush
-    FinishBitstream();
+    FinishBitstream(&e);
     ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.BufferedBits );
 
Index: mppenc/branches/r2d/src/mppenc.h
===================================================================
--- mppenc/branches/r2d/src/mppenc.h	(revision 65)
+++ mppenc/branches/r2d/src/mppenc.h	(revision 66)
@@ -74,12 +74,13 @@
 // extern UintMax_t     BufferedBits;              // counter for the number of written bits in the bitstream
 
-void  FlushBitstream    ( FILE* fp, const Uint32_t* buffer, size_t words32bit );
-void  UpdateHeader      ( FILE* fp, Uint32_t Frames, Uint ValidSamples );
-void  WriteBits         ( const Uint32_t input, const unsigned int bits );
-void  WriteBitsAt       ( const Uint32_t input, const unsigned int bits, const BitstreamPos pos );
-void  GetBitstreamPos   ( BitstreamPos* const pos );
+// FIXME : put in lib header
+void  FlushBitstream    ( FILE* fp, const mpc_uint32_t* buffer, size_t words32bit );
+void  UpdateHeader      ( FILE* fp, mpc_uint32_t Frames, Uint ValidSamples );
+void  WriteBits         ( mpc_encoder_t*, const mpc_uint32_t input, const unsigned int bits );
+void  WriteBitsAt       ( mpc_encoder_t*, const mpc_uint32_t input, const unsigned int bits, const BitstreamPos pos );
+void  GetBitstreamPos   ( mpc_encoder_t*, BitstreamPos* const pos );
 
 // cvd.c
-int    CVD2048 ( const float*, int* );
+int    CVD2048 ( PsyModel*, const float*, int* );
 
 
@@ -140,5 +141,5 @@
 float  ISNR_Schaetzer                  ( const float* samples, const float comp, const int res);
 float  ISNR_Schaetzer_Trans            ( const float* samples, const float comp, const int res);
-void   QuantizeSubband                 ( unsigned int* qu_output, const float* input, const int res, float* errors );
+void   QuantizeSubband                 ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder );
 void   QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR );
 
@@ -146,4 +147,5 @@
 
 
+// FIXME : no more globals
 // encode_sv7.c
 extern unsigned char  MS_Flag     [32];                  // subband-wise mid/side flag
@@ -153,8 +155,9 @@
 extern int            SCF_Index_R [32] [3];              // Scalefactor-index for Bitstream
 
+// FIXME : put in lib header
 void         Init_SV7             ( void );
-void         WriteHeader_SV7      ( const unsigned int, const unsigned int, const unsigned int, const Uint32_t TotalFrames, const unsigned int SamplesRest, const unsigned int StreamVersion, const unsigned int SampleFreq );
-void         WriteBitstream_SV7   ( const int, const SubbandQuantTyp* );
-void         FinishBitstream      ( void );
+void         WriteHeader_SV7      ( mpc_encoder_t*, const unsigned int, const unsigned int, const unsigned int, const Uint32_t TotalFrames, const unsigned int SamplesRest, const unsigned int StreamVersion, const unsigned int SampleFreq );
+void         WriteBitstream_SV7   ( mpc_encoder_t*, const int, const SubbandQuantTyp* );
+void         FinishBitstream      ( mpc_encoder_t* );
 
 
