more work

This commit is contained in:
AlexandreRouma
2023-03-27 17:26:37 +02:00
parent a9f882e5b1
commit f578adceef
4 changed files with 92 additions and 9 deletions

View File

@ -689,6 +689,7 @@ namespace ImGui {
void WaterFall::onResize() {
std::lock_guard<std::recursive_mutex> lck(latestFFTMtx);
std::lock_guard<std::mutex> lck2(smoothingBufMtx);
// return if widget is too small
if (widgetSize.x < 100 || widgetSize.y < 100) {
return;
@ -740,14 +741,23 @@ namespace ImGui {
}
latestFFTHold = new float[dataWidth];
// Reallocate smoothing buffer
if (fftSmoothing) {
if (smoothingBuf) { delete[] smoothingBuf; }
smoothingBuf = new float[dataWidth];
for (int i = 0; i < dataWidth; i++) {
smoothingBuf[i] = -1000.0f;
}
}
if (waterfallVisible) {
delete[] waterfallFb;
waterfallFb = new uint32_t[dataWidth * waterfallHeight];
memset(waterfallFb, 0, dataWidth * waterfallHeight * sizeof(uint32_t));
}
for (int i = 0; i < dataWidth; i++) {
latestFFT[i] = -1000.0; // Hide everything
latestFFTHold[i] = -1000.0;
latestFFT[i] = -1000.0f; // Hide everything
latestFFTHold[i] = -1000.0f;
}
fftAreaMin = ImVec2(widgetPos.x + (50.0f * style::uiScale), widgetPos.y + (9.0f * style::uiScale));
@ -873,6 +883,15 @@ namespace ImGui {
fftLines = 1;
}
// Apply smoothing if enabled
if (fftSmoothing && latestFFT != NULL && smoothingBuf != NULL && fftLines != 0) {
std::lock_guard<std::mutex> lck2(smoothingBufMtx);
volk_32f_s32f_multiply_32f(latestFFT, latestFFT, smoothingAlpha, dataWidth);
volk_32f_s32f_multiply_32f(smoothingBuf, smoothingBuf, smoothingBeta, dataWidth);
volk_32f_x2_add_32f(smoothingBuf, latestFFT, smoothingBuf, dataWidth);
memcpy(latestFFT, smoothingBuf, dataWidth * sizeof(float));
}
if (selectedVFO != "" && vfos.size() > 0) {
float dummy;
calculateVFOSignalInfo(waterfallVisible ? &rawFFTs[currentFFTLine * rawFFTSize] : rawFFTs, vfos[selectedVFO], dummy, selectedVFOSNR);
@ -1110,6 +1129,36 @@ namespace ImGui {
fftHoldSpeed = speed;
}
void WaterFall::setFFTSmoothing(bool enabled) {
std::lock_guard<std::mutex> lck(smoothingBufMtx);
fftSmoothing = enabled;
// Free buffer if not null
if (smoothingBuf) {delete[] smoothingBuf; }
// If disabled, stop here
if (!enabled) {
smoothingBuf = NULL;
return;
}
// Allocate and copy existing FFT into it
smoothingBuf = new float[dataWidth];
if (latestFFT) {
std::lock_guard<std::recursive_mutex> lck2(latestFFTMtx);
memcpy(smoothingBuf, latestFFT, dataWidth * sizeof(float));
}
else {
memset(smoothingBuf, 0, dataWidth * sizeof(float));
}
}
void WaterFall::setFFTSmoothingSpeed(float speed) {
std::lock_guard<std::mutex> lck(smoothingBufMtx);
smoothingAlpha = speed;
smoothingBeta = 1.0f - speed;
}
float* WaterFall::acquireLatestFFT(int& width) {
latestFFTMtx.lock();
if (!latestFFT) {

View File

@ -169,6 +169,9 @@ namespace ImGui {
void setFFTHold(bool hold);
void setFFTHoldSpeed(float speed);
void setFFTSmoothing(bool enabled);
void setFFTSmoothingSpeed(float speed);
float* acquireLatestFFT(int& width);
void releaseLatestFFT();
@ -270,6 +273,7 @@ namespace ImGui {
std::recursive_mutex buf_mtx;
std::recursive_mutex latestFFTMtx;
std::mutex texMtx;
std::mutex smoothingBufMtx;
float vRange;
@ -304,8 +308,9 @@ namespace ImGui {
//std::vector<std::vector<float>> rawFFTs;
int rawFFTSize;
float* rawFFTs = NULL;
float* latestFFT;
float* latestFFTHold;
float* latestFFT = NULL;
float* latestFFTHold = NULL;
float* smoothingBuf = NULL;
int currentFFTLine = 0;
int fftLines = 0;
@ -325,6 +330,10 @@ namespace ImGui {
bool fftHold = false;
float fftHoldSpeed = 0.3f;
bool fftSmoothing = false;
float smoothingAlpha = 0.5;
float smoothingBeta = 0.5;
// UI Select elements
bool fftResizeSelect = false;
bool freqScaleSelect = false;