From 1bb612bf624a8849979133235a0b8b65d3c39e40 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 26 Sep 2017 23:53:35 +0200 Subject: [PATCH] AM demod: use settings object to apply settings --- plugins/channelrx/demodam/amdemod.cpp | 7 --- plugins/channelrx/demodam/amdemod.h | 30 ---------- plugins/channelrx/demodam/amdemodgui.cpp | 76 ++++++++++++++++++++---- plugins/channelrx/demodam/amdemodgui.h | 3 + 4 files changed, 66 insertions(+), 50 deletions(-) diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp index 9ef6b2d57..5cbfbb8d7 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -43,13 +43,6 @@ AMDemod::AMDemod() : { setObjectName("AMDemod"); -// m_config.m_inputSampleRate = 96000; -// m_config.m_inputFrequencyOffset = 0; -// m_config.m_rfBandwidth = 5000; -// m_config.m_squelch = -40.0; -// m_config.m_volume = 2.0; -// m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); - m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; diff --git a/plugins/channelrx/demodam/amdemod.h b/plugins/channelrx/demodam/amdemod.h index 3e459807d..10ea0e9e7 100644 --- a/plugins/channelrx/demodam/amdemod.h +++ b/plugins/channelrx/demodam/amdemod.h @@ -138,37 +138,7 @@ private: RSRunning }; -// struct Config { -// int m_inputSampleRate; -// qint64 m_inputFrequencyOffset; -// Real m_rfBandwidth; -// Real m_squelch; -// Real m_volume; -// quint32 m_audioSampleRate; -// bool m_audioMute; -// bool m_bandpassEnable; -// bool m_copyAudioToUDP; -// QString m_udpAddress; -// quint16 m_udpPort; -// -// Config() : -// m_inputSampleRate(-1), -// m_inputFrequencyOffset(0), -// m_rfBandwidth(-1), -// m_squelch(0), -// m_volume(0), -// m_audioSampleRate(0), -// m_audioMute(false), -// m_bandpassEnable(false), -// m_copyAudioToUDP(false), -// m_udpAddress("127.0.0.1"), -// m_udpPort(9999) -// { } -// }; - AMDemodSettings m_settings; -// Config m_config; -// Config m_running; NCO m_nco; Interpolator m_interpolator; diff --git a/plugins/channelrx/demodam/amdemodgui.cpp b/plugins/channelrx/demodam/amdemodgui.cpp index f8a238cf4..3f5fe156e 100644 --- a/plugins/channelrx/demodam/amdemodgui.cpp +++ b/plugins/channelrx/demodam/amdemodgui.cpp @@ -155,6 +155,9 @@ bool AMDemodGUI::handleMessage(const Message& message __attribute__((unused))) void AMDemodGUI::channelMarkerChanged() { this->setWindowTitle(m_channelMarker.getTitle()); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + m_settings.m_udpAddress = m_channelMarker.getUDPAddress(), + m_settings.m_udpPort = m_channelMarker.getUDPSendPort(), displayUDPAddress(); applySettings(); } @@ -162,10 +165,13 @@ void AMDemodGUI::channelMarkerChanged() void AMDemodGUI::on_deltaFrequency_changed(qint64 value) { m_channelMarker.setCenterFrequency(value); + m_settings.m_inputFrequencyOffset = m_channelMarker.getCenterFrequency(); + applySettings(); } -void AMDemodGUI::on_bandpassEnable_toggled(bool checked __attribute__((unused))) +void AMDemodGUI::on_bandpassEnable_toggled(bool checked) { + m_settings.m_bandpassEnable = checked; applySettings(); } @@ -173,28 +179,33 @@ void AMDemodGUI::on_rfBW_valueChanged(int value) { ui->rfBWText->setText(QString("%1 kHz").arg(value / 10.0, 0, 'f', 1)); m_channelMarker.setBandwidth(value * 100); + m_settings.m_rfBandwidth = value * 100; applySettings(); } void AMDemodGUI::on_volume_valueChanged(int value) { ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); + m_settings.m_volume = value / 10.0; applySettings(); } void AMDemodGUI::on_squelch_valueChanged(int value) { ui->squelchText->setText(QString("%1 dB").arg(value)); + m_settings.m_squelch = value; applySettings(); } -void AMDemodGUI::on_audioMute_toggled(bool checked __attribute__((unused))) +void AMDemodGUI::on_audioMute_toggled(bool checked) { + m_settings.m_audioMute = checked; applySettings(); } -void AMDemodGUI::on_copyAudioToUDP_toggled(bool checked __attribute__((unused))) +void AMDemodGUI::on_copyAudioToUDP_toggled(bool checked) { + m_settings.m_copyAudioToUDP = checked; applySettings(); } @@ -257,6 +268,7 @@ AMDemodGUI::AMDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget m_deviceAPI->addChannelMarker(&m_channelMarker); m_deviceAPI->addRollupWidget(this); + displaySettings(); applySettings(true); } @@ -288,19 +300,57 @@ void AMDemodGUI::applySettings(bool force) ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); - m_amDemod->configure(m_amDemod->getInputMessageQueue(), - ui->rfBW->value() * 100.0, - ui->volume->value() / 10.0, - ui->squelch->value(), - ui->audioMute->isChecked(), - ui->bandpassEnable->isChecked(), - ui->copyAudioToUDP->isChecked(), - m_channelMarker.getUDPAddress(), - m_channelMarker.getUDPSendPort(), - force); +// m_amDemod->configure(m_amDemod->getInputMessageQueue(), +// ui->rfBW->value() * 100.0, +// ui->volume->value() / 10.0, +// ui->squelch->value(), +// ui->audioMute->isChecked(), +// ui->bandpassEnable->isChecked(), +// ui->copyAudioToUDP->isChecked(), +// m_channelMarker.getUDPAddress(), +// m_channelMarker.getUDPSendPort(), +// force); + + m_amDemod->configure(m_amDemod->getInputMessageQueue(), + m_settings.m_rfBandwidth, + m_settings.m_volume, + m_settings.m_squelch, + m_settings.m_audioMute, + m_settings.m_bandpassEnable, + m_settings.m_copyAudioToUDP, + m_settings.m_udpAddress, + m_settings.m_udpPort, + force); + } } +void AMDemodGUI::displaySettings() +{ + blockApplySettings(true); + + int displayValue = m_settings.m_rfBandwidth/100.0; + ui->rfBW->setValue(displayValue); + ui->rfBWText->setText(QString("%1 kHz").arg(displayValue / 10.0, 0, 'f', 1)); + m_channelMarker.setBandwidth(m_settings.m_rfBandwidth); + + ui->volume->setValue(m_settings.m_volume * 10.0); + ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 0, 'f', 1)); + + ui->squelch->setValue(m_settings.m_squelch); + ui->squelchText->setText(QString("%1 dB").arg(m_settings.m_squelch)); + + ui->audioMute->setChecked(m_settings.m_audioMute); + ui->bandpassEnable->setChecked(m_settings.m_bandpassEnable); + ui->copyAudioToUDP->setChecked(m_settings.m_copyAudioToUDP); + + m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); + m_channelMarker.setUDPAddress(m_settings.m_udpAddress); + m_channelMarker.setUDPSendPort(m_settings.m_udpPort); + + blockApplySettings(false); +} + void AMDemodGUI::displayUDPAddress() { ui->copyAudioToUDP->setToolTip(QString("Copy audio output to UDP %1:%2").arg(m_channelMarker.getUDPAddress()).arg(m_channelMarker.getUDPSendPort())); diff --git a/plugins/channelrx/demodam/amdemodgui.h b/plugins/channelrx/demodam/amdemodgui.h index de9c20d6e..909e39cef 100644 --- a/plugins/channelrx/demodam/amdemodgui.h +++ b/plugins/channelrx/demodam/amdemodgui.h @@ -6,6 +6,7 @@ #include "dsp/channelmarker.h" #include "dsp/movingaverage.h" #include "util/messagequeue.h" +#include "amdemodsettings.h" class PluginAPI; class DeviceSourceAPI; @@ -56,6 +57,7 @@ private: PluginAPI* m_pluginAPI; DeviceSourceAPI* m_deviceAPI; ChannelMarker m_channelMarker; + AMDemodSettings m_settings; bool m_doApplySettings; ThreadedBasebandSampleSink* m_threadedChannelizer; @@ -70,6 +72,7 @@ private: void blockApplySettings(bool block); void applySettings(bool force = false); + void displaySettings(); void displayUDPAddress(); void leaveEvent(QEvent*);