1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001,2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef FLAC__STREAM_ENCODER_H
21 #define FLAC__STREAM_ENCODER_H
24 #include "stream_decoder.h"
31 /** \file include/FLAC/stream_encoder.h
34 * This module contains the functions which implement the stream
37 * See the detailed documentation in the
38 * \link flac_stream_encoder stream encoder \endlink module.
41 /** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
45 * This module describes the two encoder layers provided by libFLAC.
47 * For encoding FLAC streams, libFLAC provides two layers of access. The
48 * lowest layer is stream-level encoding, and the highest is file-level
49 * encoding. The interfaces are described in the \link flac_stream_encoder
50 * stream encoder \endlink and \link flac_file_encoder file encoder \endlink
51 * modules respectively. Typically you will choose the highest layer that
52 * your output source will support.
54 * The stream encoder relies on callbacks for writing the data and
55 * metadata. The file encoder provides these callbacks internally and you
56 * need only supply the filename.
59 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
60 * \ingroup flac_encoder
63 * This module contains the functions which implement the stream
66 * The basic usage of this encoder is as follows:
67 * - The program creates an instance of an encoder using
68 * FLAC__stream_encoder_new().
69 * - The program overrides the default settings and sets callbacks for
70 * writing and metadata reporting using
71 * FLAC__stream_encoder_set_*() functions.
72 * - The program initializes the instance to validate the settings and
73 * prepare for encoding using FLAC__stream_encoder_init().
74 * - The program calls FLAC__stream_encoder_process() or
75 * FLAC__stream_encoder_process_interleaved() to encode data, which
76 * subsequently calls the callbacks when there is encoder data ready
78 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
79 * which causes the encoder to encode any data still in its input pipe,
80 * call the metadata callback with the final encoding statistics, and
81 * finally reset the encoder to the uninitialized state.
82 * - The instance may be used again or deleted with
83 * FLAC__stream_encoder_delete().
85 * In more detail, the stream encoder functions similarly to the
86 * \link flac_stream_decoder stream decoder \endlink, but has fewer
87 * callbacks and more options. Typically the user will create a new
88 * instance by calling FLAC__stream_encoder_new(), then set the necessary
89 * parameters and callbacks with FLAC__stream_encoder_set_*(), and
90 * initialize it by calling FLAC__stream_encoder_init().
92 * Unlike the decoders, the stream encoder has many options that can
93 * affect the speed and compression ratio. When setting these parameters
94 * you should have some basic knowledge of the format (see the
95 * <A HREF="../documentation.html#format">user-level documentation</A>
96 * or the <A HREF="../format.html">formal description</A>). The
97 * FLAC__stream_encoder_set_*() functions themselves do not validate the
98 * values as many are interdependent. The FLAC__stream_encoder_init()
99 * function will do this, so make sure to pay attention to the state
100 * returned by FLAC__stream_encoder_init() to make sure that it is
101 * FLAC__STREAM_ENCODER_OK. Any parameters that are not set before
102 * FLAC__stream_encoder_init() will take on the defaults from the
105 * The user must provide function pointers for the following callbacks:
107 * - Write callback - This function is called by the encoder anytime there
108 * is raw encoded data to write. It may include metadata mixed with
109 * encoded audio frames and the data is not guaranteed to be aligned on
110 * frame or metadata block boundaries.
111 * - Metadata callback - This function is called once at the end of
112 * encoding with the populated STREAMINFO structure. This is so file
113 * encoders can seek back to the beginning of the file and write the
114 * STREAMINFO block with the correct statistics after encoding (like
115 * minimum/maximum frame size).
117 * The call to FLAC__stream_encoder_init() currently will also immediately
118 * call the write callback several times, once with the \c fLaC signature,
119 * and once for each encoded metadata block.
121 * After initializing the instance, the user may feed audio data to the
122 * encoder in one of two ways:
124 * - Channel separate, through FLAC__stream_encoder_process() - The user
125 * will pass an array of pointers to buffers, one for each channel, to
126 * the encoder, each of the same length. The samples need not be
128 * - Channel interleaved, through
129 * FLAC__stream_encoder_process_interleaved() - The user will pass a single
130 * pointer to data that is channel-interleaved (i.e. channel0_sample0,
131 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
132 * Again, the samples need not be block-aligned but they must be
133 * sample-aligned, i.e. the first value should be channel0_sample0 and
134 * the last value channelN_sampleM.
136 * When the user is finished encoding data, it calls
137 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
138 * data still in its input pipe, and call the metadata callback with the
139 * final encoding statistics. Then the instance may be deleted with
140 * FLAC__stream_encoder_delete() or initialized again to encode another
143 * For programs that write their own metadata, but that do not know the
144 * actual metadata until after encoding, it is advantageous to instruct
145 * the encoder to write a PADDING block of the correct size, so that
146 * instead of rewriting the whole stream after encoding, the program can
147 * just overwrite the PADDING block. If only the maximum size of the
148 * metadata is known, the program can write a slightly larger padding
149 * block, then split it after encoding.
151 * Make sure you understand how lengths are calculated. All FLAC metadata
152 * blocks have a 4 byte header which contains the type and length. This
153 * length does not include the 4 bytes of the header. See the format page
154 * for the specification of metadata blocks and their lengths.
157 * The "set" functions may only be called when the encoder is in the
158 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
159 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
160 * before FLAC__stream_encoder_init(). If this is the case they will
161 * return \c true, otherwise \c false.
164 * FLAC__stream_encoder_finish() resets all settings to the constructor
165 * defaults, including the callbacks.
171 /** State values for a FLAC__StreamEncoder
173 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
177 FLAC__STREAM_ENCODER_OK = 0,
178 /**< The encoder is in the normal OK state. */
180 FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
181 /**< An error occurred in the underlying verify stream decoder;
182 * check FLAC__stream_encoder_get_verify_decoder_state().
185 FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
186 /**< The verify decoder detected a mismatch between the original
187 * audio signal and the decoded audio signal.
190 FLAC__STREAM_ENCODER_INVALID_CALLBACK,
191 /**< The encoder was initialized before setting all the required callbacks. */
193 FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
194 /**< The encoder has an invalid setting for number of channels. */
196 FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
197 /**< The encoder has an invalid setting for bits-per-sample.
198 * FLAC supports 4-32 bps but the reference encoder currently supports
202 FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
203 /**< The encoder has an invalid setting for the input sample rate. */
205 FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
206 /**< The encoder has an invalid setting for the block size. */
208 FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
209 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
211 FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
212 /**< Mid/side coding was specified but the number of channels is not equal to 2. */
214 FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
217 FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
218 /**< Loose mid/side coding was specified but mid/side coding was not. */
220 FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
221 /**< The specified block size is less than the maximum LPC order. */
223 FLAC__STREAM_ENCODER_NOT_STREAMABLE,
224 /**< The encoder is bound to the "streamable subset" but other settings violate it. */
226 FLAC__STREAM_ENCODER_FRAMING_ERROR,
227 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
229 FLAC__STREAM_ENCODER_INVALID_METADATA,
230 /**< The metadata input to the encoder is invalid. */
232 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
233 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
235 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING,
236 /**< The write_callback returned an error. */
238 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
239 /**< Memory allocation failed. */
241 FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
242 /**< FLAC__stream_encoder_init() was called when the encoder was
243 * already initialized, usually because
244 * FLAC__stream_encoder_finish() was not called.
247 FLAC__STREAM_ENCODER_UNINITIALIZED
248 /**< The encoder is in the uninitialized state. */
250 } FLAC__StreamEncoderState;
252 /** Maps a FLAC__StreamEncoderState to a C string.
254 * Using a FLAC__StreamEncoderState as the index to this array
255 * will give the string equivalent. The contents should not be modified.
257 extern const char * const FLAC__StreamEncoderStateString[];
259 /** Return values for the FLAC__StreamEncoder write callback.
263 FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
264 /**< The write was OK and encoding can continue. */
266 FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
267 /**< An unrecoverable error occurred. The encoder will return from the process call. */
269 } FLAC__StreamEncoderWriteStatus;
271 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
273 * Using a FLAC__StreamEncoderWriteStatus as the index to this array
274 * will give the string equivalent. The contents should not be modified.
276 extern const char * const FLAC__StreamEncoderWriteStatusString[];
279 /***********************************************************************
281 * class FLAC__StreamEncoder
283 ***********************************************************************/
285 struct FLAC__StreamEncoderProtected;
286 struct FLAC__StreamEncoderPrivate;
287 /** The opaque structure definition for the stream encoder type.
288 * See the \link flac_stream_encoder stream encoder module \endlink
289 * for a detailed description.
292 struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
293 struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
294 } FLAC__StreamEncoder;
296 /** Signature for the write callback.
297 * See FLAC__stream_encoder_set_write_callback() for more info.
299 * \param encoder The encoder instance calling the callback.
300 * \param buffer An array of encoded data of length \a bytes.
301 * \param bytes The byte length of \a buffer.
302 * \param samples The number of samples encoded by \a buffer.
303 * \c 0 has a special meaning; see
304 * FLAC__stream_encoder_set_write_callback().
305 * \param current_frame The number of the current frame being encoded.
306 * \param client_data The callee's client data set through
307 * FLAC__stream_encoder_set_client_data().
308 * \retval FLAC__StreamDecoderWriteStatus
309 * The callee's return status.
311 typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
313 /** Signature for the metadata callback.
314 * See FLAC__stream_encoder_set_metadata_callback() for more info.
316 * \param encoder The encoder instance calling the callback.
317 * \param metadata The final populated STREAMINFO block.
318 * \param client_data The callee's client data set through
319 * FLAC__stream_encoder_set_client_data().
321 typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
324 /***********************************************************************
326 * Class constructor/destructor
328 ***********************************************************************/
330 /** Create a new stream encoder instance. The instance is created with
331 * default settings; see the individual FLAC__stream_encoder_set_*()
332 * functions for each setting's default.
334 * \retval FLAC__StreamEncoder*
335 * \c NULL if there was an error allocating memory, else the new instance.
337 FLAC__StreamEncoder *FLAC__stream_encoder_new();
339 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
341 * \param encoder A pointer to an existing encoder.
343 * \code encoder != NULL \endcode
345 void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
347 /***********************************************************************
349 * Public class method prototypes
351 ***********************************************************************/
353 /** Set the "verify" flag. If \c true, the encoder will verify it's own
354 * encoded output by feeding it through an internal decoder and comparing
355 * the original signal against the decoded signal. If a mismatch occurs,
356 * the process call will return \c false. Note that this will slow the
357 * encoding process by the extra time required for decoding and comparison.
360 * \param encoder An encoder instance to set.
361 * \param value Flag value (see above).
363 * \code encoder != NULL \endcode
365 * \c false if the encoder is already initialized, else \c true.
367 FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
369 /** Set the "streamable subset" flag. If \c true, the encoder will comply
370 * with the subset (see the format specification) and will check the
371 * settings during FLAC__stream_encoder_init() to see if all settings
372 * comply. If \c false, the settings may take advantage of the full
373 * range that the format allows.
375 * Make sure you know what it entails before setting this to \c false.
378 * \param encoder An encoder instance to set.
379 * \param value Flag value (see above).
381 * \code encoder != NULL \endcode
383 * \c false if the encoder is already initialized, else \c true.
385 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
387 /** Set to \c true to enable mid-side encoding on stereo input. The
388 * number of channels must be 2. Set to \c false to use only
389 * independent channel coding.
392 * \param encoder An encoder instance to set.
393 * \param value Flag value (see above).
395 * \code encoder != NULL \endcode
397 * \c false if the encoder is already initialized, else \c true.
399 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
401 /** Set to \c true to enable adaptive switching between mid-side and
402 * left-right encoding on stereo input. The number of channels must
403 * be 2. Set to \c false to use exhaustive searching. In either
404 * case, the mid/side stereo setting must be \c true.
407 * \param encoder An encoder instance to set.
408 * \param value Flag value (see above).
410 * \code encoder != NULL \endcode
412 * \c false if the encoder is already initialized, else \c true.
414 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
416 /** Set the number of channels to be encoded.
419 * \param encoder An encoder instance to set.
420 * \param value See above.
422 * \code encoder != NULL \endcode
424 * \c false if the encoder is already initialized, else \c true.
426 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
428 /** Set the sample resolution of the input to be encoded.
431 * Do not feed the encoder data that is wider than the value you
432 * set here or you will generate an invalid stream.
435 * \param encoder An encoder instance to set.
436 * \param value See above.
438 * \code encoder != NULL \endcode
440 * \c false if the encoder is already initialized, else \c true.
442 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
444 /** Set the sample rate (in Hz) of the input to be encoded.
447 * \param encoder An encoder instance to set.
448 * \param value See above.
450 * \code encoder != NULL \endcode
452 * \c false if the encoder is already initialized, else \c true.
454 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
456 /** Set the blocksize to use while encoding.
459 * \param encoder An encoder instance to set.
460 * \param value See above.
462 * \code encoder != NULL \endcode
464 * \c false if the encoder is already initialized, else \c true.
466 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
468 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
471 * \param encoder An encoder instance to set.
472 * \param value See above.
474 * \code encoder != NULL \endcode
476 * \c false if the encoder is already initialized, else \c true.
478 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
480 /** Set the precision, in bits, of the quantized linear predictor
481 * coefficients, or \c 0 to let the encoder select it based on the
485 * In the current implementation, qlp_coeff_precision + bits_per_sample must
489 * \param encoder An encoder instance to set.
490 * \param value See above.
492 * \code encoder != NULL \endcode
494 * \c false if the encoder is already initialized, else \c true.
496 FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
498 /** Set to \c false to use only the specified quantized linear predictor
499 * coefficient precision, or \c true to search neighboring precision
500 * values and use the best one.
503 * \param encoder An encoder instance to set.
504 * \param value See above.
506 * \code encoder != NULL \endcode
508 * \c false if the encoder is already initialized, else \c true.
510 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
512 /** Deprecated. Setting this value has no effect.
515 * \param encoder An encoder instance to set.
516 * \param value See above.
518 * \code encoder != NULL \endcode
520 * \c false if the encoder is already initialized, else \c true.
522 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
524 /** Set to \c false to let the encoder estimate the best model order
525 * based on the residual signal energy, or \c true to force the
526 * encoder to evaluate all order models and select the best.
529 * \param encoder An encoder instance to set.
530 * \param value See above.
532 * \code encoder != NULL \endcode
534 * \c false if the encoder is already initialized, else \c true.
536 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
538 /** Set the minimum partition order to search when coding the residual.
539 * This is used in tandem with
540 * FLAC__stream_encoder_set_max_residual_partition_order().
542 * The partition order determines the context size in the residual.
543 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
545 * Set both min and max values to \c 0 to force a single context,
546 * whose Rice parameter is based on the residual signal variance.
547 * Otherwise, set a min and max order, and the encoder will search
548 * all orders, using the mean of each context for its Rice parameter,
552 * \param encoder An encoder instance to set.
553 * \param value See above.
555 * \code encoder != NULL \endcode
557 * \c false if the encoder is already initialized, else \c true.
559 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
561 /** Set the minimum partition order to search when coding the residual.
562 * This is used in tandem with
563 * FLAC__stream_encoder_set_min_residual_partition_order().
565 * The partition order determines the context size in the residual.
566 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
568 * Set both min and max values to \c 0 to force a single context,
569 * whose Rice parameter is based on the residual signal variance.
570 * Otherwise, set a min and max order, and the encoder will search
571 * all orders, using the mean of each context for its Rice parameter,
575 * \param encoder An encoder instance to set.
576 * \param value See above.
578 * \code encoder != NULL \endcode
580 * \c false if the encoder is already initialized, else \c true.
582 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
584 /** Deprecated. Setting this value has no effect.
587 * \param encoder An encoder instance to set.
588 * \param value See above.
590 * \code encoder != NULL \endcode
592 * \c false if the encoder is already initialized, else \c true.
594 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
596 /** Set an estimate of the total samples that will be encoded.
597 * This is merely an estimate and may be set to \c 0 if unknown.
598 * This value will be written to the STREAMINFO block before encoding,
599 * and can remove the need for the caller to rewrite the value later
600 * if the value is known before encoding.
603 * \param encoder An encoder instance to set.
604 * \param value See above.
606 * \code encoder != NULL \endcode
608 * \c false if the encoder is already initialized, else \c true.
610 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
612 /** Set the metadata blocks to be emitted to the stream before encoding.
613 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
614 * array of pointers to metadata blocks. The array is non-const since
615 * the encoder may need to change the \a is_last flag inside them.
616 * Otherwise, the encoder will not modify or free the blocks. It is up
617 * to the caller to free the metadata blocks after encoding.
619 * The STREAMINFO block is always written and no STREAMINFO block may
620 * occur in the supplied array.
622 * \default \c NULL, 0
623 * \param encoder An encoder instance to set.
624 * \param metadata See above.
625 * \param num_blocks See above.
627 * \code encoder != NULL \endcode
629 * \c false if the encoder is already initialized, else \c true.
631 FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
633 /** Set the write callback.
634 * The supplied function will be called by the encoder anytime there is raw
635 * encoded data ready to write. It may include metadata mixed with encoded
636 * audio frames and the data is not guaranteed to be aligned on frame or
637 * metadata block boundaries.
639 * The only duty of the callback is to write out the \a bytes worth of data
640 * in \a buffer to the current position in the output stream. The arguments
641 * \a samples and \a current_frame are purely informational. If \a samples
642 * is greater than \c 0, then \a current_frame will hold the current frame
643 * number that is being written; otherwise, the write callback is being called
647 * The callback is mandatory and must be set before initialization.
650 * \param encoder An encoder instance to set.
651 * \param value See above.
653 * \code encoder != NULL \endcode
654 * \code value != NULL \endcode
656 * \c false if the encoder is already initialized, else \c true.
658 FLAC__bool FLAC__stream_encoder_set_write_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback value);
660 /** Set the metadata callback.
661 * The supplied function will be called once at the end of encoding with
662 * the populated STREAMINFO structure. This is so file encoders can seek
663 * back to the beginning of the file and write the STREAMINFO block with
664 * the correct statistics after encoding (like minimum/maximum frame size
665 * and total samples).
668 * The callback is mandatory and must be set before initialization.
671 * \param encoder An encoder instance to set.
672 * \param value See above.
674 * \code encoder != NULL \endcode
675 * \code value != NULL \endcode
677 * \c false if the encoder is already initialized, else \c true.
679 FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderMetadataCallback value);
681 /** Set the client data to be passed back to callbacks.
682 * This value will be supplied to callbacks in their \a client_data
686 * \param encoder An encoder instance to set.
687 * \param value See above.
689 * \code encoder != NULL \endcode
691 * \c false if the encoder is already initialized, else \c true.
693 FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
695 /** Get the current encoder state.
697 * \param encoder An encoder instance to query.
699 * \code encoder != NULL \endcode
700 * \retval FLAC__StreamEncoderState
701 * The current encoder state.
703 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
705 /** Get the state of the verify stream decoder.
706 * Useful when the stream encoder state is
707 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
709 * \param encoder An encoder instance to query.
711 * \code encoder != NULL \endcode
712 * \retval FLAC__StreamDecoderState
713 * The verify stream decoder state.
715 FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
717 /** Get relevant values about the nature of a verify decoder error.
718 * Useful when the stream encoder state is
719 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should
720 * be addresses in which the stats will be returned, or NULL if value
723 * \param encoder An encoder instance to query.
724 * \param absolute_sample The absolute sample number of the mismatch.
725 * \param frame_number The number of the frame in which the mismatch occurred.
726 * \param channel The channel in which the mismatch occurred.
727 * \param sample The number of the sample (relative to the frame) in
728 * which the mismatch occurred.
729 * \param expected The expected value for the sample in question.
730 * \param got The actual value returned by the decoder.
732 * \code encoder != NULL \endcode
734 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);
736 /** Get the "verify" flag.
738 * \param encoder An encoder instance to query.
740 * \code encoder != NULL \endcode
742 * See FLAC__stream_encoder_set_verify().
744 FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
746 /** Get the "streamable subset" flag.
748 * \param encoder An encoder instance to query.
750 * \code encoder != NULL \endcode
752 * See FLAC__stream_encoder_set_streamable_subset().
754 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
756 /** Get the "mid/side stereo coding" flag.
758 * \param encoder An encoder instance to query.
760 * \code encoder != NULL \endcode
762 * See FLAC__stream_encoder_get_do_mid_side_stereo().
764 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
766 /** Get the "adaptive mid/side switching" flag.
768 * \param encoder An encoder instance to query.
770 * \code encoder != NULL \endcode
772 * See FLAC__stream_encoder_set_loose_mid_side_stereo().
774 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
776 /** Get the number of input channels being processed.
778 * \param encoder An encoder instance to query.
780 * \code encoder != NULL \endcode
782 * See FLAC__stream_encoder_set_channels().
784 unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
786 /** Get the input sample resolution setting.
788 * \param encoder An encoder instance to query.
790 * \code encoder != NULL \endcode
792 * See FLAC__stream_encoder_set_bits_per_sample().
794 unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
796 /** Get the input sample rate setting.
798 * \param encoder An encoder instance to query.
800 * \code encoder != NULL \endcode
802 * See FLAC__stream_encoder_set_sample_rate().
804 unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
806 /** Get the blocksize setting.
808 * \param encoder An encoder instance to query.
810 * \code encoder != NULL \endcode
812 * See FLAC__stream_encoder_set_blocksize().
814 unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
816 /** Get the maximum LPC order setting.
818 * \param encoder An encoder instance to query.
820 * \code encoder != NULL \endcode
822 * See FLAC__stream_encoder_set_max_lpc_order().
824 unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
826 /** Get the quantized linear predictor coefficient precision setting.
828 * \param encoder An encoder instance to query.
830 * \code encoder != NULL \endcode
832 * See FLAC__stream_encoder_set_qlp_coeff_precision().
834 unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
836 /** Get the qlp coefficient precision search flag.
838 * \param encoder An encoder instance to query.
840 * \code encoder != NULL \endcode
842 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
844 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
846 /** Get the "escape coding" flag.
848 * \param encoder An encoder instance to query.
850 * \code encoder != NULL \endcode
852 * See FLAC__stream_encoder_set_do_escape_coding().
854 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
856 /** Get the exhaustive model search flag.
858 * \param encoder An encoder instance to query.
860 * \code encoder != NULL \endcode
862 * See FLAC__stream_encoder_set_do_exhaustive_model_search().
864 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
866 /** Get the minimum residual partition order setting.
868 * \param encoder An encoder instance to query.
870 * \code encoder != NULL \endcode
872 * See FLAC__stream_encoder_set_min_residual_partition_order().
874 unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
876 /** Get maximum residual partition order setting.
878 * \param encoder An encoder instance to query.
880 * \code encoder != NULL \endcode
882 * See FLAC__stream_encoder_set_max_residual_partition_order().
884 unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
886 /** Get the Rice parameter search distance setting.
888 * \param encoder An encoder instance to query.
890 * \code encoder != NULL \endcode
892 * See FLAC__stream_encoder_set_rice_parameter_search_dist().
894 unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
896 /** Get the previously set estimate of the total samples to be encoded.
897 * The encoder merely mimics back the value given to
898 * FLAC__stream_encoder_set_total_samples_estimate() since it has no
899 * other way of knowing how many samples the user will encode.
901 * \param encoder An encoder instance to set.
903 * \code encoder != NULL \endcode
904 * \retval FLAC__uint64
905 * See FLAC__stream_encoder_get_total_samples_estimate().
907 FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
909 /** Initialize the encoder instance.
910 * Should be called after FLAC__stream_encoder_new() and
911 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
912 * or FLAC__stream_encoder_process_interleaved(). Will set and return
913 * the encoder state, which will be FLAC__STREAM_ENCODER_OK if
914 * initialization succeeded.
916 * The call to FLAC__stream_encoder_init() currently will also immediately
917 * call the write callback several times, once with the \c fLaC signature,
918 * and once for each encoded metadata block.
920 * \param encoder An uninitialized encoder instance.
922 * \code encoder != NULL \endcode
923 * \retval FLAC__StreamEncoderState
924 * \c FLAC__STREAM_ENCODER_OK if initialization was successful; see
925 * FLAC__StreamEncoderState for the meanings of other return values.
927 FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
929 /** Finish the encoding process.
930 * Flushes the encoding buffer, releases resources, resets the encoder
931 * settings to their defaults, and returns the encoder state to
932 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
933 * one or more write callbacks before returning, and will generate
934 * a metadata callback.
936 * In the event of a prematurely-terminated encode, it is not strictly
937 * necessary to call this immediately before FLAC__stream_encoder_delete()
938 * but it is good practice to match every FLAC__stream_encoder_init()
939 * with a FLAC__stream_encoder_finish().
941 * \param encoder An uninitialized encoder instance.
943 * \code encoder != NULL \endcode
945 void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
947 /** Submit data for encoding.
948 * This version allows you to supply the input data via an array of
949 * pointers, each pointer pointing to an array of \a samples samples
950 * representing one channel. The samples need not be block-aligned,
951 * but each channel should have the same number of samples.
953 * \param encoder An initialized encoder instance in the OK state.
954 * \param buffer An array of pointers to each channel's signal.
955 * \param samples The number of samples in one channel.
957 * \code encoder != NULL \endcode
958 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
960 * \c true if successful, else \c false; in this case, check the
961 * encoder state with FLAC__stream_encoder_get_state() to see what
964 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
966 /** Submit data for encoding.
967 * This version allows you to supply the input data where the channels
968 * are interleaved into a single array (i.e. channel0_sample0,
969 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
970 * The samples need not be block-aligned but they must be
971 * sample-aligned, i.e. the first value should be channel0_sample0
972 * and the last value channelN_sampleM.
974 * \param encoder An initialized encoder instance in the OK state.
975 * \param buffer An array of channel-interleaved data (see above).
976 * \param samples The number of samples in one channel, the same as for
977 * FLAC__stream_encoder_process(). For example, if
978 * encoding two channels, \c 1000 \a samples corresponds
979 * to a \a buffer of 2000 values.
981 * \code encoder != NULL \endcode
982 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
984 * \c true if successful, else \c false; in this case, check the
985 * encoder state with FLAC__stream_encoder_get_state() to see what
988 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);