From af5103552c935ba892924cab84ed0e577009b9a5 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 17 Aug 2017 00:16:17 +0200 Subject: [PATCH] UDPSink plugin: implemented volume control --- plugins/channeltx/udpsink/udpsink.cpp | 10 +++-- plugins/channeltx/udpsink/udpsink.h | 9 +++++ plugins/channeltx/udpsink/udpsinkgui.cpp | 10 ++--- plugins/channeltx/udpsink/udpsinkgui.h | 1 - plugins/channeltx/udpsink/udpsinkgui.ui | 48 ++++++++++++++++++++++-- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/plugins/channeltx/udpsink/udpsink.cpp b/plugins/channeltx/udpsink/udpsink.cpp index d16125e9a..d45c787c5 100644 --- a/plugins/channeltx/udpsink/udpsink.cpp +++ b/plugins/channeltx/udpsink/udpsink.cpp @@ -112,8 +112,8 @@ void UDPSink::modulateSample() if (m_running.m_sampleFormat == FormatS16LE) { m_udpHandler.readSample(s); - m_modSample.real(s.m_real); - m_modSample.imag(s.m_imag); + m_modSample.real(s.m_real * m_running.m_volume); + m_modSample.imag(s.m_imag * m_running.m_volume); calculateLevel(m_modSample); } else @@ -208,6 +208,7 @@ bool UDPSink::handleMessage(const Message& cmd) m_config.m_udpAddressStr = cfg.getUDPAddress(); m_config.m_udpPort = cfg.getUDPPort(); m_config.m_channelMute = cfg.getChannelMute(); + m_config.m_volume = cfg.getVolume(); apply(cfg.getForce()); @@ -218,7 +219,8 @@ bool UDPSink::handleMessage(const Message& cmd) << " m_fmDeviation: " << m_config.m_fmDeviation << " m_udpAddressStr: " << m_config.m_udpAddressStr << " m_udpPort: " << m_config.m_udpPort - << " m_channelMute: " << m_config.m_channelMute; + << " m_channelMute: " << m_config.m_channelMute + << " m_volume: " << m_config.m_volume; return true; } @@ -303,6 +305,7 @@ void UDPSink::configure(MessageQueue* messageQueue, QString& udpAddress, int udpPort, bool channelMute, + Real volume, bool force) { Message* cmd = MsgUDPSinkConfigure::create(sampleFormat, @@ -312,6 +315,7 @@ void UDPSink::configure(MessageQueue* messageQueue, udpAddress, udpPort, channelMute, + volume, force); messageQueue->push(cmd); } diff --git a/plugins/channeltx/udpsink/udpsink.h b/plugins/channeltx/udpsink/udpsink.h index 102a0e00b..ff057add1 100644 --- a/plugins/channeltx/udpsink/udpsink.h +++ b/plugins/channeltx/udpsink/udpsink.h @@ -65,6 +65,7 @@ public: QString& udpAddress, int udpPort, bool channelMute, + Real volume, bool force = false); void setSpectrum(MessageQueue* messageQueue, bool enabled); @@ -89,6 +90,7 @@ private: const QString& getUDPAddress() const { return m_udpAddress; } int getUDPPort() const { return m_udpPort; } bool getChannelMute() const { return m_channelMute; } + Real getVolume() const { return m_volume; } bool getForce() const { return m_force; } static MsgUDPSinkConfigure* create(SampleFormat @@ -99,6 +101,7 @@ private: QString& udpAddress, int udpPort, bool channelMute, + Real volume, bool force) { return new MsgUDPSinkConfigure(sampleFormat, @@ -108,6 +111,7 @@ private: udpAddress, udpPort, channelMute, + volume, force); } @@ -119,6 +123,7 @@ private: QString m_udpAddress; int m_udpPort; bool m_channelMute; + Real m_volume; bool m_force; MsgUDPSinkConfigure(SampleFormat sampleFormat, @@ -128,6 +133,7 @@ private: QString& udpAddress, int udpPort, bool channelMute, + Real volume, bool force) : Message(), m_sampleFormat(sampleFormat), @@ -137,6 +143,7 @@ private: m_udpAddress(udpAddress), m_udpPort(udpPort), m_channelMute(channelMute), + m_volume(volume), m_force(force) { } }; @@ -170,6 +177,7 @@ private: Real m_rfBandwidth; int m_fmDeviation; bool m_channelMute; + Real m_volume; QString m_udpAddressStr; quint16 m_udpPort; @@ -183,6 +191,7 @@ private: m_rfBandwidth(12500), m_fmDeviation(1.0), m_channelMute(false), + m_volume(1.0), m_udpAddressStr("127.0.0.1"), m_udpPort(9999) {} diff --git a/plugins/channeltx/udpsink/udpsinkgui.cpp b/plugins/channeltx/udpsink/udpsinkgui.cpp index baa660018..24c080798 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.cpp +++ b/plugins/channeltx/udpsink/udpsinkgui.cpp @@ -71,7 +71,7 @@ void UDPSinkGUI::resetToDefaults() ui->udpAddress->setText("127.0.0.1"); ui->udpPort->setText("9999"); ui->spectrumGUI->resetToDefaults(); - ui->volume->setValue(20); + ui->volume->setValue(10); blockApplySettings(false); applySettings(); @@ -89,7 +89,7 @@ QByteArray UDPSinkGUI::serialize() const s.writeBlob(7, ui->spectrumGUI->serialize()); s.writeS32(8, m_channelMarker.getCenterFrequency()); s.writeString(9, m_udpAddress); - s.writeS32(10, (qint32)m_volume); + s.writeS32(10, ui->volume->value()); s.writeS32(11, m_fmDeviation); s.writeU32(12, m_channelMarker.getColor().rgb()); s.writeString(13, m_channelMarker.getTitle()); @@ -164,7 +164,7 @@ bool UDPSinkGUI::deserialize(const QByteArray& data) m_channelMarker.setCenterFrequency(s32tmp); d.readString(9, &strtmp, "127.0.0.1"); ui->udpAddress->setText(strtmp); - d.readS32(10, &s32tmp, 20); + d.readS32(10, &s32tmp, 10); ui->volume->setValue(s32tmp); d.readS32(11, &s32tmp, 2500); ui->fmDeviation->setText(QString("%1").arg(s32tmp)); @@ -387,6 +387,7 @@ void UDPSinkGUI::applySettings(bool force) m_udpAddress, udpPort, ui->channelMute->isChecked(), + ui->volume->value() / 10.0f, force); ui->applyBtn->setEnabled(false); @@ -442,8 +443,7 @@ void UDPSinkGUI::on_udpPort_textEdited(const QString& arg1 __attribute__((unused void UDPSinkGUI::on_volume_valueChanged(int value) { - ui->volume->setValue(value); - ui->volumeText->setText(QString("%1").arg(value)); + ui->volumeText->setText(tr("%1").arg(value/10.0, 0, 'f', 1)); applySettings(); } diff --git a/plugins/channeltx/udpsink/udpsinkgui.h b/plugins/channeltx/udpsink/udpsinkgui.h index 378efff55..767b60bc4 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.h +++ b/plugins/channeltx/udpsink/udpsinkgui.h @@ -87,7 +87,6 @@ private: Real m_inputSampleRate; Real m_rfBandwidth; int m_fmDeviation; - int m_volume; QString m_udpAddress; int m_udpPort; bool m_basicSettingsShown; diff --git a/plugins/channeltx/udpsink/udpsinkgui.ui b/plugins/channeltx/udpsink/udpsinkgui.ui index 368b8ac12..6bb298ce2 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.ui +++ b/plugins/channeltx/udpsink/udpsinkgui.ui @@ -321,6 +321,36 @@ + + + + Sq + + + + + + + + 22 + 22 + + + + Power squelch threshold (dB) + + + + + + + Power squelch threshold (dB) + + + -00 + + + @@ -336,16 +366,28 @@ - 24 - 24 + 22 + 22 + + 50 + + + 1 + + + 10 + - 20 + 0.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter