I ran across this recently:
...replicate the essentials of my earlier 8-bit experiments: a wave generator whose pitch is controlled by a function consisting of shifts and logical operators. The simplest waveform for /dev/dsp programs is sawtooth. A simple for(;;)putchar(t++)generates a sawtooth wave with a cycle length of 256 bytes, resulting in a frequency of 31.25 Hz when using the the default sample rate of 8000 Hz. The pitch can be changed with multiplication. t++*2 is an octave higher, t++*3 goes up by 7 semitones from there, t++*(t>>8) produces a rising sound. After a couple of trials, I came up with something that I wanted to share on an IRC channel:
from this site.
I gave it a go on my linux machine and was stunned, its pretty damned cool how so much structure can come out of a simple set of rules. After fiddling with it a bit I had a go at implementing it on an Arduino.
The basic code goes something like:
- Initialise an 8khz timer, this runs the code above on "t" and sticks it into the analog pins (where a speaker/headphone is connected)
- Initialise a 16bit timer for the analog pins
- Read the Pot level on analog pin 0 and set which algorithm to use for generation
Code is here if anyone wants to try it :)
Future plans are to write a small parser so I can write algorithms on the device itself using a wheel selector and LCD screen :)