Random Music Box

Demonstration


Random Music Box - The funniest videos clips are here


Program Explanation

First off, we have to make some notes with the PIC. Because notes in the musical sense are linear, but in the physical sense, are exponential, the easiest way to translate between the two domains is with a lookup table. In other words, it would be very difficult for the PIC to compute frequencies (440, 256) from note indexes (A, C, B-flat).

However, we are not computing frequency, but time intervals. Each "oscillator" is controlled by a timer and a reset-index. Each loop of the main cycle, the timer is decremented by TMR0. If it reached zero, the output bit is flipped and the timer is reloaded with the reset-index. So we really need to compute the interval of a half-cycle.

Each "beat" (which is modulated by TMR1), an onbeat subroutine is called which determines the next notes the oscillators should play. The "melody" oscillator is updated every beat whereas the "chord" and "bass" oscillators are updated every bar, or 4 beats.

It is fairly easy to trace what happens when an oscillator index is updated. Through various parameters including the beat number, the progression index, the chord type (0=major or 1=minor), and the timer "random" values, notes from a chord progression are chosen. The chord progressions were derived from standard music theory and Wikipedia.


Files

Source Code
HEX File
Schematic - Scanned very poorly, sorry. I clarified all the text though.
Perl Script to generate the timing intervals for a given note.


Return to Projects

nerd[1<<8] at gmail dot com