Added PulseAudio backend
This commit introduces PulseAudio support using PulseAudio's "Simple API". The PulseAudio backend will be included during compilation if USE_PULSEAUDIO is defined.
This commit is contained in:
parent
c17c7502d8
commit
a9771c918d
|
@ -0,0 +1,48 @@
|
|||
#include "oslib/audiobackend_pulseaudio.h"
|
||||
#ifdef USE_PULSEAUDIO
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <pulse/simple.h>
|
||||
|
||||
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
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_pulseaudio;
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue