diff options
| author | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
| commit | c25cbdf6fb6d946175f4335fab77bfea601b56db (patch) | |
| tree | 6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /Audio/TxAudioQueue.hpp | |
| parent | 71f5689252c9f13e70e1c24856904475b2307809 (diff) | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (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/TxAudioQueue.hpp')
| -rw-r--r-- | Audio/TxAudioQueue.hpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Audio/TxAudioQueue.hpp b/Audio/TxAudioQueue.hpp new file mode 100644 index 00000000..8e1a4710 --- /dev/null +++ b/Audio/TxAudioQueue.hpp @@ -0,0 +1,93 @@ +#ifndef TX_AUDIO_QUEUE_HPP_ +#define TX_AUDIO_QUEUE_HPP_ + +#include <memory> + +#include <QMetaType> +#include <QVector> +#include <QtGlobal> + +struct TxAudioQueueEpoch +{ + constexpr TxAudioQueueEpoch () noexcept : value_ {0} {} + explicit constexpr TxAudioQueueEpoch (qint64 value) noexcept : value_ {value} {} + + static constexpr TxAudioQueueEpoch invalid () noexcept {return TxAudioQueueEpoch {};} + constexpr bool isValid () const noexcept {return value_ > 0;} + constexpr qint64 value () const noexcept {return value_;} + +private: + qint64 value_; +}; + +inline constexpr bool operator == (TxAudioQueueEpoch lhs, + TxAudioQueueEpoch rhs) noexcept +{ + return lhs.value () == rhs.value (); +} + +inline constexpr bool operator != (TxAudioQueueEpoch lhs, + TxAudioQueueEpoch rhs) noexcept +{ + return !(lhs == rhs); +} + +struct TxAudioQueueProgress +{ + TxAudioQueueEpoch epoch {}; + qint64 queued_samples {0}; + qint64 served_samples {0}; + qint64 total_samples {0}; +}; + +struct TxAudioQueueDrainState +{ + bool ready {false}; + TxAudioQueueEpoch epoch {}; + qint64 total_at_drain {0}; +}; + +struct TxAudioQueueEnqueueResult +{ + bool accepted {false}; + TxAudioQueueProgress progress {}; +}; + +class TxAudioQueue +{ +public: + // One serialized producer owns clear/enqueue; one consumer owns reset/pull/drain. + static constexpr qint64 defaultCapacity () noexcept {return 60 * 48000;} + + TxAudioQueue (); + explicit TxAudioQueue (qint64 capacity_samples); + ~TxAudioQueue (); + + TxAudioQueue (TxAudioQueue const&) = delete; + TxAudioQueue& operator = (TxAudioQueue const&) = delete; + + TxAudioQueueEnqueueResult enqueue (QVector<qint16> const& samples, + TxAudioQueueEpoch epoch); + TxAudioQueueEnqueueResult enqueue (qint16 const * samples, qint64 count, + TxAudioQueueEpoch epoch); + void clear (TxAudioQueueEpoch epoch); + void applyPendingReset () noexcept; + + qint16 pullSample (qint64 drain_guard) noexcept; + TxAudioQueueDrainState takeDrainReady () noexcept; + + // A concurrent clear may produce progress with an invalid epoch. + TxAudioQueueProgress progress () const noexcept; + qint64 capacity () const noexcept; + +private: + class Impl; + std::unique_ptr<Impl> impl_; +}; + +Q_DECLARE_METATYPE (TxAudioQueueEpoch) +Q_DECLARE_METATYPE (TxAudioQueueProgress) +Q_DECLARE_METATYPE (TxAudioQueueDrainState) +Q_DECLARE_METATYPE (TxAudioQueueEnqueueResult) + +#endif |
