Per-demodulator gain settings

This commit is contained in:
Charles J. Cliffe 2015-01-10 20:33:30 -05:00
parent f454c34245
commit 60b5dbb07f
8 changed files with 70 additions and 4 deletions

View File

@ -33,7 +33,7 @@ EVT_IDLE(AppFrame::OnIdle)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
AppFrame::AppFrame() : 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 *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL);
@ -87,6 +87,13 @@ AppFrame::AppFrame() :
demodTray->Add(demodScopeTray, 30, wxEXPAND | wxALL, 0); 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->Add(demodTray, 12, wxEXPAND | wxALL, 0);
vbox->AddSpacer(2); vbox->AddSpacer(2);
spectrumCanvas = new SpectrumCanvas(this, NULL); spectrumCanvas = new SpectrumCanvas(this, NULL);
@ -215,6 +222,8 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
wxGetApp().getDemodMgr().terminateAll(); wxGetApp().getDemodMgr().terminateAll();
wxGetApp().setFrequency(DEFAULT_FREQ); wxGetApp().setFrequency(DEFAULT_FREQ);
wxGetApp().setOffset(0); wxGetApp().setOffset(0);
SetTitle(wxT(CUBICSDR_TITLE));
currentSessionFile = "";
} else if (event.GetId() == wxID_EXIT) { } else if (event.GetId() == wxID_EXIT) {
Close(false); Close(false);
} }
@ -245,6 +254,7 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
if (demod) { if (demod) {
if (demod != activeDemodulator) { if (demod != activeDemodulator) {
demodSignalMeter->setInputValue(demod->getSquelchLevel()); demodSignalMeter->setInputValue(demod->getSquelchLevel());
demodGainMeter->setInputValue(demod->getGain());
int outputDevice = demod->getOutputDevice(); int outputDevice = demod->getOutputDevice();
scopeCanvas->setDeviceName(outputDevices[outputDevice].name); scopeCanvas->setDeviceName(outputDevices[outputDevice].name);
outputDeviceMenuItems[outputDevice]->Check(true); outputDeviceMenuItems[outputDevice]->Check(true);
@ -272,9 +282,14 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
demodSpectrumCanvas->setBandwidth(demodBw); demodSpectrumCanvas->setBandwidth(demodBw);
} }
demodSignalMeter->setLevel(demod->getSignalLevel()); demodSignalMeter->setLevel(demod->getSignalLevel());
demodGainMeter->setLevel(demod->getGain());
if (demodSignalMeter->inputChanged()) { if (demodSignalMeter->inputChanged()) {
demod->setSquelchLevel(demodSignalMeter->getInputValue()); demod->setSquelchLevel(demodSignalMeter->getInputValue());
} }
if (demodGainMeter->inputChanged()) {
demod->setGain(demodGainMeter->getInputValue());
demodGainMeter->setLevel(demodGainMeter->getInputValue());
}
activeDemodulator = demod; activeDemodulator = demod;
} }
@ -344,9 +359,16 @@ void AppFrame::saveSession(std::string fileName) {
*demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled() ? 1 : 0; *demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled() ? 1 : 0;
*demod->newChild("stereo") = (*instance_i)->isStereo() ? 1 : 0; *demod->newChild("stereo") = (*instance_i)->isStereo() ? 1 : 0;
*demod->newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name; *demod->newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name;
*demod->newChild("gain") = (*instance_i)->getGain();
} }
s.SaveToFileXML(fileName); 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) { 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 squelch_enabled = demod->hasAnother("squelch_enabled") ? (int) *demod->getNext("squelch_enabled") : 0;
int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0; int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0;
std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : ""; 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(); DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread();
newDemod->setDemodulatorType(type); newDemod->setDemodulatorType(type);
newDemod->setBandwidth(bandwidth); newDemod->setBandwidth(bandwidth);
newDemod->setFrequency(freq); newDemod->setFrequency(freq);
newDemod->setGain(gain);
newDemod->updateLabel(freq); newDemod->updateLabel(freq);
if (squelch_enabled) { if (squelch_enabled) {
newDemod->setSquelchEnabled(true); 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\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl; std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl;
std::cout << "\t\tOutput Device: " << output_device << std::endl; std::cout << "\t\tOutput Device: " << output_device << std::endl;
} }
} catch (DataInvalidChildException &e) { } catch (DataInvalidChildException &e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
return false; return false;
@ -436,4 +458,9 @@ bool AppFrame::loadSession(std::string fileName) {
} }
currentSessionFile = 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()));
} }

View File

@ -40,6 +40,7 @@ private:
SpectrumCanvas *demodSpectrumCanvas; SpectrumCanvas *demodSpectrumCanvas;
WaterfallCanvas *demodWaterfallCanvas; WaterfallCanvas *demodWaterfallCanvas;
MeterCanvas *demodSignalMeter; MeterCanvas *demodSignalMeter;
MeterCanvas *demodGainMeter;
TuningCanvas *demodTuner; TuningCanvas *demodTuner;
// event table // event table

View File

@ -1,6 +1,14 @@
#pragma once #pragma once
#define CUBICSDR_VERSION "v0.01a" #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__ #ifdef __APPLE__
#define BUF_SIZE (16384*2) #define BUF_SIZE (16384*2)

View File

@ -460,3 +460,17 @@ void AudioThread::setActive(bool state) {
AudioThreadCommandQueue *AudioThread::getCommandQueue() { AudioThreadCommandQueue *AudioThread::getCommandQueue() {
return &cmdQueue; 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;
}

View File

@ -63,7 +63,7 @@ public:
std::atomic<bool> initialized; std::atomic<bool> initialized;
std::atomic<bool> active; std::atomic<bool> active;
std::atomic<int> outputDevice; std::atomic<int> outputDevice;
float gain; std::atomic<float> gain;
AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify); AudioThread(AudioThreadInputQueue *inputQueue, DemodulatorThreadCommandQueue* threadQueueNotify);
~AudioThread(); ~AudioThread();
@ -79,6 +79,9 @@ public:
bool isActive(); bool isActive();
void setActive(bool state); void setActive(bool state);
void setGain(float gain_in);
float getGain();
AudioThreadCommandQueue *getCommandQueue(); AudioThreadCommandQueue *getCommandQueue();
private: private:

View File

@ -298,3 +298,11 @@ long long DemodulatorInstance::getFrequency() {
} }
return currentFrequency; return currentFrequency;
} }
void DemodulatorInstance::setGain(float gain_in) {
audioThread->setGain(gain_in);
}
float DemodulatorInstance::getGain() {
return audioThread->getGain();
}

View File

@ -69,6 +69,9 @@ public:
void setBandwidth(int bw); void setBandwidth(int bw);
int getBandwidth(); int getBandwidth();
void setGain(float gain_in);
float getGain();
void setFrequency(long long freq); void setFrequency(long long freq);
long long getFrequency(); long long getFrequency();
private: private:

View File

@ -717,6 +717,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
demod->setSquelchLevel(last->getSquelchLevel()); demod->setSquelchLevel(last->getSquelchLevel());
demod->setSquelchEnabled(last->isSquelchEnabled()); demod->setSquelchEnabled(last->isSquelchEnabled());
demod->setStereo(last->isStereo()); demod->setStereo(last->isStereo());
demod->setGain(last->getGain());
} }
demod->run(); demod->run();
@ -776,6 +777,7 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
demod->setSquelchLevel(last->getSquelchLevel()); demod->setSquelchLevel(last->getSquelchLevel());
demod->setSquelchEnabled(last->isSquelchEnabled()); demod->setSquelchEnabled(last->isSquelchEnabled());
demod->setStereo(last->isStereo()); demod->setStereo(last->isStereo());
demod->setGain(last->getGain());
} }
demod->run(); demod->run();