Cleanup, demod limits, prevent negative freq, move iq resampler process back to demodulator pre thread

This commit is contained in:
Charles J. Cliffe
2015-01-04 13:20:31 -05:00
parent e2e261f1c0
commit 44bee1f553
16 changed files with 200 additions and 160 deletions
+26 -32
View File
@@ -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;
}
+6 -8
View File
@@ -6,16 +6,15 @@
#include <vector>
#include <queue>
#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<float> 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();
};
+5 -5
View File
@@ -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);
+11 -7
View File
@@ -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);
}
+30 -35
View File
@@ -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) {
-3
View File
@@ -61,9 +61,6 @@ private:
WaterfallContext *glContext;
int activeDemodulatorBandwidth;
int activeDemodulatorFrequency;
DragState dragState;
DragState nextDragState;