4#include "JS8_Audio/AudioDevice.h"
7#include <vendor/Eigen/Dense>
29 static constexpr std::size_t NDOWN = 48 / 12;
30 static constexpr std::size_t NTAPS = 49;
31 static constexpr std::size_t SHIFT = NTAPS - NDOWN;
37 using Vector = Eigen::Vector<float, NTAPS>;
38 using Sample = Eigen::Map<Eigen::Vector<short, NDOWN>
const>;
43 explicit Filter(std::array<Vector::value_type, NTAPS>
const &lowpass)
44 : m_w(lowpass.data()), m_t(Vector::Zero()) {}
49 auto downSample(Sample::value_type
const *
const data) {
50 m_t.head(SHIFT) = m_t.segment(NDOWN, SHIFT);
51 m_t.tail(NDOWN) = Sample(data).cast<Vector::value_type>();
53 return static_cast<Sample::value_type
>(std::round(m_w.dot(m_t)));
59 Eigen::Map<Vector const> m_w;
65 static constexpr std::size_t MaxBufferSize = 7 * 512;
71 using Buffer = std::array<short, MaxBufferSize * Filter::NDOWN>;
76 Detector(
unsigned frameRate,
unsigned periodLengthInSeconds,
77 QObject *parent =
nullptr);
81 unsigned period()
const {
return m_period; }
85 QMutex *getMutex() {
return &m_lock; }
86 void setTRPeriod(
unsigned p) { m_period = p; }
95 bool reset()
override;
101 Q_SIGNAL
void framesWritten(qint64)
const;
107 qint64 readData(
char *, qint64)
override {
return -1; }
108 qint64
writeData(
char const *, qint64)
override;
113 unsigned m_frameRate;
118 Buffer::size_type m_bufferPos = 0;
119 std::size_t m_samplesPerFFT = MaxBufferSize;
bool reset() override
Reset the detector state.
Definition Detector.cpp:85
void resetBufferContent()
Reset the buffer content to zero.
Definition Detector.cpp:148
Detector(unsigned frameRate, unsigned periodLengthInSeconds, QObject *parent=nullptr)
Construct a new Detector object.
Definition Detector.cpp:65
void resetBufferPosition()
Reset the buffer position based on current time.
Definition Detector.cpp:114
unsigned secondInPeriod() const
Get the current second in the period.
Definition Detector.cpp:227
Q_SLOT void setBlockSize(unsigned)
Set the block size for FFT processing.
Definition Detector.cpp:77
void clear()
Clear the detector buffer.
Definition Detector.cpp:96
qint64 writeData(char const *, qint64) override
Write data to the detector buffer.
Definition Detector.cpp:162