]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/soundmgr_openal.cxx
Add missing include files needed by the new math code under windows
[simgear.git] / simgear / sound / soundmgr_openal.cxx
index e16f76981857f70a986c431e48ae629af4f241ac..82971d300a4d94aa87c80c4316ff6fa334c64070 100644 (file)
 //
 // $Id$
 
+#ifdef HAVE_CONFIG_H
+#  include <simgear_config.h>
+#endif
+
 #include <simgear/compiler.h>
 
 #if defined(__APPLE__)
 #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,17 +84,26 @@ SGSoundMgr::SGSoundMgr() {
     SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" );
 
     // initialize OpenAL
-    if ( (dev = alcOpenDevice( NULL )) != NULL) {
-        context = alcCreateContext( dev, NULL );
+#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
+    if (!alutInit(NULL, NULL))
+    {
+        ALenum error = alutGetError ();
+        SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" );
+        SG_LOG( SG_GENERAL, SG_ALERT, "   "+string(alutGetErrorString(error)));
+        working = false;
     }
-
-    if ( (dev != NULL) && (context != NULL) ) {
+    context = alcGetCurrentContext();
+#else
+    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!" );
     }
+#endif
 
     listener_pos[0] = 0.0;
     listener_pos[1] = 0.0;
@@ -115,16 +139,12 @@ SGSoundMgr::SGSoundMgr() {
 
 SGSoundMgr::~SGSoundMgr() {
 
-    alcDestroyContext( context );
-    //
-    // Remove the samples from the sample manager.
-    //
-    sample_map_iterator sample_current = samples.begin();
-    sample_map_iterator sample_end = samples.end();
-    for ( ; sample_current != sample_end; ++sample_current ) {
-       SGSoundSample *sample = sample_current->second;
-       delete sample;
-    }
+#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1
+    alutExit ();
+#else
+    if (context)
+        alcDestroyContext( context );
+#endif
 }
 
 
@@ -133,12 +153,6 @@ void SGSoundMgr::init() {
     //
     // Remove the samples from the sample manager.
     //
-    sample_map_iterator sample_current = samples.begin();
-    sample_map_iterator sample_end = samples.end();
-    for ( ; sample_current != sample_end; ++sample_current ) {
-        SGSoundSample *sample = sample_current->second;
-        delete sample;
-    }
     samples.clear();
 }
 
@@ -163,10 +177,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 +190,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()!" );
+        }
     }
 }
 
@@ -204,8 +222,6 @@ bool SGSoundMgr::remove( const string &refname ) {
     if ( sample_it != samples.end() ) {
        // first stop the sound from playing (so we don't bomb the
        // audio scheduler)
-       SGSoundSample *sample = sample_it->second;
-        delete sample;
         samples.erase( sample_it );
 
         // cout << "sndmgr: removed -> " << refname << endl;