2
0

format.h 40 KB

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