From 444e8ed8571b1f7fdd80a81121a474d9b0144d17 Mon Sep 17 00:00:00 2001 From: Hexameron Date: Wed, 28 May 2014 19:13:09 +0100 Subject: [PATCH] Rework decimation. --- include/dsp/samplesource/samplesource.h | 1 - plugins/channel/nfm/nfmdemod.cpp | 31 +++++---- plugins/channel/nfm/nfmdemodgui.cpp | 2 +- plugins/channel/ssb/ssbdemodgui.cpp | 2 +- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 6 -- plugins/samplesource/rtlsdr/rtlsdrinput.h | 1 - plugins/samplesource/rtlsdr/rtlsdrthread.cpp | 67 ++------------------ plugins/samplesource/rtlsdr/rtlsdrthread.h | 5 -- sdrbase/dsp/dspengine.cpp | 7 -- 9 files changed, 25 insertions(+), 97 deletions(-) diff --git a/include/dsp/samplesource/samplesource.h b/include/dsp/samplesource/samplesource.h index 9edf524e1..1e50c993a 100644 --- a/include/dsp/samplesource/samplesource.h +++ b/include/dsp/samplesource/samplesource.h @@ -45,7 +45,6 @@ public: virtual const QString& getDeviceDescription() const = 0; virtual int getSampleRate() const = 0; - virtual int wfdecimation() const = 0; virtual quint64 getCenterFrequency() const = 0; virtual bool handleMessage(Message* message) = 0; diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index d9bbc08d9..11992e0fe 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -56,10 +56,12 @@ void NFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBa cmd->submit(messageQueue, this); } +int framedrop = 0; void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool firstOfBurst) { Complex ci; bool consumed; + qint16 sample; for(SampleVector::const_iterator it = begin; it < end; ++it) { Complex c(it->real() / 32768.0, it->imag() / 32768.0); @@ -67,22 +69,25 @@ void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter consumed = false; if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) { - m_sampleBuffer.push_back(Sample(ci.real() * 32768.0, ci.imag() * 32768.0)); + if (++framedrop & 1) { + m_movingAverage.feed(ci.real() * ci.real() + ci.imag() * ci.imag()); + if(m_movingAverage.average() >= m_squelchLevel) + m_squelchState = m_sampleRate / 50; + } + Complex d = ci * conj(m_lastSample); + m_lastSample = ci; + Real demod = atan2(d.imag(), d.real()) / M_PI; + demod = m_volume * m_lowpass.filter(demod); + sample = demod * 32767; - m_movingAverage.feed(ci.real() * ci.real() + ci.imag() * ci.imag()); + if (!(framedrop & 3)) + m_sampleBuffer.push_back(Sample(sample, sample)); - if(m_movingAverage.average() >= m_squelchLevel) - m_squelchState = m_sampleRate / 50; - - if(m_squelchState > 0) { + if(m_squelchState > 0) m_squelchState--; - Complex d = ci * conj(m_lastSample); - m_lastSample = ci; - Real demod = atan2(d.imag(), d.real()) / M_PI; - demod = m_lowpass.filter(demod); - demod *= m_volume; - qint16 sample = demod * 32767; - + else + sample = 0; + { m_audioBuffer[m_audioBufferFill].l = sample; m_audioBuffer[m_audioBufferFill].r = sample; ++m_audioBufferFill; diff --git a/plugins/channel/nfm/nfmdemodgui.cpp b/plugins/channel/nfm/nfmdemodgui.cpp index 446fbcae6..0b314fafd 100644 --- a/plugins/channel/nfm/nfmdemodgui.cpp +++ b/plugins/channel/nfm/nfmdemodgui.cpp @@ -164,7 +164,7 @@ NFMDemodGUI::NFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : m_pluginAPI->addSampleSink(m_threadedSampleSink); ui->glSpectrum->setCenterFrequency(0); - ui->glSpectrum->setSampleRate(48000); + ui->glSpectrum->setSampleRate(12000); ui->glSpectrum->setDisplayWaterfall(true); ui->glSpectrum->setDisplayMaxHold(true); m_spectrumVis->configure(m_threadedSampleSink->getMessageQueue(), 64, 10, FFTWindow::BlackmanHarris); diff --git a/plugins/channel/ssb/ssbdemodgui.cpp b/plugins/channel/ssb/ssbdemodgui.cpp index 2ed1404eb..a861e10b2 100644 --- a/plugins/channel/ssb/ssbdemodgui.cpp +++ b/plugins/channel/ssb/ssbdemodgui.cpp @@ -140,7 +140,7 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : ui->glSpectrum->setCenterFrequency(0); ui->glSpectrum->setSampleRate(12000); ui->glSpectrum->setDisplayWaterfall(true); - ui->glSpectrum->setDisplayMaxHold(false); + ui->glSpectrum->setDisplayMaxHold(true); m_spectrumVis->configure(m_threadedSampleSink->getMessageQueue(), 64, 10, FFTWindow::BlackmanHarris); m_channelMarker = new ChannelMarker(this); diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 0e84b8746..5ea49d3e8 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -185,12 +185,6 @@ int RTLSDRInput::getSampleRate() const return 1536000 / (1 << m_settings.m_decimation); } -int RTLSDRInput::wfdecimation() const -{ - // decimate waterfall more when downsampling less - return (1 << (4 - m_settings.m_decimation) ) -1; -} - quint64 RTLSDRInput::getCenterFrequency() const { return m_generalSettings.m_centerFrequency; diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.h b/plugins/samplesource/rtlsdr/rtlsdrinput.h index bad62c221..d171af1ad 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.h +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.h @@ -87,7 +87,6 @@ public: const QString& getDeviceDescription() const; int getSampleRate() const; - int wfdecimation() const; quint64 getCenterFrequency() const; bool handleMessage(Message* message); diff --git a/plugins/samplesource/rtlsdr/rtlsdrthread.cpp b/plugins/samplesource/rtlsdr/rtlsdrthread.cpp index 963903989..ec5a60873 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrthread.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrthread.cpp @@ -74,66 +74,6 @@ void RTLSDRThread::run() m_running = false; } -#if 0 - -void RTLSDRThread::decimate2(SampleVector::iterator* it, const quint8* buf, qint32 len) -{ - for(int pos = 0; pos < len; pos += 2) { - Sample s((((qint8)buf[pos]) - 128) << 8, (((qint8)buf[pos + 1]) - 128) << 8); - if(m_decimator2.workDecimateCenter(&s)) { - **it = s; - ++(*it); - } - } -} - -void RTLSDRThread::decimate4(SampleVector::iterator* it, const quint8* buf, qint32 len) -{ - for(int pos = 0; pos < len; pos += 2) { - Sample s((((qint8)buf[pos]) - 128) << 8, (((qint8)buf[pos + 1]) - 128) << 8); - if(m_decimator2.workDecimateCenter(&s)) { - if(m_decimator4.workDecimateCenter(&s)) { - **it = s; - ++(*it); - } - } - } -} - -void RTLSDRThread::decimate8(SampleVector::iterator* it, const quint8* buf, qint32 len) -{ - for(int pos = 0; pos < len; pos += 2) { - Sample s((((qint8)buf[pos]) - 128) << 8, (((qint8)buf[pos + 1]) - 128) << 8); - if(m_decimator2.workDecimateCenter(&s)) { - if(m_decimator4.workDecimateCenter(&s)) { - if(m_decimator8.workDecimateCenter(&s)) { - **it = s; - ++(*it); - } - } - } - } -} - -void RTLSDRThread::decimate16(SampleVector::iterator* it, const quint8* buf, qint32 len) -{ - for(int pos = 0; pos < len; pos += 2) { - Sample s((((qint8)buf[pos]) - 128) << 8, (((qint8)buf[pos + 1]) - 128) << 8); - if(m_decimator2.workDecimateCenter(&s)) { - if(m_decimator4.workDecimateCenter(&s)) { - if(m_decimator8.workDecimateCenter(&s)) { - if(m_decimator16.workDecimateCenter(&s)) { - **it = s; - ++(*it); - } - } - } - } - } -} - -#else - void RTLSDRThread::decimate2(SampleVector::iterator* it, const quint8* buf, qint32 len) { qint16 xreal, yimag; @@ -194,13 +134,16 @@ void RTLSDRThread::decimate16(SampleVector::iterator* it, const quint8* buf, qin (*it)++; } } -#endif +int localdecimation = 0; void RTLSDRThread::callback(const quint8* buf, qint32 len) { qint16 xreal, yimag, phase; SampleVector::iterator it = m_convertBuffer.begin(); + if (++localdecimation < (1 << (4 - m_decimation))) return; + localdecimation = 0; + switch(m_decimation) { case 0: // 1:1 = no decimation // just rotation @@ -210,7 +153,7 @@ void RTLSDRThread::callback(const quint8* buf, qint32 len) xreal = phase * (buf[pos+0] - 127); yimag = phase * (buf[pos+1] - 127); *it++ = Sample( xreal<<7,yimag<<7); - xreal = phase * (128 - buf[pos+3]); + xreal = phase * (127 - buf[pos+3]); yimag = phase * (buf[pos+2] - 127); *it++ = Sample( xreal<<7,yimag<<7); } diff --git a/plugins/samplesource/rtlsdr/rtlsdrthread.h b/plugins/samplesource/rtlsdr/rtlsdrthread.h index 08837effa..e2e4f042c 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrthread.h +++ b/plugins/samplesource/rtlsdr/rtlsdrthread.h @@ -48,11 +48,6 @@ private: int m_decimation; - IntHalfbandFilter m_decimator2; - IntHalfbandFilter m_decimator4; - IntHalfbandFilter m_decimator8; - IntHalfbandFilter m_decimator16; - void run(); void decimate2(SampleVector::iterator* it, const quint8* buf, qint32 len); diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index f254763ce..1ed675397 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -196,7 +196,6 @@ void DSPEngine::imbalance(SampleVector::iterator begin, SampleVector::iterator e it->m_imag = (it->m_imag * m_imbalance) >> 16; } -int drop_frame = 0; void DSPEngine::work() { SampleFifo* sampleFifo = m_sampleSource->getSampleFifo(); @@ -211,12 +210,6 @@ void DSPEngine::work() size_t count = sampleFifo->readBegin(sampleFifo->fill(), &part1begin, &part1end, &part2begin, &part2end); - if (m_sampleSource->wfdecimation() & drop_frame++) { - sampleFifo->readCommit(count); - samplesDone += count; - continue; - } - // first part of FIFO data if(part1begin != part1end) { // correct stuff