Index: libmpcdec/branches/zorg/src/mpc_decoder.c
===================================================================
--- libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 70)
+++ libmpcdec/branches/zorg/src/mpc_decoder.c	(revision 81)
@@ -70,5 +70,4 @@
 // forward declarations
 //------------------------------------------------------------------------------
-static void mpc_decoder_read_bitstream_sv6(mpc_decoder *d, mpc_bool_t seeking);
 static void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t seeking);
 static void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band);
@@ -77,15 +76,15 @@
 // utility functions
 //------------------------------------------------------------------------------
-static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size) 
-{ 
-    return d->r->read(d->r, ptr, size); 
-}
-
-static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) 
-{ 
-    return d->r->seek(d->r, offset); 
-}
-
-static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) 
+static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size)
+{
+    return d->r->read(d->r, ptr, size);
+}
+
+static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset)
+{
+    return d->r->seek(d->r, offset);
+}
+
+static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count)
 {
     return f_read(d, ptr, count << 2) >> 2;
@@ -130,5 +129,5 @@
 // resets bitstream decoding
 static void
-mpc_decoder_reset_bitstream_decode(mpc_decoder *d) 
+mpc_decoder_reset_bitstream_decode(mpc_decoder *d)
 {
     d->dword = 0;
@@ -140,5 +139,5 @@
 // reports the number of read bits
 static mpc_uint32_t
-mpc_decoder_bits_read(mpc_decoder *d) 
+mpc_decoder_bits_read(mpc_decoder *d)
 {
     return 32 * d->WordsRead + d->pos;
@@ -147,5 +146,5 @@
 // read desired number of bits out of the bitstream (max 31)
 static mpc_uint32_t
-mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) 
+mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits)
 {
     mpc_uint32_t out = d->dword;
@@ -191,17 +190,23 @@
 }
 
-// decode SCFI-bundle (sv4,5,6)
+void mpc_decoder_get_block(mpc_decoder *d, mpc_block_t * p_block)
+{
+	unsigned char tmp;
+	unsigned int size = 2;
+
+	p_block->size = 0;
+	p_block->key[0] = mpc_decoder_bitstream_read(d, 8);
+	p_block->key[1] = mpc_decoder_bitstream_read(d, 8);
+	do {
+		tmp = mpc_decoder_bitstream_read(d, 8);
+		p_block->size = (p_block->size << 7) | (tmp & 0x7F);
+		size++;
+	} while((tmp & 0x80));
+
+	p_block->size -= size;
+}
+
 static void
-mpc_decoder_scfi_bundle_read(mpc_decoder *d, const mpc_huffman* Table,
-                             mpc_int32_t* SCFI, mpc_bool_t* DSCF)
-{
-    mpc_uint32_t value = mpc_decoder_huffman_decode(d, Table, 6);
-
-    *SCFI = value >> 1;
-    *DSCF = value &  1;
-}
-
-static void
-mpc_decoder_reset_v(mpc_decoder *d) 
+mpc_decoder_reset_v(mpc_decoder *d)
 {
     memset(d->V_L, 0, sizeof d->V_L);
@@ -210,5 +215,5 @@
 
 static void
-mpc_decoder_reset_synthesis(mpc_decoder *d) 
+mpc_decoder_reset_synthesis(mpc_decoder *d)
 {
     mpc_decoder_reset_v(d);
@@ -216,5 +221,5 @@
 
 static void
-mpc_decoder_reset_y(mpc_decoder *d) 
+mpc_decoder_reset_y(mpc_decoder *d)
 {
     memset(d->Y_L, 0, sizeof d->Y_L);
@@ -223,5 +228,5 @@
 
 static void
-mpc_decoder_reset_globals(mpc_decoder *d) 
+mpc_decoder_reset_globals(mpc_decoder *d)
 {
     mpc_decoder_reset_bitstream_decode(d);
@@ -268,5 +273,5 @@
 
 static mpc_uint32_t
-mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) 
+mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
 {
     mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH;
@@ -285,18 +290,36 @@
     }
 
-    // read jump-info for validity check of frame
-    FwdJumpInfo  = mpc_decoder_bitstream_read(d, 20);
-
-    // decode data and check for validity of frame
-    FrameBitCnt = mpc_decoder_bits_read(d);
     switch (d->StreamVersion) {
     case 0x07:
     case 0x17:
+		// read jump-info for validity check of frame
+		FwdJumpInfo  = mpc_decoder_bitstream_read(d, 20);
+    	// decode data and check for validity of frame
+		FrameBitCnt = mpc_decoder_bits_read(d);
         mpc_decoder_read_bitstream_sv7(d, FALSE);
+		d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
         break;
+	case 0x08:
+		if (d->BlockBits < 8){
+			mpc_block_t block;
+			// trouver le block
+			mpc_decoder_bitstream_read(d, d->BlockBits);
+			while (1) {
+				mpc_decoder_get_block(d, &block);
+				if (memcmp(block.key, "AD", 2) != 0)
+					mpc_decoder_seek(d, mpc_decoder_bits_read(d) + block.size * 8);
+				else
+					break;
+			}
+			d->BlockBits = block.size * 8;
+		}
+		FrameBitCnt = mpc_decoder_bits_read(d);
+		mpc_decoder_read_bitstream_sv7(d, FALSE);
+		d->BlockBits -= mpc_decoder_bits_read(d) - FrameBitCnt;
+		d->FrameWasValid = 1;
+		break;
     default:
         return (mpc_uint32_t)(-1);
     }
-    d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
 
     // synthesize signal
@@ -307,5 +330,5 @@
 
     // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
-    if (d->DecodedFrames == d->OverallFrames  && d->StreamVersion >= 6) {        
+    if (d->DecodedFrames == d->OverallFrames  && d->StreamVersion >= 6) {
         // reconstruct exact filelength
         mpc_int32_t  mod_block   = mpc_decoder_bitstream_read(d,  11);
@@ -314,5 +337,5 @@
         if (mod_block == 0) {
             // Encoder bugfix
-            mod_block = 1152;                    
+            mod_block = 1152;
         }
         FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH;
@@ -345,6 +368,6 @@
             output_frame_length -= d->samples_to_skip;
             memmove(
-                buffer, 
-                buffer + d->samples_to_skip * 2, 
+                buffer,
+                buffer + d->samples_to_skip * 2,
                 output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT));
             d->samples_to_skip = 0;
@@ -357,6 +380,6 @@
 mpc_uint32_t mpc_decoder_decode(
     mpc_decoder *d,
-    MPC_SAMPLE_FORMAT *buffer, 
-    mpc_uint32_t *vbr_update_acc, 
+    MPC_SAMPLE_FORMAT *buffer,
+    mpc_uint32_t *vbr_update_acc,
     mpc_uint32_t *vbr_update_bits)
 {
@@ -378,5 +401,5 @@
             // error occurred in bitstream
             return (mpc_uint32_t)(-1);
-        } 
+        }
         else {
             if (vbr_update_acc && vbr_update_bits) {
@@ -399,5 +422,5 @@
 
 void
-mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) 
+mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band)
 {
     mpc_int32_t     Band;
@@ -855,4 +878,5 @@
   d->__r1 = 1;
   d->__r2 = 1;
+  d->BlockBits = 0;
 
   d->Max_Band = 0;
@@ -872,4 +896,5 @@
     case  0x07:
     case  0x17: fpos = 200; break;
+	case  0x08: fpos = 32; break;
     }
     return fpos;
@@ -892,8 +917,8 @@
 }
 
-mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si) 
+mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si)
 {
     mpc_decoder* p_tmp;
-    
+
     p_tmp = malloc(sizeof *p_tmp);
     memset(p_tmp, 0, sizeof *p_tmp);
@@ -927,10 +952,10 @@
 }
 
-mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) 
+mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds)
 {
     return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5));
 }
 
-mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) 
+mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
 {
     mpc_uint32_t fpos;
