summaryrefslogtreecommitdiff
path: root/Audio/AudioStreamClock.hpp
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /Audio/AudioStreamClock.hpp
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'Audio/AudioStreamClock.hpp')
-rw-r--r--Audio/AudioStreamClock.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/Audio/AudioStreamClock.hpp b/Audio/AudioStreamClock.hpp
new file mode 100644
index 00000000..65e5b1e1
--- /dev/null
+++ b/Audio/AudioStreamClock.hpp
@@ -0,0 +1,59 @@
+// -*- Mode: C++ -*-
+#ifndef AUDIO_STREAM_CLOCK_HPP__
+#define AUDIO_STREAM_CLOCK_HPP__
+
+#include <QtGlobal>
+
+#include "Audio/AudioStreamDescriptor.hpp"
+
+class AudioStreamClock
+{
+public:
+ enum class Reference
+ {
+ ArrivalWallClock,
+ CaptureAnchor
+ };
+
+ void setDescriptor (AudioStreamDescriptor descriptor) noexcept
+ {
+ descriptor_ = descriptor;
+ captured_frames_ = 0;
+ }
+
+ Reference reference () const noexcept
+ {
+ return descriptor_.isValid ()
+ && descriptor_.clock_domain
+ == AudioStreamDescriptor::ClockDomain::SystemClock
+ && descriptor_.timing_evidence
+ == AudioStreamDescriptor::TimingEvidence::CaptureTimeAnchored
+ && descriptor_.capture_anchor_utc_ms > 0
+ ? Reference::CaptureAnchor : Reference::ArrivalWallClock;
+ }
+
+ qint64 timestamp (qint64 arrival_utc_ms) const noexcept
+ {
+ if (Reference::CaptureAnchor != reference ())
+ {
+ return arrival_utc_ms;
+ }
+
+ return descriptor_.capture_anchor_utc_ms
+ + captured_frames_ * 1000 / descriptor_.sample_rate_hz;
+ }
+
+ void advance (qint64 frames) noexcept
+ {
+ if (Reference::CaptureAnchor == reference () && frames > 0)
+ {
+ captured_frames_ += frames;
+ }
+ }
+
+private:
+ AudioStreamDescriptor descriptor_;
+ qint64 captured_frames_ {0};
+};
+
+#endif