Can tell more about an old sound problem

Monkey Forums/Monkey Bug Reports/Can tell more about an old sound problem

Midimaster(Posted 2013) [#1]
I'm working on a piano module and the sounds worked perfect unitl today. Suddenly sound did not appear...

I examined what happenend and now I write you the results:

If you use less than 8 channels you can repeat the same sound as often as you want.

If you use more than 8 channels and change the sounds often, you will also get no problems.

But if you use more tha 8 channels and repeat the same sound often, only channel 0 to 7 will work and 9-xxx will not work

I'm using V71 on Win-XP in HTML5 Firefox 22

here is the code:

Strict
Import mojo


Class Game Extends App

	
	Field Zeit%, ChannelStep%, Piano:Sound[12], PianoStep%
	
	Method OnCreate%()
		SetUpdateRate 10
		
		'Load only one will cause bugs behind the 8th channel
			Piano[0]=LoadSound("piano20.ogg")
		
		' Or load a lot of sounds will work perfect:
			For Local i%=0 To 11
				'Piano[i]=LoadSound("piano" + (20+i) +".ogg")
			Next
		Return 0
	End	



	Method OnUpdate%()
		If KeyHit(KEY_ESCAPE) Error ""
		If Zeit<Millisecs()
			Zeit=Millisecs() + 200
			Print "Play Sound  on Channel " +  ChannelStep 
			SetChannelVolume ChannelStep,1
			
			'play always the same sound or chage:
				'PianoStep=(PianoStep +1) Mod 12
					
			PlaySound Piano[PianoStep], ChannelStep
			ChannelStep=(ChannelStep+1) Mod 20			
		Endif
		Return 0
	End	

	Method OnRender%()
		Cls 0,255,0
		Return 0
	End	
	
End

Function Main%()
	New Game
	Return 0
End



The sound is a small(11k) short(1.5sec) Piano-Sound as "Piano20.ogg" here:

http://www.blitzforum.de/upload/file.php?id=12510

I think it has something to do with a limitation of maximum of instances of the same sound source. With 20 different piano sounds it works without problems. Even, when the same sound is played more then 8 times in total

Perhaps its a problem of the garbage collector?



Can somebody confirm the problem?



A Possible Workaround

This is a workaround that causes no errors:

Use different channels if the sound is a seldom one. Use always the same channel, when the sound happens often.

In my project, the piano key will happend seldom. "Seldom" means the same sound will not happend more than 8 times within 4 seconds. So I asign each new event to one of the channels "0" to "19".

But the metromon sound ("clack") will return every 250msec -500msec . So i asign it to the fix channel "20" all the time.


Xaron(Posted 2013) [#2]
I confirm that with my own app. Just tested to play the same(!) sound. I increase the sound channel with every play from 0 to 31. The sound stops playing with channel 8 and plays again with channel 0.

This happens with HTML5 and Google Chrome.


marksibly(Posted 2013) [#3]
Try removing line 571 in mojo.html.js - just after //Max out?

It's there for a reason though - allowing to many instances of a sound to be simultaneous 'loaded' used to crash some browsers, or do something weird. Perhaps that's been fixed by now though.


Midimaster(Posted 2013) [#4]
Thank you Mark...

...for clarify that there is a reason for your limitation. If some browser had problems with more than 8 simultanously played sounds I will respect this and use my workaround. Removing the line 571 is no solution, because I never know, whether a user works with an old browser.

But does this mean that this limitation is not set on other targets? My final target will be Android and IOs for this game.

And a last thought: I recognized the problem when adding a "metronom sound" ("clack"). It only had a length of 500msec. On a max speed of bpm=200 the first clack has finished, before the third starts. So there should never be a situation, where more than two "clack" sound channels with same sound are activ. Does the GC not destroy finished sound channels?


Midimaster(Posted 2013) [#5]
Again me...

I need to know what will happend to channels if they already played its sound until the end? Will they be cleaned up some time? Or can I trust on, that it still avaiable also much later for a "ResumeChannel()"?