Skip to content

Commit

Permalink
Added FFT hold feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Mar 31, 2022
1 parent 83da29e commit 747b6bf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ int sdrpp_main(int argc, char* argv[]) {
defConfig["bandPlanPos"] = 0;
defConfig["centerTuning"] = false;
defConfig["colorMap"] = "Classic";
defConfig["fftHold"] = false;
defConfig["fftHoldSpeed"] = 60;
defConfig["fastFFT"] = false;
defConfig["fftHeight"] = 300;
defConfig["fftRate"] = 20;
Expand Down
28 changes: 28 additions & 0 deletions core/src/gui/menus/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace displaymenu {
int fftRate = 20;
int uiScaleId = 0;
bool restartRequired = false;
bool fftHold = false;
int fftHoldSpeed = 60;

OptionList<float, float> uiScales;

Expand Down Expand Up @@ -50,6 +52,10 @@ namespace displaymenu {

int fftSizeId = 0;

void updateFFTHoldSpeed() {
gui::waterfall.setFFTHoldSpeed(fftHoldSpeed / (fftRate * 10.0f));
}

void init() {
showWaterfall = core::configManager.conf["showWaterfall"];
showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall();
Expand Down Expand Up @@ -93,6 +99,11 @@ namespace displaymenu {

gui::menu.locked = core::configManager.conf["lockMenuOrder"];

fftHold = core::configManager.conf["fftHold"];
fftHoldSpeed = core::configManager.conf["fftHoldSpeed"];
gui::waterfall.setFFTHold(fftHold);
updateFFTHoldSpeed();

// Define and load UI scales
uiScales.define(1.0f, "100%", 1.0f);
uiScales.define(2.0f, "200%", 2.0f);
Expand Down Expand Up @@ -132,6 +143,22 @@ namespace displaymenu {
core::configManager.release(true);
}

if (ImGui::Checkbox("FFT Hold##_sdrpp", &fftHold)) {
gui::waterfall.setFFTHold(fftHold);
core::configManager.acquire();
core::configManager.conf["fftHold"] = fftHold;
core::configManager.release(true);
}

ImGui::LeftLabel("FFT Hold Speed");
ImGui::FillWidth();
if (ImGui::InputInt("##sdrpp_fft_hold_speed", &fftHoldSpeed)) {
updateFFTHoldSpeed();
core::configManager.acquire();
core::configManager.conf["fftHoldSpeed"] = fftHoldSpeed;
core::configManager.release(true);
}

ImGui::LeftLabel("High-DPI Scaling");
ImGui::FillWidth();
if (ImGui::Combo("##sdrpp_ui_scale", &uiScaleId, uiScales.txt)) {
Expand All @@ -146,6 +173,7 @@ namespace displaymenu {
if (ImGui::InputInt("##sdrpp_fft_rate", &fftRate, 1, 10)) {
fftRate = std::max<int>(1, fftRate);
sigpath::signalPath.setFFTRate(fftRate);
updateFFTHoldSpeed();
core::configManager.acquire();
core::configManager.conf["fftRate"] = fftRate;
core::configManager.release(true);
Expand Down
8 changes: 7 additions & 1 deletion core/src/gui/theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool ThemeManager::loadTheme(std::string path) {
if (param == "name" || param == "author") { continue; }

// Exception for non-imgu colors
if (param == "WaterfallBackground" || param == "ClearColor") {
if (param == "WaterfallBackground" || param == "ClearColor" || param == "FFTHoldColor") {
if (val[0] != '#' || !std::all_of(val.begin() + 1, val.end(), ::isxdigit) || val.length() != 9) {
spdlog::error("Theme {0} contains invalid {1} field. Expected hex RGBA color", path, param);
return false;
Expand Down Expand Up @@ -152,6 +152,12 @@ bool ThemeManager::applyTheme(std::string name) {
continue;
}

if (param == "FFTHoldColor") {
decodeRGBA(val, ret);
fftHoldColor = ImVec4((float)ret[0] / 255.0f, (float)ret[1] / 255.0f, (float)ret[2] / 255.0f, (float)ret[3] / 255.0f);
continue;
}

// If param is a color, check that it's a valid RGBA hex value
if (IMGUI_COL_IDS.find(param) != IMGUI_COL_IDS.end()) {
decodeRGBA(val, ret);
Expand Down
2 changes: 1 addition & 1 deletion core/src/gui/theme_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ThemeManager {
std::vector<std::string> getThemeNames();

ImVec4 waterfallBg = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
;
ImVec4 fftHoldColor = ImVec4(0.0f, 1.0f, 0.75f, 1.0f);
ImVec4 clearColor = ImVec4(0.0666f, 0.0666f, 0.0666f, 1.0f);

private:
Expand Down
12 changes: 8 additions & 4 deletions core/src/gui/widgets/waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ namespace ImGui {
lastWidgetPos.y = 0;
lastWidgetSize.x = 0;
lastWidgetSize.y = 0;
latestFFT = new float[1];
latestFFTHold = new float[1];
latestFFT = new float[dataWidth];
latestFFTHold = new float[dataWidth];
waterfallFb = new uint32_t[1];

viewBandwidth = 1.0;
Expand All @@ -98,7 +98,7 @@ namespace ImGui {
char buf[100];

ImU32 trace = ImGui::GetColorU32(ImGuiCol_PlotLines);
ImU32 traceHold = ImGui::ColorConvertFloat4ToU32(ImVec4(1.0, 1.0, 0.0, 1.0));
ImU32 traceHold = ImGui::ColorConvertFloat4ToU32(gui::themeManager.fftHoldColor);
ImU32 shadow = ImGui::GetColorU32(ImGuiCol_PlotLines, 0.2);
ImU32 text = ImGui::GetColorU32(ImGuiCol_Text);
float textVOffset = 10.0f * style::uiScale;
Expand Down Expand Up @@ -888,7 +888,7 @@ namespace ImGui {
// If FFT hold is enabled, update it
if (fftHold && latestFFT != NULL && latestFFTHold != NULL && fftLines != 0) {
for (int i = 1; i < dataWidth; i++) {
latestFFTHold[i] = std::max<float>(latestFFT[i], latestFFTHold[i] - 0.3f);
latestFFTHold[i] = std::max<float>(latestFFT[i], latestFFTHold[i] - fftHoldSpeed);
}
}

Expand Down Expand Up @@ -1112,6 +1112,10 @@ namespace ImGui {
}
}

void WaterFall::setFFTHoldSpeed(float speed) {
fftHoldSpeed = speed;
}

void WaterfallVFO::setOffset(double offset) {
generalOffset = offset;
if (reference == REF_CENTER) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/gui/widgets/waterfall.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ namespace ImGui {
void setBandPlanPos(int pos);

void setFFTHold(bool hold);
void setFFTHoldSpeed(float speed);

bool centerFreqMoved = false;
bool vfoFreqChanged = false;
Expand Down Expand Up @@ -328,6 +329,7 @@ namespace ImGui {
int bandPlanPos = BANDPLAN_POS_BOTTOM;

bool fftHold = false;
float fftHoldSpeed = 0.3f;

// UI Select elements
bool fftResizeSelect = false;
Expand Down
1 change: 1 addition & 0 deletions root/res/themes/dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"CheckMark": "#3D84E0FF",
"ChildBg": "#FFFFFF00",
"DragDropTarget": "#FFFF00E5",
"FFTHoldColor": "#FFFF00FF",
"FrameBg": "#33353889",
"FrameBgActive": "#33353889",
"FrameBgHovered": "#33353889",
Expand Down
1 change: 1 addition & 0 deletions root/res/themes/light.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"CheckMark": "#3D84E0FF",
"ChildBg": "#00000000",
"DragDropTarget": "#0000FFE5",
"FFTHoldColor": "#C08000FF",
"FrameBg": "#ACA7A389",
"FrameBgActive": "#ACA7A389",
"FrameBgHovered": "#ACA7A389",
Expand Down

0 comments on commit 747b6bf

Please sign in to comment.