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
+8 -8
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();
}
}
+5 -5
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;
+4 -4
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;
+3 -3
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);
+6 -7
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;
+7 -7
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);
+1 -1
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;
+91
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
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();
};
+87
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);
}
+22
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;
};
+48 -55
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;
+1 -1
View File
@@ -70,7 +70,7 @@ private:
msresamp_crcf resampler;
double resamplerRatio;
nco_crcf freqShifter;
int shiftFrequency;
long shiftFrequency;
int lastInputBandwidth;
float mouseZoom, zoom;