DirectSound on the MicDirectSound is composed of a number of components or interfaces, just like DirectDraw. However, this is a book on game programming, so we only have time to look at |the most important ones. Hence, I won't be discussing the 3D sound component, DirectSound3D, or the sound capturing interface, DirectSoundCapture. I'm going to focus on the primary interfaces of DirectSound and that's it. Believe me, that's enough to keep you busy. Figure 10.7 illustrates the relationship of DirectSound to the rest of the Windows subsystems. Notice that it is very similar to DirectDraw. However, DirectSound has a really cool feature that DirectDraw doesn't—if you don't have a DirectSound driver for your sound card, DirectSound will still work, but it will use emulation and the Windows DDI instead. So as long as you ship your product with the DirectSound .DLLs, your code will work even if the user doesn't have DirectSound drivers for his card. It won't be as fast, but it will still work. This is very cool. Figure 10.7. DirectSound's place in Windows.DirectSound has two components as far as we are concerned:
To create a DirectSound application, all you need to do is include these files in your application and everything should be fine. To use DirectSound, you must create a DirectSound COM object and then request the various interfaces from the main object. Figure 10.8 illustrates the main interfaces of DirectSound:
Figure 10.8. The interfaces of DirectSound.To use DirectSound, you first create the main DirectSound object, create one or more secondary sound buffers, load them with sounds, and then play any sound you want. DirectSound will take care of the details, such as mixing. So let's start with creating the main DirectSound object itself. NOTE Although with DirectX 8.0 there is a new DirectSound interface, IDirectSound8, basically Microsoft skipped versions 2, 3, 4, 5, 6, 7. However, it brings nothing to the table for us, so we are going to use the standard DirectSound interfaces that have been available since DirectX 3.0. |