V22.0201 (sec. 1) - Computer Systems Organization (Honors)

Assignment 5

Write a program to interpret a piece of music written in (a subset of) the abc musical notation language and play the music over your PC's speaker.  This program should be written in a combination of C (not C++) and assembly language.  How much of it is written in C and how much in assembly language is up to you, but the solution must include some assembly language code.

The abc language permits the representation of a single line of music by a sequence of ASCII characters.  The letters CDEFGAB represent the octave starting at middle-C;  the letters cdefgab the octave above it.   A ',' after a letter indicates that the note should be played one octave lower;  a ' after a letter, that it should be played one octave higher.  Together this allows for all notes in a 4-octave range.  A sharp is represented by a '^' before a letter;  a flat by '_' before a letter. Accidentals (sharps and flats) are to be interpreted as in musial notation:  they apply to subsequent instances of the same note in the same measure.  More information about the musical scale is available here.

Rhythm:  There is a default note length, t;  unmodified letters are played this length.  A letter can be followed by an integer, n ("C2");  this indicates that the note is to be played for length n*t.  The letter can also be followed by "/m" ("C/2") to indicate that it is to be played for length t/m, or by "n/m" to indicate that it is to be played for length t*n/m.  A rest is indicated by the letter 'z', which can be modified in the same way.  The sequence x>y indicates a dotted pair, which is equivalent to x3/2 y1/2.

The notes may be separated by blanks and by '|' to indicate the division into measures (these do not affect the music to be played).

A sequence of measures enclosed in  |:  :| are to be repeated once.  Just ':|' indicates to repeat everything from the beginning.

The Star-Spangled Banner in this notation is

 A>^F|D2 ^F2 A2|d4    ^f>e|d2 ^F2 ^G2|A4    A2  |^f3 e d2|^c4 B^c |d2 d2  A2 |^F2 D2:|
^f>^f|^f2 g2 a2|a4    g>^f|e2 ^f2  g2|g4    g2  |^f3 e d2|^c4 B>^c|d2 ^F2 ^G2|A4 A2  |
      d2 d2 d^c|B2 B2 B2  |e2 g^f  ed|d2 ^c2 A>A|d3 e ^fg|a4 d>e  |^f3  g  e2|d6    ||

The music can (indeed, in standard abc language, must) be preceded by a set of information fields of the form letter:value, one per line..  Important fields include

In standard notation, the tune immediately follows the K:key line.

This assignment is due on November 26th and is worth 15 points.  For full credit, you should implement all the features described above, except for the information fields, and should generate an error message for any input that is invalid (or, more precisely, that you cannot handle).  The program, when run, should read a file 'music.txt' and play the music therein.  If you also implement the K and Q information fields (for the major keys), you get one more point.  As usual, there is a penalty of 1/2 point for each day late.

Email your assignment to the grader.  Include your name and "Asgn 5" in the subject line.