From b828b3636ffad2421cc734c3178c7deec9bf37b4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 31 Mar 2016 21:32:50 -0400 Subject: [PATCH] Add 'Reduced CPU Usage' menu option and config entry. --- src/AppConfig.cpp | 17 +++++++++++- src/AppConfig.h | 5 +++- src/AppFrame.cpp | 35 +++++++++++++++++++++++-- src/AppFrame.h | 4 +++ src/process/SpectrumVisualProcessor.cpp | 8 ++++++ src/process/SpectrumVisualProcessor.h | 1 + 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index 53e4e2d..506c4c9 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -199,6 +199,7 @@ AppConfig::AppConfig() : configName("") { winH.store(0); winMax.store(false); showTips.store(true); + lowPerfMode.store(false); themeId.store(0); snap.store(1); centerFreq.store(100000000); @@ -265,6 +266,14 @@ bool AppConfig::getShowTips() { return showTips.load(); } +void AppConfig::setLowPerfMode(bool show) { + lowPerfMode.store(show); +} + +bool AppConfig::getLowPerfMode() { + return lowPerfMode.load(); +} + wxRect *AppConfig::getWindow() { wxRect *r = NULL; if (winH.load() && winW.load()) { @@ -360,6 +369,7 @@ bool AppConfig::save() { *window_node->newChild("max") = winMax.load(); *window_node->newChild("tips") = showTips.load(); + *window_node->newChild("low_perf_mode") = lowPerfMode.load(); *window_node->newChild("theme") = themeId.load(); *window_node->newChild("snap") = snap.load(); *window_node->newChild("center_freq") = centerFreq.load(); @@ -444,7 +454,7 @@ bool AppConfig::load() { if (cfg.rootNode()->hasAnother("window")) { int x,y,w,h; - int max,tips; + int max,tips,lpm; DataNode *win_node = cfg.rootNode()->getNext("window"); @@ -470,6 +480,11 @@ bool AppConfig::load() { showTips.store(tips?true:false); } + if (win_node->hasAnother("low_perf_mode")) { + win_node->getNext("low_perf_mode")->element()->get(lpm); + lowPerfMode.store(lpm?true:false); + } + if (win_node->hasAnother("theme")) { int theme; win_node->getNext("theme")->element()->get(theme); diff --git a/src/AppConfig.h b/src/AppConfig.h index dabadb1..4b1198d 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -73,6 +73,9 @@ public: void setShowTips(bool show); bool getShowTips(); + void setLowPerfMode(bool lpm); + bool getLowPerfMode(); + void setTheme(int themeId); int getTheme(); @@ -127,7 +130,7 @@ private: std::string configName; std::map deviceConfig; std::atomic_int winX,winY,winW,winH; - std::atomic_bool winMax, showTips; + std::atomic_bool winMax, showTips, lowPerfMode; std::atomic_int themeId; std::atomic_llong snap; std::atomic_llong centerFreq; diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index a09f068..b6cac84 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -605,6 +605,14 @@ void AppFrame::updateDeviceParams() { showTipMenuItem = newSettingsMenu->AppendCheckItem(wxID_SET_TIPS, "Show Hover Tips"); showTipMenuItem->Check(wxGetApp().getConfig()->getShowTips()); + lowPerfMode = wxGetApp().getConfig()->getLowPerfMode(); + lowPerfMenuItem = newSettingsMenu->AppendCheckItem(wxID_LOW_PERF, "Reduce CPU Usage"); + if (lowPerfMode) { + lowPerfMenuItem->Check(true); + } + + newSettingsMenu->AppendSeparator(); + newSettingsMenu->Append(wxID_SET_FREQ_OFFSET, "Frequency Offset"); if (devInfo->hasCORR(SOAPY_SDR_RX, 0)) { @@ -626,6 +634,10 @@ void AppFrame::updateDeviceParams() { SoapySDR::ArgInfoList::const_iterator args_i; settingArgs = soapyDev->getSettingInfo(); + + if (settingArgs.size()) { + newSettingsMenu->AppendSeparator(); + } for (args_i = settingArgs.begin(); args_i != settingArgs.end(); args_i++) { SoapySDR::ArgInfo arg = (*args_i); @@ -781,6 +793,21 @@ void AppFrame::OnMenu(wxCommandEvent& event) { wxGetApp().setDevice(dev); } } + } else if (event.GetId() == wxID_LOW_PERF) { + lowPerfMode = lowPerfMenuItem->IsChecked(); + wxGetApp().getConfig()->setLowPerfMode(lowPerfMode); + +// long srate = wxGetApp().getSampleRate(); +// if (srate > CHANNELIZER_RATE_MAX && lowPerfMode) { +// if (wxGetApp().getSpectrumProcessor()->getFFTSize() != 1024) { +// setMainWaterfallFFTSize(1024); +// } +// } else if (srate > CHANNELIZER_RATE_MAX) { +// if (wxGetApp().getSpectrumProcessor()->getFFTSize() != 2048) { +// setMainWaterfallFFTSize(2048); +// } +// } + } else if (event.GetId() == wxID_SET_TIPS ) { if (wxGetApp().getConfig()->getShowTips()) { wxGetApp().getConfig()->setShowTips(false); @@ -1462,9 +1489,13 @@ void AppFrame::OnIdle(wxIdleEvent& event) { #endif if (!this->IsActive()) { - std::this_thread::sleep_for(std::chrono::milliseconds(25)); + std::this_thread::sleep_for(std::chrono::milliseconds(30)); } else { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + if (lowPerfMode) { + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + } else { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + } } event.RequestMore(); diff --git a/src/AppFrame.h b/src/AppFrame.h index 2e06889..5b89b6f 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -31,6 +31,7 @@ #define wxID_SDR_DEVICES 2008 #define wxID_AGC_CONTROL 2009 #define wxID_SDR_START_STOP 2010 +#define wxID_LOW_PERF 2011 #define wxID_MAIN_SPLITTER 2050 #define wxID_VIS_SPLITTER 2051 @@ -134,6 +135,7 @@ private: wxMenu *sampleRateMenu; wxMenuItem *agcMenuItem; wxMenuItem *iqSwapMenuItem; + wxMenuItem *lowPerfMenuItem; wxMenu *settingsMenu; SoapySDR::ArgInfoList settingArgs; int settingsIdMax; @@ -152,6 +154,8 @@ private: ModemArgInfoList newModemArgs; wxMenuItem *showTipMenuItem; + bool lowPerfMode; + #ifdef USE_HAMLIB void enableRig(); void disableRig(); diff --git a/src/process/SpectrumVisualProcessor.cpp b/src/process/SpectrumVisualProcessor.cpp index 1a43af4..da8283f 100644 --- a/src/process/SpectrumVisualProcessor.cpp +++ b/src/process/SpectrumVisualProcessor.cpp @@ -201,6 +201,14 @@ void SpectrumVisualProcessor::setFFTSize(unsigned int fftSize_in) { fftSizeChanged.store(true); } +unsigned int SpectrumVisualProcessor::getFFTSize() { + if (fftSizeChanged.load()) { + return newFFTSize; + } + return fftSize.load(); +} + + void SpectrumVisualProcessor::setHideDC(bool hideDC) { this->hideDC.store(hideDC); } diff --git a/src/process/SpectrumVisualProcessor.h b/src/process/SpectrumVisualProcessor.h index 57f3036..59e9236 100644 --- a/src/process/SpectrumVisualProcessor.h +++ b/src/process/SpectrumVisualProcessor.h @@ -47,6 +47,7 @@ public: void setup(unsigned int fftSize); void setFFTSize(unsigned int fftSize); + unsigned int getFFTSize(); void setHideDC(bool hideDC); void setScaleFactor(float sf);