Game Development Reference
In-Depth Information
XAudio2
XAudio2 is, of course, newer and more powerful than DirectSound. We will add some
more code to the same file we've spent the first part of this chapter working on
(
TileGameWindow.cs
).
As usual, we first need to add some
using
statements at the top of the file, so that
we can use XAudio2.
using SlimDX.XAudio2;
Next, we will create some member variables to hold our
XAudio2
objects. This time
there are four of them.
XAudio2 m_XAudio2;
MasteringVoice m_MasteringVoice;
AudioBuffer m_AudioBuffer;
SourceVoice m_SourceVoice;
The first one,
m_XAudio2
, will hold our
XAudio2
object. The second one will hold
our
mastering voice
. In XAudio2, the
MasteringVoice
class is used to represent
the sound output device. The third variable is the buffer that we will store our sound
in. Lastly, we have a
SourceVoice
object. This is used to submit our audio data to
the
MasteringVoice
object for processing.
The next thing we should do is edit the
if
statement we added to the bottom of the
constructor earlier in this chapter. The following code needs to be changed:
if (m_UseDirectSound)
InitDirectSound();
The following change has to be made:
if (m_UseDirectSound)
InitDirectSound();