make typedefs for callbacks
[platform/upstream/flac.git] / include / FLAC / stream_encoder.h
1 /* libFLAC - Free Lossless Audio Codec library
2  * Copyright (C) 2000,2001,2002  Josh Coalson
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA  02111-1307, USA.
18  */
19
20 #ifndef FLAC__STREAM_ENCODER_H
21 #define FLAC__STREAM_ENCODER_H
22
23 #include "format.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 /** \file include/FLAC/stream_encoder.h
31  *
32  *  \brief
33  *  This module contains the functions which implement the stream
34  *  encoder.
35  *
36  *  See the detailed documentation in the
37  *  \link flac_stream_encoder stream encoder \endlink module.
38  */
39
40 /** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
41  *  \ingroup flac
42  *
43  *  \brief
44  *  This module describes the two encoder layers provided by libFLAC.
45  *
46  * For encoding FLAC streams, libFLAC provides two layers of access.  The
47  * lowest layer is stream-level encoding, and the highest is file-level
48  * encoding.  The interfaces are described in the \link flac_stream_encoder
49  * stream encoder \endlink and \link flac_file_encoder file encoder \endlink
50  * modules respectively.  Typically you will choose the highest layer that
51  * your output source will support.
52  *
53  * The stream encoder relies on callbacks for writing the data and
54  * metadata. The file encoder provides these callbacks internally and you
55  * need only supply the filename.
56  */
57
58 /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
59  *  \ingroup flac_encoder
60  *
61  *  \brief
62  *  This module contains the functions which implement the stream
63  *  encoder.
64  *
65  * The basic usage of this encoder is as follows:
66  * - The program creates an instance of an encoder using
67  *   FLAC__stream_encoder_new().
68  * - The program overrides the default settings and sets callbacks for
69  *   writing and metadata reporting using
70  *   FLAC__stream_encoder_set_*() functions.
71  * - The program initializes the instance to validate the settings and
72  *   prepare for encoding using FLAC__stream_encoder_init().
73  * - The program calls FLAC__stream_encoder_process() or
74  *   FLAC__stream_encoder_process_interleaved() to encode data, which
75  *   subsequently calls the callbacks when there is encoder data ready
76  *   to be written.
77  * - The program finishes the encoding with FLAC__stream_encoder_finish(),
78  *   which causes the encoder to encode any data still in its input pipe,
79  *   call the metadata callback with the final encoding statistics, and
80  *   finally reset the encoder to the uninitialized state.
81  * - The instance may be used again or deleted with
82  *   FLAC__stream_encoder_delete().
83  *
84  * In more detail, the stream encoder functions similarly to the
85  * \link flac_stream_decoder stream decoder \endlink, but has fewer
86  * callbacks and more options.  Typically the user will create a new
87  * instance by calling FLAC__stream_encoder_new(), then set the necessary
88  * parameters and callbacks with FLAC__stream_encoder_set_*(), and
89  * initialize it by calling FLAC__stream_encoder_init().
90  *
91  * Unlike the decoders, the stream encoder has many options that can
92  * affect the speed and compression ratio.  When setting these parameters
93  * you should have some basic knowledge of the format (see the
94  * <A HREF="../documentation.html#format">user-level documentation</A>
95  * or the <A HREF="../format.html">formal description</A>).  The
96  * FLAC__stream_encoder_set_*() functions themselves do not validate the
97  * values as many are interdependent.  The FLAC__stream_encoder_init()
98  * function will do this, so make sure to pay attention to the state
99  * returned by FLAC__stream_encoder_init() to make sure that it is
100  * FLAC__STREAM_ENCODER_OK.  Any parameters that are not set before
101  * FLAC__stream_encoder_init() will take on the defaults from the
102  * constructor.
103  *
104  * The user must provide function pointers for the following callbacks:
105  *
106  * - Write callback - This function is called by the encoder anytime there
107  *   is raw encoded data to write.  It may include metadata mixed with
108  *   encoded audio frames and the data is not guaranteed to be aligned on
109  *   frame or metadata block boundaries.
110  * - Metadata callback - This function is called once at the end of
111  *   encoding with the populated STREAMINFO structure.  This is so file
112  *   encoders can seek back to the beginning of the file and write the
113  *   STREAMINFO block with the correct statistics after encoding (like
114  *   minimum/maximum frame size).
115  *
116  * The call to FLAC__stream_encoder_init() currently will also immediately
117  * call the write callback several times, once with the \c fLaC signature,
118  * and once for each encoded metadata block.
119  *
120  * After initializing the instance, the user may feed audio data to the
121  * encoder in one of two ways:
122  *
123  * - Channel separate, through FLAC__stream_encoder_process() - The user
124  *   will pass an array of pointers to buffers, one for each channel, to
125  *   the encoder, each of the same length.  The samples need not be
126  *   block-aligned.
127  * - Channel interleaved, through
128  *   FLAC__stream_encoder_process_interleaved() - The user will pass a single
129  *   pointer to data that is channel-interleaved (i.e. channel0_sample0,
130  *   channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
131  *   Again, the samples need not be block-aligned but they must be
132  *   sample-aligned, i.e. the first value should be channel0_sample0 and
133  *   the last value channelN_sampleM.
134  *
135  * When the user is finished encoding data, it calls
136  * FLAC__stream_encoder_finish(), which causes the encoder to encode any
137  * data still in its input pipe, and call the metadata callback with the
138  * final encoding statistics.  Then the instance may be deleted with
139  * FLAC__stream_encoder_delete() or initialized again to encode another
140  * stream.
141  *
142  * For programs that write their own metadata, but that do not know the
143  * actual metadata until after encoding, it is advantageous to instruct
144  * the encoder to write a PADDING block of the correct size, so that
145  * instead of rewriting the whole stream after encoding, the program can
146  * just overwrite the PADDING block.  If only the maximum size of the
147  * metadata is known, the program can write a slightly larger padding
148  * block, then split it after encoding.
149  *
150  * Make sure you understand how lengths are calculated.  All FLAC metadata
151  * blocks have a 4 byte header which contains the type and length.  This
152  * length does not include the 4 bytes of the header.  See the format page
153  * for the specification of metadata blocks and their lengths.
154  *
155  * \note
156  * The "set" functions may only be called when the encoder is in the
157  * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
158  * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
159  * before FLAC__stream_encoder_init().  If this is the case they will
160  * return \c true, otherwise \c false.
161  *
162  * \note
163  * FLAC__stream_encoder_finish() resets all settings to the constructor
164  * defaults, including the callbacks.
165  *
166  * \{
167  */
168
169
170 /** State values for a FLAC__StreamEncoder
171  *
172  *  The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
173  */
174 typedef enum {
175
176         FLAC__STREAM_ENCODER_OK = 0,
177         /**< The encoder is in the normal OK state. */
178
179         FLAC__STREAM_ENCODER_INVALID_CALLBACK,
180         /**< The encoder was initialized before setting all the required callbacks. */
181
182         FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
183         /**< The encoder has an invalid setting for number of channels. */
184
185         FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
186         /**< The encoder has an invalid setting for bits-per-sample.
187          * FLAC supports 4-32 bps but the reference encoder currently supports
188          * only up to 24 bps.
189          */
190
191         FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
192         /**< The encoder has an invalid setting for the input sample rate. */
193
194         FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
195         /**< The encoder has an invalid setting for the block size. */
196
197         FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
198         /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
199
200         FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
201         /**< Mid/side coding was specified but the number of channels is not equal to 2. */
202
203         FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
204         /**< Deprecated. */
205
206         FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
207         /**< Loose mid/side coding was specified but mid/side coding was not. */
208
209         FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
210         /**< The specified block size is less than the maximum LPC order. */
211
212         FLAC__STREAM_ENCODER_NOT_STREAMABLE,
213         /**< The encoder is bound to the "streamable subset" but other settings violate it. */
214
215         FLAC__STREAM_ENCODER_FRAMING_ERROR,
216         /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
217
218         FLAC__STREAM_ENCODER_INVALID_METADATA,
219         /**< The metadata input to the encoder is invalid. */
220
221         FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
222         /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
223
224         FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING,
225         /**< The write_callback returned an error. */
226
227         FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
228         /**< Memory allocation failed. */
229
230         FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
231         /**< FLAC__stream_encoder_init() was called when the encoder was
232          * already initialized, usually because
233          * FLAC__stream_encoder_finish() was not called.
234          */
235
236         FLAC__STREAM_ENCODER_UNINITIALIZED
237         /**< The encoder is in the uninitialized state. */
238
239 } FLAC__StreamEncoderState;
240
241 /** Maps a FLAC__StreamEncoderState to a C string.
242  *
243  *  Using a FLAC__StreamEncoderState as the index to this array
244  *  will give the string equivalent.  The contents should not be modified.
245  */
246 extern const char * const FLAC__StreamEncoderStateString[];
247
248 /** Return values for the FLAC__StreamEncoder write callback.
249  */
250 typedef enum {
251
252         FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
253         /**< The write was OK and encoding can continue. */
254
255         FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
256         /**< An unrecoverable error occurred.  The encoder will return from the process call. */
257
258 } FLAC__StreamEncoderWriteStatus;
259
260 /** Maps a FLAC__StreamEncoderWriteStatus to a C string.
261  *
262  *  Using a FLAC__StreamEncoderWriteStatus as the index to this array
263  *  will give the string equivalent.  The contents should not be modified.
264  */
265 extern const char * const FLAC__StreamEncoderWriteStatusString[];
266
267
268 /***********************************************************************
269  *
270  * class FLAC__StreamEncoder
271  *
272  ***********************************************************************/
273
274 struct FLAC__StreamEncoderProtected;
275 struct FLAC__StreamEncoderPrivate;
276 /** The opaque structure definition for the stream encoder type.
277  *  See the \link flac_stream_encoder stream encoder module \endlink
278  *  for a detailed description.
279  */
280 typedef struct {
281         struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
282         struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
283 } FLAC__StreamEncoder;
284
285 /*@@@@ document: */
286 typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
287 typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
288
289
290 /***********************************************************************
291  *
292  * Class constructor/destructor
293  *
294  ***********************************************************************/
295
296 /** Create a new stream encoder instance.  The instance is created with
297  *  default settings; see the individual FLAC__stream_encoder_set_*()
298  *  functions for each setting's default.
299  *
300  * \retval FLAC__StreamEncoder*
301  *    \c NULL if there was an error allocating memory, else the new instance.
302  */
303 FLAC__StreamEncoder *FLAC__stream_encoder_new();
304
305 /** Free an encoder instance.  Deletes the object pointed to by \a encoder.
306  *
307  * \param encoder  A pointer to an existing encoder.
308  * \assert
309  *    \code encoder != NULL \endcode
310  */
311 void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
312
313 /***********************************************************************
314  *
315  * Public class method prototypes
316  *
317  ***********************************************************************/
318
319 /** Set the "streamable subset" flag.  If \c true, the encoder will comply
320  *  with the subset (see the format specification) and will check the
321  *  settings during FLAC__stream_encoder_init() to see if all settings
322  *  comply.  If \c false, the settings may take advantage of the full
323  *  range that the format allows.
324  *
325  *  Make sure you know what it entails before setting this to \c false.
326  *
327  * \default \c true
328  * \param  encoder  An encoder instance to set.
329  * \param  value    Flag value (see above).
330  * \assert
331  *    \code encoder != NULL \endcode
332  * \retval FLAC__bool
333  *    \c false if the encoder is already initialized, else \c true.
334  */
335 FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
336
337 /** Set to \c true to enable mid-side encoding on stereo input.  The
338  *  number of channels must be 2.  Set to \c false to use only
339  *  independent channel coding.
340  *
341  * \default \c false
342  * \param  encoder  An encoder instance to set.
343  * \param  value    Flag value (see above).
344  * \assert
345  *    \code encoder != NULL \endcode
346  * \retval FLAC__bool
347  *    \c false if the encoder is already initialized, else \c true.
348  */
349 FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
350
351 /** Set to \c true to enable adaptive switching between mid-side and
352  *  left-right encoding on stereo input.  The number of channels must
353  *  be 2.  Set to \c false to use exhaustive searching.  In either
354  *  case, the mid/side stereo setting must be \c true.
355  *
356  * \default \c false
357  * \param  encoder  An encoder instance to set.
358  * \param  value    Flag value (see above).
359  * \assert
360  *    \code encoder != NULL \endcode
361  * \retval FLAC__bool
362  *    \c false if the encoder is already initialized, else \c true.
363  */
364 FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
365
366 /** Set the number of channels to be encoded.
367  *
368  * \default \c 2
369  * \param  encoder  An encoder instance to set.
370  * \param  value    See above.
371  * \assert
372  *    \code encoder != NULL \endcode
373  * \retval FLAC__bool
374  *    \c false if the encoder is already initialized, else \c true.
375  */
376 FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
377
378 /** Set the sample resolution of the input to be encoded.
379  *
380  * \warning
381  * Do not feed the encoder data that is wider than the value you
382  * set here or you will generate an invalid stream.
383  *
384  * \default \c 16
385  * \param  encoder  An encoder instance to set.
386  * \param  value    See above.
387  * \assert
388  *    \code encoder != NULL \endcode
389  * \retval FLAC__bool
390  *    \c false if the encoder is already initialized, else \c true.
391  */
392 FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
393
394 /** Set the sample rate (in Hz) of the input to be encoded.
395  *
396  * \default \c 44100
397  * \param  encoder  An encoder instance to set.
398  * \param  value    See above.
399  * \assert
400  *    \code encoder != NULL \endcode
401  * \retval FLAC__bool
402  *    \c false if the encoder is already initialized, else \c true.
403  */
404 FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
405
406 /** Set the blocksize to use while encoding.
407  *
408  * \default \c 1152
409  * \param  encoder  An encoder instance to set.
410  * \param  value    See above.
411  * \assert
412  *    \code encoder != NULL \endcode
413  * \retval FLAC__bool
414  *    \c false if the encoder is already initialized, else \c true.
415  */
416 FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
417
418 /** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
419  *
420  * \default \c 0
421  * \param  encoder  An encoder instance to set.
422  * \param  value    See above.
423  * \assert
424  *    \code encoder != NULL \endcode
425  * \retval FLAC__bool
426  *    \c false if the encoder is already initialized, else \c true.
427  */
428 FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
429
430 /** Set the precision, in bits, of the quantized linear predictor
431  *  coefficients, or \c 0 to let the encoder select it based on the
432  *  blocksize.
433  *
434  * \note
435  * In the current implementation, qlp_coeff_precision + bits_per_sample must
436  * be less than 32.
437  *
438  * \default \c 0
439  * \param  encoder  An encoder instance to set.
440  * \param  value    See above.
441  * \assert
442  *    \code encoder != NULL \endcode
443  * \retval FLAC__bool
444  *    \c false if the encoder is already initialized, else \c true.
445  */
446 FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
447
448 /** Set to \c false to use only the specified quantized linear predictor
449  *  coefficient precision, or \c true to search neighboring precision
450  *  values and use the best one.
451  *
452  * \default \c false
453  * \param  encoder  An encoder instance to set.
454  * \param  value    See above.
455  * \assert
456  *    \code encoder != NULL \endcode
457  * \retval FLAC__bool
458  *    \c false if the encoder is already initialized, else \c true.
459  */
460 FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
461
462 /** Deprecated.  Setting this value has no effect.
463  *
464  * \default \c false
465  * \param  encoder  An encoder instance to set.
466  * \param  value    See above.
467  * \assert
468  *    \code encoder != NULL \endcode
469  * \retval FLAC__bool
470  *    \c false if the encoder is already initialized, else \c true.
471  */
472 FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
473
474 /** Set to \c false to let the encoder estimate the best model order
475  *  based on the residual signal energy, or \c true to force the
476  *  encoder to evaluate all order models and select the best.
477  *
478  * \default \c false
479  * \param  encoder  An encoder instance to set.
480  * \param  value    See above.
481  * \assert
482  *    \code encoder != NULL \endcode
483  * \retval FLAC__bool
484  *    \c false if the encoder is already initialized, else \c true.
485  */
486 FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
487
488 /** Set the minimum partition order to search when coding the residual.
489  *  This is used in tandem with
490  *  FLAC__stream_encoder_set_max_residual_partition_order().
491  *
492  *  The partition order determines the context size in the residual.
493  *  The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
494  *
495  *  Set both min and max values to \c 0 to force a single context,
496  *  whose Rice parameter is based on the residual signal variance.
497  *  Otherwise, set a min and max order, and the encoder will search
498  *  all orders, using the mean of each context for its Rice parameter,
499  *  and use the best.
500  *
501  * \default \c 0
502  * \param  encoder  An encoder instance to set.
503  * \param  value    See above.
504  * \assert
505  *    \code encoder != NULL \endcode
506  * \retval FLAC__bool
507  *    \c false if the encoder is already initialized, else \c true.
508  */
509 FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
510
511 /** Set the minimum partition order to search when coding the residual.
512  *  This is used in tandem with
513  *  FLAC__stream_encoder_set_min_residual_partition_order().
514  *
515  *  The partition order determines the context size in the residual.
516  *  The context size will be approximately <tt>blocksize / (2 ^ order)</tt>.
517  *
518  *  Set both min and max values to \c 0 to force a single context,
519  *  whose Rice parameter is based on the residual signal variance.
520  *  Otherwise, set a min and max order, and the encoder will search
521  *  all orders, using the mean of each context for its Rice parameter,
522  *  and use the best.
523  *
524  * \default \c 0
525  * \param  encoder  An encoder instance to set.
526  * \param  value    See above.
527  * \assert
528  *    \code encoder != NULL \endcode
529  * \retval FLAC__bool
530  *    \c false if the encoder is already initialized, else \c true.
531  */
532 FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
533
534 /** Deprecated.  Setting this value has no effect.
535  *
536  * \default \c 0
537  * \param  encoder  An encoder instance to set.
538  * \param  value    See above.
539  * \assert
540  *    \code encoder != NULL \endcode
541  * \retval FLAC__bool
542  *    \c false if the encoder is already initialized, else \c true.
543  */
544 FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
545
546 /** Set an estimate of the total samples that will be encoded.
547  *  This is merely an estimate and may be set to \c 0 if unknown.
548  *  This value will be written to the STREAMINFO block before encoding,
549  *  and can remove the need for the caller to rewrite the value later
550  *  if the value is known before encoding.
551  *
552  * \default \c 0
553  * \param  encoder  An encoder instance to set.
554  * \param  value    See above.
555  * \assert
556  *    \code encoder != NULL \endcode
557  * \retval FLAC__bool
558  *    \c false if the encoder is already initialized, else \c true.
559  */
560 FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
561
562 /** Set the metadata blocks to be emitted to the stream before encoding.
563  *  A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
564  *  array of pointers to metadata blocks.  The array is non-const since
565  *  the encoder may need to change the \a is_last flag inside them.
566  *  Otherwise, the encoder will not modify or free the blocks.  It is up
567  *  to the caller to free the metadata blocks after encoding.
568  *
569  *  The STREAMINFO block is always written and no STREAMINFO block may
570  *  occur in the supplied array.
571  *
572  * \default \c NULL, 0
573  * \param  encoder     An encoder instance to set.
574  * \param  metadata    See above.
575  * \param  num_blocks  See above.
576  * \assert
577  *    \code encoder != NULL \endcode
578  * \retval FLAC__bool
579  *    \c false if the encoder is already initialized, else \c true.
580  */
581 FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
582
583 /** Set the write callback.
584  *  The supplied function will be called by the encoder anytime there is raw
585  *  encoded data ready to write.  It may include metadata mixed with encoded
586  *  audio frames and the data is not guaranteed to be aligned on frame or
587  *  metadata block boundaries.
588  *
589  *  The only duty of the callback is to write out the \a bytes worth of data
590  *  in \a buffer to the current position in the output stream.  The arguments
591  *  \a samples and \a current_frame are purely informational.  If \a samples
592  *  is greater than \c 0, then \a current_frame will hold the current frame
593  *  number that is being written; otherwise, the write callback is being called
594  *  to write metadata.
595  *
596  * \note
597  * The callback is mandatory and must be set before initialization.
598  *
599  * \default \c NULL
600  * \param  encoder  An encoder instance to set.
601  * \param  value    See above.
602  * \assert
603  *    \code encoder != NULL \endcode
604  *    \code value != NULL \endcode
605  * \retval FLAC__bool
606  *    \c false if the encoder is already initialized, else \c true.
607  */
608 FLAC__bool FLAC__stream_encoder_set_write_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback value);
609
610 /** Set the metadata callback.
611  *  The supplied function will be called once at the end of encoding with
612  *  the populated STREAMINFO structure.  This is so file encoders can seek
613  *  back to the beginning of the file and write the STREAMINFO block with
614  *  the correct statistics after encoding (like minimum/maximum frame size
615  *  and total samples).
616  *
617  * \note
618  * The callback is mandatory and must be set before initialization.
619  *
620  * \default \c NULL
621  * \param  encoder  An encoder instance to set.
622  * \param  value    See above.
623  * \assert
624  *    \code encoder != NULL \endcode
625  *    \code value != NULL \endcode
626  * \retval FLAC__bool
627  *    \c false if the encoder is already initialized, else \c true.
628  */
629 FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderMetadataCallback value);
630
631 /** Set the client data to be passed back to callbacks.
632  *  This value will be supplied to callbacks in their \a client_data
633  *  argument.
634  *
635  * \default \c NULL
636  * \param  encoder  An encoder instance to set.
637  * \param  value    See above.
638  * \assert
639  *    \code encoder != NULL \endcode
640  * \retval FLAC__bool
641  *    \c false if the encoder is already initialized, else \c true.
642  */
643 FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
644
645 /** Get the current encoder state.
646  *
647  * \param  encoder  An encoder instance to query.
648  * \assert
649  *    \code encoder != NULL \endcode
650  * \retval FLAC__StreamEncoderState
651  *    The current encoder state.
652  */
653 FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
654
655 /** Get the "streamable subset" flag.
656  *
657  * \param  encoder  An encoder instance to query.
658  * \assert
659  *    \code encoder != NULL \endcode
660  * \retval FLAC__bool
661  *    See FLAC__stream_encoder_set_streamable_subset().
662  */
663 FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
664
665 /** Get the "mid/side stereo coding" flag.
666  *
667  * \param  encoder  An encoder instance to query.
668  * \assert
669  *    \code encoder != NULL \endcode
670  * \retval FLAC__bool
671  *    See FLAC__stream_encoder_get_do_mid_side_stereo().
672  */
673 FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
674
675 /** Get the "adaptive mid/side switching" flag.
676  *
677  * \param  encoder  An encoder instance to query.
678  * \assert
679  *    \code encoder != NULL \endcode
680  * \retval FLAC__bool
681  *    See FLAC__stream_encoder_set_loose_mid_side_stereo().
682  */
683 FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
684
685 /** Get the number of input channels being processed.
686  *
687  * \param  encoder  An encoder instance to query.
688  * \assert
689  *    \code encoder != NULL \endcode
690  * \retval FLAC__bool
691  *    See FLAC__stream_encoder_set_channels().
692  */
693 unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
694
695 /** Get the input sample resolution setting.
696  *
697  * \param  encoder  An encoder instance to query.
698  * \assert
699  *    \code encoder != NULL \endcode
700  * \retval FLAC__bool
701  *    See FLAC__stream_encoder_set_bits_per_sample().
702  */
703 unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
704
705 /** Get the input sample rate setting.
706  *
707  * \param  encoder  An encoder instance to query.
708  * \assert
709  *    \code encoder != NULL \endcode
710  * \retval FLAC__bool
711  *    See FLAC__stream_encoder_set_sample_rate().
712  */
713 unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
714
715 /** Get the blocksize setting.
716  *
717  * \param  encoder  An encoder instance to query.
718  * \assert
719  *    \code encoder != NULL \endcode
720  * \retval FLAC__bool
721  *    See FLAC__stream_encoder_set_blocksize().
722  */
723 unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
724
725 /** Get the maximum LPC order setting.
726  *
727  * \param  encoder  An encoder instance to query.
728  * \assert
729  *    \code encoder != NULL \endcode
730  * \retval FLAC__bool
731  *    See FLAC__stream_encoder_set_max_lpc_order().
732  */
733 unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
734
735 /** Get the quantized linear predictor coefficient precision setting.
736  *
737  * \param  encoder  An encoder instance to query.
738  * \assert
739  *    \code encoder != NULL \endcode
740  * \retval FLAC__bool
741  *    See FLAC__stream_encoder_set_qlp_coeff_precision().
742  */
743 unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
744
745 /** Get the qlp coefficient precision search flag.
746  *
747  * \param  encoder  An encoder instance to query.
748  * \assert
749  *    \code encoder != NULL \endcode
750  * \retval FLAC__bool
751  *    See FLAC__stream_encoder_set_do_qlp_coeff_prec_search().
752  */
753 FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
754
755 /** Get the "escape coding" flag.
756  *
757  * \param  encoder  An encoder instance to query.
758  * \assert
759  *    \code encoder != NULL \endcode
760  * \retval FLAC__bool
761  *    See FLAC__stream_encoder_set_do_escape_coding().
762  */
763 FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
764
765 /** Get the exhaustive model search flag.
766  *
767  * \param  encoder  An encoder instance to query.
768  * \assert
769  *    \code encoder != NULL \endcode
770  * \retval FLAC__bool
771  *    See FLAC__stream_encoder_set_do_exhaustive_model_search().
772  */
773 FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
774
775 /** Get the minimum residual partition order setting.
776  *
777  * \param  encoder  An encoder instance to query.
778  * \assert
779  *    \code encoder != NULL \endcode
780  * \retval FLAC__bool
781  *    See FLAC__stream_encoder_set_min_residual_partition_order().
782  */
783 unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
784
785 /** Get maximum residual partition order setting.
786  *
787  * \param  encoder  An encoder instance to query.
788  * \assert
789  *    \code encoder != NULL \endcode
790  * \retval FLAC__bool
791  *    See FLAC__stream_encoder_set_max_residual_partition_order().
792  */
793 unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
794
795 /** Get the Rice parameter search distance setting.
796  *
797  * \param  encoder  An encoder instance to query.
798  * \assert
799  *    \code encoder != NULL \endcode
800  * \retval FLAC__bool
801  *    See FLAC__stream_encoder_set_rice_parameter_search_dist().
802  */
803 unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
804
805 /** Initialize the encoder instance.
806  *  Should be called after FLAC__stream_encoder_new() and
807  *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
808  *  or FLAC__stream_encoder_process_interleaved().  Will set and return
809  *  the encoder state, which will be FLAC__STREAM_ENCODER_OK if
810  *  initialization succeeded.
811  *
812  *  The call to FLAC__stream_encoder_init() currently will also immediately
813  *  call the write callback several times, once with the \c fLaC signature,
814  *  and once for each encoded metadata block.
815  *
816  * \param  encoder  An uninitialized encoder instance.
817  * \assert
818  *    \code encoder != NULL \endcode
819  * \retval FLAC__StreamEncoderState
820  *    \c FLAC__STREAM_ENCODER_OK if initialization was successful; see
821  *    FLAC__StreamEncoderState for the meanings of other return values.
822  */
823 FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
824
825 /** Finish the encoding process.
826  *  Flushes the encoding buffer, releases resources, resets the encoder
827  *  settings to their defaults, and returns the encoder state to
828  *  FLAC__STREAM_ENCODER_UNINITIALIZED.  Note that this can generate
829  *  one or more write callbacks before returning, and will generate
830  *  a metadata callback.
831  *
832  *  In the event of a prematurely-terminated encode, it is not strictly
833  *  necessary to call this immediately before FLAC__stream_encoder_delete()
834  *  but it is good practice to match every FLAC__stream_encoder_init()
835  *  with a FLAC__stream_encoder_finish().
836  *
837  * \param  encoder  An uninitialized encoder instance.
838  * \assert
839  *    \code encoder != NULL \endcode
840  */
841 void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
842
843 /** Submit data for encoding.
844  *  This version allows you to supply the input data via an array of
845  *  pointers, each pointer pointing to an array of \a samples samples
846  *  representing one channel.  The samples need not be block-aligned,
847  *  but each channel should have the same number of samples.
848  *
849  * \param  encoder  An initialized encoder instance in the OK state.
850  * \param  buffer   An array of pointers to each channel's signal.
851  * \param  samples  The number of samples in one channel.
852  * \assert
853  *    \code encoder != NULL \endcode
854  *    \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
855  * \retval FLAC__bool
856  *    \c true if successful, else \c false; in this case, check the
857  *    encoder state with FLAC__stream_encoder_get_state() to see what
858  *    went wrong.
859  */
860 FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
861
862 /** Submit data for encoding.
863  *  This version allows you to supply the input data where the channels
864  *  are interleaved into a single array (i.e. channel0_sample0,
865  *  channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
866  *  The samples need not be block-aligned but they must be
867  *  sample-aligned, i.e. the first value should be channel0_sample0
868  *  and the last value channelN_sampleM.
869  *
870  * \param  encoder  An initialized encoder instance in the OK state.
871  * \param  buffer   An array of channel-interleaved data (see above).
872  * \param  samples  The number of samples in one channel, the same as for
873  *                  FLAC__stream_encoder_process().  For example, if
874  *                  encoding two channels, \c 1000 \a samples corresponds
875  *                  to a \a buffer of 2000 values.
876  * \assert
877  *    \code encoder != NULL \endcode
878  *    \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode
879  * \retval FLAC__bool
880  *    \c true if successful, else \c false; in this case, check the
881  *    encoder state with FLAC__stream_encoder_get_state() to see what
882  *    went wrong.
883  */
884 FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
885
886 /* \} */
887
888 #ifdef __cplusplus
889 }
890 #endif
891
892 #endif