2002-08-02 06:03:18 +00:00
|
|
|
/* libFLAC++ - Free Lossless Audio Codec library
|
|
|
|
|
* Copyright (C) 2002 Josh Coalson
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "FLAC++/encoder.h"
|
|
|
|
|
#include "FLAC/assert.h"
|
|
|
|
|
|
|
|
|
|
namespace FLAC {
|
|
|
|
|
namespace Encoder {
|
|
|
|
|
|
2002-09-06 00:40:30 +00:00
|
|
|
const char *File::State::resolved_as_cstring(const File &encoder) const
|
|
|
|
|
{
|
|
|
|
|
if(state_ == ::FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
|
|
|
|
|
FLAC::Encoder::SeekableStream::State state__ = encoder.get_seekable_stream_encoder_state();
|
|
|
|
|
if(state__ == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
|
|
|
|
|
FLAC::Encoder::Stream::State state___ = encoder.get_stream_encoder_state();
|
|
|
|
|
if(state___ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
|
|
|
|
|
return encoder.get_verify_decoder_state().as_cstring();
|
|
|
|
|
else
|
|
|
|
|
return state___.as_cstring();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return state__.as_cstring();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return as_cstring();
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-02 06:03:18 +00:00
|
|
|
File::File():
|
|
|
|
|
encoder_(::FLAC__file_encoder_new())
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
File::~File()
|
|
|
|
|
{
|
|
|
|
|
if(0 != encoder_) {
|
|
|
|
|
::FLAC__file_encoder_finish(encoder_);
|
|
|
|
|
::FLAC__file_encoder_delete(encoder_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::is_valid() const
|
|
|
|
|
{
|
|
|
|
|
return 0 != encoder_;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-03 21:56:15 +00:00
|
|
|
bool File::set_verify(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_verify(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-02 06:03:18 +00:00
|
|
|
bool File::set_streamable_subset(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_streamable_subset(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_do_mid_side_stereo(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_do_mid_side_stereo(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_loose_mid_side_stereo(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_loose_mid_side_stereo(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_channels(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_channels(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_bits_per_sample(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_bits_per_sample(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_sample_rate(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_sample_rate(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_blocksize(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_blocksize(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_max_lpc_order(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_max_lpc_order(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_qlp_coeff_precision(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_qlp_coeff_precision(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_do_qlp_coeff_prec_search(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_do_escape_coding(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_do_escape_coding(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_do_exhaustive_model_search(bool value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_do_exhaustive_model_search(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_min_residual_partition_order(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_min_residual_partition_order(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_max_residual_partition_order(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_max_residual_partition_order(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_rice_parameter_search_dist(unsigned value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_rice_parameter_search_dist(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_total_samples_estimate(FLAC__uint64 value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_total_samples_estimate(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_metadata(encoder_, metadata, num_blocks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::set_filename(const char *value)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_set_filename(encoder_, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File::State File::get_state() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return State(::FLAC__file_encoder_get_state(encoder_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SeekableStream::State File::get_seekable_stream_encoder_state() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return SeekableStream::State(::FLAC__file_encoder_get_seekable_stream_encoder_state(encoder_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Stream::State File::get_stream_encoder_state() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return Stream::State(::FLAC__file_encoder_get_stream_encoder_state(encoder_));
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-03 21:56:15 +00:00
|
|
|
Decoder::Stream::State File::get_verify_decoder_state() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return Decoder::Stream::State(::FLAC__file_encoder_get_verify_decoder_state(encoder_));
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-07 23:54:55 +00:00
|
|
|
void File::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
2002-08-21 05:27:01 +00:00
|
|
|
::FLAC__file_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
|
2002-08-07 23:54:55 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-03 21:56:15 +00:00
|
|
|
bool File::get_verify() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_verify(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-02 06:03:18 +00:00
|
|
|
bool File::get_streamable_subset() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_streamable_subset(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::get_do_mid_side_stereo() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_do_mid_side_stereo(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::get_loose_mid_side_stereo() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_loose_mid_side_stereo(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_channels() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_channels(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_bits_per_sample() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_bits_per_sample(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_sample_rate() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_sample_rate(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_blocksize() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_blocksize(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_max_lpc_order() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_max_lpc_order(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_qlp_coeff_precision() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_qlp_coeff_precision(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::get_do_qlp_coeff_prec_search() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::get_do_escape_coding() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_do_escape_coding(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::get_do_exhaustive_model_search() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_get_do_exhaustive_model_search(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_min_residual_partition_order() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_min_residual_partition_order(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_max_residual_partition_order() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_max_residual_partition_order(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned File::get_rice_parameter_search_dist() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_rice_parameter_search_dist(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-02 07:40:38 +00:00
|
|
|
FLAC__uint64 File::get_total_samples_estimate() const
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return ::FLAC__file_encoder_get_total_samples_estimate(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-02 06:03:18 +00:00
|
|
|
File::State File::init()
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
2002-08-02 07:40:38 +00:00
|
|
|
::FLAC__file_encoder_set_progress_callback(encoder_, progress_callback_);
|
|
|
|
|
::FLAC__file_encoder_set_client_data(encoder_, (void*)this);
|
2002-08-02 06:03:18 +00:00
|
|
|
return State(::FLAC__file_encoder_init(encoder_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void File::finish()
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
::FLAC__file_encoder_finish(encoder_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::process(const FLAC__int32 * const buffer[], unsigned samples)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_process(encoder_, buffer, samples);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool File::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
|
|
|
|
|
{
|
|
|
|
|
FLAC__ASSERT(is_valid());
|
|
|
|
|
return (bool)::FLAC__file_encoder_process_interleaved(encoder_, buffer, samples);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-08 22:55:45 +00:00
|
|
|
void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
|
2002-08-02 07:40:38 +00:00
|
|
|
{
|
2002-08-08 22:55:45 +00:00
|
|
|
(void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
|
2002-08-02 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-08 22:55:45 +00:00
|
|
|
void File::progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
|
2002-08-02 07:40:38 +00:00
|
|
|
{
|
|
|
|
|
(void)encoder;
|
|
|
|
|
FLAC__ASSERT(0 != client_data);
|
|
|
|
|
File *instance = reinterpret_cast<File *>(client_data);
|
|
|
|
|
FLAC__ASSERT(0 != instance);
|
2002-08-08 22:55:45 +00:00
|
|
|
instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);
|
2002-08-02 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-02 06:03:18 +00:00
|
|
|
};
|
|
|
|
|
};
|