1 #include "audiographer/sndfile_base.h"
2 #include "audiographer/exception.h"
4 #include <boost/format.hpp>
13 /* SndfileWriterBase */
15 SndfileBase::SndfileBase (ChannelCount channels, nframes_t samplerate, int format, string const & path)
20 sf_info.channels = channels;
21 sf_info.samplerate = samplerate;
22 sf_info.format = format;
24 if (!sf_format_check (&sf_info)) {
25 throw Exception (*this, "Invalid format in constructor");
28 if (path.length() == 0) {
29 throw Exception (*this, "No output file specified");
32 /* TODO add checks that the directory path exists, and also
33 check if we are overwriting an existing file...
37 if (path.compare ("temp")) {
38 if ((sndfile = sf_open (path.c_str(), SFM_WRITE, &sf_info)) == 0) {
39 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
40 throw Exception (*this, str (boost::format ("Cannot open output file \"%1%\" (%2%)") % path % errbuf));
44 if (!(file = tmpfile ())) {
45 throw Exception (*this, "Cannot open tempfile");
47 sndfile = sf_open_fd (fileno(file), SFM_RDWR, &sf_info, true);
51 SndfileBase::~SndfileBase ()