encoder.h
Go to the documentation of this file.
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002-2009 Josh Coalson
* Copyright (C) 2011-2025 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FLACPP__ENCODER_H
#define FLACPP__ENCODER_H
#include "export.h"
#include "FLAC/stream_encoder.h"
#include "decoder.h"
#include "metadata.h"
namespace FLAC {
namespace Encoder {
class FLACPP_API Stream {
public:
class FLACPP_API State {
public:
inline State(::FLAC__StreamEncoderState state): state_(state) { }
inline operator ::FLAC__StreamEncoderState() const { return state_; }
inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
protected:
::FLAC__StreamEncoderState state_;
};
Stream();
virtual ~Stream();
virtual bool is_valid() const;
inline operator bool() const { return is_valid(); }
virtual bool set_ogg_serial_number(long value);
virtual bool set_verify(bool value);
virtual bool set_streamable_subset(bool value);
virtual bool set_channels(uint32_t value);
virtual bool set_bits_per_sample(uint32_t value);
virtual bool set_sample_rate(uint32_t value);
virtual bool set_compression_level(uint32_t value);
virtual bool set_blocksize(uint32_t value);
virtual bool set_do_mid_side_stereo(bool value);
virtual bool set_loose_mid_side_stereo(bool value);
virtual bool set_apodization(const char *specification);
virtual bool set_max_lpc_order(uint32_t value);
virtual bool set_qlp_coeff_precision(uint32_t value);
virtual bool set_do_qlp_coeff_prec_search(bool value);
virtual bool set_do_escape_coding(bool value);
virtual bool set_do_exhaustive_model_search(bool value);
virtual bool set_min_residual_partition_order(uint32_t value);
virtual bool set_max_residual_partition_order(uint32_t value);
virtual bool set_rice_parameter_search_dist(uint32_t value);
virtual bool set_total_samples_estimate(FLAC__uint64 value);
virtual bool set_metadata(::FLAC__StreamMetadata **metadata, uint32_t num_blocks);
virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, uint32_t num_blocks);
virtual bool set_limit_min_bitrate(bool value);
virtual uint32_t set_num_threads(uint32_t value);
/* get_state() is not virtual since we want subclasses to be able to return their own state */
State get_state() const;
virtual Decoder::Stream::State get_verify_decoder_state() const;
virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got);
virtual bool get_verify() const;
virtual bool get_streamable_subset() const;
virtual bool get_do_mid_side_stereo() const;
virtual bool get_loose_mid_side_stereo() const;
virtual uint32_t get_channels() const;
virtual uint32_t get_bits_per_sample() const;
virtual uint32_t get_sample_rate() const;
virtual uint32_t get_blocksize() const;
virtual uint32_t get_max_lpc_order() const;
virtual uint32_t get_qlp_coeff_precision() const;
virtual bool get_do_qlp_coeff_prec_search() const;
virtual bool get_do_escape_coding() const;
virtual bool get_do_exhaustive_model_search() const;
virtual uint32_t get_min_residual_partition_order() const;
virtual uint32_t get_max_residual_partition_order() const;
virtual uint32_t get_rice_parameter_search_dist() const;
virtual FLAC__uint64 get_total_samples_estimate() const;
virtual bool get_limit_min_bitrate() const;
virtual uint32_t get_num_threads() const;
virtual ::FLAC__StreamEncoderInitStatus init();
virtual ::FLAC__StreamEncoderInitStatus init_ogg();
virtual bool finish();
virtual bool process(const FLAC__int32 * const buffer[], uint32_t samples);
virtual bool process_interleaved(const FLAC__int32 buffer[], uint32_t samples);
protected:
virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame) = 0;
virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
#if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
// lame hack: some compilers can't see a protected encoder_ from nested State::resolved_as_cstring()
friend State;
#endif
::FLAC__StreamEncoder *encoder_;
static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);
static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
private:
// Private and undefined so you can't use them:
Stream(const Stream &);
void operator=(const Stream &);
};
class FLACPP_API File: public Stream {
public:
File();
virtual ~File();
using Stream::init;
virtual ::FLAC__StreamEncoderInitStatus init(FILE *file);
virtual ::FLAC__StreamEncoderInitStatus init(const char *filename);
virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename);
using Stream::init_ogg;
virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file);
virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename);
virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename);
protected:
virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate);
virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame);
private:
static void progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate, void *client_data);
// Private and undefined so you can't use them:
File(const Stream &);
void operator=(const Stream &);
};
}
}
#endif
export.h
This module contains #defines and symbols for exporting function calls, and providing version informa...
metadata.h
This module provides functions for creating and manipulating FLAC metadata blocks in memory,...
FLAC::Decoder::Stream::State
Definition decoder.h:104
FLAC::Encoder::File
This class wraps the FLAC__StreamEncoder. If you are not encoding to a file, you may need to use FLAC...
Definition encoder.h:237
FLAC::Encoder::File::init_ogg
virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename)
See FLAC__stream_encoder_init_ogg_file()
FLAC::Encoder::File::init_ogg
virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename)
See FLAC__stream_encoder_init_ogg_file()
FLAC::Encoder::File::init
virtual ::FLAC__StreamEncoderInitStatus init(const char *filename)
See FLAC__stream_encoder_init_file()
FLAC::Encoder::File::init
virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename)
See FLAC__stream_encoder_init_file()
FLAC::Encoder::File::init_ogg
virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file)
See FLAC__stream_encoder_init_ogg_FILE()
FLAC::Encoder::File::write_callback
virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame)
This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied intern...
FLAC::Encoder::File::progress_callback
virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, uint32_t frames_written, uint32_t total_frames_estimate)
See FLAC__StreamEncoderProgressCallback.
FLAC::Encoder::File::init
virtual ::FLAC__StreamEncoderInitStatus init(FILE *file)
See FLAC__stream_encoder_init_FILE()
FLAC::Encoder::Stream::State
Definition encoder.h:106
FLAC::Encoder::Stream
This class wraps the FLAC__StreamEncoder. If you are encoding to a file, FLAC::Encoder::File may be m...
Definition encoder.h:102
FLAC::Encoder::Stream::get_do_mid_side_stereo
virtual bool get_do_mid_side_stereo() const
See FLAC__stream_encoder_get_do_mid_side_stereo()
FLAC::Encoder::Stream::set_do_mid_side_stereo
virtual bool set_do_mid_side_stereo(bool value)
See FLAC__stream_encoder_set_do_mid_side_stereo()
FLAC::Encoder::Stream::set_max_residual_partition_order
virtual bool set_max_residual_partition_order(uint32_t value)
See FLAC__stream_encoder_set_max_residual_partition_order()
FLAC::Encoder::Stream::get_do_exhaustive_model_search
virtual bool get_do_exhaustive_model_search() const
See FLAC__stream_encoder_get_do_exhaustive_model_search()
FLAC::Encoder::Stream::init
virtual ::FLAC__StreamEncoderInitStatus init()
See FLAC__stream_encoder_init_stream()
FLAC::Encoder::Stream::set_compression_level
virtual bool set_compression_level(uint32_t value)
See FLAC__stream_encoder_set_compression_level()
FLAC::Encoder::Stream::set_limit_min_bitrate
virtual bool set_limit_min_bitrate(bool value)
See FLAC__stream_encoder_set_limit_min_bitrate()
FLAC::Encoder::Stream::get_verify_decoder_error_stats
virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, uint32_t *frame_number, uint32_t *channel, uint32_t *sample, FLAC__int32 *expected, FLAC__int32 *got)
See FLAC__stream_encoder_get_verify_decoder_error_stats()
FLAC::Encoder::Stream::set_do_exhaustive_model_search
virtual bool set_do_exhaustive_model_search(bool value)
See FLAC__stream_encoder_set_do_exhaustive_model_search()
FLAC::Encoder::Stream::get_num_threads
virtual uint32_t get_num_threads() const
See FLAC__stream_encoder_get_num_threads()
FLAC::Encoder::Stream::set_blocksize
virtual bool set_blocksize(uint32_t value)
See FLAC__stream_encoder_set_blocksize()
FLAC::Encoder::Stream::set_min_residual_partition_order
virtual bool set_min_residual_partition_order(uint32_t value)
See FLAC__stream_encoder_set_min_residual_partition_order()
FLAC::Encoder::Stream::read_callback
virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes)
See FLAC__StreamEncoderReadCallback.
FLAC::Encoder::Stream::set_do_escape_coding
virtual bool set_do_escape_coding(bool value)
See FLAC__stream_encoder_set_do_escape_coding()
FLAC::Encoder::Stream::set_apodization
virtual bool set_apodization(const char *specification)
See FLAC__stream_encoder_set_apodization()
FLAC::Encoder::Stream::get_streamable_subset
virtual bool get_streamable_subset() const
See FLAC__stream_encoder_get_streamable_subset()
FLAC::Encoder::Stream::get_bits_per_sample
virtual uint32_t get_bits_per_sample() const
See FLAC__stream_encoder_get_bits_per_sample()
FLAC::Encoder::Stream::tell_callback
virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset)
See FLAC__StreamEncoderTellCallback.
FLAC::Encoder::Stream::set_sample_rate
virtual bool set_sample_rate(uint32_t value)
See FLAC__stream_encoder_set_sample_rate()
FLAC::Encoder::Stream::set_total_samples_estimate
virtual bool set_total_samples_estimate(FLAC__uint64 value)
See FLAC__stream_encoder_set_total_samples_estimate()
FLAC::Encoder::Stream::set_metadata
virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, uint32_t num_blocks)
See FLAC__stream_encoder_set_metadata()
FLAC::Encoder::Stream::set_qlp_coeff_precision
virtual bool set_qlp_coeff_precision(uint32_t value)
See FLAC__stream_encoder_set_qlp_coeff_precision()
FLAC::Encoder::Stream::set_channels
virtual bool set_channels(uint32_t value)
See FLAC__stream_encoder_set_channels()
FLAC::Encoder::Stream::init_ogg
virtual ::FLAC__StreamEncoderInitStatus init_ogg()
See FLAC__stream_encoder_init_ogg_stream()
FLAC::Encoder::Stream::set_bits_per_sample
virtual bool set_bits_per_sample(uint32_t value)
See FLAC__stream_encoder_set_bits_per_sample()
FLAC::Encoder::Stream::is_valid
virtual bool is_valid() const
FLAC::Encoder::Stream::get_loose_mid_side_stereo
virtual bool get_loose_mid_side_stereo() const
See FLAC__stream_encoder_get_loose_mid_side_stereo()
FLAC::Encoder::Stream::get_max_residual_partition_order
virtual uint32_t get_max_residual_partition_order() const
See FLAC__stream_encoder_get_max_residual_partition_order()
FLAC::Encoder::Stream::get_blocksize
virtual uint32_t get_blocksize() const
See FLAC__stream_encoder_get_blocksize()
FLAC::Encoder::Stream::get_do_qlp_coeff_prec_search
virtual bool get_do_qlp_coeff_prec_search() const
See FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
FLAC::Encoder::Stream::seek_callback
virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset)
See FLAC__StreamEncoderSeekCallback.
FLAC::Encoder::Stream::set_rice_parameter_search_dist
virtual bool set_rice_parameter_search_dist(uint32_t value)
See FLAC__stream_encoder_set_rice_parameter_search_dist()
FLAC::Encoder::Stream::get_qlp_coeff_precision
virtual uint32_t get_qlp_coeff_precision() const
See FLAC__stream_encoder_get_qlp_coeff_precision()
FLAC::Encoder::Stream::set_verify
virtual bool set_verify(bool value)
See FLAC__stream_encoder_set_verify()
FLAC::Encoder::Stream::set_streamable_subset
virtual bool set_streamable_subset(bool value)
See FLAC__stream_encoder_set_streamable_subset()
FLAC::Encoder::Stream::get_verify_decoder_state
virtual Decoder::Stream::State get_verify_decoder_state() const
See FLAC__stream_encoder_get_verify_decoder_state()
FLAC::Encoder::Stream::get_channels
virtual uint32_t get_channels() const
See FLAC__stream_encoder_get_channels()
FLAC::Encoder::Stream::set_do_qlp_coeff_prec_search
virtual bool set_do_qlp_coeff_prec_search(bool value)
See FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
FLAC::Encoder::Stream::set_num_threads
virtual uint32_t set_num_threads(uint32_t value)
See FLAC__stream_encoder_set_num_threads()
FLAC::Encoder::Stream::get_state
State get_state() const
See FLAC__stream_encoder_get_state()
FLAC::Encoder::Stream::get_verify
virtual bool get_verify() const
See FLAC__stream_encoder_get_verify()
FLAC::Encoder::Stream::set_loose_mid_side_stereo
virtual bool set_loose_mid_side_stereo(bool value)
See FLAC__stream_encoder_set_loose_mid_side_stereo()
FLAC::Encoder::Stream::get_max_lpc_order
virtual uint32_t get_max_lpc_order() const
See FLAC__stream_encoder_get_max_lpc_order()
FLAC::Encoder::Stream::get_rice_parameter_search_dist
virtual uint32_t get_rice_parameter_search_dist() const
See FLAC__stream_encoder_get_rice_parameter_search_dist()
FLAC::Encoder::Stream::get_do_escape_coding
virtual bool get_do_escape_coding() const
See FLAC__stream_encoder_get_do_escape_coding()
FLAC::Encoder::Stream::get_min_residual_partition_order
virtual uint32_t get_min_residual_partition_order() const
See FLAC__stream_encoder_get_min_residual_partition_order()
FLAC::Encoder::Stream::set_metadata
virtual bool set_metadata(::FLAC__StreamMetadata **metadata, uint32_t num_blocks)
See FLAC__stream_encoder_set_metadata()
FLAC::Encoder::Stream::process
virtual bool process(const FLAC__int32 *const buffer[], uint32_t samples)
See FLAC__stream_encoder_process()
FLAC::Encoder::Stream::get_sample_rate
virtual uint32_t get_sample_rate() const
See FLAC__stream_encoder_get_sample_rate()
FLAC::Encoder::Stream::get_limit_min_bitrate
virtual bool get_limit_min_bitrate() const
See FLAC__stream_encoder_get_limit_min_bitrate()
FLAC::Encoder::Stream::process_interleaved
virtual bool process_interleaved(const FLAC__int32 buffer[], uint32_t samples)
See FLAC__stream_encoder_process_interleaved()
FLAC::Encoder::Stream::get_total_samples_estimate
virtual FLAC__uint64 get_total_samples_estimate() const
See FLAC__stream_encoder_get_total_samples_estimate()
FLAC::Encoder::Stream::write_callback
virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame)=0
See FLAC__StreamEncoderWriteCallback.
FLAC::Encoder::Stream::finish
virtual bool finish()
See FLAC__stream_encoder_finish()
FLAC::Encoder::Stream::metadata_callback
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata)
See FLAC__StreamEncoderMetadataCallback.
FLAC::Encoder::Stream::set_ogg_serial_number
virtual bool set_ogg_serial_number(long value)
See FLAC__stream_encoder_set_ogg_serial_number()
FLAC::Encoder::Stream::set_max_lpc_order
virtual bool set_max_lpc_order(uint32_t value)
See FLAC__stream_encoder_set_max_lpc_order()
FLAC::Metadata::Prototype
Definition metadata.h:109
decoder.h
This module contains the classes which implement the various decoders.
FLAC__StreamEncoderState
FLAC__StreamEncoderState
Definition stream_encoder.h:241
FLACPP_API
#define FLACPP_API
Definition export.h:88
stream_encoder.h
This module contains the functions which implement the stream encoder.
FLAC__StreamEncoder
Definition stream_encoder.h:469
FLAC__StreamMetadata
Definition format.h:841

Copyright (c) 2000-2009 Josh Coalson Copyright (c) 2011-2025 Xiph.Org Foundation