Fix frequency related data types for >2Ghz

This commit is contained in:
Charles J. Cliffe 2015-01-04 17:11:20 -05:00
parent 44bee1f553
commit 9f945026b8
29 changed files with 393 additions and 144 deletions

View File

@ -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

View File

@ -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) {

View File

@ -7,6 +7,7 @@
#include "SpectrumCanvas.h"
#include "WaterfallCanvas.h"
#include "MeterCanvas.h"
#include "TuningCanvas.h"
#include <map>
@ -36,6 +37,7 @@ private:
SpectrumCanvas *demodSpectrumCanvas;
WaterfallCanvas *demodWaterfallCanvas;
MeterCanvas *demodSignalMeter;
TuningCanvas *demodTuner;
// event table
DemodulatorInstance *activeDemodulator;

View File

@ -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;
}

View File

@ -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;

View File

@ -20,7 +20,7 @@
class AudioThreadInput: public ReferenceCounter {
public:
int frequency;
long long frequency;
int sampleRate;
int channels;
std::vector<float> data;

View File

@ -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<liquid_float_complex> 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<float> *data) :
DemodulatorThreadAudioData(long long frequency, unsigned int sampleRate, std::vector<float> *data) :
frequency(frequency), sampleRate(sampleRate), channels(1), data(data) {
}
@ -119,7 +119,7 @@ typedef ThreadQueue<DemodulatorThreadControlCommand> 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;

View File

@ -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;
}

View File

@ -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<bool> squelch;
std::atomic<bool> stereo;
int currentDemodType;
long long currentFrequency;
int currentBandwidth;
int currentFrequency;
int currentDemodType;
};

View File

@ -62,17 +62,17 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
garbageCollect();
}
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
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);

View File

@ -13,7 +13,7 @@ public:
DemodulatorInstance *newThread();
std::vector<DemodulatorInstance *> &getDemodulators();
std::vector<DemodulatorInstance *> *getDemodulatorsAt(int freq, int bandwidth);
std::vector<DemodulatorInstance *> *getDemodulatorsAt(long long freq, int bandwidth);
void deleteThread(DemodulatorInstance *);
void terminateAll();

View File

@ -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;
}
}

View File

@ -65,7 +65,7 @@ public:
DemodulatorThreadCommandEnum cmd;
unsigned int frequency;
long long frequency;
unsigned int inputRate;
unsigned int bandwidth;
unsigned int audioSampleRate;

View File

@ -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;

View File

@ -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;
}

View File

@ -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<signed char> data;
@ -45,7 +45,7 @@ public:
}
SDRThreadIQData(unsigned int bandwidth, unsigned int frequency, std::vector<signed char> *data) :
SDRThreadIQData(unsigned int bandwidth, long long frequency, std::vector<signed char> *data) :
frequency(frequency), bandwidth(bandwidth) {
}

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -15,7 +15,7 @@ SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedCont
}
void SpectrumContext::Draw(std::vector<float> &points, int freq, int bandwidth) {
void SpectrumContext::Draw(std::vector<float> &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<float> &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);

View File

@ -11,7 +11,7 @@ class SpectrumContext: public PrimaryGLContext {
public:
SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext);
void Draw(std::vector<float> &points, int freq, int bandwidth);
void Draw(std::vector<float> &points, long long freq, int bandwidth);
private:
int fft_size;

View File

@ -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 <algorithm>
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;
}

40
src/visual/TuningCanvas.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include "wx/glcanvas.h"
#include "wx/timer.h"
#include <vector>
#include <queue>
#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();
};

View File

@ -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<char> {
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);
}

View File

@ -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;
};

View File

@ -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<DemodulatorInstance *> *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;

View File

@ -70,7 +70,7 @@ private:
msresamp_crcf resampler;
double resamplerRatio;
nco_crcf freqShifter;
int shiftFrequency;
long shiftFrequency;
int lastInputBandwidth;
float mouseZoom, zoom;