Microsoft DirectX 8.1 (Visual Basic)

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. Create and initialize the performance

Most applications have a single performance object. You create it by calling DirectX8.DirectMusicPerformanceCreate. Then call DirectMusicPerformance8.InitAudio. This method can set up a default audiopath.

2. Create the loader

Call DirectX8.DirectMusicLoaderCreate to obtain a DirectMusicLoader8 object. You need to do this only once, and you should keep the same loader object for the life of the application.

3. Load a segment

Call DirectMusicLoader8.SetSearchDirectory so the loader can find the data files. Then call DirectMusicLoader8.LoadSegment or DirectMusicLoader8.LoadSegmentFromResource to obtain a DirectMusicSegment8 object from a file or resource.

4. 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 DirectMusicSegment8.Download.

5. Play the segment

Pass the segment pointer to DirectMusicPerformance8.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.