annotate win32-mingw/include/FLAC/stream_encoder.h @ 33:879bdc878826

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