add table of contents
[platform/upstream/flac.git] / doc / html / format.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <!-- Copyright (c)  2000,2001,2002,2003,2004  Josh Coalson -->
3 <!-- Permission is granted to copy, distribute and/or modify this document -->
4 <!-- under the terms of the GNU Free Documentation License, Version 1.1 -->
5 <!-- or any later version published by the Free Software Foundation; -->
6 <!-- with no invariant sections. -->
7 <!-- A copy of the license can be found at http://www.gnu.org/copyleft/fdl.html -->
8 <HTML>
9 <HEAD>
10         <TITLE>FLAC - format</TITLE>
11 </HEAD>
12
13 <BODY MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" RIGHTMARGIN="0" TOPMARGIN="0" BGCOLOR="#99CC99" TEXT="#000000" LINK="#336699" VLINK="#336699" ALINK="#336699">
14
15 <TABLE BORDER=0 WIDTH="100%" CELLPADDING=1 CELLSPACING=0>
16         <TR>
17                 <TD ALIGN="CENTER" BGCOLOR="#000000"><A HREF="http://flac.sourceforge.net/"><IMG SRC="images/logo130.gif" ALIGN=CENTER ALT="FLAC Logo" BORDER=0 HSPACE=0></a></TD>
18         </TR>
19 </TABLE>
20
21 <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>
22
23 <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>
24
25 <TABLE WIDTH="100%" CELLPADDING=0 CELLSPACING=0 BORDER=0>
26         <TR>
27                 <TD ALIGN="CENTER" BGCOLOR="#D3D4C5">
28                         <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
29                                 <TR>
30                                         <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>
31                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="faq.html">faq</A>&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
32                                         <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>
33                                         <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>
34                                         <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>
35                                         <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>
36                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;format&nbsp;&nbsp;</TD><TD BGCOLOR="#D3D4C5" ALIGN=CENTER>|</TD>
37                                         <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>
38                                         <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>
39                                         <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>
40                                         <TD           BGCOLOR="#D3D4C5" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="developers.html">developers</A>&nbsp;&nbsp;</TD>
41                                 </TR>
42                         </TABLE>
43                 </TD>
44         </TR>
45 </TABLE>
46
47 <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>
48
49 <TABLE WIDTH="100%" CELLPADDING=0 CELLSPACING=0 BORDER=0>
50         <TR>
51                 <TD ALIGN="CENTER" BGCOLOR="#EEEED4">
52                         <TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>
53                                 <TR>
54                                         <TD HEIGHT=22 BGCOLOR="#EEEED4" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;english&nbsp;&nbsp;</TD><TD BGCOLOR="#EEEED4" ALIGN=CENTER>|</TD>
55                                         <TD           BGCOLOR="#EEEED4" ALIGN=CENTER NOWRAP>&nbsp;&nbsp;<A CLASS="topnav" HREF="ru/format.html">russian</A>&nbsp;&nbsp;</TD>
56                                 </TR>
57                         </TABLE>
58                 </TD>
59         </TR>
60 </TABLE>
61
62 <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>
63
64 <CENTER>
65
66 <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>
67
68
69 <TABLE WIDTH="100%" CELLPADDING="5" CELLSPACING="5" BORDER="0">
70 <TR><TD>
71         <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>
72         <TABLE CELLSPACING="0" CELLPADDING="3" WIDTH="100%" BORDER="0" BGCOLOR="#D3D4C5">
73                 <TR><TD><FONT FACE="Lucida,Verdana,Helvetica,Arial">
74                 <B><FONT SIZE="+2">format</FONT></B>
75                 </FONT></TD></TR>
76         </TABLE>
77         <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>
78         <TABLE CELLSPACING="0" CELLPADDING="3" WIDTH="100%" BORDER="0" BGCOLOR="#EEEED4">
79         <TR><TD><FONT FACE="Lucida,Verdana,Helvetica,Arial">
80         <P>
81                 This is a detailed description of the FLAC format.
82         </P>
83         <P>
84                 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:
85         </P>
86         <P>
87         <UL>
88                 <LI>
89                         <A HREF="http://svr-www.eng.cam.ac.uk/~ajr/">A. J. Robinson</A> for his work on <A HREF="http://www-svr.eng.cam.ac.uk/reports/abstracts/robinson_tr156.html">Shorten</A>; his paper is a good starting point on some of the basic methods used by FLAC.  FLAC expands on the fixed predictors used in shorten.
90                 </LI>
91                 <LI>
92                         <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.
93                 </LI>
94                 <LI>
95                         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.
96                 </LI>
97                 <LI>
98                         And of course, the main guy, <A HREF="http://www.digitalcentury.com/encyclo/update/shannon.html">Claude Shannon</A>
99                 </LI>
100         </UL>
101         </P>
102         <P>
103                 <A NAME="toc"><FONT SIZE="+1"><B><U>Table of Contents</U></B></FONT></A>
104         </P>
105         <P>
106         <UL>
107                 <LI><A HREF="#scope">Scope</A></LI>
108                 <LI><A HREF="#architecture">Architecture</A></LI>
109                 <LI><A HREF="#definitions">Definitions</A></LI>
110                 <LI><A HREF="#blocking">Blocking</A></LI>
111                 <LI><A HREF="#interchannel">Interchannel Decorrelation</A></LI>
112                 <LI><A HREF="#prediction">Prediction</A></LI>
113                 <LI><A HREF="#residualcoding">Residual Coding</A></LI>
114                 <LI><A HREF="#format_overview">Format</A></LI>
115                 <LI><A HREF="#subset">FLAC Subset</A></LI>
116                 <LI>Specification
117                         <UL>
118                                 <LI><A HREF="#stream">STREAM</A>
119                                         <UL>
120                                                 <LI><A HREF="#metadata_block">METADATA_BLOCK</A>
121                                                         <UL>
122                                                                 <LI><A HREF="#metadata_block_header">METADATA_BLOCK_HEADER</A></LI>
123                                                                 <LI><A HREF="#metadata_block_data">METADATA_BLOCK_DATA</A>
124                                                                         <UL>
125                                                                                 <LI><A HREF="#metadata_block_streaminfo">METADATA_BLOCK_STREAMINFO</A></LI>
126                                                                                 <LI><A HREF="#metadata_block_padding">METADATA_BLOCK_PADDING</A></LI>
127                                                                                 <LI><A HREF="#metadata_block_application">METADATA_BLOCK_APPLICATION</A></LI>
128                                                                                 <LI><A HREF="#metadata_block_seektable">METADATA_BLOCK_SEEKTABLE</A>
129                                                                                         <UL>
130                                                                                                 <LI><A HREF="#seekpoint">SEEKPOINT</A></LI>
131                                                                                         </UL>
132                                                                                 </LI>
133                                                                                 <LI><A HREF="#metadata_block_vorbis_comment">METADATA_BLOCK_VORBIS_COMMENT</A></LI>
134                                                                                 <LI><A HREF="#metadata_block_cuesheet">METADATA_BLOCK_CUESHEET</A>
135                                                                                         <UL>
136                                                                                                 <LI><A HREF="#cuesheet_track">CUESHEET_TRACK</A>
137                                                                                                         <UL>
138                                                                                                                 <LI><A HREF="#cuesheet_track_index">CUESHEET_TRACK_INDEX</A></LI>
139                                                                                                         </UL>
140                                                                                                 </LI>
141                                                                                         </UL>
142                                                                                 </LI>
143                                                                         </UL>
144                                                                 </LI>
145                                                         </UL>
146                                                 </LI>
147                                         </UL>
148                                 </LI>
149                                 <LI>
150                                         <UL>
151                                                 <LI><A HREF="#frame">FRAME</A>
152                                                         <UL>
153                                                                 <LI><A HREF="#frame_header">FRAME_HEADER</A></LI>
154                                                                 <LI><A HREF="#frame_footer">FRAME_FOOTER</A></LI>
155                                                                 <LI><A HREF="#subframe">SUBFRAME</A>
156                                                                         <UL>
157                                                                                 <LI><A HREF="#subframe_header">SUBFRAME_HEADER</A></LI>
158                                                                                 <LI><A HREF="#subframe_constant">SUBFRAME_CONSTANT</A></LI>
159                                                                                 <LI><A HREF="#subframe_fixed">SUBFRAME_FIXED</A></LI>
160                                                                                 <LI><A HREF="#subframe_lpc">SUBFRAME_LPC</A></LI>
161                                                                                 <LI><A HREF="#subframe_verbatim">SUBFRAME_VERBATIM</A>
162                                                                                         <UL>
163                                                                                                 <LI><A HREF="#residual">RESIDUAL</A>
164                                                                                                         <UL>
165                                                                                                                 <LI><A HREF="#partitioned_rice">RESIDUAL_CODING_METHOD_PARTITIONED_RICE</A>
166                                                                                                                         <UL>
167                                                                                                                                 <LI><A HREF="#rice_partition">RICE_PARTITION</A></LI>
168                                                                                                                         </UL>
169                                                                                                                 </LI>
170                                                                                                         </UL>
171                                                                                                 </LI>
172                                                                                         </UL>
173                                                                                 </LI>
174                                                                         </UL>
175                                                                 </LI>
176                                                         </UL>
177                                                 </LI>
178                                         </UL>
179                                 </LI>
180                         </UL>
181                 </LI>
182         </UL>
183         </P>
184         <P>
185                 <A NAME="scope"><FONT SIZE="+1"><B><U>Scope</U></B></FONT></A>
186         </P>
187         <P>
188                 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.
189         </P>
190         <P>
191                 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.
192         </P>
193         <P>
194                 <A NAME="architecture"><FONT SIZE="+1"><B><U>Architecture</U></B></FONT></A>
195         </P>
196         <P>
197                 Similar to many audio coders, a FLAC encoder has the following stages:
198         </P>
199         <UL>
200                 <P><LI>
201                         <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.
202                 </LI></P>
203                 <P><LI>
204                         <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.
205                 </LI></P>
206                 <P><LI>
207                         <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.
208                 </LI></P>
209                 <LI><P>
210                         <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.
211                 </LI></P>
212         </UL>
213         <P>
214                 In addition, FLAC specifies a metadata system, which allows arbitrary information about the stream to be included at the beginning of the stream.
215         </P>
216         <P>
217                 <A NAME="definitions"><FONT SIZE="+1"><B><U>Definitions</U></B></FONT></A>
218         </P>
219         <P>
220                 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.
221         </P>
222         <UL>
223                 <P><LI>
224                         <B>Block</B>: One or more audio samples that span several channels.
225                 </LI></P>
226                 <P><LI>
227                         <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.
228                 </LI></P>
229                 <P><LI>
230                         <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.
231                 </LI></P>
232                 <P><LI>
233                         <B>Frame</B>: A frame header plus one or more subframes.
234                 </LI></P>
235                 <P><LI>
236                         <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.
237                 </LI></P>
238         </UL>
239         <P>
240                 <A NAME="blocking"><FONT SIZE="+1"><B><U>Blocking</U></B></FONT></A>
241         </P>
242         <P>
243                 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.
244         </P>
245         <P>
246                 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.
247         </P>
248         <P>
249                 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.
250         </P>
251         <P>
252                 <A NAME="interchannel"><FONT SIZE="+1"><B><U>Interchannel Decorrelation</U></B></FONT></A>
253         </P>
254         <P>
255                 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.
256         </P>
257         <UL>
258                 <P><LI>
259                         <B>Independent</B>.  The left and right channels are coded independently.
260                 </LI></P>
261                 <P><LI>
262                         <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).
263                 </LI></P>
264                 <P><LI>
265                         <B>Left-side</B>.  The left channel and side channel are coded.
266                 </LI></P>
267                 <P><LI>
268                         <B>Right-side</B>.  The right channel and side channel are coded
269                 </LI></P>
270         </UL>
271         <P>
272                 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.
273         </P>
274         <P>
275                 <A NAME="prediction"><FONT SIZE="+1"><B><U>Prediction</U></B></FONT></A>
276         </P>
277         <P>
278                 FLAC uses four methods for modeling the input signal:
279         </P>
280         <UL>
281                 <P><LI>
282                         <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.
283                 </LI></P>
284                 <P><LI>
285                         <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.
286                 </LI></P>
287                 <P><LI>
288                         <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.
289                 </LI></P>
290                 <P><LI>
291                         <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.
292                 </LI></P>
293         </UL>
294         <P>
295                 <A NAME="residualcoding"><FONT SIZE="+1"><B><U>Residual Coding</U></B></FONT></A>
296         </P>
297         <P>
298                 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.)
299         </P>
300         <P>
301                 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.
302         </P>
303         <P>
304                 <A NAME="format_overview"><FONT SIZE="+1"><B><U>Format</U></B></FONT>
305         </P>
306         <P>
307                 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.
308         </P>
309         <P>
310                 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.
311         </P>
312         <P>
313                 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.</A>
314         </P>
315         <P>
316                 Before the formal description of the stream, an overview might be helpful.
317         </P>
318         <UL>
319                 <P><LI>
320                         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.
321                 </LI></P>
322                 <P><LI>
323                         FLAC supports up to 128 kinds of metadata blocks; currently the following are defined:
324                         <UL>
325                                 <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>
326                                 <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>
327                                 <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 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).</LI>
328                                 <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>
329                                 <LI><A NAME="def_VORBIS_COMMENT"><B>VORBIS_COMMENT</B>: 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 <A HREF="http://xiph.org/ogg/vorbis/doc/v-comment.html">Vorbis comment specification</A>.  This is the only officially supported tagging mechanism in FLAC.  There may be only one VORBIS_COMMENT block in a stream.</LI>
330                                 <LI><A NAME="def_CUESHEET"><B>CUESHEET</B>: 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.</LI>
331                         </UL>
332                 </LI></P>
333                 <P><LI>
334                         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.
335                 </LI></P>
336                 <P><LI>
337                         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.
338                 </LI></P>
339                 <P><LI>
340                         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.
341                 </LI></P>
342                 <P><LI>
343                         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.
344                 </LI></P>
345                 <P><LI>
346                         <A NAME="subset">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 encoding parameters such that decoder buffer sizes and other resource requirements 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:
347                         <UL>
348                         <LI>
349                                 The blocksize bits in the <A HREF="#frame_header">frame header</A> must be 0001-0101 or 1000-1110, specifying a fixed-blocksize stream (the exception being the last block as described in the table) and a few allowable blocksizes.  This also means that the STREAMINFO metadata block must specify equal mininum and maximum blocksizes.
350                         </LI>
351                         <LI>
352                                 The sample rate bits in the <A HREF="#frame_header">frame header</A> must be 0001-1011.
353                         </LI>
354                         <LI>
355                                 The bits-per-sample bits in the <A HREF="#frame_header">frame header</A> must be 001-111.
356                         </LI>
357                         </UL>
358                 </LI></P>
359         </UL>
360
361         <P>
362                 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.
363         </P>
364
365         </FONT>
366         </TD></TR>
367         </TABLE>
368         <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>
369
370         <P>
371         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
372         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
373                 <TR>
374                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
375                                 <A NAME="stream"><FONT SIZE="+1"><B>STREAM</B></FONT></A>
376                         </TD>
377                 </TR>
378                 <TR>
379                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
380                                 &lt;32&gt;
381                         </TD>
382                         <TD>
383                                 "fLaC", the FLAC stream marker in ASCII, meaning byte 0 of the stream is 0x66, followed by 0x4C 0x61 0x43
384                         </TD>
385                 </TR>
386                 <TR>
387                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
388                                 <A HREF="#metadata_block_streaminfo"><I>METADATA_BLOCK</I></A>
389                         </TD>
390                         <TD>
391                                 This is the mandatory STREAMINFO metadata block that has the basic properties of the stream
392                         </TD>
393                 </TR>
394                 <TR>
395                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
396                                 <A HREF="#metadata_block"><I>METADATA_BLOCK</I></A>*
397                         </TD>
398                         <TD>
399                                 Zero or more metadata blocks
400                         </TD>
401                 </TR>
402                 <TR>
403                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
404                                 <A HREF="#frame"><I>FRAME</I></A>+
405                         </TD>
406                         <TD>
407                                 One or more audio frames
408                         </TD>
409                 </TR>
410         </TABLE>
411         </TD></TR></TABLE>
412         </P>
413
414         <P>
415         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
416         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
417                 <TR>
418                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
419                                 <A NAME="metadata_block"><FONT SIZE="+1"><B>METADATA_BLOCK</B></FONT></A>
420                         </TD>
421                 </TR>
422                 <TR>
423                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
424                                 <A HREF="#metadata_block_header"><I>METADATA_BLOCK_HEADER</I></A>
425                         </TD>
426                         <TD>
427                                 A block header that specifies the type and size of the metadata block data.
428                         </TD>
429                 </TR>
430                 <TR>
431                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
432                                 <A HREF="#metadata_block_data"><I>METADATA_BLOCK_DATA</I></A>
433                         </TD>
434                         <TD>
435                                 &nbsp;
436                         </TD>
437                 </TR>
438         </TABLE>
439         </TD></TR></TABLE>
440         </P>
441
442         <P>
443         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
444         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
445                 <TR>
446                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
447                                 <A NAME="metadata_block_header"><FONT SIZE="+1"><B>METADATA_BLOCK_HEADER</B></FONT></A>
448                         </TD>
449                 </TR>
450                 <TR>
451                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
452                                 &lt;1&gt;
453                         </TD>
454                         <TD>
455                                 Last-metadata-block flag: '1' if this block is the last metadata block before the audio blocks, '0' otherwise.
456                         </TD>
457                 </TR>
458                 <TR>
459                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
460                                 &lt;7&gt;
461                         </TD>
462                         <TD>
463                                 BLOCK_TYPE<BR>
464                                 <UL>
465                                 <LI>
466                                         <TT>0</TT> : STREAMINFO
467                                 </LI>
468                                 <LI>
469                                         <TT>1</TT> : PADDING
470                                 </LI>
471                                 <LI>
472                                         <TT>2</TT> : APPLICATION
473                                 </LI>
474                                 <LI>
475                                         <TT>3</TT> : SEEKTABLE
476                                 </LI>
477                                 <LI>
478                                         <TT>4</TT> : VORBIS_COMMENT
479                                 </LI>
480                                 <LI>
481                                         <TT>5</TT> : CUESHEET
482                                 </LI>
483                                 <LI>
484                                         <TT>6-126</TT> : reserved
485                                 </LI>
486                                 <LI>
487                                         <TT>127</TT> : invalid, to avoid confusion with a frame sync code
488                                 </LI>
489                                 </UL>
490                         </TD>
491                 </TR>
492                 <TR>
493                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
494                                 &lt;24&gt;
495                         </TD>
496                         <TD>
497                                 Length (in bytes) of metadata to follow (does not include the size of the METADATA_BLOCK_HEADER)
498                         </TD>
499                 </TR>
500         </TABLE>
501         </TD></TR></TABLE>
502         </P>
503
504         <P>
505         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
506         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
507                 <TR>
508                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
509                                 <A NAME="metadata_block_data"><FONT SIZE="+1"><B>METADATA_BLOCK_DATA</B></FONT></A>
510                         </TD>
511                 </TR>
512                 <TR>
513                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
514                                 <A HREF="#metadata_block_streaminfo"><I>METADATA_BLOCK_STREAMINFO</I></A><BR>
515                                 || <A HREF="#metadata_block_padding"><I>METADATA_BLOCK_PADDING</I></A><BR>
516                                 || <A HREF="#metadata_block_application"><I>METADATA_BLOCK_APPLICATION</I></A><BR>
517                                 || <A HREF="#metadata_block_seektable"><I>METADATA_BLOCK_SEEKTABLE</I></A><BR>
518                                 || <A HREF="#metadata_block_vorbis_comment"><I>METADATA_BLOCK_VORBIS_COMMENT</I></A><BR>
519                                 || <A HREF="#metadata_block_cuesheet"><I>METADATA_BLOCK_CUESHEET</I></A>
520                         </TD>
521                         <TD>
522                                 The block data must match the block type in the block header.
523                         </TD>
524                 </TR>
525         </TABLE>
526         </TD></TR></TABLE>
527         </P>
528
529         <P>
530         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
531         <TABLE WIDTH="100%" BORDER="1">
532                 <TR>
533                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
534                                 <A NAME="metadata_block_streaminfo"><FONT SIZE="+1"><B>METADATA_BLOCK_STREAMINFO</B></FONT></A>
535                         </TD>
536                 </TR>
537                 <TR>
538                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
539                                 &lt;16&gt;
540                         </TD>
541                         <TD>
542                                 The minimum block size (in samples) used in the stream.
543                         </TD>
544                 </TR>
545                 <TR>
546                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
547                                 &lt;16&gt;
548                         </TD>
549                         <TD>
550                                 The maximum block size (in samples) used in the stream.  (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
551                         </TD>
552                 </TR>
553                 <TR>
554                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
555                                 &lt;24&gt;
556                         </TD>
557                         <TD>
558                                 The minimum frame size (in bytes) used in the stream.  May be 0 to imply the value is not known.
559                         </TD>
560                 </TR>
561                 <TR>
562                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
563                                 &lt;24&gt;
564                         </TD>
565                         <TD>
566                                 The maximum frame size (in bytes) used in the stream.  May be 0 to imply the value is not known.
567                         </TD>
568                 </TR>
569                 <TR>
570                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
571                                 &lt;20&gt;
572                         </TD>
573                         <TD>
574                                 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.
575                         </TD>
576                 </TR>
577                 <TR>
578                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
579                                 &lt;3&gt;
580                         </TD>
581                         <TD>
582                                 (number of channels)-1.  FLAC supports from 1 to 8 channels
583                         </TD>
584                 </TR>
585                 <TR>
586                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
587                                 &lt;5&gt;
588                         </TD>
589                         <TD>
590                                 (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.
591                         </TD>
592                 </TR>
593                 <TR>
594                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
595                                 &lt;36&gt;
596                         </TD>
597                         <TD>
598                                 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.
599                         </TD>
600                 </TR>
601                 <TR>
602                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
603                                 &lt;128&gt;
604                         </TD>
605                         <TD>
606                                 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.
607                         </TD>
608                 </TR>
609                 <TR>
610                         <TD>
611                         </TD>
612                         <TD BGCOLOR="#F4F4CC">
613                                 <FONT SIZE="+1">NOTES</FONT><BR>
614                                 <UL>
615                                 <LI>
616                                         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.
617                                 </LI>
618                                 </UL>
619                         </TD>
620                 </TR>
621         </TABLE>
622         </TD></TR></TABLE>
623         </P>
624
625         <P>
626         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
627         <TABLE WIDTH="100%" BORDER="1">
628                 <TR>
629                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
630                                 <A NAME="metadata_block_padding"><FONT SIZE="+1"><B>METADATA_BLOCK_PADDING</B></FONT></A>
631                         </TD>
632                 </TR>
633                 <TR>
634                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
635                                 &lt;n&gt;
636                         </TD>
637                         <TD>
638                                 n '0' bits (n must be a multiple of 8)
639                         </TD>
640                 </TR>
641         </TABLE>
642         </TD></TR></TABLE>
643         </P>
644
645         <P>
646         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
647         <TABLE WIDTH="100%" BORDER="1">
648                 <TR>
649                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
650                                 <A NAME="metadata_block_application"><FONT SIZE="+1"><B>METADATA_BLOCK_APPLICATION</B></FONT></A>
651                         </TD>
652                 </TR>
653                 <TR>
654                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
655                                 &lt;32&gt;
656                         </TD>
657                         <TD>
658                                 Registered application ID.  (Visit the <A HREF="id.html">registration page</A> to register an ID with FLAC.)
659                         </TD>
660                 </TR>
661                 <TR>
662                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
663                                 &lt;n&gt;
664                         </TD>
665                         <TD>
666                                 Application data (n must be a multiple of 8)
667                         </TD>
668                 </TR>
669         </TABLE>
670         </TD></TR></TABLE>
671         </P>
672
673         <P>
674         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
675         <TABLE WIDTH="100%" BORDER="1">
676                 <TR>
677                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
678                                 <A NAME="metadata_block_seektable"><FONT SIZE="+1"><B>METADATA_BLOCK_SEEKTABLE</B></FONT></A>
679                         </TD>
680                 </TR>
681                 <TR>
682                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
683                                 <A HREF="#seekpoint"><I>SEEKPOINT</I></A>+
684                         </TD>
685                         <TD>
686                                 One or more seek points.
687                         </TD>
688                 </TR>
689                 <TR>
690                         <TD>
691                         </TD>
692                         <TD BGCOLOR="#F4F4CC">
693                                 <FONT SIZE="+1">NOTE</FONT><BR>
694                                 <UL>
695                                 <LI>
696                                         The number of seek points is implied by the metadata header 'length' field, i.e. equal to length / 18.
697                                 </LI>
698                                 </UL>
699                         </TD>
700                 </TR>
701         </TABLE>
702         </TD></TR></TABLE>
703         </P>
704
705         <P>
706         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
707         <TABLE WIDTH="100%" BORDER="1">
708                 <TR>
709                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
710                                 <A NAME="seekpoint"><FONT SIZE="+1"><B>SEEKPOINT</B></FONT></A>
711                         </TD>
712                 </TR>
713                 <TR>
714                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
715                                 &lt;64&gt;
716                         </TD>
717                         <TD>
718                                 Sample number of first sample in the target frame, or 0xFFFFFFFFFFFFFFFF for a placeholder point.
719                         </TD>
720                 </TR>
721                 <TR>
722                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
723                                 &lt;64&gt;
724                         </TD>
725                         <TD>
726                                 Offset (in bytes) from the first byte of the first frame header to the first byte of the target frame's header.
727                         </TD>
728                 </TR>
729                 <TR>
730                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
731                                 &lt;16&gt;
732                         </TD>
733                         <TD>
734                                 Number of samples in the target frame.
735                         </TD>
736                 </TR>
737                 <TR>
738                         <TD>
739                         </TD>
740                         <TD BGCOLOR="#F4F4CC">
741                                 <FONT SIZE="+1">NOTES</FONT><BR>
742                                 <UL>
743                                 <LI>
744                                         For placeholder points, the second and third field values are undefined.
745                                 </LI>
746                                 <LI>
747                                         Seek points within a table must be sorted in ascending order by sample number.
748                                 </LI>
749                                 <LI>
750                                         Seek points within a table must be unique by sample number, with the exception of placeholder points.
751                                 </LI>
752                                 <LI>
753                                         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.
754                                 </LI>
755                                 </UL>
756                         </TD>
757                 </TR>
758         </TABLE>
759         </TD></TR></TABLE>
760         </P>
761
762         <P>
763         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
764         <TABLE WIDTH="100%" BORDER="1">
765                 <TR>
766                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
767                                 <A NAME="metadata_block_vorbis_comment"><FONT SIZE="+1"><B>METADATA_BLOCK_VORBIS_COMMENT</B></FONT></A>
768                         </TD>
769                 </TR>
770                 <TR>
771                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
772                                 &lt;n&gt;
773                         </TD>
774                         <TD>
775                                 The contents of a vorbis comment packet as specified <A HREF="http://www.xiph.org/ogg/vorbis/doc/v-comment.html">here</A>, including the vendor string.  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.
776                         </TD>
777                 </TR>
778         </TABLE>
779         </TD></TR></TABLE>
780         </P>
781
782         <P>
783         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
784         <TABLE WIDTH="100%" BORDER="1">
785                 <TR>
786                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
787                                 <A NAME="metadata_block_cuesheet"><FONT SIZE="+1"><B>METADATA_BLOCK_CUESHEET</B></FONT></A>
788                         </TD>
789                 </TR>
790                 <TR>
791                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
792                                 &lt;128*8&gt;
793                         </TD>
794                         <TD>
795                                 Media catalog number, in ASCII printable characters 0x20-0x7e.  In general, the media catalog number may be 0 to 128 bytes long; any unused characters should be right-padded with NUL characters.  For CD-DA, this is a thirteen digit number, followed by 115 NUL bytes.
796                         </TD>
797                 </TR>
798                 <TR>
799                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
800                                 &lt;64&gt;
801                         </TD>
802                         <TD>
803                                 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.
804                         </TD>
805                 </TR>
806                 <TR>
807                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
808                                 &lt;1&gt;
809                         </TD>
810                         <TD>
811                                 <TT>1</TT> if the CUESHEET corresponds to a Compact Disc, else <TT>0</TT>.
812                         </TD>
813                 </TR>
814                 <TR>
815                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
816                                 &lt;7+258*8&gt;
817                         </TD>
818                         <TD>
819                                 Reserved.  All bits must be set to zero.
820                         </TD>
821                 </TR>
822                 <TR>
823                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
824                                 &lt;8&gt;
825                         </TD>
826                         <TD>
827                                 The number of tracks.  For CD-DA, this number must be no more than 100 (99 regular tracks and one leadout track).
828                         </TD>
829                 </TR>
830                 <TR>
831                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
832                                 <A HREF="#cuesheet_track"><I>CUESHEET_TRACK</I></A>+
833                         </TD>
834                         <TD>
835                                 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.
836                         </TD>
837                 </TR>
838         </TABLE>
839         </TD></TR></TABLE>
840         </P>
841
842         <P>
843         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
844         <TABLE WIDTH="100%" BORDER="1">
845                 <TR>
846                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
847                                 <A NAME="cuesheet_track"><FONT SIZE="+1"><B>CUESHEET_TRACK</B></FONT></A>
848                         </TD>
849                 </TR>
850                 <TR>
851                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
852                                 &lt;64&gt;
853                         </TD>
854                         <TD>
855                                 Track offset in samples, relative to the beginning of the FLAC audio stream.  It is the offset to the first index point of the track.  (Note how this differs from CD-DA, where the track's offset in the TOC is that of the track's INDEX 01 even if there is an INDEX 00.)  For CD-DA, the offset must be evenly divisible by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec).
856                         </TD>
857                 </TR>
858                 <TR>
859                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
860                                 &lt;8&gt;
861                         </TD>
862                         <TD>
863                                 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.  It is not required but encouraged to start with track 1 and increase sequentially.  Track numbers must be unique within a CUESHEET.
864                         </TD>
865                 </TR>
866                 <TR>
867                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
868                                 &lt;12*8&gt;
869                         </TD>
870                         <TD>
871                                 Track ISRC.  This is a 12-digit alphanumeric code; see <A HREF="http://www.ifpi.org/isrc/isrc_handbook.html">here</A> and <A HREF="http://www.disctronics.co.uk/technology/cdaudio/cdaud_isrc.htm">here</A>.  A value of 12 ASCII NUL characters may be used to denote absence of an ISRC.
872                         </TD>
873                 </TR>
874                 <TR>
875                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
876                                 &lt;1&gt;
877                         </TD>
878                         <TD>
879                                 The track type: 0 for audio, 1 for non-audio.  This corresponds to the CD-DA Q-channel control bit 3.
880                         </TD>
881                 </TR>
882                 <TR>
883                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
884                                 &lt;1&gt;
885                         </TD>
886                         <TD>
887                                 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 <A HREF="http://www.chipchapin.com/CDMedia/cdda9.php3">here</A>.
888                         </TD>
889                 </TR>
890                 <TR>
891                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
892                                 &lt;6+13*8&gt;
893                         </TD>
894                         <TD>
895                                 Reserved.  All bits must be set to zero.
896                         </TD>
897                 </TR>
898                 <TR>
899                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
900                                 &lt;8&gt;
901                         </TD>
902                         <TD>
903                                 The number of track index points.  There must be at least one index in every track in a CUESHEET except for the lead-out track, which must have zero.  For CD-DA, this number may be no more than 100.
904                         </TD>
905                 </TR>
906                 <TR>
907                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
908                                 <A HREF="#cuesheet_track_index"><I>CUESHEET_TRACK_INDEX</I></A>+
909                         </TD>
910                         <TD>
911                                 For all tracks except the lead-out track, one or more track index points.
912                         </TD>
913                 </TR>
914         </TABLE>
915         </TD></TR></TABLE>
916         </P>
917
918         <P>
919         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
920         <TABLE WIDTH="100%" BORDER="1">
921                 <TR>
922                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
923                                 <A NAME="cuesheet_track_index"><FONT SIZE="+1"><B>CUESHEET_TRACK_INDEX</B></FONT></A>
924                         </TD>
925                 </TR>
926                 <TR>
927                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
928                                 &lt;64&gt;
929                         </TD>
930                         <TD>
931                                 Offset in samples, relative to the track offset, of the index point.  For CD-DA, the offset must be evenly divisible by 588 samples (588 samples = 44100 samples/sec * 1/75th of a sec).  Note that the offset is from the beginning of the track, not the beginning of the audio data.
932                         </TD>
933                 </TR>
934                 <TR>
935                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
936                                 &lt;8&gt;
937                         </TD>
938                         <TD>
939                                 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.
940                         </TD>
941                 </TR>
942                 <TR>
943                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
944                                 &lt;3*8&gt;
945                         </TD>
946                         <TD>
947                                 Reserved.  All bits must be set to zero.
948                         </TD>
949                 </TR>
950         </TABLE>
951         </TD></TR></TABLE>
952         </P>
953
954         <P>
955         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
956         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
957                 <TR>
958                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
959                                 <A NAME="frame"><FONT SIZE="+1"><B>FRAME</B></FONT></A>
960                         </TD>
961                 </TR>
962                 <TR>
963                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
964                                 <A HREF="#frame_header"><I>FRAME_HEADER</I></A>
965                         </TD>
966                         <TD>
967                                 &nbsp;
968                         </TD>
969                 </TR>
970                 <TR>
971                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
972                                 <A HREF="#subframe"><I>SUBFRAME</I></A>+
973                         </TD>
974                         <TD>
975                                 One SUBFRAME per channel.
976                         </TD>
977                 </TR>
978                 <TR>
979                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
980                                 &lt;?&gt;
981                         </TD>
982                         <TD>
983                                 Zero-padding to byte alignment.
984                         </TD>
985                 </TR>
986                 <TR>
987                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
988                                 <A HREF="#frame_footer"><I>FRAME_FOOTER</I></A>
989                         </TD>
990                         <TD>
991                                 &nbsp;
992                         </TD>
993                 </TR>
994         </TABLE>
995         </TD></TR></TABLE>
996         </P>
997
998         <P>
999         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1000         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1001                 <TR>
1002                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1003                                 <A NAME="frame_header"><FONT SIZE="+1"><B>FRAME_HEADER</B></FONT></A>
1004                         </TD>
1005                 </TR>
1006                 <TR>
1007                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1008                                 &lt;14&gt;
1009                         </TD>
1010                         <TD>
1011                                 Sync code '<TT>11111111111110</TT>'
1012                         </TD>
1013                 </TR>
1014                 <TR>
1015                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1016                                 &lt;2&gt;
1017                         </TD>
1018                         <TD>
1019                                 Reserved:<BR>
1020                                 <UL>
1021                                 <LI>
1022                                         <TT>00</TT> : mandatory value
1023                                 </LI>
1024                                 <LI>
1025                                         <TT>01-11</TT> : reserved for future use
1026                                 </LI>
1027                                 </UL>
1028                         </TD>
1029                 </TR>
1030                 <TR>
1031                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1032                                 &lt;4&gt;
1033                         </TD>
1034                         <TD>
1035                                 Block size in inter-channel samples:<BR>
1036                                 <UL>
1037                                 <LI>
1038                                         <TT>0000</TT> : get from STREAMINFO metadata block
1039                                 </LI>
1040                                 <LI>
1041                                         <TT>0001</TT> : 192 samples
1042                                 </LI>
1043                                 <LI>
1044                                         <TT>0010-0101</TT> : 576 * (2^(n-2)) samples, i.e. 576/1152/2304/4608
1045                                 </LI>
1046                                 <LI>
1047                                         <TT>0110</TT> : get 8 bit (blocksize-1) from end of header
1048                                 </LI>
1049                                 <LI>
1050                                         <TT>0111</TT> : get 16 bit (blocksize-1) from end of header
1051                                 </LI>
1052                                 <LI>
1053                                         <TT>1000-1111</TT> : 256 * (2^(n-8)) samples, i.e. 256/512/1024/2048/4096/8192/16384/32768
1054                                 </LI>
1055                                 </UL>
1056                         </TD>
1057                 </TR>
1058                 <TR>
1059                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1060                                 &lt;4&gt;
1061                         </TD>
1062                         <TD>
1063                                 Sample rate:<BR>
1064                                 <UL>
1065                                 <LI>
1066                                         <TT>0000</TT> : get from STREAMINFO metadata block
1067                                 </LI>
1068                                 <LI>
1069                                         <TT>0001-0011</TT> : reserved
1070                                 </LI>
1071                                 <LI>
1072                                         <TT>0100</TT> : 8kHz
1073                                 </LI>
1074                                 <LI>
1075                                         <TT>0101</TT> : 16kHz
1076                                 </LI>
1077                                 <LI>
1078                                         <TT>0110</TT> : 22.05kHz
1079                                 </LI>
1080                                 <LI>
1081                                         <TT>0111</TT> : 24kHz
1082                                 </LI>
1083                                 <LI>
1084                                         <TT>1000</TT> : 32kHz
1085                                 </LI>
1086                                 <LI>
1087                                         <TT>1001</TT> : 44.1kHz
1088                                 </LI>
1089                                 <LI>
1090                                         <TT>1010</TT> : 48kHz
1091                                 </LI>
1092                                 <LI>
1093                                         <TT>1011</TT> : 96kHz
1094                                 </LI>
1095                                 <LI>
1096                                         <TT>1100</TT> : get 8 bit sample rate (in kHz) from end of header
1097                                 </LI>
1098                                 <LI>
1099                                         <TT>1101</TT> : get 16 bit sample rate (in Hz) from end of header
1100                                 </LI>
1101                                 <LI>
1102                                         <TT>1110</TT> : get 16 bit sample rate (in tens of Hz) from end of header
1103                                 </LI>
1104                                 <LI>
1105                                         <TT>1111</TT> : invalid, to prevent sync-fooling string of 1s
1106                                 </LI>
1107                                 </UL>
1108                         </TD>
1109                 </TR>
1110                 <TR>
1111                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1112                                 &lt;4&gt;
1113                         </TD>
1114                         <TD>
1115                                 Channel assignment
1116                                 <UL>
1117                                 <LI>
1118                                         <TT>0000-0111</TT> : (number of independent channels)-1.  when == 0001, channel 0 is the left channel and channel 1 is the right
1119                                 </LI>
1120                                 <LI>
1121                                         <TT>1000</TT> : left/side stereo: channel 0 is the left channel, channel 1 is the side(difference) channel
1122                                 </LI>
1123                                 <LI>
1124                                         <TT>1001</TT> : right/side stereo: channel 0 is the side(difference) channel, channel 1 is the right channel
1125                                 </LI>
1126                                 <LI>
1127                                         <TT>1010</TT> : mid/side stereo: channel 0 is the mid(average) channel, channel 1 is the side(difference) channel
1128                                 </LI>
1129                                 <LI>
1130                                         <TT>1011-1111</TT> : reserved
1131                                 </LI>
1132                                 </UL>
1133                         </TD>
1134                 </TR>
1135                 <TR>
1136                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1137                                 &lt;3&gt;
1138                         </TD>
1139                         <TD>
1140                                 Sample size in bits:<BR>
1141                                 <UL>
1142                                 <LI>
1143                                         <TT>000</TT> : get from STREAMINFO metadata block
1144                                 </LI>
1145                                 <LI>
1146                                         <TT>001</TT> : 8 bits per sample
1147                                 </LI>
1148                                 <LI>
1149                                         <TT>010</TT> : 12 bits per sample
1150                                 </LI>
1151                                 <LI>
1152                                         <TT>011</TT> : reserved
1153                                 </LI>
1154                                 <LI>
1155                                         <TT>100</TT> : 16 bits per sample
1156                                 </LI>
1157                                 <LI>
1158                                         <TT>101</TT> : 20 bits per sample
1159                                 </LI>
1160                                 <LI>
1161                                         <TT>110</TT> : 24 bits per sample
1162                                 </LI>
1163                                 <LI>
1164                                         <TT>111</TT> : reserved
1165                                 </LI>
1166                                 </UL>
1167                         </TD>
1168                 </TR>
1169                 <TR>
1170                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1171                                 &lt;1&gt;
1172                         </TD>
1173                         <TD>
1174                                 Zero bit padding, to prevent sync-fooling string of 1s
1175                         </TD>
1176                 </TR>
1177                 <TR>
1178                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1179                                 &lt;?&gt;
1180                         </TD>
1181                         <TD>
1182                                 if(variable blocksize)<BR>
1183                                 &nbsp;&nbsp;&nbsp;&lt;8-56&gt;:"UTF-8" coded sample number (decoded number is 36 bits)<BR>
1184                                 else<BR>
1185                                 &nbsp;&nbsp;&nbsp;&lt;8-48&gt;:"UTF-8" coded frame number (decoded number is 31 bits)
1186                         </TD>
1187                 </TR>
1188                 <TR>
1189                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1190                                 &lt;?&gt;
1191                         </TD>
1192                         <TD>
1193                                 if(blocksize bits == 011x)<BR>
1194                                 &nbsp;&nbsp;&nbsp;8/16 bit (blocksize-1)
1195                         </TD>
1196                 </TR>
1197                 <TR>
1198                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1199                                 &lt;?&gt;
1200                         </TD>
1201                         <TD>
1202                                 if(sample rate bits == 11xx)<BR>
1203                                 &nbsp;&nbsp;&nbsp;8/16 bit sample rate
1204                         </TD>
1205                 </TR>
1206                 <TR>
1207                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1208                                 &lt;8&gt;
1209                         </TD>
1210                         <TD>
1211                                 CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0) of everything before the crc, including the sync code
1212                         </TD>
1213                 </TR>
1214                 <TR>
1215                         <TD>
1216                         </TD>
1217                         <TD BGCOLOR="#F4F4CC">
1218                                 <FONT SIZE="+1">NOTES</FONT><BR>
1219                                 <UL>
1220                                 <LI>
1221                                         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 unless it has STREAMINFO metadata and the min_blocksize and max_blocksize values in it match.  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.
1222                                 </LI>
1223                                 <LI>
1224                                         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.
1225                                 </LI>
1226                                 </UL>
1227                         </TD>
1228                 </TR>
1229         </TABLE>
1230         </TD></TR></TABLE>
1231         </P>
1232
1233         <P>
1234         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1235         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1236                 <TR>
1237                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1238                                 <A NAME="frame_footer"><FONT SIZE="+1"><B>FRAME_FOOTER</B></FONT></A>
1239                         </TD>
1240                 </TR>
1241                 <TR>
1242                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1243                                 &lt;16&gt;
1244                         </TD>
1245                         <TD>
1246                                 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
1247                         </TD>
1248                 </TR>
1249         </TABLE>
1250         </TD></TR></TABLE>
1251         </P>
1252
1253         <P>
1254         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1255         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1256                 <TR>
1257                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1258                                 <A NAME="subframe"><FONT SIZE="+1"><B>SUBFRAME</B></FONT></A>
1259                         </TD>
1260                 </TR>
1261                 <TR>
1262                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1263                                 <A HREF="#subframe_header"><I>SUBFRAME_HEADER</I></A>
1264                         </TD>
1265                         <TD>
1266                                 &nbsp;
1267                         </TD>
1268                 </TR>
1269                 <TR>
1270                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1271                                 <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>
1272                         </TD>
1273                         <TD VALIGN="TOP">
1274                                 The SUBFRAME_HEADER specifies which one.
1275                         </TD>
1276                 </TR>
1277         </TABLE>
1278         </TD></TR></TABLE>
1279         </P>
1280
1281         <P>
1282         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1283         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1284                 <TR>
1285                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1286                                 <A NAME="subframe_header"><FONT SIZE="+1"><B>SUBFRAME_HEADER</B></FONT></A>
1287                         </TD>
1288                 </TR>
1289                 <TR>
1290                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1291                                 &lt;1&gt;
1292                         </TD>
1293                         <TD>
1294                                 Zero bit padding, to prevent sync-fooling string of 1s
1295                         </TD>
1296                 </TR>
1297                 <TR>
1298                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1299                                 &lt;6&gt;
1300                         </TD>
1301                         <TD>
1302                                 Subframe type:
1303                                 <UL>
1304                                 <LI>
1305                                         <TT>000000</TT> : <A HREF="#subframe_constant">SUBFRAME_CONSTANT</A>
1306                                 </LI>
1307                                 <LI>
1308                                         <TT>000001</TT> : <A HREF="#subframe_verbatim">SUBFRAME_VERBATIM</A>
1309                                 </LI>
1310                                 <LI>
1311                                         <TT>00001x</TT> : reserved
1312                                 </LI>
1313                                 <LI>
1314                                         <TT>0001xx</TT> : reserved
1315                                 </LI>
1316                                 <LI>
1317                                         <TT>001xxx</TT> : if(xxx <= 4) <A HREF="#subframe_fixed">SUBFRAME_FIXED</A>, xxx=order ; else reserved
1318                                 </LI>
1319                                 <LI>
1320                                         <TT>01xxxx</TT> : reserved
1321                                 </LI>
1322                                 <LI>
1323                                         <TT>1xxxxx</TT> : <A HREF="#subframe_lpc">SUBFRAME_LPC</A>, xxxxx=order-1
1324                                 </LI>
1325                                 </UL>
1326                         </TD>
1327                 </TR>
1328                 <TR>
1329                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1330                                 &lt;1+k&gt;
1331                         </TD>
1332                         <TD>
1333                                 'Wasted bits-per-sample' flag:
1334                                 <UL>
1335                                 <LI>
1336                                         <TT>0</TT> : no wasted bits-per-sample in source subblock, k=0
1337                                 </LI>
1338                                 <LI>
1339                                         <TT>1</TT> : k wasted bits-per-sample in source subblock, k-1 follows, unary coded; e.g. k=3 =&gt; 001 follows, k=7 =&gt; 0000001 follows.
1340                                 </LI>
1341                         </TD>
1342                 </TR>
1343         </TABLE>
1344         </TD></TR></TABLE>
1345         </P>
1346
1347         <P>
1348         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1349         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1350                 <TR>
1351                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1352                                 <A NAME="subframe_constant"><FONT SIZE="+1"><B>SUBFRAME_CONSTANT</B></FONT></A>
1353                         </TD>
1354                 </TR>
1355                 <TR>
1356                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1357                                 &lt;n&gt;
1358                         </TD>
1359                         <TD>
1360                                 Unencoded constant value of the subblock, n = frame's bits-per-sample.
1361                         </TD>
1362                 </TR>
1363         </TABLE>
1364         </TD></TR></TABLE>
1365         </P>
1366
1367         <P>
1368         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1369         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1370                 <TR>
1371                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1372                                 <A NAME="subframe_fixed"><FONT SIZE="+1"><B>SUBFRAME_FIXED</B></FONT></A>
1373                         </TD>
1374                 </TR>
1375                 <TR>
1376                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1377                                 &lt;n&gt;
1378                         </TD>
1379                         <TD>
1380                                 Unencoded warm-up samples (n = frame's bits-per-sample * predictor order).
1381                         </TD>
1382                 </TR>
1383                 <TR>
1384                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1385                                 <A HREF="#residual"><I>RESIDUAL</I></A>
1386                         </TD>
1387                         <TD>
1388                                 Encoded residual
1389                         </TD>
1390                 </TR>
1391         </TABLE>
1392         </TD></TR></TABLE>
1393         </P>
1394
1395         <P>
1396         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1397         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1398                 <TR>
1399                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1400                                 <A NAME="subframe_lpc"><FONT SIZE="+1"><B>SUBFRAME_LPC</B></FONT></A>
1401                         </TD>
1402                 </TR>
1403                 <TR>
1404                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1405                                 &lt;n&gt;
1406                         </TD>
1407                         <TD>
1408                                 Unencoded warm-up samples (n = frame's bits-per-sample * lpc order).
1409                         </TD>
1410                 </TR>
1411                 <TR>
1412                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1413                                 &lt;4&gt;
1414                         </TD>
1415                         <TD>
1416                                 (Quantized linear predictor coefficients' precision in bits)-1 (1111 = invalid).
1417                         </TD>
1418                 </TR>
1419                 <TR>
1420                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1421                                 &lt;5&gt;
1422                         </TD>
1423                         <TD>
1424                                 Quantized linear predictor coefficient shift needed in bits (NOTE: this number is signed two's-complement).
1425                         </TD>
1426                 </TR>
1427                 <TR>
1428                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1429                                 &lt;n&gt;
1430                         </TD>
1431                         <TD>
1432                                 Unencoded predictor coefficients (n = qlp coeff precision * lpc order) (NOTE: the coefficients are signed two's-complement).
1433                         </TD>
1434                 </TR>
1435                 <TR>
1436                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1437                                 <A HREF="#residual"><I>RESIDUAL</I></A>
1438                         </TD>
1439                         <TD>
1440                                 Encoded residual
1441                         </TD>
1442                 </TR>
1443         </TABLE>
1444         </TD></TR></TABLE>
1445         </P>
1446
1447         <P>
1448         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1449         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1450                 <TR>
1451                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1452                                 <A NAME="subframe_verbatim"><FONT SIZE="+1"><B>SUBFRAME_VERBATIM</B></FONT></A>
1453                         </TD>
1454                 </TR>
1455                 <TR>
1456                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1457                                 &lt;n*i&gt;
1458                         </TD>
1459                         <TD>
1460                                 Unencoded subblock; n = frame's bits-per-sample, i = frame's blocksize.
1461                         </TD>
1462                 </TR>
1463         </TABLE>
1464         </TD></TR></TABLE>
1465         </P>
1466
1467         <P>
1468         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1469         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1470                 <TR>
1471                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1472                                 <A NAME="residual"><FONT SIZE="+1"><B>RESIDUAL</B></FONT></A>
1473                         </TD>
1474                 </TR>
1475                 <TR>
1476                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1477                                 &lt;2&gt;
1478                         </TD>
1479                         <TD>
1480                                 Residual coding method:<BR>
1481                                 <UL>
1482                                 <LI>
1483                                         <TT>00</TT> : partitioned rice coding
1484                                 </LI>
1485                                 <LI>
1486                                         <TT>01-11</TT> : reserved
1487                                 </LI>
1488                                 </UL>
1489                         </TD>
1490                 </TR>
1491                 <TR>
1492                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1493                                 <A HREF="#partitioned_rice"><I>RESIDUAL_CODING_METHOD_PARTITIONED_RICE</I></A>
1494                         </TD>
1495                         <TD>
1496                                 &nbsp;
1497                         </TD>
1498                 </TR>
1499                 <TR>
1500                         <TD>
1501                         </TD>
1502                         <TD BGCOLOR="#F4F4CC">
1503                                 <FONT SIZE="+1">NOTES</FONT><BR>
1504                                 <UL>
1505                                 <LI>
1506                                         Currently, FLAC specifies only one entropy coding method.
1507                                 </LI>
1508                                 </UL>
1509                         </TD>
1510                 </TR>
1511         </TABLE>
1512         </TD></TR></TABLE>
1513         </P>
1514
1515         <P>
1516         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1517         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1518                 <TR>
1519                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1520                                 <A NAME="partitioned_rice"><FONT SIZE="+1"><B>RESIDUAL_CODING_METHOD_PARTITIONED_RICE</B></FONT></A>
1521                         </TD>
1522                 </TR>
1523                 <TR>
1524                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1525                                 &lt;4&gt;
1526                         </TD>
1527                         <TD>
1528                                 Partition order.
1529                         </TD>
1530                 </TR>
1531                 <TR>
1532                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1533                                 <A HREF="#rice_partition"><I>RICE_PARTITION</I></A>+
1534                         </TD>
1535                         <TD>
1536                                 There will be 2^order partitions.
1537                         </TD>
1538                 </TR>
1539         </TABLE>
1540         </TD></TR></TABLE>
1541         </P>
1542
1543         <P>
1544         <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#EEEED4"><TR><TD>
1545         <TABLE WIDTH="100%" BORDER="1" BGCOLOR="#EEEED4">
1546                 <TR>
1547                         <TD COLSPAN="2" BGCOLOR="#D3D4C5">
1548                                 <A NAME="rice_partition"><FONT SIZE="+1"><B>RICE_PARTITION</B></FONT></A>
1549                         </TD>
1550                 </TR>
1551                 <TR>
1552                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1553                                 &lt;4(+5)&gt;
1554                         </TD>
1555                         <TD>
1556                                 Encoding parameter:<BR>
1557                                 <UL>
1558                                 <LI>
1559                                         <TT>0000-1110</TT> : Rice parameter.
1560                                 </LI>
1561                                 <LI>
1562                                         <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.
1563                                 </LI>
1564                                 </UL>
1565                         </TD>
1566                 </TR>
1567                 <TR>
1568                         <TD ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#F4F4CC">
1569                                 &lt;?&gt;
1570                         </TD>
1571                         <TD>
1572                                 Encoded residual.  The number of samples (n) in the partition is determined as follows:<BR>
1573                                 <UL>
1574                                 <LI>
1575                                         if the partition order is zero, n = frame's blocksize - predictor order
1576                                 </LI>
1577                                 <LI>
1578                                         else if this is not the first partition of the subframe, n = (frame's blocksize / (2^partition order))
1579                                 </LI>
1580                                 <LI>
1581                                         else n = (frame's blocksize / (2^partition order)) - predictor order
1582                                 </LI>
1583                                 </UL>
1584                         </TD>
1585                 </TR>
1586         </TABLE>
1587         </TD></TR></TABLE>
1588         </P>
1589
1590 </TD></TR>
1591 </TABLE>
1592
1593
1594 </CENTER>
1595
1596 <P>&nbsp;Copyright (c) 2000,2001,2002,2003,2004 Josh Coalson</P>
1597
1598 </BODY>
1599 </HTML>