From fa780d9134bb3af1fa2fa8098397922da4c8ec49 Mon Sep 17 00:00:00 2001 From: Hexameron Date: Sun, 15 Jun 2014 09:32:25 +0100 Subject: [PATCH] Demispectrum. --- include-gpl/dsp/channelizer.h | 2 +- include-gpl/dsp/scopevis.h | 2 +- include-gpl/dsp/spectrumvis.h | 2 +- include/dsp/samplesink.h | 2 +- include/dsp/threadedsamplesink.h | 2 +- plugins/channel/nfm/nfmdemod.cpp | 4 ++-- plugins/channel/nfm/nfmdemod.h | 2 +- plugins/channel/ssb/ssbdemod.cpp | 4 ++-- plugins/channel/ssb/ssbdemod.h | 2 +- plugins/channel/tcpsrc/tcpsrc.cpp | 4 ++-- plugins/channel/tcpsrc/tcpsrc.h | 2 +- plugins/channel/tetra/tetrademod.cpp | 4 ++-- plugins/channel/tetra/tetrademod.h | 2 +- sdrbase/dsp/channelizer.cpp | 11 +++++++---- sdrbase/dsp/dspengine.cpp | 7 +++---- sdrbase/dsp/scopevis.cpp | 2 +- sdrbase/dsp/spectrumvis.cpp | 12 ++++++++++-- sdrbase/dsp/threadedsamplesink.cpp | 11 +++++------ 18 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include-gpl/dsp/channelizer.h b/include-gpl/dsp/channelizer.h index cf3ede3ac..ddff7162b 100644 --- a/include-gpl/dsp/channelizer.h +++ b/include-gpl/dsp/channelizer.h @@ -15,7 +15,7 @@ public: void configure(MessageQueue* messageQueue, int sampleRate, int centerFrequency); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/include-gpl/dsp/scopevis.h b/include-gpl/dsp/scopevis.h index 4845a632f..59a92d7d1 100644 --- a/include-gpl/dsp/scopevis.h +++ b/include-gpl/dsp/scopevis.h @@ -19,7 +19,7 @@ public: void configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, Real triggerLevelHigh, Real triggerLevelLow); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* message); diff --git a/include-gpl/dsp/spectrumvis.h b/include-gpl/dsp/spectrumvis.h index ebc16ab09..8708cdc3a 100644 --- a/include-gpl/dsp/spectrumvis.h +++ b/include-gpl/dsp/spectrumvis.h @@ -16,7 +16,7 @@ public: void configure(MessageQueue* msgQueue, int fftSize, int overlapPercent, FFTWindow::Function window); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* message); diff --git a/include/dsp/samplesink.h b/include/dsp/samplesink.h index 1c8fb3237..29f2103f1 100644 --- a/include/dsp/samplesink.h +++ b/include/dsp/samplesink.h @@ -12,7 +12,7 @@ public: SampleSink(); virtual ~SampleSink(); - virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) = 0; + virtual void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) = 0; virtual void start() = 0; virtual void stop() = 0; virtual bool handleMessage(Message* cmd) = 0; diff --git a/include/dsp/threadedsamplesink.h b/include/dsp/threadedsamplesink.h index 1e470fe1b..694e127c3 100644 --- a/include/dsp/threadedsamplesink.h +++ b/include/dsp/threadedsamplesink.h @@ -19,7 +19,7 @@ public: MessageQueue* getMessageQueue() { return &m_messageQueue; } - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index 11992e0fe..c64298ba1 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -57,7 +57,7 @@ void NFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBa } int framedrop = 0; -void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; bool consumed; @@ -109,7 +109,7 @@ void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter m_audioBufferFill = 0; if(m_sampleSink != NULL) - m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), firstOfBurst); + m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), true); m_sampleBuffer.clear(); } diff --git a/plugins/channel/nfm/nfmdemod.h b/plugins/channel/nfm/nfmdemod.h index a312abbb3..d293124e7 100644 --- a/plugins/channel/nfm/nfmdemod.h +++ b/plugins/channel/nfm/nfmdemod.h @@ -36,7 +36,7 @@ public: void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/plugins/channel/ssb/ssbdemod.cpp b/plugins/channel/ssb/ssbdemod.cpp index f8d1ce7b7..3000bbab8 100644 --- a/plugins/channel/ssb/ssbdemod.cpp +++ b/plugins/channel/ssb/ssbdemod.cpp @@ -53,7 +53,7 @@ void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real volume } int undersamplecount = 0; -void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; bool consumed; @@ -88,7 +88,7 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter m_audioBufferFill = 0; if(m_sampleSink != NULL) - m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), firstOfBurst); + m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), true); m_sampleBuffer.clear(); } diff --git a/plugins/channel/ssb/ssbdemod.h b/plugins/channel/ssb/ssbdemod.h index 65230032c..0e3c44356 100644 --- a/plugins/channel/ssb/ssbdemod.h +++ b/plugins/channel/ssb/ssbdemod.h @@ -35,7 +35,7 @@ public: void configure(MessageQueue* messageQueue, Real Bandwidth, Real volume); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index 9cfee4354..c656bf56f 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -43,7 +43,7 @@ void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled) cmd->submit(messageQueue, this); } -void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; bool consumed; @@ -60,7 +60,7 @@ void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterat } if((m_spectrum != NULL) && (m_spectrumEnabled)) - m_spectrum->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), firstOfBurst); + m_spectrum->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly); for(int i = 0; i < m_s16leSockets.count(); i++) m_s16leSockets[i].socket->write((const char*)&m_sampleBuffer[0], m_sampleBuffer.size() * 4); diff --git a/plugins/channel/tcpsrc/tcpsrc.h b/plugins/channel/tcpsrc/tcpsrc.h index 012a4dff2..dc40b0d22 100644 --- a/plugins/channel/tcpsrc/tcpsrc.h +++ b/plugins/channel/tcpsrc/tcpsrc.h @@ -26,7 +26,7 @@ public: void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort); void setSpectrum(MessageQueue* messageQueue, bool enabled); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/plugins/channel/tetra/tetrademod.cpp b/plugins/channel/tetra/tetrademod.cpp index f26810a70..c6027ad40 100644 --- a/plugins/channel/tetra/tetrademod.cpp +++ b/plugins/channel/tetra/tetrademod.cpp @@ -44,7 +44,7 @@ void TetraDemod::configure(MessageQueue* messageQueue) cmd->submit(messageQueue, this); } -void TetraDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void TetraDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { size_t count = end - begin; @@ -68,7 +68,7 @@ void TetraDemod::feed(SampleVector::const_iterator begin, SampleVector::const_it } if(m_sampleSink != NULL) - m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), firstOfBurst); + m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly); m_sampleBuffer.clear(); } diff --git a/plugins/channel/tetra/tetrademod.h b/plugins/channel/tetra/tetrademod.h index a2a474b63..b031b58c1 100644 --- a/plugins/channel/tetra/tetrademod.h +++ b/plugins/channel/tetra/tetrademod.h @@ -32,7 +32,7 @@ public: void configure(MessageQueue* messageQueue); - void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst); + void feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly); void start(); void stop(); bool handleMessage(Message* cmd); diff --git a/sdrbase/dsp/channelizer.cpp b/sdrbase/dsp/channelizer.cpp index d57ef8b5d..d7f37ae55 100644 --- a/sdrbase/dsp/channelizer.cpp +++ b/sdrbase/dsp/channelizer.cpp @@ -23,8 +23,13 @@ void Channelizer::configure(MessageQueue* messageQueue, int sampleRate, int cent cmd->submit(messageQueue, this); } -void Channelizer::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void Channelizer::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { + if(m_sampleSink == NULL) { + m_sampleBuffer.clear(); + return; + } + for(SampleVector::const_iterator sample = begin; sample != end; ++sample) { Sample s(*sample); FilterStages::iterator stage = m_filterStages.begin(); @@ -37,9 +42,7 @@ void Channelizer::feed(SampleVector::const_iterator begin, SampleVector::const_i m_sampleBuffer.push_back(s); } - if(m_sampleSink != NULL) - m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), firstOfBurst); - + m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly); m_sampleBuffer.clear(); } diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index 949dfec80..76763fbb2 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -200,7 +200,7 @@ void DSPEngine::work() { SampleFifo* sampleFifo = m_sampleSource->getSampleFifo(); size_t samplesDone = 0; - bool firstOfBurst = true; + bool positiveOnly = false; while((sampleFifo->fill() > 0) && (m_messageQueue.countPending() == 0) && (samplesDone < m_sampleRate)) { SampleVector::iterator part1begin; @@ -219,7 +219,7 @@ void DSPEngine::work() imbalance(part1begin, part1end); // feed data to handlers for(SampleSinks::const_iterator it = m_sampleSinks.begin(); it != m_sampleSinks.end(); it++) - (*it)->feed(part1begin, part1end, firstOfBurst); + (*it)->feed(part1begin, part1end, positiveOnly); } // second part of FIFO data (used when block wraps around) if(part2begin != part2end) { @@ -230,9 +230,8 @@ void DSPEngine::work() imbalance(part2begin, part2end); // feed data to handlers for(SampleSinks::const_iterator it = m_sampleSinks.begin(); it != m_sampleSinks.end(); it++) - (*it)->feed(part2begin, part2end, firstOfBurst); + (*it)->feed(part2begin, part2end, positiveOnly); } - firstOfBurst = false; // adjust FIFO pointers sampleFifo->readCommit(count); diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 0dc8e23ee..d5aca9921 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -21,7 +21,7 @@ void ScopeVis::configure(MessageQueue* msgQueue, TriggerChannel triggerChannel, cmd->submit(msgQueue, this); } -void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void ScopeVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { while(begin < end) { if(m_triggerChannel == TriggerChannelI) { diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 102ad3855..1bc9a43f4 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -34,7 +34,7 @@ void SpectrumVis::configure(MessageQueue* msgQueue, int fftSize, int overlapPerc cmd->submit(msgQueue, this); } -void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { // if no visualisation is set, send the samples to /dev/null if(m_glSpectrum == NULL) @@ -60,7 +60,15 @@ void SpectrumVis::feed(SampleVector::const_iterator begin, SampleVector::const_i Real ofs = 20.0f * log10f(1.0f / m_fftSize); Real mult = (10.0f / log2f(10.0f)); const Complex* fftOut = m_fft->out(); - for(size_t i = 0; i < m_fftSize; i++) { + size_t spectrumStart = 0; + + if ( positiveOnly ) { + Real logZero = ofs + mult * log2f( 0 ); + for(size_t i = 0; i < m_fftSize / 2; i++) + m_logPowerSpectrum[i] = logZero; + spectrumStart = m_fftSize / 2; + } + for(size_t i = spectrumStart; i < m_fftSize; i++) { Complex c = fftOut[((i + (m_fftSize >> 1)) & (m_fftSize - 1))]; Real v = c.real() * c.real() + c.imag() * c.imag(); v = mult * log2f(v) + ofs; diff --git a/sdrbase/dsp/threadedsamplesink.cpp b/sdrbase/dsp/threadedsamplesink.cpp index dc164b4b4..da20ecd1a 100644 --- a/sdrbase/dsp/threadedsamplesink.cpp +++ b/sdrbase/dsp/threadedsamplesink.cpp @@ -27,9 +27,9 @@ ThreadedSampleSink::~ThreadedSampleSink() delete m_thread; } -void ThreadedSampleSink::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) +void ThreadedSampleSink::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { - Q_UNUSED(firstOfBurst); + Q_UNUSED(positiveOnly); m_sampleFifo.write(begin, end); } @@ -54,7 +54,7 @@ bool ThreadedSampleSink::handleMessage(Message* cmd) void ThreadedSampleSink::handleData() { - bool firstOfBurst = true; + bool positiveOnly = false; while((m_sampleFifo.fill() > 0) && (m_messageQueue.countPending() == 0)) { SampleVector::iterator part1begin; @@ -68,15 +68,14 @@ void ThreadedSampleSink::handleData() if(part1begin != part1end) { // handle data if(m_sampleSink != NULL) - m_sampleSink->feed(part1begin, part1end, firstOfBurst); + m_sampleSink->feed(part1begin, part1end, positiveOnly); } // second part of FIFO data (used when block wraps around) if(part2begin != part2end) { // handle data if(m_sampleSink != NULL) - m_sampleSink->feed(part2begin, part2end, firstOfBurst); + m_sampleSink->feed(part2begin, part2end, positiveOnly); } - firstOfBurst = false; // adjust FIFO pointers m_sampleFifo.readCommit(count);