JS8Call-Improved master
Loading...
Searching...
No Matches
Modulator.h
1#ifndef MODULATOR_HPP__
2#define MODULATOR_HPP__
3
4#include "JS8_Audio/AudioDevice.h"
5
6#include <QAudio>
7#include <QPointer>
8
9class SoundOutput;
10
20class Modulator final : public AudioDevice {
21 Q_OBJECT;
22
23 public:
24 enum class State { Synchronizing, Active, Idle };
25
26 // Constructor
27
28 explicit Modulator(QObject *parent = nullptr) : AudioDevice{parent} {}
29
30 // Inline accessors
31
37 bool isIdle() const { return m_state.load() == State::Idle; }
38
39 // Manipulators
40
41 void close() override;
42
49 Q_SLOT void setAudioFrequency(double const audioFrequency) {
50 m_audioFrequency = audioFrequency;
51 }
52
53 // Slots
54
55 Q_SLOT void start(double audioFrequency, int submode, double tx_delay,
56 SoundOutput *stream, Channel channel);
57 Q_SLOT void stop(bool quick = false);
58 Q_SLOT void tune(bool state = true);
59
60 protected:
61 // QIODevice protocol
62
63 qint64 readData(char *, qint64) override;
64 qint64 writeData(char const *, qint64) override {
65 return -1; // we don't consume data
66 }
67
68 // In current Qt versions, bytesAvailable() must return a size
69 // that exceeds some threshold in order for the AudioSink to go
70 // into Active state and start pulling data. This behavior began
71 // on Windows with the 6.4 release, on Mac with 6.8, and on Linux
72 // with 6.9.
73 //
74 // See: https://bugreports.qt.io/browse/QTBUG-108672
75
76 qint64 bytesAvailable() const override { return 8000; }
77
78 private:
79 // Data members
80
81 QPointer<SoundOutput> m_stream;
82 std::atomic<State> m_state = State::Idle;
83 bool m_quickClose = false;
84 bool m_tuning = false;
85 double m_audioFrequency;
86 double m_audioFrequency0;
87 double m_toneSpacing;
88 double m_phi;
89 double m_dphi;
90 double m_amp;
91 double m_nsps;
92 qint64 m_silentFrames;
93 unsigned m_ic;
94 unsigned m_isym0;
95};
96
97#endif
qint64 readData(char *, qint64) override
Read data from the modulator.
Definition Modulator.cpp:178
Q_SLOT void tune(bool state=true)
Set tuning mode.
Definition Modulator.cpp:139
Q_SLOT void start(double audioFrequency, int submode, double tx_delay, SoundOutput *stream, Channel channel)
Start the modulation process.
Definition Modulator.cpp:38
Q_SLOT void setAudioFrequency(double const audioFrequency)
Definition Modulator.h:49
void close() override
Close the modulator.
Definition Modulator.cpp:159
bool isIdle() const
Definition Modulator.h:37
Q_SLOT void stop(bool quick=false)
Stop the modulation process.
Definition Modulator.cpp:150
Definition SoundOutput.h:13