The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

1790 lines
82KB

  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2000-2009 Josh Coalson
  3. * Copyright (C) 2011-2014 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__STREAM_ENCODER_H
  33. #define FLAC__STREAM_ENCODER_H
  34. #include "export.h"
  35. #include "format.h"
  36. #include "stream_decoder.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /** \file include/FLAC/stream_encoder.h
  41. *
  42. * \brief
  43. * This module contains the functions which implement the stream
  44. * encoder.
  45. *
  46. * See the detailed documentation in the
  47. * \link flac_stream_encoder stream encoder \endlink module.
  48. */
  49. /** \defgroup flac_encoder FLAC/ \*_encoder.h: encoder interfaces
  50. * \ingroup flac
  51. *
  52. * \brief
  53. * This module describes the encoder layers provided by libFLAC.
  54. *
  55. * The stream encoder can be used to encode complete streams either to the
  56. * client via callbacks, or directly to a file, depending on how it is
  57. * initialized. When encoding via callbacks, the client provides a write
  58. * callback which will be called whenever FLAC data is ready to be written.
  59. * If the client also supplies a seek callback, the encoder will also
  60. * automatically handle the writing back of metadata discovered while
  61. * encoding, like stream info, seek points offsets, etc. When encoding to
  62. * a file, the client needs only supply a filename or open \c FILE* and an
  63. * optional progress callback for periodic notification of progress; the
  64. * write and seek callbacks are supplied internally. For more info see the
  65. * \link flac_stream_encoder stream encoder \endlink module.
  66. */
  67. /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
  68. * \ingroup flac_encoder
  69. *
  70. * \brief
  71. * This module contains the functions which implement the stream
  72. * encoder.
  73. *
  74. * The stream encoder can encode to native FLAC, and optionally Ogg FLAC
  75. * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files.
  76. *
  77. * The basic usage of this encoder is as follows:
  78. * - The program creates an instance of an encoder using
  79. * FLAC__stream_encoder_new().
  80. * - The program overrides the default settings using
  81. * FLAC__stream_encoder_set_*() functions. At a minimum, the following
  82. * functions should be called:
  83. * - FLAC__stream_encoder_set_channels()
  84. * - FLAC__stream_encoder_set_bits_per_sample()
  85. * - FLAC__stream_encoder_set_sample_rate()
  86. * - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC)
  87. * - FLAC__stream_encoder_set_total_samples_estimate() (if known)
  88. * - If the application wants to control the compression level or set its own
  89. * metadata, then the following should also be called:
  90. * - FLAC__stream_encoder_set_compression_level()
  91. * - FLAC__stream_encoder_set_verify()
  92. * - FLAC__stream_encoder_set_metadata()
  93. * - The rest of the set functions should only be called if the client needs
  94. * exact control over how the audio is compressed; thorough understanding
  95. * of the FLAC format is necessary to achieve good results.
  96. * - The program initializes the instance to validate the settings and
  97. * prepare for encoding using
  98. * - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE()
  99. * or FLAC__stream_encoder_init_file() for native FLAC
  100. * - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE()
  101. * or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC
  102. * - The program calls FLAC__stream_encoder_process() or
  103. * FLAC__stream_encoder_process_interleaved() to encode data, which
  104. * subsequently calls the callbacks when there is encoder data ready
  105. * to be written.
  106. * - The program finishes the encoding with FLAC__stream_encoder_finish(),
  107. * which causes the encoder to encode any data still in its input pipe,
  108. * update the metadata with the final encoding statistics if output
  109. * seeking is possible, and finally reset the encoder to the
  110. * uninitialized state.
  111. * - The instance may be used again or deleted with
  112. * FLAC__stream_encoder_delete().
  113. *
  114. * In more detail, the stream encoder functions similarly to the
  115. * \link flac_stream_decoder stream decoder \endlink, but has fewer
  116. * callbacks and more options. Typically the client will create a new
  117. * instance by calling FLAC__stream_encoder_new(), then set the necessary
  118. * parameters with FLAC__stream_encoder_set_*(), and initialize it by
  119. * calling one of the FLAC__stream_encoder_init_*() functions.
  120. *
  121. * Unlike the decoders, the stream encoder has many options that can
  122. * affect the speed and compression ratio. When setting these parameters
  123. * you should have some basic knowledge of the format (see the
  124. * <A HREF="../documentation_format_overview.html">user-level documentation</A>
  125. * or the <A HREF="../format.html">formal description</A>). The
  126. * FLAC__stream_encoder_set_*() functions themselves do not validate the
  127. * values as many are interdependent. The FLAC__stream_encoder_init_*()
  128. * functions will do this, so make sure to pay attention to the state
  129. * returned by FLAC__stream_encoder_init_*() to make sure that it is
  130. * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set
  131. * before FLAC__stream_encoder_init_*() will take on the defaults from
  132. * the constructor.
  133. *
  134. * There are three initialization functions for native FLAC, one for
  135. * setting up the encoder to encode FLAC data to the client via
  136. * callbacks, and two for encoding directly to a file.
  137. *
  138. * For encoding via callbacks, use FLAC__stream_encoder_init_stream().
  139. * You must also supply a write callback which will be called anytime
  140. * there is raw encoded data to write. If the client can seek the output
  141. * it is best to also supply seek and tell callbacks, as this allows the
  142. * encoder to go back after encoding is finished to write back
  143. * information that was collected while encoding, like seek point offsets,
  144. * frame sizes, etc.
  145. *
  146. * For encoding directly to a file, use FLAC__stream_encoder_init_FILE()
  147. * or FLAC__stream_encoder_init_file(). Then you must only supply a
  148. * filename or open \c FILE*; the encoder will handle all the callbacks
  149. * internally. You may also supply a progress callback for periodic
  150. * notification of the encoding progress.
  151. *
  152. * There are three similarly-named init functions for encoding to Ogg
  153. * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the
  154. * library has been built with Ogg support.
  155. *
  156. * The call to FLAC__stream_encoder_init_*() currently will also immediately
  157. * call the write callback several times, once with the \c fLaC signature,
  158. * and once for each encoded metadata block. Note that for Ogg FLAC
  159. * encoding you will usually get at least twice the number of callbacks than
  160. * with native FLAC, one for the Ogg page header and one for the page body.
  161. *
  162. * After initializing the instance, the client may feed audio data to the
  163. * encoder in one of two ways:
  164. *
  165. * - Channel separate, through FLAC__stream_encoder_process() - The client
  166. * will pass an array of pointers to buffers, one for each channel, to
  167. * the encoder, each of the same length. The samples need not be
  168. * block-aligned, but each channel should have the same number of samples.
  169. * - Channel interleaved, through
  170. * FLAC__stream_encoder_process_interleaved() - The client will pass a single
  171. * pointer to data that is channel-interleaved (i.e. channel0_sample0,
  172. * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
  173. * Again, the samples need not be block-aligned but they must be
  174. * sample-aligned, i.e. the first value should be channel0_sample0 and
  175. * the last value channelN_sampleM.
  176. *
  177. * Note that for either process call, each sample in the buffers should be a
  178. * signed integer, right-justified to the resolution set by
  179. * FLAC__stream_encoder_set_bits_per_sample(). For example, if the resolution
  180. * is 16 bits per sample, the samples should all be in the range [-32768,32767].
  181. *
  182. * When the client is finished encoding data, it calls
  183. * FLAC__stream_encoder_finish(), which causes the encoder to encode any
  184. * data still in its input pipe, and call the metadata callback with the
  185. * final encoding statistics. Then the instance may be deleted with
  186. * FLAC__stream_encoder_delete() or initialized again to encode another
  187. * stream.
  188. *
  189. * For programs that write their own metadata, but that do not know the
  190. * actual metadata until after encoding, it is advantageous to instruct
  191. * the encoder to write a PADDING block of the correct size, so that
  192. * instead of rewriting the whole stream after encoding, the program can
  193. * just overwrite the PADDING block. If only the maximum size of the
  194. * metadata is known, the program can write a slightly larger padding
  195. * block, then split it after encoding.
  196. *
  197. * Make sure you understand how lengths are calculated. All FLAC metadata
  198. * blocks have a 4 byte header which contains the type and length. This
  199. * length does not include the 4 bytes of the header. See the format page
  200. * for the specification of metadata blocks and their lengths.
  201. *
  202. * \note
  203. * If you are writing the FLAC data to a file via callbacks, make sure it
  204. * is open for update (e.g. mode "w+" for stdio streams). This is because
  205. * after the first encoding pass, the encoder will try to seek back to the
  206. * beginning of the stream, to the STREAMINFO block, to write some data
  207. * there. (If using FLAC__stream_encoder_init*_file() or
  208. * FLAC__stream_encoder_init*_FILE(), the file is managed internally.)
  209. *
  210. * \note
  211. * The "set" functions may only be called when the encoder is in the
  212. * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
  213. * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
  214. * before FLAC__stream_encoder_init_*(). If this is the case they will
  215. * return \c true, otherwise \c false.
  216. *
  217. * \note
  218. * FLAC__stream_encoder_finish() resets all settings to the constructor
  219. * defaults.
  220. *
  221. * \{
  222. */
  223. /** State values for a FLAC__StreamEncoder.
  224. *
  225. * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
  226. *
  227. * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK
  228. * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and
  229. * must be deleted with FLAC__stream_encoder_delete().
  230. */
  231. typedef enum {
  232. FLAC__STREAM_ENCODER_OK = 0,
  233. /**< The encoder is in the normal OK state and samples can be processed. */
  234. FLAC__STREAM_ENCODER_UNINITIALIZED,
  235. /**< The encoder is in the uninitialized state; one of the
  236. * FLAC__stream_encoder_init_*() functions must be called before samples
  237. * can be processed.
  238. */
  239. FLAC__STREAM_ENCODER_OGG_ERROR,
  240. /**< An error occurred in the underlying Ogg layer. */
  241. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  242. /**< An error occurred in the underlying verify stream decoder;
  243. * check FLAC__stream_encoder_get_verify_decoder_state().
  244. */
  245. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  246. /**< The verify decoder detected a mismatch between the original
  247. * audio signal and the decoded audio signal.
  248. */
  249. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  250. /**< One of the callbacks returned a fatal error. */
  251. FLAC__STREAM_ENCODER_IO_ERROR,
  252. /**< An I/O error occurred while opening/reading/writing a file.
  253. * Check \c errno.
  254. */
  255. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  256. /**< An error occurred while writing the stream; usually, the
  257. * write_callback returned an error.
  258. */
  259. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  260. /**< Memory allocation failed. */
  261. } FLAC__StreamEncoderState;
  262. /** Maps a FLAC__StreamEncoderState to a C string.
  263. *
  264. * Using a FLAC__StreamEncoderState as the index to this array
  265. * will give the string equivalent. The contents should not be modified.
  266. */
  267. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  268. /** Possible return values for the FLAC__stream_encoder_init_*() functions.
  269. */
  270. typedef enum {
  271. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  272. /**< Initialization was successful. */
  273. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  274. /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */
  275. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  276. /**< The library was not compiled with support for the given container
  277. * format.
  278. */
  279. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  280. /**< A required callback was not supplied. */
  281. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  282. /**< The encoder has an invalid setting for number of channels. */
  283. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  284. /**< The encoder has an invalid setting for bits-per-sample.
  285. * FLAC supports 4-32 bps but the reference encoder currently supports
  286. * only up to 24 bps.
  287. */
  288. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  289. /**< The encoder has an invalid setting for the input sample rate. */
  290. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  291. /**< The encoder has an invalid setting for the block size. */
  292. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  293. /**< The encoder has an invalid setting for the maximum LPC order. */
  294. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  295. /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
  296. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  297. /**< The specified block size is less than the maximum LPC order. */
  298. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  299. /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */
  300. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  301. /**< The metadata input to the encoder is invalid, in one of the following ways:
  302. * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
  303. * - One of the metadata blocks contains an undefined type
  304. * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal()
  305. * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal()
  306. * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
  307. */
  308. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  309. /**< FLAC__stream_encoder_init_*() was called when the encoder was
  310. * already initialized, usually because
  311. * FLAC__stream_encoder_finish() was not called.
  312. */
  313. } FLAC__StreamEncoderInitStatus;
  314. /** Maps a FLAC__StreamEncoderInitStatus to a C string.
  315. *
  316. * Using a FLAC__StreamEncoderInitStatus as the index to this array
  317. * will give the string equivalent. The contents should not be modified.
  318. */
  319. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  320. /** Return values for the FLAC__StreamEncoder read callback.
  321. */
  322. typedef enum {
  323. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  324. /**< The read was OK and decoding can continue. */
  325. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  326. /**< The read was attempted at the end of the stream. */
  327. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  328. /**< An unrecoverable error occurred. */
  329. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  330. /**< Client does not support reading back from the output. */
  331. } FLAC__StreamEncoderReadStatus;
  332. /** Maps a FLAC__StreamEncoderReadStatus to a C string.
  333. *
  334. * Using a FLAC__StreamEncoderReadStatus as the index to this array
  335. * will give the string equivalent. The contents should not be modified.
  336. */
  337. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  338. /** Return values for the FLAC__StreamEncoder write callback.
  339. */
  340. typedef enum {
  341. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  342. /**< The write was OK and encoding can continue. */
  343. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  344. /**< An unrecoverable error occurred. The encoder will return from the process call. */
  345. } FLAC__StreamEncoderWriteStatus;
  346. /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
  347. *
  348. * Using a FLAC__StreamEncoderWriteStatus as the index to this array
  349. * will give the string equivalent. The contents should not be modified.
  350. */
  351. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  352. /** Return values for the FLAC__StreamEncoder seek callback.
  353. */
  354. typedef enum {
  355. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  356. /**< The seek was OK and encoding can continue. */
  357. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  358. /**< An unrecoverable error occurred. */
  359. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  360. /**< Client does not support seeking. */
  361. } FLAC__StreamEncoderSeekStatus;
  362. /** Maps a FLAC__StreamEncoderSeekStatus to a C string.
  363. *
  364. * Using a FLAC__StreamEncoderSeekStatus as the index to this array
  365. * will give the string equivalent. The contents should not be modified.
  366. */
  367. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  368. /** Return values for the FLAC__StreamEncoder tell callback.
  369. */
  370. typedef enum {
  371. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  372. /**< The tell was OK and encoding can continue. */
  373. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  374. /**< An unrecoverable error occurred. */
  375. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  376. /**< Client does not support seeking. */
  377. } FLAC__StreamEncoderTellStatus;
  378. /** Maps a FLAC__StreamEncoderTellStatus to a C string.
  379. *
  380. * Using a FLAC__StreamEncoderTellStatus as the index to this array
  381. * will give the string equivalent. The contents should not be modified.
  382. */
  383. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  384. /***********************************************************************
  385. *
  386. * class FLAC__StreamEncoder
  387. *
  388. ***********************************************************************/
  389. struct FLAC__StreamEncoderProtected;
  390. struct FLAC__StreamEncoderPrivate;
  391. /** The opaque structure definition for the stream encoder type.
  392. * See the \link flac_stream_encoder stream encoder module \endlink
  393. * for a detailed description.
  394. */
  395. typedef struct {
  396. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  397. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  398. } FLAC__StreamEncoder;
  399. /** Signature for the read callback.
  400. *
  401. * A function pointer matching this signature must be passed to
  402. * FLAC__stream_encoder_init_ogg_stream() if seeking is supported.
  403. * The supplied function will be called when the encoder needs to read back
  404. * encoded data. This happens during the metadata callback, when the encoder
  405. * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
  406. * while encoding. The address of the buffer to be filled is supplied, along
  407. * with the number of bytes the buffer can hold. The callback may choose to
  408. * supply less data and modify the byte count but must be careful not to
  409. * overflow the buffer. The callback then returns a status code chosen from
  410. * FLAC__StreamEncoderReadStatus.
  411. *
  412. * Here is an example of a read callback for stdio streams:
  413. * \code
  414. * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  415. * {
  416. * FILE *file = ((MyClientData*)client_data)->file;
  417. * if(*bytes > 0) {
  418. * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file);
  419. * if(ferror(file))
  420. * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  421. * else if(*bytes == 0)
  422. * return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  423. * else
  424. * return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  425. * }
  426. * else
  427. * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  428. * }
  429. * \endcode
  430. *
  431. * \note In general, FLAC__StreamEncoder functions which change the
  432. * state should not be called on the \a encoder while in the callback.
  433. *
  434. * \param encoder The encoder instance calling the callback.
  435. * \param buffer A pointer to a location for the callee to store
  436. * data to be encoded.
  437. * \param bytes A pointer to the size of the buffer. On entry
  438. * to the callback, it contains the maximum number
  439. * of bytes that may be stored in \a buffer. The
  440. * callee must set it to the actual number of bytes
  441. * stored (0 in case of error or end-of-stream) before
  442. * returning.
  443. * \param client_data The callee's client data set through
  444. * FLAC__stream_encoder_set_client_data().
  445. * \retval FLAC__StreamEncoderReadStatus
  446. * The callee's return status.
  447. */
  448. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  449. /** Signature for the write callback.
  450. *
  451. * A function pointer matching this signature must be passed to
  452. * FLAC__stream_encoder_init*_stream(). The supplied function will be called
  453. * by the encoder anytime there is raw encoded data ready to write. It may
  454. * include metadata mixed with encoded audio frames and the data is not
  455. * guaranteed to be aligned on frame or metadata block boundaries.
  456. *
  457. * The only duty of the callback is to write out the \a bytes worth of data
  458. * in \a buffer to the current position in the output stream. The arguments
  459. * \a samples and \a current_frame are purely informational. If \a samples
  460. * is greater than \c 0, then \a current_frame will hold the current frame
  461. * number that is being written; otherwise it indicates that the write
  462. * callback is being called to write metadata.
  463. *
  464. * \note
  465. * Unlike when writing to native FLAC, when writing to Ogg FLAC the
  466. * write callback will be called twice when writing each audio
  467. * frame; once for the page header, and once for the page body.
  468. * When writing the page header, the \a samples argument to the
  469. * write callback will be \c 0.
  470. *
  471. * \note In general, FLAC__StreamEncoder functions which change the
  472. * state should not be called on the \a encoder while in the callback.
  473. *
  474. * \param encoder The encoder instance calling the callback.
  475. * \param buffer An array of encoded data of length \a bytes.
  476. * \param bytes The byte length of \a buffer.
  477. * \param samples The number of samples encoded by \a buffer.
  478. * \c 0 has a special meaning; see above.
  479. * \param current_frame The number of the current frame being encoded.
  480. * \param client_data The callee's client data set through
  481. * FLAC__stream_encoder_init_*().
  482. * \retval FLAC__StreamEncoderWriteStatus
  483. * The callee's return status.
  484. */
  485. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  486. /** Signature for the seek callback.
  487. *
  488. * A function pointer matching this signature may be passed to
  489. * FLAC__stream_encoder_init*_stream(). The supplied function will be called
  490. * when the encoder needs to seek the output stream. The encoder will pass
  491. * the absolute byte offset to seek to, 0 meaning the beginning of the stream.
  492. *
  493. * Here is an example of a seek callback for stdio streams:
  494. * \code
  495. * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  496. * {
  497. * FILE *file = ((MyClientData*)client_data)->file;
  498. * if(file == stdin)
  499. * return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  500. * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  501. * return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  502. * else
  503. * return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  504. * }
  505. * \endcode
  506. *
  507. * \note In general, FLAC__StreamEncoder functions which change the
  508. * state should not be called on the \a encoder while in the callback.
  509. *
  510. * \param encoder The encoder instance calling the callback.
  511. * \param absolute_byte_offset The offset from the beginning of the stream
  512. * to seek to.
  513. * \param client_data The callee's client data set through
  514. * FLAC__stream_encoder_init_*().
  515. * \retval FLAC__StreamEncoderSeekStatus
  516. * The callee's return status.
  517. */
  518. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  519. /** Signature for the tell callback.
  520. *
  521. * A function pointer matching this signature may be passed to
  522. * FLAC__stream_encoder_init*_stream(). The supplied function will be called
  523. * when the encoder needs to know the current position of the output stream.
  524. *
  525. * \warning
  526. * The callback must return the true current byte offset of the output to
  527. * which the encoder is writing. If you are buffering the output, make
  528. * sure and take this into account. If you are writing directly to a
  529. * FILE* from your write callback, ftell() is sufficient. If you are
  530. * writing directly to a file descriptor from your write callback, you
  531. * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to
  532. * these points to rewrite metadata after encoding.
  533. *
  534. * Here is an example of a tell callback for stdio streams:
  535. * \code
  536. * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  537. * {
  538. * FILE *file = ((MyClientData*)client_data)->file;
  539. * off_t pos;
  540. * if(file == stdin)
  541. * return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  542. * else if((pos = ftello(file)) < 0)
  543. * return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  544. * else {
  545. * *absolute_byte_offset = (FLAC__uint64)pos;
  546. * return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  547. * }
  548. * }
  549. * \endcode
  550. *
  551. * \note In general, FLAC__StreamEncoder functions which change the
  552. * state should not be called on the \a encoder while in the callback.
  553. *
  554. * \param encoder The encoder instance calling the callback.
  555. * \param absolute_byte_offset The address at which to store the current
  556. * position of the output.
  557. * \param client_data The callee's client data set through
  558. * FLAC__stream_encoder_init_*().
  559. * \retval FLAC__StreamEncoderTellStatus
  560. * The callee's return status.
  561. */
  562. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  563. /** Signature for the metadata callback.
  564. *
  565. * A function pointer matching this signature may be passed to
  566. * FLAC__stream_encoder_init*_stream(). The supplied function will be called
  567. * once at the end of encoding with the populated STREAMINFO structure. This
  568. * is so the client can seek back to the beginning of the file and write the
  569. * STREAMINFO block with the correct statistics after encoding (like
  570. * minimum/maximum frame size and total samples).
  571. *
  572. * \note In general, FLAC__StreamEncoder functions which change the
  573. * state should not be called on the \a encoder while in the callback.
  574. *
  575. * \param encoder The encoder instance calling the callback.
  576. * \param metadata The final populated STREAMINFO block.
  577. * \param client_data The callee's client data set through
  578. * FLAC__stream_encoder_init_*().
  579. */
  580. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  581. /** Signature for the progress callback.
  582. *
  583. * A function pointer matching this signature may be passed to
  584. * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE().
  585. * The supplied function will be called when the encoder has finished
  586. * writing a frame. The \c total_frames_estimate argument to the
  587. * callback will be based on the value from
  588. * FLAC__stream_encoder_set_total_samples_estimate().
  589. *
  590. * \note In general, FLAC__StreamEncoder functions which change the
  591. * state should not be called on the \a encoder while in the callback.
  592. *
  593. * \param encoder The encoder instance calling the callback.
  594. * \param bytes_written Bytes written so far.
  595. * \param samples_written Samples written so far.
  596. * \param frames_written Frames written so far.
  597. * \param total_frames_estimate The estimate of the total number of
  598. * frames to be written.
  599. * \param client_data The callee's client data set through
  600. * FLAC__stream_encoder_init_*().
  601. */
  602. typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
  603. /***********************************************************************
  604. *
  605. * Class constructor/destructor
  606. *
  607. ***********************************************************************/
  608. /** Create a new stream encoder instance. The instance is created with
  609. * default settings; see the individual FLAC__stream_encoder_set_*()
  610. * functions for each setting's default.
  611. *
  612. * \retval FLAC__StreamEncoder*
  613. * \c NULL if there was an error allocating memory, else the new instance.
  614. */
  615. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  616. /** Free an encoder instance. Deletes the object pointed to by \a encoder.
  617. *
  618. * \param encoder A pointer to an existing encoder.
  619. * \assert
  620. * \code encoder != NULL \endcode
  621. */
  622. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  623. /***********************************************************************
  624. *
  625. * Public class method prototypes
  626. *
  627. ***********************************************************************/
  628. /** Set the serial number for the FLAC stream to use in the Ogg container.
  629. *
  630. * \note
  631. * This does not need to be set for native FLAC encoding.
  632. *
  633. * \note
  634. * It is recommended to set a serial number explicitly as the default of '0'
  635. * may collide with other streams.
  636. *
  637. * \default \c 0
  638. * \param encoder An encoder instance to set.
  639. * \param serial_number See above.
  640. * \assert
  641. * \code encoder != NULL \endcode
  642. * \retval FLAC__bool
  643. * \c false if the encoder is already initialized, else \c true.
  644. */
  645. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  646. /** Set the "verify" flag. If \c true, the encoder will verify it's own
  647. * encoded output by feeding it through an internal decoder and comparing
  648. * the original signal against the decoded signal. If a mismatch occurs,
  649. * the process call will return \c false. Note that this will slow the
  650. * encoding process by the extra time required for decoding and comparison.
  651. *
  652. * \default \c false
  653. * \param encoder An encoder instance to set.
  654. * \param value Flag value (see above).
  655. * \assert
  656. * \code encoder != NULL \endcode
  657. * \retval FLAC__bool
  658. * \c false if the encoder is already initialized, else \c true.
  659. */
  660. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  661. /** Set the <A HREF="../format.html#subset">Subset</A> flag. If \c true,
  662. * the encoder will comply with the Subset and will check the
  663. * settings during FLAC__stream_encoder_init_*() to see if all settings
  664. * comply. If \c false, the settings may take advantage of the full
  665. * range that the format allows.
  666. *
  667. * Make sure you know what it entails before setting this to \c false.
  668. *
  669. * \default \c true
  670. * \param encoder An encoder instance to set.
  671. * \param value Flag value (see above).
  672. * \assert
  673. * \code encoder != NULL \endcode
  674. * \retval FLAC__bool
  675. * \c false if the encoder is already initialized, else \c true.
  676. */
  677. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  678. /** Set the number of channels to be encoded.
  679. *
  680. * \default \c 2
  681. * \param encoder An encoder instance to set.
  682. * \param value See above.
  683. * \assert
  684. * \code encoder != NULL \endcode
  685. * \retval FLAC__bool
  686. * \c false if the encoder is already initialized, else \c true.
  687. */
  688. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  689. /** Set the sample resolution of the input to be encoded.
  690. *
  691. * \warning
  692. * Do not feed the encoder data that is wider than the value you
  693. * set here or you will generate an invalid stream.
  694. *
  695. * \default \c 16
  696. * \param encoder An encoder instance to set.
  697. * \param value See above.
  698. * \assert
  699. * \code encoder != NULL \endcode
  700. * \retval FLAC__bool
  701. * \c false if the encoder is already initialized, else \c true.
  702. */
  703. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  704. /** Set the sample rate (in Hz) of the input to be encoded.
  705. *
  706. * \default \c 44100
  707. * \param encoder An encoder instance to set.
  708. * \param value See above.
  709. * \assert
  710. * \code encoder != NULL \endcode
  711. * \retval FLAC__bool
  712. * \c false if the encoder is already initialized, else \c true.
  713. */
  714. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  715. /** Set the compression level
  716. *
  717. * The compression level is roughly proportional to the amount of effort
  718. * the encoder expends to compress the file. A higher level usually
  719. * means more computation but higher compression. The default level is
  720. * suitable for most applications.
  721. *
  722. * Currently the levels range from \c 0 (fastest, least compression) to
  723. * \c 8 (slowest, most compression). A value larger than \c 8 will be
  724. * treated as \c 8.
  725. *
  726. * This function automatically calls the following other \c _set_
  727. * functions with appropriate values, so the client does not need to
  728. * unless it specifically wants to override them:
  729. * - FLAC__stream_encoder_set_do_mid_side_stereo()
  730. * - FLAC__stream_encoder_set_loose_mid_side_stereo()
  731. * - FLAC__stream_encoder_set_apodization()
  732. * - FLAC__stream_encoder_set_max_lpc_order()
  733. * - FLAC__stream_encoder_set_qlp_coeff_precision()
  734. * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
  735. * - FLAC__stream_encoder_set_do_escape_coding()
  736. * - FLAC__stream_encoder_set_do_exhaustive_model_search()
  737. * - FLAC__stream_encoder_set_min_residual_partition_order()
  738. * - FLAC__stream_encoder_set_max_residual_partition_order()
  739. * - FLAC__stream_encoder_set_rice_parameter_search_dist()
  740. *
  741. * The actual values set for each level are:
  742. * <table>
  743. * <tr>
  744. * <td><b>level</b></td>
  745. * <td>do mid-side stereo</td>
  746. * <td>loose mid-side stereo</td>
  747. * <td>apodization</td>
  748. * <td>max lpc order</td>
  749. * <td>qlp coeff precision</td>
  750. * <td>qlp coeff prec search</td>
  751. * <td>escape coding</td>
  752. * <td>exhaustive model search</td>
  753. * <td>min residual partition order</td>
  754. * <td>max residual partition order</td>
  755. * <td>rice parameter search dist</td>
  756. * </tr>
  757. * <tr> <td><b>0</b></td> <td>false</td> <td>false</td> <td>tukey(0.5)<td> <td>0</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>3</td> <td>0</td> </tr>
  758. * <tr> <td><b>1</b></td> <td>true</td> <td>true</td> <td>tukey(0.5)<td> <td>0</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>3</td> <td>0</td> </tr>
  759. * <tr> <td><b>2</b></td> <td>true</td> <td>false</td> <td>tukey(0.5)<td> <td>0</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>3</td> <td>0</td> </tr>
  760. * <tr> <td><b>3</b></td> <td>false</td> <td>false</td> <td>tukey(0.5)<td> <td>6</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>4</td> <td>0</td> </tr>
  761. * <tr> <td><b>4</b></td> <td>true</td> <td>true</td> <td>tukey(0.5)<td> <td>8</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>4</td> <td>0</td> </tr>
  762. * <tr> <td><b>5</b></td> <td>true</td> <td>false</td> <td>tukey(0.5)<td> <td>8</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>5</td> <td>0</td> </tr>
  763. * <tr> <td><b>6</b></td> <td>true</td> <td>false</td> <td>tukey(0.5);partial_tukey(2)<td> <td>8</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>6</td> <td>0</td> </tr>
  764. * <tr> <td><b>7</b></td> <td>true</td> <td>false</td> <td>tukey(0.5);partial_tukey(2)<td> <td>12</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>6</td> <td>0</td> </tr>
  765. * <tr> <td><b>8</b></td> <td>true</td> <td>false</td> <td>tukey(0.5);partial_tukey(2);punchout_tukey(3)</td> <td>12</td> <td>0</td> <td>false</td> <td>false</td> <td>false</td> <td>0</td> <td>6</td> <td>0</td> </tr>
  766. * </table>
  767. *
  768. * \default \c 5
  769. * \param encoder An encoder instance to set.
  770. * \param value See above.
  771. * \assert
  772. * \code encoder != NULL \endcode
  773. * \retval FLAC__bool
  774. * \c false if the encoder is already initialized, else \c true.
  775. */
  776. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  777. /** Set the blocksize to use while encoding.
  778. *
  779. * The number of samples to use per frame. Use \c 0 to let the encoder
  780. * estimate a blocksize; this is usually best.
  781. *
  782. * \default \c 0
  783. * \param encoder An encoder instance to set.
  784. * \param value See above.
  785. * \assert
  786. * \code encoder != NULL \endcode
  787. * \retval FLAC__bool
  788. * \c false if the encoder is already initialized, else \c true.
  789. */
  790. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  791. /** Set to \c true to enable mid-side encoding on stereo input. The
  792. * number of channels must be 2 for this to have any effect. Set to
  793. * \c false to use only independent channel coding.
  794. *
  795. * \default \c false
  796. * \param encoder An encoder instance to set.
  797. * \param value Flag value (see above).
  798. * \assert
  799. * \code encoder != NULL \endcode
  800. * \retval FLAC__bool
  801. * \c false if the encoder is already initialized, else \c true.
  802. */
  803. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  804. /** Set to \c true to enable adaptive switching between mid-side and
  805. * left-right encoding on stereo input. Set to \c false to use
  806. * exhaustive searching. Setting this to \c true requires
  807. * FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to
  808. * \c true in order to have any effect.
  809. *
  810. * \default \c false
  811. * \param encoder An encoder instance to set.
  812. * \param value Flag value (see above).
  813. * \assert
  814. * \code encoder != NULL \endcode
  815. * \retval FLAC__bool
  816. * \c false if the encoder is already initialized, else \c true.
  817. */
  818. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  819. /** Sets the apodization function(s) the encoder will use when windowing
  820. * audio data for LPC analysis.
  821. *
  822. * The \a specification is a plain ASCII string which specifies exactly
  823. * which functions to use. There may be more than one (up to 32),
  824. * separated by \c ';' characters. Some functions take one or more
  825. * comma-separated arguments in parentheses.
  826. *
  827. * The available functions are \c bartlett, \c bartlett_hann,
  828. * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop,
  829. * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall,
  830. * \c rectangle, \c triangle, \c tukey(P), \c partial_tukey(n[/ov[/P]]),
  831. * \c punchout_tukey(n[/ov[/P]]), \c welch.
  832. *
  833. * For \c gauss(STDDEV), STDDEV specifies the standard deviation
  834. * (0<STDDEV<=0.5).
  835. *
  836. * For \c tukey(P), P specifies the fraction of the window that is
  837. * tapered (0<=P<=1). P=0 corresponds to \c rectangle and P=1
  838. * corresponds to \c hann.
  839. *
  840. * Specifying \c partial_tukey or \c punchout_tukey works a little
  841. * different. These do not specify a single apodization function, but
  842. * a series of them with some overlap. partial_tukey specifies a series
  843. * of small windows (all treated separately) while punchout_tukey
  844. * specifies a series of windows that have a hole in them. In this way,
  845. * the predictor is constructed with only a part of the block, which
  846. * helps in case a block consists of dissimilar parts.
  847. *
  848. * The three parameters that can be specified for the functions are
  849. * n, ov and P. n is the number of functions to add, ov is the overlap
  850. * of the windows in case of partial_tukey and the overlap in the gaps
  851. * in case of punchout_tukey. P is the fraction of the window that is
  852. * tapered, like with a regular tukey window. The function can be
  853. * specified with only a number, a number and an overlap, or a number
  854. * an overlap and a P, for example, partial_tukey(3), partial_tukey(3/0.3)
  855. * and partial_tukey(3/0.3/0.5) are all valid. ov should be smaller than 1
  856. * and can be negative.
  857. *
  858. * Example specifications are \c "blackman" or
  859. * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)"
  860. *
  861. * Any function that is specified erroneously is silently dropped. Up
  862. * to 32 functions are kept, the rest are dropped. If the specification
  863. * is empty the encoder defaults to \c "tukey(0.5)".
  864. *
  865. * When more than one function is specified, then for every subframe the
  866. * encoder will try each of them separately and choose the window that
  867. * results in the smallest compressed subframe.
  868. *
  869. * Note that each function specified causes the encoder to occupy a
  870. * floating point array in which to store the window. Also note that the
  871. * values of P, STDDEV and ov are locale-specific, so if the comma
  872. * separator specified by the locale is a comma, a comma should be used.
  873. *
  874. * \default \c "tukey(0.5)"
  875. * \param encoder An encoder instance to set.
  876. * \param specification See above.
  877. * \assert
  878. * \code encoder != NULL \endcode
  879. * \code specification != NULL \endcode
  880. * \retval FLAC__bool
  881. * \c false if the encoder is already initialized, else \c true.
  882. */
  883. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  884. /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
  885. *
  886. * \default \c 0
  887. * \param encoder An encoder instance to set.
  888. * \param value See above.
  889. * \assert
  890. * \code encoder != NULL \endcode
  891. * \retval FLAC__bool
  892. * \c false if the encoder is already initialized, else \c true.
  893. */
  894. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  895. /** Set the precision, in bits, of the quantized linear predictor
  896. * coefficients, or \c 0 to let the encoder select it based on the
  897. * blocksize.
  898. *
  899. * \note
  900. * In the current implementation, qlp_coeff_precision + bits_per_sample must
  901. * be less than 32.
  902. *
  903. * \default \c 0
  904. * \param encoder An encoder instance to set.
  905. * \param value See above.
  906. * \assert
  907. * \code encoder != NULL \endcode
  908. * \retval FLAC__bool
  909. * \c false if the encoder is already initialized, else \c true.
  910. */
  911. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  912. /** Set to \c false to use only the specified quantized linear predictor
  913. * coefficient precision, or \c true to search neighboring precision
  914. * values and use the best one.
  915. *
  916. * \default \c false
  917. * \param encoder An encoder instance to set.
  918. * \param value See above.
  919. * \assert
  920. * \code encoder != NULL \endcode
  921. * \retval FLAC__bool
  922. * \c false if the encoder is already initialized, else \c true.
  923. */
  924. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  925. /** Deprecated. Setting this value has no effect.
  926. *
  927. * \default \c false
  928. * \param encoder An encoder instance to set.
  929. * \param value See above.
  930. * \assert
  931. * \code encoder != NULL \endcode
  932. * \retval FLAC__bool
  933. * \c false if the encoder is already initialized, else \c true.
  934. */
  935. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  936. /** Set to \c false to let the encoder estimate the best model order
  937. * based on the residual signal energy, or \c true to force the
  938. * encoder to evaluate all order models and select the best.
  939. *
  940. * \default \c false
  941. * \param encoder An encoder instance to set.
  942. * \param value See above.
  943. * \assert
  944. * \code encoder != NULL \endcode
  945. * \retval FLAC__bool
  946. * \c false if the encoder is already initialized, else \c true.
  947. */
  948. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  949. /** Set the minimum partition order to search when coding the residual.
  950. * This is used in tandem with
  951. * FLAC__stream_encoder_set_max_residual_partition_order().
  952. *
  953. * The partition order determines the context size in the residual.
  954. * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
  955. *
  956. * Set both min and max values to \c 0 to force a single context,
  957. * whose Rice parameter is based on the residual signal variance.
  958. * Otherwise, set a min and max order, and the encoder will search
  959. * all orders, using the mean of each context for its Rice parameter,
  960. * and use the best.
  961. *
  962. * \default \c 0
  963. * \param encoder An encoder instance to set.
  964. * \param value See above.
  965. * \assert
  966. * \code encoder != NULL \endcode
  967. * \retval FLAC__bool
  968. * \c false if the encoder is already initialized, else \c true.
  969. */
  970. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  971. /** Set the maximum partition order to search when coding the residual.
  972. * This is used in tandem with
  973. * FLAC__stream_encoder_set_min_residual_partition_order().
  974. *
  975. * The partition order determines the context size in the residual.
  976. * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
  977. *
  978. * Set both min and max values to \c 0 to force a single context,
  979. * whose Rice parameter is based on the residual signal variance.
  980. * Otherwise, set a min and max order, and the encoder will search
  981. * all orders, using the mean of each context for its Rice parameter,
  982. * and use the best.
  983. *
  984. * \default \c 0
  985. * \param encoder An encoder instance to set.
  986. * \param value See above.
  987. * \assert
  988. * \code encoder != NULL \endcode
  989. * \retval FLAC__bool
  990. * \c false if the encoder is already initialized, else \c true.
  991. */
  992. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  993. /** Deprecated. Setting this value has no effect.
  994. *
  995. * \default \c 0
  996. * \param encoder An encoder instance to set.
  997. * \param value See above.
  998. * \assert
  999. * \code encoder != NULL \endcode
  1000. * \retval FLAC__bool
  1001. * \c false if the encoder is already initialized, else \c true.
  1002. */
  1003. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  1004. /** Set an estimate of the total samples that will be encoded.
  1005. * This is merely an estimate and may be set to \c 0 if unknown.
  1006. * This value will be written to the STREAMINFO block before encoding,
  1007. * and can remove the need for the caller to rewrite the value later
  1008. * if the value is known before encoding.
  1009. *
  1010. * \default \c 0
  1011. * \param encoder An encoder instance to set.
  1012. * \param value See above.
  1013. * \assert
  1014. * \code encoder != NULL \endcode
  1015. * \retval FLAC__bool
  1016. * \c false if the encoder is already initialized, else \c true.
  1017. */
  1018. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  1019. /** Set the metadata blocks to be emitted to the stream before encoding.
  1020. * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
  1021. * array of pointers to metadata blocks. The array is non-const since
  1022. * the encoder may need to change the \a is_last flag inside them, and
  1023. * in some cases update seek point offsets. Otherwise, the encoder will
  1024. * not modify or free the blocks. It is up to the caller to free the
  1025. * metadata blocks after encoding finishes.
  1026. *
  1027. * \note
  1028. * The encoder stores only copies of the pointers in the \a metadata array;
  1029. * the metadata blocks themselves must survive at least until after
  1030. * FLAC__stream_encoder_finish() returns. Do not free the blocks until then.
  1031. *
  1032. * \note
  1033. * The STREAMINFO block is always written and no STREAMINFO block may
  1034. * occur in the supplied array.
  1035. *
  1036. * \note
  1037. * By default the encoder does not create a SEEKTABLE. If one is supplied
  1038. * in the \a metadata array, but the client has specified that it does not
  1039. * support seeking, then the SEEKTABLE will be written verbatim. However
  1040. * by itself this is not very useful as the client will not know the stream
  1041. * offsets for the seekpoints ahead of time. In order to get a proper
  1042. * seektable the client must support seeking. See next note.
  1043. *
  1044. * \note
  1045. * SEEKTABLE blocks are handled specially. Since you will not know
  1046. * the values for the seek point stream offsets, you should pass in
  1047. * a SEEKTABLE 'template', that is, a SEEKTABLE object with the
  1048. * required sample numbers (or placeholder points), with \c 0 for the
  1049. * \a frame_samples and \a stream_offset fields for each point. If the
  1050. * client has specified that it supports seeking by providing a seek
  1051. * callback to FLAC__stream_encoder_init_stream() or both seek AND read
  1052. * callback to FLAC__stream_encoder_init_ogg_stream() (or by using
  1053. * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()),
  1054. * then while it is encoding the encoder will fill the stream offsets in
  1055. * for you and when encoding is finished, it will seek back and write the
  1056. * real values into the SEEKTABLE block in the stream. There are helper
  1057. * routines for manipulating seektable template blocks; see metadata.h:
  1058. * FLAC__metadata_object_seektable_template_*(). If the client does
  1059. * not support seeking, the SEEKTABLE will have inaccurate offsets which
  1060. * will slow down or remove the ability to seek in the FLAC stream.
  1061. *
  1062. * \note
  1063. * The encoder instance \b will modify the first \c SEEKTABLE block
  1064. * as it transforms the template to a valid seektable while encoding,
  1065. * but it is still up to the caller to free all metadata blocks after
  1066. * encoding.
  1067. *
  1068. * \note
  1069. * A VORBIS_COMMENT block may be supplied. The vendor string in it
  1070. * will be ignored. libFLAC will use it's own vendor string. libFLAC
  1071. * will not modify the passed-in VORBIS_COMMENT's vendor string, it
  1072. * will simply write it's own into the stream. If no VORBIS_COMMENT
  1073. * block is present in the \a metadata array, libFLAC will write an
  1074. * empty one, containing only the vendor string.
  1075. *
  1076. * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
  1077. * the second metadata block of the stream. The encoder already supplies
  1078. * the STREAMINFO block automatically. If \a metadata does not contain a
  1079. * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if
  1080. * \a metadata does contain a VORBIS_COMMENT block and it is not the
  1081. * first, the init function will reorder \a metadata by moving the
  1082. * VORBIS_COMMENT block to the front; the relative ordering of the other
  1083. * blocks will remain as they were.
  1084. *
  1085. * \note The Ogg FLAC mapping limits the number of metadata blocks per
  1086. * stream to \c 65535. If \a num_blocks exceeds this the function will
  1087. * return \c false.
  1088. *
  1089. * \default \c NULL, 0
  1090. * \param encoder An encoder instance to set.
  1091. * \param metadata See above.
  1092. * \param num_blocks See above.
  1093. * \assert
  1094. * \code encoder != NULL \endcode
  1095. * \retval FLAC__bool
  1096. * \c false if the encoder is already initialized, else \c true.
  1097. * \c false if the encoder is already initialized, or if
  1098. * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true.
  1099. */
  1100. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  1101. /** Get the current encoder state.
  1102. *
  1103. * \param encoder An encoder instance to query.
  1104. * \assert
  1105. * \code encoder != NULL \endcode
  1106. * \retval FLAC__StreamEncoderState
  1107. * The current encoder state.
  1108. */
  1109. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  1110. /** Get the state of the verify stream decoder.
  1111. * Useful when the stream encoder state is
  1112. * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
  1113. *
  1114. * \param encoder An encoder instance to query.
  1115. * \assert
  1116. * \code encoder != NULL \endcode
  1117. * \retval FLAC__StreamDecoderState
  1118. * The verify stream decoder state.
  1119. */
  1120. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  1121. /** Get the current encoder state as a C string.
  1122. * This version automatically resolves
  1123. * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the
  1124. * verify decoder's state.
  1125. *
  1126. * \param encoder A encoder instance to query.
  1127. * \assert
  1128. * \code encoder != NULL \endcode
  1129. * \retval const char *
  1130. * The encoder state as a C string. Do not modify the contents.
  1131. */
  1132. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  1133. /** Get relevant values about the nature of a verify decoder error.
  1134. * Useful when the stream encoder state is
  1135. * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should
  1136. * be addresses in which the stats will be returned, or NULL if value
  1137. * is not desired.
  1138. *
  1139. * \param encoder An encoder instance to query.
  1140. * \param absolute_sample The absolute sample number of the mismatch.
  1141. * \param frame_number The number of the frame in which the mismatch occurred.
  1142. * \param channel The channel in which the mismatch occurred.
  1143. * \param sample The number of the sample (relative to the frame) in
  1144. * which the mismatch occurred.
  1145. * \param expected The expected value for the sample in question.
  1146. * \param got The actual value returned by the decoder.
  1147. * \assert
  1148. * \code encoder != NULL \endcode
  1149. */
  1150. FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
  1151. /** Get the "verify" flag.
  1152. *
  1153. * \param encoder An encoder instance to query.
  1154. * \assert
  1155. * \code encoder != NULL \endcode
  1156. * \retval FLAC__bool
  1157. * See FLAC__stream_encoder_set_verify().
  1158. */
  1159. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  1160. /** Get the <A HREF="../format.html#subset>Subset</A> flag.
  1161. *
  1162. * \param encoder An encoder instance to query.
  1163. * \assert
  1164. * \code encoder != NULL \endcode
  1165. * \retval FLAC__bool
  1166. * See FLAC__stream_encoder_set_streamable_subset().
  1167. */
  1168. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  1169. /** Get the number of input channels being processed.
  1170. *
  1171. * \param encoder An encoder instance to query.
  1172. * \assert
  1173. * \code encoder != NULL \endcode
  1174. * \retval unsigned
  1175. * See FLAC__stream_encoder_set_channels().
  1176. */
  1177. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  1178. /** Get the input sample resolution setting.
  1179. *
  1180. * \param encoder An encoder instance to query.
  1181. * \assert
  1182. * \code encoder != NULL \endcode
  1183. * \retval unsigned
  1184. * See FLAC__stream_encoder_set_bits_per_sample().
  1185. */
  1186. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  1187. /** Get the input sample rate setting.
  1188. *
  1189. * \param encoder An encoder instance to query.
  1190. * \assert
  1191. * \code encoder != NULL \endcode
  1192. * \retval unsigned
  1193. * See FLAC__stream_encoder_set_sample_rate().
  1194. */
  1195. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  1196. /** Get the blocksize setting.
  1197. *
  1198. * \param encoder An encoder instance to query.
  1199. * \assert
  1200. * \code encoder != NULL \endcode
  1201. * \retval unsigned
  1202. * See FLAC__stream_encoder_set_blocksize().
  1203. */
  1204. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  1205. /** Get the "mid/side stereo coding" flag.
  1206. *
  1207. * \param encoder An encoder instance to query.
  1208. * \assert
  1209. * \code encoder != NULL \endcode
  1210. * \retval FLAC__bool
  1211. * See FLAC__stream_encoder_get_do_mid_side_stereo().
  1212. */
  1213. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  1214. /** Get the "adaptive mid/side switching" flag.
  1215. *
  1216. * \param encoder An encoder instance to query.
  1217. * \assert
  1218. * \code encoder != NULL \endcode
  1219. * \retval FLAC__bool
  1220. * See FLAC__stream_encoder_set_loose_mid_side_stereo().
  1221. */
  1222. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  1223. /** Get the maximum LPC order setting.
  1224. *
  1225. * \param encoder An encoder instance to query.
  1226. * \assert
  1227. * \code encoder != NULL \endcode
  1228. * \retval unsigned
  1229. * See FLAC__stream_encoder_set_max_lpc_order().
  1230. */
  1231. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  1232. /** Get the quantized linear predictor coefficient precision setting.
  1233. *
  1234. * \param encoder An encoder instance to query.
  1235. * \assert
  1236. * \code encoder != NULL \endcode
  1237. * \retval unsigned
  1238. * See FLAC__stream_encoder_set_qlp_coeff_precision().
  1239. */
  1240. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  1241. /** Get the qlp coefficient precision search flag.
  1242. *
  1243. * \param encoder An encoder instance to query.
  1244. * \assert
  1245. * \code encoder != NULL \endcode
  1246. * \retval FLAC__bool
  1247. * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
  1248. */
  1249. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  1250. /** Get the "escape coding" flag.
  1251. *
  1252. * \param encoder An encoder instance to query.
  1253. * \assert
  1254. * \code encoder != NULL \endcode
  1255. * \retval FLAC__bool
  1256. * See FLAC__stream_encoder_set_do_escape_coding().
  1257. */
  1258. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  1259. /** Get the exhaustive model search flag.
  1260. *
  1261. * \param encoder An encoder instance to query.
  1262. * \assert
  1263. * \code encoder != NULL \endcode
  1264. * \retval FLAC__bool
  1265. * See FLAC__stream_encoder_set_do_exhaustive_model_search().
  1266. */
  1267. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  1268. /** Get the minimum residual partition order setting.
  1269. *
  1270. * \param encoder An encoder instance to query.
  1271. * \assert
  1272. * \code encoder != NULL \endcode
  1273. * \retval unsigned
  1274. * See FLAC__stream_encoder_set_min_residual_partition_order().
  1275. */
  1276. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  1277. /** Get maximum residual partition order setting.
  1278. *
  1279. * \param encoder An encoder instance to query.
  1280. * \assert
  1281. * \code encoder != NULL \endcode
  1282. * \retval unsigned
  1283. * See FLAC__stream_encoder_set_max_residual_partition_order().
  1284. */
  1285. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  1286. /** Get the Rice parameter search distance setting.
  1287. *
  1288. * \param encoder An encoder instance to query.
  1289. * \assert
  1290. * \code encoder != NULL \endcode
  1291. * \retval unsigned
  1292. * See FLAC__stream_encoder_set_rice_parameter_search_dist().
  1293. */
  1294. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  1295. /** Get the previously set estimate of the total samples to be encoded.
  1296. * The encoder merely mimics back the value given to
  1297. * FLAC__stream_encoder_set_total_samples_estimate() since it has no
  1298. * other way of knowing how many samples the client will encode.
  1299. *
  1300. * \param encoder An encoder instance to set.
  1301. * \assert
  1302. * \code encoder != NULL \endcode
  1303. * \retval FLAC__uint64
  1304. * See FLAC__stream_encoder_get_total_samples_estimate().
  1305. */
  1306. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  1307. /** Initialize the encoder instance to encode native FLAC streams.
  1308. *
  1309. * This flavor of initialization sets up the encoder to encode to a
  1310. * native FLAC stream. I/O is performed via callbacks to the client.
  1311. * For encoding to a plain file via filename or open \c FILE*,
  1312. * FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE()
  1313. * provide a simpler interface.
  1314. *
  1315. * This function should be called after FLAC__stream_encoder_new() and
  1316. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1317. * or FLAC__stream_encoder_process_interleaved().
  1318. * initialization succeeded.
  1319. *
  1320. * The call to FLAC__stream_encoder_init_stream() currently will also
  1321. * immediately call the write callback several times, once with the \c fLaC
  1322. * signature, and once for each encoded metadata block.
  1323. *
  1324. * \param encoder An uninitialized encoder instance.
  1325. * \param write_callback See FLAC__StreamEncoderWriteCallback. This
  1326. * pointer must not be \c NULL.
  1327. * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
  1328. * pointer may be \c NULL if seeking is not
  1329. * supported. The encoder uses seeking to go back
  1330. * and write some some stream statistics to the
  1331. * STREAMINFO block; this is recommended but not
  1332. * necessary to create a valid FLAC stream. If
  1333. * \a seek_callback is not \c NULL then a
  1334. * \a tell_callback must also be supplied.
  1335. * Alternatively, a dummy seek callback that just
  1336. * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  1337. * may also be supplied, all though this is slightly
  1338. * less efficient for the encoder.
  1339. * \param tell_callback See FLAC__StreamEncoderTellCallback. This
  1340. * pointer may be \c NULL if seeking is not
  1341. * supported. If \a seek_callback is \c NULL then
  1342. * this argument will be ignored. If
  1343. * \a seek_callback is not \c NULL then a
  1344. * \a tell_callback must also be supplied.
  1345. * Alternatively, a dummy tell callback that just
  1346. * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  1347. * may also be supplied, all though this is slightly
  1348. * less efficient for the encoder.
  1349. * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
  1350. * pointer may be \c NULL if the callback is not
  1351. * desired. If the client provides a seek callback,
  1352. * this function is not necessary as the encoder
  1353. * will automatically seek back and update the
  1354. * STREAMINFO block. It may also be \c NULL if the
  1355. * client does not support seeking, since it will
  1356. * have no way of going back to update the
  1357. * STREAMINFO. However the client can still supply
  1358. * a callback if it would like to know the details
  1359. * from the STREAMINFO.
  1360. * \param client_data This value will be supplied to callbacks in their
  1361. * \a client_data argument.
  1362. * \assert
  1363. * \code encoder != NULL \endcode
  1364. * \retval FLAC__StreamEncoderInitStatus
  1365. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1366. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1367. */
  1368. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  1369. /** Initialize the encoder instance to encode Ogg FLAC streams.
  1370. *
  1371. * This flavor of initialization sets up the encoder to encode to a FLAC
  1372. * stream in an Ogg container. I/O is performed via callbacks to the
  1373. * client. For encoding to a plain file via filename or open \c FILE*,
  1374. * FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE()
  1375. * provide a simpler interface.
  1376. *
  1377. * This function should be called after FLAC__stream_encoder_new() and
  1378. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1379. * or FLAC__stream_encoder_process_interleaved().
  1380. * initialization succeeded.
  1381. *
  1382. * The call to FLAC__stream_encoder_init_ogg_stream() currently will also
  1383. * immediately call the write callback several times to write the metadata
  1384. * packets.
  1385. *
  1386. * \param encoder An uninitialized encoder instance.
  1387. * \param read_callback See FLAC__StreamEncoderReadCallback. This
  1388. * pointer must not be \c NULL if \a seek_callback
  1389. * is non-NULL since they are both needed to be
  1390. * able to write data back to the Ogg FLAC stream
  1391. * in the post-encode phase.
  1392. * \param write_callback See FLAC__StreamEncoderWriteCallback. This
  1393. * pointer must not be \c NULL.
  1394. * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
  1395. * pointer may be \c NULL if seeking is not
  1396. * supported. The encoder uses seeking to go back
  1397. * and write some some stream statistics to the
  1398. * STREAMINFO block; this is recommended but not
  1399. * necessary to create a valid FLAC stream. If
  1400. * \a seek_callback is not \c NULL then a
  1401. * \a tell_callback must also be supplied.
  1402. * Alternatively, a dummy seek callback that just
  1403. * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  1404. * may also be supplied, all though this is slightly
  1405. * less efficient for the encoder.
  1406. * \param tell_callback See FLAC__StreamEncoderTellCallback. This
  1407. * pointer may be \c NULL if seeking is not
  1408. * supported. If \a seek_callback is \c NULL then
  1409. * this argument will be ignored. If
  1410. * \a seek_callback is not \c NULL then a
  1411. * \a tell_callback must also be supplied.
  1412. * Alternatively, a dummy tell callback that just
  1413. * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  1414. * may also be supplied, all though this is slightly
  1415. * less efficient for the encoder.
  1416. * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
  1417. * pointer may be \c NULL if the callback is not
  1418. * desired. If the client provides a seek callback,
  1419. * this function is not necessary as the encoder
  1420. * will automatically seek back and update the
  1421. * STREAMINFO block. It may also be \c NULL if the
  1422. * client does not support seeking, since it will
  1423. * have no way of going back to update the
  1424. * STREAMINFO. However the client can still supply
  1425. * a callback if it would like to know the details
  1426. * from the STREAMINFO.
  1427. * \param client_data This value will be supplied to callbacks in their
  1428. * \a client_data argument.
  1429. * \assert
  1430. * \code encoder != NULL \endcode
  1431. * \retval FLAC__StreamEncoderInitStatus
  1432. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1433. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1434. */
  1435. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
  1436. /** Initialize the encoder instance to encode native FLAC files.
  1437. *
  1438. * This flavor of initialization sets up the encoder to encode to a
  1439. * plain native FLAC file. For non-stdio streams, you must use
  1440. * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
  1441. *
  1442. * This function should be called after FLAC__stream_encoder_new() and
  1443. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1444. * or FLAC__stream_encoder_process_interleaved().
  1445. * initialization succeeded.
  1446. *
  1447. * \param encoder An uninitialized encoder instance.
  1448. * \param file An open file. The file should have been opened
  1449. * with mode \c "w+b" and rewound. The file
  1450. * becomes owned by the encoder and should not be
  1451. * manipulated by the client while encoding.
  1452. * Unless \a file is \c stdout, it will be closed
  1453. * when FLAC__stream_encoder_finish() is called.
  1454. * Note however that a proper SEEKTABLE cannot be
  1455. * created when encoding to \c stdout since it is
  1456. * not seekable.
  1457. * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
  1458. * pointer may be \c NULL if the callback is not
  1459. * desired.
  1460. * \param client_data This value will be supplied to callbacks in their
  1461. * \a client_data argument.
  1462. * \assert
  1463. * \code encoder != NULL \endcode
  1464. * \code file != NULL \endcode
  1465. * \retval FLAC__StreamEncoderInitStatus
  1466. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1467. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1468. */
  1469. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  1470. /** Initialize the encoder instance to encode Ogg FLAC files.
  1471. *
  1472. * This flavor of initialization sets up the encoder to encode to a
  1473. * plain Ogg FLAC file. For non-stdio streams, you must use
  1474. * FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O.
  1475. *
  1476. * This function should be called after FLAC__stream_encoder_new() and
  1477. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1478. * or FLAC__stream_encoder_process_interleaved().
  1479. * initialization succeeded.
  1480. *
  1481. * \param encoder An uninitialized encoder instance.
  1482. * \param file An open file. The file should have been opened
  1483. * with mode \c "w+b" and rewound. The file
  1484. * becomes owned by the encoder and should not be
  1485. * manipulated by the client while encoding.
  1486. * Unless \a file is \c stdout, it will be closed
  1487. * when FLAC__stream_encoder_finish() is called.
  1488. * Note however that a proper SEEKTABLE cannot be
  1489. * created when encoding to \c stdout since it is
  1490. * not seekable.
  1491. * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
  1492. * pointer may be \c NULL if the callback is not
  1493. * desired.
  1494. * \param client_data This value will be supplied to callbacks in their
  1495. * \a client_data argument.
  1496. * \assert
  1497. * \code encoder != NULL \endcode
  1498. * \code file != NULL \endcode
  1499. * \retval FLAC__StreamEncoderInitStatus
  1500. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1501. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1502. */
  1503. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  1504. /** Initialize the encoder instance to encode native FLAC files.
  1505. *
  1506. * This flavor of initialization sets up the encoder to encode to a plain
  1507. * FLAC file. If POSIX fopen() semantics are not sufficient (for example,
  1508. * with Unicode filenames on Windows), you must use
  1509. * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream()
  1510. * and provide callbacks for the I/O.
  1511. *
  1512. * This function should be called after FLAC__stream_encoder_new() and
  1513. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1514. * or FLAC__stream_encoder_process_interleaved().
  1515. * initialization succeeded.
  1516. *
  1517. * \param encoder An uninitialized encoder instance.
  1518. * \param filename The name of the file to encode to. The file will
  1519. * be opened with fopen(). Use \c NULL to encode to
  1520. * \c stdout. Note however that a proper SEEKTABLE
  1521. * cannot be created when encoding to \c stdout since
  1522. * it is not seekable.
  1523. * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
  1524. * pointer may be \c NULL if the callback is not
  1525. * desired.
  1526. * \param client_data This value will be supplied to callbacks in their
  1527. * \a client_data argument.
  1528. * \assert
  1529. * \code encoder != NULL \endcode
  1530. * \retval FLAC__StreamEncoderInitStatus
  1531. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1532. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1533. */
  1534. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  1535. /** Initialize the encoder instance to encode Ogg FLAC files.
  1536. *
  1537. * This flavor of initialization sets up the encoder to encode to a plain
  1538. * Ogg FLAC file. If POSIX fopen() semantics are not sufficient (for example,
  1539. * with Unicode filenames on Windows), you must use
  1540. * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream()
  1541. * and provide callbacks for the I/O.
  1542. *
  1543. * This function should be called after FLAC__stream_encoder_new() and
  1544. * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
  1545. * or FLAC__stream_encoder_process_interleaved().
  1546. * initialization succeeded.
  1547. *
  1548. * \param encoder An uninitialized encoder instance.
  1549. * \param filename The name of the file to encode to. The file will
  1550. * be opened with fopen(). Use \c NULL to encode to
  1551. * \c stdout. Note however that a proper SEEKTABLE
  1552. * cannot be created when encoding to \c stdout since
  1553. * it is not seekable.
  1554. * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
  1555. * pointer may be \c NULL if the callback is not
  1556. * desired.
  1557. * \param client_data This value will be supplied to callbacks in their
  1558. * \a client_data argument.
  1559. * \assert
  1560. * \code encoder != NULL \endcode
  1561. * \retval FLAC__StreamEncoderInitStatus
  1562. * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
  1563. * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
  1564. */
  1565. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  1566. /** Finish the encoding process.
  1567. * Flushes the encoding buffer, releases resources, resets the encoder
  1568. * settings to their defaults, and returns the encoder state to
  1569. * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
  1570. * one or more write callbacks before returning, and will generate
  1571. * a metadata callback.
  1572. *
  1573. * Note that in the course of processing the last frame, errors can
  1574. * occur, so the caller should be sure to check the return value to
  1575. * ensure the file was encoded properly.
  1576. *
  1577. * In the event of a prematurely-terminated encode, it is not strictly
  1578. * necessary to call this immediately before FLAC__stream_encoder_delete()
  1579. * but it is good practice to match every FLAC__stream_encoder_init_*()
  1580. * with a FLAC__stream_encoder_finish().
  1581. *
  1582. * \param encoder An uninitialized encoder instance.
  1583. * \assert
  1584. * \code encoder != NULL \endcode
  1585. * \retval FLAC__bool
  1586. * \c false if an error occurred processing the last frame; or if verify
  1587. * mode is set (see FLAC__stream_encoder_set_verify()), there was a
  1588. * verify mismatch; else \c true. If \c false, caller should check the
  1589. * state with FLAC__stream_encoder_get_state() for more information
  1590. * about the error.
  1591. */
  1592. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  1593. /** Submit data for encoding.
  1594. * This version allows you to supply the input data via an array of
  1595. * pointers, each pointer pointing to an array of \a samples samples
  1596. * representing one channel. The samples need not be block-aligned,
  1597. * but each channel should have the same number of samples. Each sample
  1598. * should be a signed integer, right-justified to the resolution set by
  1599. * FLAC__stream_encoder_set_bits_per_sample(). For example, if the
  1600. * resolution is 16 bits per sample, the samples should all be in the
  1601. * range [-32768,32767].
  1602. *
  1603. * For applications where channel order is important, channels must
  1604. * follow the order as described in the
  1605. * <A HREF="../format.html#frame_header">frame header</A>.
  1606. *
  1607. * \param encoder An initialized encoder instance in the OK state.
  1608. * \param buffer An array of pointers to each channel's signal.
  1609. * \param samples The number of samples in one channel.
  1610. * \assert
  1611. * \code encoder != NULL \endcode
  1612. * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
  1613. * \retval FLAC__bool
  1614. * \c true if successful, else \c false; in this case, check the
  1615. * encoder state with FLAC__stream_encoder_get_state() to see what
  1616. * went wrong.
  1617. */
  1618. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  1619. /** Submit data for encoding.
  1620. * This version allows you to supply the input data where the channels
  1621. * are interleaved into a single array (i.e. channel0_sample0,
  1622. * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
  1623. * The samples need not be block-aligned but they must be
  1624. * sample-aligned, i.e. the first value should be channel0_sample0
  1625. * and the last value channelN_sampleM. Each sample should be a signed
  1626. * integer, right-justified to the resolution set by
  1627. * FLAC__stream_encoder_set_bits_per_sample(). For example, if the
  1628. * resolution is 16 bits per sample, the samples should all be in the
  1629. * range [-32768,32767].
  1630. *
  1631. * For applications where channel order is important, channels must
  1632. * follow the order as described in the
  1633. * <A HREF="../format.html#frame_header">frame header</A>.
  1634. *
  1635. * \param encoder An initialized encoder instance in the OK state.
  1636. * \param buffer An array of channel-interleaved data (see above).
  1637. * \param samples The number of samples in one channel, the same as for
  1638. * FLAC__stream_encoder_process(). For example, if
  1639. * encoding two channels, \c 1000 \a samples corresponds
  1640. * to a \a buffer of 2000 values.
  1641. * \assert
  1642. * \code encoder != NULL \endcode
  1643. * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
  1644. * \retval FLAC__bool
  1645. * \c true if successful, else \c false; in this case, check the
  1646. * encoder state with FLAC__stream_encoder_get_state() to see what
  1647. * went wrong.
  1648. */
  1649. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  1650. /* \} */
  1651. #ifdef __cplusplus
  1652. }
  1653. #endif
  1654. #endif