Microsoft DirectX 8.1 (C++)

Basic Steps in Playing Sounds

If you understand the fundamentals outlined in Basic Concepts of DirectX Audio, you're ready to implement a rudimentary soundtrack in an application. After learning these few simple steps, you can go on to explore other parts of the API that will give you as much control over the soundtrack as you need.

This topic gives an overview of the necessary steps, without getting into the coding details. For sample code, see Tutorial 1: Playing Audio Files.

To produce a sound, an application needs to do the following:

1. Initialize COM

There are no helper functions for creating DirectMusic objects, so you need to call CoInitializeEx to initialize COM.

2. Create and initialize the performance

Most applications have a single performance object. You create it by calling CoCreateInstance and obtaining the IDirectMusicPerformance8 interface. Then call IDirectMusicPerformance8::InitAudio. This method can set up a default audiopath.

3. Create the loader

Using CoCreateInstance, obtain an IDirectMusicLoader8 interface. You need to do this only once, and you should keep the same loader object for the life of the application.

4. Load a segment

Call IDirectMusicLoader8::SetSearchDirectory so the loader can find the data files. Then call IDirectMusicLoader8::GetObject to load a segment from a file or resource and obtain its IDirectMusicSegment8 interface.

5. Download the band

Download DLS data to the synthesizer so that instruments can play. Wave files also must be downloaded. The simplest way to do this is by calling IDirectMusicSegment8::Download.

6. Play the segment

Pass the segment pointer to IDirectMusicPerformance8::PlaySegmentEx.

For a more detailed look at this process, see the following topics:

Note   It is also possible to play wave sounds using only the DirectSound interfaces. However, doing so requires you to parse the data source yourself and handle the streaming of data to buffers. For more information, see Wave Playback in DirectSound.