6a56f833f1e40146cb9e44bbab81db094458b890
[platform/upstream/flac.git] / include / FLAC / format.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLAC__FORMAT_H
21 #define FLAC__FORMAT_H
22
23 #include "ordinals.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /** \file include/FLAC/format.h
30  *
31  *  \brief
32  *  This module contains structure definitions for the representation
33  *  of FLAC format components in memory.  These are the basic
34  *  structures used by the rest of the interfaces.
35  *
36  *  See the detailed documentation in the
37  *  \link flac_format format \endlink module.
38  */
39
40 /** \defgroup flac_format FLAC/format.h: format components
41  *  \ingroup flac
42  *
43  *  \brief
44  *  This module contains structure definitions for the representation
45  *  of FLAC format components in memory.  These are the basic
46  *  structures used by the rest of the interfaces.
47  *
48  *  First, you should be familiar with the
49  *  <A HREF="../format.html">FLAC format</A>.  Many of the values here
50  *  follow directly from the specification.  As a user of libFLAC, the
51  *  interesting parts really are the structures that describe the frame
52  *  header and metadata blocks.
53  *
54  *  The format structures here are very primitive, designed to store
55  *  information in an efficient way.  Reading information from the
56  *  structures is easy but creating or modifying them directly is
57  *  more complex.  For the most part, as a user of a library, editing
58  *  is not necessary; however, for metadata blocks it is, so there are
59  *  convenience functions provided in the \link flac_metadata metadata
60  *  module \endlink to simplify the manipulation of metadata blocks.
61  *
62  * \note
63  * It's not the best convention, but symbols ending in _LEN are in bits
64  * and _LENGTH are in bytes.  _LENGTH symbols are \#defines instead of
65  * global variables because they are usually used when declaring byte
66  * arrays and some compilers require compile-time knowledge of array
67  * sizes when declared on the stack.
68  *
69  * \{
70  */
71
72
73 /*
74         Most of the values described in this file are defined by the FLAC
75         format specification.  There is nothing to tune here.
76 */
77
78 /** The minimum block size, in samples, permitted by the format. */
79 #define FLAC__MIN_BLOCK_SIZE (16u)
80
81 /** The maximum block size, in samples, permitted by the format. */
82 #define FLAC__MAX_BLOCK_SIZE (65535u)
83
84 /** The maximum number of channels permitted by the format. */
85 #define FLAC__MAX_CHANNELS (8u)
86
87 /** The minimum sample resolution permitted by the format. */
88 #define FLAC__MIN_BITS_PER_SAMPLE (4u)
89
90 /** The maximum sample resolution permitted by the format. */
91 #define FLAC__MAX_BITS_PER_SAMPLE (32u)
92
93 /** The maximum sample resolution permitted by libFLAC.
94  *
95  * \warning
96  * FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format.  However,
97  * the reference encoder/decoder is currently limited to 24 bits because
98  * of prevalent 32-bit math, so make sure and use this value when
99  * appropriate.
100  */
101 #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
102
103 /** The maximum sample rate permitted by the format.  The value is
104  *  ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
105  *  as to why.
106  */
107 #define FLAC__MAX_SAMPLE_RATE (655350u)
108
109 /** The maximum LPC order permitted by the format. */
110 #define FLAC__MAX_LPC_ORDER (32u)
111
112 /** The minimum quantized linear predictor coefficient precision
113  *  permitted by the format.
114  */
115 #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
116
117 /** The maximum order of the fixed predictors permitted by the format. */
118 #define FLAC__MAX_FIXED_ORDER (4u)
119
120 /** The maximum Rice partition order permitted by the format. */
121 #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
122
123 /** The version string of the release, stamped onto the libraries and binaries.
124  *
125  * \note
126  * This does not correspond to the shared library version number, which
127  * is used to determine binary compatibility.
128  */
129 extern const char *FLAC__VERSION_STRING;
130
131 /** The vendor string inserted by the encoder into the VORBIS_COMMENT block.
132  *  This is a nulL-terminated ASCII string; when inserted into the
133  *  VORBIS_COMMENT the trailing null is stripped.
134  */
135 extern const char *FLAC__VENDOR_STRING;
136
137 /** The byte string representation of the beginning of a FLAC stream. */
138 extern const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
139
140 /** The 32-bit integer big-endian representation of the beginning of
141  *  a FLAC stream.
142  */
143 extern const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
144
145 /** The length of the FLAC signature in bits. */
146 extern const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
147
148 /** The length of the FLAC signature in bytes. */
149 #define FLAC__STREAM_SYNC_LENGTH (4u)
150
151
152 /*****************************************************************************
153  *
154  * Subframe structures
155  *
156  *****************************************************************************/
157
158 /*****************************************************************************/
159
160 /** An enumeration of the available entropy coding methods. */
161 typedef enum {
162         FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
163         /**< Residual is coded by partitioning into contexts, each with it's own
164          * Rice parameter. */
165 } FLAC__EntropyCodingMethodType;
166
167 /** Maps a FLAC__EntropyCodingMethodType to a C string.
168  *
169  *  Using a FLAC__EntropyCodingMethodType as the index to this array will
170  *  give the string equivalent.  The contents should not be modified.
171  */
172 extern const char * const FLAC__EntropyCodingMethodTypeString[];
173
174
175 /** Contents of a Rice partitioned residual
176  */
177 typedef struct {
178
179         unsigned *parameters;
180         /**< The Rice parameters for each context. */
181
182         unsigned *raw_bits;
183         /**< Widths for escape-coded partitions. */
184
185         unsigned capacity_by_order;
186         /**< The capacity of the \a parameters and \a raw_bits arrays
187          * specified as an order, i.e. the number of array elements
188          * allocated is 2 ^ \a capacity_by_order.
189          */
190 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
191
192 /** Header for a Rice partitioned residual.  (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
193  */
194 typedef struct {
195
196         unsigned order;
197         /**< The partition order, i.e. # of contexts = 2 ^ \a order. */
198
199         const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
200         /**< The context's Rice parameters and/or raw bits. */
201
202 } FLAC__EntropyCodingMethod_PartitionedRice;
203
204 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
205 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
206 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
207
208 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
209 /**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
210
211 /** Header for the entropy coding method.  (c.f. <A HREF="../format.html#residual">format specification</A>)
212  */
213 typedef struct {
214         FLAC__EntropyCodingMethodType type;
215         union {
216                 FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
217         } data;
218 } FLAC__EntropyCodingMethod;
219
220 extern const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
221
222 /*****************************************************************************/
223
224 /** An enumeration of the available subframe types. */
225 typedef enum {
226         FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
227         FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
228         FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
229         FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
230 } FLAC__SubframeType;
231
232 /** Maps a FLAC__SubframeType to a C string.
233  *
234  *  Using a FLAC__SubframeType as the index to this array will
235  *  give the string equivalent.  The contents should not be modified.
236  */
237 extern const char * const FLAC__SubframeTypeString[];
238
239
240 /** CONSTANT subframe.  (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
241  */
242 typedef struct {
243         FLAC__int32 value; /**< The constant signal value. */
244 } FLAC__Subframe_Constant;
245
246
247 /** VERBATIM subframe.  (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
248  */
249 typedef struct {
250         const FLAC__int32 *data; /**< A pointer to verbatim signal. */
251 } FLAC__Subframe_Verbatim;
252
253
254 /** FIXED subframe.  (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
255  */
256 typedef struct {
257         FLAC__EntropyCodingMethod entropy_coding_method;
258         /**< The residual coding method. */
259
260         unsigned order;
261         /**< The polynomial order. */
262
263         FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
264         /**< Warmup samples to prime the predictor, length == order. */
265
266         const FLAC__int32 *residual;
267         /**< The residual signal, length == (blocksize minus order) samples. */
268 } FLAC__Subframe_Fixed;
269
270
271 /** LPC subframe.  (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
272  */
273 typedef struct {
274         FLAC__EntropyCodingMethod entropy_coding_method;
275         /**< The residual coding method. */
276
277         unsigned order;
278         /**< The FIR order. */
279
280         unsigned qlp_coeff_precision;
281         /**< Quantized FIR filter coefficient precision in bits. */
282
283         int quantization_level;
284         /**< The qlp coeff shift needed. */
285
286         FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
287         /**< FIR filter coefficients. */
288
289         FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
290         /**< Warmup samples to prime the predictor, length == order. */
291
292         const FLAC__int32 *residual;
293         /**< The residual signal, length == (blocksize minus order) samples. */
294 } FLAC__Subframe_LPC;
295
296 extern const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
297 extern const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
298
299
300 /** FLAC subframe structure.  (c.f. <A HREF="../format.html#subframe">format specification</A>)
301  */
302 typedef struct {
303         FLAC__SubframeType type;
304         union {
305                 FLAC__Subframe_Constant constant;
306                 FLAC__Subframe_Fixed fixed;
307                 FLAC__Subframe_LPC lpc;
308                 FLAC__Subframe_Verbatim verbatim;
309         } data;
310         unsigned wasted_bits;
311 } FLAC__Subframe;
312
313 extern const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; /**< == 1 (bit) */
314 extern const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
315 extern const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
316
317 extern const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
318 extern const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
319 extern const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
320 extern const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
321
322 /*****************************************************************************/
323
324
325 /*****************************************************************************
326  *
327  * Frame structures
328  *
329  *****************************************************************************/
330
331 /** An enumeration of the available channel assignments. */
332 typedef enum {
333         FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
334         FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
335         FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
336         FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
337 } FLAC__ChannelAssignment;
338
339 /** Maps a FLAC__ChannelAssignment to a C string.
340  *
341  *  Using a FLAC__ChannelAssignment as the index to this array will
342  *  give the string equivalent.  The contents should not be modified.
343  */
344 extern const char * const FLAC__ChannelAssignmentString[];
345
346 /** An enumeration of the possible frame numbering methods. */
347 typedef enum {
348         FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
349         FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
350 } FLAC__FrameNumberType;
351
352 /** Maps a FLAC__FrameNumberType to a C string.
353  *
354  *  Using a FLAC__FrameNumberType as the index to this array will
355  *  give the string equivalent.  The contents should not be modified.
356  */
357 extern const char * const FLAC__FrameNumberTypeString[];
358
359
360 /** FLAC frame header structure.  (c.f. <A HREF="../format.html#frame_header">format specification</A>)
361  */
362 typedef struct {
363         unsigned blocksize;
364         /**< The number of samples per subframe. */
365
366         unsigned sample_rate;
367         /**< The sample rate in Hz. */
368
369         unsigned channels;
370         /**< The number of channels (== number of subframes). */
371
372         FLAC__ChannelAssignment channel_assignment;
373         /**< The channel assignment for the frame. */
374
375         unsigned bits_per_sample;
376         /**< The sample resolution. */
377
378         FLAC__FrameNumberType number_type;
379         /**< The numbering scheme used for the frame. */
380
381         union {
382                 FLAC__uint32 frame_number;
383                 FLAC__uint64 sample_number;
384         } number;
385         /**< The frame number or sample number of first sample in frame;
386          * use the \a number_type value to determine which to use. */
387
388         FLAC__uint8 crc;
389         /**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0)
390          * of the raw frame header bytes, meaning everything before the CRC byte
391          * including the sync code.
392          */
393 } FLAC__FrameHeader;
394
395 extern const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
396 extern const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
397 extern const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 2 (bits) */
398 extern const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
399 extern const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
400 extern const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
401 extern const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
402 extern const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
403 extern const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
404
405
406 /** FLAC frame footer structure.  (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
407  */
408 typedef struct {
409         FLAC__uint16 crc;
410         /**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with
411          * 0) of the bytes before the crc, back to and including the frame header
412          * sync code.
413          */
414 } FLAC__FrameFooter;
415
416 extern const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
417
418
419 /** FLAC frame structure.  (c.f. <A HREF="../format.html#frame">format specification</A>)
420  */
421 typedef struct {
422         FLAC__FrameHeader header;
423         FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
424         FLAC__FrameFooter footer;
425 } FLAC__Frame;
426
427 /*****************************************************************************/
428
429
430 /*****************************************************************************
431  *
432  * Meta-data structures
433  *
434  *****************************************************************************/
435
436 /** An enumeration of the available metadata block types. */
437 typedef enum {
438
439         FLAC__METADATA_TYPE_STREAMINFO = 0,
440         /**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
441
442         FLAC__METADATA_TYPE_PADDING = 1,
443         /**< <A HREF="../format.html#metadata_block_padding"PADDING</A> block */
444
445         FLAC__METADATA_TYPE_APPLICATION = 2,
446         /**< <A HREF="../format.html#metadata_block_application"APPLICATION</A> block */
447
448         FLAC__METADATA_TYPE_SEEKTABLE = 3,
449         /**< <A HREF="../format.html#metadata_block_seektable"SEEKTABLE</A> block */
450
451         FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
452         /**< <A HREF="../format.html#metadata_block_vorbis_comment"VORBISCOMMENT</A> block */
453
454 } FLAC__MetadataType;
455
456 /** Maps a FLAC__MetadataType to a C string.
457  *
458  *  Using a FLAC__MetadataType as the index to this array will
459  *  give the string equivalent.  The contents should not be modified.
460  */
461 extern const char * const FLAC__MetadataTypeString[];
462
463
464 /** FLAC STREAMINFO structure.  (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
465  */
466 typedef struct {
467         unsigned min_blocksize, max_blocksize;
468         unsigned min_framesize, max_framesize;
469         unsigned sample_rate;
470         unsigned channels;
471         unsigned bits_per_sample;
472         FLAC__uint64 total_samples;
473         FLAC__byte md5sum[16];
474 } FLAC__StreamMetadata_StreamInfo;
475
476 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
477 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
478 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
479 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
480 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
481 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
482 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
483 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
484 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
485
486 /** The total stream length of the STREAMINFO block in bytes. */
487 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
488
489 /** FLAC PADDING structure.  (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
490  */
491 typedef struct {
492         int dummy;
493         /**< Conceptually this is an empty struct since we don't store the
494          * padding bytes.  Empty structs are not allowed by some C compilers,
495          * hence the dummy.
496          */
497 } FLAC__StreamMetadata_Padding;
498
499
500 /** FLAC APPLICATION structure.  (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
501  */
502 typedef struct {
503         FLAC__byte id[4];
504         FLAC__byte *data;
505 } FLAC__StreamMetadata_Application;
506
507 extern const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
508
509 /** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
510  */
511 typedef struct {
512         FLAC__uint64 sample_number;
513         /**<  The sample number of the target frame. */
514
515         FLAC__uint64 stream_offset;
516         /**< The offset, in bytes, of the target frame with respect to
517          * beginning of the first frame. */
518
519         unsigned frame_samples;
520         /**< The number of samples in the target frame. */
521 } FLAC__StreamMetadata_SeekPoint;
522
523 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
524 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
525 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
526
527 /** The total stream length of a seek point in bytes. */
528 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
529
530 /** The value used in the \a sample_number field of
531  *  FLAC__StreamMetadataSeekPoint used to indicate a placeholder
532  *  point (== 0xffffffffffffffff).
533  */
534 extern const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
535
536
537 /** FLAC SEEKTABLE structure.  (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
538  *
539  * \note From the format specification:
540  * - The seek points must be sorted by ascending sample number.
541  * - Each seek point's sample number must be the first sample of the
542  *   target frame.
543  * - Each seek point's sample number must be unique within the table.
544  * - Existence of a SEEKTABLE block implies a correct setting of
545  *   total_samples in the stream_info block.
546  * - Behavior is undefined when more than one SEEKTABLE block is
547  *   present in a stream.
548  */
549 typedef struct {
550         unsigned num_points;
551         FLAC__StreamMetadata_SeekPoint *points;
552 } FLAC__StreamMetadata_SeekTable;
553
554
555 /** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
556  */
557 typedef struct {
558         FLAC__uint32 length;
559         FLAC__byte *entry;
560 } FLAC__StreamMetadata_VorbisComment_Entry;
561
562 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
563
564
565 /** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
566  */
567 typedef struct {
568         FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
569         FLAC__uint32 num_comments;
570         FLAC__StreamMetadata_VorbisComment_Entry *comments;
571 } FLAC__StreamMetadata_VorbisComment;
572
573 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
574
575
576 /** FLAC metadata block structure.  (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
577  */
578 typedef struct {
579         FLAC__MetadataType type;
580         /**< The type of the metadata block; used determine which member of the
581          * \a data union to dereference. */
582
583         FLAC__bool is_last;
584         /**< \c true if this metadata block is the last, else \a false */
585
586         unsigned length;
587         /**< Length, in bytes, of the block data as it appears in the stream. */
588
589         union {
590                 FLAC__StreamMetadata_StreamInfo stream_info;
591                 FLAC__StreamMetadata_Padding padding;
592                 FLAC__StreamMetadata_Application application;
593                 FLAC__StreamMetadata_SeekTable seek_table;
594                 FLAC__StreamMetadata_VorbisComment vorbis_comment;
595         } data;
596         /**< Polymorphic block data; use the \a type value to determine which
597          * to use. */
598 } FLAC__StreamMetadata;
599
600 extern const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
601 extern const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
602 extern const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
603
604 /** The total stream length of a metadata block header in bytes. */
605 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
606
607 /*****************************************************************************/
608
609
610 /*****************************************************************************
611  *
612  * Utility functions
613  *
614  *****************************************************************************/
615
616 /** Tests that a sample rate is valid for FLAC.  Since the rules for valid
617  *  sample rates are slightly complex, they are encapsulated in this function.
618  *
619  * \param sample_rate  The sample rate to test for compliance.
620  * \retval FLAC__bool
621  *    \c true if the given sample rate conforms to the specification, else
622  *    \c false.
623  */
624 FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
625
626 /** Check a seek table to see if it conforms to the FLAC specification.
627  *  See the format specification for limits on the contents of the
628  *  seek table.
629  *
630  * \param seek_table  A pointer to a seek table to be checked.
631  * \assert
632  *    \code seek_table != NULL \endcode
633  * \retval FLAC__bool
634  *    \c false if seek table is illegal, else \c true.
635  */
636 FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
637
638 /** Sort a seek table's seek points according to the format specification.
639  *  This includes a "unique-ification" step to remove duplicates, i.e.
640  *  seek points with identical \a sample_number values.  Duplicate seek
641  *  points are converted into placeholder points and sorted to the end of
642  *  the table.
643  *
644  * \param seek_table  A pointer to a seek table to be sorted.
645  * \assert
646  *    \code seek_table != NULL \endcode
647  * \retval unsigned
648  *    The number of duplicate seek points converted into placeholders.
649  */
650 unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
651
652 /* \} */
653
654 #ifdef __cplusplus
655 }
656 #endif
657
658 #endif