2014-10-27 21:22:29 -04:00
|
|
|
#include "AppFrame.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
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
#include <vector>
|
|
|
|
#include "SDRThread.h"
|
2014-11-17 22:58:56 -05:00
|
|
|
#include "DemodulatorMgr.h"
|
2014-11-16 16:51:45 -05:00
|
|
|
#include "AudioThread.h"
|
2014-11-16 19:02:40 -05:00
|
|
|
#include "CubicSDR.h"
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-11-21 21:50:14 -05:00
|
|
|
#include <thread>
|
|
|
|
|
2014-12-27 23:47:56 -05:00
|
|
|
#include <wx/panel.h>
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
wxBEGIN_EVENT_TABLE(AppFrame, wxFrame)
|
|
|
|
//EVT_MENU(wxID_NEW, AppFrame::OnNewWindow)
|
2014-12-31 21:31:37 -05:00
|
|
|
//EVT_MENU(wxID_CLOSE, AppFrame::OnClose)
|
|
|
|
EVT_MENU(wxID_ANY, AppFrame::OnMenu)
|
|
|
|
|
2014-11-17 18:14:37 -05:00
|
|
|
EVT_COMMAND(wxID_ANY, wxEVT_THREAD, AppFrame::OnThread)
|
2014-10-28 21:39:59 -04:00
|
|
|
EVT_IDLE(AppFrame::OnIdle)
|
2014-10-27 21:22:29 -04:00
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
AppFrame::AppFrame() :
|
2014-12-31 21:31:37 -05:00
|
|
|
wxFrame(NULL, wxID_ANY, wxT("CubicSDR")), activeDemodulator(NULL) {
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
2014-12-27 23:47:56 -05:00
|
|
|
wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL);
|
2014-12-28 20:55:05 -05:00
|
|
|
wxBoxSizer *demodVisuals = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxBoxSizer *demodTray = new wxBoxSizer(wxHORIZONTAL);
|
2014-12-27 23:47:56 -05:00
|
|
|
|
2014-12-29 00:24:10 -05:00
|
|
|
/*
|
2014-12-27 23:47:56 -05:00
|
|
|
demodTray->AddSpacer(5);
|
|
|
|
demodOpts->AddSpacer(5);
|
|
|
|
|
|
|
|
wxStaticText *audioDeviceLabel = new wxStaticText(this, wxID_ANY, wxString("Audio Device:"));
|
|
|
|
demodOpts->Add(audioDeviceLabel, 1, wxFIXED_MINSIZE | wxALL, 0);
|
|
|
|
|
|
|
|
wxArrayString str;
|
|
|
|
str.Add("Primary Device");
|
|
|
|
wxChoice *wxCh = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, str);
|
|
|
|
demodOpts->Add(wxCh, 1, wxFIXED_MINSIZE | wxALL, 0);
|
|
|
|
|
|
|
|
demodOpts->AddSpacer(2);
|
|
|
|
|
|
|
|
wxStaticText *demodTypeLabel = new wxStaticText(this, wxID_ANY, wxString("Demodulation:"));
|
|
|
|
demodOpts->Add(demodTypeLabel, 1, wxFIXED_MINSIZE | wxALL, 0);
|
|
|
|
|
|
|
|
str.Clear();
|
|
|
|
str.Add("FM");
|
|
|
|
str.Add("FM Stereo");
|
|
|
|
str.Add("AM");
|
|
|
|
str.Add("LSB");
|
|
|
|
str.Add("USB");
|
|
|
|
wxChoice *wxDemodChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, str);
|
|
|
|
demodOpts->Add(wxDemodChoice, 1, wxFIXED_MINSIZE | wxALL, 0);
|
|
|
|
|
|
|
|
demodOpts->AddSpacer(5);
|
|
|
|
demodTray->AddSpacer(5);
|
|
|
|
|
2014-12-29 00:24:10 -05:00
|
|
|
demodTray->Add(demodOpts, 1, wxEXPAND | wxALL, 0); */
|
2014-11-15 23:41:41 -05:00
|
|
|
|
2014-12-29 00:24:10 -05:00
|
|
|
demodSpectrumCanvas = new SpectrumCanvas(this, NULL);
|
|
|
|
demodSpectrumCanvas->Setup(1024);
|
|
|
|
demodSpectrumCanvas->SetView(DEFAULT_FREQ, 300000);
|
|
|
|
demodVisuals->Add(demodSpectrumCanvas, 1, wxEXPAND | wxALL, 0);
|
|
|
|
|
|
|
|
demodVisuals->AddSpacer(1);
|
2014-12-28 20:55:05 -05:00
|
|
|
|
2014-12-28 05:13:46 -05:00
|
|
|
demodWaterfallCanvas = new WaterfallCanvas(this, NULL);
|
2014-12-29 00:24:10 -05:00
|
|
|
demodWaterfallCanvas->Setup(1024, 256);
|
|
|
|
demodWaterfallCanvas->SetView(DEFAULT_FREQ, 300000);
|
|
|
|
demodWaterfallCanvas->attachSpectrumCanvas(demodSpectrumCanvas);
|
2014-12-28 20:55:05 -05:00
|
|
|
demodVisuals->Add(demodWaterfallCanvas, 3, wxEXPAND | wxALL, 0);
|
|
|
|
|
2014-12-31 19:45:01 -05:00
|
|
|
demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0);
|
|
|
|
|
|
|
|
demodTray->AddSpacer(2);
|
|
|
|
|
|
|
|
demodSignalMeter = new MeterCanvas(this, NULL);
|
|
|
|
demodSignalMeter->setMax(0.5);
|
|
|
|
demodTray->Add(demodSignalMeter, 1, wxEXPAND | wxALL, 0);
|
2014-12-28 20:55:05 -05:00
|
|
|
|
|
|
|
demodTray->AddSpacer(2);
|
2014-12-28 05:13:46 -05:00
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
scopeCanvas = new ScopeCanvas(this, NULL);
|
2014-12-31 19:45:01 -05:00
|
|
|
demodTray->Add(scopeCanvas, 30, wxEXPAND | wxALL, 0);
|
2014-12-27 23:47:56 -05:00
|
|
|
|
2014-12-28 20:55:05 -05:00
|
|
|
vbox->Add(demodTray, 2, wxEXPAND | wxALL, 0);
|
2014-11-15 23:41:41 -05:00
|
|
|
vbox->AddSpacer(2);
|
|
|
|
spectrumCanvas = new SpectrumCanvas(this, NULL);
|
2014-12-28 05:13:46 -05:00
|
|
|
spectrumCanvas->Setup(2048);
|
2014-11-15 23:41:41 -05:00
|
|
|
vbox->Add(spectrumCanvas, 1, wxEXPAND | wxALL, 0);
|
|
|
|
vbox->AddSpacer(2);
|
|
|
|
waterfallCanvas = new WaterfallCanvas(this, NULL);
|
2014-12-29 00:24:10 -05:00
|
|
|
waterfallCanvas->Setup(2048, 512);
|
|
|
|
waterfallCanvas->attachSpectrumCanvas(spectrumCanvas);
|
2014-11-15 23:41:41 -05:00
|
|
|
vbox->Add(waterfallCanvas, 4, wxEXPAND | wxALL, 0);
|
|
|
|
|
|
|
|
this->SetSizer(vbox);
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-12-10 21:22:13 -05:00
|
|
|
waterfallCanvas->SetFocusFromKbd();
|
|
|
|
waterfallCanvas->SetFocus();
|
|
|
|
|
2014-10-27 23:52:25 -04:00
|
|
|
// SetIcon(wxICON(sample));
|
2014-10-27 21:22:29 -04:00
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
// Make a menubar
|
2014-12-31 19:45:01 -05:00
|
|
|
// wxMenu *menu = new wxMenu;
|
2014-10-27 21:22:29 -04:00
|
|
|
// menu->Append(wxID_NEW);
|
|
|
|
// menu->AppendSeparator();
|
2014-12-31 19:45:01 -05:00
|
|
|
// menu->Append(wxID_CLOSE);
|
|
|
|
// wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
// menuBar->Append(menu, wxT("&File"));
|
|
|
|
|
|
|
|
wxMenu *menu = new wxMenu;
|
|
|
|
|
|
|
|
std::vector<RtAudio::DeviceInfo> devices;
|
|
|
|
std::vector<RtAudio::DeviceInfo>::iterator devices_i;
|
|
|
|
std::map<int,RtAudio::DeviceInfo>::iterator mdevices_i;
|
|
|
|
AudioThread::enumerateDevices(devices);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (devices_i = devices.begin(); devices_i != devices.end(); devices_i++) {
|
|
|
|
if (devices_i->inputChannels) {
|
|
|
|
input_devices[i] = *devices_i;
|
|
|
|
}
|
|
|
|
if (devices_i->outputChannels) {
|
|
|
|
output_devices[i] = *devices_i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2014-12-31 21:31:37 -05:00
|
|
|
i = 0;
|
2014-12-31 19:45:01 -05:00
|
|
|
|
|
|
|
for (mdevices_i = output_devices.begin(); mdevices_i != output_devices.end(); mdevices_i++) {
|
2014-12-31 21:31:37 -05:00
|
|
|
wxMenuItem *itm = menu->AppendRadioItem(wxID_RT_AUDIO_DEVICE+mdevices_i->first,mdevices_i->second.name,wxT("Description?"));
|
2014-12-31 19:45:01 -05:00
|
|
|
if (mdevices_i->second.isDefaultOutput) {
|
|
|
|
itm->Check(true);
|
|
|
|
}
|
2014-12-31 21:31:37 -05:00
|
|
|
output_device_menuitems[mdevices_i->first] = itm;
|
2014-12-31 19:45:01 -05:00
|
|
|
}
|
|
|
|
|
2014-10-27 21:22:29 -04:00
|
|
|
wxMenuBar *menuBar = new wxMenuBar;
|
2014-12-31 19:45:01 -05:00
|
|
|
menuBar->Append(menu, wxT("&Device"));
|
2014-10-27 21:22:29 -04:00
|
|
|
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
CreateStatusBar();
|
2014-11-16 19:02:40 -05:00
|
|
|
SetClientSize(1280, 600);
|
2014-10-31 01:37:01 -04:00
|
|
|
Centre();
|
2014-10-27 21:22:29 -04:00
|
|
|
Show();
|
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), DEFAULT_FREQ));
|
2014-11-25 00:35:06 -05:00
|
|
|
|
2014-10-27 21:22:29 -04:00
|
|
|
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
|
|
|
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
|
|
|
// ShowFullScreen(true);
|
|
|
|
}
|
|
|
|
|
2014-11-04 18:39:08 -05:00
|
|
|
AppFrame::~AppFrame() {
|
|
|
|
|
2014-11-11 20:25:16 -05:00
|
|
|
}
|
|
|
|
|
2014-12-31 21:31:37 -05:00
|
|
|
void AppFrame::OnMenu(wxCommandEvent& event) {
|
|
|
|
if (event.GetId() >= wxID_RT_AUDIO_DEVICE && event.GetId() < wxID_RT_AUDIO_DEVICE+output_devices.size()) {
|
|
|
|
if (activeDemodulator) {
|
|
|
|
activeDemodulator->setOutputDevice(event.GetId()-wxID_RT_AUDIO_DEVICE);
|
|
|
|
activeDemodulator = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-10-27 21:22:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) {
|
|
|
|
new AppFrame();
|
|
|
|
}
|
2014-10-28 21:39:59 -04:00
|
|
|
|
2014-11-17 18:14:37 -05:00
|
|
|
void AppFrame::OnThread(wxCommandEvent& event) {
|
2014-11-22 22:17:33 -05:00
|
|
|
event.Skip();
|
2014-11-16 16:51:45 -05:00
|
|
|
}
|
|
|
|
|
2014-10-28 21:39:59 -04:00
|
|
|
void AppFrame::OnIdle(wxIdleEvent& event) {
|
2014-11-22 20:57:06 -05:00
|
|
|
bool work_done = false;
|
2014-10-28 21:39:59 -04:00
|
|
|
|
2014-12-16 20:33:44 -05:00
|
|
|
//#ifdef __APPLE__
|
|
|
|
// std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
|
|
|
// std::this_thread::yield();
|
|
|
|
//#endif
|
2014-12-28 05:13:46 -05:00
|
|
|
|
|
|
|
DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
|
|
|
|
|
|
|
|
if (demod) {
|
2014-12-31 19:45:01 -05:00
|
|
|
if (demod != activeDemodulator) {
|
|
|
|
demodSignalMeter->setInputValue(demod->getSquelchLevel());
|
2014-12-31 21:31:37 -05:00
|
|
|
int outputDevice = demod->getOutputDevice();
|
|
|
|
scopeCanvas->setDeviceName(output_devices[outputDevice].name);
|
|
|
|
output_device_menuitems[outputDevice]->Check(true);
|
2014-12-31 19:45:01 -05:00
|
|
|
}
|
2014-12-28 20:55:05 -05:00
|
|
|
if (demodWaterfallCanvas->getDragState() == WaterfallCanvas::WF_DRAG_NONE) {
|
|
|
|
if (demod->getParams().frequency != demodWaterfallCanvas->GetCenterFrequency()) {
|
|
|
|
demodWaterfallCanvas->SetCenterFrequency(demod->getParams().frequency);
|
2014-12-29 00:24:10 -05:00
|
|
|
demodSpectrumCanvas->SetCenterFrequency(demod->getParams().frequency);
|
2014-12-28 20:55:05 -05:00
|
|
|
}
|
|
|
|
unsigned int demodBw = (unsigned int) ceil((float) demod->getParams().bandwidth * 2.5);
|
2014-12-29 00:24:10 -05:00
|
|
|
if (demodBw > SRATE / 2) {
|
|
|
|
demodBw = SRATE / 2;
|
2014-12-28 20:55:05 -05:00
|
|
|
}
|
|
|
|
if (demodBw != demodWaterfallCanvas->GetBandwidth()) {
|
|
|
|
demodWaterfallCanvas->SetBandwidth(demodBw);
|
2014-12-29 00:24:10 -05:00
|
|
|
demodSpectrumCanvas->SetBandwidth(demodBw);
|
2014-12-28 20:55:05 -05:00
|
|
|
}
|
2014-12-28 05:13:46 -05:00
|
|
|
}
|
2014-12-31 19:45:01 -05:00
|
|
|
demodSignalMeter->setLevel(demod->getSignalLevel());
|
|
|
|
if (demodSignalMeter->inputChanged()) {
|
|
|
|
demod->setSquelchLevel(demodSignalMeter->getInputValue());
|
|
|
|
}
|
|
|
|
activeDemodulator = demod;
|
2014-12-28 05:13:46 -05:00
|
|
|
}
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
if (!wxGetApp().getIQVisualQueue()->empty()) {
|
2014-12-26 16:15:35 -05:00
|
|
|
DemodulatorThreadIQData *iqData;
|
2014-11-23 19:39:27 -05:00
|
|
|
wxGetApp().getIQVisualQueue()->pop(iqData);
|
2014-11-22 20:57:06 -05:00
|
|
|
|
2014-12-23 01:59:03 -05:00
|
|
|
if (iqData && iqData->data.size()) {
|
2014-12-29 00:24:10 -05:00
|
|
|
// spectrumCanvas->setData(iqData);
|
2014-12-28 05:13:46 -05:00
|
|
|
waterfallCanvas->setData(iqData);
|
|
|
|
demodWaterfallCanvas->setData(iqData);
|
2014-12-23 01:59:03 -05:00
|
|
|
delete iqData;
|
2014-11-22 20:57:06 -05:00
|
|
|
} else {
|
|
|
|
std::cout << "Incoming IQ data empty?" << std::endl;
|
|
|
|
}
|
|
|
|
work_done = true;
|
|
|
|
}
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
if (!wxGetApp().getAudioVisualQueue()->empty()) {
|
2014-12-23 01:59:03 -05:00
|
|
|
AudioThreadInput *demodAudioData;
|
2014-11-23 19:39:27 -05:00
|
|
|
wxGetApp().getAudioVisualQueue()->pop(demodAudioData);
|
2014-12-23 01:59:03 -05:00
|
|
|
if (demodAudioData && demodAudioData->data.size()) {
|
2014-12-28 05:13:46 -05:00
|
|
|
if (scopeCanvas->waveform_points.size() != demodAudioData->data.size() * 2) {
|
|
|
|
scopeCanvas->waveform_points.resize(demodAudioData->data.size() * 2);
|
2014-11-22 22:17:33 -05:00
|
|
|
}
|
|
|
|
|
2014-12-23 01:59:03 -05:00
|
|
|
for (int i = 0, iMax = demodAudioData->data.size(); i < iMax; i++) {
|
|
|
|
scopeCanvas->waveform_points[i * 2 + 1] = demodAudioData->data[i] * 0.5f;
|
2014-11-22 22:17:33 -05:00
|
|
|
scopeCanvas->waveform_points[i * 2] = ((double) i / (double) iMax);
|
|
|
|
}
|
|
|
|
|
2014-12-29 00:24:10 -05:00
|
|
|
scopeCanvas->setStereo(demodAudioData->channels == 2);
|
2014-12-26 23:28:18 -05:00
|
|
|
|
2014-12-23 01:59:03 -05:00
|
|
|
delete demodAudioData;
|
2014-11-22 22:17:33 -05:00
|
|
|
} else {
|
|
|
|
std::cout << "Incoming Demodulator data empty?" << std::endl;
|
|
|
|
}
|
|
|
|
work_done = true;
|
|
|
|
}
|
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
if (!work_done) {
|
2014-12-16 21:30:03 -05:00
|
|
|
event.Skip();
|
2014-11-22 20:57:06 -05:00
|
|
|
}
|
2014-10-28 21:39:59 -04:00
|
|
|
}
|