UtiLite
0.2.14
A lite utilities library
|
00001 00007 #ifndef UAUDIORECORDER_H 00008 #define UAUDIORECORDER_H 00009 00010 #include "utilite/UtiLiteExp.h" // DLL export/import defines 00011 00012 #include <utilite/USemaphore.h> 00013 #include <utilite/UMutex.h> 00014 #include <utilite/UThreadNode.h> 00015 00016 #include <vector> 00017 00046 class UTILITE_EXP UAudioRecorder : public UThreadNode { 00047 public: 00048 virtual ~UAudioRecorder(); 00049 00050 virtual bool init() 00051 { 00052 _samplesMutex.lock(); 00053 _samples.clear(); 00054 _samplesMutex.unlock(); 00055 return true; 00056 } 00057 virtual void close() {} 00058 00059 void stop() {join(true);} // for convenience 00060 00072 bool getNextFrame(std::vector<char> & frame, 00073 bool removeOldFrames = false); 00074 00085 bool getNextFrame(std::vector<char> & frame, 00086 int &frameId); 00087 00099 bool getMultiFrame(std::vector<char> & frame, 00100 int frameIdBeg, 00101 int frameIdEnd); 00102 00114 bool getFrame(std::vector<char> & frame, int frameId); 00115 00123 void removeFrames(int frameIdBeg, 00124 int frameIdEnd); 00125 00126 int getNumFrames(); 00127 int getNextFrameToGet(); 00128 00129 int samples(); 00130 00131 int fs() const {return _fs;} 00132 int frameLength() const {return _frameLength;} 00133 int bytesPerSample() const {return _bytesPerSample;} 00134 int channels() const {return _channels;} 00135 00136 protected: 00137 UAudioRecorder(int fs = 44100, 00138 int frameLength = 1024, 00139 int bytesPerSample = 2, 00140 int channels = 1); 00141 00142 virtual void mainLoopEnd(); 00143 void pushBackSamples(void * data, int dataLengthInBytes); 00144 00145 void setFs(int fs) {_fs = fs;} 00146 void setFrameLength(int frameLength) {_frameLength = frameLength;} 00147 void setBytesPerSample(int bytesPerSample) {_bytesPerSample = bytesPerSample;} 00148 void setChannels(int channels) {_channels = channels;} 00149 00150 private: 00151 UMutex _samplesMutex; 00152 std::vector<char> _samples; 00153 00154 int _fs; 00155 int _frameLength; 00156 int _bytesPerSample; 00157 int _channels; 00158 00159 int _nextFrameToGet; 00160 USemaphore _getTrameSemaphore; 00161 00162 }; 00163 00164 #endif