Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: FLAC - format Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1:  english  | Chris@1:  russian  Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: format Chris@1:
Chris@1:
Chris@1:
Chris@1: This is a detailed description of the FLAC format. There is also a companion document that describes FLAC-to-Ogg mapping.
Chris@1:
Chris@1: For a user-oriented overview, see About the FLAC Format.
Chris@1:
Chris@1: Table of Contents Chris@1: Chris@1: Acknowledgments
Chris@1:
Chris@1: FLAC owes much to the many people who have advanced the audio compression field so freely. For instance: Chris@1: Chris@1: Scope
Chris@1:
Chris@1: It is a known fact that no algorithm can losslessly compress all possible input, so most compressors restrict themselves to a useful domain and try to work as well as possible within that domain. FLAC's domain is audio data. Though it can losslessly code any input, only certain kinds of input will get smaller. FLAC exploits the fact that audio data typically has a high degree of sample-to-sample correlation.
Chris@1:
Chris@1: Within the audio domain, there are many possible subdomains. For example: low bitrate speech, high-bitrate multi-channel music, etc. FLAC itself does not target a specific subdomain but many of the default parameters of the reference encoder are tuned to CD-quality music data (i.e. 44.1kHz, 2 channel, 16 bits per sample). The effect of the encoding parameters on different kinds of audio data will be examined later.
Chris@1:
Chris@1: Architecture
Chris@1:
Chris@1: Similar to many audio coders, a FLAC encoder has the following stages: Chris@1: Chris@1: In addition, FLAC specifies a metadata system, which allows arbitrary information about the stream to be included at the beginning of the stream.
Chris@1:
Chris@1: Definitions
Chris@1:
Chris@1: Many terms like "block" and "frame" are used to mean different things in differenct encoding schemes. For example, a frame in MP3 corresponds to many samples across several channels, whereas an S/PDIF frame represents just one sample for each channel. The definitions we use for FLAC follow. Note that when we talk about blocks and subblocks we are referring to the raw unencoded audio data that is the input to the encoder, and when we talk about frames and subframes, we are referring to the FLAC-encoded data. Chris@1: Chris@1: Blocking
Chris@1:
Chris@1: The size used for blocking the audio data has a direct effect on the compression ratio. If the block size is too small, the resulting large number of frames mean that excess bits will be wasted on frame headers. If the block size is too large, the characteristics of the signal may vary so much that the encoder will be unable to find a good predictor. In order to simplify encoder/decoder design, FLAC imposes a minimum block size of 16 samples, and a maximum block size of 65535 samples. This range covers the optimal size for all of the audio data FLAC supports.
Chris@1:
Chris@1: Currently the reference encoder uses a fixed block size, optimized on the sample rate of the input. Future versions may vary the block size depending on the characteristics of the signal.
Chris@1:
Chris@1: Blocked data is passed to the predictor stage one subblock (channel) at a time. Each subblock is independently coded into a subframe, and the subframes are concatenated into a frame. Because each channel is coded separately, it means that one channel of a stereo frame may be encoded as a constant subframe, and the other an LPC subframe.
Chris@1:
Chris@1: Interchannel Decorrelation
Chris@1:
Chris@1: In stereo streams, many times there is an exploitable amount of correlation between the left and right channels. FLAC allows the frames of stereo streams to have different channel assignments, and an encoder may choose to use the best representation on a frame-by-frame basis. Chris@1: Chris@1: Surprisingly, the left-side and right-side forms can be the most efficient in many frames, even though the raw number of bits per sample needed for the original signal is slightly more than that needed for independent or mid-side coding.
Chris@1:
Chris@1: Prediction
Chris@1:
Chris@1: FLAC uses four methods for modeling the input signal: Chris@1: Chris@1: Residual Coding
Chris@1:
Chris@1: FLAC currently defines two similar methods for the coding of the error signal from the prediction stage. The error signal is coded using Rice codes in one of two ways: 1) the encoder estimates a single Rice parameter based on the variance of the residual and Rice codes the entire residual using this parameter; 2) the residual is partitioned into several equal-length regions of contiguous samples, and each region is coded with its own Rice parameter based on the region's mean. (Note that the first method is a special case of the second method with one partition, except the Rice parameter is based on the residual variance instead of the mean.)
Chris@1:
Chris@1: The FLAC format has reserved space for other coding methods. Some possiblities for volunteers would be to explore better context-modeling of the Rice parameter, or Huffman coding. See LOCO-I and pucrunch for descriptions of several universal codes.
Chris@1:
Chris@1: Format
Chris@1:
Chris@1: This section specifies the FLAC bitstream format. FLAC has no format version information, but it does contain reserved space in several places. Future versions of the format may use this reserved space safely without breaking the format of older streams. Older decoders may choose to abort decoding or skip data encoded with newer methods. Apart from reserved patterns, in places the format specifies invalid patterns, meaning that the patterns may never appear in any valid bitstream, in any prior, present, or future versions of the format. These invalid patterns are usually used to make the synchronization mechanism more robust.
Chris@1:
Chris@1: All numbers used in a FLAC bitstream are integers; there are no floating-point representations. All numbers are big-endian coded. All numbers are unsigned unless otherwise specified.
Chris@1:
Chris@1: Before the formal description of the stream, an overview might be helpful. Chris@1: Chris@1: Chris@1: The following tables constitute a formal description of the FLAC format. Numbers in angle brackets indicate how many bits are used for a given field.
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: STREAM Chris@1:
Chris@1: <32> Chris@1: Chris@1: "fLaC", the FLAC stream marker in ASCII, meaning byte 0 of the stream is 0x66, followed by 0x4C 0x61 0x43 Chris@1:
Chris@1: METADATA_BLOCK Chris@1: Chris@1: This is the mandatory STREAMINFO metadata block that has the basic properties of the stream Chris@1:
Chris@1: METADATA_BLOCK* Chris@1: Chris@1: Zero or more metadata blocks Chris@1:
Chris@1: FRAME+ Chris@1: Chris@1: One or more audio frames Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK Chris@1:
Chris@1: METADATA_BLOCK_HEADER Chris@1: Chris@1: A block header that specifies the type and size of the metadata block data. Chris@1:
Chris@1: METADATA_BLOCK_DATA Chris@1: Chris@1:   Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_HEADER Chris@1:
Chris@1: <1> Chris@1: Chris@1: Last-metadata-block flag: '1' if this block is the last metadata block before the audio blocks, '0' otherwise. Chris@1:
Chris@1: <7> Chris@1: Chris@1: BLOCK_TYPE
Chris@1:
    Chris@1:
  • Chris@1: 0 : STREAMINFO Chris@1:
  • Chris@1:
  • Chris@1: 1 : PADDING Chris@1:
  • Chris@1:
  • Chris@1: 2 : APPLICATION Chris@1:
  • Chris@1:
  • Chris@1: 3 : SEEKTABLE Chris@1:
  • Chris@1:
  • Chris@1: 4 : VORBIS_COMMENT Chris@1:
  • Chris@1:
  • Chris@1: 5 : CUESHEET Chris@1:
  • Chris@1:
  • Chris@1: 6 : PICTURE Chris@1:
  • Chris@1:
  • Chris@1: 7-126 : reserved Chris@1:
  • Chris@1:
  • Chris@1: 127 : invalid, to avoid confusion with a frame sync code Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <24> Chris@1: Chris@1: Length (in bytes) of metadata to follow (does not include the size of the METADATA_BLOCK_HEADER) Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_DATA Chris@1:
Chris@1: METADATA_BLOCK_STREAMINFO
Chris@1: || METADATA_BLOCK_PADDING
Chris@1: || METADATA_BLOCK_APPLICATION
Chris@1: || METADATA_BLOCK_SEEKTABLE
Chris@1: || METADATA_BLOCK_VORBIS_COMMENT
Chris@1: || METADATA_BLOCK_CUESHEET
Chris@1: || METADATA_BLOCK_PICTURE Chris@1:
Chris@1: The block data must match the block type in the block header. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_STREAMINFO Chris@1:
Chris@1: <16> Chris@1: Chris@1: The minimum block size (in samples) used in the stream. Chris@1:
Chris@1: <16> Chris@1: Chris@1: The maximum block size (in samples) used in the stream. (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream. Chris@1:
Chris@1: <24> Chris@1: Chris@1: The minimum frame size (in bytes) used in the stream. May be 0 to imply the value is not known. Chris@1:
Chris@1: <24> Chris@1: Chris@1: The maximum frame size (in bytes) used in the stream. May be 0 to imply the value is not known. Chris@1:
Chris@1: <20> Chris@1: Chris@1: Sample rate in Hz. Though 20 bits are available, the maximum sample rate is limited by the structure of frame headers to 655350Hz. Also, a value of 0 is invalid. Chris@1:
Chris@1: <3> Chris@1: Chris@1: (number of channels)-1. FLAC supports from 1 to 8 channels Chris@1:
Chris@1: <5> Chris@1: Chris@1: (bits per sample)-1. FLAC supports from 4 to 32 bits per sample. Currently the reference encoder and decoders only support up to 24 bits per sample. Chris@1:
Chris@1: <36> Chris@1: Chris@1: Total samples in stream. 'Samples' means inter-channel sample, i.e. one second of 44.1Khz audio will have 44100 samples regardless of the number of channels. A value of zero here means the number of total samples is unknown. Chris@1:
Chris@1: <128> Chris@1: Chris@1: MD5 signature of the unencoded audio data. This allows the decoder to determine if an error exists in the audio data even when the error does not result in an invalid bitstream. Chris@1:
Chris@1: Chris@1: NOTES
Chris@1:
    Chris@1:
  • Chris@1: FLAC specifies a minimum block size of 16 and a maximum block size of 65535, meaning the bit patterns corresponding to the numbers 0-15 in the minimum blocksize and maximum blocksize fields are invalid. Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_PADDING Chris@1:
Chris@1: <n> Chris@1: Chris@1: n '0' bits (n must be a multiple of 8) Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_APPLICATION Chris@1:
Chris@1: <32> Chris@1: Chris@1: Registered application ID. (Visit the registration page to register an ID with FLAC.) Chris@1:
Chris@1: <n> Chris@1: Chris@1: Application data (n must be a multiple of 8) Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_SEEKTABLE Chris@1:
Chris@1: SEEKPOINT+ Chris@1: Chris@1: One or more seek points. Chris@1:
Chris@1: Chris@1: NOTE
Chris@1:
    Chris@1:
  • Chris@1: The number of seek points is implied by the metadata header 'length' field, i.e. equal to length / 18. Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SEEKPOINT Chris@1:
Chris@1: <64> Chris@1: Chris@1: Sample number of first sample in the target frame, or 0xFFFFFFFFFFFFFFFF for a placeholder point. Chris@1:
Chris@1: <64> Chris@1: Chris@1: Offset (in bytes) from the first byte of the first frame header to the first byte of the target frame's header. Chris@1:
Chris@1: <16> Chris@1: Chris@1: Number of samples in the target frame. Chris@1:
Chris@1: Chris@1: NOTES
Chris@1:
    Chris@1:
  • Chris@1: For placeholder points, the second and third field values are undefined. Chris@1:
  • Chris@1:
  • Chris@1: Seek points within a table must be sorted in ascending order by sample number. Chris@1:
  • Chris@1:
  • Chris@1: Seek points within a table must be unique by sample number, with the exception of placeholder points. Chris@1:
  • Chris@1:
  • Chris@1: The previous two notes imply that there may be any number of placeholder points, but they must all occur at the end of the table. Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_VORBIS_COMMENT Chris@1:
Chris@1: <n> Chris@1: Chris@1: Also known as FLAC tags, the contents of a vorbis comment packet as specified here (without the framing bit). Note that the vorbis comment spec allows for on the order of 2 ^ 64 bytes of data where as the FLAC metadata block is limited to 2 ^ 24 bytes. Given the stated purpose of vorbis comments, i.e. human-readable textual information, this limit is unlikely to be restrictive. Also note that the 32-bit field lengths are little-endian coded according to the vorbis spec, as opposed to the usual big-endian coding of fixed-length integers in the rest of FLAC. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_CUESHEET Chris@1:
Chris@1: <128*8> Chris@1: Chris@1: Media catalog number, in ASCII printable characters 0x20-0x7e. In general, the media catalog number may be 0 to 128 bytes long; any unused characters should be right-padded with NUL characters. For CD-DA, this is a thirteen digit number, followed by 115 NUL bytes. Chris@1:
Chris@1: <64> Chris@1: Chris@1: The number of lead-in samples. This field has meaning only for CD-DA cuesheets; for other uses it should be 0. For CD-DA, the lead-in is the TRACK 00 area where the table of contents is stored; more precisely, it is the number of samples from the first sample of the media to the first sample of the first index point of the first track. According to the Red Book, the lead-in must be silence and CD grabbing software does not usually store it; additionally, the lead-in must be at least two seconds but may be longer. For these reasons the lead-in length is stored here so that the absolute position of the first track can be computed. Note that the lead-in stored here is the number of samples up to the first index point of the first track, not necessarily to INDEX 01 of the first track; even the first track may have INDEX 00 data. Chris@1:
Chris@1: <1> Chris@1: Chris@1: 1 if the CUESHEET corresponds to a Compact Disc, else 0. Chris@1:
Chris@1: <7+258*8> Chris@1: Chris@1: Reserved. All bits must be set to zero. Chris@1:
Chris@1: <8> Chris@1: Chris@1: The number of tracks. Must be at least 1 (because of the requisite lead-out track). For CD-DA, this number must be no more than 100 (99 regular tracks and one lead-out track). Chris@1:
Chris@1: CUESHEET_TRACK+ Chris@1: Chris@1: One or more tracks. A CUESHEET block is required to have a lead-out track; it is always the last track in the CUESHEET. For CD-DA, the lead-out track number must be 170 as specified by the Red Book, otherwise is must be 255. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: CUESHEET_TRACK Chris@1:
Chris@1: <64> Chris@1: Chris@1: Track offset in samples, relative to the beginning of the FLAC audio stream. It is the offset to the first index point of the track. (Note how this differs from CD-DA, where the track's offset in the TOC is that of the track's INDEX 01 even if there is an INDEX 00.) For CD-DA, the offset must be evenly divisible by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec). Chris@1:
Chris@1: <8> Chris@1: Chris@1: Track number. A track number of 0 is not allowed to avoid conflicting with the CD-DA spec, which reserves this for the lead-in. For CD-DA the number must be 1-99, or 170 for the lead-out; for non-CD-DA, the track number must for 255 for the lead-out. It is not required but encouraged to start with track 1 and increase sequentially. Track numbers must be unique within a CUESHEET. Chris@1:
Chris@1: <12*8> Chris@1: Chris@1: Track ISRC. This is a 12-digit alphanumeric code; see here and here. A value of 12 ASCII NUL characters may be used to denote absence of an ISRC. Chris@1:
Chris@1: <1> Chris@1: Chris@1: The track type: 0 for audio, 1 for non-audio. This corresponds to the CD-DA Q-channel control bit 3. Chris@1:
Chris@1: <1> Chris@1: Chris@1: The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. This corresponds to the CD-DA Q-channel control bit 5; see here. Chris@1:
Chris@1: <6+13*8> Chris@1: Chris@1: Reserved. All bits must be set to zero. Chris@1:
Chris@1: <8> Chris@1: Chris@1: The number of track index points. There must be at least one index in every track in a CUESHEET except for the lead-out track, which must have zero. For CD-DA, this number may be no more than 100. Chris@1:
Chris@1: CUESHEET_TRACK_INDEX+ Chris@1: Chris@1: For all tracks except the lead-out track, one or more track index points. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: CUESHEET_TRACK_INDEX Chris@1:
Chris@1: <64> Chris@1: Chris@1: Offset in samples, relative to the track offset, of the index point. For CD-DA, the offset must be evenly divisible by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec). Note that the offset is from the beginning of the track, not the beginning of the audio data. Chris@1:
Chris@1: <8> Chris@1: Chris@1: The index point number. For CD-DA, an index number of 0 corresponds to the track pre-gap. The first index in a track must have a number of 0 or 1, and subsequently, index numbers must increase by 1. Index numbers must be unique within a track. Chris@1:
Chris@1: <3*8> Chris@1: Chris@1: Reserved. All bits must be set to zero. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: METADATA_BLOCK_PICTURE Chris@1:
Chris@1: <32> Chris@1: Chris@1: The picture type according to the ID3v2 APIC frame:
Chris@1:
    Chris@1:
  • 0 - Other
  • Chris@1:
  • 1 - 32x32 pixels 'file icon' (PNG only)
  • Chris@1:
  • 2 - Other file icon
  • Chris@1:
  • 3 - Cover (front)
  • Chris@1:
  • 4 - Cover (back)
  • Chris@1:
  • 5 - Leaflet page
  • Chris@1:
  • 6 - Media (e.g. label side of CD)
  • Chris@1:
  • 7 - Lead artist/lead performer/soloist
  • Chris@1:
  • 8 - Artist/performer
  • Chris@1:
  • 9 - Conductor
  • Chris@1:
  • 10 - Band/Orchestra
  • Chris@1:
  • 11 - Composer
  • Chris@1:
  • 12 - Lyricist/text writer
  • Chris@1:
  • 13 - Recording Location
  • Chris@1:
  • 14 - During recording
  • Chris@1:
  • 15 - During performance
  • Chris@1:
  • 16 - Movie/video screen capture
  • Chris@1:
  • 17 - A bright coloured fish
  • Chris@1:
  • 18 - Illustration
  • Chris@1:
  • 19 - Band/artist logotype
  • Chris@1:
  • 20 - Publisher/Studio logotype
  • Chris@1:
Chris@1: Others are reserved and should not be used. There may only be one each of picture type 1 and 2 in a file. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The length of the MIME type string in bytes. Chris@1:
Chris@1: <n*8> Chris@1: Chris@1: The MIME type string, in printable ASCII characters 0x20-0x7e. The MIME type may also be --> to signify that the data part is a URL of the picture instead of the picture data itself. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The length of the description string in bytes. Chris@1:
Chris@1: <n*8> Chris@1: Chris@1: The description of the picture, in UTF-8. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The width of the picture in pixels. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The height of the picture in pixels. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The color depth of the picture in bits-per-pixel. Chris@1:
Chris@1: <32> Chris@1: Chris@1: For indexed-color pictures (e.g. GIF), the number of colors used, or 0 for non-indexed pictures. Chris@1:
Chris@1: <32> Chris@1: Chris@1: The length of the picture data in bytes. Chris@1:
Chris@1: <n*8> Chris@1: Chris@1: The binary picture data. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: FRAME Chris@1:
Chris@1: FRAME_HEADER Chris@1: Chris@1:   Chris@1:
Chris@1: SUBFRAME+ Chris@1: Chris@1: One SUBFRAME per channel. Chris@1:
Chris@1: <?> Chris@1: Chris@1: Zero-padding to byte alignment. Chris@1:
Chris@1: FRAME_FOOTER Chris@1: Chris@1:   Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: FRAME_HEADER Chris@1:
Chris@1: <14> Chris@1: Chris@1: Sync code '11111111111110' Chris@1:
Chris@1: <1> Chris@1: Chris@1: Reserved:
Chris@1:
    Chris@1:
  • Chris@1: 0 : mandatory value Chris@1:
  • Chris@1:
  • Chris@1: 1 : reserved for future use Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <1> Chris@1: Chris@1: Blocking strategy:
Chris@1:
    Chris@1:
  • Chris@1: 0 : fixed-blocksize stream; frame header encodes the frame number Chris@1:
  • Chris@1:
  • Chris@1: 1 : variable-blocksize stream; frame header encodes the sample number Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <4> Chris@1: Chris@1: Block size in inter-channel samples:
Chris@1:
    Chris@1:
  • Chris@1: 0000 : reserved Chris@1:
  • Chris@1:
  • Chris@1: 0001 : 192 samples Chris@1:
  • Chris@1:
  • Chris@1: 0010-0101 : 576 * (2^(n-2)) samples, i.e. 576/1152/2304/4608 Chris@1:
  • Chris@1:
  • Chris@1: 0110 : get 8 bit (blocksize-1) from end of header Chris@1:
  • Chris@1:
  • Chris@1: 0111 : get 16 bit (blocksize-1) from end of header Chris@1:
  • Chris@1:
  • Chris@1: 1000-1111 : 256 * (2^(n-8)) samples, i.e. 256/512/1024/2048/4096/8192/16384/32768 Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <4> Chris@1: Chris@1: Sample rate:
Chris@1:
    Chris@1:
  • Chris@1: 0000 : get from STREAMINFO metadata block Chris@1:
  • Chris@1:
  • Chris@1: 0001 : 88.2kHz Chris@1:
  • Chris@1:
  • Chris@1: 0010 : 176.4kHz Chris@1:
  • Chris@1:
  • Chris@1: 0011 : 192kHz Chris@1:
  • Chris@1:
  • Chris@1: 0100 : 8kHz Chris@1:
  • Chris@1:
  • Chris@1: 0101 : 16kHz Chris@1:
  • Chris@1:
  • Chris@1: 0110 : 22.05kHz Chris@1:
  • Chris@1:
  • Chris@1: 0111 : 24kHz Chris@1:
  • Chris@1:
  • Chris@1: 1000 : 32kHz Chris@1:
  • Chris@1:
  • Chris@1: 1001 : 44.1kHz Chris@1:
  • Chris@1:
  • Chris@1: 1010 : 48kHz Chris@1:
  • Chris@1:
  • Chris@1: 1011 : 96kHz Chris@1:
  • Chris@1:
  • Chris@1: 1100 : get 8 bit sample rate (in kHz) from end of header Chris@1:
  • Chris@1:
  • Chris@1: 1101 : get 16 bit sample rate (in Hz) from end of header Chris@1:
  • Chris@1:
  • Chris@1: 1110 : get 16 bit sample rate (in tens of Hz) from end of header Chris@1:
  • Chris@1:
  • Chris@1: 1111 : invalid, to prevent sync-fooling string of 1s Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <4> Chris@1: Chris@1: Channel assignment Chris@1:
    Chris@1:
  • Chris@1: 0000-0111 : (number of independent channels)-1. Where defined, the channel order follows SMPTE/ITU-R recommendations. The assignments are as follows: Chris@1:
      Chris@1:
    • 1 channel: mono
    • Chris@1:
    • 2 channels: left, right
    • Chris@1:
    • 3 channels: left, right, center
    • Chris@1:
    • 4 channels: left, right, back left, back right
    • Chris@1:
    • 5 channels: left, right, center, back/surround left, back/surround right
    • Chris@1:
    • 6 channels: left, right, center, LFE, back/surround left, back/surround right
    • Chris@1:
    • 7 channels: not defined
    • Chris@1:
    • 8 channels: not defined
    • Chris@1:
    Chris@1:
  • Chris@1:
  • Chris@1: 1000 : left/side stereo: channel 0 is the left channel, channel 1 is the side(difference) channel Chris@1:
  • Chris@1:
  • Chris@1: 1001 : right/side stereo: channel 0 is the side(difference) channel, channel 1 is the right channel Chris@1:
  • Chris@1:
  • Chris@1: 1010 : mid/side stereo: channel 0 is the mid(average) channel, channel 1 is the side(difference) channel Chris@1:
  • Chris@1:
  • Chris@1: 1011-1111 : reserved Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <3> Chris@1: Chris@1: Sample size in bits:
Chris@1:
    Chris@1:
  • Chris@1: 000 : get from STREAMINFO metadata block Chris@1:
  • Chris@1:
  • Chris@1: 001 : 8 bits per sample Chris@1:
  • Chris@1:
  • Chris@1: 010 : 12 bits per sample Chris@1:
  • Chris@1:
  • Chris@1: 011 : reserved Chris@1:
  • Chris@1:
  • Chris@1: 100 : 16 bits per sample Chris@1:
  • Chris@1:
  • Chris@1: 101 : 20 bits per sample Chris@1:
  • Chris@1:
  • Chris@1: 110 : 24 bits per sample Chris@1:
  • Chris@1:
  • Chris@1: 111 : reserved Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <1> Chris@1: Chris@1: Reserved:
Chris@1:
    Chris@1:
  • Chris@1: 0 : mandatory value Chris@1:
  • Chris@1:
  • Chris@1: 1 : reserved for future use Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <?> Chris@1: Chris@1: if(variable blocksize)
Chris@1:    <8-56>:"UTF-8" coded sample number (decoded number is 36 bits)
Chris@1: else
Chris@1:    <8-48>:"UTF-8" coded frame number (decoded number is 31 bits) Chris@1:
Chris@1: <?> Chris@1: Chris@1: if(blocksize bits == 011x)
Chris@1:    8/16 bit (blocksize-1) Chris@1:
Chris@1: <?> Chris@1: Chris@1: if(sample rate bits == 11xx)
Chris@1:    8/16 bit sample rate Chris@1:
Chris@1: <8> Chris@1: Chris@1: CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0) of everything before the crc, including the sync code Chris@1:
Chris@1: Chris@1: NOTES
Chris@1:
    Chris@1:
  • Chris@1: The "blocking strategy" bit must be the same throughout the entire stream. Chris@1:
  • Chris@1:
  • Chris@1: The "blocking strategy" bit determines how to calculate the sample number of the first sample in the frame. If the bit is 0 (fixed-blocksize), the frame header encodes the frame number as above, and the frame's starting sample number will be the frame number times the blocksize. If it is 1 (variable-blocksize), the frame header encodes the frame's starting sample number itself. (In the case of a fixed-blocksize stream, only the last block may be shorter than the stream blocksize; its starting sample number will be calculated as the frame number times the previous frame's blocksize, or zero if it is the first frame). Chris@1:
  • Chris@1:
  • Chris@1: The "UTF-8" coding used for the sample/frame number is the same variable length code used to store compressed UCS-2, extended to handle larger input. Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: FRAME_FOOTER Chris@1:
Chris@1: <16> Chris@1: Chris@1: CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with 0) of everything before the crc, back to and including the frame header sync code Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME Chris@1:
Chris@1: SUBFRAME_HEADER Chris@1: Chris@1:   Chris@1:
Chris@1: SUBFRAME_CONSTANT
|| SUBFRAME_FIXED
|| SUBFRAME_LPC
|| SUBFRAME_VERBATIM Chris@1:
Chris@1: The SUBFRAME_HEADER specifies which one. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME_HEADER Chris@1:
Chris@1: <1> Chris@1: Chris@1: Zero bit padding, to prevent sync-fooling string of 1s Chris@1:
Chris@1: <6> Chris@1: Chris@1: Subframe type: Chris@1:
    Chris@1:
  • Chris@1: 000000 : SUBFRAME_CONSTANT Chris@1:
  • Chris@1:
  • Chris@1: 000001 : SUBFRAME_VERBATIM Chris@1:
  • Chris@1:
  • Chris@1: 00001x : reserved Chris@1:
  • Chris@1:
  • Chris@1: 0001xx : reserved Chris@1:
  • Chris@1:
  • Chris@1: 001xxx : if(xxx <= 4) SUBFRAME_FIXED, xxx=order ; else reserved Chris@1:
  • Chris@1:
  • Chris@1: 01xxxx : reserved Chris@1:
  • Chris@1:
  • Chris@1: 1xxxxx : SUBFRAME_LPC, xxxxx=order-1 Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <1+k> Chris@1: Chris@1: 'Wasted bits-per-sample' flag: Chris@1:
    Chris@1:
  • Chris@1: 0 : no wasted bits-per-sample in source subblock, k=0 Chris@1:
  • Chris@1:
  • Chris@1: 1 : k wasted bits-per-sample in source subblock, k-1 follows, unary coded; e.g. k=3 => 001 follows, k=7 => 0000001 follows. Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME_CONSTANT Chris@1:
Chris@1: <n> Chris@1: Chris@1: Unencoded constant value of the subblock, n = frame's bits-per-sample. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME_FIXED Chris@1:
Chris@1: <n> Chris@1: Chris@1: Unencoded warm-up samples (n = frame's bits-per-sample * predictor order). Chris@1:
Chris@1: RESIDUAL Chris@1: Chris@1: Encoded residual Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME_LPC Chris@1:
Chris@1: <n> Chris@1: Chris@1: Unencoded warm-up samples (n = frame's bits-per-sample * lpc order). Chris@1:
Chris@1: <4> Chris@1: Chris@1: (Quantized linear predictor coefficients' precision in bits)-1 (1111 = invalid). Chris@1:
Chris@1: <5> Chris@1: Chris@1: Quantized linear predictor coefficient shift needed in bits (NOTE: this number is signed two's-complement). Chris@1:
Chris@1: <n> Chris@1: Chris@1: Unencoded predictor coefficients (n = qlp coeff precision * lpc order) (NOTE: the coefficients are signed two's-complement). Chris@1:
Chris@1: RESIDUAL Chris@1: Chris@1: Encoded residual Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: SUBFRAME_VERBATIM Chris@1:
Chris@1: <n*i> Chris@1: Chris@1: Unencoded subblock; n = frame's bits-per-sample, i = frame's blocksize. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: RESIDUAL Chris@1:
Chris@1: <2> Chris@1: Chris@1: Residual coding method:
Chris@1:
    Chris@1:
  • Chris@1: 00 : partitioned Rice coding with 4-bit Rice parameter; RESIDUAL_CODING_METHOD_PARTITIONED_RICE follows Chris@1:
  • Chris@1:
  • Chris@1: 01 : partitioned Rice coding with 5-bit Rice parameter; RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 follows Chris@1:
  • Chris@1:
  • Chris@1: 10-11 : reserved Chris@1:
  • Chris@1:
Chris@1:
Chris@1: RESIDUAL_CODING_METHOD_PARTITIONED_RICE ||
Chris@1: RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 Chris@1:
Chris@1:   Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: RESIDUAL_CODING_METHOD_PARTITIONED_RICE Chris@1:
Chris@1: <4> Chris@1: Chris@1: Partition order. Chris@1:
Chris@1: RICE_PARTITION+ Chris@1: Chris@1: There will be 2^order partitions. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: RICE_PARTITION Chris@1:
Chris@1: <4(+5)> Chris@1: Chris@1: Encoding parameter:
Chris@1:
    Chris@1:
  • Chris@1: 0000-1110 : Rice parameter. Chris@1:
  • Chris@1:
  • Chris@1: 1111 : Escape code, meaning the partition is in unencoded binary form using n bits per sample; n follows as a 5-bit number. Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <?> Chris@1: Chris@1: Encoded residual. The number of samples (n) in the partition is determined as follows:
Chris@1:
    Chris@1:
  • Chris@1: if the partition order is zero, n = frame's blocksize - predictor order Chris@1:
  • Chris@1:
  • Chris@1: else if this is not the first partition of the subframe, n = (frame's blocksize / (2^partition order)) Chris@1:
  • Chris@1:
  • Chris@1: else n = (frame's blocksize / (2^partition order)) - predictor order Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: RESIDUAL_CODING_METHOD_PARTITIONED_RICE2 Chris@1:
Chris@1: <4> Chris@1: Chris@1: Partition order. Chris@1:
Chris@1: RICE2_PARTITION+ Chris@1: Chris@1: There will be 2^order partitions. Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1:
Chris@1: Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1: RICE2_PARTITION Chris@1:
Chris@1: <5(+5)> Chris@1: Chris@1: Encoding parameter:
Chris@1:
    Chris@1:
  • Chris@1: 0000-11110 : Rice parameter. Chris@1:
  • Chris@1:
  • Chris@1: 11111 : Escape code, meaning the partition is in unencoded binary form using n bits per sample; n follows as a 5-bit number. Chris@1:
  • Chris@1:
Chris@1:
Chris@1: <?> Chris@1: Chris@1: Encoded residual. The number of samples (n) in the partition is determined as follows:
Chris@1:
    Chris@1:
  • Chris@1: if the partition order is zero, n = frame's blocksize - predictor order Chris@1:
  • Chris@1:
  • Chris@1: else if this is not the first partition of the subframe, n = (frame's blocksize / (2^partition order)) Chris@1:
  • Chris@1:
  • Chris@1: else n = (frame's blocksize / (2^partition order)) - predictor order Chris@1:
  • Chris@1:
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: