Files
WSJT-X/Modulator.hpp
T

85 lines
1.9 KiB
C++
Raw Normal View History

2013-08-05 17:41:12 +00:00
#ifndef MODULATOR_HPP__
#define MODULATOR_HPP__
#include <QAudio>
2013-08-10 15:29:55 +00:00
#include "AudioDevice.hpp"
2013-08-07 23:09:13 +00:00
class SoundOutput;
2013-08-05 17:41:12 +00: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 AudioDevice
2013-08-05 17:41:12 +00:00
{
Q_OBJECT;
public:
2013-08-10 15:29:55 +00:00
enum ModulatorState {Synchronizing, Active, Idle};
2013-08-07 23:09:13 +00:00
Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent = nullptr);
2013-08-07 23:09:13 +00:00
void close () override;
2013-08-07 23:09:13 +00:00
2013-08-05 17:41:12 +00:00
bool isTuning () const {return m_tuning;}
unsigned frequency () const {return m_frequency;}
2013-08-07 23:09:13 +00:00
bool isActive () const {return m_state != Idle;}
void setSpread(double s) {m_fSpread=s;}
2013-08-05 17:41:12 +00:00
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;
2013-08-05 17:41:12 +00:00
protected:
qint64 readData (char * data, qint64 maxSize);
qint64 writeData (char const * /* data */, qint64 /* maxSize */)
{
return -1; // we don't consume data
}
2013-08-10 15:29:55 +00:00
private:
qint16 postProcessSample (qint16 sample) const;
2013-08-05 17:41:12 +00:00
SoundOutput * m_stream;
bool m_quickClose;
2013-08-07 23:09:13 +00:00
unsigned m_symbolsLength;
2013-08-05 17:41:12 +00:00
static double const m_twoPi;
static unsigned const m_nspd; // CW ID WPM factor
double m_phi;
double m_dphi;
double m_amp;
2013-08-05 17:41:12 +00:00
double m_nsps;
2013-08-07 23:09:13 +00:00
double volatile m_frequency;
double m_frequency0;
2013-08-05 17:41:12 +00:00
double m_snr;
double m_fac;
double m_toneSpacing;
double m_fSpread;
2013-08-07 23:09:13 +00:00
qint64 m_silentFrames;
unsigned m_frameRate;
unsigned m_period;
2013-08-07 23:09:13 +00:00
ModulatorState volatile m_state;
2013-08-07 23:09:13 +00:00
bool volatile m_tuning;
2013-08-05 17:41:12 +00:00
bool m_addNoise;
bool m_cwLevel;
2013-08-05 17:41:12 +00:00
unsigned m_ic;
unsigned m_isym0;
2013-08-10 15:29:55 +00:00
qint16 m_ramp;
2013-08-05 17:41:12 +00:00
};
#endif