Index: libmpc/branches/r2d/mpc2sv8/mpc2sv8.c
===================================================================
--- libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 203)
+++ libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 204)
@@ -80,4 +80,5 @@
 	mpc_status err;
 	mpc_encoder_t e;
+	mpc_uint_t si_size;
 
     printf("mpc2sv8 - musepack (mpc) sv7 to sv8 converter\n");
@@ -105,11 +106,11 @@
 	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);
+	si_size = writeBlock(&e, "SI", MPC_TRUE, 0);
 	writeEncoderInfo(&e, si.profile, si.pns, 0, 0, 0, 0); // FIXME : convert encoder information
-	writeBlock(&e, "EI", MPC_FALSE);
+	writeBlock(&e, "EI", MPC_FALSE, 0);
 	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
+	writeBlock(&e, "SP", MPC_FALSE, 0); // reserve space for seek pointer
 	while(MPC_TRUE)
 	{
@@ -130,9 +131,15 @@
 		e.seek_pos++;
 	}
-	writeBlock(&e, "AD", MPC_FALSE);
+	writeBlock(&e, "AD", MPC_FALSE, 0);
 	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
+	writeBlock(&e, "ST", MPC_FALSE, 0); // write seek table block
+	writeBlock(&e, "SE", MPC_FALSE, 0); // write end of stream block
+	if (demux->d->samples != si.samples) {
+		fseek(e.outputFile, e.seek_ref + 4, SEEK_SET);
+		writeStreamInfo( &e, si.max_band, si.ms > 0, demux->d->samples,
+						  si.sample_freq, si.channels);
+		writeBlock(&e, "SI", MPC_TRUE, si_size);
+		fseek(e.outputFile, 0, SEEK_END);
+	}
 
 	// copie fin fichier
