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,2003,2004,2005  Josh Coalson
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright
00009  * notice, this list of conditions and the following disclaimer.
00010  *
00011  * - Redistributions in binary form must reproduce the above copyright
00012  * notice, this list of conditions and the following disclaimer in the
00013  * documentation and/or other materials provided with the distribution.
00014  *
00015  * - Neither the name of the Xiph.org Foundation nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef FLAC__FORMAT_H
00033 #define FLAC__FORMAT_H
00034 
00035 #include "export.h"
00036 #include "ordinals.h"
00037 
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041 
00086 /*
00087     Most of the values described in this file are defined by the FLAC
00088     format specification.  There is nothing to tune here.
00089 */
00090 
00092 #define FLAC__MAX_METADATA_TYPE_CODE (126u)
00093 
00095 #define FLAC__MIN_BLOCK_SIZE (16u)
00096 
00098 #define FLAC__MAX_BLOCK_SIZE (65535u)
00099 
00101 #define FLAC__MAX_CHANNELS (8u)
00102 
00104 #define FLAC__MIN_BITS_PER_SAMPLE (4u)
00105 
00107 #define FLAC__MAX_BITS_PER_SAMPLE (32u)
00108 
00117 #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
00118 
00123 #define FLAC__MAX_SAMPLE_RATE (655350u)
00124 
00126 #define FLAC__MAX_LPC_ORDER (32u)
00127 
00131 #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
00132 
00136 #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
00137 
00139 #define FLAC__MAX_FIXED_ORDER (4u)
00140 
00142 #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
00143 
00145 #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
00146 
00153 extern FLAC_API const char *FLAC__VERSION_STRING;
00154 
00159 extern FLAC_API const char *FLAC__VENDOR_STRING;
00160 
00162 extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
00163 
00167 extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
00168 
00170 extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
00171 
00173 #define FLAC__STREAM_SYNC_LENGTH (4u)
00174 
00175 
00176 /*****************************************************************************
00177  *
00178  * Subframe structures
00179  *
00180  *****************************************************************************/
00181 
00182 /*****************************************************************************/
00183 
00185 typedef enum {
00186     FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0
00189 } FLAC__EntropyCodingMethodType;
00190 
00196 extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
00197 
00198 
00201 typedef struct {
00202 
00203     unsigned *parameters;
00206     unsigned *raw_bits;
00209     unsigned capacity_by_order;
00214 } FLAC__EntropyCodingMethod_PartitionedRiceContents;
00215 
00218 typedef struct {
00219 
00220     unsigned order;
00223     const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
00226 } FLAC__EntropyCodingMethod_PartitionedRice;
00227 
00228 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; 
00229 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; 
00230 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; 
00232 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
00237 typedef struct {
00238     FLAC__EntropyCodingMethodType type;
00239     union {
00240         FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
00241     } data;
00242 } FLAC__EntropyCodingMethod;
00243 
00244 extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; 
00246 /*****************************************************************************/
00247 
00249 typedef enum {
00250     FLAC__SUBFRAME_TYPE_CONSTANT = 0, 
00251     FLAC__SUBFRAME_TYPE_VERBATIM = 1, 
00252     FLAC__SUBFRAME_TYPE_FIXED = 2, 
00253     FLAC__SUBFRAME_TYPE_LPC = 3 
00254 } FLAC__SubframeType;
00255 
00261 extern FLAC_API const char * const FLAC__SubframeTypeString[];
00262 
00263 
00266 typedef struct {
00267     FLAC__int32 value; 
00268 } FLAC__Subframe_Constant;
00269 
00270 
00273 typedef struct {
00274     const FLAC__int32 *data; 
00275 } FLAC__Subframe_Verbatim;
00276 
00277 
00280 typedef struct {
00281     FLAC__EntropyCodingMethod entropy_coding_method;
00284     unsigned order;
00287     FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
00290     const FLAC__int32 *residual;
00292 } FLAC__Subframe_Fixed;
00293 
00294 
00297 typedef struct {
00298     FLAC__EntropyCodingMethod entropy_coding_method;
00301     unsigned order;
00304     unsigned qlp_coeff_precision;
00307     int quantization_level;
00310     FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
00313     FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
00316     const FLAC__int32 *residual;
00318 } FLAC__Subframe_LPC;
00319 
00320 extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; 
00321 extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; 
00326 typedef struct {
00327     FLAC__SubframeType type;
00328     union {
00329         FLAC__Subframe_Constant constant;
00330         FLAC__Subframe_Fixed fixed;
00331         FLAC__Subframe_LPC lpc;
00332         FLAC__Subframe_Verbatim verbatim;
00333     } data;
00334     unsigned wasted_bits;
00335 } FLAC__Subframe;
00336 
00337 extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN; 
00338 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; 
00339 extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; 
00341 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /* = 0x00 */
00342 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /* = 0x02 */
00343 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /* = 0x10 */
00344 extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /* = 0x40 */
00345 
00346 /*****************************************************************************/
00347 
00348 
00349 /*****************************************************************************
00350  *
00351  * Frame structures
00352  *
00353  *****************************************************************************/
00354 
00356 typedef enum {
00357     FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, 
00358     FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, 
00359     FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, 
00360     FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 
00361 } FLAC__ChannelAssignment;
00362 
00368 extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
00369 
00371 typedef enum {
00372     FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, 
00373     FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER 
00374 } FLAC__FrameNumberType;
00375 
00381 extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
00382 
00383 
00386 typedef struct {
00387     unsigned blocksize;
00390     unsigned sample_rate;
00393     unsigned channels;
00396     FLAC__ChannelAssignment channel_assignment;
00399     unsigned bits_per_sample;
00402     FLAC__FrameNumberType number_type;
00405     union {
00406         FLAC__uint32 frame_number;
00407         FLAC__uint64 sample_number;
00408     } number;
00412     FLAC__uint8 crc;
00417 } FLAC__FrameHeader;
00418 
00419 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; 
00420 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; 
00421 extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; 
00422 extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; 
00423 extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; 
00424 extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; 
00425 extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; 
00426 extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; 
00427 extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; 
00432 typedef struct {
00433     FLAC__uint16 crc;
00438 } FLAC__FrameFooter;
00439 
00440 extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; 
00445 typedef struct {
00446     FLAC__FrameHeader header;
00447     FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
00448     FLAC__FrameFooter footer;
00449 } FLAC__Frame;
00450 
00451 /*****************************************************************************/
00452 
00453 
00454 /*****************************************************************************
00455  *
00456  * Meta-data structures
00457  *
00458  *****************************************************************************/
00459 
00461 typedef enum {
00462 
00463     FLAC__METADATA_TYPE_STREAMINFO = 0,
00466     FLAC__METADATA_TYPE_PADDING = 1,
00469     FLAC__METADATA_TYPE_APPLICATION = 2,
00472     FLAC__METADATA_TYPE_SEEKTABLE = 3,
00475     FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
00478     FLAC__METADATA_TYPE_CUESHEET = 5,
00481     FLAC__METADATA_TYPE_UNDEFINED = 6
00484 } FLAC__MetadataType;
00485 
00491 extern FLAC_API const char * const FLAC__MetadataTypeString[];
00492 
00493 
00496 typedef struct {
00497     unsigned min_blocksize, max_blocksize;
00498     unsigned min_framesize, max_framesize;
00499     unsigned sample_rate;
00500     unsigned channels;
00501     unsigned bits_per_sample;
00502     FLAC__uint64 total_samples;
00503     FLAC__byte md5sum[16];
00504 } FLAC__StreamMetadata_StreamInfo;
00505 
00506 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; 
00507 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; 
00508 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; 
00509 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; 
00510 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; 
00511 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; 
00512 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; 
00513 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; 
00514 extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; 
00517 #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
00518 
00521 typedef struct {
00522     int dummy;
00527 } FLAC__StreamMetadata_Padding;
00528 
00529 
00532 typedef struct {
00533     FLAC__byte id[4];
00534     FLAC__byte *data;
00535 } FLAC__StreamMetadata_Application;
00536 
00537 extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; 
00541 typedef struct {
00542     FLAC__uint64 sample_number;
00545     FLAC__uint64 stream_offset;
00549     unsigned frame_samples;
00551 } FLAC__StreamMetadata_SeekPoint;
00552 
00553 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; 
00554 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; 
00555 extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; 
00558 #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
00559 
00564 extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
00565 
00566 
00579 typedef struct {
00580     unsigned num_points;
00581     FLAC__StreamMetadata_SeekPoint *points;
00582 } FLAC__StreamMetadata_SeekTable;
00583 
00584 
00591 typedef struct {
00592     FLAC__uint32 length;
00593     FLAC__byte *entry;
00594 } FLAC__StreamMetadata_VorbisComment_Entry;
00595 
00596 extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; 
00601 typedef struct {
00602     FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
00603     FLAC__uint32 num_comments;
00604     FLAC__StreamMetadata_VorbisComment_Entry *comments;
00605 } FLAC__StreamMetadata_VorbisComment;
00606 
00607 extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; 
00614 typedef struct {
00615     FLAC__uint64 offset;
00620     FLAC__byte number;
00622 } FLAC__StreamMetadata_CueSheet_Index;
00623 
00624 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; 
00625 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; 
00626 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; 
00633 typedef struct {
00634     FLAC__uint64 offset;
00637     FLAC__byte number;
00640     char isrc[13];
00643     unsigned type:1;
00646     unsigned pre_emphasis:1;
00649     FLAC__byte num_indices;
00652     FLAC__StreamMetadata_CueSheet_Index *indices;
00655 } FLAC__StreamMetadata_CueSheet_Track;
00656 
00657 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; 
00658 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; 
00659 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; 
00660 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; 
00661 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; 
00662 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; 
00663 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; 
00670 typedef struct {
00671     char media_catalog_number[129];
00677     FLAC__uint64 lead_in;
00680     FLAC__bool is_cd;
00683     unsigned num_tracks;
00686     FLAC__StreamMetadata_CueSheet_Track *tracks;
00689 } FLAC__StreamMetadata_CueSheet;
00690 
00691 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; 
00692 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; 
00693 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; 
00694 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; 
00695 extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; 
00702 typedef struct {
00703     FLAC__byte *data;
00704 } FLAC__StreamMetadata_Unknown;
00705 
00706 
00709 typedef struct {
00710     FLAC__MetadataType type;
00715     FLAC__bool is_last;
00718     unsigned length;
00721     union {
00722         FLAC__StreamMetadata_StreamInfo stream_info;
00723         FLAC__StreamMetadata_Padding padding;
00724         FLAC__StreamMetadata_Application application;
00725         FLAC__StreamMetadata_SeekTable seek_table;
00726         FLAC__StreamMetadata_VorbisComment vorbis_comment;
00727         FLAC__StreamMetadata_CueSheet cue_sheet;
00728         FLAC__StreamMetadata_Unknown unknown;
00729     } data;
00732 } FLAC__StreamMetadata;
00733 
00734 extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; 
00735 extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; 
00736 extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; 
00739 #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
00740 
00741 /*****************************************************************************/
00742 
00743 
00744 /*****************************************************************************
00745  *
00746  * Utility functions
00747  *
00748  *****************************************************************************/
00749 
00758 FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
00759 
00772 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
00773 
00788 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
00789 
00804 FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
00805 
00806 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
00817 FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
00818 
00819 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
00832 FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
00833 
00834 /* @@@@ add to unit tests; it is already indirectly tested by the metadata_object tests */
00853 FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
00854 
00855 /* \} */
00856 
00857 #ifdef __cplusplus
00858 }
00859 #endif
00860 
00861 #endif

Generated on Fri Feb 4 18:39:10 2005 for FLAC by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002