To synthesize nice sounding musical notes you need to control spectral content of the note, the rise time (attack), fall time (decay), and the change in spectral content during attack and decay. Also it is nice to have at least two independent musical voices. And all of this has to be done using the modest arithmetic capability of an 8-bit microcontroller. We use Atmel atmega-series MCUs. The scheme used for the attack and decay envelope was to generate the product of two exponentials, a saturating rise exponential and an exponential decay. The process to convert this complicated sounding envelope into fixed point shifts and adds (and one integer multiply) will be covered below. The spectral content of the notes was enriched using FM modulation, which is widely used for musical and special effects. Since directly computing sine waveforms is also mathematically heavy, direct digital synthesis (DDS) was used to produce waveforms. The DDS scheme explained below is used to generate both the FM modulating sine wave signal and the fundamental sine wave for the musical note.
WINAVR GCC program. (Circuit Cellar version) For Markov music box running on atmega644 or atmega1284 at 16 MHz. Pin B.3 is the PWM output connected through a 10,000 radian/sec lowpass filter to amplified speakers. Port C is hooked to 8 pushbuttons which control transition matrix, tempo, beat pattern, and timbre for each voice.
Markov Music Box Examples and code:
Auto-Composing Piano, Chaorong Chen and Siyu Zhan
Tunes from students: Fur Elise:
Pitch Structure of Melodic Lines: An Interface between Physics and Perception, Jorge E. Useche
and Rafael G. Hurtado, http://palm.mindmodeling.org/cogsci2011/papers/08...