#include <stdio.h>
-#include <AL/al.h>
-#include <AL/alut.h>
+#ifdef __MINGW32__
+// This is broken, but allows the file to compile without a POSIX
+// environment.
+static unsigned int sleep(unsigned int secs) { return 0; }
+#else
+#include <unistd.h> // sleep()
+#endif
+
+#if defined( __APPLE__ )
+# define AL_ILLEGAL_ENUM AL_INVALID_ENUM
+# define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
+# include <OpenAL/al.h>
+# include <OpenAL/alc.h>
+# include <OpenAL/alut.h>
+#else
+# include <AL/al.h>
+# include <AL/alc.h>
+# include <AL/alut.h>
+#endif
#include <simgear/debug/logstream.hxx>
int main( int argc, char *argv[] ) {
// initialize OpenAL
- alutInit( 0, NULL );
- alGetError();
- if ( alGetError() != AL_NO_ERROR) {
- SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" );
+ ALCdevice *dev;
+ ALCcontext *context;
+
+ // initialize OpenAL
+ if ( (dev = alcOpenDevice( NULL )) != NULL
+ && ( context = alcCreateContext( dev, NULL )) != NULL ) {
+ alcMakeContextCurrent( context );
+ } else {
+ context = 0;
+ SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" );
}
// Position of the listener.
}
// Load the sample file
+#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
+
+ buffer = alutCreateBufferFromFile("jet.wav");
+ if (buffer == AL_NONE) {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data.");
+ }
+
+#else
+# if defined (__APPLE__)
+ alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq );
+# else
alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq, &loop );
+# endif
if (alGetError() != AL_NO_ERROR) {
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to load wav file.");
}
}
alutUnloadWAV( format, data, size, freq );
+#endif
alGenSources(1, &source);
if (alGetError() != AL_NO_ERROR) {