2013-08-05 13:41:12 -04:00
|
|
|
#ifndef MODULATOR_HPP__
|
|
|
|
#define MODULATOR_HPP__
|
|
|
|
|
|
|
|
#include <QIODevice>
|
2013-08-07 19:09:13 -04:00
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
# define NUM_CHANNELS 2
|
|
|
|
#else
|
|
|
|
# define NUM_CHANNELS 1
|
|
|
|
#endif
|
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.
|
|
|
|
//
|
|
|
|
class Modulator : public QIODevice
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
Q_PROPERTY (unsigned frequency READ frequency WRITE setFrequency);
|
|
|
|
Q_PROPERTY (bool tuning READ isTuning WRITE tune);
|
|
|
|
Q_PROPERTY (bool muted READ isMuted WRITE mute);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Q_DISABLE_COPY (Modulator);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent = 0);
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
bool open () {return QIODevice::open (QIODevice::ReadOnly | QIODevice::Unbuffered);}
|
|
|
|
|
|
|
|
Q_SLOT void send (unsigned symbolsLength, double framesPerSymbol, unsigned frequency, bool synchronize = true, double dBSNR = 99.);
|
|
|
|
|
|
|
|
Q_SLOT void stop () {Q_EMIT stateChanged ((m_state = Idle));}
|
|
|
|
|
2013-08-05 13:41:12 -04:00
|
|
|
bool isTuning () const {return m_tuning;}
|
|
|
|
Q_SLOT void tune (bool newState = true) {m_tuning = newState;}
|
|
|
|
|
|
|
|
bool isMuted () const {return m_muted;}
|
|
|
|
Q_SLOT void mute (bool newState = true) {m_muted = newState;}
|
|
|
|
|
|
|
|
unsigned frequency () const {return m_frequency;}
|
|
|
|
Q_SLOT void setFrequency (unsigned newFrequency) {m_frequency = newFrequency;}
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
enum ModulatorState {Synchronizing, Active, Idle};
|
|
|
|
Q_SIGNAL void stateChanged (ModulatorState);
|
|
|
|
bool isActive () const {return m_state != Idle;}
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
bool isSequential () const {return true;}
|
2013-08-05 13:41:12 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
qint64 readData (char * data, qint64 maxSize);
|
|
|
|
qint64 writeData (char const * /* data */, qint64 /* maxSize */)
|
|
|
|
{
|
|
|
|
return -1; // we don't consume data
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-08-07 19:09:13 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
qint16 channel[NUM_CHANNELS];
|
|
|
|
} frame_t;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
|
|
|
frame_t postProcessFrame (frame_t frame) const;
|
|
|
|
|
2013-08-07 19:09:13 -04:00
|
|
|
unsigned m_symbolsLength;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
|
|
|
static double const m_twoPi;
|
|
|
|
static unsigned const m_nspd; // CW ID WPM factor
|
|
|
|
|
|
|
|
int m_frameRate;
|
|
|
|
int m_period;
|
|
|
|
double m_nsps;
|
2013-08-07 19:09:13 -04:00
|
|
|
double volatile m_frequency;
|
2013-08-05 13:41:12 -04:00
|
|
|
double m_snr;
|
2013-08-07 19:09:13 -04:00
|
|
|
qint64 m_silentFrames;
|
|
|
|
qint64 m_framesSent;
|
|
|
|
ModulatorState volatile m_state;
|
|
|
|
bool volatile m_tuning;
|
|
|
|
bool volatile m_muted;
|
2013-08-05 13:41:12 -04:00
|
|
|
bool m_addNoise;
|
|
|
|
double m_phi;
|
|
|
|
double m_dphi;
|
|
|
|
double m_amp;
|
|
|
|
unsigned m_ic;
|
|
|
|
double m_fac;
|
|
|
|
unsigned m_isym0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|