diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 8a6568787..f75af005a 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -1343,9 +1343,7 @@ void FinishLevel() if (levelnum != kMap20) { EraseScreen(4); - SetLocalChan(1); - PlayLocalSound(StaticSound[59], 0); - SetLocalChan(0); + PlayLocalSound(StaticSound[59], 0, true); videoNextPage(); WaitTicks(12); WaitVBL(); @@ -2570,10 +2568,7 @@ void DoTitle() SetOverscan(BASEPAL); GrabPalette(); - SetLocalChan(1); - PlayLocalSound(StaticSound[59], 0); - - SetLocalChan(0); + PlayLocalSound(StaticSound[59], 0, true); EraseScreen(4); diff --git a/source/exhumed/src/sound.cpp b/source/exhumed/src/sound.cpp index b692eac7a..1044ea15b 100644 --- a/source/exhumed/src/sound.cpp +++ b/source/exhumed/src/sound.cpp @@ -160,11 +160,6 @@ enum nSwirlyChan4, }; -void SetLocalChan(int c) -{ - nLocalChan = c; -} - //========================================================================== // // @@ -337,33 +332,41 @@ void BendAmbientSound(void) // //========================================================================== -void PlayLocalSound(short nSound, short nRate) +void PlayLocalSound(short nSound, short nRate, bool unattached) { if (nSound < 0 || nSound >= kMaxSounds || !soundEngine->isValidSoundId(nSound + 1)) { initprintf("PlayLocalSound: Invalid sound nSound == %i, nRate == %i\n", nSound, nRate); return; } + int bLoop = looped[nSound]; if (nLocalChan == nAmbientChannel) nAmbientChannel = -1; - int bLoop = looped[nSound]; - ActiveSound* pASound = &sActiveSound[nLocalChan]; - if (pASound->snd_channel != nullptr) - soundEngine->StopChannel(pASound->snd_channel); - - // There is exactly one occurence in the entire game which alters the pitch. - pASound->snd_channel = soundEngine->StartSound(SOURCE_Unattached, nullptr, nullptr, CHAN_BODY, CHANF_OVERLAP, nSound + 1, 1.f, ATTN_NONE, nullptr); - - if (nRate && pASound->snd_channel) + ActiveSound* pASound = nullptr; + + if (!unattached) { - float ratefac = (11025 + nRate) / 11025.f; - soundEngine->SetPitch(pASound->snd_channel, ratefac); + pASound = &sActiveSound[nLocalChan]; + if (pASound->snd_channel != nullptr) + soundEngine->StopChannel(pASound->snd_channel); } - pASound->snd_id = nSound; + // There is exactly one occurence in the entire game which alters the pitch, and that's the laugh on the logo. + auto chan = soundEngine->StartSound(SOURCE_Unattached, nullptr, nullptr, CHAN_BODY, CHANF_OVERLAP, nSound + 1, 1.f, ATTN_NONE, nullptr); + + if (nRate && chan) + { + float ratefac = (11025 + nRate) / 11025.f; + soundEngine->SetPitch(chan, ratefac); + } + if (pASound) + { + pASound->snd_id = nSound; + pASound->snd_channel = chan; + } } //========================================================================== diff --git a/source/exhumed/src/sound.h b/source/exhumed/src/sound.h index efcf2331f..02276dcc2 100644 --- a/source/exhumed/src/sound.h +++ b/source/exhumed/src/sound.h @@ -125,11 +125,10 @@ int fadecdaudio(); int LocalSoundPlaying(); void LoadFX(); void StopAllSounds(); -void SetLocalChan(int nChannel); int GetLocalSound(); void UpdateLocalSound(); void StopLocalSound(); -void PlayLocalSound(short nSound, short val); +void PlayLocalSound(short nSound, short val, bool unattached = false); int LoadSound(const char* sound); void BendAmbientSound();