Music

 

Rather than develop sounds and music through trial and error (as other groups did in the digital lab) we decided to think about it to make it work.  We first referenced the Professor Landís page on generating music using the Mega32.  Using the prototype from class we set a Pin1 on PortD as the toggle for the Audio In on the Tee-Vee.  Pin1 is set between high and low at a frequency equivalent to an audio frequency in units of 63.625 usec. 

For example A4 is 440 Hz.  It has a ~2.2727 msec period.  Therefore there are ~36 units of 63.625 usec in 2.2727 msec of time.  So to produce an A4 tone in through the speaker on the Tee-Vee we toggle Pin1 high for 18 interrupt cycles and low for another 18.  Simple. 

In the music world tones are incrememnted in what is know as a "half-step".  One whole step is two half-steps, and one octave is 12 half steps.  The difference between C4 and C5 is an octave.  Also the higher note has twice the frequency as the lower note (in an octave).  Given this, X12 = 2 (remember 12 half-steps in an octave, 2x the frequency).  So x = ~1.0595, so a half step is 1.0595x the frequency of the half-step before it.  Here is a chart for easier explanation:

A4 = ~440 Hz

A5 = ~880 Hz

1.059512 = ~(880/440)

Deriving a list of Tones and their corresponding frequencies given in half-steps:

Tone (starting at 4th octave)

Frequency (Hz)

Periods of 63.625 usec in one period of the tone

C

260.4

60.4

C#

276.1

56.9

D

292.6

53.7

Eb

310.2

50.67

E

328.8

47.8

F

348.5

45.1

F#

369.4

42.5

G

391.6

40.1

G#

415.1

37.9

A

440

35.7

A#

466.4

33.7

B

494.4

31.8

C

524.0

30.0

We round the number of counts of 63.625 usec to hole numbers and divide by two.  This tells us how long (in interrupt counts) to set Pin1 high and then low to get a desired tone from the speaker through the Tee-Vee. 

For Connect4, we noticed that the little jingle could be

We are unsure of what key this is in, but as long as the relation between the half steps and whole steps remains the same it will sound very close to the original jingle nonetheless.