From 44bee1f55356e3ab124e326a67c845d216f075da Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 4 Jan 2015 13:20:31 -0500 Subject: [PATCH] Cleanup, demod limits, prevent negative freq, move iq resampler process back to demodulator pre thread --- src/AppFrame.cpp | 1 + src/CubicSDR.cpp | 4 +- src/demod/DemodDefs.h | 4 +- src/demod/DemodulatorInstance.cpp | 61 ++++++++++++++++++---- src/demod/DemodulatorInstance.h | 13 ++++- src/demod/DemodulatorPreThread.cpp | 20 ++++++-- src/demod/DemodulatorPreThread.h | 1 + src/demod/DemodulatorThread.cpp | 82 +++++++++++++----------------- src/demod/DemodulatorThread.h | 1 - src/sdr/SDRThread.cpp | 5 +- src/visual/MeterCanvas.cpp | 58 ++++++++++----------- src/visual/MeterCanvas.h | 14 +++-- src/visual/PrimaryGLContext.cpp | 10 ++-- src/visual/SpectrumCanvas.cpp | 18 ++++--- src/visual/WaterfallCanvas.cpp | 65 +++++++++++------------ src/visual/WaterfallCanvas.h | 3 -- 16 files changed, 200 insertions(+), 160 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 9847fe2..8a4bde1 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -57,6 +57,7 @@ AppFrame::AppFrame() : demodSignalMeter = new MeterCanvas(this, NULL); demodSignalMeter->setMax(0.5); + demodSignalMeter->setHelpTip("Current Signal Level. Click / Drag to set Squelch level."); demodTray->Add(demodSignalMeter, 1, wxEXPAND | wxALL, 0); demodTray->AddSpacer(2); diff --git a/src/CubicSDR.cpp b/src/CubicSDR.cpp index 142073d..db46c29 100644 --- a/src/CubicSDR.cpp +++ b/src/CubicSDR.cpp @@ -101,8 +101,10 @@ PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) { } void CubicSDR::setFrequency(unsigned int freq) { + if (freq < SRATE/2) { + freq = SRATE/2; + } frequency = freq; -// demodulatorTest->getParams().frequency = freq; SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE); command.int_value = freq; threadCmdQueueSDR->push(command); diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index 852dcba..fcc4ecc 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -75,14 +75,12 @@ class DemodulatorThreadPostIQData: public ReferenceCounter { public: std::vector data; int bandwidth; - msresamp_crcf resampler; - double resamplerRatio; msresamp_rrrf audioResampler; msresamp_rrrf stereoResampler; double audioResampleRatio; DemodulatorThreadPostIQData() : - bandwidth(0), resampler(NULL), resamplerRatio(0), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(0) { + bandwidth(0), audioResampler(NULL), stereoResampler(NULL), audioResampleRatio(0) { } diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 615dab7..1291ba4 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) { + false), preDemodTerminated(false), active(false), squelch(false), stereo(false), currentBandwidth(0), currentFrequency(0) { label = new std::string("Unnamed"); threadQueueDemod = new DemodulatorThreadInputQueue; @@ -157,7 +157,6 @@ void DemodulatorInstance::setStereo(bool state) { demodulatorThread->setStereo(state); } - void DemodulatorInstance::squelchAuto() { DemodulatorThreadControlCommand command; command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_SQUELCH_ON; @@ -191,12 +190,10 @@ void DemodulatorInstance::setSquelchLevel(float signal_level_in) { demodulatorThread->setSquelchLevel(signal_level_in); } - float DemodulatorInstance::getSquelchLevel() { return demodulatorThread->getSquelchLevel(); } - void DemodulatorInstance::setOutputDevice(int device_id) { if (audioThread) { AudioThreadCommand command; @@ -210,17 +207,63 @@ int DemodulatorInstance::getOutputDevice() { return audioThread->getOutputDevice(); } +void DemodulatorInstance::checkBandwidth() { + if ((currentDemodType == DEMOD_TYPE_USB || currentDemodType == DEMOD_TYPE_LSB) && (getBandwidth() > 60000)) { + setBandwidth(60000); + } +} + void DemodulatorInstance::setDemodulatorType(int demod_type_in) { if (demodulatorThread && threadQueueControl) { DemodulatorThreadControlCommand command; - command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE; - currentDemodType = demod_type_in; - command.demodType = demod_type_in; - threadQueueControl->push(command); - } + command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE; + currentDemodType = demod_type_in; + command.demodType = demod_type_in; + checkBandwidth(); + threadQueueControl->push(command); + } } int DemodulatorInstance::getDemodulatorType() { return currentDemodType; } +void DemodulatorInstance::setBandwidth(int bw) { + if (demodulatorPreThread && threadQueueCommand) { + DemodulatorThreadCommand command; + command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH; + currentBandwidth = bw; + checkBandwidth(); + command.int_value = currentBandwidth; + threadQueueCommand->push(command); + } + demodulatorPreThread->getParams().bandwidth; +} + +int DemodulatorInstance::getBandwidth() { + if (!currentBandwidth) { + currentBandwidth = demodulatorPreThread->getParams().bandwidth; + } + return currentBandwidth; +} + +void DemodulatorInstance::setFrequency(unsigned int freq) { + if (((long)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; + threadQueueCommand->push(command); + } + demodulatorPreThread->getParams().bandwidth; +} + +int DemodulatorInstance::getFrequency() { + if (!currentFrequency) { + currentFrequency = demodulatorPreThread->getParams().frequency; + } + return currentFrequency; +} diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index 5a440b3..0113196 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -66,7 +66,15 @@ public: void setDemodulatorType(int demod_type_in); int getDemodulatorType(); + void setBandwidth(int bw); + int getBandwidth(); + + void setFrequency(unsigned int freq); + int getFrequency(); private: + + void checkBandwidth(); + std::atomic label; // bool terminated; // bool demodTerminated; // @@ -77,5 +85,6 @@ private: std::atomic stereo; int currentDemodType; -}; - + int currentBandwidth; + int currentFrequency; + }; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index db7a57d..7980aba 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -173,16 +173,24 @@ void DemodulatorPreThread::threadMain() { buffers.push_back(resamp); } - resamp->setRefCount(1); - resamp->data.assign(in_buf, in_buf + bufSize); + int out_size = ceil((double) (bufSize) * iqResampleRatio) + 512; -// firfilt_crcf_execute_block(fir_filter, in_buf, bufSize, &((*resamp.data)[0])); + if (resampledData.size() != out_size) { + if (resampledData.capacity() < out_size) { + resampledData.reserve(out_size); + } + resampledData.resize(out_size); + } + + unsigned int numWritten; + msresamp_crcf_execute(iqResampler, in_buf, bufSize, &resampledData[0], &numWritten); + + resamp->setRefCount(1); + resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten); resamp->audioResampleRatio = audioResampleRatio; resamp->audioResampler = audioResampler; resamp->stereoResampler = stereoResampler; - resamp->resamplerRatio = iqResampleRatio; - resamp->resampler = iqResampler; resamp->bandwidth = params.bandwidth; iqOutputQueue->push(resamp); @@ -197,6 +205,8 @@ void DemodulatorPreThread::threadMain() { switch (result.cmd) { case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS: + msresamp_crcf_destroy(iqResampler); + iqResampler = result.resampler; audioResampler = result.audioResampler; stereoResampler = result.stereoResampler; diff --git a/src/demod/DemodulatorPreThread.h b/src/demod/DemodulatorPreThread.h index 2fa7168..2785b2b 100644 --- a/src/demod/DemodulatorPreThread.h +++ b/src/demod/DemodulatorPreThread.h @@ -48,6 +48,7 @@ protected: msresamp_crcf iqResampler; double iqResampleRatio; + std::vector resampledData; msresamp_rrrf audioResampler; msresamp_rrrf stereoResampler; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index e3e163f..1f12c22 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -35,7 +35,6 @@ void DemodulatorThread::threadMain() { pthread_setschedparam(tID, SCHED_FIFO, &prio); #endif - msresamp_crcf resampler = NULL; msresamp_rrrf audioResampler = NULL; msresamp_rrrf stereoResampler = NULL; firfilt_rrrf firStereoLeft = NULL; @@ -104,15 +103,12 @@ void DemodulatorThread::threadMain() { continue; } - if (resampler == NULL) { - resampler = inp->resampler; + if (audioResampler == NULL) { audioResampler = inp->audioResampler; stereoResampler = inp->stereoResampler; - } else if (resampler != inp->resampler) { - msresamp_crcf_destroy(resampler); + } else if (audioResampler != inp->audioResampler) { msresamp_rrrf_destroy(audioResampler); msresamp_rrrf_destroy(stereoResampler); - resampler = inp->resampler; audioResampler = inp->audioResampler; stereoResampler = inp->stereoResampler; @@ -122,34 +118,27 @@ void DemodulatorThread::threadMain() { freqdem_reset(demodFM); } - int out_size = ceil((double) (bufSize) * inp->resamplerRatio) + 512; - - if (agcData.size() != out_size) { - if (agcData.capacity() < out_size) { - agcData.reserve(out_size); - agcAMData.reserve(out_size); - resampledData.reserve(out_size); + if (agcData.size() != bufSize) { + if (agcData.capacity() < bufSize) { + agcData.reserve(bufSize); + agcAMData.reserve(bufSize); } - agcData.resize(out_size); - resampledData.resize(out_size); - agcAMData.resize(out_size); + agcData.resize(bufSize); + agcAMData.resize(bufSize); } - unsigned int numWritten; - msresamp_crcf_execute(resampler, &(inp->data[0]), bufSize, &resampledData[0], &numWritten); - double audio_resample_ratio = inp->audioResampleRatio; - if (demodOutputData.size() != numWritten) { - if (demodOutputData.capacity() < numWritten) { - demodOutputData.reserve(numWritten); + if (demodOutputData.size() != bufSize) { + if (demodOutputData.capacity() < bufSize) { + demodOutputData.reserve(bufSize); } - demodOutputData.resize(numWritten); + demodOutputData.resize(bufSize); } - int audio_out_size = ceil((double) (numWritten) * audio_resample_ratio) + 512; + int audio_out_size = ceil((double) (bufSize) * audio_resample_ratio) + 512; - agc_crcf_execute_block(iqAutoGain, &resampledData[0], numWritten, &agcData[0]); + agc_crcf_execute_block(iqAutoGain, &(inp->data[0]), bufSize, &agcData[0]); float currentSignalLevel = 0; @@ -160,27 +149,27 @@ void DemodulatorThread::threadMain() { } if (demodulatorType == DEMOD_TYPE_FM) { - freqdem_demodulate_block(demodFM, &agcData[0], numWritten, &demodOutputData[0]); + freqdem_demodulate_block(demodFM, &agcData[0], bufSize, &demodOutputData[0]); } else { float p; switch (demodulatorType.load()) { case DEMOD_TYPE_LSB: - for (int i = 0; i < numWritten; i++) { // Reject upper band - nco_crcf_mix_up(ssbShifterUp, resampledData[i], &x); + for (int i = 0; i < bufSize; i++) { // Reject upper band + nco_crcf_mix_up(ssbShifterUp, inp->data[i], &x); nco_crcf_step(ssbShifterUp); firfilt_crcf_push(firSSB, x); firfilt_crcf_execute(firSSB, &x); - nco_crcf_mix_down(ssbShifterDown, x, &resampledData[i]); + nco_crcf_mix_down(ssbShifterDown, x, &(inp->data[i])); nco_crcf_step(ssbShifterDown); } break; case DEMOD_TYPE_USB: - for (int i = 0; i < numWritten; i++) { // Reject lower band - nco_crcf_mix_down(ssbShifterDown, resampledData[i], &x); + for (int i = 0; i < bufSize; i++) { // Reject lower band + nco_crcf_mix_down(ssbShifterDown, inp->data[i], &x); nco_crcf_step(ssbShifterDown); firfilt_crcf_push(firSSB, x); firfilt_crcf_execute(firSSB, &x); - nco_crcf_mix_up(ssbShifterUp, x, &resampledData[i]); + nco_crcf_mix_up(ssbShifterUp, x, &(inp->data[i])); nco_crcf_step(ssbShifterUp); } break; @@ -190,8 +179,8 @@ void DemodulatorThread::threadMain() { amOutputCeil = 0; - for (int i = 0; i < numWritten; i++) { - ampmodem_demodulate(demodAM, resampledData[i], &demodOutputData[i]); + for (int i = 0; i < bufSize; i++) { + ampmodem_demodulate(demodAM, inp->data[i], &demodOutputData[i]); if (demodOutputData[i] > amOutputCeil) { amOutputCeil = demodOutputData[i]; } @@ -201,7 +190,7 @@ void DemodulatorThread::threadMain() { float gain = 0.95 / amOutputCeilMAA; - for (int i = 0; i < numWritten; i++) { + for (int i = 0; i < bufSize; i++) { demodOutputData[i] *= gain; } } @@ -214,14 +203,14 @@ void DemodulatorThread::threadMain() { } unsigned int numAudioWritten; - msresamp_rrrf_execute(audioResampler, &demodOutputData[0], numWritten, &resampledOutputData[0], &numAudioWritten); + msresamp_rrrf_execute(audioResampler, &demodOutputData[0], bufSize, &resampledOutputData[0], &numAudioWritten); if (stereo) { - if (demodStereoData.size() != numWritten) { - if (demodStereoData.capacity() < numWritten) { - demodStereoData.reserve(numWritten); + if (demodStereoData.size() != bufSize) { + if (demodStereoData.capacity() < bufSize) { + demodStereoData.reserve(bufSize); } - demodStereoData.resize(numWritten); + demodStereoData.resize(bufSize); } double freq = (2.0 * M_PI) * (((double) abs(38000)) / ((double) inp->bandwidth)); @@ -231,7 +220,7 @@ void DemodulatorThread::threadMain() { stereoShiftFrequency = freq; } - for (int i = 0; i < numWritten; i++) { + for (int i = 0; i < bufSize; i++) { firhilbf_r2c_execute(firStereoR2C, demodOutputData[i], &x); nco_crcf_mix_down(stereoShifter, x, &y); nco_crcf_step(stereoShifter); @@ -245,7 +234,7 @@ void DemodulatorThread::threadMain() { resampledStereoData.resize(audio_out_size); } - msresamp_rrrf_execute(stereoResampler, &demodStereoData[0], numWritten, &resampledStereoData[0], &numAudioWritten); + msresamp_rrrf_execute(stereoResampler, &demodStereoData[0], bufSize, &resampledStereoData[0], &numAudioWritten); } if (currentSignalLevel > signalLevel) { @@ -318,15 +307,15 @@ void DemodulatorThread::threadMain() { } } else { ati_vis->channels = 1; - if (numAudioWritten > numWritten) { + if (numAudioWritten > bufSize) { if (num_vis > numAudioWritten) { num_vis = numAudioWritten; } ati_vis->data.assign(resampledOutputData.begin(), resampledOutputData.begin() + num_vis); } else { - if (num_vis > numWritten) { - num_vis = numWritten; + if (num_vis > bufSize) { + num_vis = bufSize; } ati_vis->data.assign(demodOutputData.begin(), demodOutputData.begin() + num_vis); } @@ -379,9 +368,6 @@ void DemodulatorThread::threadMain() { inp->decRefCount(); } - if (resampler != NULL) { - msresamp_crcf_destroy(resampler); - } if (audioResampler != NULL) { msresamp_rrrf_destroy(audioResampler); } diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index f4ed640..898f4d6 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -48,7 +48,6 @@ protected: std::deque outputBuffers; std::deque::iterator outputBuffersI; - std::vector resampledData; std::vector agcData; std::vector agcAMData; std::vector demodOutputData; diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 2d54845..ccb83e8 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -145,9 +145,12 @@ void SDRThread::threadMain() { switch (command.cmd) { case SDRThreadCommand::SDR_THREAD_CMD_TUNE: - std::cout << "Set frequency: " << command.int_value << std::endl; freq_changed = true; new_freq = command.int_value; + if (new_freq < SRATE / 2) { + new_freq = SRATE / 2; + } + std::cout << "Set frequency: " << new_freq << std::endl; break; default: break; diff --git a/src/visual/MeterCanvas.cpp b/src/visual/MeterCanvas.cpp index 3bd15e0..45ae8f2 100644 --- a/src/visual/MeterCanvas.cpp +++ b/src/visual/MeterCanvas.cpp @@ -25,11 +25,9 @@ EVT_ENTER_WINDOW(MeterCanvas::OnMouseEnterWindow) wxEND_EVENT_TABLE() MeterCanvas::MeterCanvas(wxWindow *parent, int *attribList) : - wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, - wxFULL_REPAINT_ON_RESIZE), parent(parent), level(0), level_max(1), inputValue(0), userInputValue(0), shiftDown(false), altDown(false), ctrlDown(false) { + InteractiveCanvas(parent, attribList), level(0), level_max(1), inputValue(0), userInputValue(0) { glContext = new MeterContext(this, &wxGetApp().GetContext(this)); - mTracker.setTarget(this); } MeterCanvas::~MeterCanvas() { @@ -50,9 +48,11 @@ void MeterCanvas::setMax(float max_in) { bool MeterCanvas::setInputValue(float slider_in) { userInputValue = inputValue = slider_in; } + bool MeterCanvas::inputChanged() { return (inputValue != userInputValue); } + float MeterCanvas::getInputValue() { inputValue = userInputValue; return userInputValue; @@ -66,13 +66,13 @@ void MeterCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glViewport(0, 0, ClientSize.x, ClientSize.y); glContext->DrawBegin(); - if (mTracker.mouseInView()) { - glContext->Draw(0.4, 0.4, 0.4, 0.5, mTracker.getMouseY()); + if (mouseTracker.mouseInView()) { + glContext->Draw(0.4, 0.4, 0.4, 0.5, mouseTracker.getMouseY()); } - glContext->Draw(0.1, 0.75, 0.1, 0.5, level/level_max); + glContext->Draw(0.1, 0.75, 0.1, 0.5, level / level_max); - glContext->Draw(0.75, 0.1, 0.1, 0.5, userInputValue/level_max); + glContext->Draw(0.75, 0.1, 0.1, 0.5, userInputValue / level_max); glContext->DrawEnd(); @@ -84,48 +84,42 @@ void MeterCanvas::OnIdle(wxIdleEvent &event) { } void MeterCanvas::OnMouseMoved(wxMouseEvent& event) { - mTracker.OnMouseMoved(event); + InteractiveCanvas::OnMouseMoved(event); - shiftDown = event.ShiftDown(); - altDown = event.AltDown(); - ctrlDown = event.ControlDown(); - - if (mTracker.mouseDown()) { - userInputValue = mTracker.getMouseY()*level_max; + if (mouseTracker.mouseDown()) { + userInputValue = mouseTracker.getMouseY() * level_max; + } else { + if (!helpTip.empty()) { + setStatusText(helpTip); + } } } void MeterCanvas::OnMouseDown(wxMouseEvent& event) { - mTracker.OnMouseDown(event); - - shiftDown = event.ShiftDown(); - altDown = event.AltDown(); - ctrlDown = event.ControlDown(); - - userInputValue = mTracker.getMouseY()*level_max; - mTracker.setHorizDragLock(true); + InteractiveCanvas::OnMouseDown(event); + userInputValue = mouseTracker.getMouseY() * level_max; + mouseTracker.setHorizDragLock(true); } void MeterCanvas::OnMouseWheelMoved(wxMouseEvent& event) { - mTracker.OnMouseWheelMoved(event); + InteractiveCanvas::OnMouseWheelMoved(event); } void MeterCanvas::OnMouseReleased(wxMouseEvent& event) { - mTracker.OnMouseReleased(event); - - shiftDown = event.ShiftDown(); - altDown = event.AltDown(); - ctrlDown = event.ControlDown(); - - userInputValue = mTracker.getMouseY()*level_max; + InteractiveCanvas::OnMouseReleased(event); + userInputValue = mouseTracker.getMouseY() * level_max; } void MeterCanvas::OnMouseLeftWindow(wxMouseEvent& event) { - mTracker.OnMouseLeftWindow(event); + InteractiveCanvas::OnMouseLeftWindow(event); SetCursor(wxCURSOR_CROSS); } void MeterCanvas::OnMouseEnterWindow(wxMouseEvent& event) { - mTracker.OnMouseEnterWindow(event); + InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event); SetCursor(wxCURSOR_CROSS); } + +void MeterCanvas::setHelpTip(std::string tip) { + helpTip = tip; +} diff --git a/src/visual/MeterCanvas.h b/src/visual/MeterCanvas.h index 0dd25b6..e64ef5c 100644 --- a/src/visual/MeterCanvas.h +++ b/src/visual/MeterCanvas.h @@ -6,16 +6,15 @@ #include #include +#include "InteractiveCanvas.h" #include "MeterContext.h" #include "MouseTracker.h" #include "fftw3.h" #include "Timer.h" -class MeterCanvas: public wxGLCanvas { +class MeterCanvas: public InteractiveCanvas { public: - std::vector waveform_points; - MeterCanvas(wxWindow *parent, int *attribList = NULL); ~MeterCanvas(); @@ -28,6 +27,8 @@ public: bool inputChanged(); float getInputValue(); + void setHelpTip(std::string tip); + private: void OnPaint(wxPaintEvent& event); void OnIdle(wxIdleEvent &event); @@ -39,8 +40,6 @@ private: void OnMouseEnterWindow(wxMouseEvent& event); void OnMouseLeftWindow(wxMouseEvent& event); - MouseTracker mTracker; - wxWindow *parent; MeterContext *glContext; float level; @@ -49,9 +48,8 @@ private: float inputValue; float userInputValue; - bool shiftDown; - bool altDown; - bool ctrlDown; + std::string helpTip; + // wxDECLARE_EVENT_TABLE(); }; diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index 4edd881..990ceb3 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -107,7 +107,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float center_freq = wxGetApp().getFrequency(); } - float uxPos = (float) (demod->getParams().frequency - (center_freq - srate / 2)) / (float) srate; + float uxPos = (float) (demod->getFrequency() - (center_freq - srate / 2)) / (float) srate; uxPos = (uxPos - 0.5) * 2.0; glDisable(GL_TEXTURE_2D); @@ -116,7 +116,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glColor4f(r, g, b, 0.6); - float ofs = ((float) demod->getParams().bandwidth) / (float) srate; + float ofs = ((float) demod->getBandwidth()) / (float) srate; glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glColor4f(r, g, b, 0.2); @@ -162,7 +162,7 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f center_freq = wxGetApp().getFrequency(); } - float uxPos = (float) (demod->getParams().frequency - (center_freq - srate / 2)) / (float) srate; + float uxPos = (float) (demod->getFrequency() - (center_freq - srate / 2)) / (float) srate; glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); @@ -175,7 +175,7 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); - float ofs = ((float) demod->getParams().bandwidth) / (float) srate; + float ofs = ((float) demod->getBandwidth()) / (float) srate; glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); @@ -254,7 +254,7 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b, if (!demod) { bw = defaultDemodParams.bandwidth; } else { - bw = demod->getParams().bandwidth; + bw = demod->getBandwidth(); } glDisable(GL_DEPTH_TEST); diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index 890d3af..e080708 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) { - int freq = wxGetApp().getFrequency(); + unsigned int freq = wxGetApp().getFrequency(); if (isView) { centerFreq = centerFreq - freqChange; @@ -187,19 +187,23 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { waterfallCanvas->setCenterFrequency(centerFreq); } - int bw = (int) bandwidth; - int bwOfs = ((int) centerFreq > freq) ? ((int) bandwidth / 2) : (-(int) bandwidth / 2); - int freqEdge = ((int) centerFreq + bwOfs); + long bw = (long) bandwidth; + long bwOfs = (centerFreq > freq) ? ((long) bandwidth / 2) : (-(long) bandwidth / 2); + long freqEdge = ((long) centerFreq + bwOfs); - if (abs(freq - freqEdge) > (SRATE / 2)) { - freqChange = -(((int) centerFreq > freq) ? (freqEdge - freq - (SRATE / 2)) : (freqEdge - freq + (SRATE / 2))); + if (abs((long) freq - freqEdge) > (SRATE / 2)) { + freqChange = -((centerFreq > freq) ? (freqEdge - (long)freq - (SRATE / 2)) : (freqEdge - (long)freq + (SRATE / 2))); } else { freqChange = 0; } } if (freqChange) { - freq -= freqChange; + if ((long)freq - freqChange < SRATE/2) { + freq = SRATE/2; + } else { + freq -= freqChange; + } wxGetApp().setFrequency(freq); setStatusText("Set center frequency: %s", freq); } diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 89e39f1..8e1414c 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -33,7 +33,7 @@ EVT_ENTER_WINDOW(WaterfallCanvas::OnMouseEnterWindow) wxEND_EVENT_TABLE() WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : - InteractiveCanvas(parent, attribList), spectrumCanvas(NULL), activeDemodulatorBandwidth(0), activeDemodulatorFrequency(0), dragState( + 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) { @@ -228,7 +228,11 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { case WXK_LEFT: freq = wxGetApp().getFrequency(); if (shiftDown) { - freq -= SRATE * 10; + if (((long) freq - SRATE * 10) < SRATE / 2) { + freq = SRATE / 2; + } else { + freq -= SRATE * 10; + } if (isView) { setView(centerFreq - SRATE * 10, getBandwidth()); if (spectrumCanvas) { @@ -236,7 +240,11 @@ void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) { } } } else { - freq -= SRATE / 2; + if (((long) freq - SRATE / 2) < SRATE / 2) { + freq = SRATE / 2; + } else { + freq -= SRATE / 2; + } if (isView) { setView(centerFreq - SRATE / 2, getBandwidth()); if (spectrumCanvas) { @@ -290,7 +298,7 @@ void WaterfallCanvas::setData(DemodulatorThreadIQData *input) { if (mouseZoom != 1) { currentZoom = mouseZoom; - mouseZoom = mouseZoom + (1.0 - mouseZoom)*0.2; + mouseZoom = mouseZoom + (1.0 - mouseZoom) * 0.2; } unsigned int bw; @@ -539,45 +547,34 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { bwDiff = -bwDiff; } - if (!activeDemodulatorBandwidth) { - activeDemodulatorBandwidth = demod->getParams().bandwidth; + int currentBW = demod->getBandwidth(); + + currentBW = currentBW + bwDiff; + if (currentBW > SRATE) { + currentBW = SRATE; + } + if (currentBW < MIN_BANDWIDTH) { + currentBW = MIN_BANDWIDTH; } - DemodulatorThreadCommand command; - command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH; - activeDemodulatorBandwidth = activeDemodulatorBandwidth + bwDiff; - if (activeDemodulatorBandwidth > SRATE) { - activeDemodulatorBandwidth = SRATE; - } - if (activeDemodulatorBandwidth < MIN_BANDWIDTH) { - activeDemodulatorBandwidth = MIN_BANDWIDTH; - } - - command.int_value = activeDemodulatorBandwidth; - demod->getCommandQueue()->push(command); - setStatusText("Set demodulator bandwidth: %s", activeDemodulatorBandwidth); + demod->setBandwidth(currentBW); + setStatusText("Set demodulator bandwidth: %s", demod->getBandwidth()); } if (dragState == WF_DRAG_FREQUENCY) { int bwDiff = (int) (mouseTracker.getDeltaMouseX() * (float) getBandwidth()); - if (!activeDemodulatorFrequency) { - activeDemodulatorFrequency = demod->getParams().frequency; - } + unsigned int currentFreq = demod->getFrequency(); - DemodulatorThreadCommand command; - command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY; - activeDemodulatorFrequency = activeDemodulatorFrequency + bwDiff; + currentFreq = (unsigned int)((int)currentFreq + bwDiff); - command.int_value = activeDemodulatorFrequency; - demod->getCommandQueue()->push(command); + demod->setFrequency(currentFreq); + demod->updateLabel(currentFreq); - demod->updateLabel(activeDemodulatorFrequency); - - setStatusText("Set demodulator frequency: %s", activeDemodulatorFrequency); + setStatusText("Set demodulator frequency: %s", demod->getFrequency()); } } else if (mouseTracker.mouseRightDown()) { - mouseZoom = mouseZoom + ((1.0 - (mouseTracker.getDeltaMouseY()*4.0))-mouseZoom) * 0.1; + mouseZoom = mouseZoom + ((1.0 - (mouseTracker.getDeltaMouseY() * 4.0)) - mouseZoom) * 0.1; } else { int freqPos = getFrequencyAt(mouseTracker.getMouseX()); @@ -655,7 +652,8 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { if (shiftDown) { setStatusText("Click to create a new demodulator or hold ALT to drag range."); } else { - setStatusText("Click to move active demodulator frequency or hold ALT to drag range; hold SHIFT to create new. Right drag or A / Z to Zoom. Arrow keys (+SHIFT) to move center frequency."); + setStatusText( + "Click to move active demodulator frequency or hold ALT to drag range; hold SHIFT to create new. Right drag or A / Z to Zoom. Arrow keys (+SHIFT) to move center frequency."); } } @@ -671,9 +669,6 @@ void WaterfallCanvas::OnMouseDown(wxMouseEvent& event) { if (dragState && dragState != WF_DRAG_RANGE) { wxGetApp().getDemodMgr().setActiveDemodulator(wxGetApp().getDemodMgr().getActiveDemodulator(), false); } - - activeDemodulatorBandwidth = 0; - activeDemodulatorFrequency = 0; } void WaterfallCanvas::OnMouseWheelMoved(wxMouseEvent& event) { diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index 71e189f..91df4f5 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -61,9 +61,6 @@ private: WaterfallContext *glContext; - int activeDemodulatorBandwidth; - int activeDemodulatorFrequency; - DragState dragState; DragState nextDragState;