From 8e924a3dbaf45f8993df94a098c6e6093b097723 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 16 Jul 2021 02:40:44 +0200 Subject: [PATCH] AIS mod and demod, IEEE 802.15.4 mod: scope and spectrum feed optimization --- plugins/channelrx/demodais/aisdemodsink.cpp | 19 +++++++----- plugins/channelrx/demodais/aisdemodsink.h | 4 +++ .../channelrx/noisefigure/noisefiguresink.h | 3 +- .../mod802.15.4/ieee_802_15_4_modsource.cpp | 28 ++++++++++++----- .../mod802.15.4/ieee_802_15_4_modsource.h | 7 ++++- plugins/channeltx/modais/aismodsource.cpp | 30 +++++++++++++------ plugins/channeltx/modais/aismodsource.h | 9 +++++- 7 files changed, 73 insertions(+), 27 deletions(-) diff --git a/plugins/channelrx/demodais/aisdemodsink.cpp b/plugins/channelrx/demodais/aisdemodsink.cpp index 48353ca4c..a4fce9ade 100644 --- a/plugins/channelrx/demodais/aisdemodsink.cpp +++ b/plugins/channelrx/demodais/aisdemodsink.cpp @@ -41,12 +41,14 @@ AISDemodSink::AISDemodSink(AISDemod *aisDemod) : m_magsqCount(0), m_messageQueueToChannel(nullptr), m_rxBuf(nullptr), - m_train(nullptr) + m_train(nullptr), + m_sampleBufferIndex(0) { m_magsq = 0.0; m_demodBuffer.resize(1<<12); m_demodBufferFill = 0; + m_sampleBuffer.resize(m_sampleBufferSize); applySettings(m_settings, true); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); @@ -64,12 +66,15 @@ void AISDemodSink::sampleToScope(Complex sample) { Real r = std::real(sample) * SDR_RX_SCALEF; Real i = std::imag(sample) * SDR_RX_SCALEF; - SampleVector m_sampleBuffer; - m_sampleBuffer.push_back(Sample(r, i)); - std::vector vbegin; - vbegin.push_back(m_sampleBuffer.begin()); - m_scopeSink->feed(vbegin, m_sampleBuffer.end() - m_sampleBuffer.begin()); - m_sampleBuffer.clear(); + m_sampleBuffer[m_sampleBufferIndex++] = Sample(r, i); + + if (m_sampleBufferIndex == m_sampleBufferSize) + { + std::vector vbegin; + vbegin.push_back(m_sampleBuffer.begin()); + m_scopeSink->feed(vbegin, m_sampleBufferSize); + m_sampleBufferIndex = 0; + } } } diff --git a/plugins/channelrx/demodais/aisdemodsink.h b/plugins/channelrx/demodais/aisdemodsink.h index fc7688e9a..27d67b279 100644 --- a/plugins/channelrx/demodais/aisdemodsink.h +++ b/plugins/channelrx/demodais/aisdemodsink.h @@ -131,6 +131,10 @@ private: QVector m_demodBuffer; int m_demodBufferFill; + SampleVector m_sampleBuffer; + static const int m_sampleBufferSize = AISDemodSettings::AISDEMOD_CHANNEL_SAMPLE_RATE / 20; + int m_sampleBufferIndex; + void processOneSample(Complex &ci); MessageQueue *getMessageQueueToChannel() { return m_messageQueueToChannel; } void sampleToScope(Complex sample); diff --git a/plugins/channelrx/noisefigure/noisefiguresink.h b/plugins/channelrx/noisefigure/noisefiguresink.h index 0f35eb003..acd18106d 100644 --- a/plugins/channelrx/noisefigure/noisefiguresink.h +++ b/plugins/channelrx/noisefigure/noisefiguresink.h @@ -85,7 +85,7 @@ private: NoiseFigureSettings m_settings; ChannelAPI *m_channel; int m_channelSampleRate; - + int m_fftSequence; FFTEngine *m_fft; int m_fftCounter; @@ -106,7 +106,6 @@ private: void processOneSample(Complex &ci); MessageQueue *getMessageQueueToChannel() { return m_messageQueueToChannel; } - void sampleToScope(Complex sample); }; #endif // INCLUDE_NOISEFIGURESINK_H diff --git a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.cpp b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.cpp index f5713bcf2..722b83e53 100644 --- a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.cpp +++ b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.cpp @@ -32,6 +32,8 @@ IEEE_802_15_4_ModSource::IEEE_802_15_4_ModSource() : m_scrambler(0x108, 0x1fe, 1), m_spectrumSink(nullptr), m_scopeSink(nullptr), + m_specSampleBufferIndex(0), + m_scopeSampleBufferIndex(0), m_magsq(0.0), m_levelCalcCount(0), m_peakLevel(0.0f), @@ -48,6 +50,8 @@ IEEE_802_15_4_ModSource::IEEE_802_15_4_ModSource() : m_lowpass.create(301, m_channelSampleRate, 22000.0 / 2.0); m_pulseShapeI.create(1, 6, m_channelSampleRate/300000, true); m_pulseShapeQ.create(1, 6, m_channelSampleRate/300000, true); + m_specSampleBuffer.resize(m_specSampleBufferSize); + m_scopeSampleBuffer.resize(m_scopeSampleBufferSize); applySettings(m_settings, true); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); } @@ -106,9 +110,14 @@ void IEEE_802_15_4_ModSource::sampleToSpectrum(Complex sample) { Real r = std::real(out) * SDR_TX_SCALEF; Real i = std::imag(out) * SDR_TX_SCALEF; - m_sampleBuffer.push_back(Sample(r, i)); - m_spectrumSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false); - m_sampleBuffer.clear(); + m_specSampleBuffer[m_specSampleBufferIndex++] = Sample(r, i); + + if (m_specSampleBufferIndex == m_specSampleBufferSize) + { + m_spectrumSink->feed(m_specSampleBuffer.begin(), m_specSampleBuffer.end(), false); + m_specSampleBufferIndex = 0; + } + m_interpolatorDistanceRemain += m_interpolatorDistance; } } @@ -120,10 +129,15 @@ void IEEE_802_15_4_ModSource::sampleToScope(Complex sample) { Real r = std::real(sample) * SDR_RX_SCALEF; Real i = std::imag(sample) * SDR_RX_SCALEF; - m_sampleBuffer.push_back(Sample(r, i)); - std::vector vbegin; - m_scopeSink->feed(vbegin, m_sampleBuffer.end() - m_sampleBuffer.begin()); - m_sampleBuffer.clear(); + m_scopeSampleBuffer[m_scopeSampleBufferIndex++] = Sample(r, i); + + if (m_scopeSampleBufferIndex == m_scopeSampleBufferSize) + { + std::vector vbegin; + vbegin.push_back(m_scopeSampleBuffer.begin()); + m_scopeSink->feed(vbegin, m_scopeSampleBufferSize); + m_scopeSampleBufferIndex = 0; + } } } diff --git a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.h b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.h index 8367c7f4b..bc642db21 100644 --- a/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.h +++ b/plugins/channeltx/mod802.15.4/ieee_802_15_4_modsource.h @@ -86,7 +86,12 @@ private: BasebandSampleSink* m_spectrumSink; // Spectrum GUI to display baseband waveform ScopeVis* m_scopeSink; // Scope GUI to display baseband waveform - SampleVector m_sampleBuffer; + SampleVector m_specSampleBuffer; + int m_specSampleBufferIndex; + static const int m_specSampleBufferSize = 1024; + SampleVector m_scopeSampleBuffer; + int m_scopeSampleBufferIndex; + static const int m_scopeSampleBufferSize = 4800; Interpolator m_interpolator; // Interpolator to downsample to 4k in spectrum Real m_interpolatorDistance; Real m_interpolatorDistanceRemain; diff --git a/plugins/channeltx/modais/aismodsource.cpp b/plugins/channeltx/modais/aismodsource.cpp index 00d61a4db..7df575d8d 100644 --- a/plugins/channeltx/modais/aismodsource.cpp +++ b/plugins/channeltx/modais/aismodsource.cpp @@ -41,10 +41,14 @@ AISModSource::AISModSource() : m_byteIdx(0), m_bitIdx(0), m_last5Bits(0), - m_bitCount(0) + m_bitCount(0), + m_scopeSampleBufferIndex(0), + m_specSampleBufferIndex(0) { m_demodBuffer.resize(1<<12); m_demodBufferFill = 0; + m_scopeSampleBuffer.resize(m_scopeSampleBufferSize); + m_specSampleBuffer.resize(m_specSampleBufferSize); applySettings(m_settings, true); applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true); @@ -113,9 +117,13 @@ void AISModSource::sampleToSpectrum(Complex sample) { Real r = std::real(sample) * SDR_TX_SCALEF; Real i = std::imag(sample) * SDR_TX_SCALEF; - m_sampleBuffer.push_back(Sample(r, i)); - m_spectrumSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false); - m_sampleBuffer.clear(); + m_specSampleBuffer[m_specSampleBufferIndex++] = Sample(r, i); + + if (m_specSampleBufferIndex == m_specSampleBufferSize) + { + m_spectrumSink->feed(m_specSampleBuffer.begin(), m_specSampleBuffer.end(), false); + m_specSampleBufferIndex = 0; + } } } @@ -125,11 +133,15 @@ void AISModSource::sampleToScope(Complex sample) { Real r = std::real(sample) * SDR_RX_SCALEF; Real i = std::imag(sample) * SDR_RX_SCALEF; - m_sampleBuffer.push_back(Sample(r, i)); - std::vector vbegin; - vbegin.push_back(m_sampleBuffer.begin()); - m_scopeSink->feed(vbegin, m_sampleBuffer.end() - m_sampleBuffer.begin()); - m_sampleBuffer.clear(); + m_scopeSampleBuffer[m_scopeSampleBufferIndex++] = Sample(r, i); + + if (m_scopeSampleBufferIndex == m_scopeSampleBufferSize) + { + std::vector vbegin; + vbegin.push_back(m_scopeSampleBuffer.begin()); + m_scopeSink->feed(vbegin, m_scopeSampleBufferSize); + m_scopeSampleBufferIndex = 0; + } } } diff --git a/plugins/channeltx/modais/aismodsource.h b/plugins/channeltx/modais/aismodsource.h index edf65e2b7..d18d32c51 100644 --- a/plugins/channeltx/modais/aismodsource.h +++ b/plugins/channeltx/modais/aismodsource.h @@ -90,7 +90,6 @@ private: BasebandSampleSink* m_spectrumSink; // Spectrum GUI to display baseband waveform ScopeVis* m_scopeSink; // Scope GUI to display baseband waveform - SampleVector m_sampleBuffer; Interpolator m_interpolator; // Interpolator to channel sample rate Real m_interpolatorDistance; @@ -129,6 +128,14 @@ private: QVector m_demodBuffer; int m_demodBufferFill; + SampleVector m_scopeSampleBuffer; + static const int m_scopeSampleBufferSize = AISModSettings::AISMOD_SAMPLE_RATE / 20; + int m_scopeSampleBufferIndex; + + SampleVector m_specSampleBuffer; + static const int m_specSampleBufferSize = 1024; + int m_specSampleBufferIndex; + bool bitsValid(); // Are there and bits to transmit int getBit(); // Get bit from m_bits void addBit(int bit); // Add bit to m_bits, with zero stuffing