provide a way to sync between visualization and sound

workaround for http://musicpd.org/mantis/view.php?id=2503
This commit is contained in:
Andrzej Rybczak
2009-10-27 02:15:51 +01:00
parent 164d32c079
commit e43ea18d29
6 changed files with 46 additions and 1 deletions

View File

@@ -35,6 +35,16 @@
#visualizer_fifo_path = "" #visualizer_fifo_path = ""
# #
## ##
## Note: Below parameter is needed for ncmpcpp
## to determine which output provides data for
## visualizer and thus allow syncing between
## visualization and sound as currently there
## are some problems with it.
##
#
#visualizer_output_name = ""
#
##
## Note: To enable spectrum frequency visualization ## Note: To enable spectrum frequency visualization
## you need to compile ncmpcpp with fftw3 support. ## you need to compile ncmpcpp with fftw3 support.
## ##

View File

@@ -70,6 +70,9 @@ Set connection timeout to MPD to given value.
Default number of seconds to crossfade, if enabled by ncmpcpp. Default number of seconds to crossfade, if enabled by ncmpcpp.
.TP .TP
.B visualizer_fifo_path = PATH .B visualizer_fifo_path = PATH
Name of output that provides data for visualizer. Needed to keep sound and visualization in sync.
.TP
.B visualizer_output_name = NAME
Path to mpd fifo output. This is needed to make music visualizer work (note that output sound format of this fifo has to be 44100:16:1) Path to mpd fifo output. This is needed to make music visualizer work (note that output sound format of this fifo has to be 44100:16:1)
.TP .TP
.B visualizer_type = spectrum/wave .B visualizer_type = spectrum/wave

View File

@@ -521,11 +521,16 @@ void ReadConfiguration(ncmpcpp_config &conf)
conf.mpd_music_dir = v + "/"; conf.mpd_music_dir = v + "/";
} }
} }
if (cl.find("visualizer_fifo_path") != std::string::npos) else if (cl.find("visualizer_fifo_path") != std::string::npos)
{ {
if (!v.empty()) if (!v.empty())
conf.visualizer_fifo_path = v; conf.visualizer_fifo_path = v;
} }
else if (cl.find("visualizer_output_name") != std::string::npos)
{
if (!v.empty())
conf.visualizer_output_name = v;
}
else if (cl.find("mpd_port") != std::string::npos) else if (cl.find("mpd_port") != std::string::npos)
{ {
if (StrToInt(v)) if (StrToInt(v))

View File

@@ -131,6 +131,7 @@ struct ncmpcpp_config
std::string mpd_host; std::string mpd_host;
std::string mpd_music_dir; std::string mpd_music_dir;
std::string visualizer_fifo_path; std::string visualizer_fifo_path;
std::string visualizer_output_name;
std::string empty_tag; std::string empty_tag;
std::string song_list_columns_format; std::string song_list_columns_format;
std::string song_list_format; std::string song_list_format;

View File

@@ -29,6 +29,7 @@
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h>
using Global::myScreen; using Global::myScreen;
using Global::MainStartY; using Global::MainStartY;
@@ -53,6 +54,18 @@ void Visualizer::Init()
itsPlan = fftw_plan_dft_r2c_1d(Samples, itsInput, itsOutput, FFTW_ESTIMATE); itsPlan = fftw_plan_dft_r2c_1d(Samples, itsInput, itsOutput, FFTW_ESTIMATE);
# endif // HAVE_FFTW3_H # endif // HAVE_FFTW3_H
itsOutputID = -1;
if (!Config.visualizer_output_name.empty())
{
MPD::OutputList outputs;
Mpd.GetOutputs(outputs);
for (unsigned i = 0; i < outputs.size(); ++i)
if (outputs[i].first == Config.visualizer_output_name)
itsOutputID = i;
if (itsOutputID == -1)
ShowMessage("There is no output named \"%s\"!", Config.visualizer_output_name.c_str());
}
isInitialized = 1; isInitialized = 1;
} }
@@ -72,6 +85,9 @@ void Visualizer::SwitchTo()
SetFD(); SetFD();
itsTimer.tv_sec = 0;
itsTimer.tv_usec = 0;
if (itsFifo >= 0) if (itsFifo >= 0)
Global::wFooter->SetTimeout(1000/25); Global::wFooter->SetTimeout(1000/25);
Global::RedrawHeader = 1; Global::RedrawHeader = 1;
@@ -101,6 +117,13 @@ void Visualizer::Update()
return; return;
} }
if (itsOutputID != -1 && Global::Timer.tv_sec > itsTimer.tv_sec+5)
{
Mpd.DisableOutput(itsOutputID);
Mpd.EnableOutput(itsOutputID);
gettimeofday(&itsTimer, 0);
}
// it supports only PCM in format 44100:16:1 // it supports only PCM in format 44100:16:1
static int16_t buf[Samples]; static int16_t buf[Samples];
ssize_t data = read(itsFifo, buf, sizeof(buf)); ssize_t data = read(itsFifo, buf, sizeof(buf));

View File

@@ -65,6 +65,9 @@ class Visualizer : public Screen<Window>
void DrawFrequencySpectrum(int16_t *, ssize_t); void DrawFrequencySpectrum(int16_t *, ssize_t);
# endif // HAVE_FFTW3_H # endif // HAVE_FFTW3_H
int itsOutputID;
timeval itsTimer;
int itsFifo; int itsFifo;
# ifdef HAVE_FFTW3_H # ifdef HAVE_FFTW3_H
unsigned *itsFreqsMagnitude; unsigned *itsFreqsMagnitude;