mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	Simplify interpolator.
This commit is contained in:
		
							parent
							
								
									ad68f6a06c
								
							
						
					
					
						commit
						a9c2c14221
					
				@ -17,17 +17,13 @@ public:
 | 
				
			|||||||
	void create(int phaseSteps, double sampleRate, double cutoff);
 | 
						void create(int phaseSteps, double sampleRate, double cutoff);
 | 
				
			||||||
	void free();
 | 
						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);
 | 
							advanceFilter(next);
 | 
				
			||||||
		*distance -= 1.0;
 | 
							*distance -= 1.0;
 | 
				
			||||||
				*consumed = true;
 | 
							if (*distance >= 1.0)
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		doInterpolate((int)floor(*distance * (Real)m_phaseSteps), result);
 | 
							doInterpolate((int)floor(*distance * (Real)m_phaseSteps), result);
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -60,15 +60,13 @@ int framedrop = 0;
 | 
				
			|||||||
void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
 | 
					void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Complex ci;
 | 
						Complex ci;
 | 
				
			||||||
	bool consumed;
 | 
					 | 
				
			||||||
	qint16 sample;
 | 
						qint16 sample;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
						for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
				
			||||||
		Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
							Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
				
			||||||
		c *= m_nco.nextIQ();
 | 
							c *= m_nco.nextIQ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		consumed = false;
 | 
							if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) {
 | 
				
			||||||
		if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) {
 | 
					 | 
				
			||||||
			if (++framedrop & 1) {
 | 
								if (++framedrop & 1) {
 | 
				
			||||||
				m_movingAverage.feed(ci.real() * ci.real() + ci.imag() * ci.imag());
 | 
									m_movingAverage.feed(ci.real() * ci.real() + ci.imag() * ci.imag());
 | 
				
			||||||
				if(m_movingAverage.average() >= m_squelchLevel)
 | 
									if(m_movingAverage.average() >= m_squelchLevel)
 | 
				
			||||||
 | 
				
			|||||||
@ -61,14 +61,12 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
 | 
				
			|||||||
	Complex ci;
 | 
						Complex ci;
 | 
				
			||||||
	cmplx *sideband;
 | 
						cmplx *sideband;
 | 
				
			||||||
	int n_out;
 | 
						int n_out;
 | 
				
			||||||
	bool consumed;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
						for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
				
			||||||
		Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
							Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
				
			||||||
		c *= m_nco.nextIQ();
 | 
							c *= m_nco.nextIQ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		consumed = false;
 | 
							if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) {
 | 
				
			||||||
		if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) {
 | 
					 | 
				
			||||||
			n_out = SSBFilter->run(ci, &sideband, m_usb);
 | 
								n_out = SSBFilter->run(ci, &sideband, m_usb);
 | 
				
			||||||
			m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0;
 | 
								m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0;
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
 | 
				
			|||||||
@ -13,8 +13,8 @@ TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* s
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	m_inputSampleRate = 100000;
 | 
						m_inputSampleRate = 100000;
 | 
				
			||||||
	m_sampleFormat = FormatS8;
 | 
						m_sampleFormat = FormatS8;
 | 
				
			||||||
	m_outputSampleRate = 50000;
 | 
						m_outputSampleRate = 48000;
 | 
				
			||||||
	m_rfBandwidth = 50000;
 | 
						m_rfBandwidth = 40000;
 | 
				
			||||||
	m_tcpPort = 9999;
 | 
						m_tcpPort = 9999;
 | 
				
			||||||
	m_nco.setFreq(0, m_inputSampleRate);
 | 
						m_nco.setFreq(0, m_inputSampleRate);
 | 
				
			||||||
	m_interpolator.create(16, m_inputSampleRate, m_rfBandwidth / 2.1);
 | 
						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)
 | 
					void TCPSrc::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Complex ci;
 | 
						Complex ci;
 | 
				
			||||||
	bool consumed;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
						for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
				
			||||||
		Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
							Complex c(it->real() / 32768.0, it->imag() / 32768.0);
 | 
				
			||||||
		c *= m_nco.nextIQ();
 | 
							c *= m_nco.nextIQ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		consumed = false;
 | 
							if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &ci)) {
 | 
				
			||||||
		if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) {
 | 
					 | 
				
			||||||
			m_sampleBuffer.push_back(Sample(ci.real() * 32768.0, ci.imag() * 32768.0));
 | 
								m_sampleBuffer.push_back(Sample(ci.real() * 32768.0, ci.imag() * 32768.0));
 | 
				
			||||||
			m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate;
 | 
								m_sampleDistanceRemain += m_inputSampleRate / m_outputSampleRate;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,6 @@ WFMDemod::WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
 | 
				
			|||||||
	m_sampleRate = 250000;
 | 
						m_sampleRate = 250000;
 | 
				
			||||||
	m_frequency = 0;
 | 
						m_frequency = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	m_nco.setFreq(m_frequency, m_sampleRate);
 | 
					 | 
				
			||||||
	m_interpolator.create(16, m_sampleRate, 16000);
 | 
						m_interpolator.create(16, m_sampleRate, 16000);
 | 
				
			||||||
	m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0;
 | 
						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)
 | 
					void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Complex ci;
 | 
					 | 
				
			||||||
	bool consumed;
 | 
					 | 
				
			||||||
	qint16 sample;
 | 
						qint16 sample;
 | 
				
			||||||
	Real demod;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(SampleVector::const_iterator it = begin; it < end; ++it) {
 | 
						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);
 | 
							Complex d = c * conj(m_lastSample);
 | 
				
			||||||
		m_lastSample = c;
 | 
							m_lastSample = c;
 | 
				
			||||||
		demod = atan2(d.imag(), d.real());
 | 
							Complex e(atan2(d.imag(), d.real()), 0);
 | 
				
			||||||
		Complex e(demod * 3000 / M_PI, 0);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		consumed = false;
 | 
							if(m_interpolator.interpolate(&m_sampleDistanceRemain, e, &c)) {
 | 
				
			||||||
		if(m_interpolator.interpolate(&m_sampleDistanceRemain, e, &consumed, &ci)) {
 | 
								sample = (qint16)(c.real() * m_volume * 800.0);
 | 
				
			||||||
			sample = (qint16)(ci.real() * m_volume);
 | 
					 | 
				
			||||||
			m_sampleBuffer.push_back(Sample(sample, sample));
 | 
								m_sampleBuffer.push_back(Sample(sample, sample));
 | 
				
			||||||
			m_audioBuffer[m_audioBufferFill].l = sample;
 | 
								m_audioBuffer[m_audioBufferFill].l = sample;
 | 
				
			||||||
			m_audioBuffer[m_audioBufferFill].r = 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);
 | 
										qDebug("lost %u samples", m_audioBufferFill - res);
 | 
				
			||||||
				m_audioBufferFill = 0;
 | 
									m_audioBufferFill = 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					 | 
				
			||||||
			m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0;
 | 
								m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,9 +20,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
#include "dsp/samplesink.h"
 | 
					#include "dsp/samplesink.h"
 | 
				
			||||||
#include "dsp/nco.h"
 | 
					 | 
				
			||||||
#include "dsp/interpolator.h"
 | 
					#include "dsp/interpolator.h"
 | 
				
			||||||
#include "dsp/lowpass.h"
 | 
					 | 
				
			||||||
#include "audio/audiofifo.h"
 | 
					#include "audio/audiofifo.h"
 | 
				
			||||||
#include "util/message.h"
 | 
					#include "util/message.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -75,7 +73,6 @@ private:
 | 
				
			|||||||
	int m_sampleRate;
 | 
						int m_sampleRate;
 | 
				
			||||||
	int m_frequency;
 | 
						int m_frequency;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	NCO m_nco;
 | 
					 | 
				
			||||||
	Interpolator m_interpolator;
 | 
						Interpolator m_interpolator;
 | 
				
			||||||
	Real m_sampleDistanceRemain;
 | 
						Real m_sampleDistanceRemain;
 | 
				
			||||||
	Complex m_lastSample;
 | 
						Complex m_lastSample;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user