bugfix(audio): Fix range volume fade of 3D sounds and make it configurable in AudioSettings.ini#2369
Open
xezon wants to merge 3 commits intoTheSuperHackers:mainfrom
Open
bugfix(audio): Fix range volume fade of 3D sounds and make it configurable in AudioSettings.ini#2369xezon wants to merge 3 commits intoTheSuperHackers:mainfrom
xezon wants to merge 3 commits intoTheSuperHackers:mainfrom
Conversation
…rable in AudioSettings.ini
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/Common/AudioSettings.h | Adds m_use3DSoundRangeVolumeFade and m_3DSoundRangeVolumeFadeExponent fields with correct constructor initialization; existing structure and pragma-once guard are intact. |
| Core/GameEngine/Source/Common/Audio/GameAudio.cpp | Two new INI parse-table entries wired up correctly to the new AudioSettings fields; no functional issues. |
| Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp | Replaces the broken reciprocal-distance attenuation with a correct configurable exponential fade; logic is sound for valid exponent values but lacks a guard against zero or negative exponents which can produce negative volume output. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[getEffectiveVolume called] --> B{isPositionalAudio?}
B -- No --> C[volume *= m_soundVolume]
B -- Yes --> D{getCurrentPosition != null?}
D -- No --> E[return volume as-is]
D -- Yes --> F[compute distance vector\ndistance = listenerPos - soundPos]
F --> G{ST_GLOBAL flag?}
G -- Yes --> H[objMin/Max = globalMinRange / globalMaxRange]
G -- No --> I[objMin/Max = event minDistance / maxDistance]
H & I --> J[objDistance = distance.length]
J --> K{objDistance >= objMaxDistance?}
K -- Yes --> L[volume = 0.0f]
K -- No --> M{use3DSoundRangeVolumeFade\n&& objDistance > objMinDistance?}
M -- No --> N[volume unchanged]
M -- Yes --> O["attenuation = (objDist - minDist) / (maxDist - minDist)"]
O --> P["attenuation = pow(attenuation, fadeExponent)"]
P --> Q["volume *= 1.0f - attenuation"]
L & N & Q --> R[return volume]
Last reviewed commit: 49616d2
Skyaero42
requested changes
Mar 1, 2026
Skyaero42
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is a follow up for #2058 which accidentally and insufficiently changed the volume of 3D sounds depending on their distance to the camera pivot.
Originally the sounds did not correctly consider the 3D distance checks in
MilesAudioManager::getEffectiveVolume. They were considered for some logic, but not for the actual volume. This meant that the volume never correctly faded between the min and max ranges of audio events, and left sharp audio cut offs instead.Problems
The originally unused fade math in
MilesAudioManager::getEffectiveVolumewas incorrect. The commented linear fade math was actually correct.The original 3D sounds were always loud all the way to the max range because they never faded correctly. Therefore an exponential fade is suitable to better preserve the original loudness of 3D sounds.
AudioSettings.ini
New configuration options were added to AudioSettings.ini to control the 3D sounds fade behavior:
Use3DSoundRangeVolumeFade = Yes/No// Set No for original bugged behavior3DSoundRangeVolumeFadeExponent = 1..N// Set 1 for linear fade, larger 1 for sharp fade near max rangeExponential Fade
I picked a exponent of 4 which creates a curve like this and sounded good.
x(0) is MinRange, x(1) is MaxRange
y(0) is MinVolume, y(1) is MaxVolume