From 1b9c71b2520a2f5ffc3cb024bd7ccf8aeab52350 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 1 Jun 2013 17:46:50 +0000 Subject: [PATCH] - Added S_ChangeSoundVolume() to change the volume of an already playing sound, accessible through the new ACS function SoundVolume. SVN r4318 (trunk) --- src/p_acs.cpp | 24 ++++++++++++++++++++++++ src/s_sound.cpp | 24 +++++++++++++++++++++++- src/s_sound.h | 3 +++ src/sound/fmodsound.cpp | 14 ++++++++++++++ src/sound/fmodsound.h | 3 +++ src/sound/i_sound.cpp | 3 +++ src/sound/i_sound.h | 3 +++ 7 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index bd1f18484..99ddf7780 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -4134,6 +4134,7 @@ enum EACSFunctions ACSF_StrMid, ACSF_GetActorClass, ACSF_GetWeapon, + ACSF_SoundVolume, // ZDaemon ACSF_GetTeamScore = 19620, // (int team) @@ -4964,6 +4965,29 @@ doplaysound: if (!looping) } break; + case ACSF_SoundVolume: + // SoundVolume(int tid, int channel, fixed volume) + { + int chan = args[1]; + float volume = FIXED2FLOAT(args[2]); + + if (args[0] == 0) + { + S_ChangeSoundVolume(activator, chan, volume); + } + else + { + FActorIterator it(args[0]); + AActor *spot; + + while ((spot = it.Next()) != NULL) + { + S_ChangeSoundVolume(spot, chan, volume); + } + } + } + break; + case ACSF_strcmp: case ACSF_stricmp: if (argCount >= 2) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 3da346bf3..2626c2b82 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1592,6 +1592,29 @@ void S_RelinkSound (AActor *from, AActor *to) } } + +//========================================================================== +// +// S_ChangeSoundVolume +// +//========================================================================== + +bool S_ChangeSoundVolume(AActor *actor, int channel, float volume) +{ + for (FSoundChan *chan = Channels; chan != NULL; chan = chan->NextChan) + { + if (chan->SourceType == SOURCE_Actor && + chan->Actor == actor && + (chan->EntChannel == channel || (i_compatflags & COMPATF_MAGICSILENCE))) + { + GSnd->ChannelVolume(chan, volume); + chan->Volume = volume; + return true; + } + } + return false; +} + //========================================================================== // // S_GetSoundPlayingInfo @@ -2136,7 +2159,6 @@ void S_StopChannel(FSoundChan *chan) } } - //========================================================================== // // (FArchive &) << (FSoundID &) diff --git a/src/s_sound.h b/src/s_sound.h index 2f4f68647..346e51ce1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -303,6 +303,9 @@ bool S_GetSoundPlayingInfo (const FPolyObj *poly, int sound_id); bool S_IsActorPlayingSomething (AActor *actor, int channel, int sound_id); +// Change a playing sound's volume +bool S_ChangeSoundVolume(AActor *actor, int channel, float volume); + // Moves all sounds from one mobj to another void S_RelinkSound (AActor *from, AActor *to); diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index 5abb67e76..133fc2406 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -2053,6 +2053,20 @@ void FMODSoundRenderer::StopChannel(FISoundChannel *chan) } } +//========================================================================== +// +// FMODSoundRenderer :: ChannelVolume +// +//========================================================================== + +void FMODSoundRenderer::ChannelVolume(FISoundChannel *chan, float volume) +{ + if (chan != NULL && chan->SysChannel != NULL) + { + ((FMOD::Channel *)chan->SysChannel)->setVolume(volume); + } +} + //========================================================================== // // FMODSoundRenderer :: GetPosition diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index 99d627e5f..93b70ce87 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -33,6 +33,9 @@ public: // Stops a sound channel. void StopChannel (FISoundChannel *chan); + // Changes a channel's volume. + void ChannelVolume (FISoundChannel *chan, float volume); + // Marks a channel's start time without actually playing it. void MarkStartTime (FISoundChannel *chan); diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 0fe68a25c..c95b0221f 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -150,6 +150,9 @@ public: void StopChannel(FISoundChannel *chan) { } + void ChannelVolume(FISoundChannel *, float) + { + } // Streaming sounds. SoundStream *CreateStream (SoundStreamCallback callback, int buffbytes, int flags, int samplerate, void *userdata) diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index c905678ad..adce8796b 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -110,6 +110,9 @@ public: // Stops a sound channel. virtual void StopChannel (FISoundChannel *chan) = 0; + // Changes a channel's volume. + virtual void ChannelVolume (FISoundChannel *chan, float volume) = 0; + // Marks a channel's start time without actually playing it. virtual void MarkStartTime (FISoundChannel *chan) = 0;