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