AllocChannel explanation needed

BlitzMax Forums/BlitzMax Beginners Area/AllocChannel explanation needed

QuickSilva(Posted 2009) [#1]
Could someone please explain the correct usage of this command?

Currently I am doing,

Sound:TSound=LoadSound("Sound.wav")
Channel01:TChannel=AllocChannel()
PlaySound(Sound,Channel01)

Is this the correct procedure?

How about if I stop this sound and want to play another sound through the same channel? I keep getting crashes so thats why I`m asking. Do I need to stop it\re-allocate it?

Thanks for any help,
Jason.


GfK(Posted 2009) [#2]
You don't even have to allocate a channel first. This will do the same thing:
Channel01:TChannel = PlaySound(sound)


I've always found this very confusing, as PlaySound (and CueSound) has a tChannel parameter, but it also returns a tChannel object. Never really understood why you'd need both.

Regarding the other thing, I generally do something like:
If channel.Playing()
	channel.Stop()
	channel = Null
EndIf
channel = PlaySound(newSound)
Whether this is all necessary, I don't know. I think I might have originally done it this way because channel.playing() didn't used to work right on paused channels. Or something.


plash(Posted 2009) [#3]
I've always found this very confusing, as PlaySound (and CueSound) has a tChannel parameter, but it also returns a tChannel object. Never really understood why you'd need both.
Probably because it will create a channel (return) if one is not given (parameter).


GfK(Posted 2009) [#4]
Probably because it will create a channel (return) if one is not given (parameter).
...so why not just use channel:TChannel = PlaySound(sound) throughout? Under what circumstances would you need to give it a channel parameter, and how would you benefit from doing so?


plash(Posted 2009) [#5]
...so why not just use channel:TChannel = PlaySound(sound) throughout? Under what circumstances would you need to give it a channel parameter, and how would you benefit from doing so?
Instead of PlaySound allocating a new channel every time you call it, you could simply have one (or multiple, for different effect types) channel and keep reusing it.


Grey Alien(Posted 2009) [#6]
Instead of PlaySound allocating a new channel every time you call it, you could simply have one (or multiple, for different effect types) channel and keep reusing it.
Which is what I do so I like it the way it works now.

@QuickSilva: Yeah if you ever call StopChannel it destroys the channel but does not null the pointer (so you could end up using it again by accident and it will crash). So after using StopChannel if you want to use the same channel variable again you need to do another AllocChannel. Take a look at my framework.


QuickSilva(Posted 2009) [#7]
Thanks for the explanations all. I`ll take a look at your FrameWork Grey Alien, should have looked there first in hindsight.

I just found the array of commands a tad confusing from reading the docs but it`s all clear now :)

Jason.