wiki:SV8Specification

Version 30 (modified by zorg, 17 years ago) (diff)

Mostly Cosmetics, extract RG from SH

SV8 specification draft

Nota : All fields, unless explicitely specified otherwise are read and written in Big-Endian order.

File magic number

Magic number is on 32bits and is equal to 'MPCK' or 0x4D50434B

Packet formatting

All packets are formatted using Key / Size / Payload.
Keys are 16 bits long. It's equivalent to the packet ID or type.
Size is a variable-size field using the same values as nut :

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
...

Size defines the packet length in bytes, including the Key and Size fields. So the minimum length of a block is 3 bytes.
The payload is the actual packet data. Its size can be null.
All unused bits in a packet MUST be null.

Field Size (bits) Payload
Key 16 "EX"
Size n*8; 0 < n < 10 0x1A
Payload Size * 8 "example"

Summary of reserved packet keys

Packet Name Key Mandatory
Stream Header SH yes
Replaygain RG yes
Encoder Info EI no
Edition ED no
Seek Table Offset SO no
Audio Packet AP yes
Seek Table ST no
Stream End SE yes

Stream Header Packet

This packet key is "SI".
It contains the informations needed to decode the stream. This block is mandatory and must be written before the first audio packet.

Field Size (bits) Payload Comment
CRC 32 CRC 32 of the block (this field excluded). 0 = invalid
Stream version 8 8 Bitstream version
Sample count n*8; 0 < n < 10 Number of samples in the stream. 0 = unknown
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 True if Mid Side Stereo is enabled
Audio block frames 3 0..7 Number of frames per audio packet (4value=(1..16384))

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.

Replaygain Packet

This packet key is "RG".
It contains the necessary data needed to apply replaygain on the current stream. This packet is mandatory and must be written before the first audio packet.

Field Size (bits) Payload Comment
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

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 ?).

Encoder Info Packet

This packet key is "EI".

Field Size (bits) Payload Comment
Profile 7 0..15.875 quality in 4.3 format
PNS tool 1 True if enabled
Major 8 1 Major version
Minor 8 17 Minor version, even numbers for stable version, odd when unstable
Build 8 3 Build

Edition Packet

This packet key is "ED"
The SV8 stream allow only to start decoding on first packet frame, so cutting the stream require to cut on packet boundaries. This packet provides more precise cutting possibilities.
This packet must be written before the first audio packet.

Field Size (bits) Payload Comment
Beginning silence n*8; 0 < n < 10 Number of samples to skip at the beginning of the stream
End silence n*8; 0 < n < 10 Number of samples to skip at the end of the stream

Seek Table Offset Packet

This packet key is "SO".
It contains an offset to the seek table packet.

Field Size (bits) Payload Comment
Offset n*8; 0 < n < 10 Offset from this packet to the seek table packet

Audio Packet

This packet key is "AP".
It contains audio frames. The first frame is a key frame.

Field Size (bits) Payload Comment
Audio Frames ? n (or less if last packet) frames of audio as defined in SH packet

Seek Table Packet

This packet key is "ST".

Field Size (bits) Payload Comment
Seek Count n*8; 0 < n < 10 Number of seek elements in this table
Seek Distance 4 0..15 Distance between referenced blocks = 2Value
Seek Data ?

Format of seek data :

  • Reference offset for seeking is the musepack magic number
  • First 2 values are stored using the same code as the packet size code.
  • Next values are coded as :
    code = value(n) - 2*value(n-1) + value(n-2)
    code <<= 1;
    if (code < 0)
      code = -code | 1;
    

code is sent as golomb code with M = 212.

Security Packet

Checksum (MD5, SHA1) or error correcting code (LDPC).
To be defined later. May be better to keep security features external only.

Stream End Packet

This packet key is "SE".
Recommended packet size is 3 bytes.
This packet is mandatory and must be the last stream packet. Tags, if present, must be written after this packet.

Streaming

This file format can be used for streaming. The "SH" block is (can?) used as synchronization marker. The decoder will scan for a "SH" block and check its CRC. Once the decoder is synchronized, it will start decoding. It's up to the streaming server to choose when to send "SH" block.
There is currently no way to send tags during playback. This must be changed (a tag packet ?).

Tags

No packet must be written after the stream end packet to allow tagging by other applications.
Remarks about tagging? Incompatibilities?

Attachments (3)

Download all attachments as: .zip