mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-02-03 09:44:26 -05:00
Cleanup: demodulator mgr, instances, threads
This commit is contained in:
parent
0b97bd360a
commit
4605eaccf0
@ -18,15 +18,14 @@ class DemodulatorThread;
|
||||
class DemodulatorThreadControlCommand {
|
||||
public:
|
||||
enum DemodulatorThreadControlCommandEnum {
|
||||
DEMOD_THREAD_CMD_CTL_NULL, DEMOD_THREAD_CMD_CTL_SQUELCH_ON, DEMOD_THREAD_CMD_CTL_SQUELCH_OFF, DEMOD_THREAD_CMD_CTL_TYPE
|
||||
DEMOD_THREAD_CMD_CTL_NULL, DEMOD_THREAD_CMD_CTL_SQUELCH_ON, DEMOD_THREAD_CMD_CTL_SQUELCH_OFF
|
||||
};
|
||||
|
||||
DemodulatorThreadControlCommand() :
|
||||
cmd(DEMOD_THREAD_CMD_CTL_NULL), demodType("") {
|
||||
cmd(DEMOD_THREAD_CMD_CTL_NULL) {
|
||||
}
|
||||
|
||||
DemodulatorThreadControlCommandEnum cmd;
|
||||
std::string demodType;
|
||||
};
|
||||
|
||||
class DemodulatorThreadIQData {
|
||||
@ -48,9 +47,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ~DemodulatorThreadIQData() {
|
||||
|
||||
}
|
||||
virtual ~DemodulatorThreadIQData() = default;
|
||||
};
|
||||
|
||||
class Modem;
|
||||
@ -71,34 +68,9 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual ~DemodulatorThreadPostIQData() {
|
||||
|
||||
}
|
||||
virtual ~DemodulatorThreadPostIQData() = default;
|
||||
};
|
||||
|
||||
|
||||
class DemodulatorThreadAudioData {
|
||||
public:
|
||||
long long frequency;
|
||||
unsigned int sampleRate;
|
||||
unsigned char channels;
|
||||
|
||||
std::vector<float> *data;
|
||||
|
||||
DemodulatorThreadAudioData() :
|
||||
frequency(0), sampleRate(0), channels(0), data(NULL) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorThreadAudioData(long long frequency, unsigned int sampleRate, std::vector<float> *data) :
|
||||
frequency(frequency), sampleRate(sampleRate), channels(1), data(data) {
|
||||
|
||||
}
|
||||
|
||||
virtual ~DemodulatorThreadAudioData() {
|
||||
|
||||
}
|
||||
};
|
||||
typedef std::shared_ptr<DemodulatorThreadIQData> DemodulatorThreadIQDataPtr;
|
||||
typedef std::shared_ptr<DemodulatorThreadPostIQData> DemodulatorThreadPostIQDataPtr;
|
||||
|
||||
|
@ -20,9 +20,7 @@ DemodVisualCue::DemodVisualCue() {
|
||||
squelchBreak.store(false);
|
||||
}
|
||||
|
||||
DemodVisualCue::~DemodVisualCue() {
|
||||
|
||||
}
|
||||
DemodVisualCue::~DemodVisualCue() = default;
|
||||
|
||||
void DemodVisualCue::triggerSquelchBreak(int counter) {
|
||||
squelchBreak.store(counter);
|
||||
@ -121,7 +119,7 @@ DemodulatorInstance::~DemodulatorInstance() {
|
||||
} //end while
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueuePtr tQueue) {
|
||||
void DemodulatorInstance::setVisualOutputQueue(const DemodulatorThreadOutputQueuePtr& tQueue) {
|
||||
demodulatorThread->setOutputQueue("AudioVisualOutput", tQueue);
|
||||
}
|
||||
|
||||
@ -379,11 +377,11 @@ int DemodulatorInstance::getOutputDevice() {
|
||||
return currentOutputDevice;
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
|
||||
void DemodulatorInstance::setDemodulatorType(const std::string& demod_type_in) {
|
||||
setGain(getGain());
|
||||
if (demodulatorPreThread) {
|
||||
std::string currentDemodType = demodulatorPreThread->getDemodType();
|
||||
if ((currentDemodType != "") && (currentDemodType != demod_type_in)) {
|
||||
if ((!currentDemodType.empty()) && (currentDemodType != demod_type_in)) {
|
||||
lastModemSettings[currentDemodType] = demodulatorPreThread->readModemSettings();
|
||||
lastModemBandwidth[currentDemodType] = demodulatorPreThread->getBandwidth();
|
||||
}
|
||||
@ -395,7 +393,7 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
|
||||
|
||||
demodulatorPreThread->setDemodType(demod_type_in);
|
||||
int lastbw = 0;
|
||||
if (currentDemodType != "" && lastModemBandwidth.find(demod_type_in) != lastModemBandwidth.end()) {
|
||||
if (!currentDemodType.empty() && lastModemBandwidth.find(demod_type_in) != lastModemBandwidth.end()) {
|
||||
lastbw = lastModemBandwidth[demod_type_in];
|
||||
}
|
||||
if (!lastbw) {
|
||||
@ -407,7 +405,7 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) {
|
||||
|
||||
#if ENABLE_DIGITAL_LAB
|
||||
if (isModemInitialized() && getModemType() == "digital") {
|
||||
ModemDigitalOutputConsole *outp = (ModemDigitalOutputConsole *)getOutput();
|
||||
auto *outp = (ModemDigitalOutputConsole *)getOutput();
|
||||
outp->setTitle(getDemodulatorType() + ": " + frequencyToStr(getFrequency()));
|
||||
}
|
||||
#endif
|
||||
@ -463,7 +461,7 @@ void DemodulatorInstance::setFrequency(long long freq) {
|
||||
#if ENABLE_DIGITAL_LAB
|
||||
if (activeOutput) {
|
||||
if (isModemInitialized() && getModemType() == "digital") {
|
||||
ModemDigitalOutputConsole *outp = (ModemDigitalOutputConsole *)getOutput();
|
||||
auto *outp = (ModemDigitalOutputConsole *)getOutput();
|
||||
outp->setTitle(getDemodulatorType() + ": " + frequencyToStr(getFrequency()));
|
||||
}
|
||||
}
|
||||
@ -488,7 +486,7 @@ void DemodulatorInstance::setAudioSampleRate(int sampleRate) {
|
||||
demodulatorPreThread->setAudioSampleRate(sampleRate);
|
||||
}
|
||||
|
||||
int DemodulatorInstance::getAudioSampleRate() {
|
||||
int DemodulatorInstance::getAudioSampleRate() const {
|
||||
if (!audioThread) {
|
||||
return 0;
|
||||
}
|
||||
@ -509,16 +507,16 @@ bool DemodulatorInstance::isFollow() {
|
||||
return follow.load();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setFollow(bool follow) {
|
||||
this->follow.store(follow);
|
||||
void DemodulatorInstance::setFollow(bool follow_in) {
|
||||
follow.store(follow_in);
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isTracking() {
|
||||
return tracking.load();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setTracking(bool tracking) {
|
||||
this->tracking.store(tracking);
|
||||
void DemodulatorInstance::setTracking(bool tracking_in) {
|
||||
tracking.store(tracking_in);
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isDeltaLock() {
|
||||
@ -541,10 +539,10 @@ bool DemodulatorInstance::isMuted() {
|
||||
return demodulatorThread->isMuted();
|
||||
}
|
||||
|
||||
void DemodulatorInstance::setMuted(bool muted) {
|
||||
this->muted = muted;
|
||||
demodulatorThread->setMuted(muted);
|
||||
wxGetApp().getDemodMgr().setLastMuted(muted);
|
||||
void DemodulatorInstance::setMuted(bool muted_in) {
|
||||
muted = muted_in;
|
||||
demodulatorThread->setMuted(muted_in);
|
||||
wxGetApp().getDemodMgr().setLastMuted(muted_in);
|
||||
}
|
||||
|
||||
bool DemodulatorInstance::isRecording()
|
||||
@ -580,11 +578,11 @@ ModemArgInfoList DemodulatorInstance::getModemArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
std::string DemodulatorInstance::readModemSetting(std::string setting) {
|
||||
std::string DemodulatorInstance::readModemSetting(const std::string& setting) {
|
||||
return demodulatorPreThread->readModemSetting(setting);
|
||||
}
|
||||
|
||||
void DemodulatorInstance::writeModemSetting(std::string setting, std::string value) {
|
||||
void DemodulatorInstance::writeModemSetting(const std::string& setting, std::string value) {
|
||||
demodulatorPreThread->writeModemSetting(setting, value);
|
||||
}
|
||||
|
||||
@ -610,7 +608,7 @@ std::string DemodulatorInstance::getModemType() {
|
||||
return "";
|
||||
}
|
||||
|
||||
ModemSettings DemodulatorInstance::getLastModemSettings(std::string demodType) {
|
||||
ModemSettings DemodulatorInstance::getLastModemSettings(const std::string& demodType) {
|
||||
if (lastModemSettings.find(demodType) != lastModemSettings.end()) {
|
||||
return lastModemSettings[demodType];
|
||||
} else {
|
||||
@ -625,8 +623,8 @@ void DemodulatorInstance::startRecording() {
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSinkFileThread *newSinkThread = new AudioSinkFileThread();
|
||||
AudioFileWAV *afHandler = new AudioFileWAV();
|
||||
auto *newSinkThread = new AudioSinkFileThread();
|
||||
auto *afHandler = new AudioFileWAV();
|
||||
|
||||
std::stringstream fileName;
|
||||
|
||||
@ -701,7 +699,7 @@ void DemodulatorInstance::hideOutput() {
|
||||
void DemodulatorInstance::closeOutput() {
|
||||
if (isModemInitialized()) {
|
||||
if (getModemType() == "digital") {
|
||||
ModemDigital *dModem = (ModemDigital *)demodulatorPreThread->getModem();
|
||||
auto *dModem = (ModemDigital *)demodulatorPreThread->getModem();
|
||||
dModem->setOutput(nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
DemodulatorInstance();
|
||||
~DemodulatorInstance();
|
||||
|
||||
void setVisualOutputQueue(DemodulatorThreadOutputQueuePtr tQueue);
|
||||
void setVisualOutputQueue(const DemodulatorThreadOutputQueuePtr& tQueue);
|
||||
|
||||
void run();
|
||||
void terminate();
|
||||
@ -76,7 +76,7 @@ public:
|
||||
void setOutputDevice(int device_id);
|
||||
int getOutputDevice();
|
||||
|
||||
void setDemodulatorType(std::string demod_type_in);
|
||||
void setDemodulatorType(const std::string& demod_type_in);
|
||||
std::string getDemodulatorType();
|
||||
|
||||
std::wstring getDemodulatorUserLabel();
|
||||
@ -95,13 +95,13 @@ public:
|
||||
long long getFrequency();
|
||||
|
||||
void setAudioSampleRate(int sampleRate);
|
||||
int getAudioSampleRate();
|
||||
int getAudioSampleRate() const;
|
||||
|
||||
bool isFollow();
|
||||
void setFollow(bool follow);
|
||||
void setFollow(bool follow_in);
|
||||
|
||||
bool isTracking();
|
||||
void setTracking(bool tracking);
|
||||
void setTracking(bool tracking_in);
|
||||
|
||||
bool isDeltaLock();
|
||||
void setDeltaLock(bool lock);
|
||||
@ -109,7 +109,7 @@ public:
|
||||
int getDeltaLockOfs();
|
||||
|
||||
bool isMuted();
|
||||
void setMuted(bool muted);
|
||||
void setMuted(bool muted_in);
|
||||
|
||||
bool isRecording();
|
||||
void setRecording(bool recording);
|
||||
@ -119,14 +119,14 @@ public:
|
||||
DemodulatorThreadInputQueuePtr getIQInputDataPipe();
|
||||
|
||||
ModemArgInfoList getModemArgs();
|
||||
std::string readModemSetting(std::string setting);
|
||||
std::string readModemSetting(const std::string& setting);
|
||||
ModemSettings readModemSettings();
|
||||
void writeModemSetting(std::string setting, std::string value);
|
||||
void writeModemSetting(const std::string& setting, std::string value);
|
||||
void writeModemSettings(ModemSettings settings);
|
||||
|
||||
bool isModemInitialized();
|
||||
std::string getModemType();
|
||||
ModemSettings getLastModemSettings(std::string demodType);
|
||||
ModemSettings getLastModemSettings(const std::string& demodType);
|
||||
|
||||
#if ENABLE_DIGITAL_LAB
|
||||
ModemDigitalOutput *getOutput();
|
||||
|
@ -2,13 +2,9 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include <DemodulatorMgr.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "DemodulatorMgr.h"
|
||||
#include "CubicSDR.h"
|
||||
|
||||
#if USE_HAMLIB
|
||||
@ -18,8 +14,8 @@
|
||||
#include "DataTree.h"
|
||||
#include <wx/string.h>
|
||||
|
||||
bool demodFreqCompare (DemodulatorInstancePtr i, DemodulatorInstancePtr j) { return (i->getFrequency() < j->getFrequency()); }
|
||||
bool inactiveCompare (DemodulatorInstancePtr i, DemodulatorInstancePtr j) { return (i->isActive() < j->isActive()); }
|
||||
bool demodFreqCompare (const DemodulatorInstancePtr& i, const DemodulatorInstancePtr& j) { return (i->getFrequency() < j->getFrequency()); }
|
||||
bool inactiveCompare (const DemodulatorInstancePtr& i, const DemodulatorInstancePtr& j) { return (i->isActive() < j->isActive()); }
|
||||
|
||||
DemodulatorMgr::DemodulatorMgr() {
|
||||
|
||||
@ -55,7 +51,7 @@ void DemodulatorMgr::terminateAll() {
|
||||
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
|
||||
while (demods.size()) {
|
||||
while (!demods.empty()) {
|
||||
|
||||
DemodulatorInstancePtr d = demods.back();
|
||||
demods.pop_back();
|
||||
@ -95,7 +91,7 @@ std::vector<DemodulatorInstancePtr> DemodulatorMgr::getOrderedDemodulators(bool
|
||||
return demods_ordered;
|
||||
}
|
||||
|
||||
DemodulatorInstancePtr DemodulatorMgr::getPreviousDemodulator(DemodulatorInstancePtr demod, bool actives) {
|
||||
DemodulatorInstancePtr DemodulatorMgr::getPreviousDemodulator(const DemodulatorInstancePtr& demod, bool actives) {
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
if (!getCurrentModem()) {
|
||||
return nullptr;
|
||||
@ -112,7 +108,7 @@ DemodulatorInstancePtr DemodulatorMgr::getPreviousDemodulator(DemodulatorInstanc
|
||||
return *(--p);
|
||||
}
|
||||
|
||||
DemodulatorInstancePtr DemodulatorMgr::getNextDemodulator(DemodulatorInstancePtr demod, bool actives) {
|
||||
DemodulatorInstancePtr DemodulatorMgr::getNextDemodulator(const DemodulatorInstancePtr& demod, bool actives) {
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
if (!getCurrentModem()) {
|
||||
return nullptr;
|
||||
@ -144,7 +140,7 @@ DemodulatorInstancePtr DemodulatorMgr::getFirstDemodulator() {
|
||||
return getOrderedDemodulators().front();
|
||||
}
|
||||
|
||||
void DemodulatorMgr::deleteThread(DemodulatorInstancePtr demod) {
|
||||
void DemodulatorMgr::deleteThread(const DemodulatorInstancePtr& demod) {
|
||||
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
|
||||
@ -176,9 +172,7 @@ std::vector<DemodulatorInstancePtr> DemodulatorMgr::getDemodulatorsAt(long long
|
||||
|
||||
std::vector<DemodulatorInstancePtr> foundDemods;
|
||||
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstancePtr testDemod = demods[i];
|
||||
|
||||
for (auto testDemod : demods) {
|
||||
long long freqTest = testDemod->getFrequency();
|
||||
long long bandwidthTest = testDemod->getBandwidth();
|
||||
long long halfBandwidthTest = bandwidthTest / 2;
|
||||
@ -195,9 +189,7 @@ std::vector<DemodulatorInstancePtr> DemodulatorMgr::getDemodulatorsAt(long long
|
||||
|
||||
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
DemodulatorInstancePtr testDemod = demods[i];
|
||||
|
||||
for (auto testDemod : demods) {
|
||||
long long freqTest = testDemod->getFrequency();
|
||||
long long bandwidthTest = testDemod->getBandwidth();
|
||||
long long halfBandwidthTest = bandwidthTest / 2;
|
||||
@ -214,7 +206,7 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
||||
}
|
||||
|
||||
|
||||
void DemodulatorMgr::setActiveDemodulator(DemodulatorInstancePtr demod, bool temporary) {
|
||||
void DemodulatorMgr::setActiveDemodulator(const DemodulatorInstancePtr& demod, bool temporary) {
|
||||
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
|
||||
@ -261,7 +253,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstancePtr demod, bool tem
|
||||
void DemodulatorMgr::setActiveDemodulatorByRawPointer(DemodulatorInstance* demod, bool temporary) {
|
||||
std::lock_guard < std::recursive_mutex > lock(demods_busy);
|
||||
|
||||
for (auto existing_demod : demods) {
|
||||
for (const auto& existing_demod : demods) {
|
||||
|
||||
if (existing_demod.get() == demod) {
|
||||
|
||||
@ -335,7 +327,7 @@ void DemodulatorMgr::updateLastState() {
|
||||
if (currentModem) {
|
||||
lastBandwidth = currentModem->getBandwidth();
|
||||
lastDemodType = currentModem->getDemodulatorType();
|
||||
lastDemodLock = currentModem->getDemodulatorLock()?true:false;
|
||||
lastDemodLock = currentModem->getDemodulatorLock() != 0;
|
||||
lastSquelchEnabled = currentModem->isSquelchEnabled();
|
||||
lastSquelch = currentModem->getSquelchLevel();
|
||||
lastGain = currentModem->getGain();
|
||||
@ -348,29 +340,29 @@ int DemodulatorMgr::getLastBandwidth() const {
|
||||
return lastBandwidth;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastBandwidth(int lastBandwidth) {
|
||||
if (lastBandwidth < MIN_BANDWIDTH) {
|
||||
lastBandwidth = MIN_BANDWIDTH;
|
||||
} else if (lastBandwidth > wxGetApp().getSampleRate()) {
|
||||
lastBandwidth = wxGetApp().getSampleRate();
|
||||
void DemodulatorMgr::setLastBandwidth(int lastBandwidth_in) {
|
||||
if (lastBandwidth_in < MIN_BANDWIDTH) {
|
||||
lastBandwidth_in = MIN_BANDWIDTH;
|
||||
} else if (lastBandwidth_in > wxGetApp().getSampleRate()) {
|
||||
lastBandwidth_in = wxGetApp().getSampleRate();
|
||||
}
|
||||
this->lastBandwidth = lastBandwidth;
|
||||
lastBandwidth = lastBandwidth_in;
|
||||
}
|
||||
|
||||
std::string DemodulatorMgr::getLastDemodulatorType() const {
|
||||
return lastDemodType;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastDemodulatorType(std::string lastDemodType) {
|
||||
this->lastDemodType = lastDemodType;
|
||||
void DemodulatorMgr::setLastDemodulatorType(std::string lastDemodType_in) {
|
||||
lastDemodType = lastDemodType_in;
|
||||
}
|
||||
|
||||
float DemodulatorMgr::getLastGain() const {
|
||||
return lastGain;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastGain(float lastGain) {
|
||||
this->lastGain = lastGain;
|
||||
void DemodulatorMgr::setLastGain(float lastGain_in) {
|
||||
lastGain = lastGain_in;
|
||||
}
|
||||
|
||||
|
||||
@ -386,31 +378,31 @@ float DemodulatorMgr::getLastSquelchLevel() const {
|
||||
return lastSquelch;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastSquelchLevel(float lastSquelch) {
|
||||
this->lastSquelch = lastSquelch;
|
||||
void DemodulatorMgr::setLastSquelchLevel(float lastSquelch_in) {
|
||||
lastSquelch = lastSquelch_in;
|
||||
}
|
||||
|
||||
bool DemodulatorMgr::isLastSquelchEnabled() const {
|
||||
return lastSquelchEnabled;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastSquelchEnabled(bool lastSquelchEnabled) {
|
||||
this->lastSquelchEnabled = lastSquelchEnabled;
|
||||
void DemodulatorMgr::setLastSquelchEnabled(bool lastSquelchEnabled_in) {
|
||||
lastSquelchEnabled = lastSquelchEnabled_in;
|
||||
}
|
||||
|
||||
bool DemodulatorMgr::isLastMuted() const {
|
||||
return lastMuted;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastMuted(bool lastMuted) {
|
||||
this->lastMuted = lastMuted;
|
||||
void DemodulatorMgr::setLastMuted(bool lastMuted_in) {
|
||||
lastMuted = lastMuted_in;
|
||||
}
|
||||
|
||||
ModemSettings DemodulatorMgr::getLastModemSettings(std::string modemType) {
|
||||
ModemSettings DemodulatorMgr::getLastModemSettings(const std::string& modemType) {
|
||||
return lastModemSettings[modemType];
|
||||
}
|
||||
|
||||
void DemodulatorMgr::setLastModemSettings(std::string modemType, ModemSettings settings) {
|
||||
void DemodulatorMgr::setLastModemSettings(const std::string& modemType, ModemSettings settings) {
|
||||
lastModemSettings[modemType] = settings;
|
||||
}
|
||||
|
||||
@ -422,7 +414,7 @@ std::map<int, RtAudio::DeviceInfo> DemodulatorMgr::getOutputDevices() {
|
||||
return outputDevices;
|
||||
}
|
||||
|
||||
void DemodulatorMgr::saveInstance(DataNode *node, DemodulatorInstancePtr inst) {
|
||||
void DemodulatorMgr::saveInstance(DataNode *node, const DemodulatorInstancePtr& inst) {
|
||||
|
||||
*node->newChild("bandwidth") = inst->getBandwidth();
|
||||
*node->newChild("frequency") = inst->getFrequency();
|
||||
@ -444,7 +436,7 @@ void DemodulatorMgr::saveInstance(DataNode *node, DemodulatorInstancePtr inst) {
|
||||
}
|
||||
|
||||
ModemSettings saveSettings = inst->readModemSettings();
|
||||
if (saveSettings.size()) {
|
||||
if (!saveSettings.empty()) {
|
||||
DataNode *settingsNode = node->newChild("settings");
|
||||
for (ModemSettings::const_iterator msi = saveSettings.begin(); msi != saveSettings.end(); msi++) {
|
||||
*settingsNode->newChild(msi->first.c_str()) = msi->second;
|
||||
@ -454,7 +446,7 @@ void DemodulatorMgr::saveInstance(DataNode *node, DemodulatorInstancePtr inst) {
|
||||
|
||||
std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) {
|
||||
|
||||
std::wstring decodedWString = L"";
|
||||
std::wstring decodedWString;
|
||||
|
||||
if (node != nullptr) {
|
||||
|
||||
@ -462,7 +454,7 @@ std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) {
|
||||
try {
|
||||
node->element()->get(decodedWString);
|
||||
|
||||
} catch (DataTypeMismatchException e) {
|
||||
} catch (const DataTypeMismatchException &e) {
|
||||
//2) wstring decode fail, try simple std::string
|
||||
std::string decodedStdString;
|
||||
try {
|
||||
@ -472,7 +464,7 @@ std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) {
|
||||
//use wxString for a clean conversion to a wstring:
|
||||
decodedWString = wxString(decodedStdString).ToStdWstring();
|
||||
|
||||
} catch (DataTypeMismatchException e) {
|
||||
} catch (const DataTypeMismatchException &e) {
|
||||
//nothing works, return an empty string.
|
||||
decodedWString = L"";
|
||||
}
|
||||
@ -490,22 +482,22 @@ DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
|
||||
|
||||
node->rewindAll();
|
||||
|
||||
long bandwidth = *node->getNext("bandwidth");
|
||||
long long freq = *node->getNext("frequency");
|
||||
long bandwidth = (long)*node->getNext("bandwidth");
|
||||
long long freq = (long long)*node->getNext("frequency");
|
||||
float squelch_level = node->hasAnother("squelch_level") ? (float) *node->getNext("squelch_level") : 0;
|
||||
int squelch_enabled = node->hasAnother("squelch_enabled") ? (int) *node->getNext("squelch_enabled") : 0;
|
||||
int muted = node->hasAnother("muted") ? (int) *node->getNext("muted") : 0;
|
||||
int delta_locked = node->hasAnother("delta_lock") ? (int) *node->getNext("delta_lock") : 0;
|
||||
int delta_ofs = node->hasAnother("delta_ofs") ? (int) *node->getNext("delta_ofs") : 0;
|
||||
std::string output_device = node->hasAnother("output_device") ? string(*(node->getNext("output_device"))) : "";
|
||||
float gain = node->hasAnother("gain") ? (float) *node->getNext("gain") : 1.0;
|
||||
std::string output_device = node->hasAnother("output_device") ? ((string)*(node->getNext("output_device"))) : "";
|
||||
float gain = node->hasAnother("gain") ? (float) *node->getNext("gain") : 1.0f;
|
||||
|
||||
std::string type = "FM";
|
||||
|
||||
DataNode *demodTypeNode = node->hasAnother("type")?node->getNext("type"):nullptr;
|
||||
|
||||
if (demodTypeNode && demodTypeNode->element()->getDataType() == DataElement::DATA_INT) {
|
||||
int legacyType = *demodTypeNode;
|
||||
int legacyType = (int)*demodTypeNode;
|
||||
int legacyStereo = node->hasAnother("stereo") ? (int) *node->getNext("stereo") : 0;
|
||||
switch (legacyType) { // legacy demod ID
|
||||
case 1: type = legacyStereo?"FMS":"FM"; break;
|
||||
@ -531,7 +523,7 @@ DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
|
||||
}
|
||||
|
||||
//read the user label associated with the demodulator
|
||||
std::wstring user_label = L"";
|
||||
std::wstring user_label;
|
||||
|
||||
DataNode *demodUserLabel = node->hasAnother("user_label") ? node->getNext("user_label") : nullptr;
|
||||
|
||||
@ -549,7 +541,7 @@ DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
|
||||
std::string keyName = settingNode->getName();
|
||||
std::string strSettingValue = settingNode->element()->toString();
|
||||
|
||||
if (keyName != "" && strSettingValue != "") {
|
||||
if (!keyName.empty() && !strSettingValue.empty()) {
|
||||
mSettings[keyName] = strSettingValue;
|
||||
}
|
||||
}
|
||||
@ -564,7 +556,7 @@ DemodulatorInstancePtr DemodulatorMgr::loadInstance(DataNode *node) {
|
||||
newDemod->setFrequency(freq);
|
||||
newDemod->setGain(gain);
|
||||
newDemod->updateLabel(freq);
|
||||
newDemod->setMuted(muted?true:false);
|
||||
newDemod->setMuted(muted != 0);
|
||||
if (delta_locked) {
|
||||
newDemod->setDeltaLock(true);
|
||||
newDemod->setDeltaLockOfs(delta_ofs);
|
||||
|
@ -24,16 +24,16 @@ public:
|
||||
std::vector<DemodulatorInstancePtr> getOrderedDemodulators(bool actives = true);
|
||||
std::vector<DemodulatorInstancePtr> getDemodulatorsAt(long long freq, int bandwidth);
|
||||
|
||||
DemodulatorInstancePtr getPreviousDemodulator(DemodulatorInstancePtr demod, bool actives = true);
|
||||
DemodulatorInstancePtr getNextDemodulator(DemodulatorInstancePtr demod, bool actives = true);
|
||||
DemodulatorInstancePtr getPreviousDemodulator(const DemodulatorInstancePtr& demod, bool actives = true);
|
||||
DemodulatorInstancePtr getNextDemodulator(const DemodulatorInstancePtr& demod, bool actives = true);
|
||||
DemodulatorInstancePtr getLastDemodulator();
|
||||
DemodulatorInstancePtr getFirstDemodulator();
|
||||
bool anyDemodulatorsAt(long long freq, int bandwidth);
|
||||
void deleteThread(DemodulatorInstancePtr);
|
||||
void deleteThread(const DemodulatorInstancePtr&);
|
||||
|
||||
void terminateAll();
|
||||
|
||||
void setActiveDemodulator(DemodulatorInstancePtr demod, bool temporary = true);
|
||||
void setActiveDemodulator(const DemodulatorInstancePtr& demod, bool temporary = true);
|
||||
|
||||
//Dangerous: this is only intended by some internal classes,
|
||||
// and only set a pre-existing demod
|
||||
@ -47,34 +47,34 @@ public:
|
||||
int bandwidth);
|
||||
|
||||
int getLastBandwidth() const;
|
||||
void setLastBandwidth(int lastBandwidth);
|
||||
void setLastBandwidth(int lastBandwidth_in);
|
||||
|
||||
std::string getLastDemodulatorType() const;
|
||||
void setLastDemodulatorType(std::string lastDemodType);
|
||||
void setLastDemodulatorType(std::string lastDemodType_in);
|
||||
|
||||
float getLastGain() const;
|
||||
void setLastGain(float lastGain);
|
||||
void setLastGain(float lastGain_in);
|
||||
|
||||
bool getLastDeltaLock() const;
|
||||
void setLastDeltaLock(bool lock);
|
||||
|
||||
float getLastSquelchLevel() const;
|
||||
void setLastSquelchLevel(float lastSquelch);
|
||||
void setLastSquelchLevel(float lastSquelch_in);
|
||||
|
||||
bool isLastSquelchEnabled() const;
|
||||
void setLastSquelchEnabled(bool lastSquelchEnabled);
|
||||
void setLastSquelchEnabled(bool lastSquelchEnabled_in);
|
||||
|
||||
bool isLastMuted() const;
|
||||
void setLastMuted(bool lastMuted);
|
||||
void setLastMuted(bool lastMuted_in);
|
||||
|
||||
ModemSettings getLastModemSettings(std::string);
|
||||
void setLastModemSettings(std::string, ModemSettings);
|
||||
ModemSettings getLastModemSettings(const std::string&);
|
||||
void setLastModemSettings(const std::string&, ModemSettings);
|
||||
|
||||
void updateLastState();
|
||||
|
||||
void setOutputDevices(std::map<int,RtAudio::DeviceInfo> devs);
|
||||
std::map<int, RtAudio::DeviceInfo> getOutputDevices();
|
||||
void saveInstance(DataNode *node, DemodulatorInstancePtr inst);
|
||||
void saveInstance(DataNode *node, const DemodulatorInstancePtr& inst);
|
||||
|
||||
DemodulatorInstancePtr loadInstance(DataNode *node);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) Charles J. Cliffe
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include "CubicSDRDefs.h"
|
||||
#include <vector>
|
||||
|
||||
#ifdef __APPLE__
|
||||
@ -15,7 +14,7 @@
|
||||
//50 ms
|
||||
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
|
||||
|
||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance* parent) : IOThread(), iqResampler(NULL), iqResampleRatio(1), cModem(nullptr), cModemKit(nullptr)
|
||||
DemodulatorPreThread::DemodulatorPreThread(DemodulatorInstance* parent) : IOThread(), iqResampler(nullptr), iqResampleRatio(1), cModem(nullptr), cModemKit(nullptr)
|
||||
{
|
||||
initialized.store(false);
|
||||
this->parent = parent;
|
||||
@ -50,8 +49,7 @@ bool DemodulatorPreThread::isInitialized() {
|
||||
return initialized.load();
|
||||
}
|
||||
|
||||
DemodulatorPreThread::~DemodulatorPreThread() {
|
||||
}
|
||||
DemodulatorPreThread::~DemodulatorPreThread() = default;
|
||||
|
||||
void DemodulatorPreThread::run() {
|
||||
#ifdef __APPLE__
|
||||
@ -98,8 +96,7 @@ void DemodulatorPreThread::run() {
|
||||
audioSampleRateChanged.store(true);
|
||||
}
|
||||
} else if (parent->getAudioSampleRate() != newAudioSampleRate) {
|
||||
int newRate;
|
||||
if ((newRate = parent->getAudioSampleRate())) {
|
||||
if (parent->getAudioSampleRate()) {
|
||||
newAudioSampleRate = parent->getAudioSampleRate();
|
||||
audioSampleRateChanged.store(true);
|
||||
}
|
||||
@ -116,9 +113,9 @@ void DemodulatorPreThread::run() {
|
||||
sampleRateChanged.store(false);
|
||||
audioSampleRateChanged.store(false);
|
||||
ModemSettings lastSettings = parent->getLastModemSettings(newDemodType);
|
||||
if (lastSettings.size() != 0) {
|
||||
if (!lastSettings.empty()) {
|
||||
command.settings = lastSettings;
|
||||
if (modemSettingsBuffered.size()) {
|
||||
if (!modemSettingsBuffered.empty()) {
|
||||
for (ModemSettings::const_iterator msi = modemSettingsBuffered.begin(); msi != modemSettingsBuffered.end(); msi++) {
|
||||
command.settings[msi->first] = msi->second;
|
||||
}
|
||||
@ -168,7 +165,7 @@ void DemodulatorPreThread::run() {
|
||||
|
||||
// std::lock_guard < std::mutex > lock(inp->m_mutex);
|
||||
std::vector<liquid_float_complex> *data = &inp->data;
|
||||
if (data->size() && (inp->sampleRate == currentSampleRate) && cModem && cModemKit) {
|
||||
if (!data->empty() && (inp->sampleRate == currentSampleRate) && cModem && cModemKit) {
|
||||
size_t bufSize = data->size();
|
||||
|
||||
if (in_buf_data.size() != bufSize) {
|
||||
@ -184,7 +181,7 @@ void DemodulatorPreThread::run() {
|
||||
|
||||
liquid_float_complex *in_buf = &in_buf_data[0];
|
||||
liquid_float_complex *out_buf = &out_buf_data[0];
|
||||
liquid_float_complex *temp_buf = NULL;
|
||||
liquid_float_complex *temp_buf;
|
||||
|
||||
if (shiftFrequency != 0) {
|
||||
if (shiftFrequency < 0) {
|
||||
@ -241,7 +238,7 @@ void DemodulatorPreThread::run() {
|
||||
cModem = result.modem;
|
||||
#if ENABLE_DIGITAL_LAB
|
||||
if (cModem->getType() == "digital") {
|
||||
ModemDigital *mDigi = (ModemDigital *)cModem;
|
||||
auto *mDigi = (ModemDigital *)cModem;
|
||||
mDigi->setOutput(parent->getOutput());
|
||||
}
|
||||
#endif
|
||||
@ -260,7 +257,7 @@ void DemodulatorPreThread::run() {
|
||||
currentSampleRate = result.sampleRate;
|
||||
}
|
||||
|
||||
if (result.modemName != "") {
|
||||
if (!result.modemName.empty()) {
|
||||
demodType = result.modemName;
|
||||
demodTypeChanged.store(false);
|
||||
}
|
||||
@ -285,8 +282,8 @@ void DemodulatorPreThread::run() {
|
||||
iqInputQueue->flush();
|
||||
}
|
||||
|
||||
void DemodulatorPreThread::setDemodType(std::string demodType) {
|
||||
newDemodType = demodType;
|
||||
void DemodulatorPreThread::setDemodType(std::string demodType_in) {
|
||||
newDemodType = demodType_in;
|
||||
demodTypeChanged.store(true);
|
||||
}
|
||||
|
||||
@ -377,7 +374,7 @@ ModemKit *DemodulatorPreThread::getModemKit() {
|
||||
}
|
||||
|
||||
|
||||
std::string DemodulatorPreThread::readModemSetting(std::string setting) {
|
||||
std::string DemodulatorPreThread::readModemSetting(const std::string& setting) {
|
||||
if (cModem) {
|
||||
return cModem->readSetting(setting);
|
||||
} else if (modemSettingsBuffered.find(setting) != modemSettingsBuffered.end()) {
|
||||
@ -386,7 +383,7 @@ std::string DemodulatorPreThread::readModemSetting(std::string setting) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void DemodulatorPreThread::writeModemSetting(std::string setting, std::string value) {
|
||||
void DemodulatorPreThread::writeModemSetting(const std::string& setting, std::string value) {
|
||||
modemSettingsBuffered[setting] = value;
|
||||
modemSettingsChanged.store(true);
|
||||
}
|
||||
|
@ -17,12 +17,12 @@ class DemodulatorInstance;
|
||||
class DemodulatorPreThread : public IOThread {
|
||||
public:
|
||||
|
||||
DemodulatorPreThread(DemodulatorInstance* parent);
|
||||
virtual ~DemodulatorPreThread();
|
||||
explicit DemodulatorPreThread(DemodulatorInstance* parent);
|
||||
~DemodulatorPreThread() override;
|
||||
|
||||
virtual void run();
|
||||
void run() override;
|
||||
|
||||
void setDemodType(std::string demodType);
|
||||
void setDemodType(std::string demodType_in);
|
||||
std::string getDemodType();
|
||||
|
||||
void setFrequency(long long sampleRate);
|
||||
@ -39,13 +39,13 @@ public:
|
||||
|
||||
bool isInitialized();
|
||||
|
||||
virtual void terminate();
|
||||
void terminate() override;
|
||||
|
||||
Modem *getModem();
|
||||
ModemKit *getModemKit();
|
||||
|
||||
std::string readModemSetting(std::string setting);
|
||||
void writeModemSetting(std::string setting, std::string value);
|
||||
std::string readModemSetting(const std::string& setting);
|
||||
void writeModemSetting(const std::string& setting, std::string value);
|
||||
ModemSettings readModemSettings();
|
||||
void writeModemSettings(ModemSettings settings);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) Charles J. Cliffe
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "DemodulatorThread.h"
|
||||
#include "DemodulatorInstance.h"
|
||||
#include "CubicSDR.h"
|
||||
@ -148,7 +147,7 @@ void DemodulatorThread::run() {
|
||||
double currentSignalLevel = 0;
|
||||
double sampleTime = double(inp->data.size()) / double(inp->sampleRate);
|
||||
|
||||
if (audioOutputQueue != nullptr && ati && ati->data.size()) {
|
||||
if (audioOutputQueue != nullptr && ati && !ati->data.empty()) {
|
||||
double accum = 0;
|
||||
|
||||
if (cModem->useSignalOutput()) {
|
||||
@ -389,8 +388,8 @@ bool DemodulatorThread::isMuted() {
|
||||
return muted.load();
|
||||
}
|
||||
|
||||
void DemodulatorThread::setMuted(bool muted) {
|
||||
this->muted.store(muted);
|
||||
void DemodulatorThread::setMuted(bool muted_in) {
|
||||
muted.store(muted_in);
|
||||
}
|
||||
|
||||
float DemodulatorThread::getSignalLevel() {
|
||||
|
@ -21,15 +21,15 @@ class DemodulatorInstance;
|
||||
class DemodulatorThread : public IOThread {
|
||||
public:
|
||||
|
||||
DemodulatorThread(DemodulatorInstance* parent);
|
||||
virtual ~DemodulatorThread();
|
||||
explicit DemodulatorThread(DemodulatorInstance* parent);
|
||||
~DemodulatorThread() override;
|
||||
|
||||
void onBindOutput(std::string name, ThreadQueueBasePtr threadQueue);
|
||||
void onBindOutput(std::string name, ThreadQueueBasePtr threadQueue) override;
|
||||
|
||||
virtual void run();
|
||||
virtual void terminate();
|
||||
void run() override;
|
||||
void terminate() override;
|
||||
|
||||
void setMuted(bool state);
|
||||
void setMuted(bool muted_in);
|
||||
bool isMuted();
|
||||
|
||||
float getSignalLevel();
|
||||
|
@ -2,9 +2,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#include "DemodulatorWorkerThread.h"
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "CubicSDR.h"
|
||||
#include <vector>
|
||||
|
||||
//50 ms
|
||||
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
|
||||
@ -13,8 +11,7 @@ DemodulatorWorkerThread::DemodulatorWorkerThread() : IOThread(),
|
||||
cModem(nullptr), cModemKit(nullptr) {
|
||||
}
|
||||
|
||||
DemodulatorWorkerThread::~DemodulatorWorkerThread() {
|
||||
}
|
||||
DemodulatorWorkerThread::~DemodulatorWorkerThread() = default;
|
||||
|
||||
void DemodulatorWorkerThread::run() {
|
||||
|
||||
@ -66,7 +63,7 @@ void DemodulatorWorkerThread::run() {
|
||||
cModem = Modem::makeModem(demodCommand.demodType);
|
||||
cModemName = cModem->getName();
|
||||
cModemType = cModem->getType();
|
||||
if (demodCommand.settings.size()) {
|
||||
if (!demodCommand.settings.empty()) {
|
||||
cModem->writeSettings(demodCommand.settings);
|
||||
}
|
||||
result.sampleRate = demodCommand.sampleRate;
|
||||
|
@ -19,11 +19,11 @@ public:
|
||||
};
|
||||
|
||||
DemodulatorWorkerThreadResult() :
|
||||
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(nullptr), iqResampleRatio(0), sampleRate(0), bandwidth(0), modemKit(nullptr), modemType("") {
|
||||
cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(nullptr), iqResampleRatio(0), sampleRate(0), bandwidth(0), modemKit(nullptr) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) :
|
||||
explicit DemodulatorWorkerThreadResult(DemodulatorThreadResultEnum cmd) :
|
||||
DemodulatorWorkerThreadResult() {
|
||||
this->cmd = cmd;
|
||||
}
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
long long sampleRate;
|
||||
unsigned int bandwidth;
|
||||
Modem *modem;
|
||||
Modem *modem{};
|
||||
ModemKit *modemKit;
|
||||
std::string modemType;
|
||||
std::string modemName;
|
||||
@ -48,12 +48,12 @@ public:
|
||||
};
|
||||
|
||||
DemodulatorWorkerThreadCommand() :
|
||||
cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") {
|
||||
cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||
cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") {
|
||||
explicit DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) :
|
||||
cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) {
|
||||
|
||||
}
|
||||
|
||||
@ -77,9 +77,9 @@ class DemodulatorWorkerThread : public IOThread {
|
||||
public:
|
||||
|
||||
DemodulatorWorkerThread();
|
||||
virtual ~DemodulatorWorkerThread();
|
||||
~DemodulatorWorkerThread() override;
|
||||
|
||||
virtual void run();
|
||||
void run() override;
|
||||
|
||||
void setCommandQueue(DemodulatorThreadWorkerCommandQueuePtr tQueue) {
|
||||
commandQueue = tQueue;
|
||||
@ -89,7 +89,7 @@ public:
|
||||
resultQueue = tQueue;
|
||||
}
|
||||
|
||||
virtual void terminate();
|
||||
void terminate() override;
|
||||
|
||||
protected:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user