| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | #ifndef DETECTOR_HPP__
 | 
					
						
							|  |  |  | #define DETECTOR_HPP__
 | 
					
						
							| 
									
										
										
										
											2013-08-10 15:29:55 +00:00
										 |  |  | #include "AudioDevice.hpp"
 | 
					
						
							| 
									
										
										
										
											2013-09-28 18:34:27 +00:00
										 |  |  | #include <QScopedArrayPointer>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | // output device that distributes data in predefined chunks via a signal
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // the underlying device for this abstraction is just the buffer that
 | 
					
						
							|  |  |  | // stores samples throughout a receiving period
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2013-08-10 15:29:55 +00:00
										 |  |  | class Detector : public AudioDevice | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   Q_OBJECT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // if the data buffer were not global storage and fixed size then we
 | 
					
						
							|  |  |  |   // might want maximum size passed as constructor arguments
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2013-09-28 18:34:27 +00:00
										 |  |  |   // we down sample by a factor of 4
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  |   // the samplesPerFFT argument is the number after down sampling
 | 
					
						
							| 
									
										
										
										
											2013-09-28 18:34:27 +00:00
										 |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2016-06-17 01:27:00 +00:00
										 |  |  |   Detector (unsigned frameRate, unsigned periodLengthInSeconds, unsigned downSampleFactor = 4u, QObject * parent = 0); | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-27 13:08:28 +00:00
										 |  |  |   void setPeriod(unsigned p) {m_period=p;} | 
					
						
							| 
									
										
										
										
											2014-04-07 00:55:05 +00:00
										 |  |  |   bool reset () override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 01:27:00 +00:00
										 |  |  |   Q_SIGNAL void framesWritten (qint64) const; | 
					
						
							|  |  |  |   Q_SLOT void setBlockSize (unsigned); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2016-04-06 22:37:22 +00:00
										 |  |  |   qint64 readData (char * /* data */, qint64 /* maxSize */) override | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     return -1;			// we don't produce data
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-06 22:37:22 +00:00
										 |  |  |   qint64 writeData (char const * data, qint64 maxSize) override; | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |   void clear ();		// discard buffer contents
 | 
					
						
							|  |  |  |   unsigned secondInPeriod () const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unsigned m_frameRate; | 
					
						
							|  |  |  |   unsigned m_period; | 
					
						
							| 
									
										
										
										
											2013-10-04 19:00:29 +00:00
										 |  |  |   unsigned m_downSampleFactor; | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  |   qint32 m_samplesPerFFT;	// after any down sampling
 | 
					
						
							|  |  |  |   qint32 m_ns; | 
					
						
							| 
									
										
										
										
											2016-06-17 01:27:00 +00:00
										 |  |  |   static size_t const max_buffer_size {7 * 512}; | 
					
						
							| 
									
										
										
										
											2013-09-28 18:34:27 +00:00
										 |  |  |   QScopedArrayPointer<short> m_buffer; // de-interleaved sample buffer
 | 
					
						
							| 
									
										
										
										
											2014-04-03 19:29:13 +00:00
										 |  |  |   // big enough for all the
 | 
					
						
							|  |  |  |   // samples for one increment of
 | 
					
						
							|  |  |  |   // data (a signals worth) at
 | 
					
						
							|  |  |  |   // the input sample rate
 | 
					
						
							| 
									
										
										
										
											2013-09-28 18:34:27 +00:00
										 |  |  |   unsigned m_bufferPos; | 
					
						
							| 
									
										
										
										
											2013-08-07 23:09:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |