au.itd.SetSpeedOfSound
au.itd.SetSpeedOfSound
#Overview
name: au.itd.SetSpeedOfSound
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Sets speed of sound to use for ITD calculations.\nValue: Speed of sound in meters.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of au.itd.SetSpeedOfSound is to set the speed of sound used for Interaural Time Difference (ITD) calculations in the spatialization system of Unreal Engine 5. This setting is crucial for accurately simulating the perception of sound direction in 3D space.
This setting variable is primarily used by the Spatialization plugin, which is part of Unreal Engine’s audio system. Specifically, it’s utilized in the ITDSpatializer module, which handles spatial audio processing.
The value of this variable is set using a console variable (CVar) system. It’s initialized with a default value of 343.0f meters per second, which is the approximate speed of sound in air at room temperature. Developers can modify this value at runtime using console commands or through code.
The au.itd.SetSpeedOfSound variable interacts directly with the SpeedOfSoundCVar variable. They share the same value, with SpeedOfSoundCVar being the actual float variable used in calculations throughout the code.
Developers should be aware that changing this value will affect the perceived spatialization of all sounds in the game. It’s particularly important for maintaining realistic audio behavior in different environments (e.g., underwater scenes might require a different speed of sound).
Best practices when using this variable include:
- Only modifying it if you have a specific reason to do so (e.g., simulating different environments).
- Ensuring that any changes are consistent with the game’s audio design and physical setting.
- Testing thoroughly after making changes, as it can significantly impact the player’s audio experience.
Regarding the associated variable SpeedOfSoundCVar:
The purpose of SpeedOfSoundCVar is to store and provide access to the speed of sound value within the ITDSpatializer code. It’s the actual variable used in calculations, while au.itd.SetSpeedOfSound is the console variable name used to set its value.
SpeedOfSoundCVar is used in the Spatialization plugin, specifically in the ITDSpatializer module. It’s directly used in calculations for determining audio delay times based on spatial positioning.
The value of SpeedOfSoundCVar is set through the au.itd.SetSpeedOfSound console variable. It’s initialized with a default value of 343.0f meters per second.
This variable interacts closely with other variables in the spatial audio calculations, such as HeadWidthCVar, which represents the width of the listener’s head.
Developers should be aware that this variable is used in critical audio spatialization calculations. Changes to its value will directly affect how sound is perceived to move through space in the game.
Best practices for SpeedOfSoundCVar include:
- Avoiding direct modification of this variable in code; instead, use the au.itd.SetSpeedOfSound console variable to change its value.
- Considering the impact on all spatial audio when modifying this value.
- Ensuring that any changes to this value are scientifically accurate if aiming for realistic audio simulation.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/Runtime/Spatialization/Source/Spatialization/Private/ITDSpatializer.cpp:11
Scope: file
Source code excerpt:
static float SpeedOfSoundCVar = 343.0f;
FAutoConsoleVariableRef CVarSpeedOfSound(
TEXT("au.itd.SetSpeedOfSound"),
SpeedOfSoundCVar,
TEXT("Sets speed of sound to use for ITD calculations.\n")
TEXT("Value: Speed of sound in meters."),
ECVF_Default);
static float HeadWidthCVar = 34.0f;
#Associated Variable and Callsites
This variable is associated with another variable named SpeedOfSoundCVar
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Plugins/Runtime/Spatialization/Source/Spatialization/Private/ITDSpatializer.cpp:9
Scope: file
Source code excerpt:
const int32 NumOutputChannels = 2;
static float SpeedOfSoundCVar = 343.0f;
FAutoConsoleVariableRef CVarSpeedOfSound(
TEXT("au.itd.SetSpeedOfSound"),
SpeedOfSoundCVar,
TEXT("Sets speed of sound to use for ITD calculations.\n")
TEXT("Value: Speed of sound in meters."),
ECVF_Default);
static float HeadWidthCVar = 34.0f;
FAutoConsoleVariableRef CVarHeadWidth(
#Loc: <Workspace>/Engine/Plugins/Runtime/Spatialization/Source/Spatialization/Private/ITDSpatializer.cpp:49
Scope (from outer to inner):
file
function FSourceSpatializer::FSourceSpatializer
Source code excerpt:
{
// Max delay line length will be the maximum distance audio will need to travel divided by the speed of sound:
const float MaxDelay = 0.5f; //HeadWidthCVar / 1000.0f / SpeedOfSoundCVar;
const float EaseFactor = Audio::FExponentialEase::GetFactorForTau(InterpolationTauCVar, InSampleRate);
LeftDelays.Reset();
LeftDelays.AddDefaulted(2);
RightDelays.Reset();
#Loc: <Workspace>/Engine/Plugins/Runtime/Spatialization/Source/Spatialization/Private/ITDSpatializer.cpp:184
Scope (from outer to inner):
file
function void FSourceSpatializer::EvaluateDelayDestinationForInputChannel
Source code excerpt:
const float DistanceToRightEar = FMath::Sqrt((X * X) + FMath::Square(HeadRadius - Y));
const float DeltaInSeconds = (DistanceToLeftEar - DistanceToRightEar) / SpeedOfSoundCVar;
if (DeltaInSeconds > 0)
{
LeftDelays[ChannelIndex].SetEasedDelayMsec(DeltaInSeconds * 1000.0f);
RightDelays[ChannelIndex].SetEasedDelayMsec(0.0f);
}