From 3f31ec42c55b7f5894ff7909558ec8e21bfe5555 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 16 Feb 2014 18:59:35 +0000 Subject: projectm: added multi-channel mode git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4098 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Visual/projectm/projectmplugin.cpp | 48 +++++++++++++++++++++++--- src/plugins/Visual/projectm/projectmplugin.h | 2 ++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/plugins/Visual/projectm/projectmplugin.cpp b/src/plugins/Visual/projectm/projectmplugin.cpp index 37af68d86..94468d101 100644 --- a/src/plugins/Visual/projectm/projectmplugin.cpp +++ b/src/plugins/Visual/projectm/projectmplugin.cpp @@ -40,6 +40,8 @@ ProjectMPlugin::ProjectMPlugin (QWidget *parent) setlocale(LC_NUMERIC, "C"); //fixes problem with none-english locales setWindowTitle(tr("ProjectM")); + m_buf = 0; + m_buf_size = 0; QListWidget *listWidget = new QListWidget(this); listWidget->setAlternatingRowColors(true); m_projectMWidget = new ProjectMWidget(listWidget, this); @@ -63,7 +65,10 @@ ProjectMPlugin::ProjectMPlugin (QWidget *parent) } ProjectMPlugin::~ProjectMPlugin() -{} +{ + if(m_buf) + free(m_buf); +} void ProjectMPlugin::clear() { @@ -80,10 +85,43 @@ void ProjectMPlugin::setFullScreen(bool yes) void ProjectMPlugin::add (unsigned char *data, qint64 size, int chan) { - Q_UNUSED(chan); - //TODO multichannel support - if (m_projectMWidget->projectMInstance()) - m_projectMWidget->projectMInstance()->pcm()->addPCM16Data((short *)data, size/4); + projectM *instance = m_projectMWidget->projectMInstance(); + if (!instance) + return; + if(chan == 2) + m_projectMWidget->projectMInstance()->pcm()->addPCM16Data((short *)data, size >> 2); + else + { + int samples = size / chan / 2; //number of samples for each channel (16 bit) + if(m_buf_size < samples * 4) //requied bytes + { + m_buf = (short*)realloc(m_buf, samples * 4); + m_buf_size = samples * 4; + } + short *in_buf = (short *)data; + + if(chan == 1) + { + //convert mono to stereo + for(int i = 0; i < samples; ++i) + { + ((short *)m_buf)[i*2] = in_buf[0]; + ((short *)m_buf)[i*2+1] = in_buf[0]; + in_buf++; + } + } + else + { + //convert multi-channel to stereo + for(int i = 0; i < samples; ++i) + { + ((short*)m_buf)[i*2] = in_buf[0]; + ((short*)m_buf)[i*2+1] = in_buf[1]; + in_buf += chan; + } + } + m_projectMWidget->projectMInstance()->pcm()->addPCM16Data(m_buf, samples); + } } void ProjectMPlugin::closeEvent (QCloseEvent *event) diff --git a/src/plugins/Visual/projectm/projectmplugin.h b/src/plugins/Visual/projectm/projectmplugin.h index 3a53bae36..99a7fc649 100644 --- a/src/plugins/Visual/projectm/projectmplugin.h +++ b/src/plugins/Visual/projectm/projectmplugin.h @@ -46,6 +46,8 @@ private: QTimer *m_timer; ProjectMWidget *m_projectMWidget; QSplitter *m_splitter; + short *m_buf; + int m_buf_size; }; -- cgit v1.2.3-13-gbd6f