Playing sounds

BlitzMax Forums/BlitzMax Programming/Playing sounds

Raz(Posted 2006) [#1]
I remember a while ago seeing a few posts regarding sound problems and ive only just started considering how I will play them, does the following look ok? Am I missing any obvious problems with this method (I understood the main problems were people running out of channels, this dedicates each sound to its own channel)

'sound trial

Graphics 640,480,0

Global SoundArray:TSound[13]

Const sc_bee_col:Int = 0
Const sc_bee_hit:Int = 1
Const sc_coin_col:Int = 2
Const sc_coin_count:Int = 3
Const sc_fred_b_norm:Int = 4
Const sc_fred_b_low:Int = 5
Const sc_fred_b_high:Int = 6
Const sc_fred_dash:Int = 7
Const sc_menu_click_s:Int = 8
Const sc_menu_click_l:Int = 9
Const sc_spring_col_1:Int = 10
Const sc_spring_col_2:Int = 11
Const sc_statue_col:Int = 12

Soundarray[ sc_bee_col ] = LoadSound("Sound\bee_collide.wav")
Soundarray[ sc_bee_hit ] = LoadSound("Sound\bee_hit.wav")
Soundarray[ sc_coin_col ] = LoadSound("Sound\coin_collect.wav")
Soundarray[ sc_coin_count ] = LoadSound("Sound\coin_count.wav")
Soundarray[ sc_fred_b_norm ] = LoadSound("Sound\fred_bounce_normal.wav")
Soundarray[ sc_fred_b_low ] = LoadSound("Sound\fred_bounce_low.wav")
Soundarray[ sc_fred_b_high ] = LoadSound("Sound\fred_bounce_high.wav")
Soundarray[ sc_fred_dash ] = LoadSound("Sound\fred_dash.wav")
Soundarray[ sc_menu_click_s ] = LoadSound("Sound\menu_click_short.wav")
Soundarray[ sc_menu_click_l ] = LoadSound("Sound\menu_click_long.wav")
Soundarray[ sc_spring_col_1 ] = LoadSound("Sound\spring_collide_1.wav")
Soundarray[ sc_spring_col_2 ] = LoadSound("Sound\spring_collide_2.wav")
Soundarray[ sc_statue_col ] = LoadSound("Sound\statue_collect.wav")


Function Play_sound(Sound:Int)

	PlaySound(soundarray[sound],sound)
	
End Function

For Local xx:Int = 0 To 12
	
	WaitKey()
	play_sound(xx)
	
Next

End


ta!


Raz(Posted 2006) [#2]
actually i have come across a problem. It works fine until you set 'strict' where it says it cannot convert an int to a tchannel (which is fair enough i spose)

how do I overcome this?

ta


Raz(Posted 2006) [#3]
Nevermind Defiance saved the day :D

The solution, to have an array of TChannel's as well


Dreamora(Posted 2006) [#4]
Function Play_sound:TChannel(Sound:Int)

return PlaySound(soundarray[sound])

End Function



You will need the return as you will surely want to know if a sound is running and stop the channel as well to prevent "channel flooding"


Raz(Posted 2006) [#5]
as I am specifying the channel each time, does that not prevent said flooding?