UtiLite  0.3.1
A lite utilities library
audio/include/utilite/UAudioCaptureFFT.h
00001 /*
00002  * Micro.h
00003  *
00004  *  Created on: Mar 5, 2012
00005  *      Author: MatLab
00006  */
00007 
00008 #ifndef MICRO_H_
00009 #define MICRO_H_
00010 
00011 #include "utilite/UtiLiteAudioExp.h" // DLL export/import defines
00012 
00013 #include "utilite/UThreadNode.h"
00014 #include "utilite/UAudioEvent.h"
00015 #include "utilite/UTimer.h"
00016 #include <string>
00017 #include <vector>
00018 
00019 class UAudioCapture;
00020 
00025 class UTILITEAUDIO_EXP UAudioCaptureFFT : public UThread
00026 {
00027         typedef float fftwf_complex[2];
00028 public:
00029         UAudioCaptureFFT(UAudioEvent::Type eventType,
00030                         int deviceId,
00031                         int fs,
00032                         int frameLength,
00033                         int channels,
00034                         int bytesPerSample,
00035                         bool overlap = false,
00036                         int id = 0);
00037         UAudioCaptureFFT(UAudioEvent::Type eventType,
00038                         const std::string & path,
00039                         float frameRate,
00040                         bool simulateFrameRate = true,
00041                         bool playWhileRecording = false,
00042                         bool overlap = false,
00043                         int id = 0);
00044         virtual ~UAudioCaptureFFT();
00045 
00046         bool init();
00047         void stop(); // same as kill() but handle the case where underlying recorder is running and not the micro.
00048         void startRecorder(); // must only be used if Micro::start() is not used
00049 
00050         void setPositionMs(unsigned int pos);
00051 
00052         std::vector<std::vector<char> > getFrame();
00053         std::vector<std::vector<char> > getFrame(std::vector<std::vector<float> > & frameFreq, bool sqrdMagn = false);
00054         std::vector<std::vector<float> > computeFFT(const std::vector<std::vector<char> > & frame, bool sqrdMagn = false);
00055 
00056         int fs();
00057         int bytesPerSample();
00058         int channels();
00059         int nfft();
00060         int samples();
00061         float frameRate() const {return _frameRate;}
00062 
00063 protected:
00064         virtual void mainLoopBegin();
00065         virtual void mainLoop();
00066         virtual void mainLoopKill();
00067 
00068 private:
00069         UAudioEvent::Type _eventType;
00070         UAudioCapture* _recorder;
00071         float _frameRate;
00072         bool _simulateFreq;
00073         bool _overlap;
00074         UTimer _timer;
00075         std::vector<float> _window;
00076         std::vector<float> _in;
00077         fftwf_complex * _out; // fftwf_complex
00078         void * _p; // fftwf_plan
00079         int _id;
00080         std::vector<char> _lastFrame;
00081 };
00082 
00083 #endif /* MICRO_H_ */
 All Classes Files Functions Variables Enumerations Friends Defines