aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Visual/projectm/projectmplugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Visual/projectm/projectmplugin.cpp')
-rw-r--r--src/plugins/Visual/projectm/projectmplugin.cpp54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/plugins/Visual/projectm/projectmplugin.cpp b/src/plugins/Visual/projectm/projectmplugin.cpp
index 583f3650b..18bed4bcc 100644
--- a/src/plugins/Visual/projectm/projectmplugin.cpp
+++ b/src/plugins/Visual/projectm/projectmplugin.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2014 by Ilya Kotov *
+ * Copyright (C) 2009-2015 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -41,9 +41,6 @@ ProjectMPlugin::ProjectMPlugin (QWidget *parent)
setWindowTitle(tr("ProjectM"));
setWindowIcon(parent->windowIcon());
- m_buf = 0;
- m_buf_size = 0;
-
m_splitter = new QSplitter(Qt::Horizontal, this);
QListWidget *listWidget = new QListWidget(m_splitter);
listWidget->setAlternatingRowColors(true);
@@ -68,10 +65,7 @@ ProjectMPlugin::ProjectMPlugin (QWidget *parent)
}
ProjectMPlugin::~ProjectMPlugin()
-{
- if(m_buf)
- free(m_buf);
-}
+{}
void ProjectMPlugin::clear()
{
@@ -86,45 +80,33 @@ void ProjectMPlugin::setFullScreen(bool yes)
setWindowState(windowState() & ~Qt::WindowFullScreen);
}
-void ProjectMPlugin::add (unsigned char *data, qint64 size, int chan)
+void ProjectMPlugin::add (float *data, size_t samples, int chan)
{
projectM *instance = m_projectMWidget->projectMInstance();
if (!instance)
return;
- if(chan == 2)
- m_projectMWidget->projectMInstance()->pcm()->addPCM16Data((short *)data, size >> 2);
- else
+
+ size_t frames = qMin(samples / chan, (size_t)512);
+
+ if(chan == 1)
{
- int samples = size / chan / 2; //number of samples for each channel (16 bit)
- if(m_buf_size < samples * 4) //requied bytes
+ for(size_t i = 0; i <= frames; i++)
{
- m_buf = (short*)realloc(m_buf, samples * 4);
- m_buf_size = samples * 4;
+ m_buf[0][i] = data[i*chan] * 32767.0;
+ m_buf[1][i] = data[i*chan] * 32767.0;
}
- 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
+ }
+ else
+ {
+ for(size_t i = 0; i <= frames; i++)
{
- //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_buf[0][i] = data[i*chan] * 32767.0;
+ m_buf[1][i] = data[i*chan+1] * 32767.0;
}
- m_projectMWidget->projectMInstance()->pcm()->addPCM16Data(m_buf, samples);
}
+
+ m_projectMWidget->projectMInstance()->pcm()->addPCM16(m_buf);
}
void ProjectMPlugin::closeEvent (QCloseEvent *event)