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