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