summaryrefslogtreecommitdiff
path: root/src/screens/visualizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/screens/visualizer.cpp')
-rw-r--r--src/screens/visualizer.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/screens/visualizer.cpp b/src/screens/visualizer.cpp
index c60c1dc3..ce1c4105 100644
--- a/src/screens/visualizer.cpp
+++ b/src/screens/visualizer.cpp
@@ -69,6 +69,8 @@ const NC::FormattedColor &toColor(size_t number, size_t max, bool wrap = true)
Visualizer::Visualizer()
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", NC::Color::Default, NC::Border()))
+, m_output_id(-1)
+, m_reset_output(false)
, m_source_fd(-1)
, m_sample_consumption_rate(5)
, m_sample_consumption_rate_up_ctr(0)
@@ -103,14 +105,7 @@ void Visualizer::switchTo()
SwitchTo::execute(this);
Clear();
OpenDataSource();
- // Disable and enable FIFO to get rid of the difference between audio and
- // visualization.
- if (m_output_id != -1)
- {
- Mpd.DisableOutput(m_output_id);
- usleep(50000);
- Mpd.EnableOutput(m_output_id);
- }
+ m_reset_output = true;
drawHeader();
# ifdef HAVE_FFTW3_H
GenLogspace();
@@ -142,6 +137,16 @@ void Visualizer::update()
if (m_source_fd < 0)
return;
+ // Disable and enable FIFO to get rid of the difference between audio and
+ // visualization.
+ if (m_reset_output && m_output_id != -1)
+ {
+ Mpd.DisableOutput(m_output_id);
+ usleep(50000);
+ Mpd.EnableOutput(m_output_id);
+ m_reset_output = false;
+ }
+
// PCM in format 44100:16:1 (for mono visualization) and
// 44100:16:2 (for stereo visualization) is supported.
ssize_t bytes_read = read(m_source_fd, m_incoming_samples.data(),