~ubuntu-branches/ubuntu/raring/flac/raring

« back to all changes in this revision

Viewing changes to include/FLAC/stream_encoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libFLAC - Free Lossless Audio Codec library
2
 
 * Copyright (C) 2000,2001,2002,2003,2004,2005  Josh Coalson
 
2
 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3
3
 *
4
4
 * Redistribution and use in source and binary forms, with or without
5
5
 * modification, are permitted provided that the following conditions
32
32
#ifndef FLAC__STREAM_ENCODER_H
33
33
#define FLAC__STREAM_ENCODER_H
34
34
 
 
35
#include <stdio.h> /* for FILE */
35
36
#include "export.h"
36
37
#include "format.h"
37
38
#include "stream_decoder.h"
51
52
 *  \link flac_stream_encoder stream encoder \endlink module.
52
53
 */
53
54
 
54
 
/** \defgroup flac_encoder FLAC/ *_encoder.h: encoder interfaces
 
55
/** \defgroup flac_encoder FLAC/ \*_encoder.h: encoder interfaces
55
56
 *  \ingroup flac
56
57
 *
57
58
 *  \brief
58
 
 *  This module describes the two encoder layers provided by libFLAC.
59
 
 *
60
 
 * For encoding FLAC streams, libFLAC provides three layers of access.  The
61
 
 * lowest layer is non-seekable stream-level encoding, the next is seekable
62
 
 * stream-level encoding, and the highest layer is file-level encoding.  The
63
 
 * interfaces are described in the \link flac_stream_encoder stream encoder
64
 
 * \endlink, \link flac_seekable_stream_encoder seekable stream encoder
65
 
 * \endlink, and \link flac_file_encoder file encoder \endlink modules
66
 
 * respectively.  Typically you will choose the highest layer that your input
67
 
 * source will support.
68
 
 * The stream encoder relies on callbacks for writing the data and
69
 
 * metadata. The file encoder provides these callbacks internally and you
70
 
 * need only supply the filename.
71
 
 *
72
 
 * The stream encoder relies on callbacks for writing the data and has no
73
 
 * provisions for seeking the output.  The seekable stream encoder wraps
74
 
 * the stream encoder and also automaticallay handles the writing back of
75
 
 * metadata discovered while encoding.  However, you must provide extra
76
 
 * callbacks for seek-related operations on your output, like seek and
77
 
 * tell.  The file encoder wraps the seekable stream encoder and supplies
78
 
 * all of the callbacks internally, simplifying the processing of standard
79
 
 * files.  The only callback exposed is for progress reporting, and that
80
 
 * is optional.
 
59
 *  This module describes the encoder layers provided by libFLAC.
 
60
 *
 
61
 * The stream encoder can be used to encode complete streams either to the
 
62
 * client via callbacks, or directly to a file, depending on how it is
 
63
 * initialized.  When encoding via callbacks, the client provides a write
 
64
 * callback which will be called whenever FLAC data is ready to be written.
 
65
 * If the client also supplies a seek callback, the encoder will also
 
66
 * automatically handle the writing back of metadata discovered while
 
67
 * encoding, like stream info, seek points offsets, etc.  When encoding to
 
68
 * a file, the client needs only supply a filename or open \c FILE* and an
 
69
 * optional progress callback for periodic notification of progress; the
 
70
 * write and seek callbacks are supplied internally.  For more info see the
 
71
 * \link flac_stream_encoder stream encoder \endlink module.
81
72
 */
82
73
 
83
74
/** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface
87
78
 *  This module contains the functions which implement the stream
88
79
 *  encoder.
89
80
 *
 
81
 * The stream encoder can encode to native FLAC, and optionally Ogg FLAC
 
82
 * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files.
 
83
 *
90
84
 * The basic usage of this encoder is as follows:
91
85
 * - The program creates an instance of an encoder using
92
86
 *   FLAC__stream_encoder_new().
93
 
 * - The program overrides the default settings and sets callbacks using
94
 
 *   FLAC__stream_encoder_set_*() functions.
 
87
 * - The program overrides the default settings using
 
88
 *   FLAC__stream_encoder_set_*() functions.  At a minimum, the following
 
89
 *   functions should be called:
 
90
 *   - FLAC__stream_encoder_set_channels()
 
91
 *   - FLAC__stream_encoder_set_bits_per_sample()
 
92
 *   - FLAC__stream_encoder_set_sample_rate()
 
93
 *   - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC)
 
94
 *   - FLAC__stream_encoder_set_total_samples_estimate() (if known)
 
95
 * - If the application wants to control the compression level or set its own
 
96
 *   metadata, then the following should also be called:
 
97
 *   - FLAC__stream_encoder_set_compression_level()
 
98
 *   - FLAC__stream_encoder_set_verify()
 
99
 *   - FLAC__stream_encoder_set_metadata()
 
100
 * - The rest of the set functions should only be called if the client needs
 
101
 *   exact control over how the audio is compressed; thorough understanding
 
102
 *   of the FLAC format is necessary to achieve good results.
95
103
 * - The program initializes the instance to validate the settings and
96
 
 *   prepare for encoding using FLAC__stream_encoder_init().
 
104
 *   prepare for encoding using
 
105
 *   - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE()
 
106
 *     or FLAC__stream_encoder_init_file() for native FLAC
 
107
 *   - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE()
 
108
 *     or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC
97
109
 * - The program calls FLAC__stream_encoder_process() or
98
110
 *   FLAC__stream_encoder_process_interleaved() to encode data, which
99
111
 *   subsequently calls the callbacks when there is encoder data ready
100
112
 *   to be written.
101
113
 * - The program finishes the encoding with FLAC__stream_encoder_finish(),
102
114
 *   which causes the encoder to encode any data still in its input pipe,
103
 
 *   call the metadata callback with the final encoding statistics, and
104
 
 *   finally reset the encoder to the uninitialized state.
 
115
 *   update the metadata with the final encoding statistics if output
 
116
 *   seeking is possible, and finally reset the encoder to the
 
117
 *   uninitialized state.
105
118
 * - The instance may be used again or deleted with
106
119
 *   FLAC__stream_encoder_delete().
107
120
 *
108
121
 * In more detail, the stream encoder functions similarly to the
109
122
 * \link flac_stream_decoder stream decoder \endlink, but has fewer
110
 
 * callbacks and more options.  Typically the user will create a new
 
123
 * callbacks and more options.  Typically the client will create a new
111
124
 * instance by calling FLAC__stream_encoder_new(), then set the necessary
112
 
 * parameters and callbacks with FLAC__stream_encoder_set_*(), and
113
 
 * initialize it by calling FLAC__stream_encoder_init().
 
125
 * parameters with FLAC__stream_encoder_set_*(), and initialize it by
 
126
 * calling one of the FLAC__stream_encoder_init_*() functions.
114
127
 *
115
128
 * Unlike the decoders, the stream encoder has many options that can
116
129
 * affect the speed and compression ratio.  When setting these parameters
118
131
 * <A HREF="../documentation.html#format">user-level documentation</A>
119
132
 * or the <A HREF="../format.html">formal description</A>).  The
120
133
 * FLAC__stream_encoder_set_*() functions themselves do not validate the
121
 
 * values as many are interdependent.  The FLAC__stream_encoder_init()
122
 
 * function will do this, so make sure to pay attention to the state
123
 
 * returned by FLAC__stream_encoder_init() to make sure that it is
124
 
 * FLAC__STREAM_ENCODER_OK.  Any parameters that are not set before
125
 
 * FLAC__stream_encoder_init() will take on the defaults from the
126
 
 * constructor.
127
 
 *
128
 
 * The user must provide function pointers for the following callbacks:
129
 
 *
130
 
 * - Write callback - This function is called by the encoder anytime there
131
 
 *   is raw encoded data to write.  It may include metadata mixed with
132
 
 *   encoded audio frames and the data is not guaranteed to be aligned on
133
 
 *   frame or metadata block boundaries.
134
 
 * - Metadata callback - This function is called once at the end of
135
 
 *   encoding with the populated STREAMINFO structure.  This is so file
136
 
 *   encoders can seek back to the beginning of the file and write the
137
 
 *   STREAMINFO block with the correct statistics after encoding (like
138
 
 *   minimum/maximum frame size).
139
 
 *
140
 
 * The call to FLAC__stream_encoder_init() currently will also immediately
 
134
 * values as many are interdependent.  The FLAC__stream_encoder_init_*()
 
135
 * functions will do this, so make sure to pay attention to the state
 
136
 * returned by FLAC__stream_encoder_init_*() to make sure that it is
 
137
 * FLAC__STREAM_ENCODER_INIT_STATUS_OK.  Any parameters that are not set
 
138
 * before FLAC__stream_encoder_init_*() will take on the defaults from
 
139
 * the constructor.
 
140
 *
 
141
 * There are three initialization functions for native FLAC, one for
 
142
 * setting up the encoder to encode FLAC data to the client via
 
143
 * callbacks, and two for encoding directly to a file.
 
144
 *
 
145
 * For encoding via callbacks, use FLAC__stream_encoder_init_stream().
 
146
 * You must also supply a write callback which will be called anytime
 
147
 * there is raw encoded data to write.  If the client can seek the output
 
148
 * it is best to also supply seek and tell callbacks, as this allows the
 
149
 * encoder to go back after encoding is finished to write back
 
150
 * information that was collected while encoding, like seek point offsets,
 
151
 * frame sizes, etc.
 
152
 *
 
153
 * For encoding directly to a file, use FLAC__stream_encoder_init_FILE()
 
154
 * or FLAC__stream_encoder_init_file().  Then you must only supply a
 
155
 * filename or open \c FILE*; the encoder will handle all the callbacks
 
156
 * internally.  You may also supply a progress callback for periodic
 
157
 * notification of the encoding progress.
 
158
 *
 
159
 * There are three similarly-named init functions for encoding to Ogg
 
160
 * FLAC streams.  Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the
 
161
 * library has been built with Ogg support.
 
162
 *
 
163
 * The call to FLAC__stream_encoder_init_*() currently will also immediately
141
164
 * call the write callback several times, once with the \c fLaC signature,
142
 
 * and once for each encoded metadata block.
 
165
 * and once for each encoded metadata block.  Note that for Ogg FLAC
 
166
 * encoding you will usually get at least twice the number of callbacks than
 
167
 * with native FLAC, one for the Ogg page header and one for the page body.
143
168
 *
144
 
 * After initializing the instance, the user may feed audio data to the
 
169
 * After initializing the instance, the client may feed audio data to the
145
170
 * encoder in one of two ways:
146
171
 *
147
 
 * - Channel separate, through FLAC__stream_encoder_process() - The user
 
172
 * - Channel separate, through FLAC__stream_encoder_process() - The client
148
173
 *   will pass an array of pointers to buffers, one for each channel, to
149
174
 *   the encoder, each of the same length.  The samples need not be
150
 
 *   block-aligned.
 
175
 *   block-aligned, but each channel should have the same number of samples.
151
176
 * - Channel interleaved, through
152
 
 *   FLAC__stream_encoder_process_interleaved() - The user will pass a single
 
177
 *   FLAC__stream_encoder_process_interleaved() - The client will pass a single
153
178
 *   pointer to data that is channel-interleaved (i.e. channel0_sample0,
154
179
 *   channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
155
180
 *   Again, the samples need not be block-aligned but they must be
156
181
 *   sample-aligned, i.e. the first value should be channel0_sample0 and
157
182
 *   the last value channelN_sampleM.
158
183
 *
159
 
 * When the user is finished encoding data, it calls
 
184
 * Note that for either process call, each sample in the buffers should be a
 
185
 * signed integer, right-justified to the resolution set by
 
186
 * FLAC__stream_encoder_set_bits_per_sample().  For example, if the resolution
 
187
 * is 16 bits per sample, the samples should all be in the range [-32768,32767].
 
188
 *
 
189
 * When the client is finished encoding data, it calls
160
190
 * FLAC__stream_encoder_finish(), which causes the encoder to encode any
161
191
 * data still in its input pipe, and call the metadata callback with the
162
192
 * final encoding statistics.  Then the instance may be deleted with
177
207
 * for the specification of metadata blocks and their lengths.
178
208
 *
179
209
 * \note
 
210
 * If you are writing the FLAC data to a file via callbacks, make sure it
 
211
 * is open for update (e.g. mode "w+" for stdio streams).  This is because
 
212
 * after the first encoding pass, the encoder will try to seek back to the
 
213
 * beginning of the stream, to the STREAMINFO block, to write some data
 
214
 * there.  (If using FLAC__stream_encoder_init*_file() or
 
215
 * FLAC__stream_encoder_init*_FILE(), the file is managed internally.)
 
216
 *
 
217
 * \note
180
218
 * The "set" functions may only be called when the encoder is in the
181
219
 * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after
182
220
 * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but
183
 
 * before FLAC__stream_encoder_init().  If this is the case they will
 
221
 * before FLAC__stream_encoder_init_*().  If this is the case they will
184
222
 * return \c true, otherwise \c false.
185
223
 *
186
224
 * \note
187
225
 * FLAC__stream_encoder_finish() resets all settings to the constructor
188
 
 * defaults, including the callbacks.
 
226
 * defaults.
189
227
 *
190
228
 * \{
191
229
 */
192
230
 
193
231
 
194
 
/** State values for a FLAC__StreamEncoder
195
 
 *
196
 
 *  The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
 
232
/** State values for a FLAC__StreamEncoder.
 
233
 *
 
234
 * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state().
 
235
 *
 
236
 * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK
 
237
 * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and
 
238
 * must be deleted with FLAC__stream_encoder_delete().
197
239
 */
198
240
typedef enum {
199
241
 
200
242
        FLAC__STREAM_ENCODER_OK = 0,
201
 
        /**< The encoder is in the normal OK state. */
 
243
        /**< The encoder is in the normal OK state and samples can be processed. */
 
244
 
 
245
        FLAC__STREAM_ENCODER_UNINITIALIZED,
 
246
        /**< The encoder is in the uninitialized state; one of the
 
247
         * FLAC__stream_encoder_init_*() functions must be called before samples
 
248
         * can be processed.
 
249
         */
 
250
 
 
251
        FLAC__STREAM_ENCODER_OGG_ERROR,
 
252
        /**< An error occurred in the underlying Ogg layer.  */
202
253
 
203
254
        FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
204
255
        /**< An error occurred in the underlying verify stream decoder;
210
261
         * audio signal and the decoded audio signal.
211
262
         */
212
263
 
213
 
        FLAC__STREAM_ENCODER_INVALID_CALLBACK,
214
 
        /**< The encoder was initialized before setting all the required callbacks. */
215
 
 
216
 
        FLAC__STREAM_ENCODER_INVALID_NUMBER_OF_CHANNELS,
 
264
        FLAC__STREAM_ENCODER_CLIENT_ERROR,
 
265
        /**< One of the callbacks returned a fatal error. */
 
266
 
 
267
        FLAC__STREAM_ENCODER_IO_ERROR,
 
268
        /**< An I/O error occurred while opening/reading/writing a file.
 
269
         * Check \c errno.
 
270
         */
 
271
 
 
272
        FLAC__STREAM_ENCODER_FRAMING_ERROR,
 
273
        /**< An error occurred while writing the stream; usually, the
 
274
         * write_callback returned an error.
 
275
         */
 
276
 
 
277
        FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
 
278
        /**< Memory allocation failed. */
 
279
 
 
280
} FLAC__StreamEncoderState;
 
281
 
 
282
/** Maps a FLAC__StreamEncoderState to a C string.
 
283
 *
 
284
 *  Using a FLAC__StreamEncoderState as the index to this array
 
285
 *  will give the string equivalent.  The contents should not be modified.
 
286
 */
 
287
extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
 
288
 
 
289
 
 
290
/** Possible return values for the FLAC__stream_encoder_init_*() functions.
 
291
 */
 
292
typedef enum {
 
293
 
 
294
        FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
 
295
        /**< Initialization was successful. */
 
296
 
 
297
        FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
 
298
        /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */
 
299
 
 
300
        FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
 
301
        /**< The library was not compiled with support for the given container
 
302
         * format.
 
303
         */
 
304
 
 
305
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
 
306
        /**< A required callback was not supplied. */
 
307
 
 
308
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
217
309
        /**< The encoder has an invalid setting for number of channels. */
218
310
 
219
 
        FLAC__STREAM_ENCODER_INVALID_BITS_PER_SAMPLE,
 
311
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
220
312
        /**< The encoder has an invalid setting for bits-per-sample.
221
313
         * FLAC supports 4-32 bps but the reference encoder currently supports
222
314
         * only up to 24 bps.
223
315
         */
224
316
 
225
 
        FLAC__STREAM_ENCODER_INVALID_SAMPLE_RATE,
 
317
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
226
318
        /**< The encoder has an invalid setting for the input sample rate. */
227
319
 
228
 
        FLAC__STREAM_ENCODER_INVALID_BLOCK_SIZE,
 
320
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
229
321
        /**< The encoder has an invalid setting for the block size. */
230
322
 
231
 
        FLAC__STREAM_ENCODER_INVALID_MAX_LPC_ORDER,
 
323
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
232
324
        /**< The encoder has an invalid setting for the maximum LPC order. */
233
325
 
234
 
        FLAC__STREAM_ENCODER_INVALID_QLP_COEFF_PRECISION,
 
326
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
235
327
        /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */
236
328
 
237
 
        FLAC__STREAM_ENCODER_MID_SIDE_CHANNELS_MISMATCH,
238
 
        /**< Mid/side coding was specified but the number of channels is not equal to 2. */
239
 
 
240
 
        FLAC__STREAM_ENCODER_MID_SIDE_SAMPLE_SIZE_MISMATCH,
241
 
        /**< Deprecated. */
242
 
 
243
 
        FLAC__STREAM_ENCODER_ILLEGAL_MID_SIDE_FORCE,
244
 
        /**< Loose mid/side coding was specified but mid/side coding was not. */
245
 
 
246
 
        FLAC__STREAM_ENCODER_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
 
329
        FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
247
330
        /**< The specified block size is less than the maximum LPC order. */
248
331
 
249
 
        FLAC__STREAM_ENCODER_NOT_STREAMABLE,
250
 
        /**< The encoder is bound to the "streamable subset" but other settings violate it. */
251
 
 
252
 
        FLAC__STREAM_ENCODER_FRAMING_ERROR,
253
 
        /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
254
 
 
255
 
        FLAC__STREAM_ENCODER_INVALID_METADATA,
 
332
        FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
 
333
        /**< The encoder is bound to the <A HREF="../format.html#subset">Subset</A> but other settings violate it. */
 
334
 
 
335
        FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
256
336
        /**< The metadata input to the encoder is invalid, in one of the following ways:
257
337
         * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0
258
338
         * - One of the metadata blocks contains an undefined type
261
341
         * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block
262
342
         */
263
343
 
264
 
        FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_ENCODING,
265
 
        /**< An error occurred while writing the stream; usually, the write_callback returned an error. */
266
 
 
267
 
        FLAC__STREAM_ENCODER_FATAL_ERROR_WHILE_WRITING,
268
 
        /**< The write_callback returned an error. */
269
 
 
270
 
        FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR,
271
 
        /**< Memory allocation failed. */
272
 
 
273
 
        FLAC__STREAM_ENCODER_ALREADY_INITIALIZED,
274
 
        /**< FLAC__stream_encoder_init() was called when the encoder was
 
344
        FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
 
345
        /**< FLAC__stream_encoder_init_*() was called when the encoder was
275
346
         * already initialized, usually because
276
347
         * FLAC__stream_encoder_finish() was not called.
277
348
         */
278
349
 
279
 
        FLAC__STREAM_ENCODER_UNINITIALIZED
280
 
        /**< The encoder is in the uninitialized state. */
281
 
 
282
 
} FLAC__StreamEncoderState;
283
 
 
284
 
/** Maps a FLAC__StreamEncoderState to a C string.
285
 
 *
286
 
 *  Using a FLAC__StreamEncoderState as the index to this array
287
 
 *  will give the string equivalent.  The contents should not be modified.
288
 
 */
289
 
extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
 
350
} FLAC__StreamEncoderInitStatus;
 
351
 
 
352
/** Maps a FLAC__StreamEncoderInitStatus to a C string.
 
353
 *
 
354
 *  Using a FLAC__StreamEncoderInitStatus as the index to this array
 
355
 *  will give the string equivalent.  The contents should not be modified.
 
356
 */
 
357
extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
 
358
 
 
359
 
 
360
/** Return values for the FLAC__StreamEncoder read callback.
 
361
 */
 
362
typedef enum {
 
363
 
 
364
        FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
 
365
        /**< The read was OK and decoding can continue. */
 
366
 
 
367
        FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
 
368
        /**< The read was attempted at the end of the stream. */
 
369
 
 
370
        FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
 
371
        /**< An unrecoverable error occurred. */
 
372
 
 
373
        FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
 
374
        /**< Client does not support reading back from the output. */
 
375
 
 
376
} FLAC__StreamEncoderReadStatus;
 
377
 
 
378
/** Maps a FLAC__StreamEncoderReadStatus to a C string.
 
379
 *
 
380
 *  Using a FLAC__StreamEncoderReadStatus as the index to this array
 
381
 *  will give the string equivalent.  The contents should not be modified.
 
382
 */
 
383
extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
 
384
 
290
385
 
291
386
/** Return values for the FLAC__StreamEncoder write callback.
292
387
 */
308
403
extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
309
404
 
310
405
 
 
406
/** Return values for the FLAC__StreamEncoder seek callback.
 
407
 */
 
408
typedef enum {
 
409
 
 
410
        FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
 
411
        /**< The seek was OK and encoding can continue. */
 
412
 
 
413
        FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
 
414
        /**< An unrecoverable error occurred. */
 
415
 
 
416
        FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
 
417
        /**< Client does not support seeking. */
 
418
 
 
419
} FLAC__StreamEncoderSeekStatus;
 
420
 
 
421
/** Maps a FLAC__StreamEncoderSeekStatus to a C string.
 
422
 *
 
423
 *  Using a FLAC__StreamEncoderSeekStatus as the index to this array
 
424
 *  will give the string equivalent.  The contents should not be modified.
 
425
 */
 
426
extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
 
427
 
 
428
 
 
429
/** Return values for the FLAC__StreamEncoder tell callback.
 
430
 */
 
431
typedef enum {
 
432
 
 
433
        FLAC__STREAM_ENCODER_TELL_STATUS_OK,
 
434
        /**< The tell was OK and encoding can continue. */
 
435
 
 
436
        FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
 
437
        /**< An unrecoverable error occurred. */
 
438
 
 
439
        FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
 
440
        /**< Client does not support seeking. */
 
441
 
 
442
} FLAC__StreamEncoderTellStatus;
 
443
 
 
444
/** Maps a FLAC__StreamEncoderTellStatus to a C string.
 
445
 *
 
446
 *  Using a FLAC__StreamEncoderTellStatus as the index to this array
 
447
 *  will give the string equivalent.  The contents should not be modified.
 
448
 */
 
449
extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
 
450
 
 
451
 
311
452
/***********************************************************************
312
453
 *
313
454
 * class FLAC__StreamEncoder
325
466
        struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
326
467
} FLAC__StreamEncoder;
327
468
 
 
469
/** Signature for the read callback.
 
470
 *
 
471
 *  A function pointer matching this signature must be passed to
 
472
 *  FLAC__stream_encoder_init_ogg_stream() if seeking is supported.
 
473
 *  The supplied function will be called when the encoder needs to read back
 
474
 *  encoded data.  This happens during the metadata callback, when the encoder
 
475
 *  has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered
 
476
 *  while encoding.  The address of the buffer to be filled is supplied, along
 
477
 *  with the number of bytes the buffer can hold.  The callback may choose to
 
478
 *  supply less data and modify the byte count but must be careful not to
 
479
 *  overflow the buffer.  The callback then returns a status code chosen from
 
480
 *  FLAC__StreamEncoderReadStatus.
 
481
 *
 
482
 * Here is an example of a read callback for stdio streams:
 
483
 * \code
 
484
 * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
 
485
 * {
 
486
 *   FILE *file = ((MyClientData*)client_data)->file;
 
487
 *   if(*bytes > 0) {
 
488
 *     *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file);
 
489
 *     if(ferror(file))
 
490
 *       return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
 
491
 *     else if(*bytes == 0)
 
492
 *       return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
 
493
 *     else
 
494
 *       return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
 
495
 *   }
 
496
 *   else
 
497
 *     return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
 
498
 * }
 
499
 * \endcode
 
500
 *
 
501
 * \note In general, FLAC__StreamEncoder functions which change the
 
502
 * state should not be called on the \a encoder while in the callback.
 
503
 *
 
504
 * \param  encoder  The encoder instance calling the callback.
 
505
 * \param  buffer   A pointer to a location for the callee to store
 
506
 *                  data to be encoded.
 
507
 * \param  bytes    A pointer to the size of the buffer.  On entry
 
508
 *                  to the callback, it contains the maximum number
 
509
 *                  of bytes that may be stored in \a buffer.  The
 
510
 *                  callee must set it to the actual number of bytes
 
511
 *                  stored (0 in case of error or end-of-stream) before
 
512
 *                  returning.
 
513
 * \param  client_data  The callee's client data set through
 
514
 *                      FLAC__stream_encoder_set_client_data().
 
515
 * \retval FLAC__StreamEncoderReadStatus
 
516
 *    The callee's return status.
 
517
 */
 
518
typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
 
519
 
328
520
/** Signature for the write callback.
329
 
 *  See FLAC__stream_encoder_set_write_callback() for more info.
 
521
 *
 
522
 *  A function pointer matching this signature must be passed to
 
523
 *  FLAC__stream_encoder_init*_stream().  The supplied function will be called
 
524
 *  by the encoder anytime there is raw encoded data ready to write.  It may
 
525
 *  include metadata mixed with encoded audio frames and the data is not
 
526
 *  guaranteed to be aligned on frame or metadata block boundaries.
 
527
 *
 
528
 *  The only duty of the callback is to write out the \a bytes worth of data
 
529
 *  in \a buffer to the current position in the output stream.  The arguments
 
530
 *  \a samples and \a current_frame are purely informational.  If \a samples
 
531
 *  is greater than \c 0, then \a current_frame will hold the current frame
 
532
 *  number that is being written; otherwise it indicates that the write
 
533
 *  callback is being called to write metadata.
 
534
 *
 
535
 * \note
 
536
 * Unlike when writing to native FLAC, when writing to Ogg FLAC the
 
537
 * write callback will be called twice when writing each audio
 
538
 * frame; once for the page header, and once for the page body.
 
539
 * When writing the page header, the \a samples argument to the
 
540
 * write callback will be \c 0.
 
541
 *
 
542
 * \note In general, FLAC__StreamEncoder functions which change the
 
543
 * state should not be called on the \a encoder while in the callback.
330
544
 *
331
545
 * \param  encoder  The encoder instance calling the callback.
332
546
 * \param  buffer   An array of encoded data of length \a bytes.
333
547
 * \param  bytes    The byte length of \a buffer.
334
548
 * \param  samples  The number of samples encoded by \a buffer.
335
 
 *                  \c 0 has a special meaning; see
336
 
 *                  FLAC__stream_encoder_set_write_callback().
 
549
 *                  \c 0 has a special meaning; see above.
337
550
 * \param  current_frame  The number of the current frame being encoded.
338
551
 * \param  client_data  The callee's client data set through
339
 
 *                      FLAC__stream_encoder_set_client_data().
 
552
 *                      FLAC__stream_encoder_init_*().
340
553
 * \retval FLAC__StreamEncoderWriteStatus
341
554
 *    The callee's return status.
342
555
 */
343
 
typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
 
556
typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
 
557
 
 
558
/** Signature for the seek callback.
 
559
 *
 
560
 *  A function pointer matching this signature may be passed to
 
561
 *  FLAC__stream_encoder_init*_stream().  The supplied function will be called
 
562
 *  when the encoder needs to seek the output stream.  The encoder will pass
 
563
 *  the absolute byte offset to seek to, 0 meaning the beginning of the stream.
 
564
 *
 
565
 * Here is an example of a seek callback for stdio streams:
 
566
 * \code
 
567
 * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
 
568
 * {
 
569
 *   FILE *file = ((MyClientData*)client_data)->file;
 
570
 *   if(file == stdin)
 
571
 *     return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
 
572
 *   else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
 
573
 *     return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
 
574
 *   else
 
575
 *     return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
 
576
 * }
 
577
 * \endcode
 
578
 *
 
579
 * \note In general, FLAC__StreamEncoder functions which change the
 
580
 * state should not be called on the \a encoder while in the callback.
 
581
 *
 
582
 * \param  encoder  The encoder instance calling the callback.
 
583
 * \param  absolute_byte_offset  The offset from the beginning of the stream
 
584
 *                               to seek to.
 
585
 * \param  client_data  The callee's client data set through
 
586
 *                      FLAC__stream_encoder_init_*().
 
587
 * \retval FLAC__StreamEncoderSeekStatus
 
588
 *    The callee's return status.
 
589
 */
 
590
typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
 
591
 
 
592
/** Signature for the tell callback.
 
593
 *
 
594
 *  A function pointer matching this signature may be passed to
 
595
 *  FLAC__stream_encoder_init*_stream().  The supplied function will be called
 
596
 *  when the encoder needs to know the current position of the output stream.
 
597
 *
 
598
 * \warning
 
599
 * The callback must return the true current byte offset of the output to
 
600
 * which the encoder is writing.  If you are buffering the output, make
 
601
 * sure and take this into account.  If you are writing directly to a
 
602
 * FILE* from your write callback, ftell() is sufficient.  If you are
 
603
 * writing directly to a file descriptor from your write callback, you
 
604
 * can use lseek(fd, SEEK_CUR, 0).  The encoder may later seek back to
 
605
 * these points to rewrite metadata after encoding.
 
606
 *
 
607
 * Here is an example of a tell callback for stdio streams:
 
608
 * \code
 
609
 * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
 
610
 * {
 
611
 *   FILE *file = ((MyClientData*)client_data)->file;
 
612
 *   off_t pos;
 
613
 *   if(file == stdin)
 
614
 *     return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
 
615
 *   else if((pos = ftello(file)) < 0)
 
616
 *     return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
 
617
 *   else {
 
618
 *     *absolute_byte_offset = (FLAC__uint64)pos;
 
619
 *     return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
 
620
 *   }
 
621
 * }
 
622
 * \endcode
 
623
 *
 
624
 * \note In general, FLAC__StreamEncoder functions which change the
 
625
 * state should not be called on the \a encoder while in the callback.
 
626
 *
 
627
 * \param  encoder  The encoder instance calling the callback.
 
628
 * \param  absolute_byte_offset  The address at which to store the current
 
629
 *                               position of the output.
 
630
 * \param  client_data  The callee's client data set through
 
631
 *                      FLAC__stream_encoder_init_*().
 
632
 * \retval FLAC__StreamEncoderTellStatus
 
633
 *    The callee's return status.
 
634
 */
 
635
typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
344
636
 
345
637
/** Signature for the metadata callback.
346
 
 *  See FLAC__stream_encoder_set_metadata_callback() for more info.
 
638
 *
 
639
 *  A function pointer matching this signature may be passed to
 
640
 *  FLAC__stream_encoder_init*_stream().  The supplied function will be called
 
641
 *  once at the end of encoding with the populated STREAMINFO structure.  This
 
642
 *  is so the client can seek back to the beginning of the file and write the
 
643
 *  STREAMINFO block with the correct statistics after encoding (like
 
644
 *  minimum/maximum frame size and total samples).
 
645
 *
 
646
 * \note In general, FLAC__StreamEncoder functions which change the
 
647
 * state should not be called on the \a encoder while in the callback.
347
648
 *
348
649
 * \param  encoder      The encoder instance calling the callback.
349
650
 * \param  metadata     The final populated STREAMINFO block.
350
651
 * \param  client_data  The callee's client data set through
351
 
 *                      FLAC__stream_encoder_set_client_data().
 
652
 *                      FLAC__stream_encoder_init_*().
352
653
 */
353
654
typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
354
655
 
 
656
/** Signature for the progress callback.
 
657
 *
 
658
 *  A function pointer matching this signature may be passed to
 
659
 *  FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE().
 
660
 *  The supplied function will be called when the encoder has finished
 
661
 *  writing a frame.  The \c total_frames_estimate argument to the
 
662
 *  callback will be based on the value from
 
663
 *  FLAC__stream_encoder_set_total_samples_estimate().
 
664
 *
 
665
 * \note In general, FLAC__StreamEncoder functions which change the
 
666
 * state should not be called on the \a encoder while in the callback.
 
667
 *
 
668
 * \param  encoder          The encoder instance calling the callback.
 
669
 * \param  bytes_written    Bytes written so far.
 
670
 * \param  samples_written  Samples written so far.
 
671
 * \param  frames_written   Frames written so far.
 
672
 * \param  total_frames_estimate  The estimate of the total number of
 
673
 *                                frames to be written.
 
674
 * \param  client_data      The callee's client data set through
 
675
 *                          FLAC__stream_encoder_init_*().
 
676
 */
 
677
typedef void (*FLAC__StreamEncoderProgressCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data);
 
678
 
355
679
 
356
680
/***********************************************************************
357
681
 *
366
690
 * \retval FLAC__StreamEncoder*
367
691
 *    \c NULL if there was an error allocating memory, else the new instance.
368
692
 */
369
 
FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new();
 
693
FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
370
694
 
371
695
/** Free an encoder instance.  Deletes the object pointed to by \a encoder.
372
696
 *
383
707
 *
384
708
 ***********************************************************************/
385
709
 
 
710
/** Set the serial number for the FLAC stream to use in the Ogg container.
 
711
 *
 
712
 * \note
 
713
 * This does not need to be set for native FLAC encoding.
 
714
 *
 
715
 * \note
 
716
 * It is recommended to set a serial number explicitly as the default of '0'
 
717
 * may collide with other streams.
 
718
 *
 
719
 * \default \c 0
 
720
 * \param  encoder        An encoder instance to set.
 
721
 * \param  serial_number  See above.
 
722
 * \assert
 
723
 *    \code encoder != NULL \endcode
 
724
 * \retval FLAC__bool
 
725
 *    \c false if the encoder is already initialized, else \c true.
 
726
 */
 
727
FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
 
728
 
386
729
/** Set the "verify" flag.  If \c true, the encoder will verify it's own
387
730
 *  encoded output by feeding it through an internal decoder and comparing
388
731
 *  the original signal against the decoded signal.  If a mismatch occurs,
399
742
 */
400
743
FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
401
744
 
402
 
/** Set the "streamable subset" flag.  If \c true, the encoder will comply
403
 
 *  with the subset (see the format specification) and will check the
404
 
 *  settings during FLAC__stream_encoder_init() to see if all settings
 
745
/** Set the <A HREF="../format.html#subset">Subset</A> flag.  If \c true,
 
746
 *  the encoder will comply with the Subset and will check the
 
747
 *  settings during FLAC__stream_encoder_init_*() to see if all settings
405
748
 *  comply.  If \c false, the settings may take advantage of the full
406
749
 *  range that the format allows.
407
750
 *
417
760
 */
418
761
FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
419
762
 
420
 
/** Set to \c true to enable mid-side encoding on stereo input.  The
421
 
 *  number of channels must be 2.  Set to \c false to use only
422
 
 *  independent channel coding.
423
 
 *
424
 
 * \default \c false
425
 
 * \param  encoder  An encoder instance to set.
426
 
 * \param  value    Flag value (see above).
427
 
 * \assert
428
 
 *    \code encoder != NULL \endcode
429
 
 * \retval FLAC__bool
430
 
 *    \c false if the encoder is already initialized, else \c true.
431
 
 */
432
 
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
433
 
 
434
 
/** Set to \c true to enable adaptive switching between mid-side and
435
 
 *  left-right encoding on stereo input.  The number of channels must
436
 
 *  be 2.  Set to \c false to use exhaustive searching.  In either
437
 
 *  case, the mid/side stereo setting must be \c true.
438
 
 *
439
 
 * \default \c false
440
 
 * \param  encoder  An encoder instance to set.
441
 
 * \param  value    Flag value (see above).
442
 
 * \assert
443
 
 *    \code encoder != NULL \endcode
444
 
 * \retval FLAC__bool
445
 
 *    \c false if the encoder is already initialized, else \c true.
446
 
 */
447
 
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
448
 
 
449
763
/** Set the number of channels to be encoded.
450
764
 *
451
765
 * \default \c 2
486
800
 */
487
801
FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
488
802
 
 
803
/** Set the compression level
 
804
 *
 
805
 * The compression level is roughly proportional to the amount of effort
 
806
 * the encoder expends to compress the file.  A higher level usually
 
807
 * means more computation but higher compression.  The default level is
 
808
 * suitable for most applications.
 
809
 *
 
810
 * Currently the levels range from \c 0 (fastest, least compression) to
 
811
 * \c 8 (slowest, most compression).  A value larger than \c 8 will be
 
812
 * treated as \c 8.
 
813
 *
 
814
 * This function automatically calls the following other \c _set_
 
815
 * functions with appropriate values, so the client does not need to
 
816
 * unless it specifically wants to override them:
 
817
 * - FLAC__stream_encoder_set_do_mid_side_stereo()
 
818
 * - FLAC__stream_encoder_set_loose_mid_side_stereo()
 
819
 * - FLAC__stream_encoder_set_apodization()
 
820
 * - FLAC__stream_encoder_set_max_lpc_order()
 
821
 * - FLAC__stream_encoder_set_qlp_coeff_precision()
 
822
 * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
 
823
 * - FLAC__stream_encoder_set_do_escape_coding()
 
824
 * - FLAC__stream_encoder_set_do_exhaustive_model_search()
 
825
 * - FLAC__stream_encoder_set_min_residual_partition_order()
 
826
 * - FLAC__stream_encoder_set_max_residual_partition_order()
 
827
 * - FLAC__stream_encoder_set_rice_parameter_search_dist()
 
828
 *
 
829
 * The actual values set for each level are:
 
830
 * <table>
 
831
 * <tr>
 
832
 *  <td><b>level</b><td>
 
833
 *  <td>do mid-side stereo<td>
 
834
 *  <td>loose mid-side stereo<td>
 
835
 *  <td>apodization<td>
 
836
 *  <td>max lpc order<td>
 
837
 *  <td>qlp coeff precision<td>
 
838
 *  <td>qlp coeff prec search<td>
 
839
 *  <td>escape coding<td>
 
840
 *  <td>exhaustive model search<td>
 
841
 *  <td>min residual partition order<td>
 
842
 *  <td>max residual partition order<td>
 
843
 *  <td>rice parameter search dist<td>
 
844
 * </tr>
 
845
 * <tr>  <td><b>0</b><td>  <td>false<td>  <td>false<td>  <td>tukey(0.5)<td>  <td>0<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>3<td>  <td>0<td>  </tr>
 
846
 * <tr>  <td><b>1</b><td>  <td>true<td>   <td>true<td>   <td>tukey(0.5)<td>  <td>0<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>3<td>  <td>0<td>  </tr>
 
847
 * <tr>  <td><b>2</b><td>  <td>true<td>   <td>false<td>  <td>tukey(0.5)<td>  <td>0<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>3<td>  <td>0<td>  </tr>
 
848
 * <tr>  <td><b>3</b><td>  <td>false<td>  <td>false<td>  <td>tukey(0.5)<td>  <td>6<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>4<td>  <td>0<td>  </tr>
 
849
 * <tr>  <td><b>4</b><td>  <td>true<td>   <td>true<td>   <td>tukey(0.5)<td>  <td>8<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>4<td>  <td>0<td>  </tr>
 
850
 * <tr>  <td><b>5</b><td>  <td>true<td>   <td>false<td>  <td>tukey(0.5)<td>  <td>8<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>5<td>  <td>0<td>  </tr>
 
851
 * <tr>  <td><b>6</b><td>  <td>true<td>   <td>false<td>  <td>tukey(0.5)<td>  <td>8<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>false<td>  <td>0<td>  <td>6<td>  <td>0<td>  </tr>
 
852
 * <tr>  <td><b>7</b><td>  <td>true<td>   <td>false<td>  <td>tukey(0.5)<td>  <td>8<td>   <td>0<td>  <td>false<td>  <td>false<td>  <td>true<td>   <td>0<td>  <td>6<td>  <td>0<td>  </tr>
 
853
 * <tr>  <td><b>8</b><td>  <td>true<td>   <td>false<td>  <td>tukey(0.5)<td>  <td>12<td>  <td>0<td>  <td>false<td>  <td>false<td>  <td>true<td>   <td>0<td>  <td>6<td>  <td>0<td>  </tr>
 
854
 * </table>
 
855
 *
 
856
 * \default \c 5
 
857
 * \param  encoder  An encoder instance to set.
 
858
 * \param  value    See above.
 
859
 * \assert
 
860
 *    \code encoder != NULL \endcode
 
861
 * \retval FLAC__bool
 
862
 *    \c false if the encoder is already initialized, else \c true.
 
863
 */
 
864
FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
 
865
 
489
866
/** Set the blocksize to use while encoding.
490
867
 *
491
 
 * \default \c 1152
 
868
 * The number of samples to use per frame.  Use \c 0 to let the encoder
 
869
 * estimate a blocksize; this is usually best.
 
870
 *
 
871
 * \default \c 0
492
872
 * \param  encoder  An encoder instance to set.
493
873
 * \param  value    See above.
494
874
 * \assert
498
878
 */
499
879
FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
500
880
 
 
881
/** Set to \c true to enable mid-side encoding on stereo input.  The
 
882
 *  number of channels must be 2 for this to have any effect.  Set to
 
883
 *  \c false to use only independent channel coding.
 
884
 *
 
885
 * \default \c false
 
886
 * \param  encoder  An encoder instance to set.
 
887
 * \param  value    Flag value (see above).
 
888
 * \assert
 
889
 *    \code encoder != NULL \endcode
 
890
 * \retval FLAC__bool
 
891
 *    \c false if the encoder is already initialized, else \c true.
 
892
 */
 
893
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
 
894
 
 
895
/** Set to \c true to enable adaptive switching between mid-side and
 
896
 *  left-right encoding on stereo input.  Set to \c false to use
 
897
 *  exhaustive searching.  Setting this to \c true requires
 
898
 *  FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to
 
899
 *  \c true in order to have any effect.
 
900
 *
 
901
 * \default \c false
 
902
 * \param  encoder  An encoder instance to set.
 
903
 * \param  value    Flag value (see above).
 
904
 * \assert
 
905
 *    \code encoder != NULL \endcode
 
906
 * \retval FLAC__bool
 
907
 *    \c false if the encoder is already initialized, else \c true.
 
908
 */
 
909
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
 
910
 
 
911
/* @@@@add to unit tests*/
 
912
/** Sets the apodization function(s) the encoder will use when windowing
 
913
 *  audio data for LPC analysis.
 
914
 *
 
915
 * The \a specification is a plain ASCII string which specifies exactly
 
916
 * which functions to use.  There may be more than one (up to 32),
 
917
 * separated by \c ';' characters.  Some functions take one or more
 
918
 * comma-separated arguments in parentheses.
 
919
 *
 
920
 * The available functions are \c bartlett, \c bartlett_hann,
 
921
 * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop,
 
922
 * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall,
 
923
 * \c rectangle, \c triangle, \c tukey(P), \c welch.
 
924
 *
 
925
 * For \c gauss(STDDEV), STDDEV specifies the standard deviation
 
926
 * (0<STDDEV<=0.5).
 
927
 *
 
928
 * For \c tukey(P), P specifies the fraction of the window that is
 
929
 * tapered (0<=P<=1).  P=0 corresponds to \c rectangle and P=1
 
930
 * corresponds to \c hann.
 
931
 *
 
932
 * Example specifications are \c "blackman" or
 
933
 * \c "hann;triangle;tukey(0.5);tukey(0.25);tukey(0.125)"
 
934
 *
 
935
 * Any function that is specified erroneously is silently dropped.  Up
 
936
 * to 32 functions are kept, the rest are dropped.  If the specification
 
937
 * is empty the encoder defaults to \c "tukey(0.5)".
 
938
 *
 
939
 * When more than one function is specified, then for every subframe the
 
940
 * encoder will try each of them separately and choose the window that
 
941
 * results in the smallest compressed subframe.
 
942
 *
 
943
 * Note that each function specified causes the encoder to occupy a
 
944
 * floating point array in which to store the window.
 
945
 *
 
946
 * \default \c "tukey(0.5)"
 
947
 * \param  encoder        An encoder instance to set.
 
948
 * \param  specification  See above.
 
949
 * \assert
 
950
 *    \code encoder != NULL \endcode
 
951
 *    \code specification != NULL \endcode
 
952
 * \retval FLAC__bool
 
953
 *    \c false if the encoder is already initialized, else \c true.
 
954
 */
 
955
FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
 
956
 
501
957
/** Set the maximum LPC order, or \c 0 to use only the fixed predictors.
502
958
 *
503
959
 * \default \c 0
645
1101
/** Set the metadata blocks to be emitted to the stream before encoding.
646
1102
 *  A value of \c NULL, \c 0 implies no metadata; otherwise, supply an
647
1103
 *  array of pointers to metadata blocks.  The array is non-const since
648
 
 *  the encoder may need to change the \a is_last flag inside them.
649
 
 *  Otherwise, the encoder will not modify or free the blocks.  It is up
650
 
 *  to the caller to free the metadata blocks after encoding.
 
1104
 *  the encoder may need to change the \a is_last flag inside them, and
 
1105
 *  in some cases update seek point offsets.  Otherwise, the encoder will
 
1106
 *  not modify or free the blocks.  It is up to the caller to free the
 
1107
 *  metadata blocks after encoding finishes.
651
1108
 *
652
1109
 * \note
653
 
 * The encoder stores only the \a metadata pointer; the passed-in array
654
 
 * must survive at least until after FLAC__stream_encoder_init() returns.
655
 
 * Do not modify the array or free the blocks until then.
 
1110
 * The encoder stores only copies of the pointers in the \a metadata array;
 
1111
 * the metadata blocks themselves must survive at least until after
 
1112
 * FLAC__stream_encoder_finish() returns.  Do not free the blocks until then.
656
1113
 *
657
1114
 * \note
658
1115
 * The STREAMINFO block is always written and no STREAMINFO block may
660
1117
 *
661
1118
 * \note
662
1119
 * By default the encoder does not create a SEEKTABLE.  If one is supplied
663
 
 * in the \a metadata array it will be written verbatim.  However by itself
664
 
 * this is not very useful as the user will not know the stream offsets for
665
 
 * the seekpoints ahead of time.  You must use the seekable stream encoder
666
 
 * to generate a legal seektable
667
 
 * (see FLAC__seekable_stream_encoder_set_metadata())
 
1120
 * in the \a metadata array, but the client has specified that it does not
 
1121
 * support seeking, then the SEEKTABLE will be written verbatim.  However
 
1122
 * by itself this is not very useful as the client will not know the stream
 
1123
 * offsets for the seekpoints ahead of time.  In order to get a proper
 
1124
 * seektable the client must support seeking.  See next note.
 
1125
 *
 
1126
 * \note
 
1127
 * SEEKTABLE blocks are handled specially.  Since you will not know
 
1128
 * the values for the seek point stream offsets, you should pass in
 
1129
 * a SEEKTABLE 'template', that is, a SEEKTABLE object with the
 
1130
 * required sample numbers (or placeholder points), with \c 0 for the
 
1131
 * \a frame_samples and \a stream_offset fields for each point.  If the
 
1132
 * client has specified that it supports seeking by providing a seek
 
1133
 * callback to FLAC__stream_encoder_init_stream() or both seek AND read
 
1134
 * callback to FLAC__stream_encoder_init_ogg_stream() (or by using
 
1135
 * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()),
 
1136
 * then while it is encoding the encoder will fill the stream offsets in
 
1137
 * for you and when encoding is finished, it will seek back and write the
 
1138
 * real values into the SEEKTABLE block in the stream.  There are helper
 
1139
 * routines for manipulating seektable template blocks; see metadata.h:
 
1140
 * FLAC__metadata_object_seektable_template_*().  If the client does
 
1141
 * not support seeking, the SEEKTABLE will have inaccurate offsets which
 
1142
 * will slow down or remove the ability to seek in the FLAC stream.
 
1143
 *
 
1144
 * \note
 
1145
 * The encoder instance \b will modify the first \c SEEKTABLE block
 
1146
 * as it transforms the template to a valid seektable while encoding,
 
1147
 * but it is still up to the caller to free all metadata blocks after
 
1148
 * encoding.
668
1149
 *
669
1150
 * \note
670
1151
 * A VORBIS_COMMENT block may be supplied.  The vendor string in it
674
1155
 * block is present in the \a metadata array, libFLAC will write an
675
1156
 * empty one, containing only the vendor string.
676
1157
 *
 
1158
 * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be
 
1159
 * the second metadata block of the stream.  The encoder already supplies
 
1160
 * the STREAMINFO block automatically.  If \a metadata does not contain a
 
1161
 * VORBIS_COMMENT block, the encoder will supply that too.  Otherwise, if
 
1162
 * \a metadata does contain a VORBIS_COMMENT block and it is not the
 
1163
 * first, the init function will reorder \a metadata by moving the
 
1164
 * VORBIS_COMMENT block to the front; the relative ordering of the other
 
1165
 * blocks will remain as they were.
 
1166
 *
 
1167
 * \note The Ogg FLAC mapping limits the number of metadata blocks per
 
1168
 * stream to \c 65535.  If \a num_blocks exceeds this the function will
 
1169
 * return \c false.
 
1170
 *
677
1171
 * \default \c NULL, 0
678
1172
 * \param  encoder     An encoder instance to set.
679
1173
 * \param  metadata    See above.
682
1176
 *    \code encoder != NULL \endcode
683
1177
 * \retval FLAC__bool
684
1178
 *    \c false if the encoder is already initialized, else \c true.
 
1179
 *    \c false if the encoder is already initialized, or if
 
1180
 *    \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true.
685
1181
 */
686
1182
FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
687
1183
 
688
 
/** Set the write callback.
689
 
 *  The supplied function will be called by the encoder anytime there is raw
690
 
 *  encoded data ready to write.  It may include metadata mixed with encoded
691
 
 *  audio frames and the data is not guaranteed to be aligned on frame or
692
 
 *  metadata block boundaries.
693
 
 *
694
 
 *  The only duty of the callback is to write out the \a bytes worth of data
695
 
 *  in \a buffer to the current position in the output stream.  The arguments
696
 
 *  \a samples and \a current_frame are purely informational.  If \a samples
697
 
 *  is greater than \c 0, then \a current_frame will hold the current frame
698
 
 *  number that is being written; otherwise, the write callback is being called
699
 
 *  to write metadata.
700
 
 *
701
 
 * \note
702
 
 * The callback is mandatory and must be set before initialization.
703
 
 *
704
 
 * \default \c NULL
705
 
 * \param  encoder  An encoder instance to set.
706
 
 * \param  value    See above.
707
 
 * \assert
708
 
 *    \code encoder != NULL \endcode
709
 
 *    \code value != NULL \endcode
710
 
 * \retval FLAC__bool
711
 
 *    \c false if the encoder is already initialized, else \c true.
712
 
 */
713
 
FLAC_API FLAC__bool FLAC__stream_encoder_set_write_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback value);
714
 
 
715
 
/** Set the metadata callback.
716
 
 *  The supplied function will be called once at the end of encoding with
717
 
 *  the populated STREAMINFO structure.  This is so file encoders can seek
718
 
 *  back to the beginning of the file and write the STREAMINFO block with
719
 
 *  the correct statistics after encoding (like minimum/maximum frame size
720
 
 *  and total samples).
721
 
 *
722
 
 * \note
723
 
 * The callback is mandatory and must be set before initialization.
724
 
 *
725
 
 * \default \c NULL
726
 
 * \param  encoder  An encoder instance to set.
727
 
 * \param  value    See above.
728
 
 * \assert
729
 
 *    \code encoder != NULL \endcode
730
 
 *    \code value != NULL \endcode
731
 
 * \retval FLAC__bool
732
 
 *    \c false if the encoder is already initialized, else \c true.
733
 
 */
734
 
FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata_callback(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderMetadataCallback value);
735
 
 
736
 
/** Set the client data to be passed back to callbacks.
737
 
 *  This value will be supplied to callbacks in their \a client_data
738
 
 *  argument.
739
 
 *
740
 
 * \default \c NULL
741
 
 * \param  encoder  An encoder instance to set.
742
 
 * \param  value    See above.
743
 
 * \assert
744
 
 *    \code encoder != NULL \endcode
745
 
 * \retval FLAC__bool
746
 
 *    \c false if the encoder is already initialized, else \c true.
747
 
 */
748
 
FLAC_API FLAC__bool FLAC__stream_encoder_set_client_data(FLAC__StreamEncoder *encoder, void *value);
749
 
 
750
1184
/** Get the current encoder state.
751
1185
 *
752
1186
 * \param  encoder  An encoder instance to query.
811
1245
 */
812
1246
FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
813
1247
 
814
 
/** Get the "streamable subset" flag.
 
1248
/** Get the <A HREF="../format.html#subset>Subset</A> flag.
815
1249
 *
816
1250
 * \param  encoder  An encoder instance to query.
817
1251
 * \assert
821
1255
 */
822
1256
FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
823
1257
 
824
 
/** Get the "mid/side stereo coding" flag.
825
 
 *
826
 
 * \param  encoder  An encoder instance to query.
827
 
 * \assert
828
 
 *    \code encoder != NULL \endcode
829
 
 * \retval FLAC__bool
830
 
 *    See FLAC__stream_encoder_get_do_mid_side_stereo().
831
 
 */
832
 
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
833
 
 
834
 
/** Get the "adaptive mid/side switching" flag.
835
 
 *
836
 
 * \param  encoder  An encoder instance to query.
837
 
 * \assert
838
 
 *    \code encoder != NULL \endcode
839
 
 * \retval FLAC__bool
840
 
 *    See FLAC__stream_encoder_set_loose_mid_side_stereo().
841
 
 */
842
 
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
843
 
 
844
1258
/** Get the number of input channels being processed.
845
1259
 *
846
1260
 * \param  encoder  An encoder instance to query.
881
1295
 */
882
1296
FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
883
1297
 
 
1298
/** Get the "mid/side stereo coding" flag.
 
1299
 *
 
1300
 * \param  encoder  An encoder instance to query.
 
1301
 * \assert
 
1302
 *    \code encoder != NULL \endcode
 
1303
 * \retval FLAC__bool
 
1304
 *    See FLAC__stream_encoder_get_do_mid_side_stereo().
 
1305
 */
 
1306
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
 
1307
 
 
1308
/** Get the "adaptive mid/side switching" flag.
 
1309
 *
 
1310
 * \param  encoder  An encoder instance to query.
 
1311
 * \assert
 
1312
 *    \code encoder != NULL \endcode
 
1313
 * \retval FLAC__bool
 
1314
 *    See FLAC__stream_encoder_set_loose_mid_side_stereo().
 
1315
 */
 
1316
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
 
1317
 
884
1318
/** Get the maximum LPC order setting.
885
1319
 *
886
1320
 * \param  encoder  An encoder instance to query.
964
1398
/** Get the previously set estimate of the total samples to be encoded.
965
1399
 *  The encoder merely mimics back the value given to
966
1400
 *  FLAC__stream_encoder_set_total_samples_estimate() since it has no
967
 
 *  other way of knowing how many samples the user will encode.
 
1401
 *  other way of knowing how many samples the client will encode.
968
1402
 *
969
1403
 * \param  encoder  An encoder instance to set.
970
1404
 * \assert
974
1408
 */
975
1409
FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
976
1410
 
977
 
/** Initialize the encoder instance.
978
 
 *  Should be called after FLAC__stream_encoder_new() and
979
 
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
980
 
 *  or FLAC__stream_encoder_process_interleaved().  Will set and return
981
 
 *  the encoder state, which will be FLAC__STREAM_ENCODER_OK if
982
 
 *  initialization succeeded.
983
 
 *
984
 
 *  The call to FLAC__stream_encoder_init() currently will also immediately
985
 
 *  call the write callback several times, once with the \c fLaC signature,
986
 
 *  and once for each encoded metadata block.
987
 
 *
988
 
 * \param  encoder  An uninitialized encoder instance.
989
 
 * \assert
990
 
 *    \code encoder != NULL \endcode
991
 
 * \retval FLAC__StreamEncoderState
992
 
 *    \c FLAC__STREAM_ENCODER_OK if initialization was successful; see
993
 
 *    FLAC__StreamEncoderState for the meanings of other return values.
994
 
 */
995
 
FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_init(FLAC__StreamEncoder *encoder);
 
1411
/** Initialize the encoder instance to encode native FLAC streams.
 
1412
 *
 
1413
 *  This flavor of initialization sets up the encoder to encode to a
 
1414
 *  native FLAC stream. I/O is performed via callbacks to the client.
 
1415
 *  For encoding to a plain file via filename or open \c FILE*,
 
1416
 *  FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE()
 
1417
 *  provide a simpler interface.
 
1418
 *
 
1419
 *  This function should be called after FLAC__stream_encoder_new() and
 
1420
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1421
 *  or FLAC__stream_encoder_process_interleaved().
 
1422
 *  initialization succeeded.
 
1423
 *
 
1424
 *  The call to FLAC__stream_encoder_init_stream() currently will also
 
1425
 *  immediately call the write callback several times, once with the \c fLaC
 
1426
 *  signature, and once for each encoded metadata block.
 
1427
 *
 
1428
 * \param  encoder            An uninitialized encoder instance.
 
1429
 * \param  write_callback     See FLAC__StreamEncoderWriteCallback.  This
 
1430
 *                            pointer must not be \c NULL.
 
1431
 * \param  seek_callback      See FLAC__StreamEncoderSeekCallback.  This
 
1432
 *                            pointer may be \c NULL if seeking is not
 
1433
 *                            supported.  The encoder uses seeking to go back
 
1434
 *                            and write some some stream statistics to the
 
1435
 *                            STREAMINFO block; this is recommended but not
 
1436
 *                            necessary to create a valid FLAC stream.  If
 
1437
 *                            \a seek_callback is not \c NULL then a
 
1438
 *                            \a tell_callback must also be supplied.
 
1439
 *                            Alternatively, a dummy seek callback that just
 
1440
 *                            returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
 
1441
 *                            may also be supplied, all though this is slightly
 
1442
 *                            less efficient for the encoder.
 
1443
 * \param  tell_callback      See FLAC__StreamEncoderTellCallback.  This
 
1444
 *                            pointer may be \c NULL if seeking is not
 
1445
 *                            supported.  If \a seek_callback is \c NULL then
 
1446
 *                            this argument will be ignored.  If
 
1447
 *                            \a seek_callback is not \c NULL then a
 
1448
 *                            \a tell_callback must also be supplied.
 
1449
 *                            Alternatively, a dummy tell callback that just
 
1450
 *                            returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
 
1451
 *                            may also be supplied, all though this is slightly
 
1452
 *                            less efficient for the encoder.
 
1453
 * \param  metadata_callback  See FLAC__StreamEncoderMetadataCallback.  This
 
1454
 *                            pointer may be \c NULL if the callback is not
 
1455
 *                            desired.  If the client provides a seek callback,
 
1456
 *                            this function is not necessary as the encoder
 
1457
 *                            will automatically seek back and update the
 
1458
 *                            STREAMINFO block.  It may also be \c NULL if the
 
1459
 *                            client does not support seeking, since it will
 
1460
 *                            have no way of going back to update the
 
1461
 *                            STREAMINFO.  However the client can still supply
 
1462
 *                            a callback if it would like to know the details
 
1463
 *                            from the STREAMINFO.
 
1464
 * \param  client_data        This value will be supplied to callbacks in their
 
1465
 *                            \a client_data argument.
 
1466
 * \assert
 
1467
 *    \code encoder != NULL \endcode
 
1468
 * \retval FLAC__StreamEncoderInitStatus
 
1469
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1470
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1471
 */
 
1472
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
 
1473
 
 
1474
/** Initialize the encoder instance to encode Ogg FLAC streams.
 
1475
 *
 
1476
 *  This flavor of initialization sets up the encoder to encode to a FLAC
 
1477
 *  stream in an Ogg container.  I/O is performed via callbacks to the
 
1478
 *  client.  For encoding to a plain file via filename or open \c FILE*,
 
1479
 *  FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE()
 
1480
 *  provide a simpler interface.
 
1481
 *
 
1482
 *  This function should be called after FLAC__stream_encoder_new() and
 
1483
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1484
 *  or FLAC__stream_encoder_process_interleaved().
 
1485
 *  initialization succeeded.
 
1486
 *
 
1487
 *  The call to FLAC__stream_encoder_init_ogg_stream() currently will also
 
1488
 *  immediately call the write callback several times to write the metadata
 
1489
 *  packets.
 
1490
 *
 
1491
 * \param  encoder            An uninitialized encoder instance.
 
1492
 * \param  read_callback      See FLAC__StreamEncoderReadCallback.  This
 
1493
 *                            pointer must not be \c NULL if \a seek_callback
 
1494
 *                            is non-NULL since they are both needed to be
 
1495
 *                            able to write data back to the Ogg FLAC stream
 
1496
 *                            in the post-encode phase.
 
1497
 * \param  write_callback     See FLAC__StreamEncoderWriteCallback.  This
 
1498
 *                            pointer must not be \c NULL.
 
1499
 * \param  seek_callback      See FLAC__StreamEncoderSeekCallback.  This
 
1500
 *                            pointer may be \c NULL if seeking is not
 
1501
 *                            supported.  The encoder uses seeking to go back
 
1502
 *                            and write some some stream statistics to the
 
1503
 *                            STREAMINFO block; this is recommended but not
 
1504
 *                            necessary to create a valid FLAC stream.  If
 
1505
 *                            \a seek_callback is not \c NULL then a
 
1506
 *                            \a tell_callback must also be supplied.
 
1507
 *                            Alternatively, a dummy seek callback that just
 
1508
 *                            returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
 
1509
 *                            may also be supplied, all though this is slightly
 
1510
 *                            less efficient for the encoder.
 
1511
 * \param  tell_callback      See FLAC__StreamEncoderTellCallback.  This
 
1512
 *                            pointer may be \c NULL if seeking is not
 
1513
 *                            supported.  If \a seek_callback is \c NULL then
 
1514
 *                            this argument will be ignored.  If
 
1515
 *                            \a seek_callback is not \c NULL then a
 
1516
 *                            \a tell_callback must also be supplied.
 
1517
 *                            Alternatively, a dummy tell callback that just
 
1518
 *                            returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
 
1519
 *                            may also be supplied, all though this is slightly
 
1520
 *                            less efficient for the encoder.
 
1521
 * \param  metadata_callback  See FLAC__StreamEncoderMetadataCallback.  This
 
1522
 *                            pointer may be \c NULL if the callback is not
 
1523
 *                            desired.  If the client provides a seek callback,
 
1524
 *                            this function is not necessary as the encoder
 
1525
 *                            will automatically seek back and update the
 
1526
 *                            STREAMINFO block.  It may also be \c NULL if the
 
1527
 *                            client does not support seeking, since it will
 
1528
 *                            have no way of going back to update the
 
1529
 *                            STREAMINFO.  However the client can still supply
 
1530
 *                            a callback if it would like to know the details
 
1531
 *                            from the STREAMINFO.
 
1532
 * \param  client_data        This value will be supplied to callbacks in their
 
1533
 *                            \a client_data argument.
 
1534
 * \assert
 
1535
 *    \code encoder != NULL \endcode
 
1536
 * \retval FLAC__StreamEncoderInitStatus
 
1537
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1538
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1539
 */
 
1540
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data);
 
1541
 
 
1542
/** Initialize the encoder instance to encode native FLAC files.
 
1543
 *
 
1544
 *  This flavor of initialization sets up the encoder to encode to a
 
1545
 *  plain native FLAC file.  For non-stdio streams, you must use
 
1546
 *  FLAC__stream_encoder_init_stream() and provide callbacks for the I/O.
 
1547
 *
 
1548
 *  This function should be called after FLAC__stream_encoder_new() and
 
1549
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1550
 *  or FLAC__stream_encoder_process_interleaved().
 
1551
 *  initialization succeeded.
 
1552
 *
 
1553
 * \param  encoder            An uninitialized encoder instance.
 
1554
 * \param  file               An open file.  The file should have been opened
 
1555
 *                            with mode \c "w+b" and rewound.  The file
 
1556
 *                            becomes owned by the encoder and should not be
 
1557
 *                            manipulated by the client while encoding.
 
1558
 *                            Unless \a file is \c stdout, it will be closed
 
1559
 *                            when FLAC__stream_encoder_finish() is called.
 
1560
 *                            Note however that a proper SEEKTABLE cannot be
 
1561
 *                            created when encoding to \c stdout since it is
 
1562
 *                            not seekable.
 
1563
 * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
 
1564
 *                            pointer may be \c NULL if the callback is not
 
1565
 *                            desired.
 
1566
 * \param  client_data        This value will be supplied to callbacks in their
 
1567
 *                            \a client_data argument.
 
1568
 * \assert
 
1569
 *    \code encoder != NULL \endcode
 
1570
 *    \code file != NULL \endcode
 
1571
 * \retval FLAC__StreamEncoderInitStatus
 
1572
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1573
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1574
 */
 
1575
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
 
1576
 
 
1577
/** Initialize the encoder instance to encode Ogg FLAC files.
 
1578
 *
 
1579
 *  This flavor of initialization sets up the encoder to encode to a
 
1580
 *  plain Ogg FLAC file.  For non-stdio streams, you must use
 
1581
 *  FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O.
 
1582
 *
 
1583
 *  This function should be called after FLAC__stream_encoder_new() and
 
1584
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1585
 *  or FLAC__stream_encoder_process_interleaved().
 
1586
 *  initialization succeeded.
 
1587
 *
 
1588
 * \param  encoder            An uninitialized encoder instance.
 
1589
 * \param  file               An open file.  The file should have been opened
 
1590
 *                            with mode \c "w+b" and rewound.  The file
 
1591
 *                            becomes owned by the encoder and should not be
 
1592
 *                            manipulated by the client while encoding.
 
1593
 *                            Unless \a file is \c stdout, it will be closed
 
1594
 *                            when FLAC__stream_encoder_finish() is called.
 
1595
 *                            Note however that a proper SEEKTABLE cannot be
 
1596
 *                            created when encoding to \c stdout since it is
 
1597
 *                            not seekable.
 
1598
 * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
 
1599
 *                            pointer may be \c NULL if the callback is not
 
1600
 *                            desired.
 
1601
 * \param  client_data        This value will be supplied to callbacks in their
 
1602
 *                            \a client_data argument.
 
1603
 * \assert
 
1604
 *    \code encoder != NULL \endcode
 
1605
 *    \code file != NULL \endcode
 
1606
 * \retval FLAC__StreamEncoderInitStatus
 
1607
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1608
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1609
 */
 
1610
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
 
1611
 
 
1612
/** Initialize the encoder instance to encode native FLAC files.
 
1613
 *
 
1614
 *  This flavor of initialization sets up the encoder to encode to a plain
 
1615
 *  FLAC file.  If POSIX fopen() semantics are not sufficient (for example,
 
1616
 *  with Unicode filenames on Windows), you must use
 
1617
 *  FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream()
 
1618
 *  and provide callbacks for the I/O.
 
1619
 *
 
1620
 *  This function should be called after FLAC__stream_encoder_new() and
 
1621
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1622
 *  or FLAC__stream_encoder_process_interleaved().
 
1623
 *  initialization succeeded.
 
1624
 *
 
1625
 * \param  encoder            An uninitialized encoder instance.
 
1626
 * \param  filename           The name of the file to encode to.  The file will
 
1627
 *                            be opened with fopen().  Use \c NULL to encode to
 
1628
 *                            \c stdout.  Note however that a proper SEEKTABLE
 
1629
 *                            cannot be created when encoding to \c stdout since
 
1630
 *                            it is not seekable.
 
1631
 * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
 
1632
 *                            pointer may be \c NULL if the callback is not
 
1633
 *                            desired.
 
1634
 * \param  client_data        This value will be supplied to callbacks in their
 
1635
 *                            \a client_data argument.
 
1636
 * \assert
 
1637
 *    \code encoder != NULL \endcode
 
1638
 * \retval FLAC__StreamEncoderInitStatus
 
1639
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1640
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1641
 */
 
1642
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
 
1643
 
 
1644
/** Initialize the encoder instance to encode Ogg FLAC files.
 
1645
 *
 
1646
 *  This flavor of initialization sets up the encoder to encode to a plain
 
1647
 *  Ogg FLAC file.  If POSIX fopen() semantics are not sufficient (for example,
 
1648
 *  with Unicode filenames on Windows), you must use
 
1649
 *  FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream()
 
1650
 *  and provide callbacks for the I/O.
 
1651
 *
 
1652
 *  This function should be called after FLAC__stream_encoder_new() and
 
1653
 *  FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process()
 
1654
 *  or FLAC__stream_encoder_process_interleaved().
 
1655
 *  initialization succeeded.
 
1656
 *
 
1657
 * \param  encoder            An uninitialized encoder instance.
 
1658
 * \param  filename           The name of the file to encode to.  The file will
 
1659
 *                            be opened with fopen().  Use \c NULL to encode to
 
1660
 *                            \c stdout.  Note however that a proper SEEKTABLE
 
1661
 *                            cannot be created when encoding to \c stdout since
 
1662
 *                            it is not seekable.
 
1663
 * \param  progress_callback  See FLAC__StreamEncoderProgressCallback.  This
 
1664
 *                            pointer may be \c NULL if the callback is not
 
1665
 *                            desired.
 
1666
 * \param  client_data        This value will be supplied to callbacks in their
 
1667
 *                            \a client_data argument.
 
1668
 * \assert
 
1669
 *    \code encoder != NULL \endcode
 
1670
 * \retval FLAC__StreamEncoderInitStatus
 
1671
 *    \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful;
 
1672
 *    see FLAC__StreamEncoderInitStatus for the meanings of other return values.
 
1673
 */
 
1674
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
996
1675
 
997
1676
/** Finish the encoding process.
998
1677
 *  Flushes the encoding buffer, releases resources, resets the encoder
1001
1680
 *  one or more write callbacks before returning, and will generate
1002
1681
 *  a metadata callback.
1003
1682
 *
 
1683
 *  Note that in the course of processing the last frame, errors can
 
1684
 *  occur, so the caller should be sure to check the return value to
 
1685
 *  ensure the file was encoded properly.
 
1686
 *
1004
1687
 *  In the event of a prematurely-terminated encode, it is not strictly
1005
1688
 *  necessary to call this immediately before FLAC__stream_encoder_delete()
1006
 
 *  but it is good practice to match every FLAC__stream_encoder_init()
 
1689
 *  but it is good practice to match every FLAC__stream_encoder_init_*()
1007
1690
 *  with a FLAC__stream_encoder_finish().
1008
1691
 *
1009
1692
 * \param  encoder  An uninitialized encoder instance.
1010
1693
 * \assert
1011
1694
 *    \code encoder != NULL \endcode
 
1695
 * \retval FLAC__bool
 
1696
 *    \c false if an error occurred processing the last frame; or if verify
 
1697
 *    mode is set (see FLAC__stream_encoder_set_verify()), there was a
 
1698
 *    verify mismatch; else \c true.  If \c false, caller should check the
 
1699
 *    state with FLAC__stream_encoder_get_state() for more information
 
1700
 *    about the error.
1012
1701
 */
1013
 
FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
 
1702
FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
1014
1703
 
1015
1704
/** Submit data for encoding.
1016
1705
 *  This version allows you to supply the input data via an array of
1017
1706
 *  pointers, each pointer pointing to an array of \a samples samples
1018
1707
 *  representing one channel.  The samples need not be block-aligned,
1019
 
 *  but each channel should have the same number of samples.
 
1708
 *  but each channel should have the same number of samples.  Each sample
 
1709
 *  should be a signed integer, right-justified to the resolution set by
 
1710
 *  FLAC__stream_encoder_set_bits_per_sample().  For example, if the
 
1711
 *  resolution is 16 bits per sample, the samples should all be in the
 
1712
 *  range [-32768,32767].
 
1713
 *
 
1714
 *  For applications where channel order is important, channels must
 
1715
 *  follow the order as described in the
 
1716
 *  <A HREF="../format.html#frame_header">frame header</A>.
1020
1717
 *
1021
1718
 * \param  encoder  An initialized encoder instance in the OK state.
1022
1719
 * \param  buffer   An array of pointers to each channel's signal.
1037
1734
 *  channel1_sample0, ... , channelN_sample0, channel0_sample1, ...).
1038
1735
 *  The samples need not be block-aligned but they must be
1039
1736
 *  sample-aligned, i.e. the first value should be channel0_sample0
1040
 
 *  and the last value channelN_sampleM.
 
1737
 *  and the last value channelN_sampleM.  Each sample should be a signed
 
1738
 *  integer, right-justified to the resolution set by
 
1739
 *  FLAC__stream_encoder_set_bits_per_sample().  For example, if the
 
1740
 *  resolution is 16 bits per sample, the samples should all be in the
 
1741
 *  range [-32768,32767].
 
1742
 *
 
1743
 *  For applications where channel order is important, channels must
 
1744
 *  follow the order as described in the
 
1745
 *  <A HREF="../format.html#frame_header">frame header</A>.
1041
1746
 *
1042
1747
 * \param  encoder  An initialized encoder instance in the OK state.
1043
1748
 * \param  buffer   An array of channel-interleaved data (see above).