OpenAL channel bug. Please help me test.

BlitzMax Forums/BlitzMax Programming/OpenAL channel bug. Please help me test.

I believe I've got to the route of a problem I encountered a while back with Open AL.

Basically there is a 256 channel limit which is reached EVEN IF you use Stop Channel to free up a channel for reuse.

Get this sample:

http://www.greyaliengames.com/misc/test.wav

and put it in the same folder as the test app:

and if you don't have OpenAL installed, put these in the same folder as the app:

http://www.greyaliengames.com/misc/OpenAL.zip (234k)

Strict

EnableOpenALAudio()
SetAudioDriver("OpenAL Generic Software") 'comment this out for no crash

Const MAX_CHANNELS=16
Global channels:TChannel[MAX_CHANNELS]
Global CurrentChannel=0

Local sound:TSound = LoadSound("test.wav")

Local Counter=0
Local total=0
Const TEST_VALUE = 16 'anything up to and including 15 will result in a sound, anything over will not.

Graphics 400,300,0

While Not KeyHit(KEY_ESCAPE)
	Cls
	Counter:+1
	If Counter=5 Then
		If Total<TEST_VALUE Then
			CreateChannels()		
			KillChannels()
			Counter=0
		ElseIf total=TEST_VALUE
			CreateChannels()		
			Play(Sound)			
		EndIf
		Total:+1
	EndIf
	DrawText Total,10,10
	DrawText CurrentChannel,10,30
	Flip
Wend

Function Play(sample:TSound)
	Local ch:TChannel=channels[CurrentChannel]
	CueSound(sample, ch)
	ResumeChannel(ch)		
	CurrentChannel:+1
	If CurrentChannel=MAX_CHANNELS Then CurrentChannel=0
End Function

Function CreateChannels()
	For Local i=0 To MAX_CHANNELS-1
		channels[i]=AllocChannel()
	Next
End Function

Function KillChannels()
	For Local i=0 To MAX_CHANNELS-1
		StopChannel(Channels[i])
		Channels[i]=Null
	Next
End Function


When you run it, you will NOT hear any sound when the counter hits 17.

The bug exists with all OpenAL drivers:

'OpenAL Default
'OpenAL Generic Software
'OpenAL Generic Hardware
'OpenAL

It does NOT exist with FreeAudio or DirectSound.

What does the code do? It makes a channel array (of 16 channels) and destroys it 16 times then tries to play a sound on the 17th channel array. The astute of you will realise that 16x16=256 and thus it is failing to play on the 257th channel. HOWEVER, I'm using STOPCHANNEL to free the channels and setting the pointer to null for what it's worth and thus the channel should be completely freed up for reuse, but it is not.

Please see if you get the same results on your PC (different OSes welcome). If so, I'll post this in the bug forum.

Thanks in advance!

[edit] of course I'm quite prepared for someone to tell me I'm using this code in an "incorrect" manner, but I don't think I am especially as the behavious is inconsistent between the drivers - for example you can go over 4096 channel creations/freeings with DirectSound and FreeAudio using the above code.