diff --git a/source/main/Application.cpp b/source/main/Application.cpp index b88b192d93..fe3151bd6d 100644 --- a/source/main/Application.cpp +++ b/source/main/Application.cpp @@ -206,8 +206,6 @@ CVar* io_discord_rpc; CVar* io_invert_orbitcam; // Audio -CVar* audio_air_absorption_factor; -CVar* audio_air_absorption_gain_hf; CVar* audio_master_volume; CVar* audio_enable_creak; CVar* audio_enable_obstruction; diff --git a/source/main/Application.h b/source/main/Application.h index f834fec7cd..b4c2830f8e 100644 --- a/source/main/Application.h +++ b/source/main/Application.h @@ -453,8 +453,6 @@ extern CVar* io_discord_rpc; extern CVar* io_invert_orbitcam; // Audio -extern CVar* audio_air_absorption_factor; -extern CVar* audio_air_absorption_gain_hf; extern CVar* audio_master_volume; extern CVar* audio_enable_creak; extern CVar* audio_enable_obstruction; diff --git a/source/main/audio/SoundManager.cpp b/source/main/audio/SoundManager.cpp index 19a48ff6da..1c0c9a55c3 100644 --- a/source/main/audio/SoundManager.cpp +++ b/source/main/audio/SoundManager.cpp @@ -384,7 +384,7 @@ void SoundManager::Update(const float dt_sec) for(int hardware_index = 0; hardware_index < hardware_sources_num; hardware_index++) { // update air absorption factor - alSourcef(hardware_sources[hardware_index], AL_AIR_ABSORPTION_FACTOR, App::audio_air_absorption_factor->getFloat()); + alSourcef(hardware_sources[hardware_index], AL_AIR_ABSORPTION_FACTOR, m_air_absorption_factor); this->UpdateObstructionFilter(hardware_index); } @@ -433,8 +433,6 @@ void SoundManager::UpdateListenerEffectSlot(const float dt_sec) EFXEAXREVERBPROPERTIES current_environmental_properties = *m_listener_efx_reverb_properties; - current_environmental_properties.flAirAbsorptionGainHF = App::audio_air_absorption_gain_hf->getFloat(); - // early reflections panning, delay and strength if (App::audio_enable_reflection_panning->getBool() && m_efx_reverb_engine == EfxReverbEngine::EAXREVERB) { diff --git a/source/main/audio/SoundManager.h b/source/main/audio/SoundManager.h index fe7eca2aea..00319a4746 100644 --- a/source/main/audio/SoundManager.h +++ b/source/main/audio/SoundManager.h @@ -138,6 +138,17 @@ class SoundManager */ void SetDopplerFactor(const float doppler_factor) const { alDopplerFactor(doppler_factor); } + /** + * Sets the air absorptions factor for the direct path of all sounds. + * @param air_absorption_factor Air absorption factor within the range of AL_AIR_ABSORPTION_FACTOR. + */ + void SetAirAbsorptionFactor(const float air_absorption_factor) { m_air_absorption_factor = air_absorption_factor; } + + /** + * @return current value set for the air absorption factor for the direct path of sounds + */ + float GetAirAbsorptionFactor() const { return m_air_absorption_factor; } + /** * Returns the number of currently used hardware sources. In a typical scenario, * this value changes dynamically. @@ -233,6 +244,7 @@ class SoundManager bool m_efx_is_available = false; ALuint m_listener_slot = 0; ALuint m_efx_outdoor_obstruction_lowpass_filter_id = 0; + float m_air_absorption_factor = 1.0f; EfxReverbEngine m_efx_reverb_engine = EfxReverbEngine::NONE; const EFXEAXREVERBPROPERTIES* m_listener_efx_reverb_properties = nullptr; std::map m_efx_properties_map; diff --git a/source/main/audio/SoundScriptManager.cpp b/source/main/audio/SoundScriptManager.cpp index dc092080d8..e85d244d32 100644 --- a/source/main/audio/SoundScriptManager.cpp +++ b/source/main/audio/SoundScriptManager.cpp @@ -361,18 +361,16 @@ void SoundScriptManager::SetListenerEnvironment(Vector3 listener_position) { 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 water - and assuming the Air Absorption Gain HF property of OpenAL is set to the minimum of 0.892, - the absorption factor should be ~11.25, which is just slightly above the maximum of 10.0. - */ - App::audio_air_absorption_factor->setVal(10.0f); - App::audio_air_absorption_gain_hf->setVal(0.892f); + * 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 - App::audio_air_absorption_factor->setVal(1.0f); - App::audio_air_absorption_gain_hf->setVal(0.994f); + sound_manager->SetAirAbsorptionFactor(1.0f); } if (App::audio_enable_efx->getBool()) diff --git a/source/main/system/CVar.cpp b/source/main/system/CVar.cpp index a1322f736e..fca9c1acd4 100644 --- a/source/main/system/CVar.cpp +++ b/source/main/system/CVar.cpp @@ -149,8 +149,6 @@ void Console::cVarSetupBuiltins() App::io_discord_rpc = this->cVarCreate("io_discord_rpc", "Discord Rich Presence", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "true"); App::io_invert_orbitcam = this->cVarCreate("io_invert_orbitcam", "Invert orbit camera", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false"); - App::audio_air_absorption_factor = this->cVarCreate("audio_air_absorption_factor", "Air absorption factor", CVAR_TYPE_FLOAT, "1.0"); - App::audio_air_absorption_gain_hf = this->cVarCreate("audio_air_absorption_gain_hf", "Air absorption Gain HF", CVAR_TYPE_FLOAT, "0.994"); App::audio_master_volume = this->cVarCreate("audio_master_volume", "Sound Volume", CVAR_ARCHIVE | CVAR_TYPE_FLOAT, "1.0"); App::audio_enable_creak = this->cVarCreate("audio_enable_creak", "Creak Sound", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false"); App::audio_enable_obstruction = this->cVarCreate("audio_enable_obstruction", "Obstruction of sounds", CVAR_ARCHIVE | CVAR_TYPE_BOOL, "false");