ORIGINAL CODE CALCULATED MANY FACTORS ON THE FLY
The program uses some floating point math to adjust all the note durations for a song, based on the particular pitch of the note and the tempo of the song. First, however, if the song data requested a shift, all the pitches are moved up or down by the number of steps in the file. Then while the program runs, it takes a pitch number for each note and uses it to look up a repetition count to achieve that frequency.
This may make sense when the program can access a number of songs from disk, but with a demonstration program on the demo monitor performing a single action, all that calculation is not required. Ultimately all the calculations produce two loop counts - an inner loop number that sets the pitch of the note and an outer loop count that issues the note for a number of eighth note durations. Therefore, I precalculate the loop counts and store those in the program.
SPREADSHEET USED TO CALCULATE AND CONVERT BEFORE CODING
I was able to perform the floating point calculations on a spreadsheet. As well, I do the shift of pitch and look up the pitch table to grab the inner loop count for each note. The floating point calculations generated an integer multiplication factor for the outer loop counter, which is multiplied by the count of eighth notes assigned for each note of the song.
The output was a simple table of constants for the inner loop count (note pitch) and a simple table of the outer loop count (note duration). A single integer holds the number of notes in the song. This makes the code itself very simple. It simply advances through the tables, setting the inner/outer loop counters and running through the loops for each of the song's notes.
REVIEWED THE FORTRAN GENERATED TO VERIFY TIMING
I compiled the Fortran program and stepped through its code to see exactly what instructions were used in the loops that produced the notes. Using the timing of the hardware as documented in the IBM Functional Characteristics manual, I figured out the time consumed for one loop pass, about 60 microseconds.
Then looking at the counter values that are used in the note pitch tables, I could validate that the total time doing the inner loop corresponds to the musical pitches in the table. Then, using the formulas in the program for converting the eighth note duration counts to outer loop counts, I verified that these numbers would last for appropriate times - 1/8th of a second, 1/4 of a second, and so forth.
Based on the timing, it should produce the songs as expected, but I don't have a machine to run this on right now to check what a radio picks up. I am confident enough to send this to SSM to try on their machine.
TWO DEMOS FINISHED BUT NOT TESTED
I coded up two demos, one plays the melody of Michelle, the other plays Love is Blue. These are pretty compact, so that I could produce more songs.
No comments:
Post a Comment