Fixed waterfall non-threadsafe behavior

This commit is contained in:
Ryzerth 2020-12-14 19:33:30 +01:00
parent 1fcd783dd9
commit d9dcfa4a88
3 changed files with 52 additions and 39 deletions

View File

@ -151,15 +151,17 @@ namespace ImGui {
} }
// Data // Data
for (int i = 1; i < dataWidth; i++) { if (latestFFT != NULL && fftLines != 0) {
double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor); for (int i = 1; i < dataWidth; i++) {
double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor); double aPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i - 1] - fftMin) * scaleFactor);
aPos = std::clamp<double>(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); double bPos = widgetPos.y + fftHeight + 10 - ((latestFFT[i] - fftMin) * scaleFactor);
bPos = std::clamp<double>(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10); aPos = std::clamp<double>(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)), bPos = std::clamp<double>(bPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0); window->DrawList->AddLine(ImVec2(widgetPos.x + 49 + i, roundf(aPos)),
window->DrawList->AddLine(ImVec2(widgetPos.x + 50 + i, roundf(bPos)), ImVec2(widgetPos.x + 50 + i, roundf(bPos)), trace, 1.0);
ImVec2(widgetPos.x + 50 + i, widgetPos.y + fftHeight + 10), shadow, 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 // X Axis
@ -407,28 +409,33 @@ namespace ImGui {
fftHeight = widgetSize.y - 50; fftHeight = widgetSize.y - 50;
} }
dataWidth = widgetSize.x - 60.0; dataWidth = widgetSize.x - 60.0;
delete[] latestFFT;
// Raw FFT resize if (waterfallVisible) {
fftLines = std::min<int>(fftLines, waterfallHeight); // Raw FFT resize
if (rawFFTs != NULL) { fftLines = std::min<int>(fftLines, waterfallHeight) - 1;
if (currentFFTLine != 0) { if (rawFFTs != NULL) {
float* tempWF = new float[currentFFTLine * rawFFTSize]; if (currentFFTLine != 0) {
int moveCount = lastWaterfallHeight - currentFFTLine; float* tempWF = new float[currentFFTLine * rawFFTSize];
memcpy(tempWF, rawFFTs, currentFFTLine * rawFFTSize * sizeof(float)); int moveCount = lastWaterfallHeight - currentFFTLine;
memmove(rawFFTs, &rawFFTs[currentFFTLine * rawFFTSize], moveCount * rawFFTSize * sizeof(float)); memcpy(tempWF, rawFFTs, currentFFTLine * rawFFTSize * sizeof(float));
memcpy(&rawFFTs[moveCount * rawFFTSize], tempWF, currentFFTLine * rawFFTSize * sizeof(float)); memmove(rawFFTs, &rawFFTs[currentFFTLine * rawFFTSize], moveCount * rawFFTSize * sizeof(float));
delete[] tempWF; memcpy(&rawFFTs[moveCount * rawFFTSize], tempWF, currentFFTLine * rawFFTSize * sizeof(float));
delete[] tempWF;
}
currentFFTLine = 0;
rawFFTs = (float*)realloc(rawFFTs, waterfallHeight * rawFFTSize * sizeof(float));
} }
currentFFTLine = 0; else {
rawFFTs = (float*)realloc(rawFFTs, waterfallHeight * rawFFTSize * sizeof(float)); rawFFTs = (float*)malloc(waterfallHeight * rawFFTSize * sizeof(float));
}
// ==============
} }
else {
rawFFTs = (float*)malloc(waterfallHeight * rawFFTSize * sizeof(float));
}
// ==============
if (latestFFT != NULL) {
delete[] latestFFT;
}
latestFFT = new float[dataWidth]; latestFFT = new float[dataWidth];
if (waterfallVisible) { if (waterfallVisible) {
delete[] waterfallFb; delete[] waterfallFb;
waterfallFb = new uint32_t[dataWidth * waterfallHeight]; waterfallFb = new uint32_t[dataWidth * waterfallHeight];
@ -839,18 +846,24 @@ namespace ImGui {
void WaterFall::showWaterfall() { void WaterFall::showWaterfall() {
waterfallVisible = true; waterfallVisible = true;
buf_mtx.lock();
onResize(); onResize();
buf_mtx.unlock();
} }
void WaterFall::hideWaterfall() { void WaterFall::hideWaterfall() {
waterfallVisible = false; waterfallVisible = false;
buf_mtx.lock();
onResize(); onResize();
buf_mtx.unlock();
} }
void WaterFall::setFFTHeight(int height) { void WaterFall::setFFTHeight(int height) {
FFTAreaHeight = height; FFTAreaHeight = height;
newFFTAreaHeight = height; newFFTAreaHeight = height;
buf_mtx.lock();
onResize(); onResize();
buf_mtx.unlock();
} }
int WaterFall::getFFTHeight() { int WaterFall::getFFTHeight() {

View File

@ -3,7 +3,7 @@
"bandPlanEnabled": true, "bandPlanEnabled": true,
"centerTuning": false, "centerTuning": false,
"fftHeight": 300, "fftHeight": 300,
"frequency": 98712000, "frequency": 100100000,
"max": 0.0, "max": 0.0,
"maximized": true, "maximized": true,
"menuOrder": [ "menuOrder": [
@ -17,7 +17,7 @@
"Display" "Display"
], ],
"menuWidth": 300, "menuWidth": 300,
"min": -55.147056579589844, "min": -61.764705657958984,
"moduleInstances": { "moduleInstances": {
"Audio Sink": "audio_sink", "Audio Sink": "audio_sink",
"PlutoSDR Source": "plutosdr_source", "PlutoSDR Source": "plutosdr_source",
@ -27,16 +27,16 @@
"SoapySDR Source": "soapy_source" "SoapySDR Source": "soapy_source"
}, },
"modules": [ "modules": [
"./radio/Release/radio.dll", "./radio/RelWithDebInfo/radio.dll",
"./recorder/Release/recorder.dll", "./recorder/RelWithDebInfo/recorder.dll",
"./soapy_source/Release/soapy_source.dll", "./soapy_source/RelWithDebInfo/soapy_source.dll",
"./rtl_tcp_source/Release/rtl_tcp_source.dll", "./rtl_tcp_source/RelWithDebInfo/rtl_tcp_source.dll",
"./audio_sink/Release/audio_sink.dll", "./audio_sink/RelWithDebInfo/audio_sink.dll",
"./plutosdr_source/Release/plutosdr_source.dll" "./plutosdr_source/RelWithDebInfo/plutosdr_source.dll"
], ],
"offset": 0.0, "offset": 0.0,
"showWaterfall": true, "showWaterfall": true,
"source": "SoapySDR", "source": "PlutoSDR",
"streams": { "streams": {
"Radio": { "Radio": {
"muted": false, "muted": false,

View File

@ -1,8 +1,8 @@
{ {
"device": "HackRF One #0 901868dc282c8f8b", "device": "",
"devices": { "devices": {
"": { "": {
"agc": false, "agc": true,
"gains": { "gains": {
"PGA": 0.0 "PGA": 0.0
}, },
@ -27,7 +27,7 @@
"gains": { "gains": {
"TUNER": 37.3390007019043 "TUNER": 37.3390007019043
}, },
"sampleRate": 2560000.0 "sampleRate": 250000.0
}, },
"HackRF One #0 901868dc282c8f8b": { "HackRF One #0 901868dc282c8f8b": {
"gains": { "gains": {
@ -35,7 +35,7 @@
"LNA": 24.503000259399414, "LNA": 24.503000259399414,
"VGA": 16.332000732421875 "VGA": 16.332000732421875
}, },
"sampleRate": 16000000.0 "sampleRate": 8000000.0
}, },
"Microphone (Realtek High Definition Audio)": { "Microphone (Realtek High Definition Audio)": {
"sampleRate": 96000.0 "sampleRate": 96000.0