]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/soundmgr_openal.cxx
MacOS-X fixes.
[simgear.git] / simgear / sound / soundmgr_openal.cxx
index e16f76981857f70a986c431e48ae629af4f241ac..7d97d95cc8e7a9ac2a07912e99b45542439fcf32 100644 (file)
 #endif
 
 #if defined (__APPLE__)
-// any C++ header file undefines isinf and isnan
-// so this should be included before <iostream>
-inline int (isinf)(double r) { return isinf(r); }
-inline int (isnan)(double r) { return isnan(r); } 
+#  ifdef __GNUC__
+#    if ( __GNUC__ >= 3 ) && ( __GNUC_MINOR__ >= 3 )
+//  #        include <math.h>
+inline int (isnan)(double r) { return !(r <= 0 || r >= 0); }
+#    else
+    // any C++ header file undefines isinf and isnan
+    // so this should be included before <iostream>
+    // the functions are STILL in libm (libSystem on mac os x)
+extern "C" int isnan (double);
+extern "C" int isinf (double);
+#    endif
+#  else
+//    inline int (isinf)(double r) { return isinf(r); }
+//    inline int (isnan)(double r) { return isnan(r); }
+#  endif
 #endif
 
 #if defined (__FreeBSD__)
@@ -69,15 +80,13 @@ SGSoundMgr::SGSoundMgr() {
     SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" );
 
     // initialize OpenAL
-    if ( (dev = alcOpenDevice( NULL )) != NULL) {
-        context = alcCreateContext( dev, NULL );
-    }
-
-    if ( (dev != NULL) && (context != NULL) ) {
+    if ( (dev = alcOpenDevice( NULL )) != NULL
+            && ( context = alcCreateContext( dev, NULL )) != NULL ) {
         working = true;
-         alcMakeContextCurrent( context );
+        alcMakeContextCurrent( context );
     } else {
         working = false;
+        context = 0;
        SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" );
     }
 
@@ -115,7 +124,8 @@ SGSoundMgr::SGSoundMgr() {
 
 SGSoundMgr::~SGSoundMgr() {
 
-    alcDestroyContext( context );
+    if (context)
+        alcDestroyContext( context );
     //
     // Remove the samples from the sample manager.
     //
@@ -163,10 +173,12 @@ void SGSoundMgr::update( double dt ) {
 void
 SGSoundMgr::pause ()
 {
-    alcSuspendContext( context );
-    if ( alGetError() != AL_NO_ERROR) {
-       SG_LOG( SG_GENERAL, SG_ALERT,
-                "Oops AL error after soundmgr pause()!" );
+    if (context) {
+        alcSuspendContext( context );
+        if ( alGetError() != AL_NO_ERROR) {
+           SG_LOG( SG_GENERAL, SG_ALERT,
+                    "Oops AL error after soundmgr pause()!" );
+        }
     }
 }
 
@@ -174,10 +186,12 @@ SGSoundMgr::pause ()
 void
 SGSoundMgr::resume ()
 {
-    alcProcessContext( context );
-    if ( alGetError() != AL_NO_ERROR) {
-       SG_LOG( SG_GENERAL, SG_ALERT,
-                "Oops AL error after soundmgr resume()!" );
+    if (context) {
+        alcProcessContext( context );
+        if ( alGetError() != AL_NO_ERROR) {
+           SG_LOG( SG_GENERAL, SG_ALERT,
+                    "Oops AL error after soundmgr resume()!" );
+        }
     }
 }