From 3ddac32b4f35678b0c48c73f5461cbd920e7ad2b Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 10 Aug 2012 03:49:50 +0000 Subject: [PATCH] - Because setting a DSP unit inactive completely ceases all processing on it, including timing, sounds queued up while the Channel Group Target Unit is inactive will all play at the same time once the unit is made active. To avoid this, it is now only deactivated when the gamestate is GS_LEVEL. Otherwise, it just gets muted. Fixes http://forum.zdoom.org/viewtopic.php?f=2&t=33592 "Strife voices overlap" SVN r3818 (trunk) --- src/s_sound.cpp | 6 ++++-- src/sound/fmodsound.cpp | 36 ++++++++++++++++++++++++++++++++++-- src/sound/fmodsound.h | 3 ++- src/sound/i_sound.cpp | 2 +- src/sound/i_sound.h | 8 +++++++- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 6c548f400..9749d635c 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1764,7 +1764,7 @@ void S_SetSoundPaused (int state) S_ResumeSound(true); if (GSnd != NULL) { - GSnd->SetInactive(false); + GSnd->SetInactive(SoundRenderer::INACTIVE_Active); } if (!netgame #ifdef _DEBUG @@ -1783,7 +1783,9 @@ void S_SetSoundPaused (int state) S_PauseSound(false, true); if (GSnd != NULL) { - GSnd->SetInactive(true); + GSnd->SetInactive(gamestate == GS_LEVEL ? + SoundRenderer::INACTIVE_Complete : + SoundRenderer::INACTIVE_Mute); } if (!netgame #ifdef _DEBUG diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index b01754324..5abb67e76 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -672,6 +672,7 @@ bool FMODSoundRenderer::Init() PrevEnvironment = DefaultEnvironments[0]; DSPClock.AsOne = 0; ChannelGroupTargetUnit = NULL; + ChannelGroupTargetUnitOutput = NULL; SfxReverbHooked = false; SfxReverbPlaceholder = NULL; OutputPlugin = 0; @@ -1155,6 +1156,15 @@ bool FMODSoundRenderer::Init() { ChannelGroupTargetUnit = NULL; } + else + { + FMOD::DSP *dontcare; + result = ChannelGroupTargetUnit->getOutput(0, &dontcare, &ChannelGroupTargetUnitOutput); + if (result != FMOD_OK) + { + ChannelGroupTargetUnitOutput = NULL; + } + } } } @@ -2123,11 +2133,33 @@ void FMODSoundRenderer::SetSfxPaused(bool paused, int slot) // //========================================================================== -void FMODSoundRenderer::SetInactive(bool inactive) +void FMODSoundRenderer::SetInactive(SoundRenderer::EInactiveState inactive) { + float mix; + bool active; + + if (inactive == INACTIVE_Active) + { + mix = 1; + active = true; + } + else if (inactive == INACTIVE_Complete) + { + mix = 1; + active = false; + } + else // inactive == INACTIVE_Mute + { + mix = 0; + active = true; + } + if (ChannelGroupTargetUnitOutput != NULL) + { + ChannelGroupTargetUnitOutput->setMix(mix); + } if (ChannelGroupTargetUnit != NULL) { - ChannelGroupTargetUnit->setActive(!inactive); + ChannelGroupTargetUnit->setActive(active); } } diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index e00b2ed27..99d627e5f 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -49,7 +49,7 @@ public: void SetSfxPaused (bool paused, int slot); // Pauses or resumes *every* channel, including environmental reverb. - void SetInactive (bool inactive); + void SetInactive (EInactiveState inactive); // Updates the position of a sound channel. void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel); @@ -107,6 +107,7 @@ private: FMOD::ChannelGroup *MusicGroup; FMOD::DSP *WaterLP, *WaterReverb; FMOD::DSPConnection *SfxConnection; + FMOD::DSPConnection *ChannelGroupTargetUnitOutput; FMOD::DSP *ChannelGroupTargetUnit; FMOD::DSP *SfxReverbPlaceholder; bool SfxReverbHooked; diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 27c00e93f..0fe68a25c 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -199,7 +199,7 @@ public: } // Pauses or resumes *every* channel, including environmental reverb. - void SetInactive(bool inactive) + void SetInactive(SoundRenderer::EInactiveState inactive) { } diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index 660e47166..c905678ad 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -126,7 +126,13 @@ public: virtual void SetSfxPaused (bool paused, int slot) = 0; // Pauses or resumes *every* channel, including environmental reverb. - virtual void SetInactive(bool inactive) = 0; + enum EInactiveState + { + INACTIVE_Active, // sound is active + INACTIVE_Complete, // sound is completely paused + INACTIVE_Mute // sound is only muted + }; + virtual void SetInactive(EInactiveState inactive) = 0; // Updates the volume, separation, and pitch of a sound channel. virtual void UpdateSoundParams3D (SoundListener *listener, FISoundChannel *chan, bool areasound, const FVector3 &pos, const FVector3 &vel) = 0;