From 26ca55734943e1f67f76920918a6b54a8cee5a55 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 27 Jun 2015 23:23:43 -0400 Subject: [PATCH 1/8] Experimental raw I/Q output mode --- src/AppFrame.cpp | 1 + src/demod/DemodDefs.h | 2 ++ src/demod/DemodulatorInstance.cpp | 20 ++++++++++++++-- src/demod/DemodulatorThread.cpp | 38 +++++++++++++++++++++++++------ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index b659b0f..970a738 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -57,6 +57,7 @@ AppFrame::AppFrame() : demodModeSelector->addChoice(DEMOD_TYPE_LSB, "LSB"); demodModeSelector->addChoice(DEMOD_TYPE_USB, "USB"); demodModeSelector->addChoice(DEMOD_TYPE_DSB, "DSB"); + demodModeSelector->addChoice(DEMOD_TYPE_RAW, "I/Q"); demodModeSelector->setSelection(DEMOD_TYPE_FM); demodModeSelector->setHelpTip("Choose modulation type: Frequency Modulation, Amplitude Modulation and Lower, Upper or Double Side-Band."); demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0); diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index a3db3e0..c5381d0 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -13,6 +13,8 @@ #define DEMOD_TYPE_LSB 3 #define DEMOD_TYPE_USB 4 #define DEMOD_TYPE_DSB 5 +#define DEMOD_TYPE_RAW 6 + class DemodulatorThread; class DemodulatorThreadCommand { diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 0f16c68..ed5bb96 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -220,13 +220,12 @@ void DemodulatorInstance::setOutputDevice(int device_id) { if (!active) { audioThread->setInitOutputDevice(device_id); } else if (audioThread) { - setAudioSampleRate(AudioThread::deviceSampleRate[device_id]); - AudioThreadCommand command; command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; command.int_value = device_id; audioThread->getCommandQueue()->push(command); } + setAudioSampleRate(AudioThread::deviceSampleRate[device_id]); currentOutputDevice = device_id; } @@ -258,6 +257,13 @@ void DemodulatorInstance::setDemodulatorType(int demod_type_in) { checkBandwidth(); threadQueueControl->push(command); } + if (currentDemodType == DEMOD_TYPE_RAW) { + if (currentAudioSampleRate) { + setBandwidth(currentAudioSampleRate); + } else { + setBandwidth(AudioThread::deviceSampleRate[getOutputDevice()]); + } + } } int DemodulatorInstance::getDemodulatorType() { @@ -265,6 +271,13 @@ int DemodulatorInstance::getDemodulatorType() { } void DemodulatorInstance::setBandwidth(int bw) { + if (currentDemodType == DEMOD_TYPE_RAW) { + if (currentAudioSampleRate) { + bw = currentAudioSampleRate; + } else { + bw = AudioThread::deviceSampleRate[getOutputDevice()]; + } + } if (!active) { currentBandwidth = bw; checkBandwidth(); @@ -321,6 +334,9 @@ void DemodulatorInstance::setAudioSampleRate(int sampleRate) { command.llong_value = sampleRate; threadQueueCommand->push(command); } + if (currentDemodType == DEMOD_TYPE_RAW) { + setBandwidth(currentAudioSampleRate); + } } int DemodulatorInstance::getAudioSampleRate() { diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 160e04d..6f7246f 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -173,6 +173,8 @@ void DemodulatorThread::threadMain() { if (demodulatorType == DEMOD_TYPE_FM) { freqdem_demodulate_block(demodFM, &agcData[0], bufSize, &demodOutputData[0]); + } else if (demodulatorType == DEMOD_TYPE_RAW) { + // do nothing here.. } else { float p; switch (demodulatorType.load()) { @@ -222,6 +224,10 @@ void DemodulatorThread::threadMain() { } unsigned int numAudioWritten; + + if (demodulatorType == DEMOD_TYPE_RAW) { + numAudioWritten = bufSize; + } else { msresamp_rrrf_execute(audioResampler, &demodOutputData[0], bufSize, &resampledOutputData[0], &numAudioWritten); if (stereo && inp->sampleRate >= 100000) { @@ -276,6 +282,7 @@ void DemodulatorThread::threadMain() { msresamp_rrrf_execute(stereoResampler, &demodStereoData[0], bufSize, &resampledStereoData[0], &numAudioWritten); } + } if (currentSignalLevel > signalLevel) { signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.5; @@ -303,7 +310,17 @@ void DemodulatorThread::threadMain() { ati->sampleRate = audioSampleRate; ati->setRefCount(1); - if (stereo && inp->sampleRate >= 100000) { + if (demodulatorType == DEMOD_TYPE_RAW) { + ati->channels = 2; + if (ati->data.capacity() < (numAudioWritten * 2)) { + ati->data.reserve(numAudioWritten * 2); + } + ati->data.resize(numAudioWritten * 2); + for (int i = 0; i < numAudioWritten; i++) { + ati->data[i * 2] = agcData[i].real; + ati->data[i * 2 + 1] = agcData[i].imag; + } + } else if (stereo && inp->sampleRate >= 100000) { ati->channels = 2; if (ati->data.capacity() < (numAudioWritten * 2)) { ati->data.reserve(numAudioWritten * 2); @@ -344,18 +361,25 @@ void DemodulatorThread::threadMain() { ati_vis->busy_update.lock(); int num_vis = DEMOD_VIS_SIZE; - if (stereo && inp->sampleRate >= 100000) { + if (demodulatorType == DEMOD_TYPE_RAW || (stereo && inp->sampleRate >= 100000)) { ati_vis->channels = 2; int stereoSize = ati->data.size(); - if (stereoSize > DEMOD_VIS_SIZE) { - stereoSize = DEMOD_VIS_SIZE; + if (stereoSize > DEMOD_VIS_SIZE * 2) { + stereoSize = DEMOD_VIS_SIZE * 2; } ati_vis->data.resize(stereoSize); - for (int i = 0; i < stereoSize / 2; i++) { - ati_vis->data[i] = ati->data[i * 2]; - ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1]; + if (demodulatorType == DEMOD_TYPE_RAW) { + for (int i = 0; i < stereoSize / 2; i++) { + ati_vis->data[i] = ati->data[i * 2] * 0.5; + ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1] * 0.5; + } + } else { + for (int i = 0; i < stereoSize / 2; i++) { + ati_vis->data[i] = ati->data[i * 2]; + ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1]; + } } } else { ati_vis->channels = 1; From be1055a2c7ddb674223c3724256a7b2dcb9c010e Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 17 Jul 2015 19:14:39 -0400 Subject: [PATCH 2/8] reduce demod I/Q AGC bandwidth for better raw output --- src/demod/DemodulatorThread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 6f7246f..7ffd6a9 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -61,7 +61,7 @@ void DemodulatorThread::threadMain() { // Automatic IQ gain iqAutoGain = agc_crcf_create(); - agc_crcf_set_bandwidth(iqAutoGain, 0.9); + agc_crcf_set_bandwidth(iqAutoGain, 0.1); AudioThreadInput *ati_vis = new AudioThreadInput; ati_vis->data.reserve(DEMOD_VIS_SIZE); @@ -372,8 +372,8 @@ void DemodulatorThread::threadMain() { if (demodulatorType == DEMOD_TYPE_RAW) { for (int i = 0; i < stereoSize / 2; i++) { - ati_vis->data[i] = ati->data[i * 2] * 0.5; - ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1] * 0.5; + ati_vis->data[i] = ati->data[i * 2] * 0.75; + ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1] * 0.75; } } else { for (int i = 0; i < stereoSize / 2; i++) { From 9bd7ebf07ad46a6d79712128e96a05647365fff9 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 17 Jul 2015 22:27:38 -0400 Subject: [PATCH 3/8] Set raw demod type before bandwidth to prevent crash from previous bw setting --- src/visual/WaterfallCanvas.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 59f7c21..e657a7f 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -820,8 +820,8 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { demod = wxGetApp().getDemodMgr().newThread(); demod->setFrequency(freq); - demod->setBandwidth(mgr->getLastBandwidth()); demod->setDemodulatorType(mgr->getLastDemodulatorType()); + demod->setBandwidth(mgr->getLastBandwidth()); demod->setSquelchLevel(mgr->getLastSquelchLevel()); demod->setSquelchEnabled(mgr->isLastSquelchEnabled()); demod->setStereo(mgr->isLastStereo()); From 8827ff9e26cbb47c814c54e1daabc44d16714791 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 18 Jul 2015 17:03:29 -0400 Subject: [PATCH 4/8] add some missing init vars causing problems with new demod 0/false value checks --- src/CubicSDR.h | 2 +- src/demod/DemodulatorInstance.cpp | 2 +- src/visual/WaterfallCanvas.cpp | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/CubicSDR.h b/src/CubicSDR.h index 9ed5c5b..fb9027b 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -22,7 +22,7 @@ class CubicSDR: public wxApp { public: CubicSDR() : - m_glContext(NULL), frequency(DEFAULT_FREQ), sdrThread(NULL), sdrPostThread(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), iqPostDataQueue(NULL), audioVisualQueue(NULL), t_SDR(NULL), t_PostSDR(NULL), sampleRate(DEFAULT_SAMPLE_RATE), offset(0), snap(1) { + appframe(NULL), m_glContext(NULL), frequency(DEFAULT_FREQ), sdrThread(NULL), sdrPostThread(NULL), threadCmdQueueSDR(NULL), iqVisualQueue(NULL), iqPostDataQueue(NULL), audioVisualQueue(NULL), t_SDR(NULL), t_PostSDR(NULL), sampleRate(DEFAULT_SAMPLE_RATE), offset(0), snap(1), directSamplingMode(0), ppm(0) { } diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index ed5bb96..8d4201f 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -2,7 +2,7 @@ DemodulatorInstance::DemodulatorInstance() : t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(true), audioTerminated(true), demodTerminated( - true), preDemodTerminated(true), active(false), squelch(false), stereo(false), currentFrequency(0), currentBandwidth(0), currentOutputDevice(-1) { + true), preDemodTerminated(true), active(false), squelch(false), stereo(false), tracking(false), follow(false), currentAudioSampleRate(0), currentFrequency(0), currentBandwidth(0), currentOutputDevice(-1) { label = new std::string("Unnamed"); threadQueueDemod = new DemodulatorThreadInputQueue; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index e657a7f..abbcf0e 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -907,9 +907,8 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { } else { demod = wxGetApp().getDemodMgr().newThread(); demod->setFrequency(freq); - demod->setBandwidth(bw); - demod->setDemodulatorType(mgr->getLastDemodulatorType()); + demod->setBandwidth(bw); demod->setSquelchLevel(mgr->getLastSquelchLevel()); demod->setSquelchEnabled(mgr->isLastSquelchEnabled()); demod->setStereo(mgr->isLastStereo()); From db434348a44c47bfd68e79c815bc5da3299e37e0 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 18 Jul 2015 21:49:53 -0400 Subject: [PATCH 5/8] save frequency snap value --- src/AppConfig.cpp | 17 ++++++++++++++++- src/AppConfig.h | 6 +++++- src/AppFrame.cpp | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index d6db8dc..9b057ee 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -121,6 +121,7 @@ AppConfig::AppConfig() { winH.store(0); winMax.store(false); themeId.store(0); + snap.store(1); } @@ -186,6 +187,15 @@ int AppConfig::getTheme() { } +void AppConfig::setSnap(long long snapVal) { + this->snap.store(snapVal); +} + +long long AppConfig::getSnap() { + return snap.load(); +} + + bool AppConfig::save() { DataTree cfg; @@ -200,8 +210,8 @@ bool AppConfig::save() { *window_node->newChild("h") = winH.load(); *window_node->newChild("max") = winMax.load(); - *window_node->newChild("theme") = themeId.load(); + *window_node->newChild("snap") = snap.load(); } DataNode *devices_node = cfg.rootNode()->newChild("devices"); @@ -275,6 +285,11 @@ bool AppConfig::load() { themeId.store(theme); } + if (win_node->hasAnother("snap")) { + long long snapVal; + win_node->getNext("snap")->element()->get(snapVal); + snap.store(snapVal); + } } if (cfg.rootNode()->hasAnother("devices")) { diff --git a/src/AppConfig.h b/src/AppConfig.h index debc640..9d13f49 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -55,7 +55,10 @@ public: void setTheme(int themeId); int getTheme(); - + + void setSnap(long long snapVal); + long long getSnap(); + bool save(); bool load(); bool reset(); @@ -65,4 +68,5 @@ private: std::atomic_int winX,winY,winW,winH; std::atomic_bool winMax; std::atomic_int themeId; + std::atomic_llong snap; }; diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 1336f81..5b8396b 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -319,6 +319,9 @@ AppFrame::AppFrame() : if (max) { this->Maximize(); } + + long long freqSnap = wxGetApp().getConfig()->getSnap(); + wxGetApp().setFrequencySnap(freqSnap); ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme()); @@ -528,6 +531,7 @@ void AppFrame::OnClose(wxCloseEvent& event) { wxGetApp().getConfig()->setWindow(this->GetPosition(), this->GetClientSize()); wxGetApp().getConfig()->setWindowMaximized(this->IsMaximized()); wxGetApp().getConfig()->setTheme(ThemeMgr::mgr.getTheme()); + wxGetApp().getConfig()->setSnap(wxGetApp().getFrequencySnap()); wxGetApp().getConfig()->save(); event.Skip(); } From 927de58e4e2f5464b9db1cdb2b6ce0ce1970c3f7 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 19 Jul 2015 12:56:54 -0400 Subject: [PATCH 6/8] reduce excessive re-saving of config --- src/AppFrame.cpp | 5 +++++ src/CubicSDR.cpp | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 5b8396b..10643f6 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -376,16 +376,21 @@ void AppFrame::OnMenu(wxCommandEvent& event) { "Frequency Offset", wxGetApp().getOffset(), -2000000000, 2000000000, this); if (ofs != -1) { wxGetApp().setOffset(ofs); + wxGetApp().saveConfig(); } } else if (event.GetId() == wxID_SET_DS_OFF) { wxGetApp().setDirectSampling(0); + wxGetApp().saveConfig(); } else if (event.GetId() == wxID_SET_DS_I) { wxGetApp().setDirectSampling(1); + wxGetApp().saveConfig(); } else if (event.GetId() == wxID_SET_DS_Q) { wxGetApp().setDirectSampling(2); + wxGetApp().saveConfig(); } else if (event.GetId() == wxID_SET_SWAP_IQ) { bool swap_state = !wxGetApp().getSwapIQ(); wxGetApp().setSwapIQ(swap_state); + wxGetApp().saveConfig(); iqSwapMenuItem->Check(swap_state); } else if (event.GetId() == wxID_SET_PPM) { long ofs = wxGetNumberFromUser("Frequency correction for device in PPM.\ni.e. -51 for -51 PPM\n\nNote: you can adjust PPM interactively\nby holding ALT over the frequency tuning bar.\n", "Parts per million (PPM)", diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 3e47710..1fa1e54 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -193,7 +193,6 @@ void CubicSDR::setOffset(long long ofs) { SDRDeviceInfo *dev = (*getDevices())[getDevice()]; config.getDevice(dev->getDeviceId())->setOffset(ofs); - config.save(); } void CubicSDR::setDirectSampling(int mode) { @@ -204,7 +203,6 @@ void CubicSDR::setDirectSampling(int mode) { SDRDeviceInfo *dev = (*getDevices())[getDevice()]; config.getDevice(dev->getDeviceId())->setDirectSampling(mode); - config.save(); } int CubicSDR::getDirectSampling() { @@ -215,7 +213,6 @@ void CubicSDR::setSwapIQ(bool swapIQ) { sdrPostThread->setSwapIQ(swapIQ); SDRDeviceInfo *dev = (*getDevices())[getDevice()]; config.getDevice(dev->getDeviceId())->setIQSwap(swapIQ); - config.save(); } bool CubicSDR::getSwapIQ() { @@ -309,7 +306,6 @@ void CubicSDR::setPPM(int ppm_in) { SDRDeviceInfo *dev = (*getDevices())[getDevice()]; config.getDevice(dev->getDeviceId())->setPPM(ppm_in); - config.save(); } int CubicSDR::getPPM() { From 6beeb705494f468e3b70b2517382cfcce94595d4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 19 Jul 2015 15:34:06 -0400 Subject: [PATCH 7/8] Disable I/Q AGC when gain < 0.25 --- src/demod/DemodulatorInstance.cpp | 50 +++++++++++++++++++++---------- src/demod/DemodulatorInstance.h | 27 +++++++++-------- src/demod/DemodulatorThread.cpp | 48 ++++++++++++++++++++--------- src/demod/DemodulatorThread.h | 10 +++++-- 4 files changed, 89 insertions(+), 46 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 8d4201f..ba58e7c 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -2,7 +2,7 @@ DemodulatorInstance::DemodulatorInstance() : t_Demod(NULL), t_PreDemod(NULL), t_Audio(NULL), threadQueueDemod(NULL), demodulatorThread(NULL), terminated(true), audioTerminated(true), demodTerminated( - true), preDemodTerminated(true), active(false), squelch(false), stereo(false), tracking(false), follow(false), currentAudioSampleRate(0), currentFrequency(0), currentBandwidth(0), currentOutputDevice(-1) { + true), preDemodTerminated(true), active(false), squelch(false), stereo(false), tracking(false), follow(false), currentAudioSampleRate(0), currentFrequency(0), currentBandwidth(0), currentOutputDevice(-1), currentAudioGain(1.0) { label = new std::string("Unnamed"); threadQueueDemod = new DemodulatorThreadInputQueue; @@ -244,25 +244,31 @@ void DemodulatorInstance::checkBandwidth() { } void DemodulatorInstance::setDemodulatorType(int demod_type_in) { - if (!active) { - currentDemodType = demod_type_in; - checkBandwidth(); - demodulatorPreThread->getParams().demodType = currentDemodType; - demodulatorThread->setDemodulatorType(currentDemodType); - } else if (demodulatorThread && threadQueueControl) { - DemodulatorThreadControlCommand command; - command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE; - currentDemodType = demod_type_in; - command.demodType = demod_type_in; - checkBandwidth(); - threadQueueControl->push(command); - } + currentDemodType = demod_type_in; + if (currentDemodType == DEMOD_TYPE_RAW) { if (currentAudioSampleRate) { setBandwidth(currentAudioSampleRate); } else { setBandwidth(AudioThread::deviceSampleRate[getOutputDevice()]); } + } else if (currentDemodType == DEMOD_TYPE_USB || currentDemodType == DEMOD_TYPE_LSB || currentDemodType == DEMOD_TYPE_DSB || currentDemodType == DEMOD_TYPE_AM) { + demodulatorThread->setAGC(false); + } else { + demodulatorThread->setAGC(true); + } + setGain(getGain()); + + if (!active) { + checkBandwidth(); + demodulatorPreThread->getParams().demodType = currentDemodType; + demodulatorThread->setDemodulatorType(currentDemodType); + } else if (demodulatorThread && threadQueueControl) { + DemodulatorThreadControlCommand command; + command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE; + command.demodType = demod_type_in; + checkBandwidth(); + threadQueueControl->push(command); } } @@ -348,11 +354,23 @@ int DemodulatorInstance::getAudioSampleRate() { void DemodulatorInstance::setGain(float gain_in) { - audioThread->setGain(gain_in); + currentAudioGain = gain_in; + + if (currentDemodType == DEMOD_TYPE_RAW) { + if (gain_in < 0.25) { + audioThread->setGain(1.0); + demodulatorThread->setAGC(false); + } else { + audioThread->setGain(gain_in); + demodulatorThread->setAGC(true); + } + } else { + audioThread->setGain(gain_in); + } } float DemodulatorInstance::getGain() { - return audioThread->getGain(); + return currentAudioGain; } bool DemodulatorInstance::isFollow() { diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index bbb4841..b0b8682 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -87,18 +87,19 @@ private: void checkBandwidth(); std::atomic label; // - bool terminated; // - bool demodTerminated; // - bool audioTerminated; // - bool preDemodTerminated; - std::atomic active; - std::atomic squelch; - std::atomic stereo; + std::atomic_bool terminated; // + std::atomic_bool demodTerminated; // + std::atomic_bool audioTerminated; // + std::atomic_bool preDemodTerminated; + std::atomic_bool active; + std::atomic_bool squelch; + std::atomic_bool stereo; - long long currentFrequency; - int currentBandwidth; - int currentDemodType; - int currentOutputDevice; - int currentAudioSampleRate; - bool follow, tracking; + std::atomic_llong currentFrequency; + std::atomic_int currentBandwidth; + std::atomic_int currentDemodType; + std::atomic_int currentOutputDevice; + std::atomic_int currentAudioSampleRate; + std::atomic currentAudioGain; + std::atomic_bool follow, tracking; }; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 7ffd6a9..00df8a7 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -14,7 +14,7 @@ DemodulatorThread::DemodulatorThread(DemodulatorThreadPostInputQueue* iqInputQueue, DemodulatorThreadControlCommandQueue *threadQueueControl, DemodulatorThreadCommandQueue* threadQueueNotify) : iqInputQueue(iqInputQueue), audioVisOutputQueue(NULL), audioOutputQueue(NULL), iqAutoGain(NULL), amOutputCeil(1), amOutputCeilMA(1), amOutputCeilMAA( - 1), stereo(false), terminated( + 1), stereo(false), agcEnabled(true), terminated( false), demodulatorType(DEMOD_TYPE_FM), threadQueueNotify(threadQueueNotify), threadQueueControl(threadQueueControl), squelchLevel(0), signalLevel( 0), squelchEnabled(false), audioSampleRate(0) { @@ -171,8 +171,16 @@ void DemodulatorThread::threadMain() { currentSignalLevel = agc_crcf_get_signal_level(iqAutoGain); } + std::vector *inputData; + + if (agcEnabled) { + inputData = &agcData; + } else { + inputData = &inp->data; + } + if (demodulatorType == DEMOD_TYPE_FM) { - freqdem_demodulate_block(demodFM, &agcData[0], bufSize, &demodOutputData[0]); + freqdem_demodulate_block(demodFM, &(*inputData)[0], bufSize, &demodOutputData[0]); } else if (demodulatorType == DEMOD_TYPE_RAW) { // do nothing here.. } else { @@ -180,20 +188,20 @@ void DemodulatorThread::threadMain() { switch (demodulatorType.load()) { case DEMOD_TYPE_LSB: for (int i = 0; i < bufSize; i++) { // Reject upper band - resamp2_cccf_filter_execute(ssbFilt,inp->data[i],&x,&y); + resamp2_cccf_filter_execute(ssbFilt,(*inputData)[i],&x,&y); ampmodem_demodulate(demodAM, x, &demodOutputData[i]); } break; case DEMOD_TYPE_USB: for (int i = 0; i < bufSize; i++) { // Reject lower band - resamp2_cccf_filter_execute(ssbFilt,inp->data[i],&x,&y); + resamp2_cccf_filter_execute(ssbFilt,(*inputData)[i],&x,&y); ampmodem_demodulate(demodAM, y, &demodOutputData[i]); } break; case DEMOD_TYPE_AM: case DEMOD_TYPE_DSB: for (int i = 0; i < bufSize; i++) { - ampmodem_demodulate(demodAM, inp->data[i], &demodOutputData[i]); + ampmodem_demodulate(demodAM, (*inputData)[i], &demodOutputData[i]); } break; } @@ -317,8 +325,8 @@ void DemodulatorThread::threadMain() { } ati->data.resize(numAudioWritten * 2); for (int i = 0; i < numAudioWritten; i++) { - ati->data[i * 2] = agcData[i].real; - ati->data[i * 2 + 1] = agcData[i].imag; + ati->data[i * 2] = (*inputData)[i].real; + ati->data[i * 2 + 1] = (*inputData)[i].imag; } } else if (stereo && inp->sampleRate >= 100000) { ati->channels = 2; @@ -351,8 +359,6 @@ void DemodulatorThread::threadMain() { ati->peak = p; } } - - audioOutputQueue->push(ati); } } @@ -372,8 +378,8 @@ void DemodulatorThread::threadMain() { if (demodulatorType == DEMOD_TYPE_RAW) { for (int i = 0; i < stereoSize / 2; i++) { - ati_vis->data[i] = ati->data[i * 2] * 0.75; - ati_vis->data[i + stereoSize / 2] = ati->data[i * 2 + 1] * 0.75; + ati_vis->data[i] = agcData[i].real * 0.75; + ati_vis->data[i + stereoSize / 2] = agcData[i].imag * 0.75; } } else { for (int i = 0; i < stereoSize / 2; i++) { @@ -403,6 +409,11 @@ void DemodulatorThread::threadMain() { ati_vis->busy_update.unlock(); } + + if (ati != NULL) { + audioOutputQueue->push(ati); + } + if (!threadQueueControl->empty()) { int newDemodType = DEMOD_TYPE_NULL; @@ -513,16 +524,25 @@ void DemodulatorThread::terminate() { } void DemodulatorThread::setStereo(bool state) { - stereo = state; + stereo.store(state); std::cout << "Stereo " << (state ? "Enabled" : "Disabled") << std::endl; } bool DemodulatorThread::isStereo() { - return stereo; + return stereo.load(); } +void DemodulatorThread::setAGC(bool state) { + agcEnabled.store(state); +} + +bool DemodulatorThread::getAGC() { + return agcEnabled.load(); +} + + float DemodulatorThread::getSignalLevel() { - return signalLevel; + return signalLevel.load(); } void DemodulatorThread::setSquelchLevel(float signal_level_in) { diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index f9d013b..be6cf69 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -31,6 +31,9 @@ public: void setStereo(bool state); bool isStereo(); + void setAGC(bool state); + bool getAGC(); + float getSignalLevel(); void setSquelchLevel(float signal_level_in); float getSquelchLevel(); @@ -72,9 +75,10 @@ protected: float amOutputCeilMA; float amOutputCeilMAA; - std::atomic stereo; - std::atomic terminated; - std::atomic demodulatorType; + std::atomic_bool stereo; + std::atomic_bool agcEnabled; + std::atomic_bool terminated; + std::atomic_int demodulatorType; int audioSampleRate; DemodulatorThreadCommandQueue* threadQueueNotify; From 57e988572f7b45cd5f7590dffe857ee51e0b2911 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 19 Jul 2015 23:19:10 -0400 Subject: [PATCH 8/8] type updates --- src/CubicSDRDefs.h | 2 +- src/audio/AudioThread.h | 12 ++++++------ src/demod/DemodulatorPreThread.h | 4 ++-- src/demod/DemodulatorWorkerThread.h | 2 +- src/sdr/SDRPostThread.h | 4 ++-- src/sdr/SDRThread.h | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index c40a0b1..2656f85 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -53,5 +53,5 @@ public: return refCount.load(); } protected: - std::atomic refCount; + std::atomic_int refCount; }; diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index 7adfa6f..2e2adbf 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -52,12 +52,12 @@ public: AudioThreadInput *currentInput; AudioThreadInputQueue *inputQueue; - std::atomic audioQueuePtr; - std::atomic underflowCount; - std::atomic terminated; - std::atomic initialized; - std::atomic active; - std::atomic outputDevice; + std::atomic_uint audioQueuePtr; + std::atomic_uint underflowCount; + std::atomic_bool terminated; + std::atomic_bool initialized; + std::atomic_bool active; + std::atomic_int outputDevice; std::atomic gain; AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify); diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 632c4c9..b5e5ec2 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -68,8 +68,8 @@ protected: nco_crcf freqShifter; int shiftFrequency; - std::atomic terminated; - std::atomic initialized; + std::atomic_bool terminated; + std::atomic_bool initialized; DemodulatorWorkerThread *workerThread; std::thread *t_Worker; diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 989b048..86c5baf 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -93,5 +93,5 @@ protected: DemodulatorThreadWorkerCommandQueue *commandQueue; DemodulatorThreadWorkerResultQueue *resultQueue; - std::atomic terminated; + std::atomic_bool terminated; }; diff --git a/src/sdr/SDRPostThread.h b/src/sdr/SDRPostThread.h index 11d3f2f..a1aed7d 100644 --- a/src/sdr/SDRPostThread.h +++ b/src/sdr/SDRPostThread.h @@ -31,10 +31,10 @@ protected: std::mutex busy_demod; std::vector demodulators; - std::atomic terminated; + std::atomic_bool terminated; iirfilt_crcf dcFilter; int num_vis_samples; - std::atomic swapIQ; + std::atomic_bool swapIQ; private: std::vector _lut; diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index 9bea334..67318a9 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -149,10 +149,10 @@ public: protected: std::atomic sampleRate; - std::atomic offset; + std::atomic_llong offset; std::atomic commandQueue; std::atomic iqDataOutQueue; - std::atomic terminated; - std::atomic deviceId; + std::atomic_bool terminated; + std::atomic_int deviceId; };