#include "audiographer/sndfile_writer.h" #include "audiographer/exception.h" #include #include namespace AudioGrapher { using std::string; using boost::str; using boost::format; template SndfileWriter::SndfileWriter (ChannelCount channels, nframes_t samplerate, int format, string const & path) : SndfileBase (channels, samplerate, format, path) { // init write function init (); } template <> void SndfileWriter::init () { write_func = &sf_write_float; } template <> void SndfileWriter::init () { write_func = &sf_write_int; } template <> void SndfileWriter::init () { write_func = &sf_write_short; } template void SndfileWriter::process (ProcessContext const & c) { if (c.channels() != sf_info.channels) { throw Exception (*this, str (boost::format( "Wrong number of channels given to process(), %1% instead of %2%") % c.channels() % sf_info.channels)); } char errbuf[256]; nframes_t written = (*write_func) (sndfile, c.data(), c.frames()); if (written != c.frames()) { sf_error_str (sndfile, errbuf, sizeof (errbuf) - 1); throw Exception (*this, str ( format("Could not write data to output file (%1%)") % errbuf)); } if (c.has_flag(ProcessContext::EndOfInput)) { sf_write_sync (sndfile); //#ifdef HAVE_SIGCPP FileWritten (path); //#endif } } template class SndfileWriter; template class SndfileWriter; template class SndfileWriter; } // namespace