summaryrefslogtreecommitdiff
path: root/Modulator/JttyTxStream.hpp
blob: 1a1d878405fef07fe83531526d11d6fa78860865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef JTTY_TX_STREAM_HPP__
#define JTTY_TX_STREAM_HPP__

#include <atomic>
#include <QPointer>
#include <QTimer>
#include <QVector>

#include "Audio/AudioDevice.hpp"
#include "Audio/TxAudioQueue.hpp"
#include "Audio/TxPlaybackEvidence.hpp"
#include "Audio/TxRequest.hpp"

class SoundOutput;

TxEvidence::TxStartSnapshot makeJttyTxStartSnapshot (
  TxEvidence::TxRequest const& request, qint64 committedEndSample);

//
// JTTY-only asynchronous transmit source.
//
// A QIODevice adapter around the shared JTTY PCM FIFO. readData() only serves
// samples and records drain readiness; drained() is emitted by a timer outside
// the audio pull path.
//
class JttyTxStream
  : public AudioDevice
{
  Q_OBJECT;

public:
  explicit JttyTxStream (TxAudioQueue& queue, QObject * parent = nullptr);

  bool isActive () const {return m_active;}

  Q_SLOT void start (TxEvidence::TxRequest request, SoundOutput * stream);
  Q_SLOT void stop ();

  Q_SIGNAL void drained (TxAudioQueueDrainState drain);
  Q_SIGNAL void txSourceCommitted (TxEvidence::TxStartSnapshot snapshot);

protected:
  qint64 readData (char * data, qint64 maxSize) override;
  qint64 writeData (char const * /* data */, qint64 /* maxSize */) override
  {
    return -1;                  // we don't consume data
  }

private:
  Q_SLOT void pollDrain ();

  TxAudioQueue& m_queue;
  std::atomic<qint64> m_drainGuard;

  QPointer<SoundOutput> m_stream;
  QTimer * m_drainTimer;
  std::atomic<bool> m_active;
};

#endif