new visualization type: sound wave
This commit is contained in:
@@ -34,6 +34,8 @@
|
|||||||
#
|
#
|
||||||
#visualizer_fifo_path = ""
|
#visualizer_fifo_path = ""
|
||||||
#
|
#
|
||||||
|
#visualizer_type = "spectrum" (spectrum/wave)
|
||||||
|
#
|
||||||
##### system encoding #####
|
##### system encoding #####
|
||||||
##
|
##
|
||||||
## if you use encoding other than utf8, set it in
|
## if you use encoding other than utf8, set it in
|
||||||
|
|||||||
@@ -66,9 +66,12 @@ Set connection timeout to MPD to given value.
|
|||||||
.B mpd_crossfade_time = SECONDS
|
.B mpd_crossfade_time = SECONDS
|
||||||
Default number of seconds to crossfade, if enabled by ncmpcpp.
|
Default number of seconds to crossfade, if enabled by ncmpcpp.
|
||||||
.TP
|
.TP
|
||||||
.B fifo_visualizer_path = PATH
|
.B visualizer_fifo_path = PATH
|
||||||
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
|
||||||
|
Defines default visualizer type.
|
||||||
|
.TP
|
||||||
.B system_encoding = ENCODING
|
.B system_encoding = ENCODING
|
||||||
If you use encoding other than utf8, set it in order to handle utf8 encoded strings properly.
|
If you use encoding other than utf8, set it in order to handle utf8 encoded strings properly.
|
||||||
.TP
|
.TP
|
||||||
|
|||||||
@@ -298,6 +298,12 @@ void Help::GetKeybindings()
|
|||||||
# endif // ENABLE_OUTPUTS
|
# endif // ENABLE_OUTPUTS
|
||||||
|
|
||||||
|
|
||||||
|
# ifdef ENABLE_VISUALIZER
|
||||||
|
*w << "\n\n " << fmtBold << "Keys - Music visualizer\n -----------------------------------------\n" << fmtBoldEnd;
|
||||||
|
*w << DisplayKeys(Key.Space) << "Toggle visualization type\n";
|
||||||
|
# endif // ENABLE_VISUALIZER
|
||||||
|
|
||||||
|
|
||||||
*w << "\n\n " << fmtBold << "Mouse - Global\n -----------------------------------------\n" << fmtBoldEnd;
|
*w << "\n\n " << fmtBold << "Mouse - Global\n -----------------------------------------\n" << fmtBoldEnd;
|
||||||
*w << "\tLeft click on \"Playing/Paused\" " << ": Play/pause\n";
|
*w << "\tLeft click on \"Playing/Paused\" " << ": Play/pause\n";
|
||||||
*w << "\tLeft click on progressbar " << ": Go to chosen position in played track\n";
|
*w << "\tLeft click on progressbar " << ": Go to chosen position in played track\n";
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
|
|||||||
conf.ask_before_clearing_main_playlist = false;
|
conf.ask_before_clearing_main_playlist = false;
|
||||||
conf.mouse_support = true;
|
conf.mouse_support = true;
|
||||||
conf.new_design = false;
|
conf.new_design = false;
|
||||||
|
conf.visualizer_use_wave = false;
|
||||||
conf.set_window_title = true;
|
conf.set_window_title = true;
|
||||||
conf.mpd_port = 6600;
|
conf.mpd_port = 6600;
|
||||||
conf.mpd_connection_timeout = 15;
|
conf.mpd_connection_timeout = 15;
|
||||||
@@ -789,6 +790,10 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
|||||||
{
|
{
|
||||||
conf.ask_before_clearing_main_playlist = v == "yes";
|
conf.ask_before_clearing_main_playlist = v == "yes";
|
||||||
}
|
}
|
||||||
|
else if (cl.find("visualizer_type") != std::string::npos)
|
||||||
|
{
|
||||||
|
conf.visualizer_use_wave = v == "wave";
|
||||||
|
}
|
||||||
else if (cl.find("mouse_support") != std::string::npos)
|
else if (cl.find("mouse_support") != std::string::npos)
|
||||||
{
|
{
|
||||||
conf.mouse_support = v == "yes";
|
conf.mouse_support = v == "yes";
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ struct ncmpcpp_config
|
|||||||
bool ask_before_clearing_main_playlist;
|
bool ask_before_clearing_main_playlist;
|
||||||
bool mouse_support;
|
bool mouse_support;
|
||||||
bool new_design;
|
bool new_design;
|
||||||
|
bool visualizer_use_wave;
|
||||||
|
|
||||||
int mpd_port;
|
int mpd_port;
|
||||||
int mpd_connection_timeout;
|
int mpd_connection_timeout;
|
||||||
|
|||||||
@@ -102,6 +102,37 @@ void Visualizer::Update()
|
|||||||
if (data < 0) // no data available in fifo
|
if (data < 0) // no data available in fifo
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
w->Clear(0);
|
||||||
|
Config.visualizer_use_wave ? DrawSoundWave(buf, data) : DrawFrequencySpectrum(buf, data);
|
||||||
|
w->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Visualizer::SpacePressed()
|
||||||
|
{
|
||||||
|
Config.visualizer_use_wave = !Config.visualizer_use_wave;
|
||||||
|
ShowMessage("Visualization type: %s", Config.visualizer_use_wave ? "Sound wave" : "Frequency spectrum");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Visualizer::DrawSoundWave(int16_t *buf, ssize_t data)
|
||||||
|
{
|
||||||
|
const int samples_per_col = data/sizeof(int16_t)/COLS;
|
||||||
|
const int half_height = MainHeight/2;
|
||||||
|
*w << fmtAltCharset;
|
||||||
|
for (int i = 0; i < COLS; ++i)
|
||||||
|
{
|
||||||
|
double point_pos = 0;
|
||||||
|
for (int j = 0; j < samples_per_col; ++j)
|
||||||
|
point_pos += buf[i*samples_per_col+j];
|
||||||
|
point_pos /= samples_per_col;
|
||||||
|
point_pos /= std::numeric_limits<int16_t>::max();
|
||||||
|
point_pos *= half_height;
|
||||||
|
*w << XY(i, half_height+point_pos) << '`';
|
||||||
|
}
|
||||||
|
*w << fmtAltCharsetEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t data)
|
||||||
|
{
|
||||||
// zero old values
|
// zero old values
|
||||||
std::fill(buf+data/sizeof(int16_t), buf+Samples, 0);
|
std::fill(buf+data/sizeof(int16_t), buf+Samples, 0);
|
||||||
for (unsigned i = 0; i < Samples; ++i)
|
for (unsigned i = 0; i < Samples; ++i)
|
||||||
@@ -113,17 +144,15 @@ void Visualizer::Update()
|
|||||||
for (unsigned i = 0; i < FFTResults; ++i)
|
for (unsigned i = 0; i < FFTResults; ++i)
|
||||||
itsFreqsMagnitude[i] = sqrt(itsOutput[i][0]*itsOutput[i][0] + itsOutput[i][1]*itsOutput[i][1])/1e5*LINES/5;
|
itsFreqsMagnitude[i] = sqrt(itsOutput[i][0]*itsOutput[i][0] + itsOutput[i][1]*itsOutput[i][1])/1e5*LINES/5;
|
||||||
|
|
||||||
w->Clear(0);
|
|
||||||
const int freqs_per_col = FFTResults/COLS /* cut bandwidth a little to achieve better look */ * 4/5;
|
const int freqs_per_col = FFTResults/COLS /* cut bandwidth a little to achieve better look */ * 4/5;
|
||||||
for (int i = 0; i < COLS; ++i)
|
for (int i = 0; i < COLS; ++i)
|
||||||
{
|
{
|
||||||
size_t bar_height = 0;
|
size_t bar_height = 0;
|
||||||
for (int j = 0; j < freqs_per_col; ++j)
|
for (int j = 0; j < freqs_per_col; ++j)
|
||||||
bar_height += itsFreqsMagnitude[i*freqs_per_col+j];
|
bar_height += itsFreqsMagnitude[i*freqs_per_col+j];
|
||||||
bar_height = std::min(bar_height/freqs_per_col, Global::MainHeight);
|
bar_height = std::min(bar_height/freqs_per_col, MainHeight);
|
||||||
mvwvline(w->Raw(), Global::MainHeight-bar_height, i, 0, bar_height);
|
mvwvline(w->Raw(), MainHeight-bar_height, i, 0, bar_height);
|
||||||
}
|
}
|
||||||
w->Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Visualizer::SetFD()
|
void Visualizer::SetFD()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class Visualizer : public Screen<Window>
|
|||||||
virtual void Scroll(Where, const int *) { }
|
virtual void Scroll(Where, const int *) { }
|
||||||
|
|
||||||
virtual void EnterPressed() { }
|
virtual void EnterPressed() { }
|
||||||
virtual void SpacePressed() { }
|
virtual void SpacePressed();
|
||||||
virtual void MouseButtonPressed(MEVENT) { }
|
virtual void MouseButtonPressed(MEVENT) { }
|
||||||
|
|
||||||
virtual NCurses::List *GetList() { return 0; }
|
virtual NCurses::List *GetList() { return 0; }
|
||||||
@@ -58,6 +58,9 @@ class Visualizer : public Screen<Window>
|
|||||||
virtual void Init();
|
virtual void Init();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void DrawSoundWave(int16_t *, ssize_t);
|
||||||
|
void DrawFrequencySpectrum(int16_t *, ssize_t);
|
||||||
|
|
||||||
int itsFifo;
|
int itsFifo;
|
||||||
unsigned *itsFreqsMagnitude;
|
unsigned *itsFreqsMagnitude;
|
||||||
double *itsInput;
|
double *itsInput;
|
||||||
|
|||||||
Reference in New Issue
Block a user