1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef FLAC__STREAM_ENCODER_H
33 #define FLAC__STREAM_ENCODER_H
35 #include <stdio.h> /* for FILE */
38 #include "stream_decoder.h"
45 /** \file include/FLAC/stream_encoder.h
48 * This module contains the functions which implement the stream
51 * See the detailed documentation in the
52 * \link flac_stream_encoder stream encoder \endlink module.
55 /** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
59 * This module describes the two encoder layers provided by libFLAC.
61 * libFLAC provides two ways of encoding FLAC streams. There is a @@@@@@frame encoder which encodes single frames at a time, and a stream encoder which encodes whole streams.
63 * @@@@@@TODO frame encoder
65 * The stream encoder can be used encode complete streams either to the
66 * client via callbacks, or directly to a file, depending on how it is
67 * initialized. When encoding via callbacks, the client provides a write
68 * callback which will be called whenever FLAC data is ready to be written.
69 * If the client also supplies a seek callback, the encoder will also
70 * automatically handle the writing back of metadata discovered while
71 * encoding, like stream info, seek points offsets, etc. When encoding to
72 * a file, the client needs only supply a filename or open \c FILE* and an
73 * optional progress callback for periodic notification of progress; the
74 * write and seek callbacks are supplied internally. For more info see the
75 * \link flac_stream_encoder stream encoder \endlink module.
78 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
79 * \ingroup flac_encoder
82 * This module contains the functions which implement the stream
85 * The basic usage of this encoder is as follows:
86 * - The program creates an instance of an encoder using
87 * FLAC__stream_encoder_new().
88 * - The program overrides the default settings using
89 * FLAC__stream_encoder_set_*() functions.
90 * - The program initializes the instance to validate the settings and
91 * prepare for encoding using FLAC__stream_encoder_init_stream() or
92 * FLAC__stream_encoder_init_FILE() or FLAC__stream_encoder_init_file(),
93 * depending on the nature of the output.
94 * - The program calls FLAC__stream_encoder_process() or
95 * FLAC__stream_encoder_process_interleaved() to encode data, which
96 * subsequently calls the callbacks when there is encoder data ready
98 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
99 * which causes the encoder to encode any data still in its input pipe,
100 * update the metadata with the final encoding statistics if output
101 * seeking is possible, and finally reset the encoder to the
102 * uninitialized state.
103 * - The instance may be used again or deleted with
104 * FLAC__stream_encoder_delete().
106 * In more detail, the stream encoder functions similarly to the
107 * \link flac_stream_decoder stream decoder \endlink, but has fewer
108 * callbacks and more options. Typically the user will create a new
109 * instance by calling FLAC__stream_encoder_new(), then set the necessary
110 * parameters with FLAC__stream_encoder_set_*(), and initialize it by
111 * calling FLAC__stream_encoder_init_stream() or
112 * FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE().
114 * Unlike the decoders, the stream encoder has many options that can
115 * affect the speed and compression ratio. When setting these parameters
116 * you should have some basic knowledge of the format (see the
117 * <A HREF="../documentation.html#format">user-level documentation</A>
118 * or the <A HREF="../format.html">formal description</A>). The
119 * FLAC__stream_encoder_set_*() functions themselves do not validate the
120 * values as many are interdependent. The FLAC__stream_encoder_init_*()
121 * functions will do this, so make sure to pay attention to the state
122 * returned by FLAC__stream_encoder_init_*() to make sure that it is
123 * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set
124 * before FLAC__stream_encoder_init_*() will take on the defaults from
127 * There are three initialization functions, one for setting up the encoder
128 * to encode FLAC data to the client via callbacks, and two for encoding
129 * directly to a file.
131 * For encoding via callbacks, use FLAC__stream_encoder_init_stream().
132 * You must also supply a write callback which will be called anytime
133 * there is raw encoded data to write. If the client can seek the output
134 * it is best to also supply seek and tell callbacks, as this allows the
135 * encoder to go back after encoding is finished to write back
136 * information that was collected while encoding, like seek point offsets,
139 * For encoding directly to a file, use FLAC__stream_encoder_init_FILE()
140 * or FLAC__stream_encoder_init_file(). Then you must only supply a
141 * filename or open \c FILE*; the encoder will handle all the callbacks
142 * internally. You may also supply a progress callback for periodic
143 * notification of the encoding progress.
145 * The call to FLAC__stream_encoder_init_*() currently will also immediately
146 * call the write callback several times, once with the \c fLaC signature,
147 * and once for each encoded metadata block.
149 * After initializing the instance, the user may feed audio data to the
150 * encoder in one of two ways:
152 * - Channel separate, through FLAC__stream_encoder_process() - The user
153 * will pass an array of pointers to buffers, one for each channel, to
154 * the encoder, each of the same length. The samples need not be
156 * - Channel interleaved, through
157 * FLAC__stream_encoder_process_interleaved() - The user will pass a single
158 * pointer to data that is channel-interleaved (i.e. channel0_sample0,
159 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
160 * Again, the samples need not be block-aligned but they must be
161 * sample-aligned, i.e. the first value should be channel0_sample0 and
162 * the last value channelN_sampleM.
164 * When the user is finished encoding data, it calls
165 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
166 * data still in its input pipe, and call the metadata callback with the
167 * final encoding statistics. Then the instance may be deleted with
168 * FLAC__stream_encoder_delete() or initialized again to encode another
171 * For programs that write their own metadata, but that do not know the
172 * actual metadata until after encoding, it is advantageous to instruct
173 * the encoder to write a PADDING block of the correct size, so that
174 * instead of rewriting the whole stream after encoding, the program can
175 * just overwrite the PADDING block. If only the maximum size of the
176 * metadata is known, the program can write a slightly larger padding
177 * block, then split it after encoding.
179 * Make sure you understand how lengths are calculated. All FLAC metadata
180 * blocks have a 4 byte header which contains the type and length. This
181 * length does not include the 4 bytes of the header. See the format page
182 * for the specification of metadata blocks and their lengths.
185 * If you are writing the FLAC data to a file via callbacks, make sure it
186 * is open for update (e.g. mode "w+" for stdio streams). This is because
187 * after the first encoding pass, the encoder will try to seek back to the
188 * beginning of the stream, to the STREAMINFO block, to write some data
189 * there. (If using FLAC__stream_encoder_init_file() or
190 * FLAC__stream_encoder_init_FILE(), the file is managed internally.)
193 * The "set" functions may only be called when the encoder is in the
194 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
195 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
196 * before FLAC__stream_encoder_init(). If this is the case they will
197 * return \c true, otherwise \c false.
200 * FLAC__stream_encoder_finish() resets all settings to the constructor
207 /** State values for a FLAC__StreamEncoder.
209 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
211 * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK
212 * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and
213 * must be deleted with FLAC__stream_encoder_delete().
217 FLAC__STREAM_ENCODER_OK = 0,
218 /**< The encoder is in the normal OK state and samples can be processed. */
220 FLAC__STREAM_ENCODER_UNINITIALIZED,
221 /**< The encoder is in the uninitialized state; one of the
222 * FLAC__stream_encoder_init_*() functions must be called before samples
226 FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
227 /**< An error occurred in the underlying verify stream decoder;
228 * check FLAC__stream_encoder_get_verify_decoder_state().
231 FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
232 /**< The verify decoder detected a mismatch between the original
233 * audio signal and the decoded audio signal.
236 FLAC__STREAM_ENCODER_CLIENT_ERROR,
237 /**< One of the callbacks returned a fatal error. */
239 FLAC__STREAM_ENCODER_IO_ERROR,
240 /**< An I/O error occurred while opening/reading/writing a file.
244 FLAC__STREAM_ENCODER_FRAMING_ERROR,
245 /**< An error occurred while writing the stream; usually, the
246 * write_callback returned an error.
249 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
250 /**< Memory allocation failed. */
252 } FLAC__StreamEncoderState;
254 /** Maps a FLAC__StreamEncoderState to a C string.
256 * Using a FLAC__StreamEncoderState as the index to this array
257 * will give the string equivalent. The contents should not be modified.
259 extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
261 /** Possible return values for the FLAC__stream_encoder_init_*() functions.
265 FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
266 /**< Initialization was successful. */
268 FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
269 /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */
271 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
272 /**< A required callback was not supplied. */
274 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
275 /**< The encoder has an invalid setting for number of channels. */
277 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
278 /**< The encoder has an invalid setting for bits-per-sample.
279 * FLAC supports 4-32 bps but the reference encoder currently supports
283 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
284 /**< The encoder has an invalid setting for the input sample rate. */
286 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
287 /**< The encoder has an invalid setting for the block size. */
289 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
290 /**< The encoder has an invalid setting for the maximum LPC order. */
292 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
293 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
295 FLAC__STREAM_ENCODER_INIT_STATUS_MID_SIDE_CHANNELS_MISMATCH,
296 /**< Mid/side coding was specified but the number of channels is not equal to 2. */
298 FLAC__STREAM_ENCODER_INIT_STATUS_ILLEGAL_MID_SIDE_FORCE,
299 /**< Loose mid/side coding was specified but mid/side coding was not. */
301 FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
302 /**< The specified block size is less than the maximum LPC order. */
304 FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
305 /**< The encoder is bound to the "streamable subset" but other settings violate it. */
307 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
308 /**< The metadata input to the encoder is invalid, in one of the following ways:
309 * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
310 * - One of the metadata blocks contains an undefined type
311 * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal()
312 * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal()
313 * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
316 FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
317 /**< FLAC__stream_encoder_init_*() was called when the encoder was
318 * already initialized, usually because
319 * FLAC__stream_encoder_finish() was not called.
322 } FLAC__StreamEncoderInitStatus;
324 /** Maps a FLAC__StreamEncoderInitStatus to a C string.
326 * Using a FLAC__StreamEncoderInitStatus as the index to this array
327 * will give the string equivalent. The contents should not be modified.
329 extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
331 /** Return values for the FLAC__StreamEncoder write callback.
335 FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
336 /**< The write was OK and encoding can continue. */
338 FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
339 /**< An unrecoverable error occurred. The encoder will return from the process call. */
341 } FLAC__StreamEncoderWriteStatus;
343 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
345 * Using a FLAC__StreamEncoderWriteStatus as the index to this array
346 * will give the string equivalent. The contents should not be modified.
348 extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
350 /** Return values for the FLAC__StreamEncoder seek callback.
354 FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
355 /**< The seek was OK and encoding can continue. */
357 FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
358 /**< An unrecoverable error occurred. */
360 FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
361 /**< Client does not support seeking. */
363 } FLAC__StreamEncoderSeekStatus;
365 /** Maps a FLAC__StreamEncoderSeekStatus to a C string.
367 * Using a FLAC__StreamEncoderSeekStatus as the index to this array
368 * will give the string equivalent. The contents should not be modified.
370 extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
373 /** Return values for the FLAC__StreamEncoder tell callback.
377 FLAC__STREAM_ENCODER_TELL_STATUS_OK,
378 /**< The tell was OK and encoding can continue. */
380 FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
381 /**< An unrecoverable error occurred. */
383 FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
384 /**< Client does not support seeking. */
386 } FLAC__StreamEncoderTellStatus;
388 /** Maps a FLAC__StreamEncoderTellStatus to a C string.
390 * Using a FLAC__StreamEncoderTellStatus as the index to this array
391 * will give the string equivalent. The contents should not be modified.
393 extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
396 /***********************************************************************
398 * class FLAC__StreamEncoder
400 ***********************************************************************/
402 struct FLAC__StreamEncoderProtected;
403 struct FLAC__StreamEncoderPrivate;
404 /** The opaque structure definition for the stream encoder type.
405 * See the \link flac_stream_encoder stream encoder module \endlink
406 * for a detailed description.
409 struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
410 struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
411 } FLAC__StreamEncoder;
413 /** Signature for the write callback.
415 * A function pointer matching this signature must be passed to
416 * FLAC__stream_encoder_init_stream(). The supplied function will be called
417 * by the encoder anytime there is raw encoded data ready to write. It may
418 * include metadata mixed with encoded audio frames and the data is not
419 * guaranteed to be aligned on frame or metadata block boundaries.
421 * The only duty of the callback is to write out the \a bytes worth of data
422 * in \a buffer to the current position in the output stream. The arguments
423 * \a samples and \a current_frame are purely informational. If \a samples
424 * is greater than \c 0, then \a current_frame will hold the current frame
425 * number that is being written; otherwise it indicates that the write
426 * callback is being called to write metadata.
428 * \note In general, FLAC__StreamEncoder functions which change the
429 * state should not be called on the \a encoder while in the callback.
431 * \param encoder The encoder instance calling the callback.
432 * \param buffer An array of encoded data of length \a bytes.
433 * \param bytes The byte length of \a buffer.
434 * \param samples The number of samples encoded by \a buffer.
435 * \c 0 has a special meaning; see above.
436 * \param current_frame The number of the current frame being encoded.
437 * \param client_data The callee's client data set through
438 * FLAC__stream_encoder_init_*().
439 * \retval FLAC__StreamEncoderWriteStatus
440 * The callee's return status.
442 typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
444 /** Signature for the seek callback.
446 * A function pointer matching this signature may be passed to
447 * FLAC__stream_encoder_init_stream(). The supplied function will be called
448 * when the encoder needs to seek the output stream. The encoder will pass
449 * the absolute byte offset to seek to, 0 meaning the beginning of the stream.
451 * \note In general, FLAC__StreamEncoder functions which change the
452 * state should not be called on the \a encoder while in the callback.
454 * \param encoder The encoder instance calling the callback.
455 * \param absolute_byte_offset The offset from the beginning of the stream
457 * \param client_data The callee's client data set through
458 * FLAC__stream_encoder_init_*().
459 * \retval FLAC__StreamEncoderSeekStatus
460 * The callee's return status.
462 typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
464 /** Signature for the tell callback.
466 * A function pointer matching this signature may be passed to
467 * FLAC__stream_encoder_init_stream(). The supplied function will be called
468 * when the encoder needs to know the current position of the output stream.
471 * The callback must return the true current byte offset of the output to
472 * which the encoder is writing. If you are buffering the output, make
473 * sure and take this into account. If you are writing directly to a
474 * FILE* from your write callback, ftell() is sufficient. If you are
475 * writing directly to a file descriptor from your write callback, you
476 * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to
477 * these points to rewrite metadata after encoding.
479 * \note In general, FLAC__StreamEncoder functions which change the
480 * state should not be called on the \a encoder while in the callback.
482 * \param encoder The encoder instance calling the callback.
483 * \param absolute_byte_offset The address at which to store the current
484 * position of the output.
485 * \param client_data The callee's client data set through
486 * FLAC__stream_encoder_init_*().
487 * \retval FLAC__StreamEncoderTellStatus
488 * The callee's return status.
490 typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
492 /** Signature for the metadata callback.
494 * A function pointer matching this signature may be passed to
495 * FLAC__stream_encoder_init_stream(). The supplied function will be called
496 * once at the end of encoding with the populated STREAMINFO structure. This
497 * is so the client can seek back to the beginning of the file and write the
498 * STREAMINFO block with the correct statistics after encoding (like
499 * minimum/maximum frame size and total samples).
501 * \note In general, FLAC__StreamEncoder functions which change the
502 * state should not be called on the \a encoder while in the callback.
504 * \param encoder The encoder instance calling the callback.
505 * \param metadata The final populated STREAMINFO block.
506 * \param client_data The callee's client data set through
507 * FLAC__stream_encoder_init_*().
509 typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
511 /** Signature for the progress callback.
513 * A function pointer matching this signature may be passed to
514 * FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE().
515 * The supplied function will be called when the encoder has finished
516 * writing a frame. The \c total_frames_estimate argument to the
517 * callback will be based on the value from
518 * FLAC__file_encoder_set_total_samples_estimate().
520 * \note In general, FLAC__StreamEncoder functions which change the
521 * state should not be called on the \a encoder while in the callback.
523 * \param encoder The encoder instance calling the callback.
524 * \param bytes_written Bytes written so far.
525 * \param samples_written Samples written so far.
526 * \param frames_written Frames written so far.
527 * \param total_frames_estimate The estimate of the total number of
528 * frames to be written.
529 * \param client_data The callee's client data set through
530 * FLAC__stream_encoder_init_*().
532 typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
535 /***********************************************************************
537 * Class constructor/destructor
539 ***********************************************************************/
541 /** Create a new stream encoder instance. The instance is created with
542 * default settings; see the individual FLAC__stream_encoder_set_*()
543 * functions for each setting's default.
545 * \retval FLAC__StreamEncoder*
546 * \c NULL if there was an error allocating memory, else the new instance.
548 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new();
550 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
552 * \param encoder A pointer to an existing encoder.
554 * \code encoder != NULL \endcode
556 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
559 /***********************************************************************
561 * Public class method prototypes
563 ***********************************************************************/
565 /** Set the "verify" flag. If \c true, the encoder will verify it's own
566 * encoded output by feeding it through an internal decoder and comparing
567 * the original signal against the decoded signal. If a mismatch occurs,
568 * the process call will return \c false. Note that this will slow the
569 * encoding process by the extra time required for decoding and comparison.
572 * \param encoder An encoder instance to set.
573 * \param value Flag value (see above).
575 * \code encoder != NULL \endcode
577 * \c false if the encoder is already initialized, else \c true.
579 FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
581 /** Set the "streamable subset" flag. If \c true, the encoder will comply
582 * with the subset (see the format specification) and will check the
583 * settings during FLAC__stream_encoder_init() to see if all settings
584 * comply. If \c false, the settings may take advantage of the full
585 * range that the format allows.
587 * Make sure you know what it entails before setting this to \c false.
590 * \param encoder An encoder instance to set.
591 * \param value Flag value (see above).
593 * \code encoder != NULL \endcode
595 * \c false if the encoder is already initialized, else \c true.
597 FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
599 /** Set to \c true to enable mid-side encoding on stereo input. The
600 * number of channels must be 2. Set to \c false to use only
601 * independent channel coding.
604 * \param encoder An encoder instance to set.
605 * \param value Flag value (see above).
607 * \code encoder != NULL \endcode
609 * \c false if the encoder is already initialized, else \c true.
611 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
613 /** Set to \c true to enable adaptive switching between mid-side and
614 * left-right encoding on stereo input. The number of channels must
615 * be 2. Set to \c false to use exhaustive searching. In either
616 * case, the mid/side stereo setting must be \c true.
619 * \param encoder An encoder instance to set.
620 * \param value Flag value (see above).
622 * \code encoder != NULL \endcode
624 * \c false if the encoder is already initialized, else \c true.
626 FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
628 /** Set the number of channels to be encoded.
631 * \param encoder An encoder instance to set.
632 * \param value See above.
634 * \code encoder != NULL \endcode
636 * \c false if the encoder is already initialized, else \c true.
638 FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
640 /** Set the sample resolution of the input to be encoded.
643 * Do not feed the encoder data that is wider than the value you
644 * set here or you will generate an invalid stream.
647 * \param encoder An encoder instance to set.
648 * \param value See above.
650 * \code encoder != NULL \endcode
652 * \c false if the encoder is already initialized, else \c true.
654 FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
656 /** Set the sample rate (in Hz) of the input to be encoded.
659 * \param encoder An encoder instance to set.
660 * \param value See above.
662 * \code encoder != NULL \endcode
664 * \c false if the encoder is already initialized, else \c true.
666 FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
668 /** Set the blocksize to use while encoding.
671 * \param encoder An encoder instance to set.
672 * \param value See above.
674 * \code encoder != NULL \endcode
676 * \c false if the encoder is already initialized, else \c true.
678 FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
680 /** Sets the apodization function(s) the encoder will use when windowing
681 * audio data for LPC analysis.
683 * The \a specification is a plain ASCII string which specifies exactly
684 * which functions to use. There may be more than one (up to 32),
685 * separated by \c ';' characters. Some functions take one or more
686 * comma-separated arguments in parentheses.
688 * The available functions are \c bartlett, \c bartlett_hann,
689 * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop,
690 * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall,
691 * \c rectangle, \c triangle, \c tukey(P), \c welch.
693 * For \c gauss(STDDEV), STDDEV specifies the standard deviation
696 * For \c tukey(P), P specifies the fraction of the window that is
697 * tapered (0<=P<=1). P=0 corresponds to \c rectangle and P=1
698 * corresponds to \c hann.
700 * Example specifications are \c "blackman" or
701 * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)"
703 * Any function that is specified erroneously is silently dropped. Up
704 * to 32 functions are kept, the rest are dropped. If the specification
705 * is empty the encoder defaults to \c "tukey(0.5)".
707 * When more than one function is specified, then for every subframe the
708 * encoder will try each of them separately and choose the window that
709 * results in the smallest compressed subframe.
711 * Note that each function specified causes the encoder to occupy a
712 * floating point array in which to store the window.
714 * \default \c "tukey(0.5)"
715 * \param encoder An encoder instance to set.
716 * \param specification See above.
718 * \code encoder != NULL \endcode
719 * \code specification != NULL \endcode
721 * \c false if the encoder is already initialized, else \c true.
723 /* @@@@add to unit tests*/
724 FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
726 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
729 * \param encoder An encoder instance to set.
730 * \param value See above.
732 * \code encoder != NULL \endcode
734 * \c false if the encoder is already initialized, else \c true.
736 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
738 /** Set the precision, in bits, of the quantized linear predictor
739 * coefficients, or \c 0 to let the encoder select it based on the
743 * In the current implementation, qlp_coeff_precision + bits_per_sample must
747 * \param encoder An encoder instance to set.
748 * \param value See above.
750 * \code encoder != NULL \endcode
752 * \c false if the encoder is already initialized, else \c true.
754 FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
756 /** Set to \c false to use only the specified quantized linear predictor
757 * coefficient precision, or \c true to search neighboring precision
758 * values and use the best one.
761 * \param encoder An encoder instance to set.
762 * \param value See above.
764 * \code encoder != NULL \endcode
766 * \c false if the encoder is already initialized, else \c true.
768 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
770 /** Deprecated. Setting this value has no effect.
773 * \param encoder An encoder instance to set.
774 * \param value See above.
776 * \code encoder != NULL \endcode
778 * \c false if the encoder is already initialized, else \c true.
780 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
782 /** Set to \c false to let the encoder estimate the best model order
783 * based on the residual signal energy, or \c true to force the
784 * encoder to evaluate all order models and select the best.
787 * \param encoder An encoder instance to set.
788 * \param value See above.
790 * \code encoder != NULL \endcode
792 * \c false if the encoder is already initialized, else \c true.
794 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
796 /** Set the minimum partition order to search when coding the residual.
797 * This is used in tandem with
798 * FLAC__stream_encoder_set_max_residual_partition_order().
800 * The partition order determines the context size in the residual.
801 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
803 * Set both min and max values to \c 0 to force a single context,
804 * whose Rice parameter is based on the residual signal variance.
805 * Otherwise, set a min and max order, and the encoder will search
806 * all orders, using the mean of each context for its Rice parameter,
810 * \param encoder An encoder instance to set.
811 * \param value See above.
813 * \code encoder != NULL \endcode
815 * \c false if the encoder is already initialized, else \c true.
817 FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
819 /** Set the maximum partition order to search when coding the residual.
820 * This is used in tandem with
821 * FLAC__stream_encoder_set_min_residual_partition_order().
823 * The partition order determines the context size in the residual.
824 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
826 * Set both min and max values to \c 0 to force a single context,
827 * whose Rice parameter is based on the residual signal variance.
828 * Otherwise, set a min and max order, and the encoder will search
829 * all orders, using the mean of each context for its Rice parameter,
833 * \param encoder An encoder instance to set.
834 * \param value See above.
836 * \code encoder != NULL \endcode
838 * \c false if the encoder is already initialized, else \c true.
840 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
842 /** Deprecated. Setting this value has no effect.
845 * \param encoder An encoder instance to set.
846 * \param value See above.
848 * \code encoder != NULL \endcode
850 * \c false if the encoder is already initialized, else \c true.
852 FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
854 /** Set an estimate of the total samples that will be encoded.
855 * This is merely an estimate and may be set to \c 0 if unknown.
856 * This value will be written to the STREAMINFO block before encoding,
857 * and can remove the need for the caller to rewrite the value later
858 * if the value is known before encoding.
861 * \param encoder An encoder instance to set.
862 * \param value See above.
864 * \code encoder != NULL \endcode
866 * \c false if the encoder is already initialized, else \c true.
868 FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
870 /** Set the metadata blocks to be emitted to the stream before encoding.
871 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
872 * array of pointers to metadata blocks. The array is non-const since
873 * the encoder may need to change the \a is_last flag inside them, and
874 * in some cases update seek point offsets. Otherwise, the encoder will
875 * not modify or free the blocks. It is up to the caller to free the
876 * metadata blocks after encoding.
879 * The encoder stores only the \a metadata pointer; the passed-in array
880 * must survive at least until after FLAC__stream_encoder_init() returns.
881 * Do not modify the array or free the blocks until then.
884 * The STREAMINFO block is always written and no STREAMINFO block may
885 * occur in the supplied array.
888 * By default the encoder does not create a SEEKTABLE. If one is supplied
889 * in the \a metadata array, but the client has specified that it does not
890 * support seeking, then the SEEKTABLE will be written verbatim. However
891 * by itself this is not very useful as the client will not know the stream
892 * offsets for the seekpoints ahead of time. In order to get a proper
893 * seektable the client must support seeking. See next note.
896 * SEEKTABLE blocks are handled specially. Since you will not know
897 * the values for the seek point stream offsets, you should pass in
898 * a SEEKTABLE 'template', that is, a SEEKTABLE object with the
899 * required sample numbers (or placeholder points), with \c 0 for the
900 * \a frame_samples and \a stream_offset fields for each point. If the
901 * client has specified that it supports seeking by providing a seek
902 * callback to FLAC__stream_encoder_init_stream() (or by using
903 * FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE()),
904 * then while it is encoding the encoder will fill the stream offsets in
905 * for you and when encoding is finished, it will seek back and write the
906 * real values into the SEEKTABLE block in the stream. There are helper
907 * routines for manipulating seektable template blocks; see metadata.h:
908 * FLAC__metadata_object_seektable_template_*(). If the client does
909 * not support seeking, the SEEKTABLE will have inaccurate offsets which
910 * will slow down or remove the ability to seek in the FLAC stream.
913 * The encoder instance \b will modify the first \c SEEKTABLE block
914 * as it transforms the template to a valid seektable while encoding,
915 * but it is still up to the caller to free all metadata blocks after
919 * A VORBIS_COMMENT block may be supplied. The vendor string in it
920 * will be ignored. libFLAC will use it's own vendor string. libFLAC
921 * will not modify the passed-in VORBIS_COMMENT's vendor string, it
922 * will simply write it's own into the stream. If no VORBIS_COMMENT
923 * block is present in the \a metadata array, libFLAC will write an
924 * empty one, containing only the vendor string.
926 * \default \c NULL, 0
927 * \param encoder An encoder instance to set.
928 * \param metadata See above.
929 * \param num_blocks See above.
931 * \code encoder != NULL \endcode
933 * \c false if the encoder is already initialized, else \c true.
935 FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
937 /** Get the current encoder state.
939 * \param encoder An encoder instance to query.
941 * \code encoder != NULL \endcode
942 * \retval FLAC__StreamEncoderState
943 * The current encoder state.
945 FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
947 /** Get the state of the verify stream decoder.
948 * Useful when the stream encoder state is
949 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
951 * \param encoder An encoder instance to query.
953 * \code encoder != NULL \endcode
954 * \retval FLAC__StreamDecoderState
955 * The verify stream decoder state.
957 FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
959 /** Get the current encoder state as a C string.
960 * This version automatically resolves
961 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the
962 * verify decoder's state.
964 * \param encoder A encoder instance to query.
966 * \code encoder != NULL \endcode
967 * \retval const char *
968 * The encoder state as a C string. Do not modify the contents.
970 FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
972 /** Get relevant values about the nature of a verify decoder error.
973 * Useful when the stream encoder state is
974 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should
975 * be addresses in which the stats will be returned, or NULL if value
978 * \param encoder An encoder instance to query.
979 * \param absolute_sample The absolute sample number of the mismatch.
980 * \param frame_number The number of the frame in which the mismatch occurred.
981 * \param channel The channel in which the mismatch occurred.
982 * \param sample The number of the sample (relative to the frame) in
983 * which the mismatch occurred.
984 * \param expected The expected value for the sample in question.
985 * \param got The actual value returned by the decoder.
987 * \code encoder != NULL \endcode
989 FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got);
991 /** Get the "verify" flag.
993 * \param encoder An encoder instance to query.
995 * \code encoder != NULL \endcode
997 * See FLAC__stream_encoder_set_verify().
999 FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
1001 /** Get the "streamable subset" flag.
1003 * \param encoder An encoder instance to query.
1005 * \code encoder != NULL \endcode
1006 * \retval FLAC__bool
1007 * See FLAC__stream_encoder_set_streamable_subset().
1009 FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
1011 /** Get the "mid/side stereo coding" flag.
1013 * \param encoder An encoder instance to query.
1015 * \code encoder != NULL \endcode
1016 * \retval FLAC__bool
1017 * See FLAC__stream_encoder_get_do_mid_side_stereo().
1019 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1021 /** Get the "adaptive mid/side switching" flag.
1023 * \param encoder An encoder instance to query.
1025 * \code encoder != NULL \endcode
1026 * \retval FLAC__bool
1027 * See FLAC__stream_encoder_set_loose_mid_side_stereo().
1029 FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1031 /** Get the number of input channels being processed.
1033 * \param encoder An encoder instance to query.
1035 * \code encoder != NULL \endcode
1037 * See FLAC__stream_encoder_set_channels().
1039 FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
1041 /** Get the input sample resolution setting.
1043 * \param encoder An encoder instance to query.
1045 * \code encoder != NULL \endcode
1047 * See FLAC__stream_encoder_set_bits_per_sample().
1049 FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
1051 /** Get the input sample rate setting.
1053 * \param encoder An encoder instance to query.
1055 * \code encoder != NULL \endcode
1057 * See FLAC__stream_encoder_set_sample_rate().
1059 FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
1061 /** Get the blocksize setting.
1063 * \param encoder An encoder instance to query.
1065 * \code encoder != NULL \endcode
1067 * See FLAC__stream_encoder_set_blocksize().
1069 FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
1071 /** Get the maximum LPC order setting.
1073 * \param encoder An encoder instance to query.
1075 * \code encoder != NULL \endcode
1077 * See FLAC__stream_encoder_set_max_lpc_order().
1079 FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
1081 /** Get the quantized linear predictor coefficient precision setting.
1083 * \param encoder An encoder instance to query.
1085 * \code encoder != NULL \endcode
1087 * See FLAC__stream_encoder_set_qlp_coeff_precision().
1089 FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
1091 /** Get the qlp coefficient precision search flag.
1093 * \param encoder An encoder instance to query.
1095 * \code encoder != NULL \endcode
1096 * \retval FLAC__bool
1097 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
1099 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
1101 /** Get the "escape coding" flag.
1103 * \param encoder An encoder instance to query.
1105 * \code encoder != NULL \endcode
1106 * \retval FLAC__bool
1107 * See FLAC__stream_encoder_set_do_escape_coding().
1109 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
1111 /** Get the exhaustive model search flag.
1113 * \param encoder An encoder instance to query.
1115 * \code encoder != NULL \endcode
1116 * \retval FLAC__bool
1117 * See FLAC__stream_encoder_set_do_exhaustive_model_search().
1119 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
1121 /** Get the minimum residual partition order setting.
1123 * \param encoder An encoder instance to query.
1125 * \code encoder != NULL \endcode
1127 * See FLAC__stream_encoder_set_min_residual_partition_order().
1129 FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
1131 /** Get maximum residual partition order setting.
1133 * \param encoder An encoder instance to query.
1135 * \code encoder != NULL \endcode
1137 * See FLAC__stream_encoder_set_max_residual_partition_order().
1139 FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
1141 /** Get the Rice parameter search distance setting.
1143 * \param encoder An encoder instance to query.
1145 * \code encoder != NULL \endcode
1147 * See FLAC__stream_encoder_set_rice_parameter_search_dist().
1149 FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
1151 /** Get the previously set estimate of the total samples to be encoded.
1152 * The encoder merely mimics back the value given to
1153 * FLAC__stream_encoder_set_total_samples_estimate() since it has no
1154 * other way of knowing how many samples the user will encode.
1156 * \param encoder An encoder instance to set.
1158 * \code encoder != NULL \endcode
1159 * \retval FLAC__uint64
1160 * See FLAC__stream_encoder_get_total_samples_estimate().
1162 FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
1164 /** Initialize the encoder instance.
1166 * This flavor of initialization sets up the encoder to encode to a stream.
1167 * I/O is performed via callbacks to the client. For encoding to a plain file
1168 * via filename or open \c FILE*, FLAC__stream_encoder_init_file() and
1169 * FLAC__stream_encoder_init_FILE() provide a simpler interface.
1171 * This function should be called after FLAC__stream_encoder_new() and
1172 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1173 * or FLAC__stream_encoder_process_interleaved().
1174 * initialization succeeded.
1176 * The call to FLAC__stream_encoder_init_stream() currently will also immediately
1177 * call the write callback several times, once with the \c fLaC signature,
1178 * and once for each encoded metadata block.
1180 * \param encoder An uninitialized encoder instance.
1181 * \param write_callback See FLAC__StreamEncoderWriteCallback. This
1182 * pointer must not be \c NULL.
1183 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
1184 * pointer may be \c NULL if seeking is not
1185 * supported. The encoder uses seeking to go back
1186 * and write some some stream statistics to the
1187 * STREAMINFO block; this is recommended but not
1188 * necessary to create a valid FLAC stream. If
1189 * \a seek_callback is not \c NULL then a
1190 * \a tell_callback must also be supplied.
1191 * Alternatively, a dummy seek callback that just
1192 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
1193 * may also be supplied, all though this is slightly
1194 * less efficient for the decoder.
1195 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
1196 * pointer may be \c NULL if seeking is not
1197 * supported. If \a seek_callback is \c NULL then
1198 * this argument will be ignored. If
1199 * \a seek_callback is not \c NULL then a
1200 * \a tell_callback must also be supplied.
1201 * Alternatively, a dummy tell callback that just
1202 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
1203 * may also be supplied, all though this is slightly
1204 * less efficient for the decoder.
1205 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
1206 * pointer may be \c NULL if the callback is not
1207 * desired. If the client provides a seek callback,
1208 * this function is not necessary as the encoder
1209 * will automatically seek back and update the
1210 * STREAMINFO block. It may also be \c NULL if the
1211 * client does not support seeking, since it will
1212 * have no way of going back to update the
1213 * STREAMINFO. However the client can still supply
1214 * a callback if it would like to know the details
1215 * from the STREAMINFO.
1216 * \param client_data This value will be supplied to callbacks in their
1217 * \a client_data argument.
1219 * \code encoder != NULL \endcode
1220 * \retval FLAC__StreamEncoderInitStatus
1221 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1222 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1224 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
1226 /** Initialize the encoder instance.
1228 * This flavor of initialization sets up the encoder to encode to a plain
1229 * file. For non-stdio streams, you must use
1230 * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
1232 * This function should be called after FLAC__stream_encoder_new() and
1233 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1234 * or FLAC__stream_encoder_process_interleaved().
1235 * initialization succeeded.
1237 * The call to FLAC__stream_encoder_init_stream() currently will also immediately
1238 * call the write callback several times, once with the \c fLaC signature,
1239 * and once for each encoded metadata block.
1241 * \param encoder An uninitialized encoder instance.
1242 * \param file An open file. The file should have been opened
1243 * with mode \c "w+b" and rewound. The file
1244 * becomes owned by the encoder and should not be
1245 * manipulated by the client while encoding.
1246 * Unless \a file is \c stdout, it will be closed
1247 * when FLAC__stream_encoder_finish() is called.
1248 * Note however that a proper SEEKTABLE cannot be
1249 * created when encoding to \c stdout since it is
1251 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1252 * pointer may be \c NULL if the callback is not
1254 * \param client_data This value will be supplied to callbacks in their
1255 * \a client_data argument.
1257 * \code encoder != NULL \endcode
1258 * \code file != NULL \endcode
1259 * \retval FLAC__StreamEncoderInitStatus
1260 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1261 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1263 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1265 /** Initialize the encoder instance.
1267 * This flavor of initialization sets up the encoder to encode to a plain
1268 * file. If POSIX fopen() semantics are not sufficient (for example,
1269 * with Unicode filenames on Windows), you must use
1270 * FLAC__stream_encodeR_init_FILE(), or FLAC__stream_encoder_init_stream()
1271 * and provide callbacks for the I/O.
1273 * This function should be called after FLAC__stream_encoder_new() and
1274 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1275 * or FLAC__stream_encoder_process_interleaved().
1276 * initialization succeeded.
1278 * The call to FLAC__stream_encoder_init_stream() currently will also immediately
1279 * call the write callback several times, once with the \c fLaC signature,
1280 * and once for each encoded metadata block.
1282 * \param encoder An uninitialized encoder instance.
1283 * \param filename The name of the file to encode to. The file will
1284 * be opened with fopen(). Use \c NULL to encode to
1285 * \c stdout. Note however that a proper SEEKTABLE
1286 * cannot be created when encoding to \c stdout since
1287 * it is not seekable.
1288 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1289 * pointer may be \c NULL if the callback is not
1291 * \param client_data This value will be supplied to callbacks in their
1292 * \a client_data argument.
1294 * \code encoder != NULL \endcode
1295 * \retval FLAC__StreamEncoderInitStatus
1296 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1297 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1299 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1301 /** Finish the encoding process.
1302 * Flushes the encoding buffer, releases resources, resets the encoder
1303 * settings to their defaults, and returns the encoder state to
1304 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
1305 * one or more write callbacks before returning, and will generate
1306 * a metadata callback.
1308 * In the event of a prematurely-terminated encode, it is not strictly
1309 * necessary to call this immediately before FLAC__stream_encoder_delete()
1310 * but it is good practice to match every FLAC__stream_encoder_init()
1311 * with a FLAC__stream_encoder_finish().
1313 * \param encoder An uninitialized encoder instance.
1315 * \code encoder != NULL \endcode
1317 FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
1319 /** Submit data for encoding.
1320 * This version allows you to supply the input data via an array of
1321 * pointers, each pointer pointing to an array of \a samples samples
1322 * representing one channel. The samples need not be block-aligned,
1323 * but each channel should have the same number of samples.
1325 * \param encoder An initialized encoder instance in the OK state.
1326 * \param buffer An array of pointers to each channel's signal.
1327 * \param samples The number of samples in one channel.
1329 * \code encoder != NULL \endcode
1330 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
1331 * \retval FLAC__bool
1332 * \c true if successful, else \c false; in this case, check the
1333 * encoder state with FLAC__stream_encoder_get_state() to see what
1336 FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
1338 /** Submit data for encoding.
1339 * This version allows you to supply the input data where the channels
1340 * are interleaved into a single array (i.e. channel0_sample0,
1341 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
1342 * The samples need not be block-aligned but they must be
1343 * sample-aligned, i.e. the first value should be channel0_sample0
1344 * and the last value channelN_sampleM.
1346 * \param encoder An initialized encoder instance in the OK state.
1347 * \param buffer An array of channel-interleaved data (see above).
1348 * \param samples The number of samples in one channel, the same as for
1349 * FLAC__stream_encoder_process(). For example, if
1350 * encoding two channels, \c 1000 \a samples corresponds
1351 * to a \a buffer of 2000 values.
1353 * \code encoder != NULL \endcode
1354 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
1355 * \retval FLAC__bool
1356 * \c true if successful, else \c false; in this case, check the
1357 * encoder state with FLAC__stream_encoder_get_state() to see what
1360 FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);