2013-08-05 13:41:12 -04:00
|
|
|
#ifndef MODULATOR_HPP__
|
|
|
|
#define MODULATOR_HPP__
|
|
|
|
|
2014-04-06 17:58:11 -04:00
|
|
|
#include <QAudio>
|
2015-07-13 07:00:55 -04:00
|
|
|
#include <QPointer>
|
2014-04-06 17:58:11 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
#include "AudioDevice.hpp"
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-06 17:58:11 -04:00
|
|
|
class SoundOutput;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2014-04-03 15:29:13 -04:00
|
|
|
class Modulator
|
|
|
|
: public AudioDevice
|
2013-08-05 13:41:12 -04:00
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
2013-08-10 11:29:55 -04:00
|
|
|
enum ModulatorState {Synchronizing, Active, Idle};
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent = nullptr);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
void close () override;
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-05 13:41:12 -04:00
|
|
|
bool isTuning () const {return m_tuning;}
|
2015-05-29 15:23:54 -04:00
|
|
|
double frequency () const {return m_frequency;}
|
2013-08-07 19:09:13 -04:00
|
|
|
bool isActive () const {return m_state != Idle;}
|
2014-04-08 07:56:29 -04:00
|
|
|
void setSpread(double s) {m_fSpread=s;}
|
2018-02-12 11:59:31 -05:00
|
|
|
void setTRPeriod(unsigned p) {m_period=p;}
|
2016-07-13 15:17:47 -04:00
|
|
|
void set_nsym(int n) {m_symbolsLength=n;}
|
2019-01-23 10:09:18 -05:00
|
|
|
void set_ms0(qint64 ms) {m_ms0=ms;}
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2015-11-17 20:28:12 -05:00
|
|
|
Q_SLOT void start (unsigned symbolsLength, double framesPerSymbol, double frequency,
|
|
|
|
double toneSpacing, SoundOutput *, Channel = Mono,
|
|
|
|
bool synchronize = true, bool fastMode = false,
|
|
|
|
double dBSNR = 99., int TRperiod=60);
|
2014-04-06 17:58:11 -04:00
|
|
|
Q_SLOT void stop (bool quick = false);
|
|
|
|
Q_SLOT void tune (bool newState = true);
|
2015-05-29 15:23:54 -04:00
|
|
|
Q_SLOT void setFrequency (double newFrequency) {m_frequency = newFrequency;}
|
2014-04-03 15:29:13 -04:00
|
|
|
Q_SIGNAL void stateChanged (ModulatorState) const;
|
|
|
|
|
2013-08-05 13:41:12 -04:00
|
|
|
protected:
|
2016-04-06 18:37:22 -04:00
|
|
|
qint64 readData (char * data, qint64 maxSize) override;
|
|
|
|
qint64 writeData (char const * /* data */, qint64 /* maxSize */) override
|
2013-08-05 13:41:12 -04:00
|
|
|
{
|
|
|
|
return -1; // we don't consume data
|
|
|
|
}
|
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
private:
|
|
|
|
qint16 postProcessSample (qint16 sample) const;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2015-07-13 07:00:55 -04:00
|
|
|
QPointer<SoundOutput> m_stream;
|
2014-04-06 17:58:11 -04:00
|
|
|
bool m_quickClose;
|
2014-04-03 15:29:13 -04:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
unsigned m_symbolsLength;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2016-04-30 20:40:51 -04:00
|
|
|
static double constexpr m_twoPi = 2.0 * 3.141592653589793238462;
|
2016-10-13 12:19:24 -04:00
|
|
|
unsigned m_nspd = 2048 + 512; // CW ID WPM factor = 22.5 WPM
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2014-03-05 13:20:40 -05:00
|
|
|
double m_phi;
|
|
|
|
double m_dphi;
|
|
|
|
double m_amp;
|
2013-08-05 13:41:12 -04:00
|
|
|
double m_nsps;
|
2013-08-07 19:09:13 -04:00
|
|
|
double volatile m_frequency;
|
2014-09-24 13:25:19 -04:00
|
|
|
double m_frequency0;
|
2013-08-05 13:41:12 -04:00
|
|
|
double m_snr;
|
2014-03-05 13:20:40 -05:00
|
|
|
double m_fac;
|
|
|
|
double m_toneSpacing;
|
|
|
|
double m_fSpread;
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
qint64 m_silentFrames;
|
2019-01-23 10:09:18 -05:00
|
|
|
qint64 m_ms0;
|
2015-11-17 20:28:12 -05:00
|
|
|
qint32 m_TRperiod;
|
2015-04-22 13:48:03 -04:00
|
|
|
qint16 m_ramp;
|
2014-03-05 13:20:40 -05:00
|
|
|
|
2014-04-03 15:29:13 -04:00
|
|
|
unsigned m_frameRate;
|
|
|
|
unsigned m_period;
|
2013-08-07 19:09:13 -04:00
|
|
|
ModulatorState volatile m_state;
|
2014-03-05 13:20:40 -05:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
bool volatile m_tuning;
|
2013-08-05 13:41:12 -04:00
|
|
|
bool m_addNoise;
|
2015-11-17 20:28:12 -05:00
|
|
|
bool m_bFastMode;
|
2014-03-05 13:20:40 -05:00
|
|
|
|
2014-04-06 17:58:11 -04:00
|
|
|
bool m_cwLevel;
|
2013-08-05 13:41:12 -04:00
|
|
|
unsigned m_ic;
|
|
|
|
unsigned m_isym0;
|
2016-04-30 20:40:51 -04:00
|
|
|
int m_j0;
|
|
|
|
double m_toneFrequency0;
|
2013-08-05 13:41:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|