浏览代码

Merge branch 'fix-audio-distance-factor' of github.com:nikolmiv/panda3d

Closes: #13
rdb 8 年之前
父节点
当前提交
4cd826e63a

+ 4 - 3
panda/src/audio/audioManager.h

@@ -154,9 +154,10 @@ PUBLISHED:
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
 
 
   // Control the "relative scale that sets the distance factor" units for 3D
   // Control the "relative scale that sets the distance factor" units for 3D
-  // spacialized audio.  Default is 1.0 Fmod uses meters internally, so give a
-  // float in Units-per meter Don't know what Miles uses.  Default is 1.0
-  // which is adjust in panda to be feet.
+  // spacialized audio. This is a float in units-per-meter. Default value is
+  // 1.0, which means that Panda units are understood as meters; for e.g.
+  // feet, set 3.28. This factor is applied only to Fmod and OpenAL at the
+  // moment.
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
 
 

+ 3 - 7
panda/src/audiotraits/fmodAudioManager.cxx

@@ -42,14 +42,8 @@ pset<FmodAudioManager *> FmodAudioManager::_all_managers;
 
 
 bool FmodAudioManager::_system_is_valid = false;
 bool FmodAudioManager::_system_is_valid = false;
 
 
-
-// This sets the distance factor for 3D audio to use feet.  FMOD uses meters
-// by default.  Since Panda use feet we need to compensate for that with a
-// factor of 3.28 This can be overwritten.  You just need to call
-// audio_3d_set_distance_factor(PN_stdfloat factor) and set your new factor.
-
 PN_stdfloat FmodAudioManager::_doppler_factor = 1;
 PN_stdfloat FmodAudioManager::_doppler_factor = 1;
-PN_stdfloat FmodAudioManager::_distance_factor = 3.28;
+PN_stdfloat FmodAudioManager::_distance_factor = 1;
 PN_stdfloat FmodAudioManager::_drop_off_factor = 1;
 PN_stdfloat FmodAudioManager::_drop_off_factor = 1;
 
 
 
 
@@ -100,6 +94,8 @@ FmodAudioManager() {
   _up.y = 0;
   _up.y = 0;
   _up.z = 0;
   _up.z = 0;
 
 
+  _active = true;
+
   _saved_outputtype = FMOD_OUTPUTTYPE_AUTODETECT;
   _saved_outputtype = FMOD_OUTPUTTYPE_AUTODETECT;
 
 
   if (_system == (FMOD::System *)NULL) {
   if (_system == (FMOD::System *)NULL) {

+ 5 - 3
panda/src/audiotraits/fmodAudioManager.h

@@ -123,9 +123,11 @@ public:
                                                 PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
                                                 PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
 
 
-  // Control the "relative distance factor" for 3D spacialized audio.  Default
-  // is 1.0 Fmod uses meters internally, so give a float in Units-per meter
-  // Don't know what Miles uses.
+  // Control the "relative scale that sets the distance factor" units for 3D
+  // spacialized audio. This is a float in units-per-meter. Default value is
+  // 1.0, which means that Panda units are understood as meters; for e.g.
+  // feet, set 3.28. This factor is applied only to Fmod and OpenAL at the
+  // moment.
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
 
 

+ 3 - 0
panda/src/audiotraits/fmodAudioSound.cxx

@@ -55,6 +55,9 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
   _velocity.y = 0;
   _velocity.y = 0;
   _velocity.z = 0;
   _velocity.z = 0;
 
 
+  _min_dist = 1.0;
+  _max_dist = 1000000000.0;
+
   // Play Rate Variable
   // Play Rate Variable
   _playrate = 1;
   _playrate = 1;
 
 

+ 7 - 8
panda/src/audiotraits/openalAudioManager.cxx

@@ -97,7 +97,7 @@ OpenALAudioManager() {
   _is_valid = true;
   _is_valid = true;
 
 
   // Init 3D attributes
   // Init 3D attributes
-  _distance_factor = 3.28;
+  _distance_factor = 1;
   _drop_off_factor = 1;
   _drop_off_factor = 1;
 
 
   _position[0] = 0;
   _position[0] = 0;
@@ -715,12 +715,11 @@ audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *
   *uz = _forward_up[4];
   *uz = _forward_up[4];
 }
 }
 
 
-
 /**
 /**
- * Set units per foot WARNING: OpenAL has no distance factor but we use this
- * as a scale on the min/max distances of sounds to preserve FMOD
- * compatibility.  Also, adjusts the speed of sound to compensate for unit
- * difference.  OpenAL's default speed of sound is 343.3 m/s == 1126.3 ft/s
+ * Set value in units per meter
+ * WARNING: OpenAL has no distance factor but we use this as a scale
+ *          on the min/max distances of sounds to preserve FMOD compatibility.
+ *          Also adjusts the speed of sound to compensate for unit difference.
  */
  */
 void OpenALAudioManager::
 void OpenALAudioManager::
 audio_3d_set_distance_factor(PN_stdfloat factor) {
 audio_3d_set_distance_factor(PN_stdfloat factor) {
@@ -732,7 +731,7 @@ audio_3d_set_distance_factor(PN_stdfloat factor) {
   alGetError(); // clear errors
   alGetError(); // clear errors
 
 
   if (_distance_factor>0) {
   if (_distance_factor>0) {
-    alSpeedOfSound(1126.3*_distance_factor);
+    alSpeedOfSound(343.3*_distance_factor);
     al_audio_errcheck("alSpeedOfSound()");
     al_audio_errcheck("alSpeedOfSound()");
     // resets the doppler factor to the correct setting in case it was set to
     // resets the doppler factor to the correct setting in case it was set to
     // 0.0 by a distance_factor<=0.0
     // 0.0 by a distance_factor<=0.0
@@ -752,7 +751,7 @@ audio_3d_set_distance_factor(PN_stdfloat factor) {
 }
 }
 
 
 /**
 /**
- * Sets units per foot
+ * Get value in units per meter
  */
  */
 PN_stdfloat OpenALAudioManager::
 PN_stdfloat OpenALAudioManager::
 audio_3d_get_distance_factor() const {
 audio_3d_get_distance_factor() const {

+ 8 - 5
panda/src/audiotraits/openalAudioManager.h

@@ -84,11 +84,14 @@ class EXPCL_OPENAL_AUDIO OpenALAudioManager : public AudioManager {
                                                 PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
                                                 PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
                                                 PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
 
 
-  // Control the "relative distance factor" for 3D spacialized audio in units-
-  // per-foot.  Default is 1.0 OpenAL has no distance factor but we use this
-  // as a scale on the minmax distances of sounds to preserve FMOD
-  // compatibility.  Also, adjusts the speed of sound to compensate for unit
-  // difference.
+
+  // Control the "relative scale that sets the distance factor" units for 3D
+  // spacialized audio. This is a float in units-per-meter. Default value is
+  // 1.0, which means that Panda units are understood as meters; for e.g.
+  // feet, set 3.28. This factor is applied only to Fmod and OpenAL at the
+  // moment.
+  // OpenAL in fact has no distance factor like Fmod, but works with the speed
+  // of sound instead, so we use this factor to scale the speed of sound.
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual void audio_3d_set_distance_factor(PN_stdfloat factor);
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
   virtual PN_stdfloat audio_3d_get_distance_factor() const;
 
 

+ 3 - 3
panda/src/audiotraits/openalAudioSound.cxx

@@ -48,7 +48,7 @@ OpenALAudioSound(OpenALAudioManager* manager,
   _balance(0),
   _balance(0),
   _play_rate(1.0),
   _play_rate(1.0),
   _positional(positional),
   _positional(positional),
-  _min_dist(3.28f),
+  _min_dist(1.0f),
   _max_dist(1000000000.0f),
   _max_dist(1000000000.0f),
   _drop_off_factor(1.0f),
   _drop_off_factor(1.0f),
   _length(0.0),
   _length(0.0),
@@ -673,7 +673,7 @@ set_3d_min_distance(PN_stdfloat dist) {
     _manager->make_current();
     _manager->make_current();
 
 
     alGetError(); // clear errors
     alGetError(); // clear errors
-    alSourcef(_source,AL_REFERENCE_DISTANCE,_min_dist*_manager->audio_3d_get_distance_factor());
+    alSourcef(_source,AL_REFERENCE_DISTANCE,_min_dist);
     al_audio_errcheck("alSourcefv(_source,AL_REFERENCE_DISTANCE)");
     al_audio_errcheck("alSourcefv(_source,AL_REFERENCE_DISTANCE)");
   }
   }
 }
 }
@@ -698,7 +698,7 @@ set_3d_max_distance(PN_stdfloat dist) {
     _manager->make_current();
     _manager->make_current();
 
 
     alGetError(); // clear errors
     alGetError(); // clear errors
-    alSourcef(_source,AL_MAX_DISTANCE,_max_dist*_manager->audio_3d_get_distance_factor());
+    alSourcef(_source,AL_MAX_DISTANCE,_max_dist);
     al_audio_errcheck("alSourcefv(_source,AL_MAX_DISTANCE)");
     al_audio_errcheck("alSourcefv(_source,AL_MAX_DISTANCE)");
   }
   }
 }
 }