Index: /libmpc/branches/r2d/include/mpc/streaminfo.h
===================================================================
--- /libmpc/branches/r2d/include/mpc/streaminfo.h	(revision 219)
+++ /libmpc/branches/r2d/include/mpc/streaminfo.h	(revision 220)
@@ -79,4 +79,6 @@
     mpc_uint32_t         is_true_gapless;    ///< True gapless? (0: no, 1: yes)
 	mpc_uint64_t         samples;            ///< Number of samples in the stream
+	mpc_uint64_t         beg_silence;        ///< Number of samples that must not be played at the beginning of the stream
+	mpc_uint64_t         end_silence;        ///< Number of samples that must not be played at the end of the stream
     //@}
 
Index: /libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 219)
+++ /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 220)
@@ -298,12 +298,14 @@
 		mpc_demux_fill(d, 11, 0); // max header block size
 		size = mpc_bits_get_block(&d->bits_reader, &b);
-		while( memcmp(b.key, "AD", 2) != 0 ){ // scan all blocks until audio
+		while( memcmp(b.key, "AP", 2) != 0 ){ // scan all blocks until audio
 			mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0);
-			if (memcmp(b.key, "SI", 2) == 0){
+			if (memcmp(b.key, "SH", 2) == 0){
 				int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size);
 				if (ret != MPC_STATUS_OK) return ret;
-			} else if (memcmp(b.key, "EI", 2) == 0)
+			} else if (memcmp(b.key, "RG", 2) == 0)
+				streaminfo_gain(&d->si, &d->bits_reader);
+			else if (memcmp(b.key, "EI", 2) == 0)
 				streaminfo_encoder_info(&d->si, &d->bits_reader);
-			else if (memcmp(b.key, "SP", 2) == 0)
+			else if (memcmp(b.key, "SO", 2) == 0)
 				mpc_demux_SP(d, size, (mpc_uint32_t) b.size);
 			else if (memcmp(b.key, "ST", 2) == 0)
@@ -366,5 +368,5 @@
 			mpc_demux_fill(d, 11, 0); // max header block size
 			mpc_bits_get_block(&d->bits_reader, &b);
-			while( memcmp(b.key, "AD", 2) != 0 ) { // scan all blocks until audio
+			while( memcmp(b.key, "AP", 2) != 0 ) { // scan all blocks until audio
 				if (memcmp(b.key, "SE", 2) == 0) { // end block
 					i->bits = -1;
@@ -436,5 +438,5 @@
 		size = mpc_bits_get_block(&d->bits_reader, &b);
 		while(i < fwd) {
-			if (memcmp(b.key, "AD", 2) == 0) {
+			if (memcmp(b.key, "AP", 2) == 0) {
 				if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) {
 					d->seek_table[d->seek_table_size] = (mpc_uint32_t) mpc_demux_pos(d) - 8 * size;
Index: /libmpc/branches/r2d/libmpcdec/streaminfo.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 219)
+++ /libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 220)
@@ -84,6 +84,5 @@
 		int major = si->encoder_version >> 24;
 		int minor = (si->encoder_version >> 16) & 0xFF;
-		int impl = (si->encoder_version >> 8) & 0xFF;
-		int build = si->encoder_version & 0xFF;
+		int build = (si->encoder_version >> 8) & 0xFF;
 		char * tmp = "--Stable--";
 
@@ -91,6 +90,5 @@
 			tmp = "--Unstable--";
 
-		sprintf(si->encoder, "%s %u.%u.%u build %u", tmp, major, minor, impl,
-				build);
+		sprintf(si->encoder, "%s %u.%u build %u", tmp, major, minor, build);
 	}
 }
@@ -164,5 +162,7 @@
 	mpc_bits_reader r = *r_in;
 
-	mpc_bits_read(&r, 8); // gain version
+	int version = mpc_bits_read(&r, 8); // gain version
+	if (version != 1) // we only know ver 1
+		return;
 	si->gain_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
 	si->peak_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
@@ -177,6 +177,5 @@
 {
 	mpc_uint32_t CRC;
-	mpc_uint64_t info_len;
-	mpc_bits_reader r = *r_in, r_gain;
+	mpc_bits_reader r = *r_in;
 
 	CRC = mpc_bits_read(&r, 32);
@@ -184,8 +183,4 @@
 		return MPC_STATUS_FILE;
 
-	r_gain = r;
-	mpc_bits_get_size(&r, &info_len);
-	r_gain.buff += info_len;
-
 	si->stream_version = mpc_bits_read(&r, 8);
 	if (si->stream_version != 8)
@@ -193,8 +188,11 @@
 
 	mpc_bits_get_size(&r, &si->samples);
+	mpc_bits_get_size(&r, &si->beg_silence);
+	mpc_bits_get_size(&r, &si->end_silence);
+
 	si->is_true_gapless = 1;
 	si->sample_freq = samplefreqs[mpc_bits_read(&r, 3)];
+	si->max_band = mpc_bits_read(&r, 5) + 1;
 	si->channels = mpc_bits_read(&r, 4) + 1;
-	si->max_band = mpc_bits_read(&r, 5) + 1;
 	si->ms = mpc_bits_read(&r, 1);
 	si->block_pwr = mpc_bits_read(&r, 3) * 2;
@@ -206,6 +204,4 @@
 				*  si->sample_freq / si->samples;
 
-	streaminfo_gain(si, &r_gain);
-
 	return MPC_STATUS_OK;
 }
@@ -219,8 +215,8 @@
 	si->profile_name       = mpc_get_version_string(si->profile);
 	si->pns                = mpc_bits_read(&r, 1);
-	si->encoder_version = mpc_bits_read(&r, 4) << 24; // major
+	si->encoder_version = mpc_bits_read(&r, 8) << 24; // major
 	si->encoder_version |= mpc_bits_read(&r, 8) << 16; // minor
-	si->encoder_version |= mpc_bits_read(&r, 4) << 8; // implementation
-	si->encoder_version |= mpc_bits_read(&r, 8); // build
+	si->encoder_version |= mpc_bits_read(&r, 8) << 8; // build
+
 
 	mpc_get_encoder_string(si);
Index: /libmpc/branches/r2d/libmpcenc/encode_sv7.c
===================================================================
--- /libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 219)
+++ /libmpc/branches/r2d/libmpcenc/encode_sv7.c	(revision 220)
@@ -60,9 +60,9 @@
 
 // writes replay gain info
-static void writeGainInfo ( mpc_encoder_t * e,
-							unsigned short t_gain,
-							unsigned short t_peak,
-							unsigned short a_gain,
-							unsigned short a_peak)
+void writeGainInfo ( mpc_encoder_t * e,
+					 unsigned short t_gain,
+					 unsigned short t_peak,
+					 unsigned short a_gain,
+					 unsigned short a_peak)
 {
 	writeBits ( e, 1,  8 ); // version
@@ -80,15 +80,8 @@
                   const unsigned int  SamplesCount,
                   const unsigned int  SampleFreq,
-				  const unsigned int  ChannelCount,
-				  unsigned short t_gain,
-				  unsigned short t_peak,
-				  unsigned short a_gain,
-				  unsigned short a_peak)
+				  const unsigned int  ChannelCount)
 {
 	unsigned char tmp[10];
-	int i, len = encodeSize(SamplesCount, (char *)tmp, MPC_FALSE);
-
-	len = encodeSize(len + 3, (char *)tmp, MPC_TRUE);
-	writeBits ( e, tmp[0]  , 8 );
+	int i, len;
 
     writeBits ( e, 8,  8 );    // StreamVersion
@@ -96,5 +89,7 @@
 	len = encodeSize(SamplesCount, (char *)tmp, MPC_FALSE);
 	for( i = 0; i < len; i++) // nb of samples
-		writeBits ( e, tmp[i]  , 8 );
+		writeBits ( e, tmp[i], 8 );
+	writeBits ( e, 0, 8 ); // nb of samples to skip at beginning
+	writeBits ( e, 0, 8 ); // nb of samples to skip at end
 
 	switch ( SampleFreq ) {
@@ -107,10 +102,8 @@
 	}
 
+	writeBits ( e, MaxBand - 1  ,  5 );    // Bandwidth
 	writeBits ( e, ChannelCount - 1  ,  4 );    // Channels
-	writeBits ( e, MaxBand - 1  ,  5 );    // Bandwidth
 	writeBits ( e, MS_on        ,  1 );    // MS-Coding Flag
 	writeBits ( e, FRAMES_PER_BLOCK_PWR >> 1,  3 );    // frames per block (log4 unit)
-
-	writeGainInfo(e, t_gain, t_peak, a_gain, a_peak);
 }
 
@@ -121,12 +114,10 @@
 						const int version_major,
 						const int version_minor,
-						const int version_implement,
 						const int version_build )
 {
 	writeBits ( e, (mpc_uint32_t)(profile * 8 + .5),  7 );
 	writeBits ( e, PNS_on,  1 );
-	writeBits ( e, version_major,  4 );
+	writeBits ( e, version_major,  8 );
 	writeBits ( e, version_minor,  8 );
-	writeBits ( e, version_implement,  4 );
 	writeBits ( e, version_build,  8 );
 }
@@ -269,5 +260,5 @@
 	for ( n = 0; n < MaxBand; n++ ) {
 		int Res = e->Res_L[n];
-		const unsigned int * q = e->Q[n].L;
+		const 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] =
@@ -356,5 +347,5 @@
 		}
 		e->block_cnt++;
-		writeBlock(e, "AD", MPC_FALSE, 0);
+		writeBlock(e, "AP", MPC_FALSE, 0);
 	}
 }
Index: /libmpc/branches/r2d/libmpcenc/libmpcenc.h
===================================================================
--- /libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 219)
+++ /libmpc/branches/r2d/libmpcenc/libmpcenc.h	(revision 220)
@@ -80,9 +80,10 @@
 						const unsigned int  SamplesCount,
 						const unsigned int  SampleFreq,
-						const unsigned int  ChannelCount,
-						unsigned short t_gain,
-						unsigned short t_peak,
-						unsigned short a_gain,
-						unsigned short a_peak);
+						const unsigned int  ChannelCount);
+ void writeGainInfo ( mpc_encoder_t * e,
+					  unsigned short t_gain,
+					  unsigned short t_peak,
+					  unsigned short a_gain,
+					  unsigned short a_peak);
  void writeEncoderInfo ( mpc_encoder_t * e,
 						 const float profile,
@@ -90,5 +91,4 @@
 						 const int version_major,
 						 const int version_minor,
-						 const int version_implement,
 						 const int version_build );
  mpc_uint32_t writeBlock ( mpc_encoder_t *, const char *, const mpc_bool_t, mpc_uint32_t);
Index: /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c
===================================================================
--- /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 219)
+++ /libmpc/branches/r2d/mpc2sv8/mpc2sv8.c	(revision 220)
@@ -123,14 +123,15 @@
 	writeMagic(&e);
 	writeStreamInfo( &e, si.max_band, si.ms > 0, si.samples, si.sample_freq,
-					  si.channels, si.gain_title, si.gain_album, si.peak_title,
-					  si.peak_album);
-	si_size = writeBlock(&e, "SI", MPC_TRUE, 0);
+					  si.channels);
+	si_size = writeBlock(&e, "SH", MPC_TRUE, 0);
+	writeGainInfo(&e, si.gain_title, si.gain_album, si.peak_title, si.peak_album);
+	si_size = writeBlock(&e, "RG", MPC_FALSE, 0);
 	writeEncoderInfo(&e, si.profile, si.pns, si.encoder_version / 100,
-					  si.encoder_version % 100, 0, 0);
+					  si.encoder_version % 100, 0);
 	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, 0); // reserve space for seek pointer
+	writeBlock(&e, "SO", MPC_FALSE, 0); // reserve space for seek offset
 	while(MPC_TRUE)
 	{
@@ -152,5 +153,5 @@
 		}
 		e.block_cnt++;
-		writeBlock(&e, "AD", MPC_FALSE, 0);
+		writeBlock(&e, "AP", MPC_FALSE, 0);
 	}
 	writeSeekTable(&e);
@@ -160,7 +161,6 @@
 		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, si.gain_title,
-						  si.gain_album, si.peak_title, si.peak_album);
-		writeBlock(&e, "SI", MPC_TRUE, si_size);
+						  si.sample_freq, si.channels);
+		writeBlock(&e, "SH", MPC_TRUE, si_size);
 		fseek(e.outputFile, 0, SEEK_END);
 	}
Index: /libmpc/branches/r2d/mpcenc/config.h
===================================================================
--- /libmpc/branches/r2d/mpcenc/config.h	(revision 219)
+++ /libmpc/branches/r2d/mpcenc/config.h	(revision 220)
@@ -31,14 +31,7 @@
 /* parsed values from file "version" */
 
-#ifndef MPPDEC_VERSION
-# define MPPDEC_VERSION   "1.15v"
-#endif
-
-#define MPPDEC_BUILD  "--Alpha--"
-
-#define MPPENC_MAJOR 1
-#define MPPENC_MINOR 17
-#define MPPENC_IMPLEMENT 0
-#define MPPENC_BUILD 0
+#define MPCENC_MAJOR 1
+#define MPCENC_MINOR 17
+#define MPCENC_BUILD 0
 
 /* end of config.h */
Index: /libmpc/branches/r2d/mpcenc/mpcenc.c
===================================================================
--- /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 219)
+++ /libmpc/branches/r2d/mpcenc/mpcenc.c	(revision 220)
@@ -1611,13 +1611,15 @@
 	writeMagic(&e);
 	writeStreamInfo ( &e, m.Max_Band, m.MS_Channelmode > 0, SamplesInWAVE,
-					   m.SampleFreq, Wave.Channels > 2 ? 2 : Wave.Channels, 0, 0, 0, 0);
-	si_size = writeBlock(&e, "SI", MPC_TRUE, 0);
-	writeEncoderInfo(&e, m.FullQual, m.PNS > 0, MPPENC_MAJOR, MPPENC_MINOR,
-					  MPPENC_IMPLEMENT, MPPENC_BUILD);
+					   m.SampleFreq, Wave.Channels > 2 ? 2 : Wave.Channels);
+	si_size = writeBlock(&e, "SH", MPC_TRUE, 0);
+	writeGainInfo ( &e, 0, 0, 0, 0);
+	writeBlock(&e, "RG", MPC_FALSE, 0);
+	writeEncoderInfo(&e, m.FullQual, m.PNS > 0, MPCENC_MAJOR, MPCENC_MINOR,
+					  MPCENC_BUILD);
 	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, 0); // reserve space for seek pointer
+	writeBlock(&e, "SO", MPC_FALSE, 0); // reserve space for seek offset
 
 
@@ -1724,5 +1726,5 @@
 		}
 		e.block_cnt++;
-		writeBlock(&e, "AD", MPC_FALSE, 0);
+		writeBlock(&e, "AP", MPC_FALSE, 0);
 	}
 	writeSeekTable(&e);
@@ -1734,6 +1736,6 @@
 		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);
+						   m.SampleFreq, Wave.Channels > 2 ? 2 : Wave.Channels);
+		writeBlock(&e, "SH", MPC_TRUE, si_size);
 		fseek(e.outputFile, 0, SEEK_END);
 	}
Index: /libmpc/branches/r2d/mpcgain/mpcgain.c
===================================================================
--- /libmpc/branches/r2d/mpcgain/mpcgain.c	(revision 219)
+++ /libmpc/branches/r2d/mpcgain/mpcgain.c	(revision 220)
@@ -41,7 +41,4 @@
 #include "../libmpcdec/huffman.h"
 #include "../libmpcdec/mpc_bits_reader.h"
-
-// crc32.c
-unsigned long crc32(unsigned char *buf, int len);
 
 static void usage(const char *exename)
@@ -124,5 +121,4 @@
 		mpc_block b;
 		mpc_uint64_t size;
-		mpc_uint32_t crc_pos, crc;
 		FILE * file;
 
@@ -140,6 +136,6 @@
 		size = mpc_bits_get_block(&r, &b);
 
-		while( memcmp(b.key, "SI", 2) != 0 ) {
-			header_pos[j] += b.size;
+		while( memcmp(b.key, "RG", 2) != 0 ) {
+			header_pos[j] += b.size + size;
 			fseek(file, header_pos[j], SEEK_SET);
 			fread(buffer, 1, 16, file);
@@ -150,11 +146,4 @@
 
 		header_pos[j] += size;
-
-		fread(buffer + 16, 1, 48, file);
-
-		crc_pos = r.buff - buffer + (8 > r.count); // save position of CRC
-		r.buff += 4; // skip CRC
-		mpc_bits_get_size(&r, &size);
-		size += 4 + crc_pos;
 
 		buffer[size] = 1; // replaygain version
@@ -168,12 +157,6 @@
 		buffer[size + 8] = album_peak & 0xFF;
 
-		crc = crc32(buffer + crc_pos + 4, (int)b.size - 4);
-		buffer[crc_pos] = crc >> 24;
-		buffer[crc_pos + 1] = (crc >> 16) & 0xFF;
-		buffer[crc_pos + 2] = (crc >> 8) & 0xFF;
-		buffer[crc_pos + 3] = crc & 0xFF;
-
 		fseek(file, header_pos[j], SEEK_SET);
-		fwrite(buffer + crc_pos, 1, b.size, file);
+		fwrite(buffer + size, 1, b.size, file);
 		fclose(file);
 	}
