Sorry for the double post.
Well, the Beep function is in terms of frequency and duration. Frequency is in terms of cycles per second, duration is in terms of milliseconds. (I goofed in my post; I changed the 200 to a 100 to speed up the tempo.)
Ok, here is some background about music. Musical pitch is determined by the frequency, or cycles per second, of a note. One cycle per second is also one Hertz, or Hz. You will usually see frequency values expressed in terms of Hz.
Musical instruments are tuned such that one of their notes is at an agreed-upon frequency; modern orchestras tune the A above middle C to 440 Hz. This is termed "A-440 tuning." Hypetia's E4 constant is analogous to this idea. If you changed the constant to 440 you would find that the whole piece sounded higher.
Next, notes that are an octave apart from one another are in a frequency ratio of 2 to 1. So, the A an octave higher than A-440 has a frequency of 880 Hz, while the one an octave lower is at 220 Hz. In western music, there are twelve equally-spaced notes in an octave. Each of these is called a "half tone", and a run of all twelve notes in succession is called a "chromatic scale." Hypetia's program expresses the notes of the chromatic scale in terms of ASCII letters, where the first note is a, the next is b, and so on. A chromatic scale, from the lowest note available to the one an octave higher, would be expressed by the string "abcdefghijklm", where m is the note an octave higher than a.
Now, let's break down the formula:
Code:
Frequency = E4 * 2 ^ ((Asc(Mid$(Frequencies, Note, 1)) - 96) / 12)
First, let's look at this:
Code:
Mid$(Frequencies, Note, 1
Inside the for next loop, this pulls the characters out of the Frequencies string variable one at a time. So, if Frequencies = "abcdefghijkl", it will pull out an a the first time through the loop, a b the next time, and so on. So, let's substitute an a in the code for the Mid$ formula:
Code:
Frequency = E4 * 2 ^ ((Asc("a")) - 96) / 12)
Note that asc("a") is 97. So this code boils down to
Code:
Frequency = E4 * 2 ^ (1/12)
Now, if there were a b in the original string, that would boil down to 2^(2/12), a c would be 2^(3/12) and so on. An l would be 2^(12/12), which of course equals 2. This means that l would multiply E4 by 2, and would therefore be an octave higher than the constant.
So, the number 96 in Hypetia's formula is because the ascii value for "a" is 97, and the number 12 is because there are 12 notes in a western musical scale.
As for duration, lowering the number 200 in the formula will speed up the tempo, raising it will slow down the tempo.
Bob
Bob