From eb7b3a2567a07e421c8793ae9e362903a12aa3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Thu, 2 Jan 2025 13:52:18 +0800 Subject: [PATCH] HIST_DEPTH --- sndlock.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/sndlock.cpp b/sndlock.cpp index df9715e..7e5098f 100644 --- a/sndlock.cpp +++ b/sndlock.cpp @@ -25,12 +25,14 @@ static std::atomic shutdown_threads; static std::atomic frequency[SND_PCHAN]; static std::atomic amplitude[SND_PCHAN]; -static std::atomic lpf_bandwidth[SND_PCHAN]; +#define HIST_DEPTH 512 + +static std::atomic lpf_bandwidth[SND_PCHAN]; 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 float li_hist_mag[SND_PCHAN][HIST_DEPTH]; +static float li_hist_phase[SND_PCHAN][HIST_DEPTH]; static void dsp_thread() { @@ -136,10 +138,10 @@ static void dsp_thread() 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); + std::memmove(&li_hist_mag[i][0], &li_hist_mag[i][1], (HIST_DEPTH-1)*sizeof(float)); + li_hist_mag[i][HIST_DEPTH-1] = std::abs(lockin_out); + std::memmove(&li_hist_phase[i][0], &li_hist_phase[i][1], (HIST_DEPTH-1)*sizeof(float)); + li_hist_phase[i][HIST_DEPTH-1] = std::arg(lockin_out); } } } @@ -257,9 +259,9 @@ int main(int argc, char* argv[]) { 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)); + ImGui::PlotLines(str, li_hist_mag[i], HIST_DEPTH, 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)); + ImGui::PlotLines(str, li_hist_phase[i], HIST_DEPTH, 0, 0, -M_PI, M_PI, ImVec2(0.0f, 200.0f)); } bool pause_l = li_hist_pause[i]; sprintf(str, "pause##%d", i);