From a9c2c14221c261f3982f34a6b710c7d523e644bd Mon Sep 17 00:00:00 2001 From: John Greb Date: Tue, 25 Nov 2014 08:31:44 +0000 Subject: [PATCH] Simplify interpolator. --- include-gpl/dsp/interpolator.h | 16 ++++++---------- plugins/channel/nfm/nfmdemod.cpp | 4 +--- plugins/channel/ssb/ssbdemod.cpp | 4 +--- plugins/channel/tcpsrc/tcpsrc.cpp | 9 +++------ plugins/channel/wfm/wfmdemod.cpp | 15 ++++----------- plugins/channel/wfm/wfmdemod.h | 3 --- 6 files changed, 15 insertions(+), 36 deletions(-) diff --git a/include-gpl/dsp/interpolator.h b/include-gpl/dsp/interpolator.h index ae91062e2..1965f0e57 100644 --- a/include-gpl/dsp/interpolator.h +++ b/include-gpl/dsp/interpolator.h @@ -17,17 +17,13 @@ public: void create(int phaseSteps, double sampleRate, double cutoff); void free(); - bool interpolate(Real* distance, const Complex& next, bool* consumed, Complex* result) + // Original code allowed for upsampling, but was never used that way + bool interpolate(Real* distance, const Complex& next, Complex* result) { - while(*distance >= 1.0) { - if(!(*consumed)) { - advanceFilter(next); - *distance -= 1.0; - *consumed = true; - } else { - return false; - } - } + advanceFilter(next); + *distance -= 1.0; + if (*distance >= 1.0) + return false; doInterpolate((int)floor(*distance * (Real)m_phaseSteps), result); return true; } diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index 0d6510f14..167606f08 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -60,15 +60,13 @@ int framedrop = 0; void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { 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); c *= m_nco.nextIQ(); - consumed = false; - if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) { + if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) { if (++framedrop & 1) { m_movingAverage.feed(ci.real() * ci.real() + ci.imag() * ci.imag()); if(m_movingAverage.average() >= m_squelchLevel) diff --git a/plugins/channel/ssb/ssbdemod.cpp b/plugins/channel/ssb/ssbdemod.cpp index bbd9055e0..91d2721bd 100644 --- a/plugins/channel/ssb/ssbdemod.cpp +++ b/plugins/channel/ssb/ssbdemod.cpp @@ -61,14 +61,12 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter Complex ci; cmplx *sideband; int n_out; - bool consumed; for(SampleVector::const_iterator it = begin; it < end; ++it) { Complex c(it->real() / 32768.0, it->imag() / 32768.0); c *= m_nco.nextIQ(); - consumed = false; - if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) { + if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) { n_out = SSBFilter->run(ci, &sideband, m_usb); m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0; } else diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index c656bf56f..1a7bd2218 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -13,8 +13,8 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* s { m_inputSampleRate = 100000; m_sampleFormat = FormatS8; - m_outputSampleRate = 50000; - m_rfBandwidth = 50000; + m_outputSampleRate = 48000; + m_rfBandwidth = 40000; m_tcpPort = 9999; m_nco.setFreq(0, m_inputSampleRate); m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.1); @@ -46,14 +46,11 @@ void TCPSrc::setSpectrum(MessageQueue* messageQueue, bool enabled) void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; - bool consumed; - for(SampleVector::const_iterator it = begin; it < end; ++it) { Complex c(it->real() / 32768.0, it->imag() / 32768.0); c *= m_nco.nextIQ(); - consumed = false; - if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) { + if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) { m_sampleBuffer.push_back(Sample(ci.real() * 32768.0, ci.imag() * 32768.0)); m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate; } diff --git a/plugins/channel/wfm/wfmdemod.cpp b/plugins/channel/wfm/wfmdemod.cpp index 13bbe66c9..9440eab18 100644 --- a/plugins/channel/wfm/wfmdemod.cpp +++ b/plugins/channel/wfm/wfmdemod.cpp @@ -31,7 +31,6 @@ WFMDemod::WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : m_sampleRate = 250000; m_frequency = 0; - m_nco.setFreq(m_frequency, m_sampleRate); m_interpolator.create(16, m_sampleRate, 16000); m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0; @@ -51,21 +50,16 @@ void WFMDemod::configure(MessageQueue* messageQueue, Real afBandwidth, Real volu void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { - Complex ci; - bool consumed; qint16 sample; - Real demod; for(SampleVector::const_iterator it = begin; it < end; ++it) { - Complex c(it->real() , it->imag()); + Complex c(it->real(), it->imag()); Complex d = c * conj(m_lastSample); m_lastSample = c; - demod = atan2(d.imag(), d.real()); - Complex e(demod * 3000 / M_PI, 0); + Complex e(atan2(d.imag(), d.real()), 0); - consumed = false; - if(m_interpolator.interpolate(&m_sampleDistanceRemain, e, &consumed, &ci)) { - sample = (qint16)(ci.real() * m_volume); + if(m_interpolator.interpolate(&m_sampleDistanceRemain, e, &c)) { + sample = (qint16)(c.real() * m_volume * 800.0); m_sampleBuffer.push_back(Sample(sample, sample)); m_audioBuffer[m_audioBufferFill].l = sample; m_audioBuffer[m_audioBufferFill].r = sample; @@ -76,7 +70,6 @@ void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter qDebug("lost %u samples", m_audioBufferFill - res); m_audioBufferFill = 0; } - m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0; } } diff --git a/plugins/channel/wfm/wfmdemod.h b/plugins/channel/wfm/wfmdemod.h index e06c7c6fc..7772ac388 100644 --- a/plugins/channel/wfm/wfmdemod.h +++ b/plugins/channel/wfm/wfmdemod.h @@ -20,9 +20,7 @@ #include #include "dsp/samplesink.h" -#include "dsp/nco.h" #include "dsp/interpolator.h" -#include "dsp/lowpass.h" #include "audio/audiofifo.h" #include "util/message.h" @@ -75,7 +73,6 @@ private: int m_sampleRate; int m_frequency; - NCO m_nco; Interpolator m_interpolator; Real m_sampleDistanceRemain; Complex m_lastSample;