DirectX SDK

Minimum and Maximum Distances

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 is especially useful when an application must compensate for the difference in absolute volume levels of different sounds. Although a jet engine is much louder than a bee, for example, for practical reasons these sounds must be recorded at similar absolute volumes. An application might use a minimum distance of 100 meters for the jet engine and 2 centimeters for the bee. With these settings, the jet engine would be at half volume when the listener was 200 meters away, but the bee would be at half volume when the listener was 4 centimeters away.

The default minimum distance for a sound buffer, DS3D_DEFAULTMINDISTANCE, is currently defined as 1 unit. Unless you change this value, the sound will be only half as loud when it is 2 meters away from the user, a quarter as loud at 4 meters, and so on. For most sounds you will probably want to set a larger minimum distance.

The maximum distance for a sound source is the distance beyond which the sound does not get any quieter. The default maximum distance for a DirectSound 3-D buffer (DS3D_DEFAULTMAXDISTANCE) is a huge number, meaning that in most cases the attenuation will continue to be calculated even when the sound ceases to be audible. In order to avoid unnecessary processing, 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 would ensure that the sound always had 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.

The following illustration shows the concepts of minimum and maximum distance.

[C++]

An application sets and retrieves the minimum distance value by using the IDirectSound3DBuffer::SetMinDistance and IDirectSound3DBuffer::GetMinDistance methods. Similarly, it can set and retrieve the maximum distance value by using the IDirectSound3DBuffer::SetMaxDistance and IDirectSound3DBuffer::GetMaxDistance methods.

[Visual Basic]

An application sets and retrieves the minimum distance value by using the DirectSound3DBuffer.SetMinDistance and DirectSound3DBuffer.GetMinDistance methods. Similarly, it can set and retrieve the maximum distance value by using the DirectSound3DBuffer.SetMaxDistance and DirectSound3DBuffer.GetMaxDistance methods.

By default, distance values are expressed in meters. See Distance Factor.

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