Implement pulseaudio output. It is rather crude but seems to work.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5626 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-06-06 04:02:16 +00:00
parent 5341bbad3a
commit 9c3c7c5443
3 changed files with 31 additions and 6 deletions

View File

@ -310,7 +310,7 @@ if sys.platform != 'darwin':
if env['openal']: if env['openal']:
env['HAVE_OPENAL'] = conf.CheckPKG('openal') env['HAVE_OPENAL'] = conf.CheckPKG('openal')
env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890) env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890)
#env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse') env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse')
# OpenCL # OpenCL
env['HAVE_OPENCL'] = 0 env['HAVE_OPENCL'] = 0
@ -419,6 +419,7 @@ conf.Define('HAVE_AO', env['HAVE_AO'])
conf.Define('HAVE_OPENCL', env['HAVE_OPENCL']) conf.Define('HAVE_OPENCL', env['HAVE_OPENCL'])
conf.Define('HAVE_OPENAL', env['HAVE_OPENAL']) conf.Define('HAVE_OPENAL', env['HAVE_OPENAL'])
conf.Define('HAVE_ALSA', env['HAVE_ALSA']) conf.Define('HAVE_ALSA', env['HAVE_ALSA'])
conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO'])
conf.Define('HAVE_WX', env['HAVE_WX']) conf.Define('HAVE_WX', env['HAVE_WX'])
conf.Define('USE_WX', env['USE_WX']) conf.Define('USE_WX', env['USE_WX'])
conf.Define('HAVE_X11', env['HAVE_X11']) conf.Define('HAVE_X11', env['HAVE_X11'])

View File

@ -61,11 +61,19 @@ void PulseAudio::Update()
// Called on audio thread. // Called on audio thread.
void PulseAudio::SoundLoop() void PulseAudio::SoundLoop()
{ {
PulseInit(); if (!PulseInit()) {
thread_data = 2;
return;
}
while (!thread_data) while (!thread_data)
{ {
int err;
int frames_to_deliver = 512; int frames_to_deliver = 512;
m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver); m_mixer->Mix(reinterpret_cast<short *>(mix_buffer), frames_to_deliver);
if (pa_simple_write(handle, mix_buffer, frames_to_deliver * 2 * 2, &err) < 0)
{
ERROR_LOG(AUDIO, "pa_simple_write fail: %s", pa_strerror(err));
}
} }
PulseShutdown(); PulseShutdown();
thread_data = 2; thread_data = 2;
@ -73,6 +81,22 @@ void PulseAudio::SoundLoop()
bool PulseAudio::PulseInit() bool PulseAudio::PulseInit()
{ {
// The Sample format to use
static const pa_sample_spec ss = {
PA_SAMPLE_S16LE,
m_mixer->GetSampleRate(),
2
};
int err;
if (!(handle = pa_simple_new(NULL, "dolphin-emu", PA_STREAM_PLAYBACK, NULL,
"emulator", &ss, NULL, NULL, &err)))
{
ERROR_LOG(AUDIO, "PulseAudio open error: %s\n", pa_strerror(err));
return false;
}
NOTICE_LOG(AUDIO, "Pulse successfully initialized.\n"); NOTICE_LOG(AUDIO, "Pulse successfully initialized.\n");
return true; return true;
} }
@ -81,7 +105,7 @@ void PulseAudio::PulseShutdown()
{ {
if (handle != NULL) if (handle != NULL)
{ {
pa_simple_free(handle);
handle = NULL; handle = NULL;
} }
} }

View File

@ -18,7 +18,7 @@
#ifndef _PULSE_AUDIO_STREAM_H #ifndef _PULSE_AUDIO_STREAM_H
#define _PULSE_AUDIO_STREAM_H #define _PULSE_AUDIO_STREAM_H
#if defined(HAVE_PULSE) && HAVE_PULSE #if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
#include <pulse/simple.h> #include <pulse/simple.h>
#include <pulse/error.h> #include <pulse/error.h>
#include <pulse/gccmacro.h> #include <pulse/gccmacro.h>
@ -31,7 +31,7 @@
class PulseAudio : public SoundStream class PulseAudio : public SoundStream
{ {
#if defined(HAVE_PULSE) && HAVE_PULSE #if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
public: public:
PulseAudio(CMixer *mixer); PulseAudio(CMixer *mixer);
virtual ~PulseAudio(); virtual ~PulseAudio();
@ -60,7 +60,7 @@ private:
// 2 = done shutting down. // 2 = done shutting down.
volatile int thread_data; volatile int thread_data;
snd_pcm_t *handle; pa_simple *handle;
#else #else
public: public:
PulseAudio(CMixer *mixer) : SoundStream(mixer) {} PulseAudio(CMixer *mixer) : SoundStream(mixer) {}