Commit ebece62e authored by Josh Coalson's avatar Josh Coalson
Browse files

new seekable stream encoder and file encoder layers

parent 14ff156e
......@@ -32,7 +32,9 @@ libFLAC___la_LDFLAGS = -version-info 1:1:0
libFLAC___la_SOURCES = \
file_decoder.cc \
file_encoder.cc \
metadata.cc \
seekable_stream_decoder.cc \
seekable_stream_encoder.cc \
stream_decoder.cc \
stream_encoder.cc
......@@ -25,8 +25,10 @@ INCLUDES = -I../../include
OBJS = \
file_decoder.o \
file_encoder.o \
metadata.o \
seekable_stream_decoder.o \
seekable_stream_encoder.o \
stream_decoder.o \
stream_encoder.o
......
......@@ -30,8 +30,10 @@ SUFFIXES = .cc
CC_FILES= \
file_decoder.cc \
file_encoder.cc \
metadata.cc \
seekable_stream_decoder.cc \
seekable_stream_encoder.cc \
stream_decoder.cc \
stream_encoder.cc
......@@ -45,10 +47,14 @@ libFLAC++.lib: $(OBJS)
# can't figure out how to get it to take .cc so we just hack it for now:
file_decoder.obj: file_decoder.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP file_decoder.cc
file_encoder.obj: file_encoder.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP file_encoder.cc
metadata.obj: metadata.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP metadata.cc
seekable_stream_decoder.obj: seekable_stream_decoder.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP seekable_stream_decoder.cc
seekable_stream_encoder.obj: seekable_stream_encoder.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP seekable_stream_encoder.cc
stream_decoder.obj: stream_decoder.cc
$(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP stream_decoder.cc
stream_encoder.obj: stream_encoder.cc
......
/* 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 {
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_;
}
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_));
}
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_);
}
File::State File::init()
{
FLAC__ASSERT(is_valid());
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);
}
};
};
/* 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 {
SeekableStream::SeekableStream():
encoder_(::FLAC__seekable_stream_encoder_new())
{ }
SeekableStream::~SeekableStream()
{
if(0 != encoder_) {
::FLAC__seekable_stream_encoder_finish(encoder_);
::FLAC__seekable_stream_encoder_delete(encoder_);
}
}
bool SeekableStream::is_valid() const
{
return 0 != encoder_;
}
bool SeekableStream::set_streamable_subset(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_streamable_subset(encoder_, value);
}
bool SeekableStream::set_do_mid_side_stereo(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder_, value);
}
bool SeekableStream::set_loose_mid_side_stereo(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder_, value);
}
bool SeekableStream::set_channels(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_channels(encoder_, value);
}
bool SeekableStream::set_bits_per_sample(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_bits_per_sample(encoder_, value);
}
bool SeekableStream::set_sample_rate(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_sample_rate(encoder_, value);
}
bool SeekableStream::set_blocksize(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_blocksize(encoder_, value);
}
bool SeekableStream::set_max_lpc_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_max_lpc_order(encoder_, value);
}
bool SeekableStream::set_qlp_coeff_precision(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder_, value);
}
bool SeekableStream::set_do_qlp_coeff_prec_search(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
}
bool SeekableStream::set_do_escape_coding(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_do_escape_coding(encoder_, value);
}
bool SeekableStream::set_do_exhaustive_model_search(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder_, value);
}
bool SeekableStream::set_min_residual_partition_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder_, value);
}
bool SeekableStream::set_max_residual_partition_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder_, value);
}
bool SeekableStream::set_rice_parameter_search_dist(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder_, value);
}
bool SeekableStream::set_total_samples_estimate(FLAC__uint64 value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder_, value);
}
bool SeekableStream::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_set_metadata(encoder_, metadata, num_blocks);
}
SeekableStream::State SeekableStream::get_state() const
{
FLAC__ASSERT(is_valid());
return State(::FLAC__seekable_stream_encoder_get_state(encoder_));
}
Stream::State SeekableStream::get_stream_encoder_state() const
{
FLAC__ASSERT(is_valid());
return Stream::State(::FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder_));
}
bool SeekableStream::get_streamable_subset() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_streamable_subset(encoder_);
}
bool SeekableStream::get_do_mid_side_stereo() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder_);
}
bool SeekableStream::get_loose_mid_side_stereo() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder_);
}
unsigned SeekableStream::get_channels() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_channels(encoder_);
}
unsigned SeekableStream::get_bits_per_sample() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_bits_per_sample(encoder_);
}
unsigned SeekableStream::get_sample_rate() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_sample_rate(encoder_);
}
unsigned SeekableStream::get_blocksize() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_blocksize(encoder_);
}
unsigned SeekableStream::get_max_lpc_order() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_max_lpc_order(encoder_);
}
unsigned SeekableStream::get_qlp_coeff_precision() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder_);
}
bool SeekableStream::get_do_qlp_coeff_prec_search() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder_);
}
bool SeekableStream::get_do_escape_coding() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_do_escape_coding(encoder_);
}
bool SeekableStream::get_do_exhaustive_model_search() const
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder_);
}
unsigned SeekableStream::get_min_residual_partition_order() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder_);
}
unsigned SeekableStream::get_max_residual_partition_order() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder_);
}
unsigned SeekableStream::get_rice_parameter_search_dist() const
{
FLAC__ASSERT(is_valid());
return ::FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder_);
}
SeekableStream::State SeekableStream::init()
{
FLAC__ASSERT(is_valid());
::FLAC__seekable_stream_encoder_set_seek_callback(encoder_, seek_callback_);
::FLAC__seekable_stream_encoder_set_write_callback(encoder_, write_callback_);
::FLAC__seekable_stream_encoder_set_client_data(encoder_, (void*)this);
return State(::FLAC__seekable_stream_encoder_init(encoder_));
}
void SeekableStream::finish()
{
FLAC__ASSERT(is_valid());
::FLAC__seekable_stream_encoder_finish(encoder_);
}
bool SeekableStream::process(const FLAC__int32 * const buffer[], unsigned samples)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_process(encoder_, buffer, samples);
}
bool SeekableStream::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__seekable_stream_encoder_process_interleaved(encoder_, buffer, samples);
}
::FLAC__SeekableStreamEncoderSeekStatus SeekableStream::seek_callback_(const ::FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
FLAC__ASSERT(0 != instance);
return instance->seek_callback(absolute_byte_offset);
}
::FLAC__StreamEncoderWriteStatus SeekableStream::write_callback_(const ::FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{