Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Core/GameEngine/Include/Common/AudioSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Core/GameEngine/Source/Common/Audio/GameAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
23 changes: 12 additions & 11 deletions Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,30 +2690,31 @@ 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
{
objMinDistance = event->getAudioEventInfo()->m_minDistance;
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when objMaxDistance and objMinDistance are set by m_globalMaxRange and m_globalMinRange, they are set through ini. Theoretically, a user could (incorrectly) edit the ini such that the values are the same, causing a division by zero.

Looking at it, this could also be the case if objMax/MinDistance is set by m_minDistance and m_maxDistance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If objMaxDistance == objMinDistance, then it never gets here, because if( objDistance >= objMaxDistance ) above.

attenuation = pow(attenuation, audioSettings->m_3DSoundRangeVolumeFadeExponent);
volume *= 1.0f - attenuation;
}
}
}
else
Expand Down
Loading