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