diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2012-11-27 14:01:22 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2012-11-27 14:20:53 +0800 |
commit | 619d51ca8914bd66e63274db074f44cd3180c987 (patch) | |
tree | ecb477240e59e02b6ff31ff058b602e1125ba06c | |
parent | dc69d7d189870b6e33f30846f5ec7c093f121183 (diff) |
Subclass ThreadedMixerDevice for ExternAudioDevice instead of MixerDevice
-rw-r--r-- | src/device_extern.cpp | 36 | ||||
-rw-r--r-- | src/device_extern.h | 9 |
2 files changed, 19 insertions, 26 deletions
diff --git a/src/device_extern.cpp b/src/device_extern.cpp index cf586c1..3d61e0f 100644 --- a/src/device_extern.cpp +++ b/src/device_extern.cpp @@ -74,7 +74,7 @@ namespace audiere { ExternModule module; if (!module.init("./libExtAudioDevice.so") && - !module.init("libExtAudioDevice.so")) + !module.init("libExtAudioDevice.so")) return 0; ret = module.open(44100, 2, 16, 1); @@ -98,40 +98,34 @@ namespace audiere { } ExternAudioDevice::ExternAudioDevice(ExternModule module, - int rate, - int buffer_size) - : MixerDevice(rate), m_module(module), m_rate(rate) + int rate, + int buffer_size) + : ThreadedMixerDevice(rate, buffer_size, 8), m_module(module), m_rate(rate) { - m_buffer_size = buffer_size; - m_buffer = new char [buffer_size]; + start(); } ExternAudioDevice::~ExternAudioDevice() { ADR_GUARD("ExternAudioDevice::~ExternAudioDevice"); + shutdown(); m_module.stop(); m_module.close(); m_module.uninit(); - delete [] m_buffer; } - void ADR_CALL - ExternAudioDevice::update() { - 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); - while (sample_left > 0) { - if (m_module.write(sample_buf, sample_left * 4) < 0) { - AI_Sleep(2); + void ExternAudioDevice::outputBuffer(const char* buf, int buf_len) { + ADR_GUARD("ExternAudioDevice::outputBuffer"); + int left = buf_len; + while (left > 0) { + int ret = m_module.write(buf, left); + if (ret < 0) { + break; } else { - sample_left = 0; + left -= ret; + buf += ret; } } } diff --git a/src/device_extern.h b/src/device_extern.h index ff61e54..bb06ba6 100644 --- a/src/device_extern.h +++ b/src/device_extern.h @@ -8,7 +8,7 @@ namespace audiere { - class ExternAudioDevice : public MixerDevice { + class ExternAudioDevice : public ThreadedMixerDevice { public: typedef int (*DeviceOpenProc)(int sr, int c, int bs, int is); typedef int (*DeviceStartProc)(); @@ -73,13 +73,12 @@ namespace audiere { ~ExternAudioDevice(); public: - void ADR_CALL update(); - const char* ADR_CALL getName(); + virtual const char* ADR_CALL getName(); private: + virtual void outputBuffer(const char* buf, int buf_len); + ExternModule m_module; - int m_buffer_size; - char* m_buffer; int m_rate; }; |