Game Development Reference
In-Depth Information
There is still one more little thing we need to take care of before we test our XAudio2
code. We need to add some new code into the managed section of our Dis-
pose(bool) method. We have four objects we need to dispose of, so the code
looks like the following:
// XAudio2 Stuff
if (m_SourceVoice != null)
m_SourceVoice.Dispose();
if (m_AudioBuffer != null)
m_AudioBuffer.Dispose();
if (m_MasteringVoice != null)
m_MasteringVoice.Dispose();
if (m_XAudio2 != null)
m_XAudio2.Dispose();
We are now ready to test our new code. If you run the program, the music will keep
looping until you close the program. You may also notice that unlike the DirectSound
demo, if the window loses focus, XAudio2 just keeps playing the sound.
As we could in DirectSound, we can of course change the volume of our sound, or
pan it in XAudio2. So how do we accomplish this?
Volume control
We can change the overall volume of our sound by changing the value of the
SourceVoice object's Volume property.Thevalueofthispropertyisafloatingpoint
amplitude multiplier in the range - 2 24 to 2 24 . With a value of 1.0f , there is no atten-
uation and no gain. A value of 0 results in silence. Negative values can be used to
invert the phase of the audio.
Frequency control
Adjusting the frequency of the sound is a bit different in XAudio2 than it is in Dir-
ectSound. In XAudio2, this is expressed as a frequency ratio. You can change it by
Search WWH ::




Custom Search