diff --git a/core/oslib/audiobackend_pulseaudio.cpp b/core/oslib/audiobackend_pulseaudio.cpp new file mode 100644 index 000000000..dea4256cc --- /dev/null +++ b/core/oslib/audiobackend_pulseaudio.cpp @@ -0,0 +1,48 @@ +#include "oslib/audiobackend_pulseaudio.h" +#ifdef USE_PULSEAUDIO +#include +#include +#include +#include + +static pa_simple *pulse_stream; + +static void pulseaudio_init() +{ + pa_sample_spec ss; + ss.format = PA_SAMPLE_S16LE; + ss.channels = 2; + ss.rate = 44100; + /* Create a new playback stream */ + pulse_stream = pa_simple_new(NULL, "reicast", PA_STREAM_PLAYBACK, NULL, "reicast", &ss, NULL, NULL, NULL); + if (!pulse_stream) { + fprintf(stderr, "PulseAudio: pa_simple_new() failed!\n"); + } +} + +static u32 pulseaudio_push(void* frame, u32 samples, bool wait) +{ + if (pa_simple_write(pulse_stream, frame, (size_t) samples*4, NULL) < 0) { + fprintf(stderr, "PulseAudio: pa_simple_write() failed!\n"); + } +} + +static void pulseaudio_term() { + if(pulse_stream != NULL) + { + // Make sure that every single sample was played + if (pa_simple_drain(pulse_stream, NULL) < 0) { + fprintf(stderr, "PulseAudio: pa_simple_drain() failed!\n"); + } + pa_simple_free(pulse_stream); + } +} + +audiobackend_t audiobackend_pulseaudio = { + "pulse", // Slug + "PulseAudio", // Name + &pulseaudio_init, + &pulseaudio_push, + &pulseaudio_term +}; +#endif diff --git a/core/oslib/audiobackend_pulseaudio.h b/core/oslib/audiobackend_pulseaudio.h new file mode 100644 index 000000000..7948d5b16 --- /dev/null +++ b/core/oslib/audiobackend_pulseaudio.h @@ -0,0 +1,4 @@ +#pragma once +#include "oslib/audiostream.h" + +extern audiobackend_t audiobackend_pulseaudio; diff --git a/core/oslib/audiostream.cpp b/core/oslib/audiostream.cpp index 1d983c071..538dd5edb 100644 --- a/core/oslib/audiostream.cpp +++ b/core/oslib/audiostream.cpp @@ -6,6 +6,7 @@ #include "oslib/audiobackend_android.h" #include "oslib/audiobackend_alsa.h" #include "oslib/audiobackend_oss.h" +#include "oslib/audiobackend_pulseaudio.h" struct SoundFrame { s16 l;s16 r; }; #define SAMPLE_COUNT 512 @@ -82,6 +83,9 @@ void RegisterAllAudioBackends() { #if HOST_OS==OS_LINUX && !defined(TARGET_NACL32) && !defined(ANDROID) RegisterAudioBackend(&audiobackend_alsa); #endif + #if USE_PULSEAUDIO + RegisterAudioBackend(&audiobackend_pulseaudio); + #endif audiobackends_registered = true; } diff --git a/shell/lin86/Makefile b/shell/lin86/Makefile index 7d2e02384..91383dad9 100644 --- a/shell/lin86/Makefile +++ b/shell/lin86/Makefile @@ -6,6 +6,7 @@ X86_REC := 1 #NO_REC := 1 #NO_REND := 1 WEBUI :=1 +#USE_PULSEAUDIO := 1 RZDCY_SRC_DIR = ../../core @@ -73,6 +74,11 @@ LIBS += -ldl -lGL #for desktop gl #LIBS += -lEGL -lGLESv2 #-lglslcompiler -lIMGegl -lpvr2d -lsrv_um LIBS += -lpthread -lasound -lX11 +ifdef USE_PULSEAUDIO + CXXFLAGS += -D USE_PULSEAUDIO + LIBS += -lpulse-simple +endif + OBJECTS=$(RZDCY_FILES:.cpp=.build_obj) OBJECTS:=$(OBJECTS:.c=.build_obj)