summaryrefslogtreecommitdiff
path: root/Detector.cpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
committerhibby <d@vehibberd.com>2018-02-16 15:17:14 +0000
commit37f727ac0746fd85504aa46c1f023c09b3eff33a (patch)
treec8a7ce04545040a8f161ba279528730bd9a3e6ab /Detector.cpp
parentd63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff)
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'Detector.cpp')
-rw-r--r--Detector.cpp104
1 files changed, 51 insertions, 53 deletions
diff --git a/Detector.cpp b/Detector.cpp
index ef7a8ffa..69a10f5e 100644
--- a/Detector.cpp
+++ b/Detector.cpp
@@ -11,22 +11,26 @@ extern "C" {
}
Detector::Detector (unsigned frameRate, unsigned periodLengthInSeconds,
- unsigned framesPerSignal, unsigned downSampleFactor,
- QObject * parent)
+ unsigned downSampleFactor, QObject * parent)
: AudioDevice (parent)
, m_frameRate (frameRate)
, m_period (periodLengthInSeconds)
, m_downSampleFactor (downSampleFactor)
- , m_framesPerSignal (framesPerSignal)
- , m_starting (false)
+ , m_samplesPerFFT {max_buffer_size}
+ , m_ns (999)
, m_buffer ((downSampleFactor > 1) ?
- new short [framesPerSignal * downSampleFactor] : 0)
+ new short [max_buffer_size * downSampleFactor] : nullptr)
, m_bufferPos (0)
{
(void)m_frameRate; // quell compiler warning
clear ();
}
+void Detector::setBlockSize (unsigned n)
+{
+ m_samplesPerFFT = n;
+}
+
bool Detector::reset ()
{
clear ();
@@ -40,84 +44,78 @@ void Detector::clear ()
// set index to roughly where we are in time (1ms resolution)
// qint64 now (QDateTime::currentMSecsSinceEpoch ());
// unsigned msInPeriod ((now % 86400000LL) % (m_period * 1000));
- // jt9com_.kin = qMin ((msInPeriod * m_frameRate) / 1000, static_cast<unsigned> (sizeof (jt9com_.d2) / sizeof (jt9com_.d2[0])));
- jt9com_.kin = 0;
+ // dec_data.params.kin = qMin ((msInPeriod * m_frameRate) / 1000, static_cast<unsigned> (sizeof (dec_data.d2) / sizeof (dec_data.d2[0])));
+ dec_data.params.kin = 0;
m_bufferPos = 0;
// fill buffer with zeros (G4WJS commented out because it might cause decoder hangs)
- // qFill (jt9com_.d2, jt9com_.d2 + sizeof (jt9com_.d2) / sizeof (jt9com_.d2[0]), 0);
+ // qFill (dec_data.d2, dec_data.d2 + sizeof (dec_data.d2) / sizeof (dec_data.d2[0]), 0);
}
qint64 Detector::writeData (char const * data, qint64 maxSize)
{
- // no torn frames
- Q_ASSERT (!(maxSize % static_cast<qint64> (bytesPerFrame ())));
- // these are in terms of input frames (not down sampled)
- size_t framesAcceptable ((sizeof (jt9com_.d2) /
- sizeof (jt9com_.d2[0]) - jt9com_.kin) * m_downSampleFactor);
- size_t framesAccepted (qMin (static_cast<size_t> (maxSize /
- bytesPerFrame ()), framesAcceptable));
-
- if (framesAccepted < static_cast<size_t> (maxSize / bytesPerFrame ())) {
- qDebug () << "dropped " << maxSize / bytesPerFrame () - framesAccepted
- << " frames of data on the floor!";
+ int ns=secondInPeriod();
+ if(ns < m_ns) { // When ns has wrapped around to zero, restart the buffers
+ dec_data.params.kin = 0;
+ m_bufferPos = 0;
+ }
+ m_ns=ns;
+
+ // no torn frames
+ Q_ASSERT (!(maxSize % static_cast<qint64> (bytesPerFrame ())));
+ // these are in terms of input frames (not down sampled)
+ size_t framesAcceptable ((sizeof (dec_data.d2) /
+ sizeof (dec_data.d2[0]) - dec_data.params.kin) * m_downSampleFactor);
+ size_t framesAccepted (qMin (static_cast<size_t> (maxSize /
+ bytesPerFrame ()), framesAcceptable));
+
+ if (framesAccepted < static_cast<size_t> (maxSize / bytesPerFrame ())) {
+ qDebug () << "dropped " << maxSize / bytesPerFrame () - framesAccepted
+ << " frames of data on the floor!"
+ << dec_data.params.kin << ns;
}
for (unsigned remaining = framesAccepted; remaining; ) {
- size_t numFramesProcessed (qMin (m_framesPerSignal *
+ size_t numFramesProcessed (qMin (m_samplesPerFFT *
m_downSampleFactor - m_bufferPos, remaining));
if(m_downSampleFactor > 1) {
store (&data[(framesAccepted - remaining) * bytesPerFrame ()],
numFramesProcessed, &m_buffer[m_bufferPos]);
m_bufferPos += numFramesProcessed;
- if(m_bufferPos==m_framesPerSignal*m_downSampleFactor) {
- qint32 framesToProcess (m_framesPerSignal * m_downSampleFactor);
- qint32 framesAfterDownSample;
- if(framesToProcess==13824 and jt9com_.kin>=0 and jt9com_.kin<1440000) {
- fil4_(&m_buffer[0], &framesToProcess, &jt9com_.d2[jt9com_.kin],
+
+ if(m_bufferPos==m_samplesPerFFT*m_downSampleFactor) {
+ qint32 framesToProcess (m_samplesPerFFT * m_downSampleFactor);
+ qint32 framesAfterDownSample (m_samplesPerFFT);
+ if(m_downSampleFactor > 1 && dec_data.params.kin>=0 &&
+ dec_data.params.kin < (NTMAX*12000 - framesAfterDownSample)) {
+ fil4_(&m_buffer[0], &framesToProcess, &dec_data.d2[dec_data.params.kin],
&framesAfterDownSample);
- jt9com_.kin += framesAfterDownSample;
+ dec_data.params.kin += framesAfterDownSample;
} else {
- qDebug() << "framesToProcess = " << framesToProcess;
- qDebug() << "jt9com_.kin = " << jt9com_.kin;
- qDebug() << "secondInPeriod = " << secondInPeriod();
+ // qDebug() << "framesToProcess = " << framesToProcess;
+ // qDebug() << "dec_data.params.kin = " << dec_data.params.kin;
+ // qDebug() << "secondInPeriod = " << secondInPeriod();
+ // qDebug() << "framesAfterDownSample" << framesAfterDownSample;
}
- Q_EMIT framesWritten (jt9com_.kin);
+ Q_EMIT framesWritten (dec_data.params.kin);
m_bufferPos = 0;
}
} else {
store (&data[(framesAccepted - remaining) * bytesPerFrame ()],
- numFramesProcessed, &jt9com_.d2[jt9com_.kin]);
+ numFramesProcessed, &dec_data.d2[dec_data.params.kin]);
m_bufferPos += numFramesProcessed;
- jt9com_.kin += numFramesProcessed;
- if (m_bufferPos == static_cast<unsigned> (m_framesPerSignal)) {
- Q_EMIT framesWritten (jt9com_.kin);
+ dec_data.params.kin += numFramesProcessed;
+ if (m_bufferPos == static_cast<unsigned> (m_samplesPerFFT)) {
+ Q_EMIT framesWritten (dec_data.params.kin);
m_bufferPos = 0;
}
}
-
- if (!secondInPeriod ()) {
- if (!m_starting) {
- // next samples will be in new period so wrap around to
- // start of buffer
- //
- // we don't bother calling reset () since we expect to fill
- // the whole buffer and don't need to waste cycles zeroing
- jt9com_.kin = 0;
- m_bufferPos = 0;
- m_starting = true;
- }
- } else if(m_starting) {
- m_starting = false;
- }
remaining -= numFramesProcessed;
}
- // } else {
- // jt9com_.kin = 0;
- // m_bufferPos = 0;
- // }
+
+
return maxSize; // we drop any data past the end of the buffer on
// the floor until the next period starts