Microsoft DirectX 9.0

Play 3D Sound Sample

Description

The Play 3D Sound sample shows how to create a 3-D sound buffer and manipulate its properties. It is similar to the 3D Audio Sample but uses only the DirectSound API.

Path

Source: (SDK root)\Samples\C++\DirectSound\Play3DSound

Executable: (SDK root)\Samples\C++\DirectSound\Bin

User's Guide

Click Sound File and load a WAV file. Play the sound. The position of the sound source is shown as a red dot on the graph, where the x-axis is from left to right and the z-axis is from bottom to top. Change the range of movement on the two axes by using the sliders.

The listener is located at the center of the graph, and has its default orientation, looking along the positive z-axis; that is, toward the top of the screen. The sound source moves to the listener's left and right and to the listener's front and rear, but does not move above and below the listener.

The sliders in the center of the window control the properties of the listener; that is, the global sound properties. If you click Defer Settings, changes are not applied until you click Apply Settings.

Programming Notes

For a simpler example of how to set up a DirectSound buffer without 3-D positioning, see the Play Sound Sample.

The sample obtains an IDirectSound3DListener8 interface as follows:

  1. Describes a buffer in a DSBUFFERDESC structure containing the DSBCAPS_CTRL3D and DSBCAPS_PRIMARYBUFFER flags.
  2. Passes the buffer description to IDirectSound8::CreateSoundBuffer. This creates a primary buffer object with 3-D capabilities.
  3. Calls QueryInterface to obtain the IDirectSound3DListener8 interface. This interface controls global 3-D properties.

The sample obtains an IDirectSound3DBuffer8 interface as follows:

  1. Describes a buffer in a DSBUFFERDESC structure, setting the DSBCAPS_CTRL3D capabilties flag and and a 3-D virtualization algorithm.
  2. Passes the buffer description to IDirectSound8::CreateSoundBuffer, creating a secondary buffer object with 3-D capabilities.
  3. Calls QueryInterface to obtain the IDirectSound3DBuffer8 interface. This interface controls the 3-D properties of sounds played through the buffer.

The application sets the parameters of the listener by calling IDirectSound3DListener8::SetAllParameters. The listener properties are described in a DS3DLISTENER structure. To set the position of the sound source, the application calls IDirectSound3DBuffer8::SetAllParameters, passing in a DS3DBUFFER structure.

If the DS3D_DEFERRED flag is set when parameters are set, nothing is actually changed until IDirectSound3DListener8::CommitDeferredSettings is called. This method commits all deferred settings for buffers as well as the listener, and makes it possible for DirectSound to perform calculations once instead of many times.

See Also