mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
Treat the sound offset as the offset in seconds
This commit is contained in:
parent
8b7587f9a6
commit
82f3651f81
6 changed files with 16 additions and 43 deletions
|
@ -109,13 +109,13 @@ namespace MWBase
|
|||
PlayType type=Play_TypeSfx, PlayMode mode=Play_Normal,
|
||||
float offset=0) = 0;
|
||||
///< Play a sound, independently of 3D-position
|
||||
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual MWBase::SoundPtr playSound3D(const MWWorld::Ptr &reference, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type=Play_TypeSfx,
|
||||
PlayMode mode=Play_Normal, float offset=0) = 0;
|
||||
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
||||
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual MWBase::SoundPtr playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type=Play_TypeSfx, PlayMode mode=Play_Normal, float offset=0) = 0;
|
||||
|
|
|
@ -169,7 +169,9 @@ namespace MWClass
|
|||
{
|
||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||
closeSound, 0.5f);
|
||||
float offset = doorRot/ 3.14159265f * 2.0f;
|
||||
// Doors rotate at 90 degrees per second, so start the sound at
|
||||
// where it would be at the current rotation.
|
||||
float offset = doorRot/(3.14159265f * 0.5f);
|
||||
action->setSoundOffset(offset);
|
||||
action->setSound(openSound);
|
||||
}
|
||||
|
@ -177,10 +179,8 @@ namespace MWClass
|
|||
{
|
||||
MWBase::Environment::get().getSoundManager()->fadeOutSound3D(ptr,
|
||||
openSound, 0.5f);
|
||||
float offset = 1.0f - doorRot/ 3.14159265f * 2.0f;
|
||||
//most if not all door have closing bang somewhere in the middle of the sound,
|
||||
//so we divide offset by two
|
||||
action->setSoundOffset(offset * 0.5f);
|
||||
float offset = 1.0f - doorRot/(3.14159265f * 0.5f);
|
||||
action->setSoundOffset(std::max(offset, 0.0f));
|
||||
action->setSound(closeSound);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,18 +146,6 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
|||
return AL_NONE;
|
||||
}
|
||||
|
||||
static double getBufferLength(ALuint buffer)
|
||||
{
|
||||
ALint bufferSize, frequency, channels, bitsPerSample;
|
||||
alGetBufferi(buffer, AL_SIZE, &bufferSize);
|
||||
alGetBufferi(buffer, AL_FREQUENCY, &frequency);
|
||||
alGetBufferi(buffer, AL_CHANNELS, &channels);
|
||||
alGetBufferi(buffer, AL_BITS, &bitsPerSample);
|
||||
throwALerror();
|
||||
|
||||
return (8.0*bufferSize)/(frequency*channels*bitsPerSample);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// A streaming OpenAL sound.
|
||||
|
@ -863,14 +851,9 @@ MWBase::SoundPtr OpenAL_Output::playSound(Sound_Handle data, float vol, float ba
|
|||
}
|
||||
|
||||
sound->updateAll(true);
|
||||
if(offset < 0.0f)
|
||||
offset = 0.0f;
|
||||
if(offset > 1.0f)
|
||||
offset = 1.0f;
|
||||
alSourcei(src, AL_BUFFER, GET_PTRID(data));
|
||||
alSourcef(src, AL_SEC_OFFSET, offset/pitch);
|
||||
|
||||
ALuint buffer = GET_PTRID(data);
|
||||
alSourcei(src, AL_BUFFER, buffer);
|
||||
alSourcef(src, AL_SEC_OFFSET, static_cast<ALfloat>(getBufferLength(buffer)*offset / pitch));
|
||||
alSourcePlay(src);
|
||||
throwALerror();
|
||||
|
||||
|
@ -898,14 +881,8 @@ MWBase::SoundPtr OpenAL_Output::playSound3D(Sound_Handle data, const osg::Vec3f
|
|||
}
|
||||
|
||||
sound->updateAll(false);
|
||||
if(offset < 0.0f)
|
||||
offset = 0.0f;
|
||||
if(offset > 1.0f)
|
||||
offset = 1.0f;
|
||||
|
||||
ALuint buffer = GET_PTRID(data);
|
||||
alSourcei(src, AL_BUFFER, buffer);
|
||||
alSourcef(src, AL_SEC_OFFSET, static_cast<ALfloat>(getBufferLength(buffer)*offset / pitch));
|
||||
alSourcei(src, AL_BUFFER, GET_PTRID(data));
|
||||
alSourcef(src, AL_SEC_OFFSET, offset/pitch);
|
||||
|
||||
alSourcePlay(src);
|
||||
throwALerror();
|
||||
|
|
|
@ -42,9 +42,7 @@ namespace MWSound
|
|||
virtual void unloadSound(Sound_Handle data);
|
||||
virtual size_t getSoundDataSize(Sound_Handle data) const;
|
||||
|
||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
virtual MWBase::SoundPtr playSound(Sound_Handle data, float vol, float basevol, float pitch, int flags, float offset);
|
||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
virtual MWBase::SoundPtr playSound3D(Sound_Handle data, const osg::Vec3f &pos,
|
||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset);
|
||||
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags);
|
||||
|
|
|
@ -30,9 +30,9 @@ namespace MWSound
|
|||
virtual void unloadSound(Sound_Handle data) = 0;
|
||||
virtual size_t getSoundDataSize(Sound_Handle data) const = 0;
|
||||
|
||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
/// @param offset Number of seconds into the sound to start playback.
|
||||
virtual MWBase::SoundPtr playSound(Sound_Handle data, float vol, float basevol, float pitch, int flags, float offset) = 0;
|
||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
/// @param offset Number of seconds into the sound to start playback.
|
||||
virtual MWBase::SoundPtr playSound3D(Sound_Handle data, const osg::Vec3f &pos,
|
||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset) = 0;
|
||||
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float basevol, float pitch, int flags) = 0;
|
||||
|
|
|
@ -166,20 +166,18 @@ namespace MWSound
|
|||
|
||||
virtual MWBase::SoundPtr playSound(const std::string& soundId, float volume, float pitch, PlayType type=Play_TypeSfx, PlayMode mode=Play_Normal, float offset=0);
|
||||
///< Play a sound, independently of 3D-position
|
||||
///< @param offset value from [0,1], when to start playback. 0 is beginning, 1 is end.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual MWBase::SoundPtr playSound3D(const MWWorld::Ptr &reference, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type=Play_TypeSfx,
|
||||
PlayMode mode=Play_Normal, float offset=0);
|
||||
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
||||
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual MWBase::SoundPtr playSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||
float volume, float pitch, PlayType type, PlayMode mode, float offset=0);
|
||||
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
|
||||
|
||||
///< Play a sound from an object
|
||||
///< @param offset value from [0,1], when to start playback. 0 is beginning, 1 is end.
|
||||
///< @param offset Number of seconds into the sound to start playback.
|
||||
|
||||
virtual void stopSound3D(const MWWorld::Ptr &reference, const std::string& soundId);
|
||||
///< Stop the given object from playing the given sound,
|
||||
|
|
Loading…
Reference in a new issue