From 9f945026b8a769ae033c09cde5781eb0f310b642 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 4 Jan 2015 17:11:20 -0500 Subject: [PATCH] Fix frequency related data types for >2Ghz --- CMakeLists.txt | 4 ++ src/AppFrame.cpp | 15 +++- src/AppFrame.h | 2 + src/CubicSDR.cpp | 6 +- src/CubicSDR.h | 6 +- src/audio/AudioThread.h | 2 +- src/demod/DemodDefs.h | 14 ++-- src/demod/DemodulatorInstance.cpp | 18 ++--- src/demod/DemodulatorInstance.h | 10 +-- src/demod/DemodulatorMgr.cpp | 10 +-- src/demod/DemodulatorMgr.h | 2 +- src/demod/DemodulatorPreThread.cpp | 12 ++-- src/demod/DemodulatorWorkerThread.h | 2 +- src/sdr/SDRPostThread.cpp | 4 +- src/sdr/SDRThread.cpp | 6 +- src/sdr/SDRThread.h | 10 +-- src/visual/InteractiveCanvas.cpp | 16 ++--- src/visual/InteractiveCanvas.h | 10 +-- src/visual/PrimaryGLContext.cpp | 8 +-- src/visual/PrimaryGLContext.h | 6 +- src/visual/SpectrumCanvas.cpp | 13 ++-- src/visual/SpectrumContext.cpp | 14 ++-- src/visual/SpectrumContext.h | 2 +- src/visual/TuningCanvas.cpp | 91 ++++++++++++++++++++++++ src/visual/TuningCanvas.h | 40 +++++++++++ src/visual/TuningContext.cpp | 87 +++++++++++++++++++++++ src/visual/TuningContext.h | 22 ++++++ src/visual/WaterfallCanvas.cpp | 103 +++++++++++++--------------- src/visual/WaterfallCanvas.h | 2 +- 29 files changed, 393 insertions(+), 144 deletions(-) create mode 100644 src/visual/TuningCanvas.cpp create mode 100644 src/visual/TuningCanvas.h create mode 100644 src/visual/TuningContext.cpp create mode 100644 src/visual/TuningContext.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d8d9868..72f8ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,8 @@ SET (cubicsdr_sources src/visual/InteractiveCanvas.cpp src/visual/MeterCanvas.cpp src/visual/MeterContext.cpp + src/visual/TuningCanvas.cpp + src/visual/TuningContext.cpp src/visual/ScopeCanvas.cpp src/visual/ScopeContext.cpp src/visual/SpectrumCanvas.cpp @@ -171,6 +173,8 @@ SET (cubicsdr_headers src/visual/InteractiveCanvas.h src/visual/MeterCanvas.h src/visual/MeterContext.h + src/visual/TuningCanvas.h + src/visual/TuningContext.h src/visual/ScopeCanvas.h src/visual/ScopeContext.h src/visual/SpectrumCanvas.h diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 8a4bde1..e1c5325 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -36,6 +36,7 @@ AppFrame::AppFrame() : wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodVisuals = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodTray = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL); demodSpectrumCanvas = new SpectrumCanvas(this, NULL); demodSpectrumCanvas->setup(1024); @@ -63,7 +64,15 @@ AppFrame::AppFrame() : demodTray->AddSpacer(2); scopeCanvas = new ScopeCanvas(this, NULL); - demodTray->Add(scopeCanvas, 30, wxEXPAND | wxALL, 0); + demodScopeTray->Add(scopeCanvas, 8, wxEXPAND | wxALL, 0); + + demodScopeTray->AddSpacer(2); + + demodTuner = new TuningCanvas(this, NULL); + demodTuner->setHelpTip("Testing tuner"); + demodScopeTray->Add(demodTuner, 1, wxEXPAND | wxALL, 0); + + demodTray->Add(demodScopeTray, 30, wxEXPAND | wxALL, 0); vbox->Add(demodTray, 2, wxEXPAND | wxALL, 0); vbox->AddSpacer(2); @@ -208,8 +217,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) { } if (demodWaterfallCanvas->getDragState() == WaterfallCanvas::WF_DRAG_NONE) { if (demod->getParams().frequency != demodWaterfallCanvas->getCenterFrequency()) { - demodWaterfallCanvas->setCenterFrequency(demod->getParams().frequency); - demodSpectrumCanvas->setCenterFrequency(demod->getParams().frequency); + demodWaterfallCanvas->setCenterFrequency(demod->getFrequency()); + demodSpectrumCanvas->setCenterFrequency(demod->getFrequency()); } unsigned int demodBw = (unsigned int) ceil((float) demod->getParams().bandwidth * 2.5); if (demodBw > SRATE / 2) { diff --git a/src/AppFrame.h b/src/AppFrame.h index b1b8804..4140676 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -7,6 +7,7 @@ #include "SpectrumCanvas.h" #include "WaterfallCanvas.h" #include "MeterCanvas.h" +#include "TuningCanvas.h" #include @@ -36,6 +37,7 @@ private: SpectrumCanvas *demodSpectrumCanvas; WaterfallCanvas *demodWaterfallCanvas; MeterCanvas *demodSignalMeter; + TuningCanvas *demodTuner; // event table DemodulatorInstance *activeDemodulator; diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index db46c29..dacf40c 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -100,17 +100,17 @@ PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) { return *glContext; } -void CubicSDR::setFrequency(unsigned int freq) { +void CubicSDR::setFrequency(long long freq) { if (freq < SRATE/2) { freq = SRATE/2; } frequency = freq; SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE); - command.int_value = freq; + command.llong_value = freq; threadCmdQueueSDR->push(command); } -int CubicSDR::getFrequency() { +long long CubicSDR::getFrequency() { return frequency; } diff --git a/src/CubicSDR.h b/src/CubicSDR.h index b84e23e..1355dcd 100644 --- a/src/CubicSDR.h +++ b/src/CubicSDR.h @@ -29,8 +29,8 @@ public: virtual bool OnInit(); virtual int OnExit(); - void setFrequency(unsigned int freq); - int getFrequency(); + void setFrequency(long long freq); + long long getFrequency(); DemodulatorThreadOutputQueue* getAudioVisualQueue(); DemodulatorThreadInputQueue* getIQVisualQueue(); @@ -44,7 +44,7 @@ private: DemodulatorMgr demodMgr; - unsigned int frequency; + long long frequency; SDRThread *sdrThread; SDRPostThread *sdrPostThread; diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index ea1e84f..d18b1e4 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -20,7 +20,7 @@ class AudioThreadInput: public ReferenceCounter { public: - int frequency; + long long frequency; int sampleRate; int channels; std::vector data; diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index fcc4ecc..5d16436 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -27,18 +27,18 @@ public: }; DemodulatorThreadCommand() : - cmd(DEMOD_THREAD_CMD_NULL), context(NULL), int_value(0) { + cmd(DEMOD_THREAD_CMD_NULL), context(NULL), llong_value(0) { } DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) : - cmd(cmd), context(NULL), int_value(0) { + cmd(cmd), context(NULL), llong_value(0) { } DemodulatorThreadCommandEnum cmd; void *context; - int int_value; + long long llong_value; }; class DemodulatorThreadControlCommand { @@ -57,7 +57,7 @@ public: class DemodulatorThreadIQData: public ReferenceCounter { public: - unsigned int frequency; + long long frequency; unsigned int bandwidth; std::vector data; @@ -91,7 +91,7 @@ public: class DemodulatorThreadAudioData: public ReferenceCounter { public: - unsigned int frequency; + long long frequency; unsigned int sampleRate; unsigned char channels; @@ -102,7 +102,7 @@ public: } - DemodulatorThreadAudioData(unsigned int frequency, unsigned int sampleRate, std::vector *data) : + DemodulatorThreadAudioData(long long frequency, unsigned int sampleRate, std::vector *data) : frequency(frequency), sampleRate(sampleRate), channels(1), data(data) { } @@ -119,7 +119,7 @@ typedef ThreadQueue DemodulatorThreadControlCom class DemodulatorThreadParameters { public: - unsigned int frequency; + long long frequency; unsigned int inputRate; unsigned int bandwidth; // set equal to disable second stage re-sampling? unsigned int audioSampleRate; diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 1291ba4..abc9e81 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(false), audioTerminated(false), demodTerminated( - false), preDemodTerminated(false), active(false), squelch(false), stereo(false), currentBandwidth(0), currentFrequency(0) { + false), preDemodTerminated(false), active(false), squelch(false), stereo(false), currentFrequency(0), currentBandwidth(0) { label = new std::string("Unnamed"); threadQueueDemod = new DemodulatorThreadInputQueue; @@ -36,6 +36,8 @@ void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQu } void DemodulatorInstance::run() { + currentFrequency = demodulatorPreThread->getParams().frequency; + t_Audio = new std::thread(&AudioThread::threadMain, audioThread); #ifdef __APPLE__ // Already using pthreads, might as well do some custom init.. @@ -63,10 +65,10 @@ void DemodulatorInstance::run() { active = true; } -void DemodulatorInstance::updateLabel(int freq) { +void DemodulatorInstance::updateLabel(long long freq) { std::stringstream newLabel; newLabel.precision(3); - newLabel << std::fixed << ((float) freq / 1000000.0); + newLabel << std::fixed << ((long double) freq / 1000000.0); setLabel(newLabel.str()); } @@ -234,7 +236,7 @@ void DemodulatorInstance::setBandwidth(int bw) { command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH; currentBandwidth = bw; checkBandwidth(); - command.int_value = currentBandwidth; + command.llong_value = currentBandwidth; threadQueueCommand->push(command); } demodulatorPreThread->getParams().bandwidth; @@ -247,21 +249,21 @@ int DemodulatorInstance::getBandwidth() { return currentBandwidth; } -void DemodulatorInstance::setFrequency(unsigned int freq) { - if (((long)freq - getBandwidth()/2) < SRATE/2) { +void DemodulatorInstance::setFrequency(long long freq) { + if ((freq - getBandwidth()/2) < SRATE/2) { freq = SRATE/2 - getBandwidth()/2; } if (demodulatorPreThread && threadQueueCommand) { DemodulatorThreadCommand command; command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY; currentFrequency = freq; - command.int_value = freq; + command.llong_value = freq; threadQueueCommand->push(command); } demodulatorPreThread->getParams().bandwidth; } -int DemodulatorInstance::getFrequency() { +long long DemodulatorInstance::getFrequency() { if (!currentFrequency) { currentFrequency = demodulatorPreThread->getParams().frequency; } diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index 0113196..eedaa5a 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -44,7 +44,7 @@ public: void setLabel(std::string labelStr); bool isTerminated(); - void updateLabel(int freq); + void updateLabel(long long freq); bool isActive(); void setActive(bool state); @@ -69,8 +69,8 @@ public: void setBandwidth(int bw); int getBandwidth(); - void setFrequency(unsigned int freq); - int getFrequency(); + void setFrequency(long long freq); + long long getFrequency(); private: void checkBandwidth(); @@ -84,7 +84,7 @@ private: std::atomic squelch; std::atomic stereo; - int currentDemodType; + long long currentFrequency; int currentBandwidth; - int currentFrequency; + int currentDemodType; }; diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 31069fb..7b32bab 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -62,17 +62,17 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) { garbageCollect(); } -std::vector *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) { +std::vector *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) { std::vector *foundDemods = new std::vector(); for (int i = 0, iMax = demods.size(); i < iMax; i++) { DemodulatorInstance *testDemod = demods[i]; - int freqTest = testDemod->getParams().frequency; - int bandwidthTest = testDemod->getParams().bandwidth; - int halfBandwidthTest = bandwidthTest / 2; + long long freqTest = testDemod->getParams().frequency; + long long bandwidthTest = testDemod->getParams().bandwidth; + long long halfBandwidthTest = bandwidthTest / 2; - int halfBuffer = bandwidth / 2; + long long halfBuffer = bandwidth / 2; if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) { foundDemods->push_back(testDemod); diff --git a/src/demod/DemodulatorMgr.h b/src/demod/DemodulatorMgr.h index 2bbb072..bfa233e 100644 --- a/src/demod/DemodulatorMgr.h +++ b/src/demod/DemodulatorMgr.h @@ -13,7 +13,7 @@ public: DemodulatorInstance *newThread(); std::vector &getDemodulators(); - std::vector *getDemodulatorsAt(int freq, int bandwidth); + std::vector *getDemodulatorsAt(long long freq, int bandwidth); void deleteThread(DemodulatorInstance *); void terminateAll(); diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 7980aba..0b6d3d2 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -84,17 +84,17 @@ void DemodulatorPreThread::threadMain() { commandQueue->pop(command); switch (command.cmd) { case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH: - if (command.int_value < 1500) { - command.int_value = 1500; + if (command.llong_value < 1500) { + command.llong_value = 1500; } - if (command.int_value > SRATE) { - command.int_value = SRATE; + if (command.llong_value > SRATE) { + command.llong_value = SRATE; } - bandwidthParams.bandwidth = command.int_value; + bandwidthParams.bandwidth = command.llong_value; bandwidthChanged = true; break; case DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY: - params.frequency = command.int_value; + params.frequency = command.llong_value; break; } } diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 96382c8..489652f 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -65,7 +65,7 @@ public: DemodulatorThreadCommandEnum cmd; - unsigned int frequency; + long long frequency; unsigned int inputRate; unsigned int bandwidth; unsigned int audioSampleRate; diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index b269d42..9be2080 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -132,7 +132,7 @@ void SDRPostThread::threadMain() { DemodulatorInstance *demod = *i; if (demod->getParams().frequency != data_in->frequency - && abs(data_in->frequency - demod->getParams().frequency) > (int) ((double) ((double) SRATE / 2.0))) { + && abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) { continue; } activeDemods++; @@ -166,7 +166,7 @@ void SDRPostThread::threadMain() { DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod; if (demod->getParams().frequency != data_in->frequency - && abs(data_in->frequency - demod->getParams().frequency) > (int) ((double) ((double) SRATE / 2.0))) { + && abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) { if (demod->isActive()) { demod->setActive(false); DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index ccb83e8..8f4e97c 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -110,7 +110,7 @@ void SDRThread::threadMain() { signed char buf[BUF_SIZE]; - unsigned int frequency = DEFAULT_FREQ; + long long frequency = DEFAULT_FREQ; unsigned int bandwidth = SRATE; rtlsdr_open(&dev, firstDevAvailable); @@ -137,7 +137,7 @@ void SDRThread::threadMain() { if (!cmdQueue->empty()) { bool freq_changed = false; - float new_freq; + long long new_freq; while (!cmdQueue->empty()) { SDRThreadCommand command; @@ -146,7 +146,7 @@ void SDRThread::threadMain() { switch (command.cmd) { case SDRThreadCommand::SDR_THREAD_CMD_TUNE: freq_changed = true; - new_freq = command.int_value; + new_freq = command.llong_value; if (new_freq < SRATE / 2) { new_freq = SRATE / 2; } diff --git a/src/sdr/SDRThread.h b/src/sdr/SDRThread.h index fcacda9..3c83870 100644 --- a/src/sdr/SDRThread.h +++ b/src/sdr/SDRThread.h @@ -21,22 +21,22 @@ public: }; SDRThreadCommand() : - cmd(SDR_THREAD_CMD_NULL), int_value(0) { + cmd(SDR_THREAD_CMD_NULL), llong_value(0) { } SDRThreadCommand(SDRThreadCommandEnum cmd) : - cmd(cmd), int_value(0) { + cmd(cmd), llong_value(0) { } SDRThreadCommandEnum cmd; - int int_value; + long long llong_value; }; class SDRThreadIQData: public ReferenceCounter { public: - unsigned int frequency; + long long frequency; unsigned int bandwidth; std::vector data; @@ -45,7 +45,7 @@ public: } - SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector *data) : + SDRThreadIQData(unsigned int bandwidth, long long frequency, std::vector *data) : frequency(frequency), bandwidth(bandwidth) { } diff --git a/src/visual/InteractiveCanvas.cpp b/src/visual/InteractiveCanvas.cpp index f50690b..204a808 100644 --- a/src/visual/InteractiveCanvas.cpp +++ b/src/visual/InteractiveCanvas.cpp @@ -27,7 +27,7 @@ InteractiveCanvas::InteractiveCanvas(wxWindow *parent, int *attribList) : InteractiveCanvas::~InteractiveCanvas() { } -void InteractiveCanvas::setView(int center_freq_in, int bandwidth_in) { +void InteractiveCanvas::setView(long long center_freq_in, int bandwidth_in) { isView = true; centerFreq = center_freq_in; bandwidth = bandwidth_in; @@ -41,23 +41,23 @@ void InteractiveCanvas::disableView() { lastBandwidth = 0; } -int InteractiveCanvas::getFrequencyAt(float x) { - int iqCenterFreq = getCenterFrequency(); - int iqBandwidth = getBandwidth(); - int freq = iqCenterFreq - (int) (0.5 * (float) iqBandwidth) + (int) ((float) x * (float) iqBandwidth); +long long InteractiveCanvas::getFrequencyAt(float x) { + long long iqCenterFreq = getCenterFrequency(); + long long iqBandwidth = getBandwidth(); + long long freq = iqCenterFreq - (long long)(0.5 * (long double) iqBandwidth) + ((long double) x * (long double) iqBandwidth); return freq; } -void InteractiveCanvas::setCenterFrequency(unsigned int center_freq_in) { +void InteractiveCanvas::setCenterFrequency(long long center_freq_in) { centerFreq = center_freq_in; } -unsigned int InteractiveCanvas::getCenterFrequency() { +long long InteractiveCanvas::getCenterFrequency() { if (isView) { return centerFreq; } else { - return (unsigned int) wxGetApp().getFrequency(); + return wxGetApp().getFrequency(); } } diff --git a/src/visual/InteractiveCanvas.h b/src/visual/InteractiveCanvas.h index bf80c01..6699d49 100644 --- a/src/visual/InteractiveCanvas.h +++ b/src/visual/InteractiveCanvas.h @@ -11,13 +11,13 @@ public: InteractiveCanvas(wxWindow *parent, int *attribList = NULL); ~InteractiveCanvas(); - int getFrequencyAt(float x); + long long getFrequencyAt(float x); - void setView(int center_freq_in, int bandwidth_in); + void setView(long long center_freq_in, int bandwidth_in); void disableView(); - void setCenterFrequency(unsigned int center_freq_in); - unsigned int getCenterFrequency(); + void setCenterFrequency(long long center_freq_in); + long long getCenterFrequency(); void setBandwidth(unsigned int bandwidth_in); unsigned int getBandwidth(); @@ -45,7 +45,7 @@ protected: bool altDown; bool ctrlDown; - unsigned int centerFreq; + long long centerFreq; unsigned int bandwidth; unsigned int lastBandwidth; diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index 990ceb3..cf48555 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -92,7 +92,7 @@ GLFont &PrimaryGLContext::getFont(GLFontSize esize) { return fonts[esize]; } -void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float g, float b, int center_freq, int srate) { +void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float g, float b, long long center_freq, long long srate) { if (!demod) { return; } @@ -153,7 +153,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float } -void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b, int center_freq, int srate) { +void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b, long long center_freq, long long srate) { if (!demod) { return; } @@ -246,10 +246,10 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f } -void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b, float w, int center_freq, int srate) { +void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b, float w, long long center_freq, long long srate) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); - int bw = 0; + long long bw = 0; if (!demod) { bw = defaultDemodParams.bandwidth; diff --git a/src/visual/PrimaryGLContext.h b/src/visual/PrimaryGLContext.h index 9635548..85e22af 100644 --- a/src/visual/PrimaryGLContext.h +++ b/src/visual/PrimaryGLContext.h @@ -23,9 +23,9 @@ public: void BeginDraw(); void EndDraw(); - void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0, int center_freq = -1, int srate = SRATE); - void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, int center_freq = -1, int srate = SRATE); - void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, int center_freq = -1, int srate = SRATE); + void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0, long long center_freq = -1, long long srate = SRATE); + void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = SRATE); + void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = SRATE); static GLFont &getFont(GLFontSize esize); diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index e080708..e6e17c0 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -179,7 +179,7 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { int freqChange = mouseTracker.getDeltaMouseX() * getBandwidth(); if (freqChange != 0) { - unsigned int freq = wxGetApp().getFrequency(); + long long freq = wxGetApp().getFrequency(); if (isView) { centerFreq = centerFreq - freqChange; @@ -187,19 +187,18 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { waterfallCanvas->setCenterFrequency(centerFreq); } - long bw = (long) bandwidth; - long bwOfs = (centerFreq > freq) ? ((long) bandwidth / 2) : (-(long) bandwidth / 2); - long freqEdge = ((long) centerFreq + bwOfs); + long long bwOfs = (centerFreq > freq) ? ((long long) bandwidth / 2) : (-(long long) bandwidth / 2); + long long freqEdge = centerFreq + bwOfs; - if (abs((long) freq - freqEdge) > (SRATE / 2)) { - freqChange = -((centerFreq > freq) ? (freqEdge - (long)freq - (SRATE / 2)) : (freqEdge - (long)freq + (SRATE / 2))); + if (abs(freq - freqEdge) > (SRATE / 2)) { + freqChange = -((centerFreq > freq) ? (freqEdge - freq - (SRATE / 2)) : (freqEdge - freq + (SRATE / 2))); } else { freqChange = 0; } } if (freqChange) { - if ((long)freq - freqChange < SRATE/2) { + if (freq - freqChange < SRATE/2) { freq = SRATE/2; } else { freq -= freqChange; diff --git a/src/visual/SpectrumContext.cpp b/src/visual/SpectrumContext.cpp index 2a5207a..b8de9fc 100644 --- a/src/visual/SpectrumContext.cpp +++ b/src/visual/SpectrumContext.cpp @@ -15,7 +15,7 @@ SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedCont } -void SpectrumContext::Draw(std::vector &points, int freq, int bandwidth) { +void SpectrumContext::Draw(std::vector &points, long long freq, int bandwidth) { glDisable(GL_TEXTURE_2D); glColor3f(1.0, 1.0, 1.0); @@ -37,14 +37,14 @@ void SpectrumContext::Draw(std::vector &points, int freq, int bandwidth) float viewHeight = (float) vp[3]; float viewWidth = (float) vp[2]; - float leftFreq = (float) freq - ((float) bandwidth / 2.0); - float rightFreq = leftFreq + (float) bandwidth; + long long leftFreq = (float) freq - ((float) bandwidth / 2.0); + long long rightFreq = leftFreq + (float) bandwidth; - float firstMhz = floor(leftFreq / 1000000.0) * 1000000.0; - float mhzStart = ((firstMhz - leftFreq) / (rightFreq - leftFreq)) * 2.0; - float mhzStep = (100000.0 / (rightFreq - leftFreq)) * 2.0; + long long firstMhz = (leftFreq / 1000000) * 1000000; + long double mhzStart = ((long double)(firstMhz - leftFreq) / (long double)(rightFreq - leftFreq)) * 2.0; + long double mhzStep = (100000.0 / (long double)(rightFreq - leftFreq)) * 2.0; - double currentMhz = trunc(floor(firstMhz / 1000000.0)); + long double currentMhz = trunc(floor(firstMhz / 1000000.0)); std::stringstream label; label.precision(2); diff --git a/src/visual/SpectrumContext.h b/src/visual/SpectrumContext.h index 91c900c..feb0ce2 100644 --- a/src/visual/SpectrumContext.h +++ b/src/visual/SpectrumContext.h @@ -11,7 +11,7 @@ class SpectrumContext: public PrimaryGLContext { public: SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext); - void Draw(std::vector &points, int freq, int bandwidth); + void Draw(std::vector &points, long long freq, int bandwidth); private: int fft_size; diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp new file mode 100644 index 0000000..a8f8ff3 --- /dev/null +++ b/src/visual/TuningCanvas.cpp @@ -0,0 +1,91 @@ +#include "TuningCanvas.h" + +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#if !wxUSE_GLCANVAS +#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library" +#endif + +#include "CubicSDR.h" +#include "CubicSDRDefs.h" +#include "AppFrame.h" +#include + +wxBEGIN_EVENT_TABLE(TuningCanvas, wxGLCanvas) EVT_PAINT(TuningCanvas::OnPaint) +EVT_IDLE(TuningCanvas::OnIdle) +EVT_MOTION(TuningCanvas::OnMouseMoved) +EVT_LEFT_DOWN(TuningCanvas::OnMouseDown) +EVT_LEFT_UP(TuningCanvas::OnMouseReleased) +EVT_LEAVE_WINDOW(TuningCanvas::OnMouseLeftWindow) +EVT_ENTER_WINDOW(TuningCanvas::OnMouseEnterWindow) +wxEND_EVENT_TABLE() + +TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) : + InteractiveCanvas(parent, attribList) { + + glContext = new TuningContext(this, &wxGetApp().GetContext(this)); +} + +TuningCanvas::~TuningCanvas() { + +} + +void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { + wxPaintDC dc(this); + const wxSize ClientSize = GetClientSize(); + + glContext->SetCurrent(*this); + glViewport(0, 0, ClientSize.x, ClientSize.y); + + glContext->DrawBegin(); + + DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); + + if (activeDemod != NULL) { + glContext->DrawDemodFreqBw(activeDemod->getFrequency(),activeDemod->getBandwidth(),wxGetApp().getFrequency()); + } + + glContext->DrawEnd(); + + SwapBuffers(); +} + +void TuningCanvas::OnIdle(wxIdleEvent &event) { + Refresh(false); +} + +void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { + InteractiveCanvas::OnMouseMoved(event); + +} + +void TuningCanvas::OnMouseDown(wxMouseEvent& event) { + InteractiveCanvas::OnMouseDown(event); + mouseTracker.setHorizDragLock(true); +} + +void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) { + InteractiveCanvas::OnMouseWheelMoved(event); +} + +void TuningCanvas::OnMouseReleased(wxMouseEvent& event) { + InteractiveCanvas::OnMouseReleased(event); +} + +void TuningCanvas::OnMouseLeftWindow(wxMouseEvent& event) { + InteractiveCanvas::OnMouseLeftWindow(event); + SetCursor(wxCURSOR_CROSS); +} + +void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) { + InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event); + SetCursor(wxCURSOR_CROSS); +} + +void TuningCanvas::setHelpTip(std::string tip) { + helpTip = tip; +} diff --git a/src/visual/TuningCanvas.h b/src/visual/TuningCanvas.h new file mode 100644 index 0000000..3d89b90 --- /dev/null +++ b/src/visual/TuningCanvas.h @@ -0,0 +1,40 @@ +#pragma once + +#include "wx/glcanvas.h" +#include "wx/timer.h" + +#include +#include + +#include "InteractiveCanvas.h" +#include "TuningContext.h" +#include "MouseTracker.h" + +#include "fftw3.h" +#include "Timer.h" + +class TuningCanvas: public InteractiveCanvas { +public: + TuningCanvas(wxWindow *parent, int *attribList = NULL); + ~TuningCanvas(); + + void setHelpTip(std::string tip); + +private: + void OnPaint(wxPaintEvent& event); + void OnIdle(wxIdleEvent &event); + + void OnMouseMoved(wxMouseEvent& event); + void OnMouseDown(wxMouseEvent& event); + void OnMouseWheelMoved(wxMouseEvent& event); + void OnMouseReleased(wxMouseEvent& event); + void OnMouseEnterWindow(wxMouseEvent& event); + void OnMouseLeftWindow(wxMouseEvent& event); + + TuningContext *glContext; + + std::string helpTip; + // +wxDECLARE_EVENT_TABLE(); +}; + diff --git a/src/visual/TuningContext.cpp b/src/visual/TuningContext.cpp new file mode 100644 index 0000000..5883fd5 --- /dev/null +++ b/src/visual/TuningContext.cpp @@ -0,0 +1,87 @@ +#include "TuningContext.h" +#include "TuningCanvas.h" + +// http://stackoverflow.com/questions/7276826/c-format-number-with-commas +class comma_numpunct: public std::numpunct { +protected: + virtual char do_thousands_sep() const { + return ','; + } + + virtual std::string do_grouping() const { + return "\03"; + } +}; + +TuningContext::TuningContext(TuningCanvas *canvas, wxGLContext *sharedContext) : + PrimaryGLContext(canvas, sharedContext) { + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + comma_locale = std::locale(std::locale(), new comma_numpunct()); + freqStr.imbue(comma_locale); +} + +void TuningContext::DrawBegin() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glDisable(GL_TEXTURE_2D); +} + +void TuningContext::Draw(float r, float g, float b, float a, float level) { + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + glColor4f(r, g, b, a); + glBegin(GL_QUADS); + glVertex2f(1.0, -1.0 + 2.0 * level); + glVertex2f(-1.0, -1.0 + 2.0 * level); + glVertex2f(-1.0, -1.0); + glVertex2f(1.0, -1.0); + glEnd(); + glDisable(GL_BLEND); +} + +void TuningContext::DrawEnd() { + glFlush(); + + CheckGLError(); +} + +void TuningContext::DrawDemodFreqBw(long long freq, unsigned int bw, long long center) { + GLint vp[4]; + glGetIntegerv( GL_VIEWPORT, vp); + + float viewHeight = (float) vp[3]; + float viewWidth = (float) vp[2]; + + PrimaryGLContext::GLFontSize fontSize = GLFONT_SIZE16; + + int fontHeight = 16; + + if (viewWidth < 400) { + fontSize = GLFONT_SIZE12; + fontHeight = 12; + } + + getFont(fontSize).drawString("Freq: ", -0.75, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER); + freqStr.str(""); + freqStr << std::fixed << freq << "Hz"; + getFont(fontSize).drawString(freqStr.str(), -0.75, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER); + + getFont(fontSize).drawString("BW: ", -0.10, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER); + freqStr.str(""); + freqStr << std::fixed << bw << "Hz"; + getFont(fontSize).drawString(freqStr.str(), -0.10, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER); + + getFont(fontSize).drawString("CTR: ", 0.50, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER); + freqStr.str(""); + freqStr << std::fixed << center << "Hz"; + getFont(fontSize).drawString(freqStr.str(), 0.50, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER); +} + diff --git a/src/visual/TuningContext.h b/src/visual/TuningContext.h new file mode 100644 index 0000000..a1c1316 --- /dev/null +++ b/src/visual/TuningContext.h @@ -0,0 +1,22 @@ +#pragma once + +#include "PrimaryGLContext.h" +#include "Gradient.h" + +#define NUM_WATERFALL_LINES 512 + +class TuningCanvas; + +class TuningContext: public PrimaryGLContext { +public: + TuningContext(TuningCanvas *canvas, wxGLContext *sharedContext); + + void DrawBegin(); + void Draw(float r, float g, float b, float a, float level); + void DrawDemodFreqBw(long long freq, unsigned int bw, long long center); + void DrawEnd(); + +private: + std::locale comma_locale; + std::stringstream freqStr; +}; diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 8e1414c..182eb50 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -33,8 +33,8 @@ EVT_ENTER_WINDOW(WaterfallCanvas::OnMouseEnterWindow) wxEND_EVENT_TABLE() WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : - InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), dragState( - WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines(0), plan( + InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), dragState(WF_DRAG_NONE), nextDragState(WF_DRAG_NONE), fft_size(0), waterfall_lines( + 0), plan( NULL), in(NULL), out(NULL), resampler(NULL), resamplerRatio(0), lastInputBandwidth(0), zoom(1), mouseZoom(1) { glContext = new WaterfallContext(this, &wxGetApp().GetContext(this)); @@ -106,7 +106,7 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive()); int currentBandwidth = getBandwidth(); - int currentCenterFreq = getCenterFrequency(); + long long currentCenterFreq = getCenterFrequency(); if (mouseTracker.mouseInView()) { if (nextDragState == WF_DRAG_RANGE) { @@ -194,7 +194,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getActiveDemodulator(); - unsigned int freq; + long long freq; unsigned int bw; switch (event.GetKeyCode()) { case 'A': @@ -228,7 +228,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { case WXK_LEFT: freq = wxGetApp().getFrequency(); if (shiftDown) { - if (((long) freq - SRATE * 10) < SRATE / 2) { + if ((freq - SRATE * 10) < SRATE / 2) { freq = SRATE / 2; } else { freq -= SRATE * 10; @@ -240,7 +240,7 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { } } } else { - if (((long) freq - SRATE / 2) < SRATE / 2) { + if ((freq - SRATE / 2) < SRATE / 2) { freq = SRATE / 2; } else { freq -= SRATE / 2; @@ -294,28 +294,28 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) { return; } - float currentZoom = zoom; + long double currentZoom = zoom; if (mouseZoom != 1) { currentZoom = mouseZoom; mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2; } - unsigned int bw; + long long bw; if (currentZoom != 1) { - int freq = wxGetApp().getFrequency(); + long long freq = wxGetApp().getFrequency(); if (currentZoom < 1) { centerFreq = getCenterFrequency(); bw = getBandwidth(); - bw = (unsigned int) ceil((float) bw * currentZoom); + bw = (long long) ceil((long double) bw * currentZoom); if (bw < 80000) { bw = 80000; } if (mouseTracker.mouseInView()) { - int mfreqA = getFrequencyAt(mouseTracker.getMouseX()); + long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); setBandwidth(bw); - int mfreqB = getFrequencyAt(mouseTracker.getMouseX()); + long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); centerFreq += mfreqA - mfreqB; } @@ -326,19 +326,19 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) { } else { if (isView) { bw = getBandwidth(); - bw = (unsigned int) ceil((float) bw * currentZoom); - if ((int) bw >= SRATE) { - bw = (unsigned int) SRATE; + bw = (long long) ceil((long double) bw * currentZoom); + if (bw >= SRATE) { + bw = SRATE; disableView(); if (spectrumCanvas) { spectrumCanvas->disableView(); } } else { if (mouseTracker.mouseInView()) { - int freq = wxGetApp().getFrequency(); - int mfreqA = getFrequencyAt(mouseTracker.getMouseX()); + long long freq = wxGetApp().getFrequency(); + long long mfreqA = getFrequencyAt(mouseTracker.getMouseX()); setBandwidth(bw); - int mfreqB = getFrequencyAt(mouseTracker.getMouseX()); + long long mfreqB = getFrequencyAt(mouseTracker.getMouseX()); centerFreq += mfreqA - mfreqB; } @@ -378,11 +378,11 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) { } if (centerFreq != input->frequency) { - if (((int) centerFreq - (int) input->frequency) != shiftFrequency || lastInputBandwidth != input->bandwidth) { - if ((int) input->frequency - abs((int) centerFreq) < (int) ((float) ((float) SRATE / 2.0))) { - shiftFrequency = (int) centerFreq - (int) input->frequency; + if ((centerFreq - input->frequency) != shiftFrequency || lastInputBandwidth != input->bandwidth) { + if (abs(input->frequency - centerFreq) < (SRATE / 2)) { + shiftFrequency = centerFreq - input->frequency; nco_crcf_reset(freqShifter); - nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((float) abs(shiftFrequency)) / ((float) input->bandwidth))); + nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) input->bandwidth))); } } @@ -562,13 +562,11 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { } if (dragState == WF_DRAG_FREQUENCY) { - int bwDiff = (int) (mouseTracker.getDeltaMouseX() * (float) getBandwidth()); + long long bwDiff = (long long) (mouseTracker.getDeltaMouseX() * (float) getBandwidth()); + long long currentFreq = demod->getFrequency(); - unsigned int currentFreq = demod->getFrequency(); - - currentFreq = (unsigned int)((int)currentFreq + bwDiff); - - demod->setFrequency(currentFreq); + demod->setFrequency(currentFreq + bwDiff); + currentFreq = demod->getFrequency(); demod->updateLabel(currentFreq); setStatusText("Set demodulator frequency: %s", demod->getFrequency()); @@ -576,7 +574,7 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { } else if (mouseTracker.mouseRightDown()) { mouseZoom = mouseZoom + ((1.0 - (mouseTracker.getDeltaMouseY() * 4.0)) - mouseZoom) * 0.1; } else { - int freqPos = getFrequencyAt(mouseTracker.getMouseX()); + long long freqPos = getFrequencyAt(mouseTracker.getMouseX()); std::vector *demodsHover = wxGetApp().getDemodMgr().getDemodulatorsAt(freqPos, 15000); @@ -593,16 +591,16 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { } } else if (demodsHover->size()) { int hovered = -1; - int near_dist = getBandwidth(); + long near_dist = getBandwidth(); DemodulatorInstance *activeDemodulator = NULL; for (int i = 0, iMax = demodsHover->size(); i < iMax; i++) { DemodulatorInstance *demod = (*demodsHover)[i]; - int freqDiff = (int) demod->getParams().frequency - freqPos; - int halfBw = (demod->getParams().bandwidth / 2); + long long freqDiff = demod->getFrequency() - freqPos; + long halfBw = (demod->getBandwidth() / 2); - int dist = abs(freqDiff); + long dist = abs(freqDiff); if (dist < near_dist) { activeDemodulator = demod; @@ -610,7 +608,7 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { } if (dist <= halfBw && dist >= (int) ((float) halfBw / (float) 1.5)) { - int edge_dist = abs(halfBw - dist); + long edge_dist = abs(halfBw - dist); if (edge_dist < near_dist) { activeDemodulator = demod; near_dist = edge_dist; @@ -624,9 +622,9 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { wxGetApp().getDemodMgr().setActiveDemodulator(activeDemodulator); - int freqDiff = ((int) activeDemodulator->getParams().frequency - freqPos); + long long freqDiff = activeDemodulator->getFrequency() - freqPos; - if (abs(freqDiff) > (activeDemodulator->getParams().bandwidth / 3)) { + if (abs(freqDiff) > (activeDemodulator->getBandwidth() / 3)) { SetCursor(wxCURSOR_SIZEWE); if (freqDiff > 0) { @@ -688,18 +686,19 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { if (mouseTracker.getOriginDeltaMouseX() == 0 && mouseTracker.getOriginDeltaMouseY() == 0) { float pos = mouseTracker.getMouseX(); - int input_center_freq = getCenterFrequency(); - int freq = input_center_freq - (int) (0.5 * (float) getBandwidth()) + (int) ((float) pos * (float) getBandwidth()); + long long input_center_freq = getCenterFrequency(); + long long freq = input_center_freq - (long long) (0.5 * (float) getBandwidth()) + (long long) ((float) pos * (float) getBandwidth()); if (dragState == WF_DRAG_NONE) { if (!isNew && wxGetApp().getDemodMgr().getDemodulators().size()) { demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); } else { + isNew = true; demod = wxGetApp().getDemodMgr().newThread(); demod->getParams().frequency = freq; if (DemodulatorInstance *last = wxGetApp().getDemodMgr().getLastActiveDemodulator()) { - demod->getParams().bandwidth = last->getParams().bandwidth; + demod->getParams().bandwidth = last->getBandwidth(); demod->setDemodulatorType(last->getDemodulatorType()); demod->setSquelchLevel(last->getSquelchLevel()); demod->setSquelchEnabled(last->isSquelchEnabled()); @@ -718,13 +717,13 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { } demod->updateLabel(freq); + demod->setFrequency(freq); - DemodulatorThreadCommand command; - command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY; - command.int_value = freq; - demod->getCommandQueue()->push(command); - - setStatusText("New demodulator at frequency: %s", freq); + if (isNew) { + setStatusText("New demodulator at frequency: %s", freq); + } else { + setStatusText("Moved demodulator to frequency: %s", freq); + } wxGetApp().getDemodMgr().setActiveDemodulator(wxGetApp().getDemodMgr().getLastActiveDemodulator(), false); SetCursor(wxCURSOR_SIZING); @@ -739,8 +738,8 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { float width = mouseTracker.getOriginDeltaMouseX(); float pos = mouseTracker.getOriginMouseX() + width / 2.0; - int input_center_freq = getCenterFrequency(); - unsigned int freq = input_center_freq - (int) (0.5 * (float) getBandwidth()) + (int) ((float) pos * (float) getBandwidth()); + long long input_center_freq = getCenterFrequency(); + long long freq = input_center_freq - (long long) (0.5 * (float) getBandwidth()) + (long long) ((float) pos * (float) getBandwidth()); unsigned int bw = (unsigned int) (fabs(width) * (float) getBandwidth()); if (bw < MIN_BANDWIDTH) { @@ -779,14 +778,8 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { wxGetApp().getDemodMgr().setActiveDemodulator(wxGetApp().getDemodMgr().getLastActiveDemodulator(), false); demod->updateLabel(freq); - - DemodulatorThreadCommand command; - command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY; - command.int_value = freq; - demod->getCommandQueue()->push(command); - command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH; - command.int_value = bw; - demod->getCommandQueue()->push(command); + demod->setFrequency(freq); + demod->setBandwidth(bw); } dragState = WF_DRAG_NONE; diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index 91df4f5..c37c33d 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -70,7 +70,7 @@ private: msresamp_crcf resampler; double resamplerRatio; nco_crcf freqShifter; - int shiftFrequency; + long shiftFrequency; int lastInputBandwidth; float mouseZoom, zoom;