2013-08-05 13:41:12 -04:00
|
|
|
#ifndef MODULATOR_HPP__
|
|
|
|
#define MODULATOR_HPP__
|
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
#include "AudioDevice.hpp"
|
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.
|
|
|
|
//
|
2013-08-10 11:29:55 -04:00
|
|
|
class Modulator : public AudioDevice
|
2013-08-05 13:41:12 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
public:
|
2013-08-10 11:29:55 -04:00
|
|
|
enum ModulatorState {Synchronizing, Active, Idle};
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent = 0);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_SLOT void open (unsigned symbolsLength, double framesPerSymbol, unsigned frequency, AudioDevice::Channel, bool synchronize = true, double dBSNR = 99.);
|
2013-08-07 19:09:13 -04:00
|
|
|
|
2013-08-05 13:41:12 -04:00
|
|
|
bool isTuning () const {return m_tuning;}
|
|
|
|
bool isMuted () const {return m_muted;}
|
|
|
|
unsigned frequency () const {return m_frequency;}
|
2013-08-07 19:09:13 -04:00
|
|
|
bool isActive () const {return m_state != Idle;}
|
2014-03-05 13:20:40 -05:00
|
|
|
void setWide9(double d1, double d2) {m_toneSpacing=d1; m_fSpread=d2;}
|
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-10 11:29:55 -04:00
|
|
|
/* private because we epect to run in a thread and don't want direct
|
|
|
|
C++ calls made, instead they must be invoked via the Qt
|
|
|
|
signal/slot mechanism which is thread safe */
|
|
|
|
Q_SLOT void close ()
|
2013-08-07 19:09:13 -04:00
|
|
|
{
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_EMIT stateChanged ((m_state = Idle));
|
|
|
|
AudioDevice::close ();
|
|
|
|
}
|
2013-08-05 13:41:12 -04:00
|
|
|
|
2013-08-10 11:29:55 -04:00
|
|
|
Q_SLOT void tune (bool newState = true) {m_tuning = newState;}
|
|
|
|
Q_SLOT void mute (bool newState = true) {m_muted = newState;}
|
|
|
|
Q_SLOT void setFrequency (unsigned newFrequency) {m_frequency = newFrequency;}
|
|
|
|
Q_SIGNAL void stateChanged (ModulatorState);
|
|
|
|
|
|
|
|
private:
|
|
|
|
qint16 postProcessSample (qint16 sample) const;
|
2013-08-05 13:41:12 -04:00
|
|
|
|
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
|
|
|
|
|
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;
|
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;
|
|
|
|
qint64 m_framesSent;
|
2014-03-05 13:20:40 -05:00
|
|
|
|
|
|
|
int m_frameRate;
|
|
|
|
int 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;
|
|
|
|
bool volatile m_muted;
|
2013-08-05 13:41:12 -04:00
|
|
|
bool m_addNoise;
|
2014-03-05 13:20:40 -05:00
|
|
|
|
2013-08-05 13:41:12 -04:00
|
|
|
unsigned m_ic;
|
|
|
|
unsigned m_isym0;
|
2013-08-10 11:29:55 -04:00
|
|
|
qint16 m_ramp;
|
2013-08-05 13:41:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|