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
|
|
|
|
2013-09-28 14:34:27 -04:00
|
|
|
#include <QScopedArrayPointer>
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 14:34:27 -04:00
|
|
|
// we down sample by a factor of 4
|
|
|
|
//
|
|
|
|
// the framesPerSignal argument is the number after down sampling
|
|
|
|
//
|
2013-10-04 15:00:29 -04:00
|
|
|
Detector (unsigned frameRate, unsigned periodLengthInSeconds, unsigned framesPerSignal, unsigned downSampleFactor = 4u, QObject * parent = 0);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
Q_SIGNAL void framesWritten (qint64) const;
|
|
|
|
|
2014-04-06 20:55:05 -04:00
|
|
|
bool reset () override;
|
|
|
|
|
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-10-04 15:00:29 -04:00
|
|
|
unsigned m_downSampleFactor;
|
|
|
|
qint32 m_framesPerSignal; // after any down sampling
|
2013-08-07 19:09:13 -04:00
|
|
|
bool m_starting;
|
2013-09-28 14:34:27 -04:00
|
|
|
QScopedArrayPointer<short> m_buffer; // de-interleaved sample buffer
|
2014-04-03 15:29:13 -04:00
|
|
|
// big enough for all the
|
|
|
|
// samples for one increment of
|
|
|
|
// data (a signals worth) at
|
|
|
|
// the input sample rate
|
2013-09-28 14:34:27 -04:00
|
|
|
unsigned m_bufferPos;
|
2013-08-07 19:09:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|