5f971dc4e7874c3c2cb19d49b26f2aab956eaa3c
[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 metadata module to simplify
60  *  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 /* VERSION should come from configure */
124 #ifdef VERSION
125 /** The version string of the current library.
126  *
127  * \note
128  * This does not correspond to the shared library version number, which
129  * is used to determine binary compatibility.
130  */
131 #define FLAC__VERSION_STRING VERSION
132 #endif
133
134 /** The byte string representation of the beginning of a FLAC stream. */
135 extern const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */;
136
137 /** The 32-bit integer big-endian representation of the beginning of
138  *  a FLAC stream.
139  */
140 extern const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */;
141
142 /** The length of the FLAC signature in bits. */
143 extern const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */;
144
145 /** The length of the FLAC signature in bytes. */
146 #define FLAC__STREAM_SYNC_LENGTH (4u)
147
148
149 /*****************************************************************************
150  * @@@ REMOVE?
151  * NOTE: Within the bitstream, all fixed-width numbers are big-endian coded.
152  *       All numbers are unsigned unless otherwise noted.
153  *
154  *****************************************************************************/
155
156
157 /*****************************************************************************
158  *
159  * Subframe structures
160  *
161  *****************************************************************************/
162
163 /*****************************************************************************/
164
165 /** An enumeration of the available entropy coding methods. */
166 typedef enum {
167         FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
168         /**< Residual is coded by partitioning into contexts, each with it's own
169      * Rice parameter. */
170 } FLAC__EntropyCodingMethodType;
171
172 /** Maps a FLAC__EntropyCodingMethodType to a C string.
173  *
174  *  Using a FLAC__EntropyCodingMethodType as the index to this array will
175  *  give the string equivalent.  The contents should not be modified.
176  */
177 extern const char * const FLAC__EntropyCodingMethodTypeString[];
178
179
180 /** Header for a Rice partition.  (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
181  */
182 typedef struct {
183
184         unsigned order;
185         /**< The partition order, i.e. # of contexts = 2 ^ order. */
186
187         unsigned parameters[1 << FLAC__MAX_RICE_PARTITION_ORDER];
188         /**< The Rice parameters for each context. */
189
190         unsigned raw_bits[1 << FLAC__MAX_RICE_PARTITION_ORDER];
191         /**< Widths for escape-coded partitions. */
192
193 } FLAC__EntropyCodingMethod_PartitionedRice;
194
195 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
196 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
197 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
198
199 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
200 /**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
201
202 /** Header for the entropy coding method.  (c.f. <A HREF="../format.html#residual">format specification</A>)
203  */
204 typedef struct {
205         FLAC__EntropyCodingMethodType type;
206         union {
207                 FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
208         } data;
209 } FLAC__EntropyCodingMethod;
210
211 extern const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
212
213 /*****************************************************************************/
214
215 /** An enumeration of the available subframe types. */
216 typedef enum {
217         FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
218         FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
219         FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
220         FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
221 } FLAC__SubframeType;
222
223 /** Maps a FLAC__SubframeType to a C string.
224  *
225  *  Using a FLAC__SubframeType as the index to this array will
226  *  give the string equivalent.  The contents should not be modified.
227  */
228 extern const char * const FLAC__SubframeTypeString[];
229
230
231 /** CONSTANT subframe.  (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
232  */
233 typedef struct {
234         FLAC__int32 value; /**< The constant signal value. */
235 } FLAC__Subframe_Constant;
236
237
238 /** VERBATIM subframe.  (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
239  */
240 typedef struct {
241         const FLAC__int32 *data; /**< A pointer to verbatim signal. */
242 } FLAC__Subframe_Verbatim;
243
244
245 /** FIXED subframe.  (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
246  */
247 typedef struct {
248         FLAC__EntropyCodingMethod entropy_coding_method;
249         /**< The residual coding method. */
250
251         unsigned order;
252         /**< The polynomial order. */
253
254         FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
255         /**< Warmup samples to prime the predictor, length == order. */
256
257         const FLAC__int32 *residual;
258         /**< The residual signal, length == (blocksize minus order) samples. */
259 } FLAC__Subframe_Fixed;
260
261
262 /** LPC subframe.  (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
263  */
264 typedef struct {
265         FLAC__EntropyCodingMethod entropy_coding_method;
266         /**< The residual coding method. */
267
268         unsigned order;
269         /**< The FIR order. */
270
271         unsigned qlp_coeff_precision;
272         /**< Quantized FIR filter coefficient precision in bits. */
273
274         int quantization_level;
275         /**< The qlp coeff shift needed. */
276
277         FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
278         /**< FIR filter coefficients. */
279
280         FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
281         /**< Warmup samples to prime the predictor, length == order. */
282
283         const FLAC__int32 *residual;
284         /**< The residual signal, length == (blocksize minus order) samples. */
285 } FLAC__Subframe_LPC;
286
287 extern const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
288 extern const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
289
290
291 /** FLAC subframe structure.  (c.f. <A HREF="../format.html#subframe">format specification</A>)
292  */
293 typedef struct {
294         FLAC__SubframeType type;
295         union {
296                 FLAC__Subframe_Constant constant;
297                 FLAC__Subframe_Fixed fixed;
298                 FLAC__Subframe_LPC lpc;
299                 FLAC__Subframe_Verbatim verbatim;
300         } data;
301         unsigned wasted_bits;
302 } FLAC__Subframe;
303
304 extern const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; /**< == 1 (bit) */
305 extern const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
306 extern const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
307
308 extern const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
309 extern const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
310 extern const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
311 extern const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
312
313 /*****************************************************************************/
314
315
316 /*****************************************************************************
317  *
318  * Frame structures
319  *
320  *****************************************************************************/
321
322 /** An enumeration of the available channel assignments. */
323 typedef enum {
324         FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
325         FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
326         FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
327         FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
328 } FLAC__ChannelAssignment;
329
330 /** Maps a FLAC__ChannelAssignment to a C string.
331  *
332  *  Using a FLAC__ChannelAssignment as the index to this array will
333  *  give the string equivalent.  The contents should not be modified.
334  */
335 extern const char * const FLAC__ChannelAssignmentString[];
336
337 /** An enumeration of the possible frame numbering methods. */
338 typedef enum {
339         FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
340         FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
341 } FLAC__FrameNumberType;
342
343 /** Maps a FLAC__FrameNumberType to a C string.
344  *
345  *  Using a FLAC__FrameNumberType as the index to this array will
346  *  give the string equivalent.  The contents should not be modified.
347  */
348 extern const char * const FLAC__FrameNumberTypeString[];
349
350
351 /** FLAC frame header structure.  (c.f. <A HREF="../format.html#frame_header">format specification</A>)
352  */
353 typedef struct {
354         unsigned blocksize;
355         /**< The number of samples per subframe. */
356
357         unsigned sample_rate;
358         /**< The sample rate in Hz. */
359
360         unsigned channels;
361         /**< The number of channels (== number of subframes). */
362
363         FLAC__ChannelAssignment channel_assignment;
364         /**< The channel assignment for the frame. */
365
366         unsigned bits_per_sample;
367         /**< The sample resolution. */
368
369         FLAC__FrameNumberType number_type;
370         /**< The numbering scheme used for the frame. */
371
372         union {
373                 FLAC__uint32 frame_number;
374                 FLAC__uint64 sample_number;
375         } number;
376         /**< The frame number or sample number of first sample in frame;
377          * use the \a number_type value to determine which to use. */
378
379         FLAC__uint8 crc;
380         /**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0)
381          * of the raw frame header bytes, meaning everything before the CRC byte
382          * including the sync code.
383          */
384 } FLAC__FrameHeader;
385
386 extern const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
387 extern const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
388 extern const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 2 (bits) */
389 extern const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
390 extern const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
391 extern const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
392 extern const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
393 extern const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
394 extern const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
395
396
397 /** FLAC frame footer structure.  (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
398  */
399 typedef struct {
400         FLAC__uint16 crc;
401         /**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with
402          * 0) of the bytes before the crc, back to and including the frame header
403          * sync code.
404          */
405 } FLAC__FrameFooter;
406
407 extern const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
408
409
410 /** FLAC frame structure.  (c.f. <A HREF="../format.html#frame">format specification</A>)
411  */
412 typedef struct {
413         FLAC__FrameHeader header;
414         FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
415         FLAC__FrameFooter footer;
416 } FLAC__Frame;
417
418 /*****************************************************************************/
419
420
421 /*****************************************************************************
422  *
423  * Meta-data structures
424  *
425  *****************************************************************************/
426
427 /** An enumeration of the available metadata block types. */
428 typedef enum {
429
430         FLAC__METADATA_TYPE_STREAMINFO = 0,
431         /**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
432
433         FLAC__METADATA_TYPE_PADDING = 1,
434         /**< <A HREF="../format.html#metadata_block_padding"PADDING</A> block */
435
436         FLAC__METADATA_TYPE_APPLICATION = 2,
437         /**< <A HREF="../format.html#metadata_block_application"APPLICATION</A> block */
438
439         FLAC__METADATA_TYPE_SEEKTABLE = 3,
440         /**< <A HREF="../format.html#metadata_block_seektable"SEEKTABLE</A> block */
441
442         FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
443         /**< <A HREF="../format.html#metadata_block_vorbis_comment"VORBISCOMMENT</A> block */
444
445 } FLAC__MetadataType;
446
447 /** Maps a FLAC__MetadataType to a C string.
448  *
449  *  Using a FLAC__MetadataType as the index to this array will
450  *  give the string equivalent.  The contents should not be modified.
451  */
452 extern const char * const FLAC__MetadataTypeString[];
453
454
455 /** FLAC STREAMINFO structure.  (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
456  */
457 typedef struct {
458         unsigned min_blocksize, max_blocksize;
459         unsigned min_framesize, max_framesize;
460         unsigned sample_rate;
461         unsigned channels;
462         unsigned bits_per_sample;
463         FLAC__uint64 total_samples;
464         FLAC__byte md5sum[16];
465 } FLAC__StreamMetadata_StreamInfo;
466
467 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
468 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
469 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
470 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
471 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
472 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
473 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
474 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
475 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
476
477 /** The total stream length of the STREAMINFO block in bytes. */
478 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
479
480 /** FLAC PADDING structure.  (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
481  */
482 typedef struct {
483         int dummy;
484         /**< Conceptually this is an empty struct since we don't store the
485          * padding bytes.  Empty structs are not allowed by some C compilers,
486          * hence the dummy.
487          */
488 } FLAC__StreamMetadata_Padding;
489
490
491 /** FLAC APPLICATION structure.  (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
492  */
493 typedef struct {
494         FLAC__byte id[4];
495         FLAC__byte *data;
496 } FLAC__StreamMetadata_Application;
497
498 extern const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
499
500 /** SeekPoint structure used in SEEKTABLE blocks.  (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
501  */
502 typedef struct {
503         FLAC__uint64 sample_number;
504         /**<  The sample number of the target frame. */
505
506         FLAC__uint64 stream_offset;
507         /**< The offset, in bytes, of the target frame with respect to
508          * beginning of the first frame. */
509
510         unsigned frame_samples;
511         /**< The number of samples in the target frame. */
512 } FLAC__StreamMetadata_SeekPoint;
513
514 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
515 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
516 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
517
518 /** The total stream length of a seek point in bytes. */
519 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
520
521 /** The value used in the \a sample_number field of
522  *  FLAC__StreamMetadataSeekPoint used to indicate a placeholder
523  *  point (== 0xffffffffffffffff).
524  */
525 extern const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
526
527
528 /** FLAC SEEKTABLE structure.  (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
529  *
530  * \note From the format specification:
531  * - The seek points must be sorted by ascending sample number.
532  * - Each seek point's sample number must be the first sample of the
533  *   target frame.
534  * - Each seek point's sample number must be unique within the table.
535  * - Existence of a SEEKTABLE block implies a correct setting of
536  *   total_samples in the stream_info block.
537  * - Behavior is undefined when more than one SEEKTABLE block is
538  *   present in a stream.
539  */
540 typedef struct {
541         unsigned num_points;
542         FLAC__StreamMetadata_SeekPoint *points;
543 } FLAC__StreamMetadata_SeekTable;
544
545
546 /** Vorbis comment entry structure used in VORBIS_COMMENT blocks.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
547  */
548 typedef struct {
549         FLAC__uint32 length;
550         FLAC__byte *entry;
551 } FLAC__StreamMetadata_VorbisComment_Entry;
552
553 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
554
555
556 /** FLAC VORBIS_COMMENT structure.  (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
557  */
558 typedef struct {
559         FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
560         FLAC__uint32 num_comments;
561         FLAC__StreamMetadata_VorbisComment_Entry *comments;
562 } FLAC__StreamMetadata_VorbisComment;
563
564 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
565
566
567 /** FLAC metadata block structure.  (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
568  */
569 typedef struct {
570         FLAC__MetadataType type;
571         /**< The type of the metadata block; used determine which member of the
572          * \a data union to dereference. */
573
574         FLAC__bool is_last;
575         /**< \c true if this metadata block is the last, else \a false */
576
577         unsigned length;
578         /**< Length, in bytes, of the block data as it appears in the stream. */
579
580         union {
581                 FLAC__StreamMetadata_StreamInfo stream_info;
582                 FLAC__StreamMetadata_Padding padding;
583                 FLAC__StreamMetadata_Application application;
584                 FLAC__StreamMetadata_SeekTable seek_table;
585                 FLAC__StreamMetadata_VorbisComment vorbis_comment;
586         } data;
587         /**< Polymorphic block data; use the \a type value to determine which
588          * to use. */
589 } FLAC__StreamMetadata;
590
591 extern const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
592 extern const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
593 extern const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
594
595 /** The total stream length of a metadata block header in bytes. */
596 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
597
598 /*****************************************************************************/
599
600
601 /*****************************************************************************
602  *
603  * Utility functions
604  *
605  *****************************************************************************/
606
607 /** Tests that a sample rate is valid for FLAC.  Since the rules for valid
608  *  sample rates are slightly complex, they are encapsulated in this function.
609  *
610  * \param sample_rate  The sample rate to test for compliance.
611  * \retval FLAC__bool
612  *    \c true if the given sample rate conforms to the specification, else
613  *    \c false.
614  */
615 FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
616
617 /** Check a seek table to see if it conforms to the FLAC specification.
618  *  See the format specification for limits on the contents of the
619  *  seek table.
620  *
621  * \param seek_table  A pointer to a seek table to be checked.
622  * \assert
623  *    \code seek_table != NULL \endcode
624  * \retval FLAC__bool
625  *    \c false if seek table is illegal, else \c true.
626  */
627 FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
628
629 /** Sort a seek table's seek points according to the format specification.
630  *  This includes a "unique-ification" step to remove duplicates, i.e.
631  *  seek points with identical \a sample_number values.  Duplicate seek
632  *  points are converted into placeholder points and sorted to the end of
633  *  the table.
634  *
635  * \param seek_table  A pointer to a seek table to be sorted.
636  * \assert
637  *    \code seek_table != NULL \endcode
638  * \retval unsigned
639  *    The number of duplicate seek points converted into placeholders.
640  */
641 unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
642
643 /* \} */
644
645 #ifdef __cplusplus
646 }
647 #endif
648
649 #endif