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