From d4f82af20700043f3a21bce785fb8ae64f1a1440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Thu, 2 Jan 2025 12:26:00 +0800 Subject: [PATCH] phase plot, amplitude control, display pause --- sndlock.cpp | 75 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/sndlock.cpp b/sndlock.cpp index f5992f2..df9715e 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -24,10 +24,13 @@ static std::atomic shutdown_threads; static std::atomic frequency[SND_PCHAN]; +static std::atomic amplitude[SND_PCHAN]; static std::atomic lpf_bandwidth[SND_PCHAN]; -static std::mutex lpf_hist_mutex; -static float lpf_hist[SND_PCHAN][512]; +static std::mutex li_hist_mutex; +static std::atomic li_hist_pause[SND_PCHAN]; +static float li_hist_mag[SND_PCHAN][512]; +static float li_hist_phase[SND_PCHAN][512]; static void dsp_thread() { @@ -77,7 +80,7 @@ static void dsp_thread() for(int i=0;i lockin_out = lockin[i].update(sample); - lpf_count[i]++; - if(lpf_count[i] == 200) { - lpf_count[i] = 0; - std::lock_guard guard(lpf_hist_mutex); - std::memmove(&lpf_hist[i][0], &lpf_hist[i][1], 511*sizeof(float)); - lpf_hist[i][511] = mag; + if(!li_hist_pause[i]) { + li_count[i]++; + if(li_count[i] == 200) { + li_count[i] = 0; + std::lock_guard guard(li_hist_mutex); + std::memmove(&li_hist_mag[i][0], &li_hist_mag[i][1], 511*sizeof(float)); + li_hist_mag[i][511] = std::abs(lockin_out); + std::memmove(&li_hist_phase[i][0], &li_hist_phase[i][1], 511*sizeof(float)); + li_hist_phase[i][511] = std::arg(lockin_out); + } } } } @@ -157,7 +165,7 @@ int main(int argc, char* argv[]) std::atexit(glfwTerminate); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); - static GLFWwindow* window = glfwCreateWindow(1024, 768, "sndlock", nullptr, nullptr); + static GLFWwindow* window = glfwCreateWindow(1024, 1200, "sndlock", nullptr, nullptr); if(window == nullptr) { std::cerr << "failed to create GLFW window" << std::endl; return 1; @@ -185,6 +193,7 @@ int main(int argc, char* argv[]) for(int i=0;i guard(lpf_hist_mutex); - ImGui::PlotLines(str, lpf_hist[i], 512, 0, 0, -0.0f, plot_scale[i], ImVec2(0.0f, 200.0f)); + std::lock_guard guard(li_hist_mutex); + sprintf(str, "magnitude##%d", i); + ImGui::PlotLines(str, li_hist_mag[i], 512, 0, 0, -0.0f, 0.1f*plot_scale[i], ImVec2(0.0f, 200.0f)); + sprintf(str, "phase##%d", i); + ImGui::PlotLines(str, li_hist_phase[i], 512, 0, 0, -M_PI, M_PI, ImVec2(0.0f, 200.0f)); + } + bool pause_l = li_hist_pause[i]; + sprintf(str, "pause##%d", i); + ImGui::Checkbox(str, &pause_l); + li_hist_pause[i] = pause_l; + ImGui::SameLine(); + { + std::lock_guard guard(li_hist_mutex); + ImGui::Text("values: %8.5f %8.5f rad", li_hist_mag[i][511], li_hist_phase[i][511]); } } } - if(ImGui::Button("Exit")) - exit = true; ImGui::End(); ImGui::PopStyleVar(1);