2013-08-07 19:09:13 -04:00
|
|
|
#ifndef DETECTOR_HPP__
|
|
|
|
#define DETECTOR_HPP__
|
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
#include "AudioDevice.hpp"
|
2013-08-07 19:09:13 -04: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 11:29:55 -04:00
|
|
|
class Detector : public AudioDevice
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
Q_PROPERTY (bool monitoring READ isMonitoring WRITE setMonitoring);
|
|
|
|
|
|
|
|
public:
|
|
|
|
//
|
|
|
|
// if the data buffer were not global storage and fixed size then we
|
|
|
|
// might want maximum size passed as constructor arguments
|
|
|
|
//
|
2013-08-10 11:29:55 -04:00
|
|
|
Detector (unsigned frameRate, unsigned periodLengthInSeconds, unsigned framesPerSignal, QObject * parent = 0);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
bool open (Channel channel = Mono) {return AudioDevice::open (QIODevice::WriteOnly, channel);}
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
bool isMonitoring () const {return m_monitoring;}
|
|
|
|
void setMonitoring (bool newState) {m_monitoring = newState;}
|
|
|
|
|
|
|
|
bool reset ();
|
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_SIGNAL void framesWritten (qint64);
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
protected:
|
|
|
|
qint64 readData (char * /* data */, qint64 /* maxSize */)
|
|
|
|
{
|
|
|
|
return -1; // we don't produce data
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 writeData (char const * data, qint64 maxSize);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void clear (); // discard buffer contents
|
|
|
|
unsigned secondInPeriod () const;
|
|
|
|
|
|
|
|
unsigned m_frameRate;
|
|
|
|
unsigned m_period;
|
2013-08-10 11:29:55 -04:00
|
|
|
unsigned m_framesPerSignal;
|
2013-08-07 19:09:13 -04:00
|
|
|
bool m_monitoring;
|
|
|
|
bool m_starting;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|