Platform SDK: DirectX

Playback Overview

The DirectSoundBuffer 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 sound 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.

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 another's. As a result, applications do not have to repeatedly play and stop their buffers when the input focus changes.

[C++]

It is your responsibility to stream data in the correct format into the secondary sound buffers. DirectSound does not include methods for parsing a sound file or a wave resource. However, there is code in the accompanying sample applications that will help you with this task. For more information, see Using Wave Files and Reading Wave Data from a Resource.

In order to know when a streaming buffer is ready to receive new data, or when any buffer has stopped, an application can use the IDirectSoundNotify interface to set up notification positions. When the current play position reaches one of these positions, an event is signaled. Alternatively, an application can regularly poll the position of the play cursor.

[Visual Basic]

Short wave files and resources can be loaded directly into secondary buffers when the buffers are created. For longer files, it is your responsibility to parse the file and stream the data. For more information, see Using Wave Files and Reading Wave Data from a Resource.

In order to know when a streaming buffer is ready to receive new data, or when any buffer has stopped, an application can create events using the DirectX7.CreateEvent method and then call the DirectSoundBuffer.SetNotificationPositions method to set up notification positions. When the current play position matches one of these positions, an event is signaled. Alternatively, an application can regularly poll the current play position.

For more information on notification, see Play Buffer Notification