|
|
@ -648,9 +648,8 @@ size_t OpenAL_Output::getSoundDataSize(Sound_Handle data) const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWBase::SoundPtr OpenAL_Output::playSound(Sound_Handle data, float vol, float basevol, float pitch, int flags, float offset)
|
|
|
|
void OpenAL_Output::playSound(MWBase::SoundPtr sound, Sound_Handle data, float offset)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Sound> sound;
|
|
|
|
|
|
|
|
ALuint source;
|
|
|
|
ALuint source;
|
|
|
|
|
|
|
|
|
|
|
|
if(mFreeSources.empty())
|
|
|
|
if(mFreeSources.empty())
|
|
|
@ -659,16 +658,15 @@ MWBase::SoundPtr OpenAL_Output::playSound(Sound_Handle data, float vol, float ba
|
|
|
|
mFreeSources.pop_front();
|
|
|
|
mFreeSources.pop_front();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sound.reset(new Sound(vol, basevol, pitch, flags));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alSourcef(source, AL_REFERENCE_DISTANCE, 1.0f);
|
|
|
|
alSourcef(source, AL_REFERENCE_DISTANCE, 1.0f);
|
|
|
|
alSourcef(source, AL_MAX_DISTANCE, 1000.0f);
|
|
|
|
alSourcef(source, AL_MAX_DISTANCE, 1000.0f);
|
|
|
|
alSourcef(source, AL_ROLLOFF_FACTOR, 0.0f);
|
|
|
|
alSourcef(source, AL_ROLLOFF_FACTOR, 0.0f);
|
|
|
|
alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
|
|
|
|
alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
|
|
|
|
alSourcei(source, AL_LOOPING, (flags&MWBase::SoundManager::Play_Loop) ? AL_TRUE : AL_FALSE);
|
|
|
|
alSourcei(source, AL_LOOPING, sound->getIsLooping() ? AL_TRUE : AL_FALSE);
|
|
|
|
|
|
|
|
|
|
|
|
ALfloat gain = vol*basevol;
|
|
|
|
ALfloat gain = sound->getRealVolume();
|
|
|
|
if(!(flags&MWBase::SoundManager::Play_NoEnv) && mListenerEnv == Env_Underwater)
|
|
|
|
ALfloat pitch = sound->getPitch();
|
|
|
|
|
|
|
|
if(sound->getUseEnv() && mListenerEnv == Env_Underwater)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gain *= 0.9f;
|
|
|
|
gain *= 0.9f;
|
|
|
|
pitch *= 0.7f;
|
|
|
|
pitch *= 0.7f;
|
|
|
@ -681,12 +679,12 @@ MWBase::SoundPtr OpenAL_Output::playSound(Sound_Handle data, float vol, float ba
|
|
|
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
|
|
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
alSourcef(source, AL_SEC_OFFSET, offset/pitch);
|
|
|
|
alSourcef(source, AL_SEC_OFFSET, offset/pitch);
|
|
|
|
alSourcei(source, AL_BUFFER, GET_PTRID(data));
|
|
|
|
throwALerror();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alSourcei(source, AL_BUFFER, GET_PTRID(data));
|
|
|
|
alSourcePlay(source);
|
|
|
|
alSourcePlay(source);
|
|
|
|
throwALerror();
|
|
|
|
throwALerror();
|
|
|
|
|
|
|
|
|
|
|
|
sound->mHandle = MAKE_PTRID(source);
|
|
|
|
|
|
|
|
mActiveSounds.push_back(sound);
|
|
|
|
mActiveSounds.push_back(sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(std::exception&) {
|
|
|
|
catch(std::exception&) {
|
|
|
@ -694,13 +692,11 @@ MWBase::SoundPtr OpenAL_Output::playSound(Sound_Handle data, float vol, float ba
|
|
|
|
throw;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
sound->mHandle = MAKE_PTRID(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MWBase::SoundPtr OpenAL_Output::playSound3D(Sound_Handle data, const osg::Vec3f &pos, float vol, float basevol, float pitch,
|
|
|
|
void OpenAL_Output::playSound3D(MWBase::SoundPtr sound, Sound_Handle data, float offset)
|
|
|
|
float mindist, float maxdist, int flags, float offset)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Sound> sound;
|
|
|
|
|
|
|
|
ALuint source;
|
|
|
|
ALuint source;
|
|
|
|
|
|
|
|
|
|
|
|
if(mFreeSources.empty())
|
|
|
|
if(mFreeSources.empty())
|
|
|
@ -709,18 +705,19 @@ MWBase::SoundPtr OpenAL_Output::playSound3D(Sound_Handle data, const osg::Vec3f
|
|
|
|
mFreeSources.pop_front();
|
|
|
|
mFreeSources.pop_front();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sound.reset(new Sound(pos, vol, basevol, pitch, mindist, maxdist, flags));
|
|
|
|
alSourcef(source, AL_REFERENCE_DISTANCE, sound->getMinDistance());
|
|
|
|
|
|
|
|
alSourcef(source, AL_MAX_DISTANCE, sound->getMaxDistance());
|
|
|
|
alSourcef(source, AL_REFERENCE_DISTANCE, mindist);
|
|
|
|
|
|
|
|
alSourcef(source, AL_MAX_DISTANCE, maxdist);
|
|
|
|
|
|
|
|
alSourcef(source, AL_ROLLOFF_FACTOR, 1.0f);
|
|
|
|
alSourcef(source, AL_ROLLOFF_FACTOR, 1.0f);
|
|
|
|
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
|
|
|
|
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
|
|
|
|
alSourcei(source, AL_LOOPING, (flags&MWBase::SoundManager::Play_Loop) ? AL_TRUE : AL_FALSE);
|
|
|
|
alSourcei(source, AL_LOOPING, sound->getIsLooping() ? AL_TRUE : AL_FALSE);
|
|
|
|
|
|
|
|
|
|
|
|
ALfloat gain = vol*basevol;
|
|
|
|
const osg::Vec3f &pos = sound->getPosition();
|
|
|
|
|
|
|
|
ALfloat maxdist = sound->getMaxDistance();
|
|
|
|
|
|
|
|
ALfloat gain = sound->getRealVolume();
|
|
|
|
|
|
|
|
ALfloat pitch = sound->getPitch();
|
|
|
|
if((pos - mListenerPos).length2() > maxdist*maxdist)
|
|
|
|
if((pos - mListenerPos).length2() > maxdist*maxdist)
|
|
|
|
gain = 0.0f;
|
|
|
|
gain = 0.0f;
|
|
|
|
if(!(flags&MWBase::SoundManager::Play_NoEnv) && mListenerEnv == Env_Underwater)
|
|
|
|
if(sound->getUseEnv() && mListenerEnv == Env_Underwater)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gain *= 0.9f;
|
|
|
|
gain *= 0.9f;
|
|
|
|
pitch *= 0.7f;
|
|
|
|
pitch *= 0.7f;
|
|
|
@ -733,12 +730,12 @@ MWBase::SoundPtr OpenAL_Output::playSound3D(Sound_Handle data, const osg::Vec3f
|
|
|
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
|
|
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
|
|
|
|
alSourcef(source, AL_SEC_OFFSET, offset/pitch);
|
|
|
|
alSourcef(source, AL_SEC_OFFSET, offset/pitch);
|
|
|
|
alSourcei(source, AL_BUFFER, GET_PTRID(data));
|
|
|
|
throwALerror();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alSourcei(source, AL_BUFFER, GET_PTRID(data));
|
|
|
|
alSourcePlay(source);
|
|
|
|
alSourcePlay(source);
|
|
|
|
throwALerror();
|
|
|
|
throwALerror();
|
|
|
|
|
|
|
|
|
|
|
|
sound->mHandle = MAKE_PTRID(source);
|
|
|
|
|
|
|
|
mActiveSounds.push_back(sound);
|
|
|
|
mActiveSounds.push_back(sound);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(std::exception&) {
|
|
|
|
catch(std::exception&) {
|
|
|
@ -746,14 +743,12 @@ MWBase::SoundPtr OpenAL_Output::playSound3D(Sound_Handle data, const osg::Vec3f
|
|
|
|
throw;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
sound->mHandle = MAKE_PTRID(source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenAL_Output::stopSound(MWBase::SoundPtr sound)
|
|
|
|
void OpenAL_Output::stopSound(MWBase::SoundPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ALuint source = GET_PTRID(sound->mHandle);
|
|
|
|
ALuint source = GET_PTRID(sound->mHandle);
|
|
|
|
sound->mHandle = 0;
|
|
|
|
sound->mHandle = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -766,8 +761,7 @@ void OpenAL_Output::stopSound(MWBase::SoundPtr sound)
|
|
|
|
|
|
|
|
|
|
|
|
bool OpenAL_Output::isSoundPlaying(MWBase::SoundPtr sound)
|
|
|
|
bool OpenAL_Output::isSoundPlaying(MWBase::SoundPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ALuint source = GET_PTRID(sound->mHandle);
|
|
|
|
ALuint source = GET_PTRID(sound->mHandle);
|
|
|
|
ALint state;
|
|
|
|
ALint state;
|
|
|
|
|
|
|
|
|
|
|
@ -911,8 +905,7 @@ MWBase::SoundStreamPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const os
|
|
|
|
|
|
|
|
|
|
|
|
void OpenAL_Output::stopStream(MWBase::SoundStreamPtr sound)
|
|
|
|
void OpenAL_Output::stopStream(MWBase::SoundStreamPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
ALuint source = stream->mSource;
|
|
|
|
ALuint source = stream->mSource;
|
|
|
|
|
|
|
|
|
|
|
@ -930,16 +923,14 @@ void OpenAL_Output::stopStream(MWBase::SoundStreamPtr sound)
|
|
|
|
|
|
|
|
|
|
|
|
double OpenAL_Output::getStreamDelay(MWBase::SoundStreamPtr sound)
|
|
|
|
double OpenAL_Output::getStreamDelay(MWBase::SoundStreamPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return 0.0;
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
return stream->getStreamDelay();
|
|
|
|
return stream->getStreamDelay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double OpenAL_Output::getStreamOffset(MWBase::SoundStreamPtr sound)
|
|
|
|
double OpenAL_Output::getStreamOffset(MWBase::SoundStreamPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return 0.0;
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
boost::lock_guard<boost::mutex> lock(mStreamThread->mMutex);
|
|
|
|
boost::lock_guard<boost::mutex> lock(mStreamThread->mMutex);
|
|
|
|
return stream->getStreamOffset();
|
|
|
|
return stream->getStreamOffset();
|
|
|
@ -947,8 +938,7 @@ double OpenAL_Output::getStreamOffset(MWBase::SoundStreamPtr sound)
|
|
|
|
|
|
|
|
|
|
|
|
bool OpenAL_Output::isStreamPlaying(MWBase::SoundStreamPtr sound)
|
|
|
|
bool OpenAL_Output::isStreamPlaying(MWBase::SoundStreamPtr sound)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!sound->mHandle)
|
|
|
|
if(!sound->mHandle) return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
|
|
|
boost::lock_guard<boost::mutex> lock(mStreamThread->mMutex);
|
|
|
|
boost::lock_guard<boost::mutex> lock(mStreamThread->mMutex);
|
|
|
|
return stream->isPlaying();
|
|
|
|
return stream->isPlaying();
|
|
|
|