Here is everything I have so far. It's not much but it's a start.
It's for OSX. I'm going to try to make it work on windows later when I have something up and running.
ModuleInfo "Version: 1.00"
ModuleInfo "License: HTTP://www.openal.org"
ModuleInfo "Modserver: PUB"
Import "-framework openal"
Extern
Function alutInit( argc:Int, argv:String[] )
Function alutExit()
Function alutLoadWAVFile( path:Byte Ptr, format:Int Var, data:Byte Ptr, size:Int Var, freq:Int Var, loop:Int Var )
Function alutUnloadWAV( format:Int, data:Byte Ptr, size:Int, freq:Int )
Function alGetError:Int()
Function alGenBuffers( num:Int, buffer:Int Var )
Function alDeleteBuffers( num:Int, buffer:Int Var )
Function alBufferData( buffer:Int, format:Int, data:Byte Ptr, size:Int, freq:Int )
Function alGenSources( num:Int, source:Int Var )
Function alDeleteSources( num:Int, source:Int Var )
Function alSourcei( source:Int, al_type:Int, value:Int )
Function alSourcef( source:Int, al_type:Int, value:Float )
Function alSourcefv( source:Int, al_type:Int, value:Float[] )
Function alSourcePlay( source:Int )
Function alSourceStop( source:Int )
Function alSourcePause( source:Int )
Function alListenerfv( al_type:Int, value:Float[] )
End Extern
Const AL_NONE:Int = 0
Const AL_FALSE:Int = 0
Const AL_TRUE:Int = 1
Const AL_PITCH:Int = $1003
Const AL_POSITION:Int = $1004
Const AL_VELOCITY:Int = $1006
Const AL_LOOPING:Int = $1007
Const AL_BUFFER:Int = $1009
Const AL_GAIN:Int = $100A
Const AL_ORIENTATION:Int = $100F
Const AL_NO_ERROR:Int = AL_FALSE
Const AL_INVALID_NAME:Int = $A001
Const AL_INVALID_ENUM:Int = $A002
Const AL_INVALID_VALUE:Int = $A003
Const AL_INVALID_OPERATION:Int = $A004
Const AL_OUT_OF_MEMORY:Int = $A005
test code:
Strict
AppTitle = "OpenAL test"
Graphics 640,480,0
alutinit(0,Null)
alGetError()
Global wav_data:Int
Global speaker:Int
Global speakerpos:Float[] = [ 0.0, 0.0, 0.0 ]
Global speakervel:Float[] = [ 0.0, 0.0, 0.0 ]
Global earpos:Float[] = [ 0.0, 0.0, 0.0 ]
Global earvel:Float[] = [ 0.0, 0.0, 0.0 ]
Global earorientation:Float[] = [ 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 ]
If Not LoadData() Then
EndGraphics()
Notify "Error while loading data!"
End
EndIf
SetSpeakerValues()
While Not KeyHit( KEY_ESCAPE )
If KeyHit( KEY_P ) Then alSourcePlay( speaker )
If KeyHit( KEY_S ) Then alSourceStop( speaker )
If KeyHit( KEY_H ) Then alSourcePause( speaker )
Cls
DrawText "OpenAL test - ESC to quit", 50,50
DrawText "P: Play", 100,100
DrawText "S: Stop", 100,120
DrawText "H: Pause", 100,140
Flip
Wend
KillData()
End
Function SetSpeakerValues()
alListenerfv(AL_POSITION, earPos)
alListenerfv(AL_VELOCITY, earVel)
alListenerfv(AL_ORIENTATION, earOrientation)
EndFunction
Function LoadData:Int()
Local format:Int
Local size:Int
Local data:Byte Ptr
Local freq:Int
Local loop:Int
alGenBuffers(1, wav_data )
If alGetError() <> AL_NO_ERROR Then Return False
alutLoadWAVFile("test.wav".tocstring(), format, data, size, freq, loop )
alBufferData( wav_data, format, data, size, freq )
alutUnloadWAV( format, data, size, freq )
' Bind buffer with a source.
alGenSources(1, speaker)
If alGetError() <> AL_NO_ERROR Then Return False
alSourcei (speaker, AL_BUFFER, wav_data )
alSourcef (speaker, AL_PITCH, 1.0 )
alSourcef (speaker, AL_GAIN, 1.0 )
alSourcefv(speaker, AL_POSITION, SpeakerPos)
alSourcefv(speaker, AL_VELOCITY, SpeakerVel)
alSourcei (speaker, AL_LOOPING, loop )
Return True
EndFunction
Function KillData()
alDeleteBuffers( 1, wav_data )
alDeleteBuffers( 1, speaker )
alutExit()
EndFunction
And finaly, the tutorial I'm following to learn OpenAL:
http://www.devmaster.net/articles/openal-tutorials/lesson1.phpEdit:
Never used the $z thing before. Is this correct?
Function alutLoadWAVFile( path$z, '... and the rest
It compiles anyway and, as you said , didn't solve the crashing issue. :)
Edit2:
Also, OpenAL works just fine if I write a small test in C using the source from that tutorial.