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