diff options
author | Joerg Mueller <nexyon@gmail.com> | 2009-07-28 22:42:26 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2009-07-28 22:42:26 +0400 |
commit | f7b291790890580b5a297405cc32421c11b9a3cf (patch) | |
tree | 2607d5320144468cee6ce01a487ad2d3fd0742f4 /intern | |
parent | 154c7c97f4fb0b2a54c13c4155b1dd33c3b2f9dc (diff) |
Sound Branch
Sequencer audio update, still not perfect, but improving.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/audaspace/AUD_C-API.h | 17 | ||||
-rw-r--r-- | intern/audaspace/OpenAL/AUD_OpenALDevice.cpp | 81 | ||||
-rw-r--r-- | intern/audaspace/OpenAL/AUD_OpenALDevice.h | 1 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_C-API.cpp | 23 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_IDevice.h | 8 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_NULLDevice.cpp | 5 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_NULLDevice.h | 1 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SoftwareDevice.cpp | 16 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_SoftwareDevice.h | 1 |
9 files changed, 126 insertions, 27 deletions
diff --git a/intern/audaspace/AUD_C-API.h b/intern/audaspace/AUD_C-API.h index a1418a989b1..1ee4b33e9fe 100644 --- a/intern/audaspace/AUD_C-API.h +++ b/intern/audaspace/AUD_C-API.h @@ -72,6 +72,16 @@ extern int* AUD_enumDevices(); extern void AUD_exit(); /** + * Locks the playback device. + */ +extern void AUD_lock(); + +/** + * Unlocks the device. + */ +extern void AUD_unlock(); + +/** * Returns information about a sound. * \param sound The sound to get the info about. * \return The AUD_SoundInfo structure with filled in data. @@ -192,6 +202,13 @@ extern int AUD_setKeep(AUD_Handle* handle, int keep); extern int AUD_seek(AUD_Handle* handle, float seekTo); /** + * Retrieves the playback position of a handle. + * \return The current playback position in seconds or 0.0 if the handle is + * invalid. + */ +extern float AUD_getPosition(AUD_Handle* handle); + +/** * Returns the status of a playing, paused or stopped sound. * \param handle The handle to the sound. * \return The status of the sound behind the handle. diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp index 763cd86cccd..5af9c93076a 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.cpp @@ -204,7 +204,7 @@ void AUD_OpenALDevice::updateStreams() // check if the sound has been stopped alGetSourcei(sound->source, AL_SOURCE_STATE, &info); - if(info == AL_STOPPED) + if(info != AL_PLAYING) { // if it really stopped if(sound->data_end) @@ -538,11 +538,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep) alSourcei(sound->source, AL_BUFFER, (*i)->buffer); if(alGetError() != AL_NO_ERROR) AUD_THROW(AUD_ERROR_OPENAL); - - alSourcePlay(sound->source); - - if(alGetError() != AL_NO_ERROR) - AUD_THROW(AUD_ERROR_OPENAL); } catch(AUD_Exception e) { @@ -645,11 +640,6 @@ AUD_Handle* AUD_OpenALDevice::play(AUD_IFactory* factory, bool keep) alSourceQueueBuffers(sound->source, 3, sound->buffers); if(alGetError() != AL_NO_ERROR) AUD_THROW(AUD_ERROR_OPENAL); - - alSourcePlay(sound->source); - - if(alGetError() != AL_NO_ERROR) - AUD_THROW(AUD_ERROR_OPENAL); } catch(AUD_Exception e) { @@ -715,20 +705,6 @@ bool AUD_OpenALDevice::resume(AUD_Handle* handle) if(*i == handle) { m_playingSounds->push_back(*i); - - alGetSourcei((*i)->source, AL_SOURCE_STATE, &info); - - switch(info) - { - case AL_PLAYING: - break; - case AL_STOPPED: -// alSourceRewind((*i)->source); - default: -// alSourcePlay((*i)->source); - break; - } - start(); m_pausedSounds->erase(i); unlock(); @@ -835,6 +811,41 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position) alhandle->reader->seek((int)(position * alhandle->reader->getSpecs().rate)); alhandle->data_end = false; + + ALint info; + + alGetSourcei(alhandle->source, AL_SOURCE_STATE, &info); + + if(info != AL_PLAYING) + { + if(info != AL_STOPPED) + alSourceStop(alhandle->source); + + alSourceUnqueueBuffers(alhandle->source, 3, alhandle->buffers); + if(alGetError() == AL_NO_ERROR) + { + sample_t* buf; + int length; + AUD_Specs specs = alhandle->reader->getSpecs(); + + for(int i=0; i<3; i++) + { + length = m_buffersize; + alhandle->reader->read(length, buf); + alBufferData(alhandle->buffers[i], alhandle->format, + buf, length * AUD_SAMPLE_SIZE(specs), + specs.rate); + + if(alGetError() != AL_NO_ERROR) + break; + } + + alSourceQueueBuffers(alhandle->source, 3, + alhandle->buffers); + } + + alSourceRewind(alhandle->source); + } } unlock(); return true; @@ -844,6 +855,26 @@ bool AUD_OpenALDevice::seek(AUD_Handle* handle, float position) return false; } +float AUD_OpenALDevice::getPosition(AUD_Handle* handle) +{ + lock(); + + float position = 0.0; + + if(isValid(handle)) + { + AUD_OpenALHandle* h = (AUD_OpenALHandle*)handle; + if(h->isBuffered) + alGetSourcef(h->source, AL_SEC_OFFSET, &position); + else + position = h->reader->getPosition() / + (float)h->reader->getSpecs().rate; + } + + unlock(); + return position; +} + AUD_Status AUD_OpenALDevice::getStatus(AUD_Handle* handle) { lock(); diff --git a/intern/audaspace/OpenAL/AUD_OpenALDevice.h b/intern/audaspace/OpenAL/AUD_OpenALDevice.h index e1d86867fd6..8864ccc4e01 100644 --- a/intern/audaspace/OpenAL/AUD_OpenALDevice.h +++ b/intern/audaspace/OpenAL/AUD_OpenALDevice.h @@ -149,6 +149,7 @@ public: virtual bool setKeep(AUD_Handle* handle, bool keep); virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message); virtual bool seek(AUD_Handle* handle, float position); + virtual float getPosition(AUD_Handle* handle); virtual AUD_Status getStatus(AUD_Handle* handle); virtual void lock(); virtual void unlock(); diff --git a/intern/audaspace/intern/AUD_C-API.cpp b/intern/audaspace/intern/AUD_C-API.cpp index ccf3ca3c6a1..30c637eda5b 100644 --- a/intern/audaspace/intern/AUD_C-API.cpp +++ b/intern/audaspace/intern/AUD_C-API.cpp @@ -133,6 +133,18 @@ void AUD_exit() AUD_3ddevice = NULL; } +void AUD_lock() +{ + assert(AUD_device); + AUD_device->lock(); +} + +void AUD_unlock() +{ + assert(AUD_device); + AUD_device->unlock(); +} + AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) { assert(sound); @@ -300,8 +312,9 @@ int AUD_resume(AUD_Handle* handle) int AUD_stop(AUD_Handle* handle) { - assert(AUD_device); - return AUD_device->stop(handle); + if(AUD_device) + return AUD_device->stop(handle); + return false; } int AUD_setKeep(AUD_Handle* handle, int keep) @@ -316,6 +329,12 @@ int AUD_seek(AUD_Handle* handle, float seekTo) return AUD_device->seek(handle, seekTo); } +float AUD_getPosition(AUD_Handle* handle) +{ + assert(AUD_device); + return AUD_device->getPosition(handle); +} + AUD_Status AUD_getStatus(AUD_Handle* handle) { assert(AUD_device); diff --git a/intern/audaspace/intern/AUD_IDevice.h b/intern/audaspace/intern/AUD_IDevice.h index 3200169e41c..72bd9dcbf66 100644 --- a/intern/audaspace/intern/AUD_IDevice.h +++ b/intern/audaspace/intern/AUD_IDevice.h @@ -127,6 +127,14 @@ public: virtual bool seek(AUD_Handle* handle, float position)=0; /** + * Retrieves the current playback position of a sound. + * \param handle The handle returned by the play function. + * \return The playback position in seconds, or 0.0 if the handle is + * invalid. + */ + virtual float getPosition(AUD_Handle* handle)=0; + + /** * Returns the status of a played back sound. * \param handle The handle returned by the play function. * \return diff --git a/intern/audaspace/intern/AUD_NULLDevice.cpp b/intern/audaspace/intern/AUD_NULLDevice.cpp index 20bde0164ce..d237b71b67e 100644 --- a/intern/audaspace/intern/AUD_NULLDevice.cpp +++ b/intern/audaspace/intern/AUD_NULLDevice.cpp @@ -74,6 +74,11 @@ bool AUD_NULLDevice::seek(AUD_Handle* handle, float position) return false; } +float AUD_NULLDevice::getPosition(AUD_Handle* handle) +{ + return 0.0f; +} + AUD_Status AUD_NULLDevice::getStatus(AUD_Handle* handle) { return AUD_STATUS_INVALID; diff --git a/intern/audaspace/intern/AUD_NULLDevice.h b/intern/audaspace/intern/AUD_NULLDevice.h index c0cf7ed4e51..155f24f8837 100644 --- a/intern/audaspace/intern/AUD_NULLDevice.h +++ b/intern/audaspace/intern/AUD_NULLDevice.h @@ -53,6 +53,7 @@ public: virtual bool setKeep(AUD_Handle* handle, bool keep); virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message); virtual bool seek(AUD_Handle* handle, float position); + virtual float getPosition(AUD_Handle* handle); virtual AUD_Status getStatus(AUD_Handle* handle); virtual void lock(); virtual void unlock(); diff --git a/intern/audaspace/intern/AUD_SoftwareDevice.cpp b/intern/audaspace/intern/AUD_SoftwareDevice.cpp index 0de79f988bc..1a2a53fed19 100644 --- a/intern/audaspace/intern/AUD_SoftwareDevice.cpp +++ b/intern/audaspace/intern/AUD_SoftwareDevice.cpp @@ -324,6 +324,22 @@ bool AUD_SoftwareDevice::seek(AUD_Handle* handle, float position) return false; } +float AUD_SoftwareDevice::getPosition(AUD_Handle* handle) +{ + lock(); + + float position = 0.0f; + + if(isValid(handle)) + { + AUD_SoftwareHandle* h = (AUD_SoftwareHandle*)handle; + position = h->reader->getPosition() / (float)m_specs.rate; + } + + unlock(); + return position; +} + AUD_Status AUD_SoftwareDevice::getStatus(AUD_Handle* handle) { lock(); diff --git a/intern/audaspace/intern/AUD_SoftwareDevice.h b/intern/audaspace/intern/AUD_SoftwareDevice.h index afab92fc4cd..3768786fa9c 100644 --- a/intern/audaspace/intern/AUD_SoftwareDevice.h +++ b/intern/audaspace/intern/AUD_SoftwareDevice.h @@ -125,6 +125,7 @@ public: virtual bool setKeep(AUD_Handle* handle, bool keep); virtual bool sendMessage(AUD_Handle* handle, AUD_Message &message); virtual bool seek(AUD_Handle* handle, float position); + virtual float getPosition(AUD_Handle* handle); virtual AUD_Status getStatus(AUD_Handle* handle); virtual void lock(); virtual void unlock(); |