Index: /libmpc/branches/r2d/Makefile.am
===================================================================
--- /libmpc/branches/r2d/Makefile.am	(revision 202)
+++ /libmpc/branches/r2d/Makefile.am	(revision 203)
@@ -1,3 +1,3 @@
 AUTOMAKE_OPTIONS = foreign
 SUBDIRS = common libwavformat libreplaygain libmpcpsy libmpcenc libmpcdec \
-		mpcenc mpcdec mpcgain
+			mpcenc mpcdec mpcgain mpc2sv8
Index: /libmpc/branches/r2d/configure.in
===================================================================
--- /libmpc/branches/r2d/configure.in	(revision 202)
+++ /libmpc/branches/r2d/configure.in	(revision 203)
@@ -9,3 +9,3 @@
 AM_PROG_LIBTOOL
 
-AC_OUTPUT(Makefile libmpcenc/Makefile libmpcpsy/Makefile mpcenc/Makefile libwavformat/Makefile libmpcdec/Makefile mpcdec/Makefile common/Makefile libreplaygain/Makefile mpcgain/Makefile)
+AC_OUTPUT(Makefile libmpcenc/Makefile libmpcpsy/Makefile mpcenc/Makefile libwavformat/Makefile libmpcdec/Makefile mpcdec/Makefile common/Makefile libreplaygain/Makefile mpcgain/Makefile mpc2sv8/Makefile)
Index: /libmpc/branches/r2d/include/mpc/mpc_types.h
===================================================================
--- /libmpc/branches/r2d/include/mpc/mpc_types.h	(revision 202)
+++ /libmpc/branches/r2d/include/mpc/mpc_types.h	(revision 203)
@@ -76,4 +76,9 @@
 # define mpc_int64_max 9223372036854775807ll
 
+typedef struct mpc_quantizer {
+	mpc_int32_t  L [36];
+	mpc_int32_t  R [36];
+} mpc_quantizer;
+
 /// Libmpcdec error codes
 typedef enum mpc_status {
Index: /libmpc/branches/r2d/libmpc.kdevelop
===================================================================
--- /libmpc/branches/r2d/libmpc.kdevelop	(revision 202)
+++ /libmpc/branches/r2d/libmpc.kdevelop	(revision 203)
@@ -3,5 +3,5 @@
   <general>
     <author>Nicolas Botti</author>
-    <email/>
+    <email></email>
     <version>0.1</version>
     <projectmanagement>KDevAutoProject</projectmanagement>
@@ -14,13 +14,13 @@
     <projectdirectory>.</projectdirectory>
     <absoluteprojectpath>false</absoluteprojectpath>
-    <description/>
+    <description></description>
   </general>
   <kdevautoproject>
     <general>
-      <activetarget>mpcgain/mpcgain</activetarget>
-      <useconfiguration>optimized</useconfiguration>
+      <activetarget>mpc2sv8/mpc2sv8</activetarget>
+      <useconfiguration>debug</useconfiguration>
     </general>
     <run>
-      <mainprogram/>
+      <mainprogram></mainprogram>
       <terminal>true</terminal>
       <directoryradio>executable</directoryradio>
@@ -29,7 +29,8 @@
         <mpcdec/>
         <mpcgain/>
+        <mpc2sv8>~/test1.mpc ~/test1-conv.mpc</mpc2sv8>
       </runarguments>
       <customdirectory>/</customdirectory>
-      <programargs/>
+      <programargs></programargs>
       <autocompile>true</autocompile>
       <envvars/>
@@ -187,5 +188,5 @@
     </codecompletion>
     <creategettersetter>
-      <prefixGet/>
+      <prefixGet></prefixGet>
       <prefixSet>set</prefixSet>
       <prefixVariable>m_,_</prefixVariable>
@@ -203,10 +204,10 @@
   <kdevdebugger>
     <general>
-      <programargs>/home/nico/*.mpc</programargs>
-      <gdbpath/>
+      <programargs>~/test1.mpc ~/test1-conv.mpc</programargs>
+      <gdbpath></gdbpath>
       <dbgshell>libtool</dbgshell>
-      <configGdbScript/>
-      <runShellScript/>
-      <runGdbScript/>
+      <configGdbScript></configGdbScript>
+      <runShellScript></runShellScript>
+      <runGdbScript></runGdbScript>
       <breakonloadinglibs>true</breakonloadinglibs>
       <separatetty>false</separatetty>
Index: /libmpc/branches/r2d/libmpcdec/decoder.h
===================================================================
--- /libmpc/branches/r2d/libmpcdec/decoder.h	(revision 202)
+++ /libmpc/branches/r2d/libmpcdec/decoder.h	(revision 203)
@@ -56,9 +56,4 @@
 };
 
-typedef struct mpc_quantizer {
-    mpc_int32_t  L [36];
-    mpc_int32_t  R [36];
-} mpc_quantizer;
-
 struct mpc_decoder_t {
     /// @name internal state variables
Index: /libmpc/branches/r2d/libmpcdec/mpc_decoder.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_decoder.c	(revision 202)
+++ /libmpc/branches/r2d/libmpcdec/mpc_decoder.c	(revision 203)
@@ -183,5 +183,5 @@
 
 	if (d->samples_to_skip) {
-		if (i->samples < d->samples_to_skip) {
+		if (i->samples <= d->samples_to_skip) {
 			d->samples_to_skip -= i->samples;
 			i->samples = 0;
Index: /libmpc/branches/r2d/libmpcenc/encode_sv7.c
===================================================================
--- /libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 202)
+++ /libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 203)
@@ -58,14 +58,4 @@
  */
 
-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 SV8
 void
@@ -146,5 +136,5 @@
 // formatting and writing SV8-bitstream for one frame
 void
-writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand, const SubbandQuantTyp*  Q )
+writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand)
 {
 	int n;
@@ -152,5 +142,5 @@
 
 	for( n = MaxBand; n >= 0; n--)
-		if (Res_L[n] != 0 || Res_R[n] != 0) break;
+		if (e->Res_L[n] != 0 || e->Res_R[n] != 0) break;
 
 	n++;
@@ -168,14 +158,14 @@
 
 	if (MaxBand) {
-		writeBits(e, HuffRes[0][Res_L[MaxBand - 1]].Code, HuffRes[0][Res_L[MaxBand - 1]].Length);
-		writeBits(e, HuffRes[0][Res_R[MaxBand - 1]].Code, HuffRes[0][Res_R[MaxBand - 1]].Length);
+		writeBits(e, HuffRes[0][e->Res_L[MaxBand - 1]].Code, HuffRes[0][e->Res_L[MaxBand - 1]].Length);
+		writeBits(e, HuffRes[0][e->Res_R[MaxBand - 1]].Code, HuffRes[0][e->Res_R[MaxBand - 1]].Length);
 		for ( n = MaxBand - 2; n >= 0; n--) {
-			int tmp = Res_L[n] - Res_L[n + 1];
+			int tmp = e->Res_L[n] - e->Res_L[n + 1];
 			if (tmp < 0) tmp += 17;
-			writeBits(e, HuffRes[Res_L[n + 1] > 2][tmp].Code, HuffRes[Res_L[n + 1] > 2][tmp].Length);
-
-			tmp = Res_R[n] - Res_R[n + 1];
+			writeBits(e, HuffRes[e->Res_L[n + 1] > 2][tmp].Code, HuffRes[e->Res_L[n + 1] > 2][tmp].Length);
+
+			tmp = e->Res_R[n] - e->Res_R[n + 1];
 			if (tmp < 0) tmp += 17;
-			writeBits(e, HuffRes[Res_R[n + 1] > 2][tmp].Code, HuffRes[Res_R[n + 1] > 2][tmp].Length);
+			writeBits(e, HuffRes[e->Res_R[n + 1] > 2][tmp].Code, HuffRes[e->Res_R[n + 1] > 2][tmp].Length);
 		}
 
@@ -184,7 +174,7 @@
 			int cnt = 0, tot = 0;
 			for( n = 0; n < MaxBand; n++) {
-				if ( Res_L[n] != 0 || Res_R[n] != 0 ) {
-					tmp = (tmp << 1) | MS_Flag[n];
-					cnt += MS_Flag[n];
+				if ( e->Res_L[n] != 0 || e->Res_R[n] != 0 ) {
+					tmp = (tmp << 1) | e->MS_Flag[n];
+					cnt += e->MS_Flag[n];
 					tot++;
 				}
@@ -200,5 +190,5 @@
 	if (e->framesInBlock == 0){
 		for( n = 0; n < 32; n++)
-			DSCF_RLL_L[n] = DSCF_RLL_R[n] = 1; // new block -> force key frame
+			e->DSCF_Flag_L[n] = e->DSCF_Flag_R[n] = 1; // new block -> force key frame
 	}
 
@@ -207,10 +197,10 @@
 	for ( n = 0; n < MaxBand; n++ ) {
 		int tmp = 0, cnt = -1;
-		if (Res_L[n]) {
-			tmp = (SCF_Index_L[n][1] == SCF_Index_L[n][0]) * 2 + (SCF_Index_L[n][2] == SCF_Index_L[n][1]);
+		if (e->Res_L[n]) {
+			tmp = (e->SCF_Index_L[n][1] == e->SCF_Index_L[n][0]) * 2 + (e->SCF_Index_L[n][2] == e->SCF_Index_L[n][1]);
 			cnt++;
 		}
-		if (Res_R[n]) {
-			tmp = (tmp << 2) | ((SCF_Index_R[n][1] == SCF_Index_R[n][0]) * 2 + (SCF_Index_R[n][2] == SCF_Index_R[n][1]));
+		if (e->Res_R[n]) {
+			tmp = (tmp << 2) | ((e->SCF_Index_R[n][1] == e->SCF_Index_R[n][0]) * 2 + (e->SCF_Index_R[n][2] == e->SCF_Index_R[n][1]));
 			cnt++;
 		}
@@ -222,11 +212,11 @@
 
 	for ( n = 0; n < MaxBand; n++ ) {
-		if ( Res_L[n] ) {
+		if ( e->Res_L[n] ) {
 			int m;
-			if (DSCF_RLL_L[n] == 1) {
-				writeBits(e, SCF_Index_L[n][0] + 6, 7);
-				DSCF_RLL_L[n] = 0;
+			if (e->DSCF_Flag_L[n] == 1) {
+				writeBits(e, e->SCF_Index_L[n][0] + 6, 7);
+				e->DSCF_Flag_L[n] = 0;
 			} else {
-				unsigned int tmp = (SCF_Index_L[n][0] - SCF_Last_L[n] + 31) & 127;
+				unsigned int tmp = (e->SCF_Index_L[n][0] - e->SCF_Last_L[n] + 31) & 127;
 				if (tmp < 64)
 					writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length);
@@ -237,6 +227,6 @@
 			}
 			for( m = 0; m < 2; m++){
-				if (SCF_Index_L[n][m+1] != SCF_Index_L[n][m]) {
-					unsigned int tmp = (SCF_Index_L[n][m+1] - SCF_Index_L[n][m] + 31) & 127;
+				if (e->SCF_Index_L[n][m+1] != e->SCF_Index_L[n][m]) {
+					unsigned int tmp = (e->SCF_Index_L[n][m+1] - e->SCF_Index_L[n][m] + 31) & 127;
 					if (tmp < 64)
 						writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length);
@@ -247,13 +237,13 @@
 				}
 			}
-			SCF_Last_L[n] = SCF_Index_L[n][2];
-		}
-		if ( Res_R[n] ) {
+			e->SCF_Last_L[n] = e->SCF_Index_L[n][2];
+		}
+		if ( e->Res_R[n] ) {
 			int m;
-			if (DSCF_RLL_R[n] == 1) {
-				writeBits(e, SCF_Index_R[n][0] + 6, 7);
-				DSCF_RLL_R[n] = 0;
+			if (e->DSCF_Flag_R[n] == 1) {
+				writeBits(e, e->SCF_Index_R[n][0] + 6, 7);
+				e->DSCF_Flag_R[n] = 0;
 			} else {
-				unsigned int tmp = (SCF_Index_R[n][0] - SCF_Last_R[n] + 31) & 127;
+				unsigned int tmp = (e->SCF_Index_R[n][0] - e->SCF_Last_R[n] + 31) & 127;
 				if (tmp < 64)
 					writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length);
@@ -264,6 +254,6 @@
 			}
 			for( m = 0; m < 2; m++){
-				if (SCF_Index_R[n][m+1] != SCF_Index_R[n][m]) {
-					unsigned int tmp = (SCF_Index_R[n][m+1] - SCF_Index_R[n][m] + 31) & 127;
+				if (e->SCF_Index_R[n][m+1] != e->SCF_Index_R[n][m]) {
+					unsigned int tmp = (e->SCF_Index_R[n][m+1] - e->SCF_Index_R[n][m] + 31) & 127;
 					if (tmp < 64)
 						writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length);
@@ -274,5 +264,5 @@
 				}
 			}
-			SCF_Last_R[n] = SCF_Index_R[n][2];
+			e->SCF_Last_R[n] = e->SCF_Index_R[n][2];
 		}
 	}
@@ -280,6 +270,6 @@
 	/*********************************** Samples *********************************/
 	for ( n = 0; n < MaxBand; n++ ) {
-		int Res = Res_L[n];
-		const unsigned int * q = Q[n].L;
+		int Res = e->Res_L[n];
+		const unsigned int * q = e->Q[n].L;
 		static const unsigned int thres[] = {0, 0, 3, 7, 9, 1, 3, 4, 8};
 		static const int HuffQ2_var[5*5*5] =
@@ -357,6 +347,6 @@
 			}
 
-			Res = Res_R[n];
-		} while (q == Q[n].L && (q = Q[n].R));
+			Res = e->Res_R[n];
+		} while (q == e->Q[n].L && (q = e->Q[n].R));
 	}
 
Index: /libmpc/branches/r2d/libmpcenc/libmpcenc.h
===================================================================
--- /libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 202)
+++ /libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 203)
@@ -36,9 +36,4 @@
 
 typedef struct {
-	unsigned int  L [36];
-	unsigned int  R [36];
-} SubbandQuantTyp;
-
-typedef struct {
 	mpc_uint16_t	Code;        // >= 14 bit
 	mpc_uint16_t	Length;      // >=  4 bit
@@ -63,7 +58,38 @@
 	FILE * outputFile; // ouput file
 
-	unsigned int  MS_Channelmode;
-	unsigned int  Overflows; //       = 0;      // number of internal (filterbank) clippings
-	unsigned int MaxBand; /// number of non zero bands in last frame
+	mpc_uint32_t MS_Channelmode;
+	mpc_uint32_t Overflows; //       = 0;      // number of internal (filterbank) clippings
+	mpc_uint32_t MaxBand; /// number of non zero bands in last frame
+
+ 	mpc_int32_t   SCF_Index_L [32] [3];
+	mpc_int32_t   SCF_Index_R [32] [3];       // holds scalefactor-indices
+	mpc_int32_t   SCF_Last_L  [32];
+	mpc_int32_t   SCF_Last_R  [32];           // Last coded SCF value
+	mpc_quantizer Q [32];                     // holds quantized samples
+	mpc_int32_t   Res_L [32];
+	mpc_int32_t   Res_R [32];                 // holds the chosen quantizer for each subband
+	mpc_bool_t    DSCF_Flag_L [32];
+	mpc_bool_t    DSCF_Flag_R [32];           // differential SCF used?
+	mpc_bool_t    MS_Flag[32];                // MS used?
  } mpc_encoder_t;
 
+ void         Init_SV8             ( mpc_encoder_t* );
+ void writeStreamInfo ( mpc_encoder_t*e,
+						const unsigned int  MaxBand,
+						const unsigned int  MS_on,
+						const unsigned int  SamplesCount,
+						const unsigned int  SampleFreq,
+						const unsigned int  ChannelCount);
+ void writeEncoderInfo ( mpc_encoder_t * e,
+						 const float profile,
+						 const int PNS_on,
+						 const int version_major,
+						 const int version_minor,
+						 const int version_implement,
+						 const int version_build );
+ void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC);
+ void writeMagic (mpc_encoder_t * e);
+ void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits );
+ void writeSeekTable (mpc_encoder_t * e);
+ void writeBitstream_SV8 ( mpc_encoder_t*, int);
+
Index: /libmpc/branches/r2d/mpc2sv8/Makefile.am
===================================================================
--- /libmpc/branches/r2d/mpc2sv8/Makefile.am	(revision 203)
+++ /libmpc/branches/r2d/mpc2sv8/Makefile.am	(revision 203)
@@ -0,0 +1,6 @@
+INCLUDES = -I$(top_srcdir)/include
+METASOURCES = AUTO
+bin_PROGRAMS = mpc2sv8
+mpc2sv8_SOURCES = mpc2sv8.c
+mpc2sv8_LDADD = $(top_builddir)/libmpcenc/libmpcenc.a \
+	$(top_builddir)/libmpcdec/libmpcdec.la -lm
Index: /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c
===================================================================
--- /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 203)
+++ /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 203)
@@ -0,0 +1,146 @@
+/*
+  Copyright (c) 2007, 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.
+*/
+#include <stdio.h>
+#include <mpc/mpcdec.h>
+
+#include "../libmpcdec/decoder.h"
+#include "../libmpcdec/internal.h"
+#include "../libmpcenc/libmpcenc.h"
+
+static void datacpy(mpc_decoder * d, mpc_encoder_t * e)
+{
+	static const int  offset[] = { 0, 1, 2, 3, 4, 7, 15, 31, 63, 127, 255, 511,
+		1023, 2047, 4095, 8191, 16383, 32767 };
+	int i, j;
+
+	memcpy(e->SCF_Index_L, d->SCF_Index_L, sizeof(e->SCF_Index_L));
+	memcpy(e->SCF_Index_R, d->SCF_Index_R, sizeof(e->SCF_Index_R));
+	memcpy(e->Res_L, d->Res_L, sizeof(e->Res_L));
+	memcpy(e->Res_R, d->Res_R, sizeof(e->Res_R));
+	memcpy(e->MS_Flag, d->MS_Flag, sizeof(e->MS_Flag));
+
+	for( i = 0; i < d->max_band; i++){
+		mpc_int32_t * q_d = d->Q[i].L, * q_e = e->Q[i].L, Res = d->Res_L[i];
+
+		if (Res != 0)
+			for( j = 0; j < 36; j++)
+				q_e[j] = q_d[j] + offset[Res];
+
+		q_d = d->Q[i].R, q_e = e->Q[i].R, Res = d->Res_R[i];
+
+		if (Res != 0)
+			for( j = 0; j < 36; j++)
+				q_e[j] = q_d[j] + offset[Res];
+	}
+}
+
+static void
+usage(const char *exename)
+{
+    printf("Usage: %s <infile.mpc> <outfile.mpc>\n", exename);
+}
+
+int
+main(int argc, char **argv)
+{
+    mpc_reader reader;
+	mpc_demux* demux;
+	mpc_streaminfo si;
+	mpc_status err;
+	mpc_encoder_t e;
+
+    printf("mpc2sv8 - musepack (mpc) sv7 to sv8 converter\n");
+    if(3 != argc) {
+        usage(argv[0]);
+        return 0;
+    }
+
+    err = mpc_reader_init_stdio(&reader, argv[1]);
+    if(err < 0) return !MPC_STATUS_OK;
+
+    demux = mpc_demux_init(&reader);
+    if(!demux) return !MPC_STATUS_OK;
+    mpc_demux_get_info(demux,  &si);
+
+	Init_SV8 (&e);
+	e.outputFile = fopen( argv[2], "w+b" );
+	e.MS_Channelmode = si.ms;
+
+	// copie dÃ©but fichier
+
+	// conversion stream
+	e.seek_ref = ftell(e.outputFile);
+	writeMagic(&e);
+	writeStreamInfo( &e, si.max_band, si.ms > 0, si.samples, si.sample_freq,
+					  si.channels); // FIXME : convert replay gain info
+	writeBlock(&e, "SI", MPC_TRUE);
+	writeEncoderInfo(&e, si.profile, si.pns, 0, 0, 0, 0); // FIXME : convert encoder information
+	writeBlock(&e, "EI", MPC_FALSE);
+	e.seek_ptr = ftell(e.outputFile);
+	writeBits (&e, 0, 8);
+	writeBits (&e, 0, 32); // jump 40 bits for seek table pointer
+	writeBlock(&e, "SP", MPC_FALSE); // reserve space for seek pointer
+	while(MPC_TRUE)
+	{
+		mpc_frame_info frame;
+
+		demux->d->samples_to_skip = MPC_FRAME_LENGTH + MPC_DECODER_SYNTH_DELAY;
+		frame.buffer = 0;
+		mpc_demux_decode(demux, &frame);
+
+		if(frame.bits == -1) break;
+
+		datacpy(demux->d, &e);
+		writeBitstream_SV8 ( &e, si.max_band); // write SV8-Bitstream
+	}
+    // write the last incomplete block
+	if ((e.block_cnt & ((1 << e.seek_pwr) - 1)) == 0) {
+		e.seek_table[e.seek_pos] = ftell(e.outputFile);
+		e.seek_pos++;
+	}
+	writeBlock(&e, "AD", MPC_FALSE);
+	writeSeekTable(&e);
+	writeBlock(&e, "ST", MPC_FALSE); // write seek table block
+	writeBlock(&e, "SE", MPC_FALSE); // write end of stream block
+	// FIXME : put correct stream length in SI block
+
+	// copie fin fichier
+
+
+	fclose ( e.outputFile );
+    mpc_demux_exit(demux);
+    mpc_reader_exit_stdio(&reader);
+
+    return 0;
+}
Index: /libmpc/branches/r2d/mpcenc/mpcenc.c
===================================================================
--- /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 202)
+++ /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 203)
@@ -534,6 +534,6 @@
 
         // Where is scf{R,L} [0...2] initialized ???
-        scfL = SCF_Index_L [Band];
-        scfR = SCF_Index_R [Band];
+        scfL = e->SCF_Index_L [Band];
+		scfR = e->SCF_Index_R [Band];
         if (tmp_L [0] > 0.) scfL [0] = IFLOORF (-12.6f * LOG10 (tmp_L [0]) + 57.8945021823f );
         if (tmp_L [1] > 0.) scfL [1] = IFLOORF (-12.6f * LOG10 (tmp_L [1]) + 57.8945021823f );
@@ -669,5 +669,5 @@
                 const int*              resR,
                 const SubbandFloatTyp*  subx,
-                SubbandQuantTyp*        subq )
+				mpc_quantizer*          subq )
 {
     static float  errorL [32] [36 + MAX_NS_ORDER];
@@ -1500,5 +1500,4 @@
     PCMDataTyp       Main;                      // contains PCM data for 1600 samples
     SubbandFloatTyp  X [32];                    // Subbandsamples as float()
-    SubbandQuantTyp  Q [32];                    // Subband samples after quantization
     wave_t           Wave;                      // contains WAV-files arguments
     mpc_uint64_t        AllSamplesRead   =    0;   // overall read Samples per channel
@@ -1518,6 +1517,6 @@
     // initialize tables which must be initialized once and only once
 
-	m.SCF_Index_L = (int*) SCF_Index_L;
-	m.SCF_Index_R = (int*) SCF_Index_R;
+	m.SCF_Index_L = (int*) e.SCF_Index_L;
+	m.SCF_Index_R = (int*) e.SCF_Index_R;
 
 	Init_Psychoakustik (&m);
@@ -1672,6 +1671,6 @@
         // you only get null samples at the output of the filterbank when the last frame contains zeroes
 
-        memset ( Res_L, 0, sizeof Res_L );
-        memset ( Res_R, 0, sizeof Res_R );
+		memset ( e.Res_L, 0, sizeof e.Res_L );
+		memset ( e.Res_R, 0, sizeof e.Res_R );
 
         if ( !Silence  ||  !OldSilence ) {
@@ -1681,19 +1680,19 @@
 				RaiseSMR (&m, m.Max_Band, &SMR );                            // Minimum-operation on SBRs (full bandwidth)
 			if ( m.MS_Channelmode > 0 )
-				MS_LR_Entscheidung ( m.Max_Band, MS_Flag, &SMR, X );      // Selection of M/S- or L/R-Coding
+				MS_LR_Entscheidung ( m.Max_Band, e.MS_Flag, &SMR, X );      // Selection of M/S- or L/R-Coding
 			SCF_Extraktion (&m, &e, m.Max_Band, X );                             // Extraction of the scalefactors and normalization of the subband samples
             TransientenCalc ( Transient, TransientL, TransientR );
 			if ( m.NS_Order > 0 ) {
-				NS_Analyse (&m, m.Max_Band, MS_Flag, SMR, Transient );                  // calculate possible ANS-Filter and the expected gain
+				NS_Analyse (&m, m.Max_Band, e.MS_Flag, SMR, Transient );                  // calculate possible ANS-Filter and the expected gain
             }
 
-            Allocate ( m.Max_Band, Res_L, X[0].L, SCF_Index_L[0], m.SNR_comp_L, SMR.L, Power_L, Transient , m.PNS );   // allocate bits for left + right channel
-			Allocate ( m.Max_Band, Res_R, X[0].R, SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient , m.PNS );
-
-			Quantisierung (&m, m.Max_Band, Res_L, Res_R, X, Q );             // quantize samples
+			Allocate ( m.Max_Band, e.Res_L, X[0].L, e.SCF_Index_L[0], m.SNR_comp_L, SMR.L, Power_L, Transient , m.PNS );   // allocate bits for left + right channel
+			Allocate ( m.Max_Band, e.Res_R, X[0].R, e.SCF_Index_R[0], m.SNR_comp_R, SMR.R, Power_R, Transient , m.PNS );
+
+			Quantisierung (&m, m.Max_Band, e.Res_L, e.Res_R, X, e.Q );             // quantize samples
         }
 
         OldSilence      = Silence;
-        writeBitstream_SV8 ( &e, m.Max_Band, Q ); // write SV8-Bitstream
+        writeBitstream_SV8 ( &e, m.Max_Band); // write SV8-Bitstream
 
         if ( (int)(time (NULL) - T) >= 0 ) {                            // output
Index: /libmpc/branches/r2d/mpcenc/mpcenc.h
===================================================================
--- /libmpc/branches/r2d/mpcenc/mpcenc.h	(revision 202)
+++ /libmpc/branches/r2d/mpcenc/mpcenc.h	(revision 203)
@@ -255,34 +255,4 @@
 void   NoiseInjectionComp ( void );
 
-
-// FIXME : no more globals
-// encode_sv7.c
-extern unsigned char  MS_Flag     [32];                  // subband-wise mid/side flag
-extern int            Res_L       [32];
-extern int            Res_R       [32];                  // resolution steps of the subbands
-extern int            SCF_Index_L [32] [3];
-extern int            SCF_Index_R [32] [3];              // Scalefactor-index for Bitstream
-
-// FIXME : put in lib header
-void         Init_SV8             ( mpc_encoder_t* );
-void writeStreamInfo ( mpc_encoder_t*e,
-					   const unsigned int  MaxBand,
-					   const unsigned int  MS_on,
-					   const unsigned int  SamplesCount,
-					   const unsigned int  SampleFreq,
-					   const unsigned int  ChannelCount);
-void writeEncoderInfo ( mpc_encoder_t * e,
-						const float profile,
-						const int PNS_on,
-						const int version_major,
-						const int version_minor,
-						const int version_implement,
-						const int version_build );
-void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC);
-void writeMagic (mpc_encoder_t * e);
-void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits );
-void writeSeekTable (mpc_encoder_t * e);
-void writeBitstream_SV8 ( mpc_encoder_t*, int, const SubbandQuantTyp*);
-
 // keyboard.c
 int    WaitKey      ( void );
