Microsoft DirectX 8.1 (C++) |
The DirectSound object represents a device and is used to manage that device and create sound buffers.
Multiple applications can create DirectSound objects for the same sound device. When the input focus changes between applications, the audio output automatically switches from one application's streams to the other's. As a result, applications do not have to repeatedly play and stop their buffers when the input focus changes.
The DirectSound buffer object represents a buffer containing sound data. Buffer objects are used to start, stop, and pause sound playback, as well as to set attributes such as frequency and format.
The primary buffer holds the audio that the listener will hear. Secondary sound buffers each contain a single sound or stream of audio. DirectSound automatically creates a primary buffer, but it is the application's responsibility to create secondary buffers. When sounds in secondary buffers are played, DirectSound mixes them in the primary buffer and sends them to the output device. Only the available processing time limits the number of buffers that DirectSound can mix.
A short sound can be loaded into a buffer in its entirety and played at any time by a simple method call. Longer sounds have to be streamed. An application can ascertain when it is time to stream more data into the buffer, either by polling the position of the play cursor or by requesting notification when the play cursor reaches certain points.
It is your responsibility to put data in the correct format into the secondary sound buffers. DirectSound does not include methods for parsing a wave file or resource. However, there is code in the SDK sample applications that helps with this task.