summaryrefslogtreecommitdiff
path: root/Modulator.hpp
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
commitd63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch)
treeb9c1f6245147a310aac3762630bad389bbb57335 /Modulator.hpp
parentc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff)
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'Modulator.hpp')
-rw-r--r--Modulator.hpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/Modulator.hpp b/Modulator.hpp
new file mode 100644
index 00000000..80c900c0
--- /dev/null
+++ b/Modulator.hpp
@@ -0,0 +1,84 @@
+#ifndef MODULATOR_HPP__
+#define MODULATOR_HPP__
+
+#include <QAudio>
+
+#include "AudioDevice.hpp"
+
+class SoundOutput;
+
+//
+// Input device that generates PCM audio frames that encode a message
+// and an optional CW ID.
+//
+// Output can be muted while underway, preserving waveform timing when
+// transmission is resumed.
+//
+class Modulator
+ : public AudioDevice
+{
+ Q_OBJECT;
+
+public:
+ enum ModulatorState {Synchronizing, Active, Idle};
+
+ Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent = nullptr);
+
+ void close () override;
+
+ bool isTuning () const {return m_tuning;}
+ unsigned frequency () const {return m_frequency;}
+ bool isActive () const {return m_state != Idle;}
+ void setSpread(double s) {m_fSpread=s;}
+
+ Q_SLOT void start (unsigned symbolsLength, double framesPerSymbol, unsigned frequency, double toneSpacing, SoundOutput *, Channel = Mono, bool synchronize = true, double dBSNR = 99.);
+ Q_SLOT void stop (bool quick = false);
+ Q_SLOT void tune (bool newState = true);
+ Q_SLOT void setFrequency (unsigned newFrequency) {m_frequency = newFrequency;}
+ Q_SIGNAL void stateChanged (ModulatorState) const;
+
+protected:
+ qint64 readData (char * data, qint64 maxSize);
+ qint64 writeData (char const * /* data */, qint64 /* maxSize */)
+ {
+ return -1; // we don't consume data
+ }
+
+private:
+ qint16 postProcessSample (qint16 sample) const;
+
+ SoundOutput * m_stream;
+ bool m_quickClose;
+
+ unsigned m_symbolsLength;
+
+ static double const m_twoPi;
+ static unsigned const m_nspd; // CW ID WPM factor
+
+ double m_phi;
+ double m_dphi;
+ double m_amp;
+ double m_nsps;
+ double volatile m_frequency;
+ double m_frequency0;
+ double m_snr;
+ double m_fac;
+ double m_toneSpacing;
+ double m_fSpread;
+
+ qint64 m_silentFrames;
+
+ unsigned m_frameRate;
+ unsigned m_period;
+ ModulatorState volatile m_state;
+
+ bool volatile m_tuning;
+ bool m_addNoise;
+
+ bool m_cwLevel;
+ unsigned m_ic;
+ unsigned m_isym0;
+ qint16 m_ramp;
+};
+
+#endif