<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>
<rfc ipr="trust200902" category="std" docName="draft-ietf-cellar-flac-00">
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc private=""?>
<?rfc topblock="yes"?>
<?rfc comments="no"?>
<front>
<title abbrev="FLAC">Free Lossless Audio Codec</title>

<author initials="J." surname="Coalson" fullname="Josh Coalson">
<organization></organization>
<address>
<postal>
<street></street>
<city></city>
<code></code>
<country></country>
<region></region>
</postal>
<phone></phone>
<email></email>
<uri></uri>
</address>
</author>
<author initials="" surname="" fullname="">
<organization>Xiph.Org Foundation</organization>
<address>
<postal>
<street></street>
<city></city>
<code></code>
<country></country>
<region></region>
</postal>
<phone></phone>
<email></email>
<uri></uri>
</address>
</author>
<author initials="A." surname="Weaver" fullname="Andrew Weaver">
<organization></organization>
<address>
<postal>
<street></street>
<city></city>
<code></code>
<country></country>
<region></region>
</postal>
<phone></phone>
<email>theandrewjw@gmail.com</email>
<uri></uri>
</address>
</author>
<date year="2019" month="July" day="29"/>

<area>art</area>
<workgroup>cellar</workgroup>
<keyword>free,lossless,audio,codec,encoder,decoder,compression,compressor,archival,archive,archiving,backup,music</keyword>


<abstract>
<t>This document defines FLAC, which stands for Free Lossless Audio Codec, a free, open source codec for lossless audio compression and decompression.
</t>
</abstract>


</front>

<middle>

<section anchor="introduction" title="Introduction">
<t>This is a detailed description of the FLAC format. There is also a companion document that describes <eref target="https://xiph.org/flac/ogg_mapping.html">FLAC-to-Ogg mapping</eref>.
</t>
<t>For a user-oriented overview, see <eref target="https://xiph.org/flac/documentation_format_overview.html">About the FLAC Format</eref>.
</t>
</section>

<section anchor="notation-and-conventions" title="Notation and Conventions">
<t>The key words &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as described in <xref target="RFC2119"/>.
</t>
</section>

<section anchor="acknowledgments" title="Acknowledgments">
<t>FLAC owes much to the many people who have advanced the audio compression field so freely. For instance:
- <eref target="http://svr-www.eng.cam.ac.uk/~ajr/">A. J. Robinson</eref> for his work on <eref target="http://svr-www.eng.cam.ac.uk/reports/abstracts/robinson_tr156.html">Shorten</eref>; his paper is a good starting point on some of the basic methods used by FLAC. FLAC trivially extends and improves the fixed predictors, LPC coefficient quantization, and Exponential-Golomb coding used in Shorten.
- <eref target="https://web.archive.org/web/20040215005354/http://csi.usc.edu/faculty/golomb.html">S. W. Golomb</eref> and Robert F. Rice; their universal codes are used by FLAC's entropy coder.
- N. Levinson and J. Durbin; the reference encoder uses an algorithm developed and refined by them for determining the LPC coefficients from the autocorrelation coefficients.
- And of course, <eref target="http://en.wikipedia.org/wiki/Claude_Shannon">Claude Shannon</eref>
</t>
</section>

<section anchor="scope" title="Scope">
<t>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.
</t>
<t>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.1 kHz, 2 channel, 16 bits per sample). The effect of the encoding parameters on different kinds of audio data will be examined later.
</t>
</section>

<section anchor="architecture" title="Architecture">
<t>Similar to many audio coders, a FLAC encoder has the following stages:
</t>
<t>
<list style="symbols">
<t><spanx style="verb">Blocking</spanx> (see <xref target="blocking"/>). The input is broken up into many contiguous blocks. With FLAC, the blocks MAY vary in size. The optimal size of the block is usually affected by many factors, including the sample rate, spectral characteristics over time, etc. Though FLAC allows the block size to vary within a stream, the reference encoder uses a fixed block size.</t>
<t><spanx style="verb">Interchannel Decorrelation</spanx> (see <xref target="interchannel-decorrelation"/>). In the case of stereo streams, the encoder will create mid and side signals based on the average and difference (respectively) of the left and right channels. The encoder will then pass the best form of the signal to the next stage.</t>
<t><spanx style="verb">Prediction</spanx> (see <xref target="prediction"/>). The block is passed through a prediction stage where the encoder tries to find a mathematical description (usually an approximate one) of the signal. This description is typically much smaller than the raw signal itself. Since the methods of prediction are known to both the encoder and decoder, only the parameters of the predictor need be included in the compressed stream. FLAC currently uses four different classes of predictors, but the format has reserved space for additional methods. FLAC allows the class of predictor to change from block to block, or even within the channels of a block.</t>
<t><spanx style="verb">Residual Coding</spanx> (See <xref target="residual-coding"/>). If the predictor does not describe the signal exactly, the difference between the original signal and the predicted signal (called the error or residual signal) MUST be coded losslessly. If the predictor is effective, the residual signal will require fewer bits per sample than the original signal. FLAC currently uses only one method for encoding the residual, but the format has reserved space for additional methods. FLAC allows the residual coding method to change from block to block, or even within the channels of a block.</t>
</list>
</t>
<t>In addition, FLAC specifies a metadata system, which allows arbitrary information about the stream to be included at the beginning of the stream.
</t>
</section>

<section anchor="definitions" title="Definitions">
<t>Many terms like &quot;block&quot; and &quot;frame&quot; are used to mean different things in different 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.
</t>
<t>
<list style="symbols">
<t><spanx style="strong">Block</spanx>: One or more audio samples that span several channels.</t>
<t><spanx style="strong">Subblock</spanx>: One or more audio samples within a channel. A block contains one subblock for each channel, and all subblocks contain the same number of samples.</t>
<t><spanx style="strong">Blocksize</spanx>: The number of samples in any of a block's subblocks. For example, a one second block sampled at 44.1 kHz has a blocksize of 44100, regardless of the number of channels.</t>
<t><spanx style="strong">Frame</spanx>: A frame header plus one or more subframes.</t>
<t><spanx style="strong">Subframe</spanx>: A subframe header plus one or more encoded samples from a given channel. All subframes within a frame will contain the same number of samples.</t>
<t><spanx style="strong">Exponential-Golomb coding</spanx>: One of Robert Rice's universal coding schemes, FLAC's residual coder, compresses data by writing the number of bits to be read minus 1, before writing the actual value.</t>
<t><spanx style="strong">LPC</spanx>: <eref target="https://en.wikipedia.org/wiki/Linear_predictive_coding">Linear predictive coding</eref>.</t>
</list>
</t>
</section>

<section anchor="blocking" title="Blocking">
<t>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.
</t>
<t>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.
</t>
<t>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, one channel of a stereo frame MAY be encoded as a constant subframe, and the other an LPC subframe.
</t>
</section>

<section anchor="interchannel-decorrelation" title="Interchannel Decorrelation">
<t>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.
</t>
<t>
<list style="symbols">
<t><spanx style="strong">Independent</spanx>. The left and right channels are coded independently.</t>
<t><spanx style="strong">Mid-side</spanx>. The left and right channels are transformed into mid and side channels. The mid channel is the midpoint (average) of the left and right signals, and the side is the difference signal (left minus right).</t>
<t><spanx style="strong">Left-side</spanx>. The left channel and side channel are coded.</t>
<t><spanx style="strong">Right-side</spanx>. The right channel and side channel are coded.</t>
</list>
</t>
<t>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.
</t>
</section>

<section anchor="prediction" title="Prediction">
<t>FLAC uses four methods for modeling the input signal:
</t>
<t>
<list style="numbers">
<t><spanx style="strong">Verbatim</spanx>. This is essentially a zero-order predictor of the signal. The predicted signal is zero, meaning the residual is the signal itself, and the compression is zero. This is the baseline against which the other predictors are measured. If you feed random data to the encoder, the verbatim predictor will probably be used for every subblock. Since the raw signal is not actually passed through the residual coding stage (it is added to the stream 'verbatim'), the encoding results will not be the same as a zero-order linear predictor.</t>
<t><spanx style="strong">Constant</spanx>. This predictor is used whenever the subblock is pure DC (&quot;digital silence&quot;), i.e. a constant value throughout. The signal is run-length encoded and added to the stream.</t>
<t><spanx style="strong">Fixed linear predictor</spanx>. FLAC uses a class of computationally-efficient fixed linear predictors (for a good description, see <eref target="http://www.hpl.hp.com/techreports/1999/HPL-1999-144.pdf">audiopak</eref> and <eref target="http://svr-www.eng.cam.ac.uk/reports/abstracts/robinson_tr156.html">shorten</eref>). FLAC adds a fourth-order predictor to the zero-to-third-order predictors used by Shorten. Since the predictors are fixed, the predictor order is the only parameter that needs to be stored in the compressed stream. The error signal is then passed to the residual coder.</t>
<t><spanx style="strong">FIR Linear prediction</spanx>. For more accurate modeling (at a cost of slower encoding), FLAC supports up to 32nd order FIR linear prediction (again, for information on linear prediction, see <eref target="http://www.hpl.hp.com/techreports/1999/HPL-1999-144.pdf">audiopak</eref> and <eref target="http://svr-www.eng.cam.ac.uk/reports/abstracts/robinson_tr156.html">shorten</eref>). The reference encoder uses the Levinson-Durbin method for calculating the LPC coefficients from the autocorrelation coefficients, and the coefficients are quantized before computing the residual. Whereas encoders such as Shorten used a fixed quantization for the entire input, FLAC allows the quantized coefficient precision to vary from subframe to subframe. The FLAC reference encoder estimates the optimal precision to use based on the block size and dynamic range of the original signal.</t>
</list>
</t>
</section>

<section anchor="residual-coding" title="Residual Coding">
<t>FLAC uses Exponential-Golomb (a variant of Rice) coding as its residual encoder. You can learn more about <eref target="https://en.wikipedia.org/wiki/Exponential-Golomb_coding">exp-golomb coding</eref> on Wikipedia.
</t>
<t>FLAC currently defines two similar methods for the coding of the error signal from the prediction stage. The error signal is coded using Exponential-Golomb codes in one of two ways:
</t>
<t>
<list style="numbers">
<t>the encoder estimates a single exp-golomb parameter based on the variance of the residual and exp-golomb codes the entire residual using this parameter;</t>
<t>the residual is partitioned into several equal-length regions of contiguous samples, and each region is coded with its own exp-golomb parameter based on the region's mean.</t>
</list>
</t>
<t>(Note that the first method is a special case of the second method with one partition, except the exp-golomb parameter is based on the residual variance instead of the mean.)
</t>
<t>The FLAC format has reserved space for other coding methods. Some possibilities for volunteers would be to explore better context-modeling of the exp-golomb parameter, or Huffman coding. See <eref target="http://www.hpl.hp.com/techreports/98/HPL-98-193.html">LOCO-I</eref> and <eref target="http://web.archive.org/web/20140827133312/http://www.cs.tut.fi/~albert/Dev/pucrunch/packing.html">pucrunch</eref> for descriptions of several universal codes.
</t>
</section>

<section anchor="format" title="Format">
<t>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.
</t>
<t>All numbers used in a FLAC bitstream MUST be integers; there are no floating-point representations. All numbers MUST be big-endian coded. All numbers MUST be unsigned unless otherwise specified.
</t>
<t>Before the formal description of the stream, an overview might be helpful.
</t>
<t>
<list style="symbols">
<t>A FLAC bitstream consists of the &quot;fLaC&quot; (i.e. 0x664C6143) marker at the beginning of the stream, followed by a mandatory metadata block (called the STREAMINFO block), any number of other metadata blocks, then the audio frames.</t>
<t>FLAC supports up to 128 kinds of metadata blocks; currently the following are defined:
<list style="symbols">
<t><spanx style="verb">STREAMINFO</spanx>: This block has information about the whole stream, like sample rate, number of channels, total number of samples, etc. It MUST be present as the first metadata block in the stream. Other metadata blocks MAY follow, and ones that the decoder doesn't understand, it will skip.</t>
<t><spanx style="verb">PADDING</spanx>: This block allows for an arbitrary amount of padding. The contents of a PADDING block have no meaning. This block is useful when it is known that metadata will be edited after encoding; the user can instruct the encoder to reserve a PADDING block of sufficient size so that when metadata is added, it will simply overwrite the padding (which is relatively quick) instead of having to insert it into the right place in the existing file (which would normally require rewriting the entire file).</t>
<t><spanx style="verb">APPLICATION</spanx>: This block is for use by third-party applications. The only mandatory field is a 32-bit identifier. This ID is granted upon request to an application by the FLAC maintainers. The remainder is of the block is defined by the registered application. Visit the <eref target="https://xiph.org/flac/id.html">registration page</eref> if you would like to register an ID for your application with FLAC.</t>
<t><spanx style="verb">SEEKTABLE</spanx>: This is an OPTIONAL block for storing seek points. It is possible to seek to any given sample in a FLAC stream without a seek table, but the delay can be unpredictable since the bitrate MAY vary widely within a stream. By adding seek points to a stream, this delay can be significantly reduced. Each seek point takes 18 bytes, so 1% resolution within a stream adds less than 2K. There can be only one SEEKTABLE in a stream, but the table can have any number of seek points. There is also a special 'placeholder' seekpoint which will be ignored by decoders but which can be used to reserve space for future seek point insertion.</t>
<t><spanx style="verb">VORBIS_COMMENT</spanx>: This block is for storing a list of human-readable name/value pairs. Values are encoded using UTF-8. It is an implementation of the <eref target="http://xiph.org/vorbis/doc/v-comment.html">Vorbis comment specification</eref> (without the framing bit). This is the only officially supported tagging mechanism in FLAC. There MUST be only zero or one VORBIS_COMMENT blocks in a stream. In some external documentation, Vorbis comments are called FLAC tags to lessen confusion.</t>
<t><spanx style="verb">CUESHEET</spanx>: This block is for storing various information that can be used in a cue sheet. It supports track and index points, compatible with Red Book CD digital audio discs, as well as other CD-DA metadata such as media catalog number and track ISRCs. The CUESHEET block is especially useful for backing up CD-DA discs, but it can be used as a general purpose cueing mechanism for playback.</t>
<t><spanx style="verb">PICTURE</spanx>: This block is for storing pictures associated with the file, most commonly cover art from CDs. There MAY be more than one PICTURE block in a file. The picture format is similar to the <eref target="http://www.id3.org/id3v2.4.0-frames">APIC frame in ID3v2</eref>. The PICTURE block has a type, MIME type, and UTF-8 description like ID3v2, and supports external linking via URL (though this is discouraged). The differences are that there is no uniqueness constraint on the description field, and the MIME type is mandatory. The FLAC PICTURE block also includes the resolution, color depth, and palette size so that the client can search for a suitable picture without having to scan them all.</t>
</list></t>
<t>The audio data is composed of one or more audio frames. Each frame consists of a frame header, which contains a sync code, information about the frame like the block size, sample rate, number of channels, et cetera, and an 8-bit CRC. The frame header also contains either the sample number of the first sample in the frame (for variable-blocksize streams), or the frame number (for fixed-blocksize streams). This allows for fast, sample-accurate seeking to be performed. Following the frame header are encoded subframes, one for each channel, and finally, the frame is zero-padded to a byte boundary. Each subframe has its own header that specifies how the subframe is encoded.</t>
<t>Since a decoder MAY start decoding in the middle of a stream, there MUST be a method to determine the start of a frame. A 14-bit sync code begins each frame. The sync code will not appear anywhere else in the frame header. However, since it MAY appear in the subframes, the decoder has two other ways of ensuring a correct sync. The first is to check that the rest of the frame header contains no invalid data. Even this is not foolproof since valid header patterns can still occur within the subframes. The decoder's final check is to generate an 8-bit CRC of the frame header and compare this to the CRC stored at the end of the frame header.</t>
<t>Again, since a decoder MAY start decoding at an arbitrary frame in the stream, each frame header MUST contain some basic information about the stream because the decoder MAY not have access to the STREAMINFO metadata block at the start of the stream. This information includes sample rate, bits per sample, number of channels, etc. Since the frame header is pure overhead, it has a direct effect on the compression ratio. To keep the frame header as small as possible, FLAC uses lookup tables for the most commonly used values for frame parameters. For instance, the sample rate part of the frame header is specified using 4 bits. Eight of the bit patterns correspond to the commonly used sample rates of 8, 16, 22.05, 24, 32, 44.1, 48 or 96 kHz. However, odd sample rates can be specified by using one of the 'hint' bit patterns, directing the decoder to find the exact sample rate at the end of the frame header. The same method is used for specifying the block size and bits per sample. In this way, the frame header size stays small for all of the most common forms of audio data.</t>
<t>Individual subframes (one for each channel) are coded separately within a frame, and appear serially in the stream. In other words, the encoded audio data is NOT channel-interleaved. This reduces decoder complexity at the cost of requiring larger decode buffers. Each subframe has its own header specifying the attributes of the subframe, like prediction method and order, residual coding parameters, etc. The header is followed by the encoded audio data for that channel.</t>
<t><spanx style="verb">FLAC</spanx> specifies a subset of itself as the Subset format. The purpose of this is to ensure that any streams encoded according to the Subset are truly &quot;streamable&quot;, meaning that a decoder that cannot seek within the stream can still pick up in the middle of the stream and start decoding. It also makes hardware decoder implementations more practical by limiting the encoding parameters such that decoder buffer sizes and other resource requirements can be easily determined. <spanx style="strong">flac</spanx> generates Subset streams by default unless the &quot;--lax&quot; command-line option is used. The Subset makes the following limitations on what MAY be used in the stream:
<list style="symbols">
<t>The blocksize bits in the <spanx style="verb">FRAME_HEADER</spanx> (see <xref target="frameheader"/>) MUST be 0b0001-0b1110. The blocksize MUST be &lt;= 16384; if the sample rate is &lt;= 48000 Hz, the blocksize MUST be &lt;= 4608 = 2^9 * 3^2.</t>
<t>The sample rate bits in the <spanx style="verb">FRAME_HEADER</spanx> MUST be 0b0001-0b1110.</t>
<t>The bits-per-sample bits in the <spanx style="verb">FRAME_HEADER</spanx> MUST be 0b001-0b111.</t>
<t>If the sample rate is &lt;= 48000 Hz, the filter order in <spanx style="verb">LPC subframes</spanx> (see <xref target="subframelpc"/>) MUST be less than or equal to 12, i.e. the subframe type bits in the <spanx style="verb">SUBFRAME_HEADER</spanx> (see <xref target="subframeheader"/>) SHOULD NOT be 0b101100-0b111111.</t>
<t>The Rice partition order in an <spanx style="verb">exp-golomb coded residual section</spanx> (see <xref target="residualcodingmethodpartitionedexpgolomb"/>) MUST be less than or equal to 8.</t>
</list></t>
</list>
</t>

<section anchor="conventions" title="Conventions">
<t>The following tables constitute a formal description of the FLAC format. Values expressed as <spanx style="verb">u(n)</spanx> represent unsigned big-endian integer using <spanx style="verb">n</spanx> bits. <spanx style="verb">n</spanx> may be expressed as an equation using <spanx style="verb">*</spanx> (multiplication), <spanx style="verb">/</spanx> (division), <spanx style="verb">+</spanx> (addition), or <spanx style="verb">-</spanx> (subtraction). An inclusive range of the number of bits expressed may be represented with an ellipsis, such as <spanx style="verb">u(m...n)</spanx>. The name of a value followed by an asterisk <spanx style="verb">*</spanx> indicates zero or more occurrences of the value. The name of a value followed by a plus sign <spanx style="verb">+</spanx> indicates one or more occurrences of the value.
</t>
</section>

<section anchor="stream" title="STREAM">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(32)</spanx></c><c>&quot;fLaC&quot;, the FLAC stream marker in ASCII, meaning byte 0 of the stream is 0x66, followed by 0x4C 0x61 0x43</c>
<c><spanx style="verb">METADATA_BLOCK_STREAMINFO</spanx></c><c>This is the mandatory STREAMINFO metadata block that has the basic properties of the stream.</c>
<c><spanx style="verb">METADATA_BLOCK</spanx>*</c><c>Zero or more metadata blocks</c>
<c><spanx style="verb">FRAME</spanx>+</c><c>One or more audio frames</c>
</texttable>
</section>

<section anchor="metadatablock" title="METADATA_BLOCK">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">METADATA_BLOCK_HEADER</spanx></c><c>A block header that specifies the type and size of the metadata block data.</c>
<c><spanx style="verb">METADATA_BLOCK_DATA</spanx></c><c></c>
</texttable>
</section>

<section anchor="metadatablockheader" title="METADATA_BLOCK_HEADER">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(1)</spanx></c><c>Last-metadata-block flag: '1' if this block is the last metadata block before the audio blocks, '0' otherwise.</c>
<c><spanx style="verb">u(7)</spanx></c><c><spanx style="verb">BLOCK_TYPE</spanx></c>
<c><spanx style="verb">u(24)</spanx></c><c>Length (in bytes) of metadata to follow (does not include the size of the <spanx style="verb">METADATA_BLOCK_HEADER</spanx>)</c>
</texttable>
</section>

<section anchor="blocktype" title="BLOCK_TYPE">
<texttable>
<ttcol align="left">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>STREAMINFO</c>
<c>1</c><c>PADDING</c>
<c>2</c><c>APPLICATION</c>
<c>3</c><c>SEEKTABLE</c>
<c>4</c><c>VORBIS_COMMENT</c>
<c>5</c><c>CUESHEET</c>
<c>6</c><c>PICTURE</c>
<c>7 - 126</c><c>reserved</c>
<c>127</c><c>invalid, to avoid confusion with a frame sync code</c>
</texttable>
</section>

<section anchor="metadatablockdata" title="METADATA_BLOCK_DATA">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">METADATA_BLOCK_STREAMINFO</spanx> || <spanx style="verb">METADATA_BLOCK_PADDING</spanx> || <spanx style="verb">METADATA_BLOCK_APPLICATION</spanx> || <spanx style="verb">METADATA_BLOCK_SEEKTABLE</spanx> || <spanx style="verb">METADATA_BLOCK_VORBIS_COMMENT</spanx> || <spanx style="verb">METADATA_BLOCK_CUESHEET</spanx> || <spanx style="verb">METADATA_BLOCK_PICTURE</spanx></c><c>The block data MUST match the block type in the block header.</c>
</texttable>
</section>

<section anchor="metadatablockstreaminfo" title="METADATA_BLOCK_STREAMINFO">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(16)</spanx></c><c>The minimum block size (in samples) used in the stream.</c>
<c><spanx style="verb">u(16)</spanx></c><c>The maximum block size (in samples) used in the stream. (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.</c>
<c><spanx style="verb">u(24)</spanx></c><c>The minimum frame size (in bytes) used in the stream. A value of <spanx style="verb">0</spanx> signifies that the value is not known.</c>
<c><spanx style="verb">u(24)</spanx></c><c>The maximum frame size (in bytes) used in the stream. A value of <spanx style="verb">0</spanx> signifies that the value is not known.</c>
<c><spanx style="verb">u(20)</spanx></c><c>Sample rate in Hz. Though 20 bits are available, the maximum sample rate is limited by the structure of frame headers to 655350 Hz. Also, a value of 0 is invalid.</c>
<c><spanx style="verb">u(3)</spanx></c><c>(number of channels)-1. FLAC supports from 1 to 8 channels</c>
<c><spanx style="verb">u(5)</spanx></c><c>(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.</c>
<c><spanx style="verb">u(36)</spanx></c><c>Total samples in stream. 'Samples' means inter-channel sample, i.e. one second of 44.1 kHz audio will have 44100 samples regardless of the number of channels. A value of zero here means the number of total samples is unknown.</c>
<c><spanx style="verb">u(128)</spanx></c><c>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.</c>
</texttable>
<t>NOTE
</t>
<t>
<list style="symbols">
<t>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.</t>
</list>
</t>
</section>

<section anchor="metadatablockpadding" title="METADATA_BLOCK_PADDING">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n)</spanx></c><c>n '0' bits (n MUST be a multiple of 8)</c>
</texttable>
</section>

<section anchor="metadatablockapplication" title="METADATA_BLOCK_APPLICATION">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(32)</spanx></c><c>Registered application ID. (Visit the <eref target="https://xiph.org/flac/id.html">registration page</eref> to register an ID with FLAC.)</c>
<c><spanx style="verb">u(n)</spanx></c><c>Application data (n MUST be a multiple of 8)</c>
</texttable>
</section>

<section anchor="metadatablockseektable" title="METADATA_BLOCK_SEEKTABLE">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">SEEKPOINT</spanx>+</c><c>One or more seek points.</c>
</texttable>
<t>NOTE
- The number of seek points is implied by the metadata header 'length' field, i.e. equal to length / 18.
</t>
</section>

<section anchor="seekpoint" title="SEEKPOINT">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(64)</spanx></c><c>Sample number of first sample in the target frame, or <spanx style="verb">0xFFFFFFFFFFFFFFFF</spanx> for a placeholder point.</c>
<c><spanx style="verb">u(64)</spanx></c><c>Offset (in bytes) from the first byte of the first frame header to the first byte of the target frame's header.</c>
<c><spanx style="verb">u(16)</spanx></c><c>Number of samples in the target frame.</c>
</texttable>
<t>NOTES
</t>
<t>
<list style="symbols">
<t>For placeholder points, the second and third field values are undefined.</t>
<t>Seek points within a table MUST be sorted in ascending order by sample number.</t>
<t>Seek points within a table MUST be unique by sample number, with the exception of placeholder points.</t>
<t>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.</t>
</list>
</t>
</section>

<section anchor="metadatablockvorbiscomment" title="METADATA_BLOCK_VORBIS_COMMENT">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n)</spanx></c><c>Also known as FLAC tags, the contents of a vorbis comment packet as specified <eref target="http://www.xiph.org/vorbis/doc/v-comment.html">here</eref> (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.</c>
</texttable>
</section>

<section anchor="metadatablockcuesheet" title="METADATA_BLOCK_CUESHEET">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(128*8)</spanx></c><c>Media catalog number, in ASCII printable characters 0x20-0x7E. In general, the media catalog number SHOULD 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.</c>
<c><spanx style="verb">u(64)</spanx></c><c>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.</c>
<c><spanx style="verb">u(1)</spanx></c><c><spanx style="verb">1</spanx> if the CUESHEET corresponds to a Compact Disc, else <spanx style="verb">0</spanx>.</c>
<c><spanx style="verb">u(7+258*8)</spanx></c><c>Reserved. All bits MUST be set to zero.</c>
<c><spanx style="verb">u(8)</spanx></c><c>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).</c>
<c><spanx style="verb">CUESHEET_TRACK</spanx>+</c><c>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 it MUST be 255.</c>
</texttable>
</section>

<section anchor="cuesheettrack" title="CUESHEET_TRACK">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(64)</spanx></c><c>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/s * 1/75 s).</c>
<c><spanx style="verb">u(8)</spanx></c><c>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.</c>
<c><spanx style="verb">u(12*8)</spanx></c><c>Track ISRC. This is a 12-digit alphanumeric code; see <eref target="http://isrc.ifpi.org/">here</eref> and <eref target="http://www.disctronics.co.uk/technology/cdaudio/cdaud_isrc.htm">here</eref>. A value of 12 ASCII NUL characters MAY be used to denote absence of an ISRC.</c>
<c><spanx style="verb">u(1)</spanx></c><c>The track type: 0 for audio, 1 for non-audio. This corresponds to the CD-DA Q-channel control bit 3.</c>
<c><spanx style="verb">u(1)</spanx></c><c>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 <eref target="http://www.chipchapin.com/CDMedia/cdda9.php3">here</eref>.</c>
<c><spanx style="verb">u(6+13*8)</spanx></c><c>Reserved. All bits MUST be set to zero.</c>
<c><spanx style="verb">u(8)</spanx></c><c>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 SHOULD NOT be more than 100.</c>
<c><spanx style="verb">CUESHEET_TRACK_INDEX</spanx>+</c><c>For all tracks except the lead-out track, one or more track index points.</c>
</texttable>
</section>

<section anchor="cuesheettrackindex" title="CUESHEET_TRACK_INDEX">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(64)</spanx></c><c>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/s * 1/75 s). Note that the offset is from the beginning of the track, not the beginning of the audio data.</c>
<c><spanx style="verb">u(8)</spanx></c><c>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.</c>
<c><spanx style="verb">u(3*8)</spanx></c><c>Reserved. All bits MUST be set to zero.</c>
</texttable>
</section>

<section anchor="metadatablockpicture" title="METADATA_BLOCK_PICTURE">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(32)</spanx></c><c>The PICTURE_TYPE according to the ID3v2 APIC frame.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The length of the MIME type string in bytes.</c>
<c><spanx style="verb">u(n*8)</spanx></c><c>The MIME type string, in printable ASCII characters 0x20-0x7E. The MIME type MAY also be <spanx style="verb">--&gt;</spanx> to signify that the data part is a URL of the picture instead of the picture data itself.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The length of the description string in bytes.</c>
<c><spanx style="verb">u(n*8)</spanx></c><c>The description of the picture, in UTF-8.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The width of the picture in pixels.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The height of the picture in pixels.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The color depth of the picture in bits-per-pixel.</c>
<c><spanx style="verb">u(32)</spanx></c><c>For indexed-color pictures (e.g. GIF), the number of colors used, or <spanx style="verb">0</spanx> for non-indexed pictures.</c>
<c><spanx style="verb">u(32)</spanx></c><c>The length of the picture data in bytes.</c>
<c><spanx style="verb">u(n*8)</spanx></c><c>The binary picture data.</c>
</texttable>
</section>

<section anchor="picturetype" title="PICTURE_TYPE">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>Other</c>
<c>1</c><c>32x32 pixels 'file icon' (PNG only)</c>
<c>2</c><c>Other file icon</c>
<c>3</c><c>Cover (front)</c>
<c>4</c><c>Cover (back)</c>
<c>5</c><c>Leaflet page</c>
<c>6</c><c>Media (e.g. label side of CD)</c>
<c>7</c><c>Lead artist/lead performer/soloist</c>
<c>8</c><c>Artist/performer</c>
<c>9</c><c>Conductor</c>
<c>10</c><c>Band/Orchestra</c>
<c>11</c><c>Composer</c>
<c>12</c><c>Lyricist/text writer</c>
<c>13</c><c>Recording Location</c>
<c>14</c><c>During recording</c>
<c>15</c><c>During performance</c>
<c>16</c><c>Movie/video screen capture</c>
<c>17</c><c>A bright colored fish</c>
<c>18</c><c>Illustration</c>
<c>19</c><c>Band/artist logotype</c>
<c>20</c><c>Publisher/Studio logotype</c>
</texttable>
<t>Other values are reserved and SHOULD NOT be used. There MAY only be one each of picture type 1 and 2 in a file.
</t>
</section>

<section anchor="frame" title="FRAME">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">FRAME_HEADER</spanx></c><c></c>
<c><spanx style="verb">SUBFRAME</spanx>+</c><c>One SUBFRAME per channel.</c>
<c><spanx style="verb">u(?)</spanx></c><c>Zero-padding to byte alignment.</c>
<c><spanx style="verb">FRAME_FOOTER</spanx></c><c></c>
</texttable>
</section>

<section anchor="frameheader" title="FRAME_HEADER">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(14)</spanx></c><c>Sync code '0b11111111111110'</c>
<c><spanx style="verb">u(1)</spanx></c><c><spanx style="verb">FRAME HEADER RESERVED</spanx></c>
<c><spanx style="verb">u(1)</spanx></c><c><spanx style="verb">BLOCKING STRATEGY</spanx></c>
<c><spanx style="verb">u(4)</spanx></c><c><spanx style="verb">INTERCHANNEL SAMPLE BLOCK SIZE</spanx></c>
<c><spanx style="verb">u(4)</spanx></c><c><spanx style="verb">SAMPLE RATE</spanx></c>
<c><spanx style="verb">u(4)</spanx></c><c><spanx style="verb">CHANNEL ASSIGNMENT</spanx></c>
<c><spanx style="verb">u(3)</spanx></c><c><spanx style="verb">SAMPLE SIZE</spanx></c>
<c><spanx style="verb">u(1)</spanx></c><c><spanx style="verb">FRAME HEADER RESERVED2</spanx></c>
<c><spanx style="verb">u(?)</spanx></c><c><spanx style="verb">CODED NUMBER</spanx></c>
<c><spanx style="verb">u(?)</spanx></c><c><spanx style="verb">BLOCK SIZE INT</spanx></c>
<c><spanx style="verb">u(?)</spanx></c><c><spanx style="verb">SAMPLE RATE INT</spanx></c>
<c><spanx style="verb">u(8)</spanx></c><c><spanx style="verb">FRAME CRC</spanx></c>
</texttable>

<section anchor="frame-header-reserved" title="FRAME HEADER RESERVED">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>mandatory value</c>
<c>1</c><c>reserved for future use</c>
</texttable>
<t>FRAME HEADER RESERVED MUST remain reserved for <spanx style="verb">0</spanx> in order for a FLAC frame's initial 15 bits to be distinguishable from the start of an MPEG audio frame (<eref target="http://lists.xiph.org/pipermail/flac-dev/2008-December/002607.html">see also</eref>).
</t>
</section>

<section anchor="blocking-strategy" title="BLOCKING STRATEGY">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>fixed-blocksize stream; frame header encodes the frame number</c>
<c>1</c><c>variable-blocksize stream; frame header encodes the sample number</c>
</texttable>
<t>The <spanx style="verb">BLOCKING STRATEGY</spanx> bit MUST be the same throughout the entire stream.
</t>
<t>The <spanx style="verb">BLOCKING STRATEGY</spanx> bit determines how to calculate the sample number of the first sample in the frame. If the bit is <spanx style="verb">0</spanx> (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 <spanx style="verb">1</spanx> (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).
</t>
</section>

<section anchor="interchannel-sample-block-size" title="INTERCHANNEL SAMPLE BLOCK SIZE">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b0000</c><c>reserved</c>
<c>0b0001</c><c>192 samples</c>
<c>0b0010 - 0b0101</c><c>576 * (2^(n-2)) samples, i.e. 576, 1152, 2304 or 4608</c>
<c>0b0110</c><c>get 8 bit (blocksize-1) from end of header</c>
<c>0b0111</c><c>get 16 bit (blocksize-1) from end of header</c>
<c>0b1000 - 0b1111</c><c>256 * (2^(n-8)) samples, i.e. 256, 512, 1024, 2048, 4096, 8192, 16384 or 32768</c>
</texttable>
</section>

<section anchor="sample-rate" title="SAMPLE RATE">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b0000</c><c>get from STREAMINFO metadata block</c>
<c>0b0001</c><c>88.2 kHz</c>
<c>0b0010</c><c>176.4 kHz</c>
<c>0b0011</c><c>192 kHz</c>
<c>0b0100</c><c>8 kHz</c>
<c>0b0101</c><c>16 kHz</c>
<c>0b0110</c><c>22.05 kHz</c>
<c>0b0111</c><c>24 kHz</c>
<c>0b1000</c><c>32 kHz</c>
<c>0b1001</c><c>44.1 kHz</c>
<c>0b1010</c><c>48 kHz</c>
<c>0b1011</c><c>96 kHz</c>
<c>0b1100</c><c>get 8 bit sample rate (in kHz) from end of header</c>
<c>0b1101</c><c>get 16 bit sample rate (in Hz) from end of header</c>
<c>0b1110</c><c>get 16 bit sample rate (in daHz) from end of header</c>
<c>0b1111</c><c>invalid, to prevent sync-fooling string of 1s</c>
</texttable>
</section>

<section anchor="channel-assignment" title="CHANNEL ASSIGNMENT">
<t>For values 0b0000-0b0111, the value represents the (number of independent channels)-1. Where defined, the channel order follows SMPTE/ITU-R recommendations.
</t>
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b0000</c><c>1 channel: mono</c>
<c>0b0001</c><c>2 channels: left, right</c>
<c>0b0010</c><c>3 channels: left, right, center</c>
<c>0b0011</c><c>4 channels: front left, front right, back left, back right</c>
<c>0b0100</c><c>5 channels: front left, front right, front center, back/surround left, back/surround right</c>
<c>0b0101</c><c>6 channels: front left, front right, front center, LFE, back/surround left, back/surround right</c>
<c>0b0110</c><c>7 channels: front left, front right, front center, LFE, back center, side left, side right</c>
<c>0b0111</c><c>8 channels: front left, front right, front center, LFE, back left, back right, side left, side right</c>
<c>0b1000</c><c>left/side stereo: channel 0 is the left channel, channel 1 is the side(difference) channel</c>
<c>0b1001</c><c>right/side stereo: channel 0 is the side(difference) channel, channel 1 is the right channel</c>
<c>0b1010</c><c>mid/side stereo: channel 0 is the mid(average) channel, channel 1 is the side(difference) channel</c>
<c>0b1011 - 0b1111</c><c>reserved</c>
</texttable>
</section>

<section anchor="sample-size" title="SAMPLE SIZE">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b000</c><c>get from STREAMINFO metadata block</c>
<c>0b001</c><c>8 bits per sample</c>
<c>0b010</c><c>12 bits per sample</c>
<c>0b011</c><c>reserved</c>
<c>0b100</c><c>16 bits per sample</c>
<c>0b101</c><c>20 bits per sample</c>
<c>0b110</c><c>24 bits per sample</c>
<c>0b111</c><c>reserved</c>
</texttable>
<t>For subframes that encode a difference channel, the sample size is one bit larger than the sample size of the frame, in order to be able to encode the difference between extreme values.
</t>
</section>

<section anchor="frame-header-reserved2" title="FRAME HEADER RESERVED2">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>mandatory value</c>
<c>1</c><c>reserved for future use</c>
</texttable>
</section>

<section anchor="coded-number" title="CODED NUMBER">
<t>Frame/Sample numbers are encoded using the UTF-8 format, from BEFORE it was limited to 4 bytes by RFC3629, this variant supports the original 7 byte maximum.
</t>
<t>Note to implementors: All Unicode compliant UTF-8 decoders and encoders are limited to 4 bytes, it's best to just write your own one off solution.
</t>

<figure align="center"><artwork align="center">
if(variable blocksize)
  `u(8...56)`: "UTF-8" coded sample number (decoded number is 36 bits)
else
  `u(8...48)`: "UTF-8" coded frame number (decoded number is 31 bits)
</artwork></figure>
</section>

<section anchor="block-size-int" title="BLOCK SIZE INT">

<figure align="center"><artwork align="center">
if(`INTERCHANNEL SAMPLE BLOCK SIZE` == 0b0110)
  8 bit (blocksize-1)
else if(`INTERCHANNEL SAMPLE BLOCK SIZE` == 0b0111)
  16 bit (blocksize-1)
</artwork></figure>
</section>

<section anchor="sample-rate-int" title="SAMPLE RATE INT">

<figure align="center"><artwork align="center">
if(`SAMPLE RATE` == 0b1100)
  8 bit sample rate (in kHz)
else if(`SAMPLE RATE` == 0b1101)
  16 bit sample rate (in Hz)
else if(`SAMPLE RATE` == 0b1110)
  16 bit sample rate (in daHz)
</artwork></figure>
</section>

<section anchor="frame-crc" title="FRAME CRC">
<t>CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0) of everything before the CRC, including the sync code
</t>
</section>
</section>

<section anchor="framefooter" title="FRAME_FOOTER">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(16)</spanx></c><c>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</c>
</texttable>
</section>

<section anchor="subframe" title="SUBFRAME">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">SUBFRAME_HEADER</spanx></c><c></c>
<c><spanx style="verb">SUBFRAME_CONSTANT</spanx> || <spanx style="verb">SUBFRAME_FIXED</spanx> || <spanx style="verb">SUBFRAME_LPC</spanx> || <spanx style="verb">SUBFRAME_VERBATIM</spanx></c><c>The SUBFRAME_HEADER specifies which one.</c>
</texttable>
</section>

<section anchor="subframeheader" title="SUBFRAME_HEADER">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(1)</spanx></c><c>Zero bit padding, to prevent sync-fooling string of 1s</c>
<c><spanx style="verb">u(6)</spanx></c><c><spanx style="verb">SUBFRAME TYPE</spanx> (see <xref target="subframe-type"/>)</c>
<c><spanx style="verb">u(1+k)</spanx></c><c><spanx style="verb">WASTED BITS PER SAMPLE FLAG</spanx> (see <xref target="wasted-bits-per-sample-flag"/>)</c>
</texttable>

<section anchor="subframe-type" title="SUBFRAME TYPE">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b000000</c><c><spanx style="verb">SUBFRAME_CONSTANT</spanx></c>
<c>0b000001</c><c><spanx style="verb">SUBFRAME_VERBATIM</spanx></c>
<c>0b00001x</c><c>reserved</c>
<c>0b0001xx</c><c>reserved</c>
<c>0b001xxx</c><c>if(xxx &lt;= 4) <spanx style="verb">SUBFRAME_FIXED</spanx>, xxx=order; else reserved</c>
<c>0b01xxxx</c><c>reserved</c>
<c>0b1xxxxx</c><c><spanx style="verb">SUBFRAME_LPC</spanx>, xxxxx=order-1</c>
</texttable>
</section>

<section anchor="wasted-bits-per-sample-flag" title="WASTED BITS PER SAMPLE FLAG">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0</c><c>no wasted bits-per-sample in source subblock, k=0</c>
<c>1</c><c>k wasted bits-per-sample in source subblock, k-1 follows, unary coded; e.g. k=3 =&gt; 0b001 follows, k=7 =&gt; 0b0000001 follows.</c>
</texttable>
<t>The size of the samples stored in the subframe is the subframe sample size reduced by k bits. Decoded samples must be shifted left by k bits.
</t>
</section>
</section>

<section anchor="subframeconstant" title="SUBFRAME_CONSTANT">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n)</spanx></c><c>Unencoded constant value of the subblock, n = frame's bits-per-sample.</c>
</texttable>
</section>

<section anchor="subframefixed" title="SUBFRAME_FIXED">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n)</spanx></c><c>Unencoded warm-up samples (n = frame's bits-per-sample * predictor order).</c>
<c><spanx style="verb">RESIDUAL</spanx></c><c>Encoded residual</c>
</texttable>
</section>

<section anchor="subframelpc" title="SUBFRAME_LPC">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n)</spanx></c><c>Unencoded warm-up samples (n = frame's bits-per-sample * lpc order).</c>
<c><spanx style="verb">u(4)</spanx></c><c>(quantized linear predictor coefficients' precision in bits)-1 (NOTE: 0b1111 is invalid).</c>
<c><spanx style="verb">u(5)</spanx></c><c>Quantized linear predictor coefficient shift needed in bits (NOTE: this number is signed two's-complement).</c>
<c><spanx style="verb">u(n)</spanx></c><c>Unencoded predictor coefficients (n = qlp coeff precision * lpc order) (NOTE: the coefficients are signed two's-complement).</c>
<c><spanx style="verb">RESIDUAL</spanx></c><c>Encoded residual</c>
</texttable>
</section>

<section anchor="subframeverbatim" title="SUBFRAME_VERBATIM">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(n\*i)</spanx></c><c>Unencoded subblock, where <spanx style="verb">n</spanx> is frame's bits-per-sample and <spanx style="verb">i</spanx> is frame's blocksize.</c>
</texttable>
</section>

<section anchor="residual" title="RESIDUAL">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(2)</spanx></c><c><spanx style="verb">RESIDUAL_CODING_METHOD</spanx></c>
<c><spanx style="verb">RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB</spanx> || <spanx style="verb">RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB2</spanx></c><c></c>
</texttable>

<section anchor="residualcodingmethod" title="RESIDUAL_CODING_METHOD">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b00</c><c>partitioned Exp-Golomb coding with 4-bit Exp-Golomb parameter; RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB follows</c>
<c>0b01</c><c>partitioned Exp-Golomb coding with 5-bit Exp-Golomb parameter; RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB2 follows</c>
<c>0b10 - 0b11</c><c>reserved</c>
</texttable>
</section>

<section anchor="residualcodingmethodpartitionedexpgolomb" title="RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(4)</spanx></c><c>Partition order.</c>
<c><spanx style="verb">EXP_GOLOMB_PARTITION</spanx>+</c><c>There will be 2^order partitions.</c>
</texttable>

<section anchor="expgolombpartition" title="EXP_GOLOMB_PARTITION">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(4(+5))</spanx></c><c><spanx style="verb">EXP-GOLOMB PARTITION ENCODING PARAMETER</spanx> (see <xref target="exp-golomb-partition-encoding-parameter"/>)</c>
<c><spanx style="verb">u(?)</spanx></c><c><spanx style="verb">ENCODED RESIDUAL</spanx> (see <xref target="encoded-residual"/>)</c>
</texttable>
</section>

<section anchor="exp-golomb-partition-encoding-parameter" title="EXP GOLOMB PARTITION ENCODING PARAMETER">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b0000 - 0b1110</c><c>Exp-golomb parameter.</c>
<c>0b1111</c><c>Escape code, meaning the partition is in unencoded binary form using n bits per sample; n follows as a 5-bit number.</c>
</texttable>
</section>
</section>

<section anchor="residualcodingmethodpartitionedexpgolomb2" title="RESIDUAL_CODING_METHOD_PARTITIONED_EXP_GOLOMB2">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(4)</spanx></c><c>Partition order.</c>
<c><spanx style="verb">EXP-GOLOMB2_PARTITION</spanx>+</c><c>There will be 2^order partitions.</c>
</texttable>

<section anchor="expgolomb2partition" title="EXP_GOLOMB2_PARTITION">
<texttable>
<ttcol align="left">Data</ttcol>
<ttcol align="left">Description</ttcol>

<c><spanx style="verb">u(5(+5))</spanx></c><c><spanx style="verb">EXP-GOLOMB2 PARTITION ENCODING PARAMETER</spanx> (see <xref target="expgolomb2-partition-encoding-parameter"/>)</c>
<c><spanx style="verb">u(?)</spanx></c><c><spanx style="verb">ENCODED RESIDUAL</spanx> (see <xref target="encoded-residual"/>)</c>
</texttable>
</section>

<section anchor="expgolomb2-partition-encoding-parameter" title="EXP-GOLOMB2 PARTITION ENCODING PARAMETER">
<texttable>
<ttcol align="right">Value</ttcol>
<ttcol align="left">Description</ttcol>

<c>0b00000 - 0b11110</c><c>Exp-golomb parameter.</c>
<c>0b11111</c><c>Escape code, meaning the partition is in unencoded binary form using n bits per sample; n follows as a 5-bit number.</c>
</texttable>
</section>
</section>

<section anchor="encoded-residual" title="ENCODED RESIDUAL">
<t>The number of samples (n) in the partition is determined as follows:
</t>
<t>
<list style="symbols">
<t>if the partition order is zero, n = frame's blocksize - predictor order</t>
<t>else if this is not the first partition of the subframe, n = (frame's blocksize / (2^partition order))</t>
<t>else n = (frame's blocksize / (2^partition order)) - predictor order</t>
</list>
</t>
</section>
</section>
</section>

</middle>
<back>
<references title="Normative References">
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
</references>

</back>
</rfc>
