Game Development Reference
In-Depth Information
We will use these simpler flags in our example code. Now that we know about these
flags, we can use them to write the code that tests to see what the speaker config-
uration is. We will not use any of the flags from the first list, but rather we will just
check for certain speaker configurations using some of the flags from the second set
of flags listed previously. For example, an if statement checking to see if we have
a configuration with two output channels would look something like the following:
if (channelMask.HasFlag(Speakers.Stereo) ||
channelMask.HasFlag(Speakers.TwoPointOne)
||
channelMask.HasFlag(Speakers.Surround))
{
outputMatrix[0] = left;
outputMatrix[1] = 0.0f;
outputMatrix[2] = 0.0f;
outputMatrix[3] = right;
}
If this code is checking for a configuration using two speakers, why are we setting
four values here? The reason is because we have two channels of input. So for the
left speaker, we set a volume level for both channels. The index 0 in the array is set
to the value of our left variable. The index 1 of the array represents the volume
level of the right channel. Since we don't want the right channel to play out of the left
speaker at all, we set this to 0.0f . Likewise, the elements 2 and 3 are setting the
volume levels for the right speaker. We set element 2 to a value of 0.0f , since we
don't want the left channel sound to play out of the right speaker. And lastly, element
3 is set to our right variable. So, as you can see, for each speaker that will be out-
putting sound, we must set the volume levels for all of the channels that our sound
has.
You can find this sample code in the downloadable code for this chapter. This pan-
ning code is commented out though. Just uncomment it and play around with it.
Note that better sound configurations, such as 5.1 or 7.1, will use more elements of
this array, since they have more channels to set the volume levels for.
Search WWH ::




Custom Search