Share via


Minimum and Maximum Distances

[The feature associated with this page, DirectSound, is a legacy feature. It has been superseded by WASAPI and Audio Graphs. Media Casting have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Media Casting instead of DirectSound, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

As a listener approaches a sound source, the sound gets louder; the volume doubles when the distance is halved. Past a certain point, however, it is not reasonable for the volume to continue to increase. This is the minimum distance for the sound source.

The minimum distance that you set for a sound determines how quickly that sound fades away with distance. For example, you might set this value to 100 meters for a jet engine and to 2 centimeters for a bee. With these settings, the jet engine is at half volume when 200 meters away from the listener, but the bee is at half volume when only 4 centimeters away.

The following illustration shows how minimum and maximum distance affect the volume of a jet engine and a bee at increasing distances.

Figure 1.��Minimum and maximum distances

Ee418662.minmax(en-us,VS.85).gif

The default minimum distance for a sound buffer, DS3D_DEFAULTMINDISTANCE, is defined as 1 unit, or 1 meter at the default distance factor. Unless you change this value, the sound is at full volume when it is 1 meter away from the listener, at half volume at 2 meters, at quarter volume at 4 meters, and so on. For most sounds you will probably want to set a larger minimum distance so that the sound does not fade so rapidly as it moves away.

The maximum distance for a sound source is the distance beyond which the volume of the sound no longer decreases. The default maximum distance for a DirectSound 3D buffer (DS3D_DEFAULTMAXDISTANCE) is 1 billion, meaning that in most cases the attenuation will continue to be calculated long after the sound has moved out of hearing range. To avoid unnecessary processing on software buffers under VXD drivers, applications should set a reasonable maximum distance and include the DSBCAPS_MUTE3DATMAXDISTANCE flag when creating the buffer.

The maximum distance can also be used to prevent a sound from becoming inaudible. For example, if you have set the minimum distance for a sound at 100 meters, that sound might become effectively inaudible at 1,000 meters or less. By setting the maximum distance at 800 meters, you ensure that the sound always has at least one-eighth of its maximum volume regardless of the distance. In this case, of course, you would not set the DSBCAPS_MUTE3DATMAXDISTANCE flag.

By default, distance values are expressed in meters.

To adjust the effect of distance on volume for all sound buffers, you can change the rolloff factor.