diff --git a/Core/GameEngine/Include/Common/AudioSettings.h b/Core/GameEngine/Include/Common/AudioSettings.h index 93a485e848a..f7f99628890 100644 --- a/Core/GameEngine/Include/Common/AudioSettings.h +++ b/Core/GameEngine/Include/Common/AudioSettings.h @@ -32,15 +32,15 @@ enum { MAX_HW_PROVIDERS = 4 }; -// TheSuperHackers @tweak xezon 23/07/2025 Adds setting to modify the volume of money deposit and withdraw sounds - struct AudioSettings { AudioSettings() + : m_use3DSoundRangeVolumeFade(true) // Enabled by default because it prevents audio cut off at the max range of 3D sounds + , m_3DSoundRangeVolumeFadeExponent(4.0f) // Exponent of 4 gives a nice balance between loud sounds and graceful fade #if RTS_GENERALS - : m_defaultMoneyTransactionVolume(1.0f) + , m_defaultMoneyTransactionVolume(1.0f) #elif RTS_ZEROHOUR - : m_defaultMoneyTransactionVolume(0.0f) // Uses zero volume by default because originally the money sounds did not work in Zero Hour + , m_defaultMoneyTransactionVolume(0.0f) // Uses zero volume by default because originally the money sounds did not work in Zero Hour #endif { } @@ -58,6 +58,9 @@ struct AudioSettings Int m_sampleCount2D; Int m_sampleCount3D; Int m_streamCount; + Bool m_use3DSoundRangeVolumeFade; // TheSuperHackers @feature Enables 3D sound range volume fade as originally intended + Real m_3DSoundRangeVolumeFadeExponent; // TheSuperHackers @feature Sets 3D sound range volume fade exponent for non-linear fade. + // The higher the exponent, the sharper the decline at the max range. Int m_globalMinRange; Int m_globalMaxRange; Int m_drawableAmbientFrames; @@ -83,7 +86,7 @@ struct AudioSettings Real m_preferred3DSoundVolume; Real m_preferredSpeechVolume; Real m_preferredMusicVolume; - Real m_preferredMoneyTransactionVolume; + Real m_preferredMoneyTransactionVolume; // TheSuperHackers @feature Modifies the volume of money deposit and withdraw sounds //The desired altitude of the microphone to improve panning relative to terrain. Real m_microphoneDesiredHeightAboveTerrain; diff --git a/Core/GameEngine/Source/Common/Audio/GameAudio.cpp b/Core/GameEngine/Source/Common/Audio/GameAudio.cpp index bb9808f624e..0da135a86a4 100644 --- a/Core/GameEngine/Source/Common/Audio/GameAudio.cpp +++ b/Core/GameEngine/Source/Common/Audio/GameAudio.cpp @@ -116,6 +116,8 @@ static const FieldParse audioSettingsFieldParseTable[] = { "Default3DSpeakerType", parseSpeakerType, nullptr, offsetof( AudioSettings, m_defaultSpeakerType3D) }, { "MinSampleVolume", INI::parsePercentToReal, nullptr, offsetof( AudioSettings, m_minVolume) }, + { "Use3DSoundRangeVolumeFade", INI::parseBool, nullptr, offsetof( AudioSettings, m_use3DSoundRangeVolumeFade) }, + { "3DSoundRangeVolumeFadeExponent", INI::parseReal, nullptr, offsetof( AudioSettings, m_3DSoundRangeVolumeFadeExponent) }, { "GlobalMinRange", INI::parseInt, nullptr, offsetof( AudioSettings, m_globalMinRange) }, { "GlobalMaxRange", INI::parseInt, nullptr, offsetof( AudioSettings, m_globalMaxRange) }, { "TimeBetweenDrawableSounds", INI::parseDurationUnsignedInt, nullptr, offsetof( AudioSettings, m_drawableAmbientFrames) }, diff --git a/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp index 1d41ef08736..b0107b96d0e 100644 --- a/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp +++ b/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp @@ -2690,10 +2690,12 @@ Real MilesAudioManager::getEffectiveVolume(AudioEventRTS *event) const Real objMinDistance; Real objMaxDistance; + const AudioSettings *audioSettings = TheAudio->getAudioSettings(); + if (event->getAudioEventInfo()->m_type & ST_GLOBAL) { - objMinDistance = TheAudio->getAudioSettings()->m_globalMinRange; - objMaxDistance = TheAudio->getAudioSettings()->m_globalMaxRange; + objMinDistance = audioSettings->m_globalMinRange; + objMaxDistance = audioSettings->m_globalMaxRange; } else { @@ -2701,19 +2703,18 @@ Real MilesAudioManager::getEffectiveVolume(AudioEventRTS *event) const objMaxDistance = event->getAudioEventInfo()->m_maxDistance; } - Real objDistance = distance.length(); - if( objDistance > objMinDistance ) - { - volume *= 1 / (objDistance / objMinDistance); - } + const Real objDistance = distance.length(); + if( objDistance >= objMaxDistance ) { volume = 0.0f; } - //else if( objDistance > objMinDistance ) - //{ - // volume *= 1.0f - (objDistance - objMinDistance) / (objMaxDistance - objMinDistance); - //} + else if( audioSettings->m_use3DSoundRangeVolumeFade && objDistance > objMinDistance ) + { + Real attenuation = (objDistance - objMinDistance) / (objMaxDistance - objMinDistance); + attenuation = pow(attenuation, audioSettings->m_3DSoundRangeVolumeFadeExponent); + volume *= 1.0f - attenuation; + } } } else