Share via


3-D Buffers

Each sound source in a 3-D environment is represented by an object of the Buffer3D class. This class is supported only by sound buffers created with the BufferCaps.Control3D property.

Applications must supply monaural sound sources when using the 3-D capabilities of Microsoft DirectSound. If you attempt to create a buffer with the Control3D property set and a WAV format with more than one channel, an exception is raised.

This section describes how your applications can obtain and manage Buffer3D objects. The following topics are discussed.

  • Obtaining the Buffer3D Object
  • Batch Parameters for 3-D Buffers
  • Minimum and Maximum Distances
  • Processing Mode
  • Buffer Position and Velocity
  • Sound Cones

Obtaining the Buffer3D Object

Create a Buffer3D object by passing a SecondaryBuffer object to the Buffer3D constructor. The BufferDescription.Control3D property must have been set to true.

See Also

Buffer3D(SecondaryBuffer)

Batch Parameters for 3-D Buffers

Applications can retrieve or set a 3-D sound buffer's parameters individually or in batches. To set individual values, your application can use the applicable Buffer3D property. However, applications often must set or retrieve several values at once as the sound source moves about, changes velocity, and so on. You can do this by using the Buffer3D.AllParameters property.

Parameter changes can also be made more efficiently by flagging them as deferred and then running them all at once. For more information, see Deferred Settings.

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 practical 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 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 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 2 meters away, at quarter volume 4 meters away, 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 does not get any lower. The default maximum distance for a DirectSound 3-D buffer 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 virtual device drivers, applications should set a reasonable maximum distance and include the Mute3DAtMaximumDistance property 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 should not set the Mute3DAtMaximumDistance property.

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

Graph of effects of minimum and maximum distances on sound volume

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.

See Also

Buffer3D.AllParameters property

Buffer3D.MaxDistance property

Buffer3D.MinDistance property

Processing Mode

Sound buffers have three processing modes: normal, head-relative, and disabled.

In normal mode, the sound source is positioned and oriented absolutely in world space. This is the default mode, and is used for sound sources that do not move and turn with the listener.

In head-relative mode, the 3-D properties of the sound source are all relative to the current position, velocity, and orientation of the listener. As the listener moves and turns, the buffer is automatically repositioned in world space. Head-relative mode can be used for sounds such as the listener's own footsteps. However, most head-relative sounds do not have to be 3-D sounds at all.

In disabled mode, 3-D sound processing is disabled and the sound seems to originate from the center of the listener's head.

See Also

Buffer3D.AllParameters property

Buffer3D.Mode property

Buffer Position and Velocity

As a sound source moves, it is up to the application to specify values for its position and velocity.

Position is measured in distance units along each of the three axes, relative to either world space or the listener, depending on the processing mode.

Velocity is measured in distance units per second along each of the three axes of a vector. By default, distance units are meters. Velocity is used by DirectSound only to calculate the effects of Doppler shift.

See Also

Buffer3D.AllParameters property

Buffer3D.Position property

Buffer3D.Velocity property

Distance Factor

Doppler Factor

Processing Mode

Sound Cones

A sound with no orientation has the same amplitude at a given distance in all directions. A sound with an orientation is loudest in the direction of orientation. The model that describes the loudness of the oriented sound is called a sound cone, which has its apex located at the source of the sound. Sound cones are made up of an inside (or inner) cone and an outside (or outer) cone. The outside cone angle must always be equal to or greater than the inside cone angle.

At any angle within the inner cone, the volume of the sound is just what it would be if there were no cone, after taking into account the basic volume of the buffer, the distance from the listener, the listener's orientation, and so on.

At any angle outside the outer cone, the normal volume is attenuated by a factor set by the application. The outside cone volume is expressed in hundredths of decibels and is a negative value, because it represents attenuation from the default volume of 0.

Between the inner and outer cones is a zone of transition from the inside volume to the outside volume. The volume decreases as the angle increases.

The following illustration shows the concept of sound cones.

Diagram of listener within inside and outside sound cones

Every 3-D sound buffer has a sound cone, but by default a buffer behaves like an omnidirectional sound source, because the outside volume is not attenuated, and the inside and outside cone angles are 360 degrees. Unless the application changes these values, the sound does not have any apparent orientation.

Designing sound cones properly can add dramatic effects to your application. For example, you could position a sound source in the center of a room, setting its orientation toward an open door in a hallway. Then set the angle of the inside cone so that it extends to the width of the doorway, make the outside cone a bit wider, and set the outside cone volume to inaudible. A listener moving along the hallway will begin to hear the sound only when near the doorway, and the sound will be loudest as the listener passes in front of the open door.

See Also

Buffer3D.ConeAngles property

Buffer3D.ConeOrientation property

Buffer3D.ConeOutsideVolume property