From d2dbb2ff11843c46b5f23e3bcc261d4e631703bb Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 16:47:35 -0400 Subject: [PATCH 1/7] OSX re-tweak, might need a more accurate frame timer for windows.. --- src/AppFrame.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 9d59c67..bf29cb6 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -405,7 +405,14 @@ void AppFrame::initDeviceParams(std::string deviceId) { if (!frame_timer.IsRunning()) { // frame rate = 1000 / 30 = 33ms + +// windows needs a bit more time or it lags? +#ifdef _WIN32 frame_timer.Start(25); +#else + frame_timer.Start(33); +#endif + } } From 6ae02bee9c1e52059e002e49bb5b6fd76f69c575 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 18:07:06 -0400 Subject: [PATCH 2/7] Frame timer too jittery for anything but OSX, back to throttling which looks nicer.. --- src/AppFrame.cpp | 27 +++++++++++++-------------- src/AppFrame.h | 2 +- src/CubicSDRDefs.h | 2 +- src/sdr/SDRPostThread.cpp | 5 +++++ src/visual/MeterCanvas.cpp | 3 ++- src/visual/ModeSelectorCanvas.cpp | 3 ++- src/visual/ScopeCanvas.cpp | 3 ++- src/visual/SpectrumCanvas.cpp | 3 ++- src/visual/TuningCanvas.cpp | 2 ++ src/visual/WaterfallCanvas.cpp | 3 ++- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index bf29cb6..e0745ec 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -35,7 +35,7 @@ EVT_CLOSE(AppFrame::OnClose) EVT_MENU(wxID_ANY, AppFrame::OnMenu) EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread) EVT_IDLE(AppFrame::OnIdle) -EVT_TIMER(FRAME_TIMER_ID, AppFrame::OnTimer) +//EVT_TIMER(FRAME_TIMER_ID, AppFrame::OnTimer) wxEND_EVENT_TABLE() AppFrame::AppFrame() : @@ -407,11 +407,11 @@ void AppFrame::initDeviceParams(std::string deviceId) { // frame rate = 1000 / 30 = 33ms // windows needs a bit more time or it lags? -#ifdef _WIN32 - frame_timer.Start(25); -#else - frame_timer.Start(33); -#endif +//#ifdef _WIN32 +// frame_timer.Start(25); +//#else +// frame_timer.Start(15); +//#endif } } @@ -608,10 +608,10 @@ void AppFrame::OnThread(wxCommandEvent& event) { } void AppFrame::OnIdle(wxIdleEvent& event) { - event.Skip(); -} - -void AppFrame::OnTimer(wxTimerEvent& event) { +// event.Skip(); +//} +// +//void AppFrame::OnTimer(wxTimerEvent& event) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); @@ -768,9 +768,8 @@ void AppFrame::OnTimer(wxTimerEvent& event) { while (!wproc->isInputEmpty()) { wproc->run(); } - - scopeCanvas->Refresh(); + /* scopeCanvas->Refresh(); waterfallCanvas->Refresh(); spectrumCanvas->Refresh(); @@ -792,9 +791,9 @@ void AppFrame::OnTimer(wxTimerEvent& event) { } if (spectrumAvgMeter->getMouseTracker()->mouseInView()) { spectrumAvgMeter->Refresh(); - } + } */ - event.Skip(); + event.RequestMore(); } void AppFrame::saveSession(std::string fileName) { diff --git a/src/AppFrame.h b/src/AppFrame.h index 7194068..fd9eac6 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -69,7 +69,7 @@ private: void OnClose(wxCloseEvent& event); void OnNewWindow(wxCommandEvent& event); void OnIdle(wxIdleEvent& event); - void OnTimer(wxTimerEvent& event); +// void OnTimer(wxTimerEvent& event); ScopeCanvas *scopeCanvas; SpectrumCanvas *spectrumCanvas; diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index fb96a68..b2c326a 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -33,4 +33,4 @@ const char filePathSeparator = #define DEFAULT_DEMOD_TYPE 1 #define DEFAULT_DEMOD_BW 200000 -#define DEFAULT_WATERFALL_LPS 24 \ No newline at end of file +#define DEFAULT_WATERFALL_LPS 30 \ No newline at end of file diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 4efc143..5658615 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -91,6 +91,7 @@ void SDRPostThread::run() { iqDataInQueue->pop(data_in); // std::lock_guard < std::mutex > lock(data_in->m_mutex); + int num_vis_samples = this->num_vis_samples; if (data_in && data_in->data.size()) { int dataSize = data_in->data.size()/2; @@ -120,6 +121,10 @@ void SDRPostThread::run() { visualDataOut->busy_rw.lock(); visualDataOut->setRefCount(1); + if (num_vis_samples > data_in->data.size()) { + num_vis_samples = data_in->data.size(); + } + if (visualDataOut->data.size() < num_vis_samples) { if (visualDataOut->data.capacity() < num_vis_samples) { visualDataOut->data.reserve(num_vis_samples); diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index 423fc20..07e7984 100644 --- a/src/visual/MeterCanvas.cpp +++ b/src/visual/MeterCanvas.cpp @@ -79,7 +79,8 @@ void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { } void MeterCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } void MeterCanvas::OnMouseMoved(wxMouseEvent& event) { diff --git a/src/visual/ModeSelectorCanvas.cpp b/src/visual/ModeSelectorCanvas.cpp index 98172b5..5058291 100644 --- a/src/visual/ModeSelectorCanvas.cpp +++ b/src/visual/ModeSelectorCanvas.cpp @@ -72,7 +72,8 @@ void ModeSelectorCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { } void ModeSelectorCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } void ModeSelectorCanvas::OnMouseMoved(wxMouseEvent& event) { diff --git a/src/visual/ScopeCanvas.cpp b/src/visual/ScopeCanvas.cpp index 1063c16..a4cd4be 100644 --- a/src/visual/ScopeCanvas.cpp +++ b/src/visual/ScopeCanvas.cpp @@ -87,7 +87,8 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { } void ScopeCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } ScopeRenderDataQueue *ScopeCanvas::getInputQueue() { diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index f07ae9c..f21a6a8 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -85,7 +85,8 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void SpectrumCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index cb618f6..23f15a4 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -252,6 +252,8 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) { dragging = false; } } + Refresh(); + event.RequestMore(); } void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 51d1723..892b17f 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -347,7 +347,8 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { } } void WaterfallCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { From 8bce6329820049ae27d39139ec905ab9f6dfc65d Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 18:16:53 -0400 Subject: [PATCH 3/7] Add some sleep to AppFrame idle to prevent it from chewing up too much CPU while minimized --- src/AppFrame.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index e0745ec..5930a5c 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -769,6 +769,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) { wproc->run(); } + usleep(5000); /* scopeCanvas->Refresh(); waterfallCanvas->Refresh(); From 33d51b2bff7b40fd7753edee1647ef2cdc3723c8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 19:39:11 -0400 Subject: [PATCH 4/7] Improve input response time, balance visuals, fix a bug --- src/AppFrame.cpp | 24 +++++------------------- src/AppFrame.h | 4 ---- src/CubicSDRDefs.h | 2 +- src/sdr/SDRPostThread.cpp | 4 ++-- src/visual/WaterfallCanvas.cpp | 31 +++++++++++++++++++------------ src/visual/WaterfallCanvas.h | 1 + 6 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 5930a5c..614b2e5 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -35,11 +35,10 @@ EVT_CLOSE(AppFrame::OnClose) EVT_MENU(wxID_ANY, AppFrame::OnMenu) EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread) EVT_IDLE(AppFrame::OnIdle) -//EVT_TIMER(FRAME_TIMER_ID, AppFrame::OnTimer) wxEND_EVENT_TABLE() AppFrame::AppFrame() : - wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL), frame_timer(this, FRAME_TIMER_ID) { + wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { #ifdef __linux__ SetIcon(wxICON(cubicsdr)); @@ -261,7 +260,7 @@ AppFrame::AppFrame() : // sampleRateMenuItems[wxID_BANDWIDTH_3000M] = menu->AppendRadioItem(wxID_BANDWIDTH_3000M, "3.0M"); sampleRateMenuItems[wxID_BANDWIDTH_3200M] = menu->AppendRadioItem(wxID_BANDWIDTH_3200M, "3.2M"); - sampleRateMenuItems[wxID_BANDWIDTH_2400M]->Check(true); + sampleRateMenuItems[wxID_BANDWIDTH_2048M]->Check(true); menuBar->Append(menu, wxT("&Input Bandwidth")); @@ -402,18 +401,6 @@ void AppFrame::initDeviceParams(std::string deviceId) { if (devConfig->getIQSwap()) { iqSwapMenuItem->Check(); } - - if (!frame_timer.IsRunning()) { - // frame rate = 1000 / 30 = 33ms - -// windows needs a bit more time or it lags? -//#ifdef _WIN32 -// frame_timer.Start(25); -//#else -// frame_timer.Start(15); -//#endif - - } } @@ -608,10 +595,6 @@ void AppFrame::OnThread(wxCommandEvent& event) { } void AppFrame::OnIdle(wxIdleEvent& event) { -// event.Skip(); -//} -// -//void AppFrame::OnTimer(wxTimerEvent& event) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); @@ -769,6 +752,9 @@ void AppFrame::OnIdle(wxIdleEvent& event) { wproc->run(); } + waterfallCanvas->processInputQueue(); + demodWaterfallCanvas->processInputQueue(); + usleep(5000); /* scopeCanvas->Refresh(); diff --git a/src/AppFrame.h b/src/AppFrame.h index fd9eac6..3531de5 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -50,8 +50,6 @@ #define wxID_AUDIO_BANDWIDTH_BASE 9000 #define wxID_AUDIO_DEVICE_MULTIPLIER 50 -#define FRAME_TIMER_ID 1000 - // Define a new frame type class AppFrame: public wxFrame { public: @@ -69,7 +67,6 @@ private: void OnClose(wxCloseEvent& event); void OnNewWindow(wxCommandEvent& event); void OnIdle(wxIdleEvent& event); -// void OnTimer(wxTimerEvent& event); ScopeCanvas *scopeCanvas; SpectrumCanvas *spectrumCanvas; @@ -96,7 +93,6 @@ private: wxMenuItem *iqSwapMenuItem; std::string currentSessionFile; - wxTimer frame_timer; FFTDataDistributor fftDistrib; DemodulatorThreadInputQueue fftQueue; diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index b2c326a..677e68b 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -27,7 +27,7 @@ const char filePathSeparator = #define BUF_SIZE (16384*6) -#define DEFAULT_SAMPLE_RATE 2400000 +#define DEFAULT_SAMPLE_RATE 2048000 #define DEFAULT_FFT_SIZE 2048 #define DEFAULT_DEMOD_TYPE 1 diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 5658615..7a999f9 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -121,8 +121,8 @@ void SDRPostThread::run() { visualDataOut->busy_rw.lock(); visualDataOut->setRefCount(1); - if (num_vis_samples > data_in->data.size()) { - num_vis_samples = data_in->data.size(); + if (num_vis_samples > dataOut.size()) { + num_vis_samples = dataOut.size(); } if (visualDataOut->data.size() < num_vis_samples) { diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 892b17f..2a52a11 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -68,6 +68,25 @@ void WaterfallCanvas::attachSpectrumCanvas(SpectrumCanvas *canvas_in) { spectrumCanvas = canvas_in; } +void WaterfallCanvas::processInputQueue() { + if (!glContext) { + return; + } + glContext->SetCurrent(*this); + + while (!visualDataQueue.empty()) { + SpectrumVisualData *vData; + + visualDataQueue.pop(vData); + + if (vData) { + waterfallPanel.setPoints(vData->spectrum_points); + waterfallPanel.step(); + vData->decRefCount(); + } + } +} + void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); @@ -139,18 +158,6 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glContext->SetCurrent(*this); initGLExtensions(); glViewport(0, 0, ClientSize.x, ClientSize.y); - - while (!visualDataQueue.empty()) { - SpectrumVisualData *vData; - - visualDataQueue.pop(vData); - - if (vData) { - waterfallPanel.setPoints(vData->spectrum_points); - waterfallPanel.step(); - vData->decRefCount(); - } - } glContext->BeginDraw(0,0,0); diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index b570ffb..2f51ec3 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -26,6 +26,7 @@ public: DragState getNextDragState(); void attachSpectrumCanvas(SpectrumCanvas *canvas_in); + void processInputQueue(); SpectrumVisualDataQueue *getVisualDataQueue(); private: From 9de7bc95fbae8abd0334b6a453c403fc9da0bef3 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 20:05:57 -0400 Subject: [PATCH 5/7] meter visual fix, tuner refresh fix --- src/AppFrame.cpp | 12 ++++++++---- src/visual/MeterCanvas.cpp | 12 ++++++++++-- src/visual/MeterCanvas.h | 3 +++ src/visual/TuningCanvas.cpp | 4 +++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 614b2e5..890aa25 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -106,6 +106,7 @@ AppFrame::AppFrame() : demodGainMeter = new MeterCanvas(this, attribList); demodGainMeter->setMax(2.0); demodGainMeter->setHelpTip("Current Demodulator Gain Level. Click / Drag to set Gain level."); + demodGainMeter->setShowUserInput(false); demodTray->Add(demodGainMeter, 1, wxEXPAND | wxALL, 0); vbox->Add(demodTray, 12, wxEXPAND | wxALL, 0); @@ -118,8 +119,9 @@ AppFrame::AppFrame() : spectrumAvgMeter = new MeterCanvas(this, attribList); spectrumAvgMeter->setMax(3.0); - spectrumAvgMeter->setInputValue(1.0); - + spectrumAvgMeter->setLevel(1.0); + spectrumAvgMeter->setShowUserInput(false); + spectrumSizer->Add(spectrumCanvas, 63, wxEXPAND | wxALL, 0); spectrumSizer->AddSpacer(1); spectrumSizer->Add(spectrumAvgMeter, 1, wxEXPAND | wxALL, 0); @@ -142,7 +144,8 @@ AppFrame::AppFrame() : waterfallSpeedMeter = new MeterCanvas(this, attribList); waterfallSpeedMeter->setMax(sqrt(1024)); - waterfallSpeedMeter->setInputValue(sqrt(DEFAULT_WATERFALL_LPS)); + waterfallSpeedMeter->setLevel(sqrt(DEFAULT_WATERFALL_LPS)); + waterfallSpeedMeter->setShowUserInput(false); wfSizer->Add(waterfallCanvas, 63, wxEXPAND | wxALL, 0); wfSizer->AddSpacer(1); @@ -737,7 +740,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) { } if (waterfallSpeedMeter->inputChanged()) { - int val = (int)waterfallSpeedMeter->getInputValue(); + float val = waterfallSpeedMeter->getInputValue(); + waterfallSpeedMeter->setLevel(val); fftDistrib.setLinesPerSecond((int)ceil(val*val)); wxGetApp().getWaterfallVisualQueue()->set_max_num_items((int)ceil(val*val)); } diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index 07e7984..46153a0 100644 --- a/src/visual/MeterCanvas.cpp +++ b/src/visual/MeterCanvas.cpp @@ -25,7 +25,7 @@ EVT_ENTER_WINDOW(MeterCanvas::OnMouseEnterWindow) wxEND_EVENT_TABLE() MeterCanvas::MeterCanvas(wxWindow *parent, int *attribList) : - InteractiveCanvas(parent, attribList), level(0), level_max(1), inputValue(0), userInputValue(0) { + InteractiveCanvas(parent, attribList), level(0), level_max(1), inputValue(0), userInputValue(0), showUserInput(true) { glContext = new MeterContext(this, &wxGetApp().GetContext(this)); } @@ -58,6 +58,10 @@ float MeterCanvas::getInputValue() { return userInputValue; } +void MeterCanvas::setShowUserInput(bool showUserInput) { + this->showUserInput = showUserInput; +} + void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); const wxSize ClientSize = GetClientSize(); @@ -68,11 +72,15 @@ void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glViewport(0, 0, ClientSize.x, ClientSize.y); glContext->DrawBegin(); + glContext->Draw(ThemeMgr::mgr.currentTheme->generalBackground.r, ThemeMgr::mgr.currentTheme->generalBackground.g, ThemeMgr::mgr.currentTheme->generalBackground.b, 0.5, 1.0); + if (mouseTracker.mouseInView()) { glContext->Draw(0.4, 0.4, 0.4, 0.5, mouseTracker.getMouseY()); } glContext->Draw(ThemeMgr::mgr.currentTheme->meterLevel.r, ThemeMgr::mgr.currentTheme->meterLevel.g, ThemeMgr::mgr.currentTheme->meterLevel.b, 0.5, level / level_max); - glContext->Draw(ThemeMgr::mgr.currentTheme->meterValue.r, ThemeMgr::mgr.currentTheme->meterValue.g, ThemeMgr::mgr.currentTheme->meterValue.b, 0.5, userInputValue / level_max); + if (showUserInput) { + glContext->Draw(ThemeMgr::mgr.currentTheme->meterValue.r, ThemeMgr::mgr.currentTheme->meterValue.g, ThemeMgr::mgr.currentTheme->meterValue.b, 0.5, userInputValue / level_max); + } glContext->DrawEnd(); SwapBuffers(); diff --git a/src/visual/MeterCanvas.h b/src/visual/MeterCanvas.h index a6968b1..0cc97cd 100644 --- a/src/visual/MeterCanvas.h +++ b/src/visual/MeterCanvas.h @@ -26,6 +26,7 @@ public: void setInputValue(float slider_in); bool inputChanged(); float getInputValue(); + void setShowUserInput(bool showUserInput); void setHelpTip(std::string tip); @@ -48,6 +49,8 @@ private: float inputValue; float userInputValue; + bool showUserInput; + std::string helpTip; // wxDECLARE_EVENT_TABLE(); diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index 23f15a4..8a85ac4 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -252,7 +252,9 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) { dragging = false; } } - Refresh(); + if (mouseTracker.mouseInView() || changed()) { + Refresh(); + } event.RequestMore(); } From 1d5a2f1ac7b08d85387da962fb0e191c52f01405 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 21:45:02 -0400 Subject: [PATCH 6/7] Fix for an initial priming overload and visuals memory leak --- src/CubicSDR.cpp | 4 +++- src/IOThread.h | 5 +++++ src/demod/DemodulatorThread.cpp | 2 +- src/sdr/SDRPostThread.cpp | 10 ++++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index ca1eef3..2283d57 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -78,9 +78,11 @@ bool CubicSDR::OnInit() { scopeProcessor.setInput(pipeAudioVisualData); // I/Q Data - pipeSDRIQData = new SDRThreadIQDataQueue; + pipeSDRIQData = new SDRThreadIQDataQueue(); pipeSDRCommand = new SDRThreadCommandQueue(); + pipeSDRIQData->set_max_num_items(1); + sdrThread = new SDRThread(); sdrThread->setInputQueue("SDRCommandQueue",pipeSDRCommand); sdrThread->setOutputQueue("IQDataOutput",pipeSDRIQData); diff --git a/src/IOThread.h b/src/IOThread.h index 734b37a..743635c 100644 --- a/src/IOThread.h +++ b/src/IOThread.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "ThreadQueue.h" @@ -63,6 +64,10 @@ public: return buf; } +// if (outputBuffers.size() > 100) { +// std::cout << "Buffer over 100.." << std::endl; +// } + buf = new BufferType(); outputBuffers.push_back(buf); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index d987a15..becc261 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -94,7 +94,7 @@ void DemodulatorThread::run() { while (!terminated) { DemodulatorThreadPostIQData *inp; iqInputQueue->pop(inp); - std::lock_guard < std::mutex > lock(inp->m_mutex); +// std::lock_guard < std::mutex > lock(inp->m_mutex); int bufSize = inp->data.size(); diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 7a999f9..a9955cd 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -86,6 +86,8 @@ void SDRPostThread::run() { std::vector fpData; std::vector dataOut; + iqDataInQueue->set_max_num_items(30); + while (!terminated) { SDRThreadIQData *data_in; @@ -203,8 +205,12 @@ void SDRPostThread::run() { } if (iqDataOutQueue != NULL) { - iqDataOutQueue->push(demodDataOut); - pushedData = true; + if (!iqDataOutQueue->full()) { + iqDataOutQueue->push(demodDataOut); + pushedData = true; + } else { + demodDataOut->decRefCount(); + } } if (!pushedData && iqDataOutQueue == NULL) { From b345dc7516de0130021c8984a16a82bfef2bb2a8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 12 Aug 2015 22:14:14 -0400 Subject: [PATCH 7/7] Spectrum averaging control now functional --- src/AppFrame.cpp | 12 +++++++++--- src/process/SpectrumVisualProcessor.cpp | 12 ++++++++---- src/process/SpectrumVisualProcessor.h | 3 +++ src/sdr/SDRPostThread.cpp | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 890aa25..07c919b 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -118,8 +118,8 @@ AppFrame::AppFrame() : wxGetApp().getSpectrumProcesor()->attachOutput(spectrumCanvas->getVisualDataQueue()); spectrumAvgMeter = new MeterCanvas(this, attribList); - spectrumAvgMeter->setMax(3.0); - spectrumAvgMeter->setLevel(1.0); + spectrumAvgMeter->setMax(1.0); + spectrumAvgMeter->setLevel(0.65); spectrumAvgMeter->setShowUserInput(false); spectrumSizer->Add(spectrumCanvas, 63, wxEXPAND | wxALL, 0); @@ -712,9 +712,15 @@ void AppFrame::OnIdle(wxIdleEvent& event) { wxGetApp().getScopeProcessor()->run(); wxGetApp().getSpectrumDistributor()->run(); - + SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcesor(); + if (spectrumAvgMeter->inputChanged()) { + float val = spectrumAvgMeter->getInputValue(); + spectrumAvgMeter->setLevel(val); + proc->setFFTAverageRate(val); + } + proc->setView(spectrumCanvas->getViewState()); proc->setBandwidth(spectrumCanvas->getBandwidth()); proc->setCenterFrequency(spectrumCanvas->getCenterFrequency()); diff --git a/src/process/SpectrumVisualProcessor.cpp b/src/process/SpectrumVisualProcessor.cpp index 932477b..34b2543 100644 --- a/src/process/SpectrumVisualProcessor.cpp +++ b/src/process/SpectrumVisualProcessor.cpp @@ -15,6 +15,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last fft_ceil_ma = fft_ceil_maa = 100.0; fft_floor_ma = fft_floor_maa = 0.0; desiredInputSize = 0; + fft_average_rate = 0.65; } SpectrumVisualProcessor::~SpectrumVisualProcessor() { @@ -29,6 +30,9 @@ void SpectrumVisualProcessor::setView(bool bView) { is_view.store(bView); } +void SpectrumVisualProcessor::setFFTAverageRate(float fftAverageRate) { + this->fft_average_rate = fftAverageRate; +} void SpectrumVisualProcessor::setCenterFrequency(long long centerFreq_in) { centerFreq.store(centerFreq_in); @@ -260,11 +264,11 @@ void SpectrumVisualProcessor::process() { for (int i = 0, iMax = fftSize; i < iMax; i++) { if (is_view.load()) { - fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65; - fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65; + fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * fft_average_rate; + fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * fft_average_rate; } else { - fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * 0.65; - fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * 0.65; + fft_result_maa[i] += (fft_result_ma[i] - fft_result_maa[i]) * fft_average_rate; + fft_result_ma[i] += (fft_result[i] - fft_result_ma[i]) * fft_average_rate; } if (fft_result_maa[i] > fft_ceil) { diff --git a/src/process/SpectrumVisualProcessor.h b/src/process/SpectrumVisualProcessor.h index 2ee8ba2..134d61f 100644 --- a/src/process/SpectrumVisualProcessor.h +++ b/src/process/SpectrumVisualProcessor.h @@ -21,6 +21,8 @@ public: bool isView(); void setView(bool bView); + void setFFTAverageRate(float fftAverageRate); + void setCenterFrequency(long long centerFreq_in); long long getCenterFrequency(); @@ -50,6 +52,7 @@ private: float fft_ceil_ma, fft_ceil_maa; float fft_floor_ma, fft_floor_maa; + float fft_average_rate; std::vector fft_result; std::vector fft_result_ma; diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index a9955cd..30944cf 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -86,7 +86,7 @@ void SDRPostThread::run() { std::vector fpData; std::vector dataOut; - iqDataInQueue->set_max_num_items(30); + iqDataInQueue->set_max_num_items(0); while (!terminated) { SDRThreadIQData *data_in;