From 68e6ebe24cb476997b2ddfc21a5b13fb6f332fa7 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Fri, 16 Jul 2021 21:00:28 +0300 Subject: Render texture onto window on each iteration. Keep colormap in renderer so we don't pass the colormapped windows like animals. Pre-render empty window. Fixes #15. --- src/specgram.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/specgram.cpp') diff --git a/src/specgram.cpp b/src/specgram.cpp index cb646fc..d70126f 100644 --- a/src/specgram.cpp +++ b/src/specgram.cpp @@ -165,6 +165,7 @@ main(int argc, char** argv) std::unique_ptr live = nullptr; if (conf.IsLive()) { live = std::make_unique(conf, *color_map, *value_map); + live->Render(); /* render empty window */ } /* create input parser */ @@ -218,7 +219,7 @@ main(int argc, char** argv) /* main loop */ while (main_loop_running && !reader->ReachedEOF()) { - /* check for window events (if necessary) */ + /* check for window events (if necessary) and redraw */ if (live != nullptr) { if (!live->HandleEvents()) { /* exited by closing window */ @@ -226,6 +227,7 @@ main(int argc, char** argv) /* uninstall signal so that reader thread can exit successfully */ std::signal(SIGINT, nullptr); } + live->Render(); } /* check for a complete block */ @@ -282,7 +284,7 @@ main(int argc, char** argv) assert(window_sum.size() == normalized_magnitude.size()); assert(conf.GetAverageCount() > 0); for (std::size_t i = 0; i < window_sum.size(); i++) { - window_sum[i] += normalized_magnitude[i] / conf.GetAverageCount(); + window_sum[i] += normalized_magnitude[i] / (double)conf.GetAverageCount(); } window_sum_count++; @@ -291,17 +293,14 @@ main(int argc, char** argv) continue; } - /* colorize FFT */ - auto colorized = color_map->Map(window_sum); - /* add to live */ if (live != nullptr) { - live->AddWindow(colorized, window_sum); - } - - /* add to history */ - if (have_output) { - history.push_back(colorized); + auto colorized = live->AddWindow(window_sum); + if (have_output) { + history.push_back(colorized); + } + } else if (have_output) { + history.push_back(color_map->Map(window_sum)); } /* reset */ -- cgit v1.2.3