Creating a sound system - How to

Blitz3D Forums/Blitz3D Programming/Creating a sound system - How to

cyberyoyo(Posted 2008) [#1]
Hi guys
I am now ready to implement management of sound in my little game framework. But I realize I am not sure how the blitz system work, and I havenot worked with sounds on computers since a looong time ago.

Here is what I plan doing for managing sounds, please tell me if it is the correct way to do it:
What I think I'm going to do is create an array of sound channels (something like20) with each channel being specialized in one type of sound.
For example, 2 channels for music playback, 2 for interface sounds, 2 for player sounds, 5 for enemy generated sounds,etc..
Is this the correct way to do it?
I realize that I don't really understand how sound channels work.
Can you just fire a sound (creating a channel) and then just forget that channel, and use new ones for every played sounds? Or is it better to reuse sound channels for following sound?
Is there a limit in the number of channels you can create simultaneously (or not)?
I would appreciate any help in that matter.


Jasu(Posted 2008) [#2]
You cannot tell Blitz to use some channel. All it does is just give you the channel number so you can control it after it has started to play.

If you want to limit the amount of channels being used, you should proceed with the array thingy. If you run out of channels and need to replace some sound with another, you need to stop the old channel which is playing and the start the other. The new sound starts on another channel, which is a little stupid. But this solution has one advantage: pause game. If you wish that sounds pause for the time user has paused the game, it's easy to just go through the array and pause to sounds, and of course resume them when pause is over.

I've tried searching the forums for the upper limit of simultanous sounds, but haven't found anything solid. Some suggested that it was over a thousand sounds. I'm not sure since I hear sounds getting cut off with my current project. Might be a bug in my code, but also might not.


Rob Farley(Posted 2008) [#3]
From memory there was an FMod update in version 1.errrr and this allowed up to 1024 channels.

Regarding handling sounds yourself this kinda depends on what you're trying to handle.

I often attach an emitter to a mesh and have a type that holds the mesh, emitter, stats for object etc. This way if you entity distance is too far you can check the channel playing for that type sound and do what you feel necessary.

I handle the sounds for each object at an object level rather than at a global level. So I would never let an object play more than a couple of sounds at a time. Of course if you've got 100s of objects on screen this could be a problem. But if you know you're never going to have more than 5 or 10 on screen you shouldn't run into problems.

Also if you've got voice you'll probably only want to have one channel for that and create a type that is the queue. Then you have an check that sees if the voice channel is playing, if it's not then go to the next item in the queue etc etc etc.


cyberyoyo(Posted 2008) [#4]
Okay thanks for the pointers guys.
I think I'll use an array of channels because it makes things more controlled than just relying on the sound cards' unknown performances and it's better to limit the amount of similar sounds playing (for example gunshots) IMO.