1 #ifndef AUDIOGRAPHER_INTERLEAVER_H
2 #define AUDIOGRAPHER_INTERLEAVER_H
5 #include "listed_source.h"
12 namespace AudioGrapher
16 class Interleaver : public ListedSource<T>
21 ~Interleaver() { reset(); }
23 void init (unsigned int num_channels, nframes_t max_frames_per_channel);
24 typename Source<T>::SinkPtr input (unsigned int channel);
28 class Input : public Sink<T>
31 Input (Interleaver & parent, unsigned int channel)
32 : frames_written (0), parent (parent), channel (channel) {}
34 void process (ProcessContext<T> const & c)
36 if (c.channels() > 1) { throw Exception (*this, "Data input has more than on channel"); }
37 if (frames_written) { throw Exception (*this, "Input channels out of sync"); }
38 frames_written = c.frames();
39 parent.write_channel (c, channel);
42 using Sink<T>::process;
44 nframes_t frames() { return frames_written; }
45 void reset() { frames_written = 0; }
48 nframes_t frames_written;
54 void reset_channels ();
55 void write_channel (ProcessContext<T> const & c, unsigned int channel);
56 nframes_t ready_to_output();
59 typedef boost::shared_ptr<Input> InputPtr;
60 std::vector<InputPtr> inputs;
62 unsigned int channels;
67 #include "interleaver-inl.h"
71 #endif // AUDIOGRAPHER_INTERLEAVER_H