diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2010-12-12 11:19:30 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2010-12-12 11:19:30 +0800 |
commit | cb66a74924469ee99fd946dc4fa54e0c465173b3 (patch) | |
tree | c1f1fb22ff30fd63d93f07e95232568cdf37d67e | |
parent | ce93417d8fad28def3e9b8bfffc87ddd4de5d687 (diff) |
android: add a driver for android
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/device.cpp | 15 | ||||
-rw-r--r-- | src/device_android.cpp | 72 | ||||
-rw-r--r-- | src/device_android.h | 36 |
4 files changed, 127 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 15c2c42..753c381 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -89,6 +89,8 @@ COREAUDIO_DIST = device_coreaudio.cpp \ device_coreaudio.h endif +ANDROIDAUDIO_DIST = device_android.cpp device_android.h + # Automake blows. # A lot. if HAVE_LIBCDAUDIO @@ -130,8 +132,8 @@ EXTRA_DIST = \ $(LIBCDAUDIO_DIST) $(WINCDAUDIO_DIST) $(NULLCDAUDIO_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) $(MIDI_DIST) $(THREADS_DIST) \ - $(EXTERN_DIST) + $(ALSA_DIST) $(NEXUS_DIST) $(ZTE_DIST) $(ANDROIDAUDIO_DIST) \ + $(MIDI_DIST) $(THREADS_DIST) $(EXTERN_DIST) libaudiere_la_SOURCES = \ $(MIDI_SOURCES) \ diff --git a/src/device.cpp b/src/device.cpp index db3d1ba..ec0a0d6 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -56,6 +56,10 @@ #include "device_coreaudio.h" #endif +#ifdef HAVE_GAME_LAUNCHER + #include "device_android.h" +#endif + namespace audiere { AbstractDevice::AbstractDevice() { @@ -168,6 +172,9 @@ namespace audiere { "directsound:DirectSound (high-performance)" ";" "winmm:Windows Multimedia (compatible)" ";" #else +#ifdef HAVE_GAME_LAUNCHER + "android:Android Audio Driver" ";" +#endif #ifdef HAVE_ALSA "alsa:Advance Linux Sound Architecture" ";" #endif @@ -256,6 +263,7 @@ namespace audiere { TRY_GROUP("extern"); TRY_GROUP("zte"); TRY_GROUP("alsa"); + TRY_GROUP("android"); TRY_GROUP("nexus"); TRY_GROUP("oss"); TRY_GROUP("coreaudio"); @@ -325,6 +333,13 @@ namespace audiere { } #endif + #ifdef HAVE_GAME_LAUNCHER + if (name == "android") { + TRY_DEVICE(AndroidAudioDevice); + return 0; + } + #endif + if (name == "null") { TRY_DEVICE(NullAudioDevice); return 0; diff --git a/src/device_android.cpp b/src/device_android.cpp new file mode 100644 index 0000000..0c6d330 --- /dev/null +++ b/src/device_android.cpp @@ -0,0 +1,72 @@ +#include <algorithm> +#include <string> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> + +#include "device_android.h" +#include "debug.h" + + +namespace audiere { + + AndroidAudioDevice* + AndroidAudioDevice::create(const ParameterList& parameters) { + int ret = awAudioInit(44100, 2, 16); + if (ret < 0) + return 0; + return new AndroidAudioDevice(44100, 2048); + } + + + AndroidAudioDevice::AndroidAudioDevice(int rate, int buffer_size) + : MixerDevice(rate), m_rate(rate) + { + m_buffer_size = buffer_size; + m_buffer = new char [buffer_size]; + awAudioSetReadCallback(dataReadCallback, this); + } + + + AndroidAudioDevice::~AndroidAudioDevice() { + ADR_GUARD("AndroidAudioDevice::~AndroidAudioDevice"); + + awAudioSetReadCallback(0, 0); + delete [] m_buffer; + } + + + void + AndroidAudioDevice::dataReadCallback(void* arg) { + AndroidAudioDevice* device = static_cast<AndroidAudioDevice*>(arg); + if (!device) + return; + device->writeData(); + } + + void + AndroidAudioDevice::writeData() { + int sample_len; + size_t sample_left; + char* sample_buf; + + sample_buf = m_buffer; + sample_len = m_buffer_size / 4; + + sample_left = read(sample_len, sample_buf); + if (sample_left) + awAudioWrite((void*)sample_buf, sample_left * 4); + } + + void + AndroidAudioDevice::update() { + AI_Sleep(10); + } + + const char* ADR_CALL + AndroidAudioDevice::getName() { + return "android"; + } + +} diff --git a/src/device_android.h b/src/device_android.h new file mode 100644 index 0000000..aa28e1c --- /dev/null +++ b/src/device_android.h @@ -0,0 +1,36 @@ +#ifndef DEVICE_ANDROID_H +#define DEVICE_ANDROID_H + + +#include "audiere.h" +#include "device_mixer.h" + +#include "GameAudio.h" + +namespace audiere { + + class AndroidAudioDevice : public MixerDevice { + public: + static AndroidAudioDevice* create(const ParameterList& parameters); + + private: + AndroidAudioDevice(int rate, int buffer_size); + ~AndroidAudioDevice(); + + public: + void ADR_CALL update(); + const char* ADR_CALL getName(); + + private: + int m_buffer_size; + char* m_buffer; + int m_rate; + + void writeData(); + static void dataReadCallback(void*); + }; + +} + + +#endif |