From 005eae774e3daadf0cf3efa60a0c97186bf05921 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 25 Aug 2015 08:24:23 +0200 Subject: [PATCH] Deep redesign: use references for the iterator parameters of the sample sinks feed method --- include-gpl/dsp/channelizer.h | 2 +- include-gpl/dsp/filesink.h | 2 +- include-gpl/dsp/scopevis.h | 2 +- include-gpl/dsp/spectrumscopecombovis.h | 2 +- include-gpl/dsp/spectrumvis.h | 4 +-- include/dsp/samplesink.h | 2 +- plugins/channel/am/amdemod.cpp | 2 +- plugins/channel/am/amdemod.h | 2 +- plugins/channel/chanalyzer/chanalyzer.cpp | 2 +- plugins/channel/chanalyzer/chanalyzer.h | 2 +- plugins/channel/lora/lorademod.cpp | 2 +- plugins/channel/lora/lorademod.h | 2 +- plugins/channel/nfm/nfmdemod.cpp | 2 +- plugins/channel/nfm/nfmdemod.h | 2 +- plugins/channel/ssb/ssbdemod.cpp | 2 +- plugins/channel/ssb/ssbdemod.h | 2 +- plugins/channel/tcpsrc/tcpsrc.cpp | 2 +- plugins/channel/tcpsrc/tcpsrc.h | 2 +- plugins/channel/wfm/wfmdemod.cpp | 2 +- plugins/channel/wfm/wfmdemod.h | 2 +- sdrbase/dsp/channelizer.cpp | 2 +- sdrbase/dsp/filesink.cpp | 2 +- sdrbase/dsp/scopevis.cpp | 4 ++- sdrbase/dsp/spectrumscopecombovis.cpp | 2 +- sdrbase/dsp/spectrumvis.cpp | 44 ++++++++++++++++------- 25 files changed, 59 insertions(+), 37 deletions(-) diff --git a/include-gpl/dsp/channelizer.h b/include-gpl/dsp/channelizer.h index 870985e83..5f2bca3fc 100644 --- a/include-gpl/dsp/channelizer.h +++ b/include-gpl/dsp/channelizer.h @@ -38,7 +38,7 @@ public: virtual void start(); virtual void stop(); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual bool handleMessage(const Message& cmd); protected: diff --git a/include-gpl/dsp/filesink.h b/include-gpl/dsp/filesink.h index 821c74cc1..e13871d28 100644 --- a/include-gpl/dsp/filesink.h +++ b/include-gpl/dsp/filesink.h @@ -28,7 +28,7 @@ public: void configure(MessageQueue* msgQueue, const std::string& filename); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& message); diff --git a/include-gpl/dsp/scopevis.h b/include-gpl/dsp/scopevis.h index d56a2da42..c774bed32 100644 --- a/include-gpl/dsp/scopevis.h +++ b/include-gpl/dsp/scopevis.h @@ -35,7 +35,7 @@ public: uint traceSize); void setOneShot(bool oneShot); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& message); diff --git a/include-gpl/dsp/spectrumscopecombovis.h b/include-gpl/dsp/spectrumscopecombovis.h index ae1d4c00b..2c5837c6e 100644 --- a/include-gpl/dsp/spectrumscopecombovis.h +++ b/include-gpl/dsp/spectrumscopecombovis.h @@ -14,7 +14,7 @@ public: SpectrumScopeComboVis(SpectrumVis* spectrumVis, ScopeVis* scopeVis); virtual ~SpectrumScopeComboVis(); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& message); diff --git a/include-gpl/dsp/spectrumvis.h b/include-gpl/dsp/spectrumvis.h index 2e1b5e897..9c3b6d3a0 100644 --- a/include-gpl/dsp/spectrumvis.h +++ b/include-gpl/dsp/spectrumvis.h @@ -39,8 +39,8 @@ public: void configure(MessageQueue* msgQueue, int fftSize, int overlapPercent, FFTWindow::Function window); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); - void feedTriggered(SampleVector::const_iterator triggerPoint, SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); + void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& message); diff --git a/include/dsp/samplesink.h b/include/dsp/samplesink.h index 6d05820a9..dbb55ab04 100644 --- a/include/dsp/samplesink.h +++ b/include/dsp/samplesink.h @@ -16,7 +16,7 @@ public: virtual void start() = 0; virtual void stop() = 0; - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) = 0; + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) = 0; virtual bool handleMessage(const Message& cmd) = 0; //!< Processing of a message. Returns true if message has actually been processed MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication diff --git a/plugins/channel/am/amdemod.cpp b/plugins/channel/am/amdemod.cpp index 2c7a8e13e..bd8fe4def 100644 --- a/plugins/channel/am/amdemod.cpp +++ b/plugins/channel/am/amdemod.cpp @@ -63,7 +63,7 @@ void AMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBan messageQueue->push(cmd); } -void AMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void AMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) { Complex ci; diff --git a/plugins/channel/am/amdemod.h b/plugins/channel/am/amdemod.h index aa12e915a..9ca0f3d22 100644 --- a/plugins/channel/am/amdemod.h +++ b/plugins/channel/am/amdemod.h @@ -36,7 +36,7 @@ public: void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool po); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/chanalyzer/chanalyzer.cpp b/plugins/channel/chanalyzer/chanalyzer.cpp index 394737748..b07d77334 100644 --- a/plugins/channel/chanalyzer/chanalyzer.cpp +++ b/plugins/channel/chanalyzer/chanalyzer.cpp @@ -60,7 +60,7 @@ void ChannelAnalyzer::configure(MessageQueue* messageQueue, messageQueue->push(cmd); } -void ChannelAnalyzer::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { fftfilt::cmplx *sideband, sum; int n_out; diff --git a/plugins/channel/chanalyzer/chanalyzer.h b/plugins/channel/chanalyzer/chanalyzer.h index 3fc5ad7b1..4c0fd24ae 100644 --- a/plugins/channel/chanalyzer/chanalyzer.h +++ b/plugins/channel/chanalyzer/chanalyzer.h @@ -43,7 +43,7 @@ public: return m_sampleRate; } - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/lora/lorademod.cpp b/plugins/channel/lora/lorademod.cpp index f1a96907c..61f0ca1d7 100644 --- a/plugins/channel/lora/lorademod.cpp +++ b/plugins/channel/lora/lorademod.cpp @@ -236,7 +236,7 @@ int LoRaDemod::detect(Complex c, Complex a) return m_result; } -void LoRaDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool pO) +void LoRaDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO) { int newangle; Complex ci; diff --git a/plugins/channel/lora/lorademod.h b/plugins/channel/lora/lorademod.h index 272b3cc48..d8858e8e0 100644 --- a/plugins/channel/lora/lorademod.h +++ b/plugins/channel/lora/lorademod.h @@ -39,7 +39,7 @@ public: void configure(MessageQueue* messageQueue, Real Bandwidth); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool pO); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool pO); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index bb25d0ef5..8848b5a60 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -106,7 +106,7 @@ Real angleDist(Real a, Real b) return dist; } -void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) { Complex ci; diff --git a/plugins/channel/nfm/nfmdemod.h b/plugins/channel/nfm/nfmdemod.h index 00a6f3d8f..251fc6674 100644 --- a/plugins/channel/nfm/nfmdemod.h +++ b/plugins/channel/nfm/nfmdemod.h @@ -41,7 +41,7 @@ public: void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool po); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/ssb/ssbdemod.cpp b/plugins/channel/ssb/ssbdemod.cpp index fcdc224cb..224de0a43 100644 --- a/plugins/channel/ssb/ssbdemod.cpp +++ b/plugins/channel/ssb/ssbdemod.cpp @@ -71,7 +71,7 @@ void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCut messageQueue->push(cmd); } -void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void SSBDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { Complex ci; fftfilt::cmplx *sideband, sum; diff --git a/plugins/channel/ssb/ssbdemod.h b/plugins/channel/ssb/ssbdemod.h index 05d5593eb..a8e2ceb64 100644 --- a/plugins/channel/ssb/ssbdemod.h +++ b/plugins/channel/ssb/ssbdemod.h @@ -36,7 +36,7 @@ public: void configure(MessageQueue* messageQueue, Real Bandwidth, Real LowCutoff, Real volume, int spanLog2); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index 7ee908c6b..3b953a83a 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -71,7 +71,7 @@ void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled) messageQueue->push(cmd); } -void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void TCPSrc::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { Complex ci; fftfilt::cmplx* sideband; diff --git a/plugins/channel/tcpsrc/tcpsrc.h b/plugins/channel/tcpsrc/tcpsrc.h index a005f9baf..dce83c1d3 100644 --- a/plugins/channel/tcpsrc/tcpsrc.h +++ b/plugins/channel/tcpsrc/tcpsrc.h @@ -32,7 +32,7 @@ public: void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort, int boost); void setSpectrum(MessageQueue* messageQueue, bool enabled); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/plugins/channel/wfm/wfmdemod.cpp b/plugins/channel/wfm/wfmdemod.cpp index 7e9946dec..59b3a72d4 100644 --- a/plugins/channel/wfm/wfmdemod.cpp +++ b/plugins/channel/wfm/wfmdemod.cpp @@ -69,7 +69,7 @@ void WFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBa messageQueue->push(cmd); } -void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) { Complex ci; fftfilt::cmplx *rf; diff --git a/plugins/channel/wfm/wfmdemod.h b/plugins/channel/wfm/wfmdemod.h index ee598475f..839d51c07 100644 --- a/plugins/channel/wfm/wfmdemod.h +++ b/plugins/channel/wfm/wfmdemod.h @@ -38,7 +38,7 @@ public: void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool po); + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); virtual void start(); virtual void stop(); virtual bool handleMessage(const Message& cmd); diff --git a/sdrbase/dsp/channelizer.cpp b/sdrbase/dsp/channelizer.cpp index 7168b15b9..23988779c 100644 --- a/sdrbase/dsp/channelizer.cpp +++ b/sdrbase/dsp/channelizer.cpp @@ -30,7 +30,7 @@ void Channelizer::configure(MessageQueue* messageQueue, int sampleRate, int cent messageQueue->push(cmd); } -void Channelizer::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void Channelizer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { if(m_sampleSink == 0) { m_sampleBuffer.clear(); diff --git a/sdrbase/dsp/filesink.cpp b/sdrbase/dsp/filesink.cpp index c5f66b689..84118d09f 100644 --- a/sdrbase/dsp/filesink.cpp +++ b/sdrbase/dsp/filesink.cpp @@ -30,7 +30,7 @@ void FileSink::configure(MessageQueue* msgQueue, const std::string& filename) msgQueue->push(cmd); } -void FileSink::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void FileSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { // if no recording is active, send the samples to /dev/null if(!m_recordOn) diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index f8323a23a..38829b711 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -55,8 +55,10 @@ void ScopeVis::configure(MessageQueue* msgQueue, msgQueue->push(cmd); } -void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void ScopeVis::feed(const SampleVector::const_iterator& cbegin, const SampleVector::const_iterator& end, bool positiveOnly) { + SampleVector::const_iterator begin(cbegin); + if (m_triggerChannel == TriggerFreeRun) { m_triggerPoint = begin; } diff --git a/sdrbase/dsp/spectrumscopecombovis.cpp b/sdrbase/dsp/spectrumscopecombovis.cpp index b75366b13..8b5352303 100644 --- a/sdrbase/dsp/spectrumscopecombovis.cpp +++ b/sdrbase/dsp/spectrumscopecombovis.cpp @@ -13,7 +13,7 @@ SpectrumScopeComboVis::~SpectrumScopeComboVis() { } -void SpectrumScopeComboVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void SpectrumScopeComboVis::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { m_scopeVis->feed(begin, end, false); SampleVector::const_iterator triggerPoint = m_scopeVis->getTriggerPoint(); diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 22f1b1d38..3f34dfecc 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -38,7 +38,7 @@ void SpectrumVis::configure(MessageQueue* msgQueue, int fftSize, int overlapPerc msgQueue->push(cmd); } -void SpectrumVis::feedTriggered(SampleVector::const_iterator triggerPoint, SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void SpectrumVis::feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { feed(triggerPoint, end, positiveOnly); // normal feed from trigger point /* @@ -59,21 +59,31 @@ void SpectrumVis::feedTriggered(SampleVector::const_iterator triggerPoint, Sampl }*/ } -void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) +void SpectrumVis::feed(const SampleVector::const_iterator& cbegin, const SampleVector::const_iterator& end, bool positiveOnly) { // if no visualisation is set, send the samples to /dev/null - if(m_glSpectrum == NULL) - return; - while(begin < end) { + if(m_glSpectrum == 0) + { + return; + } + + SampleVector::const_iterator begin(cbegin); + + while (begin < end) + { std::size_t todo = end - begin; std::size_t samplesNeeded = m_refillSize - m_fftBufferFill; - if(todo >= samplesNeeded) { + if (todo >= samplesNeeded) + { // fill up the buffer std::vector::iterator it = m_fftBuffer.begin() + m_fftBufferFill; - for(std::size_t i = 0; i < samplesNeeded; ++i, ++begin) + + for (std::size_t i = 0; i < samplesNeeded; ++i, ++begin) + { *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); + } // apply fft window (and copy from m_fftBuffer to m_fftIn) m_window.apply(&m_fftBuffer[0], m_fft->in()); @@ -89,16 +99,21 @@ void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_i Real v; std::size_t halfSize = m_fftSize / 2; - if ( positiveOnly ) { - for(std::size_t i = 0; i < halfSize; i++) { + if ( positiveOnly ) + { + for (std::size_t i = 0; i < halfSize; i++) + { c = fftOut[i]; v = c.real() * c.real() + c.imag() * c.imag(); v = mult * log2f(v) + ofs; m_logPowerSpectrum[i * 2] = v; m_logPowerSpectrum[i * 2 + 1] = v; } - } else { - for(std::size_t i = 0; i < halfSize; i++) { + } + else + { + for (std::size_t i = 0; i < halfSize; i++) + { c = fftOut[i + halfSize]; v = c.real() * c.real() + c.imag() * c.imag(); v = mult * log2f(v) + ofs; @@ -120,10 +135,15 @@ void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_i // start over m_fftBufferFill = m_overlapSize; m_needMoreSamples = false; - } else { + } + else + { // not enough samples for FFT - just fill in new data and return for(std::vector::iterator it = m_fftBuffer.begin() + m_fftBufferFill; begin < end; ++begin) + { *it++ = Complex(begin->real() / 32768.0, begin->imag() / 32768.0); + } + m_fftBufferFill += todo; m_needMoreSamples = true; }