mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Merge branch 'fix-audio-distance-factor' of github.com:nikolmiv/panda3d
Closes: #13
This commit is contained in:
commit
4cd826e63a
@ -154,9 +154,10 @@ PUBLISHED:
|
||||
PN_stdfloat *ux, PN_stdfloat *uy, PN_stdfloat *uz);
|
||||
|
||||
// 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 PN_stdfloat audio_3d_get_distance_factor() const;
|
||||
|
||||
|
@ -42,14 +42,8 @@ pset<FmodAudioManager *> FmodAudioManager::_all_managers;
|
||||
|
||||
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::_distance_factor = 3.28;
|
||||
PN_stdfloat FmodAudioManager::_distance_factor = 1;
|
||||
PN_stdfloat FmodAudioManager::_drop_off_factor = 1;
|
||||
|
||||
|
||||
@ -100,6 +94,8 @@ FmodAudioManager() {
|
||||
_up.y = 0;
|
||||
_up.z = 0;
|
||||
|
||||
_active = true;
|
||||
|
||||
_saved_outputtype = FMOD_OUTPUTTYPE_AUTODETECT;
|
||||
|
||||
if (_system == (FMOD::System *)NULL) {
|
||||
|
@ -123,9 +123,11 @@ public:
|
||||
PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
|
||||
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 PN_stdfloat audio_3d_get_distance_factor() const;
|
||||
|
||||
|
@ -55,6 +55,9 @@ FmodAudioSound(AudioManager *manager, Filename file_name, bool positional) {
|
||||
_velocity.y = 0;
|
||||
_velocity.z = 0;
|
||||
|
||||
_min_dist = 1.0;
|
||||
_max_dist = 1000000000.0;
|
||||
|
||||
// Play Rate Variable
|
||||
_playrate = 1;
|
||||
|
||||
|
@ -97,7 +97,7 @@ OpenALAudioManager() {
|
||||
_is_valid = true;
|
||||
|
||||
// Init 3D attributes
|
||||
_distance_factor = 3.28;
|
||||
_distance_factor = 1;
|
||||
_drop_off_factor = 1;
|
||||
|
||||
_position[0] = 0;
|
||||
@ -715,12 +715,11 @@ audio_3d_get_listener_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *
|
||||
*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::
|
||||
audio_3d_set_distance_factor(PN_stdfloat factor) {
|
||||
@ -732,7 +731,7 @@ audio_3d_set_distance_factor(PN_stdfloat factor) {
|
||||
alGetError(); // clear errors
|
||||
|
||||
if (_distance_factor>0) {
|
||||
alSpeedOfSound(1126.3*_distance_factor);
|
||||
alSpeedOfSound(343.3*_distance_factor);
|
||||
al_audio_errcheck("alSpeedOfSound()");
|
||||
// resets the doppler factor to the correct setting in case it was set to
|
||||
// 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::
|
||||
audio_3d_get_distance_factor() const {
|
||||
|
@ -84,11 +84,14 @@ class EXPCL_OPENAL_AUDIO OpenALAudioManager : public AudioManager {
|
||||
PN_stdfloat *fx, PN_stdfloat *fy, PN_stdfloat *fz,
|
||||
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 PN_stdfloat audio_3d_get_distance_factor() const;
|
||||
|
||||
|
@ -48,7 +48,7 @@ OpenALAudioSound(OpenALAudioManager* manager,
|
||||
_balance(0),
|
||||
_play_rate(1.0),
|
||||
_positional(positional),
|
||||
_min_dist(3.28f),
|
||||
_min_dist(1.0f),
|
||||
_max_dist(1000000000.0f),
|
||||
_drop_off_factor(1.0f),
|
||||
_length(0.0),
|
||||
@ -673,7 +673,7 @@ set_3d_min_distance(PN_stdfloat dist) {
|
||||
_manager->make_current();
|
||||
|
||||
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)");
|
||||
}
|
||||
}
|
||||
@ -698,7 +698,7 @@ set_3d_max_distance(PN_stdfloat dist) {
|
||||
_manager->make_current();
|
||||
|
||||
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)");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user