From 365154767a7c8d8e327b2b1c8d4800203f6e9838 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 2 Apr 2017 02:00:05 +0200 Subject: [PATCH] RTLSDR plugin: continuous sample rate setting --- devices/hackrf/devicehackrfvalues.cpp | 50 ---- devices/hackrf/devicehackrfvalues.h | 8 - .../hackrfoutput/hackrfoutputgui.ui | 4 +- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 65 ++--- plugins/samplesource/rtlsdr/rtlsdrgui.h | 12 +- plugins/samplesource/rtlsdr/rtlsdrgui.ui | 228 ++++++++++-------- plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 4 +- plugins/samplesource/rtlsdr/rtlsdrplugin.cpp | 2 +- .../samplesource/rtlsdr/rtlsdrsettings.cpp | 7 +- plugins/samplesource/rtlsdr/rtlsdrsettings.h | 1 + 10 files changed, 154 insertions(+), 227 deletions(-) diff --git a/devices/hackrf/devicehackrfvalues.cpp b/devices/hackrf/devicehackrfvalues.cpp index b15724554..b38cc6c2c 100644 --- a/devices/hackrf/devicehackrfvalues.cpp +++ b/devices/hackrf/devicehackrfvalues.cpp @@ -16,56 +16,6 @@ #include "devicehackrfvalues.h" -const unsigned int HackRFSampleRates::m_nb_rates = 22; -const unsigned int HackRFSampleRates::m_rates[HackRFSampleRates::m_nb_rates] = { - 2400000, - 2600000, - 3000000, - 3150000, // for PAL-M - 3200000, - 3250000, // For PAL-BGIL - 4000000, - 4333333, // for GSM - 4800000, - 5600000, - 6000000, - 6300000, // for PAL-M - 6400000, - 6500000, // For PAL-BGIL - 8000000, - 9600000, - 12000000, - 12800000, - 16000000, - 18000000, - 19200000, - 20000000}; - -unsigned int HackRFSampleRates::getRate(unsigned int rate_index) -{ - if (rate_index < m_nb_rates) - { - return m_rates[rate_index]; - } - else - { - return m_rates[0]; - } -} - -unsigned int HackRFSampleRates::getRateIndex(unsigned int rate) -{ - for (unsigned int i=0; i < m_nb_rates; i++) - { - if (rate == m_rates[i]) - { - return i; - } - } - - return 0; -} - const unsigned int HackRFBandwidths::m_nb_bw = 16; const unsigned int HackRFBandwidths::m_bw_k[HackRFBandwidths::m_nb_bw] = { 1750, diff --git a/devices/hackrf/devicehackrfvalues.h b/devices/hackrf/devicehackrfvalues.h index fca91c691..3059473c8 100644 --- a/devices/hackrf/devicehackrfvalues.h +++ b/devices/hackrf/devicehackrfvalues.h @@ -17,14 +17,6 @@ #ifndef DEVICES_HACKRF_DEVICEHACKRFVALUES_H_ #define DEVICES_HACKRF_DEVICEHACKRFVALUES_H_ -class HackRFSampleRates { -public: - static unsigned int getRate(unsigned int rate_index); - static unsigned int getRateIndex(unsigned int rate); - static const unsigned int m_nb_rates; - static const unsigned int m_rates[]; -}; - class HackRFBandwidths { public: static unsigned int getBandwidth(unsigned int bandwidth_index); diff --git a/plugins/samplesink/hackrfoutput/hackrfoutputgui.ui b/plugins/samplesink/hackrfoutput/hackrfoutputgui.ui index 0ab0ed1e5..bb1493889 100644 --- a/plugins/samplesink/hackrfoutput/hackrfoutputgui.ui +++ b/plugins/samplesink/hackrfoutput/hackrfoutputgui.ui @@ -7,7 +7,7 @@ 0 0 320 - 300 + 200 @@ -19,7 +19,7 @@ 320 - 300 + 200 diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index c0e727d8d..daa0dc2c2 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -40,12 +40,8 @@ RTLSDRGui::RTLSDRGui(DeviceSourceAPI *deviceAPI, QWidget* parent) : ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); ui->centerFrequency->setValueRange(7, 24000U, 1900000U); - ui->sampleRate->clear(); - - for (int i = 0; i < RTLSDRSampleRates::getNbRates(); i++) - { - ui->sampleRate->addItem(QString::number(RTLSDRSampleRates::getRate(i)/1000)); - } + ui->newSampleRate->setColorMapper(ColorMapper(ColorMapper::ReverseGreenYellow)); + ui->newSampleRate->setValueRange(7, 950000U, 2400000U); connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware())); connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); @@ -202,8 +198,6 @@ void RTLSDRGui::displaySettings() ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); ui->dcOffset->setChecked(m_settings.m_dcBlock); ui->iqImbalance->setChecked(m_settings.m_iqImbalance); - unsigned int sampleRateIndex = RTLSDRSampleRates::getRateIndex(m_settings.m_devSampleRate); - ui->sampleRate->setCurrentIndex(sampleRateIndex); ui->ppm->setValue(m_settings.m_loPpmCorrection); ui->ppmText->setText(tr("%1").arg(m_settings.m_loPpmCorrection)); ui->decim->setCurrentIndex(m_settings.m_log2Decim); @@ -305,10 +299,6 @@ void RTLSDRGui::on_gain_valueChanged(int value) void RTLSDRGui::on_sampleRate_currentIndexChanged(int index) { - int newrate = RTLSDRSampleRates::getRate(index); - m_settings.m_devSampleRate = newrate; - - sendSettings(); } void RTLSDRGui::on_startStop_toggled(bool checked) @@ -402,48 +392,21 @@ void RTLSDRGui::on_checkBox_stateChanged(int state) sendSettings(); } -const unsigned int RTLSDRSampleRates::m_nb_rates = 13; -const unsigned int RTLSDRSampleRates::m_rates[] = { - 250000, - 256000, - 1000000, - 1024000, - 1152000, - 1200000, - 1536000, - 1600000, - 2000000, - 2048000, - 2166667, // for GSM - 2304000, - 2400000}; - -unsigned int RTLSDRSampleRates::getRate(unsigned int rate_index) +void RTLSDRGui::on_newSampleRate_changed(quint64 value) { - if (rate_index < m_nb_rates) - { - return m_rates[rate_index]; - } - else - { - return m_rates[0]; - } + m_settings.m_devSampleRate = value; + sendSettings(); } -unsigned int RTLSDRSampleRates::getRateIndex(unsigned int rate) +void RTLSDRGui::on_lowSampleRate_toggled(bool checked) { - for (unsigned int i=0; i < m_nb_rates; i++) - { - if (rate == m_rates[i]) - { - return i; - } - } + if (checked) { + ui->newSampleRate->setValueRange(7, 230000U, 300000U); + } else { + ui->newSampleRate->setValueRange(7, 950000U, 2400000U); + } - return 0; -} - -unsigned int RTLSDRSampleRates::getNbRates() -{ - return RTLSDRSampleRates::m_nb_rates; + m_settings.m_devSampleRate = ui->newSampleRate->getValueNew(); + qDebug("RTLSDRGui::on_lowSampleRate_toggled: %d S/s", m_settings.m_devSampleRate); + sendSettings(); } diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.h b/plugins/samplesource/rtlsdr/rtlsdrgui.h index e7fa92f48..06313c2be 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -68,6 +68,8 @@ private: private slots: void handleDSPMessages(); void on_centerFrequency_changed(quint64 value); + void on_newSampleRate_changed(quint64 value); + void on_lowSampleRate_toggled(bool checked); void on_dcOffset_toggled(bool checked); void on_iqImbalance_toggled(bool checked); void on_decim_currentIndexChanged(int index); @@ -83,14 +85,4 @@ private slots: void handleSourceMessages(); }; -class RTLSDRSampleRates { -public: - static unsigned int getRate(unsigned int rate_index); - static unsigned int getRateIndex(unsigned int rate); - static unsigned int getNbRates(); -private: - static const unsigned int m_nb_rates; - static const unsigned int m_rates[]; -}; - #endif // INCLUDE_RTLSDRGUI_H diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.ui b/plugins/samplesource/rtlsdr/rtlsdrgui.ui index fd01039d9..d4d0bcd1d 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.ui +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.ui @@ -6,20 +6,20 @@ 0 0 - 300 - 190 + 320 + 220 - + 0 0 - 300 - 190 + 320 + 220 @@ -35,7 +35,16 @@ 3 - + + 2 + + + 2 + + + 2 + + 2 @@ -248,38 +257,7 @@ - - - - - - Qt::Horizontal - - - - - - - - - - 0 - 0 - - - - SR - - - - - - - k - - - - + @@ -310,47 +288,115 @@ - + Fp - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + + + + + Qt::Horizontal + + + + + + + 6 + + + 6 + + + 6 + + + 6 + + + - Sample rate in kS/s + Toggle low/high sample rate range + + + L + + + true - + + + + + 0 + 0 + + + + SR + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Monospace + 12 + + + + Device sample rate (S/s) + + + + + + + S/s + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Dec + + + + @@ -396,15 +442,22 @@ - - + + + + + + + + RTLSDR special direct sampling mode (HF Bands) + - Dec + No-mod Direct Sampling - - + + Qt::Horizontal @@ -480,33 +533,6 @@ - - - - - - RTLSDR special direct sampling mode (HF Bands) - - - No-mod Direct Sampling - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index cfd8b08d1..f4d35c217 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -329,8 +329,8 @@ bool RTLSDRInput::applySettings(const RTLSDRSettings& settings, bool force) { qDebug() << "RTLSDRInput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz" << " device center freq: " << deviceCenterFrequency << " Hz" - << " device sample rate: " << devSampleRate << "Hz" - << " Actual sample rate: " << devSampleRate/(1<