RingBuffer.h

Go to the documentation of this file.
00001 //
00002 //  RingBuffer.h -- the ring buffer class specification
00003 //  See the copyright notice and acknowledgment of authors in the file COPYRIGHT
00004 //
00005 // This is a typical circular buffer with one writer and multiple readers (tap instances)
00006 
00007 #ifndef CSL_RingBuffer_H
00008 #define CSL_RingBuffer_H
00009 
00010 #include "CSL_Core.h"
00011 
00012 namespace csl {
00013 
00014 //class RingBuffer;     ///< forward declaration
00018 
00019 class RingBufferTap: public UnitGenerator, public Scalable, public Seekable {
00020 
00021 public:
00022     friend class RingBuffer;                    
00023 
00024     RingBufferTap(RingBuffer *parent, int offset = 0);  
00025 
00026     unsigned mLoopStartFrame;               
00027     unsigned mLoopEndFrame;             
00028 
00029     unsigned duration() const;
00030     unsigned seekTo(int position, SeekPosition whence) throw(CException);
00031     void setLoopStart(unsigned frame) { mLoopStartFrame = frame; }
00032     void setLoopEnd(unsigned frame) { mLoopEndFrame = frame; }
00033     
00034     void nextBuffer(Buffer &outputBuffer) throw(CException);            
00035     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00036     void destructiveNextBuffer(Buffer&outputBuffer) throw(CException);  
00037     void destructiveNextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00038                                 
00039 protected:
00040     unsigned mTempCurrentFrame;         // A hack necessary to track info.
00041     RingBuffer *mParentBuffer;              // A reference to the buffer from which i'm reading.
00042     
00043     void setOffset(int offset);
00044 };
00045 
00046 // NOTE: Doesn't delete the memory allocated for the buffer. It should! Jorge, June 2006.
00047 
00051 
00052 class RingBuffer : public UnitGenerator, public Scalable, public Writeable {
00053 
00054 public:
00055     friend class RingBufferTap;  
00056 
00057     RingBuffer() : UnitGenerator(), Writeable(), mCurrentWriteFrame(0), mBuffer(), mTap(this), mTempCurrentWriteFrame(0) { };
00058     RingBuffer(unsigned int numChannels, unsigned int numFrames) : UnitGenerator(), Writeable(), mCurrentWriteFrame(0),
00059             mBuffer(numChannels, numFrames), mTap(this), mTempCurrentWriteFrame(0) { mBuffer.allocateMonoBuffers(); };
00060 
00061 
00062     unsigned mCurrentWriteFrame; 
00063     Buffer mBuffer;
00064     RingBufferTap mTap;         
00065 
00066     unsigned seekTo(int position) throw(CException);
00067     
00070     void setLoopStart(unsigned frame) { mTap.setLoopStart(frame); };    
00071     void setLoopEnd(unsigned frame) { mTap.setLoopEnd(frame); };        
00072 
00076     void nextBuffer(Buffer &outputBuffer) throw(CException);            
00077     void writeBuffer(Buffer &inputBuffer) throw(CException);                
00078     void sumIntoBuffer(Buffer &inputBuffer) throw(CException);          
00079     void destructiveNextBuffer(Buffer &outputBuffer) throw(CException); 
00080     void writeBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00081     void sumIntoBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00082     
00083 protected:
00084     unsigned mTempCurrentWriteFrame;    
00085 };
00086 
00089 
00090 class BufferStream : public UnitGenerator, public Seekable, public Writeable {
00091 public:
00092     BufferStream(Buffer &buffer) : UnitGenerator(), Seekable(), Writeable(), mBuffer(&buffer), 
00093                     mCurrentWriteFrame(0), mTempCurrentFrame(0), mTempCurrentWriteFrame(0) { };
00094 
00095     void nextBuffer(Buffer &outputBuffer) throw(CException); 
00096     void writeBuffer(Buffer &inputBuffer) throw(CException); 
00097     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw(CException);
00098     void writeBuffer(Buffer &inputBuffer, unsigned bufNum) throw(CException);
00099     void setBuffer(Buffer &buffer) { mBuffer = &buffer; }
00100     unsigned seekTo(int position, SeekPosition whence) throw(CException);
00101     unsigned duration() const;
00102 
00103 protected:
00104     Buffer *mBuffer;
00105     unsigned mCurrentWriteFrame;
00106     unsigned mTempCurrentFrame;         
00107     unsigned mTempCurrentWriteFrame;    
00108 };
00109 
00110 }
00111 
00112 #endif
00113 

Generated on Fri Apr 6 20:18:12 2007 for CSL by  doxygen 1.4.5-20051010