add baudline to the list of progs that use flac
[flac.git] / doc / format.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <HTML>
3 <HEAD>
4         <TITLE>FLAC - format</TITLE>
5 </HEAD>
6
7 <BODY MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" RIGHTMARGIN="0" TOPMARGIN="0" BGCOLOR="#99CC99" TEXT="#000000" LINK="#336699" VLINK="#336699" ALINK="#336699">
8
9 <TABLE BORDER=0 WIDTH="100%" CELLPADDING=1 CELLSPACING=0>
10         <TR>
11                 <TD ALIGN="CENTER" BGCOLOR="#000000"><A HREF="http://flac.sourceforge.net/"><IMG SRC="images/logo.jpg" ALIGN=CENTER ALT="FLAC Logo" BORDER=0 HSPACE=0></a></TD>
12         </TR>
13 </TABLE>
14
15 <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#99CC99"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="25" ALT=""></TD></TR></TABLE>
16
17 <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#000000"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="2" ALT=""></TD></TR></TABLE>
18
19 <TABLE WIDTH="100%" CELLPADDING=0 CELLSPACING=0 BORDER=0>
20         <TR>
21                 <TD ALIGN="CENTER" BGCOLOR="#D3D4C5">
22                         <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
23                                 <TR>
24                                         <TD HEIGHT=22 BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="index.html">home</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
25                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="news.html">news</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
26                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="download.html">download</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
27                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="features.html">features</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
28                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="goals.html">goals</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
29                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;format&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
30                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="id.html">id</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
31                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="comparison.html">comparison</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
32                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="documentation.html">documentation</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
33                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="developers.html">developers</A>&nbsp;&nbsp;</TD>
34                                 </TR>
35                         </TABLE>
36                 </TD>
37         </TR>
38 </TABLE>
39
40 <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#000000"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="2" ALT=""></TD></TR></TABLE>
41
42 <CENTER>
43
44 <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#99CC99"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="15" ALT=""></TD></TR></TABLE>
45
46
47 <TABLE WIDTH="100%" CELLPADDING="5" CELLSPACING="5" BORDER="0">
48 <TR><TD>
49         <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#000000"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="1" ALT=""></TD></TR></TABLE>
50         <TABLE CELLSPACING="0" CELLPADDING="3" WIDTH="100%" BORDER="0" BGCOLOR="#D3D4C5">
51                 <TR><TD><FONT FACE="Lucida,Verdana,Helvetica,Arial">
52                 <B><FONT SIZE="+2">format</FONT></B>
53                 </FONT></TD></TR>
54         </TABLE>
55         <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#000000"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="1" ALT=""></TD></TR></TABLE>
56         <TABLE CELLSPACING="0" CELLPADDING="3" WIDTH="100%" BORDER="0" BGCOLOR="#EEEED4">
57         <TR><TD><FONT FACE="Lucida,Verdana,Helvetica,Arial">
58         <P>
59                 This is a detailed description of the FLAC format.  The format is currently in the beta stage, which means it will not change in a way that will break backward compatibility unless a bug related to the format is found.  Until the first official release you should probably not use FLAC for archiving unless you keep your beta binaries.
60         </P>
61         <P>
62                 First, as the original developer I have to say that I am not a compression expert and I feel obligated to give credit where it is due.  FLAC owes a lot to the many people who have advanced the audio compression field so freely.  For instance:
63         </P>
64         <P>
65         <UL>
66                 <LI>
67                         <A HREF="http://svr-www.eng.cam.ac.uk/~ajr/">A. J. Robinson</A> for his work on <A HREF="http://svr-www.eng.cam.ac.uk/~ajr/GroupPubs/Robinson94-tr156/index.html">Shorten</A>; his code and paper are a good starting point on some of the basic methods used by FLAC.  FLAC expands on the fixed predictors used in shorten.
68                 </LI>
69                 <LI>
70                         <A HREF="http://commsci.usc.edu/faculty/golomb.html">S. W. Golomb</A> and Robert F. Rice; their universal codes are used by FLAC's entropy coder.
71                 </LI>
72                 <LI>
73                         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.
74                 </LI>
75                 <LI>
76                         And of course, the main guy, <A HREF="http://www.digitalcentury.com/encyclo/update/shannon.html">Claude Shannon</A>
77                 </LI>
78         </UL>
79         </P>
80         <P>
81                 <A NAME="scope"><FONT SIZE="+1"><B><U>Scope</U></B></FONT></A>
82         </P>
83         <P>
84                 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 <B>code</B> 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.
85         </P>
86         <P>
87                 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.
88         </P>
89         <P>
90                 <A NAME="architecture"><FONT SIZE="+1"><B><U>Architecture</U></B></FONT></A>
91         </P>
92         <P>
93                 Similar to many audio coders, a FLAC encoder has the following stages:
94         </P>
95         <UL>
96                 <P><LI>
97                         <A HREF="#blocking">Blocking</A>.  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.
98                 </LI></P>
99                 <P><LI>
100                         <A HREF="#interchannel">Interchannel Decorrelation</A>.  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.
101                 </LI></P>
102                 <P><LI>
103                         <A HREF="#prediction">Prediction</A>.  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 (described in the <A HREF="#prediction">prediction</A> section), 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.
104                 </LI></P>
105                 <LI><P>
106                         <A HREF="#residualcoding">Residual coding</A>.  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 losslessy.  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 (see the <A HREF="#residualcoding">Residual coding</A> section), 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.
107                 </LI></P>
108         </UL>
109         <P>
110                 In addition, FLAC specifies a metadata system, which allows arbitrary information about the stream to be included at the beginning of the stream.
111         </P>
112         <P>
113                 <A NAME="definitions"><FONT SIZE="+1"><B><U>Definitions</U></B></FONT></A>
114         </P>
115         <P>
116                 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 refering to the raw unencoded audio data that is the input to the encoder, and when we talk about frames and subframes, we are refering to the FLAC-encoded data.
117         </P>
118         <UL>
119                 <P><LI>
120                         <B>Block</B>: One or more audio samples that span several channels.
121                 </LI></P>
122                 <P><LI>
123                         <B>Subblock</B>: One or more audio samples within a channel.  So a block contains one subblock for each channel, and all subblocks contain the same number of samples.
124                 </LI></P>
125                 <P><LI>
126                         <B>Blocksize</B>: The number of samples in any of a block's subblocks.  For example, a one second block sampled at 44.1KHz has a blocksize of 44100, regardless of the number of channels.
127                 </LI></P>
128                 <P><LI>
129                         <B>Frame</B>: A frame header plus one or more subframes.
130                 </LI></P>
131                 <P><LI>
132                         <B>Subframe</B>: 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.
133                 </LI></P>
134         </UL>
135         <P>
136                 <A NAME="blocking"><FONT SIZE="+1"><B><U>Blocking</U></B></FONT></A>
137         </P>
138         <P>
139                 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.
140         </P>
141         <P>
142                 Currently the reference encoder uses a fixed block size, optimized on the sample rate of the input.  Future version may vary the block size depending on the characteristics of the signal.
143         </P>
144         <P>
145                 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.
146         </P>
147         <P>
148                 <A NAME="interchannel"><FONT SIZE="+1"><B><U>Interchannel Decorrelation</U></B></FONT></A>
149         </P>
150         <P>
151                 In stereo streams, in many cases 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.
152         </P>
153         <UL>
154                 <P><LI>
155                         <B>Independent</B>.  The left and right channels are coded independently.
156                 </LI></P>
157                 <P><LI>
158                         <B>Mid-side</B>.  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).
159                 </LI></P>
160                 <P><LI>
161                         <B>Left-side</B>.  The left channel and side channel are coded.
162                 </LI></P>
163                 <P><LI>
164                         <B>Right-side</B>.  The right channel and side channel are coded
165                 </LI></P>
166         </UL>
167         <P>
168                 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.
169         </P>
170         <P>
171                 <A NAME="prediction"><FONT SIZE="+1"><B><U>Prediction</U></B></FONT></A>
172         </P>
173         <P>
174                 FLAC uses four methods for modeling the input signal:
175         </P>
176         <UL>
177                 <P><LI>
178                         <B>Verbatim</B>.  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.
179                 </LI></P>
180                 <P><LI>
181                         <B>Constant</B>.  This predictor is used whenever the subblock is pure DC ("digital silence"), i.e. a constant value throughout.  The signal is run-length encoded and added to the stream.
182                 </LI></P>
183                 <P><LI>
184                         <B>Fixed linear predictor</B>.  FLAC uses a class of computationally-efficient fixed linear predictors (for a good description, see <A HREF="http://www.hpl.hp.com/techreports/1999/HPL-1999-144.pdf">audiopak</A> and <A HREF="http://svr-www.eng.cam.ac.uk/~ajr/GroupPubs/Robinson94-tr156/index.html">shorten</A>).  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.
185                 </LI></P>
186                 <P><LI>
187                         <B>FIR Linear prediction</B>.  For more accurate modeling (at a cost of slower encoding), FLAC supports up to 32nd order FIR linear prediction (again, for info on linear prediction, see <A HREF="http://www.hpl.hp.com/techreports/1999/HPL-1999-144.pdf">audiopak</A> and <A HREF="http://svr-www.eng.cam.ac.uk/~ajr/GroupPubs/Robinson94-tr156/index.html">shorten</A>).  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.
188                 </LI></P>
189         </UL>
190         <P>
191                 <A NAME="residualcoding"><FONT SIZE="+1"><B><U>Residual Coding</U></B></FONT></A>
192         </P>
193         <P>
194                 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.)
195         </P>
196         <P>
197                 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 <A HREF="http://www.hpl.hp.com/techreports/98/HPL-98-193.html">LOCO-I</A> and <A HREF="http://www.cs.tut.fi/~albert/Dev/pucrunch/packing.html">pucrunch</A> for descriptions of several universal codes.
198         </P>
199         <P>
200                 <FONT SIZE="+1"><B><U>Format</U></B></FONT>
201         </P>
202         <P>
203                 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.
204         </P>
205         <P>
206                 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.
207         </P>
208         <P>
209                 <A NAME="overview">A FLAC bitstream may be appended with ID3V1 data or prepended with ID3V2 data.  FLAC has no knowledge of such data, but the reference decoder knows how to skip an ID3 tag.  The input plugins support ID3V1 tags</A>
210         </P>
211         <P>
212                 Before the formal description of the stream, an overview might be helpful.
213         </P>
214         <UL>
215                 <P><LI>
216                         A FLAC bitstream consists of the "fLaC" 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.
217                 </LI></P>
218                 <P><LI>
219                         FLAC supports up to 128 kinds of metadata blocks; currently the following are defined:
220                         <UL>
221                                 <LI><A NAME="def_STREAMINFO"><B>STREAMINFO</B>: 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.</LI>
222                                 <LI><A NAME="def_APPLICATION"><B>APPLICATION</B>: 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 <A HREF="id.html">registration page</A> if you would like to register an ID for your application with FLAC.</LI>
223                                 <LI><A NAME="def_PADDING"><B>PADDING</B>: This block allows for an arbitrary amount of padding.  The contents of a PADDING block have no meaning.  This block useful when it is known that an APPLICATION block will be added after encoding; the user can instruct the encoder to reserve a PADDING block of the proper size so that the application may directly write over it later (which is relatively quick) instead of having to insert the APPLICATION block (which would normally require rewriting the entire file).</LI>
224                                 <LI><A NAME="def_SEEKTABLE"><B>SEEKTABLE</B>: 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.</LI>
225                         </UL>
226                 </LI></P>
227                 <P><LI>
228                         The audio data is composed of one or more audio frames.  Each frame consists of a frame header, which contains a sync code, info 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.
229                 </LI></P>
230                 <P><LI>
231                         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.
232                 </LI></P>
233                 <P><LI>
234                         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/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.
235                 </LI></P>
236                 <P><LI>
237                         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.
238                 </LI></P>
239                 <P><LI>
240                         FLAC 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 "streamable", 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 blocking such that decoder buffer sizes can be easily determined.  "flac" generates Subset streams by default unless the "--lax" command-line option is used.  The Subset makes the following limitations on what may be used in the stream:
241                         <UL>
242                         <LI>
243                                 The blocksize bits in the <A HREF="#frame_header">frame header</A> must be 0001-0101 or 1000-1111, specifying a fixed-blocksize stream (the exception being the last block as described in the table).  This also means that the STREAMINFO metadata block must specify equal mininum and maximum blocksizes.
244                         </LI>
245                         <LI>
246                                 The bits-per-sample bits in the <A HREF="#frame_header">frame header</A> must be 001-110.
247                         </LI>
248                         <LI>
249                                 The sample rate bits in the <A HREF="#frame_header">frame header</A> must be 0001-1011.
250                         </LI>
251                         </UL>
252                 </LI></P>
253         </UL>
254
255         <P>
256                 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.
257         </P>
258
259         </FONT>
260         </TD></TR>
261         </TABLE>
262         <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"><TR BGCOLOR="#000000"><TD><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="1" ALT=""></TD></TR></TABLE>
263
264         <P>
265         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
266         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
267                 <TR>
268                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
269                                 <A NAME="stream"><FONT SIZE="+1"><B>STREAM</B></FONT></A>
270                         </TD>
271                 </TR>
272                 <TR>
273                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
274                                 &lt;32&gt;
275                         </TD>
276                         <TD>
277                                 "fLaC", the FLAC stream marker in ASCII, meaning byte 0 of the stream is 0x66, followed by 0x4C 0x61 0x43
278                         </TD>
279                 </TR>
280                 <TR>
281                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
282                                 <A HREF="#metadata_streaminfo_block"><I>METADATA_BLOCK</I></A>
283                         </TD>
284                         <TD>
285                                 This is the mandatory STREAMINFO metadata block that has the basic properties of the stream
286                         </TD>
287                 </TR>
288                 <TR>
289                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
290                                 <A HREF="#metadata_block"><I>METADATA_BLOCK</I></A>*
291                         </TD>
292                         <TD>
293                                 Zero or more metadata blocks
294                         </TD>
295                 </TR>
296                 <TR>
297                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
298                                 <A HREF="#frame"><I>FRAME</I></A>+
299                         </TD>
300                         <TD>
301                                 One or more audio frames
302                         </TD>
303                 </TR>
304         </TABLE>
305         </TD></TR></TABLE>
306         </P>
307
308         <P>
309         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
310         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
311                 <TR>
312                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
313                                 <A NAME="metadata_block"><FONT SIZE="+1"><B>METADATA_BLOCK</B></FONT></A>
314                         </TD>
315                 </TR>
316                 <TR>
317                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
318                                 <A HREF="#metadata_block_header"><I>METADATA_BLOCK_HEADER</I></A>
319                         </TD>
320                         <TD>
321                                 A block header that specifies the type and size of the metadata block data.
322                         </TD>
323                 </TR>
324                 <TR>
325                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
326                                 <A HREF="#metadata_block_data"><I>METADATA_BLOCK_DATA</I></A>
327                         </TD>
328                         <TD>
329                                 &nbsp;
330                         </TD>
331                 </TR>
332         </TABLE>
333         </TD></TR></TABLE>
334         </P>
335
336         <P>
337         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
338         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
339                 <TR>
340                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
341                                 <A NAME="metadata_block_header"><FONT SIZE="+1"><B>METADATA_BLOCK_HEADER</B></FONT></A>
342                         </TD>
343                 </TR>
344                 <TR>
345                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
346                                 &lt;1&gt;
347                         </TD>
348                         <TD>
349                                 Last-metadata-block flag: '1' if this block is the last metadata block before the audio blocks, '0' otherwise.
350                         </TD>
351                 </TR>
352                 <TR>
353                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
354                                 &lt;7&gt;
355                         </TD>
356                         <TD>
357                                 BLOCK_TYPE<BR>
358                                 <UL>
359                                 <LI>
360                                         <TT>0</TT> : STREAMINFO
361                                 </LI>
362                                 <LI>
363                                         <TT>1</TT> : PADDING
364                                 </LI>
365                                 <LI>
366                                         <TT>2</TT> : APPLICATION
367                                 </LI>
368                                 <LI>
369                                         <TT>3</TT> : SEEKTABLE
370                                 </LI>
371                                 <LI>
372                                         <TT>3-127</TT> : reserved
373                                 </LI>
374                                 </UL>
375                         </TD>
376                 </TR>
377                 <TR>
378                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
379                                 &lt;24&gt;
380                         </TD>
381                         <TD>
382                                 Length (in bytes) of metadata to follow (does not include the size of the METADATA_BLOCK_HEADER)
383                         </TD>
384                 </TR>
385         </TABLE>
386         </TD></TR></TABLE>
387         </P>
388
389         <P>
390         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
391         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
392                 <TR>
393                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
394                                 <A NAME="metadata_block_data"><FONT SIZE="+1"><B>METADATA_BLOCK_DATA</B></FONT></A>
395                         </TD>
396                 </TR>
397                 <TR>
398                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
399                                 <A HREF="#metadata_block_streaminfo"><I>METADATA_BLOCK_STREAMINFO</I></A><BR>|| <A HREF="#metadata_block_padding"><I>METADATA_BLOCK_PADDING</I></A><BR>|| <A HREF="#metadata_block_application"><I>METADATA_BLOCK_APPLICATION</I></A><BR>|| <A HREF="#metadata_block_seektable"><I>METADATA_BLOCK_SEEKTABLE</I></A>
400                         </TD>
401                         <TD>
402                                 The block data must match the block type in the block header.
403                         </TD>
404                 </TR>
405         </TABLE>
406         </TD></TR></TABLE>
407         </P>
408
409         <P>
410         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
411         <TABLE WIDTH="100%" BORDER="1">
412                 <TR>
413                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
414                                 <A NAME="metadata_block_streaminfo"><FONT SIZE="+1"><B>METADATA_BLOCK_STREAMINFO</B></FONT></A>
415                         </TD>
416                 </TR>
417                 <TR>
418                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
419                                 &lt;16&gt;
420                         </TD>
421                         <TD>
422                                 The minimum block size (in samples) used in the stream.
423                         </TD>
424                 </TR>
425                 <TR>
426                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
427                                 &lt;16&gt;
428                         </TD>
429                         <TD>
430                                 The maximum block size (in samples) used in the stream.  (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
431                         </TD>
432                 </TR>
433                 <TR>
434                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
435                                 &lt;24&gt;
436                         </TD>
437                         <TD>
438                                 The minimum frame size (in bytes) used in the stream.  May be 0 to imply the value is not known.
439                         </TD>
440                 </TR>
441                 <TR>
442                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
443                                 &lt;24&gt;
444                         </TD>
445                         <TD>
446                                 The maximum frame size (in bytes) used in the stream.  May be 0 to imply the value is not known.
447                         </TD>
448                 </TR>
449                 <TR>
450                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
451                                 &lt;20&gt;
452                         </TD>
453                         <TD>
454                                 Sample rate in Hz.  Though 20 bits are available, the maximum sample rate is limited by the structure of frame headers to 1048570Hz.  Also, a value of 0 is invalid.
455                         </TD>
456                 </TR>
457                 <TR>
458                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
459                                 &lt;3&gt;
460                         </TD>
461                         <TD>
462                                 (number of channels)-1.  FLAC supports from 1 to 8 channels
463                         </TD>
464                 </TR>
465                 <TR>
466                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
467                                 &lt;5&gt;
468                         </TD>
469                         <TD>
470                                 (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.
471                         </TD>
472                 </TR>
473                 <TR>
474                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
475                                 &lt;36&gt;
476                         </TD>
477                         <TD>
478                                 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.
479                         </TD>
480                 </TR>
481                 <TR>
482                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
483                                 &lt;128&gt;
484                         </TD>
485                         <TD>
486                                 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.
487                         </TD>
488                 </TR>
489                 <TR>
490                         <TD>
491                         </TD>
492                         <TD BGCOLOR="#F4F4CC">
493                                 <FONT SIZE="+1">NOTES</FONT><BR>
494                                 <UL>
495                                 <LI>
496                                         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.
497                                 </LI>
498                                 </UL>
499                         </TD>
500                 </TR>
501         </TABLE>
502         </TD></TR></TABLE>
503         </P>
504
505         <P>
506         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
507         <TABLE WIDTH="100%" BORDER="1">
508                 <TR>
509                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
510                                 <A NAME="metadata_block_padding"><FONT SIZE="+1"><B>METADATA_BLOCK_PADDING</B></FONT></A>
511                         </TD>
512                 </TR>
513                 <TR>
514                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
515                                 &lt;n&gt;
516                         </TD>
517                         <TD>
518                                 n '0' bits (n must be a multiple of 8)
519                         </TD>
520                 </TR>
521         </TABLE>
522         </TD></TR></TABLE>
523         </P>
524
525         <P>
526         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
527         <TABLE WIDTH="100%" BORDER="1">
528                 <TR>
529                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
530                                 <A NAME="metadata_block_application"><FONT SIZE="+1"><B>METADATA_BLOCK_APPLICATION</B></FONT></A>
531                         </TD>
532                 </TR>
533                 <TR>
534                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
535                                 &lt;32&gt;
536                         </TD>
537                         <TD>
538                                 Registered application ID.  (Visit the <A HREF="id.html">registration page</A> to register an ID with FLAC.)
539                         </TD>
540                 </TR>
541                 <TR>
542                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
543                                 &lt;n&gt;
544                         </TD>
545                         <TD>
546                                 Application data (n must be a multiple of 8)
547                         </TD>
548                 </TR>
549         </TABLE>
550         </TD></TR></TABLE>
551         </P>
552
553         <P>
554         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
555         <TABLE WIDTH="100%" BORDER="1">
556                 <TR>
557                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
558                                 <A NAME="metadata_block_seektable"><FONT SIZE="+1"><B>METADATA_BLOCK_SEEKTABLE</B></FONT></A>
559                         </TD>
560                 </TR>
561                 <TR>
562                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
563                                 <A HREF="#metadata_block_seekpoint"><I>SEEKPOINT</I></A>+
564                         </TD>
565                         <TD>
566                                 One or more seek points.
567                         </TD>
568                 </TR>
569                 <TR>
570                         <TD>
571                         </TD>
572                         <TD BGCOLOR="#F4F4CC">
573                                 <FONT SIZE="+1">NOTE</FONT><BR>
574                                 <UL>
575                                 <LI>
576                                         The number of seek points is implied by the metadata header 'length' field, i.e. equal to length / 18.
577                                 </LI>
578                                 </UL>
579                         </TD>
580                 </TR>
581         </TABLE>
582         </TD></TR></TABLE>
583         </P>
584
585         <P>
586         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
587         <TABLE WIDTH="100%" BORDER="1">
588                 <TR>
589                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
590                                 <A NAME="metadata_block_seekpoint"><FONT SIZE="+1"><B>METADATA_BLOCK_SEEKPOINT</B></FONT></A>
591                         </TD>
592                 </TR>
593                 <TR>
594                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
595                                 &lt;64&gt;
596                         </TD>
597                         <TD>
598                                 Sample number of first sample in the target frame, or 0xFFFFFFFFFFFFFFFF for a placeholder point.
599                         </TD>
600                 </TR>
601                 <TR>
602                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
603                                 &lt;64&gt;
604                         </TD>
605                         <TD>
606                                 Offset (in bytes) from the first byte of the first frame header to the first byte of the target frame's header.
607                         </TD>
608                 </TR>
609                 <TR>
610                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
611                                 &lt;16&gt;
612                         </TD>
613                         <TD>
614                                 Number of samples in the target frame.
615                         </TD>
616                 </TR>
617                 <TR>
618                         <TD>
619                         </TD>
620                         <TD BGCOLOR="#F4F4CC">
621                                 <FONT SIZE="+1">NOTES</FONT><BR>
622                                 <UL>
623                                 <LI>
624                                         For placeholder points, the second and third field values are undefined.
625                                 </LI>
626                                 <LI>
627                                         Seek points within a table must be sorted in ascending order by sample number.
628                                 </LI>
629                                 <LI>
630                                         Seek points within a table must be unique by sample number, with the exception of placeholder points.
631                                 </LI>
632                                 <LI>
633                                         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.
634                                 </LI>
635                                 </UL>
636                         </TD>
637                 </TR>
638         </TABLE>
639         </TD></TR></TABLE>
640         </P>
641
642         <P>
643         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
644         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
645                 <TR>
646                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
647                                 <A NAME="frame"><FONT SIZE="+1"><B>FRAME</B></FONT></A>
648                         </TD>
649                 </TR>
650                 <TR>
651                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
652                                 <A HREF="#frame_header"><I>FRAME_HEADER</I></A>
653                         </TD>
654                         <TD>
655                                 &nbsp;
656                         </TD>
657                 </TR>
658                 <TR>
659                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
660                                 <A HREF="#subframe"><I>SUBFRAME</I></A>+
661                         </TD>
662                         <TD>
663                                 One SUBFRAME per channel.
664                         </TD>
665                 </TR>
666                 <TR>
667                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
668                                 &lt;?&gt;
669                         </TD>
670                         <TD>
671                                 Zero-padding to byte alignment.
672                         </TD>
673                 </TR>
674                 <TR>
675                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
676                                 <A HREF="#frame_footer"><I>FRAME_FOOTER</I></A>
677                         </TD>
678                         <TD>
679                                 &nbsp;
680                         </TD>
681                 </TR>
682         </TABLE>
683         </TD></TR></TABLE>
684         </P>
685
686         <P>
687         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
688         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
689                 <TR>
690                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
691                                 <A NAME="frame_header"><FONT SIZE="+1"><B>FRAME_HEADER</B></FONT></A>
692                         </TD>
693                 </TR>
694                 <TR>
695                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
696                                 &lt;14&gt;
697                         </TD>
698                         <TD>
699                                 Sync code '<TT>11111111111110</TT>'
700                         </TD>
701                 </TR>
702                 <TR>
703                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
704                                 &lt;2&gt;
705                         </TD>
706                         <TD>
707                                 Reserved:<BR>
708                                 <UL>
709                                 <LI>
710                                         <TT>00</TT> : mandatory value
711                                 </LI>
712                                 <LI>
713                                         <TT>01-11</TT> : reserved for future use
714                                 </LI>
715                                 </UL>
716                         </TD>
717                 </TR>
718                 <TR>
719                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
720                                 &lt;4&gt;
721                         </TD>
722                         <TD>
723                                 Block size in inter-channel samples:<BR>
724                                 <UL>
725                                 <LI>
726                                         <TT>0000</TT> : get from STREAMINFO metadata block
727                                 </LI>
728                                 <LI>
729                                         <TT>0001</TT> : 192 samples
730                                 </LI>
731                                 <LI>
732                                         <TT>0010-0101</TT> : 576 * (2^(n-2)) samples, i.e. 576/1152/2304/4608
733                                 </LI>
734                                 <LI>
735                                         <TT>0110</TT> : get 8 bit (blocksize-1) from end of header
736                                 </LI>
737                                 <LI>
738                                         <TT>0111</TT> : get 16 bit (blocksize-1) from end of header
739                                 </LI>
740                                 <LI>
741                                         <TT>1000-1111</TT> : 256 * (2^(n-8)) samples, i.e. 256/512/1024/2048/4096/8192/16384/32768
742                                 </LI>
743                                 </UL>
744                         </TD>
745                 </TR>
746                 <TR>
747                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
748                                 &lt;4&gt;
749                         </TD>
750                         <TD>
751                                 Sample rate:<BR>
752                                 <UL>
753                                 <LI>
754                                         <TT>0000</TT> : get from STREAMINFO metadata block
755                                 </LI>
756                                 <LI>
757                                         <TT>0001-0011</TT> : reserved
758                                 </LI>
759                                 <LI>
760                                         <TT>0100</TT> : 8kHz
761                                 </LI>
762                                 <LI>
763                                         <TT>0101</TT> : 16kHz
764                                 </LI>
765                                 <LI>
766                                         <TT>0110</TT> : 22.05kHz
767                                 </LI>
768                                 <LI>
769                                         <TT>0111</TT> : 24kHz
770                                 </LI>
771                                 <LI>
772                                         <TT>1000</TT> : 32kHz
773                                 </LI>
774                                 <LI>
775                                         <TT>1001</TT> : 44.1kHz
776                                 </LI>
777                                 <LI>
778                                         <TT>1010</TT> : 48kHz
779                                 </LI>
780                                 <LI>
781                                         <TT>1011</TT> : 96kHz
782                                 </LI>
783                                 <LI>
784                                         <TT>1100</TT> : get 8 bit sample rate (in kHz) from end of header
785                                 </LI>
786                                 <LI>
787                                         <TT>1101</TT> : get 16 bit sample rate (in Hz) from end of header
788                                 </LI>
789                                 <LI>
790                                         <TT>1110</TT> : get 16 bit sample rate (in tens of Hz) from end of header
791                                 </LI>
792                                 <LI>
793                                         <TT>1111</TT> : invalid, to prevent sync-fooling string of 1s
794                                 </LI>
795                                 </UL>
796                         </TD>
797                 </TR>
798                 <TR>
799                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
800                                 &lt;4&gt;
801                         </TD>
802                         <TD>
803                                 Channel assignment
804                                 <UL>
805                                 <LI>
806                                         <TT>0000-0111</TT> : (number of independent channels)-1.  when == 0001, channel 0 is the left channel and channel 1 is the right
807                                 </LI>
808                                 <LI>
809                                         <TT>1000</TT> : left/side stereo: channel 0 is the left channel, channel 1 is the side(difference) channel
810                                 </LI>
811                                 <LI>
812                                         <TT>1001</TT> : right/side stereo: channel 0 is the side(difference) channel, channel 1 is the right channel
813                                 </LI>
814                                 <LI>
815                                         <TT>1010</TT> : mid/side stereo: channel 0 is the mid(average) channel, channel 1 is the side(difference) channel
816                                 </LI>
817                                 <LI>
818                                         <TT>1011-1111</TT> : reserved
819                                 </LI>
820                                 </UL>
821                         </TD>
822                 </TR>
823                 <TR>
824                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
825                                 &lt;3&gt;
826                         </TD>
827                         <TD>
828                                 Sample size in bits:<BR>
829                                 <UL>
830                                 <LI>
831                                         <TT>000</TT> : get from STREAMINFO metadata block
832                                 </LI>
833                                 <LI>
834                                         <TT>001</TT> : 8 bits per sample
835                                 </LI>
836                                 <LI>
837                                         <TT>010</TT> : 12 bits per sample
838                                 </LI>
839                                 <LI>
840                                         <TT>011</TT> : reserved
841                                 </LI>
842                                 <LI>
843                                         <TT>100</TT> : 16 bits per sample
844                                 </LI>
845                                 <LI>
846                                         <TT>101</TT> : 20 bits per sample
847                                 </LI>
848                                 <LI>
849                                         <TT>110</TT> : 24 bits per sample
850                                 </LI>
851                                 <LI>
852                                         <TT>111</TT> : reserved
853                                 </LI>
854                                 </UL>
855                         </TD>
856                 </TR>
857                 <TR>
858                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
859                                 &lt;1&gt;
860                         </TD>
861                         <TD>
862                                 Zero bit padding, to prevent sync-fooling string of 1s
863                         </TD>
864                 </TR>
865                 <TR>
866                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
867                                 &lt;?&gt;
868                         </TD>
869                         <TD>
870                                 if(variable blocksize)<BR>
871                                 &nbsp;&nbsp;&nbsp;&lt;8-56&gt;:"UTF-8" coded sample number (decoded number is 36 bits)<BR>
872                                 else<BR>
873                                 &nbsp;&nbsp;&nbsp;&lt;8-48&gt;:"UTF-8" coded frame number (decoded number is 31 bits)
874                         </TD>
875                 </TR>
876                 <TR>
877                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
878                                 &lt;?&gt;
879                         </TD>
880                         <TD>
881                                 if(blocksize bits == 011x)<BR>
882                                 &nbsp;&nbsp;&nbsp;8/16 bit (blocksize-1)
883                         </TD>
884                 </TR>
885                 <TR>
886                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
887                                 &lt;?&gt;
888                         </TD>
889                         <TD>
890                                 if(sample rate bits == 11xx)<BR>
891                                 &nbsp;&nbsp;&nbsp;8/16 bit sample rate
892                         </TD>
893                 </TR>
894                 <TR>
895                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
896                                 &lt;8&gt;
897                         </TD>
898                         <TD>
899                                 CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0) of everything before the crc, including the sync code
900                         </TD>
901                 </TR>
902                 <TR>
903                         <TD>
904                         </TD>
905                         <TD BGCOLOR="#F4F4CC">
906                                 <FONT SIZE="+1">NOTES</FONT><BR>
907                                 <UL>
908                                 <LI>
909                                         The blocksize bits 0000-0101 and 1000-1111 may only be used if the blocksize is fixed throughout the entire stream.  Blocksize bits 0110-0111 may be used in any case but the decoder will have to pessimistically guess that it is a variable-blocksize stream.  There is only one special case: the encoder may use blocksize bits 0110-0111 on the last frame of a fixed-blocksize stream, as long as the blocksize is not greater than the stream blocksize.
910                                 </LI>
911                                 <LI>
912                                         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.
913                                 </LI>
914                                 </UL>
915                         </TD>
916                 </TR>
917         </TABLE>
918         </TD></TR></TABLE>
919         </P>
920
921         <P>
922         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
923         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
924                 <TR>
925                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
926                                 <A NAME="frame_footer"><FONT SIZE="+1"><B>FRAME_FOOTER</B></FONT></A>
927                         </TD>
928                 </TR>
929                 <TR>
930                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
931                                 &lt;16&gt;
932                         </TD>
933                         <TD>
934                                 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
935                         </TD>
936                 </TR>
937         </TABLE>
938         </TD></TR></TABLE>
939         </P>
940
941         <P>
942         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
943         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
944                 <TR>
945                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
946                                 <A NAME="subframe"><FONT SIZE="+1"><B>SUBFRAME</B></FONT></A>
947                         </TD>
948                 </TR>
949                 <TR>
950                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
951                                 <A HREF="#subframe_header"><I>SUBFRAME_HEADER</I></A>
952                         </TD>
953                         <TD>
954                                 &nbsp;
955                         </TD>
956                 </TR>
957                 <TR>
958                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
959                                 <A HREF="#subframe_constant"><I>SUBFRAME_CONSTANT</I></A><BR>|| <A HREF="#subframe_fixed"><I>SUBFRAME_FIXED</I></A><BR>|| <A HREF="#subframe_lpc"><I>SUBFRAME_LPC</I></A><BR>|| <A HREF="#subframe_verbatim"><I>SUBFRAME_VERBATIM</I></A>
960                         </TD>
961                         <TD VALIGN="TOP">
962                                 The SUBFRAME_HEADER specifies which one.
963                         </TD>
964                 </TR>
965         </TABLE>
966         </TD></TR></TABLE>
967         </P>
968
969         <P>
970         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
971         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
972                 <TR>
973                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
974                                 <A NAME="subframe_header"><FONT SIZE="+1"><B>SUBFRAME_HEADER</B></FONT></A>
975                         </TD>
976                 </TR>
977                 <TR>
978                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
979                                 &lt;1&gt;
980                         </TD>
981                         <TD>
982                                 Zero bit padding, to prevent sync-fooling string of 1s
983                         </TD>
984                 </TR>
985                 <TR>
986                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
987                                 &lt;6&gt;
988                         </TD>
989                         <TD>
990                                 Subframe type:
991                                 <UL>
992                                 <LI>
993                                         <TT>000000</TT> : <A HREF="#subframe_constant">SUBFRAME_CONSTANT</A>
994                                 </LI>
995                                 <LI>
996                                         <TT>000001</TT> : <A HREF="#subframe_verbatim">SUBFRAME_VERBATIM</A>
997                                 </LI>
998                                 <LI>
999                                         <TT>00001x</TT> : reserved
1000                                 </LI>
1001                                 <LI>
1002                                         <TT>0001xx</TT> : reserved
1003                                 </LI>
1004                                 <LI>
1005                                         <TT>001xxx</TT> : if(xxx <= 4) <A HREF="#subframe_fixed">SUBFRAME_FIXED</A>, xxx=order ; else reserved
1006                                 </LI>
1007                                 <LI>
1008                                         <TT>01xxxx</TT> : reserved
1009                                 </LI>
1010                                 <LI>
1011                                         <TT>1xxxxx</TT> : <A HREF="#subframe_lpc">SUBFRAME_LPC</A>, xxxxx=order-1
1012                                 </LI>
1013                                 </UL>
1014                         </TD>
1015                 </TR>
1016                 <TR>
1017                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1018                                 &lt;1+k&gt;
1019                         </TD>
1020                         <TD>
1021                                 'Wasted bits-per-sample' flag:
1022                                 <UL>
1023                                 <LI>
1024                                         <TT>0</TT> : no wasted bits-per-sample in source subblock, k=0
1025                                 </LI>
1026                                 <LI>
1027                                         <TT>1</TT> : k wasted bits-per-sample in source subblock, k-1 follows, unary coded; i.e. k=3 => 001 follows, k=7 => 0000001 follows.
1028                                 </LI>
1029                         </TD>
1030                 </TR>
1031         </TABLE>
1032         </TD></TR></TABLE>
1033         </P>
1034
1035         <P>
1036         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1037         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1038                 <TR>
1039                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1040                                 <A NAME="subframe_constant"><FONT SIZE="+1"><B>SUBFRAME_CONSTANT</B></FONT></A>
1041                         </TD>
1042                 </TR>
1043                 <TR>
1044                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1045                                 &lt;n&gt;
1046                         </TD>
1047                         <TD>
1048                                 Unencoded constant value of the subblock, n = frame's bits-per-sample.
1049                         </TD>
1050                 </TR>
1051         </TABLE>
1052         </TD></TR></TABLE>
1053         </P>
1054
1055         <P>
1056         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1057         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1058                 <TR>
1059                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1060                                 <A NAME="subframe_fixed"><FONT SIZE="+1"><B>SUBFRAME_FIXED</B></FONT></A>
1061                         </TD>
1062                 </TR>
1063                 <TR>
1064                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1065                                 &lt;n&gt;
1066                         </TD>
1067                         <TD>
1068                                 Unencoded warm-up samples (n = frame's bits-per-sample * predictor order).
1069                         </TD>
1070                 </TR>
1071                 <TR>
1072                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1073                                 <A HREF="#residual"><I>RESIDUAL</I></A>
1074                         </TD>
1075                         <TD>
1076                                 Encoded residual
1077                         </TD>
1078                 </TR>
1079         </TABLE>
1080         </TD></TR></TABLE>
1081         </P>
1082
1083         <P>
1084         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1085         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1086                 <TR>
1087                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1088                                 <A NAME="subframe_lpc"><FONT SIZE="+1"><B>SUBFRAME_LPC</B></FONT></A>
1089                         </TD>
1090                 </TR>
1091                 <TR>
1092                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1093                                 &lt;n&gt;
1094                         </TD>
1095                         <TD>
1096                                 Unencoded warm-up samples (n = frame's bits-per-sample * lpc order).
1097                         </TD>
1098                 </TR>
1099                 <TR>
1100                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1101                                 &lt;4&gt;
1102                         </TD>
1103                         <TD>
1104                                 (Quantized linear predictor coefficients' precision in bits)-1 (1111 = invalid).
1105                         </TD>
1106                 </TR>
1107                 <TR>
1108                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1109                                 &lt;5&gt;
1110                         </TD>
1111                         <TD>
1112                                 Quantized linear predictor coefficient shift needed in bits (NOTE: this number is signed two's-complement).
1113                         </TD>
1114                 </TR>
1115                 <TR>
1116                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1117                                 &lt;n&gt;
1118                         </TD>
1119                         <TD>
1120                                 Unencoded predictor coefficients (n = qlp coeff precision * lpc order) (NOTE: the coefficients are signed two's-complement).
1121                         </TD>
1122                 </TR>
1123                 <TR>
1124                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1125                                 <A HREF="#residual"><I>RESIDUAL</I></A>
1126                         </TD>
1127                         <TD>
1128                                 Encoded residual
1129                         </TD>
1130                 </TR>
1131         </TABLE>
1132         </TD></TR></TABLE>
1133         </P>
1134
1135         <P>
1136         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1137         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1138                 <TR>
1139                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1140                                 <A NAME="subframe_verbatim"><FONT SIZE="+1"><B>SUBFRAME_VERBATIM</B></FONT></A>
1141                         </TD>
1142                 </TR>
1143                 <TR>
1144                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1145                                 &lt;n*i&gt;
1146                         </TD>
1147                         <TD>
1148                                 Unencoded subblock; n = frame's bits-per-sample, i = frame's blocksize.
1149                         </TD>
1150                 </TR>
1151         </TABLE>
1152         </TD></TR></TABLE>
1153         </P>
1154
1155         <P>
1156         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1157         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1158                 <TR>
1159                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1160                                 <A NAME="residual"><FONT SIZE="+1"><B>RESIDUAL</B></FONT></A>
1161                         </TD>
1162                 </TR>
1163                 <TR>
1164                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1165                                 &lt;2&gt;
1166                         </TD>
1167                         <TD>
1168                                 Residual coding method:<BR>
1169                                 <UL>
1170                                 <LI>
1171                                         <TT>00</TT> : partitioned rice coding
1172                                 </LI>
1173                                 <LI>
1174                                         <TT>01-11</TT> : reserved
1175                                 </LI>
1176                                 </UL>
1177                         </TD>
1178                 </TR>
1179                 <TR>
1180                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1181                                 <A HREF="#partitioned_rice"><I>RESIDUAL_CODING_METHOD_PARTITIONED_RICE</I></A>
1182                         </TD>
1183                         <TD>
1184                                 &nbsp;
1185                         </TD>
1186                 </TR>
1187                 <TR>
1188                         <TD>
1189                         </TD>
1190                         <TD BGCOLOR="#F4F4CC">
1191                                 <FONT SIZE="+1">NOTES</FONT><BR>
1192                                 <UL>
1193                                 <LI>
1194                                         Currently, FLAC specifies only one entropy coding method.
1195                                 </LI>
1196                                 </UL>
1197                         </TD>
1198                 </TR>
1199         </TABLE>
1200         </TD></TR></TABLE>
1201         </P>
1202
1203         <P>
1204         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1205         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1206                 <TR>
1207                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1208                                 <A NAME="partitioned_rice"><FONT SIZE="+1"><B>RESIDUAL_CODING_METHOD_PARTITIONED_RICE</B></FONT></A>
1209                         </TD>
1210                 </TR>
1211                 <TR>
1212                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1213                                 &lt;4&gt;
1214                         </TD>
1215                         <TD>
1216                                 Partition order.
1217                         </TD>
1218                 </TR>
1219                 <TR>
1220                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1221                                 <A HREF="#rice_partition"><I>RICE_PARTITION</I></A>+
1222                         </TD>
1223                         <TD>
1224                                 There will be 2^order partitions.
1225                         </TD>
1226                 </TR>
1227         </TABLE>
1228         </TD></TR></TABLE>
1229         </P>
1230
1231         <P>
1232         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1233         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1234                 <TR>
1235                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1236                                 <A NAME="rice_partition"><FONT SIZE="+1"><B>RICE_PARTITION</B></FONT></A>
1237                         </TD>
1238                 </TR>
1239                 <TR>
1240                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1241                                 &lt;4(+5)&gt;
1242                         </TD>
1243                         <TD>
1244                                 Encoding parameter:<BR>
1245                                 <UL>
1246                                 <LI>
1247                                         <TT>0000-1110</TT> : Rice parameter.
1248                                 </LI>
1249                                 <LI>
1250                                         <TT>1111</TT> : Escape code, meaning the partition is in unencoded binary form using n bits per sample; n follows as a 5-bit number.
1251                                 </LI>
1252                                 </UL>
1253                         </TD>
1254                 </TR>
1255                 <TR>
1256                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1257                                 &lt;?&gt;
1258                         </TD>
1259                         <TD>
1260                                 Encoded residual.  The number of samples (n) in the partition is determined as follows:<BR>
1261                                 <UL>
1262                                 <LI>
1263                                         if the partition order is zero, n = frame's blocksize
1264                                 </LI>
1265                                 <LI>
1266                                         else if this is not the first partition of the subframe, n = (frame's blocksize / (2^partition order))
1267                                 </LI>
1268                                 <LI>
1269                                         else n = (frame's blocksize / (2^partition order)) - predictor order
1270                                 </LI>
1271                                 </UL>
1272                         </TD>
1273                 </TR>
1274         </TABLE>
1275         </TD></TR></TABLE>
1276         </P>
1277
1278 </TD></TR>
1279 </TABLE>
1280
1281
1282 </CENTER>
1283
1284 </BODY>
1285 </HTML>