[Added] Check if sound is currently playing in a channel

Moderator: GZDoom Developers

Check if sound is currently playing in a channel

Postby Marisa Kirisame » Fri Dec 22, 2017 4:47 pm

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.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby _mental_ » Sat Dec 23, 2017 7:13 am

Do you need some like this?
Code: Select allExpand view
bool S_IsChannelPlaying (int channel)

Or maybe this?
Code: Select allExpand view
bool S_IsActorPlaying(Actor source, int channel, Sound id)
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Sun Dec 24, 2017 7:29 am

If the first function can be called from within the playing actor, then yes, that one would be handy.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby _mental_ » Sun Dec 24, 2017 7:35 am

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 allExpand view
class Actor
{
    // ...
    native bool A_IsPlayingSound(int channel, sound sound_id = "");
    // ...
}
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Sun Dec 24, 2017 10:29 am

Oh, that one would do it, yes.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby RaveYard » Mon Dec 25, 2017 12:08 pm

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

Or am I missing something?
RaveYard
 
Joined: 12 Apr 2013

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Tue Dec 26, 2017 6:04 am

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?
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby _mental_ » Tue Dec 26, 2017 7:46 am

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.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Wed Dec 27, 2017 3:57 am

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.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby RaveYard » Wed Dec 27, 2017 5:46 am

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.
RaveYard
 
Joined: 12 Apr 2013

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Wed Dec 27, 2017 6:55 am

The flags for this actor are +NOGRAVITY, +NOBLOCKMAP, +NOSECTOR and +DONTSPLASH (because it's used on Heretic). Is that enough?
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby RaveYard » Wed Dec 27, 2017 10:32 am

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 )
RaveYard
 
Joined: 12 Apr 2013

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Thu Dec 28, 2017 5:39 am

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
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Check if sound is currently playing in a channel

Postby Graf Zahl » Mon Dec 16, 2019 4:36 pm

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Check if sound is currently playing in a channel

Postby Marisa Kirisame » Tue Dec 17, 2019 1:30 am

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
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Next

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest