add frequency cursor
This commit is contained in:
parent
5e83a22455
commit
9226bc5523
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user