summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Rybczak <andrzej@rybczak.net>2020-12-14 13:35:04 +0100
committerAndrzej Rybczak <andrzej@rybczak.net>2020-12-14 13:39:12 +0100
commitb8983b93eca707cafe5630962f7035775ebbae31 (patch)
treea4649ad81d40e874b2dc99348fa7879e254927fd
parent8237bcef27016d0a49b572a65b85c910b964f6d8 (diff)
Set sizes of samples read properly for stereo visualizers
-rw-r--r--doc/config6
-rw-r--r--doc/ncmpcpp.12
-rw-r--r--src/screens/visualizer.cpp82
-rw-r--r--src/screens/visualizer.h5
-rw-r--r--src/settings.cpp6
5 files changed, 51 insertions, 50 deletions
diff --git a/doc/config b/doc/config
index 628d96e3..fe066d78 100644
--- a/doc/config
+++ b/doc/config
@@ -105,13 +105,13 @@
#
#visualizer_spectrum_smooth_look = yes
#
-## A value between 1 and 7 inclusive. Specifying a larger value makes the
+## A value between 1 and 5 inclusive. Specifying a larger value makes the
## visualizer look at a larger slice of time, which results in less jumpy
## visualizer output.
#
-#visualizer_spectrum_dft_size = 4
+#visualizer_spectrum_dft_size = 3
#
-#visualizer_spectrum_gain = 20
+#visualizer_spectrum_gain = 10
#
## Left-most frequency of visualizer in Hz, must be less than HZ MAX
#
diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1
index affa0049..bf937baa 100644
--- a/doc/ncmpcpp.1
+++ b/doc/ncmpcpp.1
@@ -107,7 +107,7 @@ Automatically scale visualizer size.
For spectrum visualizer, use unicode block characters for a smoother, more continuous look. This will override the visualizer_look option. With transparent terminals and visualizer_in_stereo set, artifacts may be visible on the bottom half of the visualization.
.TP
.B visualizer_spectrum_dft_size = NUMBER
-For spectrum visualizer, a value between 1 and 7 inclusive. Specifying a larger value makes the visualizer look at a larger slice of time, which results in less jumpy visualizer output.
+For spectrum visualizer, a value between 1 and 5 inclusive. Specifying a larger value makes the visualizer look at a larger slice of time, which results in less jumpy visualizer output.
.TP
.B visualizer_spectrum_gain = dB
Gain for spectrum visualizer in dB, larger/smaller values shift bars up/down.
diff --git a/src/screens/visualizer.cpp b/src/screens/visualizer.cpp
index 84655eba..ea28d0b2 100644
--- a/src/screens/visualizer.cpp
+++ b/src/screens/visualizer.cpp
@@ -52,7 +52,7 @@ Visualizer *myVisualizer;
namespace {
-const int fps = 30;
+const size_t fps = 30;
const uint32_t MIN_DFT_SIZE = 14;
// toColor: a scaling function for coloring. For numbers 0 to max this function
@@ -83,16 +83,7 @@ Visualizer::Visualizer()
#endif
{
ResetFD();
-# ifdef HAVE_FFTW3_H
- m_read_samples = DFT_NONZERO_SIZE;
-# else
- m_read_samples = 44100 / fps;
-# endif // HAVE_FFTW3_H
- if (Config.visualizer_in_stereo)
- m_read_samples *= 2;
- m_sample_buffer.resize(m_read_samples, 0);
- m_temp_sample_buffer.resize(m_read_samples, 0);
-
+ SetVisualizationType();
# ifdef HAVE_FFTW3_H
m_fftw_results = DFT_TOTAL_SIZE/2+1;
m_freq_magnitudes.resize(m_fftw_results);
@@ -166,39 +157,8 @@ void Visualizer::update()
m_timer = Global::Timer;
}
- void (Visualizer::*draw)(int16_t *, ssize_t, size_t, size_t);
- void (Visualizer::*drawStereo)(int16_t *, int16_t *, ssize_t, size_t);
-# ifdef HAVE_FFTW3_H
- if (Config.visualizer_type == VisualizerType::Spectrum)
- {
- m_read_samples = DFT_NONZERO_SIZE;
- draw = &Visualizer::DrawFrequencySpectrum;
- drawStereo = &Visualizer::DrawFrequencySpectrumStereo;
- }
- else
-# endif // HAVE_FFTW3_H
- if (Config.visualizer_type == VisualizerType::WaveFilled)
+ if (Config.visualizer_autoscale)
{
- m_read_samples = 44100 / fps;
- draw = &Visualizer::DrawSoundWaveFill;
- drawStereo = &Visualizer::DrawSoundWaveFillStereo;
- }
- else if (Config.visualizer_type == VisualizerType::Ellipse)
- {
- m_read_samples = 44100 / fps;
- draw = &Visualizer::DrawSoundEllipse;
- drawStereo = &Visualizer::DrawSoundEllipseStereo;
- }
- else
- {
- m_read_samples = 44100 / fps;
- draw = &Visualizer::DrawSoundWave;
- drawStereo = &Visualizer::DrawSoundWaveStereo;
- }
- m_sample_buffer.resize(m_read_samples);
- m_temp_sample_buffer.resize(m_read_samples);
-
- if (Config.visualizer_autoscale) {
m_auto_scale_multiplier += 1.0/fps;
for (auto &sample : m_sample_buffer)
{
@@ -634,6 +594,41 @@ void Visualizer::GenLogspace()
}
#endif // HAVE_FFTW3_H
+void Visualizer::SetVisualizationType()
+{
+ switch (Config.visualizer_type)
+ {
+ case VisualizerType::Wave:
+ m_read_samples = std::max(44100 / fps, w.getWidth());
+ draw = &Visualizer::DrawSoundWave;
+ drawStereo = &Visualizer::DrawSoundWaveStereo;
+ break;
+ case VisualizerType::WaveFilled:
+ m_read_samples = std::max(44100 / fps, w.getWidth());
+ draw = &Visualizer::DrawSoundWaveFill;
+ drawStereo = &Visualizer::DrawSoundWaveFillStereo;
+ break;
+# ifdef HAVE_FFTW3_H
+ case VisualizerType::Spectrum:
+ m_read_samples = DFT_NONZERO_SIZE;
+ draw = &Visualizer::DrawFrequencySpectrum;
+ drawStereo = &Visualizer::DrawFrequencySpectrumStereo;
+ break;
+# endif // HAVE_FFTW3_H
+ case VisualizerType::Ellipse:
+ m_read_samples = 44100 / fps;
+ draw = &Visualizer::DrawSoundEllipse;
+ drawStereo = &Visualizer::DrawSoundEllipseStereo;
+ break;
+ }
+ if (Config.visualizer_in_stereo)
+ m_read_samples *= 2;
+ m_sample_buffer.resize(m_read_samples);
+ m_temp_sample_buffer.resize(m_read_samples);
+ std::fill(m_sample_buffer.begin(), m_sample_buffer.end(), 0);
+ std::fill(m_temp_sample_buffer.begin(), m_temp_sample_buffer.end(), 0);
+}
+
/**********************************************************************/
void Visualizer::Clear()
@@ -665,6 +660,7 @@ void Visualizer::ToggleVisualizationType()
Config.visualizer_type = VisualizerType::Wave;
break;
}
+ SetVisualizationType();
Statusbar::printf("Visualization type: %1%", Config.visualizer_type);
}
diff --git a/src/screens/visualizer.h b/src/screens/visualizer.h
index 2c658719..ce2e49fa 100644
--- a/src/screens/visualizer.h
+++ b/src/screens/visualizer.h
@@ -77,6 +77,11 @@ private:
double Interpolate(size_t, size_t);
# endif // HAVE_FFTW3_H
+ void SetVisualizationType();
+
+ void (Visualizer::*draw)(int16_t *, ssize_t, size_t, size_t);
+ void (Visualizer::*drawStereo)(int16_t *, int16_t *, ssize_t, size_t);
+
int m_output_id;
boost::posix_time::ptime m_timer;
diff --git a/src/settings.cpp b/src/settings.cpp
index d65aee73..177a38cb 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -296,13 +296,13 @@ 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,
- "4", [](std::string v) {
+ "3", [](std::string v) {
uint32_t result = verbose_lexical_cast<uint32_t>(v);
- boundsCheck<uint32_t>(result, 1, 7);
+ boundsCheck<uint32_t>(result, 1, 5);
return result + 11;
});
p.add("visualizer_spectrum_gain", &visualizer_spectrum_gain,
- "20", [](std::string v) {
+ "10", [](std::string v) {
auto result = verbose_lexical_cast<double>(v);
boundsCheck<double>(result, 0, 100);
return result;