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 encoder layers provided by libFLAC.
61 * The stream encoder can be used to encode complete streams either to the
62 * client via callbacks, or directly to a file, depending on how it is
63 * initialized. When encoding via callbacks, the client provides a write
64 * callback which will be called whenever FLAC data is ready to be written.
65 * If the client also supplies a seek callback, the encoder will also
66 * automatically handle the writing back of metadata discovered while
67 * encoding, like stream info, seek points offsets, etc. When encoding to
68 * a file, the client needs only supply a filename or open \c FILE* and an
69 * optional progress callback for periodic notification of progress; the
70 * write and seek callbacks are supplied internally. For more info see the
71 * \link flac_stream_encoder stream encoder \endlink module.
74 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
75 * \ingroup flac_encoder
78 * This module contains the functions which implement the stream
81 * The stream encoder can encode to native FLAC, and optionally Ogg FLAC
82 * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files.
84 * The basic usage of this encoder is as follows:
85 * - The program creates an instance of an encoder using
86 * FLAC__stream_encoder_new().
87 * - The program overrides the default settings using
88 * FLAC__stream_encoder_set_*() functions. At a minimum, the following
89 * functions should be called:
90 * - FLAC__stream_encoder_set_channels()
91 * - FLAC__stream_encoder_set_bits_per_sample()
92 * - FLAC__stream_encoder_set_sample_rate()
93 * - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC)
94 * - FLAC__stream_encoder_set_total_samples_estimate() (if known)
95 * - If the application wants to control the compression level or set its own
96 * metadata, then the following should also be called:
97 * - FLAC__stream_encoder_set_compression_level()
98 * - FLAC__stream_encoder_set_verify()
99 * - FLAC__stream_encoder_set_metadata()
100 * - The rest of the set functions should only be called if the client needs
101 * exact control over how the audio is compressed; thorough understanding
102 * of the FLAC format is necessary to achieve good results.
103 * - The program initializes the instance to validate the settings and
104 * prepare for encoding using
105 * - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE()
106 * or FLAC__stream_encoder_init_file() for native FLAC
107 * - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE()
108 * or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC
109 * - The program calls FLAC__stream_encoder_process() or
110 * FLAC__stream_encoder_process_interleaved() to encode data, which
111 * subsequently calls the callbacks when there is encoder data ready
113 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
114 * which causes the encoder to encode any data still in its input pipe,
115 * update the metadata with the final encoding statistics if output
116 * seeking is possible, and finally reset the encoder to the
117 * uninitialized state.
118 * - The instance may be used again or deleted with
119 * FLAC__stream_encoder_delete().
121 * In more detail, the stream encoder functions similarly to the
122 * \link flac_stream_decoder stream decoder \endlink, but has fewer
123 * callbacks and more options. Typically the client will create a new
124 * instance by calling FLAC__stream_encoder_new(), then set the necessary
125 * parameters with FLAC__stream_encoder_set_*(), and initialize it by
126 * calling one of the FLAC__stream_encoder_init_*() functions.
128 * Unlike the decoders, the stream encoder has many options that can
129 * affect the speed and compression ratio. When setting these parameters
130 * you should have some basic knowledge of the format (see the
131 * <A HREF="../documentation.html#format">user-level documentation</A>
132 * or the <A HREF="../format.html">formal description</A>). The
133 * FLAC__stream_encoder_set_*() functions themselves do not validate the
134 * values as many are interdependent. The FLAC__stream_encoder_init_*()
135 * functions will do this, so make sure to pay attention to the state
136 * returned by FLAC__stream_encoder_init_*() to make sure that it is
137 * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set
138 * before FLAC__stream_encoder_init_*() will take on the defaults from
141 * There are three initialization functions for native FLAC, one for
142 * setting up the encoder to encode FLAC data to the client via
143 * callbacks, and two for encoding directly to a file.
145 * For encoding via callbacks, use FLAC__stream_encoder_init_stream().
146 * You must also supply a write callback which will be called anytime
147 * there is raw encoded data to write. If the client can seek the output
148 * it is best to also supply seek and tell callbacks, as this allows the
149 * encoder to go back after encoding is finished to write back
150 * information that was collected while encoding, like seek point offsets,
153 * For encoding directly to a file, use FLAC__stream_encoder_init_FILE()
154 * or FLAC__stream_encoder_init_file(). Then you must only supply a
155 * filename or open \c FILE*; the encoder will handle all the callbacks
156 * internally. You may also supply a progress callback for periodic
157 * notification of the encoding progress.
159 * There are three similarly-named init functions for encoding to Ogg
160 * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the
161 * library has been built with Ogg support.
163 * The call to FLAC__stream_encoder_init_*() currently will also immediately
164 * call the write callback several times, once with the \c fLaC signature,
165 * and once for each encoded metadata block. Note that for Ogg FLAC
166 * encoding you will usually get twice the number of callbacks than with
167 * native FLAC, one for the Ogg page header and one for the page body.
169 * After initializing the instance, the client may feed audio data to the
170 * encoder in one of two ways:
172 * - Channel separate, through FLAC__stream_encoder_process() - The client
173 * will pass an array of pointers to buffers, one for each channel, to
174 * the encoder, each of the same length. The samples need not be
176 * - Channel interleaved, through
177 * FLAC__stream_encoder_process_interleaved() - The client will pass a single
178 * pointer to data that is channel-interleaved (i.e. channel0_sample0,
179 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
180 * Again, the samples need not be block-aligned but they must be
181 * sample-aligned, i.e. the first value should be channel0_sample0 and
182 * the last value channelN_sampleM.
184 * When the client is finished encoding data, it calls
185 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
186 * data still in its input pipe, and call the metadata callback with the
187 * final encoding statistics. Then the instance may be deleted with
188 * FLAC__stream_encoder_delete() or initialized again to encode another
191 * For programs that write their own metadata, but that do not know the
192 * actual metadata until after encoding, it is advantageous to instruct
193 * the encoder to write a PADDING block of the correct size, so that
194 * instead of rewriting the whole stream after encoding, the program can
195 * just overwrite the PADDING block. If only the maximum size of the
196 * metadata is known, the program can write a slightly larger padding
197 * block, then split it after encoding.
199 * Make sure you understand how lengths are calculated. All FLAC metadata
200 * blocks have a 4 byte header which contains the type and length. This
201 * length does not include the 4 bytes of the header. See the format page
202 * for the specification of metadata blocks and their lengths.
205 * If you are writing the FLAC data to a file via callbacks, make sure it
206 * is open for update (e.g. mode "w+" for stdio streams). This is because
207 * after the first encoding pass, the encoder will try to seek back to the
208 * beginning of the stream, to the STREAMINFO block, to write some data
209 * there. (If using FLAC__stream_encoder_init*_file() or
210 * FLAC__stream_encoder_init*_FILE(), the file is managed internally.)
213 * The "set" functions may only be called when the encoder is in the
214 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
215 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
216 * before FLAC__stream_encoder_init_*(). If this is the case they will
217 * return \c true, otherwise \c false.
220 * FLAC__stream_encoder_finish() resets all settings to the constructor
227 /** State values for a FLAC__StreamEncoder.
229 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
231 * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK
232 * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and
233 * must be deleted with FLAC__stream_encoder_delete().
237 FLAC__STREAM_ENCODER_OK = 0,
238 /**< The encoder is in the normal OK state and samples can be processed. */
240 FLAC__STREAM_ENCODER_UNINITIALIZED,
241 /**< The encoder is in the uninitialized state; one of the
242 * FLAC__stream_encoder_init_*() functions must be called before samples
246 FLAC__STREAM_ENCODER_OGG_ERROR,
247 /**< An error occurred in the underlying Ogg layer. */
249 FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
250 /**< An error occurred in the underlying verify stream decoder;
251 * check FLAC__stream_encoder_get_verify_decoder_state().
254 FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
255 /**< The verify decoder detected a mismatch between the original
256 * audio signal and the decoded audio signal.
259 FLAC__STREAM_ENCODER_CLIENT_ERROR,
260 /**< One of the callbacks returned a fatal error. */
262 FLAC__STREAM_ENCODER_IO_ERROR,
263 /**< An I/O error occurred while opening/reading/writing a file.
267 FLAC__STREAM_ENCODER_FRAMING_ERROR,
268 /**< An error occurred while writing the stream; usually, the
269 * write_callback returned an error.
272 FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
273 /**< Memory allocation failed. */
275 } FLAC__StreamEncoderState;
277 /** Maps a FLAC__StreamEncoderState to a C string.
279 * Using a FLAC__StreamEncoderState as the index to this array
280 * will give the string equivalent. The contents should not be modified.
282 extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
285 /** Possible return values for the FLAC__stream_encoder_init_*() functions.
289 FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
290 /**< Initialization was successful. */
292 FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
293 /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */
295 FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
296 /**< The library was not compiled with support for the given container
300 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
301 /**< A required callback was not supplied. */
303 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
304 /**< The encoder has an invalid setting for number of channels. */
306 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
307 /**< The encoder has an invalid setting for bits-per-sample.
308 * FLAC supports 4-32 bps but the reference encoder currently supports
312 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
313 /**< The encoder has an invalid setting for the input sample rate. */
315 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
316 /**< The encoder has an invalid setting for the block size. */
318 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
319 /**< The encoder has an invalid setting for the maximum LPC order. */
321 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
322 /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
324 FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
325 /**< The specified block size is less than the maximum LPC order. */
327 FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
328 /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */
330 FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
331 /**< The metadata input to the encoder is invalid, in one of the following ways:
332 * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
333 * - One of the metadata blocks contains an undefined type
334 * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal()
335 * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal()
336 * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
339 FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
340 /**< FLAC__stream_encoder_init_*() was called when the encoder was
341 * already initialized, usually because
342 * FLAC__stream_encoder_finish() was not called.
345 } FLAC__StreamEncoderInitStatus;
347 /** Maps a FLAC__StreamEncoderInitStatus to a C string.
349 * Using a FLAC__StreamEncoderInitStatus as the index to this array
350 * will give the string equivalent. The contents should not be modified.
352 extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
355 /** Return values for the FLAC__StreamEncoder read callback.
359 FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
360 /**< The read was OK and decoding can continue. */
362 FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
363 /**< The read was attempted at the end of the stream. */
365 FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
366 /**< An unrecoverable error occurred. */
368 FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
369 /**< Client does not support reading back from the output. */
371 } FLAC__StreamEncoderReadStatus;
373 /** Maps a FLAC__StreamEncoderReadStatus to a C string.
375 * Using a FLAC__StreamEncoderReadStatus as the index to this array
376 * will give the string equivalent. The contents should not be modified.
378 extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
381 /** Return values for the FLAC__StreamEncoder write callback.
385 FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
386 /**< The write was OK and encoding can continue. */
388 FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
389 /**< An unrecoverable error occurred. The encoder will return from the process call. */
391 } FLAC__StreamEncoderWriteStatus;
393 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
395 * Using a FLAC__StreamEncoderWriteStatus as the index to this array
396 * will give the string equivalent. The contents should not be modified.
398 extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
401 /** Return values for the FLAC__StreamEncoder seek callback.
405 FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
406 /**< The seek was OK and encoding can continue. */
408 FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
409 /**< An unrecoverable error occurred. */
411 FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
412 /**< Client does not support seeking. */
414 } FLAC__StreamEncoderSeekStatus;
416 /** Maps a FLAC__StreamEncoderSeekStatus to a C string.
418 * Using a FLAC__StreamEncoderSeekStatus as the index to this array
419 * will give the string equivalent. The contents should not be modified.
421 extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
424 /** Return values for the FLAC__StreamEncoder tell callback.
428 FLAC__STREAM_ENCODER_TELL_STATUS_OK,
429 /**< The tell was OK and encoding can continue. */
431 FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
432 /**< An unrecoverable error occurred. */
434 FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
435 /**< Client does not support seeking. */
437 } FLAC__StreamEncoderTellStatus;
439 /** Maps a FLAC__StreamEncoderTellStatus to a C string.
441 * Using a FLAC__StreamEncoderTellStatus as the index to this array
442 * will give the string equivalent. The contents should not be modified.
444 extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
447 /***********************************************************************
449 * class FLAC__StreamEncoder
451 ***********************************************************************/
453 struct FLAC__StreamEncoderProtected;
454 struct FLAC__StreamEncoderPrivate;
455 /** The opaque structure definition for the stream encoder type.
456 * See the \link flac_stream_encoder stream encoder module \endlink
457 * for a detailed description.
460 struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
461 struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
462 } FLAC__StreamEncoder;
464 /** Signature for the read callback.
466 * A function pointer matching this signature must be passed to
467 * FLAC__stream_encoder_init_ogg_stream() if seeking is supported.
468 * The supplied function will be called when the encoder needs to read back
469 * encoded data. This happens during the metadata callback, when the encoder
470 * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
471 * while encoding. The address of the buffer to be filled is supplied, along
472 * with the number of bytes the buffer can hold. The callback may choose to
473 * supply less data and modify the byte count but must be careful not to
474 * overflow the buffer. The callback then returns a status code chosen from
475 * FLAC__StreamEncoderReadStatus.
477 * Here is an example of a read callback for stdio streams:
479 * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
481 * FILE *file = ((MyClientData*)client_data)->file;
483 * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file);
485 * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
486 * else if(*bytes == 0)
487 * return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
489 * return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
492 * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
496 * \note In general, FLAC__StreamEncoder functions which change the
497 * state should not be called on the \a encoder while in the callback.
499 * \param encoder The encoder instance calling the callback.
500 * \param buffer A pointer to a location for the callee to store
501 * data to be encoded.
502 * \param bytes A pointer to the size of the buffer. On entry
503 * to the callback, it contains the maximum number
504 * of bytes that may be stored in \a buffer. The
505 * callee must set it to the actual number of bytes
506 * stored (0 in case of error or end-of-stream) before
508 * \param client_data The callee's client data set through
509 * FLAC__stream_encoder_set_client_data().
510 * \retval FLAC__StreamEncoderReadStatus
511 * The callee's return status.
513 typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
515 /** Signature for the write callback.
517 * A function pointer matching this signature must be passed to
518 * FLAC__stream_encoder_init*_stream(). The supplied function will be called
519 * by the encoder anytime there is raw encoded data ready to write. It may
520 * include metadata mixed with encoded audio frames and the data is not
521 * guaranteed to be aligned on frame or metadata block boundaries.
523 * The only duty of the callback is to write out the \a bytes worth of data
524 * in \a buffer to the current position in the output stream. The arguments
525 * \a samples and \a current_frame are purely informational. If \a samples
526 * is greater than \c 0, then \a current_frame will hold the current frame
527 * number that is being written; otherwise it indicates that the write
528 * callback is being called to write metadata.
531 * Unlike when writing to native FLAC, when writing to Ogg FLAC the
532 * write callback will be called twice when writing each audio
533 * frame; once for the page header, and once for the page body.
534 * When writing the page header, the \a samples argument to the
535 * write callback will be \c 0.
537 * \note In general, FLAC__StreamEncoder functions which change the
538 * state should not be called on the \a encoder while in the callback.
540 * \param encoder The encoder instance calling the callback.
541 * \param buffer An array of encoded data of length \a bytes.
542 * \param bytes The byte length of \a buffer.
543 * \param samples The number of samples encoded by \a buffer.
544 * \c 0 has a special meaning; see above.
545 * \param current_frame The number of the current frame being encoded.
546 * \param client_data The callee's client data set through
547 * FLAC__stream_encoder_init_*().
548 * \retval FLAC__StreamEncoderWriteStatus
549 * The callee's return status.
551 typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
553 /** Signature for the seek callback.
555 * A function pointer matching this signature may be passed to
556 * FLAC__stream_encoder_init*_stream(). The supplied function will be called
557 * when the encoder needs to seek the output stream. The encoder will pass
558 * the absolute byte offset to seek to, 0 meaning the beginning of the stream.
560 * Here is an example of a seek callback for stdio streams:
562 * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
564 * FILE *file = ((MyClientData*)client_data)->file;
566 * return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
567 * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
568 * return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
570 * return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
574 * \note In general, FLAC__StreamEncoder functions which change the
575 * state should not be called on the \a encoder while in the callback.
577 * \param encoder The encoder instance calling the callback.
578 * \param absolute_byte_offset The offset from the beginning of the stream
580 * \param client_data The callee's client data set through
581 * FLAC__stream_encoder_init_*().
582 * \retval FLAC__StreamEncoderSeekStatus
583 * The callee's return status.
585 typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
587 /** Signature for the tell callback.
589 * A function pointer matching this signature may be passed to
590 * FLAC__stream_encoder_init*_stream(). The supplied function will be called
591 * when the encoder needs to know the current position of the output stream.
594 * The callback must return the true current byte offset of the output to
595 * which the encoder is writing. If you are buffering the output, make
596 * sure and take this into account. If you are writing directly to a
597 * FILE* from your write callback, ftell() is sufficient. If you are
598 * writing directly to a file descriptor from your write callback, you
599 * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to
600 * these points to rewrite metadata after encoding.
602 * Here is an example of a tell callback for stdio streams:
604 * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
606 * FILE *file = ((MyClientData*)client_data)->file;
609 * return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
610 * else if((pos = ftello(file)) < 0)
611 * return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
613 * *absolute_byte_offset = (FLAC__uint64)pos;
614 * return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
619 * \note In general, FLAC__StreamEncoder functions which change the
620 * state should not be called on the \a encoder while in the callback.
622 * \param encoder The encoder instance calling the callback.
623 * \param absolute_byte_offset The address at which to store the current
624 * position of the output.
625 * \param client_data The callee's client data set through
626 * FLAC__stream_encoder_init_*().
627 * \retval FLAC__StreamEncoderTellStatus
628 * The callee's return status.
630 typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
632 /** Signature for the metadata callback.
634 * A function pointer matching this signature may be passed to
635 * FLAC__stream_encoder_init*_stream(). The supplied function will be called
636 * once at the end of encoding with the populated STREAMINFO structure. This
637 * is so the client can seek back to the beginning of the file and write the
638 * STREAMINFO block with the correct statistics after encoding (like
639 * minimum/maximum frame size and total samples).
641 * \note In general, FLAC__StreamEncoder functions which change the
642 * state should not be called on the \a encoder while in the callback.
644 * \param encoder The encoder instance calling the callback.
645 * \param metadata The final populated STREAMINFO block.
646 * \param client_data The callee's client data set through
647 * FLAC__stream_encoder_init_*().
649 typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
651 /** Signature for the progress callback.
653 * A function pointer matching this signature may be passed to
654 * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE().
655 * The supplied function will be called when the encoder has finished
656 * writing a frame. The \c total_frames_estimate argument to the
657 * callback will be based on the value from
658 * FLAC__stream_encoder_set_total_samples_estimate().
660 * \note In general, FLAC__StreamEncoder functions which change the
661 * state should not be called on the \a encoder while in the callback.
663 * \param encoder The encoder instance calling the callback.
664 * \param bytes_written Bytes written so far.
665 * \param samples_written Samples written so far.
666 * \param frames_written Frames written so far.
667 * \param total_frames_estimate The estimate of the total number of
668 * frames to be written.
669 * \param client_data The callee's client data set through
670 * FLAC__stream_encoder_init_*().
672 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);
675 /***********************************************************************
677 * Class constructor/destructor
679 ***********************************************************************/
681 /** Create a new stream encoder instance. The instance is created with
682 * default settings; see the individual FLAC__stream_encoder_set_*()
683 * functions for each setting's default.
685 * \retval FLAC__StreamEncoder*
686 * \c NULL if there was an error allocating memory, else the new instance.
688 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new();
690 /** Free an encoder instance. Deletes the object pointed to by \a encoder.
692 * \param encoder A pointer to an existing encoder.
694 * \code encoder != NULL \endcode
696 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
699 /***********************************************************************
701 * Public class method prototypes
703 ***********************************************************************/
705 /** Set the serial number for the FLAC stream to use in the Ogg container.
708 * This does not need to be set for native FLAC encoding.
711 * It is recommended to set a serial number explicitly as the default of '0'
712 * may collide with other streams.
715 * \param encoder An encoder instance to set.
716 * \param serial_number See above.
718 * \code encoder != NULL \endcode
720 * \c false if the encoder is already initialized, else \c true.
722 FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
724 /** Set the "verify" flag. If \c true, the encoder will verify it's own
725 * encoded output by feeding it through an internal decoder and comparing
726 * the original signal against the decoded signal. If a mismatch occurs,
727 * the process call will return \c false. Note that this will slow the
728 * encoding process by the extra time required for decoding and comparison.
731 * \param encoder An encoder instance to set.
732 * \param value Flag value (see above).
734 * \code encoder != NULL \endcode
736 * \c false if the encoder is already initialized, else \c true.
738 FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
740 /** Set the <A HREF="../format.html#subset">Subset</A> flag. If \c true,
741 * the encoder will comply with the Subset and will check the
742 * settings during FLAC__stream_encoder_init_*() to see if all settings
743 * comply. If \c false, the settings may take advantage of the full
744 * range that the format allows.
746 * Make sure you know what it entails before setting this to \c false.
749 * \param encoder An encoder instance to set.
750 * \param value Flag value (see above).
752 * \code encoder != NULL \endcode
754 * \c false if the encoder is already initialized, else \c true.
756 FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
758 /** Set the number of channels to be encoded.
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_channels(FLAC__StreamEncoder *encoder, unsigned value);
770 /** Set the sample resolution of the input to be encoded.
773 * Do not feed the encoder data that is wider than the value you
774 * set here or you will generate an invalid stream.
777 * \param encoder An encoder instance to set.
778 * \param value See above.
780 * \code encoder != NULL \endcode
782 * \c false if the encoder is already initialized, else \c true.
784 FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
786 /** Set the sample rate (in Hz) of the input to be encoded.
789 * \param encoder An encoder instance to set.
790 * \param value See above.
792 * \code encoder != NULL \endcode
794 * \c false if the encoder is already initialized, else \c true.
796 FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
798 /** Set the compression level
800 * The compression level is roughly proportional to the amount of effort
801 * the encoder expends to compress the file. A higher level usually
802 * means more computation but higher compression. The default level is
803 * suitable for most applications.
805 * Currently the levels range from \c 0 (fastest, least compression) to
806 * \c 8 (slowest, most compression). A value larger than \c 8 will be
809 * This function automatically calls the following other \c _set_
810 * functions with appropriate values, so the client does not need to
811 * unless it specifically wants to override them:
812 * - FLAC__stream_encoder_set_do_mid_side_stereo()
813 * - FLAC__stream_encoder_set_loose_mid_side_stereo()
814 * - FLAC__stream_encoder_set_apodization()
815 * - FLAC__stream_encoder_set_max_lpc_order()
816 * - FLAC__stream_encoder_set_qlp_coeff_precision()
817 * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
818 * - FLAC__stream_encoder_set_do_escape_coding()
819 * - FLAC__stream_encoder_set_do_exhaustive_model_search()
820 * - FLAC__stream_encoder_set_min_residual_partition_order()
821 * - FLAC__stream_encoder_set_max_residual_partition_order()
822 * - FLAC__stream_encoder_set_rice_parameter_search_dist()
824 * The actual values set for each level are:
827 * <td><b>level</b><td>
828 * <td>do mid-side stereo<td>
829 * <td>loose mid-side stereo<td>
830 * <td>apodization<td>
831 * <td>max lpc order<td>
832 * <td>qlp coeff precision<td>
833 * <td>qlp coeff prec search<td>
834 * <td>escape coding<td>
835 * <td>exhaustive model search<td>
836 * <td>min residual partition order<td>
837 * <td>max residual partition order<td>
838 * <td>rice parameter search dist<td>
840 * <tr> <td><b>0</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>2<td> <td>2<td> <td>0<td> </tr>
841 * <tr> <td><b>1</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>2<td> <td>2<td> <td>0<td> </tr>
842 * <tr> <td><b>2</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>0<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>3<td> <td>0<td> </tr>
843 * <tr> <td><b>3</b><td> <td>false<td> <td>false<td> <td>tukey(0.5)<td> <td>6<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
844 * <tr> <td><b>4</b><td> <td>true<td> <td>true<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
845 * <tr> <td><b>5</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>3<td> <td>3<td> <td>0<td> </tr>
846 * <tr> <td><b>6</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>false<td> <td>0<td> <td>4<td> <td>0<td> </tr>
847 * <tr> <td><b>7</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>8<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr>
848 * <tr> <td><b>8</b><td> <td>true<td> <td>false<td> <td>tukey(0.5)<td> <td>12<td> <td>0<td> <td>false<td> <td>false<td> <td>true<td> <td>0<td> <td>6<td> <td>0<td> </tr>
852 * \param encoder An encoder instance to set.
853 * \param value See above.
855 * \code encoder != NULL \endcode
857 * \c false if the encoder is already initialized, else \c true.
859 FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
861 /** Set the blocksize to use while encoding.
863 * The number of samples to use per frame. Use \c 0 to let the encoder
864 * estimate a blocksize; this is usually best.
867 * \param encoder An encoder instance to set.
868 * \param value See above.
870 * \code encoder != NULL \endcode
872 * \c false if the encoder is already initialized, else \c true.
874 FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
876 /** Set to \c true to enable mid-side encoding on stereo input. The
877 * number of channels must be 2 for this to have any effect. Set to
878 * \c false to use only independent channel coding.
881 * \param encoder An encoder instance to set.
882 * \param value Flag value (see above).
884 * \code encoder != NULL \endcode
886 * \c false if the encoder is already initialized, else \c true.
888 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
890 /** Set to \c true to enable adaptive switching between mid-side and
891 * left-right encoding on stereo input. Set to \c false to use
892 * exhaustive searching. Setting this to \c true requires
893 * FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to
894 * \c true in order to have any effect.
897 * \param encoder An encoder instance to set.
898 * \param value Flag value (see above).
900 * \code encoder != NULL \endcode
902 * \c false if the encoder is already initialized, else \c true.
904 FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
906 /* @@@@add to unit tests*/
907 /** Sets the apodization function(s) the encoder will use when windowing
908 * audio data for LPC analysis.
910 * The \a specification is a plain ASCII string which specifies exactly
911 * which functions to use. There may be more than one (up to 32),
912 * separated by \c ';' characters. Some functions take one or more
913 * comma-separated arguments in parentheses.
915 * The available functions are \c bartlett, \c bartlett_hann,
916 * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop,
917 * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall,
918 * \c rectangle, \c triangle, \c tukey(P), \c welch.
920 * For \c gauss(STDDEV), STDDEV specifies the standard deviation
923 * For \c tukey(P), P specifies the fraction of the window that is
924 * tapered (0<=P<=1). P=0 corresponds to \c rectangle and P=1
925 * corresponds to \c hann.
927 * Example specifications are \c "blackman" or
928 * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)"
930 * Any function that is specified erroneously is silently dropped. Up
931 * to 32 functions are kept, the rest are dropped. If the specification
932 * is empty the encoder defaults to \c "tukey(0.5)".
934 * When more than one function is specified, then for every subframe the
935 * encoder will try each of them separately and choose the window that
936 * results in the smallest compressed subframe.
938 * Note that each function specified causes the encoder to occupy a
939 * floating point array in which to store the window.
941 * \default \c "tukey(0.5)"
942 * \param encoder An encoder instance to set.
943 * \param specification See above.
945 * \code encoder != NULL \endcode
946 * \code specification != NULL \endcode
948 * \c false if the encoder is already initialized, else \c true.
950 FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
952 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
955 * \param encoder An encoder instance to set.
956 * \param value See above.
958 * \code encoder != NULL \endcode
960 * \c false if the encoder is already initialized, else \c true.
962 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
964 /** Set the precision, in bits, of the quantized linear predictor
965 * coefficients, or \c 0 to let the encoder select it based on the
969 * In the current implementation, qlp_coeff_precision + bits_per_sample must
973 * \param encoder An encoder instance to set.
974 * \param value See above.
976 * \code encoder != NULL \endcode
978 * \c false if the encoder is already initialized, else \c true.
980 FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
982 /** Set to \c false to use only the specified quantized linear predictor
983 * coefficient precision, or \c true to search neighboring precision
984 * values and use the best one.
987 * \param encoder An encoder instance to set.
988 * \param value See above.
990 * \code encoder != NULL \endcode
992 * \c false if the encoder is already initialized, else \c true.
994 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
996 /** Deprecated. Setting this value has no effect.
999 * \param encoder An encoder instance to set.
1000 * \param value See above.
1002 * \code encoder != NULL \endcode
1003 * \retval FLAC__bool
1004 * \c false if the encoder is already initialized, else \c true.
1006 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
1008 /** Set to \c false to let the encoder estimate the best model order
1009 * based on the residual signal energy, or \c true to force the
1010 * encoder to evaluate all order models and select the best.
1013 * \param encoder An encoder instance to set.
1014 * \param value See above.
1016 * \code encoder != NULL \endcode
1017 * \retval FLAC__bool
1018 * \c false if the encoder is already initialized, else \c true.
1020 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
1022 /** Set the minimum partition order to search when coding the residual.
1023 * This is used in tandem with
1024 * FLAC__stream_encoder_set_max_residual_partition_order().
1026 * The partition order determines the context size in the residual.
1027 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
1029 * Set both min and max values to \c 0 to force a single context,
1030 * whose Rice parameter is based on the residual signal variance.
1031 * Otherwise, set a min and max order, and the encoder will search
1032 * all orders, using the mean of each context for its Rice parameter,
1036 * \param encoder An encoder instance to set.
1037 * \param value See above.
1039 * \code encoder != NULL \endcode
1040 * \retval FLAC__bool
1041 * \c false if the encoder is already initialized, else \c true.
1043 FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
1045 /** Set the maximum partition order to search when coding the residual.
1046 * This is used in tandem with
1047 * FLAC__stream_encoder_set_min_residual_partition_order().
1049 * The partition order determines the context size in the residual.
1050 * The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
1052 * Set both min and max values to \c 0 to force a single context,
1053 * whose Rice parameter is based on the residual signal variance.
1054 * Otherwise, set a min and max order, and the encoder will search
1055 * all orders, using the mean of each context for its Rice parameter,
1059 * \param encoder An encoder instance to set.
1060 * \param value See above.
1062 * \code encoder != NULL \endcode
1063 * \retval FLAC__bool
1064 * \c false if the encoder is already initialized, else \c true.
1066 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
1068 /** Deprecated. Setting this value has no effect.
1071 * \param encoder An encoder instance to set.
1072 * \param value See above.
1074 * \code encoder != NULL \endcode
1075 * \retval FLAC__bool
1076 * \c false if the encoder is already initialized, else \c true.
1078 FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
1080 /** Set an estimate of the total samples that will be encoded.
1081 * This is merely an estimate and may be set to \c 0 if unknown.
1082 * This value will be written to the STREAMINFO block before encoding,
1083 * and can remove the need for the caller to rewrite the value later
1084 * if the value is known before encoding.
1087 * \param encoder An encoder instance to set.
1088 * \param value See above.
1090 * \code encoder != NULL \endcode
1091 * \retval FLAC__bool
1092 * \c false if the encoder is already initialized, else \c true.
1094 FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
1096 /** Set the metadata blocks to be emitted to the stream before encoding.
1097 * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
1098 * array of pointers to metadata blocks. The array is non-const since
1099 * the encoder may need to change the \a is_last flag inside them, and
1100 * in some cases update seek point offsets. Otherwise, the encoder will
1101 * not modify or free the blocks. It is up to the caller to free the
1102 * metadata blocks after encoding.
1105 * The encoder stores only the \a metadata pointer; the passed-in array
1106 * must survive at least until after FLAC__stream_encoder_init_*() returns.
1107 * Do not modify the array or free the blocks until then.
1110 * The STREAMINFO block is always written and no STREAMINFO block may
1111 * occur in the supplied array.
1114 * By default the encoder does not create a SEEKTABLE. If one is supplied
1115 * in the \a metadata array, but the client has specified that it does not
1116 * support seeking, then the SEEKTABLE will be written verbatim. However
1117 * by itself this is not very useful as the client will not know the stream
1118 * offsets for the seekpoints ahead of time. In order to get a proper
1119 * seektable the client must support seeking. See next note.
1122 * SEEKTABLE blocks are handled specially. Since you will not know
1123 * the values for the seek point stream offsets, you should pass in
1124 * a SEEKTABLE 'template', that is, a SEEKTABLE object with the
1125 * required sample numbers (or placeholder points), with \c 0 for the
1126 * \a frame_samples and \a stream_offset fields for each point. If the
1127 * client has specified that it supports seeking by providing a seek
1128 * callback to FLAC__stream_encoder_init_stream() or both seek AND read
1129 * callback to FLAC__stream_encoder_init_ogg_stream() (or by using
1130 * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()),
1131 * then while it is encoding the encoder will fill the stream offsets in
1132 * for you and when encoding is finished, it will seek back and write the
1133 * real values into the SEEKTABLE block in the stream. There are helper
1134 * routines for manipulating seektable template blocks; see metadata.h:
1135 * FLAC__metadata_object_seektable_template_*(). If the client does
1136 * not support seeking, the SEEKTABLE will have inaccurate offsets which
1137 * will slow down or remove the ability to seek in the FLAC stream.
1140 * The encoder instance \b will modify the first \c SEEKTABLE block
1141 * as it transforms the template to a valid seektable while encoding,
1142 * but it is still up to the caller to free all metadata blocks after
1146 * A VORBIS_COMMENT block may be supplied. The vendor string in it
1147 * will be ignored. libFLAC will use it's own vendor string. libFLAC
1148 * will not modify the passed-in VORBIS_COMMENT's vendor string, it
1149 * will simply write it's own into the stream. If no VORBIS_COMMENT
1150 * block is present in the \a metadata array, libFLAC will write an
1151 * empty one, containing only the vendor string.
1153 * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
1154 * the second metadata block of the stream. The encoder already supplies
1155 * the STREAMINFO block automatically. If \a metadata does not contain a
1156 * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if
1157 * \a metadata does contain a VORBIS_COMMENT block and it is not the
1158 * first, the init function will reorder \a metadata by moving the
1159 * VORBIS_COMMENT block to the front; the relative ordering of the other
1160 * blocks will remain as they were.
1162 * \note The Ogg FLAC mapping limits the number of metadata blocks per
1163 * stream to \c 65535. If \a num_blocks exceeds this the function will
1166 * \default \c NULL, 0
1167 * \param encoder An encoder instance to set.
1168 * \param metadata See above.
1169 * \param num_blocks See above.
1171 * \code encoder != NULL \endcode
1172 * \retval FLAC__bool
1173 * \c false if the encoder is already initialized, else \c true.
1174 * \c false if the encoder is already initialized, or if
1175 * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true.
1177 FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
1179 /** Get the current encoder state.
1181 * \param encoder An encoder instance to query.
1183 * \code encoder != NULL \endcode
1184 * \retval FLAC__StreamEncoderState
1185 * The current encoder state.
1187 FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
1189 /** Get the state of the verify stream decoder.
1190 * Useful when the stream encoder state is
1191 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
1193 * \param encoder An encoder instance to query.
1195 * \code encoder != NULL \endcode
1196 * \retval FLAC__StreamDecoderState
1197 * The verify stream decoder state.
1199 FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
1201 /** Get the current encoder state as a C string.
1202 * This version automatically resolves
1203 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the
1204 * verify decoder's state.
1206 * \param encoder A encoder instance to query.
1208 * \code encoder != NULL \endcode
1209 * \retval const char *
1210 * The encoder state as a C string. Do not modify the contents.
1212 FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
1214 /** Get relevant values about the nature of a verify decoder error.
1215 * Useful when the stream encoder state is
1216 * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should
1217 * be addresses in which the stats will be returned, or NULL if value
1220 * \param encoder An encoder instance to query.
1221 * \param absolute_sample The absolute sample number of the mismatch.
1222 * \param frame_number The number of the frame in which the mismatch occurred.
1223 * \param channel The channel in which the mismatch occurred.
1224 * \param sample The number of the sample (relative to the frame) in
1225 * which the mismatch occurred.
1226 * \param expected The expected value for the sample in question.
1227 * \param got The actual value returned by the decoder.
1229 * \code encoder != NULL \endcode
1231 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);
1233 /** Get the "verify" flag.
1235 * \param encoder An encoder instance to query.
1237 * \code encoder != NULL \endcode
1238 * \retval FLAC__bool
1239 * See FLAC__stream_encoder_set_verify().
1241 FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
1243 /** Get the <A HREF="../format.html#subset>Subset</A> flag.
1245 * \param encoder An encoder instance to query.
1247 * \code encoder != NULL \endcode
1248 * \retval FLAC__bool
1249 * See FLAC__stream_encoder_set_streamable_subset().
1251 FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
1253 /** Get the number of input channels being processed.
1255 * \param encoder An encoder instance to query.
1257 * \code encoder != NULL \endcode
1259 * See FLAC__stream_encoder_set_channels().
1261 FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
1263 /** Get the input sample resolution setting.
1265 * \param encoder An encoder instance to query.
1267 * \code encoder != NULL \endcode
1269 * See FLAC__stream_encoder_set_bits_per_sample().
1271 FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
1273 /** Get the input sample rate setting.
1275 * \param encoder An encoder instance to query.
1277 * \code encoder != NULL \endcode
1279 * See FLAC__stream_encoder_set_sample_rate().
1281 FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
1283 /** Get the blocksize setting.
1285 * \param encoder An encoder instance to query.
1287 * \code encoder != NULL \endcode
1289 * See FLAC__stream_encoder_set_blocksize().
1291 FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
1293 /** Get the "mid/side stereo coding" flag.
1295 * \param encoder An encoder instance to query.
1297 * \code encoder != NULL \endcode
1298 * \retval FLAC__bool
1299 * See FLAC__stream_encoder_get_do_mid_side_stereo().
1301 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1303 /** Get the "adaptive mid/side switching" flag.
1305 * \param encoder An encoder instance to query.
1307 * \code encoder != NULL \endcode
1308 * \retval FLAC__bool
1309 * See FLAC__stream_encoder_set_loose_mid_side_stereo().
1311 FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1313 /** Get the maximum LPC order setting.
1315 * \param encoder An encoder instance to query.
1317 * \code encoder != NULL \endcode
1319 * See FLAC__stream_encoder_set_max_lpc_order().
1321 FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
1323 /** Get the quantized linear predictor coefficient precision setting.
1325 * \param encoder An encoder instance to query.
1327 * \code encoder != NULL \endcode
1329 * See FLAC__stream_encoder_set_qlp_coeff_precision().
1331 FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
1333 /** Get the qlp coefficient precision search flag.
1335 * \param encoder An encoder instance to query.
1337 * \code encoder != NULL \endcode
1338 * \retval FLAC__bool
1339 * See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
1341 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
1343 /** Get the "escape coding" flag.
1345 * \param encoder An encoder instance to query.
1347 * \code encoder != NULL \endcode
1348 * \retval FLAC__bool
1349 * See FLAC__stream_encoder_set_do_escape_coding().
1351 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
1353 /** Get the exhaustive model search flag.
1355 * \param encoder An encoder instance to query.
1357 * \code encoder != NULL \endcode
1358 * \retval FLAC__bool
1359 * See FLAC__stream_encoder_set_do_exhaustive_model_search().
1361 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
1363 /** Get the minimum residual partition order setting.
1365 * \param encoder An encoder instance to query.
1367 * \code encoder != NULL \endcode
1369 * See FLAC__stream_encoder_set_min_residual_partition_order().
1371 FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
1373 /** Get maximum residual partition order setting.
1375 * \param encoder An encoder instance to query.
1377 * \code encoder != NULL \endcode
1379 * See FLAC__stream_encoder_set_max_residual_partition_order().
1381 FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
1383 /** Get the Rice parameter search distance setting.
1385 * \param encoder An encoder instance to query.
1387 * \code encoder != NULL \endcode
1389 * See FLAC__stream_encoder_set_rice_parameter_search_dist().
1391 FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
1393 /** Get the previously set estimate of the total samples to be encoded.
1394 * The encoder merely mimics back the value given to
1395 * FLAC__stream_encoder_set_total_samples_estimate() since it has no
1396 * other way of knowing how many samples the client will encode.
1398 * \param encoder An encoder instance to set.
1400 * \code encoder != NULL \endcode
1401 * \retval FLAC__uint64
1402 * See FLAC__stream_encoder_get_total_samples_estimate().
1404 FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
1406 /** Initialize the encoder instance to encode native FLAC streams.
1408 * This flavor of initialization sets up the encoder to encode to a
1409 * native FLAC stream. I/O is performed via callbacks to the client.
1410 * For encoding to a plain file via filename or open \c FILE*,
1411 * FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE()
1412 * provide a simpler interface.
1414 * This function should be called after FLAC__stream_encoder_new() and
1415 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1416 * or FLAC__stream_encoder_process_interleaved().
1417 * initialization succeeded.
1419 * The call to FLAC__stream_encoder_init_stream() currently will also
1420 * immediately call the write callback several times, once with the \c fLaC
1421 * signature, and once for each encoded metadata block.
1423 * \param encoder An uninitialized encoder instance.
1424 * \param write_callback See FLAC__StreamEncoderWriteCallback. This
1425 * pointer must not be \c NULL.
1426 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
1427 * pointer may be \c NULL if seeking is not
1428 * supported. The encoder uses seeking to go back
1429 * and write some some stream statistics to the
1430 * STREAMINFO block; this is recommended but not
1431 * necessary to create a valid FLAC stream. If
1432 * \a seek_callback is not \c NULL then a
1433 * \a tell_callback must also be supplied.
1434 * Alternatively, a dummy seek callback that just
1435 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
1436 * may also be supplied, all though this is slightly
1437 * less efficient for the encoder.
1438 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
1439 * pointer may be \c NULL if seeking is not
1440 * supported. If \a seek_callback is \c NULL then
1441 * this argument will be ignored. If
1442 * \a seek_callback is not \c NULL then a
1443 * \a tell_callback must also be supplied.
1444 * Alternatively, a dummy tell callback that just
1445 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
1446 * may also be supplied, all though this is slightly
1447 * less efficient for the encoder.
1448 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
1449 * pointer may be \c NULL if the callback is not
1450 * desired. If the client provides a seek callback,
1451 * this function is not necessary as the encoder
1452 * will automatically seek back and update the
1453 * STREAMINFO block. It may also be \c NULL if the
1454 * client does not support seeking, since it will
1455 * have no way of going back to update the
1456 * STREAMINFO. However the client can still supply
1457 * a callback if it would like to know the details
1458 * from the STREAMINFO.
1459 * \param client_data This value will be supplied to callbacks in their
1460 * \a client_data argument.
1462 * \code encoder != NULL \endcode
1463 * \retval FLAC__StreamEncoderInitStatus
1464 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1465 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1467 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);
1469 /** Initialize the encoder instance to encode Ogg FLAC streams.
1471 * This flavor of initialization sets up the encoder to encode to a FLAC
1472 * stream in an Ogg container. I/O is performed via callbacks to the
1473 * client. For encoding to a plain file via filename or open \c FILE*,
1474 * FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE()
1475 * provide a simpler interface.
1477 * This function should be called after FLAC__stream_encoder_new() and
1478 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1479 * or FLAC__stream_encoder_process_interleaved().
1480 * initialization succeeded.
1482 * The call to FLAC__stream_encoder_init_ogg_stream() currently will also
1483 * immediately call the write callback several times to write the metadata
1486 * \param encoder An uninitialized encoder instance.
1487 * \param read_callback See FLAC__StreamEncoderReadCallback. This
1488 * pointer must not be \c NULL if \a seek_callback
1489 * is non-NULL since they are both needed to be
1490 * able to write data back to the Ogg FLAC stream
1491 * in the post-encode phase.
1492 * \param write_callback See FLAC__StreamEncoderWriteCallback. This
1493 * pointer must not be \c NULL.
1494 * \param seek_callback See FLAC__StreamEncoderSeekCallback. This
1495 * pointer may be \c NULL if seeking is not
1496 * supported. The encoder uses seeking to go back
1497 * and write some some stream statistics to the
1498 * STREAMINFO block; this is recommended but not
1499 * necessary to create a valid FLAC stream. If
1500 * \a seek_callback is not \c NULL then a
1501 * \a tell_callback must also be supplied.
1502 * Alternatively, a dummy seek callback that just
1503 * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
1504 * may also be supplied, all though this is slightly
1505 * less efficient for the encoder.
1506 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
1507 * pointer may be \c NULL if seeking is not
1508 * supported. If \a seek_callback is \c NULL then
1509 * this argument will be ignored. If
1510 * \a seek_callback is not \c NULL then a
1511 * \a tell_callback must also be supplied.
1512 * Alternatively, a dummy tell callback that just
1513 * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
1514 * may also be supplied, all though this is slightly
1515 * less efficient for the encoder.
1516 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
1517 * pointer may be \c NULL if the callback is not
1518 * desired. If the client provides a seek callback,
1519 * this function is not necessary as the encoder
1520 * will automatically seek back and update the
1521 * STREAMINFO block. It may also be \c NULL if the
1522 * client does not support seeking, since it will
1523 * have no way of going back to update the
1524 * STREAMINFO. However the client can still supply
1525 * a callback if it would like to know the details
1526 * from the STREAMINFO.
1527 * \param client_data This value will be supplied to callbacks in their
1528 * \a client_data argument.
1530 * \code encoder != NULL \endcode
1531 * \retval FLAC__StreamEncoderInitStatus
1532 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1533 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1535 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
1537 /** Initialize the encoder instance to encode native FLAC files.
1539 * This flavor of initialization sets up the encoder to encode to a
1540 * plain native FLAC file. For non-stdio streams, you must use
1541 * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
1543 * This function should be called after FLAC__stream_encoder_new() and
1544 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1545 * or FLAC__stream_encoder_process_interleaved().
1546 * initialization succeeded.
1548 * \param encoder An uninitialized encoder instance.
1549 * \param file An open file. The file should have been opened
1550 * with mode \c "w+b" and rewound. The file
1551 * becomes owned by the encoder and should not be
1552 * manipulated by the client while encoding.
1553 * Unless \a file is \c stdout, it will be closed
1554 * when FLAC__stream_encoder_finish() is called.
1555 * Note however that a proper SEEKTABLE cannot be
1556 * created when encoding to \c stdout since it is
1558 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1559 * pointer may be \c NULL if the callback is not
1561 * \param client_data This value will be supplied to callbacks in their
1562 * \a client_data argument.
1564 * \code encoder != NULL \endcode
1565 * \code file != NULL \endcode
1566 * \retval FLAC__StreamEncoderInitStatus
1567 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1568 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1570 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1572 /** Initialize the encoder instance to encode Ogg FLAC files.
1574 * This flavor of initialization sets up the encoder to encode to a
1575 * plain Ogg FLAC file. For non-stdio streams, you must use
1576 * FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O.
1578 * This function should be called after FLAC__stream_encoder_new() and
1579 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1580 * or FLAC__stream_encoder_process_interleaved().
1581 * initialization succeeded.
1583 * \param encoder An uninitialized encoder instance.
1584 * \param file An open file. The file should have been opened
1585 * with mode \c "w+b" and rewound. The file
1586 * becomes owned by the encoder and should not be
1587 * manipulated by the client while encoding.
1588 * Unless \a file is \c stdout, it will be closed
1589 * when FLAC__stream_encoder_finish() is called.
1590 * Note however that a proper SEEKTABLE cannot be
1591 * created when encoding to \c stdout since it is
1593 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1594 * pointer may be \c NULL if the callback is not
1596 * \param client_data This value will be supplied to callbacks in their
1597 * \a client_data argument.
1599 * \code encoder != NULL \endcode
1600 * \code file != NULL \endcode
1601 * \retval FLAC__StreamEncoderInitStatus
1602 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1603 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1605 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1607 /** Initialize the encoder instance to encode native FLAC files.
1609 * This flavor of initialization sets up the encoder to encode to a plain
1610 * FLAC file. If POSIX fopen() semantics are not sufficient (for example,
1611 * with Unicode filenames on Windows), you must use
1612 * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream()
1613 * and provide callbacks for the I/O.
1615 * This function should be called after FLAC__stream_encoder_new() and
1616 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1617 * or FLAC__stream_encoder_process_interleaved().
1618 * initialization succeeded.
1620 * \param encoder An uninitialized encoder instance.
1621 * \param filename The name of the file to encode to. The file will
1622 * be opened with fopen(). Use \c NULL to encode to
1623 * \c stdout. Note however that a proper SEEKTABLE
1624 * cannot be created when encoding to \c stdout since
1625 * it is not seekable.
1626 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1627 * pointer may be \c NULL if the callback is not
1629 * \param client_data This value will be supplied to callbacks in their
1630 * \a client_data argument.
1632 * \code encoder != NULL \endcode
1633 * \retval FLAC__StreamEncoderInitStatus
1634 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1635 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1637 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1639 /** Initialize the encoder instance to encode Ogg FLAC files.
1641 * This flavor of initialization sets up the encoder to encode to a plain
1642 * Ogg FLAC file. If POSIX fopen() semantics are not sufficient (for example,
1643 * with Unicode filenames on Windows), you must use
1644 * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream()
1645 * and provide callbacks for the I/O.
1647 * This function should be called after FLAC__stream_encoder_new() and
1648 * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1649 * or FLAC__stream_encoder_process_interleaved().
1650 * initialization succeeded.
1652 * \param encoder An uninitialized encoder instance.
1653 * \param filename The name of the file to encode to. The file will
1654 * be opened with fopen(). Use \c NULL to encode to
1655 * \c stdout. Note however that a proper SEEKTABLE
1656 * cannot be created when encoding to \c stdout since
1657 * it is not seekable.
1658 * \param progress_callback See FLAC__StreamEncoderProgressCallback. This
1659 * pointer may be \c NULL if the callback is not
1661 * \param client_data This value will be supplied to callbacks in their
1662 * \a client_data argument.
1664 * \code encoder != NULL \endcode
1665 * \retval FLAC__StreamEncoderInitStatus
1666 * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1667 * see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1669 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1671 /** Finish the encoding process.
1672 * Flushes the encoding buffer, releases resources, resets the encoder
1673 * settings to their defaults, and returns the encoder state to
1674 * FLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate
1675 * one or more write callbacks before returning, and will generate
1676 * a metadata callback.
1678 * Note that in the course of processing the last frame, errors can
1679 * occur, so the caller should be sure to check the return value to
1680 * ensure the file was encoded properly.
1682 * In the event of a prematurely-terminated encode, it is not strictly
1683 * necessary to call this immediately before FLAC__stream_encoder_delete()
1684 * but it is good practice to match every FLAC__stream_encoder_init_*()
1685 * with a FLAC__stream_encoder_finish().
1687 * \param encoder An uninitialized encoder instance.
1689 * \code encoder != NULL \endcode
1690 * \retval FLAC__bool
1691 * \c false if an error occurred processing the last frame; or if verify
1692 * mode is set (see FLAC__stream_encoder_set_verify()), there was a
1693 * verify mismatch; else \c true. If \c false, caller should check the
1694 * state with FLAC__stream_encoder_get_state() for more information
1697 FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
1699 /** Submit data for encoding.
1700 * This version allows you to supply the input data via an array of
1701 * pointers, each pointer pointing to an array of \a samples samples
1702 * representing one channel. The samples need not be block-aligned,
1703 * but each channel should have the same number of samples.
1705 * For applications where channel order is important, channels must
1706 * follow the order as described in the
1707 * <A HREF="../format.html#frame_header">frame header</A>.
1709 * \param encoder An initialized encoder instance in the OK state.
1710 * \param buffer An array of pointers to each channel's signal.
1711 * \param samples The number of samples in one channel.
1713 * \code encoder != NULL \endcode
1714 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
1715 * \retval FLAC__bool
1716 * \c true if successful, else \c false; in this case, check the
1717 * encoder state with FLAC__stream_encoder_get_state() to see what
1720 FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
1722 /** Submit data for encoding.
1723 * This version allows you to supply the input data where the channels
1724 * are interleaved into a single array (i.e. channel0_sample0,
1725 * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
1726 * The samples need not be block-aligned but they must be
1727 * sample-aligned, i.e. the first value should be channel0_sample0
1728 * and the last value channelN_sampleM.
1730 * For applications where channel order is important, channels must
1731 * follow the order as described in the
1732 * <A HREF="../format.html#frame_header">frame header</A>.
1734 * \param encoder An initialized encoder instance in the OK state.
1735 * \param buffer An array of channel-interleaved data (see above).
1736 * \param samples The number of samples in one channel, the same as for
1737 * FLAC__stream_encoder_process(). For example, if
1738 * encoding two channels, \c 1000 \a samples corresponds
1739 * to a \a buffer of 2000 values.
1741 * \code encoder != NULL \endcode
1742 * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
1743 * \retval FLAC__bool
1744 * \c true if successful, else \c false; in this case, check the
1745 * encoder state with FLAC__stream_encoder_get_state() to see what
1748 FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);