new seekable stream encoder and file encoder layers
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 2 Aug 2002 06:03:18 +0000 (06:03 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 2 Aug 2002 06:03:18 +0000 (06:03 +0000)
src/libFLAC++/Makefile.am
src/libFLAC++/Makefile.lite
src/libFLAC++/Makefile.vc
src/libFLAC++/file_encoder.cc [new file with mode: 0644]
src/libFLAC++/seekable_stream_encoder.cc [new file with mode: 0644]
src/test_libFLAC++/encoders.cc
src/test_libFLAC/encoders.c

index 718c8a3..9988679 100644 (file)
@@ -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 
index 887b6a9..a294f4c 100644 (file)
@@ -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
 
index 41ad982..5303616 100644 (file)
@@ -30,8 +30,10 @@ SUFFIXES = .cc
 \r
 CC_FILES= \\r
        file_decoder.cc \\r
+       file_encoder.cc \\r
        metadata.cc \\r
        seekable_stream_decoder.cc \\r
+       seekable_stream_encoder.cc \\r
        stream_decoder.cc \\r
        stream_encoder.cc\r
 \r
@@ -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:\r
 file_decoder.obj: file_decoder.cc\r
        $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP file_decoder.cc\r
+file_encoder.obj: file_encoder.cc\r
+       $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP file_encoder.cc\r
 metadata.obj: metadata.cc\r
        $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP metadata.cc\r
 seekable_stream_decoder.obj: seekable_stream_decoder.cc\r
        $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP seekable_stream_decoder.cc\r
+seekable_stream_encoder.obj: seekable_stream_encoder.cc\r
+       $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP seekable_stream_encoder.cc\r
 stream_decoder.obj: stream_decoder.cc\r
        $(cc) /D "_LIB" /O2 /GR $(crelease) $(cflags) /I "..\..\include" -DSTRICT -YX -DNODEBUG /TP stream_decoder.cc\r
 stream_encoder.obj: stream_encoder.cc\r
diff --git a/src/libFLAC++/file_encoder.cc b/src/libFLAC++/file_encoder.cc
new file mode 100644 (file)
index 0000000..9d24cfe
--- /dev/null
@@ -0,0 +1,284 @@
+/* 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);
+               }
+
+       };
+};
diff --git a/src/libFLAC++/seekable_stream_encoder.cc b/src/libFLAC++/seekable_stream_encoder.cc
new file mode 100644 (file)
index 0000000..ee36896
--- /dev/null
@@ -0,0 +1,293 @@
+/* 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)
+               {
+                       (void)encoder;
+                       FLAC__ASSERT(0 != client_data);
+                       SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
+                       FLAC__ASSERT(0 != instance);
+                       return instance->write_callback(buffer, bytes, samples, current_frame);
+               }
+
+       };
+};
index 047f62c..1175e57 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
 static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_;
 static ::FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_ };
 static const unsigned num_metadata_ = 5;
+static const char *flacfilename_ = "metadata.flac";
 
 static void *malloc_or_die_(size_t size)
 {
@@ -146,9 +147,11 @@ bool StreamEncoder::die(const char *msg) const
        State state = get_state();
 
        if(msg)
-               printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)((::FLAC__StreamEncoderState)state), state.as_cstring());
+               printf("FAILED, %s", msg);
        else
-               printf("FAILED, state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state), state.as_cstring());
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state), state.as_cstring());
 
        return false;
 }
@@ -401,11 +404,607 @@ static bool test_stream_encoder()
        return true;
 }
 
-bool test_encoders()
+class SeekableStreamEncoder : public FLAC::Encoder::SeekableStream {
+public:
+       SeekableStreamEncoder(): FLAC::Encoder::SeekableStream() { }
+       ~SeekableStreamEncoder() { }
+
+       // from FLAC::Encoder::SeekableStream
+       ::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
+       ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
+
+       bool die(const char *msg = 0) const;
+};
+
+::FLAC__SeekableStreamEncoderSeekStatus SeekableStreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset)
 {
-       init_metadata_blocks_();
+       (void)absolute_byte_offset;
 
-       if(!test_stream_encoder())
+       return ::FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
+}
+
+::FLAC__StreamEncoderWriteStatus SeekableStreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
+{
+       (void)buffer, (void)bytes, (void)samples, (void)current_frame;
+
+       return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+bool SeekableStreamEncoder::die(const char *msg) const
+{
+       State state = get_state();
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state), state.as_cstring());
+       if(state == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
+               FLAC::Encoder::Stream::State state_ = get_stream_encoder_state();
+               printf("      stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
+       }
+
+       return false;
+}
+
+static bool test_seekable_stream_encoder()
+{
+       SeekableStreamEncoder *encoder;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libFLAC++ unit test: FLAC::Encoder::SeekableStream\n\n");
+
+       printf("allocating encoder instance... ");
+       encoder = new SeekableStreamEncoder();
+       if(0 == encoder) {
+               printf("FAILED, new returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing is_valid()... ");
+       if(!encoder->is_valid()) {
+               printf("FAILED, returned false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing set_streamable_subset()... ");
+       if(!encoder->set_streamable_subset(true))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_mid_side_stereo()... ");
+       if(!encoder->set_do_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_loose_mid_side_stereo()... ");
+       if(!encoder->set_loose_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_channels()... ");
+       if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_bits_per_sample()... ");
+       if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_sample_rate()... ");
+       if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_blocksize()... ");
+       if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_lpc_order()... ");
+       if(!encoder->set_max_lpc_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_qlp_coeff_precision()... ");
+       if(!encoder->set_qlp_coeff_precision(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_qlp_coeff_prec_search()... ");
+       if(!encoder->set_do_qlp_coeff_prec_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_escape_coding()... ");
+       if(!encoder->set_do_escape_coding(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_exhaustive_model_search()... ");
+       if(!encoder->set_do_exhaustive_model_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_min_residual_partition_order()... ");
+       if(!encoder->set_min_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_residual_partition_order()... ");
+       if(!encoder->set_max_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_rice_parameter_search_dist()... ");
+       if(!encoder->set_rice_parameter_search_dist(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_total_samples_estimate()... ");
+       if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_metadata()... ");
+       if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing init()... ");
+       if(encoder->init() != ::FLAC__SEEKABLE_STREAM_ENCODER_OK)
+               return encoder->die();
+       printf("OK\n");
+
+       printf("testing get_state()... ");
+       FLAC::Encoder::SeekableStream::State state = encoder->get_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state), state.as_cstring());
+
+       printf("testing get_stream_encoder_state()... ");
+       FLAC::Encoder::Stream::State state_ = encoder->get_stream_encoder_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
+
+       printf("testing get_streamable_subset()... ");
+       if(encoder->get_streamable_subset() != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_mid_side_stereo()... ");
+       if(encoder->get_do_mid_side_stereo() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_loose_mid_side_stereo()... ");
+       if(encoder->get_loose_mid_side_stereo() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_channels()... ");
+       if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_bits_per_sample()... ");
+       if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_sample_rate()... ");
+       if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_blocksize()... ");
+       if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_max_lpc_order()... ");
+       if(encoder->get_max_lpc_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_qlp_coeff_precision()... ");
+       (void)encoder->get_qlp_coeff_precision();
+       /* we asked the encoder to auto select this so we accept anything */
+       printf("OK\n");
+
+       printf("testing get_do_qlp_coeff_prec_search()... ");
+       if(encoder->get_do_qlp_coeff_prec_search() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_escape_coding()... ");
+       if(encoder->get_do_escape_coding() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_exhaustive_model_search()... ");
+       if(encoder->get_do_exhaustive_model_search() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_min_residual_partition_order()... ");
+       if(encoder->get_min_residual_partition_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_max_residual_partition_order()... ");
+       if(encoder->get_max_residual_partition_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_rice_parameter_search_dist()... ");
+       if(encoder->get_rice_parameter_search_dist() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
+               return false;
+       }
+       printf("OK\n");
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       printf("testing process()... ");
+       if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing process_interleaved()... ");
+       if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing finish()... ");
+       encoder->finish();
+       printf("OK\n");
+
+       printf("freeing encoder instance... ");
+       delete encoder;
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+class FileEncoder : public FLAC::Encoder::File {
+public:
+       FileEncoder(): FLAC::Encoder::File() { }
+       ~FileEncoder() { }
+
+       // from FLAC::Encoder::File
+       //@@@@ progress callback
+
+       bool die(const char *msg = 0) const;
+};
+
+bool FileEncoder::die(const char *msg) const
+{
+       State state = get_state();
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)((::FLAC__FileEncoderState)state), state.as_cstring());
+       if(state == ::FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
+               FLAC::Encoder::SeekableStream::State state_ = get_seekable_stream_encoder_state();
+               printf("      seekable stream encoder state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
+               if(state_ == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
+                       FLAC::Encoder::Stream::State state__ = get_stream_encoder_state();
+                       printf("      stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
+               }
+       }
+
+       return false;
+}
+
+static bool test_file_encoder()
+{
+       FileEncoder *encoder;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libFLAC++ unit test: FLAC::Encoder::File\n\n");
+
+       printf("allocating encoder instance... ");
+       encoder = new FileEncoder();
+       if(0 == encoder) {
+               printf("FAILED, new returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing is_valid()... ");
+       if(!encoder->is_valid()) {
+               printf("FAILED, returned false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing set_streamable_subset()... ");
+       if(!encoder->set_streamable_subset(true))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_mid_side_stereo()... ");
+       if(!encoder->set_do_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_loose_mid_side_stereo()... ");
+       if(!encoder->set_loose_mid_side_stereo(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_channels()... ");
+       if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_bits_per_sample()... ");
+       if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_sample_rate()... ");
+       if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_blocksize()... ");
+       if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_lpc_order()... ");
+       if(!encoder->set_max_lpc_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_qlp_coeff_precision()... ");
+       if(!encoder->set_qlp_coeff_precision(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_qlp_coeff_prec_search()... ");
+       if(!encoder->set_do_qlp_coeff_prec_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_escape_coding()... ");
+       if(!encoder->set_do_escape_coding(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_do_exhaustive_model_search()... ");
+       if(!encoder->set_do_exhaustive_model_search(false))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_min_residual_partition_order()... ");
+       if(!encoder->set_min_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_max_residual_partition_order()... ");
+       if(!encoder->set_max_residual_partition_order(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_rice_parameter_search_dist()... ");
+       if(!encoder->set_rice_parameter_search_dist(0))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_total_samples_estimate()... ");
+       if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_metadata()... ");
+       if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing set_filename()... ");
+       if(!encoder->set_filename(flacfilename_))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing init()... ");
+       if(encoder->init() != ::FLAC__FILE_ENCODER_OK)
+               return encoder->die();
+       printf("OK\n");
+
+       printf("testing get_state()... ");
+       FLAC::Encoder::File::State state = encoder->get_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__FileEncoderState)state), state.as_cstring());
+
+       printf("testing get_seekable_stream_encoder_state()... ");
+       FLAC::Encoder::SeekableStream::State state_ = encoder->get_seekable_stream_encoder_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
+
+       printf("testing get_stream_encoder_state()... ");
+       FLAC::Encoder::Stream::State state__ = encoder->get_stream_encoder_state();
+       printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
+
+       printf("testing get_streamable_subset()... ");
+       if(encoder->get_streamable_subset() != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_mid_side_stereo()... ");
+       if(encoder->get_do_mid_side_stereo() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_loose_mid_side_stereo()... ");
+       if(encoder->get_loose_mid_side_stereo() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_channels()... ");
+       if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_bits_per_sample()... ");
+       if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_sample_rate()... ");
+       if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_blocksize()... ");
+       if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_max_lpc_order()... ");
+       if(encoder->get_max_lpc_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_qlp_coeff_precision()... ");
+       (void)encoder->get_qlp_coeff_precision();
+       /* we asked the encoder to auto select this so we accept anything */
+       printf("OK\n");
+
+       printf("testing get_do_qlp_coeff_prec_search()... ");
+       if(encoder->get_do_qlp_coeff_prec_search() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_escape_coding()... ");
+       if(encoder->get_do_escape_coding() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_do_exhaustive_model_search()... ");
+       if(encoder->get_do_exhaustive_model_search() != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_min_residual_partition_order()... ");
+       if(encoder->get_min_residual_partition_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_max_residual_partition_order()... ");
+       if(encoder->get_max_residual_partition_order() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing get_rice_parameter_search_dist()... ");
+       if(encoder->get_rice_parameter_search_dist() != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
+               return false;
+       }
+       printf("OK\n");
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       printf("testing process()... ");
+       if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing process_interleaved()... ");
+       if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return encoder->die("returned false");
+       printf("OK\n");
+
+       printf("testing finish()... ");
+       encoder->finish();
+       printf("OK\n");
+
+       printf("freeing encoder instance... ");
+       delete encoder;
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+bool test_encoders()
+{
+       init_metadata_blocks_();
+
+       if(!test_stream_encoder())
+               return false;
+
+       if(!test_seekable_stream_encoder())
+               return false;
+
+       if(!test_file_encoder())
                return false;
 
        free_metadata_blocks_();
index f9f3014..4b6f018 100644 (file)
@@ -19,6 +19,8 @@
 #include "encoders.h"
 #include "file_utils.h"
 #include "FLAC/assert.h"
+#include "FLAC/file_encoder.h"
+#include "FLAC/seekable_stream_encoder.h"
 #include "FLAC/stream_encoder.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,9 +36,51 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
        FLAC__StreamEncoderState state = FLAC__stream_encoder_get_state(encoder);
 
        if(msg)
-               printf("FAILED, %s, state = %u (%s)\n", msg, (unsigned)state, FLAC__StreamEncoderStateString[state]);
+               printf("FAILED, %s", msg);
        else
-               printf("FAILED, state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state]);
+
+       return false;
+}
+
+static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
+{
+       FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
+       if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
+               FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
+               printf("      stream encoder state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state_]);
+       }
+
+       return false;
+}
+
+static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
+{
+       FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
+
+       if(msg)
+               printf("FAILED, %s", msg);
+       else
+               printf("FAILED");
+
+       printf(", state = %u (%s)\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
+       if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
+               FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
+               printf("      seekable stream encoder state = %u (%s)\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state_]);
+               if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
+                       FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
+                       printf("      stream encoder state = %u (%s)\n", (unsigned)state, FLAC__StreamEncoderStateString[state__]);
+               }
+       }
 
        return false;
 }
@@ -128,13 +172,13 @@ static void free_metadata_blocks_()
        free(vorbiscomment_.data.vorbis_comment.comments);
 }
 
-static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
 {
        (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
        return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
 }
 
-static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
+static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
 {
        (void)encoder, (void)metadata, (void)client_data;
 }
@@ -243,12 +287,12 @@ static FLAC__bool test_stream_encoder()
        printf("OK\n");
 
        printf("testing FLAC__stream_encoder_set_write_callback()... ");
-       if(!FLAC__stream_encoder_set_write_callback(encoder, encoder_write_callback_))
+       if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
                return die_s_("returned false", encoder);
        printf("OK\n");
 
        printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
-       if(!FLAC__stream_encoder_set_metadata_callback(encoder, encoder_metadata_callback_))
+       if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
                return die_s_("returned false", encoder);
        printf("OK\n");
 
@@ -396,6 +440,522 @@ static FLAC__bool test_stream_encoder()
        return true;
 }
 
+FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
+{
+       (void)encoder, (void)absolute_byte_offset, (void)client_data;
+       return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
+}
+
+FLAC__StreamEncoderWriteStatus seekable_stream_encoder_write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
+{
+       (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
+       return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
+}
+
+static FLAC__bool test_seekable_stream_encoder()
+{
+       FLAC__SeekableStreamEncoder *encoder;
+       FLAC__SeekableStreamEncoderState state;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libFLAC unit test: FLAC__SeekableStreamEncoder\n\n");
+
+       printf("testing FLAC__seekable_stream_encoder_new()... ");
+       encoder = FLAC__seekable_stream_encoder_new();
+       if(0 == encoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
+       if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
+       if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
+       if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
+       if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
+       if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
+       if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
+       if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
+       if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
+       if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
+       if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
+       if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
+       if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
+       if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
+       if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
+       if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
+       if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
+       if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
+       if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
+       if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
+       if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_init()... ");
+       if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
+               return die_ss_(0, encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_state()... ");
+       state = FLAC__seekable_stream_encoder_get_state(encoder);
+       printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
+
+       printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
+       if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
+       if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
+       if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
+       if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
+       if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
+       if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
+       if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
+       if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
+       (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
+       /* we asked the encoder to auto select this so we accept anything */
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
+       if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
+       if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
+       if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
+       if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
+       if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
+       if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       printf("testing FLAC__seekable_stream_encoder_process()... ");
+       if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
+       if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_ss_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_finish()... ");
+       FLAC__seekable_stream_encoder_finish(encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__seekable_stream_encoder_delete()... ");
+       FLAC__seekable_stream_encoder_delete(encoder);
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
+static FLAC__bool test_file_encoder()
+{
+       FLAC__FileEncoder *encoder;
+       FLAC__FileEncoderState state;
+       FLAC__int32 samples[1024];
+       FLAC__int32 *samples_array[1] = { samples };
+       unsigned i;
+
+       printf("\n+++ libFLAC unit test: FLAC__FileEncoder\n\n");
+
+       printf("testing FLAC__file_encoder_new()... ");
+       encoder = FLAC__file_encoder_new();
+       if(0 == encoder) {
+               printf("FAILED, returned NULL\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_streamable_subset()... ");
+       if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
+       if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
+       if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_channels()... ");
+       if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
+       if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_sample_rate()... ");
+       if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_blocksize()... ");
+       if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
+       if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
+       if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
+       if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
+       if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
+       if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
+       if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
+       if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
+       if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
+       if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_metadata()... ");
+       if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_set_filename()... ");
+       if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_init()... ");
+       if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
+               return die_f_(0, encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_state()... ");
+       state = FLAC__file_encoder_get_state(encoder);
+       printf("returned state = %u (%s)... OK\n", (unsigned)state, FLAC__FileEncoderStateString[state]);
+
+       printf("testing FLAC__file_encoder_get_streamable_subset()... ");
+       if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
+               printf("FAILED, expected true, got false\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
+       if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
+       if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_channels()... ");
+       if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
+       if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_sample_rate()... ");
+       if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_blocksize()... ");
+       if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
+               printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
+       if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
+       (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
+       /* we asked the encoder to auto select this so we accept anything */
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
+       if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
+       if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
+       if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
+               printf("FAILED, expected false, got true\n");
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
+       if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
+       if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
+       if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
+               printf("FAILED, expected %u, got %u\n", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
+               return false;
+       }
+       printf("OK\n");
+
+       /* init the dummy sample buffer */
+       for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
+               samples[i] = i & 7;
+
+       printf("testing FLAC__file_encoder_process()... ");
+       if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_process_interleaved()... ");
+       if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
+               return die_f_("returned false", encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_finish()... ");
+       FLAC__file_encoder_finish(encoder);
+       printf("OK\n");
+
+       printf("testing FLAC__file_encoder_delete()... ");
+       FLAC__file_encoder_delete(encoder);
+       printf("OK\n");
+
+       printf("\nPASSED!\n");
+
+       return true;
+}
+
 FLAC__bool test_encoders()
 {
        init_metadata_blocks_();
@@ -403,6 +963,12 @@ FLAC__bool test_encoders()
        if(!test_stream_encoder())
                return false;
 
+       if(!test_seekable_stream_encoder())
+               return false;
+
+       if(!test_file_encoder())
+               return false;
+
        (void) file_utils__remove_file(flacfilename_);
        free_metadata_blocks_();