Sound unusable

Monkey Targets Forums/HTML5/Sound unusable

ziggy(Posted 2013) [#1]
I get the sound cutting and disapearing randonly on all my games on HTML5. Also, on IE10, it sometimes reflects a AUDIO ERROR1! into the console, which I've been taking a look at, and it is caused by a InvalidStateError exception into gxtkSample.prototype.AllocAudio=function() of the native mojo js.
that said, not sure where or why this AllocAudio is called, but if it is creaating the sound, it makes no sense to me, as the sound was created a lot earlier without issues. not sure what can be happening here.

While I'm debugging as much as I can, It seems channel zero is not playing any sound on HTML5 on Chrome. Also, on IE10, it seems it randmly creates the aforementioned exception and sound disappears.

This is my "mixer" class:

Global AudioMixer:Mixer
Class Mixer

	Method New()
		If running Then Error("Only one mixer allowed!")
		running = True
	End

	'summary: el volumen general de la app
 	Method MainVolume:Void(value:Float) Property
		If value > 1 Then value = 1
		If value < 0 Then value = 0
		mainVolume = value
		RefreshVolume()
	End
	
	Method MainVolume:Float() Property
		Return mainVolume
	End
	
	Method MusicVolume:Void(value:Float) Property
		If value > 1 Then value = 1
		If value < 0 Then value = 0
		musicVolume = value
		RefreshVolume()
	End
	
	Method MusicVolume:Float() Property
		Return musicVolume
	End
	
	'summary: Disparar un sonido
	
	'summary: Poner música en el canal de fondo
	Method PlayMusic(path:String, flags = Mixer.MUSIC_LOOP)
		audio.PlayMusic(path, flags)
	End
	
	Method StopMusic()
		audio.StopMusic()
	End
	
	'summary: Gets or sets the global FxVolume
	Method FxVolume:Void(value:Float) Property
		If value > 1 Then value = 1
		If value < 0 Then value = 0
		fxVolume = value
		RefreshVolume()
	End
	
	Method FxVolume:Float() Property
		Return fxVolume
	End
	
	Method MusicFader:Void(value:Float) Property
		musicFader = value
	End
	
	Method MusicFader:Float() Property
		Return musicFader
	End
	
	'summary: Disparar un sonido
	Method ShotSound(sound:Sound, volume:Float = 1, pitch:Float = 1)
		If sound = Null Then Return
		If ChannelState(currentChannel) <> 0 Then
			StopChannel(currentChannel)
		EndIf
		
		Print "channel: " + currentChannel
		PlaySound(sound, currentChannel)
		SetChannelVolume(currentChannel, mainVolume * fxVolume * volume)
		SetChannelRate(currentChannel, pitch)
		soundVolume[currentChannel] = volume
		currentChannel += 1
		If currentChannel >= MAXCHANNELS Then currentChannel = 0
	End
	
	Method StopAllSounds()
		For Local i:Int = 0 Until MAXCHANNELS
			StopChannel(i)
		Next
	End
	
	
	Const MUSIC_LOOP:Int = 1
	Const MUSIC_ONCE:Int = 0
	
	Private
	
	Method RefreshVolume()
		audio.SetMusicVolume(musicVolume * mainVolume * musicFader)
		For Local i:Int = 0 Until MAXCHANNELS
			audio.SetChannelVolume(i, mainVolume * soundVolume[i] * fxVolume)
		Next
	End
	Field mainVolume:Float = 1
	Field musicVolume:Float = 1
	Field musicFader:Float = 1
	Field currentChannel:Int = 1
	Field fxVolume:Float = 1
	Const MAXCHANNELS:Int = 10
	Field soundVolume:Float[] = New Float[MAXCHANNELS]
	Field running:Bool = False
End




MikeHart(Posted 2013) [#2]
For v70c i read that some tweaks from you got implemented into MServer. Later when i had similar problems, Mark mentioned they were caused by some tweaks to MServer. Maybe that is the reason.


ziggy(Posted 2013) [#3]
I don't think so. It fails the same from any server.


skid(Posted 2013) [#4]
I think the problem with html5 audio (untested) may be the inability to play the same sound on multiple channels.

http://www.midnightfragfest.com/2010/12/05/html5-multi-channel-sound/


Midimaster(Posted 2013) [#5]
Just a test: try to reduce the MAXCHANNELS to 8. I think there was a limit at 8...


Paul - Taiphoz(Posted 2013) [#6]
Yeah wot skid said I have that issue as well, shooting tons of bullets, and explosions all happening really fast the sound just cant handle it, I had to really screw over my audio file length so that the sounds play fast enough to get out of the way.

hope there is a solution for this at some point.


ziggy(Posted 2013) [#7]
Ok, thanks for the information. Also, is anybody else failing to get playback from cannel 0? I'm reducing the cannel number to 8 to see if it makes any difference