diff options
| author | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
|---|---|---|
| committer | Dave Hibberd <hibby@debian.org> | 2026-10-20 22:35:06 +0100 |
| commit | 82ebb1ed1af30cee4dfbb1c628431d32885a00e0 (patch) | |
| tree | 1a1f782d3e576b758be0bc61171574a7cd8f2376 /Audio/FixtureAudioInput.cpp | |
| parent | 061658210acb6425517733ea012dda803a7f72a1 (diff) | |
| parent | 61d684922b0f1c8455cc60eb3d123df058c9e1f5 (diff) | |
Merge tag 'debian/3.3.0_beta2+dfsg-1' into hibbian/trixie-backports
tagging wsjtx 3.3.0~beta2+dfsg-1
Diffstat (limited to 'Audio/FixtureAudioInput.cpp')
| -rw-r--r-- | Audio/FixtureAudioInput.cpp | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/Audio/FixtureAudioInput.cpp b/Audio/FixtureAudioInput.cpp index e72118ef..f0a6554d 100644 --- a/Audio/FixtureAudioInput.cpp +++ b/Audio/FixtureAudioInput.cpp @@ -16,10 +16,12 @@ #include "moc_FixtureAudioInput.cpp" FixtureAudioInput::FixtureAudioInput (QString path, Profile profile, + unsigned pacingSpeed, QObject * parent) : AudioInputSource {parent} , m_path {std::move (path)} , m_profile {profile} + , m_pacingSpeed {profile == Profile::Jtty ? pacingSpeed : 1} , m_timer {new QTimer {this}} { m_timer->setSingleShot (true); @@ -180,6 +182,7 @@ void FixtureAudioInput::suspend () { m_suspended = true; m_timer->stop (); + if (m_sink) m_sink->finishInput (); Q_EMIT status (tr ("Synthetic audio input suspended")); } @@ -192,8 +195,9 @@ void FixtureAudioInput::resume () m_suspended = false; if (m_emitting && m_framesEmitted) { - m_periodStartMs = QDateTime::currentMSecsSinceEpoch () + m_pacingStartMs = QDateTime::currentMSecsSinceEpoch () - (m_framesEmitted * 1000 / m_inputSampleRate); + if (Profile::Jtty != m_profile) m_periodStartMs = m_pacingStartMs; publishCaptureAnchor (m_framesEmitted); } Q_EMIT status (tr ("Synthetic audio input receiving")); @@ -205,6 +209,11 @@ qint64 FixtureAudioInput::captureTimestamp (qint64 frameIndex) const return m_periodStartMs + frameIndex * 1000 / m_inputSampleRate; } +qint64 FixtureAudioInput::pacingTimestamp (qint64 frameIndex) const +{ + return m_pacingStartMs + frameIndex * 1000 / m_inputSampleRate; +} + void FixtureAudioInput::publishCaptureAnchor (qint64 firstFrame) { auto descriptor = streamDescriptor (); @@ -218,13 +227,17 @@ void FixtureAudioInput::publishCaptureAnchor (qint64 firstFrame) void FixtureAudioInput::stop () { m_timer->stop (); + if (m_sink) m_sink->finishInput (); m_sink.clear (); m_pcm.clear (); m_leadInFrames = 0; m_tailFrames = 0; m_framesEmitted = 0; m_periodStartMs = 0; + m_pacingStartMs = 0; m_jttyAcknowledgedInputFrames = 0; + m_emissionTimer.invalidate (); + m_nextChunkMs = 0; m_chunkIndex = 0; m_started = false; m_suspended = true; @@ -247,7 +260,9 @@ void FixtureAudioInput::arm () void FixtureAudioInput::acknowledgeJttyFrames (qint64 detectorFrames) { - if (Profile::Jtty != m_profile || detectorFrames < 0) return; + if (Profile::Jtty != m_profile || detectorFrames < 0 || !m_started + || !m_emitting || m_suspended || !m_sink + || m_framesEmitted >= totalFrames ()) return; auto const inputFrames = detectorFrames * m_inputSampleRate / detectorSampleRate; m_jttyAcknowledgedInputFrames = std::max ( @@ -345,7 +360,8 @@ void FixtureAudioInput::fail (QString const& message) void FixtureAudioInput::maybeSchedule () { - if (!m_started || !m_armed || m_suspended || m_emitting) + if (!m_started || !m_armed || m_suspended || m_emitting + || m_framesEmitted >= totalFrames ()) { return; } @@ -358,29 +374,34 @@ void FixtureAudioInput::maybeSchedule () } else { - constexpr qint64 periodMs = 180000; - auto const fixtureDurationMs = (totalFrames () * 1000 + m_inputSampleRate - 1) - / m_inputSampleRate; - auto const periodOffsetMs = now % periodMs; - m_periodStartMs = periodOffsetMs + fixtureDurationMs <= periodMs - ? now : ((now / periodMs) + 1) * periodMs; + m_periodStartMs = (now / 180000) * 180000 + jttyCaptureOffsetMs (); } + m_pacingStartMs = Profile::Jtty == m_profile ? now : m_periodStartMs; + m_emissionTimer.start (); m_emitting = true; publishCaptureAnchor (m_framesEmitted); if (Profile::ReceiveHandoff == m_profile) return; - auto const delay = Profile::ReceiveHandoff == m_profile ? qint64 {0} - : std::max<qint64> (0, m_periodStartMs - now); + auto const delay = Profile::Jtty == m_profile && m_pacingSpeed > 1 + ? qint64 {1} : std::max<qint64> (0, m_pacingStartMs - now); m_timer->start (static_cast<int> (delay)); } void FixtureAudioInput::scheduleNextChunk () { + if (!m_started || !m_armed || !m_emitting || m_suspended || !m_sink + || m_framesEmitted >= totalFrames ()) return; + if (Profile::Jtty == m_profile && m_pacingSpeed > 1) + { + auto const delay = std::max<qint64> (1, m_nextChunkMs - m_emissionTimer.elapsed ()); + m_timer->start (static_cast<int> (delay)); + return; + } if (Profile::ReceiveHandoff == m_profile) { m_timer->start (0); return; } - auto const target = captureTimestamp (m_framesEmitted); + auto const target = pacingTimestamp (m_framesEmitted); auto const delay = std::max<qint64> (0, target - QDateTime::currentMSecsSinceEpoch ()); m_timer->start (static_cast<int> (delay)); } @@ -392,9 +413,10 @@ void FixtureAudioInput::emitNextChunk () return; } - auto const target = captureTimestamp (m_framesEmitted); + auto const target = pacingTimestamp (m_framesEmitted); auto const now = QDateTime::currentMSecsSinceEpoch (); - if (Profile::ReceiveHandoff != m_profile && now < target) + if (Profile::ReceiveHandoff != m_profile + && !(Profile::Jtty == m_profile && m_pacingSpeed > 1) && now < target) { m_timer->start (static_cast<int> (target - now)); return; @@ -405,7 +427,9 @@ void FixtureAudioInput::emitNextChunk () Q_EMIT emissionStarted (m_periodStartMs); } - auto remainingFrames = totalFrames () - m_framesEmitted; + auto const remainingFrames = totalFrames () - m_framesEmitted; + auto chunkFrames = std::min<qint64> ( + remainingFrames, m_chunkFrames.at (m_chunkIndex % m_chunkFrames.size ())); if (Profile::Jtty == m_profile) { constexpr qint64 maxDetectorLeadFrames = 10240; @@ -414,16 +438,13 @@ void FixtureAudioInput::emitNextChunk () auto const allowedFrames = m_jttyDecoderReady ? m_jttyAcknowledgedInputFrames + maxInputLeadFrames : m_leadInFrames; - remainingFrames = std::min ( - remainingFrames, allowedFrames - m_framesEmitted); - if (remainingFrames <= 0) + if (chunkFrames > allowedFrames - m_framesEmitted) { m_waitingForJttyDecoder = true; return; } + m_waitingForJttyDecoder = false; } - auto chunkFrames = std::min<qint64> ( - remainingFrames, m_chunkFrames.at (m_chunkIndex % m_chunkFrames.size ())); if (Profile::ReceiveHandoff == m_profile) { constexpr qint64 periodFrames = 15 * detectorSampleRate; @@ -457,9 +478,17 @@ void FixtureAudioInput::emitNextChunk () m_framesEmitted += chunkFrames; ++m_chunkIndex; + if (Profile::Jtty == m_profile) + { + auto const scaledRate = qint64 {m_inputSampleRate} * m_pacingSpeed; + // Decoder backpressure must not accumulate a burst of overdue chunks. + m_nextChunkMs = m_emissionTimer.elapsed () + + (chunkFrames * 1000 + scaledRate - 1) / scaledRate; + } if (m_framesEmitted == totalFrames ()) { m_emitting = false; + if (Profile::Jtty == m_profile) m_sink->finishInput (); Q_EMIT status (tr ("Synthetic audio fixture exhausted")); Q_EMIT emissionFinished (m_framesEmitted); return; |
