From 6dad74f3c996f3ebda769b1af3279c7b4e9e94bb Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Thu, 25 Aug 2022 02:25:33 +0200 Subject: Enable configuring spectrum analyzer FPS --- NEWS | 2 ++ nncmpp.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index cae7dc5..75cc843 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ Unreleased * Added a "z" binding to center the view on the selected item + * Made it possible to adjust the spectrum analyzer's FPS limit + * Fixed possibility of connection timeouts with PulseAudio integration diff --git a/nncmpp.c b/nncmpp.c index 3a7227e..84192ee 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -741,7 +741,8 @@ spectrum_sample (struct spectrum *s) } static bool -spectrum_init (struct spectrum *s, char *format, int bars, struct error **e) +spectrum_init (struct spectrum *s, char *format, int bars, int fps, + struct error **e) { errno = 0; @@ -817,8 +818,7 @@ spectrum_init (struct spectrum *s, char *format, int bars, struct error **e) s->top_bins[bar] = MIN (top_bin, used_bins); } - // Limit updates to 30 times per second to limit CPU load - s->samples = s->sampling_rate / s->bins * 2 / 30; + s->samples = s->sampling_rate / s->bins * 2 / MAX (fps, 1); if (s->samples < 1) s->samples = 1; @@ -1461,6 +1461,10 @@ static struct config_schema g_config_settings[] = .comment = "Number of computed audio spectrum bars", .type = CONFIG_ITEM_INTEGER, .default_ = "8" }, + { .name = "spectrum_fps", + .comment = "Maximum frames per second, affects CPU usage", + .type = CONFIG_ITEM_INTEGER, + .default_ = "30" }, #endif // WITH_FFTW #ifdef WITH_PULSE @@ -4349,6 +4353,8 @@ spectrum_setup_fifo (void) get_config_string (g.config.root, "settings.spectrum_format"); struct config_item *spectrum_bars = config_item_get (g.config.root, "settings.spectrum_bars", NULL); + struct config_item *spectrum_fps = + config_item_get (g.config.root, "settings.spectrum_fps", NULL); if (!spectrum_path) return; @@ -4360,8 +4366,8 @@ spectrum_setup_fifo (void) print_error ("spectrum: %s", "FIFO path could not be resolved"); else if (!g.locale_is_utf8) print_error ("spectrum: %s", "UTF-8 locale required"); - else if (!spectrum_init (&g.spectrum, - (char *) spectrum_format, spectrum_bars->value.integer, &e)) + else if (!spectrum_init (&g.spectrum, (char *) spectrum_format, + spectrum_bars->value.integer, spectrum_fps->value.integer, &e)) { print_error ("spectrum: %s", e->message); error_free (e); -- cgit v1.2.3-70-g09d2