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

View File

@ -128,6 +128,13 @@ void DemodulatorInstance::updateLabel(long long freq) {
}
void DemodulatorInstance::terminate() {
#if ENABLE_DIGITAL_LAB
if (activeOutput) {
closeOutput();
}
#endif
// std::cout << "Terminating demodulator audio thread.." << std::endl;
audioThread->terminate();
// std::cout << "Terminating demodulator thread.." << std::endl;
@ -156,7 +163,6 @@ bool DemodulatorInstance::isTerminated() {
if (audioTerminated) {
if (t_Audio) {
t_Audio->join();
delete t_Audio;
@ -175,11 +181,6 @@ bool DemodulatorInstance::isTerminated() {
#endif
t_Demod = nullptr;
}
#if ENABLE_DIGITAL_LAB
if (activeOutput) {
closeOutput();
}
#endif
}
if (preDemodTerminated) {
@ -314,7 +315,14 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
if (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() {

View File

@ -136,6 +136,7 @@ void DemodulatorThread::run() {
ati->sampleRate = cModemKit->sampleRate;
ati->inputRate = inp->sampleRate;
ati->data.resize(0);
}
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;
ati->peak = 0;
for (data_i = ati->data.begin(); data_i != ati->data.end(); data_i++) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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