Programming for high-performance applications and games requires efficient and dynamic sound production. Microsoft provides two methods for achieving this: MIDI streams and DirectSound. MIDI streams are actually part of the Windows 95 multimedia API. They provide the ability to time stamp MIDI messages and send a buffer of these messages to the system, which can then efficiently integrate them with its processes. For more information about MIDI streams, see the documentation included with the Microsoft Win32® Software Development Kit (SDK).
DirectSound implements a new model for playing digitally recorded sound samples and mixing sample sources. As with other object classes in the DirectX 3 SDK, DirectSound uses the hardware to its greatest advantage whenever possible, and it emulates hardware features in software when the feature is not present in hardware. You can query hardware capabilities at run time to determine the best solution for any given personal computer configuration.
DirectSound is built on the IDirectSound and IDirectSoundBuffer COM-based interfaces, and it is extensible to other interfaces. For more information about COM concepts that you should understand to create applications with the DirectX 3 SDK, see The Component Object Model.
The DirectSound object represents the sound card and its various attributes. An application creates the DirectSoundBuffer object by using the DirectSound object's IDirectSound::CreateSoundBuffer method. The DirectSoundBuffer object represents a buffer containing sound data. Several DirectSoundBuffer objects can exist and be mixed together in the primary DirectSoundBuffer object. DirectSound buffers are used to start, stop, and pause sound playback, as well as to set attributes such as frequency, format, and so on.
Depending on the card type, DirectSound buffers can exist in hardware as onboard RAM, wave-table memory, a direct memory access (DMA) channel, or a virtual buffer (for an I/O port-based audio card). Where there is no hardware implementation of a DirectSound buffer, it is emulated in system memory.
The primary sound buffer is typically used to mix sound from secondary sound buffers, but it can be accessed directly for custom mixing or other specialized activities. (Use caution in locking the primary buffer, because it blocks all access to the sound hardware from other sources.)
The secondary buffers can store common sounds played throughout an application, such as in a game. The application can play a sound stored in a secondary buffer as a single event or as a looping sound that plays repeatedly.
Secondary buffers can also play sounds that are larger than the available sound-buffer memory. When the secondary buffer is used to play a sound that is larger than the sound-buffer memory, the secondary buffer serves as a queue that stores the portions of the sound about to be played.