96ae4b7b1eb174c8bacc8d80c0285f9e1d5d4d07
[platform/upstream/flac.git] / include / FLAC / format.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002,2003  Josh Coalson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * - Neither the name of the Xiph.org Foundation nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #ifndef FLAC__FORMAT_H
33 #define FLAC__FORMAT_H
34
35 #include "export.h"
36 #include "ordinals.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /** \file include/FLAC/format.h
43  *
44  *  \brief
45  *  This module contains structure definitions for the representation
46  *  of FLAC format components in memory.  These are the basic
47  *  structures used by the rest of the interfaces.
48  *
49  *  See the detailed documentation in the
50  *  \link flac_format format \endlink module.
51  */
52
53 /** \defgroup flac_format FLAC/format.h: format components
54  *  \ingroup flac
55  *
56  *  \brief
57  *  This module contains structure definitions for the representation
58  *  of FLAC format components in memory.  These are the basic
59  *  structures used by the rest of the interfaces.
60  *
61  *  First, you should be familiar with the
62  *  <A HREF="../format.html">FLAC format</A>.  Many of the values here
63  *  follow directly from the specification.  As a user of libFLAC, the
64  *  interesting parts really are the structures that describe the frame
65  *  header and metadata blocks.
66  *
67  *  The format structures here are very primitive, designed to store
68  *  information in an efficient way.  Reading information from the
69  *  structures is easy but creating or modifying them directly is
70  *  more complex.  For the most part, as a user of a library, editing
71  *  is not necessary; however, for metadata blocks it is, so there are
72  *  convenience functions provided in the \link flac_metadata metadata
73  *  module \endlink to simplify the manipulation of metadata blocks.
74  *
75  * \note
76  * It's not the best convention, but symbols ending in _LEN are in bits
77  * and _LENGTH are in bytes.  _LENGTH symbols are \#defines instead of
78  * global variables because they are usually used when declaring byte
79  * arrays and some compilers require compile-time knowledge of array
80  * sizes when declared on the stack.
81  *
82  * \{
83  */
84
85
86 /*
87         Most of the values described in this file are defined by the FLAC
88         format specification.  There is nothing to tune here.
89 */
90
91 /** The minimum block size, in samples, permitted by the format. */
92 #define FLAC__MIN_BLOCK_SIZE (16u)
93
94 /** The maximum block size, in samples, permitted by the format. */
95 #define FLAC__MAX_BLOCK_SIZE (65535u)
96
97 /** The maximum number of channels permitted by the format. */
98 #define FLAC__MAX_CHANNELS (8u)
99
100 /** The minimum sample resolution permitted by the format. */
101 #define FLAC__MIN_BITS_PER_SAMPLE (4u)
102
103 /** The maximum sample resolution permitted by the format. */
104 #define FLAC__MAX_BITS_PER_SAMPLE (32u)
105
106 /** The maximum sample resolution permitted by libFLAC.
107  *
108  * \warning
109  * FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format.  However,
110  * the reference encoder/decoder is currently limited to 24 bits because
111  * of prevalent 32-bit math, so make sure and use this value when
112  * appropriate.
113  */
114 #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
115
116 /** The maximum sample rate permitted by the format.  The value is
117  *  ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
118  *  as to why.
119  */
120 #define FLAC__MAX_SAMPLE_RATE (655350u)
121
122 /** The maximum LPC order permitted by the format. */
123 #define FLAC__MAX_LPC_ORDER (32u)
124
125 /** The minimum quantized linear predictor coefficient precision
126  *  permitted by the format.
127  */
128 #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
129
130 /** The maximum quantized linear predictor coefficient precision
131  *  permitted by the format.
132  */
133 #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
134
135 /** The maximum order of the fixed predictors permitted by the format. */
136 #define FLAC__MAX_FIXED_ORDER (4u)
137
138 /** The maximum Rice partition order permitted by the format. */
139 #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
140
141 /** The maximum Rice partition order permitted by the FLAC Subset. */
142 #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
143
144 /** The version string of the release, stamped onto the libraries and binaries.
145  *
146  * \note
147  * This does not correspond to the shared library version number, which
148  * is used to determine binary compatibility.
149  */
150 extern FLAC_API const char *FLAC__VERSION_STRING;
151
152 /** The vendor string inserted by the encoder into the VORBIS_COMMENT block.
153  *  This is a nulL-terminated ASCII string; when inserted into the
154  *  VORBIS_COMMENT the trailing null is stripped.
155  */
156 extern FLAC_API const char *FLAC__VENDOR_STRING;
157
158 /** The byte string representation of the beginning of a FLAC stream. */
159 extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
160
161 /** The 32-bit integer big-endian representation of the beginning of
162  *  a FLAC stream.
163  */
164 extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
165
166 /** The length of the FLAC signature in bits. */
167 extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
168
169 /** The length of the FLAC signature in bytes. */
170 #define FLAC__STREAM_SYNC_LENGTH (4u)
171
172
173 /*****************************************************************************
174  *
175  * Subframe structures
176  *
177  *****************************************************************************/
178
179 /*****************************************************************************/
180
181 /** An enumeration of the available entropy coding methods. */
182 typedef enum {
183         FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
184         /**< Residual is coded by partitioning into contexts, each with it's own
185          * Rice parameter. */
186 } FLAC__EntropyCodingMethodType;
187
188 /** Maps a FLAC__EntropyCodingMethodType to a C string.
189  *
190  *  Using a FLAC__EntropyCodingMethodType as the index to this array will
191  *  give the string equivalent.  The contents should not be modified.
192  */
193 extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
194
195
196 /** Contents of a Rice partitioned residual
197  */
198 typedef struct {
199
200         unsigned *parameters;
201         /**< The Rice parameters for each context. */
202
203         unsigned *raw_bits;
204         /**< Widths for escape-coded partitions. */
205
206         unsigned capacity_by_order;
207         /**< The capacity of the \a parameters and \a raw_bits arrays
208          * specified as an order, i.e. the number of array elements
209          * allocated is 2 ^ \a capacity_by_order.
210          */
211 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
212
213 /** Header for a Rice partitioned residual.  (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
214  */
215 typedef struct {
216
217         unsigned order;
218         /**< The partition order, i.e. # of contexts = 2 ^ \a order. */
219
220         const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
221         /**< The context's Rice parameters and/or raw bits. */
222
223 } FLAC__EntropyCodingMethod_PartitionedRice;
224
225 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
226 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
227 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
228
229 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
230 /**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
231
232 /** Header for the entropy coding method.  (c.f. <A HREF="../format.html#residual">format specification</A>)
233  */
234 typedef struct {
235         FLAC__EntropyCodingMethodType type;
236         union {
237                 FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
238         } data;
239 } FLAC__EntropyCodingMethod;
240
241 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
242
243 /*****************************************************************************/
244
245 /** An enumeration of the available subframe types. */
246 typedef enum {
247         FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
248         FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
249         FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
250         FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
251 } FLAC__SubframeType;
252
253 /** Maps a FLAC__SubframeType to a C string.
254  *
255  *  Using a FLAC__SubframeType as the index to this array will
256  *  give the string equivalent.  The contents should not be modified.
257  */
258 extern FLAC_API const char * const FLAC__SubframeTypeString[];
259
260
261 /** CONSTANT subframe.  (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
262  */
263 typedef struct {
264         FLAC__int32 value; /**< The constant signal value. */
265 } FLAC__Subframe_Constant;
266
267
268 /** VERBATIM subframe.  (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
269  */
270 typedef struct {
271         const FLAC__int32 *data; /**< A pointer to verbatim signal. */
272 } FLAC__Subframe_Verbatim;
273
274
275 /** FIXED subframe.  (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
276  */
277 typedef struct {
278         FLAC__EntropyCodingMethod entropy_coding_method;
279         /**< The residual coding method. */
280
281         unsigned order;
282         /**< The polynomial order. */
283
284         FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
285         /**< Warmup samples to prime the predictor, length == order. */
286
287         const FLAC__int32 *residual;
288         /**< The residual signal, length == (blocksize minus order) samples. */
289 } FLAC__Subframe_Fixed;
290
291
292 /** LPC subframe.  (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
293  */
294 typedef struct {
295         FLAC__EntropyCodingMethod entropy_coding_method;
296         /**< The residual coding method. */
297
298         unsigned order;
299         /**< The FIR order. */
300
301         unsigned qlp_coeff_precision;
302         /**< Quantized FIR filter coefficient precision in bits. */
303
304         int quantization_level;
305         /**< The qlp coeff shift needed. */
306
307         FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
308         /**< FIR filter coefficients. */
309
310         FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
311         /**< Warmup samples to prime the predictor, length == order. */
312
313         const FLAC__int32 *residual;
314         /**< The residual signal, length == (blocksize minus order) samples. */
315 } FLAC__Subframe_LPC;
316
317 extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
318 extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
319
320
321 /** FLAC subframe structure.  (c.f. <A HREF="../format.html#subframe">format specification</A>)
322  */
323 typedef struct {
324         FLAC__SubframeType type;
325         union {
326                 FLAC__Subframe_Constant constant;
327                 FLAC__Subframe_Fixed fixed;
328                 FLAC__Subframe_LPC lpc;
329                 FLAC__Subframe_Verbatim verbatim;
330         } data;
331         unsigned wasted_bits;
332 } FLAC__Subframe;
333
334 extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; /**< == 1 (bit) */
335 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
336 extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
337
338 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
339 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
340 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
341 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
342
343 /*****************************************************************************/
344
345
346 /*****************************************************************************
347  *
348  * Frame structures
349  *
350  *****************************************************************************/
351
352 /** An enumeration of the available channel assignments. */
353 typedef enum {
354         FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
355         FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
356         FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
357         FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
358 } FLAC__ChannelAssignment;
359
360 /** Maps a FLAC__ChannelAssignment to a C string.
361  *
362  *  Using a FLAC__ChannelAssignment as the index to this array will
363  *  give the string equivalent.  The contents should not be modified.
364  */
365 extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
366
367 /** An enumeration of the possible frame numbering methods. */
368 typedef enum {
369         FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
370         FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
371 } FLAC__FrameNumberType;
372
373 /** Maps a FLAC__FrameNumberType to a C string.
374  *
375  *  Using a FLAC__FrameNumberType as the index to this array will
376  *  give the string equivalent.  The contents should not be modified.
377  */
378 extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
379
380
381 /** FLAC frame header structure.  (c.f. <A HREF="../format.html#frame_header">format specification</A>)
382  */
383 typedef struct {
384         unsigned blocksize;
385         /**< The number of samples per subframe. */
386
387         unsigned sample_rate;
388         /**< The sample rate in Hz. */
389
390         unsigned channels;
391         /**< The number of channels (== number of subframes). */
392
393         FLAC__ChannelAssignment channel_assignment;
394         /**< The channel assignment for the frame. */
395
396         unsigned bits_per_sample;
397         /**< The sample resolution. */
398
399         FLAC__FrameNumberType number_type;
400         /**< The numbering scheme used for the frame. */
401
402         union {
403                 FLAC__uint32 frame_number;
404                 FLAC__uint64 sample_number;
405         } number;
406         /**< The frame number or sample number of first sample in frame;
407          * use the \a number_type value to determine which to use. */
408
409         FLAC__uint8 crc;
410         /**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0)
411          * of the raw frame header bytes, meaning everything before the CRC byte
412          * including the sync code.
413          */
414 } FLAC__FrameHeader;
415
416 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
417 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
418 extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 2 (bits) */
419 extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
420 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
421 extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
422 extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
423 extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
424 extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
425
426
427 /** FLAC frame footer structure.  (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
428  */
429 typedef struct {
430         FLAC__uint16 crc;
431         /**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with
432          * 0) of the bytes before the crc, back to and including the frame header
433          * sync code.
434          */
435 } FLAC__FrameFooter;
436
437 extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
438
439
440 /** FLAC frame structure.  (c.f. <A HREF="../format.html#frame">format specification</A>)
441  */
442 typedef struct {
443         FLAC__FrameHeader header;
444         FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
445         FLAC__FrameFooter footer;
446 } FLAC__Frame;
447
448 /*****************************************************************************/
449
450
451 /*****************************************************************************
452  *
453  * Meta-data structures
454  *
455  *****************************************************************************/
456
457 /** An enumeration of the available metadata block types. */
458 typedef enum {
459
460         FLAC__METADATA_TYPE_STREAMINFO = 0,
461         /**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
462
463         FLAC__METADATA_TYPE_PADDING = 1,
464         /**< <A HREF="../format.html#metadata_block_padding">PADDING</A> block */
465
466         FLAC__METADATA_TYPE_APPLICATION = 2,
467         /**< <A HREF="../format.html#metadata_block_application">APPLICATION</A> block */
468
469         FLAC__METADATA_TYPE_SEEKTABLE = 3,
470         /**< <A HREF="../format.html#metadata_block_seektable">SEEKTABLE</A> block */
471
472         FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
473         /**< <A HREF="../format.html#metadata_block_vorbis_comment">VORBISCOMMENT</A> block */
474
475         FLAC__METADATA_TYPE_CUESHEET = 5,
476         /**< <A HREF="../format.html#metadata_block_cuesheet">CUESHEET</A> block */
477
478         FLAC__METADATA_TYPE_UNDEFINED = 6
479         /**< marker to denote beginning of undefined type range; this number will increase as new metadata types are added */
480
481 } FLAC__MetadataType;
482
483 /** Maps a FLAC__MetadataType to a C string.
484  *
485  *  Using a FLAC__MetadataType as the index to this array will
486  *  give the string equivalent.  The contents should not be modified.
487  */
488 extern FLAC_API const char * const FLAC__MetadataTypeString[];
489
490
491 /** FLAC STREAMINFO structure.  (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
492  */
493 typedef struct {
494         unsigned min_blocksize, max_blocksize;
495         unsigned min_framesize, max_framesize;
496         unsigned sample_rate;
497         unsigned channels;
498         unsigned bits_per_sample;
499         FLAC__uint64 total_samples;
500         FLAC__byte md5sum[16];
501 } FLAC__StreamMetadata_StreamInfo;
502
503 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
504 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
505 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
506 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
507 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
508 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
509 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
510 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
511 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
512
513 /** The total stream length of the STREAMINFO block in bytes. */
514 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
515
516 /** FLAC PADDING structure.  (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
517  */
518 typedef struct {
519         int dummy;
520         /**< Conceptually this is an empty struct since we don't store the
521          * padding bytes.  Empty structs are not allowed by some C compilers,
522          * hence the dummy.
523          */
524 } FLAC__StreamMetadata_Padding;
525
526
527 /** FLAC APPLICATION structure.  (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
528  */
529 typedef struct {
530         FLAC__byte id[4];
531         FLAC__byte *data;
532 } FLAC__StreamMetadata_Application;
533
534 extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
535
536 /** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
537  */
538 typedef struct {
539         FLAC__uint64 sample_number;
540         /**<  The sample number of the target frame. */
541
542         FLAC__uint64 stream_offset;
543         /**< The offset, in bytes, of the target frame with respect to
544          * beginning of the first frame. */
545
546         unsigned frame_samples;
547         /**< The number of samples in the target frame. */
548 } FLAC__StreamMetadata_SeekPoint;
549
550 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
551 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
552 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
553
554 /** The total stream length of a seek point in bytes. */
555 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
556
557 /** The value used in the \a sample_number field of
558  *  FLAC__StreamMetadataSeekPoint used to indicate a placeholder
559  *  point (== 0xffffffffffffffff).
560  */
561 extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
562
563
564 /** FLAC SEEKTABLE structure.  (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
565  *
566  * \note From the format specification:
567  * - The seek points must be sorted by ascending sample number.
568  * - Each seek point's sample number must be the first sample of the
569  *   target frame.
570  * - Each seek point's sample number must be unique within the table.
571  * - Existence of a SEEKTABLE block implies a correct setting of
572  *   total_samples in the stream_info block.
573  * - Behavior is undefined when more than one SEEKTABLE block is
574  *   present in a stream.
575  */
576 typedef struct {
577         unsigned num_points;
578         FLAC__StreamMetadata_SeekPoint *points;
579 } FLAC__StreamMetadata_SeekTable;
580
581
582 /** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
583  */
584 typedef struct {
585         FLAC__uint32 length;
586         FLAC__byte *entry;
587 } FLAC__StreamMetadata_VorbisComment_Entry;
588
589 extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
590
591
592 /** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
593  */
594 typedef struct {
595         FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
596         FLAC__uint32 num_comments;
597         FLAC__StreamMetadata_VorbisComment_Entry *comments;
598 } FLAC__StreamMetadata_VorbisComment;
599
600 extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
601
602
603 /** FLAC CUESHEET track index structure.  (See the
604  * <A HREF="../format.html#cuesheet_track_index">format specification</A> for
605  * the full description of each field.)
606  */
607 typedef struct {
608         FLAC__uint64 offset;
609         /**< Offset in samples, relative to the track offset, of the index
610          * point.
611          */
612
613         FLAC__byte number;
614         /**< The index point number. */
615 } FLAC__StreamMetadata_CueSheet_Index;
616
617 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
618 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
619 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
620
621
622 /** FLAC CUESHEET track structure.  (See the
623  * <A HREF="../format.html#cuesheet_track">format specification</A> for
624  * the full description of each field.)
625  */
626 typedef struct {
627         FLAC__uint64 offset;
628         /**< Track offset in samples, relative to the beginning of the FLAC audio stream. */
629
630         FLAC__byte number;
631         /**< The track number. */
632
633         char isrc[13];
634         /**< Track ISRC.  This is a 12-digit alphanumeric code plus a trailing '\0' */
635
636         unsigned type:1;
637         /**< The track type: 0 for audio, 1 for non-audio. */
638
639         unsigned pre_emphasis:1;
640         /**< The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. */
641
642         FLAC__byte num_indices;
643         /**< The number of track index points. */
644
645         FLAC__StreamMetadata_CueSheet_Index *indices;
646         /**< NULL if num_indices == 0, else pointer to array of index points. */
647
648 } FLAC__StreamMetadata_CueSheet_Track;
649
650 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
651 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
652 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
653 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
654 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
655 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
656 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
657
658
659 /** FLAC CUESHEET structure.  (See the
660  * <A HREF="../format.html#metadata_block_cuesheet">format specification</A>
661  * for the full description of each field.)
662  */
663 typedef struct {
664         char media_catalog_number[129];
665         /**< Media catalog number, in ASCII printable characters 0x20-0x7e.  In
666          * general, the media catalog number may be 0 to 128 bytes long; any
667          * unused characters should be right-padded with NUL characters.
668          */
669
670         FLAC__uint64 lead_in;
671         /**< The number of lead-in samples. */
672
673         FLAC__bool is_cd;
674         /**< \c true if CUESHEET corresponds to a Compact Disc, else \c false */
675
676         unsigned num_tracks;
677         /**< The number of tracks. */
678
679         FLAC__StreamMetadata_CueSheet_Track *tracks;
680         /**< NULL if num_tracks == 0, else pointer to array of tracks. */
681
682 } FLAC__StreamMetadata_CueSheet;
683
684 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
685 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
686 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
687 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
688 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
689
690
691 /** Structure that is used when a metadata block of unknown type is loaded.
692  *  The contents are opaque.  The structure is used only internally to
693  *  correctly handle unknown metadata.
694  */
695 typedef struct {
696         FLAC__byte *data;
697 } FLAC__StreamMetadata_Unknown;
698
699
700 /** FLAC metadata block structure.  (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
701  */
702 typedef struct {
703         FLAC__MetadataType type;
704         /**< The type of the metadata block; used determine which member of the
705          * \a data union to dereference.  If type >= FLAC__METADATA_TYPE_UNDEFINED
706          * then \a data.unknown must be used. */
707
708         FLAC__bool is_last;
709         /**< \c true if this metadata block is the last, else \a false */
710
711         unsigned length;
712         /**< Length, in bytes, of the block data as it appears in the stream. */
713
714         union {
715                 FLAC__StreamMetadata_StreamInfo stream_info;
716                 FLAC__StreamMetadata_Padding padding;
717                 FLAC__StreamMetadata_Application application;
718                 FLAC__StreamMetadata_SeekTable seek_table;
719                 FLAC__StreamMetadata_VorbisComment vorbis_comment;
720                 FLAC__StreamMetadata_CueSheet cue_sheet;
721                 FLAC__StreamMetadata_Unknown unknown;
722         } data;
723         /**< Polymorphic block data; use the \a type value to determine which
724          * to use. */
725 } FLAC__StreamMetadata;
726
727 extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
728 extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
729 extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
730
731 /** The total stream length of a metadata block header in bytes. */
732 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
733
734 /*****************************************************************************/
735
736
737 /*****************************************************************************
738  *
739  * Utility functions
740  *
741  *****************************************************************************/
742
743 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
744 /** Tests that a sample rate is valid for FLAC.  Since the rules for valid
745  *  sample rates are slightly complex, they are encapsulated in this function.
746  *
747  * \param sample_rate  The sample rate to test for compliance.
748  * \retval FLAC__bool
749  *    \c true if the given sample rate conforms to the specification, else
750  *    \c false.
751  */
752 FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
753
754 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
755 /** Check a seek table to see if it conforms to the FLAC specification.
756  *  See the format specification for limits on the contents of the
757  *  seek table.
758  *
759  * \param seek_table  A pointer to a seek table to be checked.
760  * \assert
761  *    \code seek_table != NULL \endcode
762  * \retval FLAC__bool
763  *    \c false if seek table is illegal, else \c true.
764  */
765 FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
766
767 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
768 /** Sort a seek table's seek points according to the format specification.
769  *  This includes a "unique-ification" step to remove duplicates, i.e.
770  *  seek points with identical \a sample_number values.  Duplicate seek
771  *  points are converted into placeholder points and sorted to the end of
772  *  the table.
773  *
774  * \param seek_table  A pointer to a seek table to be sorted.
775  * \assert
776  *    \code seek_table != NULL \endcode
777  * \retval unsigned
778  *    The number of duplicate seek points converted into placeholders.
779  */
780 FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
781
782 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
783 /** Check a cue sheet to see if it conforms to the FLAC specification.
784  *  See the format specification for limits on the contents of the
785  *  cue sheet.
786  *
787  * \param cue_sheet  A pointer to an existing cue sheet to be checked.
788  * \param check_cd_da_subset  If \c true, check CUESHEET against more
789  *                   stringent requirements for a CD-DA (audio) disc.
790  * \param violation  Address of a pointer to a string.  If there is a
791  *                   violation, a pointer to a string explanation of the
792  *                   violation will be returned here. \a violation may be
793  *                   \c NULL if you don't need the returned string.  Do not
794  *                   free the returned string; it will always point to static
795  *                   data.
796  * \assert
797  *    \code cue_sheet != NULL \endcode
798  * \retval FLAC__bool
799  *    \c false if cue sheet is illegal, else \c true.
800  */
801 FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
802
803 /* \} */
804
805 #ifdef __cplusplus
806 }
807 #endif
808
809 #endif