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