include/FLAC/format.h Source File

Main Page Modules Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# include/FLAC/format.h

Go to the documentation of this file.

    00001 /* libFLAC - Free Lossless Audio Codec library
    00002  * Copyright (C) 2000,2001,2002  Josh Coalson
    00003  *
    00004  * This library is free software; you can redistribute it and/or
    00005  * modify it under the terms of the GNU Library General Public
    00006  * License as published by the Free Software Foundation; either
    00007  * version 2 of the License, or (at your option) any later version.
    00008  *
    00009  * This library is distributed in the hope that it will be useful,
    00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  * Library General Public License for more details.
    00013  *
    00014  * You should have received a copy of the GNU Library General Public
    00015  * License along with this library; if not, write to the
    00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  * Boston, MA  02111-1307, USA.
    00018  */
    00019
    00020 #ifndef FLAC__FORMAT_H
    00021 #define FLAC__FORMAT_H
    00022
    00023 #include "ordinals.h"
    00024
    00025 #ifdef __cplusplus
    00026 extern "C" {
    00027 #endif
    00028
    00073 /*
    00074     Most of the values described in this file are defined by the FLAC
    00075     format specification.  There is nothing to tune here.
    00076 */
    00077
    00079 #define FLAC__MIN_BLOCK_SIZE (16u)
    00080
    00082 #define FLAC__MAX_BLOCK_SIZE (65535u)
    00083
    00085 #define FLAC__MAX_CHANNELS (8u)
    00086
    00088 #define FLAC__MIN_BITS_PER_SAMPLE (4u)
    00089
    00091 #define FLAC__MAX_BITS_PER_SAMPLE (32u)
    00092
    00101 #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
    00102
    00107 #define FLAC__MAX_SAMPLE_RATE (655350u)
    00108
    00110 #define FLAC__MAX_LPC_ORDER (32u)
    00111
    00115 #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
    00116
    00118 #define FLAC__MAX_FIXED_ORDER (4u)
    00119
    00121 #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
    00122
    00129 extern const char *FLAC__VERSION_STRING;
    00130
    00135 extern const char *FLAC__VENDOR_STRING;
    00136
    00138 extern const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
    00139
    00143 extern const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
    00144
    00146 extern const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
    00147
    00149 #define FLAC__STREAM_SYNC_LENGTH (4u)
    00150
    00151
    00152 /*****************************************************************************
    00153  *
    00154  * Subframe structures
    00155  *
    00156  *****************************************************************************/
    00157
    00158 /*****************************************************************************/
    00159
    00161 typedef enum {
    00162     FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
    00165 } FLAC__EntropyCodingMethodType;
    00166
    00172 extern const char * const FLAC__EntropyCodingMethodTypeString[];
    00173
    00174
    00177 typedef struct {
    00178
    00179     unsigned *parameters;
    00182     unsigned *raw_bits;
    00185     unsigned capacity_by_order;
    00190 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
    00191
    00194 typedef struct {
    00195
    00196     unsigned order;
    00199     const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
    00202 } FLAC__EntropyCodingMethod_PartitionedRice;
    00203
    00204 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
    00205 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
    00206 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN;
    00208 extern const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
    00213 typedef struct {
    00214     FLAC__EntropyCodingMethodType type;
    00215     union {
    00216         FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
    00217     } data;
    00218 } FLAC__EntropyCodingMethod;
    00219
    00220 extern const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN;
    00222 /*****************************************************************************/
    00223
    00225 typedef enum {
    00226     FLAC__SUBFRAME_TYPE_CONSTANT = 0,
    00227     FLAC__SUBFRAME_TYPE_VERBATIM = 1,
    00228     FLAC__SUBFRAME_TYPE_FIXED = 2,
    00229     FLAC__SUBFRAME_TYPE_LPC = 3
    00230 } FLAC__SubframeType;
    00231
    00237 extern const char * const FLAC__SubframeTypeString[];
    00238
    00239
    00242 typedef struct {
    00243     FLAC__int32 value;
    00244 } FLAC__Subframe_Constant;
    00245
    00246
    00249 typedef struct {
    00250     const FLAC__int32 *data;
    00251 } FLAC__Subframe_Verbatim;
    00252
    00253
    00256 typedef struct {
    00257     FLAC__EntropyCodingMethod entropy_coding_method;
    00260     unsigned order;
    00263     FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
    00266     const FLAC__int32 *residual;
    00268 } FLAC__Subframe_Fixed;
    00269
    00270
    00273 typedef struct {
    00274     FLAC__EntropyCodingMethod entropy_coding_method;
    00277     unsigned order;
    00280     unsigned qlp_coeff_precision;
    00283     int quantization_level;
    00286     FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
    00289     FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
    00292     const FLAC__int32 *residual;
    00294 } FLAC__Subframe_LPC;
    00295
    00296 extern const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN;
    00297 extern const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN;
    00302 typedef struct {
    00303     FLAC__SubframeType type;
    00304     union {
    00305         FLAC__Subframe_Constant constant;
    00306         FLAC__Subframe_Fixed fixed;
    00307         FLAC__Subframe_LPC lpc;
    00308         FLAC__Subframe_Verbatim verbatim;
    00309     } data;
    00310     unsigned wasted_bits;
    00311 } FLAC__Subframe;
    00312
    00313 extern const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
    00314 extern const unsigned FLAC__SUBFRAME_TYPE_LEN;
    00315 extern const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN;
    00317 extern const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
    00318 extern const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
    00319 extern const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
    00320 extern const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
    00321
    00322 /*****************************************************************************/
    00323
    00324
    00325 /*****************************************************************************
    00326  *
    00327  * Frame structures
    00328  *
    00329  *****************************************************************************/
    00330
    00332 typedef enum {
    00333     FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0,
    00334     FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1,
    00335     FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2,
    00336     FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3
    00337 } FLAC__ChannelAssignment;
    00338
    00344 extern const char * const FLAC__ChannelAssignmentString[];
    00345
    00347 typedef enum {
    00348     FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER,
    00349     FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER
    00350 } FLAC__FrameNumberType;
    00351
    00357 extern const char * const FLAC__FrameNumberTypeString[];
    00358
    00359
    00362 typedef struct {
    00363     unsigned blocksize;
    00366     unsigned sample_rate;
    00369     unsigned channels;
    00372     FLAC__ChannelAssignment channel_assignment;
    00375     unsigned bits_per_sample;
    00378     FLAC__FrameNumberType number_type;
    00381     union {
    00382         FLAC__uint32 frame_number;
    00383         FLAC__uint64 sample_number;
    00384     } number;
    00388     FLAC__uint8 crc;
    00393 } FLAC__FrameHeader;
    00394
    00395 extern const unsigned FLAC__FRAME_HEADER_SYNC;
    00396 extern const unsigned FLAC__FRAME_HEADER_SYNC_LEN;
    00397 extern const unsigned FLAC__FRAME_HEADER_RESERVED_LEN;
    00398 extern const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN;
    00399 extern const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN;
    00400 extern const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN;
    00401 extern const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN;
    00402 extern const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN;
    00403 extern const unsigned FLAC__FRAME_HEADER_CRC_LEN;
    00408 typedef struct {
    00409     FLAC__uint16 crc;
    00414 } FLAC__FrameFooter;
    00415
    00416 extern const unsigned FLAC__FRAME_FOOTER_CRC_LEN;
    00421 typedef struct {
    00422     FLAC__FrameHeader header;
    00423     FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
    00424     FLAC__FrameFooter footer;
    00425 } FLAC__Frame;
    00426
    00427 /*****************************************************************************/
    00428
    00429
    00430 /*****************************************************************************
    00431  *
    00432  * Meta-data structures
    00433  *
    00434  *****************************************************************************/
    00435
    00437 typedef enum {
    00438
    00439     FLAC__METADATA_TYPE_STREAMINFO = 0,
    00442     FLAC__METADATA_TYPE_PADDING = 1,
    00445     FLAC__METADATA_TYPE_APPLICATION = 2,
    00448     FLAC__METADATA_TYPE_SEEKTABLE = 3,
    00451     FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
    00454 } FLAC__MetadataType;
    00455
    00461 extern const char * const FLAC__MetadataTypeString[];
    00462
    00463
    00466 typedef struct {
    00467     unsigned min_blocksize, max_blocksize;
    00468     unsigned min_framesize, max_framesize;
    00469     unsigned sample_rate;
    00470     unsigned channels;
    00471     unsigned bits_per_sample;
    00472     FLAC__uint64 total_samples;
    00473     FLAC__byte md5sum[16];
    00474 } FLAC__StreamMetadata_StreamInfo;
    00475
    00476 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
    00477 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
    00478 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
    00479 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
    00480 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
    00481 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
    00482 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
    00483 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
    00484 extern const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN;
    00487 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
    00488
    00491 typedef struct {
    00492     int dummy;
    00497 } FLAC__StreamMetadata_Padding;
    00498
    00499
    00502 typedef struct {
    00503     FLAC__byte id[4];
    00504     FLAC__byte *data;
    00505 } FLAC__StreamMetadata_Application;
    00506
    00507 extern const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN;
    00511 typedef struct {
    00512     FLAC__uint64 sample_number;
    00515     FLAC__uint64 stream_offset;
    00519     unsigned frame_samples;
    00521 } FLAC__StreamMetadata_SeekPoint;
    00522
    00523 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN;
    00524 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN;
    00525 extern const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN;
    00528 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
    00529
    00534 extern const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
    00535
    00536
    00549 typedef struct {
    00550     unsigned num_points;
    00551     FLAC__StreamMetadata_SeekPoint *points;
    00552 } FLAC__StreamMetadata_SeekTable;
    00553
    00554
    00557 typedef struct {
    00558     FLAC__uint32 length;
    00559     FLAC__byte *entry;
    00560 } FLAC__StreamMetadata_VorbisComment_Entry;
    00561
    00562 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN;
    00567 typedef struct {
    00568     FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
    00569     FLAC__uint32 num_comments;
    00570     FLAC__StreamMetadata_VorbisComment_Entry *comments;
    00571 } FLAC__StreamMetadata_VorbisComment;
    00572
    00573 extern const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN;
    00578 typedef struct {
    00579     FLAC__MetadataType type;
    00583     FLAC__bool is_last;
    00586     unsigned length;
    00589     union {
    00590         FLAC__StreamMetadata_StreamInfo stream_info;
    00591         FLAC__StreamMetadata_Padding padding;
    00592         FLAC__StreamMetadata_Application application;
    00593         FLAC__StreamMetadata_SeekTable seek_table;
    00594         FLAC__StreamMetadata_VorbisComment vorbis_comment;
    00595     } data;
    00598 } FLAC__StreamMetadata;
    00599
    00600 extern const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN;
    00601 extern const unsigned FLAC__STREAM_METADATA_TYPE_LEN;
    00602 extern const unsigned FLAC__STREAM_METADATA_LENGTH_LEN;
    00605 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
    00606
    00607 /*****************************************************************************/
    00608
    00609
    00610 /*****************************************************************************
    00611  *
    00612  * Utility functions
    00613  *
    00614  *****************************************************************************/
    00615
    00624 FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
    00625
    00636 FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
    00637
    00650 unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
    00651
    00652 /* \} */
    00653
    00654 #ifdef __cplusplus
    00655 }
    00656 #endif
    00657
    00658 #endif