From 9b942910e01b2aced11f1c62cd78e0b70aa8b4bc Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 27 Jan 2019 00:50:25 +0000 Subject: [PATCH] Allow for tx periods shorter than the audio buffer size Audio will not start until at least one buffer full is achieved and as we use a large target latency of 2s to minimize CPU usage and glitches we must pad with silence when the QAudioOutput pulls buffers from the Modulator i/o device. This is all necessary with pulseaudio using the underlying o/s ALSA device, i.e. on Linux. --- Modulator.cpp | 6 ++++++ soundout.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Modulator.cpp b/Modulator.cpp index 66c7a3202..5f6f9a5ac 100644 --- a/Modulator.cpp +++ b/Modulator.cpp @@ -319,6 +319,12 @@ qint64 Modulator::readData (char * data, qint64 maxSize) // done for this chunk - continue on next call // qint64 ms1=QDateTime::currentMSecsSinceEpoch() - m_ms0; // if(m_ic>=4*144*160) qDebug() << "Modulator finished" << m_ic << 0.001*ms1; + + while (samples != end) // pad block with silence + { + samples = load (0, samples); + ++framesGenerated; + } return framesGenerated * bytesPerFrame (); } // fall through diff --git a/soundout.cpp b/soundout.cpp index a4f8800df..b21675b3a 100644 --- a/soundout.cpp +++ b/soundout.cpp @@ -101,7 +101,7 @@ void SoundOutput::restart (QIODevice * source) m_stream->setBufferSize (m_stream->format().bytesForDuration((m_msBuffered ? m_msBuffered : MS_BUFFERED) * 1000)); // qDebug() << "B" << m_stream->bufferSize() << // m_stream->periodSize() << m_stream->notifyInterval(); - + m_stream->setCategory ("production"); m_stream->start (source); }