diff --git a/SConstruct b/SConstruct index efbf4f31ff..aaeccc236b 100644 --- a/SConstruct +++ b/SConstruct @@ -310,7 +310,7 @@ if sys.platform != 'darwin': if env['openal']: env['HAVE_OPENAL'] = conf.CheckPKG('openal') env['HAVE_PORTAUDIO'] = conf.CheckPortaudio(1890) - #env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse') + env['HAVE_PULSEAUDIO'] = conf.CheckPKG('libpulse') # OpenCL 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_OPENAL', env['HAVE_OPENAL']) conf.Define('HAVE_ALSA', env['HAVE_ALSA']) +conf.Define('HAVE_PULSEAUDIO', env['HAVE_PULSEAUDIO']) conf.Define('HAVE_WX', env['HAVE_WX']) conf.Define('USE_WX', env['USE_WX']) conf.Define('HAVE_X11', env['HAVE_X11']) diff --git a/Source/Core/AudioCommon/Src/PulseAudioStream.cpp b/Source/Core/AudioCommon/Src/PulseAudioStream.cpp index 96d0157dca..321c502b9b 100644 --- a/Source/Core/AudioCommon/Src/PulseAudioStream.cpp +++ b/Source/Core/AudioCommon/Src/PulseAudioStream.cpp @@ -61,11 +61,19 @@ void PulseAudio::Update() // Called on audio thread. void PulseAudio::SoundLoop() { - PulseInit(); + if (!PulseInit()) { + thread_data = 2; + return; + } while (!thread_data) { + int err; int frames_to_deliver = 512; m_mixer->Mix(reinterpret_cast(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(); thread_data = 2; @@ -73,6 +81,22 @@ void PulseAudio::SoundLoop() 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"); return true; } @@ -81,7 +105,7 @@ void PulseAudio::PulseShutdown() { if (handle != NULL) { - + pa_simple_free(handle); handle = NULL; } } diff --git a/Source/Core/AudioCommon/Src/PulseAudioStream.h b/Source/Core/AudioCommon/Src/PulseAudioStream.h index 31cb85bb87..97fd959282 100644 --- a/Source/Core/AudioCommon/Src/PulseAudioStream.h +++ b/Source/Core/AudioCommon/Src/PulseAudioStream.h @@ -18,7 +18,7 @@ #ifndef _PULSE_AUDIO_STREAM_H #define _PULSE_AUDIO_STREAM_H -#if defined(HAVE_PULSE) && HAVE_PULSE +#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO #include #include #include @@ -31,7 +31,7 @@ class PulseAudio : public SoundStream { -#if defined(HAVE_PULSE) && HAVE_PULSE +#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO public: PulseAudio(CMixer *mixer); virtual ~PulseAudio(); @@ -60,7 +60,7 @@ private: // 2 = done shutting down. volatile int thread_data; - snd_pcm_t *handle; + pa_simple *handle; #else public: PulseAudio(CMixer *mixer) : SoundStream(mixer) {}