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