Game Development Reference
In-Depth Information
altering the value of the SourceVoice object's FrequencyRatio property. A ratio
of 1:1 means that there is no pitch change. This is the default value for this property.
The valid range of values is 1/1,024 to 1,024/1 . At a ratio of 1:1,024 the sound's
pitch is lowered by 10 octaves. On the other hand, a ratio of 1,024:1 will raise the
pitch of the sound by 10 octaves. This property is of the type float , so you would
have to calculate the ratio and pass it in. So if you want to pass in the ratio 1:1, this
property would be set to a value of 1 since one divided by one is one.
To put this in context, the default ratio has a value of 1 as we just said. A value of
2 will double the frequency of the sound and will increase its pitch by one octave. A
ratio of 0.5 will cut the frequency in half, making the track take twice as long to play
and lowering its pitch by one octave. So for example, if you want to make a sound
play at three times its normal speed, you would set the FrequencyRatio property
to a value of 3 .
Note
Each time you halve the frequency of the sound, you lower its pitch by one
octave, and likewise, each time you double the frequency, you increase the pitch
by one octave.
Pan control
Panning is a bit more complicated in XAudio2 than it is in DirectSound. There are a
number of steps we must take to pan in XAudio2. The first step is to create an output
matrix . A matrix is simply a two-dimensional table of numbers. This simply contains
the calculated panning values for each channel. We create the array as follows:
float[] outputMatrix = new float[8];
We created this array with eight elements, so that it can support speaker configura-
tions up to 7.1. For simplicity, our sample code here will simply be for stereo output.
Next, we need to calculate or set the values for the left- and right-side speakers. So,
in this case, we will create two more variables to hold these values.
Search WWH ::




Custom Search