diff --git a/core/oslib/audiobackend_libao.cpp b/core/oslib/audiobackend_libao.cpp new file mode 100644 index 000000000..1445c1492 --- /dev/null +++ b/core/oslib/audiobackend_libao.cpp @@ -0,0 +1,49 @@ +#include "oslib/audiobackend_libao.h" +#ifdef USE_LIBAO + +#include + +static ao_device *aodevice; +static ao_sample_format aoformat; + +static void libao_init() +{ + ao_initialize(); + memset(&aoformat, 0, sizeof(aoformat)); + + aoformat.bits = 16; + aoformat.channels = 2; + aoformat.rate = 44100; + aoformat.byte_format = AO_FMT_LITTLE; + + aodevice = ao_open_live(ao_default_driver_id(), &aoformat, NULL); // Live output + if (!aodevice) + aodevice = ao_open_live(ao_driver_id("null"), &aoformat, NULL); +} + +static u32 libao_push(void* frame, u32 samples, bool wait) +{ + if (aodevice) + ao_play(aodevice, (char*)frame, samples * 4); + + return 1; +} + +static void libao_term() +{ + if (aodevice) + { + ao_close(aodevice); + ao_shutdown(); + } +} + +audiobackend_t audiobackend_libao = { + "libao", // Slug + "libao", // Name + &libao_init, + &libao_push, + &libao_term +}; + +#endif diff --git a/core/oslib/audiobackend_libao.h b/core/oslib/audiobackend_libao.h new file mode 100644 index 000000000..5bf957286 --- /dev/null +++ b/core/oslib/audiobackend_libao.h @@ -0,0 +1,4 @@ +#pragma once +#include "oslib/audiostream.h" + +extern audiobackend_t audiobackend_libao; diff --git a/core/oslib/audiostream.cpp b/core/oslib/audiostream.cpp index 84c03d8dd..f89e783fb 100644 --- a/core/oslib/audiostream.cpp +++ b/core/oslib/audiostream.cpp @@ -9,6 +9,7 @@ #include "oslib/audiobackend_pulseaudio.h" #include "oslib/audiobackend_coreaudio.h" #include "oslib/audiobackend_omx.h" +#include "oslib/audiobackend_libao.h" struct SoundFrame { s16 l;s16 r; }; #define SAMPLE_COUNT 512 @@ -90,6 +91,9 @@ void RegisterAllAudioBackends() { #if USE_PULSEAUDIO RegisterAudioBackend(&audiobackend_pulseaudio); #endif + #if USE_LIBAO + RegisterAudioBackend(&audiobackend_libao); + #endif #if HOST_OS == OS_DARWIN RegisterAudioBackend(&audiobackend_coreaudio); #endif diff --git a/shell/cmake/CMakeLists.txt b/shell/cmake/CMakeLists.txt index ab8780eed..c5d855c37 100644 --- a/shell/cmake/CMakeLists.txt +++ b/shell/cmake/CMakeLists.txt @@ -18,6 +18,7 @@ endfunction() option(USE_SDL "Use SDL" OFF) option(USE_OSS "Use OSS" ON) option(USE_ALSA "Use ALSA" ON) +option(USE_LIBAO "Use LibAO" OFF) option(USE_GLES "Use GL ES" OFF) option(USE_PULSEAUDIO "Use PulseAudio" OFF) option(USE_WEBUI "Use WebUI" ON) @@ -151,6 +152,11 @@ if(USE_PULSEAUDIO) list(APPEND libs pulse-simple) endif() +if(USE_LIBAO) + add_definitions(-DUSE_LIBAO) + list(APPEND libs ao) +endif() + # Graphic stuffs: if(USE_REND) diff --git a/shell/linux/Makefile b/shell/linux/Makefile index 8c12bf177..1854955a6 100644 --- a/shell/linux/Makefile +++ b/shell/linux/Makefile @@ -5,6 +5,7 @@ FOR_LINUX :=1 WEBUI :=1 USE_OSS := 1 #USE_PULSEAUDIO := 1 +#USE_LIBAO := 1 USE_EVDEV := 1 CXX=${CC_PREFIX}g++ @@ -318,6 +319,11 @@ ifdef USE_PULSEAUDIO LIBS += `pkg-config --libs libpulse-simple` endif +ifdef USE_LIBAO + CXXFLAGS += `pkg-config --cflags ao` -D USE_LIBAO + LIBS += `pkg-config --libs ao` +endif + ifdef HAS_SOFTREND CFLAGS += -fopenmp -msse4.1 LDFLAGS += -fopenmp