]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/openal_test1.cxx
do not yet add the relative sound position to the absolute position, it's generating...
[simgear.git] / simgear / sound / openal_test1.cxx
index 5d56bc9e83222ae9df692ad0faa3b61a876b108d..94e3e4510303d2b0a6cc1daac69244f9131f55ea 100644 (file)
@@ -12,12 +12,20 @@ static unsigned int sleep(unsigned int secs) { return 0; }
 # 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>
+#elif defined(OPENALSDK)
+# include <al.h>
+# include <alc.h>
+# include <AL/alut.h> 
 #else
 # include <AL/al.h>
+# include <AL/alc.h>
 # include <AL/alut.h>
 #endif
 
+#define AUDIOFILE      SRC_DIR"/jet.wav"
+
 #include <simgear/debug/logstream.hxx>
 
 static void print_openal_error( ALuint error ) {
@@ -39,10 +47,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.
@@ -87,11 +101,11 @@ int main( int argc, char *argv[] ) {
     ALfloat source_vel[3];
 
     // configuration values
-    ALenum format;
-    ALsizei size;
-    ALvoid* data;
-    ALsizei freq;
-    ALboolean loop;
+//    ALenum format;
+//    ALsizei size;
+//    ALvoid* data;
+//    ALsizei freq;
+    ALboolean loop = false;
 
     source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0;
     source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
@@ -107,11 +121,19 @@ int main( int argc, char *argv[] ) {
     }
 
     // Load the sample file
-#if defined (__APPLE__)
-    alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq );
+#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
+
+  buffer = alutCreateBufferFromFile(AUDIOFILE);
+  if (buffer == AL_NONE) {
+    SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data.");
+  }
+
 #else
-    alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq, &loop );
-#endif
+# if defined (__APPLE__)
+    alutLoadWAVFile( (ALbyte *)AUDIOFILE, &format, &data, &size, &freq );
+# else
+    alutLoadWAVFile( (ALbyte *)AUDIOFILE, &format, &data, &size, &freq, &loop );
+# endif
     if (alGetError() != AL_NO_ERROR) {
         SG_LOG( SG_GENERAL, SG_ALERT, "Failed to load wav file.");
     }
@@ -123,6 +145,7 @@ int main( int argc, char *argv[] ) {
     }
 
     alutUnloadWAV( format, data, size, freq );
+#endif
 
     alGenSources(1, &source);
     if (alGetError() != AL_NO_ERROR) {