From 7ea41283e815a824add3ff22964849c239313013 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 9 May 2015 16:44:26 +0200 Subject: [PATCH] Added basic variable decimation --- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 9 ++++ plugins/samplesource/rtlsdr/rtlsdrgui.h | 1 + plugins/samplesource/rtlsdr/rtlsdrgui.ui | 53 ++++++++++++++++++++ plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 22 +++++++- plugins/samplesource/rtlsdr/rtlsdrinput.h | 1 + plugins/samplesource/rtlsdr/rtlsdrthread.cpp | 46 +++++++++++++++-- plugins/samplesource/rtlsdr/rtlsdrthread.h | 3 ++ 7 files changed, 131 insertions(+), 4 deletions(-) diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index 5fd10cf60..b19455be4 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -129,6 +129,15 @@ void RTLSDRGui::on_centerFrequency_changed(quint64 value) sendSettings(); } +void RTLSDRGui::on_decim_valueChanged(int value) +{ + if ((value <0) || (value > 4)) + return; + ui->decimText->setText(tr("%1").arg(1< 99) || (value < -99)) diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index 5fe3ee225..7aa150443 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -44,6 +44,7 @@ private: private slots: void on_centerFrequency_changed(quint64 value); + void on_decim_valueChanged(int value); void on_ppm_valueChanged(int value); void on_gain_valueChanged(int value); void on_samplerate_valueChanged(int value); diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.ui b/plugins/samplesource/rtlsdr/rtlsdrgui.ui index 182db9797..505d52685 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.ui +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.ui @@ -261,6 +261,59 @@ + + + + Qt::Horizontal + + + + + + + 3 + + + + + Dec. + + + + + + + 4 + + + 4 + + + 4 + + + Qt::Horizontal + + + + + + + + 40 + 0 + + + + 16 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index a1d6f1a71..aeb7a948c 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -36,6 +36,7 @@ void RTLSDRInput::Settings::resetToDefaults() m_gain = 0; m_samplerate = 1024000; m_loPpmCorrection = 0; + m_log2Decim = 4; } QByteArray RTLSDRInput::Settings::serialize() const @@ -44,6 +45,7 @@ QByteArray RTLSDRInput::Settings::serialize() const s.writeS32(1, m_gain); s.writeS32(2, m_samplerate); s.writeS32(3, m_loPpmCorrection); + s.writeU32(4, m_log2Decim); return s.final(); } @@ -60,6 +62,7 @@ bool RTLSDRInput::Settings::deserialize(const QByteArray& data) d.readS32(1, &m_gain, 0); //d.readS32(2, &m_samplerate, 0); d.readS32(3, &m_loPpmCorrection, 0); + d.readU32(4, &m_log2Decim, 4); return true; } else { resetToDefaults(); @@ -186,16 +189,26 @@ const QString& RTLSDRInput::getDeviceDescription() const int RTLSDRInput::getSampleRate() const { int rate = m_settings.m_samplerate; + return (rate / (1<setLog2Decimation(settings.m_log2Decim); + } + } + m_generalSettings.m_centerFrequency = generalSettings.m_centerFrequency; if(m_dev != NULL) { if(rtlsdr_set_center_freq( m_dev, m_generalSettings.m_centerFrequency diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.h b/plugins/samplesource/rtlsdr/rtlsdrinput.h index f3fdbc64e..1e5d84619 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.h +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.h @@ -30,6 +30,7 @@ public: qint32 m_gain; qint32 m_samplerate; qint32 m_loPpmCorrection; + quint32 m_log2Decim; Settings(); void resetToDefaults(); diff --git a/plugins/samplesource/rtlsdr/rtlsdrthread.cpp b/plugins/samplesource/rtlsdr/rtlsdrthread.cpp index 039abe6e4..3aefedc41 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrthread.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrthread.cpp @@ -28,7 +28,8 @@ RTLSDRThread::RTLSDRThread(rtlsdr_dev_t* dev, SampleFifo* sampleFifo, QObject* p m_dev(dev), m_convertBuffer(BLOCKSIZE), m_sampleFifo(sampleFifo), - m_samplerate(288000) + m_samplerate(288000), + m_log2Decim(4) { } @@ -57,6 +58,11 @@ void RTLSDRThread::setSamplerate(int samplerate) m_samplerate = samplerate; } +void RTLSDRThread::setLog2Decimation(unsigned int log2_decim) +{ + m_log2Decim = log2_decim; +} + void RTLSDRThread::run() { int res; @@ -74,6 +80,18 @@ void RTLSDRThread::run() m_running = false; } +void RTLSDRThread::decimate1(SampleVector::iterator* it, const quint8* buf, qint32 len) +{ + qint16 xreal, yimag; + for (int pos = 0; pos < len; pos += 2) { + xreal = buf[pos+0]; + yimag = buf[pos+1]; + Sample s( xreal << 3, yimag << 3 ); + **it = s; + (*it)++; + } +} + void RTLSDRThread::decimate2(SampleVector::iterator* it, const quint8* buf, qint32 len) { qint16 xreal, yimag; @@ -146,18 +164,40 @@ void RTLSDRThread::decimate16(SampleVector::iterator* it, const quint8* buf, qin -// Decimate everything by 16x, except 288kHz by 4x -// and 1152kHz, 2048kHz by 8x +// Decimate according to specified log2 (ex: log2=4 => decim=16) void RTLSDRThread::callback(const quint8* buf, qint32 len) { SampleVector::iterator it = m_convertBuffer.begin(); + switch (m_log2Decim) + { + case 0: + decimate1(&it, buf, len); + break; + case 1: + decimate2(&it, buf, len); + break; + case 2: + decimate4(&it, buf, len); + break; + case 3: + decimate8(&it, buf, len); + break; + case 4: + decimate16(&it, buf, len); + break; + default: + break; + } + + /* if (m_samplerate < 800000) decimate4(&it, buf, len); else if ((m_samplerate == 1152000)||(m_samplerate == 2048000)) decimate8(&it, buf, len); else decimate16(&it, buf, len); + */ m_sampleFifo->write(m_convertBuffer.begin(), it); diff --git a/plugins/samplesource/rtlsdr/rtlsdrthread.h b/plugins/samplesource/rtlsdr/rtlsdrthread.h index 48e5aeabd..fb5abc134 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrthread.h +++ b/plugins/samplesource/rtlsdr/rtlsdrthread.h @@ -35,6 +35,7 @@ public: void startWork(); void stopWork(); void setSamplerate(int samplerate); + void setLog2Decimation(unsigned int log2_decim); private: QMutex m_startWaitMutex; @@ -46,11 +47,13 @@ private: SampleFifo* m_sampleFifo; int m_samplerate; + unsigned int m_log2Decim; IntHalfbandFilter m_decimator2; IntHalfbandFilter m_decimator4; void run(); + void decimate1(SampleVector::iterator* it, const quint8* buf, qint32 len); void decimate2(SampleVector::iterator* it, const quint8* buf, qint32 len); void decimate4(SampleVector::iterator* it, const quint8* buf, qint32 len); void decimate8(SampleVector::iterator* it, const quint8* buf, qint32 len);