diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 29cf0448e..1734864ac 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -213,6 +213,11 @@ void MainWindow::fftHandler(dsp::complex_t* samples, int count, void* ctx) { MainWindow* _this = (MainWindow*)ctx; std::lock_guard lck(_this->fft_mtx); + // Check if the count is valid + if (count > _this->fftSize) { + return; + } + // Apply window volk_32fc_32f_multiply_32fc((lv_32fc_t*)_this->fft_in, (lv_32fc_t*)samples, sigpath::signalPath.fftTaps, count); @@ -657,9 +662,9 @@ void MainWindow::setFFTSize(int size) { gui::waterfall.setRawFFTSize(fftSize); sigpath::signalPath.setFFTSize(fftSize); + fftwf_destroy_plan(fftwPlan); fftwf_free(fft_in); fftwf_free(fft_out); - fftwf_destroy_plan(fftwPlan); fft_in = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize); fft_out = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize); diff --git a/core/src/version.h b/core/src/version.h index ddf7b304f..100907995 100644 --- a/core/src/version.h +++ b/core/src/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_STR "1.0.2" \ No newline at end of file +#define VERSION_STR "1.0.3" \ No newline at end of file diff --git a/limesdr_source/src/main.cpp b/limesdr_source/src/main.cpp index 66acb5b15..cd39116e1 100644 --- a/limesdr_source/src/main.cpp +++ b/limesdr_source/src/main.cpp @@ -335,7 +335,7 @@ class LimeSDRSourceModule : public ModuleManager::Instance { // Setup and start stream int sampCount = _this->sampleRate / 200; _this->devStream.isTx = false; - _this->devStream.channel = 0; + _this->devStream.channel = _this->chanId; _this->devStream.fifoSize = sampCount; // TODO: Check what it's actually supposed to be _this->devStream.throughputVsLatency = 0.5f; _this->devStream.dataFmt = _this->devStream.LMS_FMT_F32; diff --git a/rtl_sdr_source/src/main.cpp b/rtl_sdr_source/src/main.cpp index db054e029..1840bb364 100644 --- a/rtl_sdr_source/src/main.cpp +++ b/rtl_sdr_source/src/main.cpp @@ -162,6 +162,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance { created = true; config.conf["devices"][selectedDevName]["sampleRate"] = 2400000.0; config.conf["devices"][selectedDevName]["directSampling"] = directSamplingMode; + config.conf["devices"][selectedDevName]["ppm"] = 0; config.conf["devices"][selectedDevName]["biasT"] = biasT; config.conf["devices"][selectedDevName]["offsetTuning"] = offsetTuning; config.conf["devices"][selectedDevName]["rtlAgc"] = rtlAgc; @@ -187,6 +188,10 @@ class RTLSDRSourceModule : public ModuleManager::Instance { directSamplingMode = config.conf["devices"][selectedDevName]["directSampling"]; } + if (config.conf["devices"][selectedDevName].contains("ppm")) { + ppm = config.conf["devices"][selectedDevName]["ppm"]; + } + if (config.conf["devices"][selectedDevName].contains("biasT")) { biasT = config.conf["devices"][selectedDevName]["biasT"]; } @@ -256,6 +261,7 @@ class RTLSDRSourceModule : public ModuleManager::Instance { rtlsdr_set_sample_rate(_this->openDev, _this->sampleRate); rtlsdr_set_center_freq(_this->openDev, _this->freq); + rtlsdr_set_freq_correction(_this->openDev, _this->ppm); rtlsdr_set_tuner_bandwidth(_this->openDev, 0); rtlsdr_set_direct_sampling(_this->openDev, _this->directSamplingMode); rtlsdr_set_bias_tee(_this->openDev, _this->biasT); @@ -372,6 +378,21 @@ class RTLSDRSourceModule : public ModuleManager::Instance { } } + ImGui::Text("PPM Correction"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX()); + if (ImGui::InputInt(CONCAT("##_rtlsdr_ppm_", _this->name), &_this->ppm, 1, 10)) { + _this->ppm = std::clamp(_this->ppm, -1000000, 1000000); + if (_this->running) { + rtlsdr_set_freq_correction(_this->openDev, _this->ppm); + } + if (_this->selectedDevName != "") { + config.acquire(); + config.conf["devices"][_this->selectedDevName]["ppm"] = _this->ppm; + config.release(true); + } + } + if (ImGui::Checkbox(CONCAT("Bias T##_rtlsdr_rtl_biast_", _this->name), &_this->biasT)) { if (_this->running) { rtlsdr_set_bias_tee(_this->openDev, _this->biasT); @@ -471,6 +492,8 @@ class RTLSDRSourceModule : public ModuleManager::Instance { int devCount = 0; std::thread workerThread; + int ppm = 0; + bool biasT = false; int gainId = 0; diff --git a/rtl_tcp_source/src/main.cpp b/rtl_tcp_source/src/main.cpp index 1699ea470..0ab0b3564 100644 --- a/rtl_tcp_source/src/main.cpp +++ b/rtl_tcp_source/src/main.cpp @@ -48,6 +48,8 @@ const char* sampleRatesTxt[] = { "3.2MHz" }; +#define SAMPLE_RATE_COUNT (sizeof(sampleRates) / sizeof(double)) + class RTLTCPSourceModule : public ModuleManager::Instance { public: RTLTCPSourceModule(std::string name) { @@ -55,8 +57,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { sampleRate = 2400000.0; - int srCount = sizeof(sampleRatesTxt) / sizeof(char*); - for (int i = 0; i < srCount; i++) { + int _24id = 0; + for (int i = 0; i < SAMPLE_RATE_COUNT; i++) { + if (sampleRates[i] == 2400000) { _24id = i; } srTxt += sampleRatesTxt[i]; srTxt += '\0'; } @@ -65,7 +68,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { config.acquire(); std::string hostStr = config.conf["host"]; port = config.conf["port"]; + double wantedSr = config.conf["sampleRate"]; directSamplingMode = config.conf["directSamplingMode"]; + ppm = config.conf["ppm"]; rtlAGC = config.conf["rtlAGC"]; tunerAGC = config.conf["tunerAGC"]; gain = std::clamp(config.conf["gainIndex"], 0, 28); @@ -75,6 +80,20 @@ class RTLTCPSourceModule : public ModuleManager::Instance { strcpy(ip, hostStr.c_str()); config.release(); + bool found = false; + for (int i = 0; i < SAMPLE_RATE_COUNT; i++) { + if (sampleRates[i] == wantedSr) { + found = true; + srId = i; + sampleRate = sampleRates[i]; + break; + } + } + if (!found) { + srId = _24id; + sampleRate = sampleRates[_24id]; + } + handler.ctx = this; handler.selectHandler = menuSelected; handler.deselectHandler = menuDeselected; @@ -127,6 +146,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance { spdlog::warn("Setting sample rate to {0}", _this->sampleRate); _this->client.setFrequency(_this->freq); _this->client.setSampleRate(_this->sampleRate); + _this->client.setPPM(_this->ppm); _this->client.setDirectSampling(_this->directSamplingMode); _this->client.setAGCMode(_this->rtlAGC); _this->client.setBiasTee(_this->biasTee); @@ -191,6 +211,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { if (ImGui::Combo(CONCAT("##_rtltcp_sr_", _this->name), &_this->srId, _this->srTxt.c_str())) { _this->sampleRate = sampleRates[_this->srId]; core::setInputSampleRate(_this->sampleRate); + config.acquire(); + config.conf["sampleRate"] = _this->sampleRate; + config.release(true); } if (_this->running) { style::endDisabled(); } @@ -203,18 +226,39 @@ class RTLTCPSourceModule : public ModuleManager::Instance { _this->client.setDirectSampling(_this->directSamplingMode); _this->client.setGainIndex(_this->gain); } + config.acquire(); + config.conf["directSamplingMode"] = _this->directSamplingMode; + config.release(true); + } + + ImGui::Text("PPM Correction"); + ImGui::SameLine(); + ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX()); + if (ImGui::InputInt(CONCAT("##_rtltcp_ppm_", _this->name), &_this->ppm, 1, 10)) { + if (_this->running) { + _this->client.setPPM(_this->ppm); + } + config.acquire(); + config.conf["ppm"] = _this->ppm; + config.release(true); } if (ImGui::Checkbox(CONCAT("Bias-T##_biast_select_", _this->name), &_this->biasTee)) { if (_this->running) { _this->client.setBiasTee(_this->biasTee); } + config.acquire(); + config.conf["biasTee"] = _this->biasTee; + config.release(true); } if (ImGui::Checkbox(CONCAT("Offset Tuning##_biast_select_", _this->name), &_this->offsetTuning)) { if (_this->running) { _this->client.setOffsetTuning(_this->offsetTuning); } + config.acquire(); + config.conf["offsetTuning"] = _this->offsetTuning; + config.release(true); } if (ImGui::Checkbox("RTL AGC", &_this->rtlAGC)) { @@ -224,6 +268,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { _this->client.setGainIndex(_this->gain); } } + config.acquire(); + config.conf["rtlAGC"] = _this->rtlAGC; + config.release(true); } if (ImGui::Checkbox("Tuner AGC", &_this->tunerAGC)) { @@ -233,6 +280,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { _this->client.setGainIndex(_this->gain); } } + config.acquire(); + config.conf["tunerAGC"] = _this->tunerAGC; + config.release(true); } if (_this->tunerAGC) { style::beginDisabled(); } @@ -241,6 +291,9 @@ class RTLTCPSourceModule : public ModuleManager::Instance { if (_this->running) { _this->client.setGainIndex(_this->gain); } + config.acquire(); + config.conf["gainIndex"] = _this->gain; + config.release(true); } if (_this->tunerAGC) { style::endDisabled(); } } @@ -275,6 +328,7 @@ class RTLTCPSourceModule : public ModuleManager::Instance { char ip[1024] = "localhost"; int port = 1234; int gain = 0; + int ppm = 0; bool rtlAGC = false; bool tunerAGC = false; int directSamplingMode = 0; @@ -290,7 +344,9 @@ MOD_EXPORT void _INIT_() { json defConf; defConf["host"] = "localhost"; defConf["port"] = 1234; + defConf["sampleRate"] = 2400000.0; defConf["directSamplingMode"] = 0; + defConf["ppm"] = 0; defConf["rtlAGC"] = false; defConf["tunerAGC"] = false; defConf["gainIndex"] = 0; @@ -306,6 +362,12 @@ MOD_EXPORT void _INIT_() { if (!config.conf.contains("offsetTuning")) { config.conf["offsetTuning"] = false; } + if (!config.conf.contains("ppm")) { + config.conf["ppm"] = 0; + } + if (!config.conf.contains("sampleRate")) { + config.conf["sampleRate"] = 2400000.0; + } config.release(true); } diff --git a/rtl_tcp_source/src/rtltcp_client.h b/rtl_tcp_source/src/rtltcp_client.h index aab5e2ef7..0358f8ed7 100644 --- a/rtl_tcp_source/src/rtltcp_client.h +++ b/rtl_tcp_source/src/rtltcp_client.h @@ -166,6 +166,10 @@ class RTLTCPClient { sendCommand(4, gain); } + void setPPM(int ppm) { + sendCommand(5, (uint32_t)ppm); + } + void setAGCMode(int mode) { sendCommand(8, mode); }