annotate src/flac-1.2.1/include/FLAC/format.h @ 93:5fcdb63f4cc6

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