From a0f955e9072563113cc8c43529a286a394d256fb Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Tue, 20 Apr 2021 22:53:23 +0200 Subject: [PATCH 1/4] Full support for the RSPduo --- core/src/core.cpp | 9 ++- make_windows_package.ps1 | 1 + sdrplay_source/src/main.cpp | 115 ++++++++++++++++++++++-------------- 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/core/src/core.cpp b/core/src/core.cpp index df570eb9..92e85eeb 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -261,8 +261,13 @@ int sdrpp_main(int argc, char *argv[]) { // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(window, true); - if (ImGui_ImplOpenGL3_Init(glsl_version)) { - spdlog::warn("Working!"); + if (!ImGui_ImplOpenGL3_Init(glsl_version)) { + // If init fail, try to fall back on GLSL 1.2 + spdlog::warn("Could not init using OpenGL with normal GLSL version, falling back to GLSL 1.2"); + if (!ImGui_ImplOpenGL3_Init("#version 120")) { + spdlog::error("Failed to initialize OpenGL with GLSL 1.2"); + return -1; + } } if (!style::setDarkStyle(resDir)) { return -1; } diff --git a/make_windows_package.ps1 b/make_windows_package.ps1 index ad3a9965..d4f30e05 100644 --- a/make_windows_package.ps1 +++ b/make_windows_package.ps1 @@ -44,6 +44,7 @@ cp "C:/Program Files (x86)/RtAudio/bin/rtaudio.dll" sdrpp_windows_x64/ # Copy supporting libs cp 'C:/Program Files/PothosSDR/bin/libusb-1.0.dll' sdrpp_windows_x64/ +cp 'C:/Program Files/PothosSDR/bin/pthreadVC2.dll' sdrpp_windows_x64/ Compress-Archive -Path sdrpp_windows_x64/ -DestinationPath sdrpp_windows_x64.zip diff --git a/sdrplay_source/src/main.cpp b/sdrplay_source/src/main.cpp index 7eac2d02..28961485 100644 --- a/sdrplay_source/src/main.cpp +++ b/sdrplay_source/src/main.cpp @@ -237,6 +237,7 @@ public: sdrplay_api_ReleaseDevice(&openDev); } + openDev.tuner = sdrplay_api_Tuner_A; openDev.rspDuoMode = sdrplay_api_RspDuoMode_Single_Tuner; err = sdrplay_api_SelectDevice(&openDev); if (err != sdrplay_api_Success) { @@ -247,6 +248,9 @@ public: return; } + sdrplay_api_UnlockDeviceApi(); + sdrplay_api_DebugEnable(openDev.dev, sdrplay_api_DbgLvl_Message); + err = sdrplay_api_GetDeviceParams(openDev.dev, &openDevParams); if (err != sdrplay_api_Success) { const char* errStr = sdrplay_api_GetErrorString(err); @@ -265,6 +269,8 @@ public: return; } + channelParams = openDevParams->rxChannelA; + selectedName = devNameList[id]; if (openDev.hwVer == SDRPLAY_RSP1_ID) { @@ -415,17 +421,27 @@ public: } void rspDuoSelectTuner(sdrplay_api_TunerSelectT tuner, sdrplay_api_RspDuo_AmPortSelectT amPort) { - if (openDev.tuner != tuner) { sdrplay_api_SwapRspDuoActiveTuner(openDev.dev, &openDev.tuner, amPort); } - - // NOTE: Might need to select either A or B - openDevParams->rxChannelA->rspDuoTunerParams.tuner1AmPortSel = amPort; - sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None); + if (openDev.tuner != tuner) { + spdlog::info("Swapping tuners"); + auto ret = sdrplay_api_SwapRspDuoActiveTuner(openDev.dev, &openDev.tuner, amPort); + if (ret != 0) { + spdlog::error("Error while swapping tuners: {0}", (int)ret); + } + } + else { + channelParams->rspDuoTunerParams.tuner1AmPortSel = amPort; + sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None); + } + + // Change the channel params + channelParams = (tuner == sdrplay_api_Tuner_A) ? openDevParams->rxChannelA : openDevParams->rxChannelB; + } void rspDuoSelectAntennaPort(int port) { - if (port == 0) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_1); } - if (port == 1) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_2); } - if (port == 2) { rspDuoSelectTuner(sdrplay_api_Tuner_B, sdrplay_api_RspDuo_AMPORT_2); } + if (port == 0) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_2); } + if (port == 1) { rspDuoSelectTuner(sdrplay_api_Tuner_A, sdrplay_api_RspDuo_AMPORT_1); } + if (port == 2) { rspDuoSelectTuner(sdrplay_api_Tuner_B, sdrplay_api_RspDuo_AMPORT_1); } } private: @@ -470,16 +486,16 @@ private: if (_this->openDev.hwVer == SDRPLAY_RSP1A_ID) { _this->openDevParams->devParams->rsp1aParams.rfNotchEnable = _this->rsp1a_fmNotch; _this->openDevParams->devParams->rsp1aParams.rfNotchEnable = _this->rsp1a_dabNotch; - _this->openDevParams->rxChannelA->rsp1aTunerParams.biasTEnable = _this->rsp1a_biasT; + _this->channelParams->rsp1aTunerParams.biasTEnable = _this->rsp1a_biasT; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_RfNotchControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_RfDabNotchControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp1a_BiasTControl, sdrplay_api_Update_Ext1_None); } else if (_this->openDev.hwVer == SDRPLAY_RSP2_ID) { - _this->openDevParams->rxChannelA->rsp2TunerParams.rfNotchEnable = _this->rsp2_notch; - _this->openDevParams->rxChannelA->rsp2TunerParams.biasTEnable = _this->rsp2_biasT; - _this->openDevParams->rxChannelA->rsp2TunerParams.antennaSel = rsp2_antennaPorts[_this->rsp2_antennaPort]; - _this->openDevParams->rxChannelA->rsp2TunerParams.amPortSel = (_this->rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2; + _this->channelParams->rsp2TunerParams.rfNotchEnable = _this->rsp2_notch; + _this->channelParams->rsp2TunerParams.biasTEnable = _this->rsp2_biasT; + _this->channelParams->rsp2TunerParams.antennaSel = rsp2_antennaPorts[_this->rsp2_antennaPort]; + _this->channelParams->rsp2TunerParams.amPortSel = (_this->rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_RfNotchControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_BiasTControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Rsp2_AntennaControl, sdrplay_api_Update_Ext1_None); @@ -488,10 +504,10 @@ private: else if (_this->openDev.hwVer == SDRPLAY_RSPduo_ID) { // NOTE: mmight require setting it on both RXA and RXB _this->rspDuoSelectAntennaPort(_this->rspduo_antennaPort); - _this->openDevParams->rxChannelA->rspDuoTunerParams.biasTEnable = _this->rspduo_biasT; - _this->openDevParams->rxChannelA->rspDuoTunerParams.rfNotchEnable = _this->rspduo_fmNotch; - _this->openDevParams->rxChannelA->rspDuoTunerParams.rfDabNotchEnable = _this->rspduo_dabNotch; - _this->openDevParams->rxChannelA->rspDuoTunerParams.tuner1AmNotchEnable = _this->rspduo_amNotch; + _this->channelParams->rspDuoTunerParams.biasTEnable = _this->rspduo_biasT; + _this->channelParams->rspDuoTunerParams.rfNotchEnable = _this->rspduo_fmNotch; + _this->channelParams->rspDuoTunerParams.rfDabNotchEnable = _this->rspduo_dabNotch; + _this->channelParams->rspDuoTunerParams.tuner1AmNotchEnable = _this->rspduo_amNotch; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_BiasTControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_RfNotchControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_RspDuo_RfDabNotchControl, sdrplay_api_Update_Ext1_None); @@ -510,30 +526,38 @@ private: // General options _this->openDevParams->devParams->fsFreq.fsHz = _this->sampleRate; - _this->openDevParams->rxChannelA->tunerParams.bwType = _this->bandwidth; - _this->openDevParams->rxChannelA->tunerParams.rfFreq.rfHz = _this->freq; - _this->openDevParams->rxChannelA->tunerParams.gain.gRdB = _this->gain; - _this->openDevParams->rxChannelA->tunerParams.gain.LNAstate = _this->lnaGain; - + _this->channelParams->tunerParams.bwType = _this->bandwidth; + _this->channelParams->tunerParams.rfFreq.rfHz = _this->freq; + _this->channelParams->tunerParams.gain.gRdB = _this->gain; + _this->channelParams->tunerParams.gain.LNAstate = _this->lnaGain; + _this->channelParams->ctrlParams.decimation.enable = false; + _this->channelParams->ctrlParams.dcOffset.DCenable = true; + _this->channelParams->ctrlParams.dcOffset.IQenable = true; + _this->channelParams->tunerParams.ifType = sdrplay_api_IF_Zero; + _this->channelParams->tunerParams.loMode = sdrplay_api_LO_Auto; // Hard coded AGC parameters - _this->openDevParams->rxChannelA->ctrlParams.agc.attack_ms = 500; - _this->openDevParams->rxChannelA->ctrlParams.agc.decay_ms = 500; - _this->openDevParams->rxChannelA->ctrlParams.agc.decay_delay_ms = 200; - _this->openDevParams->rxChannelA->ctrlParams.agc.decay_threshold_dB = 5; - _this->openDevParams->rxChannelA->ctrlParams.agc.setPoint_dBfs = -30; - _this->openDevParams->rxChannelA->ctrlParams.agc.enable = agcModes[_this->agc]; + _this->channelParams->ctrlParams.agc.attack_ms = 500; + _this->channelParams->ctrlParams.agc.decay_ms = 500; + _this->channelParams->ctrlParams.agc.decay_delay_ms = 200; + _this->channelParams->ctrlParams.agc.decay_threshold_dB = 5; + _this->channelParams->ctrlParams.agc.setPoint_dBfs = -30; + _this->channelParams->ctrlParams.agc.enable = agcModes[_this->agc]; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Dev_Fs, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_IfType, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_LoMode, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Decimation, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_DCoffsetIQimbalance, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Frf, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); - sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None); // Bandwidth _this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId]; if (_this->running) { - _this->openDevParams->rxChannelA->tunerParams.bwType = _this->bandwidth; + _this->channelParams->tunerParams.bwType = _this->bandwidth; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None); } @@ -558,7 +582,7 @@ private: static void tune(double freq, void* ctx) { SDRPlaySourceModule* _this = (SDRPlaySourceModule*)ctx; if (_this->running) { - _this->openDevParams->rxChannelA->tunerParams.rfFreq.rfHz = freq; + _this->channelParams->tunerParams.rfFreq.rfHz = freq; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Frf, sdrplay_api_Update_Ext1_None); } _this->freq = freq; @@ -600,7 +624,7 @@ private: if (ImGui::Combo(CONCAT("##sdrplay_bw", _this->name), &_this->bandwidthId, bandwidthsTxt)) { _this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId]; if (_this->running) { - _this->openDevParams->rxChannelA->tunerParams.bwType = _this->bandwidth; + _this->channelParams->tunerParams.bwType = _this->bandwidth; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None); } config.aquire(); @@ -614,7 +638,7 @@ private: ImGui::SameLine(); float pos = ImGui::GetCursorPosX(); if (ImGui::SliderInt(CONCAT("##sdrplay_lna_gain", _this->name), &_this->lnaGain, _this->lnaSteps - 1, 0, "")) { - _this->openDevParams->rxChannelA->tunerParams.gain.LNAstate = _this->lnaGain; + _this->channelParams->tunerParams.gain.LNAstate = _this->lnaGain; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][_this->selectedName]["lnaGain"] = _this->lnaGain; @@ -626,7 +650,7 @@ private: ImGui::SameLine(); ImGui::SetCursorPosX(pos); if (ImGui::SliderInt(CONCAT("##sdrplay_gain", _this->name), &_this->gain, 59, 20, "")) { - _this->openDevParams->rxChannelA->tunerParams.gain.gRdB = _this->gain; + _this->channelParams->tunerParams.gain.gRdB = _this->gain; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][_this->selectedName]["ifGain"] = _this->gain; @@ -639,10 +663,10 @@ private: ImGui::SameLine(); ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX()); if (ImGui::Combo(CONCAT("##sdrplay_agc", _this->name), &_this->agc, agcModesTxt)) { - _this->openDevParams->rxChannelA->ctrlParams.agc.enable = agcModes[_this->agc]; + _this->channelParams->ctrlParams.agc.enable = agcModes[_this->agc]; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None); if (_this->agc == 0) { - _this->openDevParams->rxChannelA->tunerParams.gain.gRdB = _this->gain; + _this->channelParams->tunerParams.gain.gRdB = _this->gain; sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); } config.aquire(); @@ -697,7 +721,7 @@ private: config.release(true); } if (ImGui::Checkbox(CONCAT("Bias-T##sdrplay_rsp1a_biast", name), &rsp1a_biasT)) { - openDevParams->rxChannelA->rsp1aTunerParams.biasTEnable = rsp1a_biasT; + channelParams->rsp1aTunerParams.biasTEnable = rsp1a_biasT; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp1a_BiasTControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["biast"] = rsp1a_biasT; @@ -710,8 +734,8 @@ private: ImGui::SameLine(); ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX()); if (ImGui::Combo(CONCAT("##sdrplay_rsp2_ant", name), &rsp2_antennaPort, rsp2_antennaPortsTxt)) { - openDevParams->rxChannelA->rsp2TunerParams.antennaSel = rsp2_antennaPorts[rsp2_antennaPort]; - openDevParams->rxChannelA->rsp2TunerParams.amPortSel = (rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2; + channelParams->rsp2TunerParams.antennaSel = rsp2_antennaPorts[rsp2_antennaPort]; + channelParams->rsp2TunerParams.amPortSel = (rsp2_antennaPort == 2) ? sdrplay_api_Rsp2_AMPORT_1 : sdrplay_api_Rsp2_AMPORT_2; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_AntennaControl, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_AmPortSelect, sdrplay_api_Update_Ext1_None); config.aquire(); @@ -719,14 +743,14 @@ private: config.release(true); } if (ImGui::Checkbox(CONCAT("MW/FM Notch##sdrplay_rsp2_notch", name), &rsp2_notch)) { - openDevParams->rxChannelA->rsp2TunerParams.rfNotchEnable = rsp2_notch; + channelParams->rsp2TunerParams.rfNotchEnable = rsp2_notch; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_RfNotchControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["notch"] = rsp2_notch; config.release(true); } if (ImGui::Checkbox(CONCAT("Bias-T##sdrplay_rsp2_biast", name), &rsp2_biasT)) { - openDevParams->rxChannelA->rsp2TunerParams.biasTEnable = rsp2_biasT; + channelParams->rsp2TunerParams.biasTEnable = rsp2_biasT; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Rsp2_BiasTControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["biast"] = rsp2_biasT; @@ -746,28 +770,28 @@ private: config.release(true); } if (ImGui::Checkbox(CONCAT("FM Notch##sdrplay_rspduo_notch", name), &rspduo_fmNotch)) { - openDevParams->rxChannelA->rspDuoTunerParams.rfNotchEnable = rspduo_fmNotch; + channelParams->rspDuoTunerParams.rfNotchEnable = rspduo_fmNotch; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_RfNotchControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["fmNotch"] = rspduo_fmNotch; config.release(true); } if (ImGui::Checkbox(CONCAT("DAB Notch##sdrplay_rspduo_dabnotch", name), &rspduo_dabNotch)) { - openDevParams->rxChannelA->rspDuoTunerParams.rfDabNotchEnable = rspduo_dabNotch; + channelParams->rspDuoTunerParams.rfDabNotchEnable = rspduo_dabNotch; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_RfDabNotchControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["dabNotch"] = rspduo_dabNotch; config.release(true); } if (ImGui::Checkbox(CONCAT("AM Notch##sdrplay_rspduo_dabnotch", name), &rspduo_amNotch)) { - openDevParams->rxChannelA->rspDuoTunerParams.tuner1AmNotchEnable = rspduo_amNotch; + channelParams->rspDuoTunerParams.tuner1AmNotchEnable = rspduo_amNotch; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_Tuner1AmNotchControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["amNotch"] = rspduo_amNotch; config.release(true); } if (ImGui::Checkbox(CONCAT("Bias-T##sdrplay_rspduo_biast", name), &rspduo_biasT)) { - openDevParams->rxChannelA->rspDuoTunerParams.biasTEnable = rspduo_biasT; + channelParams->rspDuoTunerParams.biasTEnable = rspduo_biasT; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_BiasTControl, sdrplay_api_Update_Ext1_None); config.aquire(); config.conf["devices"][selectedName]["biast"] = rspduo_biasT; @@ -848,6 +872,7 @@ private: sdrplay_api_DeviceT openDev; sdrplay_api_DeviceParamsT * openDevParams; + sdrplay_api_RxChannelParamsT* channelParams; sdrplay_api_Bw_MHzT bandwidth; int bandwidthId = 0; From 6332b33f3e5d6b6598c0664e0caadbec12b9293d Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 03:03:40 +0200 Subject: [PATCH 2/4] Fixed RSP fft lag --- sdrplay_source/src/main.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/sdrplay_source/src/main.cpp b/sdrplay_source/src/main.cpp index 28961485..405d41d3 100644 --- a/sdrplay_source/src/main.cpp +++ b/sdrplay_source/src/main.cpp @@ -428,13 +428,11 @@ public: spdlog::error("Error while swapping tuners: {0}", (int)ret); } } - else { - channelParams->rspDuoTunerParams.tuner1AmPortSel = amPort; - sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None); - } // Change the channel params channelParams = (tuner == sdrplay_api_Tuner_A) ? openDevParams->rxChannelA : openDevParams->rxChannelB; + channelParams->rspDuoTunerParams.tuner1AmPortSel = amPort; + sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None); } @@ -480,7 +478,7 @@ private: sdrplay_api_ErrT err; _this->bufferIndex = 0; - _this->bufferSize = 8000000 / 200; + _this->bufferSize = (float)_this->sampleRate / 200.0f; // RSP1A Options if (_this->openDev.hwVer == SDRPLAY_RSP1A_ID) { @@ -525,6 +523,7 @@ private: } // General options + _this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId]; _this->openDevParams->devParams->fsFreq.fsHz = _this->sampleRate; _this->channelParams->tunerParams.bwType = _this->bandwidth; _this->channelParams->tunerParams.rfFreq.rfHz = _this->freq; @@ -550,16 +549,9 @@ private: sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_LoMode, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Decimation, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_DCoffsetIQimbalance, sdrplay_api_Update_Ext1_None); - sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Frf, sdrplay_api_Update_Ext1_None); sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); - - // Bandwidth - _this->bandwidth = (_this->bandwidthId == 8) ? preferedBandwidth[_this->srId] : bandwidths[_this->bandwidthId]; - if (_this->running) { - _this->channelParams->tunerParams.bwType = _this->bandwidth; - sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Tuner_BwType, sdrplay_api_Update_Ext1_None); - } + sdrplay_api_Update(_this->openDev.dev, _this->openDev.tuner, sdrplay_api_Update_Ctrl_Agc, sdrplay_api_Update_Ext1_None); _this->running = true; spdlog::info("SDRPlaySourceModule '{0}': Start!", _this->name); From a0316e57c5eadcf564cd1ce512e3036aa3b26d6e Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 14:53:09 +0200 Subject: [PATCH 3/4] Fixed gain bug for RSPduo --- sdrplay_source/src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdrplay_source/src/main.cpp b/sdrplay_source/src/main.cpp index 405d41d3..ca5eed97 100644 --- a/sdrplay_source/src/main.cpp +++ b/sdrplay_source/src/main.cpp @@ -433,6 +433,12 @@ public: channelParams = (tuner == sdrplay_api_Tuner_A) ? openDevParams->rxChannelA : openDevParams->rxChannelB; channelParams->rspDuoTunerParams.tuner1AmPortSel = amPort; sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_RspDuo_AmPortSelect, sdrplay_api_Update_Ext1_None); + + // Refresh gains (for some reason they're lost) + channelParams->tunerParams.gain.LNAstate = lnaGain; + channelParams->tunerParams.gain.gRdB = gain; + sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); + sdrplay_api_Update(openDev.dev, openDev.tuner, sdrplay_api_Update_Tuner_Gr, sdrplay_api_Update_Ext1_None); } From 4849d9cf0976a361bd63fcbb83cfc3a7c8ad5075 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 17:23:09 +0200 Subject: [PATCH 4/4] Fix for threads not terminating --- core/src/dsp/routing.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/dsp/routing.h b/core/src/dsp/routing.h index 3cd4fd65..8d8f5fad 100644 --- a/core/src/dsp/routing.h +++ b/core/src/dsp/routing.h @@ -70,6 +70,11 @@ namespace dsp { Reshaper(stream* in, int keep, int skip) { init(in, keep, skip); } + // NOTE: For some reason, the base class destrcutor doesn't get called.... this is a temporary fix I guess + ~Reshaper() { + generic_block>::stop(); + } + void init(stream* in, int keep, int skip) { _in = in; _keep = keep; @@ -114,7 +119,7 @@ namespace dsp { stream out; private: - void doStart() { + void doStart() override { workThread = std::thread(&Reshaper::loop, this); bufferWorkerThread = std::thread(&Reshaper::bufferWorker, this); } @@ -123,7 +128,7 @@ namespace dsp { while (run() >= 0); } - void doStop() { + void doStop() override { _in->stopReader(); ringBuf.stopReader(); out.stopWriter();