From 24b1002360fef7be5c99877b978939158c2acd5c Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 16 Oct 2017 22:22:29 +0200 Subject: [PATCH] UDP Sink: use settings in sink (2) --- plugins/channeltx/udpsink/udpsink.cpp | 81 +++++++++++++++++++++++++++ plugins/channeltx/udpsink/udpsink.h | 49 ++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/plugins/channeltx/udpsink/udpsink.cpp b/plugins/channeltx/udpsink/udpsink.cpp index eef2245c5..ae758bf14 100644 --- a/plugins/channeltx/udpsink/udpsink.cpp +++ b/plugins/channeltx/udpsink/udpsink.cpp @@ -21,6 +21,8 @@ #include "udpsinkmsg.h" #include "udpsink.h" +MESSAGE_CLASS_DEFINITION(UDPSink::MsgConfigureUDPSink, Message) +MESSAGE_CLASS_DEFINITION(UDPSink::MsgConfigureChannelizer, Message) MESSAGE_CLASS_DEFINITION(UDPSink::MsgUDPSinkConfigure, Message) MESSAGE_CLASS_DEFINITION(UDPSink::MsgUDPSinkSpectrum, Message) MESSAGE_CLASS_DEFINITION(UDPSink::MsgResetReadIndex, Message) @@ -559,3 +561,82 @@ void UDPSink::apply(bool force) m_running = m_config; } + +void UDPSink::applySettings(const UDPSinkSettings& settings, bool force) +{ + if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || + (settings.m_outputSampleRate != m_settings.m_outputSampleRate) || force) + { + m_settingsMutex.lock(); + m_carrierNco.setFreq(settings.m_inputFrequencyOffset, settings.m_outputSampleRate); + m_settingsMutex.unlock(); + } + + if((settings.m_outputSampleRate != m_settings.m_outputSampleRate) || + (settings.m_rfBandwidth != m_settings.m_rfBandwidth) || + (settings.m_inputSampleRate != m_settings.m_inputSampleRate) || force) + { + m_settingsMutex.lock(); + m_interpolatorDistanceRemain = 0; + m_interpolatorConsumed = false; + m_interpolatorDistance = (Real) settings.m_inputSampleRate / (Real) settings.m_outputSampleRate; + m_interpolator.create(48, settings.m_inputSampleRate, settings.m_rfBandwidth / 2.2, 3.0); + m_actualInputSampleRate = settings.m_inputSampleRate; + m_udpHandler.resetReadIndex(); + m_sampleRateSum = 0.0; + m_sampleRateAvgCounter = 0; + m_spectrumChunkSize = settings.m_inputSampleRate * 0.05; // 50 ms chunk + m_spectrumChunkCounter = 0; + m_levelNbSamples = settings.m_inputSampleRate * 0.01; // every 10 ms + m_levelCalcCount = 0; + m_peakLevel = 0.0f; + m_levelSum = 0.0f; + m_udpHandler.resizeBuffer(settings.m_inputSampleRate); + m_inMovingAverage.resize(settings.m_inputSampleRate * 0.01, 1e-10); // 10 ms + m_squelchThreshold = settings.m_inputSampleRate * settings.m_squelchGate; + initSquelch(m_squelchOpen); + m_SSBFilter->create_filter(settings.m_lowCutoff / settings.m_inputSampleRate, settings.m_rfBandwidth / settings.m_inputSampleRate); + m_settingsMutex.unlock(); + } + + if ((settings.m_squelchGate != m_settings.m_squelchGate) || force) + { + m_squelchThreshold = settings.m_outputSampleRate * settings.m_squelchGate; + initSquelch(m_squelchOpen); + } + + if ((settings.m_udpAddress != m_settings.m_udpAddress) || + (settings.m_udpPort != m_settings.m_udpPort) || force) + { + m_settingsMutex.lock(); + m_udpHandler.configureUDPLink(settings.m_udpAddress, settings.m_udpPort); + m_settingsMutex.unlock(); + } + + if ((settings.m_channelMute != m_settings.m_channelMute) || force) + { + if (!settings.m_channelMute) { + m_udpHandler.resetReadIndex(); + } + } + + if ((settings.m_autoRWBalance != m_settings.m_autoRWBalance) || force) + { + m_settingsMutex.lock(); + m_udpHandler.setAutoRWBalance(settings.m_autoRWBalance); + + if (!settings.m_autoRWBalance) + { + m_interpolatorDistanceRemain = 0; + m_interpolatorConsumed = false; + m_interpolatorDistance = (Real) settings.m_inputSampleRate / (Real) settings.m_outputSampleRate; + m_interpolator.create(48, settings.m_inputSampleRate, settings.m_rfBandwidth / 2.2, 3.0); + m_actualInputSampleRate = settings.m_inputSampleRate; + m_udpHandler.resetReadIndex(); + } + + m_settingsMutex.unlock(); + } + + m_settings = settings; +} diff --git a/plugins/channeltx/udpsink/udpsink.h b/plugins/channeltx/udpsink/udpsink.h index 44cbe4aea..f691f069b 100644 --- a/plugins/channeltx/udpsink/udpsink.h +++ b/plugins/channeltx/udpsink/udpsink.h @@ -36,6 +36,53 @@ class UDPSink : public BasebandSampleSource { Q_OBJECT public: + class MsgConfigureUDPSink : public Message { + MESSAGE_CLASS_DECLARATION + + public: + const UDPSinkSettings& getSettings() const { return m_settings; } + bool getForce() const { return m_force; } + + static MsgConfigureUDPSink* create(const UDPSinkSettings& settings, bool force) + { + return new MsgConfigureUDPSink(settings, force); + } + + private: + UDPSinkSettings m_settings; + bool m_force; + + MsgConfigureUDPSink(const UDPSinkSettings& settings, bool force) : + Message(), + m_settings(settings), + m_force(force) + { + } + }; + + class MsgConfigureChannelizer : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getSampleRate() const { return m_sampleRate; } + int getCenterFrequency() const { return m_centerFrequency; } + + static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency) + { + return new MsgConfigureChannelizer(sampleRate, centerFrequency); + } + + private: + int m_sampleRate; + int m_centerFrequency; + + MsgConfigureChannelizer(int sampleRate, int centerFrequency) : + Message(), + m_sampleRate(sampleRate), + m_centerFrequency(centerFrequency) + { } + }; + UDPSink(MessageQueue* uiMessageQueue, UDPSinkGUI* udpSinkGUI, BasebandSampleSink* spectrum); virtual ~UDPSink(); @@ -276,6 +323,7 @@ private: Config m_config; Config m_running; + UDPSinkSettings m_settings; NCO m_carrierNco; Complex m_modSample; @@ -324,6 +372,7 @@ private: static const int m_ssbFftLen = 1024; void apply(bool force); + void applySettings(const UDPSinkSettings& settings, bool force = false); void modulateSample(); void calculateLevel(Real sample); void calculateLevel(Complex sample);