From 8ab6575bd1687fc1c17d00aa54254f49ff894118 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Wed, 3 Jun 2020 14:37:52 +0200 Subject: [PATCH] - Fixed OpenAL regression with looping sounds with playing length 0. If such case occurs, the starttime parameter passed to the sound functions is ignored and truncated to 0. --- src/common/audio/sound/oalsound.cpp | 5 ++++- src/common/audio/sound/s_sound.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/audio/sound/oalsound.cpp b/src/common/audio/sound/oalsound.cpp index 69d00151c4f..be3cc5d6583 100644 --- a/src/common/audio/sound/oalsound.cpp +++ b/src/common/audio/sound/oalsound.cpp @@ -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(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(startTime, 0.f, sfxlength); alSourcef(source, AL_SEC_OFFSET, st); } else diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index b6d6bb24237..04a56491337 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -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(startTime, 0.f, (float)GSnd->GetMSLength(sfx->data) / 1000.f); + ? (sfxlength > 0 ? fmod(startTime, sfxlength) : 0) + : clamp(startTime, 0.f, sfxlength); if (attenuation > 0 && type != SOURCE_None) {