diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2012-12-03 12:42:09 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2012-12-03 12:42:09 +0800 |
commit | cd9ad696cdc9e7165b64010e213f1deafcce55fd (patch) | |
tree | babda16fc2c756dd4a267d890e1d5adb8b309e67 /src | |
parent | 772d80843fa389f78a1167c69071f2ecd80b47e0 (diff) |
Port the android device to threaded mixer device
Diffstat (limited to 'src')
-rw-r--r-- | src/device_android.cpp | 34 | ||||
-rw-r--r-- | src/device_android.h | 10 |
2 files changed, 15 insertions, 29 deletions
diff --git a/src/device_android.cpp b/src/device_android.cpp index 07a7390..cc21f4e 100644 --- a/src/device_android.cpp +++ b/src/device_android.cpp @@ -16,49 +16,39 @@ namespace audiere { int ret = AGAudioInit(44100, 2, 16); if (ret < 0) return 0; - return new AndroidAudioDevice(44100, 8192); + return new AndroidAudioDevice(44100, 4096); } AndroidAudioDevice::AndroidAudioDevice(int rate, int buffer_size) - : MixerDevice(rate), m_rate(rate) + : ThreadedMixerDevice(rate, buffer_size, 4), m_quit(false) { - m_buffer_size = buffer_size; - m_buffer = new char [buffer_size]; + start(); } AndroidAudioDevice::~AndroidAudioDevice() { ADR_GUARD("AndroidAudioDevice::~AndroidAudioDevice"); + m_quit = true; + shutdown(); AGAudioSetReadCallback(0, 0); AGAudioUninit(); - - delete [] m_buffer; } void - AndroidAudioDevice::writeData() { - int sample_len; - size_t sample_left; - char* sample_buf; + AndroidAudioDevice::outputBuffer(const char* buf, int buf_len) { + while (AGAudioIsPaused()) { + if (m_quit) + return; - sample_buf = m_buffer; - sample_len = m_buffer_size / 4; + AI_Sleep(20); + } - sample_left = read(sample_len, sample_buf); - if (sample_left) - AGAudioWrite((void*)sample_buf, sample_left * 4); + AGAudioWrite(buf, buf_len); } - void - AndroidAudioDevice::update() { - if (!AGAudioIsPaused()) - writeData(); - else - AI_Sleep(10); - } const char* ADR_CALL AndroidAudioDevice::getName() { diff --git a/src/device_android.h b/src/device_android.h index 2c469ca..9682caf 100644 --- a/src/device_android.h +++ b/src/device_android.h @@ -9,7 +9,7 @@ namespace audiere { - class AndroidAudioDevice : public MixerDevice { + class AndroidAudioDevice : public ThreadedMixerDevice { public: static AndroidAudioDevice* create(const ParameterList& parameters); @@ -18,15 +18,11 @@ namespace audiere { ~AndroidAudioDevice(); public: - void ADR_CALL update(); + void ADR_CALL outputBuffer(const char* buf, int buf_len); const char* ADR_CALL getName(); private: - int m_buffer_size; - char* m_buffer; - int m_rate; - - void writeData(); + bool m_quit; }; } |