limit subset further if sample rate is <=48kHz: max blocksize is 4608 and max LPC...
[platform/upstream/flac.git] / include / FLAC / stream_encoder.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  */
31
32 #ifndef FLAC__STREAM_ENCODER_H
33 #define FLAC__STREAM_ENCODER_H
34
35 #include <stdio.h> /* for FILE */
36 #include "export.h"
37 #include "format.h"
38 #include "stream_decoder.h"
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44
45 /** \file include/FLAC/stream_encoder.h
46  *
47  *  \brief
48  *  This module contains the functions which implement the stream
49  *  encoder.
50  *
51  *  See the detailed documentation in the
52  *  \link flac_stream_encoder stream encoder \endlink module.
53  */
54
55 /** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
56  *  \ingroup flac
57  *
58  *  \brief
59  *  This module describes the encoder layers provided by libFLAC.
60  *
61  * The stream encoder can be used 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.
72  */
73
74 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
75  *  \ingroup flac_encoder
76  *
77  *  \brief
78  *  This module contains the functions which implement the stream
79  *  encoder.
80  *
81  * The basic usage of this encoder is as follows:
82  * - The program creates an instance of an encoder using
83  *   FLAC__stream_encoder_new().
84  * - The program overrides the default settings using
85  *   FLAC__stream_encoder_set_*() functions.
86  * - The program initializes the instance to validate the settings and
87  *   prepare for encoding using FLAC__stream_encoder_init_stream() or
88  *   FLAC__stream_encoder_init_FILE() or FLAC__stream_encoder_init_file(),
89  *   depending on the nature of the output.
90  * - The program calls FLAC__stream_encoder_process() or
91  *   FLAC__stream_encoder_process_interleaved() to encode data, which
92  *   subsequently calls the callbacks when there is encoder data ready
93  *   to be written.
94  * - The program finishes the encoding with FLAC__stream_encoder_finish(),
95  *   which causes the encoder to encode any data still in its input pipe,
96  *   update the metadata with the final encoding statistics if output
97  *   seeking is possible, and finally reset the encoder to the
98  *   uninitialized state.
99  * - The instance may be used again or deleted with
100  *   FLAC__stream_encoder_delete().
101  *
102  * In more detail, the stream encoder functions similarly to the
103  * \link flac_stream_decoder stream decoder \endlink, but has fewer
104  * callbacks and more options.  Typically the user will create a new
105  * instance by calling FLAC__stream_encoder_new(), then set the necessary
106  * parameters with FLAC__stream_encoder_set_*(), and initialize it by
107  * calling FLAC__stream_encoder_init_stream() or
108  * FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE().
109  *
110  * Unlike the decoders, the stream encoder has many options that can
111  * affect the speed and compression ratio.  When setting these parameters
112  * you should have some basic knowledge of the format (see the
113  * <A HREF="../documentation.html#format">user-level documentation</A>
114  * or the <A HREF="../format.html">formal description</A>).  The
115  * FLAC__stream_encoder_set_*() functions themselves do not validate the
116  * values as many are interdependent.  The FLAC__stream_encoder_init_*()
117  * functions will do this, so make sure to pay attention to the state
118  * returned by FLAC__stream_encoder_init_*() to make sure that it is
119  * FLAC__STREAM_ENCODER_INIT_STATUS_OK.  Any parameters that are not set
120  * before FLAC__stream_encoder_init_*() will take on the defaults from
121  * the constructor.
122  *
123  * There are three initialization functions, one for setting up the encoder
124  * to encode FLAC data to the client via callbacks, and two for encoding
125  * directly to a file.
126  *
127  * For encoding via callbacks, use FLAC__stream_encoder_init_stream().
128  * You must also supply a write callback which will be called anytime
129  * there is raw encoded data to write.  If the client can seek the output
130  * it is best to also supply seek and tell callbacks, as this allows the
131  * encoder to go back after encoding is finished to write back
132  * information that was collected while encoding, like seek point offsets,
133  * frame sizes, etc.
134  *
135  * For encoding directly to a file, use FLAC__stream_encoder_init_FILE()
136  * or FLAC__stream_encoder_init_file().  Then you must only supply a
137  * filename or open \c FILE*; the encoder will handle all the callbacks
138  * internally.  You may also supply a progress callback for periodic
139  * notification of the encoding progress.
140  *
141  * The call to FLAC__stream_encoder_init_*() currently will also immediately
142  * call the write callback several times, once with the \c fLaC signature,
143  * and once for each encoded metadata block.
144  *
145  * After initializing the instance, the user may feed audio data to the
146  * encoder in one of two ways:
147  *
148  * - Channel separate, through FLAC__stream_encoder_process() - The user
149  *   will pass an array of pointers to buffers, one for each channel, to
150  *   the encoder, each of the same length.  The samples need not be
151  *   block-aligned.
152  * - Channel interleaved, through
153  *   FLAC__stream_encoder_process_interleaved() - The user will pass a single
154  *   pointer to data that is channel-interleaved (i.e. channel0_sample0,
155  *   channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
156  *   Again, the samples need not be block-aligned but they must be
157  *   sample-aligned, i.e. the first value should be channel0_sample0 and
158  *   the last value channelN_sampleM.
159  *
160  * When the user is finished encoding data, it calls
161  * FLAC__stream_encoder_finish(), which causes the encoder to encode any
162  * data still in its input pipe, and call the metadata callback with the
163  * final encoding statistics.  Then the instance may be deleted with
164  * FLAC__stream_encoder_delete() or initialized again to encode another
165  * stream.
166  *
167  * For programs that write their own metadata, but that do not know the
168  * actual metadata until after encoding, it is advantageous to instruct
169  * the encoder to write a PADDING block of the correct size, so that
170  * instead of rewriting the whole stream after encoding, the program can
171  * just overwrite the PADDING block.  If only the maximum size of the
172  * metadata is known, the program can write a slightly larger padding
173  * block, then split it after encoding.
174  *
175  * Make sure you understand how lengths are calculated.  All FLAC metadata
176  * blocks have a 4 byte header which contains the type and length.  This
177  * length does not include the 4 bytes of the header.  See the format page
178  * for the specification of metadata blocks and their lengths.
179  *
180  * \note
181  * If you are writing the FLAC data to a file via callbacks, make sure it
182  * is open for update (e.g. mode "w+" for stdio streams).  This is because
183  * after the first encoding pass, the encoder will try to seek back to the
184  * beginning of the stream, to the STREAMINFO block, to write some data
185  * there.  (If using FLAC__stream_encoder_init_file() or
186  * FLAC__stream_encoder_init_FILE(), the file is managed internally.)
187  *
188  * \note
189  * The "set" functions may only be called when the encoder is in the
190  * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
191  * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
192  * before FLAC__stream_encoder_init().  If this is the case they will
193  * return \c true, otherwise \c false.
194  *
195  * \note
196  * FLAC__stream_encoder_finish() resets all settings to the constructor
197  * defaults.
198  *
199  * \{
200  */
201
202
203 /** State values for a FLAC__StreamEncoder.
204  *
205  * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
206  *
207  * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK
208  * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and
209  * must be deleted with FLAC__stream_encoder_delete().
210  */
211 typedef enum {
212
213         FLAC__STREAM_ENCODER_OK = 0,
214         /**< The encoder is in the normal OK state and samples can be processed. */
215
216         FLAC__STREAM_ENCODER_UNINITIALIZED,
217         /**< The encoder is in the uninitialized state; one of the
218          * FLAC__stream_encoder_init_*() functions must be called before samples
219          * can be processed.
220          */
221
222         FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
223         /**< An error occurred in the underlying verify stream decoder;
224          * check FLAC__stream_encoder_get_verify_decoder_state().
225          */
226
227         FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
228         /**< The verify decoder detected a mismatch between the original
229          * audio signal and the decoded audio signal.
230          */
231
232         FLAC__STREAM_ENCODER_CLIENT_ERROR,
233         /**< One of the callbacks returned a fatal error. */
234
235         FLAC__STREAM_ENCODER_IO_ERROR,
236         /**< An I/O error occurred while opening/reading/writing a file.
237          * Check \c errno.
238          */
239
240         FLAC__STREAM_ENCODER_FRAMING_ERROR,
241         /**< An error occurred while writing the stream; usually, the
242          * write_callback returned an error.
243          */
244
245         FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
246         /**< Memory allocation failed. */
247
248 } FLAC__StreamEncoderState;
249
250 /** Maps a FLAC__StreamEncoderState to a C string.
251  *
252  *  Using a FLAC__StreamEncoderState as the index to this array
253  *  will give the string equivalent.  The contents should not be modified.
254  */
255 extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
256
257 /** Possible return values for the FLAC__stream_encoder_init_*() functions.
258  */
259 typedef enum {
260
261         FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
262         /**< Initialization was successful. */
263
264         FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
265         /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */
266
267         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
268         /**< A required callback was not supplied. */
269
270         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
271         /**< The encoder has an invalid setting for number of channels. */
272
273         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
274         /**< The encoder has an invalid setting for bits-per-sample.
275          * FLAC supports 4-32 bps but the reference encoder currently supports
276          * only up to 24 bps.
277          */
278
279         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
280         /**< The encoder has an invalid setting for the input sample rate. */
281
282         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
283         /**< The encoder has an invalid setting for the block size. */
284
285         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
286         /**< The encoder has an invalid setting for the maximum LPC order. */
287
288         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
289         /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
290
291         FLAC__STREAM_ENCODER_INIT_STATUS_MID_SIDE_CHANNELS_MISMATCH,
292         /**< Mid/side coding was specified but the number of channels is not equal to 2. */
293
294         FLAC__STREAM_ENCODER_INIT_STATUS_ILLEGAL_MID_SIDE_FORCE,
295         /**< Loose mid/side coding was specified but mid/side coding was not. */
296
297         FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
298         /**< The specified block size is less than the maximum LPC order. */
299
300         FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
301         /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */
302
303         FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
304         /**< The metadata input to the encoder is invalid, in one of the following ways:
305          * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
306          * - One of the metadata blocks contains an undefined type
307          * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal()
308          * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal()
309          * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
310          */
311
312         FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
313         /**< FLAC__stream_encoder_init_*() was called when the encoder was
314          * already initialized, usually because
315          * FLAC__stream_encoder_finish() was not called.
316          */
317
318 } FLAC__StreamEncoderInitStatus;
319
320 /** Maps a FLAC__StreamEncoderInitStatus to a C string.
321  *
322  *  Using a FLAC__StreamEncoderInitStatus as the index to this array
323  *  will give the string equivalent.  The contents should not be modified.
324  */
325 extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
326
327 /** Return values for the FLAC__StreamEncoder write callback.
328  */
329 typedef enum {
330
331         FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
332         /**< The write was OK and encoding can continue. */
333
334         FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
335         /**< An unrecoverable error occurred.  The encoder will return from the process call. */
336
337 } FLAC__StreamEncoderWriteStatus;
338
339 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
340  *
341  *  Using a FLAC__StreamEncoderWriteStatus as the index to this array
342  *  will give the string equivalent.  The contents should not be modified.
343  */
344 extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
345
346 /** Return values for the FLAC__StreamEncoder seek callback.
347  */
348 typedef enum {
349
350         FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
351         /**< The seek was OK and encoding can continue. */
352
353         FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
354         /**< An unrecoverable error occurred. */
355
356         FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
357         /**< Client does not support seeking. */
358
359 } FLAC__StreamEncoderSeekStatus;
360
361 /** Maps a FLAC__StreamEncoderSeekStatus to a C string.
362  *
363  *  Using a FLAC__StreamEncoderSeekStatus as the index to this array
364  *  will give the string equivalent.  The contents should not be modified.
365  */
366 extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
367
368
369 /** Return values for the FLAC__StreamEncoder tell callback.
370  */
371 typedef enum {
372
373         FLAC__STREAM_ENCODER_TELL_STATUS_OK,
374         /**< The tell was OK and encoding can continue. */
375
376         FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
377         /**< An unrecoverable error occurred. */
378
379         FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
380         /**< Client does not support seeking. */
381
382 } FLAC__StreamEncoderTellStatus;
383
384 /** Maps a FLAC__StreamEncoderTellStatus to a C string.
385  *
386  *  Using a FLAC__StreamEncoderTellStatus as the index to this array
387  *  will give the string equivalent.  The contents should not be modified.
388  */
389 extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
390
391
392 /***********************************************************************
393  *
394  * class FLAC__StreamEncoder
395  *
396  ***********************************************************************/
397
398 struct FLAC__StreamEncoderProtected;
399 struct FLAC__StreamEncoderPrivate;
400 /** The opaque structure definition for the stream encoder type.
401  *  See the \link flac_stream_encoder stream encoder module \endlink
402  *  for a detailed description.
403  */
404 typedef struct {
405         struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
406         struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
407 } FLAC__StreamEncoder;
408
409 /** Signature for the write callback.
410  *
411  *  A function pointer matching this signature must be passed to
412  *  FLAC__stream_encoder_init_stream().  The supplied function will be called
413  *  by the encoder anytime there is raw encoded data ready to write.  It may
414  *  include metadata mixed with encoded audio frames and the data is not
415  *  guaranteed to be aligned on frame or metadata block boundaries.
416  *
417  *  The only duty of the callback is to write out the \a bytes worth of data
418  *  in \a buffer to the current position in the output stream.  The arguments
419  *  \a samples and \a current_frame are purely informational.  If \a samples
420  *  is greater than \c 0, then \a current_frame will hold the current frame
421  *  number that is being written; otherwise it indicates that the write
422  *  callback is being called to write metadata.
423  *
424  * \note In general, FLAC__StreamEncoder functions which change the
425  * state should not be called on the \a encoder while in the callback.
426  *
427  * \param  encoder  The encoder instance calling the callback.
428  * \param  buffer   An array of encoded data of length \a bytes.
429  * \param  bytes    The byte length of \a buffer.
430  * \param  samples  The number of samples encoded by \a buffer.
431  *                  \c 0 has a special meaning; see above.
432  * \param  current_frame  The number of the current frame being encoded.
433  * \param  client_data  The callee's client data set through
434  *                      FLAC__stream_encoder_init_*().
435  * \retval FLAC__StreamEncoderWriteStatus
436  *    The callee's return status.
437  */
438 typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
439
440 /** Signature for the seek callback.
441  *
442  *  A function pointer matching this signature may be passed to
443  *  FLAC__stream_encoder_init_stream().  The supplied function will be called
444  *  when the encoder needs to seek the output stream.  The encoder will pass
445  *  the absolute byte offset to seek to, 0 meaning the beginning of the stream.
446  *
447  * \note In general, FLAC__StreamEncoder functions which change the
448  * state should not be called on the \a encoder while in the callback.
449  *
450  * \param  encoder  The encoder instance calling the callback.
451  * \param  absolute_byte_offset  The offset from the beginning of the stream
452  *                               to seek to.
453  * \param  client_data  The callee's client data set through
454  *                      FLAC__stream_encoder_init_*().
455  * \retval FLAC__StreamEncoderSeekStatus
456  *    The callee's return status.
457  */
458 typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
459
460 /** Signature for the tell callback.
461  *
462  *  A function pointer matching this signature may be passed to
463  *  FLAC__stream_encoder_init_stream().  The supplied function will be called
464  *  when the encoder needs to know the current position of the output stream.
465  *
466  * \warning
467  * The callback must return the true current byte offset of the output to
468  * which the encoder is writing.  If you are buffering the output, make
469  * sure and take this into account.  If you are writing directly to a
470  * FILE* from your write callback, ftell() is sufficient.  If you are
471  * writing directly to a file descriptor from your write callback, you
472  * can use lseek(fd, SEEK_CUR, 0).  The encoder may later seek back to
473  * these points to rewrite metadata after encoding.
474  *
475  * \note In general, FLAC__StreamEncoder functions which change the
476  * state should not be called on the \a encoder while in the callback.
477  *
478  * \param  encoder  The encoder instance calling the callback.
479  * \param  absolute_byte_offset  The address at which to store the current
480  *                               position of the output.
481  * \param  client_data  The callee's client data set through
482  *                      FLAC__stream_encoder_init_*().
483  * \retval FLAC__StreamEncoderTellStatus
484  *    The callee's return status.
485  */
486 typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
487
488 /** Signature for the metadata callback.
489  *
490  *  A function pointer matching this signature may be passed to
491  *  FLAC__stream_encoder_init_stream().  The supplied function will be called
492  *  once at the end of encoding with the populated STREAMINFO structure.  This
493  *  is so the client can seek back to the beginning of the file and write the
494  *  STREAMINFO block with the correct statistics after encoding (like
495  *  minimum/maximum frame size and total samples).
496  *
497  * \note In general, FLAC__StreamEncoder functions which change the
498  * state should not be called on the \a encoder while in the callback.
499  *
500  * \param  encoder      The encoder instance calling the callback.
501  * \param  metadata     The final populated STREAMINFO block.
502  * \param  client_data  The callee's client data set through
503  *                      FLAC__stream_encoder_init_*().
504  */
505 typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
506
507 /** Signature for the progress callback.
508  *
509  *  A function pointer matching this signature may be passed to
510  *  FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE().
511  *  The supplied function will be called when the encoder has finished
512  *  writing a frame.  The \c total_frames_estimate argument to the
513  *  callback will be based on the value from
514  *  FLAC__file_encoder_set_total_samples_estimate().
515  *
516  * \note In general, FLAC__StreamEncoder functions which change the
517  * state should not be called on the \a encoder while in the callback.
518  *
519  * \param  encoder          The encoder instance calling the callback.
520  * \param  bytes_written    Bytes written so far.
521  * \param  samples_written  Samples written so far.
522  * \param  frames_written   Frames written so far.
523  * \param  total_frames_estimate  The estimate of the total number of
524  *                                frames to be written.
525  * \param  client_data      The callee's client data set through
526  *                          FLAC__stream_encoder_init_*().
527  */
528 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);
529
530
531 /***********************************************************************
532  *
533  * Class constructor/destructor
534  *
535  ***********************************************************************/
536
537 /** Create a new stream encoder instance.  The instance is created with
538  *  default settings; see the individual FLAC__stream_encoder_set_*()
539  *  functions for each setting's default.
540  *
541  * \retval FLAC__StreamEncoder*
542  *    \c NULL if there was an error allocating memory, else the new instance.
543  */
544 FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new();
545
546 /** Free an encoder instance.  Deletes the object pointed to by \a encoder.
547  *
548  * \param encoder  A pointer to an existing encoder.
549  * \assert
550  *    \code encoder != NULL \endcode
551  */
552 FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
553
554
555 /***********************************************************************
556  *
557  * Public class method prototypes
558  *
559  ***********************************************************************/
560
561 /** Set the "verify" flag.  If \c true, the encoder will verify it's own
562  *  encoded output by feeding it through an internal decoder and comparing
563  *  the original signal against the decoded signal.  If a mismatch occurs,
564  *  the process call will return \c false.  Note that this will slow the
565  *  encoding process by the extra time required for decoding and comparison.
566  *
567  * \default \c false
568  * \param  encoder  An encoder instance to set.
569  * \param  value    Flag value (see above).
570  * \assert
571  *    \code encoder != NULL \endcode
572  * \retval FLAC__bool
573  *    \c false if the encoder is already initialized, else \c true.
574  */
575 FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
576
577 /** Set the <A HREF="../format.html#subset">Subset</A> flag.  If \c true,
578  *  the encoder will comply with the Subset and will check the
579  *  settings during FLAC__stream_encoder_init() to see if all settings
580  *  comply.  If \c false, the settings may take advantage of the full
581  *  range that the format allows.
582  *
583  *  Make sure you know what it entails before setting this to \c false.
584  *
585  * \default \c true
586  * \param  encoder  An encoder instance to set.
587  * \param  value    Flag value (see above).
588  * \assert
589  *    \code encoder != NULL \endcode
590  * \retval FLAC__bool
591  *    \c false if the encoder is already initialized, else \c true.
592  */
593 FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
594
595 /** Set to \c true to enable mid-side encoding on stereo input.  The
596  *  number of channels must be 2.  Set to \c false to use only
597  *  independent channel coding.
598  *
599  * \default \c false
600  * \param  encoder  An encoder instance to set.
601  * \param  value    Flag value (see above).
602  * \assert
603  *    \code encoder != NULL \endcode
604  * \retval FLAC__bool
605  *    \c false if the encoder is already initialized, else \c true.
606  */
607 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
608
609 /** Set to \c true to enable adaptive switching between mid-side and
610  *  left-right encoding on stereo input.  The number of channels must
611  *  be 2.  Set to \c false to use exhaustive searching.  In either
612  *  case, the mid/side stereo setting must be \c true.
613  *
614  * \default \c false
615  * \param  encoder  An encoder instance to set.
616  * \param  value    Flag value (see above).
617  * \assert
618  *    \code encoder != NULL \endcode
619  * \retval FLAC__bool
620  *    \c false if the encoder is already initialized, else \c true.
621  */
622 FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
623
624 /** Set the number of channels to be encoded.
625  *
626  * \default \c 2
627  * \param  encoder  An encoder instance to set.
628  * \param  value    See above.
629  * \assert
630  *    \code encoder != NULL \endcode
631  * \retval FLAC__bool
632  *    \c false if the encoder is already initialized, else \c true.
633  */
634 FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
635
636 /** Set the sample resolution of the input to be encoded.
637  *
638  * \warning
639  * Do not feed the encoder data that is wider than the value you
640  * set here or you will generate an invalid stream.
641  *
642  * \default \c 16
643  * \param  encoder  An encoder instance to set.
644  * \param  value    See above.
645  * \assert
646  *    \code encoder != NULL \endcode
647  * \retval FLAC__bool
648  *    \c false if the encoder is already initialized, else \c true.
649  */
650 FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
651
652 /** Set the sample rate (in Hz) of the input to be encoded.
653  *
654  * \default \c 44100
655  * \param  encoder  An encoder instance to set.
656  * \param  value    See above.
657  * \assert
658  *    \code encoder != NULL \endcode
659  * \retval FLAC__bool
660  *    \c false if the encoder is already initialized, else \c true.
661  */
662 FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
663
664 /** Set the blocksize to use while encoding.
665  *
666  * \default \c 1152
667  * \param  encoder  An encoder instance to set.
668  * \param  value    See above.
669  * \assert
670  *    \code encoder != NULL \endcode
671  * \retval FLAC__bool
672  *    \c false if the encoder is already initialized, else \c true.
673  */
674 FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
675
676 /** Sets the apodization function(s) the encoder will use when windowing
677  *  audio data for LPC analysis.
678  *
679  * The \a specification is a plain ASCII string which specifies exactly
680  * which functions to use.  There may be more than one (up to 32),
681  * separated by \c ';' characters.  Some functions take one or more
682  * comma-separated arguments in parentheses.
683  *
684  * The available functions are \c bartlett, \c bartlett_hann,
685  * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop,
686  * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall,
687  * \c rectangle, \c triangle, \c tukey(P), \c welch.
688  *
689  * For \c gauss(STDDEV), STDDEV specifies the standard deviation
690  * (0<STDDEV<=0.5).
691  *
692  * For \c tukey(P), P specifies the fraction of the window that is
693  * tapered (0<=P<=1).  P=0 corresponds to \c rectangle and P=1
694  * corresponds to \c hann.
695  *
696  * Example specifications are \c "blackman" or
697  * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)"
698  *
699  * Any function that is specified erroneously is silently dropped.  Up
700  * to 32 functions are kept, the rest are dropped.  If the specification
701  * is empty the encoder defaults to \c "tukey(0.5)".
702  *
703  * When more than one function is specified, then for every subframe the
704  * encoder will try each of them separately and choose the window that
705  * results in the smallest compressed subframe.
706  *
707  * Note that each function specified causes the encoder to occupy a
708  * floating point array in which to store the window.
709  *
710  * \default \c "tukey(0.5)"
711  * \param  encoder        An encoder instance to set.
712  * \param  specification  See above.
713  * \assert
714  *    \code encoder != NULL \endcode
715  *    \code specification != NULL \endcode
716  * \retval FLAC__bool
717  *    \c false if the encoder is already initialized, else \c true.
718  */
719 /* @@@@add to unit tests*/
720 FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
721
722 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
723  *
724  * \default \c 0
725  * \param  encoder  An encoder instance to set.
726  * \param  value    See above.
727  * \assert
728  *    \code encoder != NULL \endcode
729  * \retval FLAC__bool
730  *    \c false if the encoder is already initialized, else \c true.
731  */
732 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
733
734 /** Set the precision, in bits, of the quantized linear predictor
735  *  coefficients, or \c 0 to let the encoder select it based on the
736  *  blocksize.
737  *
738  * \note
739  * In the current implementation, qlp_coeff_precision + bits_per_sample must
740  * be less than 32.
741  *
742  * \default \c 0
743  * \param  encoder  An encoder instance to set.
744  * \param  value    See above.
745  * \assert
746  *    \code encoder != NULL \endcode
747  * \retval FLAC__bool
748  *    \c false if the encoder is already initialized, else \c true.
749  */
750 FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
751
752 /** Set to \c false to use only the specified quantized linear predictor
753  *  coefficient precision, or \c true to search neighboring precision
754  *  values and use the best one.
755  *
756  * \default \c false
757  * \param  encoder  An encoder instance to set.
758  * \param  value    See above.
759  * \assert
760  *    \code encoder != NULL \endcode
761  * \retval FLAC__bool
762  *    \c false if the encoder is already initialized, else \c true.
763  */
764 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
765
766 /** Deprecated.  Setting this value has no effect.
767  *
768  * \default \c false
769  * \param  encoder  An encoder instance to set.
770  * \param  value    See above.
771  * \assert
772  *    \code encoder != NULL \endcode
773  * \retval FLAC__bool
774  *    \c false if the encoder is already initialized, else \c true.
775  */
776 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
777
778 /** Set to \c false to let the encoder estimate the best model order
779  *  based on the residual signal energy, or \c true to force the
780  *  encoder to evaluate all order models and select the best.
781  *
782  * \default \c false
783  * \param  encoder  An encoder instance to set.
784  * \param  value    See above.
785  * \assert
786  *    \code encoder != NULL \endcode
787  * \retval FLAC__bool
788  *    \c false if the encoder is already initialized, else \c true.
789  */
790 FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
791
792 /** Set the minimum partition order to search when coding the residual.
793  *  This is used in tandem with
794  *  FLAC__stream_encoder_set_max_residual_partition_order().
795  *
796  *  The partition order determines the context size in the residual.
797  *  The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
798  *
799  *  Set both min and max values to \c 0 to force a single context,
800  *  whose Rice parameter is based on the residual signal variance.
801  *  Otherwise, set a min and max order, and the encoder will search
802  *  all orders, using the mean of each context for its Rice parameter,
803  *  and use the best.
804  *
805  * \default \c 0
806  * \param  encoder  An encoder instance to set.
807  * \param  value    See above.
808  * \assert
809  *    \code encoder != NULL \endcode
810  * \retval FLAC__bool
811  *    \c false if the encoder is already initialized, else \c true.
812  */
813 FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
814
815 /** Set the maximum partition order to search when coding the residual.
816  *  This is used in tandem with
817  *  FLAC__stream_encoder_set_min_residual_partition_order().
818  *
819  *  The partition order determines the context size in the residual.
820  *  The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
821  *
822  *  Set both min and max values to \c 0 to force a single context,
823  *  whose Rice parameter is based on the residual signal variance.
824  *  Otherwise, set a min and max order, and the encoder will search
825  *  all orders, using the mean of each context for its Rice parameter,
826  *  and use the best.
827  *
828  * \default \c 0
829  * \param  encoder  An encoder instance to set.
830  * \param  value    See above.
831  * \assert
832  *    \code encoder != NULL \endcode
833  * \retval FLAC__bool
834  *    \c false if the encoder is already initialized, else \c true.
835  */
836 FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
837
838 /** Deprecated.  Setting this value has no effect.
839  *
840  * \default \c 0
841  * \param  encoder  An encoder instance to set.
842  * \param  value    See above.
843  * \assert
844  *    \code encoder != NULL \endcode
845  * \retval FLAC__bool
846  *    \c false if the encoder is already initialized, else \c true.
847  */
848 FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
849
850 /** Set an estimate of the total samples that will be encoded.
851  *  This is merely an estimate and may be set to \c 0 if unknown.
852  *  This value will be written to the STREAMINFO block before encoding,
853  *  and can remove the need for the caller to rewrite the value later
854  *  if the value is known before encoding.
855  *
856  * \default \c 0
857  * \param  encoder  An encoder instance to set.
858  * \param  value    See above.
859  * \assert
860  *    \code encoder != NULL \endcode
861  * \retval FLAC__bool
862  *    \c false if the encoder is already initialized, else \c true.
863  */
864 FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
865
866 /** Set the metadata blocks to be emitted to the stream before encoding.
867  *  A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
868  *  array of pointers to metadata blocks.  The array is non-const since
869  *  the encoder may need to change the \a is_last flag inside them, and
870  *  in some cases update seek point offsets.  Otherwise, the encoder will
871  *  not modify or free the blocks.  It is up to the caller to free the
872  *  metadata blocks after encoding.
873  *
874  * \note
875  * The encoder stores only the \a metadata pointer; the passed-in array
876  * must survive at least until after FLAC__stream_encoder_init() returns.
877  * Do not modify the array or free the blocks until then.
878  *
879  * \note
880  * The STREAMINFO block is always written and no STREAMINFO block may
881  * occur in the supplied array.
882  *
883  * \note
884  * By default the encoder does not create a SEEKTABLE.  If one is supplied
885  * in the \a metadata array, but the client has specified that it does not
886  * support seeking, then the SEEKTABLE will be written verbatim.  However
887  * by itself this is not very useful as the client will not know the stream
888  * offsets for the seekpoints ahead of time.  In order to get a proper
889  * seektable the client must support seeking.  See next note.
890  *
891  * \note
892  * SEEKTABLE blocks are handled specially.  Since you will not know
893  * the values for the seek point stream offsets, you should pass in
894  * a SEEKTABLE 'template', that is, a SEEKTABLE object with the
895  * required sample numbers (or placeholder points), with \c 0 for the
896  * \a frame_samples and \a stream_offset fields for each point.  If the
897  * client has specified that it supports seeking by providing a seek
898  * callback to FLAC__stream_encoder_init_stream() (or by using
899  * FLAC__stream_encoder_init_file() or FLAC__stream_encoder_init_FILE()),
900  * then while it is encoding the encoder will fill the stream offsets in
901  * for you and when encoding is finished, it will seek back and write the
902  * real values into the SEEKTABLE block in the stream.  There are helper
903  * routines for manipulating seektable template blocks; see metadata.h:
904  * FLAC__metadata_object_seektable_template_*().  If the client does
905  * not support seeking, the SEEKTABLE will have inaccurate offsets which
906  * will slow down or remove the ability to seek in the FLAC stream.
907  *
908  * \note
909  * The encoder instance \b will modify the first \c SEEKTABLE block
910  * as it transforms the template to a valid seektable while encoding,
911  * but it is still up to the caller to free all metadata blocks after
912  * encoding.
913  *
914  * \note
915  * A VORBIS_COMMENT block may be supplied.  The vendor string in it
916  * will be ignored.  libFLAC will use it's own vendor string. libFLAC
917  * will not modify the passed-in VORBIS_COMMENT's vendor string, it
918  * will simply write it's own into the stream.  If no VORBIS_COMMENT
919  * block is present in the \a metadata array, libFLAC will write an
920  * empty one, containing only the vendor string.
921  *
922  * \default \c NULL, 0
923  * \param  encoder     An encoder instance to set.
924  * \param  metadata    See above.
925  * \param  num_blocks  See above.
926  * \assert
927  *    \code encoder != NULL \endcode
928  * \retval FLAC__bool
929  *    \c false if the encoder is already initialized, else \c true.
930  */
931 FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
932
933 /** Get the current encoder state.
934  *
935  * \param  encoder  An encoder instance to query.
936  * \assert
937  *    \code encoder != NULL \endcode
938  * \retval FLAC__StreamEncoderState
939  *    The current encoder state.
940  */
941 FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
942
943 /** Get the state of the verify stream decoder.
944  *  Useful when the stream encoder state is
945  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.
946  *
947  * \param  encoder  An encoder instance to query.
948  * \assert
949  *    \code encoder != NULL \endcode
950  * \retval FLAC__StreamDecoderState
951  *    The verify stream decoder state.
952  */
953 FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
954
955 /** Get the current encoder state as a C string.
956  *  This version automatically resolves
957  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the
958  *  verify decoder's state.
959  *
960  * \param  encoder  A encoder instance to query.
961  * \assert
962  *    \code encoder != NULL \endcode
963  * \retval const char *
964  *    The encoder state as a C string.  Do not modify the contents.
965  */
966 FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
967
968 /** Get relevant values about the nature of a verify decoder error.
969  *  Useful when the stream encoder state is
970  *  \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR.  The arguments should
971  *  be addresses in which the stats will be returned, or NULL if value
972  *  is not desired.
973  *
974  * \param  encoder  An encoder instance to query.
975  * \param  absolute_sample  The absolute sample number of the mismatch.
976  * \param  frame_number  The number of the frame in which the mismatch occurred.
977  * \param  channel       The channel in which the mismatch occurred.
978  * \param  sample        The number of the sample (relative to the frame) in
979  *                       which the mismatch occurred.
980  * \param  expected      The expected value for the sample in question.
981  * \param  got           The actual value returned by the decoder.
982  * \assert
983  *    \code encoder != NULL \endcode
984  */
985 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);
986
987 /** Get the "verify" flag.
988  *
989  * \param  encoder  An encoder instance to query.
990  * \assert
991  *    \code encoder != NULL \endcode
992  * \retval FLAC__bool
993  *    See FLAC__stream_encoder_set_verify().
994  */
995 FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
996
997 /** Get the <A HREF="../format.html#subset>Subset</A> flag.
998  *
999  * \param  encoder  An encoder instance to query.
1000  * \assert
1001  *    \code encoder != NULL \endcode
1002  * \retval FLAC__bool
1003  *    See FLAC__stream_encoder_set_streamable_subset().
1004  */
1005 FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
1006
1007 /** Get the "mid/side stereo coding" flag.
1008  *
1009  * \param  encoder  An encoder instance to query.
1010  * \assert
1011  *    \code encoder != NULL \endcode
1012  * \retval FLAC__bool
1013  *    See FLAC__stream_encoder_get_do_mid_side_stereo().
1014  */
1015 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1016
1017 /** Get the "adaptive mid/side switching" flag.
1018  *
1019  * \param  encoder  An encoder instance to query.
1020  * \assert
1021  *    \code encoder != NULL \endcode
1022  * \retval FLAC__bool
1023  *    See FLAC__stream_encoder_set_loose_mid_side_stereo().
1024  */
1025 FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
1026
1027 /** Get the number of input channels being processed.
1028  *
1029  * \param  encoder  An encoder instance to query.
1030  * \assert
1031  *    \code encoder != NULL \endcode
1032  * \retval unsigned
1033  *    See FLAC__stream_encoder_set_channels().
1034  */
1035 FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
1036
1037 /** Get the input sample resolution setting.
1038  *
1039  * \param  encoder  An encoder instance to query.
1040  * \assert
1041  *    \code encoder != NULL \endcode
1042  * \retval unsigned
1043  *    See FLAC__stream_encoder_set_bits_per_sample().
1044  */
1045 FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
1046
1047 /** Get the input sample rate setting.
1048  *
1049  * \param  encoder  An encoder instance to query.
1050  * \assert
1051  *    \code encoder != NULL \endcode
1052  * \retval unsigned
1053  *    See FLAC__stream_encoder_set_sample_rate().
1054  */
1055 FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
1056
1057 /** Get the blocksize setting.
1058  *
1059  * \param  encoder  An encoder instance to query.
1060  * \assert
1061  *    \code encoder != NULL \endcode
1062  * \retval unsigned
1063  *    See FLAC__stream_encoder_set_blocksize().
1064  */
1065 FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
1066
1067 /** Get the maximum LPC order setting.
1068  *
1069  * \param  encoder  An encoder instance to query.
1070  * \assert
1071  *    \code encoder != NULL \endcode
1072  * \retval unsigned
1073  *    See FLAC__stream_encoder_set_max_lpc_order().
1074  */
1075 FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
1076
1077 /** Get the quantized linear predictor coefficient precision setting.
1078  *
1079  * \param  encoder  An encoder instance to query.
1080  * \assert
1081  *    \code encoder != NULL \endcode
1082  * \retval unsigned
1083  *    See FLAC__stream_encoder_set_qlp_coeff_precision().
1084  */
1085 FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
1086
1087 /** Get the qlp coefficient precision search flag.
1088  *
1089  * \param  encoder  An encoder instance to query.
1090  * \assert
1091  *    \code encoder != NULL \endcode
1092  * \retval FLAC__bool
1093  *    See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
1094  */
1095 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
1096
1097 /** Get the "escape coding" flag.
1098  *
1099  * \param  encoder  An encoder instance to query.
1100  * \assert
1101  *    \code encoder != NULL \endcode
1102  * \retval FLAC__bool
1103  *    See FLAC__stream_encoder_set_do_escape_coding().
1104  */
1105 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
1106
1107 /** Get the exhaustive model search flag.
1108  *
1109  * \param  encoder  An encoder instance to query.
1110  * \assert
1111  *    \code encoder != NULL \endcode
1112  * \retval FLAC__bool
1113  *    See FLAC__stream_encoder_set_do_exhaustive_model_search().
1114  */
1115 FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
1116
1117 /** Get the minimum residual partition order setting.
1118  *
1119  * \param  encoder  An encoder instance to query.
1120  * \assert
1121  *    \code encoder != NULL \endcode
1122  * \retval unsigned
1123  *    See FLAC__stream_encoder_set_min_residual_partition_order().
1124  */
1125 FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
1126
1127 /** Get maximum residual partition order setting.
1128  *
1129  * \param  encoder  An encoder instance to query.
1130  * \assert
1131  *    \code encoder != NULL \endcode
1132  * \retval unsigned
1133  *    See FLAC__stream_encoder_set_max_residual_partition_order().
1134  */
1135 FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
1136
1137 /** Get the Rice parameter search distance setting.
1138  *
1139  * \param  encoder  An encoder instance to query.
1140  * \assert
1141  *    \code encoder != NULL \endcode
1142  * \retval unsigned
1143  *    See FLAC__stream_encoder_set_rice_parameter_search_dist().
1144  */
1145 FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
1146
1147 /** Get the previously set estimate of the total samples to be encoded.
1148  *  The encoder merely mimics back the value given to
1149  *  FLAC__stream_encoder_set_total_samples_estimate() since it has no
1150  *  other way of knowing how many samples the user will encode.
1151  *
1152  * \param  encoder  An encoder instance to set.
1153  * \assert
1154  *    \code encoder != NULL \endcode
1155  * \retval FLAC__uint64
1156  *    See FLAC__stream_encoder_get_total_samples_estimate().
1157  */
1158 FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
1159
1160 /** Initialize the encoder instance.
1161  *
1162  *  This flavor of initialization sets up the encoder to encode to a stream.
1163  *  I/O is performed via callbacks to the client.  For encoding to a plain file
1164  *  via filename or open \c FILE*, FLAC__stream_encoder_init_file() and
1165  *  FLAC__stream_encoder_init_FILE() provide a simpler interface.
1166  *
1167  *  This function should be called after FLAC__stream_encoder_new() and
1168  *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1169  *  or FLAC__stream_encoder_process_interleaved().
1170  *  initialization succeeded.
1171  *
1172  *  The call to FLAC__stream_encoder_init_stream() currently will also immediately
1173  *  call the write callback several times, once with the \c fLaC signature,
1174  *  and once for each encoded metadata block.
1175  *
1176  * \param  encoder            An uninitialized encoder instance.
1177  * \param  write_callback     See FLAC__StreamEncoderWriteCallback.  This
1178  *                            pointer must not be \c NULL.
1179  * \param  seek_callback      See FLAC__StreamEncoderSeekCallback.  This
1180  *                            pointer may be \c NULL if seeking is not
1181  *                            supported.  The encoder uses seeking to go back
1182  *                            and write some some stream statistics to the
1183  *                            STREAMINFO block; this is recommended but not
1184  *                            necessary to create a valid FLAC stream.  If
1185  *                            \a seek_callback is not \c NULL then a
1186  *                            \a tell_callback must also be supplied.
1187  *                            Alternatively, a dummy seek callback that just
1188  *                            returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
1189  *                            may also be supplied, all though this is slightly
1190  *                            less efficient for the decoder.
1191  * \param  tell_callback      See FLAC__StreamEncoderTellCallback.  This
1192  *                            pointer may be \c NULL if seeking is not
1193  *                            supported.  If \a seek_callback is \c NULL then
1194  *                            this argument will be ignored.  If
1195  *                            \a seek_callback is not \c NULL then a
1196  *                            \a tell_callback must also be supplied.
1197  *                            Alternatively, a dummy tell callback that just
1198  *                            returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
1199  *                            may also be supplied, all though this is slightly
1200  *                            less efficient for the decoder.
1201  * \param  metadata_callback  See FLAC__StreamEncoderMetadataCallback.  This
1202  *                            pointer may be \c NULL if the callback is not
1203  *                            desired.  If the client provides a seek callback,
1204  *                            this function is not necessary as the encoder
1205  *                            will automatically seek back and update the
1206  *                            STREAMINFO block.  It may also be \c NULL if the
1207  *                            client does not support seeking, since it will
1208  *                            have no way of going back to update the
1209  *                            STREAMINFO.  However the client can still supply
1210  *                            a callback if it would like to know the details
1211  *                            from the STREAMINFO.
1212  * \param  client_data        This value will be supplied to callbacks in their
1213  *                            \a client_data argument.
1214  * \assert
1215  *    \code encoder != NULL \endcode
1216  * \retval FLAC__StreamEncoderInitStatus
1217  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1218  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1219  */
1220 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);
1221
1222 /** Initialize the encoder instance.
1223  *
1224  *  This flavor of initialization sets up the encoder to encode to a plain
1225  *  file.  For non-stdio streams, you must use
1226  *  FLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
1227  *
1228  *  This function should be called after FLAC__stream_encoder_new() and
1229  *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1230  *  or FLAC__stream_encoder_process_interleaved().
1231  *  initialization succeeded.
1232  *
1233  *  The call to FLAC__stream_encoder_init_stream() currently will also immediately
1234  *  call the write callback several times, once with the \c fLaC signature,
1235  *  and once for each encoded metadata block.
1236  *
1237  * \param  encoder            An uninitialized encoder instance.
1238  * \param  file               An open file.  The file should have been opened
1239  *                            with mode \c "w+b" and rewound.  The file
1240  *                            becomes owned by the encoder and should not be
1241  *                            manipulated by the client while encoding.
1242  *                            Unless \a file is \c stdout, it will be closed
1243  *                            when FLAC__stream_encoder_finish() is called.
1244  *                            Note however that a proper SEEKTABLE cannot be
1245  *                            created when encoding to \c stdout since it is
1246  *                            not seekable.
1247  * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
1248  *                            pointer may be \c NULL if the callback is not
1249  *                            desired.
1250  * \param  client_data        This value will be supplied to callbacks in their
1251  *                            \a client_data argument.
1252  * \assert
1253  *    \code encoder != NULL \endcode
1254  *    \code file != NULL \endcode
1255  * \retval FLAC__StreamEncoderInitStatus
1256  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1257  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1258  */
1259 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1260
1261 /** Initialize the encoder instance.
1262  *
1263  *  This flavor of initialization sets up the encoder to encode to a plain
1264  *  file.  If POSIX fopen() semantics are not sufficient (for example,
1265  *  with Unicode filenames on Windows), you must use
1266  *  FLAC__stream_encodeR_init_FILE(), or FLAC__stream_encoder_init_stream()
1267  *  and provide callbacks for the I/O.
1268  *
1269  *  This function should be called after FLAC__stream_encoder_new() and
1270  *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
1271  *  or FLAC__stream_encoder_process_interleaved().
1272  *  initialization succeeded.
1273  *
1274  *  The call to FLAC__stream_encoder_init_stream() currently will also immediately
1275  *  call the write callback several times, once with the \c fLaC signature,
1276  *  and once for each encoded metadata block.
1277  *
1278  * \param  encoder            An uninitialized encoder instance.
1279  * \param  filename           The name of the file to encode to.  The file will
1280  *                            be opened with fopen().  Use \c NULL to encode to
1281  *                            \c stdout.  Note however that a proper SEEKTABLE
1282  *                            cannot be created when encoding to \c stdout since
1283  *                            it is not seekable.
1284  * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
1285  *                            pointer may be \c NULL if the callback is not
1286  *                            desired.
1287  * \param  client_data        This value will be supplied to callbacks in their
1288  *                            \a client_data argument.
1289  * \assert
1290  *    \code encoder != NULL \endcode
1291  * \retval FLAC__StreamEncoderInitStatus
1292  *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
1293  *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
1294  */
1295 FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
1296
1297 /** Finish the encoding process.
1298  *  Flushes the encoding buffer, releases resources, resets the encoder
1299  *  settings to their defaults, and returns the encoder state to
1300  *  FLAC__STREAM_ENCODER_UNINITIALIZED.  Note that this can generate
1301  *  one or more write callbacks before returning, and will generate
1302  *  a metadata callback.
1303  *
1304  *  In the event of a prematurely-terminated encode, it is not strictly
1305  *  necessary to call this immediately before FLAC__stream_encoder_delete()
1306  *  but it is good practice to match every FLAC__stream_encoder_init()
1307  *  with a FLAC__stream_encoder_finish().
1308  *
1309  * \param  encoder  An uninitialized encoder instance.
1310  * \assert
1311  *    \code encoder != NULL \endcode
1312  */
1313 FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
1314
1315 /** Submit data for encoding.
1316  *  This version allows you to supply the input data via an array of
1317  *  pointers, each pointer pointing to an array of \a samples samples
1318  *  representing one channel.  The samples need not be block-aligned,
1319  *  but each channel should have the same number of samples.
1320  *
1321  *  For applications where channel order is important, channels must
1322  *  follow the order as described in the
1323  *  <A HREF="../format.html#frame_header">frame header</A>.
1324  *
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.
1328  * \assert
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
1334  *    went wrong.
1335  */
1336 FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
1337
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.
1345  *
1346  *  For applications where channel order is important, channels must
1347  *  follow the order as described in the
1348  *  <A HREF="../format.html#frame_header">frame header</A>.
1349  *
1350  * \param  encoder  An initialized encoder instance in the OK state.
1351  * \param  buffer   An array of channel-interleaved data (see above).
1352  * \param  samples  The number of samples in one channel, the same as for
1353  *                  FLAC__stream_encoder_process().  For example, if
1354  *                  encoding two channels, \c 1000 \a samples corresponds
1355  *                  to a \a buffer of 2000 values.
1356  * \assert
1357  *    \code encoder != NULL \endcode
1358  *    \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
1359  * \retval FLAC__bool
1360  *    \c true if successful, else \c false; in this case, check the
1361  *    encoder state with FLAC__stream_encoder_get_state() to see what
1362  *    went wrong.
1363  */
1364 FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
1365
1366 /* \} */
1367
1368 #ifdef __cplusplus
1369 }
1370 #endif
1371
1372 #endif