Game Development Reference
In-Depth Information
DirectSound
We will add some simple sound to the 2D world we made in the previous chapter. So,
open Visual Studio and let's get started!
Note
Before we get started, it should be noted that the music track we are using in
blog
(
WrathGames Studio
). So, a big thanks goes out to them.
This sound file is, of course, included in the downloadable code for this chapter.
Open the
TileGameWindow.cs
file. First of all, we need to add the following
using
statements to the top of the file so that we can use DirectSound:
using SlimDX.DirectSound;
using SlimDX.Multimedia;
Now, we need to add some new member variables to this class. The first one we will
add is a Boolean variable named
m_UseDirectSound
. This variable can be set to
either
true
, or
false
. When it is set to
true
, the program will use DirectSound, but
if this variable is set to
false
, the program will use XAudio2. The following is the de-
claration of this variable:
bool m_UseDirectSound = true;
Next, we need to create three more member variables that will hold our
Direc-
tSound
objects. They are as follows:
DirectSound m_DirectSound;
PrimarySoundBuffer m_DSoundPrimaryBuffer;
SecondarySoundBuffer m_DSoundBuffer;