Files
WSJT-X/Modulator/Modulator.hpp
T

97 lines
2.3 KiB
C++
Raw Normal View History

2013-08-05 17:41:12 +00:00
#ifndef MODULATOR_HPP__
#define MODULATOR_HPP__
#include <QAudio>
#include <QPointer>
2019-07-02 12:45:05 -05:00
#include "Audio/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, double 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;}
double 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;}
void setTRPeriod(double p) {m_period=p;}
void set_nsym(int n) {m_symbolsLength=n;}
void set_ms0(qint64 ms) {m_ms0=ms;}
2013-08-05 17:41:12 +00:00
2020-06-29 14:47:46 -04:00
Q_SLOT void start (QString mode, unsigned symbolsLength, double framesPerSymbol, double frequency,
2015-11-18 01:28:12 +00:00
double toneSpacing, SoundOutput *, Channel = Mono,
bool synchronize = true, bool fastMode = false,
double dBSNR = 99., double TRperiod=60.0);
Q_SLOT void stop (bool quick = false);
Q_SLOT void tune (bool newState = true);
Q_SLOT void setFrequency (double newFrequency) {m_frequency = newFrequency;}
Q_SIGNAL void stateChanged (ModulatorState) const;
2013-08-05 17:41:12 +00:00
protected:
2016-04-06 22:37:22 +00:00
qint64 readData (char * data, qint64 maxSize) override;
qint64 writeData (char const * /* data */, qint64 /* maxSize */) override
2013-08-05 17:41:12 +00:00
{
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
QPointer<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 constexpr m_twoPi = 2.0 * 3.141592653589793238462;
2016-10-13 16:19:24 +00:00
unsigned m_nspd = 2048 + 512; // CW ID WPM factor = 22.5 WPM
2013-08-05 17:41:12 +00:00
double m_phi;
double m_dphi;
double m_amp;
2013-08-05 17:41:12 +00:00
double m_nsps;
double 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;
double m_TRperiod;
double m_period;
2013-08-07 23:09:13 +00:00
qint64 m_silentFrames;
qint64 m_ms0;
qint16 m_ramp;
unsigned m_frameRate;
ModulatorState m_state;
bool m_tuning;
2013-08-05 17:41:12 +00:00
bool m_addNoise;
2015-11-18 01:28:12 +00:00
bool m_bFastMode;
bool m_cwLevel;
2013-08-05 17:41:12 +00:00
unsigned m_ic;
unsigned m_isym0;
int m_j0;
double m_toneFrequency0;
2013-08-05 17:41:12 +00:00
};
#endif