Check if sound is currently playing in a channel

Moderator: GZDoom Developers

User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Check if sound is currently playing in a channel

Post by Marisa the Magician »

I'm interested in having a way to check in ZScript whether or not an actor is playing sound in a specific channel.

I have a system where this would be very useful. Basically, I spawn actors that attach to players with a specific offset in order to play some ambient noises that seem to come from a fixed direction. At the moment I hardcode their lifespan, which is rather time consuming since I have to go through so many different sound effects, and also it wouldn't take into account pitch shift.
_mental_
 
 
Posts: 3814
Joined: Sun Aug 07, 2011 4:32 am

Re: Check if sound is currently playing in a channel

Post by _mental_ »

Do you need some like this?

Code: Select all

bool S_IsChannelPlaying (int channel)
Or maybe this?

Code: Select all

bool S_IsActorPlaying(Actor source, int channel, Sound id)
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

If the first function can be called from within the playing actor, then yes, that one would be handy.
_mental_
 
 
Posts: 3814
Joined: Sun Aug 07, 2011 4:32 am

Re: Check if sound is currently playing in a channel

Post by _mental_ »

No, both are static functions in Object class. I assume you need the latter, scriptified S_IsActorPlayingSomething() function in other words.

EDIT: Or even better like this

Code: Select all

class Actor
{
    // ...
    native bool A_IsPlayingSound(int channel, sound sound_id = "");
    // ...
}
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

Oh, that one would do it, yes.
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Check if sound is currently playing in a channel

Post by RaveYard »

Isn't this feature going to cause an issue with multiplayer and demos?

Or am I missing something?
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

Actually I was wondering about that too. How would this be implemented in a way that wouldn't desync? Is it even possible to have "clientside" actors or something that wouldn't get synced?
_mental_
 
 
Posts: 3814
Joined: Sun Aug 07, 2011 4:32 am

Re: Check if sound is currently playing in a channel

Post by _mental_ »

It depends on what you about to do with information returned from this function.
If you will use it for some game logic decisions, it may cause problems in MP.
If you plan to just stop this sound and play that one, everything will be fine.
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

Oh, then I can see it causing problems, since it would be used for deleting a sound playing actor.

Edit: I talked about this with Rachael and it seems that within my use case it might not desync, actually, since the actors have no other interaction with the game at all beyond warping to the player and playing sound.
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Check if sound is currently playing in a channel

Post by RaveYard »

It shouldn't desync as long as you avoid using random number generators.

From my experience, if done well, you can spawn actors just on one peer without causing desync if they don't interact with the game and if they have specific flags and properties set.
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

The flags for this actor are +NOGRAVITY, +NOBLOCKMAP, +NOSECTOR and +DONTSPLASH (because it's used on Heretic). Is that enough?
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Check if sound is currently playing in a channel

Post by RaveYard »

Instead of +NOSECTOR you can use +NOINTERACTION and thus keep the actor visible (for other purposes if need be).

Don't forget to set "FloatBobPhase" to something else than -1 (See here why: https://github.com/coelckers/gzdoom/blo ... .cpp#L5065 )
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

Oh, I see. Although visibility isn't really important at all since it's just a sound effect. No need to be seen or anything.

I'm a bit confused about the FloatBobPhase part, though. The actor doesn't even have floatbob or anything.

Oh wait, it would screw the RNG seed, I see.

Edit: I was digging through the sources a little bit ago and I came across the S_GetMSLength() function, for getting the duration of a sound. Looking at it, I think this one might be a better choice (would even add some parity with unrealscript).

Edit 2: I opened a pull request on qzdoom for both functions.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49141
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Check if sound is currently playing in a channel

Post by Graf Zahl »

So, S_GetMSLength was exported, but S_IsActorPlayingSomething was not. So I just added that export, too.

Regarding desyncs, yes, if you make any gameplay related decisions on sounds it will desync. On the other hand, there's no way to design sound without some tools to query the state.
This is a case where trying to make it foolproof is not the best solution, at some point it is the modder's responsibility to use those functions properly.
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia

Re: Check if sound is currently playing in a channel

Post by Marisa the Magician »

Well, ever since the time I made this suggestion I've gotten quite proficient at making non-deterministic gameplay scripting that doesn't cause desyncs. :P

Return to “Closed Feature Suggestions [GZDoom]”