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
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<double>(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
bPos = std::clamp<double>(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<double>(aPos, widgetPos.y + 10, widgetPos.y + fftHeight + 10);
bPos = std::clamp<double>(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<int>(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<int>(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() {

View File

@ -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,

View File

@ -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