From 524cfbe0df8f128d132579362c4f654d3a84976e Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 2 Feb 2015 20:10:55 -0500 Subject: [PATCH 1/6] Demodulator options persist and apply to newly created --- src/AppFrame.cpp | 24 ++++++++-- src/CubicSDRDefs.h | 2 + src/demod/DemodulatorMgr.cpp | 77 +++++++++++++++++++++++++++++++-- src/demod/DemodulatorMgr.h | 25 +++++++++++ src/demod/DemodulatorThread.cpp | 21 ++++++++- src/visual/PrimaryGLContext.cpp | 2 +- src/visual/TuningCanvas.cpp | 17 +++++--- src/visual/TuningContext.cpp | 2 +- src/visual/WaterfallCanvas.cpp | 29 ++++++------- 9 files changed, 167 insertions(+), 32 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index bacb829..92a71b8 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -48,6 +48,7 @@ AppFrame::AppFrame() : demodModeSelector->addChoice(DEMOD_TYPE_LSB, "LSB"); demodModeSelector->addChoice(DEMOD_TYPE_USB, "USB"); demodModeSelector->addChoice(DEMOD_TYPE_DSB, "DSB"); + demodModeSelector->setSelection(DEMOD_TYPE_FM); demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0); // demodTray->AddSpacer(2); @@ -209,11 +210,11 @@ AppFrame::AppFrame() : devName.append(" (In Use?)"); } - menu->AppendRadioItem(wxID_DEVICE_ID+p, devName)->Check(wxGetApp().getDevice() == p); + menu->AppendRadioItem(wxID_DEVICE_ID + p, devName)->Check(wxGetApp().getDevice() == p); p++; } - menuBar->Append(menu,wxT("&Device")); + menuBar->Append(menu, wxT("&Device")); } SetMenuBar(menuBar); @@ -322,8 +323,8 @@ void AppFrame::OnMenu(wxCommandEvent& event) { } std::vector *devs = wxGetApp().getDevices(); - if (event.GetId() >= wxID_DEVICE_ID && event.GetId() <= wxID_DEVICE_ID+devs->size()) { - wxGetApp().setDevice(event.GetId()-wxID_DEVICE_ID); + if (event.GetId() >= wxID_DEVICE_ID && event.GetId() <= wxID_DEVICE_ID + devs->size()) { + wxGetApp().setDevice(event.GetId() - wxID_DEVICE_ID); } } @@ -389,6 +390,21 @@ void AppFrame::OnIdle(wxIdleEvent& event) { demodGainMeter->setLevel(demodGainMeter->getInputValue()); } activeDemodulator = demod; + } else { + DemodulatorMgr *mgr = &wxGetApp().getDemodMgr(); + + int dSelection = demodModeSelector->getSelection(); + if (dSelection != -1 && dSelection != mgr->getLastDemodulatorType()) { + mgr->setLastDemodulatorType(dSelection); + } + demodGainMeter->setLevel(mgr->getLastGain()); + if (demodSignalMeter->inputChanged()) { + mgr->setLastSquelchLevel(demodSignalMeter->getInputValue()); + } + if (demodGainMeter->inputChanged()) { + mgr->setLastGain(demodGainMeter->getInputValue()); + demodGainMeter->setLevel(demodGainMeter->getInputValue()); + } } if (!waterfallCanvas->HasFocus()) { diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 88b5cbe..4829712 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -28,6 +28,8 @@ const char filePathSeparator = #define DEFAULT_FREQ 100000000 #define AUDIO_FREQUENCY 44100 +#define DEFAULT_DEMOD_TYPE 1 +#define DEFAULT_DEMOD_BW 200000 #include #include diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 8883d0b..0801915 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -6,7 +6,8 @@ #include DemodulatorMgr::DemodulatorMgr() : - activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL) { + activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL), lastBandwidth(DEFAULT_DEMOD_BW), lastDemodType( + DEFAULT_DEMOD_TYPE), lastGain(1.0), lastSquelch(0), lastSquelchEnabled(false), lastStereo(false) { } @@ -91,6 +92,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo } else { lastActiveDemodulator = demod; } + updateLastState(); } if (activeVisualDemodulator) { @@ -117,9 +119,7 @@ DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() { } DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() { - if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) { - lastActiveDemodulator = activeDemodulator; - } + updateLastState(); return lastActiveDemodulator; } @@ -142,3 +142,72 @@ void DemodulatorMgr::garbageCollect() { } } +void DemodulatorMgr::updateLastState() { + if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) { + lastActiveDemodulator = activeDemodulator; + } + + if (lastActiveDemodulator) { + lastBandwidth = lastActiveDemodulator->getBandwidth(); + lastDemodType = lastActiveDemodulator->getDemodulatorType(); + lastSquelchEnabled = lastActiveDemodulator->isSquelchEnabled(); + lastSquelch = lastActiveDemodulator->getSquelchLevel(); + lastGain = lastActiveDemodulator->getGain(); + lastStereo = lastActiveDemodulator->isStereo(); + } + +} + +int DemodulatorMgr::getLastBandwidth() const { + return lastBandwidth; +} + +void DemodulatorMgr::setLastBandwidth(int lastBandwidth) { + if (lastBandwidth < 1500) { + lastBandwidth = 1500; + } else if (lastBandwidth > wxGetApp().getSampleRate()) { + lastBandwidth = wxGetApp().getSampleRate(); + } + this->lastBandwidth = lastBandwidth; +} + +int DemodulatorMgr::getLastDemodulatorType() const { + return lastDemodType; +} + +void DemodulatorMgr::setLastDemodulatorType(int lastDemodType) { + this->lastDemodType = lastDemodType; +} + +float DemodulatorMgr::getLastGain() const { + return lastGain; +} + +void DemodulatorMgr::setLastGain(float lastGain) { + this->lastGain = lastGain; +} + +float DemodulatorMgr::getLastSquelchLevel() const { + return lastSquelch; +} + +void DemodulatorMgr::setLastSquelchLevel(float lastSquelch) { + this->lastSquelch = lastSquelch; +} + +bool DemodulatorMgr::isLastSquelchEnabled() const { + return lastSquelchEnabled; +} + +void DemodulatorMgr::setLastSquelchEnabled(bool lastSquelchEnabled) { + this->lastSquelchEnabled = lastSquelchEnabled; +} + +bool DemodulatorMgr::isLastStereo() const { + return lastStereo; +} + +void DemodulatorMgr::setLastStereo(bool lastStereo) { + this->lastStereo = lastStereo; +} + diff --git a/src/demod/DemodulatorMgr.h b/src/demod/DemodulatorMgr.h index bfa233e..24baeb1 100644 --- a/src/demod/DemodulatorMgr.h +++ b/src/demod/DemodulatorMgr.h @@ -22,8 +22,27 @@ public: DemodulatorInstance *getActiveDemodulator(); DemodulatorInstance *getLastActiveDemodulator(); + int getLastBandwidth() const; + void setLastBandwidth(int lastBandwidth); + + int getLastDemodulatorType() const; + void setLastDemodulatorType(int lastDemodType); + + float getLastGain() const; + void setLastGain(float lastGain); + + float getLastSquelchLevel() const; + void setLastSquelchLevel(float lastSquelch); + + bool isLastSquelchEnabled() const; + void setLastSquelchEnabled(bool lastSquelchEnabled); + + bool isLastStereo() const; + void setLastStereo(bool lastStereo); + private: void garbageCollect(); + void updateLastState(); std::vector demods; std::vector demods_deleted; @@ -31,4 +50,10 @@ private: DemodulatorInstance *lastActiveDemodulator; DemodulatorInstance *activeVisualDemodulator; + int lastBandwidth; + int lastDemodType; + bool lastSquelchEnabled; + float lastSquelch; + float lastGain; + bool lastStereo; }; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 7a2d027..17d6f69 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -56,7 +56,7 @@ void DemodulatorThread::threadMain() { } unsigned int h_len = estimate_req_filter_len(ft, As); - float *h = new float[h_len]; + float *h = new float[h_len]; liquid_firdes_kaiser(h_len, firStereoCutoff, As, mu, h); firStereoLeft = firfilt_rrrf_create(h, h_len); @@ -83,7 +83,7 @@ void DemodulatorThread::threadMain() { float ssbAs = 120.0f; // stop-band attenuation [dB] h_len = estimate_req_filter_len(ssbFt, ssbAs); - float *ssb_h=new float[h_len]; + float *ssb_h = new float[h_len]; liquid_firdes_kaiser(h_len, 0.25, ssbAs, 0.0, ssb_h); firfilt_crcf firSSB = firfilt_crcf_create(ssb_h, h_len); @@ -99,6 +99,23 @@ void DemodulatorThread::threadMain() { std::cout << "Demodulator thread started.." << std::endl; + switch (demodulatorType) { + case DEMOD_TYPE_FM: + break; + case DEMOD_TYPE_LSB: + demodAM = demodAM_USB; + break; + case DEMOD_TYPE_USB: + demodAM = demodAM_LSB; + break; + case DEMOD_TYPE_DSB: + demodAM = demodAM_DSB; + break; + case DEMOD_TYPE_AM: + demodAM = demodAM_DSB_CSP; + break; + } + terminated = false; while (!terminated) { diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index fab77ba..7f9e59a 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -275,7 +275,7 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b, long long bw = 0; if (!demod) { - bw = defaultDemodParams.bandwidth; + bw = wxGetApp().getDemodMgr().getLastBandwidth(); } else { bw = demod->getBandwidth(); } diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index 67e8225..4996131 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -48,7 +48,7 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { if (activeDemod != NULL) { glContext->DrawDemodFreqBw(activeDemod->getFrequency(), activeDemod->getBandwidth(), wxGetApp().getFrequency()); } else { - glContext->DrawDemodFreqBw(0, 0, wxGetApp().getFrequency()); + glContext->DrawDemodFreqBw(0, wxGetApp().getDemodMgr().getLastBandwidth(), wxGetApp().getFrequency()); } if (mouseTracker.mouseDown()) { @@ -76,10 +76,17 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) { wxGetApp().getFrequency() + (int) (dragAccum * fabs(dragAccum * 10.0) * fabs(dragAccum * 10.0) * (float) wxGetApp().getSampleRate())); } else if (fabs(moveVal) >= 1.0) { - if (uxDown < -0.275 && activeDemod != NULL) { - activeDemod->setFrequency(activeDemod->getFrequency() + (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal))); - } else if (activeDemod != NULL) { - activeDemod->setBandwidth(activeDemod->getBandwidth() + (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal))); + if (uxDown < -0.275) { + if (activeDemod != NULL) { + activeDemod->setFrequency(activeDemod->getFrequency() + (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal))); + } + } else { + int amt = (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal)); + if (activeDemod != NULL) { + activeDemod->setBandwidth(activeDemod->getBandwidth() + amt); + } else { + wxGetApp().getDemodMgr().setLastBandwidth(wxGetApp().getDemodMgr().getLastBandwidth() + amt); + } } } diff --git a/src/visual/TuningContext.cpp b/src/visual/TuningContext.cpp index 8105c48..f348c70 100644 --- a/src/visual/TuningContext.cpp +++ b/src/visual/TuningContext.cpp @@ -82,7 +82,7 @@ void TuningContext::DrawDemodFreqBw(long long freq, unsigned int bw, long long c glColor3f(ThemeMgr::mgr.currentTheme->text.r, ThemeMgr::mgr.currentTheme->text.g, ThemeMgr::mgr.currentTheme->text.b); getFont(fontSize).drawString("Freq: ", -0.75, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER); - if (bw) { + if (freq) { freqStr.str(""); freqStr << std::fixed << freq << " Hz"; } else { diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 9987259..6431201 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -753,6 +753,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { mouseTracker.setHorizDragLock(false); DemodulatorInstance *demod; + DemodulatorMgr *mgr = &wxGetApp().getDemodMgr(); if (mouseTracker.getOriginDeltaMouseX() == 0 && mouseTracker.getOriginDeltaMouseY() == 0) { float pos = mouseTracker.getMouseX(); @@ -767,14 +768,12 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { demod = wxGetApp().getDemodMgr().newThread(); demod->setFrequency(freq); - if (DemodulatorInstance *last = wxGetApp().getDemodMgr().getLastActiveDemodulator()) { - demod->setBandwidth(last->getBandwidth()); - demod->setDemodulatorType(last->getDemodulatorType()); - demod->setSquelchLevel(last->getSquelchLevel()); - demod->setSquelchEnabled(last->isSquelchEnabled()); - demod->setStereo(last->isStereo()); - demod->setGain(last->getGain()); - } + demod->setBandwidth(mgr->getLastBandwidth()); + demod->setDemodulatorType(mgr->getLastDemodulatorType()); + demod->setSquelchLevel(mgr->getLastSquelchLevel()); + demod->setSquelchEnabled(mgr->isLastSquelchEnabled()); + demod->setStereo(mgr->isLastStereo()); + demod->setGain(mgr->getLastGain()); demod->run(); @@ -828,13 +827,13 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { demod = wxGetApp().getDemodMgr().newThread(); demod->setFrequency(freq); demod->setBandwidth(bw); - if (DemodulatorInstance *last = wxGetApp().getDemodMgr().getLastActiveDemodulator()) { - demod->setDemodulatorType(last->getDemodulatorType()); - demod->setSquelchLevel(last->getSquelchLevel()); - demod->setSquelchEnabled(last->isSquelchEnabled()); - demod->setStereo(last->isStereo()); - demod->setGain(last->getGain()); - } + + demod->setDemodulatorType(mgr->getLastDemodulatorType()); + demod->setSquelchLevel(mgr->getLastSquelchLevel()); + demod->setSquelchEnabled(mgr->isLastSquelchEnabled()); + demod->setStereo(mgr->isLastStereo()); + demod->setGain(mgr->getLastGain()); + demod->run(); wxGetApp().bindDemodulator(demod); From 1a9f7d31b7c781e0e01b1020d3f286caf3f35eea Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 3 Feb 2015 12:25:02 -0500 Subject: [PATCH 2/6] missing atomic load --- src/demod/DemodulatorThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 17d6f69..9c7d07e 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -99,7 +99,7 @@ void DemodulatorThread::threadMain() { std::cout << "Demodulator thread started.." << std::endl; - switch (demodulatorType) { + switch (demodulatorType.load()) { case DEMOD_TYPE_FM: break; case DEMOD_TYPE_LSB: From ec3e851354361e5375bad168148a11cf69eea91f Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Tue, 3 Feb 2015 19:11:30 -0500 Subject: [PATCH 3/6] Waterfall bandwidth control and new demod hover state tweaks --- src/visual/WaterfallCanvas.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 6431201..831b704 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -656,7 +656,7 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { } else { setStatusText("Click and drag to set the current demodulator range."); } - } else if (demodsHover->size()) { + } else if (demodsHover->size() && !shiftDown) { int hovered = -1; long near_dist = getBandwidth(); @@ -674,7 +674,7 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { near_dist = dist; } - if (dist <= halfBw && dist >= (int) ((float) halfBw / (float) 1.5)) { + if (dist <= halfBw && dist >= (int) ((float) halfBw / (1.5 - (0.65 * (1.0-(float)(wxGetApp().getSampleRate() - getBandwidth())/(float)wxGetApp().getSampleRate()))))) { long edge_dist = abs(halfBw - dist); if (edge_dist < near_dist) { activeDemodulator = demod; From a8070ca953f2cb62ebd6854db4fd51cb691df5fa Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 4 Feb 2015 18:10:42 -0500 Subject: [PATCH 4/6] Destroy / recreate audio thread on demodulator activate / deactivate -- fixes DirectSound issues --- CMakeLists.txt | 4 +-- src/audio/AudioThread.cpp | 53 +++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66dfae3..ced47f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,8 +65,8 @@ IF (WIN32) # Audio device selection is not mandatory, dummy audio device is used if none are compiled in. # Can also compile support for more than one simultaneously. - set(USE_AUDIO_DS OFF CACHE BOOL "Include support for DirectSound") - set(USE_AUDIO_WASAPI ON CACHE BOOL "Include support for WASAPI Audio") + set(USE_AUDIO_DS ON CACHE BOOL "Include support for DirectSound") + set(USE_AUDIO_WASAPI OFF CACHE BOOL "Include support for WASAPI Audio") # TODO: # set(USE_AUDIO_ASIO OFF CACHE BOOL "Include support for ASIO Audio") diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 54eb656..d17c68b 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -168,7 +168,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu if (!src->currentInput) { src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -183,11 +183,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -202,11 +202,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -223,11 +223,11 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu src->currentInput->decRefCount(); src->currentInput = NULL; } - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->inputQueue->pop(src->currentInput); - if (src->terminated) { + if (src->terminated || !src->active) { return 1; } src->audioQueuePtr = 0; @@ -326,7 +326,7 @@ void AudioThread::setupDevice(int deviceId) { } else { deviceController[parameters.deviceId]->bindThread(this); } - active = true; + #else if (dac.isStreamOpen()) { if (dac.isStreamRunning()) { @@ -335,16 +335,29 @@ void AudioThread::setupDevice(int deviceId) { dac.closeStream(); } - dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); - dac.startStream(); + active = true; + + if (deviceId != -1) { + dac.openStream(¶meters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); + dac.startStream(); + } else { + AudioThreadInput *dummy; + while (!inputQueue->empty()) { // flush queue + inputQueue->pop(dummy); + if (dummy) { + dummy->decRefCount(); + } + } + } #endif } catch (RtAudioError& e) { e.printMessage(); return; } - - outputDevice = deviceId; + if (deviceId != -1) { + outputDevice = deviceId; + } } int AudioThread::getOutputDevice() { @@ -440,6 +453,7 @@ bool AudioThread::isActive() { } void AudioThread::setActive(bool state) { + #ifdef USE_MIXER AudioThreadInput *dummy; if (state && !active) { @@ -459,8 +473,21 @@ void AudioThread::setActive(bool state) { } } } +#else + if (state && !active && outputDevice != -1) { + active = state; + AudioThreadCommand command; + command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; + command.int_value = outputDevice; + cmdQueue.push(command); + } else if (active && !state) { + active = state; + AudioThreadCommand command; + command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; + command.int_value = -1; + } + #endif - active = state; } AudioThreadCommandQueue *AudioThread::getCommandQueue() { From 590d494fea156401340d61aee662246406877673 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 5 Feb 2015 20:01:21 -0500 Subject: [PATCH 5/6] Fix for broken OSX audio --- src/audio/AudioThread.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index d17c68b..e74f236 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -326,6 +326,7 @@ void AudioThread::setupDevice(int deviceId) { } else { deviceController[parameters.deviceId]->bindThread(this); } + active = true; #else if (dac.isStreamOpen()) { @@ -473,6 +474,7 @@ void AudioThread::setActive(bool state) { } } } + active = state; #else if (state && !active && outputDevice != -1) { active = state; From 4218fb73a0cfe7364330555776c28ebd2923ca7f Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 5 Feb 2015 20:54:04 -0500 Subject: [PATCH 6/6] Demod visual activation when entering/leaving view --- src/AppFrame.cpp | 7 ++++++- src/demod/DemodulatorMgr.cpp | 14 +++++++++++++- src/sdr/SDRPostThread.cpp | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 92a71b8..9a68285 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -34,7 +34,7 @@ EVT_IDLE(AppFrame::OnIdle) wxEND_EVENT_TABLE() AppFrame::AppFrame() : - wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { +wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL); @@ -405,6 +405,11 @@ void AppFrame::OnIdle(wxIdleEvent& event) { mgr->setLastGain(demodGainMeter->getInputValue()); demodGainMeter->setLevel(demodGainMeter->getInputValue()); } + + if (wxGetApp().getFrequency() != demodWaterfallCanvas->getCenterFrequency()) { + demodWaterfallCanvas->setCenterFrequency(wxGetApp().getFrequency()); + demodSpectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); + } } if (!waterfallCanvas->HasFocus()) { diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 0801915..d26a9e3 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -115,6 +115,9 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo } DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() { + if (activeDemodulator && !activeDemodulator->isActive()) { + activeDemodulator = getLastActiveDemodulator(); + } return activeDemodulator; } @@ -144,7 +147,16 @@ void DemodulatorMgr::garbageCollect() { void DemodulatorMgr::updateLastState() { if (std::find(demods.begin(), demods.end(), lastActiveDemodulator) == demods.end()) { - lastActiveDemodulator = activeDemodulator; + if (activeDemodulator && activeDemodulator->isActive()) { + lastActiveDemodulator = activeDemodulator; + } else if (activeDemodulator && !activeDemodulator->isActive()){ + activeDemodulator = NULL; + lastActiveDemodulator = NULL; + } + } + + if (lastActiveDemodulator && !lastActiveDemodulator->isActive()) { + lastActiveDemodulator = NULL; } if (lastActiveDemodulator) { diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 1fa8896..81c9ef4 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -196,6 +196,9 @@ void SDRPostThread::threadMain() { } } else if (!demod->isActive()) { demod->setActive(true); + if (wxGetApp().getDemodMgr().getLastActiveDemodulator() == NULL) { + wxGetApp().getDemodMgr().setActiveDemodulator(demod); + } } if (!demod->isActive()) {