From ecde374cee29864f56da3942eaeb716a52949bc0 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Mon, 10 Aug 2020 11:01:38 +0100 Subject: [PATCH] Trying a fixed audio input buffer size --- Audio/soundin.cpp | 6 +++++- Detector/Detector.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Audio/soundin.cpp b/Audio/soundin.cpp index a2856c255..8fede3524 100644 --- a/Audio/soundin.cpp +++ b/Audio/soundin.cpp @@ -81,11 +81,13 @@ void SoundInput::start(QAudioDeviceInfo const& device, int framesPerBuffer, Audi qDebug () << "SoundIn default buffer size (bytes):" << m_stream->bufferSize (); m_stream->setBufferSize (m_stream->format ().bytesForFrames (framesPerBuffer)); + m_stream->setBufferSize (m_stream->format ().bytesForFrames (3456 * 4 * 5)); qDebug () << "SoundIn selected buffer size (bytes):" << m_stream->bufferSize (); if (sink->initialize (QIODevice::WriteOnly, channel)) { m_stream->start (sink); audioError (); + cummulative_lost_usec_ = -1; } else { @@ -159,7 +161,9 @@ void SoundInput::reset (bool report_dropped_frames) { if (m_stream) { - if (report_dropped_frames) + if (cummulative_lost_usec_ >= 0 // don't report first time as we + // don't yet known latency + && report_dropped_frames) { auto lost_usec = m_stream->elapsedUSecs () - m_stream->processedUSecs () - cummulative_lost_usec_; Q_EMIT dropped_frames (m_stream->format ().framesForDuration (lost_usec), lost_usec); diff --git a/Detector/Detector.cpp b/Detector/Detector.cpp index 06b9c6b2d..7feb5a298 100644 --- a/Detector/Detector.cpp +++ b/Detector/Detector.cpp @@ -56,6 +56,7 @@ void Detector::clear () qint64 Detector::writeData (char const * data, qint64 maxSize) { + qDebug () << "Detector::writeData: size:" << maxSize; static unsigned mstr0=999999; qint64 ms0 = QDateTime::currentMSecsSinceEpoch() % 86400000; unsigned mstr = ms0 % int(1000.0*m_period); // ms into the nominal Tx start time @@ -119,8 +120,7 @@ qint64 Detector::writeData (char const * data, qint64 maxSize) remaining -= numFramesProcessed; } - - - return maxSize; // we drop any data past the end of the buffer on - // the floor until the next period starts + // we drop any data past the end of the buffer on the floor until + // the next period starts + return maxSize; }