diff options
| author | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
|---|---|---|
| committer | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
| commit | d63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch) | |
| tree | b9c1f6245147a310aac3762630bad389bbb57335 /Detector.hpp | |
| parent | c720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff) | |
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'Detector.hpp')
| -rw-r--r-- | Detector.hpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Detector.hpp b/Detector.hpp new file mode 100644 index 00000000..355dff15 --- /dev/null +++ b/Detector.hpp @@ -0,0 +1,58 @@ +#ifndef DETECTOR_HPP__ +#define DETECTOR_HPP__ + +#include "AudioDevice.hpp" + +#include <QScopedArrayPointer> + +// +// 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 framesPerSignal argument is the number after down sampling + // + Detector (unsigned frameRate, unsigned periodLengthInSeconds, unsigned framesPerSignal, unsigned downSampleFactor = 4u, QObject * parent = 0); + + Q_SIGNAL void framesWritten (qint64) const; + + bool reset () override; + +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; + unsigned m_downSampleFactor; + qint32 m_framesPerSignal; // after any down sampling + bool m_starting; + 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; +}; + +#endif |
