From 60b5dbb07fe7d5c5f853af34e07081c298a63326 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sat, 10 Jan 2015 20:33:30 -0500 Subject: [PATCH] Per-demodulator gain settings --- src/AppFrame.cpp | 33 ++++++++++++++++++++++++++++--- src/AppFrame.h | 1 + src/CubicSDRDefs.h | 8 ++++++++ src/audio/AudioThread.cpp | 14 +++++++++++++ src/audio/AudioThread.h | 5 ++++- src/demod/DemodulatorInstance.cpp | 8 ++++++++ src/demod/DemodulatorInstance.h | 3 +++ src/visual/WaterfallCanvas.cpp | 2 ++ 8 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 2dc848c..93869c0 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -33,7 +33,7 @@ EVT_IDLE(AppFrame::OnIdle) wxEND_EVENT_TABLE() AppFrame::AppFrame() : - wxFrame(NULL, wxID_ANY, wxT("CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)")), activeDemodulator(NULL) { + wxFrame(NULL, wxID_ANY, wxT(CUBICSDR_TITLE)), activeDemodulator(NULL) { wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL); @@ -87,6 +87,13 @@ AppFrame::AppFrame() : demodTray->Add(demodScopeTray, 30, wxEXPAND | wxALL, 0); + demodTray->AddSpacer(2); + + demodGainMeter = new MeterCanvas(this, NULL); + demodGainMeter->setMax(2.0); + demodGainMeter->setHelpTip("Current Demodulator Gain Level. Click / Drag to set Gain level."); + demodTray->Add(demodGainMeter, 1, wxEXPAND | wxALL, 0); + vbox->Add(demodTray, 12, wxEXPAND | wxALL, 0); vbox->AddSpacer(2); spectrumCanvas = new SpectrumCanvas(this, NULL); @@ -215,6 +222,8 @@ void AppFrame::OnMenu(wxCommandEvent& event) { wxGetApp().getDemodMgr().terminateAll(); wxGetApp().setFrequency(DEFAULT_FREQ); wxGetApp().setOffset(0); + SetTitle(wxT(CUBICSDR_TITLE)); + currentSessionFile = ""; } else if (event.GetId() == wxID_EXIT) { Close(false); } @@ -245,6 +254,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) { if (demod) { if (demod != activeDemodulator) { demodSignalMeter->setInputValue(demod->getSquelchLevel()); + demodGainMeter->setInputValue(demod->getGain()); int outputDevice = demod->getOutputDevice(); scopeCanvas->setDeviceName(outputDevices[outputDevice].name); outputDeviceMenuItems[outputDevice]->Check(true); @@ -272,9 +282,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) { demodSpectrumCanvas->setBandwidth(demodBw); } demodSignalMeter->setLevel(demod->getSignalLevel()); + demodGainMeter->setLevel(demod->getGain()); if (demodSignalMeter->inputChanged()) { demod->setSquelchLevel(demodSignalMeter->getInputValue()); } + if (demodGainMeter->inputChanged()) { + demod->setGain(demodGainMeter->getInputValue()); + demodGainMeter->setLevel(demodGainMeter->getInputValue()); + } activeDemodulator = demod; } @@ -344,9 +359,16 @@ void AppFrame::saveSession(std::string fileName) { *demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled() ? 1 : 0; *demod->newChild("stereo") = (*instance_i)->isStereo() ? 1 : 0; *demod->newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name; + *demod->newChild("gain") = (*instance_i)->getGain(); } s.SaveToFileXML(fileName); + + + currentSessionFile = fileName; + std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator)+1); + GetStatusBar()->SetStatusText(wxString::Format(wxT("Saved session: %s"), currentSessionFile.c_str())); + SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str())); } bool AppFrame::loadSession(std::string fileName) { @@ -387,11 +409,13 @@ bool AppFrame::loadSession(std::string fileName) { int squelch_enabled = demod->hasAnother("squelch_enabled") ? (int) *demod->getNext("squelch_enabled") : 0; int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0; std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : ""; + float gain = demod->hasAnother("gain") ? (float) *demod->getNext("gain") : 1.0; DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread(); newDemod->setDemodulatorType(type); newDemod->setBandwidth(bandwidth); newDemod->setFrequency(freq); + newDemod->setGain(gain); newDemod->updateLabel(freq); if (squelch_enabled) { newDemod->setSquelchEnabled(true); @@ -424,9 +448,7 @@ bool AppFrame::loadSession(std::string fileName) { std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl; std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl; std::cout << "\t\tOutput Device: " << output_device << std::endl; - } - } catch (DataInvalidChildException &e) { std::cout << e.what() << std::endl; return false; @@ -436,4 +458,9 @@ bool AppFrame::loadSession(std::string fileName) { } currentSessionFile = fileName; + + std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator)+1); + + GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str())); + SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str())); } diff --git a/src/AppFrame.h b/src/AppFrame.h index cb7d378..d773b94 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -40,6 +40,7 @@ private: SpectrumCanvas *demodSpectrumCanvas; WaterfallCanvas *demodWaterfallCanvas; MeterCanvas *demodSignalMeter; + MeterCanvas *demodGainMeter; TuningCanvas *demodTuner; // event table diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 5c2338d..f2655b3 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -1,6 +1,14 @@ #pragma once #define CUBICSDR_VERSION "v0.01a" +#define CUBICSDR_TITLE "CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)" + +const char filePathSeparator = +#ifdef _WIN32 + '\\'; +#else + '/'; +#endif #ifdef __APPLE__ #define BUF_SIZE (16384*2) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 139d641..ebbf27f 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -460,3 +460,17 @@ void AudioThread::setActive(bool state) { AudioThreadCommandQueue *AudioThread::getCommandQueue() { return &cmdQueue; } + +void AudioThread::setGain(float gain_in) { + if (gain < 0.0) { + gain = 0.0; + } + if (gain > 2.0) { + gain = 2.0; + } + gain = gain_in; +} + +float AudioThread::getGain() { + return gain; +} diff --git a/src/audio/AudioThread.h b/src/audio/AudioThread.h index f849af7..649b07f 100644 --- a/src/audio/AudioThread.h +++ b/src/audio/AudioThread.h @@ -63,7 +63,7 @@ public: std::atomic initialized; std::atomic active; std::atomic outputDevice; - float gain; + std::atomic gain; AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify); ~AudioThread(); @@ -79,6 +79,9 @@ public: bool isActive(); void setActive(bool state); + void setGain(float gain_in); + float getGain(); + AudioThreadCommandQueue *getCommandQueue(); private: diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index a203885..5645948 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -298,3 +298,11 @@ long long DemodulatorInstance::getFrequency() { } return currentFrequency; } + +void DemodulatorInstance::setGain(float gain_in) { + audioThread->setGain(gain_in); +} + +float DemodulatorInstance::getGain() { + return audioThread->getGain(); +} diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index eedaa5a..bd2576a 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -69,6 +69,9 @@ public: void setBandwidth(int bw); int getBandwidth(); + void setGain(float gain_in); + float getGain(); + void setFrequency(long long freq); long long getFrequency(); private: diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 9a502db..c8e1ae9 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -717,6 +717,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { demod->setSquelchLevel(last->getSquelchLevel()); demod->setSquelchEnabled(last->isSquelchEnabled()); demod->setStereo(last->isStereo()); + demod->setGain(last->getGain()); } demod->run(); @@ -776,6 +777,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) { demod->setSquelchLevel(last->getSquelchLevel()); demod->setSquelchEnabled(last->isSquelchEnabled()); demod->setStereo(last->isStereo()); + demod->setGain(last->getGain()); } demod->run();