UtiLite
0.3.1
A lite utilities library
|
00001 00007 #ifndef UAUDIORECORDER_H 00008 #define UAUDIORECORDER_H 00009 00010 #include "utilite/UtiLiteAudioExp.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 00048 class UTILITEAUDIO_EXP UAudioCapture : public UThread { 00049 public: 00050 virtual ~UAudioCapture(); 00051 00052 virtual bool init() 00053 { 00054 _samplesMutex.lock(); 00055 _samples.clear(); 00056 _samplesMutex.unlock(); 00057 return true; 00058 } 00059 virtual void close() {} 00060 00061 void stop() {join(true);} // for convenience 00062 00074 bool getNextFrame(std::vector<char> & frame, 00075 bool removeOldFrames = false); 00076 00087 bool getNextFrame(std::vector<char> & frame, 00088 int &frameId); 00089 00101 bool getMultiFrame(std::vector<char> & frame, 00102 int frameIdBeg, 00103 int frameIdEnd); 00104 00116 bool getFrame(std::vector<char> & frame, int frameId); 00117 00125 void removeFrames(int frameIdBeg, 00126 int frameIdEnd); 00127 00133 void removeSamples(int sampleByteBeg, 00134 int sampleByteEnd); 00135 00136 int getNumFrames(); 00137 int getNextFrameToGet(); 00138 00139 int samples(); 00140 00141 int fs() const {return _fs;} 00142 int frameLength() const {return _frameLength;} 00143 int bytesPerSample() const {return _bytesPerSample;} 00144 int channels() const {return _channels;} 00145 00146 void setFrameLength(int frameLength) {_frameLength = frameLength;} 00147 00148 protected: 00149 UAudioCapture(int fs = 44100, 00150 int frameLength = 1024, 00151 int bytesPerSample = 2, 00152 int channels = 1); 00153 00154 virtual void mainLoopEnd(); 00155 void pushBackSamples(void * data, int dataLengthInBytes); 00156 00157 void setFs(int fs) {_fs = fs;} 00158 void setBytesPerSample(int bytesPerSample) {_bytesPerSample = bytesPerSample;} 00159 void setChannels(int channels) {_channels = channels;} 00160 00161 private: 00162 UMutex _samplesMutex; 00163 std::vector<char> _samples; 00164 00165 int _fs; 00166 int _frameLength; 00167 int _bytesPerSample; 00168 int _channels; 00169 00170 int _nextFrameToGet; 00171 USemaphore _getTrameSemaphore; 00172 00173 }; 00174 00175 #endif