Index: libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 148)
+++ libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 149)
@@ -189,6 +189,4 @@
 			} else if (memcmp(b.key, "EI", 2) == 0)
 				streaminfo_encoder_info(&d->si, &d->bits_reader);
-			else if (memcmp(b.key, "RG", 2) == 0)
-				streaminfo_gain(&d->si, &d->bits_reader);
 			d->bits_reader.buff += b.size;
 			size = mpc_bits_get_block(&d->bits_reader, &b);
Index: libmpc/branches/r2d/libmpcdec/streaminfo.c
===================================================================
--- libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 148)
+++ libmpc/branches/r2d/libmpcdec/streaminfo.c	(revision 149)
@@ -140,4 +140,17 @@
 }
 
+/// Reads replay gain datas
+void  streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in)
+{
+	mpc_bits_reader r = *r_in;
+
+	mpc_bits_read(&r, 8); // gain version
+	// FIXME : add gain conversion
+	si->gain_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
+	si->peak_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
+	si->gain_album         = (mpc_uint16_t) mpc_bits_read(&r, 16);
+	si->peak_album         = (mpc_uint16_t) mpc_bits_read(&r, 16);
+}
+
 /// Reads streaminfo from SV8 header.
 mpc_status
@@ -145,11 +158,15 @@
 						   mpc_size_t block_size)
 {
-	mpc_uint32_t CRC, CRC_tmp;
-	mpc_bits_reader r = *r_in;
+	mpc_uint32_t CRC;
+	mpc_uint64_t info_len;
+	mpc_bits_reader r = *r_in, r_gain;
 
 	CRC = mpc_bits_read(&r, 32);
-	CRC_tmp = crc32(r.buff + 1 - (r.count >> 3), block_size - 4);
-	if (CRC != CRC_tmp)
+	if (CRC != crc32(r.buff + 1 - (r.count >> 3), block_size - 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);
@@ -164,6 +181,9 @@
 	si->bitrate = 0;
 
-	si->average_bitrate = (si->tag_offset - si->header_position) * 8.0
-			*  si->sample_freq / si->samples;
+	if (si->samples != 0)
+		si->average_bitrate = (si->tag_offset - si->header_position) * 8.0
+				*  si->sample_freq / si->samples;
+
+	streaminfo_gain(si, &r_gain);
 
 	return MPC_STATUS_OK;
@@ -187,17 +207,4 @@
 }
 
-/// Reads replay gain datas
-void  streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in)
-{
-	mpc_bits_reader r = *r_in;
-
-	mpc_bits_read(&r, 8); // gain version
-	// FIXME : add gain conversion
-	si->gain_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
-	si->peak_title         = (mpc_uint16_t) mpc_bits_read(&r, 16);
-	si->gain_album         = (mpc_uint16_t) mpc_bits_read(&r, 16);
-	si->peak_album         = (mpc_uint16_t) mpc_bits_read(&r, 16);
-}
-
 double
 mpc_streaminfo_get_length(mpc_streaminfo * si)
