cannam@87: /* libFLAC - Free Lossless Audio Codec library cannam@87: * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson cannam@87: * cannam@87: * Redistribution and use in source and binary forms, with or without cannam@87: * modification, are permitted provided that the following conditions cannam@87: * are met: cannam@87: * cannam@87: * - Redistributions of source code must retain the above copyright cannam@87: * notice, this list of conditions and the following disclaimer. cannam@87: * cannam@87: * - Redistributions in binary form must reproduce the above copyright cannam@87: * notice, this list of conditions and the following disclaimer in the cannam@87: * documentation and/or other materials provided with the distribution. cannam@87: * cannam@87: * - Neither the name of the Xiph.org Foundation nor the names of its cannam@87: * contributors may be used to endorse or promote products derived from cannam@87: * this software without specific prior written permission. cannam@87: * cannam@87: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@87: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@87: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@87: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR cannam@87: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@87: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@87: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@87: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@87: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@87: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@87: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@87: */ cannam@87: cannam@87: #ifndef FLAC__STREAM_ENCODER_H cannam@87: #define FLAC__STREAM_ENCODER_H cannam@87: cannam@87: #include /* for FILE */ cannam@87: #include "export.h" cannam@87: #include "format.h" cannam@87: #include "stream_decoder.h" cannam@87: cannam@87: #ifdef __cplusplus cannam@87: extern "C" { cannam@87: #endif cannam@87: cannam@87: cannam@87: /** \file include/FLAC/stream_encoder.h cannam@87: * cannam@87: * \brief cannam@87: * This module contains the functions which implement the stream cannam@87: * encoder. cannam@87: * cannam@87: * See the detailed documentation in the cannam@87: * \link flac_stream_encoder stream encoder \endlink module. cannam@87: */ cannam@87: cannam@87: /** \defgroup flac_encoder FLAC/ \*_encoder.h: encoder interfaces cannam@87: * \ingroup flac cannam@87: * cannam@87: * \brief cannam@87: * This module describes the encoder layers provided by libFLAC. cannam@87: * cannam@87: * The stream encoder can be used to encode complete streams either to the cannam@87: * client via callbacks, or directly to a file, depending on how it is cannam@87: * initialized. When encoding via callbacks, the client provides a write cannam@87: * callback which will be called whenever FLAC data is ready to be written. cannam@87: * If the client also supplies a seek callback, the encoder will also cannam@87: * automatically handle the writing back of metadata discovered while cannam@87: * encoding, like stream info, seek points offsets, etc. When encoding to cannam@87: * a file, the client needs only supply a filename or open \c FILE* and an cannam@87: * optional progress callback for periodic notification of progress; the cannam@87: * write and seek callbacks are supplied internally. For more info see the cannam@87: * \link flac_stream_encoder stream encoder \endlink module. cannam@87: */ cannam@87: cannam@87: /** \defgroup flac_stream_encoder FLAC/stream_encoder.h: stream encoder interface cannam@87: * \ingroup flac_encoder cannam@87: * cannam@87: * \brief cannam@87: * This module contains the functions which implement the stream cannam@87: * encoder. cannam@87: * cannam@87: * The stream encoder can encode to native FLAC, and optionally Ogg FLAC cannam@87: * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files. cannam@87: * cannam@87: * The basic usage of this encoder is as follows: cannam@87: * - The program creates an instance of an encoder using cannam@87: * FLAC__stream_encoder_new(). cannam@87: * - The program overrides the default settings using cannam@87: * FLAC__stream_encoder_set_*() functions. At a minimum, the following cannam@87: * functions should be called: cannam@87: * - FLAC__stream_encoder_set_channels() cannam@87: * - FLAC__stream_encoder_set_bits_per_sample() cannam@87: * - FLAC__stream_encoder_set_sample_rate() cannam@87: * - FLAC__stream_encoder_set_ogg_serial_number() (if encoding to Ogg FLAC) cannam@87: * - FLAC__stream_encoder_set_total_samples_estimate() (if known) cannam@87: * - If the application wants to control the compression level or set its own cannam@87: * metadata, then the following should also be called: cannam@87: * - FLAC__stream_encoder_set_compression_level() cannam@87: * - FLAC__stream_encoder_set_verify() cannam@87: * - FLAC__stream_encoder_set_metadata() cannam@87: * - The rest of the set functions should only be called if the client needs cannam@87: * exact control over how the audio is compressed; thorough understanding cannam@87: * of the FLAC format is necessary to achieve good results. cannam@87: * - The program initializes the instance to validate the settings and cannam@87: * prepare for encoding using cannam@87: * - FLAC__stream_encoder_init_stream() or FLAC__stream_encoder_init_FILE() cannam@87: * or FLAC__stream_encoder_init_file() for native FLAC cannam@87: * - FLAC__stream_encoder_init_ogg_stream() or FLAC__stream_encoder_init_ogg_FILE() cannam@87: * or FLAC__stream_encoder_init_ogg_file() for Ogg FLAC cannam@87: * - The program calls FLAC__stream_encoder_process() or cannam@87: * FLAC__stream_encoder_process_interleaved() to encode data, which cannam@87: * subsequently calls the callbacks when there is encoder data ready cannam@87: * to be written. cannam@87: * - The program finishes the encoding with FLAC__stream_encoder_finish(), cannam@87: * which causes the encoder to encode any data still in its input pipe, cannam@87: * update the metadata with the final encoding statistics if output cannam@87: * seeking is possible, and finally reset the encoder to the cannam@87: * uninitialized state. cannam@87: * - The instance may be used again or deleted with cannam@87: * FLAC__stream_encoder_delete(). cannam@87: * cannam@87: * In more detail, the stream encoder functions similarly to the cannam@87: * \link flac_stream_decoder stream decoder \endlink, but has fewer cannam@87: * callbacks and more options. Typically the client will create a new cannam@87: * instance by calling FLAC__stream_encoder_new(), then set the necessary cannam@87: * parameters with FLAC__stream_encoder_set_*(), and initialize it by cannam@87: * calling one of the FLAC__stream_encoder_init_*() functions. cannam@87: * cannam@87: * Unlike the decoders, the stream encoder has many options that can cannam@87: * affect the speed and compression ratio. When setting these parameters cannam@87: * you should have some basic knowledge of the format (see the cannam@87: * user-level documentation cannam@87: * or the formal description). The cannam@87: * FLAC__stream_encoder_set_*() functions themselves do not validate the cannam@87: * values as many are interdependent. The FLAC__stream_encoder_init_*() cannam@87: * functions will do this, so make sure to pay attention to the state cannam@87: * returned by FLAC__stream_encoder_init_*() to make sure that it is cannam@87: * FLAC__STREAM_ENCODER_INIT_STATUS_OK. Any parameters that are not set cannam@87: * before FLAC__stream_encoder_init_*() will take on the defaults from cannam@87: * the constructor. cannam@87: * cannam@87: * There are three initialization functions for native FLAC, one for cannam@87: * setting up the encoder to encode FLAC data to the client via cannam@87: * callbacks, and two for encoding directly to a file. cannam@87: * cannam@87: * For encoding via callbacks, use FLAC__stream_encoder_init_stream(). cannam@87: * You must also supply a write callback which will be called anytime cannam@87: * there is raw encoded data to write. If the client can seek the output cannam@87: * it is best to also supply seek and tell callbacks, as this allows the cannam@87: * encoder to go back after encoding is finished to write back cannam@87: * information that was collected while encoding, like seek point offsets, cannam@87: * frame sizes, etc. cannam@87: * cannam@87: * For encoding directly to a file, use FLAC__stream_encoder_init_FILE() cannam@87: * or FLAC__stream_encoder_init_file(). Then you must only supply a cannam@87: * filename or open \c FILE*; the encoder will handle all the callbacks cannam@87: * internally. You may also supply a progress callback for periodic cannam@87: * notification of the encoding progress. cannam@87: * cannam@87: * There are three similarly-named init functions for encoding to Ogg cannam@87: * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the cannam@87: * library has been built with Ogg support. cannam@87: * cannam@87: * The call to FLAC__stream_encoder_init_*() currently will also immediately cannam@87: * call the write callback several times, once with the \c fLaC signature, cannam@87: * and once for each encoded metadata block. Note that for Ogg FLAC cannam@87: * encoding you will usually get at least twice the number of callbacks than cannam@87: * with native FLAC, one for the Ogg page header and one for the page body. cannam@87: * cannam@87: * After initializing the instance, the client may feed audio data to the cannam@87: * encoder in one of two ways: cannam@87: * cannam@87: * - Channel separate, through FLAC__stream_encoder_process() - The client cannam@87: * will pass an array of pointers to buffers, one for each channel, to cannam@87: * the encoder, each of the same length. The samples need not be cannam@87: * block-aligned, but each channel should have the same number of samples. cannam@87: * - Channel interleaved, through cannam@87: * FLAC__stream_encoder_process_interleaved() - The client will pass a single cannam@87: * pointer to data that is channel-interleaved (i.e. channel0_sample0, cannam@87: * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). cannam@87: * Again, the samples need not be block-aligned but they must be cannam@87: * sample-aligned, i.e. the first value should be channel0_sample0 and cannam@87: * the last value channelN_sampleM. cannam@87: * cannam@87: * Note that for either process call, each sample in the buffers should be a cannam@87: * signed integer, right-justified to the resolution set by cannam@87: * FLAC__stream_encoder_set_bits_per_sample(). For example, if the resolution cannam@87: * is 16 bits per sample, the samples should all be in the range [-32768,32767]. cannam@87: * cannam@87: * When the client is finished encoding data, it calls cannam@87: * FLAC__stream_encoder_finish(), which causes the encoder to encode any cannam@87: * data still in its input pipe, and call the metadata callback with the cannam@87: * final encoding statistics. Then the instance may be deleted with cannam@87: * FLAC__stream_encoder_delete() or initialized again to encode another cannam@87: * stream. cannam@87: * cannam@87: * For programs that write their own metadata, but that do not know the cannam@87: * actual metadata until after encoding, it is advantageous to instruct cannam@87: * the encoder to write a PADDING block of the correct size, so that cannam@87: * instead of rewriting the whole stream after encoding, the program can cannam@87: * just overwrite the PADDING block. If only the maximum size of the cannam@87: * metadata is known, the program can write a slightly larger padding cannam@87: * block, then split it after encoding. cannam@87: * cannam@87: * Make sure you understand how lengths are calculated. All FLAC metadata cannam@87: * blocks have a 4 byte header which contains the type and length. This cannam@87: * length does not include the 4 bytes of the header. See the format page cannam@87: * for the specification of metadata blocks and their lengths. cannam@87: * cannam@87: * \note cannam@87: * If you are writing the FLAC data to a file via callbacks, make sure it cannam@87: * is open for update (e.g. mode "w+" for stdio streams). This is because cannam@87: * after the first encoding pass, the encoder will try to seek back to the cannam@87: * beginning of the stream, to the STREAMINFO block, to write some data cannam@87: * there. (If using FLAC__stream_encoder_init*_file() or cannam@87: * FLAC__stream_encoder_init*_FILE(), the file is managed internally.) cannam@87: * cannam@87: * \note cannam@87: * The "set" functions may only be called when the encoder is in the cannam@87: * state FLAC__STREAM_ENCODER_UNINITIALIZED, i.e. after cannam@87: * FLAC__stream_encoder_new() or FLAC__stream_encoder_finish(), but cannam@87: * before FLAC__stream_encoder_init_*(). If this is the case they will cannam@87: * return \c true, otherwise \c false. cannam@87: * cannam@87: * \note cannam@87: * FLAC__stream_encoder_finish() resets all settings to the constructor cannam@87: * defaults. cannam@87: * cannam@87: * \{ cannam@87: */ cannam@87: cannam@87: cannam@87: /** State values for a FLAC__StreamEncoder. cannam@87: * cannam@87: * The encoder's state can be obtained by calling FLAC__stream_encoder_get_state(). cannam@87: * cannam@87: * If the encoder gets into any other state besides \c FLAC__STREAM_ENCODER_OK cannam@87: * or \c FLAC__STREAM_ENCODER_UNINITIALIZED, it becomes invalid for encoding and cannam@87: * must be deleted with FLAC__stream_encoder_delete(). cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_OK = 0, cannam@87: /**< The encoder is in the normal OK state and samples can be processed. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_UNINITIALIZED, cannam@87: /**< The encoder is in the uninitialized state; one of the cannam@87: * FLAC__stream_encoder_init_*() functions must be called before samples cannam@87: * can be processed. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_OGG_ERROR, cannam@87: /**< An error occurred in the underlying Ogg layer. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR, cannam@87: /**< An error occurred in the underlying verify stream decoder; cannam@87: * check FLAC__stream_encoder_get_verify_decoder_state(). cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA, cannam@87: /**< The verify decoder detected a mismatch between the original cannam@87: * audio signal and the decoded audio signal. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_CLIENT_ERROR, cannam@87: /**< One of the callbacks returned a fatal error. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_IO_ERROR, cannam@87: /**< An I/O error occurred while opening/reading/writing a file. cannam@87: * Check \c errno. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_FRAMING_ERROR, cannam@87: /**< An error occurred while writing the stream; usually, the cannam@87: * write_callback returned an error. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR cannam@87: /**< Memory allocation failed. */ cannam@87: cannam@87: } FLAC__StreamEncoderState; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderState to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderState as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderStateString[]; cannam@87: cannam@87: cannam@87: /** Possible return values for the FLAC__stream_encoder_init_*() functions. cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0, cannam@87: /**< Initialization was successful. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR, cannam@87: /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER, cannam@87: /**< The library was not compiled with support for the given container cannam@87: * format. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS, cannam@87: /**< A required callback was not supplied. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS, cannam@87: /**< The encoder has an invalid setting for number of channels. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE, cannam@87: /**< The encoder has an invalid setting for bits-per-sample. cannam@87: * FLAC supports 4-32 bps but the reference encoder currently supports cannam@87: * only up to 24 bps. cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE, cannam@87: /**< The encoder has an invalid setting for the input sample rate. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE, cannam@87: /**< The encoder has an invalid setting for the block size. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER, cannam@87: /**< The encoder has an invalid setting for the maximum LPC order. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION, cannam@87: /**< The encoder has an invalid setting for the precision of the quantized linear predictor coefficients. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER, cannam@87: /**< The specified block size is less than the maximum LPC order. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE, cannam@87: /**< The encoder is bound to the Subset but other settings violate it. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA, cannam@87: /**< The metadata input to the encoder is invalid, in one of the following ways: cannam@87: * - FLAC__stream_encoder_set_metadata() was called with a null pointer but a block count > 0 cannam@87: * - One of the metadata blocks contains an undefined type cannam@87: * - It contains an illegal CUESHEET as checked by FLAC__format_cuesheet_is_legal() cannam@87: * - It contains an illegal SEEKTABLE as checked by FLAC__format_seektable_is_legal() cannam@87: * - It contains more than one SEEKTABLE block or more than one VORBIS_COMMENT block cannam@87: */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED cannam@87: /**< FLAC__stream_encoder_init_*() was called when the encoder was cannam@87: * already initialized, usually because cannam@87: * FLAC__stream_encoder_finish() was not called. cannam@87: */ cannam@87: cannam@87: } FLAC__StreamEncoderInitStatus; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderInitStatus to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderInitStatus as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[]; cannam@87: cannam@87: cannam@87: /** Return values for the FLAC__StreamEncoder read callback. cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE, cannam@87: /**< The read was OK and decoding can continue. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM, cannam@87: /**< The read was attempted at the end of the stream. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_READ_STATUS_ABORT, cannam@87: /**< An unrecoverable error occurred. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED cannam@87: /**< Client does not support reading back from the output. */ cannam@87: cannam@87: } FLAC__StreamEncoderReadStatus; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderReadStatus to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderReadStatus as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[]; cannam@87: cannam@87: cannam@87: /** Return values for the FLAC__StreamEncoder write callback. cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0, cannam@87: /**< The write was OK and encoding can continue. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR cannam@87: /**< An unrecoverable error occurred. The encoder will return from the process call. */ cannam@87: cannam@87: } FLAC__StreamEncoderWriteStatus; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderWriteStatus to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderWriteStatus as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[]; cannam@87: cannam@87: cannam@87: /** Return values for the FLAC__StreamEncoder seek callback. cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_SEEK_STATUS_OK, cannam@87: /**< The seek was OK and encoding can continue. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR, cannam@87: /**< An unrecoverable error occurred. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED cannam@87: /**< Client does not support seeking. */ cannam@87: cannam@87: } FLAC__StreamEncoderSeekStatus; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderSeekStatus to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderSeekStatus as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[]; cannam@87: cannam@87: cannam@87: /** Return values for the FLAC__StreamEncoder tell callback. cannam@87: */ cannam@87: typedef enum { cannam@87: cannam@87: FLAC__STREAM_ENCODER_TELL_STATUS_OK, cannam@87: /**< The tell was OK and encoding can continue. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_TELL_STATUS_ERROR, cannam@87: /**< An unrecoverable error occurred. */ cannam@87: cannam@87: FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED cannam@87: /**< Client does not support seeking. */ cannam@87: cannam@87: } FLAC__StreamEncoderTellStatus; cannam@87: cannam@87: /** Maps a FLAC__StreamEncoderTellStatus to a C string. cannam@87: * cannam@87: * Using a FLAC__StreamEncoderTellStatus as the index to this array cannam@87: * will give the string equivalent. The contents should not be modified. cannam@87: */ cannam@87: extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[]; cannam@87: cannam@87: cannam@87: /*********************************************************************** cannam@87: * cannam@87: * class FLAC__StreamEncoder cannam@87: * cannam@87: ***********************************************************************/ cannam@87: cannam@87: struct FLAC__StreamEncoderProtected; cannam@87: struct FLAC__StreamEncoderPrivate; cannam@87: /** The opaque structure definition for the stream encoder type. cannam@87: * See the \link flac_stream_encoder stream encoder module \endlink cannam@87: * for a detailed description. cannam@87: */ cannam@87: typedef struct { cannam@87: struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ cannam@87: struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ cannam@87: } FLAC__StreamEncoder; cannam@87: cannam@87: /** Signature for the read callback. cannam@87: * cannam@87: * A function pointer matching this signature must be passed to cannam@87: * FLAC__stream_encoder_init_ogg_stream() if seeking is supported. cannam@87: * The supplied function will be called when the encoder needs to read back cannam@87: * encoded data. This happens during the metadata callback, when the encoder cannam@87: * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered cannam@87: * while encoding. The address of the buffer to be filled is supplied, along cannam@87: * with the number of bytes the buffer can hold. The callback may choose to cannam@87: * supply less data and modify the byte count but must be careful not to cannam@87: * overflow the buffer. The callback then returns a status code chosen from cannam@87: * FLAC__StreamEncoderReadStatus. cannam@87: * cannam@87: * Here is an example of a read callback for stdio streams: cannam@87: * \code cannam@87: * FLAC__StreamEncoderReadStatus read_cb(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data) cannam@87: * { cannam@87: * FILE *file = ((MyClientData*)client_data)->file; cannam@87: * if(*bytes > 0) { cannam@87: * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file); cannam@87: * if(ferror(file)) cannam@87: * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; cannam@87: * else if(*bytes == 0) cannam@87: * return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; cannam@87: * else cannam@87: * return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; cannam@87: * } cannam@87: * else cannam@87: * return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; cannam@87: * } cannam@87: * \endcode cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param buffer A pointer to a location for the callee to store cannam@87: * data to be encoded. cannam@87: * \param bytes A pointer to the size of the buffer. On entry cannam@87: * to the callback, it contains the maximum number cannam@87: * of bytes that may be stored in \a buffer. The cannam@87: * callee must set it to the actual number of bytes cannam@87: * stored (0 in case of error or end-of-stream) before cannam@87: * returning. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_set_client_data(). cannam@87: * \retval FLAC__StreamEncoderReadStatus cannam@87: * The callee's return status. cannam@87: */ cannam@87: typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data); cannam@87: cannam@87: /** Signature for the write callback. cannam@87: * cannam@87: * A function pointer matching this signature must be passed to cannam@87: * FLAC__stream_encoder_init*_stream(). The supplied function will be called cannam@87: * by the encoder anytime there is raw encoded data ready to write. It may cannam@87: * include metadata mixed with encoded audio frames and the data is not cannam@87: * guaranteed to be aligned on frame or metadata block boundaries. cannam@87: * cannam@87: * The only duty of the callback is to write out the \a bytes worth of data cannam@87: * in \a buffer to the current position in the output stream. The arguments cannam@87: * \a samples and \a current_frame are purely informational. If \a samples cannam@87: * is greater than \c 0, then \a current_frame will hold the current frame cannam@87: * number that is being written; otherwise it indicates that the write cannam@87: * callback is being called to write metadata. cannam@87: * cannam@87: * \note cannam@87: * Unlike when writing to native FLAC, when writing to Ogg FLAC the cannam@87: * write callback will be called twice when writing each audio cannam@87: * frame; once for the page header, and once for the page body. cannam@87: * When writing the page header, the \a samples argument to the cannam@87: * write callback will be \c 0. cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param buffer An array of encoded data of length \a bytes. cannam@87: * \param bytes The byte length of \a buffer. cannam@87: * \param samples The number of samples encoded by \a buffer. cannam@87: * \c 0 has a special meaning; see above. cannam@87: * \param current_frame The number of the current frame being encoded. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_init_*(). cannam@87: * \retval FLAC__StreamEncoderWriteStatus cannam@87: * The callee's return status. cannam@87: */ cannam@87: typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data); cannam@87: cannam@87: /** Signature for the seek callback. cannam@87: * cannam@87: * A function pointer matching this signature may be passed to cannam@87: * FLAC__stream_encoder_init*_stream(). The supplied function will be called cannam@87: * when the encoder needs to seek the output stream. The encoder will pass cannam@87: * the absolute byte offset to seek to, 0 meaning the beginning of the stream. cannam@87: * cannam@87: * Here is an example of a seek callback for stdio streams: cannam@87: * \code cannam@87: * FLAC__StreamEncoderSeekStatus seek_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) cannam@87: * { cannam@87: * FILE *file = ((MyClientData*)client_data)->file; cannam@87: * if(file == stdin) cannam@87: * return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED; cannam@87: * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0) cannam@87: * return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; cannam@87: * else cannam@87: * return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; cannam@87: * } cannam@87: * \endcode cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param absolute_byte_offset The offset from the beginning of the stream cannam@87: * to seek to. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_init_*(). cannam@87: * \retval FLAC__StreamEncoderSeekStatus cannam@87: * The callee's return status. cannam@87: */ cannam@87: typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); cannam@87: cannam@87: /** Signature for the tell callback. cannam@87: * cannam@87: * A function pointer matching this signature may be passed to cannam@87: * FLAC__stream_encoder_init*_stream(). The supplied function will be called cannam@87: * when the encoder needs to know the current position of the output stream. cannam@87: * cannam@87: * \warning cannam@87: * The callback must return the true current byte offset of the output to cannam@87: * which the encoder is writing. If you are buffering the output, make cannam@87: * sure and take this into account. If you are writing directly to a cannam@87: * FILE* from your write callback, ftell() is sufficient. If you are cannam@87: * writing directly to a file descriptor from your write callback, you cannam@87: * can use lseek(fd, SEEK_CUR, 0). The encoder may later seek back to cannam@87: * these points to rewrite metadata after encoding. cannam@87: * cannam@87: * Here is an example of a tell callback for stdio streams: cannam@87: * \code cannam@87: * FLAC__StreamEncoderTellStatus tell_cb(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) cannam@87: * { cannam@87: * FILE *file = ((MyClientData*)client_data)->file; cannam@87: * off_t pos; cannam@87: * if(file == stdin) cannam@87: * return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED; cannam@87: * else if((pos = ftello(file)) < 0) cannam@87: * return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; cannam@87: * else { cannam@87: * *absolute_byte_offset = (FLAC__uint64)pos; cannam@87: * return FLAC__STREAM_ENCODER_TELL_STATUS_OK; cannam@87: * } cannam@87: * } cannam@87: * \endcode cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param absolute_byte_offset The address at which to store the current cannam@87: * position of the output. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_init_*(). cannam@87: * \retval FLAC__StreamEncoderTellStatus cannam@87: * The callee's return status. cannam@87: */ cannam@87: typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); cannam@87: cannam@87: /** Signature for the metadata callback. cannam@87: * cannam@87: * A function pointer matching this signature may be passed to cannam@87: * FLAC__stream_encoder_init*_stream(). The supplied function will be called cannam@87: * once at the end of encoding with the populated STREAMINFO structure. This cannam@87: * is so the client can seek back to the beginning of the file and write the cannam@87: * STREAMINFO block with the correct statistics after encoding (like cannam@87: * minimum/maximum frame size and total samples). cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param metadata The final populated STREAMINFO block. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_init_*(). cannam@87: */ cannam@87: typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data); cannam@87: cannam@87: /** Signature for the progress callback. cannam@87: * cannam@87: * A function pointer matching this signature may be passed to cannam@87: * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE(). cannam@87: * The supplied function will be called when the encoder has finished cannam@87: * writing a frame. The \c total_frames_estimate argument to the cannam@87: * callback will be based on the value from cannam@87: * FLAC__stream_encoder_set_total_samples_estimate(). cannam@87: * cannam@87: * \note In general, FLAC__StreamEncoder functions which change the cannam@87: * state should not be called on the \a encoder while in the callback. cannam@87: * cannam@87: * \param encoder The encoder instance calling the callback. cannam@87: * \param bytes_written Bytes written so far. cannam@87: * \param samples_written Samples written so far. cannam@87: * \param frames_written Frames written so far. cannam@87: * \param total_frames_estimate The estimate of the total number of cannam@87: * frames to be written. cannam@87: * \param client_data The callee's client data set through cannam@87: * FLAC__stream_encoder_init_*(). cannam@87: */ cannam@87: 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); cannam@87: cannam@87: cannam@87: /*********************************************************************** cannam@87: * cannam@87: * Class constructor/destructor cannam@87: * cannam@87: ***********************************************************************/ cannam@87: cannam@87: /** Create a new stream encoder instance. The instance is created with cannam@87: * default settings; see the individual FLAC__stream_encoder_set_*() cannam@87: * functions for each setting's default. cannam@87: * cannam@87: * \retval FLAC__StreamEncoder* cannam@87: * \c NULL if there was an error allocating memory, else the new instance. cannam@87: */ cannam@87: FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void); cannam@87: cannam@87: /** Free an encoder instance. Deletes the object pointed to by \a encoder. cannam@87: * cannam@87: * \param encoder A pointer to an existing encoder. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: */ cannam@87: FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder); cannam@87: cannam@87: cannam@87: /*********************************************************************** cannam@87: * cannam@87: * Public class method prototypes cannam@87: * cannam@87: ***********************************************************************/ cannam@87: cannam@87: /** Set the serial number for the FLAC stream to use in the Ogg container. cannam@87: * cannam@87: * \note cannam@87: * This does not need to be set for native FLAC encoding. cannam@87: * cannam@87: * \note cannam@87: * It is recommended to set a serial number explicitly as the default of '0' cannam@87: * may collide with other streams. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param serial_number See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number); cannam@87: cannam@87: /** Set the "verify" flag. If \c true, the encoder will verify it's own cannam@87: * encoded output by feeding it through an internal decoder and comparing cannam@87: * the original signal against the decoded signal. If a mismatch occurs, cannam@87: * the process call will return \c false. Note that this will slow the cannam@87: * encoding process by the extra time required for decoding and comparison. cannam@87: * cannam@87: * \default \c false cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value Flag value (see above). cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value); cannam@87: cannam@87: /** Set the Subset flag. If \c true, cannam@87: * the encoder will comply with the Subset and will check the cannam@87: * settings during FLAC__stream_encoder_init_*() to see if all settings cannam@87: * comply. If \c false, the settings may take advantage of the full cannam@87: * range that the format allows. cannam@87: * cannam@87: * Make sure you know what it entails before setting this to \c false. cannam@87: * cannam@87: * \default \c true cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value Flag value (see above). cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value); cannam@87: cannam@87: /** Set the number of channels to be encoded. cannam@87: * cannam@87: * \default \c 2 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set the sample resolution of the input to be encoded. cannam@87: * cannam@87: * \warning cannam@87: * Do not feed the encoder data that is wider than the value you cannam@87: * set here or you will generate an invalid stream. cannam@87: * cannam@87: * \default \c 16 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set the sample rate (in Hz) of the input to be encoded. cannam@87: * cannam@87: * \default \c 44100 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set the compression level cannam@87: * cannam@87: * The compression level is roughly proportional to the amount of effort cannam@87: * the encoder expends to compress the file. A higher level usually cannam@87: * means more computation but higher compression. The default level is cannam@87: * suitable for most applications. cannam@87: * cannam@87: * Currently the levels range from \c 0 (fastest, least compression) to cannam@87: * \c 8 (slowest, most compression). A value larger than \c 8 will be cannam@87: * treated as \c 8. cannam@87: * cannam@87: * This function automatically calls the following other \c _set_ cannam@87: * functions with appropriate values, so the client does not need to cannam@87: * unless it specifically wants to override them: cannam@87: * - FLAC__stream_encoder_set_do_mid_side_stereo() cannam@87: * - FLAC__stream_encoder_set_loose_mid_side_stereo() cannam@87: * - FLAC__stream_encoder_set_apodization() cannam@87: * - FLAC__stream_encoder_set_max_lpc_order() cannam@87: * - FLAC__stream_encoder_set_qlp_coeff_precision() cannam@87: * - FLAC__stream_encoder_set_do_qlp_coeff_prec_search() cannam@87: * - FLAC__stream_encoder_set_do_escape_coding() cannam@87: * - FLAC__stream_encoder_set_do_exhaustive_model_search() cannam@87: * - FLAC__stream_encoder_set_min_residual_partition_order() cannam@87: * - FLAC__stream_encoder_set_max_residual_partition_order() cannam@87: * - FLAC__stream_encoder_set_rice_parameter_search_dist() cannam@87: * cannam@87: * The actual values set for each level are: cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: * cannam@87: *
level cannam@87: * do mid-side stereo cannam@87: * loose mid-side stereo cannam@87: * apodization cannam@87: * max lpc order cannam@87: * qlp coeff precision cannam@87: * qlp coeff prec search cannam@87: * escape coding cannam@87: * exhaustive model search cannam@87: * min residual partition order cannam@87: * max residual partition order cannam@87: * rice parameter search dist cannam@87: *
0 false false tukey(0.5) 0 0 false false false 0 3 0
1 true true tukey(0.5) 0 0 false false false 0 3 0
2 true false tukey(0.5) 0 0 false false false 0 3 0
3 false false tukey(0.5) 6 0 false false false 0 4 0
4 true true tukey(0.5) 8 0 false false false 0 4 0
5 true false tukey(0.5) 8 0 false false false 0 5 0
6 true false tukey(0.5) 8 0 false false false 0 6 0
7 true false tukey(0.5) 8 0 false false true 0 6 0
8 true false tukey(0.5) 12 0 false false true 0 6 0
cannam@87: * cannam@87: * \default \c 5 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set the blocksize to use while encoding. cannam@87: * cannam@87: * The number of samples to use per frame. Use \c 0 to let the encoder cannam@87: * estimate a blocksize; this is usually best. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set to \c true to enable mid-side encoding on stereo input. The cannam@87: * number of channels must be 2 for this to have any effect. Set to cannam@87: * \c false to use only independent channel coding. cannam@87: * cannam@87: * \default \c false cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value Flag value (see above). cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value); cannam@87: cannam@87: /** Set to \c true to enable adaptive switching between mid-side and cannam@87: * left-right encoding on stereo input. Set to \c false to use cannam@87: * exhaustive searching. Setting this to \c true requires cannam@87: * FLAC__stream_encoder_set_do_mid_side_stereo() to also be set to cannam@87: * \c true in order to have any effect. cannam@87: * cannam@87: * \default \c false cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value Flag value (see above). cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value); cannam@87: cannam@87: /** Sets the apodization function(s) the encoder will use when windowing cannam@87: * audio data for LPC analysis. cannam@87: * cannam@87: * The \a specification is a plain ASCII string which specifies exactly cannam@87: * which functions to use. There may be more than one (up to 32), cannam@87: * separated by \c ';' characters. Some functions take one or more cannam@87: * comma-separated arguments in parentheses. cannam@87: * cannam@87: * The available functions are \c bartlett, \c bartlett_hann, cannam@87: * \c blackman, \c blackman_harris_4term_92db, \c connes, \c flattop, cannam@87: * \c gauss(STDDEV), \c hamming, \c hann, \c kaiser_bessel, \c nuttall, cannam@87: * \c rectangle, \c triangle, \c tukey(P), \c welch. cannam@87: * cannam@87: * For \c gauss(STDDEV), STDDEV specifies the standard deviation cannam@87: * (0blocksize / (2 ^ order). cannam@87: * cannam@87: * Set both min and max values to \c 0 to force a single context, cannam@87: * whose Rice parameter is based on the residual signal variance. cannam@87: * Otherwise, set a min and max order, and the encoder will search cannam@87: * all orders, using the mean of each context for its Rice parameter, cannam@87: * and use the best. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set the maximum partition order to search when coding the residual. cannam@87: * This is used in tandem with cannam@87: * FLAC__stream_encoder_set_min_residual_partition_order(). cannam@87: * cannam@87: * The partition order determines the context size in the residual. cannam@87: * The context size will be approximately blocksize / (2 ^ order). cannam@87: * cannam@87: * Set both min and max values to \c 0 to force a single context, cannam@87: * whose Rice parameter is based on the residual signal variance. cannam@87: * Otherwise, set a min and max order, and the encoder will search cannam@87: * all orders, using the mean of each context for its Rice parameter, cannam@87: * and use the best. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Deprecated. Setting this value has no effect. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value); cannam@87: cannam@87: /** Set an estimate of the total samples that will be encoded. cannam@87: * This is merely an estimate and may be set to \c 0 if unknown. cannam@87: * This value will be written to the STREAMINFO block before encoding, cannam@87: * and can remove the need for the caller to rewrite the value later cannam@87: * if the value is known before encoding. cannam@87: * cannam@87: * \default \c 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param value See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value); cannam@87: cannam@87: /** Set the metadata blocks to be emitted to the stream before encoding. cannam@87: * A value of \c NULL, \c 0 implies no metadata; otherwise, supply an cannam@87: * array of pointers to metadata blocks. The array is non-const since cannam@87: * the encoder may need to change the \a is_last flag inside them, and cannam@87: * in some cases update seek point offsets. Otherwise, the encoder will cannam@87: * not modify or free the blocks. It is up to the caller to free the cannam@87: * metadata blocks after encoding finishes. cannam@87: * cannam@87: * \note cannam@87: * The encoder stores only copies of the pointers in the \a metadata array; cannam@87: * the metadata blocks themselves must survive at least until after cannam@87: * FLAC__stream_encoder_finish() returns. Do not free the blocks until then. cannam@87: * cannam@87: * \note cannam@87: * The STREAMINFO block is always written and no STREAMINFO block may cannam@87: * occur in the supplied array. cannam@87: * cannam@87: * \note cannam@87: * By default the encoder does not create a SEEKTABLE. If one is supplied cannam@87: * in the \a metadata array, but the client has specified that it does not cannam@87: * support seeking, then the SEEKTABLE will be written verbatim. However cannam@87: * by itself this is not very useful as the client will not know the stream cannam@87: * offsets for the seekpoints ahead of time. In order to get a proper cannam@87: * seektable the client must support seeking. See next note. cannam@87: * cannam@87: * \note cannam@87: * SEEKTABLE blocks are handled specially. Since you will not know cannam@87: * the values for the seek point stream offsets, you should pass in cannam@87: * a SEEKTABLE 'template', that is, a SEEKTABLE object with the cannam@87: * required sample numbers (or placeholder points), with \c 0 for the cannam@87: * \a frame_samples and \a stream_offset fields for each point. If the cannam@87: * client has specified that it supports seeking by providing a seek cannam@87: * callback to FLAC__stream_encoder_init_stream() or both seek AND read cannam@87: * callback to FLAC__stream_encoder_init_ogg_stream() (or by using cannam@87: * FLAC__stream_encoder_init*_file() or FLAC__stream_encoder_init*_FILE()), cannam@87: * then while it is encoding the encoder will fill the stream offsets in cannam@87: * for you and when encoding is finished, it will seek back and write the cannam@87: * real values into the SEEKTABLE block in the stream. There are helper cannam@87: * routines for manipulating seektable template blocks; see metadata.h: cannam@87: * FLAC__metadata_object_seektable_template_*(). If the client does cannam@87: * not support seeking, the SEEKTABLE will have inaccurate offsets which cannam@87: * will slow down or remove the ability to seek in the FLAC stream. cannam@87: * cannam@87: * \note cannam@87: * The encoder instance \b will modify the first \c SEEKTABLE block cannam@87: * as it transforms the template to a valid seektable while encoding, cannam@87: * but it is still up to the caller to free all metadata blocks after cannam@87: * encoding. cannam@87: * cannam@87: * \note cannam@87: * A VORBIS_COMMENT block may be supplied. The vendor string in it cannam@87: * will be ignored. libFLAC will use it's own vendor string. libFLAC cannam@87: * will not modify the passed-in VORBIS_COMMENT's vendor string, it cannam@87: * will simply write it's own into the stream. If no VORBIS_COMMENT cannam@87: * block is present in the \a metadata array, libFLAC will write an cannam@87: * empty one, containing only the vendor string. cannam@87: * cannam@87: * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be cannam@87: * the second metadata block of the stream. The encoder already supplies cannam@87: * the STREAMINFO block automatically. If \a metadata does not contain a cannam@87: * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if cannam@87: * \a metadata does contain a VORBIS_COMMENT block and it is not the cannam@87: * first, the init function will reorder \a metadata by moving the cannam@87: * VORBIS_COMMENT block to the front; the relative ordering of the other cannam@87: * blocks will remain as they were. cannam@87: * cannam@87: * \note The Ogg FLAC mapping limits the number of metadata blocks per cannam@87: * stream to \c 65535. If \a num_blocks exceeds this the function will cannam@87: * return \c false. cannam@87: * cannam@87: * \default \c NULL, 0 cannam@87: * \param encoder An encoder instance to set. cannam@87: * \param metadata See above. cannam@87: * \param num_blocks See above. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c false if the encoder is already initialized, else \c true. cannam@87: * \c false if the encoder is already initialized, or if cannam@87: * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks); cannam@87: cannam@87: /** Get the current encoder state. cannam@87: * cannam@87: * \param encoder An encoder instance to query. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__StreamEncoderState cannam@87: * The current encoder state. cannam@87: */ cannam@87: FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder); cannam@87: cannam@87: /** Get the state of the verify stream decoder. cannam@87: * Useful when the stream encoder state is cannam@87: * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. cannam@87: * cannam@87: * \param encoder An encoder instance to query. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__StreamDecoderState cannam@87: * The verify stream decoder state. cannam@87: */ cannam@87: FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder); cannam@87: cannam@87: /** Get the current encoder state as a C string. cannam@87: * This version automatically resolves cannam@87: * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR by getting the cannam@87: * verify decoder's state. cannam@87: * cannam@87: * \param encoder A encoder instance to query. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval const char * cannam@87: * The encoder state as a C string. Do not modify the contents. cannam@87: */ cannam@87: FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder); cannam@87: cannam@87: /** Get relevant values about the nature of a verify decoder error. cannam@87: * Useful when the stream encoder state is cannam@87: * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. The arguments should cannam@87: * be addresses in which the stats will be returned, or NULL if value cannam@87: * is not desired. cannam@87: * cannam@87: * \param encoder An encoder instance to query. cannam@87: * \param absolute_sample The absolute sample number of the mismatch. cannam@87: * \param frame_number The number of the frame in which the mismatch occurred. cannam@87: * \param channel The channel in which the mismatch occurred. cannam@87: * \param sample The number of the sample (relative to the frame) in cannam@87: * which the mismatch occurred. cannam@87: * \param expected The expected value for the sample in question. cannam@87: * \param got The actual value returned by the decoder. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: */ cannam@87: 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); cannam@87: cannam@87: /** Get the "verify" flag. cannam@87: * cannam@87: * \param encoder An encoder instance to query. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \retval FLAC__bool cannam@87: * See FLAC__stream_encoder_set_verify(). cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder); cannam@87: cannam@87: /** Get the frame header. cannam@87: * cannam@87: * \param encoder An initialized encoder instance in the OK state. cannam@87: * \param buffer An array of pointers to each channel's signal. cannam@87: * \param samples The number of samples in one channel. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c true if successful, else \c false; in this case, check the cannam@87: * encoder state with FLAC__stream_encoder_get_state() to see what cannam@87: * went wrong. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); cannam@87: cannam@87: /** Submit data for encoding. cannam@87: * This version allows you to supply the input data where the channels cannam@87: * are interleaved into a single array (i.e. channel0_sample0, cannam@87: * channel1_sample0, ... , channelN_sample0, channel0_sample1, ...). cannam@87: * The samples need not be block-aligned but they must be cannam@87: * sample-aligned, i.e. the first value should be channel0_sample0 cannam@87: * and the last value channelN_sampleM. Each sample should be a signed cannam@87: * integer, right-justified to the resolution set by cannam@87: * FLAC__stream_encoder_set_bits_per_sample(). For example, if the cannam@87: * resolution is 16 bits per sample, the samples should all be in the cannam@87: * range [-32768,32767]. cannam@87: * cannam@87: * For applications where channel order is important, channels must cannam@87: * follow the order as described in the cannam@87: * frame header. cannam@87: * cannam@87: * \param encoder An initialized encoder instance in the OK state. cannam@87: * \param buffer An array of channel-interleaved data (see above). cannam@87: * \param samples The number of samples in one channel, the same as for cannam@87: * FLAC__stream_encoder_process(). For example, if cannam@87: * encoding two channels, \c 1000 \a samples corresponds cannam@87: * to a \a buffer of 2000 values. cannam@87: * \assert cannam@87: * \code encoder != NULL \endcode cannam@87: * \code FLAC__stream_encoder_get_state(encoder) == FLAC__STREAM_ENCODER_OK \endcode cannam@87: * \retval FLAC__bool cannam@87: * \c true if successful, else \c false; in this case, check the cannam@87: * encoder state with FLAC__stream_encoder_get_state() to see what cannam@87: * went wrong. cannam@87: */ cannam@87: FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples); cannam@87: cannam@87: /* \} */ cannam@87: cannam@87: #ifdef __cplusplus cannam@87: } cannam@87: #endif cannam@87: cannam@87: #endif