diff --git a/source/main/audio/SoundManager.cpp b/source/main/audio/SoundManager.cpp index a487a04201..9ddf14b088 100644 --- a/source/main/audio/SoundManager.cpp +++ b/source/main/audio/SoundManager.cpp @@ -381,8 +381,9 @@ void SoundManager::Update(const float dt_sec) const auto water = App::GetGameContext()->GetTerrain()->getWater(); m_listener_is_underwater = (water != nullptr ? water->IsUnderWater(m_listener_position) : false); - recomputeAllSources(); - UpdateAlListener(); + this->recomputeAllSources(); + this->UpdateAlListener(); + this->UpdateListenerEnvironment(); if(App::audio_enable_efx->getBool()) { @@ -407,6 +408,35 @@ void SoundManager::SetListener(Ogre::Vector3 position, Ogre::Vector3 direction, m_listener_velocity = velocity; } +void SoundManager::UpdateListenerEnvironment() +{ + const EFXEAXREVERBPROPERTIES* listener_reverb_properties = nullptr; + + if (App::audio_engine_controls_environmental_audio->getBool()) + { + if (this->ListenerIsUnderwater()) + { + this->SetSpeedOfSound(1522.0f); // assume listener is in sea water (i.e. salt water) + /* + * According to the Francois-Garrison formula for frequency-dependant absorption at 5kHz in seawater, + * the absorption should be 0.334 db/km. OpenAL multiplies the Air Absorption Factor with an internal + * value of 0.05dB/m, so we need a factor of 0.00668f. + */ + this->SetAirAbsorptionFactor(0.00668f); + } + else + { + this->SetSpeedOfSound(343.3f); // assume listener is in air at 20° celsius + this->SetAirAbsorptionFactor(1.0f); + } + + if (App::audio_enable_efx->getBool()) + { + m_listener_efx_reverb_properties = this->GetReverbPresetAt(m_listener_position); + } + } +} + void SoundManager::UpdateAlListener() { float orientation[6]; @@ -466,11 +496,6 @@ const EFXEAXREVERBPROPERTIES* SoundManager::GetReverbPresetAt(const Ogre::Vector } } -void SoundManager::SetListenerEnvironment(const EFXEAXREVERBPROPERTIES* listener_reverb_properties) -{ - m_listener_efx_reverb_properties = listener_reverb_properties; -} - void SoundManager::UpdateListenerEffectSlot(const float dt_sec) { if(m_listener_efx_reverb_properties == nullptr) diff --git a/source/main/audio/SoundManager.h b/source/main/audio/SoundManager.h index cac3df76e5..7bd0ec2967 100644 --- a/source/main/audio/SoundManager.h +++ b/source/main/audio/SoundManager.h @@ -95,13 +95,6 @@ class SoundManager */ void SetListener(Ogre::Vector3 position, Ogre::Vector3 direction, Ogre::Vector3 up, Ogre::Vector3 velocity); - /** - * Updates the EFX/EAX reverb preset that is used as a base for updating the listener's effect slot. - * @param listener_environment The preset that will be used for the listener environment. - * @see UpdateListenerEffectSlot() - */ - void SetListenerEnvironment(const EFXEAXREVERBPROPERTIES* listener_efx_reverb_properties); - /** * Unlike the name suggests, this sets the listener's gain to 0, essentially muting all sounds. */ @@ -194,6 +187,12 @@ class SoundManager * @see SetListener() */ void UpdateAlListener(); + + /** + * Determines several properties of the environment of the listener and updates OpenAL to use them. + */ + void UpdateListenerEnvironment(); + void recomputeAllSources(); /** diff --git a/source/main/audio/SoundScriptManager.cpp b/source/main/audio/SoundScriptManager.cpp index da5d8e82a4..4654ee205b 100644 --- a/source/main/audio/SoundScriptManager.cpp +++ b/source/main/audio/SoundScriptManager.cpp @@ -24,7 +24,6 @@ #include "Actor.h" #include "CameraManager.h" -#include "GameContext.h" #include "Sound.h" #include "SoundManager.h" #include "Utils.h" @@ -321,7 +320,6 @@ void SoundScriptManager::update(float dt_sec) Ogre::Vector3 camera_direction = camera_node->getOrientation() * -Ogre::Vector3::UNIT_Z; SetListener(camera_position, camera_direction, camera_up, camera_velocity); - SetListenerEnvironment(camera_position); sound_manager->Update(dt_sec); } @@ -334,44 +332,6 @@ void SoundScriptManager::SetListener(Vector3 position, Vector3 direction, Vector sound_manager->SetListener(position, direction, up, velocity); } -void SoundScriptManager::SetListenerEnvironment(Vector3 listener_position) -{ - if (disabled) - return; - - const EFXEAXREVERBPROPERTIES* listener_reverb_properties = nullptr; - - if (App::audio_engine_controls_environmental_audio->getBool()) - { - if (sound_manager->ListenerIsUnderwater()) - { - sound_manager->SetSpeedOfSound(1522.0f); // assume listener is in sea water (i.e. salt water) - /* - * According to the Francois-Garrison formula for frequency-dependant absorption at 5kHz in seawater, - * the absorption should be 0.334 db/km. OpenAL multiplies the Air Absorption Factor with an internal - * value of 0.05dB/m, so we need a factor of 0.00668f. - */ - sound_manager->SetAirAbsorptionFactor(0.00668f); - } - else - { - sound_manager->SetSpeedOfSound(343.3f); // assume listener is in air at 20° celsius - sound_manager->SetAirAbsorptionFactor(1.0f); - } - - if (App::audio_enable_efx->getBool()) - { - listener_reverb_properties = sound_manager->GetReverbPresetAt(listener_position); - } - } - - if (App::audio_enable_efx->getBool()) - { - // always update the environment in case it was changed via console or script - sound_manager->SetListenerEnvironment(listener_reverb_properties); - } -} - const StringVector& SoundScriptManager::getScriptPatterns(void) const { return script_patterns; diff --git a/source/main/audio/SoundScriptManager.h b/source/main/audio/SoundScriptManager.h index 092b90d28f..a6bc061dd2 100644 --- a/source/main/audio/SoundScriptManager.h +++ b/source/main/audio/SoundScriptManager.h @@ -31,12 +31,6 @@ #include -#ifdef __APPLE__ - #include -#else - #include -#endif - #define SOUND_PLAY_ONCE(_ACTOR_, _TRIG_) App::GetSoundScriptManager()->trigOnce ( (_ACTOR_), (_TRIG_) ) #define SOUND_START(_ACTOR_, _TRIG_) App::GetSoundScriptManager()->trigStart ( (_ACTOR_), (_TRIG_) ) #define SOUND_STOP(_ACTOR_, _TRIG_) App::GetSoundScriptManager()->trigStop ( (_ACTOR_), (_TRIG_) )