Drag up/down to set arbitrary FM demod bandwidth

Shouldn't need separate WBFM/FM/NFM setting this way -- Just "FM" and
then set arbitrary bandwidth by dragging.

Also removed redundant demod resampling stages left over from early
experiments.
This commit is contained in:
Charles J. Cliffe 2014-11-26 21:05:19 -05:00
parent f441546023
commit ddbc08a4ff
13 changed files with 256 additions and 87 deletions

View File

@ -27,8 +27,9 @@ bool CubicSDR::OnInit() {
threadAudio = new std::thread(&AudioThread::threadMain, audioThread); threadAudio = new std::thread(&AudioThread::threadMain, audioThread);
demodulatorTest = demodMgr.newThread(); demodulatorTest = demodMgr.newThread();
demodulatorTest->params.audioInputQueue = audioInputQueue; demodulatorTest->getParams().audioInputQueue = audioInputQueue;
demodulatorTest->init(); demodulatorTest->getParams().frequency = DEFAULT_FREQ;
demodulatorTest->run();
audioVisualQueue = new DemodulatorThreadOutputQueue(); audioVisualQueue = new DemodulatorThreadOutputQueue();
demodulatorTest->setVisualOutputQueue(audioVisualQueue); demodulatorTest->setVisualOutputQueue(audioVisualQueue);
@ -87,6 +88,7 @@ PrimaryGLContext& CubicSDR::GetContext(wxGLCanvas *canvas) {
void CubicSDR::setFrequency(unsigned int freq) { void CubicSDR::setFrequency(unsigned int freq) {
frequency = freq; frequency = freq;
demodulatorTest->getParams().frequency = freq;
SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE); SDRThreadCommand command(SDRThreadCommand::SDR_THREAD_CMD_TUNE);
command.int_value = freq; command.int_value = freq;
threadCmdQueueSDR->push(command); threadCmdQueueSDR->push(command);

View File

@ -40,6 +40,10 @@ public:
return demodulatorTest; return demodulatorTest;
} }
DemodulatorMgr &getDemodMgr() {
return demodMgr;
}
private: private:
PrimaryGLContext *m_glContext; PrimaryGLContext *m_glContext;

View File

@ -2,6 +2,12 @@
DemodulatorInstance::DemodulatorInstance() : DemodulatorInstance::DemodulatorInstance() :
t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) { t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) {
threadQueueDemod = new DemodulatorThreadInputQueue;
threadQueueCommand = new DemodulatorThreadCommandQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod);
demodulatorThread->setCommandQueue(threadQueueCommand);
} }
DemodulatorInstance::~DemodulatorInstance() { DemodulatorInstance::~DemodulatorInstance() {
@ -14,20 +20,30 @@ void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQu
demodulatorThread->setVisualOutputQueue(tQueue); demodulatorThread->setVisualOutputQueue(tQueue);
} }
void DemodulatorInstance::init() { void DemodulatorInstance::run() {
if (demodulatorThread) { if (t_Demod) {
terminate(); terminate();
delete threadQueueDemod; delete threadQueueDemod;
delete demodulatorThread; delete demodulatorThread;
delete t_Demod; delete t_Demod;
threadQueueDemod = new DemodulatorThreadInputQueue;
threadQueueCommand = new DemodulatorThreadCommandQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod);
demodulatorThread->setCommandQueue(threadQueueCommand);
} }
threadQueueDemod = new DemodulatorThreadInputQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod, &params);
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread); t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
} }
DemodulatorThreadCommandQueue *DemodulatorInstance::getCommandQueue() {
return threadQueueCommand;
}
DemodulatorThreadParameters &DemodulatorInstance::getParams() {
return demodulatorThread->getParams();
}
void DemodulatorInstance::terminate() { void DemodulatorInstance::terminate() {
demodulatorThread->terminate(); demodulatorThread->terminate();
t_Demod->join(); t_Demod->join();
@ -55,3 +71,7 @@ void DemodulatorMgr::terminateAll() {
delete d; delete d;
} }
} }
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
return demods;
}

View File

@ -11,12 +11,15 @@ public:
std::thread *t_Demod; std::thread *t_Demod;
DemodulatorThreadInputQueue* threadQueueDemod; DemodulatorThreadInputQueue* threadQueueDemod;
DemodulatorThreadParameters params; DemodulatorThreadCommandQueue* threadQueueCommand;
DemodulatorInstance(); DemodulatorInstance();
~DemodulatorInstance(); ~DemodulatorInstance();
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue); void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue);
void init(); DemodulatorThreadCommandQueue *getCommandQueue();
DemodulatorThreadParameters &getParams();
void run();
void terminate(); void terminate();
}; };
@ -26,6 +29,7 @@ public:
~DemodulatorMgr(); ~DemodulatorMgr();
DemodulatorInstance *newThread(); DemodulatorInstance *newThread();
std::vector<DemodulatorInstance *> &getDemodulators();
void terminateAll(); void terminateAll();
private: private:

View File

@ -2,21 +2,27 @@
#include "CubicSDRDefs.h" #include "CubicSDRDefs.h"
#include <vector> #include <vector>
DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params_in) : DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue) :
inputQueue(pQueue), visOutQueue(NULL), terminated(false) { inputQueue(pQueue), visOutQueue(NULL), terminated(false), initialized(false), audio_resampler(NULL), audio_resample_ratio(1) {
DemodulatorThreadParameters defaultParams; }
if (!params_in) {
params = defaultParams; void DemodulatorThread::initialize() {
} else { initialized = false;
params = *params_in;
resample_ratio = (float) (params.bandwidth) / (float) params.inputRate;
audio_resample_ratio = (float) (params.audioSampleRate) / (float) params.bandwidth;
float fc = 0.5 * ((double) params.bandwidth / (double) params.inputRate); // filter cutoff frequency
if (fc <= 0) {
fc = 0;
} }
resample_ratio = (float) (params.inputResampleRate) / (float) params.inputRate; if (fc >= 0.5) {
second_resampler_ratio = (float) (params.demodResampleRate) / (float) params.inputResampleRate; fc = 0.5;
audio_resample_ratio = (float) (params.audioSampleRate) / (float) params.demodResampleRate; }
float fc = 0.5f * ((float) params.inputResampleRate / (float) params.inputRate) * 0.75; // filter cutoff frequency
float ft = 0.05f; // filter transition float ft = 0.05f; // filter transition
float As = 60.0f; // stop-band attenuation [dB] float As = 60.0f; // stop-band attenuation [dB]
float mu = 0.0f; // fractional timing offset float mu = 0.0f; // fractional timing offset
@ -28,25 +34,21 @@ DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue, Demodu
fir_filter = firfilt_crcf_create(h, h_len); fir_filter = firfilt_crcf_create(h, h_len);
h_len = estimate_req_filter_len(ft, As);
liquid_firdes_kaiser(h_len, (float) params.filterFrequency / (float) params.demodResampleRate, As, mu, h);
fir_audio_filter = firfilt_crcf_create(h, h_len);
// create multi-stage arbitrary resampler object // create multi-stage arbitrary resampler object
resampler = msresamp_crcf_create(resample_ratio, As); resampler = msresamp_crcf_create(resample_ratio, As);
msresamp_crcf_print(resampler); // msresamp_crcf_print(resampler);
second_resampler = msresamp_crcf_create(second_resampler_ratio, As);
msresamp_crcf_print(second_resampler);
audio_resampler = msresamp_crcf_create(audio_resample_ratio, As); audio_resampler = msresamp_crcf_create(audio_resample_ratio, As);
msresamp_crcf_print(audio_resampler); // msresamp_crcf_print(audio_resampler);
float kf = 0.75; // modulation factor float kf = 0.75; // modulation factor
fdem = freqdem_create(kf); fdem = freqdem_create(kf);
freqdem_print(fdem); // freqdem_print(fdem);
initialized = true;
std::cout << "inputResampleRate " << params.bandwidth << std::endl;
} }
DemodulatorThread::~DemodulatorThread() { DemodulatorThread::~DemodulatorThread() {
@ -55,10 +57,45 @@ DemodulatorThread::~DemodulatorThread() {
void DemodulatorThread::threadMain() { void DemodulatorThread::threadMain() {
if (!initialized) {
initialize();
}
while (!terminated) { while (!terminated) {
DemodulatorThreadIQData inp; DemodulatorThreadIQData inp;
inputQueue->pop(inp); inputQueue->pop(inp);
if (!commandQueue->empty()) {
bool paramsChanged = false;
while (!commandQueue->empty()) {
DemodulatorThreadCommand command;
commandQueue->pop(command);
switch (command.cmd) {
case DemodulatorThreadCommand::SDR_THREAD_CMD_SETBANDWIDTH:
if (command.int_value < 3000) {
command.int_value = 3000;
}
if (command.int_value > SRATE) {
command.int_value = SRATE;
}
params.bandwidth = command.int_value;
paramsChanged = true;
break;
}
}
if (paramsChanged) {
initialize();
while (!inputQueue->empty()) { // catch up
inputQueue->pop(inp);
}
}
}
if (!initialized) {
continue;
}
std::vector<signed char> *data = &inp.data; std::vector<signed char> *data = &inp.data;
if (data->size()) { if (data->size()) {
liquid_float_complex filtered_input[BUF_SIZE / 2]; liquid_float_complex filtered_input[BUF_SIZE / 2];
@ -103,22 +140,11 @@ void DemodulatorThread::threadMain() {
} }
} }
int wbfm_out_size = ceil((float) (num_written) * second_resampler_ratio); int audio_out_size = ceil((float) (num_written) * audio_resample_ratio);
liquid_float_complex resampled_wbfm_output[wbfm_out_size];
unsigned int num_wbfm_written;
msresamp_crcf_execute(second_resampler, resampled_output, num_written, resampled_wbfm_output, &num_wbfm_written);
for (int i = 0; i < num_wbfm_written; i++) {
firfilt_crcf_push(fir_audio_filter, resampled_wbfm_output[i]);
firfilt_crcf_execute(fir_audio_filter, &resampled_wbfm_output[i]);
}
int audio_out_size = ceil((float) (num_wbfm_written) * audio_resample_ratio);
liquid_float_complex resampled_audio_output[audio_out_size]; liquid_float_complex resampled_audio_output[audio_out_size];
unsigned int num_audio_written; unsigned int num_audio_written;
msresamp_crcf_execute(audio_resampler, resampled_wbfm_output, num_wbfm_written, resampled_audio_output, &num_audio_written); msresamp_crcf_execute(audio_resampler, resampled_output, num_written, resampled_audio_output, &num_audio_written);
std::vector<float> newBuffer; std::vector<float> newBuffer;
newBuffer.resize(num_audio_written * 2); newBuffer.resize(num_audio_written * 2);

View File

@ -16,9 +16,29 @@
#include "CubicSDRDefs.h" #include "CubicSDRDefs.h"
enum DemodulatorType { enum DemodulatorType {
DEMOD_TYPE_NULL, DEMOD_TYPE_AM, DEMOD_TYPE_FM, DEMOD_TYPE_LSB, DEMOD_TYPE_USB, DEMOD_TYPE_WFM DEMOD_TYPE_NULL, DEMOD_TYPE_AM, DEMOD_TYPE_FM, DEMOD_TYPE_LSB, DEMOD_TYPE_USB
}; };
class DemodulatorThreadCommand {
public:
enum DemodulatorThreadCommandEnum {
SDR_THREAD_CMD_NULL,
SDR_THREAD_CMD_SETBANDWIDTH
};
DemodulatorThreadCommand() : cmd(cmd), int_value(SDR_THREAD_CMD_NULL) {
}
DemodulatorThreadCommand(DemodulatorThreadCommandEnum cmd) : cmd(cmd), int_value(0) {
}
DemodulatorThreadCommandEnum cmd;
int int_value;
};
class DemodulatorThreadIQData { class DemodulatorThreadIQData {
public: public:
unsigned int frequency; unsigned int frequency;
@ -65,18 +85,16 @@ public:
class DemodulatorThreadParameters { class DemodulatorThreadParameters {
public: public:
unsigned int frequency;
unsigned int inputRate; unsigned int inputRate;
unsigned int inputResampleRate; // set equal to disable second stage re-sampling? unsigned int bandwidth; // set equal to disable second stage re-sampling?
unsigned int demodResampleRate;
unsigned int filterFrequency;
unsigned int audioSampleRate; unsigned int audioSampleRate;
AudioThreadInputQueue *audioInputQueue; AudioThreadInputQueue *audioInputQueue;
DemodulatorType demodType; DemodulatorType demodType;
DemodulatorThreadParameters() : DemodulatorThreadParameters() :
audioInputQueue(NULL), inputRate(SRATE), inputResampleRate(200000), demodResampleRate(100000), audioSampleRate(AUDIO_FREQUENCY), filterFrequency( frequency(0), audioInputQueue(NULL), inputRate(SRATE), bandwidth(200000), audioSampleRate(AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) {
32000), demodType(DEMOD_TYPE_WFM) {
} }
@ -87,11 +105,12 @@ public:
typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue; typedef ThreadQueue<DemodulatorThreadIQData> DemodulatorThreadInputQueue;
typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue; typedef ThreadQueue<AudioThreadInput> DemodulatorThreadOutputQueue;
typedef ThreadQueue<DemodulatorThreadCommand> DemodulatorThreadCommandQueue;
class DemodulatorThread { class DemodulatorThread {
public: public:
DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params); DemodulatorThread(DemodulatorThreadInputQueue* pQueue);
~DemodulatorThread(); ~DemodulatorThread();
void threadMain(); void threadMain();
@ -101,21 +120,28 @@ public:
visOutQueue->set_max_num_items(1); visOutQueue->set_max_num_items(1);
} }
void setCommandQueue(DemodulatorThreadCommandQueue *tQueue) {
commandQueue = tQueue;
}
DemodulatorThreadParameters &getParams() {
return params;
}
void initialize();
void terminate(); void terminate();
protected: protected:
DemodulatorThreadInputQueue* inputQueue; DemodulatorThreadInputQueue* inputQueue;
DemodulatorThreadOutputQueue* visOutQueue; DemodulatorThreadOutputQueue* visOutQueue;
DemodulatorThreadCommandQueue* commandQueue;
firfilt_crcf fir_filter; firfilt_crcf fir_filter;
firfilt_crcf fir_audio_filter;
msresamp_crcf resampler; msresamp_crcf resampler;
float resample_ratio; float resample_ratio;
msresamp_crcf second_resampler;
float second_resampler_ratio;
msresamp_crcf audio_resampler; msresamp_crcf audio_resampler;
float audio_resample_ratio; float audio_resample_ratio;
@ -123,4 +149,5 @@ protected:
freqdem fdem; freqdem fdem;
std::atomic<bool> terminated; std::atomic<bool> terminated;
std::atomic<bool> initialized;
}; };

View File

@ -15,17 +15,21 @@ void MouseTracker::OnMouseMoved(wxMouseEvent& event) {
deltaMouseY = mouseY - lastMouseY; deltaMouseY = mouseY - lastMouseY;
if (isMouseDown) { if (isMouseDown) {
lastMouseX = mouseX; if (horizDragLock && vertDragLock) {
target->WarpPointer(originMouseX * ClientSize.x, originMouseY * ClientSize.y);
if (vertDragLock && mouseY != lastMouseY) { mouseX = originMouseX;
target->WarpPointer(event.m_x, lastMouseY * ClientSize.y); mouseY = originMouseY;
} else { } else if (vertDragLock && mouseY != lastMouseY) {
lastMouseY = mouseY; target->WarpPointer(event.m_x, originMouseY * ClientSize.y);
mouseY = originMouseY;
} else if (horizDragLock && mouseX != lastMouseX) {
target->WarpPointer(originMouseX * ClientSize.x, event.m_y);
mouseX = originMouseX;
} }
} else {
lastMouseY = mouseY;
lastMouseX = mouseX;
} }
lastMouseX = mouseX;
lastMouseY = mouseY;
} }
void MouseTracker::OnMouseDown(wxMouseEvent& event) { void MouseTracker::OnMouseDown(wxMouseEvent& event) {
@ -105,6 +109,10 @@ void MouseTracker::setVertDragLock(bool dragLock) {
vertDragLock = dragLock; vertDragLock = dragLock;
} }
void MouseTracker::setHorizDragLock(bool dragLock) {
horizDragLock = dragLock;
}
bool MouseTracker::mouseDown() { bool MouseTracker::mouseDown() {
return isMouseDown; return isMouseDown;
} }

View File

@ -6,13 +6,13 @@ class MouseTracker {
public: public:
MouseTracker(wxWindow *target) : MouseTracker(wxWindow *target) :
target(target), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown( target(target), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown(
false), vertDragLock(false), isMouseInView(false) { false), vertDragLock(false), horizDragLock(false), isMouseInView(false) {
} }
MouseTracker() : MouseTracker() :
target(NULL), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown( target(NULL), mouseX(0), mouseY(0), lastMouseX(0), lastMouseY(0), originMouseX(0), originMouseY(0), deltaMouseX(0), deltaMouseY(0), isMouseDown(
false), vertDragLock(false), isMouseInView(false) { false), vertDragLock(false), horizDragLock(false), isMouseInView(false) {
} }
@ -35,6 +35,7 @@ public:
float getMouseY(); float getMouseY();
void setVertDragLock(bool dragLock); void setVertDragLock(bool dragLock);
void setHorizDragLock(bool dragLock);
bool mouseDown(); bool mouseDown();
bool mouseInView(); bool mouseInView();
void setTarget(wxWindow *target_in); void setTarget(wxWindow *target_in);
@ -46,6 +47,6 @@ private:
float originMouseX, originMouseY; float originMouseX, originMouseY;
bool isMouseDown, isMouseInView; bool isMouseDown, isMouseInView;
bool vertDragLock; bool vertDragLock, horizDragLock;
wxWindow *target; wxWindow *target;
}; };

View File

@ -207,6 +207,15 @@ public:
return m_queue.empty(); return m_queue.empty();
} }
/**
* Remove any items in the queue.
*/
void flush() const {
std::lock_guard < std::mutex > lock(m_mutex);
std::queue<T, Container> emptyQueue;
std::swap(m_queue, emptyQueue);
}
/** /**
* Swaps the contents. * Swaps the contents.
* \param[out] sq The ThreadQueue to swap with 'this'. * \param[out] sq The ThreadQueue to swap with 'this'.

View File

@ -29,7 +29,7 @@ wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0) { wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), bwChange(false), demodBW(0) {
int in_block_size = BUF_SIZE / 2; int in_block_size = BUF_SIZE / 2;
int out_block_size = FFT_SIZE; int out_block_size = FFT_SIZE;
@ -45,7 +45,8 @@ WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
timer.start(); timer.start();
mTracker.setTarget(this); mTracker.setTarget(this);
mTracker.setVertDragLock(true);
mTracker.setHorizDragLock(true);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
} }
@ -63,6 +64,12 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glContext->BeginDraw(); glContext->BeginDraw();
glContext->Draw(spectrum_points); glContext->Draw(spectrum_points);
std::vector<DemodulatorInstance *> *demods = &wxGetApp().getDemodMgr().getDemodulators();
for (int i = 0, iMax = demods->size(); i < iMax; i++) {
glContext->DrawDemod((*demods)[i]);
}
if (mTracker.mouseInView()) { if (mTracker.mouseInView()) {
glContext->DrawFreqSelector(mTracker.getMouseX()); glContext->DrawFreqSelector(mTracker.getMouseX());
} }
@ -180,34 +187,61 @@ void WaterfallCanvas::OnIdle(wxIdleEvent &event) {
void WaterfallCanvas::mouseMoved(wxMouseEvent& event) { void WaterfallCanvas::mouseMoved(wxMouseEvent& event) {
mTracker.OnMouseMoved(event); mTracker.OnMouseMoved(event);
DemodulatorInstance *demod = wxGetApp().getDemodTest();
if (mTracker.mouseDown()) { if (mTracker.mouseDown()) {
int freqChange = mTracker.getDeltaMouseX() * SRATE; if (demod && mTracker.getDeltaMouseY()) {
int bwDiff = (int)(mTracker.getDeltaMouseY() * 100000.0);
if (freqChange != 0) { if (!demodBW) {
int freq = wxGetApp().getFrequency(); demodBW = demod->getParams().bandwidth;
freq -= freqChange; }
wxGetApp().setFrequency(freq);
((wxFrame*) parent)->GetStatusBar()->SetStatusText( DemodulatorThreadCommand command;
wxString::Format(wxT("Set center frequency: %s"), command.cmd = DemodulatorThreadCommand::SDR_THREAD_CMD_SETBANDWIDTH;
wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); demodBW = demodBW - bwDiff;
if (demodBW < 1000) {
demodBW = 1000;
}
if (demodBW > SRATE) {
demodBW = SRATE;
}
command.int_value = demodBW;
demod->getCommandQueue()->push(command);
bwChange = true;
} }
// int freqChange = mTracker.getDeltaMouseX() * SRATE;
//
// if (freqChange != 0) {
// int freq = wxGetApp().getFrequency();
// freq -= freqChange;
// wxGetApp().setFrequency(freq);
//
// ((wxFrame*) parent)->GetStatusBar()->SetStatusText(
// wxString::Format(wxT("Set center frequency: %s"),
// wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep)));
// }
} }
} }
void WaterfallCanvas::mouseDown(wxMouseEvent& event) { void WaterfallCanvas::mouseDown(wxMouseEvent& event) {
mTracker.OnMouseDown(event); mTracker.OnMouseDown(event);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_SIZENS);
bwChange = false;
} }
void WaterfallCanvas::mouseWheelMoved(wxMouseEvent& event) { void WaterfallCanvas::mouseWheelMoved(wxMouseEvent& event) {
DemodulatorInstance *demod = wxGetApp().getDemodTest();
mTracker.OnMouseWheelMoved(event); mTracker.OnMouseWheelMoved(event);
} }
void WaterfallCanvas::mouseReleased(wxMouseEvent& event) { void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
mTracker.OnMouseReleased(event); mTracker.OnMouseReleased(event);
if (mTracker.getOriginDeltaMouseX() == 0 && mTracker.getOriginDeltaMouseX() == 0) { if (mTracker.getOriginDeltaMouseX() == 0 && mTracker.getOriginDeltaMouseY() == 0 && !bwChange) {
float pos = mTracker.getMouseX(); float pos = mTracker.getMouseX();
@ -222,15 +256,15 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep)));
} }
SetCursor(wxCURSOR_SIZEWE); SetCursor(wxCURSOR_CROSS);
} }
void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) {
mTracker.OnMouseLeftWindow(event); mTracker.OnMouseLeftWindow(event);
SetCursor(wxCURSOR_SIZEWE); SetCursor(wxCURSOR_CROSS);
} }
void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) {
mTracker.OnMouseEnterWindow(event); mTracker.OnMouseEnterWindow(event);
SetCursor(wxCURSOR_SIZEWE); SetCursor(wxCURSOR_CROSS);
} }

View File

@ -48,6 +48,8 @@ private:
Timer timer; Timer timer;
float frameTimer; float frameTimer;
MouseTracker mTracker; MouseTracker mTracker;
bool bwChange;
int demodBW;
// event table // event table
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@ -82,14 +82,14 @@ void WaterfallContext::Draw(std::vector<float> &points) {
} }
void WaterfallContext::DrawFreqSelector(float uxPos) { void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
DemodulatorInstance *demod = wxGetApp().getDemodTest();
if (!demod) { if (!demod) {
return; return;
} }
glClear(GL_DEPTH_BUFFER_BIT); float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE;
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
@ -98,7 +98,7 @@ void WaterfallContext::DrawFreqSelector(float uxPos) {
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
float ofs = ((float) demod->params.inputResampleRate) / (float) SRATE; float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
@ -107,6 +107,36 @@ void WaterfallContext::DrawFreqSelector(float uxPos) {
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
glEnd(); glEnd();
glEnable(GL_DEPTH_TEST);
}
void WaterfallContext::DrawFreqSelector(float uxPos) {
DemodulatorInstance *demod = wxGetApp().getDemodTest();
if (!demod) {
return;
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
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;
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
glEnd();
glEnable(GL_DEPTH_TEST);
} }

View File

@ -2,6 +2,7 @@
#include "PrimaryGLContext.h" #include "PrimaryGLContext.h"
#include "Gradient.h" #include "Gradient.h"
#include "DemodulatorMgr.h"
#define NUM_WATERFALL_LINES 512 #define NUM_WATERFALL_LINES 512
@ -14,6 +15,7 @@ public:
void BeginDraw(); void BeginDraw();
void Draw(std::vector<float> &points); void Draw(std::vector<float> &points);
void DrawFreqSelector(float uxPos); void DrawFreqSelector(float uxPos);
void DrawDemod(DemodulatorInstance *demod);
void EndDraw(); void EndDraw();
private: private: