Index: /libmpc/branches/r2d/mpcenc/mpcenc.c
===================================================================
--- /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 212)
+++ /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 213)
@@ -1514,4 +1514,5 @@
 	PsyModel         m;
 	mpc_encoder_t    e;
+	mpc_uint_t si_size;
 
     // initialize tables which must be initialized once and only once
@@ -1611,5 +1612,5 @@
 	writeStreamInfo ( &e, m.Max_Band, m.MS_Channelmode > 0, SamplesInWAVE,
 					   m.SampleFreq, Wave.Channels > 2 ? 2 : Wave.Channels, 0, 0, 0, 0);
-	writeBlock(&e, "SI", MPC_TRUE, 0);
+	si_size = writeBlock(&e, "SI", MPC_TRUE, 0);
 	writeEncoderInfo(&e, m.FullQual, m.PNS > 0, MPPENC_MAJOR, MPPENC_MINOR,
 					  MPPENC_IMPLEMENT, MPPENC_BUILD);
@@ -1642,6 +1643,5 @@
     if ( myfeof (Wave.fp) ) {
         stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s    \n",
-						(long double)(AllSamplesRead) / m.SampleFreq, (long double)(SamplesInWAVE) / m.SampleFreq );
-        SamplesInWAVE = AllSamplesRead;
+						(long double)(SamplesInWAVE) / m.SampleFreq, (long double)(AllSamplesRead) / m.SampleFreq);
     }
 
@@ -1712,7 +1712,6 @@
         // adapt SamplesInWAV to the real number of contained samples
         if ( myfeof (Wave.fp) ) {
-            stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s    \n",
-							(long double)(AllSamplesRead) / m.SampleFreq, (long double)(SamplesInWAVE) / m.SampleFreq );
-            SamplesInWAVE = AllSamplesRead;
+			stderr_printf ( "WAVE file has incorrect header: header: %.3f s, contents: %.3f s    \n",
+							(long double)(SamplesInWAVE) / m.SampleFreq, (long double)(AllSamplesRead) / m.SampleFreq);
         }
     }
@@ -1730,4 +1729,14 @@
 	writeBlock(&e, "ST", MPC_FALSE, 0); // write seek table block
 	writeBlock(&e, "SE", MPC_FALSE, 0); // write end of stream block
+
+	if (SamplesInWAVE != AllSamplesRead) {
+		SamplesInWAVE = AllSamplesRead;
+		fseek(e.outputFile, e.seek_ref + 4, SEEK_SET);
+		writeStreamInfo ( &e, m.Max_Band, m.MS_Channelmode > 0, SamplesInWAVE,
+						   m.SampleFreq, Wave.Channels > 2 ? 2 : Wave.Channels, 0, 0, 0, 0);
+		writeBlock(&e, "SI", MPC_TRUE, si_size);
+		fseek(e.outputFile, 0, SEEK_END);
+	}
+
     ShowProgress (&m, SamplesInWAVE, SamplesInWAVE, e.outputBits );
 
