Making a module: Void *?

BlitzMax Forums/BlitzMax Programming/Making a module: Void *?

Hi,

I'm making a module for OpenAL, and I'm having some problems.
My small test crashes while trying to load a wav file.
The point where my test is crashing is here at the alutLoadWAVfile:
	Local format:Int
	Local size:Int
	Local data:Byte Ptr ' <- Not sure if this is the bmax version of void *
	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 )

And this is how the original C source looked like:
    ALenum format;
    ALsizei size;
    ALvoid* data;
    ALsizei freq;
    ALboolean loop;

    alGenBuffers(1, &Buffer);
    if (alGetError() != AL_NO_ERROR)
        return AL_FALSE;

    alutLoadWAVFile("wavdata/FancyPants.wav", &format, &data, &size, &freq, &loop);


I think it's the void *data -> data:byte ptr part that I got wrong, but if somebody can spot any other errors I would be grateful.

Thankful for any help.

You should use $z in the function definition instead of .toCString() for the first argument of alutLoadWAVFile. That won't solve the problem, though. Could you post some more, like the function definitions (from an Extern block, presumably)?

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.php

Edit:
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.

*bump?*
No one able to help me?

As far as I know a byte ptr is used to represent any kind of pointer in C including/especially void* .

Your function definition is corrent for using $z, and when you call the function you can use a normal string literal and just drop the .toCString().

Your problem, or a problem, is you're trying to pass an array to C. Since Max's arrays are objects you'll have to pass arrays as pointers to the first element.

alSourcefv(speaker, AL_POSITION, varptr(SpeakerPos[0]))
alSourcefv(speaker, AL_VELOCITY, varptr(SpeakerVel[0]))


If C wants a float[] instead of a float* I don't know if that'd work.

Been busy with my new job, but here's the reply.

Changed the code but it still crashes at alutLoadWAVFile for some strange reason. :(