]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_openal.hxx
Oops, one addtional tweak.
[simgear.git] / simgear / sound / sample_openal.hxx
index fe79cb68f8312e3785adeca2be4089c4ef5e9e5f..edc61ec8c9efe8cbac44be61a808700c467dfa81 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include <AL/al.h>
+#include STL_STRING
+
+#if defined(__APPLE__)
+# define AL_ILLEGAL_ENUM AL_INVALID_ENUM
+# define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
+# include <OpenAL/al.h>
+# include <OpenAL/alut.h>
+#else
+# include <AL/al.h>
+# include <AL/alut.h>
+#endif
 
 #include <simgear/debug/logstream.hxx>
 
+SG_USING_STD(string);
+
 
 /**
  * manages everything we need to know for an individual sound sample
@@ -47,6 +59,8 @@ class SGSoundSample {
 
 private:
 
+    string sample_name;
+
     // Buffers hold sound data.
     ALuint buffer;
 
@@ -71,14 +85,22 @@ private:
 
 public:
 
-    SGSoundSample( const char *path, const char *file );
+    /**
+     * Constructor
+     * @param path Path name to sound
+     * @param file File name of sound
+     * @param cleanup Request clean up the intermediate data (this
+       should usually be true unless you want to manipulate the data
+       later.)
+     */
+    SGSoundSample( const char *path, const char *file, bool cleanup );
     SGSoundSample( unsigned char *_data, int len, int _freq );
     ~SGSoundSample();
 
     /**
      * Start playing this sample.
      *
-     * @param looped Define wether the sound should be played in a loop.
+     * @param _loop Define wether the sound should be played in a loop.
      */
     void play( bool _loop );
 
@@ -110,7 +132,7 @@ public:
         alGetSourcei( source, AL_SOURCE_STATE, &result );
         if ( alGetError() != AL_NO_ERROR) {
             SG_LOG( SG_GENERAL, SG_ALERT,
-                    "Oops AL error in sample is_playing()!" );
+                    "Oops AL error in sample is_playing(): " << sample_name );
         }
         return (result == AL_PLAYING) ;
     }
@@ -124,11 +146,15 @@ public:
      * Set the pitch of this sample.
      */
     inline void set_pitch( double p ) {
+        // clamp in the range of 0.01 to 2.0
+        if ( p < 0.01 ) { p = 0.01; }
+        if ( p > 2.0 ) { p = 2.0; }
         pitch = p;
         alSourcef( source, AL_PITCH, pitch );
         if ( alGetError() != AL_NO_ERROR) {
             SG_LOG( SG_GENERAL, SG_ALERT,
-                    "Oops AL error in sample set_pitch()! " << p );
+                    "Oops AL error in sample set_pitch()! " << p
+                    << " for " << sample_name );
         }
     }
 
@@ -145,7 +171,8 @@ public:
         alSourcef( source, AL_GAIN, volume );
         if ( alGetError() != AL_NO_ERROR) {
             SG_LOG( SG_GENERAL, SG_ALERT,
-                    "Oops AL error in sample set_volume()!" );
+                    "Oops AL error in sample set_volume()! " << v
+                    << " for " << sample_name  );
         }
     }