+ if( i_block_size < 2 )
+ goto corrupt;
+ i_block_size -= 2;
+
+ if( stream_Read( p_demux->s, buf, 2 ) < 2 )
+ goto corrupt;
+
+ if( buf[1] )
+ {
+ msg_Err( p_demux, "unsupported compression" );
+ return VLC_EGENERIC;
+ }
+
+ new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+ new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );
+ new_fmt.audio.i_bytes_per_frame = 1;
+ new_fmt.audio.i_frame_length = 1;
+ new_fmt.audio.i_channels = 1;
+ new_fmt.audio.i_blockalign = 1;
+ new_fmt.audio.i_bitspersample = 8;
+ new_fmt.i_bitrate = new_fmt.audio.i_rate * 8;
+ break;
+
+ case 2: /* data block with same format as the previous one */
+ if( p_sys->p_es == NULL )
+ goto corrupt; /* no previous block! */
+
+ memcpy( &new_fmt, &p_sys->fmt, sizeof( new_fmt ) );
+ break;
+
+ case 3: /* silence block */
+ if( ( i_block_size != 3 )
+ || ( stream_Read( p_demux->s, buf, 3 ) < 3 ) )
+ goto corrupt;
+
+ i_block_size = 0;
+ p_sys->i_silence_countdown = GetWLE( buf );
+
+ new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+ new_fmt.audio.i_rate = fix_voc_sr( 1000000L / (256L - buf[0]) );
+ new_fmt.audio.i_bytes_per_frame = 1;
+ new_fmt.audio.i_frame_length = 1;
+ new_fmt.audio.i_channels = 1;
+ new_fmt.audio.i_blockalign = 1;
+ new_fmt.audio.i_bitspersample = 8;
+ new_fmt.i_bitrate = new_fmt.audio.i_rate * 8;
+ break;
+
+ case 6: /* repeat block */
+ if( ( i_block_size != 2 )
+ || ( stream_Read( p_demux->s, buf, 2 ) < 2 ) )
+ goto corrupt;
+
+ i_block_size = 0;
+ p_sys->i_loop_count = GetWLE( buf );
+ p_sys->i_loop_offset = stream_Tell( p_demux->s );
+ break;
+
+ case 7: /* repeat end block */
+ if( i_block_size != 0 )
+ goto corrupt;
+
+ if( p_sys->i_loop_count > 0 )
+ {
+ if( stream_Seek( p_demux->s, p_sys->i_loop_offset ) )
+ msg_Warn( p_demux, "cannot loop: seek failed" );
+ else
+ p_sys->i_loop_count--;
+ }
+ break;
+
+ case 8:
+ /*
+ * Block 8 is a big kludge to add stereo support to block 1 :
+ * A block of type 8 is always followed by a block of type 1
+ * and specifies the number of channels in that 1-block
+ * (normally block 1 are always mono). In practice, block type 9
+ * is used for stereo rather than 8
+ */
+ if( ( i_block_size != 4 )
+ || ( stream_Read( p_demux->s, buf, 4 ) < 4 ) )
+ goto corrupt;
+
+ if( buf[2] )
+ {
+ msg_Err( p_demux, "unsupported compression" );
+ return VLC_EGENERIC;
+ }
+
+ new_fmt.i_codec = VLC_FOURCC('u','8',' ',' ');
+ new_fmt.audio.i_channels = buf[3] + 1; /* can't be nul */
+ new_fmt.audio.i_rate = 256000000L /
+ ((65536L - GetWLE(buf)) * new_fmt.audio.i_channels);
+ new_fmt.audio.i_bytes_per_frame = new_fmt.audio.i_channels;
+ new_fmt.audio.i_frame_length = 1;
+ new_fmt.audio.i_blockalign = new_fmt.audio.i_bytes_per_frame;
+ new_fmt.audio.i_bitspersample = 8 * new_fmt.audio.i_bytes_per_frame;
+ new_fmt.i_bitrate = new_fmt.audio.i_rate * 8;
+
+ /* read subsequent block 1 */
+ if( stream_Read( p_demux->s, buf, 4 ) < 4 )
+ return VLC_EGENERIC; /* EOF */
+
+ i_block_size = GetDWLE( buf ) >> 8;
+ msg_Dbg( p_demux, "new block: type: %u, size: %u",
+ (unsigned)*buf, i_block_size );
+ if( i_block_size < 2 )
+ goto corrupt;
+ i_block_size -= 2;