summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Rybczak <andrzej@rybczak.net>2020-12-22 19:32:55 +0100
committerAndrzej Rybczak <andrzej@rybczak.net>2020-12-22 19:35:51 +0100
commitd402df8eeb0c6b62f9a55746549e824ca0a156c7 (patch)
tree2f06984267c2d018922f5a7ba463247b3725604d
parentdef7ea42f6ba3bdb1319686ecdabe403662021e1 (diff)
Reduce CPU usage of the frequency spectrum visualizer
-rw-r--r--CHANGELOG.md1
-rw-r--r--configure.ac24
-rw-r--r--doc/config2
-rw-r--r--src/screens/visualizer.cpp32
-rw-r--r--src/settings.cpp4
5 files changed, 44 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 75716f75..05e7015a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
* Draw a separator between albums with the same name, but a different artist.
* Suppress output of all external commands.
* Consider mouse support when pausing and unpausing curses interface.
+* Reduce CPU usage of the frequency spectrum visualizer.
# ncmpcpp-0.9 (2020-12-20)
* Fix various Mopidy specific bugs.
diff --git a/configure.ac b/configure.ac
index c5093505..8c2d85fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,30 @@ if test "$clock" = "yes"; then
AC_DEFINE([ENABLE_CLOCK], [1], [enables clock screen])
fi
+# -ftree-vectorize
+AC_MSG_CHECKING([whether compiler supports -ftree-vectorize])
+old_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="-ftree-vectorize"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])],
+ AC_MSG_RESULT([yes])
+ tree_vectorize="-ftree-vectorize",
+ AC_MSG_RESULT([no])
+ tree_vectorize=""
+)
+CXXFLAGS="$old_CXXFLAGS $tree_vectorize"
+
+# -ffast-math
+AC_MSG_CHECKING([whether compiler supports -ffast-math])
+old_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="-ffast-math"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])],
+ AC_MSG_RESULT([yes])
+ fast_math="-ffast-math",
+ AC_MSG_RESULT([no])
+ fast_math=""
+)
+CXXFLAGS="$old_CXXFLAGS $fast_math"
+
# -std=c++14
AC_MSG_CHECKING([whether compiler supports -std=c++14])
old_CXXFLAGS="$CXXFLAGS"
diff --git a/doc/config b/doc/config
index 3c3afd35..88893cff 100644
--- a/doc/config
+++ b/doc/config
@@ -127,7 +127,7 @@
## visualizer look at a larger slice of time, which results in less jumpy
## visualizer output.
#
-#visualizer_spectrum_dft_size = 3
+#visualizer_spectrum_dft_size = 2
#
#visualizer_spectrum_gain = 10
#
diff --git a/src/screens/visualizer.cpp b/src/screens/visualizer.cpp
index 8fdcd464..af0afddb 100644
--- a/src/screens/visualizer.cpp
+++ b/src/screens/visualizer.cpp
@@ -77,8 +77,8 @@ Visualizer::Visualizer()
, m_sample_consumption_rate_dn_ctr(0)
# ifdef HAVE_FFTW3_H
,
- DFT_NONZERO_SIZE(1 << Config.visualizer_spectrum_dft_size),
- DFT_TOTAL_SIZE(1 << (Config.visualizer_spectrum_dft_size + 2)),
+ DFT_NONZERO_SIZE(2048 * (2*Config.visualizer_spectrum_dft_size + 4)),
+ DFT_TOTAL_SIZE(1 << 15),
DYNAMIC_RANGE(100-Config.visualizer_spectrum_gain),
HZ_MIN(Config.visualizer_spectrum_hz_min),
HZ_MAX(Config.visualizer_spectrum_hz_max),
@@ -206,7 +206,7 @@ void Visualizer::update()
}
else if (m_sample_consumption_rate > 0)
{
- if (++m_sample_consumption_rate_dn_ctr > 2)
+ if (++m_sample_consumption_rate_dn_ctr > 4)
{
m_sample_consumption_rate_dn_ctr = 0;
--m_sample_consumption_rate;
@@ -489,7 +489,7 @@ void Visualizer::DrawFrequencySpectrum(const int16_t *buf, ssize_t samples, size
for (size_t x = 0; x < win_width; ++x)
{
const size_t &i = m_bar_heights[h_idx].first;
- const double &bar_height = m_bar_heights[h_idx].second;
+ const double bar_height = m_bar_heights[h_idx].second;
double h = 0;
if (x == i) {
@@ -547,33 +547,33 @@ void Visualizer::DrawFrequencySpectrumStereo(const int16_t *buf_left, const int1
double Visualizer::Interpolate(size_t x, size_t h_idx)
{
- const double &x_next = m_bar_heights[h_idx].first;
- const double &h_next = m_bar_heights[h_idx].second;
+ const double x_next = m_bar_heights[h_idx].first;
+ const double h_next = m_bar_heights[h_idx].second;
double dh = 0;
if (h_idx == 0) {
// no data points on left, linear extrap
if (h_idx < m_bar_heights.size()-1) {
- const double &x_next2 = m_bar_heights[h_idx+1].first;
- const double &h_next2 = m_bar_heights[h_idx+1].second;
+ const double x_next2 = m_bar_heights[h_idx+1].first;
+ const double h_next2 = m_bar_heights[h_idx+1].second;
dh = (h_next2 - h_next) / (x_next2 - x_next);
}
return h_next - dh*(x_next-x);
} else if (h_idx == 1) {
// one data point on left, linear interp
- const double &x_prev = m_bar_heights[h_idx-1].first;
- const double &h_prev = m_bar_heights[h_idx-1].second;
+ const double x_prev = m_bar_heights[h_idx-1].first;
+ const double h_prev = m_bar_heights[h_idx-1].second;
dh = (h_next - h_prev) / (x_next - x_prev);
return h_next - dh*(x_next-x);
} else if (h_idx < m_bar_heights.size()-1) {
// two data points on both sides, cubic interp
// see https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Interpolation_on_an_arbitrary_interval
- const double &x_prev2 = m_bar_heights[h_idx-2].first;
- const double &h_prev2 = m_bar_heights[h_idx-2].second;
- const double &x_prev = m_bar_heights[h_idx-1].first;
- const double &h_prev = m_bar_heights[h_idx-1].second;
- const double &x_next2 = m_bar_heights[h_idx+1].first;
- const double &h_next2 = m_bar_heights[h_idx+1].second;
+ const double x_prev2 = m_bar_heights[h_idx-2].first;
+ const double h_prev2 = m_bar_heights[h_idx-2].second;
+ const double x_prev = m_bar_heights[h_idx-1].first;
+ const double h_prev = m_bar_heights[h_idx-1].second;
+ const double x_next2 = m_bar_heights[h_idx+1].first;
+ const double h_next2 = m_bar_heights[h_idx+1].second;
const double m0 = (h_prev - h_prev2) / (x_prev - x_prev2);
const double m1 = (h_next2 - h_next) / (x_next2 - x_next);
diff --git a/src/settings.cpp b/src/settings.cpp
index ed151b96..80a2b4e3 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -272,10 +272,10 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
p.add("visualizer_autoscale", &visualizer_autoscale, "no", yes_no);
p.add("visualizer_spectrum_smooth_look", &visualizer_spectrum_smooth_look, "yes", yes_no);
p.add("visualizer_spectrum_dft_size", &visualizer_spectrum_dft_size,
- "3", [](std::string v) {
+ "2", [](std::string v) {
auto result = verbose_lexical_cast<size_t>(v);
boundsCheck<size_t>(result, 1, 5);
- return result + 11;
+ return result;
});
p.add("visualizer_spectrum_gain", &visualizer_spectrum_gain,
"10", [](std::string v) {