]> code.bitgloo.com Git - clyne/stmdspgui.git/commitdiff
add frequency cursor frequency-plot
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 8 Jul 2023 18:54:27 +0000 (14:54 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 8 Jul 2023 18:54:27 +0000 (14:54 -0400)
source/gui_device.cpp

index 4ce56165d2cd4a1bff98d00e4695d2f99e2f1f67..8b80e9e31f697041f04d2b6e188269c90161d17b 100644 (file)
@@ -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();
     }
 }