From 3c5bad4e3d2294cefbe9acfcea5674c339392366 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 12 Mar 2015 19:41:50 -0400 Subject: [PATCH] Audio bandwidth menu items --- src/AppFrame.cpp | 57 ++++++++++++++++++++++++++++++++- src/AppFrame.h | 12 ++++--- src/CubicSDRDefs.h | 2 +- src/demod/DemodDefs.h | 2 +- src/demod/DemodulatorThread.cpp | 2 +- 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 309d517..22193e3 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -230,9 +230,39 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { p++; } - menuBar->Append(menu, wxT("&Device")); + menuBar->Append(menu, wxT("Input &Device")); } + + menu = new wxMenu; + + i = 0; + + for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { + new wxMenu; + int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first; + wxMenu *subMenu = new wxMenu; + menu->AppendSubMenu(subMenu,mdevices_i->second.name, wxT("Description?")); + + int j = 0; + for (std::vector::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { + std::stringstream srateName; + srateName << ((float)(*srate)/1000.0f) << "kHz"; + wxMenuItem *itm = subMenu->AppendRadioItem(menu_id+j, srateName.str(), wxT("Description?")); + + if ((*srate) == DEFAULT_AUDIO_SAMPLE_RATE) { + itm->Check(true); + } + + audioSampleRateMenuItems[menu_id+j] = itm; + + j++; + } + } + + menuBar->Append(menu, wxT("Audio &Bandwidth")); + + SetMenuBar(menuBar); CreateStatusBar(); @@ -346,6 +376,31 @@ void AppFrame::OnMenu(wxCommandEvent& event) { if (event.GetId() >= wxID_DEVICE_ID && event.GetId() <= wxID_DEVICE_ID + devs->size()) { wxGetApp().setDevice(event.GetId() - wxID_DEVICE_ID); } + + + if (event.GetId() >= wxID_AUDIO_BANDWIDTH_BASE) { + int evId = event.GetId(); + std::vector::iterator devices_i; + std::map::iterator mdevices_i; + + int i = 0; + for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { + int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first; + + int j = 0; + for (std::vector::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { + + if (evId == menu_id + j) { + //audioSampleRateMenuItems[menu_id+j]; + std::cout << "Would set audio sample rate on device " << mdevices_i->second.name << " (" << mdevices_i->first << ") to " << (*srate) << "Hz" << std::endl; + } + + j++; + } + i++; + } + } + } void AppFrame::OnClose(wxCommandEvent& WXUNUSED(event)) { diff --git a/src/AppFrame.h b/src/AppFrame.h index 93dad38..1863dc2 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -33,6 +33,10 @@ #define wxID_DEVICE_ID 3500 +#define wxID_AUDIO_BANDWIDTH_BASE 9000 +#define wxID_AUDIO_DEVICE_MULTIPLIER 50 + + // Define a new frame type class AppFrame: public wxFrame { @@ -60,17 +64,15 @@ private: MeterCanvas *demodSignalMeter; MeterCanvas *demodGainMeter; TuningCanvas *demodTuner; -// event table DemodulatorInstance *activeDemodulator; std::vector devices; std::map inputDevices; std::map outputDevices; - std::map outputDeviceMenuItems; - - std::map sampleRateMenuItems; - + std::map outputDeviceMenuItems; + std::map sampleRateMenuItems; + std::map audioSampleRateMenuItems; std::string currentSessionFile; diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 8b09aa1..3614fba 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -42,7 +42,7 @@ const char filePathSeparator = #define DEFAULT_FFT_SIZE 2048 #define DEFAULT_FREQ 100000000 -#define AUDIO_FREQUENCY 44100 +#define DEFAULT_AUDIO_SAMPLE_RATE 44100 #define DEFAULT_DEMOD_TYPE 1 #define DEFAULT_DEMOD_BW 200000 diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index f68686c..fb5f5d9 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -128,7 +128,7 @@ public: DemodulatorThreadParameters() : frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), bandwidth(200000), audioSampleRate( - AUDIO_FREQUENCY), demodType(DEMOD_TYPE_FM) { + DEFAULT_AUDIO_SAMPLE_RATE), demodType(DEMOD_TYPE_FM) { } diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 169137f..e8d7cf6 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -47,7 +47,7 @@ void DemodulatorThread::threadMain() { firfilt_rrrf firStereoRight = NULL; // Stereo filters / shifters - double firStereoCutoff = 0.5 * ((double) 36000 / (double) AUDIO_FREQUENCY); // filter cutoff frequency + double firStereoCutoff = 0.5 * ((double) 36000 / (double) DEFAULT_AUDIO_SAMPLE_RATE); // filter cutoff frequency float ft = 0.05f; // filter transition float As = 120.0f; // stop-band attenuation [dB] float mu = 0.0f; // fractional timing offset