aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-07-08 14:54:27 -0400
committerClyne Sullivan <clyne@bitgloo.com>2023-07-08 14:54:27 -0400
commit9226bc55235b9f7ebbbd66fdc9ff9edab73309b1 (patch)
tree67b64596919d7c6b54c823c8b1df53c72990be21
parent5e83a22455bb7a09b8b2fe04cc86112311df1be5 (diff)
add frequency cursorfrequency-plot
-rw-r--r--source/gui_device.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/source/gui_device.cpp b/source/gui_device.cpp
index 4ce5616..8b80e9e 100644
--- a/source/gui_device.cpp
+++ b/source/gui_device.cpp
@@ -473,13 +473,15 @@ void deviceRenderDraw()
}
}
+ const auto Fs = m_device->get_sample_rate();
+
const float di = static_cast<float>(buffer.size() / 2) / size.x;
const float dx = std::ceil(size.x / static_cast<float>(buffer.size()));
ImVec2 pp = p0;
float i = 0;
while (pp.x < p0.x + size.x) {
unsigned int idx = i;
- float n = std::clamp(bufferFFTOut[idx].r / buffer.size() / 2.f, 0.f, 1.f);
+ float n = std::clamp(bufferFFTOut[idx].r / Fs / 4.f, 0.f, 1.f);
i += di;
ImVec2 next (pp.x + dx, p0.y + size.y * (1 - n));
@@ -487,6 +489,18 @@ void deviceRenderDraw()
pp = next;
}
+ const auto mouse = ImGui::GetMousePos();
+ if (mouse.x > p0.x && mouse.x < p0.x + size.x &&
+ mouse.y > p0.y && mouse.y < p0.y + size.y)
+ {
+ char buf[16];
+ drawList->AddLine({mouse.x, p0.y}, {mouse.x, p0.y + size.y}, IM_COL32(255, 255, 0, 255));
+
+ const std::size_t si = (mouse.x - p0.x) / size.x * Fs / 2;
+ snprintf(buf, sizeof(buf), " %5luHz", si);
+ drawList->AddText(mouse, IM_COL32(255, 0, 0, 255), buf);
+ }
+
ImGui::End();
}
}