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