SoundEffect.DistanceScale Property

Gets or sets a value that adjusts the effect of distance calculations on the sound (emitter).

Namespace: Microsoft.Xna.Framework.Audio
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public static float DistanceScale { get; set; }

Property Value

Value that scales distance calculations on the sound (emitter).

Remarks

If sounds are attenuating too fast, which means that the sounds get quiet too quickly as they move away from the listener, you need to increase the DistanceScale. If sounds are not attenuating fast enough, decrease the DistanceScale.

This property will also affect Doppler sound.

Adjustment Effect
DistanceScale <= 0.0f Throws an ArgumentOutOfRangeException (invalid value).
0.0 < DistanceScale <= 1.0 Increases the effect of distance attenuation.
DistanceScale = 1.0 No scaling (this is the default setting).
DistanceScale > 1.0 Decrease the effect of distance attenuation.

Distance attenuation is calculated using the inverse square law:

volume = 1.0 / distance;

Adding DistanceScale into the equations give:

if (distance > DistanceScale)
{
  volume = DistanceScale / distance;
}
else
{
  volume = 1.0;
}

Exceptions

Exception type Condition
ArgumentOutOfRangeException The exception that is thrown when DistanceScale is less than or equal to 0.0.

See Also

SoundEffect Class
SoundEffect Members
Microsoft.Xna.Framework.Audio Namespace

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP, Windows Phone