- refactored pulseaudio port, cleanup left

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@700 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
w1z7ard
2007-11-11 22:54:37 +00:00
parent 4ef0b06763
commit 296ff3a8a3
4 changed files with 117 additions and 91 deletions

View File

@ -12,20 +12,18 @@ pkg_search_module(PROJECTM REQUIRED projectM qprojectM)
#pkg_search_module(PULSE_AUDIO REQUIRED pulseaudio)
# the variable "qprojectM_SRCS" contains all .cpp files of this project
set(qprojectM_pulseaudio_SRCS
qprojectM-pulseaudio.cpp ConfigFile.h ConfigFile.cpp
qprojectM-pulseaudio.cpp ConfigFile.h ConfigFile.cpp QPulseAudioThread.cpp
)
set(qprojectM_pulseaudio_MOC_HDRS
QPulseAudioThread.hpp
)
# After this call, foo_MOC_SRCS = moc_Class1.cxx moc_Class2.cxx moc_Class3.cxx.
qt4_wrap_cpp(qprojectM_pulseaudio_MOC_SRCS ${qprojectM_MOC_HDRS})
qt4_wrap_cpp(qprojectM_pulseaudio_MOC_SRCS ${qprojectM_pulseaudio_MOC_HDRS})
ADD_DEFINITIONS(-DLINUX -DPROJECTM_PREFIX='"${PROJECTM_PREFIX}"')
ADD_DEFINITIONS(${QT_DEFINITIONS})

View File

@ -0,0 +1,74 @@
#include "QPulseAudio.hpp"
#include <QtDebug>
#include "libprojectM/projectM.hpp"
#define BUFSIZE 1024
PulseAudioThread::PulseAudioThread(int _argc, char **_argv, projectM * _projectM, QObject * parent) : QThread(parent), argc(_argc), argv(_argv), s(0) , m_projectM(_projectM) {
m_timer = new QTimer(this);
}
void PulseAudioThread::cleanup() {
if ( s )
pa_simple_free ( s );
s = 0;
qDebug() << "pulse audio quit";
return ;
}
void PulseAudioThread::init() {
ss.format = PA_SAMPLE_FLOAT32LE;
ss.rate = 44100;
ss.channels = 2;
int ret = 1;
int error;
/* Create the recording stream */
if ( ! ( s = pa_simple_new ( NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error ) ) )
{
fprintf ( stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror ( error ) );
return;//RETURthis->exit(error);
}
}
void PulseAudioThread::updatePCM() {
//qDebug() << "pulse audio loop";
float buf[BUFSIZE];
ssize_t r;
int error;
qDebug() << "HERE";
/* Record some data ... */
if ( pa_simple_read ( s, buf, sizeof(buf), &error ) < 0 )
{
fprintf ( stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror ( error ) );
return; //this->exit(error);
}
qDebug() << "HERE";
m_projectM->pcm->addPCMfloat(buf, BUFSIZE);
}
PulseAudioThread::~PulseAudioThread()
{
cleanup();
}
void PulseAudioThread::run()
{
init();
connect(m_timer, SIGNAL(timeout()), this, SLOT(updatePCM()));
m_timer->start(0);
//exec();
}

View File

@ -0,0 +1,33 @@
#ifndef PULSE_AUDIO_THREAD
#include <QObject>
#include <QTimer>
#include <QThread>
class projectM;
#include <pulse/simple.h>
#include <pulse/error.h>
class PulseAudioThread : public QThread
{
Q_OBJECT
public:
PulseAudioThread () {}
PulseAudioThread(int _argc, char **_argv, projectM * projectM, QObject *parent);
~PulseAudioThread() ;
void run();
void cleanup();
private:
void init();
int argc;
char ** argv;
QTimer * m_timer;
pa_sample_spec ss ;
pa_simple * s ;
projectM * m_projectM;
public slots:
void updatePCM();
};
#endif

View File

@ -1,3 +1,4 @@
/**
* projectM -- Milkdrop-esque visualisation SDK
* Copyright (C)2003-2004 projectM Team
@ -55,7 +56,7 @@
#include <unistd.h>
#include <QThread>
#include <QTimer>
#define CONFIG_FILE "/share/projectM/config.inp"
std::string read_config();
@ -68,14 +69,9 @@ std::string read_config();
#include <string.h>
#include <errno.h>
#include <pulse/simple.h>
#include <pulse/error.h>
//#include <pulsecore/gccmacro.h>
#define BUFSIZE 1024
projectM *globalPM = NULL;
#include "QPulseAudioThread.hpp"
int dumpFrame = 0;
int frameNumber = 0;
@ -100,72 +96,7 @@ static ssize_t loop_write ( const float * data, size_t size )
class PulseAudioThread: public QThread
{
public:
PulseAudioThread(int _argc, char **_argv, QProjectM_MainWindow * window) : QThread(window), argc(_argc), argv(_argv), m_window(window) ,notStopped(true){}
void run();;
private:
int argc;
char ** argv;
QProjectM_MainWindow * m_window;
bool notStopped;
};
void PulseAudioThread::run()
{
/* The sample type to use */
static pa_sample_spec ss ;
//ss.format = PA_SAMPLE_FLOAT32;
ss.format = PA_SAMPLE_FLOAT32LE;
ss.rate = 44100;
ss.channels = 2;
pa_simple *s = NULL;
int ret = 1;
int error;
qDebug() << "here!";
/* Create the recording stream */
if ( ! ( s = pa_simple_new ( NULL, argv[0], PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error ) ) )
{
fprintf ( stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror ( error ) );
goto finish;
}
while (notStopped)
{
//qDebug() << "pulse audio loop";
float buf[BUFSIZE];
ssize_t r;
/* Record some data ... */
if ( pa_simple_read ( s, buf, sizeof(buf), &error ) < 0 )
{
fprintf ( stderr, __FILE__": pa_simple_read() failed: %s\n", pa_strerror ( error ) );
goto finish;
}
globalPM->pcm->addPCMfloat(buf, BUFSIZE);
}
ret = 0;
finish:
if ( s )
pa_simple_free ( s );
qDebug() << "pulse audio quit";
return ;
}
int main ( int argc, char*argv[] )
{
@ -180,15 +111,13 @@ int main ( int argc, char*argv[] )
QProjectM_MainWindow * mainWindow = new QProjectM_MainWindow ( config_file );
globalPM = mainWindow->getQProjectM();
mainWindow->show();
globalPM = mainWindow->getQProjectM();
PulseAudioThread * pulseThread = new PulseAudioThread(argc, argv, mainWindow);
PulseAudioThread * pulseThread = new PulseAudioThread(argc, argv, mainWindow->getQProjectM(), mainWindow);
pulseThread->start();
return app.exec();
qDebug() << "app exec";
return app.exec();
}
@ -277,12 +206,4 @@ std::string read_config()
abort();
}
int
process ( void *arg )
{
// globalPM->pcm->addPCMfloat(in,nframes);
// printf("%x %f\n",nframes,in[128]);
return 0;
}