1 #ifndef MODULATOR_HPP__ 2 #define MODULATOR_HPP__ 3 4 #include <QAudio> 5 #include <QPointer> 6 7 #include "Audio/AudioDevice.hpp" 8 9 class SoundOutput; 10 11 // 12 // Input device that generates PCM audio frames that encode a message 13 // and an optional CW ID. 14 // 15 // Output can be muted while underway, preserving waveform timing when 16 // transmission is resumed. 17 // 18 class Modulator 19 : public AudioDevice 20 { 21 Q_OBJECT; 22 23 public: 24 enum ModulatorState {Synchronizing, Active, Idle}; 25 26 Modulator (unsigned frameRate, double periodLengthInSeconds, QObject * parent = nullptr); 27 28 void close () override; 29 isTuning() const30 bool isTuning () const {return m_tuning;} frequency() const31 double frequency () const {return m_frequency;} isActive() const32 bool isActive () const {return m_state != Idle;} setSpread(double s)33 void setSpread(double s) {m_fSpread=s;} setTRPeriod(double p)34 void setTRPeriod(double p) {m_period=p;} set_nsym(int n)35 void set_nsym(int n) {m_symbolsLength=n;} set_ms0(qint64 ms)36 void set_ms0(qint64 ms) {m_ms0=ms;} 37 38 Q_SLOT void start (QString mode, unsigned symbolsLength, double framesPerSymbol, double frequency, 39 double toneSpacing, SoundOutput *, Channel = Mono, 40 bool synchronize = true, bool fastMode = false, 41 double dBSNR = 99., double TRperiod=60.0); 42 Q_SLOT void stop (bool quick = false); 43 Q_SLOT void tune (bool newState = true); setFrequency(double newFrequency)44 Q_SLOT void setFrequency (double newFrequency) {m_frequency = newFrequency;} 45 Q_SIGNAL void stateChanged (ModulatorState) const; 46 47 protected: 48 qint64 readData (char * data, qint64 maxSize) override; writeData(char const *,qint64)49 qint64 writeData (char const * /* data */, qint64 /* maxSize */) override 50 { 51 return -1; // we don't consume data 52 } 53 54 private: 55 qint16 postProcessSample (qint16 sample) const; 56 57 QPointer<SoundOutput> m_stream; 58 bool m_quickClose; 59 60 unsigned m_symbolsLength; 61 62 static double constexpr m_twoPi = 2.0 * 3.141592653589793238462; 63 unsigned m_nspd = 2048 + 512; // CW ID WPM factor = 22.5 WPM 64 65 double m_phi; 66 double m_dphi; 67 double m_amp; 68 double m_nsps; 69 double m_frequency; 70 double m_frequency0; 71 double m_snr; 72 double m_fac; 73 double m_toneSpacing; 74 double m_fSpread; 75 double m_TRperiod; 76 double m_period; 77 78 qint64 m_silentFrames; 79 qint64 m_ms0; 80 qint16 m_ramp; 81 82 unsigned m_frameRate; 83 ModulatorState m_state; 84 85 bool m_tuning; 86 bool m_addNoise; 87 bool m_bFastMode; 88 89 bool m_cwLevel; 90 unsigned m_ic; 91 unsigned m_isym0; 92 int m_j0; 93 double m_toneFrequency0; 94 }; 95 96 #endif 97