Microsoft DirectX 8.1 (C++) |
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:
There are no helper functions for creating DirectMusic objects, so you need to call CoInitializeEx to initialize COM.
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.
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.
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.
Download
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.