Play a Scale
In this lesson, we will learn about how to automatically generate various pitches. We will see that the spacing between lower pitches is different from the spacing between higher pitches.
Here is a program that plays a scale of notes from a starting frequency of 30 hertz to an upper frequency of around 10,000 hertz. Note that
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
New Frequency Spacing
When you run the prior example, note the frequencies printed to the console. Are they evenly spaced?
Take a close look at the line that creates a new frequency:
1 |
|
The effect of this line is to create a new frequency that is 10% higher than the prior frequency.
Experiments
- What happens if you change the frequency update to be
freq = freq +100