Changing the pitch of a sound is slightly more complicated than changing its volume. The most basic way to modify the pitch of a sound (although the speed of the sound is also affected) is to control how fast we advance the position value.
So far, we have used a position
variable that was an integer, and incremented its value by a full unit every time. In order to provide pitch control, we will change that variable to a floating point number, and add a pitch
variable that determines how much to increment the position.
By default, the pitch
variable will have a value of 1, which plays the sound at the normal pitch. A value of 2 will double the frequency of the sound, making it sound one octave higher, and a value of 0.5 will halve the frequency of the sound, making it sound one octave lower. For practical reasons, we will limit its value to the range between 0.25 (two octaves below the original sound) and 4 (two octaves above the original sound):
public: float GetPitch() const...