1 #include "audiographer/sndfile_writer.h"
2 #include "audiographer/exception.h"
6 #include <boost/format.hpp>
16 SndfileWriter<T>::SndfileWriter (ChannelCount channels, nframes_t samplerate, int format, string const & path) :
17 SndfileBase (channels, samplerate, format, path)
19 // init write function
25 SndfileWriter<float>::init ()
27 write_func = &sf_write_float;
32 SndfileWriter<int>::init ()
34 write_func = &sf_write_int;
39 SndfileWriter<short>::init ()
41 write_func = &sf_write_short;
46 SndfileWriter<T>::process (ProcessContext<T> const & c)
48 if (c.channels() != sf_info.channels) {
49 throw Exception (*this, str (boost::format(
50 "Wrong number of channels given to process(), %1% instead of %2%")
51 % c.channels() % sf_info.channels));
55 nframes_t written = (*write_func) (sndfile, c.data(), c.frames());
56 if (written != c.frames()) {
57 sf_error_str (sndfile, errbuf, sizeof (errbuf) - 1);
58 throw Exception (*this, str ( format("Could not write data to output file (%1%)") % errbuf));
61 if (c.has_flag(ProcessContext<T>::EndOfInput)) {
62 sf_write_sync (sndfile);
64 if (debug_level (DebugProcess)) {
65 debug_stream() << str ( format("Finished writing file %1%") % path) << std::endl;
70 template class SndfileWriter<short>;
71 template class SndfileWriter<int>;
72 template class SndfileWriter<float>;