| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | #ifndef DETECTOR_HPP__
 | 
					
						
							|  |  |  | #define DETECTOR_HPP__
 | 
					
						
							|  |  |  | #include "AudioDevice.hpp"
 | 
					
						
							|  |  |  | #include <QScopedArrayPointer>
 | 
					
						
							| 
									
										
										
										
											2019-11-17 01:21:07 -05:00
										 |  |  | #include <QMutex>
 | 
					
						
							|  |  |  | #include <QMutexLocker>
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05: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
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | class Detector : public AudioDevice | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Q_OBJECT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // if the data buffer were not global storage and fixed size then we
 | 
					
						
							|  |  |  |   // might want maximum size passed as constructor arguments
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // we down sample by a factor of 4
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // the samplesPerFFT argument is the number after down sampling
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   Detector (unsigned frameRate, unsigned periodLengthInSeconds, unsigned downSampleFactor = 4u, QObject * parent = 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-17 01:21:07 -05:00
										 |  |  |   QMutex * getMutex(){ return &m_lock; } | 
					
						
							| 
									
										
										
										
											2019-10-29 21:55:43 -04:00
										 |  |  |   unsigned period() const {return m_period;} | 
					
						
							| 
									
										
										
										
											2018-03-05 14:49:51 -05:00
										 |  |  |   void setTRPeriod(unsigned p) {m_period=p;} | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  |   bool reset () override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Q_SIGNAL void framesWritten (qint64) const; | 
					
						
							|  |  |  |   Q_SLOT void setBlockSize (unsigned); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:07:24 -04:00
										 |  |  |   void clear ();		// discard buffer contents
 | 
					
						
							|  |  |  |   unsigned secondInPeriod () const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | protected: | 
					
						
							|  |  |  |   qint64 readData (char * /* data */, qint64 /* maxSize */) override | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     return -1;			// we don't produce data
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   qint64 writeData (char const * data, qint64 maxSize) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |   unsigned m_frameRate; | 
					
						
							|  |  |  |   unsigned m_period; | 
					
						
							|  |  |  |   unsigned m_downSampleFactor; | 
					
						
							|  |  |  |   qint32 m_samplesPerFFT;	// after any down sampling
 | 
					
						
							|  |  |  |   qint32 m_ns; | 
					
						
							|  |  |  |   static size_t const max_buffer_size {7 * 512}; | 
					
						
							|  |  |  |   QScopedArrayPointer<short> m_buffer; // de-interleaved sample buffer
 | 
					
						
							|  |  |  |   // big enough for all the
 | 
					
						
							|  |  |  |   // samples for one increment of
 | 
					
						
							|  |  |  |   // data (a signals worth) at
 | 
					
						
							|  |  |  |   // the input sample rate
 | 
					
						
							|  |  |  |   unsigned m_bufferPos; | 
					
						
							| 
									
										
										
										
											2019-11-17 01:21:07 -05:00
										 |  |  |   QMutex m_lock; | 
					
						
							| 
									
										
										
										
											2018-02-08 21:28:33 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |