forked from bartvdbraak/blender
Audaspace:
RAII locking implementation. This should fix bug [#32096] Background music stops when playing 3D sounds.
This commit is contained in:
parent
05f563339b
commit
e66ee1ca9f
@ -94,6 +94,7 @@ set(SRC
|
||||
intern/AUD_IDevice.h
|
||||
intern/AUD_IFactory.h
|
||||
intern/AUD_IHandle.h
|
||||
intern/AUD_ILockable.h
|
||||
intern/AUD_IReader.h
|
||||
intern/AUD_IWriter.h
|
||||
intern/AUD_JOSResampleFactory.cpp
|
||||
@ -108,6 +109,7 @@ set(SRC
|
||||
intern/AUD_Mixer.h
|
||||
intern/AUD_MixerFactory.cpp
|
||||
intern/AUD_MixerFactory.h
|
||||
intern/AUD_MutexLock.h
|
||||
intern/AUD_NULLDevice.cpp
|
||||
intern/AUD_NULLDevice.h
|
||||
intern/AUD_PyInit.h
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "AUD_IFactory.h"
|
||||
#include "AUD_IReader.h"
|
||||
#include "AUD_ConverterReader.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
@ -125,7 +126,7 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::pause()
|
||||
{
|
||||
if(m_status)
|
||||
{
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(m_status == AUD_STATUS_PLAYING)
|
||||
{
|
||||
@ -135,12 +136,9 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::pause()
|
||||
alSourcePause(m_source);
|
||||
|
||||
m_status = AUD_STATUS_PAUSED;
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -150,7 +148,7 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::resume()
|
||||
{
|
||||
if(m_status)
|
||||
{
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(m_status == AUD_STATUS_PAUSED)
|
||||
{
|
||||
@ -159,11 +157,8 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::resume()
|
||||
|
||||
m_device->start();
|
||||
m_status = AUD_STATUS_PLAYING;
|
||||
m_device->unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -174,7 +169,10 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
// AUD_XXX Create a reference of our own object so that it doesn't get
|
||||
// deleted before the end of this function
|
||||
@ -185,8 +183,6 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::stop()
|
||||
else
|
||||
m_device->m_pausedSounds.remove(This);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
alDeleteSources(1, &m_source);
|
||||
if(!m_isBuffered)
|
||||
alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
|
||||
@ -208,12 +204,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setKeep(bool keep)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_keep = keep;
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -222,7 +219,10 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
if(m_isBuffered)
|
||||
alSourcef(m_source, AL_SEC_OFFSET, position);
|
||||
@ -272,17 +272,18 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::seek(float position)
|
||||
}
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
|
||||
{
|
||||
if(!m_status)
|
||||
return 0.0f;
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return 0.0f;
|
||||
|
||||
float position = 0.0f;
|
||||
|
||||
@ -295,8 +296,6 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getPosition()
|
||||
CYCLE_BUFFERS) / (float)specs.rate;
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
@ -309,15 +308,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getVolume()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_GAIN, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -326,12 +326,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setVolume(float volume)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_GAIN, volume);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -339,15 +340,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getPitch()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_PITCH, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -356,12 +358,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setPitch(float pitch)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_PITCH, pitch);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -385,13 +388,14 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setStopCallback(stopCallback callback,
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_stop = callback;
|
||||
m_stop_data = data;
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -404,15 +408,16 @@ AUD_Vector3 AUD_OpenALDevice::AUD_OpenALHandle::getSourceLocation()
|
||||
AUD_Vector3 result = AUD_Vector3(0, 0, 0);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
ALfloat p[3];
|
||||
alGetSourcefv(m_source, AL_POSITION, p);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
result = AUD_Vector3(p[0], p[1], p[2]);
|
||||
|
||||
return result;
|
||||
@ -423,12 +428,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceLocation(const AUD_Vector3& lo
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcefv(m_source, AL_POSITION, (ALfloat*)location.get());
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -437,15 +443,16 @@ AUD_Vector3 AUD_OpenALDevice::AUD_OpenALHandle::getSourceVelocity()
|
||||
AUD_Vector3 result = AUD_Vector3(0, 0, 0);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
ALfloat v[3];
|
||||
alGetSourcefv(m_source, AL_VELOCITY, v);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
result = AUD_Vector3(v[0], v[1], v[2]);
|
||||
|
||||
return result;
|
||||
@ -456,12 +463,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceVelocity(const AUD_Vector3& ve
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcefv(m_source, AL_VELOCITY, (ALfloat*)velocity.get());
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -472,9 +480,6 @@ AUD_Quaternion AUD_OpenALDevice::AUD_OpenALHandle::getSourceOrientation()
|
||||
|
||||
bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceOrientation(const AUD_Quaternion& orientation)
|
||||
{
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
ALfloat direction[3];
|
||||
direction[0] = -2 * (orientation.w() * orientation.y() +
|
||||
orientation.x() * orientation.z());
|
||||
@ -482,12 +487,17 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setSourceOrientation(const AUD_Quaterni
|
||||
orientation.z() * orientation.y());
|
||||
direction[2] = 2 * (orientation.x() * orientation.x() +
|
||||
orientation.y() * orientation.y()) - 1;
|
||||
m_device->lock();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcefv(m_source, AL_DIRECTION, direction);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
m_orientation = orientation;
|
||||
|
||||
return true;
|
||||
@ -500,12 +510,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::isRelative()
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alGetSourcei(m_source, AL_SOURCE_RELATIVE, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -514,12 +525,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setRelative(bool relative)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcei(m_source, AL_SOURCE_RELATIVE, relative);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -527,15 +539,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getVolumeMaximum()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_MAX_GAIN, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -544,12 +557,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMaximum(float volume)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_MAX_GAIN, volume);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -557,15 +571,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getVolumeMinimum()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_MIN_GAIN, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -574,12 +589,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setVolumeMinimum(float volume)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_MIN_GAIN, volume);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -587,15 +603,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getDistanceMaximum()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_MAX_DISTANCE, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -604,12 +621,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceMaximum(float distance)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_MAX_DISTANCE, distance);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -617,15 +635,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getDistanceReference()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_REFERENCE_DISTANCE, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -634,12 +653,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setDistanceReference(float distance)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_REFERENCE_DISTANCE, distance);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -647,15 +667,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getAttenuation()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_ROLLOFF_FACTOR, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -664,12 +685,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setAttenuation(float factor)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_ROLLOFF_FACTOR, factor);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -677,15 +699,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getConeAngleOuter()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_CONE_OUTER_ANGLE, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -694,12 +717,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleOuter(float angle)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_CONE_OUTER_ANGLE, angle);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -707,15 +731,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getConeAngleInner()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_CONE_INNER_ANGLE, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -724,12 +749,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setConeAngleInner(float angle)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_CONE_INNER_ANGLE, angle);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -737,15 +763,16 @@ float AUD_OpenALDevice::AUD_OpenALHandle::getConeVolumeOuter()
|
||||
{
|
||||
float result = std::numeric_limits<float>::quiet_NaN();
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return result;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
alGetSourcef(m_source, AL_CONE_OUTER_GAIN, &result);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -754,12 +781,13 @@ bool AUD_OpenALDevice::AUD_OpenALHandle::setConeVolumeOuter(float volume)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
alSourcef(m_source, AL_CONE_OUTER_GAIN, volume);
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -776,7 +804,7 @@ static void *AUD_openalRunThread(void *device)
|
||||
|
||||
void AUD_OpenALDevice::start(bool join)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(!m_playing)
|
||||
{
|
||||
@ -793,8 +821,6 @@ void AUD_OpenALDevice::start(bool join)
|
||||
|
||||
m_playing = true;
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_OpenALDevice::updateStreams()
|
||||
@ -1177,7 +1203,8 @@ AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> rea
|
||||
if(!getFormat(format, specs))
|
||||
return AUD_Reference<AUD_IHandle>();
|
||||
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
alcSuspendContext(m_context);
|
||||
|
||||
AUD_Reference<AUD_OpenALDevice::AUD_OpenALHandle> sound;
|
||||
@ -1190,7 +1217,6 @@ AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> rea
|
||||
catch(AUD_Exception&)
|
||||
{
|
||||
alcProcessContext(m_context);
|
||||
unlock();
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -1201,8 +1227,6 @@ AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> rea
|
||||
|
||||
start();
|
||||
|
||||
unlock();
|
||||
|
||||
return AUD_Reference<AUD_IHandle>(sound);
|
||||
}
|
||||
|
||||
@ -1285,7 +1309,8 @@ AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IFactory> fa
|
||||
|
||||
void AUD_OpenALDevice::stopAll()
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
alcSuspendContext(m_context);
|
||||
|
||||
while(!m_playingSounds.empty())
|
||||
@ -1295,7 +1320,6 @@ void AUD_OpenALDevice::stopAll()
|
||||
m_pausedSounds.front()->stop();
|
||||
|
||||
alcProcessContext(m_context);
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_OpenALDevice::lock()
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
#include "AUD_AnimateableProperty.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
@ -63,17 +64,15 @@ void AUD_AnimateableProperty::unlock()
|
||||
|
||||
void AUD_AnimateableProperty::write(const float* data)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_isAnimated = false;
|
||||
memcpy(getBuffer(), data, m_count * sizeof(float));
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_AnimateableProperty::write(const float* data, int position, int count)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_isAnimated = true;
|
||||
|
||||
@ -87,18 +86,15 @@ void AUD_AnimateableProperty::write(const float* data, int position, int count)
|
||||
|
||||
for(int i = pos; i < position; i++)
|
||||
memcpy(buf + i * m_count, buf + (pos - 1) * m_count, m_count * sizeof(float));
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_AnimateableProperty::read(float position, float* out)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(!m_isAnimated)
|
||||
{
|
||||
memcpy(out, getBuffer(), m_count * sizeof(float));
|
||||
unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -147,8 +143,6 @@ void AUD_AnimateableProperty::read(float position, float* out)
|
||||
(t3 - 2 * t2 + t) * m0 + (t3 - t2) * m1;
|
||||
}
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool AUD_AnimateableProperty::isAnimated() const
|
||||
|
@ -31,13 +31,14 @@
|
||||
#define __AUD_ANIMATEABLEPROPERTY_H__
|
||||
|
||||
#include "AUD_Buffer.h"
|
||||
#include "AUD_ILockable.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* This class saves animation data for float properties.
|
||||
*/
|
||||
class AUD_AnimateableProperty : private AUD_Buffer
|
||||
class AUD_AnimateableProperty : private AUD_Buffer, public AUD_ILockable
|
||||
{
|
||||
private:
|
||||
/// The count of floats for a single property.
|
||||
@ -68,12 +69,12 @@ public:
|
||||
/**
|
||||
* Locks the property.
|
||||
*/
|
||||
void lock();
|
||||
virtual void lock();
|
||||
|
||||
/**
|
||||
* Unlocks the previously locked property.
|
||||
*/
|
||||
void unlock();
|
||||
virtual void unlock();
|
||||
|
||||
/**
|
||||
* Writes the properties value and marks it non-animated.
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "AUD_SequencerFactory.h"
|
||||
#include "AUD_SequencerEntry.h"
|
||||
#include "AUD_SilenceFactory.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
#ifdef WITH_SDL
|
||||
#include "AUD_SDLDevice.h"
|
||||
@ -858,13 +859,12 @@ AUD_Handle *AUD_pauseAfter(AUD_Handle *handle, float seconds)
|
||||
AUD_Reference<AUD_IFactory> silence = new AUD_SilenceFactory;
|
||||
AUD_Reference<AUD_IFactory> limiter = new AUD_LimiterFactory(silence, 0, seconds);
|
||||
|
||||
AUD_device->lock();
|
||||
AUD_MutexLock lock(*AUD_device);
|
||||
|
||||
try {
|
||||
AUD_Handle handle2 = AUD_device->play(limiter);
|
||||
if (!handle2.isNull()) {
|
||||
handle2->setStopCallback((stopCallback)pauseSound, handle);
|
||||
AUD_device->unlock();
|
||||
return new AUD_Handle(handle2);
|
||||
}
|
||||
}
|
||||
@ -872,8 +872,6 @@ AUD_Handle *AUD_pauseAfter(AUD_Handle *handle, float seconds)
|
||||
{
|
||||
}
|
||||
|
||||
AUD_device->unlock();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "AUD_IFactory.h"
|
||||
#include "AUD_IReader.h"
|
||||
#include "AUD_IHandle.h"
|
||||
#include "AUD_ILockable.h"
|
||||
|
||||
/**
|
||||
* This class represents an output device for sound sources.
|
||||
@ -44,7 +45,7 @@
|
||||
* \warning Thread safety must be insured so that no reader is beeing called
|
||||
* twice at the same time.
|
||||
*/
|
||||
class AUD_IDevice
|
||||
class AUD_IDevice : public AUD_ILockable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
21
intern/audaspace/intern/AUD_ILockable.h
Normal file
21
intern/audaspace/intern/AUD_ILockable.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef AUD_ILOCKABLE_H
|
||||
#define AUD_ILOCKABLE_H
|
||||
|
||||
/**
|
||||
* This class provides an interface for lockable objects.
|
||||
* The main reason for this interface is to be used with AUD_MutexLock.
|
||||
*/
|
||||
class AUD_ILockable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Locks the object.
|
||||
*/
|
||||
virtual void lock()=0;
|
||||
/**
|
||||
* Unlocks the previously locked object.
|
||||
*/
|
||||
virtual void unlock()=0;
|
||||
};
|
||||
|
||||
#endif // AUD_ILOCKABLE_H
|
24
intern/audaspace/intern/AUD_MutexLock.h
Normal file
24
intern/audaspace/intern/AUD_MutexLock.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef AUD_MUTEXLOCK_H
|
||||
#define AUD_MUTEXLOCK_H
|
||||
|
||||
#include "AUD_ILockable.h"
|
||||
|
||||
class AUD_MutexLock
|
||||
{
|
||||
public:
|
||||
inline AUD_MutexLock(AUD_ILockable& lockable) :
|
||||
lockable(lockable)
|
||||
{
|
||||
lockable.lock();
|
||||
}
|
||||
|
||||
inline ~AUD_MutexLock()
|
||||
{
|
||||
lockable.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
AUD_ILockable& lockable;
|
||||
};
|
||||
|
||||
#endif // AUD_MUTEXLOCK_H
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "AUD_SequencerEntry.h"
|
||||
#include "AUD_SequencerReader.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
@ -87,20 +88,18 @@ void AUD_SequencerEntry::unlock()
|
||||
|
||||
void AUD_SequencerEntry::setSound(AUD_Reference<AUD_IFactory> sound)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(m_sound.get() != sound.get())
|
||||
{
|
||||
m_sound = sound;
|
||||
m_sound_status++;
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SequencerEntry::move(float begin, float end, float skip)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(m_begin != begin || m_skip != skip || m_end != end)
|
||||
{
|
||||
@ -109,17 +108,13 @@ void AUD_SequencerEntry::move(float begin, float end, float skip)
|
||||
m_end = end;
|
||||
m_pos_status++;
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SequencerEntry::mute(bool mute)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_muted = mute;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
int AUD_SequencerEntry::getID() const
|
||||
@ -150,7 +145,7 @@ void AUD_SequencerEntry::updateAll(float volume_max, float volume_min, float dis
|
||||
float distance_reference, float attenuation, float cone_angle_outer,
|
||||
float cone_angle_inner, float cone_volume_outer)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(volume_max != m_volume_max)
|
||||
{
|
||||
@ -199,8 +194,6 @@ void AUD_SequencerEntry::updateAll(float volume_max, float volume_min, float dis
|
||||
m_cone_volume_outer = cone_volume_outer;
|
||||
m_status++;
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool AUD_SequencerEntry::isRelative()
|
||||
@ -210,15 +203,13 @@ bool AUD_SequencerEntry::isRelative()
|
||||
|
||||
void AUD_SequencerEntry::setRelative(bool relative)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
if(m_relative != relative)
|
||||
{
|
||||
m_relative = relative;
|
||||
m_status++;
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getVolumeMaximum()
|
||||
@ -228,12 +219,10 @@ float AUD_SequencerEntry::getVolumeMaximum()
|
||||
|
||||
void AUD_SequencerEntry::setVolumeMaximum(float volume)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_volume_max = volume;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getVolumeMinimum()
|
||||
@ -243,12 +232,10 @@ float AUD_SequencerEntry::getVolumeMinimum()
|
||||
|
||||
void AUD_SequencerEntry::setVolumeMinimum(float volume)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_volume_min = volume;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getDistanceMaximum()
|
||||
@ -258,12 +245,10 @@ float AUD_SequencerEntry::getDistanceMaximum()
|
||||
|
||||
void AUD_SequencerEntry::setDistanceMaximum(float distance)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_distance_max = distance;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getDistanceReference()
|
||||
@ -273,12 +258,10 @@ float AUD_SequencerEntry::getDistanceReference()
|
||||
|
||||
void AUD_SequencerEntry::setDistanceReference(float distance)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_distance_reference = distance;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getAttenuation()
|
||||
@ -288,12 +271,10 @@ float AUD_SequencerEntry::getAttenuation()
|
||||
|
||||
void AUD_SequencerEntry::setAttenuation(float factor)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_attenuation = factor;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getConeAngleOuter()
|
||||
@ -303,12 +284,10 @@ float AUD_SequencerEntry::getConeAngleOuter()
|
||||
|
||||
void AUD_SequencerEntry::setConeAngleOuter(float angle)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_cone_angle_outer = angle;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getConeAngleInner()
|
||||
@ -318,12 +297,10 @@ float AUD_SequencerEntry::getConeAngleInner()
|
||||
|
||||
void AUD_SequencerEntry::setConeAngleInner(float angle)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_cone_angle_inner = angle;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerEntry::getConeVolumeOuter()
|
||||
@ -333,10 +310,8 @@ float AUD_SequencerEntry::getConeVolumeOuter()
|
||||
|
||||
void AUD_SequencerEntry::setConeVolumeOuter(float volume)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_cone_volume_outer = volume;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
@ -33,13 +33,14 @@
|
||||
#include "AUD_Reference.h"
|
||||
#include "AUD_AnimateableProperty.h"
|
||||
#include "AUD_IFactory.h"
|
||||
#include "AUD_ILockable.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* This class represents a sequenced entry in a sequencer factory.
|
||||
*/
|
||||
class AUD_SequencerEntry
|
||||
class AUD_SequencerEntry : public AUD_ILockable
|
||||
{
|
||||
friend class AUD_SequencerHandle;
|
||||
private:
|
||||
@ -130,12 +131,12 @@ public:
|
||||
/**
|
||||
* Locks the entry.
|
||||
*/
|
||||
void lock();
|
||||
virtual void lock();
|
||||
|
||||
/**
|
||||
* Unlocks the previously locked entry.
|
||||
*/
|
||||
void unlock();
|
||||
virtual void unlock();
|
||||
|
||||
/**
|
||||
* Sets the sound of the entry.
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "AUD_SequencerFactory.h"
|
||||
#include "AUD_SequencerReader.h"
|
||||
#include "AUD_3DMath.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, float fps, bool muted) :
|
||||
m_specs(specs),
|
||||
@ -75,30 +76,24 @@ void AUD_SequencerFactory::unlock()
|
||||
|
||||
void AUD_SequencerFactory::setSpecs(AUD_Specs specs)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_specs = specs;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SequencerFactory::setFPS(float fps)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_fps = fps;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SequencerFactory::mute(bool muted)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_muted = muted;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
bool AUD_SequencerFactory::getMute() const
|
||||
@ -113,12 +108,10 @@ float AUD_SequencerFactory::getSpeedOfSound() const
|
||||
|
||||
void AUD_SequencerFactory::setSpeedOfSound(float speed)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_speed_of_sound = speed;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
float AUD_SequencerFactory::getDopplerFactor() const
|
||||
@ -128,12 +121,10 @@ float AUD_SequencerFactory::getDopplerFactor() const
|
||||
|
||||
void AUD_SequencerFactory::setDopplerFactor(float factor)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_doppler_factor = factor;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
AUD_DistanceModel AUD_SequencerFactory::getDistanceModel() const
|
||||
@ -143,12 +134,10 @@ AUD_DistanceModel AUD_SequencerFactory::getDistanceModel() const
|
||||
|
||||
void AUD_SequencerFactory::setDistanceModel(AUD_DistanceModel model)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_distance_model = model;
|
||||
m_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
AUD_AnimateableProperty* AUD_SequencerFactory::getAnimProperty(AUD_AnimateablePropertyType type)
|
||||
@ -168,26 +157,22 @@ AUD_AnimateableProperty* AUD_SequencerFactory::getAnimProperty(AUD_AnimateablePr
|
||||
|
||||
AUD_Reference<AUD_SequencerEntry> AUD_SequencerFactory::add(AUD_Reference<AUD_IFactory> sound, float begin, float end, float skip)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
AUD_Reference<AUD_SequencerEntry> entry = new AUD_SequencerEntry(sound, begin, end, skip, m_id++);
|
||||
|
||||
m_entries.push_front(entry);
|
||||
m_entry_status++;
|
||||
|
||||
unlock();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void AUD_SequencerFactory::remove(AUD_Reference<AUD_SequencerEntry> entry)
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_entries.remove(entry);
|
||||
m_entry_status++;
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
AUD_Reference<AUD_IReader> AUD_SequencerFactory::createQualityReader()
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include "AUD_IFactory.h"
|
||||
#include "AUD_AnimateableProperty.h"
|
||||
#include "AUD_ILockable.h"
|
||||
|
||||
#include <list>
|
||||
#include <pthread.h>
|
||||
@ -41,7 +42,7 @@ class AUD_SequencerEntry;
|
||||
/**
|
||||
* This factory represents sequenced entries to play a sound scene.
|
||||
*/
|
||||
class AUD_SequencerFactory : public AUD_IFactory
|
||||
class AUD_SequencerFactory : public AUD_IFactory, public AUD_ILockable
|
||||
{
|
||||
friend class AUD_SequencerReader;
|
||||
private:
|
||||
@ -104,12 +105,12 @@ public:
|
||||
/**
|
||||
* Locks the factory.
|
||||
*/
|
||||
void lock();
|
||||
virtual void lock();
|
||||
|
||||
/**
|
||||
* Unlocks the previously locked factory.
|
||||
*/
|
||||
void unlock();
|
||||
virtual void unlock();
|
||||
|
||||
/**
|
||||
* Sets the audio output specification.
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "AUD_SequencerHandle.h"
|
||||
#include "AUD_ReadDevice.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
AUD_SequencerHandle::AUD_SequencerHandle(AUD_Reference<AUD_SequencerEntry> entry, AUD_ReadDevice& device) :
|
||||
m_entry(entry),
|
||||
@ -68,7 +69,7 @@ void AUD_SequencerHandle::update(float position, float frame, float fps)
|
||||
{
|
||||
if(!m_handle.isNull())
|
||||
{
|
||||
m_entry->lock();
|
||||
AUD_MutexLock lock(*m_entry);
|
||||
if(position >= m_entry->m_end && m_entry->m_end >= 0)
|
||||
m_handle->pause();
|
||||
else if(position >= m_entry->m_begin)
|
||||
@ -134,7 +135,6 @@ void AUD_SequencerHandle::update(float position, float frame, float fps)
|
||||
|
||||
if(m_entry->m_muted)
|
||||
m_handle->setVolume(0);
|
||||
m_entry->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,11 +142,10 @@ void AUD_SequencerHandle::seek(float position)
|
||||
{
|
||||
if(!m_handle.isNull())
|
||||
{
|
||||
m_entry->lock();
|
||||
AUD_MutexLock lock(*m_entry);
|
||||
if(position >= m_entry->m_end && m_entry->m_end >= 0)
|
||||
{
|
||||
m_handle->pause();
|
||||
m_entry->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -160,6 +159,5 @@ void AUD_SequencerHandle::seek(float position)
|
||||
m_handle->pause();
|
||||
else
|
||||
m_handle->resume();
|
||||
m_entry->unlock();
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
#include "AUD_SequencerReader.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
typedef std::list<AUD_Reference<AUD_SequencerHandle> >::iterator AUD_HandleIterator;
|
||||
typedef std::list<AUD_Reference<AUD_SequencerEntry> >::iterator AUD_EntryIterator;
|
||||
@ -77,7 +78,7 @@ AUD_Specs AUD_SequencerReader::getSpecs() const
|
||||
|
||||
void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
|
||||
{
|
||||
m_factory->lock();
|
||||
AUD_MutexLock lock(*m_factory);
|
||||
|
||||
if(m_factory->m_status != m_status)
|
||||
{
|
||||
@ -197,8 +198,6 @@ void AUD_SequencerReader::read(int& length, bool& eos, sample_t* buffer)
|
||||
time += float(len) / float(specs.rate);
|
||||
}
|
||||
|
||||
m_factory->unlock();
|
||||
|
||||
m_position += length;
|
||||
|
||||
eos = false;
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "AUD_IFactory.h"
|
||||
#include "AUD_JOSResampleReader.h"
|
||||
#include "AUD_LinearResampleReader.h"
|
||||
#include "AUD_MutexLock.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
@ -226,7 +227,7 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::pause()
|
||||
{
|
||||
if(m_status)
|
||||
{
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(m_status == AUD_STATUS_PLAYING)
|
||||
{
|
||||
@ -236,12 +237,9 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::pause()
|
||||
if(m_device->m_playingSounds.empty())
|
||||
m_device->playing(m_device->m_playback = false);
|
||||
m_status = AUD_STATUS_PAUSED;
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -251,7 +249,7 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::resume()
|
||||
{
|
||||
if(m_status)
|
||||
{
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(m_status == AUD_STATUS_PAUSED)
|
||||
{
|
||||
@ -261,11 +259,9 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::resume()
|
||||
if(!m_device->m_playback)
|
||||
m_device->playing(m_device->m_playback = true);
|
||||
m_status = AUD_STATUS_PLAYING;
|
||||
m_device->unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
m_device->unlock();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -276,7 +272,10 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::stop()
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
// AUD_XXX Create a reference of our own object so that it doesn't get
|
||||
// deleted before the end of this function
|
||||
@ -292,7 +291,6 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::stop()
|
||||
else
|
||||
m_device->m_pausedSounds.remove(This);
|
||||
|
||||
m_device->unlock();
|
||||
m_status = AUD_STATUS_INVALID;
|
||||
return true;
|
||||
}
|
||||
@ -310,12 +308,13 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::setKeep(bool keep)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_keep = keep;
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -324,26 +323,28 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::seek(float position)
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_reader->seek((int)(position * m_reader->getSpecs().rate));
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float AUD_SoftwareDevice::AUD_SoftwareHandle::getPosition()
|
||||
{
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return 0.0f;
|
||||
|
||||
m_device->lock();
|
||||
|
||||
float position = m_reader->getPosition() / (float)m_device->m_specs.rate;
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
@ -407,13 +408,14 @@ bool AUD_SoftwareDevice::AUD_SoftwareHandle::setStopCallback(stopCallback callba
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_device->lock();
|
||||
AUD_MutexLock lock(*m_device);
|
||||
|
||||
if(!m_status)
|
||||
return false;
|
||||
|
||||
m_stop = callback;
|
||||
m_stop_data = data;
|
||||
|
||||
m_device->unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -691,7 +693,7 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
||||
{
|
||||
m_buffer.assureSize(length * AUD_SAMPLE_SIZE(m_specs));
|
||||
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
{
|
||||
AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound;
|
||||
@ -775,8 +777,6 @@ void AUD_SoftwareDevice::mix(data_t* buffer, int length)
|
||||
sound->pause();
|
||||
}
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SoftwareDevice::setPanning(AUD_IHandle* handle, float pan)
|
||||
@ -833,12 +833,12 @@ AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IReader> r
|
||||
// play sound
|
||||
AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound = new AUD_SoftwareDevice::AUD_SoftwareHandle(this, reader, pitch, resampler, mapper, keep);
|
||||
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
m_playingSounds.push_back(sound);
|
||||
|
||||
if(!m_playback)
|
||||
playing(m_playback = true);
|
||||
unlock();
|
||||
|
||||
return AUD_Reference<AUD_IHandle>(sound);
|
||||
}
|
||||
@ -850,15 +850,13 @@ AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IFactory>
|
||||
|
||||
void AUD_SoftwareDevice::stopAll()
|
||||
{
|
||||
lock();
|
||||
AUD_MutexLock lock(*this);
|
||||
|
||||
while(!m_playingSounds.empty())
|
||||
m_playingSounds.front()->stop();
|
||||
|
||||
while(!m_pausedSounds.empty())
|
||||
m_pausedSounds.front()->stop();
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void AUD_SoftwareDevice::lock()
|
||||
|
Loading…
Reference in New Issue
Block a user