diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 644246522..661e90a44 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1493,14 +1493,20 @@ void ProcessInput(PLAYER *pPlayer) if (pXSector->locked && pPlayer == gMe) { viewSetMessage(GStrings("TXTB_LOCKED")); - sndStartSample(3062, 255, 2, 0); + auto snd = 3062; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } if (!key || pPlayer->hasKey[key]) trTriggerSector(a2, pXSector, kCmdSpritePush); else if (pPlayer == gMe) { viewSetMessage(GStrings("TXTB_KEY")); - sndStartSample(3063, 255, 2, 0); + auto snd = 3063; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } } break; @@ -1511,14 +1517,20 @@ void ProcessInput(PLAYER *pPlayer) if (pXWall->locked && pPlayer == gMe) { viewSetMessage(GStrings("TXTB_LOCKED")); - sndStartSample(3062, 255, 2, 0); + auto snd = 3062; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } if (!key || pPlayer->hasKey[key]) trTriggerWall(a2, pXWall, kCmdWallPush); else if (pPlayer == gMe) { viewSetMessage(GStrings("TXTB_KEY")); - sndStartSample(3063, 255, 2, 0); + auto snd = 3063; + if (sndCheckPlaying(snd)) + sndStopSample(snd); + sndStartSample(snd, 255, 2, 0); } break; } diff --git a/source/blood/src/sound.cpp b/source/blood/src/sound.cpp index 56f6282f5..eb70241d1 100644 --- a/source/blood/src/sound.cpp +++ b/source/blood/src/sound.cpp @@ -144,6 +144,22 @@ void SoundCallback(intptr_t val) pChannel->TotalKills = 0; } +bool sndCheckPlaying(unsigned int nSound) +{ + auto snd = soundEngine->FindSoundByResID(nSound); + return snd > 0 ? soundEngine->GetSoundPlayingInfo(SOURCE_Any, nullptr, snd) : false; +} + +void sndStopSample(unsigned int nSound) +{ + auto snd = soundEngine->FindSoundByResID(nSound); + + if (snd > 0) + { + soundEngine->StopSoundID(snd); + } +} + void sndStartSample(const char *pzSound, int nVolume, int nChannel) { if (!SoundEnabled()) diff --git a/source/blood/src/sound.h b/source/blood/src/sound.h index b3dd7085a..5fe03882d 100644 --- a/source/blood/src/sound.h +++ b/source/blood/src/sound.h @@ -45,6 +45,8 @@ struct SFX }; int sndGetRate(int format); +bool sndCheckPlaying(unsigned int nSound); +void sndStopSample(unsigned int nSound); void sndStartSample(const char *pzSound, int nVolume, int nChannel = -1); void sndStartSample(unsigned int nSound, int nVolume, int nChannel = -1, bool bLoop = false, EChanFlags soundflags = CHANF_NONE); void sndStartWavID(unsigned int nSound, int nVolume, int nChannel = -1);