The note number from the note table is added to the duration above. Then each note can be entered using only one number which is decoded by your program. This is only one method of coding note values. You may be able to come up with one with which you are more comfortable. The formula used here for encoding a note is as follows:

1. The duration (number of 1/16ths of a measure) is multiplied by 8.
2. The result of step 1 is added to the octave you've chosen (0-7).
3. The result of step 2 is then multiplied by 16.
4. Add your note choice (0-11) to the result of the operation in step 3.

In other words:

((((D*8)+O)*16)+N)
Where D = duration, O = octave, and N = note

A silence is obtained by using the negative of the duration number (number of 1/16ths of a measure * 128).

### CONTROLLING MULTIPLE VOICES

Once you have gotten used to using more than one voice, you will find that the timing of the three voices needs to be coordinated. This is accomplished in this program by:

1. Divide each musical measure into 16 parts.
2. Store the events that occur in each 1/16th measure interval in three separate arrays.

The high and low frequency bytes are calculated by dividing the frequencies of the highest octave by two (lines 180 and 190). The waveform control byte is a start signal for beginning a note or continuing a note that is already playing. It is a stop signal to end a note. The waveform choice is made once for each voice in line 40.

Again, this is only one way to control multiple voices. You may come up with your own methods. However, you should now be able to take any piece of sheet music and figure out the notes for all three voices.

 This page has been created by Sami Rautiainen. Read the small print. Last updated February 10, 2002.