Index: /libmpc/branches/r2d/libmpcdec/internal.h
===================================================================
--- /libmpc/branches/r2d/libmpcdec/internal.h	(revision 195)
+++ /libmpc/branches/r2d/libmpcdec/internal.h	(revision 196)
@@ -83,11 +83,4 @@
 };
 
-/// Searches for a ID3v2-tag and reads the length (in bytes) of it.
-///
-/// \param p_reader supplying raw stream data
-/// \return size of tag, in bytes
-/// \return MPC_STATUS_FILE on errors of any kind
-mpc_int32_t mpc_skip_id3v2(mpc_reader* p_reader);
-
 /// helper functions used by multiple files
 mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c
Index: /libmpc/branches/r2d/libmpcdec/mpc_demux.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 195)
+++ /libmpc/branches/r2d/libmpcdec/mpc_demux.c	(revision 196)
@@ -131,5 +131,5 @@
 	mpc_demux_clear_buff(d);
 	if (d->si.stream_version == 7)
-		mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (-1 << 2), MPC_BUFFER_SWAP);
+		mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (~3), MPC_BUFFER_SWAP);
 	else
 		mpc_demux_fill(d, min_bytes + ((bit_offset + 7) >> 3), 0);
@@ -146,4 +146,57 @@
 {
 	return ((d->r->tell(d->r) - d->bytes_total + d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count;
+}
+
+/**
+ * Searches for a ID3v2-tag and reads the length (in bytes) of it.
+ *
+ * @param d demuxer context
+ * @return size of tag, in bytes
+ * @return MPC_STATUS_FILE on errors of any kind
+ */
+mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d)
+{
+	mpc_uint8_t  tmp [4];
+	mpc_bool_t footerPresent;     // ID3v2.4-flag
+	mpc_int32_t size;
+
+    // we must be at the beginning of the stream
+	mpc_demux_fill(d, 3, 0);
+
+    // check id3-tag
+	if ( 0 != memcmp( d->bits_reader.buff, "ID3", 3 ) )
+		return 0;
+
+	mpc_demux_fill(d, 10, 0);
+
+	mpc_bits_read(&d->bits_reader, 24); // read ID3
+	mpc_bits_read(&d->bits_reader, 16); // read tag version
+
+	tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read flags
+	footerPresent = tmp[0] & 0x10;
+	if ( tmp[0] & 0x0F )
+		return MPC_STATUS_FILE; // not (yet???) allowed
+
+	tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read size
+	tmp[1] = mpc_bits_read(&d->bits_reader, 8); // read size
+	tmp[2] = mpc_bits_read(&d->bits_reader, 8); // read size
+	tmp[3] = mpc_bits_read(&d->bits_reader, 8); // read size
+
+	if ( (tmp[0] | tmp[1] | tmp[2] | tmp[3]) & 0x80 )
+		return MPC_STATUS_FILE; // not allowed
+
+    // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
+	size = tmp[0] << 21;
+	size |= tmp[1] << 14;
+	size |= tmp[2] << 7;
+	size |= tmp[3];
+
+	if ( footerPresent )
+		size += 10;
+
+	mpc_demux_fill(d, size, 0);
+	d->bits_reader.buff += size;
+
+	return size + 10;
 }
 
@@ -219,15 +272,10 @@
 {
 	char magic[4];
-	int err;
 
 	memset(&d->si, 0, sizeof d->si);
 
     // get header position
-	err = d->si.header_position = mpc_skip_id3v2(d->r);
-	if(err < 0) return MPC_STATUS_FILE;
-
-	// seek to first byte of mpc data
-	err = d->r->seek(d->r, d->si.header_position);
-	if(!err) return MPC_STATUS_FILE;
+	d->si.header_position = mpc_demux_skip_id3v2(d);
+	if(d->si.header_position < 0) return MPC_STATUS_FILE;
 
 	d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r);
@@ -418,2 +466,3 @@
 	return MPC_STATUS_OK;
 }
+
Index: /libmpc/branches/r2d/libmpcdec/mpc_reader.c
===================================================================
--- /libmpc/branches/r2d/libmpcdec/mpc_reader.c	(revision 195)
+++ /libmpc/branches/r2d/libmpcdec/mpc_reader.c	(revision 196)
@@ -136,47 +136,2 @@
 }
 
-mpc_int32_t
-mpc_skip_id3v2(mpc_reader* p_reader)
-{
-    mpc_uint8_t  tmp [10];
-    mpc_uint32_t unsynchronisation; // ID3v2.4-flag
-    mpc_uint32_t extHeaderPresent;  // ID3v2.4-flag
-    mpc_uint32_t experimentalFlag;  // ID3v2.4-flag
-    mpc_uint32_t footerPresent;     // ID3v2.4-flag
-    mpc_int32_t  ret;
-
-    // seek to first byte of mpc data
-    ret = p_reader->seek(p_reader, 0);
-    if(!ret) return 0;
-
-    p_reader->read(p_reader, tmp, sizeof tmp);
-
-    // check id3-tag
-    if ( 0 != memcmp( tmp, "ID3", 3 ) )
-        return 0;
-
-    // read flags
-    unsynchronisation = tmp[5] & 0x80;
-    extHeaderPresent  = tmp[5] & 0x40;
-    experimentalFlag  = tmp[5] & 0x20;
-    footerPresent     = tmp[5] & 0x10;
-
-    if ( tmp[5] & 0x0F )
-        return MPC_STATUS_FILE; // not (yet???) allowed
-    if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 )
-        return MPC_STATUS_FILE; // not allowed
-
-    // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits)
-    ret  = tmp[6] << 21;
-    ret += tmp[7] << 14;
-    ret += tmp[8] <<  7;
-    ret += tmp[9];
-    ret += 10;
-    if ( footerPresent )
-        ret += 10;
-
-    return ret;
-}
-
-
-
