Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef SAMPLE_BUFFER_HPP
00030 #define SAMPLE_BUFFER_HPP
00031 
00032 #include <boost/assert.hpp>
00033 #include "Portability.hpp"
00034 
00035 template<class T>
00036 class DllExport SampleBuffer
00037 {
00038  public:
00039   SampleBuffer() : mpBuffer(0), mPosition(0) {
00040     mpBuffer = new T[RING_SIZE];
00041   }
00042     
00043   SampleBuffer(const SampleBuffer& copy) :mpBuffer(copy.mpBuffer), mPosition(copy.mPosition) {
00044   }
00045     
00046   SampleBuffer& operator=(const SampleBuffer& other) {
00047     mpBuffer = other.mpBuffer;
00048     mPosition = other.mPosition;
00049   }
00050     
00051   ~SampleBuffer() {
00052     BOOST_VERIFY(mpBuffer != 0);
00053     delete[] mpBuffer;
00054   }
00055 
00056   size_t maximumReservation() {
00057     return RING_SIZE;
00058   }
00059     
00060   T* reserve(size_t samples) {
00061     BOOST_VERIFY(mpBuffer != 0);
00062         
00063     if (samples > maximumReservation()) {
00064       cerr << "SampleBuffer.reserve: ERROR: a reservation larger than the maximum reservation; returning 0 " << endl;
00065       return 0;
00066     }
00067         
00068     if ((mPosition + samples) >= maximumReservation()) {
00069       mPosition = 0;
00070     }
00071         
00072     T* ret = mpBuffer+mPosition;
00073     mPosition += samples;
00074     return ret;
00075   }
00076     
00077  private:
00078   static const size_t RING_SIZE=1048576;
00079   T* mpBuffer;
00080   size_t mPosition;
00081 };
00082 
00083 #endif