From 6978a90d434b3691428e60806a6f3201c324e5a9 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 7 Apr 2019 02:06:05 +0200 Subject: [PATCH] RTL-SDR: implemented baseband or device sample rate input option --- plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 79 ++++++++++++++++++++--- plugins/samplesource/rtlsdr/rtlsdrgui.h | 3 + plugins/samplesource/rtlsdr/rtlsdrgui.ui | 27 ++++++-- 3 files changed, 93 insertions(+), 16 deletions(-) diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index a241e55c9..63a680f11 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -39,6 +39,7 @@ RTLSDRGui::RTLSDRGui(DeviceUISet *deviceUISet, QWidget* parent) : m_doApplySettings(true), m_forceSettings(true), m_settings(), + m_sampleRateMode(true), m_sampleSource(0), m_lastEngineState(DSPDeviceSourceEngine::StNotStarted) { @@ -49,7 +50,6 @@ RTLSDRGui::RTLSDRGui(DeviceUISet *deviceUISet, QWidget* parent) : updateFrequencyLimits(); ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow)); - ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin, RTLSDRInput::sampleRateHighRangeMax); ui->rfBW->setColorMapper(ColorMapper(ColorMapper::GrayYellow)); ui->rfBW->setValueRange(4, 350, 8000); @@ -202,7 +202,7 @@ void RTLSDRGui::updateSampleRateAndFrequency() { m_deviceUISet->getSpectrum()->setSampleRate(m_sampleRate); m_deviceUISet->getSpectrum()->setCenterFrequency(m_deviceCenterFrequency); - ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_sampleRate / 1000.0f, 'g', 5))); + displaySampleRate(); } void RTLSDRGui::updateFrequencyLimits() @@ -249,13 +249,53 @@ void RTLSDRGui::displayGains() } } +void RTLSDRGui::displaySampleRate() +{ + ui->sampleRateMode->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); + ui->sampleRate->blockSignals(true); + + if (m_sampleRateMode) + { + ui->sampleRateMode->setText("SR"); + + if (m_settings.m_lowSampleRate) { + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateLowRangeMin, RTLSDRInput::sampleRateLowRangeMax); + } else { + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin, RTLSDRInput::sampleRateHighRangeMax); + } + + ui->sampleRate->setValue(m_settings.m_devSampleRate); + ui->sampleRate->setToolTip("Device to host sample rate (S/s)"); + ui->deviceRateText->setToolTip("Baseband sample rate (S/s)"); + uint32_t basebandSampleRate = m_settings.m_devSampleRate/(1<deviceRateText->setText(tr("%1k").arg(QString::number(basebandSampleRate / 1000.0f, 'g', 5))); + } + else + { + ui->sampleRateMode->setText("BB"); + + if (m_settings.m_lowSampleRate) { + ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateLowRangeMin/(1<sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin/(1<sampleRate->setValue(m_settings.m_devSampleRate/(1<sampleRate->setToolTip("Baseband sample rate (S/s)"); + ui->deviceRateText->setToolTip("Device to host sample rate (S/s)"); + ui->deviceRateText->setText(tr("%1k").arg(QString::number(m_settings.m_devSampleRate / 1000.0f, 'g', 5))); + } + + ui->sampleRate->blockSignals(false); +} + void RTLSDRGui::displaySettings() { ui->transverter->setDeltaFrequency(m_settings.m_transverterDeltaFrequency); ui->transverter->setDeltaFrequencyActive(m_settings.m_transverterMode); updateFrequencyLimits(); ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000); - ui->sampleRate->setValue(m_settings.m_devSampleRate); + displaySampleRate(); ui->rfBW->setValue(m_settings.m_rfBandwidth / 1000); ui->dcOffset->setChecked(m_settings.m_dcBlock); ui->iqImbalance->setChecked(m_settings.m_iqImbalance); @@ -285,12 +325,18 @@ void RTLSDRGui::on_centerFrequency_changed(quint64 value) void RTLSDRGui::on_decim_currentIndexChanged(int index) { - if ((index <0) || (index > 6)) - { + if ((index <0) || (index > 6)) { return; } m_settings.m_log2Decim = index; + displaySampleRate(); + + if (m_sampleRateMode) { + m_settings.m_devSampleRate = ui->sampleRate->getValueNew(); + } else { + m_settings.m_devSampleRate = ui->sampleRate->getValueNew() * (1 << m_settings.m_log2Decim); + } sendSettings(); } @@ -367,6 +413,12 @@ void RTLSDRGui::on_transverter_clicked() sendSettings(); } +void RTLSDRGui::on_sampleRateMode_toggled(bool checked) +{ + m_sampleRateMode = checked; + displaySampleRate(); +} + void RTLSDRGui::updateHardware() { if (m_doApplySettings) @@ -443,7 +495,12 @@ void RTLSDRGui::on_agc_stateChanged(int state) void RTLSDRGui::on_sampleRate_changed(quint64 value) { - m_settings.m_devSampleRate = value; + if (m_sampleRateMode) { + m_settings.m_devSampleRate = value; + } else { + m_settings.m_devSampleRate = value * (1 << m_settings.m_log2Decim); + } + sendSettings(); } @@ -463,14 +520,16 @@ void RTLSDRGui::on_lowSampleRate_toggled(bool checked) { m_settings.m_lowSampleRate = checked; - if (m_settings.m_lowSampleRate) { - ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateLowRangeMin, RTLSDRInput::sampleRateLowRangeMax); + displaySampleRate(); + + if (m_sampleRateMode) { + m_settings.m_devSampleRate = ui->sampleRate->getValueNew(); } else { - ui->sampleRate->setValueRange(7, RTLSDRInput::sampleRateHighRangeMin, RTLSDRInput::sampleRateHighRangeMax); + m_settings.m_devSampleRate = ui->sampleRate->getValueNew() * (1 << m_settings.m_log2Decim); } - m_settings.m_devSampleRate = ui->sampleRate->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 75c5360c8..568980d7a 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.h +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.h @@ -58,6 +58,7 @@ private: bool m_doApplySettings; bool m_forceSettings; RTLSDRSettings m_settings; + bool m_sampleRateMode; //!< true: device, false: base band sample rate update mode QTimer m_updateTimer; QTimer m_statusTimer; std::vector m_gains; @@ -68,6 +69,7 @@ private: MessageQueue m_inputMessageQueue; void displayGains(); + void displaySampleRate(); void displaySettings(); void sendSettings(); void updateSampleRateAndFrequency(); @@ -92,6 +94,7 @@ private slots: void on_startStop_toggled(bool checked); void on_record_toggled(bool checked); void on_transverter_clicked(); + void on_sampleRateMode_toggled(bool checked); void openDeviceSettingsDialog(const QPoint& p); void updateHardware(); void updateStatus(); diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.ui b/plugins/samplesource/rtlsdr/rtlsdrgui.ui index dcf3a8a25..fd218e1b9 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.ui +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.ui @@ -348,16 +348,31 @@ - - - - 0 - 0 - + + + + 26 + 0 + + + + + 26 + 16777215 + + + + Toggle between device to host and base band sample rate input SR + + true + + + true +