summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am11
-rw-r--r--src/device.cpp15
-rw-r--r--src/device_sdl.cpp84
-rw-r--r--src/device_sdl.h34
4 files changed, 143 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 753c381..e99cee2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,6 +89,14 @@ COREAUDIO_DIST = device_coreaudio.cpp \
device_coreaudio.h
endif
+if HAVE_SDL
+SDL_SOURCES = device_sdl.cpp \
+ device_sdl.h
+else
+SDL_DIST = device_sdl.cpp \
+ device_sdl.h
+endif
+
ANDROIDAUDIO_DIST = device_android.cpp device_android.h
# Automake blows.
@@ -133,7 +141,7 @@ EXTRA_DIST = \
$(FLAC_DIST) $(DUMB_DIST) $(OGG_DIST) $(SPEEX_DIST) $(AL_DIST) \
$(OSS_DIST) $(DSOUND_DIST) $(WINMM_DIST) $(COREAUDIO_DIST) \
$(ALSA_DIST) $(NEXUS_DIST) $(ZTE_DIST) $(ANDROIDAUDIO_DIST) \
- $(MIDI_DIST) $(THREADS_DIST) $(EXTERN_DIST)
+ $(SDL_DIST) $(MIDI_DIST) $(THREADS_DIST) $(EXTERN_DIST)
libaudiere_la_SOURCES = \
$(MIDI_SOURCES) \
@@ -160,6 +168,7 @@ libaudiere_la_SOURCES = \
$(OSS_SOURCES) \
$(WINMM_SOURCES) \
$(COREAUDIO_SOURCES) \
+ $(SDL_SOURCES) \
dumb_resample.cpp \
dumb_resample.h \
file_ansi.cpp \
diff --git a/src/device.cpp b/src/device.cpp
index 991058c..5438ade 100644
--- a/src/device.cpp
+++ b/src/device.cpp
@@ -60,6 +60,10 @@
#include "device_android.h"
#endif
+#ifdef HAVE_SDL
+ #include "device_sdl.h"
+#endif
+
namespace audiere {
AbstractDevice::AbstractDevice() {
@@ -202,6 +206,9 @@ namespace audiere {
#ifdef HAVE_CORE_AUDIO
"coreaudio:Core Audio (Mac OS X)"
#endif
+#ifdef HAVE_SDL
+ "sdl:Simple Direct layer"
+#endif
#endif
"null:Null output (no sound)" ;
}
@@ -267,6 +274,7 @@ namespace audiere {
TRY_GROUP("nexus");
TRY_GROUP("oss");
TRY_GROUP("coreaudio");
+ TRY_GROUP("sdl");
return 0;
}
@@ -340,6 +348,13 @@ namespace audiere {
}
#endif
+ #ifdef HAVE_SDL
+ if (name == "sdl") {
+ TRY_DEVICE(SDLAudioDevice);
+ return 0;
+ }
+ #endif
+
if (name == "null") {
TRY_DEVICE(NullAudioDevice);
return 0;
diff --git a/src/device_sdl.cpp b/src/device_sdl.cpp
new file mode 100644
index 0000000..042c4dd
--- /dev/null
+++ b/src/device_sdl.cpp
@@ -0,0 +1,84 @@
+#include <algorithm>
+#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "device_sdl.h"
+#include "debug.h"
+
+
+namespace audiere {
+
+ SDLAudioDevice*
+ SDLAudioDevice::create(const ParameterList& parameters) {
+
+ SDL_AudioSpec aspec;
+ aspec.format = AUDIO_S16LSB;
+ aspec.freq = 44100;
+ aspec.channels = 2;
+ aspec.samples = 1024;
+ aspec.callback = &SDLAudioDevice::outputCallback;
+
+ SDLAudioDevice* device = new SDLAudioDevice(aspec.freq, 4096);
+ aspec.userdata = device;
+
+ if (SDL_Init(SDL_INIT_AUDIO) < 0) {
+ ADR_LOG("Unable init sdl audio subsystem.\n");
+ delete device;
+ return 0;
+ }
+
+ SDL_AudioSpec obtained;
+ if (SDL_OpenAudio(&aspec, &obtained) < 0) {
+ ADR_LOG("Unable open sdl audio subsystem.\n");
+ delete device;
+ return 0;
+ }
+ if (aspec.format != obtained.format ||
+ aspec.freq != obtained.freq ||
+ aspec.channels != obtained.channels) {
+ ADR_LOG("Unsupported audio parameters.\n");
+ delete device;
+ return 0;
+ }
+
+ SDL_PauseAudio(0);
+ return device;
+ }
+
+ void SDLAudioDevice::outputCallback(void *user_data, Uint8 *stream, int len)
+ {
+ SDLAudioDevice *device = (SDLAudioDevice*)user_data;
+ device->read(len / 4, stream);
+ }
+
+ SDLAudioDevice::SDLAudioDevice(int rate, int buffer_size)
+ : MixerDevice(rate)
+ {
+ m_buffer_size = buffer_size;
+ m_buffer = new char [buffer_size];
+ }
+
+
+ SDLAudioDevice::~SDLAudioDevice() {
+ ADR_GUARD("SDLAudioDevice::~SDLAudioDevice");
+
+ SDL_CloseAudio();
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+
+ delete [] m_buffer;
+ }
+
+
+ void ADR_CALL
+ SDLAudioDevice::update() {
+ AI_Sleep(1);
+ }
+
+
+ const char* ADR_CALL
+ SDLAudioDevice::getName() {
+ return "sdl";
+ }
+
+}
diff --git a/src/device_sdl.h b/src/device_sdl.h
new file mode 100644
index 0000000..fc0140c
--- /dev/null
+++ b/src/device_sdl.h
@@ -0,0 +1,34 @@
+#ifndef DEVICE_NEXUS_H
+#define DEVICE_NEXUS_H
+
+
+#include "audiere.h"
+#include "device_mixer.h"
+
+#include <SDL.h>
+
+namespace audiere {
+
+ class SDLAudioDevice : public MixerDevice {
+ public:
+ static SDLAudioDevice* create(const ParameterList& parameters);
+
+ private:
+ SDLAudioDevice(int rate, int buffer_size);
+ ~SDLAudioDevice();
+
+ public:
+ void ADR_CALL update();
+ const char* ADR_CALL getName();
+
+ private:
+ int m_buffer_size;
+ char* m_buffer;
+
+ static void outputCallback(void *user_data, Uint8 *stream, int len);
+ };
+
+}
+
+
+#endif