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-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
|
|
|
|
//
|
2015-04-22 13:48:03 -04:00
|
|
|
// the samplesPerFFT argument is the number after down sampling
|
2013-09-28 14:34:27 -04:00
|
|
|
//
|
2019-05-22 12:44:28 -04:00
|
|
|
Detector (unsigned frameRate, double periodLengthInSeconds, unsigned downSampleFactor = 4u,
|
|
|
|
QObject * parent = 0);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2019-05-22 12:44:28 -04:00
|
|
|
void setTRPeriod(double p) {m_period=p;}
|
2014-04-06 20:55:05 -04:00
|
|
|
bool reset () override;
|
|
|
|
|
2016-06-16 21:27:00 -04:00
|
|
|
Q_SIGNAL void framesWritten (qint64) const;
|
|
|
|
Q_SLOT void setBlockSize (unsigned);
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
protected:
|
2016-04-06 18:37:22 -04:00
|
|
|
qint64 readData (char * /* data */, qint64 /* maxSize */) override
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
|
|
|
return -1; // we don't produce data
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:37:22 -04:00
|
|
|
qint64 writeData (char const * data, qint64 maxSize) override;
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void clear (); // discard buffer contents
|
|
|
|
|
|
|
|
unsigned m_frameRate;
|
2019-05-22 12:44:28 -04:00
|
|
|
double m_period;
|
2013-10-04 15:00:29 -04:00
|
|
|
unsigned m_downSampleFactor;
|
2015-04-22 13:48:03 -04:00
|
|
|
qint32 m_samplesPerFFT; // after any down sampling
|
2016-06-16 21:27:00 -04:00
|
|
|
static size_t const max_buffer_size {7 * 512};
|
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
|