Make modemFactories function ref vs. instances which carry other dsp kit stuff

This commit is contained in:
Charles J. Cliffe 2016-07-24 15:25:17 -04:00
parent 8f1b68d20f
commit 0090838070
45 changed files with 96 additions and 79 deletions

View File

@ -190,30 +190,30 @@ bool CubicSDR::OnInit() {
RigThread::enumerate(); RigThread::enumerate();
#endif #endif
Modem::addModemFactory(new ModemFM); Modem::addModemFactory(ModemFM::factory, "FM", 200000);
Modem::addModemFactory(new ModemNBFM); Modem::addModemFactory(ModemNBFM::factory, "NBFM", 12500);
Modem::addModemFactory(new ModemFMStereo); Modem::addModemFactory(ModemFMStereo::factory, "FMS", 200000);
Modem::addModemFactory(new ModemAM); Modem::addModemFactory(ModemAM::factory, "AM", 6000);
Modem::addModemFactory(new ModemLSB); Modem::addModemFactory(ModemLSB::factory, "LSB", 5400);
Modem::addModemFactory(new ModemUSB); Modem::addModemFactory(ModemUSB::factory, "USB", 5400);
Modem::addModemFactory(new ModemDSB); Modem::addModemFactory(ModemDSB::factory, "DSB", 5400);
Modem::addModemFactory(new ModemIQ); Modem::addModemFactory(ModemIQ::factory, "I/Q", 48000);
#ifdef ENABLE_DIGITAL_LAB #ifdef ENABLE_DIGITAL_LAB
Modem::addModemFactory(new ModemAPSK); Modem::addModemFactory(ModemAPSK::factory, "APSK", 200000);
Modem::addModemFactory(new ModemASK); Modem::addModemFactory(ModemASK::factory, "ASK", 200000);
Modem::addModemFactory(new ModemBPSK); Modem::addModemFactory(ModemBPSK::factory, "BPSK", 200000);
Modem::addModemFactory(new ModemDPSK); Modem::addModemFactory(ModemDPSK::factory, "DPSK", 200000);
#if ENABLE_LIQUID_EXPERIMENTAL #if ENABLE_LIQUID_EXPERIMENTAL
Modem::addModemFactory(new ModemFSK); Modem::addModemFactory(ModemFSK::factory, "FSK", 19200);
#endif #endif
Modem::addModemFactory(new ModemGMSK); Modem::addModemFactory(ModemGMSK::factory, "GMSK", 19200);
Modem::addModemFactory(new ModemOOK); Modem::addModemFactory(ModemOOK::factory, "OOK", 200000);
Modem::addModemFactory(new ModemPSK); Modem::addModemFactory(ModemPSK::factory, "PSK", 200000);
Modem::addModemFactory(new ModemQAM); Modem::addModemFactory(ModemQAM::factory, "QAM", 200000);
Modem::addModemFactory(new ModemQPSK); Modem::addModemFactory(ModemQPSK::factory, "QPSK", 200000);
Modem::addModemFactory(new ModemSQAM); Modem::addModemFactory(ModemSQAM::factory, "SQAM", 200000);
Modem::addModemFactory(new ModemST); Modem::addModemFactory(ModemST::factory, "ST", 200000);
#endif #endif
frequency = wxGetApp().getConfig()->getCenterFreq(); frequency = wxGetApp().getConfig()->getCenterFreq();

View File

@ -128,6 +128,13 @@ void DemodulatorInstance::updateLabel(long long freq) {
} }
void DemodulatorInstance::terminate() { void DemodulatorInstance::terminate() {
#if ENABLE_DIGITAL_LAB
if (activeOutput) {
closeOutput();
}
#endif
// std::cout << "Terminating demodulator audio thread.." << std::endl; // std::cout << "Terminating demodulator audio thread.." << std::endl;
audioThread->terminate(); audioThread->terminate();
// std::cout << "Terminating demodulator thread.." << std::endl; // std::cout << "Terminating demodulator thread.." << std::endl;
@ -156,7 +163,6 @@ bool DemodulatorInstance::isTerminated() {
if (audioTerminated) { if (audioTerminated) {
if (t_Audio) { if (t_Audio) {
t_Audio->join(); t_Audio->join();
delete t_Audio; delete t_Audio;
@ -175,11 +181,6 @@ bool DemodulatorInstance::isTerminated() {
#endif #endif
t_Demod = nullptr; t_Demod = nullptr;
} }
#if ENABLE_DIGITAL_LAB
if (activeOutput) {
closeOutput();
}
#endif
} }
if (preDemodTerminated) { if (preDemodTerminated) {
@ -314,7 +315,14 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
if (lastbw) { if (lastbw) {
setBandwidth(lastbw); setBandwidth(lastbw);
} }
}
#if ENABLE_DIGITAL_LAB
if (isModemInitialized() && getModemType() == "digital") {
ModemDigitalOutputConsole *outp = (ModemDigitalOutputConsole *)getOutput();
outp->setTitle(getDemodulatorType() + ": " + frequencyToStr(getFrequency()));
}
#endif
}
} }
std::string DemodulatorInstance::getDemodulatorType() { std::string DemodulatorInstance::getDemodulatorType() {

View File

@ -136,6 +136,7 @@ void DemodulatorThread::run() {
ati->sampleRate = cModemKit->sampleRate; ati->sampleRate = cModemKit->sampleRate;
ati->inputRate = inp->sampleRate; ati->inputRate = inp->sampleRate;
ati->data.resize(0);
} }
cModem->demodulate(cModemKit, &modemData, ati); cModem->demodulate(cModemKit, &modemData, ati);
@ -160,7 +161,7 @@ void DemodulatorThread::run() {
} }
} }
if (audioOutputQueue != nullptr && ati && !squelched) { if (audioOutputQueue != nullptr && ati && ati->data.size() && !squelched) {
std::vector<float>::iterator data_i; std::vector<float>::iterator data_i;
ati->peak = 0; ati->peak = 0;
for (data_i = ati->data.begin(); data_i != ati->data.end(); data_i++) { for (data_i = ati->data.begin(); data_i != ati->data.end(); data_i++) {

View File

@ -3,6 +3,7 @@
ModemFactoryList Modem::modemFactories; ModemFactoryList Modem::modemFactories;
DefaultRatesList Modem::modemDefaultRates;
//! Create an empty range (0.0, 0.0) //! Create an empty range (0.0, 0.0)
ModemRange::ModemRange(void) { ModemRange::ModemRange(void) {
@ -38,8 +39,9 @@ Modem::~Modem() {
} }
void Modem::addModemFactory(Modem *factorySingle) { void Modem::addModemFactory(ModemFactoryFn factoryFunc, std::string modemName, int defaultRate) {
modemFactories[factorySingle->getName()] = factorySingle; modemFactories[modemName] = factoryFunc;
modemDefaultRates[modemName] = defaultRate;
} }
ModemFactoryList Modem::getFactories() { ModemFactoryList Modem::getFactories() {
@ -48,15 +50,15 @@ ModemFactoryList Modem::getFactories() {
Modem *Modem::makeModem(std::string modemName) { Modem *Modem::makeModem(std::string modemName) {
if (modemFactories.find(modemName) != modemFactories.end()) { if (modemFactories.find(modemName) != modemFactories.end()) {
return modemFactories[modemName]->factory(); return (Modem *)modemFactories[modemName]();
} }
return nullptr; return nullptr;
} }
int Modem::getModemDefaultSampleRate(std::string modemName) { int Modem::getModemDefaultSampleRate(std::string modemName) {
if (modemFactories.find(modemName) != modemFactories.end()) { if (modemDefaultRates.find(modemName) != modemDefaultRates.end()) {
return modemFactories[modemName]->getDefaultSampleRate(); return modemDefaultRates[modemName];
} }
return 0; return 0;

View File

@ -108,14 +108,21 @@ public:
typedef std::vector<ModemArgInfo> ModemArgInfoList; typedef std::vector<ModemArgInfo> ModemArgInfoList;
class Modem; class ModemBase {
typedef std::map<std::string,Modem *> ModemFactoryList;
};
typedef ModemBase *(*ModemFactoryFn)();
typedef std::map<std::string, ModemFactoryFn> ModemFactoryList;
typedef std::map<std::string, int> DefaultRatesList;
typedef std::map<std::string, std::string> ModemSettings; typedef std::map<std::string, std::string> ModemSettings;
class Modem { class Modem : public ModemBase {
public: public:
static void addModemFactory(Modem *factorySingle); static void addModemFactory(ModemFactoryFn, std::string modemName, int defaultRate);
static ModemFactoryList getFactories(); static ModemFactoryList getFactories();
static Modem *makeModem(std::string modemName); static Modem *makeModem(std::string modemName);
@ -124,8 +131,6 @@ public:
virtual std::string getType() = 0; virtual std::string getType() = 0;
virtual std::string getName() = 0; virtual std::string getName() = 0;
virtual Modem *factory() = 0;
Modem(); Modem();
virtual ~Modem(); virtual ~Modem();
@ -149,5 +154,6 @@ public:
private: private:
static ModemFactoryList modemFactories; static ModemFactoryList modemFactories;
static DefaultRatesList modemDefaultRates;
std::atomic_bool refreshKit; std::atomic_bool refreshKit;
}; };

View File

@ -8,7 +8,7 @@ ModemAM::~ModemAM() {
ampmodem_destroy(demodAM); ampmodem_destroy(demodAM);
} }
Modem *ModemAM::factory() { ModemBase *ModemAM::factory() {
return new ModemAM; return new ModemAM;
} }

View File

@ -9,7 +9,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -8,7 +8,7 @@ ModemDSB::~ModemDSB() {
ampmodem_destroy(demodAM_DSB); ampmodem_destroy(demodAM_DSB);
} }
Modem *ModemDSB::factory() { ModemBase *ModemDSB::factory() {
return new ModemDSB; return new ModemDSB;
} }

View File

@ -9,7 +9,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -8,7 +8,7 @@ ModemFM::~ModemFM() {
freqdem_destroy(demodFM); freqdem_destroy(demodFM);
} }
Modem *ModemFM::factory() { ModemBase *ModemFM::factory() {
return new ModemFM; return new ModemFM;
} }

View File

@ -9,7 +9,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -16,7 +16,7 @@ std::string ModemFMStereo::getName() {
return "FMS"; return "FMS";
} }
Modem *ModemFMStereo::factory() { ModemBase *ModemFMStereo::factory() {
return new ModemFMStereo; return new ModemFMStereo;
} }

View File

@ -29,7 +29,7 @@ public:
std::string getType(); std::string getType();
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -12,7 +12,7 @@ std::string ModemIQ::getName() {
return "I/Q"; return "I/Q";
} }
Modem *ModemIQ::factory() { ModemBase *ModemIQ::factory() {
return new ModemIQ; return new ModemIQ;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getType(); std::string getType();
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -13,7 +13,7 @@ ModemLSB::ModemLSB() : ModemAnalog() {
c2rFilt = firhilbf_create(5, 90.0); c2rFilt = firhilbf_create(5, 90.0);
} }
Modem *ModemLSB::factory() { ModemBase *ModemLSB::factory() {
return new ModemLSB; return new ModemLSB;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -8,7 +8,7 @@ ModemNBFM::~ModemNBFM() {
freqdem_destroy(demodFM); freqdem_destroy(demodFM);
} }
Modem *ModemNBFM::factory() { ModemBase *ModemNBFM::factory() {
return new ModemNBFM; return new ModemNBFM;
} }

View File

@ -9,7 +9,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -13,7 +13,7 @@ ModemUSB::ModemUSB() : ModemAnalog() {
c2rFilt = firhilbf_create(5, 90.0); c2rFilt = firhilbf_create(5, 90.0);
} }
Modem *ModemUSB::factory() { ModemBase *ModemUSB::factory() {
return new ModemUSB; return new ModemUSB;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -12,7 +12,7 @@ ModemAPSK::ModemAPSK() : ModemDigital() {
cons = 4; cons = 4;
} }
Modem *ModemAPSK::factory() { ModemBase *ModemAPSK::factory() {
return new ModemAPSK; return new ModemAPSK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -13,7 +13,7 @@ ModemASK::ModemASK() : ModemDigital() {
cons = 2; cons = 2;
} }
Modem *ModemASK::factory() { ModemBase *ModemASK::factory() {
return new ModemASK; return new ModemASK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -4,7 +4,7 @@ ModemBPSK::ModemBPSK() : ModemDigital() {
demodBPSK = modem_create(LIQUID_MODEM_BPSK); demodBPSK = modem_create(LIQUID_MODEM_BPSK);
} }
Modem *ModemBPSK::factory() { ModemBase *ModemBPSK::factory() {
return new ModemBPSK; return new ModemBPSK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut);

View File

@ -13,7 +13,7 @@ ModemDPSK::ModemDPSK() : ModemDigital() {
cons = 2; cons = 2;
} }
Modem *ModemDPSK::factory() { ModemBase *ModemDPSK::factory() {
return new ModemDPSK; return new ModemDPSK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -9,7 +9,7 @@ ModemFSK::ModemFSK() : ModemDigital() {
outStream << std::hex; outStream << std::hex;
} }
Modem *ModemFSK::factory() { ModemBase *ModemFSK::factory() {
return new ModemFSK; return new ModemFSK;
} }

View File

@ -19,7 +19,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -16,7 +16,7 @@ std::string ModemGMSK::getName() {
return "GMSK"; return "GMSK";
} }
Modem *ModemGMSK::factory() { ModemBase *ModemGMSK::factory() {
return new ModemGMSK; return new ModemGMSK;
} }

View File

@ -19,7 +19,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);
int getDefaultSampleRate(); int getDefaultSampleRate();

View File

@ -12,7 +12,7 @@ std::string ModemOOK::getName() {
return "OOK"; return "OOK";
} }
Modem *ModemOOK::factory() { ModemBase *ModemOOK::factory() {
return new ModemOOK; return new ModemOOK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
int checkSampleRate(long long sampleRate, int audioSampleRate); int checkSampleRate(long long sampleRate, int audioSampleRate);

View File

@ -13,7 +13,7 @@ ModemPSK::ModemPSK() : ModemDigital() {
cons = 2; cons = 2;
} }
Modem *ModemPSK::factory() { ModemBase *ModemPSK::factory() {
return new ModemPSK; return new ModemPSK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -12,7 +12,7 @@ ModemQAM::ModemQAM() : ModemDigital() {
cons = 4; cons = 4;
} }
Modem *ModemQAM::factory() { ModemBase *ModemQAM::factory() {
return new ModemQAM; return new ModemQAM;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -4,7 +4,7 @@ ModemQPSK::ModemQPSK() : ModemDigital() {
demodQPSK = modem_create(LIQUID_MODEM_QPSK); demodQPSK = modem_create(LIQUID_MODEM_QPSK);
} }
Modem *ModemQPSK::factory() { ModemBase *ModemQPSK::factory() {
return new ModemQPSK; return new ModemQPSK;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut);

View File

@ -7,7 +7,7 @@ ModemSQAM::ModemSQAM() : ModemDigital() {
cons = 32; cons = 32;
} }
Modem *ModemSQAM::factory() { ModemBase *ModemSQAM::factory() {
return new ModemSQAM; return new ModemSQAM;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
ModemArgInfoList getSettings(); ModemArgInfoList getSettings();
void writeSetting(std::string setting, std::string value); void writeSetting(std::string setting, std::string value);

View File

@ -4,7 +4,7 @@ ModemST::ModemST() : ModemDigital() {
demodST = modem_create(LIQUID_MODEM_V29); demodST = modem_create(LIQUID_MODEM_V29);
} }
Modem *ModemST::factory() { ModemBase *ModemST::factory() {
return new ModemST; return new ModemST;
} }

View File

@ -8,7 +8,7 @@ public:
std::string getName(); std::string getName();
Modem *factory(); static ModemBase *factory();
void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut);