Microsoft DirectX 8.1 (Visual Basic)

Play3DSound

Description

The Play3DSound sample shows how to create a 3-D sound buffer and manipulate its properties.

Path

Source: (SDK root)\Samples\Multimedia\VBSamples\DirectSound\Play3DSound

Executable: (SDK root)\Samples\Multimedia\VBSamples\DirectSound\Bin

User's Guide

Load a mono wave file by clicking Sound. Choose a 3-D virtualization algorithm. Play the sound, and set the volume and direction of the sound source by using the sliders. The direction is the orientation of the sound cone; the sound cone is oriented toward the narrow point of the red triangle. Move the sound source by dragging the red triangle or by clicking on a destination. The listener is represented by the black triangle, which cannot be moved.

Programming Notes

Because of the limitations of a two-dimensional display, the sound source can move only along the x-axis (positive toward the right of the screen) and along the z-axis (positive toward the bottom of the screen). The application uses the default listener position (0, 0, 0) and orientation (0, 0, 1). This means that the listener is facing the top of the screen.

If the user attempts to load a stereo file, an error results, because a buffer in a stereo wave format cannot be created with the DSBCAPS_CTRL3D flag. The DSBUFFERDESC type passed to DirectSound8.CreateSoundBufferFromFile receives information about the format even though the method fails, making it possible for the application to warn the user after handling the error. Even if the method succeeds, the buffer is discarded because the application creates a new one after ascertaining the user's preferred virtualization algorithm. A DirectSound3DBuffer8 object is obtained from this buffer, and this object is used for controlling the 3-D parameters.