mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:53:50 +00:00
Update sound and stream parameters
This commit is contained in:
parent
4bd235284b
commit
a6db96b2d8
5 changed files with 70 additions and 0 deletions
|
@ -775,6 +775,33 @@ bool OpenAL_Output::isSoundPlaying(MWBase::SoundPtr sound)
|
||||||
return state == AL_PLAYING || state == AL_PAUSED;
|
return state == AL_PLAYING || state == AL_PAUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenAL_Output::updateSound(MWBase::SoundPtr sound)
|
||||||
|
{
|
||||||
|
if(!sound->mHandle) return;
|
||||||
|
ALuint source = GET_PTRID(sound->mHandle);
|
||||||
|
|
||||||
|
const osg::Vec3f &pos = sound->getPosition();
|
||||||
|
ALfloat gain = sound->getRealVolume();
|
||||||
|
ALfloat pitch = sound->getPitch();
|
||||||
|
if(sound->getIs3D())
|
||||||
|
{
|
||||||
|
ALfloat maxdist = sound->getMaxDistance();
|
||||||
|
if((pos - mListenerPos).length2() > maxdist*maxdist)
|
||||||
|
gain = 0.0f;
|
||||||
|
}
|
||||||
|
if(sound->getUseEnv() && mListenerEnv == Env_Underwater)
|
||||||
|
{
|
||||||
|
gain *= 0.9f;
|
||||||
|
pitch *= 0.7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
alSourcef(source, AL_GAIN, gain);
|
||||||
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
|
alSourcefv(source, AL_POSITION, pos.ptr());
|
||||||
|
alSource3f(source, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MWBase::SoundStreamPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, float pitch, int flags)
|
MWBase::SoundStreamPtr OpenAL_Output::streamSound(DecoderPtr decoder, float basevol, float pitch, int flags)
|
||||||
{
|
{
|
||||||
|
@ -923,6 +950,34 @@ bool OpenAL_Output::isStreamPlaying(MWBase::SoundStreamPtr sound)
|
||||||
return stream->isPlaying();
|
return stream->isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenAL_Output::updateStream(MWBase::SoundStreamPtr sound)
|
||||||
|
{
|
||||||
|
if(!sound->mHandle) return;
|
||||||
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
||||||
|
ALuint source = stream->mSource;
|
||||||
|
|
||||||
|
const osg::Vec3f &pos = sound->getPosition();
|
||||||
|
ALfloat gain = sound->getRealVolume();
|
||||||
|
ALfloat pitch = sound->getPitch();
|
||||||
|
if(sound->getIs3D())
|
||||||
|
{
|
||||||
|
ALfloat maxdist = sound->getMaxDistance();
|
||||||
|
if((pos - mListenerPos).length2() > maxdist*maxdist)
|
||||||
|
gain = 0.0f;
|
||||||
|
}
|
||||||
|
if(sound->getUseEnv() && mListenerEnv == Env_Underwater)
|
||||||
|
{
|
||||||
|
gain *= 0.9f;
|
||||||
|
pitch *= 0.7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
alSourcef(source, AL_GAIN, gain);
|
||||||
|
alSourcef(source, AL_PITCH, pitch);
|
||||||
|
alSourcefv(source, AL_POSITION, pos.ptr());
|
||||||
|
alSource3f(source, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
|
||||||
|
alSource3f(source, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void OpenAL_Output::startUpdate()
|
void OpenAL_Output::startUpdate()
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace MWSound
|
||||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset);
|
float vol, float basevol, float pitch, float min, float max, int flags, float offset);
|
||||||
virtual void stopSound(MWBase::SoundPtr sound);
|
virtual void stopSound(MWBase::SoundPtr sound);
|
||||||
virtual bool isSoundPlaying(MWBase::SoundPtr sound);
|
virtual bool isSoundPlaying(MWBase::SoundPtr sound);
|
||||||
|
virtual void updateSound(MWBase::SoundPtr sound);
|
||||||
|
|
||||||
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags);
|
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags);
|
||||||
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
|
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
|
||||||
|
@ -60,6 +61,7 @@ namespace MWSound
|
||||||
virtual double getStreamDelay(MWBase::SoundStreamPtr sound);
|
virtual double getStreamDelay(MWBase::SoundStreamPtr sound);
|
||||||
virtual double getStreamOffset(MWBase::SoundStreamPtr sound);
|
virtual double getStreamOffset(MWBase::SoundStreamPtr sound);
|
||||||
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound);
|
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound);
|
||||||
|
virtual void updateStream(MWBase::SoundStreamPtr sound);
|
||||||
|
|
||||||
virtual void startUpdate();
|
virtual void startUpdate();
|
||||||
virtual void finishUpdate();
|
virtual void finishUpdate();
|
||||||
|
|
|
@ -40,8 +40,14 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const osg::Vec3f &getPosition() const { return mPos; }
|
||||||
|
float getRealVolume() const { return mVolume * mBaseVolume; }
|
||||||
|
float getPitch() const { return mPitch; }
|
||||||
|
float getMaxDistance() const { return mMaxDistance; }
|
||||||
|
|
||||||
MWBase::SoundManager::PlayType getPlayType() const
|
MWBase::SoundManager::PlayType getPlayType() const
|
||||||
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
||||||
|
bool getUseEnv() const { return !(mFlags&MWBase::SoundManager::Play_NoEnv); }
|
||||||
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
|
bool getDistanceCull() const { return mFlags&MWBase::SoundManager::Play_RemoveAtDistance; }
|
||||||
bool getIs3D() const { return mFlags&Play_3D; }
|
bool getIs3D() const { return mFlags&Play_3D; }
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace MWSound
|
||||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset) = 0;
|
float vol, float basevol, float pitch, float min, float max, int flags, float offset) = 0;
|
||||||
virtual void stopSound(MWBase::SoundPtr sound) = 0;
|
virtual void stopSound(MWBase::SoundPtr sound) = 0;
|
||||||
virtual bool isSoundPlaying(MWBase::SoundPtr sound) = 0;
|
virtual bool isSoundPlaying(MWBase::SoundPtr sound) = 0;
|
||||||
|
virtual void updateSound(MWBase::SoundPtr sound) = 0;
|
||||||
|
|
||||||
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags) = 0;
|
virtual MWBase::SoundStreamPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags) = 0;
|
||||||
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
|
virtual MWBase::SoundStreamPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
|
||||||
|
@ -45,6 +46,7 @@ namespace MWSound
|
||||||
virtual double getStreamDelay(MWBase::SoundStreamPtr sound) = 0;
|
virtual double getStreamDelay(MWBase::SoundStreamPtr sound) = 0;
|
||||||
virtual double getStreamOffset(MWBase::SoundStreamPtr sound) = 0;
|
virtual double getStreamOffset(MWBase::SoundStreamPtr sound) = 0;
|
||||||
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound) = 0;
|
virtual bool isStreamPlaying(MWBase::SoundStreamPtr sound) = 0;
|
||||||
|
virtual void updateStream(MWBase::SoundStreamPtr sound) = 0;
|
||||||
|
|
||||||
virtual void startUpdate() = 0;
|
virtual void startUpdate() = 0;
|
||||||
virtual void finishUpdate() = 0;
|
virtual void finishUpdate() = 0;
|
||||||
|
|
|
@ -853,6 +853,7 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
sound->updateFade(duration);
|
sound->updateFade(duration);
|
||||||
|
|
||||||
|
mOutput->updateSound(sound);
|
||||||
++sndidx;
|
++sndidx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -918,6 +919,7 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
sound->updateFade(duration);
|
sound->updateFade(duration);
|
||||||
|
|
||||||
|
mOutput->updateStream(sound);
|
||||||
++sayiter;
|
++sayiter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -958,6 +960,7 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
MWBase::SoundPtr sound = sndidx->first;
|
MWBase::SoundPtr sound = sndidx->first;
|
||||||
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
||||||
|
mOutput->updateSound(sound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
|
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
|
||||||
|
@ -965,10 +968,12 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
MWBase::SoundStreamPtr sound = sayiter->second.first;
|
MWBase::SoundStreamPtr sound = sayiter->second.first;
|
||||||
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
sound->setBaseVolume(volumeFromType(sound->getPlayType()));
|
||||||
|
mOutput->updateStream(sound);
|
||||||
}
|
}
|
||||||
if(mMusic)
|
if(mMusic)
|
||||||
{
|
{
|
||||||
mMusic->setBaseVolume(volumeFromType(mMusic->getPlayType()));
|
mMusic->setBaseVolume(volumeFromType(mMusic->getPlayType()));
|
||||||
|
mOutput->updateStream(mMusic);
|
||||||
}
|
}
|
||||||
mOutput->finishUpdate();
|
mOutput->finishUpdate();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue