Sound Programming on the PC
Sound programming is one of those things that always gets put off until the end. Writing a sound system is difficult because not only do you have to understand sound and music, but you have to make sure the sound system works on every single sound card. Here lies the problem. In the past, most game programmers used a third-party sound library such as the Miles Sound System, Diamondware Sound Toolkit, or something similar. Each system has its pros and cons, but the biggest problem is price. A sound library that works for DOS and Windows can cost thousands of dollars.
You don't have to worry about DOS anymore, but you do have to worry about Windows. It's true that Windows has sound and multimedia support, but it was never designed to have the ultra-high performance needed for a real-time video game. Thankfully, DirectSound and DirectMusic solve all these problems and more. Not only are DirectSound and DirectMusic free, but they are extremely high performance, have support for a million different sound cards, and have extensions to do as little or as much as you need.
For example, DirectSound has 3D support under DirectSound3D, and DirectMusic can do a whole lot more than play MIDI files. DirectMusic is a new real-time music composing and playback technology based on DLS (Downloadable Sounds) data. This means that not only will music sound the same on every single sound card, but DirectMusic can create music on-the-fly for your game based on preprogrammed templates, motifs, and personalities that you supply. Getting DirectMusic's AI to compose for you takes a lot of work, but it may be worth it for games in which you want to change the mood based on the gameplay but don't want to compose 10-20 different versions of each song yourself. And of course in DirectX 8.0 there is a much tighter integration of DirectSound and DirectMusic under DirectX Audio. Before version 8.0, these two interfaces were semi-separate and communication between them was difficult to accomplish. With that in mind, let's learn a little about sound.