Ignition V1.3 and iPlaysound issues

Monkey Forums/Monkey Programming/Ignition V1.3 and iPlaysound issues

nrasool(Posted 2012) [#1]
Hi Everyone,

Hope you are well and everything is okay. I'm a bit confused by the following and just wondering what the answer is

If you take the following bit of code and add your own jump and music ogg files :-)

	Import playniax.ignition.framework.sound	' Import the sound module.
	Import "data/jump.ogg"
	Import "data/petersburger.ogg"
	
	Global testSound:Sound
	Global music:Sound
	Global IsJumpSound:Int = 0
	Global isMusicOn:Int = 0

	Function Main ()
		New MyApp
	End Function

	Class MyApp Extends App

		Method OnCreate ()

			testSound=LoadSound("jump.ogg")
			If testSound = Null Then Print "Sound not opened"
			
			music = LoadSound("petersburger.ogg")
			If music = Null Then Print "Music not opened"
			

			iSetSFXChannels (4)		' Set maximum of sfx channels (channels are rotated).

			SetUpdateRate (60)

		End Method

		Method OnRender ()

			Cls
			DrawText "current volume: " + iGetSFXVolume (), 0, 0	' Display the sfx main volume.
			DrawText "Press space to play sound.", 0, 32

		End Method

		Method OnUpdate ()

			If KeyHit (KEY_SPACE)
					iPlaySound testSound			' Play sfx sound.
			End If
			
			If isMusicOn = 0 Then
				iPlaySound music, 1, 1 ' Play music		
				Print "Playing theme music"				
				isMusicOn = isMusicOn + 1
			Endif

		End Method

	End Class




Now if you press space 5 times, it cuts off the "music" part. How can I have it, so it does not do this. If I just comment out iSetSFXChannels (4), it will cut off the music at 9 spaces.

Please could someone help me understand this

Many thanks

Kind Regards


Volker(Posted 2012) [#2]
Under which target? Just HTML5?


nrasool(Posted 2012) [#3]
Hey there this issues happens in both glfw and HTML5. That's the one I have tested with

Kind regards


Playniax(Posted 2012) [#4]
Judging on the code nothing is wrong with the sound system. It's a channel limitation. Monkey supports only 32 channels so when you are out of channels the choice must be made. Stop one and let the sound play again or not play sound at all. The Ignition system can not use more channels then monkey allows. Also, it rotates the channels, meaning that it will take the first available channel. If it is free to use it will play the sound using this channel. If there is no channel free it will stop the longest playing and play your new sound. I hope that clears it for you.


smilertoo(Posted 2012) [#5]
so what you need is a way to lock a channel as the music one, so its removed from the sound effect channels pool.


nrasool(Posted 2012) [#6]
Thanks Guy's, I will investigate on how to recycle channels for sound effects only. Just reading up on Channelstate and http://www.monkeycoder.co.nz/Community/posts.php?topic=2345#23253

Kind Regards