diff --git a/plugins/channelrx/localsink/localsink.cpp b/plugins/channelrx/localsink/localsink.cpp index ef2f54eeb..f5978e751 100644 --- a/plugins/channelrx/localsink/localsink.cpp +++ b/plugins/channelrx/localsink/localsink.cpp @@ -320,6 +320,8 @@ void LocalSink::applySettings(const LocalSinkSettings& settings, bool force) << "m_localDeviceIndex: " << settings.m_localDeviceIndex << "m_streamIndex: " << settings.m_streamIndex << "m_play:" << settings.m_play + << "m_dsp:" << settings.m_dsp + << "m_gaindB:" << settings.m_gaindB << "force: " << force; QList reverseAPIKeys; diff --git a/plugins/channelrx/localsink/localsinkbaseband.cpp b/plugins/channelrx/localsink/localsinkbaseband.cpp index a82d8db7e..fa60d46b8 100644 --- a/plugins/channelrx/localsink/localsinkbaseband.cpp +++ b/plugins/channelrx/localsink/localsinkbaseband.cpp @@ -173,7 +173,7 @@ void LocalSinkBaseband::applySettings(const LocalSinkSettings& settings, bool fo m_sink.setSampleRate(getChannelSampleRate()); } - //m_source.applySettings(settings, force); + m_sink.applySettings(settings, force); m_settings = settings; } diff --git a/plugins/channelrx/localsink/localsinkgui.cpp b/plugins/channelrx/localsink/localsinkgui.cpp index 38369f1fc..a8cf78ae4 100644 --- a/plugins/channelrx/localsink/localsinkgui.cpp +++ b/plugins/channelrx/localsink/localsinkgui.cpp @@ -193,6 +193,8 @@ void LocalSinkGUI::displaySettings() ui->localDevicePlay->setChecked(m_settings.m_play); ui->decimationFactor->setCurrentIndex(m_settings.m_log2Decim); + ui->dsp->setChecked(m_settings.m_dsp); + ui->gainText->setText(tr("%1").arg(m_settings.m_gaindB)); applyDecimation(); updateIndexLabel(); @@ -348,6 +350,19 @@ void LocalSinkGUI::on_localDevicePlay_toggled(bool checked) applySettings(); } +void LocalSinkGUI::on_dsp_toggled(bool checked) +{ + m_settings.m_dsp = checked; + applySettings(); +} + +void LocalSinkGUI::on_gain_valueChanged(int value) +{ + m_settings.m_gaindB = value; + ui->gainText->setText(tr("%1").arg(value)); + applySettings(); +} + void LocalSinkGUI::applyDecimation() { uint32_t maxHash = 1; @@ -387,6 +402,8 @@ void LocalSinkGUI::makeUIConnections() QObject::connect(ui->position, &QSlider::valueChanged, this, &LocalSinkGUI::on_position_valueChanged); QObject::connect(ui->localDevice, QOverload::of(&QComboBox::currentIndexChanged), this, &LocalSinkGUI::on_localDevice_currentIndexChanged); QObject::connect(ui->localDevicePlay, &ButtonSwitch::toggled, this, &LocalSinkGUI::on_localDevicePlay_toggled); + QObject::connect(ui->dsp, &ButtonSwitch::toggled, this, &LocalSinkGUI::on_dsp_toggled); + QObject::connect(ui->gain, &QSlider::valueChanged, this, &LocalSinkGUI::on_gain_valueChanged); } void LocalSinkGUI::updateAbsoluteCenterFrequency() diff --git a/plugins/channelrx/localsink/localsinkgui.h b/plugins/channelrx/localsink/localsinkgui.h index 32df9a8d6..4fb56f625 100644 --- a/plugins/channelrx/localsink/localsinkgui.h +++ b/plugins/channelrx/localsink/localsinkgui.h @@ -104,6 +104,8 @@ private slots: void on_position_valueChanged(int value); void on_localDevice_currentIndexChanged(int index); void on_localDevicePlay_toggled(bool checked); + void on_dsp_toggled(bool checked); + void on_gain_valueChanged(int value); void onWidgetRolled(QWidget* widget, bool rollDown); void onMenuDialogCalled(const QPoint& p); void tick(); diff --git a/plugins/channelrx/localsink/localsinkgui.ui b/plugins/channelrx/localsink/localsinkgui.ui index 64e3e118c..41b218f24 100644 --- a/plugins/channelrx/localsink/localsinkgui.ui +++ b/plugins/channelrx/localsink/localsinkgui.ui @@ -6,8 +6,8 @@ 0 0 - 414 - 406 + 452 + 467 @@ -34,10 +34,10 @@ - 10 - 10 - 401 - 91 + 1 + 1 + 451 + 141 @@ -66,7 +66,7 @@ 2 - + 3 @@ -290,6 +290,215 @@ + + + + DSP + + + + + + + G + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Gain in dB + + + -10 + + + 100 + + + 1 + + + + + + + + 26 + 0 + + + + Gain in dB + + + 100 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + FFT + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + FFT size + + + QComboBox::AdjustToContents + + + + 64 + + + + + 128 + + + + + 256 + + + + + 512 + + + + + 1k + + + + + 2k + + + + + 4k + + + + + 8k + + + + + + + + + 0 + 0 + + + + + 70 + 0 + + + + + 60 + 16777215 + + + + FFT filter window function + + + QComboBox::AdjustToContents + + + + Bart + + + + + B-H + + + + + FT + + + + + Ham + + + + + Han + + + + + Rec + + + + + Kai + + + + + Black + + + + + B-H7 + + + + @@ -305,13 +514,203 @@ + + + + + + Band + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + FFT band index + + + 0 + + + 9 + + + 1 + + + + + + + Qt::Vertical + + + + + + + + 20 + 0 + + + + FFT band index + + + 00 + + + + + + + f1 + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Frequency limit #1 bin + + + 0 + + + 1023 + + + 1 + + + + + + + + 50 + 0 + + + + Frequency limit #1 frequency + + + 100.00k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Vertical + + + + + + + f2 + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + Frequency limit #2 bin + + + 0 + + + 1023 + + + 1 + + + + + + + + 50 + 0 + + + + Frequency limit #2 frequency + + + 100.00k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + 10 - 110 + 160 218 284 diff --git a/plugins/channelrx/localsink/localsinksettings.cpp b/plugins/channelrx/localsink/localsinksettings.cpp index 7f84cf6b7..8a7b3478e 100644 --- a/plugins/channelrx/localsink/localsinksettings.cpp +++ b/plugins/channelrx/localsink/localsinksettings.cpp @@ -38,6 +38,8 @@ void LocalSinkSettings::resetToDefaults() m_channelMarker = nullptr; m_rollupState = nullptr; m_play = false; + m_dsp = false; + m_gaindB = 0; m_streamIndex = 0; m_useReverseAPI = false; m_reverseAPIAddress = "127.0.0.1"; @@ -75,6 +77,12 @@ QByteArray LocalSinkSettings::serialize() const s.writeS32(16, m_workspaceIndex); s.writeBlob(17, m_geometryBytes); s.writeBool(18, m_hidden); + s.writeBool(19, m_dsp); + s.writeS32(20, m_gaindB); + + if (m_spectrumGUI) { + s.writeBlob(21, m_spectrumGUI->serialize()); + } return s.final(); } @@ -133,6 +141,14 @@ bool LocalSinkSettings::deserialize(const QByteArray& data) d.readS32(16, &m_workspaceIndex, 0); d.readBlob(17, &m_geometryBytes); d.readBool(18, &m_hidden, false); + d.readBool(19, &m_dsp, false); + d.readS32(20, &m_gaindB, 0); + + if (m_spectrumGUI) + { + d.readBlob(21, &bytetmp); + m_spectrumGUI->deserialize(bytetmp); + } return true; } diff --git a/plugins/channelrx/localsink/localsinksettings.h b/plugins/channelrx/localsink/localsinksettings.h index f5290ddf6..6502e1115 100644 --- a/plugins/channelrx/localsink/localsinksettings.h +++ b/plugins/channelrx/localsink/localsinksettings.h @@ -31,6 +31,8 @@ struct LocalSinkSettings uint32_t m_log2Decim; uint32_t m_filterChainHash; bool m_play; + bool m_dsp; + int m_gaindB; int m_streamIndex; //!< MIMO channel. Not relevant when connected to SI (single Rx). bool m_useReverseAPI; QString m_reverseAPIAddress; diff --git a/plugins/channelrx/localsink/localsinksink.cpp b/plugins/channelrx/localsink/localsinksink.cpp index 77d871806..7e1125775 100644 --- a/plugins/channelrx/localsink/localsinksink.cpp +++ b/plugins/channelrx/localsink/localsinksink.cpp @@ -22,6 +22,7 @@ #include "dsp/devicesamplesource.h" #include "dsp/hbfilterchainconverter.h" #include "dsp/spectrumvis.h" +#include "util/db.h" #include "localsinkworker.h" #include "localsinksink.h" @@ -31,6 +32,7 @@ LocalSinkSink::LocalSinkSink() : m_sinkWorker(nullptr), m_spectrumSink(nullptr), m_running(false), + m_gain(1.0), m_centerFrequency(0), m_frequencyOffset(0), m_sampleRate(48000), @@ -46,8 +48,32 @@ LocalSinkSink::~LocalSinkSink() void LocalSinkSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end) { - if (m_running && m_deviceSource) { - m_deviceSource->getSampleFifo()->write(begin, end); + if (m_settings.m_dsp && (m_settings.m_gaindB != 0)) + { + m_spectrumBuffer.resize(end - begin); + std::transform( + begin, + end, + m_spectrumBuffer.begin(), + [this](const Sample& s) -> Sample { + Complex c(s.real(), s.imag()); + c *= m_gain; + return Sample(c.real(), c.imag()); + } + ); + if (m_running && m_deviceSource) { + m_deviceSource->getSampleFifo()->write(m_spectrumBuffer.begin(), m_spectrumBuffer.end()); + } + if (m_spectrumSink) { + m_spectrumSink->feed(m_spectrumBuffer.begin(), m_spectrumBuffer.end(), false); + } + m_spectrumBuffer.clear(); + } + else + { + if (m_running && m_deviceSource) { + m_deviceSource->getSampleFifo()->write(begin, end); + } } if (m_spectrumSink) { @@ -129,6 +155,10 @@ void LocalSinkSink::applySettings(const LocalSinkSettings& settings, bool force) << " m_streamIndex: " << settings.m_streamIndex << " force: " << force; + if ((settings.m_gaindB != m_settings.m_gaindB) || force) { + m_gain = CalcDb::powerFromdB(settings.m_gaindB/2.0); // Amplitude gain + } + m_settings = settings; } diff --git a/plugins/channelrx/localsink/localsinksink.h b/plugins/channelrx/localsink/localsinksink.h index 480a227f2..0aa61234c 100644 --- a/plugins/channelrx/localsink/localsinksink.h +++ b/plugins/channelrx/localsink/localsinksink.h @@ -53,6 +53,7 @@ private: SpectrumVis* m_spectrumSink; SampleVector m_spectrumBuffer; bool m_running; + float m_gain; //!< Amplitude gain uint64_t m_centerFrequency; int64_t m_frequencyOffset;