FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help: openAL on linux

 
Post new topic   Reply to topic     Forum Index -> Bindings
View previous topic :: View next topic  
Author Message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Sun Jan 07, 2007 3:13 am    Post subject: help: openAL on linux Reply with quote

Anybody got openAL working on linux?

I'm trying a simple example but after calling
alutLoadWAVFile(cast(byte*)("data/Explosion.wav".ptr), format, &data, size, freq, loopAL);
my value are sill all zero:
writefln("value for format = ?s", format);
writefln("value for data = ?s", data);
writefln("value for size = ?s", size);
writefln("value for freq = ?s", freq);
writefln("value for loopAL = ?s", loopAL);

value for format = 0
value for data = 0000
value for size = 0
value for freq = 0
value for loopAL = 0

and it segfaults soon after...

Ant
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Jan 07, 2007 9:59 am    Post subject: Reply with quote

The DerelictAL binding should be working.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Sun Jan 07, 2007 12:25 pm    Post subject: Re: help: openAL on linux - Working Reply with quote

Ant wrote:
Anybody got openAL working on linux?
...
and it segfaults soon after...

Ant

Ok , I got it working Very Happy , but:

Code:
from alut.h
/* Nasty Compatibility stuff, WARNING: THESE FUNCTIONS ARE STRONGLY DEPRECATED */
#if defined(__APPLE__)
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVFile (ALbyte *fileName, ALenum *format, void **data, ALsizei *size, ALsizei *frequency);
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVMemory (ALbyte *buffer, ALenum *format, void **data, ALsizei *size, ALsizei *frequency);
#else
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVFile (ALbyte *fileName, ALenum *format, void **data, ALsizei *size, ALsizei *frequency, ALboolean *loop);
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutLoadWAVMemory (ALbyte *buffer, ALenum *format, void **data, ALsizei *size, ALsizei *frequency, ALboolean *loop);
#endif
ALUT_API ALUT_ATTRIBUTE_DEPRECATED void ALUT_APIENTRY alutUnloadWAV (ALenum format, ALvoid *data, ALsizei size, ALsizei frequency);


So I created a complete new bindings for alut and used
Code:
ALuint buffer = alutCreateBufferFromFile("data/Explosion.wav");

instead of alutLoadWAVFile

also the loader used was the std.loader which has a funny license,
so I changed it to my Duit loader.

aldacron, Derelict doesn't have alut...

here is the test I created (public domain, you can include it with the distribution as a test - just fix the while(1) loop first Smile )
NOTE THE WHILE(1) LOOP!
Code:

module src.test.testAL;

private import c.al.al;
private import c.al.alut;

private import std.stdio;

ALuint source[1];

ALfloat[3] sourcePos = [0.0, 0.0, 0.0];
ALfloat[3] sourceVel = [0.0, 0.0, 0.0];
ALfloat[3] sourceOri = [0.0, 0.0, 0.0];

ALfloat[3] listenerPos = [0.0, 0.0, 1.0];
ALfloat[3] listenerVel = [0.0, 0.0, 0.0];
ALfloat[3] listenerOri = [0.0, 0.0, 0.0];
ALuint[] buffers;

bool openALOK;

private bool checkError(char[] msg)
{
   ALuint error = alGetError();
   writefln("AL error = ?s (?s)", error, msg);
   if ( error != AL_NO_ERROR )
   {
      writefln("alut error = ?s ", std.string.toString(alutGetErrorString(error)));
      return false;
   }
   return true;
}

private bool createBuffer(char[] fileName)
{
   ALuint buffer = alutCreateBufferFromFile("data/Explosion.wav");
   if ( !checkError("create buffer from file") )
   {
      alDeleteBuffers(1, buffers.ptr);
      return false;
   }      
   if ( buffer == AL_NONE )
   {
      writefln("buffer not created");
      return false;
   }
   writefln("\tbuffer handle = ?s", buffer);
   buffers ~= buffer;

   return true;
}

private bool generateSource()
{
   alGenSources(1, source.ptr);
   if ( !checkError("alGenSources") ) return false;
   return true;
}

private bool attachBufferToSource()
{
   alSourcei(source[0], AL_BUFFER, buffers[0]);
   if ( !checkError("alSourcei") ) return false;
   return true;
}

private bool setSource()
{
   alSourcefv (source[0], AL_POSITION, sourcePos.ptr);
   if ( !checkError("alSourcefv") ) return false;
   alSourcefv (source[0], AL_VELOCITY, sourceVel.ptr);
   if ( !checkError("alSourcefv") ) return false;
   alSourcefv (source[0], AL_DIRECTION, sourceOri.ptr);
   if ( !checkError("alSourcefv") ) return false;
   
   return true;
}

private bool setListener()
{
   alListenerfv(AL_POSITION,listenerPos.ptr);
   if ( !checkError("alListenerfv") ) return false;
   alListenerfv(AL_VELOCITY,listenerVel.ptr);
   if ( !checkError("alListenerfv") ) return false;
   alListenerfv(AL_ORIENTATION,listenerOri.ptr);
   if ( !checkError("alListenerfv") ) return false;

   return true;
}

private bool initAL()
{
   
   
   alutInit(null, null);
   //alutInitWithoutContext(null, null);
   if ( !checkError("alutInit") ) return false;
   
   if ( !createBuffer("data/Explosion.wav") ) return false;
   
   if ( !generateSource() ) return false;
   
   if ( !attachBufferToSource() ) return false;
   
   if ( !setSource() ) return false;
   
   if ( !setListener() ) return false;
   
   return true;
}

private import std.thread;
   
int main(char[][] args)
{
   openALOK = initAL();
   
   if ( openALOK )
   {
      writefln("going to play source[0]");
      alSourcePlay(source[0]);
      // if we exit immidiatly the sound is not played...
      while(1)
      {
         // todo !!!! HOW to sleep for 3 seconds? !!!!
      }
      writefln("did you hear it?");
   }
   else
   {
      writefln("Failed to init openAL");
      return 1;
   }

   return 0;
}

Ant
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Bindings All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group