StopChannel on Leopard

BlitzMax Forums/BlitzMax Programming/StopChannel on Leopard

Godra25(Posted 2014) [#1]
below is part of my code to play and stop sound by press particular keyboard button:

If KeyHit(KEY_Q)
	PlaySound bgm_shop, bgmchannel	
	Print"PLAY"
End If
	
If KeyHit(KEY_W)
	StopChannel bgmchannel		
	Print"STOP"
End If


the problem is:
1. program running, i press Q then music play
2. then, press W music stop
3. then, i press Q again, music play perfectly
4. but when i press W, music don't stop
5. and also, when i press Q again, there is overlapping music
anyone have same problem ??

i use Snow Leopard and Blitzmax 1.50
note: this program run perfectly on Windows

this result from AudioDrivers(), maybe can help

OpenAL
FreeAudio
FreeAudio CoreAudio
Null



Midimaster(Posted 2014) [#2]
I think, that is normal... If you stopp the channel first time the channel instance is deleted, ... no reference any more on this channel.

Manual:
"StopChannel() - Shuts down an audio channel. Further commands using this channel will have no effect. "

"PlaySound() - PlaySound starts a sound playing through an audio channel. If no channel is specified, PlaySound automatically allocates a channel for you. "

So If you do PlaySound() after StopChannel() this will return a new channel instance. Stopping the old instance will have no effect on the new channel Test this when starting a new sound:

bgmchannel=PlaySound(bgm_shop)


I often use CueSound() and ResumeChannel()


Godra25(Posted 2014) [#3]
as i said before, this program run correctly on Windows..

and that bgmchannel is i declare as global variable

'
'
'
Global bgmchannel:TChannel = AllocChannel()
'
'
'



but, anyway thank you for your responses


GfK(Posted 2014) [#4]
I'm pretty sure I got around this issue once - was years ago though so might be way off:
If KeyHit(KEY_Q)
        bgmchannel = AllocChannel()
	PlaySound bgm_shop, bgmchannel	
	Print"PLAY"
End If
	
If KeyHit(KEY_W)
	StopChannel bgmchannel		
        bgmchannel = Null
	Print"STOP"
End If


[edit] Which is sort of what Midimaster said (my method pre-allocates the channel, his doesn't - it's created on PlaySound/CueSound). I had a thread about it all somewhere and the only way I could get it to graft at all was by pre-allocating with AllocChannel().


Midimaster(Posted 2014) [#5]
He does not believe us... A channel once stopped is not longer allocated! It does not help to allocate it at the beginning of the code. you have to do this again and again, when filling it with a new sound.

The combination of AllocChannel() followed by PlaySound() is the same as only PlaySound() and use the returned value:

If KeyHit(KEY_Q)
        bgmchannel = AllocChannel()
	PlaySound bgm_shop, bgmchannel	
	Print"PLAY"
End If

If KeyHit(KEY_Q)
 	bgmchannel =PlaySound(bgm_shop)	
	Print"PLAY"
End If



Godra25(Posted 2014) [#6]
oh i'm sorry it doesn't mean to not believe in you..:D
what confusing me is why my code run in windows but not in mac.. may be it have different "mechanism".

NB: i'm not used to work with mac :(


but anyway, your code is work for me.. thanks both of you :D