Improving the sound engine with Mozzi
The bit-banging technique is very cheap and it's nice to learn how it works. However, I can quote some annoying things here:
No pure sound: Square waves are a sum of all odd harmonics at the fundamental frequency
No amplitude control available: Each note sounds at the same volume
We are going to use a very nice library called Mozzi, by Tim Barrass. The official website is directly hosted on GitHub at http://sensorium.github.com/Mozzi/. It includes the TimerOne
library, a very fast timer handler.
Mozzi provides a very nice 16,384 kHz, 8-bit audio output. There is also a nice basic audio toolkit containing oscillators, samples, lines and envelopes, and filtering too.
Everything is available without external hardware and by only using two pins of the Arduino.
We are going to design a small sound engine based on it.
Setting up a circuit and Mozzi library
Setting up the circuit is easy; it is the same as the latest one except that pin 9 has to be used.
Mozzi's documentation...