Some way to change A_StartSound default slot?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Some way to change A_StartSound default slot?

Post by Enjay »

[Edit: I have decided to go through the files and explicitly set the values myself. I'm putting together a resource pack that is supposed to be reasonably modular and doing what is requested below would not be consistent with that. Plus, it also means that I will have set things explicitly how I want them. However, I would still like to know how to do this for future reference, if anyone is able to help. :) ]

I was wondering if there could be a simple way to change the default channel slot for A_StartSound using ZScript.

According to the Wiki, A_StartSound defaults to using CHAN_BODY for "historical reasons". However, most of the time I find CHAN_AUTO more useful.

If an actor just has an entry like:
A_StartSound ("coolsound"); (which a lot of actors that I converted from DECORATE and then changed A_Playsound to A_StartSound do)
it will default to playing that sound on CHAN_BODY, as if the code had said:
A_StartSound ("coolsound", CHAN_BODY);
I'd prefer it to assume:
A_StartSound ("coolsound", CHAN_AUTO);
unless explicitly stated otherwise.

I'm sure ZScript could easily do this, but I don't know how.

Anyone? :)

Also, can anyone think of any problems that might arise from changing this default.
I guess the other option is to go through files searching for A_StartSound and setting the channels explicitly myself. Ultimately, that might be better?
[ Does a quick search in files for A_StartSound - "Found 975 occurrence(s) in 38 file(s)" :-? ]
User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Some way to change A_StartSound default slot?

Post by Enjay »

Enjay wrote: Sun Feb 23, 2025 1:44 pm Also, can anyone think of any problems that might arise from changing this default.
To answer my own question, yes, I can. :P

Because sounds played on CHAN_AUTO do not interrupt each other, it is possible to set up state sequence loops that are either very short, or have very long sounds and so you can get an additive effect of two or more copies of the sound playing over each other, which may not be desirable. Even worse, if you have set the sound channel to loop, but been careless enough to let the state sequence also loop back to the instruction to loop the sound, then it can get horribly loud and very messy with several copies of the sound playing over each other at slightly different times.



However, this does bring me to another question. The wiki tells me that CHAN_AUTO has the above special ability of not being interruptable by other sounds played on the channel. It also tells me that CHAN_BODY is the default (as already mentioned in my OP). However, there really isn't any information about the other channels. Do they do anything special? Are their names particularly important or meaningful? Do they imply some specific function? They seem like they should, but I can't say I've ever noticed anything special about them in game. Like, is it OK to use CHAN_VOICE on a weapon, or CHAN_WEAPON in a monster's death sequence? They all seem to work. Is there really a weapon channel that only weapons use? What is the voice channel? Is the item channel for pickup sounds, or inventory activation sounds, or not those things at all? Does it matter? What about the channels that simply have numbers?

So, if anyone can tell me what (if anything) sets these channels apart from the others, it would be greatly appreciated - it has puzzled me for years. Or are they all just available sound channels with no real difference?

CHAN_AUTO - special channel, always plays the sound with the CHANF_OVERLAP flag
CHAN_WEAPON - no information
CHAN_VOICE - no information
CHAN_ITEM - no information
CHAN_BODY - default for historical reasons, but no more information
CHAN_5 - no information
CHAN_6 - no information
CHAN_7 - no information
kadubi

Re: Some way to change A_StartSound default slot?

Post by kadubi »

Each actor has its own sound channels, as you may know. Their usage depends on the context, I suppose. Let's take a monster, for example. The sounds a monster makes, like sight, pain, death, etc, are played on CHAN_VOICE. CHAN_WEAPON is for attacks, like shooting a gun (or even melee attacks). Knowing their usage, you can either avoid accidentally overriding the sounds which are playing in those slots, or intentionally overriding them when you call a sound-playing function.
User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Some way to change A_StartSound default slot?

Post by Enjay »

OK, thank you.

So, there isn't really anything special about most of the channels, they are just named after the kind of sounds that are usually used on that channel, but don't have to be. i.e. they are names for logical convenience as much as anything? Like, we are playing all the voice sounds on chanel 2, so lets call it voice, all the weapons sounds on channel 1, so lets call it weapon etc. But if someone plays a wakeup sound on the weapon channel, or a shotgun blast on the voice channel, other than potential interruption it's all good. :?:
User avatar
phantombeta
Posts: 2149
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Some way to change A_StartSound default slot?

Post by phantombeta »

Yes, you can play anything on any channel, they're indeed just what you should use them for, to avoid sounds being cut off by other things. Vanilla Doom only had one channel, so player sounds playing would interrupt weapon sounds and vice versa, so ZDoom fixed this by adding more channels.

Though eventually modders found even this too limiting, so A_StartSound was added with the channels split from the flags, much like how A_SpawnProjectile and A_FireProjectile were added to fix the pitch miscalculation. (Took a really long time to happen, though...)
And we also got that CHANF_OVERLAP flag. Now we have practically limitless channels, and overlapping sounds, so no more worries about running out of sound channels now :P
I personally use different channels in my weapons for firing and reloading sounds so they don't cut each other off, very useful.
User avatar
Enjay
 
 
Posts: 26874
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland

Re: Some way to change A_StartSound default slot?

Post by Enjay »

Perfect. I have tried to find out what the channel names mean before. It's all nice and clear now. Thanks to you both. :thumb:

Return to “Scripting”