diff --git a/plugins/samplesource/usrpinput/readme.md b/plugins/samplesource/usrpinput/readme.md index 616c2a38c..e25e53804 100644 --- a/plugins/samplesource/usrpinput/readme.md +++ b/plugins/samplesource/usrpinput/readme.md @@ -101,6 +101,13 @@ Use this toggle button to switch the sample rate input next (8) between host to The I/Q stream from the USRP device can be decimated by a power of two by software inside the plugin before being sent to the baseband. Possible values are increasing powers of two: 1 (no decimation), 2, 4, 8, 16, 32. +

9A: Sample format

+ +The format of the samples from the device to the host, over USB or Ethernet: 16b (16 bits, the default) or 8b (8 bits). 8 bits halves the traffic, +which avoids overruns (16) at high sample rates. +It costs dynamic range (about 48 dB rather than 96), which is plenty for most digital signals, but set the gain so the signal is well above the noise, +and not much below full scale. +

10: Gain Mode

Choose between automatic or manual gain control. diff --git a/plugins/samplesource/usrpinput/usrpinput.cpp b/plugins/samplesource/usrpinput/usrpinput.cpp index e279fc124..c928c87df 100644 --- a/plugins/samplesource/usrpinput/usrpinput.cpp +++ b/plugins/samplesource/usrpinput/usrpinput.cpp @@ -465,8 +465,9 @@ bool USRPInput::acquireChannel(const USRPInputSettings& settings) } // set up the stream - std::string cpu_format("sc16"); - std::string wire_format("sc16"); + const bool sc8 = settings.m_wireFormat == 1; + std::string cpu_format(sc8 ? "sc8" : "sc16"); + std::string wire_format(sc8 ? "sc8" : "sc16"); std::vector channel_nums; channel_nums.push_back(m_deviceShared.m_channel); @@ -578,7 +579,7 @@ bool USRPInput::start() { QMutexLocker threadLocker(&m_threadMutex); - thread->setStream(m_streamId, m_bufSamples); + thread->setStream(m_streamId, m_bufSamples, settings.m_wireFormat == 1); } thread->setLog2Decimation(settings.m_log2SoftDecim); @@ -1086,6 +1087,15 @@ bool USRPInput::applySettings(const USRPInputSettings& settings, const QListgetLog2SoftDecim(), 6); } + if (deviceSettingsKeys.contains("wireFormat")) { + settings.m_wireFormat = response.getUsrpInputSettings()->getWireFormat() == 1 ? 1 : 0; + } if (deviceSettingsKeys.contains("lpfBW")) { settings.m_lpfBW = response.getUsrpInputSettings()->getLpfBw(); } @@ -1437,6 +1456,7 @@ void USRPInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& respo response.getUsrpInputSettings()->setGainMode((int) settings.m_gainMode); response.getUsrpInputSettings()->setIqCorrection(settings.m_iqCorrection ? 1 : 0); response.getUsrpInputSettings()->setLog2SoftDecim(settings.m_log2SoftDecim); + response.getUsrpInputSettings()->setWireFormat(settings.m_wireFormat); response.getUsrpInputSettings()->setLpfBw(settings.m_lpfBW); response.getUsrpInputSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency); response.getUsrpInputSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0); @@ -1558,6 +1578,9 @@ void USRPInput::webapiReverseSendSettings(const QList& deviceSettingsKe if (deviceSettingsKeys.contains("log2SoftDecim") || force) { swgUsrpInputSettings->setLog2SoftDecim(settings.m_log2SoftDecim); } + if (deviceSettingsKeys.contains("wireFormat") || force) { + swgUsrpInputSettings->setWireFormat(settings.m_wireFormat); + } if (deviceSettingsKeys.contains("lpfBW") || force) { swgUsrpInputSettings->setLpfBw(settings.m_lpfBW); } diff --git a/plugins/samplesource/usrpinput/usrpinputgui.cpp b/plugins/samplesource/usrpinput/usrpinputgui.cpp index 4f912c86a..de004af3c 100644 --- a/plugins/samplesource/usrpinput/usrpinputgui.cpp +++ b/plugins/samplesource/usrpinput/usrpinputgui.cpp @@ -424,6 +424,7 @@ void USRPInputGUI::displaySettings() ui->iqImbalance->setChecked(m_settings.m_iqCorrection); ui->swDecim->setCurrentIndex(m_settings.m_log2SoftDecim); + ui->wireFormat->setCurrentIndex(m_settings.m_wireFormat); updateSampleRate(); @@ -590,6 +591,13 @@ void USRPInputGUI::on_sampleRate_changed(quint64 value) sendSettings(); } +void USRPInputGUI::on_wireFormat_currentIndexChanged(int index) +{ + m_settings.m_wireFormat = index == 1 ? 1 : 0; + m_settingsKeys.append("wireFormat"); + sendSettings(); +} + void USRPInputGUI::on_swDecim_currentIndexChanged(int index) { if ((index <0) || (index > 6)) { @@ -827,6 +835,7 @@ void USRPInputGUI::makeUIConnections() QObject::connect(ui->iqImbalance, &ButtonSwitch::toggled, this, &USRPInputGUI::on_iqImbalance_toggled); QObject::connect(ui->sampleRate, &ValueDial::changed, this, &USRPInputGUI::on_sampleRate_changed); QObject::connect(ui->swDecim, QOverload::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_swDecim_currentIndexChanged); + QObject::connect(ui->wireFormat, QOverload::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_wireFormat_currentIndexChanged); QObject::connect(ui->lpf, &ValueDial::changed, this, &USRPInputGUI::on_lpf_changed); QObject::connect(ui->loOffset, &ValueDialZ::changed, this, &USRPInputGUI::on_loOffset_changed); QObject::connect(ui->gainMode, QOverload::of(&QComboBox::currentIndexChanged), this, &USRPInputGUI::on_gainMode_currentIndexChanged); diff --git a/plugins/samplesource/usrpinput/usrpinputgui.h b/plugins/samplesource/usrpinput/usrpinputgui.h index d3e5166fd..e2a268cbf 100644 --- a/plugins/samplesource/usrpinput/usrpinputgui.h +++ b/plugins/samplesource/usrpinput/usrpinputgui.h @@ -96,6 +96,7 @@ private slots: void on_iqImbalance_toggled(bool checked); void on_sampleRate_changed(quint64 value); void on_swDecim_currentIndexChanged(int index); + void on_wireFormat_currentIndexChanged(int index); void on_lpf_changed(quint64 value); void on_loOffset_changed(qint64 value); void on_gainMode_currentIndexChanged(int index); diff --git a/plugins/samplesource/usrpinput/usrpinputgui.ui b/plugins/samplesource/usrpinput/usrpinputgui.ui index 4907d46a7..a81eafb76 100644 --- a/plugins/samplesource/usrpinput/usrpinputgui.ui +++ b/plugins/samplesource/usrpinput/usrpinputgui.ui @@ -451,6 +451,32 @@ + + + + + 50 + 16777215 + + + + Sample format over USB or Ethernet: 16 or 8 bits. 8 bits halves the traffic, which avoids overruns at high sample rates, at the cost of dynamic range + + + 0 + + + + 16b + + + + + 8b + + + + diff --git a/plugins/samplesource/usrpinput/usrpinputsettings.cpp b/plugins/samplesource/usrpinput/usrpinputsettings.cpp index 1439b0153..b45b1de48 100644 --- a/plugins/samplesource/usrpinput/usrpinputsettings.cpp +++ b/plugins/samplesource/usrpinput/usrpinputsettings.cpp @@ -36,6 +36,7 @@ void USRPInputSettings::resetToDefaults() m_dcBlock = false; m_iqCorrection = false; m_log2SoftDecim = 0; + m_wireFormat = 0; m_lpfBW = 10e6f; m_gain = 50; m_antennaPath = "TX/RX"; @@ -82,6 +83,7 @@ QByteArray USRPInputSettings::serialize() const s.writeU32(21, m_gpioDir); s.writeU32(22, m_gpioPins); s.writeString(23, m_title); + s.writeS32(24, m_wireFormat); return s.final(); } @@ -136,6 +138,8 @@ bool USRPInputSettings::deserialize(const QByteArray& data) d.readU32(22, &uintval, 0); m_gpioPins = uintval & 0xFF; d.readString(23, &m_title, "USRP"); + d.readS32(24, &m_wireFormat, 0); + m_wireFormat = m_wireFormat == 1 ? 1 : 0; return true; } @@ -173,6 +177,9 @@ void USRPInputSettings::applySettings(const QStringList& settingsKeys, const USR if (settingsKeys.contains("log2SoftDecim")) { m_log2SoftDecim = settings.m_log2SoftDecim; } + if (settingsKeys.contains("wireFormat")) { + m_wireFormat = settings.m_wireFormat; + } if (settingsKeys.contains("lpfBW")) { m_lpfBW = settings.m_lpfBW; } @@ -254,6 +261,9 @@ QString USRPInputSettings::getDebugString(const QStringList& settingsKeys, bool if (settingsKeys.contains("log2SoftDecim") || force) { ostr << " m_log2SoftDecim: " << m_log2SoftDecim; } + if (settingsKeys.contains("wireFormat") || force) { + ostr << " m_wireFormat: " << m_wireFormat; + } if (settingsKeys.contains("lpfBW") || force) { ostr << " m_lpfBW: " << m_lpfBW; } diff --git a/plugins/samplesource/usrpinput/usrpinputsettings.h b/plugins/samplesource/usrpinput/usrpinputsettings.h index f558c89c6..28bbb2d47 100644 --- a/plugins/samplesource/usrpinput/usrpinputsettings.h +++ b/plugins/samplesource/usrpinput/usrpinputsettings.h @@ -46,6 +46,7 @@ struct USRPInputSettings bool m_dcBlock; bool m_iqCorrection; uint32_t m_log2SoftDecim; + int m_wireFormat; //!< Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8, half the traffic) float m_lpfBW; //!< Analog lowpass filter bandwidth (Hz) uint32_t m_gain; //!< Optimally distributed gain (dB) QString m_antennaPath; diff --git a/plugins/samplesource/usrpinput/usrpinputthread.cpp b/plugins/samplesource/usrpinput/usrpinputthread.cpp index 7a80c1f5a..085ad735d 100644 --- a/plugins/samplesource/usrpinput/usrpinputthread.cpp +++ b/plugins/samplesource/usrpinput/usrpinputthread.cpp @@ -39,6 +39,7 @@ USRPInputThread::USRPInputThread(DeviceUSRPParams *deviceParams, int channel, Sa m_overflows(0), m_timeouts(0), m_buf(nullptr), + m_buf8(nullptr), m_bufSamples(0), m_sampleFifo(sampleFifo), m_replayBuffer(replayBuffer), @@ -57,18 +58,21 @@ USRPInputThread::~USRPInputThread() { stopWork(); delete[] m_buf; + delete[] m_buf8; } // Set stream once it has been created. Must be called before startWork() -void USRPInputThread::setStream(uhd::rx_streamer::sptr stream, size_t bufSamples) +void USRPInputThread::setStream(uhd::rx_streamer::sptr stream, size_t bufSamples, bool sc8) { m_stream = stream; m_bufSamples = bufSamples; m_convertBuffer.resize(bufSamples); delete[] m_buf; + delete[] m_buf8; // *2 as samples are I+Q m_buf = new qint16[2*bufSamples]; std::fill(m_buf, m_buf + 2*bufSamples, 0); + m_buf8 = sc8 ? new qint8[2*bufSamples] : nullptr; } void USRPInputThread::issueStreamCmd(bool start) @@ -181,7 +185,7 @@ void USRPInputThread::stopWork() size_t USRPInputThread::recv(uhd::rx_metadata_t& md, double timeout) { if (!m_deviceParams) { - return m_stream->recv(m_buf, m_bufSamples, md, timeout); + return m_stream->recv(m_buf8 ? (void *) m_buf8 : (void *) m_buf, m_bufSamples, md, timeout); } // Only wait for a short time while holding the lock, so if our stream isn't receiving data @@ -197,7 +201,7 @@ size_t USRPInputThread::recv(uhd::rx_metadata_t& md, double timeout) { std::lock_guard recvLock(m_deviceParams->m_recvLock); - samplesReceived = m_stream->recv(m_buf, m_bufSamples, md, lockedTimeout); + samplesReceived = m_stream->recv(m_buf8 ? (void *) m_buf8 : (void *) m_buf, m_bufSamples, md, lockedTimeout); } if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) { @@ -274,7 +278,17 @@ void USRPInputThread::run() qDebug("USRPInputThread::run - bad packet error"); if (samples_received > 0) + { + // 8 bit samples widened to 16, full scale as 16 bit samples' (outside the device's receive lock) + if (m_buf8) + { + for (size_t i = 0; i < 2 * samples_received; i++) { + m_buf[i] = (qint16) (m_buf8[i] * 256); + } + } + callbackIQ(m_buf, 2 * samples_received); + } } } catch (std::exception& e) diff --git a/plugins/samplesource/usrpinput/usrpinputthread.h b/plugins/samplesource/usrpinput/usrpinputthread.h index 65ed8e444..1002af305 100644 --- a/plugins/samplesource/usrpinput/usrpinputthread.h +++ b/plugins/samplesource/usrpinput/usrpinputthread.h @@ -56,7 +56,7 @@ public: ReplayBuffer *replayBuffer, MessageQueue *reportQueue, QObject* parent = nullptr); ~USRPInputThread(); - void setStream(uhd::rx_streamer::sptr stream, size_t bufSamples); + void setStream(uhd::rx_streamer::sptr stream, size_t bufSamples, bool sc8 = false); void releaseStream(); virtual void startWork(); virtual void stopWork(); @@ -93,6 +93,7 @@ private: uhd::rx_streamer::sptr m_stream; qint16 *m_buf; + qint8 *m_buf8; //!< With sc8, what's received, before widening into m_buf size_t m_bufSamples; SampleVector m_convertBuffer; SampleSinkFifo* m_sampleFifo; diff --git a/sdrbase/resources/webapi/doc/swagger/include/USRP.yaml b/sdrbase/resources/webapi/doc/swagger/include/USRP.yaml index d665da467..84eb4c243 100644 --- a/sdrbase/resources/webapi/doc/swagger/include/USRP.yaml +++ b/sdrbase/resources/webapi/doc/swagger/include/USRP.yaml @@ -61,6 +61,9 @@ USRPInputSettings: type: integer format: int8 description: "GPIO pin-state bit mask, with one bit per pin." + wireFormat: + type: integer + description: "Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8: half the traffic, for high sample rates)." useReverseAPI: description: Synchronize with reverse API (1 for yes, 0 for no) type: integer diff --git a/swagger/sdrangel/api/swagger/include/USRP.yaml b/swagger/sdrangel/api/swagger/include/USRP.yaml index d665da467..84eb4c243 100644 --- a/swagger/sdrangel/api/swagger/include/USRP.yaml +++ b/swagger/sdrangel/api/swagger/include/USRP.yaml @@ -61,6 +61,9 @@ USRPInputSettings: type: integer format: int8 description: "GPIO pin-state bit mask, with one bit per pin." + wireFormat: + type: integer + description: "Samples over USB or Ethernet: 0 16 bit (sc16), 1 8 bit (sc8: half the traffic, for high sample rates)." useReverseAPI: description: Synchronize with reverse API (1 for yes, 0 for no) type: integer diff --git a/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp b/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp index 0f2c458d4..660e537a9 100644 --- a/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.cpp @@ -60,6 +60,8 @@ SWGUSRPInputSettings::SWGUSRPInputSettings() { m_gpio_dir_isSet = false; gpio_pins = 0; m_gpio_pins_isSet = false; + wire_format = 0; + m_wire_format_isSet = false; use_reverse_api = 0; m_use_reverse_api_isSet = false; reverse_api_address = nullptr; @@ -108,6 +110,8 @@ SWGUSRPInputSettings::init() { m_gpio_dir_isSet = false; gpio_pins = 0; m_gpio_pins_isSet = false; + wire_format = 0; + m_wire_format_isSet = false; use_reverse_api = 0; m_use_reverse_api_isSet = false; reverse_api_address = new QString(""); @@ -193,6 +197,8 @@ SWGUSRPInputSettings::fromJsonObject(QJsonObject &pJson) { ::SWGSDRangel::setValue(&gpio_pins, pJson["gpioPins"], "qint32", ""); + ::SWGSDRangel::setValue(&wire_format, pJson["wireFormat"], "qint32", ""); + ::SWGSDRangel::setValue(&use_reverse_api, pJson["useReverseAPI"], "qint32", ""); ::SWGSDRangel::setValue(&reverse_api_address, pJson["reverseAPIAddress"], "QString", "QString"); @@ -265,6 +271,9 @@ SWGUSRPInputSettings::asJsonObject() { if(m_gpio_pins_isSet){ obj->insert("gpioPins", QJsonValue(gpio_pins)); } + if(m_wire_format_isSet){ + obj->insert("wireFormat", QJsonValue(wire_format)); + } if(m_use_reverse_api_isSet){ obj->insert("useReverseAPI", QJsonValue(use_reverse_api)); } @@ -441,6 +450,16 @@ SWGUSRPInputSettings::setGpioPins(qint32 gpio_pins) { this->m_gpio_pins_isSet = true; } +qint32 +SWGUSRPInputSettings::getWireFormat() { + return wire_format; +} +void +SWGUSRPInputSettings::setWireFormat(qint32 wire_format) { + this->wire_format = wire_format; + this->m_wire_format_isSet = true; +} + qint32 SWGUSRPInputSettings::getUseReverseApi() { return use_reverse_api; @@ -534,6 +553,9 @@ SWGUSRPInputSettings::isSet(){ if(m_gpio_pins_isSet){ isObjectUpdated = true; break; } + if(m_wire_format_isSet){ + isObjectUpdated = true; break; + } if(m_use_reverse_api_isSet){ isObjectUpdated = true; break; } diff --git a/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h b/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h index 1459f3476..e1edb1d84 100644 --- a/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h +++ b/swagger/sdrangel/code/qt5/client/SWGUSRPInputSettings.h @@ -90,6 +90,9 @@ public: qint32 getGpioPins(); void setGpioPins(qint32 gpio_pins); + qint32 getWireFormat(); + void setWireFormat(qint32 wire_format); + qint32 getUseReverseApi(); void setUseReverseApi(qint32 use_reverse_api); @@ -154,6 +157,9 @@ private: qint32 gpio_pins; bool m_gpio_pins_isSet; + qint32 wire_format; + bool m_wire_format_isSet; + qint32 use_reverse_api; bool m_use_reverse_api_isSet;