Skip to content

Commit

Permalink
- Fixed OpenAL regression with looping sounds with playing length 0.
Browse files Browse the repository at this point in the history
If such case occurs, the starttime parameter passed to the sound functions is ignored and truncated to 0.
  • Loading branch information
edward-san authored and coelckers committed Jun 3, 2020
1 parent e2e47b8 commit 8ab6575
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/common/audio/sound/oalsound.cpp
Expand Up @@ -1420,7 +1420,10 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener

if(!reuse_chan || reuse_chan->StartTime == 0)
{
float st = (chanflags & SNDF_LOOP) ? fmod(startTime, (float)GetMSLength(sfx) / 1000.f) : clamp<float>(startTime, 0.f, (float)GetMSLength(sfx) / 1000.f);
float sfxlength = (float)GetMSLength(sfx) / 1000.f;
float st = (chanflags & SNDF_LOOP)
? (sfxlength > 0 ? fmod(startTime, sfxlength) : 0)
: clamp<float>(startTime, 0.f, sfxlength);
alSourcef(source, AL_SEC_OFFSET, st);
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/common/audio/sound/s_sound.cpp
Expand Up @@ -547,9 +547,10 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
if (chanflags & (CHANF_UI|CHANF_NOPAUSE)) startflags |= SNDF_NOPAUSE;
if (chanflags & CHANF_UI) startflags |= SNDF_NOREVERB;

float sfxlength = (float)GSnd->GetMSLength(sfx->data) / 1000.f;
startTime = (startflags & SNDF_LOOP)
? fmod(startTime, (float)GSnd->GetMSLength(sfx->data) / 1000.f)
: clamp<float>(startTime, 0.f, (float)GSnd->GetMSLength(sfx->data) / 1000.f);
? (sfxlength > 0 ? fmod(startTime, sfxlength) : 0)
: clamp<float>(startTime, 0.f, sfxlength);

if (attenuation > 0 && type != SOURCE_None)
{
Expand Down

0 comments on commit 8ab6575

Please sign in to comment.