Skip to content

Commit

Permalink
Add AGC button
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed May 25, 2024
1 parent 407eeaf commit 330593f
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 40 deletions.
84 changes: 48 additions & 36 deletions Default/Audio/AudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AudioProcessor::AudioProcessor(UIMediator *mediator, QObject *parent)
assertAudioDevice();

m_tracker = new Suscan::AnalyzerRequestTracker(this);
this->connectAll();
connectAll();

m_squelchLevel = 1e-2;
}
Expand All @@ -73,19 +73,19 @@ void
AudioProcessor::connectAll()
{
connect(
this->m_tracker,
m_tracker,
SIGNAL(opened(Suscan::AnalyzerRequest const &)),
this,
SLOT(onOpened(Suscan::AnalyzerRequest const &)));

connect(
this->m_tracker,
m_tracker,
SIGNAL(cancelled(Suscan::AnalyzerRequest const &)),
this,
SLOT(onCancelled(Suscan::AnalyzerRequest const &)));

connect(
this->m_tracker,
m_tracker,
SIGNAL(error(Suscan::AnalyzerRequest const &, const std::string &)),
this,
SLOT(onError(Suscan::AnalyzerRequest const &, const std::string &)));
Expand Down Expand Up @@ -142,7 +142,7 @@ AudioProcessor::openAudio()
// Prepare channel
ch.bw = m_maxAudioBw;
ch.ft = 0;
ch.fc = this->calcTrueLoFreq();
ch.fc = calcTrueLoFreq();
ch.fLow = -.5 * m_maxAudioBw;
ch.fHigh = +.5 * m_maxAudioBw;

Expand Down Expand Up @@ -187,7 +187,7 @@ AudioProcessor::closeAudio()
}

// Just in case
this->stopRecording();
stopRecording();

m_opening = false;
m_opened = false;
Expand Down Expand Up @@ -217,7 +217,7 @@ SUFREQ
AudioProcessor::calcTrueLoFreq() const
{
SUFREQ delta = 0;
SUFREQ bw = this->calcTrueBandwidth();
SUFREQ bw = calcTrueBandwidth();

if (m_demod == AudioDemod::USB)
delta += .5 * bw;
Expand All @@ -233,7 +233,7 @@ AudioProcessor::setTrueLoFreq()
assert(m_analyzer != nullptr);
assert(m_audioInspectorOpened);

m_analyzer->setInspectorFreq(m_audioInspHandle, this->calcTrueLoFreq());
m_analyzer->setInspectorFreq(m_audioInspHandle, calcTrueLoFreq());
}

void
Expand All @@ -244,7 +244,7 @@ AudioProcessor::setTrueBandwidth()

m_analyzer->setInspectorBandwidth(
m_audioInspHandle,
this->calcTrueBandwidth());
calcTrueBandwidth());
}

void
Expand All @@ -261,6 +261,7 @@ AudioProcessor::setParams()
cfg.set("audio.demodulator", SCAST(uint64_t, m_demod + 1));
cfg.set("audio.squelch", m_squelch);
cfg.set("audio.squelch-level", m_squelchLevel);
cfg.set("agc.enabled", m_agc);

// Set audio inspector parameters
m_analyzer->setInspectorConfig(m_audioInspHandle, cfg);
Expand Down Expand Up @@ -335,18 +336,18 @@ void
AudioProcessor::setAnalyzer(Suscan::Analyzer *analyzer)
{
if (m_analyzer != nullptr) {
this->disconnectAnalyzer();
this->closeAudio();
disconnectAnalyzer();
closeAudio();
}

m_analyzer = analyzer;
m_tracker->setAnalyzer(analyzer);

// Was audio enabled? Open it back
if (m_analyzer != nullptr) {
this->connectAnalyzer();
connectAnalyzer();
if (m_enabled)
this->openAudio();
openAudio();
}
}

Expand All @@ -359,10 +360,10 @@ AudioProcessor::setEnabled(bool enabled)
if (m_analyzer != nullptr) {
if (enabled) {
if (!m_opened && !m_opening)
this->openAudio();
openAudio();
} else {
if (m_opened || m_opening)
this->closeAudio();
closeAudio();
}
}
}
Expand All @@ -375,7 +376,18 @@ AudioProcessor::setSquelchEnabled(bool enabled)
m_squelch = enabled;

if (m_audioInspectorOpened)
this->setParams();
setParams();
}
}

void
AudioProcessor::setAGCEnabled(bool enabled)
{
if (m_agc != enabled) {
m_agc = enabled;

if (m_audioInspectorOpened)
setParams();
}
}

Expand All @@ -386,7 +398,7 @@ AudioProcessor::setSquelchLevel(float level)
m_squelchLevel = level;

if (m_audioInspectorOpened)
this->setParams();
setParams();
}
}

Expand Down Expand Up @@ -432,14 +444,14 @@ AudioProcessor::setDemod(AudioDemod demod)
m_demod = demod;

if (m_audioInspectorOpened) {
this->setTrueLoFreq();
this->setTrueBandwidth();
this->setParams();
setTrueLoFreq();
setTrueBandwidth();
setParams();
}

if (m_audioFileSaver != nullptr) {
this->stopRecording();
this->startRecording(m_savedPath);
stopRecording();
startRecording(m_savedPath);
}
}
}
Expand All @@ -455,7 +467,7 @@ AudioProcessor::setSampleRate(unsigned rate)
// acknowledgment to call setSampleRate
if (m_audioInspectorOpened) {
m_settingRate = true;
this->setParams();
setParams();
m_analyzer->setInspectorWatermark(
m_audioInspHandle,
PlaybackWorker::calcBufferSizeForRate(m_sampleRate) / 2);
Expand All @@ -464,8 +476,8 @@ AudioProcessor::setSampleRate(unsigned rate)
}

if (m_audioFileSaver != nullptr) {
this->stopRecording();
this->startRecording(m_savedPath);
stopRecording();
startRecording(m_savedPath);
}
}
}
Expand All @@ -477,7 +489,7 @@ AudioProcessor::setCutOff(float cutOff)
m_cutOff = cutOff;

if (m_audioInspectorOpened)
this->setParams();
setParams();
}
}

Expand All @@ -496,7 +508,7 @@ AudioProcessor::setLoFreq(SUFREQ lo)
m_lo = lo;

if (m_audioInspectorOpened)
this->setTrueLoFreq();
setTrueLoFreq();
}
}

Expand All @@ -508,18 +520,18 @@ AudioProcessor::setBandwidth(SUFREQ bw)
bw = m_maxAudioBw;

if (!sufeq(m_bw, bw, 1e-8f)) {
SUFREQ trueLo = this->calcTrueLoFreq();
SUFREQ trueLo = calcTrueLoFreq();
SUFREQ newLo;

m_bw = bw;

newLo = this->calcTrueLoFreq();
newLo = calcTrueLoFreq();

if (m_audioInspectorOpened) {
this->setTrueBandwidth();
setTrueBandwidth();

if (!sufeq(trueLo, newLo, 1e-8f))
this->setTrueLoFreq();
setTrueLoFreq();
}
}
}
Expand Down Expand Up @@ -588,7 +600,7 @@ AudioProcessor::startRecording(QString path)
params.modulation = m_demod;

m_audioFileSaver = new AudioFileSaver(params, nullptr);
this->connectAudioFileSaver();
connectAudioFileSaver();

opened = true;
}
Expand Down Expand Up @@ -646,7 +658,7 @@ AudioProcessor::onInspectorMessage(Suscan::InspectorMessage const &msg)
case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_WRONG_OBJECT:
case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_WRONG_HANDLE:
if (!m_opened) {
this->closeAudio();
closeAudio();
emit audioError("Unexpected error while opening audio channel");
}

Expand Down Expand Up @@ -714,9 +726,9 @@ AudioProcessor::onOpened(Suscan::AnalyzerRequest const &req)
m_audioInspId = req.inspectorId;
m_audioInspectorOpened = true;

this->setTrueBandwidth();
this->setTrueLoFreq();
this->setParams();
setTrueBandwidth();
setTrueLoFreq();
setParams();

m_analyzer->setInspectorWatermark(
m_audioInspHandle,
Expand Down
2 changes: 2 additions & 0 deletions Default/Audio/AudioProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace SigDigger {
// Demodulator state
Suscan::Orbit m_orbit;
bool m_enabled = false;
bool m_agc = true;
float m_volume = 0;
float m_cutOff = 0;
SUFREQ m_lo = 0;
Expand Down Expand Up @@ -100,6 +101,7 @@ namespace SigDigger {
void setEnabled(bool);
void setVolume(float);
void setSquelchEnabled(bool);
void setAGCEnabled(bool);
void setSquelchLevel(float);
void setAudioCorrection(Suscan::Orbit const &);
void setCorrectionEnabled(bool);
Expand Down
30 changes: 30 additions & 0 deletions Default/Audio/AudioWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ AudioWidgetConfig::deserialize(Suscan::Object const &conf)
LOAD(enabled);
LOAD(collapsed);
LOAD(lockToFreq);
LOAD(agc);
LOAD(demod);
LOAD(rate);
LOAD(cutOff);
Expand All @@ -94,6 +95,7 @@ AudioWidgetConfig::serialize()
STORE(enabled);
STORE(collapsed);
STORE(lockToFreq);
STORE(agc);
STORE(demod);
STORE(rate);
STORE(cutOff);
Expand Down Expand Up @@ -235,6 +237,12 @@ AudioWidget::connectAll()
this,
SLOT(onOpenDopplerSettings()));

connect(
m_ui->agcButton,
SIGNAL(clicked(bool)),
this,
SLOT(onAGCChanged()));

connect(
m_fcDialog,
SIGNAL(accepted()),
Expand Down Expand Up @@ -480,6 +488,12 @@ AudioWidget::isMuted() const
return m_ui->muteButton->isChecked();
}

bool
AudioWidget::isAGCEnabled() const
{
return m_ui->agcButton->isChecked();
}

bool
AudioWidget::isCorrectionEnabled() const
{
Expand Down Expand Up @@ -578,6 +592,15 @@ AudioWidget::setVolume(SUFLOAT volume)
m_processor->setVolume(getMuteableVolume());
}

void
AudioWidget::setAGCEnabled(bool enabled)
{
m_panelConfig->agc = enabled;
BLOCKSIG(m_ui->agcButton, setChecked(enabled));

m_processor->setAGCEnabled(enabled);
}

void
AudioWidget::setMuted(bool muted)
{
Expand Down Expand Up @@ -765,6 +788,7 @@ AudioWidget::applyConfig()
setSampleRate(m_panelConfig->rate);
setCutOff(m_panelConfig->cutOff);
setVolume(m_panelConfig->volume);
setAGCEnabled(m_panelConfig->agc);
setDemod(SigDiggerHelpers::strToDemod(m_panelConfig->demod));
setEnabled(m_panelConfig->enabled);
setLockToFreq(m_panelConfig->lockToFreq);
Expand Down Expand Up @@ -945,6 +969,12 @@ AudioWidget::onVolumeChanged()
setVolume(getVolume());
}

void
AudioWidget::onAGCChanged()
{
setAGCEnabled(isAGCEnabled());
}

void
AudioWidget::onMuteToggled(bool)
{
Expand Down
4 changes: 4 additions & 0 deletions Default/Audio/AudioWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace SigDigger {
bool enabled = false;
bool collapsed = false;
bool lockToFreq = false;
bool agc = true;

std::string demod;
std::string savePath;
Expand Down Expand Up @@ -104,6 +105,7 @@ namespace SigDigger {
void setCutOff(SUFLOAT);
void setVolume(SUFLOAT);
void setMuted(bool);
void setAGCEnabled(bool);
void setSquelchEnabled(bool);
void setSquelchLevel(SUFLOAT);

Expand All @@ -123,6 +125,7 @@ namespace SigDigger {
enum AudioDemod getDemod() const;
bool getLockToFreq() const;
unsigned int getSampleRate() const;
bool isAGCEnabled() const;
SUFLOAT getCutOff() const;
SUFLOAT getVolume() const;
bool isMuted() const;
Expand Down Expand Up @@ -169,6 +172,7 @@ namespace SigDigger {
void onSquelchLevelChanged();
void onOpenDopplerSettings();
void onLockToFreqChanged();
void onAGCChanged();

// Notifications
void onSetTLE(Suscan::InspectorMessage const &);
Expand Down
Loading

0 comments on commit 330593f

Please sign in to comment.