]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/openal_test1.cxx
Compile time fixes needed to build SimGear on recent cygwin versions.
[simgear.git] / simgear / sound / openal_test1.cxx
index 90aac164a526bd3d0287e2079d76c53156f9dcbf..25d551adfef54b04ae9bfc0dad1bae844756c49c 100644 (file)
@@ -1,12 +1,22 @@
 #include <stdio.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
 
@@ -31,10 +41,16 @@ static void print_openal_error( ALuint error ) {
 
 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.
@@ -99,7 +115,19 @@ int main( int argc, char *argv[] ) {
     }
 
     // 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.");
     }
@@ -111,6 +139,7 @@ int main( int argc, char *argv[] ) {
     }
 
     alutUnloadWAV( format, data, size, freq );
+#endif
 
     alGenSources(1, &source);
     if (alGetError() != AL_NO_ERROR) {