From 929ca50b06bd8168253ab4132a87d983e65e5b86 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Mon, 7 Dec 2020 04:13:16 +0100 Subject: [PATCH] Added AGC + Started working on channel selection --- core/src/gui/main_window.cpp | 3 +- root_dev/config.json | 33 ++-------------- root_dev/soapy_source_config.json | 5 ++- soapy/src/main.cpp | 64 ++++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 44 deletions(-) diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index c2f43049..a6f407d9 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -123,9 +123,8 @@ void windowInit() { // TODO for 0.2.5 // Add "select folder" option for the file source - // FIX AUDIO ISSUE ON BOTH LINUX AND SOMETIMES WINDOWS (probly the ring buffer, though double buffering could help) // Add default main config to avoid having to ship one - // Have a good directory system on both linux and windows + // Have a good directory system on both linux and windows (should fix occassional underruns) // Switch to double buffering // TODO for 0.2.6 diff --git a/root_dev/config.json b/root_dev/config.json index 294bddb6..f33c2893 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -1,27 +1,10 @@ { - "audio": { - "Radio": { - "device": "Speakers (Realtek High Definiti", - "sampleRate": 48000.0, - "volume": 0.4609375 - }, - "Radio 1": { - "device": "Speakers (Realtek High Definition Audio)", - "sampleRate": 48000.0, - "volume": 0.609375 - }, - "Radio 2": { - "device": "CABLE Input (VB-Audio Virtual Cable)", - "sampleRate": 48000.0, - "volume": 1.0 - } - }, "bandPlan": "General", "bandPlanEnabled": true, "fftHeight": 296, "frequency": 99000000, "max": 0.0, - "maximized": false, + "maximized": true, "menuOrder": [ "Source", "Radio", @@ -33,7 +16,7 @@ "Display" ], "menuWidth": 300, - "min": -54.41176986694336, + "min": -70.5882339477539, "offset": 0.0, "showWaterfall": true, "source": "SoapySDR", @@ -42,17 +25,7 @@ "Radio": { "muted": false, "sink": "Audio", - "volume": 0.6887755393981934 - }, - "Radio 1": { - "muted": true, - "sink": "Audio", - "volume": 0.625 - }, - "Radio 2": { - "muted": false, - "sink": "Audio", - "volume": 1.0 + "volume": 0.4285714328289032 } }, "windowSize": { diff --git a/root_dev/soapy_source_config.json b/root_dev/soapy_source_config.json index e1191d56..caffcfe6 100644 --- a/root_dev/soapy_source_config.json +++ b/root_dev/soapy_source_config.json @@ -18,11 +18,12 @@ "sampleRate": 96000.0 }, "Default Device": { - "sampleRate": 32000.0 + "sampleRate": 192000.0 }, "Generic RTL2832U OEM :: 00000001": { + "agc": false, "gains": { - "TUNER": 23.406999588012695 + "TUNER": 37.3390007019043 }, "sampleRate": 2560000.0 }, diff --git a/soapy/src/main.cpp b/soapy/src/main.cpp index 027f7df8..3a36fa06 100644 --- a/soapy/src/main.cpp +++ b/soapy/src/main.cpp @@ -114,20 +114,22 @@ private: SoapySDR::Device* dev = SoapySDR::Device::make(devArgs); - gainList = dev->listGains(SOAPY_SDR_RX, 0); + gainList = dev->listGains(SOAPY_SDR_RX, channelId); delete[] uiGains; uiGains = new float[gainList.size()]; for (auto gain : gainList) { - gainRanges.push_back(dev->getGainRange(SOAPY_SDR_RX, 0, gain)); + gainRanges.push_back(dev->getGainRange(SOAPY_SDR_RX, channelId, gain)); } - sampleRates = dev->listSampleRates(SOAPY_SDR_RX, 0); + sampleRates = dev->listSampleRates(SOAPY_SDR_RX, channelId); txtSrList = ""; for (double sr : sampleRates) { txtSrList += std::to_string((int)sr); txtSrList += '\0'; } + hasAgc = dev->hasGainMode(SOAPY_SDR_RX, channelId); + SoapySDR::Device::unmake(dev); config.aquire(); @@ -137,9 +139,23 @@ private: if (config.conf["devices"][name]["gains"].contains(gain)) { uiGains[i] = config.conf["devices"][name]["gains"][gain]; } + else { + uiGains[i] = gainRanges[i].minimum(); + } i++; } - selectSampleRate(config.conf["devices"][name]["sampleRate"]); + if (hasAgc && config.conf["devices"][name].contains("agc")) { + agc = config.conf["devices"][name]["agc"]; + } + else { + agc = false; + } + if (config.conf["devices"][name].contains("sampleRate")) { + selectSampleRate(config.conf["devices"][name]["sampleRate"]); + } + else { + selectSampleRate(sampleRates[0]); + } } else { int i = 0; @@ -147,6 +163,9 @@ private: uiGains[i] = gainRanges[i].minimum(); i++; } + if (hasAgc) { + agc = false; + } selectSampleRate(sampleRates[0]); // Select default } config.release(); @@ -161,6 +180,9 @@ private: conf["gains"][gain] = uiGains[i]; i++; } + if (hasAgc) { + conf["agc"] = agc; + } config.aquire(); config.conf["devices"][devArgs["label"]] = conf; config.release(true); @@ -184,15 +206,19 @@ private: SoapyModule* _this = (SoapyModule*)ctx; _this->dev = SoapySDR::Device::make(_this->devArgs); - _this->dev->setSampleRate(SOAPY_SDR_RX, 0, _this->sampleRate); + _this->dev->setSampleRate(SOAPY_SDR_RX, _this->channelId, _this->sampleRate); int i = 0; for (auto gain : _this->gainList) { - _this->dev->setGain(SOAPY_SDR_RX, 0, gain, _this->uiGains[i]); + _this->dev->setGain(SOAPY_SDR_RX, _this->channelId, gain, _this->uiGains[i]); i++; } - _this->dev->setFrequency(SOAPY_SDR_RX, 0, _this->freq); + if (_this->hasAgc) { + _this->dev->setGainMode(SOAPY_SDR_RX, _this->channelId, _this->agc); + } + + _this->dev->setFrequency(SOAPY_SDR_RX, _this->channelId, _this->freq); _this->devStream = _this->dev->setupStream(SOAPY_SDR_RX, "CF32"); _this->dev->activateStream(_this->devStream); @@ -218,12 +244,11 @@ private: SoapyModule* _this = (SoapyModule*)ctx; _this->freq = freq; if (_this->running) { - _this->dev->setFrequency(SOAPY_SDR_RX, 0, freq); + _this->dev->setFrequency(SOAPY_SDR_RX, _this->channelId, freq); } spdlog::info("SoapyModule '{0}': Tune: {1}!", _this->name, freq); } - static void menuHandler(void* ctx) { SoapyModule* _this = (SoapyModule*)ctx; @@ -269,6 +294,21 @@ private: } gainNameLen += 5.0f; + if (_this->hasAgc) { + if (ImGui::Checkbox((std::string("AGC##_agc_sel_") + _this->name).c_str(), &_this->agc)) { + if (_this->running) { _this->dev->setGainMode(SOAPY_SDR_RX, _this->channelId, _this->agc); } + // When disabled, reset the gains + if (!_this->agc) { + int i = 0; + for (auto gain : _this->gainList) { + _this->dev->setGain(SOAPY_SDR_RX, _this->channelId, gain, _this->uiGains[i]); + i++; + } + } + _this->saveCurrent(); + } + } + int i = 0; for (auto gain : _this->gainList) { ImGui::Text("%s gain", gain.c_str()); @@ -278,7 +318,7 @@ private: if (ImGui::SliderFloat((gain + std::string("##_gain_sel_") + _this->name).c_str(), &_this->uiGains[i], _this->gainRanges[i].minimum(), _this->gainRanges[i].maximum())) { if (_this->running) { - _this->dev->setGain(SOAPY_SDR_RX, 0, gain, _this->uiGains[i]); + _this->dev->setGain(SOAPY_SDR_RX, _this->channelId, gain, _this->uiGains[i]); } _this->saveCurrent(); } @@ -315,9 +355,13 @@ private: double freq; double sampleRate; bool running = false; + bool hasAgc = false; + bool agc = false; std::vector sampleRates; int srId = -1; float* uiGains; + int channelCount = 1; + int channelId = 0; std::vector gainList; std::vector gainRanges; };