Sound + channel management

BlitzMax Forums/BlitzMax Programming/Sound + channel management

Cocopino(Posted 2017) [#1]
Hi,

I'd like to have several dozens up to maybe a few hundred of enemies on screen at any given time. What would be the standard/best way to manage their sounds (attacking, getting hit, dying etc)?

Would you give each enemy its own channel, or even make one enemy able to make more than 1 sound simultaneously, or have a channel per each enemy type, or per each type of sound... I have no experience with this.
What would be common to do here so there's a balance between the "illusion of many enemies" and "just a lot of noise"?

Thanks!


Derron(Posted 2017) [#2]
Maybe have a look at this thread.


On a request posted some time before that thread I created this:
https://github.com/GWRon/Dig/blob/master/base.sfx.channelpool.bmx
sample:
https://github.com/GWRon/Dig/blob/master/samples/channelpool/channelpool.bmx

The idea is to have a pool of channel objects which you can fetch by "keys".
For things like "music" or "speech over"-effects you use "protected channels". All other channels could get reused if a limit is reached.

So you could use these protected channels for all the important stuff:
- background music
- alert sounds ("you are under attack")
- voices of a selected unit on getting a new command ("on your command, sir!", "as you wish")
- gui clicks

and use x-y channels for all the fight-noises (swords crashing, trees falling after lumber jack did the last hit).




The approach to have 1 channel per enemy wont work if it can get attacked, play attack sounds - and then they have to play a voice when getting user-selected.

But maybe use a mix of it - special channels for "active unit reaction sounds" + an unit-individual channel for effects (attack sounds, die sound ...).


With FreeAudio the mixing of the channel is done in software, so there is no limit except "CPU+RAM" (I think so - but one better has a look at the module's source). Dunno how it is done with OpenAL and other engines.
So a "pool" might help.

bye
Ron


Cocopino(Posted 2017) [#3]
Thanks for the example!

While it doesn't do what I was looking for exactly, it did give me a new idea about my plan of attack: for the not-so-important sounds I'll create a list/array of channels, and iterate through them to find a free one. If no free channel exists, the sound just won't get played.

This way I can easily limit or enlarge the number of sounds playing simultaneously.


Derron(Posted 2017) [#4]
Using a channel pool you could give channels a "priority". So the lower the priority, the more likely it gets chosen for a "reuse" (stopping the old sound, playing a new one).

It also depends on the "volume" of a sound. So a up-to-not-noticeable sound of some birds chirping in the wood (with 10 different birds chirping on 10 different channels) could get stopped without "disturbing" the user.

Not playing a sound seems to be better (as no sound gets stopped out of the sudden) but you then need - what you already indirectly proposed - an "important sound" list.

Also do not forget about looping sounds (fight sounds, background noise) - they will be "active" the whole time (so you might end up not having a "free channel").


bye
Ron


Cocopino(Posted 2017) [#5]
Yes, I already had some reserved separate channels like BGM, which waits until the song is done to then start another (or restart the same, as a loop). And a "GUI channel" that just waits for input and indeed will cut off a previous sound, but no other (non-gui) sounds will ever be played through that channel.

But some audio just sounds weird when suddenly stopped. I'll see if I run into a "free channel problem" before trying to tackle it.