diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 77e4e8258..4ec3aeb51 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -52,6 +52,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "st_start.h" #include "s_music.h" #include "i_video.h" +#include "c_dispatch.h" #include "glbackend/glbackend.h" #ifndef NETCODE_DISABLE #include "enet.h" @@ -603,7 +604,8 @@ int RunGame() M_Init(); SetDefaultStrings(); if (g_gameType & GAMEFLAG_RR) InitRREndMap(); // this needs to be done better later - //C_DoCommand("stat sounddebug"); + if (Args->CheckParm("-sounddebug")) + C_DoCommand("stat sounddebug"); if (enginePreInit()) { diff --git a/source/common/sound/s_sound.cpp b/source/common/sound/s_sound.cpp index e7a88100d..a56c3f90d 100644 --- a/source/common/sound/s_sound.cpp +++ b/source/common/sound/s_sound.cpp @@ -1736,7 +1736,7 @@ extern ReverbContainer* ForcedEnvironment; CVAR(Bool, snd_reverb, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) void FX_SetReverb(int strength) { - if (snd_reverb) + if (snd_reverb && strength > 0) { // todo: optimize environments. The original "reverb" was garbage and not usable as reference. if (strength < 64) strength = 0x1400; @@ -1744,6 +1744,7 @@ void FX_SetReverb(int strength) else strength = 0x1900; ForcedEnvironment = S_FindEnvironment(strength); } + else ForcedEnvironment = nullptr; } diff --git a/source/duke3d/src/sounds.cpp b/source/duke3d/src/sounds.cpp index 19ff7504b..a35defd22 100644 --- a/source/duke3d/src/sounds.cpp +++ b/source/duke3d/src/sounds.cpp @@ -475,8 +475,8 @@ int S_PlaySound(int num, int channel, EChanFlags flags) int A_PlaySound(int soundNum, int spriteNum, int channel, EChanFlags flags) { - return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, flags) : - S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, flags); + return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, channel, flags) : + S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, channel, flags); } void S_StopEnvSound(int sndNum, int sprNum, int channel) @@ -484,8 +484,15 @@ void S_StopEnvSound(int sndNum, int sprNum, int channel) if (sprNum < -1 || sprNum >= MAXSPRITES) return; if (sprNum == -1) soundEngine->StopSoundID(sndNum+1); - else if (channel == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum+1); - else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], channel, -1); + else + { + if (channel == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum + 1); + else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], channel, -1); + + // StopSound kills the actor reference so this cannot be delayed until ChannelEnded gets called. At that point the actor may also not be valid anymore. + if ( S_IsAmbientSFX(sprNum) && sector[SECT(sprNum)].lotag < 3) // ST_2_UNDERWATER + actor[sprNum].t_data[0] = 0; + } } void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset) diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index f75af005a..102bab1b9 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -1843,7 +1843,6 @@ void CheckCommandLine(int argc, char const* const* argv, int &doTitle) int GameInterface::app_main() { - C_DoCommand("stat sounddebug"); int i; //int esi = 1; //int edi = esi; diff --git a/source/rr/src/sounds.cpp b/source/rr/src/sounds.cpp index 252d6f592..cf997333d 100644 --- a/source/rr/src/sounds.cpp +++ b/source/rr/src/sounds.cpp @@ -473,17 +473,24 @@ int S_PlaySound(int sndnum, int channel, EChanFlags flags) int A_PlaySound(int soundNum, int spriteNum, int channel, EChanFlags flags) { - return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, flags) : - S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, flags); + return (unsigned)spriteNum >= MAXSPRITES ? S_PlaySound(soundNum, channel, flags) : + S_PlaySound3D(soundNum, spriteNum, &sprite[spriteNum].pos, channel, flags); } -void S_StopEnvSound(int sndNum, int sprNum, int flags) +void S_StopEnvSound(int sndNum, int sprNum, int channel) { if (sprNum < -1 || sprNum >= MAXSPRITES) return; if (sprNum == -1) soundEngine->StopSoundID(sndNum+1); - else if (flags == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum+1); - else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], flags, -1); + else + { + if (channel == -1) soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], -1, sndNum + 1); + else soundEngine->StopSound(SOURCE_Actor, &sprite[sprNum], channel, -1); + + // StopSound kills the actor reference so this cannot be delayed until ChannelEnded gets called. At that point the actor may also not be valid anymore. + if (S_IsAmbientSFX(sprNum) && sector[SECT(sprNum)].lotag < 3) // ST_2_UNDERWATER + actor[sprNum].t_data[0] = 0; + } } void S_ChangeSoundPitch(int soundNum, int spriteNum, int pitchoffset)