diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 9d59c67..1e621dd 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)); @@ -107,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,9 +118,10 @@ AppFrame::AppFrame() : wxGetApp().getSpectrumProcesor()->attachOutput(spectrumCanvas->getVisualDataQueue()); spectrumAvgMeter = new MeterCanvas(this, attribList); - spectrumAvgMeter->setMax(3.0); - spectrumAvgMeter->setInputValue(1.0); - + spectrumAvgMeter->setMax(1.0); + spectrumAvgMeter->setLevel(0.65); + spectrumAvgMeter->setShowUserInput(false); + spectrumSizer->Add(spectrumCanvas, 63, wxEXPAND | wxALL, 0); spectrumSizer->AddSpacer(1); spectrumSizer->Add(spectrumAvgMeter, 1, wxEXPAND | wxALL, 0); @@ -143,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); @@ -261,7 +263,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,11 +404,6 @@ void AppFrame::initDeviceParams(std::string deviceId) { if (devConfig->getIQSwap()) { iqSwapMenuItem->Check(); } - - if (!frame_timer.IsRunning()) { - // frame rate = 1000 / 30 = 33ms - frame_timer.Start(25); - } } @@ -601,10 +598,6 @@ void AppFrame::OnThread(wxCommandEvent& event) { } void AppFrame::OnIdle(wxIdleEvent& event) { - event.Skip(); -} - -void AppFrame::OnTimer(wxTimerEvent& event) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); @@ -719,9 +712,15 @@ void AppFrame::OnTimer(wxTimerEvent& 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()); @@ -747,7 +746,8 @@ void AppFrame::OnTimer(wxTimerEvent& 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)); } @@ -761,33 +761,15 @@ void AppFrame::OnTimer(wxTimerEvent& event) { while (!wproc->isInputEmpty()) { wproc->run(); } + + waterfallCanvas->processInputQueue(); + demodWaterfallCanvas->processInputQueue(); +#ifndef _WIN32 + usleep(5000); +#endif - scopeCanvas->Refresh(); - - waterfallCanvas->Refresh(); - spectrumCanvas->Refresh(); - - demodWaterfallCanvas->Refresh(); - demodSpectrumCanvas->Refresh(); - - demodSignalMeter->Refresh(); - demodGainMeter->Refresh(); - - if (demodTuner->getMouseTracker()->mouseInView() || demodTuner->changed()) { - demodTuner->Refresh(); - } - if (demodModeSelector->getMouseTracker()->mouseInView()) { - demodModeSelector->Refresh(); - } - if (waterfallSpeedMeter->getMouseTracker()->mouseInView()) { - waterfallSpeedMeter->Refresh(); - } - 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..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/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/CubicSDRDefs.h b/src/CubicSDRDefs.h index fb96a68..677e68b 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -27,10 +27,10 @@ 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 #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/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/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 39f97ad..4f6374d 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: double fft_ceil_ma, fft_ceil_maa; double 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 4efc143..30944cf 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -86,11 +86,14 @@ void SDRPostThread::run() { std::vector fpData; std::vector dataOut; + iqDataInQueue->set_max_num_items(0); + while (!terminated) { SDRThreadIQData *data_in; 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 +123,10 @@ void SDRPostThread::run() { visualDataOut->busy_rw.lock(); visualDataOut->setRefCount(1); + if (num_vis_samples > dataOut.size()) { + num_vis_samples = dataOut.size(); + } + if (visualDataOut->data.size() < num_vis_samples) { if (visualDataOut->data.capacity() < num_vis_samples) { visualDataOut->data.reserve(num_vis_samples); @@ -198,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) { diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index 423fc20..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,18 +72,23 @@ 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(); } void MeterCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } void MeterCanvas::OnMouseMoved(wxMouseEvent& event) { 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/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..8a85ac4 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -252,6 +252,10 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) { dragging = false; } } + if (mouseTracker.mouseInView() || changed()) { + Refresh(); + } + event.RequestMore(); } void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 51d1723..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); @@ -347,7 +354,8 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { } } void WaterfallCanvas::OnIdle(wxIdleEvent &event) { - event.Skip(); + Refresh(); + event.RequestMore(); } void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { 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: