Microsoft DirectX 9.0

First Steps in DirectMusic Programming

This topic gives an overview of the basic steps required for setting up a DirectMusic performance and playing a file. For details, see Using DirectMusic. 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. To initialize COM, you must call CoInitializeEx.
  2. Create and initialize the performance. Most applications have a single performance object. Create the performance by calling CoCreateInstance, obtaining the IDirectMusicPerformance8 interface. Then call IDirectMusicPerformance8::InitAudio. This method can set up a default audiopath.
  3. Create the loader. Using CoCreateInstance, create a loader object and obtain an IDirectMusicLoader8 interface. You need to do this only once, and normally 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 instrument data to the synthesizer so that notes can be synthesized. WAV files must also be downloaded. The simplest way to download all instruments and waves is by calling IDirectMusicSegment8::Download.
  6. Play the segment. Pass the segment pointer to IDirectMusicPerformance8::PlaySegmentEx.