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 two encoder layers provided by libFLAC.
46 * For encoding FLAC streams, libFLAC provides two layers of access. The
47 * lowest layer is stream-level encoding, and the highest is file-level
48 * encoding. The interfaces are described in the \link flac_stream_encoder
49 * stream encoder \endlink and \link flac_file_encoder file encoder \endlink
50 * modules respectively. Typically you will choose the highest layer that
51 * your output source will support.
53 * The stream encoder relies on callbacks for writing the data and
54 * metadata. The file encoder provides these callbacks internally and you
55 * need only supply the filename.
58 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
59 * \ingroup flac_encoder
62 * This module contains the functions which implement the stream
65 * The basic usage of this encoder is as follows:
66 * - The program creates an instance of an encoder using
67 * FLAC__stream_encoder_new().
68 * - The program overrides the default settings and sets callbacks for
69 * writing and metadata reporting using
70 * FLAC__stream_encoder_set_*() functions.
71 * - The program initializes the instance to validate the settings and
72 * prepare for encoding using FLAC__stream_encoder_init().
73 * - The program calls FLAC__stream_encoder_process() or
74 * FLAC__stream_encoder_process_interleaved() to encode data, which
75 * subsequently calls the callbacks when there is encoder data ready
77 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
78 * which causes the encoder to encode any data still in its input pipe,
79 * call the metadata callback with the final encoding statistics, and
80 * finally reset the encoder to the uninitialized state.
81 * - The instance may be used again or deleted with
82 * FLAC__stream_encoder_delete().
84 * In more detail, the stream encoder functions similarly to the
85 * \link flac_stream_decoder stream decoder \endlink, but has fewer
86 * callbacks and more options. Typically the user will create a new
87 * instance by calling FLAC__stream_encoder_new(), then set the necessary
88 * parameters and callbacks with FLAC__stream_encoder_set_*(), and
89 * initialize it by calling FLAC__stream_encoder_init().
91 * Unlike the decoders, the stream encoder has many options that can
92 * affect the speed and compression ratio. When setting these parameters
93 * you should have some basic knowledge of the format (see the
94 * <A HREF="../documentation.html#format">user-level documentation</A>
95 * or the <A HREF="../format.html">formal description</A>). The
96 * FLAC__stream_encoder_set_*() functions themselves do not validate the
97 * values as many are interdependent. The FLAC__stream_encoder_init()
98 * function will do this, so make sure to pay attention to the state
99 * returned by FLAC__stream_encoder_init() to make sure that it is
100 * FLAC__STREAM_ENCODER_OK. Any parameters that are not set before
101 * FLAC__stream_encoder_init() will take on the defaults from the
104 * The user must provide function pointers for the following callbacks:
106 * - Write callback - This function is called by the encoder anytime there
107 * is raw encoded data to write. It may include metadata mixed with
108 * encoded audio frames and the data is not guaranteed to be aligned on
109 * frame or metadata block boundaries.
110 * - Metadata callback - This function is called once at the end of
111 * encoding with the populated STREAMINFO structure. This is so file
112 * encoders can seek back to the beginning of the file and write the
113 * STREAMINFO block with the correct statistics after encoding (like
114 * minimum/maximum frame size).
116 * The call to FLAC__stream_encoder_init() currently will also immediately
117 * call the write callback several times, once with the \c fLaC signature,
118 * and once for each encoded metadata block.
120 * After initializing the instance, the user may feed audio data to the
121 * encoder in one of two ways:
123 * - Channel separate, through FLAC__stream_encoder_process() - The user
124 * will pass an array of pointers to buffers, one for each channel, to
125 * the encoder, each of the same length. The samples need not be
127 * - Channel interleaved, through
128 * FLAC__stream_encoder_process_interleaved() - The user will pass a single
129 * pointer to data that is channel-interleaved (i.e. channel0_sample0,
130 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
131 * Again, the samples need not be block-aligned but they must be
132 * sample-aligned, i.e. the first value should be channel0_sample0 and
133 * the last value channelN_sampleM.
135 * When the user is finished encoding data, it calls
136 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
137 * data still in its input pipe, and call the metadata callback with the
138 * final encoding statistics. Then the instance may be deleted with
139 * FLAC__stream_encoder_delete() or initialized again to encode another
142 * For programs that write their own metadata, but that do not know the
143 * actual metadata until after encoding, it is advantageous to instruct
144 * the encoder to write a PADDING block of the correct size, so that
145 * instead of rewriting the whole stream after encoding, the program can
146 * just overwrite the PADDING block. If only the maximum size of the
147 * metadata is known, the program can write a slightly larger padding
148 * block, then split it after encoding.
150 * Make sure you understand how lengths are calculated. All FLAC metadata
151 * blocks have a 4 byte header which contains the type and length. This
152 * length does not include the 4 bytes of the header. See the format page
153 * for the specification of metadata blocks and their lengths.
156 * The "set" functions may only be called when the encoder is in the
157 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
158 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
159 * before FLAC__stream_encoder_init(). If this is the case they will
160 * return \c true, otherwise \c false.
163 * FLAC__stream_encoder_finish() resets all settings to the constructor
164 * defaults, including the callbacks.
170 /** State values for a FLAC__StreamEncoder
172 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
176 FLAC__STREAM_ENCODER_OK = 0,
177 /**< The encoder is in the normal OK state. */
179 FLAC__STREAM_ENCODER_INVALID_CALLBACK,
180 /**< The encoder was initialized before setting all the required callbacks. */
182 FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
183 /**< The encoder has an invalid setting for number of channels. */
185 FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
186 /**< The encoder has an invalid setting for bits-per-sample.
187 * FLAC supports 4-32 bps but the reference encoder currently supports
191 FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
192 /**< The encoder has an invalid setting for the input sample rate. */
194 FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
195 /**< The encoder has an invalid setting for the block size. */
197 FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
198 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
200 FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
201 /**< Mid/side coding was specified but the number of channels is not equal to 2. */
203 FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
206 FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
207 /**< Loose mid/side coding was specified but mid/side coding was not. */
209 FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
210 /**< The specified block size is less than the maximum LPC order. */
212 FLAC__STREAM_ENCODER_NOT_STREAMABLE,
213 /**< The encoder is bound to the "streamable subset" but other settings violate it. */
215 FLAC__STREAM_ENCODER_FRAMING_ERROR,
216 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
218 FLAC__STREAM_ENCODER_INVALID_METADATA,
219 /**< The metadata input to the encoder is invalid. */
221 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
222 /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
224 FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING,
225 /**< The write_callback returned an error. */
227 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
228 /**< Memory allocation failed. */
230 FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
231 /**< FLAC__stream_encoder_init() was called when the encoder was
232 * already initialized, usually because
233 * FLAC__stream_encoder_finish() was not called.
236 FLAC__STREAM_ENCODER_UNINITIALIZED
237 /**< The encoder is in the uninitialized state. */
239 } FLAC__StreamEncoderState;
241 /** Maps a FLAC__StreamEncoderState to a C string.
243 * Using a FLAC__StreamEncoderState as the index to this array
244 * will give the string equivalent. The contents should not be modified.
246 extern const char * const FLAC__StreamEncoderStateString[];
248 /** Return values for the FLAC__StreamEncoder write callback.
252 FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
253 /**< The write was OK and encoding can continue. */
255 FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
256 /**< An unrecoverable error occurred. The encoder will return from the process call. */
258 } FLAC__StreamEncoderWriteStatus;
260 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
262 * Using a FLAC__StreamEncoderWriteStatus as the index to this array
263 * will give the string equivalent. The contents should not be modified.
265 extern const char * const FLAC__StreamEncoderWriteStatusString[];
268 /***********************************************************************
270 * class FLAC__StreamEncoder
272 ***********************************************************************/
274 struct FLAC__StreamEncoderProtected;
275 struct FLAC__StreamEncoderPrivate;
276 /** The opaque structure definition for the stream encoder type.
277 * See the \link flac_stream_encoder stream encoder module \endlink
278 * for a detailed description.
281 struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
282 struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
283 } FLAC__StreamEncoder;
286 /***********************************************************************
288 * Class constructor/destructor
290 ***********************************************************************/
292 /** Create a new stream encoder instance. The instance is created with
293 * default settings; see the individual FLAC__stream_encoder_set_*()
294 * functions for each setting's default.
296 * \retval FLAC__StreamEncoder*
297 * \c NULL if there was an error allocating memory, else the new instance.
299 FLAC__StreamEncoder *FLAC__stream_encoder_new();
301 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
303 * \param encoder A pointer to an existing encoder.
305 * \code encoder != NULL \endcode
307 void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
309 /***********************************************************************
311 * Public class method prototypes
313 ***********************************************************************/
315 /** Set the "streamable subset" flag. If \c true, the encoder will comply
316 * with the subset (see the format specification) and will check the
317 * settings during FLAC__stream_encoder_init() to see if all settings
318 * comply. If \c false, the settings may take advantage of the full
319 * range that the format allows.
321 * Make sure you know what it entails before setting this to \c false.
324 * \param encoder An encoder instance to set.
325 * \param value Flag value (see above).
327 * \code encoder != NULL \endcode
329 * \c false if the encoder is already initialized, else \c true.
331 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
333 /** Set to \c true to enable mid-side encoding on stereo input. The
334 * number of channels must be 2. Set to \c false to use only
335 * independent channel coding.
338 * \param encoder An encoder instance to set.
339 * \param value Flag value (see above).
341 * \code encoder != NULL \endcode
343 * \c false if the encoder is already initialized, else \c true.
345 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
347 /** Set to \c true to enable adaptive switching between mid-side and
348 * left-right encoding on stereo input. The number of channels must
349 * be 2. Set to \c false to use exhaustive searching. In either
350 * case, the mid/side stereo setting must be \c true.
353 * \param encoder An encoder instance to set.
354 * \param value Flag value (see above).
356 * \code encoder != NULL \endcode
358 * \c false if the encoder is already initialized, else \c true.
360 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
362 /** Set the number of channels to be encoded.
365 * \param encoder An encoder instance to set.
366 * \param value See above.
368 * \code encoder != NULL \endcode
370 * \c false if the encoder is already initialized, else \c true.
372 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
374 /** Set the sample resolution of the input to be encoded.
377 * Do not feed the encoder data that is wider than the value you
378 * set here or you will generate an invalid stream.
381 * \param encoder An encoder instance to set.
382 * \param value See above.
384 * \code encoder != NULL \endcode
386 * \c false if the encoder is already initialized, else \c true.
388 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
390 /** Set the sample rate (in Hz) of the input to be encoded.
393 * \param encoder An encoder instance to set.
394 * \param value See above.
396 * \code encoder != NULL \endcode
398 * \c false if the encoder is already initialized, else \c true.
400 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
402 /** Set the blocksize to use while encoding.
405 * \param encoder An encoder instance to set.
406 * \param value See above.
408 * \code encoder != NULL \endcode
410 * \c false if the encoder is already initialized, else \c true.
412 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
414 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
417 * \param encoder An encoder instance to set.
418 * \param value See above.
420 * \code encoder != NULL \endcode
422 * \c false if the encoder is already initialized, else \c true.
424 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
426 /** Set the precision, in bits, of the quantized linear predictor
427 * coefficients, or \c 0 to let the encoder select it based on the
431 * In the current implementation, qlp_coeff_precision + bits_per_sample must
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_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
444 /** Set to \c false to use only the specified quantized linear predictor
445 * coefficient precision, or \c true to search neighboring precision
446 * values and use the best one.
449 * \param encoder An encoder instance to set.
450 * \param value See above.
452 * \code encoder != NULL \endcode
454 * \c false if the encoder is already initialized, else \c true.
456 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
458 /** Deprecated. Setting this value has no effect.
461 * \param encoder An encoder instance to set.
462 * \param value See above.
464 * \code encoder != NULL \endcode
466 * \c false if the encoder is already initialized, else \c true.
468 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
470 /** Set to \c false to let the encoder estimate the best model order
471 * based on the residual signal energy, or \c true to force the
472 * encoder to evaluate all order models and select the best.
475 * \param encoder An encoder instance to set.
476 * \param value See above.
478 * \code encoder != NULL \endcode
480 * \c false if the encoder is already initialized, else \c true.
482 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
484 /** Set the minimum partition order to search when coding the residual.
485 * This is used in tandem with
486 * FLAC__stream_encoder_set_max_residual_partition_order().
488 * The partition order determines the context size in the residual.
489 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
491 * Set both min and max values to \c 0 to force a single context,
492 * whose Rice parameter is based on the residual signal variance.
493 * Otherwise, set a min and max order, and the encoder will search
494 * all orders, using the mean of each context for its Rice parameter,
498 * \param encoder An encoder instance to set.
499 * \param value See above.
501 * \code encoder != NULL \endcode
503 * \c false if the encoder is already initialized, else \c true.
505 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
507 /** Set the minimum partition order to search when coding the residual.
508 * This is used in tandem with
509 * FLAC__stream_encoder_set_min_residual_partition_order().
511 * The partition order determines the context size in the residual.
512 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
514 * Set both min and max values to \c 0 to force a single context,
515 * whose Rice parameter is based on the residual signal variance.
516 * Otherwise, set a min and max order, and the encoder will search
517 * all orders, using the mean of each context for its Rice parameter,
521 * \param encoder An encoder instance to set.
522 * \param value See above.
524 * \code encoder != NULL \endcode
526 * \c false if the encoder is already initialized, else \c true.
528 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
530 /** Deprecated. Setting this value has no effect.
533 * \param encoder An encoder instance to set.
534 * \param value See above.
536 * \code encoder != NULL \endcode
538 * \c false if the encoder is already initialized, else \c true.
540 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
542 /** Set an estimate of the total samples that will be encoded.
543 * This is merely an estimate and may be set to \c 0 if unknown.
544 * This value will be written to the STREAMINFO block before encoding,
545 * and can remove the need for the caller to rewrite the value later
546 * if the value is known before encoding.
549 * \param encoder An encoder instance to set.
550 * \param value See above.
552 * \code encoder != NULL \endcode
554 * \c false if the encoder is already initialized, else \c true.
556 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
558 /** Set the metadata blocks to be emitted to the stream before encoding.
559 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
560 * array of pointers to metadata blocks. The array is non-const since
561 * the encoder may need to change the \a is_last flag inside them.
562 * Otherwise, the encoder will not modify or free the blocks. It is up
563 * to the caller to free the metadata blocks after encoding.
565 * The STREAMINFO block is always written and no STREAMINFO block may
566 * occur in the supplied array.
568 * \default \c NULL, 0
569 * \param encoder An encoder instance to set.
570 * \param metadata See above.
571 * \param num_blocks See above.
573 * \code encoder != NULL \endcode
575 * \c false if the encoder is already initialized, else \c true.
577 FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
579 /** Set the write callback.
580 * The supplied function will be called by the encoder anytime there is raw
581 * encoded data ready to write. It may include metadata mixed with encoded
582 * audio frames and the data is not guaranteed to be aligned on frame or
583 * metadata block boundaries.
585 * The only duty of the callback is to write out the \a bytes worth of data
586 * in \a buffer to the current position in the output stream. The arguments
587 * \a samples and \a current_frame are purely informational. If \a samples
588 * is greater than \c 0, then \a current_frame will hold the current frame
589 * number that is being written; otherwise, the write callback is being called
593 * The callback is mandatory and must be set before initialization.
596 * \param encoder An encoder instance to set.
597 * \param value See above.
599 * \code encoder != NULL \endcode
600 * \code value != NULL \endcode
602 * \c false if the encoder is already initialized, else \c true.
604 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));
606 /** Set the metadata callback.
607 * The supplied function will be called once at the end of encoding with
608 * the populated STREAMINFO structure. This is so file encoders can seek
609 * back to the beginning of the file and write the STREAMINFO block with
610 * the correct statistics after encoding (like minimum/maximum frame size
611 * and total samples).
614 * The callback is mandatory and must be set before initialization.
617 * \param encoder An encoder instance to set.
618 * \param value See above.
620 * \code encoder != NULL \endcode
621 * \code value != NULL \endcode
623 * \c false if the encoder is already initialized, else \c true.
625 FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, void (*value)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data));
627 /** Set the client data to be passed back to callbacks.
628 * This value will be supplied to callbacks in their \a client_data
632 * \param encoder An encoder instance to set.
633 * \param value See above.
635 * \code encoder != NULL \endcode
637 * \c false if the encoder is already initialized, else \c true.
639 FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
641 /** Get the current encoder state.
643 * \param encoder An encoder instance to query.
645 * \code encoder != NULL \endcode
646 * \retval FLAC__StreamEncoderState
647 * The current encoder state.
649 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
651 /** Get the "streamable subset" flag.
653 * \param encoder An encoder instance to query.
655 * \code encoder != NULL \endcode
657 * See FLAC__stream_encoder_set_streamable_subset().
659 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
661 /** Get the "mid/side stereo coding" flag.
663 * \param encoder An encoder instance to query.
665 * \code encoder != NULL \endcode
667 * See FLAC__stream_encoder_get_do_mid_side_stereo().
669 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
671 /** Get the "adaptive mid/side switching" flag.
673 * \param encoder An encoder instance to query.
675 * \code encoder != NULL \endcode
677 * See FLAC__stream_encoder_set_loose_mid_side_stereo().
679 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
681 /** Get the number of input channels being processed.
683 * \param encoder An encoder instance to query.
685 * \code encoder != NULL \endcode
687 * See FLAC__stream_encoder_set_channels().
689 unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
691 /** Get the input sample resolution setting.
693 * \param encoder An encoder instance to query.
695 * \code encoder != NULL \endcode
697 * See FLAC__stream_encoder_set_bits_per_sample().
699 unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
701 /** Get the input sample rate setting.
703 * \param encoder An encoder instance to query.
705 * \code encoder != NULL \endcode
707 * See FLAC__stream_encoder_set_sample_rate().
709 unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
711 /** Get the blocksize setting.
713 * \param encoder An encoder instance to query.
715 * \code encoder != NULL \endcode
717 * See FLAC__stream_encoder_set_blocksize().
719 unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
721 /** Get the maximum LPC order setting.
723 * \param encoder An encoder instance to query.
725 * \code encoder != NULL \endcode
727 * See FLAC__stream_encoder_set_max_lpc_order().
729 unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
731 /** Get the quantized linear predictor coefficient precision setting.
733 * \param encoder An encoder instance to query.
735 * \code encoder != NULL \endcode
737 * See FLAC__stream_encoder_set_qlp_coeff_precision().
739 unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
741 /** Get the qlp coefficient precision search flag.
743 * \param encoder An encoder instance to query.
745 * \code encoder != NULL \endcode
747 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
749 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
751 /** Get the "escape coding" flag.
753 * \param encoder An encoder instance to query.
755 * \code encoder != NULL \endcode
757 * See FLAC__stream_encoder_set_do_escape_coding().
759 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
761 /** Get the exhaustive model search flag.
763 * \param encoder An encoder instance to query.
765 * \code encoder != NULL \endcode
767 * See FLAC__stream_encoder_set_do_exhaustive_model_search().
769 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
771 /** Get the minimum residual partition order setting.
773 * \param encoder An encoder instance to query.
775 * \code encoder != NULL \endcode
777 * See FLAC__stream_encoder_set_min_residual_partition_order().
779 unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
781 /** Get maximum residual partition order setting.
783 * \param encoder An encoder instance to query.
785 * \code encoder != NULL \endcode
787 * See FLAC__stream_encoder_set_max_residual_partition_order().
789 unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
791 /** Get the Rice parameter search distance setting.
793 * \param encoder An encoder instance to query.
795 * \code encoder != NULL \endcode
797 * See FLAC__stream_encoder_set_rice_parameter_search_dist().
799 unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
801 /** Initialize the encoder instance.
802 * Should be called after FLAC__stream_encoder_new() and
803 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
804 * or FLAC__stream_encoder_process_interleaved(). Will set and return
805 * the encoder state, which will be FLAC__STREAM_ENCODER_OK if
806 * initialization succeeded.
808 * The call to FLAC__stream_encoder_init() currently will also immediately
809 * call the write callback several times, once with the \c fLaC signature,
810 * and once for each encoded metadata block.
812 * \param encoder An uninitialized encoder instance.
814 * \code encoder != NULL \endcode
815 * \retval FLAC__StreamEncoderState
816 * \c FLAC__STREAM_ENCODER_OK if initialization was successful; see
817 * FLAC__StreamEncoderState for the meanings of other return values.
819 FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
821 /** Finish the encoding process.
822 * Flushes the encoding buffer, releases resources, resets the encoder
823 * settings to their defaults, and returns the encoder state to
824 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
825 * one or more write callbacks before returning, and will generate
826 * a metadata callback.
828 * In the event of a prematurely-terminated encode, it is not strictly
829 * necessary to call this immediately before FLAC__stream_encoder_delete()
830 * but it is good practice to match every FLAC__stream_encoder_init()
831 * with a FLAC__stream_encoder_finish().
833 * \param encoder An uninitialized encoder instance.
835 * \code encoder != NULL \endcode
837 void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
839 /** Submit data for encoding.
840 * This version allows you to supply the input data via an array of
841 * pointers, each pointer pointing to an array of \a samples samples
842 * representing one channel. The samples need not be block-aligned,
843 * but each channel should have the same number of samples.
845 * \param encoder An initialized encoder instance in the OK state.
846 * \param buffer An array of pointers to each channel's signal.
847 * \param samples The number of samples in one channel.
849 * \code encoder != NULL \endcode
850 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
852 * \c true if successful, else \c false; in this case, check the
853 * encoder state with FLAC__stream_encoder_get_state() to see what
856 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
858 /** Submit data for encoding.
859 * This version allows you to supply the input data where the channels
860 * are interleaved into a single array (i.e. channel0_sample0,
861 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
862 * The samples need not be block-aligned but they must be
863 * sample-aligned, i.e. the first value should be channel0_sample0
864 * and the last value channelN_sampleM.
866 * \param encoder An initialized encoder instance in the OK state.
867 * \param buffer An array of channel-interleaved data (see above).
868 * \param samples The number of samples in one channel, the same as for
869 * FLAC__stream_encoder_process(). For example, if
870 * encoding two channels, \c 1000 \a samples corresponds
871 * to a \a buffer of 2000 values.
873 * \code encoder != NULL \endcode
874 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
876 * \c true if successful, else \c false; in this case, check the
877 * encoder state with FLAC__stream_encoder_get_state() to see what
880 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);