= SV8 specification draft = Nota : All fields, unless explicitely specified otherwise are read and written in Big-Endian order, independently of the underlying architecture. == File magic number == Magic number is on 32bits and is equal to 'MPCK' or 0x4D50434B[[BR]] New value so old decoders will happily skip such files. == Block formatting == All blocks are formated using Key / Length / Value.[[BR]] Key is 16 bits long. It's the block ID.[[BR]] Length is a variable size field using the same values as [http://svn.mplayerhq.hu/mplayer/trunk/DOCS/tech/nut.txt?view=markup nut] :[[BR]] {{{ bits, big-endian 0xxx xxxx - value 0 to 2^7-2 1xxx xxxx 0xxx xxxx - value 0 to 2^14-2 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^21-2 1xxx xxxx 1xxx xxxx 1xxx xxxx 0xxx xxxx - value 0 to 2^28-2 ... }}} The length is the size of the block in bytes, including the key and size fields. So the minimum length of a block is 3 bytes.[[BR]] The value is the block content. Its size can be 0.[[BR]] All unused bits in a block MUST be 0.[[BR]] || '''Field''' || '''length (bits)''' || '''Value''' || || Key || 16 || "EX" || || Length || n*8; 0 < n < 10 || 0x1A || || Value || Length * 8 || "example" || == Summary of reserved block keys == || '''Block name''' || '''Key''' || '''Mandatory''' || || Stream information || SI || yes || || Encoder information || EI || no || || Audio data || AD || yes || || Seek Pointer || SP || no || || Seek Table || ST || no || || Stream End || SE || yes || == Stream information block == This block key is "SI".[[BR]] This block contains the informations needed to decode the stream. This block is mandatory and must be written before the first audio block.[[BR]] || '''Field''' || '''length (bits)''' || '''Value''' || '''comment''' || || CRC || 32 || || CRC 32 of the block (this field excluded). 0 = invalid || || Info length || n*8; 0 < n < 10 || || length (in bytes) from this field (included) to the ReplayGain version field || || Stream version || 8 || 8 || bitstream version || || Sample count || n*8; 0 < n < 10 || || number of samples in the stream. 0 = unknow || || Sample frequency || 3 || 0..7 || see table below || || Channel count || 4 || 1..16 || number of channels in the stream || || Max used bands || 5 || 1..32 || maximum number of bands used in the file || || MS used || 1 || || MidSideStereo || || Audio block frames || 3 || 0..7 || number of frames in an audio block is : 4^Value^ (1..16384) || || ReplayGain version || 8 || || The replay gain version - must be aligned on a byte - || || Title gain || 16 || || The loudness calculated for the title, ''and not the gain that the player must apply'' || || Title peak || 16 || || || || Album gain || 16 || || The loudness calculated for the album || || Album peak || 16 || || || Do we need to specify the channel position ? Is there standard positions / order of the channels ? Frequency table || '''Value''' || '''Frequency (Hz)''' || || 0 || 44100 || || 1 || 48000 || || 2 || 37800 || || 3 || 32000 || The CRC used is this one : [http://www.w3.org/TR/PNG/#D-CRCAppendix http://www.w3.org/TR/PNG/#D-CRCAppendix]. The replay gain values are stored in dB in Q8.8 format (maybe Q7.9 or relative to the max value for the bitdepth is better ?).[[BR]] == Encoder infomations == This block key is "EI". || '''Field''' || '''length (bits)''' || '''Value''' || '''comment''' || || profile used || 4 || 0..15 || || || PNS used || 1 || || || || Unused || 3 || || must be 0 || || MajorNumber || 4 || || || || MinorNumber || 8 || || even = release, odd = unstable || || Implementation || 4 || || || || Build || 8 || || || == Audio data block == This block key is "AD".[[BR]] This block contains audio frames. The first frame is a key frame.[[BR]] || '''Field''' || '''length (bits)''' || '''Value''' || '''comment''' || || audio frames || ? || || n (or less if last block) frames of audio data as defined in SI block || == Seek Pointer Block == This block key is "SP".[[BR]] This block contains a pointer to the seek table block. || '''Field''' || '''length (bits)''' || '''Value''' || '''comment''' || || pointer || n*8; 0 < n < 10 || || number of bytes from this block header to the "ST" block header || == Seek Table Block == This block key is "ST".[[BR]] || '''Field''' || '''length (bits)''' || '''Value''' || '''comment''' || || Seek Count || n*8; 0 < n < 10 || || number of seek elements in this table || || Seek Distance || 4 || 0..15 || distance between referenced blocks = 2^Value^ || || Seek Datas || ? || || || Format of seek datas :[[BR]] - The reference for the seek offset is the musepack magic number[[BR]] - The first 2 values are stored using the same code as the block length code.[[BR]] - The next values are coded as :[[BR]] {{{ code = value(n) - 2*value(n-1) + value(n-2) code <<= 1; if (code < 0) code = -code | 1; }}} code is sent as [http://en.wikipedia.org/wiki/Golomb_code golomb code] with M = 2^12^. == Security Block == Checksum (MD5, SHA1) or error correcting code (LDPC).[[BR]] To be defined later. May be better to keep security features external only. == End Block == This block key is "SE".[[BR]] The recommanded block lenth is 3 bytes.[[BR]] This block is mandatory and must be the last block of the stream. Tags are written after this block. == Streaming == This file format can be used for streaming. The "SI" block is used as synchronization marker. The decoder will scan for a "SI" block and check the block CRC. Once the decoder is synchronized, it will start decoding. It's up to the streaming server to choose when to send "SI" block.[[BR]] There is currently no way to send tags during playback. This must be changed (a tag block ?). == Tags == No block must be written after the end block to allow tagging by other applications.[[BR]] Remarks about tagging? Incompatibilities?[[BR]]