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
30 /** \file include/FLAC/stream_encoder.h
33 * This module contains the functions which implement the stream
36 * See the detailed documentation in the
37 * \link flac_stream_encoder stream encoder \endlink module.
40 /** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
44 * This module describes the single encoder layer provided by libFLAC.
46 * Currently there is only one level of encoder implementation which is at
47 * the stream level. There is currently no file encoder because seeking
48 * within a file while encoding seemed like too obscure a feature.
51 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
52 * \ingroup flac_encoder
55 * This module contains the functions which implement the stream
58 * The basic usage of this encoder is as follows:
59 * - The program creates an instance of an encoder using
60 * FLAC__stream_encoder_new().
61 * - The program overrides the default settings and sets callbacks for
62 * writing and metadata reporting using
63 * FLAC__stream_encoder_set_*() functions.
64 * - The program initializes the instance to validate the settings and
65 * prepare for encoding using FLAC__stream_encoder_init().
66 * - The program calls FLAC__stream_encoder_process() or
67 * FLAC__stream_encoder_process_interleaved() to encode data, which
68 * subsequently calls the callbacks when there is encoder data ready
70 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
71 * which causes the encoder to encode any data still in its input pipe,
72 * call the metadata callback with the final encoding statistics, and
73 * finally reset the encoder to the uninitialized state.
74 * - The instance may be used again or deleted with
75 * FLAC__stream_encoder_delete().
77 * In more detail, the stream encoder functions similarly to the
78 * \link flac_stream_decoder stream decoder \endlink, but has fewer
79 * callbacks and more options. Typically the user will create a new
80 * instance by calling FLAC__stream_encoder_new(), then set the necessary
81 * parameters and callbacks with FLAC__stream_encoder_set_*(), and
82 * initialize it by calling FLAC__stream_encoder_init().
84 * Unlike the decoders, the stream encoder has many options that can
85 * affect the speed and compression ratio. When setting these parameters
86 * you should have some basic knowledge of the format (see the
87 * <A HREF="../documentation.html#format">user-level documentation</A>
88 * or the <A HREF="../format.html">formal description</A>). The
89 * FLAC__stream_encoder_set_*() functions themselves do not validate the
90 * values as many are interdependent. The FLAC__stream_encoder_init()
91 * function will do this, so make sure to pay attention to the state
92 * returned by FLAC__stream_encoder_init() to make sure that it is
93 * FLAC__STREAM_ENCODER_OK. Any parameters that are not set before
94 * FLAC__stream_encoder_init() will take on the defaults from the
97 * The user must provide function pointers for the following callbacks:
99 * - Write callback - This function is called by the encoder anytime there
100 * is raw encoded data to write. It may include metadata mixed with
101 * encoded audio frames and the data is not guaranteed to be aligned on
102 * frame or metadata block boundaries.
103 * - Metadata callback - This function is called once at the end of
104 * encoding with the populated STREAMINFO structure. This is so file
105 * encoders can seek back to the beginning of the file and write the
106 * STREAMINFO block with the correct statistics after encoding (like
107 * minimum/maximum frame size).
109 * The call to FLAC__stream_encoder_init() currently will also immediately
110 * call the write callback with the \c fLaC signature and all the encoded
113 * After initializing the instance, the user may feed audio data to the
114 * encoder in one of two ways:
116 * - Channel separate, through FLAC__stream_encoder_process() - The user
117 * will pass an array of pointers to buffers, one for each channel, to
118 * the encoder, each of the same length. The samples need not be
120 * - Channel interleaved, through
121 * FLAC__stream_encoder_process_interleaved() - The user will pass a single
122 * pointer to data that is channel-interleaved (i.e. channel0_sample0,
123 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
124 * Again, the samples need not be block-aligned but they must be
125 * sample-aligned, i.e. the first value should be channel0_sample0 and
126 * the last value channelN_sampleM.
128 * When the user is finished encoding data, it calls
129 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
130 * data still in its input pipe, and call the metadata callback with the
131 * final encoding statistics. Then the instance may be deleted with
132 * FLAC__stream_encoder_delete() or initialized again to encode another
135 * For programs that write their own metadata, but that do not know the
136 * actual metadata until after encoding, it is advantageous to instruct
137 * the encoder to write a PADDING block of the correct size, so that
138 * instead of rewriting the whole stream after encoding, the program can
139 * just overwrite the PADDING block. If only the maximum size of the
140 * metadata is known, the program can write a slightly larger padding
141 * block, then split it after encoding.
143 * Make sure you understand how lengths are calculated. All FLAC metadata
144 * blocks have a 4 byte header which contains the type and length. This
145 * length does not include the 4 bytes of the header. See the format page
146 * for the specification of metadata blocks and their lengths.
149 * The "set" functions may only be called when the encoder is in the
150 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
151 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
152 * before FLAC__stream_encoder_init(). If this is the case they will
153 * return \c true, otherwise \c false.
156 * FLAC__stream_encoder_finish() resets all settings to the constructor
157 * defaults, including the callbacks.
163 /** State values for a FLAC__StreamEncoder
165 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
169 FLAC__STREAM_ENCODER_OK = 0,
170 /**< The encoder is in the normal OK state. */
172 FLAC__STREAM_ENCODER_INVALID_CALLBACK,
173 /**< The encoder was initialized before setting all the required callbacks. */
175 FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
176 /**< The encoder has an invalid setting for number of channels. */
178 FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
179 /**< The encoder has an invalid setting for bits-per-sample.
180 * FLAC supports 4-32 bps but the reference encoder currently supports
184 FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
185 /**< The encoder has an invalid setting for the input sample rate. */
187 FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
188 /**< The encoder has an invalid setting for the block size. */
190 FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
191 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
193 FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
194 /**< Mid/side coding was specified but the number of channels is not equal to 2. */
196 FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
199 FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
200 /**< Loose mid/side coding was specified but mid/side coding was not. */
202 FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
203 /**< The specified block size is less than the maximum LPC order. */
205 FLAC__STREAM_ENCODER_NOT_STREAMABLE,
206 /**< The encoder is bound to the "streamable subset" but other settings violate it. */
208 FLAC__STREAM_ENCODER_FRAMING_ERROR,
209 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
211 FLAC__STREAM_ENCODER_INVALID_METADATA,
212 /**< The metadata input to the encoder is invalid. */
214 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
215 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
217 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING,
218 /**< The write_callback returned an error. */
220 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
221 /**< Memory allocation failed. */
223 FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
224 /**< FLAC__stream_encoder_init() was called when the encoder was
225 * already initialized, usually because
226 * FLAC__stream_encoder_finish() was not called.
229 FLAC__STREAM_ENCODER_UNINITIALIZED
230 /**< The encoder is in the uninitialized state. */
232 } FLAC__StreamEncoderState;
234 /** Maps a FLAC__StreamEncoderState to a C string.
236 * Using a FLAC__StreamEncoderState as the index to this array
237 * will give the string equivalent. The contents should not be modified.
239 extern const char * const FLAC__StreamEncoderStateString[];
241 /** Return values for the FLAC__StreamEncoder write callback.
245 FLAC__STREAM_ENCODER_WRITE_OK = 0,
246 /**< The write was OK and encoding can continue. */
248 FLAC__STREAM_ENCODER_WRITE_FATAL_ERROR
249 /**< An unrecoverable error occurred. The encoder will return from the process call. */
251 } FLAC__StreamEncoderWriteStatus;
253 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
255 * Using a FLAC__StreamEncoderWriteStatus as the index to this array
256 * will give the string equivalent. The contents should not be modified.
258 extern const char * const FLAC__StreamEncoderWriteStatusString[];
261 /***********************************************************************
263 * class FLAC__StreamEncoder
265 ***********************************************************************/
267 struct FLAC__StreamEncoderProtected;
268 struct FLAC__StreamEncoderPrivate;
269 /** The opaque structure definition for the stream encoder type.
270 * See the \link flac_stream_encoder stream encoder module \endlink
271 * for a detailed description.
274 struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
275 struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
276 } FLAC__StreamEncoder;
279 /***********************************************************************
281 * Class constructor/destructor
283 ***********************************************************************/
285 /** Create a new stream encoder instance. The instance is created with
286 * default settings; see the individual FLAC__stream_encoder_set_*()
287 * functions for each setting's default.
289 * \retval FLAC__StreamEncoder*
290 * \c NULL if there was an error allocating memory, else the new instance.
292 FLAC__StreamEncoder *FLAC__stream_encoder_new();
294 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
296 * \param encoder A pointer to an existing encoder.
298 * \code encoder != NULL \endcode
300 void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
302 /***********************************************************************
304 * Public class method prototypes
306 ***********************************************************************/
308 /** Set the "streamable subset" flag. If \c true, the encoder will comply
309 * with the subset (see the format specification) and will check the
310 * settings during FLAC__stream_encoder_init() to see if all settings
311 * comply. If \c false, the settings may take advantage of the full
312 * range that the format allows.
314 * Make sure you know what it entails before setting this to \c false.
317 * \param encoder An encoder instance to set.
318 * \param value Flag value (see above).
320 * \code encoder != NULL \endcode
322 * \c false if the encoder is already initialized, else \c true.
324 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
326 /** Set to \c true to enable mid-side encoding on stereo input. The
327 * number of channels must be 2. Set to \c false to use only
328 * independent channel coding.
331 * \param encoder An encoder instance to set.
332 * \param value Flag value (see above).
334 * \code encoder != NULL \endcode
336 * \c false if the encoder is already initialized, else \c true.
338 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
340 /** Set to \c true to enable adaptive switching between mid-side and
341 * left-right encoding on stereo input. The number of channels must
342 * be 2. Set to \c false to use exhaustive searching. In either
343 * case, the mid/side stereo setting must be \c true.
346 * \param encoder An encoder instance to set.
347 * \param value Flag value (see above).
349 * \code encoder != NULL \endcode
351 * \c false if the encoder is already initialized, else \c true.
353 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
355 /** Set the number of channels to be encoded.
358 * \param encoder An encoder instance to set.
359 * \param value See above.
361 * \code encoder != NULL \endcode
363 * \c false if the encoder is already initialized, else \c true.
365 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
367 /** Set the sample resolution of the input to be encoded.
370 * Do not feed the encoder data that is wider than the value you
371 * set here or you will generate an invalid stream.
374 * \param encoder An encoder instance to set.
375 * \param value See above.
377 * \code encoder != NULL \endcode
379 * \c false if the encoder is already initialized, else \c true.
381 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
383 /** Set the sample rate (in Hz) of the input to be encoded.
386 * \param encoder An encoder instance to set.
387 * \param value See above.
389 * \code encoder != NULL \endcode
391 * \c false if the encoder is already initialized, else \c true.
393 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
395 /** Set the blocksize to use while encoding.
398 * \param encoder An encoder instance to set.
399 * \param value See above.
401 * \code encoder != NULL \endcode
403 * \c false if the encoder is already initialized, else \c true.
405 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
407 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
410 * \param encoder An encoder instance to set.
411 * \param value See above.
413 * \code encoder != NULL \endcode
415 * \c false if the encoder is already initialized, else \c true.
417 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
419 /** Set the precision, in bits, of the quantized linear predictor
420 * coefficients, or \c 0 to let the encoder select it based on the
424 * In the current implementation, qlp_coeff_precision + bits_per_sample must
428 * \param encoder An encoder instance to set.
429 * \param value See above.
431 * \code encoder != NULL \endcode
433 * \c false if the encoder is already initialized, else \c true.
435 FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
437 /** Set to \c false to use only the specified quantized linear predictor
438 * coefficient precision, or \c true to search neighboring precision
439 * values and use the best one.
442 * \param encoder An encoder instance to set.
443 * \param value See above.
445 * \code encoder != NULL \endcode
447 * \c false if the encoder is already initialized, else \c true.
449 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
451 /** Deprecated. Setting this value has no effect.
454 * \param encoder An encoder instance to set.
455 * \param value See above.
457 * \code encoder != NULL \endcode
459 * \c false if the encoder is already initialized, else \c true.
461 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
463 /** Set to \c false to let the encoder estimate the best model order
464 * based on the residual signal energy, or \c true to force the
465 * encoder to evaluate all order models and select the best.
468 * \param encoder An encoder instance to set.
469 * \param value See above.
471 * \code encoder != NULL \endcode
473 * \c false if the encoder is already initialized, else \c true.
475 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
477 /** Set the minimum partition order to search when coding the residual.
478 * This is used in tandem with
479 * FLAC__stream_encoder_set_max_residual_partition_order().
481 * The partition order determines the context size in the residual.
482 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
484 * Set both min and max values to \c 0 to force a single context,
485 * whose Rice parameter is based on the residual signal variance.
486 * Otherwise, set a min and max order, and the encoder will search
487 * all orders, using the mean of each context for its Rice parameter,
491 * \param encoder An encoder instance to set.
492 * \param value See above.
494 * \code encoder != NULL \endcode
496 * \c false if the encoder is already initialized, else \c true.
498 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
500 /** Set the minimum partition order to search when coding the residual.
501 * This is used in tandem with
502 * FLAC__stream_encoder_set_min_residual_partition_order().
504 * The partition order determines the context size in the residual.
505 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
507 * Set both min and max values to \c 0 to force a single context,
508 * whose Rice parameter is based on the residual signal variance.
509 * Otherwise, set a min and max order, and the encoder will search
510 * all orders, using the mean of each context for its Rice parameter,
514 * \param encoder An encoder instance to set.
515 * \param value See above.
517 * \code encoder != NULL \endcode
519 * \c false if the encoder is already initialized, else \c true.
521 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
523 /** Deprecated. Setting this value has no effect.
526 * \param encoder An encoder instance to set.
527 * \param value See above.
529 * \code encoder != NULL \endcode
531 * \c false if the encoder is already initialized, else \c true.
533 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
535 /** Set an estimate of the total samples that will be encoded.
536 * This is merely an estimate and may be set to \c 0 if unknown.
537 * This value will be written to the STREAMINFO block before encoding,
538 * and can remove the need for the caller to rewrite the value later
539 * if the value is known before encoding.
542 * \param encoder An encoder instance to set.
543 * \param value See above.
545 * \code encoder != NULL \endcode
547 * \c false if the encoder is already initialized, else \c true.
549 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
551 /** Set the metadata blocks to be emitted to the stream before encoding.
552 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
553 * array of pointers to metadata blocks. The array is non-const since
554 * the encoder may need to change the \a is_last flag inside them.
555 * Otherwise, the encoder will not modify or free the blocks.
557 * The STREAMINFO block is always written and no STREAMINFO block may
558 * occur in the supplied array.
560 * \default \c NULL, 0
561 * \param encoder An encoder instance to set.
562 * \param metadata See above.
563 * \param num_blocks See above.
565 * \code encoder != NULL \endcode
567 * \c false if the encoder is already initialized, else \c true.
569 FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
571 /** Set the write callback.
572 * The supplied function will be called by the encoder anytime there is raw
573 * encoded data ready to write. It may include metadata mixed with encoded
574 * audio frames and the data is not guaranteed to be aligned on frame or
575 * metadata block boundaries.
578 * The callback is mandatory and must be set before initialization.
581 * \param encoder An encoder instance to set.
582 * \param value See above.
584 * \code encoder != NULL \endcode
585 * \code value != NULL \endcode
587 * \c false if the encoder is already initialized, else \c true.
589 FLAC__bool FLAC__stream_encoder_set_write_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteStatus (*value)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data));
591 /** Set the metadata callback.
592 * The supplied function will be called once at the end of encoding with
593 * the populated STREAMINFO structure. This is so file encoders can seek
594 * back to the beginning of the file and write the STREAMINFO block with
595 * the correct statistics after encoding (like minimum/maximum frame size
596 * and total samples).
599 * The callback is mandatory and must be set before initialization.
602 * \param encoder An encoder instance to set.
603 * \param value See above.
605 * \code encoder != NULL \endcode
606 * \code value != NULL \endcode
608 * \c false if the encoder is already initialized, else \c true.
610 FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data));
612 /** Set the client data to be passed back to callbacks.
613 * This value will be supplied to callbacks in their \a client_data
617 * \param encoder An encoder instance to set.
618 * \param value See above.
620 * \code encoder != NULL \endcode
622 * \c false if the encoder is already initialized, else \c true.
624 FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
626 /** Get the current encoder state.
628 * \param encoder An encoder instance to query.
630 * \code encoder != NULL \endcode
631 * \retval FLAC__StreamEncoderState
632 * The current encoder state.
634 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
636 /** Get the "streamable subset" flag.
638 * \param encoder An encoder instance to query.
640 * \code encoder != NULL \endcode
642 * See FLAC__stream_encoder_set_streamable_subset().
644 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
646 /** Get the "mid/side stereo coding" flag.
648 * \param encoder An encoder instance to query.
650 * \code encoder != NULL \endcode
652 * See FLAC__stream_encoder_get_do_mid_side_stereo().
654 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
656 /** Get the "adaptive mid/side switching" flag.
658 * \param encoder An encoder instance to query.
660 * \code encoder != NULL \endcode
662 * See FLAC__stream_encoder_set_loose_mid_side_stereo().
664 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
666 /** Get the number of input channels being processed.
668 * \param encoder An encoder instance to query.
670 * \code encoder != NULL \endcode
672 * See FLAC__stream_encoder_set_channels().
674 unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
676 /** Get the input sample resolution setting.
678 * \param encoder An encoder instance to query.
680 * \code encoder != NULL \endcode
682 * See FLAC__stream_encoder_set_bits_per_sample().
684 unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
686 /** Get the input sample rate setting.
688 * \param encoder An encoder instance to query.
690 * \code encoder != NULL \endcode
692 * See FLAC__stream_encoder_set_sample_rate().
694 unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
696 /** Get the blocksize setting.
698 * \param encoder An encoder instance to query.
700 * \code encoder != NULL \endcode
702 * See FLAC__stream_encoder_set_blocksize().
704 unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
706 /** Get the maximum LPC order setting.
708 * \param encoder An encoder instance to query.
710 * \code encoder != NULL \endcode
712 * See FLAC__stream_encoder_set_max_lpc_order().
714 unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
716 /** Get the quantized linear predictor coefficient precision setting.
718 * \param encoder An encoder instance to query.
720 * \code encoder != NULL \endcode
722 * See FLAC__stream_encoder_set_qlp_coeff_precision().
724 unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
726 /** Get the qlp coefficient precision search flag.
728 * \param encoder An encoder instance to query.
730 * \code encoder != NULL \endcode
732 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
734 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
736 /** Get the "escape coding" flag.
738 * \param encoder An encoder instance to query.
740 * \code encoder != NULL \endcode
742 * See FLAC__stream_encoder_set_do_escape_coding().
744 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
746 /** Get the exhaustive model search flag.
748 * \param encoder An encoder instance to query.
750 * \code encoder != NULL \endcode
752 * See FLAC__stream_encoder_set_do_exhaustive_model_search().
754 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
756 /** Get the minimum residual partition order setting.
758 * \param encoder An encoder instance to query.
760 * \code encoder != NULL \endcode
762 * See FLAC__stream_encoder_set_min_residual_partition_order().
764 unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
766 /** Get maximum residual partition order setting.
768 * \param encoder An encoder instance to query.
770 * \code encoder != NULL \endcode
772 * See FLAC__stream_encoder_set_max_residual_partition_order().
774 unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
776 /** Get the Rice parameter search distance setting.
778 * \param encoder An encoder instance to query.
780 * \code encoder != NULL \endcode
782 * See FLAC__stream_encoder_set_rice_parameter_search_dist().
784 unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
786 /** Initialize the encoder instance.
787 * Should be called after FLAC__stream_encoder_new() and
788 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
789 * or FLAC__stream_encoder_process_interleaved(). Will set and return
790 * the encoder state, which will be FLAC__STREAM_ENCODER_OK if
791 * initialization succeeded.
793 * The call to FLAC__stream_encoder_init() currently will also immediately
794 * call the write callback with the \c fLaC signature and all the encoded
797 * \param encoder An uninitialized encoder instance.
799 * \code encoder != NULL \endcode
800 * \retval FLAC__StreamEncoderState
801 * \c FLAC__STREAM_ENCODER_OK if initialization was successful; see
802 * FLAC__StreamEncoderState for the meanings of other return values.
804 FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
806 /** Finish the encoding process.
807 * Flushes the encoding buffer, releases resources, resets the encoder
808 * settings to their defaults, and returns the encoder state to
809 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
810 * one or more write callbacks before returning, and will generate
811 * a metadata callback.
813 * In the event of a prematurely-terminated encode, it is not strictly
814 * necessary to call this immediately before FLAC__stream_encoder_delete()
815 * but it is good practice to match every FLAC__stream_encoder_init()
816 * with a FLAC__stream_encoder_finish().
818 * \param encoder An uninitialized encoder instance.
820 * \code encoder != NULL \endcode
822 void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
824 /** Submit data for encoding.
825 * This version allows you to supply the input data via an array of
826 * pointers, each pointer pointing to an array of \a samples samples
827 * representing one channel. The samples need not be block-aligned,
828 * but each channel should have the same number of samples.
830 * \param encoder An initialized encoder instance in the OK state.
831 * \param buffer An array of pointers to each channel's signal.
832 * \param samples The number of samples in one channel.
834 * \code encoder != NULL \endcode
835 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
837 * \c true if successful, else \c false; in this case, check the
838 * encoder state with FLAC__stream_encoder_get_state() to see what
841 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
843 /** Submit data for encoding.
844 * This version allows you to supply the input data where the channels
845 * are interleaved into a single array (i.e. channel0_sample0,
846 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
847 * The samples need not be block-aligned but they must be
848 * sample-aligned, i.e. the first value should be channel0_sample0
849 * and the last value channelN_sampleM.
852 * \param encoder An initialized encoder instance in the OK state.
853 * \param buffer An array of channel-interleaved data (see above).
854 * \param samples The number of samples in one channel, the same as for
855 * FLAC__stream_encoder_process(). For example, if
856 * encoding two channels, \c 1000 \a samples corresponds
857 * to a \a buffer of 2000 values.
859 * \code encoder != NULL \endcode
860 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
862 * \c true if successful, else \c false; in this case, check the
863 * encoder state with FLAC__stream_encoder_get_state() to see what
866 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);