1 #ifndef AUDIOGRAPHER_SNDFILE_WRITER_H
2 #define AUDIOGRAPHER_SNDFILE_WRITER_H
6 #include <boost/format.hpp>
8 #include "audiographer/flag_debuggable.h"
9 #include "audiographer/sink.h"
10 #include "audiographer/types.h"
11 #include "audiographer/sndfile/sndfile_base.h"
12 #include "audiographer/broadcast_info.h"
14 #include "pbd/signals.h"
16 namespace AudioGrapher
19 /** Writer for audio files using libsndfile.
20 * Only short, int and float are valid template parameters
22 template <typename T = DefaultSampleType>
24 : public virtual SndfileBase
27 , public FlagDebuggable<>
30 SndfileWriter (std::string const & path, int format, ChannelCount channels, framecnt_t samplerate, boost::shared_ptr<BroadcastInfo> broadcast_info)
31 : SndfileHandle (path, Write, format, channels, samplerate)
37 broadcast_info->write_to_file (this);
41 virtual ~SndfileWriter () {}
43 using SndfileHandle::operator=;
45 framecnt_t get_frames_written() const { return frames_written; }
46 void reset_frames_written_count() { frames_written = 0; }
48 /// Writes data to file
49 virtual void process (ProcessContext<T> const & c)
51 check_flags (*this, c);
53 if (throw_level (ThrowStrict) && c.channels() != channels()) {
54 throw Exception (*this, boost::str (boost::format
55 ("Wrong number of channels given to process(), %1% instead of %2%")
56 % c.channels() % channels()));
59 framecnt_t const written = write (c.data(), c.frames());
60 frames_written += written;
62 if (throw_level (ThrowProcess) && written != c.frames()) {
63 throw Exception (*this, boost::str (boost::format
64 ("Could not write data to output file (%1%)")
68 if (c.has_flag(ProcessContext<T>::EndOfInput)) {
74 using Sink<T>::process;
76 PBD::Signal1<void, std::string> FileWritten;
79 /// SndfileHandle has to be constructed directly by deriving classes
88 add_supported_flag (ProcessContext<T>::EndOfInput);
93 framecnt_t frames_written;
96 SndfileWriter (SndfileWriter const & other) {}
101 #endif // AUDIOGRAPHER_SNDFILE_WRITER_H