From 450a44036eee2c23da3784df83d1c51a0d101118 Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 8 Sep 2017 08:41:57 +0200 Subject: [PATCH] PlutoSDR input: fill sample FIFO only when convert buffer is full --- .../plutosdrinput/plutosdrinput.cpp | 22 ++++++--- .../plutosdrinput/plutosdrinputthread.cpp | 49 ++++++++++--------- .../plutosdrinput/plutosdrinputthread.h | 1 + 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp index c8520e4b7..e8f6be5ae 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinput.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinput.cpp @@ -26,7 +26,7 @@ #include "plutosdrinput.h" #include "plutosdrinputthread.h" -#define PLUTOSDR_BLOCKSIZE (1024*1024) //complex samples per buffer +#define PLUTOSDR_BLOCKSIZE (1024*1024) //complex samples per buffer (must be multiple of 64) MESSAGE_CLASS_DEFINITION(PlutoSDRInput::MsgFileRecord, Message) @@ -381,20 +381,21 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo } } + std::vector params; + bool paramsToSet = false; + if ((m_settings.m_LOppmTenths != settings.m_LOppmTenths) || force) { int64_t newXO = plutoBox->getInitialXO() + ((plutoBox->getInitialXO()*settings.m_LOppmTenths) / 10000000L); - std::vector params; params.push_back(QString(tr("xo_correction=%1").arg(newXO)).toStdString()); - plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); + paramsToSet = true; } if ((m_settings.m_centerFrequency != settings.m_centerFrequency) || force) { std::vector params; params.push_back(QString(tr("out_altvoltage0_RX_LO_frequency=%1").arg(settings.m_centerFrequency)).toStdString()); - plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); - + paramsToSet = true; forwardChangeOwnDSP = true; } @@ -402,7 +403,7 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo { std::vector params; params.push_back(QString(tr("in_voltage_rf_bandwidth=%1").arg(settings.m_lpfBW)).toStdString()); - plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); + paramsToSet = true; } if ((m_settings.m_antennaPath != settings.m_antennaPath) || force) @@ -411,7 +412,7 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo QString rfPortStr; PlutoSDRInputSettings::translateRFPath(settings.m_antennaPath, rfPortStr); params.push_back(QString(tr("in_voltage0_rf_port_select=%1").arg(rfPortStr)).toStdString()); - plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); + paramsToSet = true; } if ((m_settings.m_gainMode != settings.m_gainMode) || force) @@ -420,13 +421,18 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo QString gainModeStr; PlutoSDRInputSettings::translateGainMode(settings.m_gainMode, gainModeStr); params.push_back(QString(tr("in_voltage0_gain_control_mode=%1").arg(gainModeStr)).toStdString()); - plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); + paramsToSet = true; } if ((m_settings.m_gain != settings.m_gain) || force) { std::vector params; params.push_back(QString(tr("in_voltage0_hardwaregain=%1").arg(settings.m_gain)).toStdString()); + paramsToSet = true; + } + + if (paramsToSet) + { plutoBox->set_params(DevicePlutoSDRBox::DEVICE_PHY, params); } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp b/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp index 039908bc4..274e14198 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp +++ b/plugins/samplesource/plutosdrinput/plutosdrinputthread.cpp @@ -25,6 +25,7 @@ PlutoSDRInputThread::PlutoSDRInputThread(uint32_t blocksize, DevicePlutoSDRBox* m_blockSize(blocksize), m_convertBuffer(blocksize), m_sampleFifo(sampleFifo), + m_convertIt(m_convertBuffer.begin()), m_log2Decim(0), m_fcPos(PlutoSDRInputSettings::FC_POS_CENTER) { @@ -110,11 +111,9 @@ void PlutoSDRInputThread::run() // Decimate according to specified log2 (ex: log2=4 => decim=16) void PlutoSDRInputThread::convert(const qint16* buf, qint32 len) { - SampleVector::iterator it = m_convertBuffer.begin(); - if (m_log2Decim == 0) { - m_decimators.decimate1(&it, buf, len); + m_decimators.decimate1(&m_convertIt, buf, len); } else { @@ -123,22 +122,22 @@ void PlutoSDRInputThread::convert(const qint16* buf, qint32 len) switch (m_log2Decim) { case 1: - m_decimators.decimate2_inf(&it, buf, len); + m_decimators.decimate2_inf(&m_convertIt, buf, len); break; case 2: - m_decimators.decimate4_inf(&it, buf, len); + m_decimators.decimate4_inf(&m_convertIt, buf, len); break; case 3: - m_decimators.decimate8_inf(&it, buf, len); + m_decimators.decimate8_inf(&m_convertIt, buf, len); break; case 4: - m_decimators.decimate16_inf(&it, buf, len); + m_decimators.decimate16_inf(&m_convertIt, buf, len); break; case 5: - m_decimators.decimate32_inf(&it, buf, len); + m_decimators.decimate32_inf(&m_convertIt, buf, len); break; case 6: - m_decimators.decimate64_inf(&it, buf, len); + m_decimators.decimate64_inf(&m_convertIt, buf, len); break; default: break; @@ -149,22 +148,22 @@ void PlutoSDRInputThread::convert(const qint16* buf, qint32 len) switch (m_log2Decim) { case 1: - m_decimators.decimate2_sup(&it, buf, len); + m_decimators.decimate2_sup(&m_convertIt, buf, len); break; case 2: - m_decimators.decimate4_sup(&it, buf, len); + m_decimators.decimate4_sup(&m_convertIt, buf, len); break; case 3: - m_decimators.decimate8_sup(&it, buf, len); + m_decimators.decimate8_sup(&m_convertIt, buf, len); break; case 4: - m_decimators.decimate16_sup(&it, buf, len); + m_decimators.decimate16_sup(&m_convertIt, buf, len); break; case 5: - m_decimators.decimate32_sup(&it, buf, len); + m_decimators.decimate32_sup(&m_convertIt, buf, len); break; case 6: - m_decimators.decimate64_sup(&it, buf, len); + m_decimators.decimate64_sup(&m_convertIt, buf, len); break; default: break; @@ -175,22 +174,22 @@ void PlutoSDRInputThread::convert(const qint16* buf, qint32 len) switch (m_log2Decim) { case 1: - m_decimators.decimate2_cen(&it, buf, len); + m_decimators.decimate2_cen(&m_convertIt, buf, len); break; case 2: - m_decimators.decimate4_cen(&it, buf, len); + m_decimators.decimate4_cen(&m_convertIt, buf, len); break; case 3: - m_decimators.decimate8_cen(&it, buf, len); + m_decimators.decimate8_cen(&m_convertIt, buf, len); break; case 4: - m_decimators.decimate16_cen(&it, buf, len); + m_decimators.decimate16_cen(&m_convertIt, buf, len); break; case 5: - m_decimators.decimate32_cen(&it, buf, len); + m_decimators.decimate32_cen(&m_convertIt, buf, len); break; case 6: - m_decimators.decimate64_cen(&it, buf, len); + m_decimators.decimate64_cen(&m_convertIt, buf, len); break; default: break; @@ -198,6 +197,12 @@ void PlutoSDRInputThread::convert(const qint16* buf, qint32 len) } } - m_sampleFifo->write(m_convertBuffer.begin(), it); + ++m_convertIt; + + if (m_convertIt == m_convertBuffer.end()) + { + m_sampleFifo->write(m_convertBuffer.begin(), m_convertBuffer.end()); + m_convertIt = m_convertBuffer.begin(); + } } diff --git a/plugins/samplesource/plutosdrinput/plutosdrinputthread.h b/plugins/samplesource/plutosdrinput/plutosdrinputthread.h index 29d59747a..0f3fc5662 100644 --- a/plugins/samplesource/plutosdrinput/plutosdrinputthread.h +++ b/plugins/samplesource/plutosdrinput/plutosdrinputthread.h @@ -52,6 +52,7 @@ private: uint32_t m_blockSize; SampleVector m_convertBuffer; SampleSinkFifo* m_sampleFifo; + SampleVector::iterator m_convertIt; unsigned int m_log2Decim; // soft decimation int m_fcPos;