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