]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_openal.hxx
Don't assign the buffer data to the sample in case it is a file. Test for result...
[simgear.git] / simgear / sound / sample_openal.hxx
index d419d767c90971c38468d9bae7127a949e4fbd9f..d2cb1824763a7a76b3769397bc80a0956c9464e0 100644 (file)
@@ -172,7 +172,7 @@ public:
      * Free the data associated with this audio sample
      */
     void free_data() {
-        if ( _data ) free( _data ); _data = NULL;
+        if ( _data != NULL ) free( _data ); _data = NULL;
     }
 
     /**
@@ -230,7 +230,10 @@ public:
      * Should be between 0.0 and 2.0 for maximum compatibility.
      * @param p Pitch
      */
-    inline void set_pitch( float p ) { _pitch = p; _changed = true; }
+    inline void set_pitch( float p ) {
+        if (p > 2.0) p = 2.0; else if (p < 0.01) p = 0.01;
+        _pitch = p; _changed = true;
+    }
 
     /**
      * Get the current pitch value of this audio sample.
@@ -245,6 +248,7 @@ public:
      * @param v Volume
      */
     inline void set_master_volume( float v ) {
+        if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0;
         _master_volume = v; _changed = true;
     }
 
@@ -254,7 +258,10 @@ public:
      * volume.
      * @param v Volume
      */
-    inline void set_volume( float v ) { _volume = v; _changed = true; }
+    inline void set_volume( float v ) {
+        if (v > 1.0) v = 1.0; else if (v < 0.0) v = 0.0;
+        _volume = v; _changed = true;
+    }
 
     /**
      * Get the final volume value of this audio sample.
@@ -278,7 +285,7 @@ public:
      * Set the frequency (in Herz) of this audio sample.
      * @param freq Frequency
      */
-    inline void set_frequency( int freq ) { _freq = freq; _changed = true; }
+    inline void set_frequency( int freq ) { _freq = freq; }
 
     /**
      * Returns the frequency (in Herz) of this audio sample.
@@ -308,11 +315,11 @@ public:
     }
 
     /**
-     * Set the base position of this sound in Geodetic coordinates.
-     * @param pos Geodetic position
+     * Set the base position in Cartesian coordinates
+     * @param pos position in Cartesian coordinates
      */
-    inline void set_position_geod( const SGGeod& pos ) {
-        _base_pos = pos; _changed = true;
+    inline void set_position( const SGVec3d& pos ) {
+       _base_pos = pos; _changed = true;
     }
 
     /**
@@ -330,26 +337,28 @@ public:
         _orientation = ori; _changed = true;
     }
 
+    inline void set_rotation( const SGQuatd& ec2body ) {
+        _rotation = ec2body; _changed = true;
+    }
+
     /**
      * Set direction of this sound relative to the orientation.
      * This is in the same coordinate system as OpenGL; y=up, z=back, x=right
      * @param dir Sound emission direction
      */
     inline void set_direction( const SGVec3f& dir ) {
-        _direction = dir; _changed = true;
+        _direction = toVec3d(dir); _static_changed = true;
     }
 
     /**
      * Define the audio cone parameters for directional audio.
-     * Note: setting it to 1 degree will result in 0.5 degrees to both sides.
+     * Note: setting it to 2 degree will result in 1 degree to both sides.
      * @param inner Inner cone angle (0 - 360 degrees)
      * @param outer Outer cone angle (0 - 360 degrees)
      * @param gain Remaining gain at the edge of the outer cone (0.0 - 1.0)
      */
     void set_audio_cone( float inner, float outer, float gain ) {
-        _inner_angle = inner;
-        _outer_angle = outer;
-        _outer_gain = gain;
+        _inner_angle = inner; _outer_angle = outer; _outer_gain = gain;
         _static_changed = true;
     }
 
@@ -359,7 +368,6 @@ public:
      * @return Orientaton vector
      */
     SGVec3f& get_orientation() { return _orivec; }
-    SGVec3f& get_direction() { return _direction; }
 
     /**
      * Get the inner angle of the audio cone.
@@ -442,13 +450,15 @@ private:
     // Position of the source sound.
     SGVec3d _absolute_pos;      // absolute position
     SGVec3d _relative_pos;      // position relative to the base position
-    SGVec3f _direction;         // orientation offset
+    SGVec3d _direction;         // orientation offset
     SGVec3f _velocity;          // Velocity of the source sound.
 
     // The position and orientation of this sound
     SGQuatd _orientation;       // base orientation
     SGVec3f _orivec;           // orientation vector for OpenAL
-    SGGeod _base_pos;          // base position
+    SGVec3d _base_pos;         // base position
+
+    SGQuatd _rotation;
 
     std::string _refname;      // name or file path
     unsigned char* _data;