From f53e2288497048904754f4d7555d3d68bd102696 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 17 Nov 2015 21:49:02 -0500 Subject: [PATCH] Cleanup / finalize demod before initial testing --- src/demod/DemodulatorInstance.cpp | 5 ++--- src/demod/DemodulatorPreThread.cpp | 15 +++++++++++++-- src/demod/DemodulatorPreThread.h | 1 + src/demod/DemodulatorThread.cpp | 11 +---------- src/demod/DemodulatorThread.h | 4 ---- src/demod/DemodulatorWorkerThread.cpp | 3 +++ src/demod/DemodulatorWorkerThread.h | 4 +++- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 1405ef4..8dffd44 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -44,7 +44,7 @@ DemodulatorInstance::DemodulatorInstance() : audioThread->setInputQueue("AudioDataInput", pipeAudioData); audioThread->setOutputQueue("NotifyQueue", pipeDemodNotify); - currentDemodType = demodulatorThread->getDemodulatorType(); + currentDemodType = demodulatorPreThread->getParams().demodType; currentDemodCons = demodulatorThread->getDemodulatorCons(); } @@ -74,7 +74,7 @@ void DemodulatorInstance::run() { // } currentFrequency = demodulatorPreThread->getParams().frequency; - currentDemodType = demodulatorThread->getDemodulatorType(); + currentDemodType = demodulatorPreThread->getParams().demodType; currentDemodCons = demodulatorThread->getDemodulatorCons(); currentAudioSampleRate = AudioThread::deviceSampleRate[getOutputDevice()]; demodulatorPreThread->getParams().audioSampleRate = currentAudioSampleRate; @@ -290,7 +290,6 @@ void DemodulatorInstance::setDemodulatorType(std::string demod_type_in) { if (!active) { checkBandwidth(); demodulatorPreThread->getParams().demodType = currentDemodType; - demodulatorThread->setDemodulatorType(currentDemodType); } else if (demodulatorThread && threadQueueControl) { DemodulatorThreadControlCommand command; command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index ec49d83..21cc402 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -182,6 +182,7 @@ void DemodulatorPreThread::run() { resamp->setRefCount(1); resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten); + resamp->modemType = demodType; resamp->modem = cModem; resamp->modemKit = cModemKit; resamp->sampleRate = params.bandwidth; @@ -220,6 +221,11 @@ void DemodulatorPreThread::run() { if (result.sampleRate) { params.sampleRate = result.sampleRate; } + + if (result.modemType != "") { + demodType = result.modemType; + demodTypeChanged.store(false); + } break; default: break; @@ -245,11 +251,16 @@ void DemodulatorPreThread::setParams(DemodulatorThreadParameters ¶ms_in) { } void DemodulatorPreThread::setDemodType(std::string demodType) { - this->demodType = demodType; - demodTypeChanged.store(true); + this->newDemodType = demodType; + DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD); + command.demodType = demodType; + workerQueue->push(command); } std::string DemodulatorPreThread::getDemodType() { + if (newDemodType != demodType) { + return newDemodType; + } return demodType; } diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 65d69ee..28110dc 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -47,6 +47,7 @@ protected: std::atomic_bool initialized; std::atomic_bool demodTypeChanged; std::string demodType; + std::string newDemodType; DemodulatorWorkerThread *workerThread; std::thread *t_Worker; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index dbf03db..000c52f 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -15,7 +15,6 @@ DemodulatorThread::DemodulatorThread() : IOThread(), iqAutoGain(NULL), amOutputC muted.store(false); agcEnabled.store(false); - demodulatorType = "FM"; // advanced demodulators @@ -530,7 +529,7 @@ void DemodulatorThread::run() { ati_vis->data.resize(stereoSize); - if (demodulatorType == "I/Q") { + if (inp->modemType == "I/Q") { for (int i = 0; i < stereoSize / 2; i++) { ati_vis->data[i] = agcData[i].real * 0.75; ati_vis->data[i + stereoSize / 2] = agcData[i].imag * 0.75; @@ -656,14 +655,6 @@ float DemodulatorThread::getSquelchLevel() { return squelchLevel; } -void DemodulatorThread::setDemodulatorType(std::string demod_type_in) { - demodulatorType = demod_type_in; -} - -std::string DemodulatorThread::getDemodulatorType() { - return demodulatorType; -} - void DemodulatorThread::setDemodulatorLock(bool demod_lock_in) { demod_lock_in ? currentDemodLock = true : currentDemodLock = false; } diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 7166fed..6a0a526 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -31,9 +31,6 @@ public: float getSignalLevel(); void setSquelchLevel(float signal_level_in); float getSquelchLevel(); - - void setDemodulatorType(std::string demod_type_in); - std::string getDemodulatorType(); void setDemodulatorLock(bool demod_lock_in); int getDemodulatorLock(); @@ -137,7 +134,6 @@ protected: std::atomic_bool muted; std::atomic_bool agcEnabled; - std::string demodulatorType; std::atomic_int demodulatorCons; int audioSampleRate; diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 0ba23f3..edbc6c3 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -53,6 +53,7 @@ void DemodulatorWorkerThread::run() { if (makeDemod) { cModem = Modem::makeModem(filterCommand.demodType); + cModemType = filterCommand.demodType; } if (filterCommand.bandwidth && filterCommand.audioSampleRate) { @@ -71,6 +72,8 @@ void DemodulatorWorkerThread::run() { result.sampleRate = filterCommand.sampleRate; } + result.modemType = cModemType; + resultQueue->push(result); } diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 2a47ce4..5455a5f 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -16,7 +16,7 @@ public: }; DemodulatorWorkerThreadResult() : - cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(nullptr), iqResampleRatio(0), sampleRate(0), bandwidth(0), modemKit(nullptr) { + cmd(DEMOD_WORKER_THREAD_RESULT_NULL), iqResampler(nullptr), iqResampleRatio(0), sampleRate(0), bandwidth(0), modemKit(nullptr), modemType("") { } @@ -36,6 +36,7 @@ public: unsigned int bandwidth; Modem *modem; ModemKit *modemKit; + std::string modemType; }; class DemodulatorWorkerThreadCommand { @@ -90,4 +91,5 @@ protected: DemodulatorThreadWorkerResultQueue *resultQueue; Modem *cModem; ModemKit *cModemKit; + std::string cModemType; };