00001 #ifndef GAMMA_RECORDER_H_INC
00002 #define GAMMA_RECORDER_H_INC
00003
00004
00005
00006
00007 #include <stdlib.h>
00008 #include <vector>
00009
00010 namespace gam{
00011
00013 class Recorder {
00014 public:
00015
00018 Recorder(int channels=1, int frames=8192);
00019
00020
00022 int channels() const { return mChans; }
00023
00025 int frames() const { return size()/channels(); }
00026
00028 int size() const { return mRing.size(); }
00029
00031 void overwrite(float v, int chan){
00032 mRing[mIW+chan] = v;
00033 }
00034
00036 void write(float v, int chan=0){
00037 overwrite(v,chan);
00038 if((mIW+=channels()) >= (int)mRing.size()) mIW=0;
00039 }
00040
00043 void write(float v1, float v2, int chan=0){
00044 overwrite(v1,chan);
00045 overwrite(v2,chan+1);
00046 if((mIW+=channels()) >= (int)mRing.size()) mIW=0;
00047 }
00048
00050
00055 int read(float *& buf);
00056
00058
00061 void resize(int chans, int frames);
00062
00063 protected:
00064 int mChans;
00065 int mIW;
00066 int mIR;
00067 std::vector<float> mRing;
00068 std::vector<float> mRead;
00069 };
00070
00071 }
00072 #endif