Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
17KB

  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * - Neither the name of the Xiph.org Foundation nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef FLAC__ALL_H
  32. #define FLAC__ALL_H
  33. #include "export.h"
  34. #include "assert.h"
  35. #include "callback.h"
  36. #include "format.h"
  37. #include "metadata.h"
  38. #include "ordinals.h"
  39. #include "stream_decoder.h"
  40. #include "stream_encoder.h"
  41. #ifdef _MSC_VER
  42. /* OPT: an MSVC built-in would be better */
  43. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  44. {
  45. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  46. return (x>>16) | (x<<16);
  47. }
  48. #endif
  49. #if defined(_MSC_VER) && defined(_X86_)
  50. /* OPT: an MSVC built-in would be better */
  51. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  52. {
  53. __asm {
  54. mov edx, start
  55. mov ecx, len
  56. test ecx, ecx
  57. loop1:
  58. jz done1
  59. mov eax, [edx]
  60. bswap eax
  61. mov [edx], eax
  62. add edx, 4
  63. dec ecx
  64. jmp short loop1
  65. done1:
  66. }
  67. }
  68. #endif
  69. /** \mainpage
  70. *
  71. * \section intro Introduction
  72. *
  73. * This is the documentation for the FLAC C and C++ APIs. It is
  74. * highly interconnected; this introduction should give you a top
  75. * level idea of the structure and how to find the information you
  76. * need. As a prerequisite you should have at least a basic
  77. * knowledge of the FLAC format, documented
  78. * <A HREF="../format.html">here</A>.
  79. *
  80. * \section c_api FLAC C API
  81. *
  82. * The FLAC C API is the interface to libFLAC, a set of structures
  83. * describing the components of FLAC streams, and functions for
  84. * encoding and decoding streams, as well as manipulating FLAC
  85. * metadata in files. The public include files will be installed
  86. * in your include area (for example /usr/include/FLAC/...).
  87. *
  88. * By writing a little code and linking against libFLAC, it is
  89. * relatively easy to add FLAC support to another program. The
  90. * library is licensed under <A HREF="../license.html">Xiph's BSD license</A>.
  91. * Complete source code of libFLAC as well as the command-line
  92. * encoder and plugins is available and is a useful source of
  93. * examples.
  94. *
  95. * Aside from encoders and decoders, libFLAC provides a powerful
  96. * metadata interface for manipulating metadata in FLAC files. It
  97. * allows the user to add, delete, and modify FLAC metadata blocks
  98. * and it can automatically take advantage of PADDING blocks to avoid
  99. * rewriting the entire FLAC file when changing the size of the
  100. * metadata.
  101. *
  102. * libFLAC usually only requires the standard C library and C math
  103. * library. In particular, threading is not used so there is no
  104. * dependency on a thread library. However, libFLAC does not use
  105. * global variables and should be thread-safe.
  106. *
  107. * libFLAC also supports encoding to and decoding from Ogg FLAC.
  108. * However the metadata editing interfaces currently have limited
  109. * read-only support for Ogg FLAC files.
  110. *
  111. * \section cpp_api FLAC C++ API
  112. *
  113. * The FLAC C++ API is a set of classes that encapsulate the
  114. * structures and functions in libFLAC. They provide slightly more
  115. * functionality with respect to metadata but are otherwise
  116. * equivalent. For the most part, they share the same usage as
  117. * their counterparts in libFLAC, and the FLAC C API documentation
  118. * can be used as a supplement. The public include files
  119. * for the C++ API will be installed in your include area (for
  120. * example /usr/include/FLAC++/...).
  121. *
  122. * libFLAC++ is also licensed under
  123. * <A HREF="../license.html">Xiph's BSD license</A>.
  124. *
  125. * \section getting_started Getting Started
  126. *
  127. * A good starting point for learning the API is to browse through
  128. * the <A HREF="modules.html">modules</A>. Modules are logical
  129. * groupings of related functions or classes, which correspond roughly
  130. * to header files or sections of header files. Each module includes a
  131. * detailed description of the general usage of its functions or
  132. * classes.
  133. *
  134. * From there you can go on to look at the documentation of
  135. * individual functions. You can see different views of the individual
  136. * functions through the links in top bar across this page.
  137. *
  138. * If you prefer a more hands-on approach, you can jump right to some
  139. * <A HREF="../documentation_example_code.html">example code</A>.
  140. *
  141. * \section porting_guide Porting Guide
  142. *
  143. * Starting with FLAC 1.1.3 a \link porting Porting Guide \endlink
  144. * has been introduced which gives detailed instructions on how to
  145. * port your code to newer versions of FLAC.
  146. *
  147. * \section embedded_developers Embedded Developers
  148. *
  149. * libFLAC has grown larger over time as more functionality has been
  150. * included, but much of it may be unnecessary for a particular embedded
  151. * implementation. Unused parts may be pruned by some simple editing of
  152. * src/libFLAC/Makefile.am. In general, the decoders, encoders, and
  153. * metadata interface are all independent from each other.
  154. *
  155. * It is easiest to just describe the dependencies:
  156. *
  157. * - All modules depend on the \link flac_format Format \endlink module.
  158. * - The decoders and encoders depend on the bitbuffer.
  159. * - The decoder is independent of the encoder. The encoder uses the
  160. * decoder because of the verify feature, but this can be removed if
  161. * not needed.
  162. * - Parts of the metadata interface require the stream decoder (but not
  163. * the encoder).
  164. * - Ogg support is selectable through the compile time macro
  165. * \c FLAC__HAS_OGG.
  166. *
  167. * For example, if your application only requires the stream decoder, no
  168. * encoder, and no metadata interface, you can remove the stream encoder
  169. * and the metadata interface, which will greatly reduce the size of the
  170. * library.
  171. *
  172. * Also, there are several places in the libFLAC code with comments marked
  173. * with "OPT:" where a #define can be changed to enable code that might be
  174. * faster on a specific platform. Experimenting with these can yield faster
  175. * binaries.
  176. */
  177. /** \defgroup porting Porting Guide for New Versions
  178. *
  179. * This module describes differences in the library interfaces from
  180. * version to version. It assists in the porting of code that uses
  181. * the libraries to newer versions of FLAC.
  182. *
  183. * One simple facility for making porting easier that has been added
  184. * in FLAC 1.1.3 is a set of \c #defines in \c export.h of each
  185. * library's includes (e.g. \c include/FLAC/export.h). The
  186. * \c #defines mirror the libraries'
  187. * <A HREF="http://www.gnu.org/software/libtool/manual.html#Libtool-versioning">libtool version numbers</A>,
  188. * e.g. in libFLAC there are \c FLAC_API_VERSION_CURRENT,
  189. * \c FLAC_API_VERSION_REVISION, and \c FLAC_API_VERSION_AGE.
  190. * These can be used to support multiple versions of an API during the
  191. * transition phase, e.g.
  192. *
  193. * \code
  194. * #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
  195. * legacy code
  196. * #else
  197. * new code
  198. * #endif
  199. * \endcode
  200. *
  201. * The the source will work for multiple versions and the legacy code can
  202. * easily be removed when the transition is complete.
  203. *
  204. * Another available symbol is FLAC_API_SUPPORTS_OGG_FLAC (defined in
  205. * include/FLAC/export.h), which can be used to determine whether or not
  206. * the library has been compiled with support for Ogg FLAC. This is
  207. * simpler than trying to call an Ogg init function and catching the
  208. * error.
  209. */
  210. /** \defgroup porting_1_1_2_to_1_1_3 Porting from FLAC 1.1.2 to 1.1.3
  211. * \ingroup porting
  212. *
  213. * \brief
  214. * This module describes porting from FLAC 1.1.2 to FLAC 1.1.3.
  215. *
  216. * The main change between the APIs in 1.1.2 and 1.1.3 is that they have
  217. * been simplified. First, libOggFLAC has been merged into libFLAC and
  218. * libOggFLAC++ has been merged into libFLAC++. Second, both the three
  219. * decoding layers and three encoding layers have been merged into a
  220. * single stream decoder and stream encoder. That is, the functionality
  221. * of FLAC__SeekableStreamDecoder and FLAC__FileDecoder has been merged
  222. * into FLAC__StreamDecoder, and FLAC__SeekableStreamEncoder and
  223. * FLAC__FileEncoder into FLAC__StreamEncoder. Only the
  224. * FLAC__StreamDecoder and FLAC__StreamEncoder remain. What this means
  225. * is there is now a single API that can be used to encode or decode
  226. * streams to/from native FLAC or Ogg FLAC and the single API can work
  227. * on both seekable and non-seekable streams.
  228. *
  229. * Instead of creating an encoder or decoder of a certain layer, now the
  230. * client will always create a FLAC__StreamEncoder or
  231. * FLAC__StreamDecoder. The old layers are now differentiated by the
  232. * initialization function. For example, for the decoder,
  233. * FLAC__stream_decoder_init() has been replaced by
  234. * FLAC__stream_decoder_init_stream(). This init function takes
  235. * callbacks for the I/O, and the seeking callbacks are optional. This
  236. * allows the client to use the same object for seekable and
  237. * non-seekable streams. For decoding a FLAC file directly, the client
  238. * can use FLAC__stream_decoder_init_file() and pass just a filename
  239. * and fewer callbacks; most of the other callbacks are supplied
  240. * internally. For situations where fopen()ing by filename is not
  241. * possible (e.g. Unicode filenames on Windows) the client can instead
  242. * open the file itself and supply the FILE* to
  243. * FLAC__stream_decoder_init_FILE(). The init functions now returns a
  244. * FLAC__StreamDecoderInitStatus instead of FLAC__StreamDecoderState.
  245. * Since the callbacks and client data are now passed to the init
  246. * function, the FLAC__stream_decoder_set_*_callback() functions and
  247. * FLAC__stream_decoder_set_client_data() are no longer needed. The
  248. * rest of the calls to the decoder are the same as before.
  249. *
  250. * There are counterpart init functions for Ogg FLAC, e.g.
  251. * FLAC__stream_decoder_init_ogg_stream(). All the rest of the calls
  252. * and callbacks are the same as for native FLAC.
  253. *
  254. * As an example, in FLAC 1.1.2 a seekable stream decoder would have
  255. * been set up like so:
  256. *
  257. * \code
  258. * FLAC__SeekableStreamDecoder *decoder = FLAC__seekable_stream_decoder_new();
  259. * if(decoder == NULL) do_something;
  260. * FLAC__seekable_stream_decoder_set_md5_checking(decoder, true);
  261. * [... other settings ...]
  262. * FLAC__seekable_stream_decoder_set_read_callback(decoder, my_read_callback);
  263. * FLAC__seekable_stream_decoder_set_seek_callback(decoder, my_seek_callback);
  264. * FLAC__seekable_stream_decoder_set_tell_callback(decoder, my_tell_callback);
  265. * FLAC__seekable_stream_decoder_set_length_callback(decoder, my_length_callback);
  266. * FLAC__seekable_stream_decoder_set_eof_callback(decoder, my_eof_callback);
  267. * FLAC__seekable_stream_decoder_set_write_callback(decoder, my_write_callback);
  268. * FLAC__seekable_stream_decoder_set_metadata_callback(decoder, my_metadata_callback);
  269. * FLAC__seekable_stream_decoder_set_error_callback(decoder, my_error_callback);
  270. * FLAC__seekable_stream_decoder_set_client_data(decoder, my_client_data);
  271. * if(FLAC__seekable_stream_decoder_init(decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK) do_something;
  272. * \endcode
  273. *
  274. * In FLAC 1.1.3 it is like this:
  275. *
  276. * \code
  277. * FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new();
  278. * if(decoder == NULL) do_something;
  279. * FLAC__stream_decoder_set_md5_checking(decoder, true);
  280. * [... other settings ...]
  281. * if(FLAC__stream_decoder_init_stream(
  282. * decoder,
  283. * my_read_callback,
  284. * my_seek_callback, // or NULL
  285. * my_tell_callback, // or NULL
  286. * my_length_callback, // or NULL
  287. * my_eof_callback, // or NULL
  288. * my_write_callback,
  289. * my_metadata_callback, // or NULL
  290. * my_error_callback,
  291. * my_client_data
  292. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  293. * \endcode
  294. *
  295. * or you could do;
  296. *
  297. * \code
  298. * [...]
  299. * FILE *file = fopen("somefile.flac","rb");
  300. * if(file == NULL) do_somthing;
  301. * if(FLAC__stream_decoder_init_FILE(
  302. * decoder,
  303. * file,
  304. * my_write_callback,
  305. * my_metadata_callback, // or NULL
  306. * my_error_callback,
  307. * my_client_data
  308. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  309. * \endcode
  310. *
  311. * or just:
  312. *
  313. * \code
  314. * [...]
  315. * if(FLAC__stream_decoder_init_file(
  316. * decoder,
  317. * "somefile.flac",
  318. * my_write_callback,
  319. * my_metadata_callback, // or NULL
  320. * my_error_callback,
  321. * my_client_data
  322. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  323. * \endcode
  324. *
  325. * Another small change to the decoder is in how it handles unparseable
  326. * streams. Before, when the decoder found an unparseable stream
  327. * (reserved for when the decoder encounters a stream from a future
  328. * encoder that it can't parse), it changed the state to
  329. * \c FLAC__STREAM_DECODER_UNPARSEABLE_STREAM. Now the decoder instead
  330. * drops sync and calls the error callback with a new error code
  331. * \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM. This is
  332. * more robust. If your error callback does not discriminate on the the
  333. * error state, your code does not need to be changed.
  334. *
  335. * The encoder now has a new setting:
  336. * FLAC__stream_encoder_set_apodization(). This is for setting the
  337. * method used to window the data before LPC analysis. You only need to
  338. * add a call to this function if the default is not suitable. There
  339. * are also two new convenience functions that may be useful:
  340. * FLAC__metadata_object_cuesheet_calculate_cddb_id() and
  341. * FLAC__metadata_get_cuesheet().
  342. *
  343. * The \a bytes parameter to FLAC__StreamDecoderReadCallback,
  344. * FLAC__StreamEncoderReadCallback, and FLAC__StreamEncoderWriteCallback
  345. * is now \c size_t instead of \c unsigned.
  346. */
  347. /** \defgroup porting_1_1_3_to_1_1_4 Porting from FLAC 1.1.3 to 1.1.4
  348. * \ingroup porting
  349. *
  350. * \brief
  351. * This module describes porting from FLAC 1.1.3 to FLAC 1.1.4.
  352. *
  353. * There were no changes to any of the interfaces from 1.1.3 to 1.1.4.
  354. * There was a slight change in the implementation of
  355. * FLAC__stream_encoder_set_metadata(); the function now makes a copy
  356. * of the \a metadata array of pointers so the client no longer needs
  357. * to maintain it after the call. The objects themselves that are
  358. * pointed to by the array are still not copied though and must be
  359. * maintained until the call to FLAC__stream_encoder_finish().
  360. */
  361. /** \defgroup porting_1_1_4_to_1_2_0 Porting from FLAC 1.1.4 to 1.2.0
  362. * \ingroup porting
  363. *
  364. * \brief
  365. * This module describes porting from FLAC 1.1.4 to FLAC 1.2.0.
  366. *
  367. * There were only very minor changes to the interfaces from 1.1.4 to 1.2.0.
  368. * In libFLAC, \c FLAC__format_sample_rate_is_subset() was added.
  369. * In libFLAC++, \c FLAC::Decoder::Stream::get_decode_position() was added.
  370. *
  371. * Finally, value of the constant \c FLAC__FRAME_HEADER_RESERVED_LEN
  372. * has changed to reflect the conversion of one of the reserved bits
  373. * into active use. It used to be \c 2 and now is \c 1. However the
  374. * FLAC frame header length has not changed, so to skip the proper
  375. * number of bits, use \c FLAC__FRAME_HEADER_RESERVED_LEN +
  376. * \c FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN
  377. */
  378. /** \defgroup flac FLAC C API
  379. *
  380. * The FLAC C API is the interface to libFLAC, a set of structures
  381. * describing the components of FLAC streams, and functions for
  382. * encoding and decoding streams, as well as manipulating FLAC
  383. * metadata in files.
  384. *
  385. * You should start with the format components as all other modules
  386. * are dependent on it.
  387. */
  388. #endif