Step 1: Set Up the Audio System
The sample application declares the following object variables:
Private dx As New DirectX8
Private dml As DirectMusicLoader8
Private dmp As DirectMusicPerformance8
Private seg As DirectMusicSegment8
The only one of these objects that can be initialized during declaration is the DirectX8 object. DirectMusicLoader8 and DirectMusicPerformance8 must be created by using methods of this object, as follows:
Set dml = dx.DirectMusicLoaderCreate
Set dmp = dx.DirectMusicPerformanceCreate
After the performance has been created, it must be initialized. The DirectMusicPerformance8.InitAudio method performs the following tasks:
- Creates a DirectSound8 object. In most cases you don't need a variable for this object, and you can pass Nothing as the DirectSound parameter, or omit it.
- Associates an application window with the DirectSound object. Normally, the handle of the main application window is passed as the hwnd parameter.
- Sets up a default audiopath of a standard type. The tutorial requests a path of type DMUS_APATH_SHARED_STEREOPLUSREVERB, which is suitable for music.
- Allocates a number of performance channels to the audiopath. Wave files require only a single performance channel, and MIDI files require up to 16. Segments created in DirectMusic Producer might need more. No harm is done by asking for extra channels.
- Specifies capabilities and resources of the synthesizer. This can be done in one of two ways: by setting flags or by supplying more detailed information in the DMUS_AUDIOPARAMS type. Most applications set the DMUS_AUDIOF_ALL flag and let DirectMusic create the synthesizer with default parameters. A DMUS_AUDIOPARAMS type still has to be passed to the method, but it can be left blank, as in the DMUS_AUDIOPARAMS typesample.
In the sample application, the call to InitAudio is very simple:
dmp.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmA, Nothing, _
DMUS_APATH_SHARED_STEREOPLUSREVERB, 64
Next: Step 2: Load a File