Sound Effect Implementation Question?

BlitzMax Forums/BlitzMax Programming/Sound Effect Implementation Question?

Sean Doherty(Posted 2005) [#1]
The following is a simple sound example for a basic shooter when you fire a weapon:

-----------------------------------
Method Fire()

Local pTMissileFiringSound:TSound


pTMissileFiringSound = LoadSound("Sounds/Firing/Shot.wav")
pTMissileFiringSound.Play()

End Method
-------------------------

Couple of questions:

1) When the pTMissileFiringSound pointer goes out of scope at the end of the method why does the sound continue to play?

2) Is there anything wrong with this implementation; should I be using a TList to queue the sounds to avoid memory allocation issues? For example, what if the instance of the Type/Class that created the sound was detroyed before the sound finished?

3) If I want units in the distance to sound further away sould I use SetPan and SetDepth?

4) Is there a limit to the number of sound channels and are they automatically cleaned up at the end of the sound?

Thanks


TartanTangerine (was Indiepath)(Posted 2005) [#2]
Hi Sean,

I hope this code helps, its a multi-channel sound system I developed for BMax that allows queing, overlapping, no-overlapping. It will support as many channels as you want and any queue depth. It will also clean up after itself.

This code is based on something done for Blitz3D some years ago by someone else - no idea who.




Sean Doherty(Posted 2005) [#3]
Hey Indiepath,

Thanks for the code!

Questions: Is there anything wrong with the way I was doing it above? What advantage does this offer; just curious because I am new to Blitz Sound.


TartanTangerine (was Indiepath)(Posted 2005) [#4]
Hi Sean,

Your code looks sound (no pun intended), if you want maximum control over the sound then you really do need to go the channel route. Using Channels allows you to change pitch on the fly, volume on the fly etc.. You'll also find that with my code you can just chuck stuff at the channels and it'll decide what to do with the sound - no more overloading the soundcard when 20 explosions all happen simultaneously.

Cheers, Tim.

PS. How come you've not got my games on your site :P


tonyg(Posted 2005) [#5]
I don't think you should be using loadsound each time you fire.
An attempt to answer some questions (some guessing going on here)...
1) The variables out of scope but 'play' has automatically created a TChannel which still exists.
2) Destroy method could check whether the channel is playing and stop using stopchannel.
3) Setpan, SetDepth *and* Setvolume. There's an example in the docs.
4) Don't think there's a limit as each channel is an TChannel Object. I guess, once these are out of scope, flushmem will remove them.
<edit> I reserve the right to be very wrong


Sean Doherty(Posted 2005) [#6]
Tim,

GameSlammers primary focus is action/arcade and shooters. Also, you are using esellerate where generally I target Plimus, RegNow, or Share-It games. Altough, there are games on the site without any affiliate program in play. That said, I may be changing the affilate program we use in the next few weeks.


Sean Doherty(Posted 2005) [#7]
tonyg,

I ran accross one null exception error when setting using the channel. At the time, I was thinking that there were not channels remaining. Also, I have had no luch with SetDepth? I set the depth to -1 and the sound still comes out the front speakers; reverse is true for +1.

Presently, I am using a singleton to load all my sounds then I just allocate the channel and set the volume of the sound based on the distance of the sound from the camera (center of the screen).

I have not really had a chance to look at Tim's code in detail as of yet.


Sean Doherty(Posted 2005) [#8]
Tim,

Looking at your code but I can't see how to use it? How do I setup/queue a new sound? Do you have a sample of how you are using it?

Sean