1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-13 03:41:47 -05:00

Simplify interpolator.

This commit is contained in:
John Greb 2014-11-25 08:31:44 +00:00
parent ad68f6a06c
commit a9c2c14221
6 changed files with 15 additions and 36 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -20,9 +20,7 @@
#include <vector>
#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;