Controlling the pitch is not as straightforward as controlling the volume. We already know that modifying the frequency of a sound, changes its pitch and the channel handle actually has a setFrequency()
method just for that:
channel->setFrequency(261.626f);
However, it does not work the way some of us might expect. For example, the middle C note on a piano has a frequency of approximately 261.626 Hz, so we might expect that setting the frequency to that value, would make the sound assume a pitch close to the middle C note, but this is not the case.
In order to understand this problem, let us first turn our attention to the getFrequency()
method. If we call this method on a channel with its original frequency, what we get in return is actually the sampling rate of the sound. This means that any frequency values that we set must be relative to this value, or in other words, that any values above the original sampling rate of the sound will increase its pitch, and vice...