00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef CSL_RingBuffer_H
00011 #define CSL_RingBuffer_H
00012
00013 #include "CSL_Core.h"
00014
00015 namespace csl {
00016
00020
00021 class RingBufferTap: public UnitGenerator, public Scalable, public Seekable {
00022
00023 public:
00024 friend class RingBuffer;
00025
00028 RingBufferTap(RingBuffer *parent = 0, int offset = 0);
00029
00030 unsigned mLoopStartFrame;
00031 unsigned mLoopEndFrame;
00032
00033 void setOffset(int offset);
00034 unsigned duration() const;
00035 unsigned seekTo(int position, SeekPosition whence) throw(CException);
00036 void setLoopStart(unsigned frame) { mLoopStartFrame = frame; }
00037 void setLoopEnd(unsigned frame) { mLoopEndFrame = frame; }
00038 void setBuffer(RingBuffer *parent) { mParentBuffer = parent; }
00039
00040 void nextBuffer(Buffer &outputBuffer) throw(CException);
00041 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00042 void destructiveNextBuffer(Buffer&outputBuffer) throw(CException);
00043 void destructiveNextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00044
00045 protected:
00046 unsigned mTempCurrentFrame;
00047 RingBuffer *mParentBuffer;
00048
00049 };
00050
00054
00055
00056 class RingBuffer : public Effect, public Scalable, public Writeable {
00057
00058 public:
00059 friend class RingBufferTap;
00060
00061 RingBuffer();
00062 RingBuffer(unsigned int nmChannels, unsigned int nmFrames);
00063 RingBuffer(UnitGenerator & input, unsigned int nmChannels, unsigned int nmFrames);
00064
00065 unsigned mCurrentWriteFrame;
00066 Buffer mBuffer;
00067 RingBufferTap mTap;
00068
00069 unsigned seekTo(int position) throw(CException);
00070
00073 void setLoopStart(unsigned frame) { mTap.setLoopStart(frame); };
00074 void setLoopEnd(unsigned frame) { mTap.setLoopEnd(frame); };
00075
00079 void nextBuffer(Buffer &outputBuffer) throw(CException);
00080 void writeBuffer(Buffer &inputBuffer) throw(CException);
00081 void sumIntoBuffer(Buffer &inputBuffer) throw(CException);
00082 void destructiveNextBuffer(Buffer &outputBuffer) throw(CException);
00083 void writeBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00084 void sumIntoBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00085
00086 protected:
00087 unsigned mTempCurrentWriteFrame;
00088 };
00089
00092
00093 class BufferStream : public UnitGenerator, public Seekable, public Writeable {
00094 public:
00095 BufferStream(Buffer &buffer) : UnitGenerator(), Seekable(), Writeable(), mBuffer(&buffer),
00096 mCurrentWriteFrame(0), mTempCurrentFrame(0), mTempCurrentWriteFrame(0) { };
00097
00098 void nextBuffer(Buffer &outputBuffer) throw(CException);
00099 void writeBuffer(Buffer &inputBuffer) throw(CException);
00100 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00101 void writeBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00102 void setBuffer(Buffer &buffer) { mBuffer = &buffer; }
00103 unsigned seekTo(int position, SeekPosition whence) throw(CException);
00104 unsigned duration() const;
00105
00106 protected:
00107 Buffer *mBuffer;
00108 unsigned mCurrentWriteFrame;
00109 unsigned mTempCurrentFrame;
00110 unsigned mTempCurrentWriteFrame;
00111 };
00112
00113 }
00114
00115 #endif
00116