summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/interleaver.h
diff options
context:
space:
mode:
authorSakari Bergen <sakari.bergen@beatwaves.net>2009-12-27 14:46:23 +0000
committerSakari Bergen <sakari.bergen@beatwaves.net>2009-12-27 14:46:23 +0000
commitdde0848a984e06cbc1d4117d9cffa75c191f3b39 (patch)
tree11f3a5fe94ac792e753297e16e4e80dd7e296aea /libs/audiographer/audiographer/interleaver.h
parent35c72a53b4c6bbc61b4b86db9de629e18362b48d (diff)
Re-integrate export-optimization branch.
Export now happens directly to file (unless normalizing is required), and can be easily optimized even further. The Session process connection is still broken during export (as it was before this commit also). git-svn-id: svn://localhost/ardour2/branches/3.0@6401 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/audiographer/audiographer/interleaver.h')
-rw-r--r--libs/audiographer/audiographer/interleaver.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/libs/audiographer/audiographer/interleaver.h b/libs/audiographer/audiographer/interleaver.h
new file mode 100644
index 0000000000..3d51fed5a5
--- /dev/null
+++ b/libs/audiographer/audiographer/interleaver.h
@@ -0,0 +1,71 @@
+#ifndef AUDIOGRAPHER_INTERLEAVER_H
+#define AUDIOGRAPHER_INTERLEAVER_H
+
+#include "types.h"
+#include "listed_source.h"
+#include "sink.h"
+#include "exception.h"
+
+#include <vector>
+#include <cmath>
+
+namespace AudioGrapher
+{
+
+template<typename T>
+class Interleaver : public ListedSource<T>
+{
+ public:
+
+ Interleaver();
+ ~Interleaver() { reset(); }
+
+ void init (unsigned int num_channels, nframes_t max_frames_per_channel);
+ typename Source<T>::SinkPtr input (unsigned int channel);
+
+ private:
+
+ class Input : public Sink<T>
+ {
+ public:
+ Input (Interleaver & parent, unsigned int channel)
+ : frames_written (0), parent (parent), channel (channel) {}
+
+ void process (ProcessContext<T> const & c)
+ {
+ if (c.channels() > 1) { throw Exception (*this, "Data input has more than on channel"); }
+ if (frames_written) { throw Exception (*this, "Input channels out of sync"); }
+ frames_written = c.frames();
+ parent.write_channel (c, channel);
+ }
+
+ using Sink<T>::process;
+
+ nframes_t frames() { return frames_written; }
+ void reset() { frames_written = 0; }
+
+ private:
+ nframes_t frames_written;
+ Interleaver & parent;
+ unsigned int channel;
+ };
+
+ void reset ();
+ void reset_channels ();
+ void write_channel (ProcessContext<T> const & c, unsigned int channel);
+ nframes_t ready_to_output();
+ void output();
+
+ typedef boost::shared_ptr<Input> InputPtr;
+ std::vector<InputPtr> inputs;
+
+ unsigned int channels;
+ nframes_t max_frames;
+ T * buffer;
+};
+
+#include "interleaver-inl.h"
+
+} // namespace
+
+#endif // AUDIOGRAPHER_INTERLEAVER_H