From d9dcfa4a8856b050cc3a53b6cf4d7ea8ea9af73c Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Mon, 14 Dec 2020 19:33:30 +0100 Subject: [PATCH] Fixed waterfall non-threadsafe behavior --- core/src/gui/widgets/waterfall.cpp | 65 ++++++++++++++++++------------ root_dev/config.json | 18 ++++----- root_dev/soapy_source_config.json | 8 ++-- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 3618a6f1..025f009a 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -151,15 +151,17 @@ namespace ImGui { } // Data - for (int i = 1; i < dataWidth; i++) { - double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor); - double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor); - aPos = std::clamp(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); - bPos = std::clamp(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); - window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)), - ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0); - window->DrawList->AddLine(ImVec2(widgetPos.x + 50 + i, roundf(bPos)), - ImVec2(widgetPos.x + 50 + i, widgetPos.y + fftHeight + 10), shadow, 1.0); + if (latestFFT != NULL && fftLines != 0) { + for (int i = 1; i < dataWidth; i++) { + double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor); + double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor); + aPos = std::clamp(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); + bPos = std::clamp(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); + window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)), + ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0); + window->DrawList->AddLine(ImVec2(widgetPos.x + 50 + i, roundf(bPos)), + ImVec2(widgetPos.x + 50 + i, widgetPos.y + fftHeight + 10), shadow, 1.0); + } } // X Axis @@ -407,28 +409,33 @@ namespace ImGui { fftHeight = widgetSize.y - 50; } dataWidth = widgetSize.x - 60.0; - delete[] latestFFT; - // Raw FFT resize - fftLines = std::min(fftLines, waterfallHeight); - if (rawFFTs != NULL) { - if (currentFFTLine != 0) { - float* tempWF = new float[currentFFTLine * rawFFTSize]; - int moveCount = lastWaterfallHeight - currentFFTLine; - memcpy(tempWF, rawFFTs, currentFFTLine * rawFFTSize * sizeof(float)); - memmove(rawFFTs, &rawFFTs[currentFFTLine * rawFFTSize], moveCount * rawFFTSize * sizeof(float)); - memcpy(&rawFFTs[moveCount * rawFFTSize], tempWF, currentFFTLine * rawFFTSize * sizeof(float)); - delete[] tempWF; + if (waterfallVisible) { + // Raw FFT resize + fftLines = std::min(fftLines, waterfallHeight) - 1; + if (rawFFTs != NULL) { + if (currentFFTLine != 0) { + float* tempWF = new float[currentFFTLine * rawFFTSize]; + int moveCount = lastWaterfallHeight - currentFFTLine; + memcpy(tempWF, rawFFTs, currentFFTLine * rawFFTSize * sizeof(float)); + memmove(rawFFTs, &rawFFTs[currentFFTLine * rawFFTSize], moveCount * rawFFTSize * sizeof(float)); + memcpy(&rawFFTs[moveCount * rawFFTSize], tempWF, currentFFTLine * rawFFTSize * sizeof(float)); + delete[] tempWF; + } + currentFFTLine = 0; + rawFFTs = (float*)realloc(rawFFTs, waterfallHeight * rawFFTSize * sizeof(float)); } - currentFFTLine = 0; - rawFFTs = (float*)realloc(rawFFTs, waterfallHeight * rawFFTSize * sizeof(float)); + else { + rawFFTs = (float*)malloc(waterfallHeight * rawFFTSize * sizeof(float)); + } + // ============== } - else { - rawFFTs = (float*)malloc(waterfallHeight * rawFFTSize * sizeof(float)); - } - // ============== + if (latestFFT != NULL) { + delete[] latestFFT; + } latestFFT = new float[dataWidth]; + if (waterfallVisible) { delete[] waterfallFb; waterfallFb = new uint32_t[dataWidth * waterfallHeight]; @@ -839,18 +846,24 @@ namespace ImGui { void WaterFall::showWaterfall() { waterfallVisible = true; + buf_mtx.lock(); onResize(); + buf_mtx.unlock(); } void WaterFall::hideWaterfall() { waterfallVisible = false; + buf_mtx.lock(); onResize(); + buf_mtx.unlock(); } void WaterFall::setFFTHeight(int height) { FFTAreaHeight = height; newFFTAreaHeight = height; + buf_mtx.lock(); onResize(); + buf_mtx.unlock(); } int WaterFall::getFFTHeight() { diff --git a/root_dev/config.json b/root_dev/config.json index c5bec388..45c143f0 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -3,7 +3,7 @@ "bandPlanEnabled": true, "centerTuning": false, "fftHeight": 300, - "frequency": 98712000, + "frequency": 100100000, "max": 0.0, "maximized": true, "menuOrder": [ @@ -17,7 +17,7 @@ "Display" ], "menuWidth": 300, - "min": -55.147056579589844, + "min": -61.764705657958984, "moduleInstances": { "Audio Sink": "audio_sink", "PlutoSDR Source": "plutosdr_source", @@ -27,16 +27,16 @@ "SoapySDR Source": "soapy_source" }, "modules": [ - "./radio/Release/radio.dll", - "./recorder/Release/recorder.dll", - "./soapy_source/Release/soapy_source.dll", - "./rtl_tcp_source/Release/rtl_tcp_source.dll", - "./audio_sink/Release/audio_sink.dll", - "./plutosdr_source/Release/plutosdr_source.dll" + "./radio/RelWithDebInfo/radio.dll", + "./recorder/RelWithDebInfo/recorder.dll", + "./soapy_source/RelWithDebInfo/soapy_source.dll", + "./rtl_tcp_source/RelWithDebInfo/rtl_tcp_source.dll", + "./audio_sink/RelWithDebInfo/audio_sink.dll", + "./plutosdr_source/RelWithDebInfo/plutosdr_source.dll" ], "offset": 0.0, "showWaterfall": true, - "source": "SoapySDR", + "source": "PlutoSDR", "streams": { "Radio": { "muted": false, diff --git a/root_dev/soapy_source_config.json b/root_dev/soapy_source_config.json index c919d06e..1e46a6fa 100644 --- a/root_dev/soapy_source_config.json +++ b/root_dev/soapy_source_config.json @@ -1,8 +1,8 @@ { - "device": "HackRF One #0 901868dc282c8f8b", + "device": "", "devices": { "": { - "agc": false, + "agc": true, "gains": { "PGA": 0.0 }, @@ -27,7 +27,7 @@ "gains": { "TUNER": 37.3390007019043 }, - "sampleRate": 2560000.0 + "sampleRate": 250000.0 }, "HackRF One #0 901868dc282c8f8b": { "gains": { @@ -35,7 +35,7 @@ "LNA": 24.503000259399414, "VGA": 16.332000732421875 }, - "sampleRate": 16000000.0 + "sampleRate": 8000000.0 }, "Microphone (Realtek High Definition Audio)": { "sampleRate": 96000.0