A keyboard harmony CBI system can be implemented on a computer system that is interfaced with a MIDI keyboard. The keyboard will inform the computer each time a student has depressed or released a key and will send the computer the MIDI note number that of the key that was pressed. As Figure 5.10 below indicates, the octave of each key can be determined from the formula
Octave = INT (Note Number / 12) + 1
where INT represents the integer result of the division by 12. The pitch class of each key is given by the formula
PC = Note Number - ((INT (Note Number / 12)) * 12)
A note's pitch class is equivalent to the value of the remainder that results during the calculation of the note's octave value. Because keyboards follow a mod 12 organization, pitch class values fall in the range 0 to 11.
Figure 5.10. The octaves and pitch classes of note numbers.
Octave values may need to be adjusted to coordinate the output of a MIDI keyboard with a notational software package. By definition, the MIDI note number corresponding with middle C is 60. This value places middle C in octave 6. Some notation packages place it in octave 4. A simple subtraction adjusts the octave properly. Because each key transmits a unique note number, determining the octave and the pitch class that a key represents is simple.
When a computer listens to a student singing or playing an instrument, however, the task is more difficult. The computer first must determine the value of the pitch that is being produced. It then must convert the pitch value to its corresponding octave and pitch class values. Because pitches produced by singing and by many instruments are not limited to discrete values, several factors influence this conversion:
In my sight singing CAI curriculum, I use equal tempered tuning as a basis for calculating pitch class values. I consider notes that are more than a quarter tone sharp or flat to belong to a neighboring pitch class. Because software converts a pitch to its octave and pitch class values, the tunings and tolerances for any pitch class can readily be changed.
Table 5.1 shows the frequencies, in an equal-tempered tuning system, of the notes C to B in the first complete octave on the piano.
The frequency of the quarter tone between each of these notes also is shown. These quarter tone frequency values act as upper and lower boundaries for the notes between which they fall. The quarter tone below a note will be referred to as a note's lower quarter tone or LQT. The quarter tone above a note likewise will be called the upper quarter tone or UQT. Because each of the note entries shown in Table 5.1 corresponds with only one pitch class, the frequency values of the quarter tones act as the limits of mistuning that any pitch class can be allowed to have. For example, frequencies representing PC 0 include those satisfying the inequality
LQT (PC 0) <= Frequency Value < UQT (PC 0)
Obviously, UQT (PC 0) = LQT (PC 1), UQT (PC 6) = LQT (PC 7), and so forth. To avoid assigning a frequency to two pitch classes, the range of frequencies assigned to a pitch class includes the LQT but not the UQT. The table lists the frequency ranges that correspond with pitch classes in octave 1, but these values can be modified to calculate the pitch class of a note in any octave.
Because a tone's frequency is the result of the recurrence of some aspects of the tone's sound pressure pattern in a certain time span, a computer system usually just calculates the time that passes before the pattern recurs. This span of time is the tone's period value, which is the inverse of its frequency value (period = 1 / frequency). The pitch detection system discussed in Section 4 calculates a tone's period in microseconds.
It happens that the period value of the UQT (PC 11) is 15,737 usec. This value is nearly 16,384 usec., which is 214 usec. Having the smallest period value in an octave be a power of two would be a great convenience, since all other period values in that octave would be greater in value, but still would be less than the value of the next power of two. Knowing between which powers of two a period's value lies is equivalent to knowing in which octave a pitch is sounding.
If the period of each quarter tone value, measured in microseconds, is multiplies by 1.04101563, the resulting values for LQT (PC 0) to UQT (PC 11) fall in the range 32,765 to 16,382. These extreme values are adjusted respectively to 32,767 ($7FFF) and 16,384 ($4000). This adjustment is inconsequential, as it changes the lower frequency limit by .002 Hz and the upper limit by .005 Hz in this lowest octave. The binary values of the lower and upper limits are
32,767 0111 1111 1111 1111
16,384 0100 0000 0000 0000
Now these values and consequently all the values between them have their highest order "1" in the same bit position. Consequently, all the pitches in this octave can be represented by periods with the values 01xx xxxx xxxx xxxx, where x = 0 or x = 1.
The number of the octave in which a pitch lies may be determined by multiplying its period value in microseconds by 1.04101563 and then shifting the resulting value left until a "1" appears in the most significant (or sign) bit of the sixteen-bit computer word. The number of left shifts needed to place a "1" in the most significant bit position is the octave number of the pitch. In the octave shown in Table 5.1, one shift would place a "1" in the most significant bit position. These values lie in octave 1 of the piano keyboard, as indicated. Two must be added to the octave value calculated in this fashion to represent its octave on a MIDI keyboard, since the lowest complete octave on the piano is in MIDI octave 3.
Multiplying a number by a value such as 1.04101563 might seem to be time consuming, even if an assembly language routine carries out the calculation. This multiplication is equivalent to the following expression:
Result = Period + (Period / 32) + Period / 128) + (Period / 512)
These "divisions," of course, are merely right shifts of the period value. This multiplication can quickly be accomplished either in assembly language or in a high-level language by carrying out the shifts and the additions.
Once the octave of a pitch is known, its pitch class can be determined by calculating between which two quarter tone values it lies. This is done simply by comparing the adjusted period value with each of the values in the rightmost column of Table 5.1. For each pitch class, x, the inequality
LQT (PC x) <= Adjusted Period < UQT (PC x)
is tested until an x is found that satisfies the inequality. Only values for octave 1 are needed in the table because period values in all octaves must be shifted left in the process of calculating their octave. Actually, shifted values are one bit position to the left of the values in the table when the octave is found. Shifting the adjusted period value back one bit position to the right effectively places all period values in octave 1.
If you feel that quarter tones limits for a pitch class are too wide, you can adjust the table entries, or even the organization of the table, to suit your needs. Since the calculation of pitch class does not destroy the period value, you might also wish to use the period to calculate how many cents the performed pitch is away from the expected pitch. Such information would help a student in intonation drills.
[ Index | Previous Paragraph | Next Paragraph ]