ELM Home Page

Wavetable Melody Generator

Jan 17, 2006


Tiny45

This is a music generator circuit that will be the most popular teaching matter for electronics handicrafts. In this project, I tried to apply Wavetable Method to simulate a mechanical music box exactly; as a result, I could achieve to ganarate a sound like music box.

Wavetable Synthesizer

The wavetable synthesizer synthesizes a sound with pre-sampled (pre-synthesized) waveform. This is a method that have established at dawn of digital synthesizer. MOD Sound on AMIGA is the first time that wavetable synthesizer was realized on the PC if my memory serves. Ofcourse the wavetable synthesizer is embedded as a sound driver into recent PCs. The theory of wavetable synthesizer is very simple and its processor load is relatively low. However, it requires large amount of memory because there are wavetable data for source of sound. Therefore, following technics are applied to existing wavetable synthesizer.

  1. Not reserve wavetables for each tone. It can also synthesize any tone with a wavetable with changing play back speed.
  2. Not reserve all part of wavetable. Monotonous part can be replaced with a loop.
  3. Decaying waveform can be simulated in envelope genarotor.

Software

How Wavetable Synthesizer Works

Wavetable Synthesizer
Wavetable Synth
Reading a Wavetable
Wavetable

Because the sound of music box is relatively simple, it is easy to simulate with cheap microcontroller. The attack part, instant the comb tooth picked, changes its waveform drastically and it has many overtones. The susutain part is a monotone with slow decay. Release part is not needed. The wavetable can be divided in two part, attack and sustain. The sustain part is read in wrap arownd to reduce memory space.

When note is on, tone register (ω), read pointer (φ) and envelope generator will be initialized. The read pointer is increased by tone register every sampling time, so that generated tone can be determined by value of tone register at will. This is the same principle of DDS. When look up any value from wavetable, interpolation with fractional part of read pointer is effective to eliminate aliasing error but not implemented to this project. The envelope generator makes decay sound with changing wave amplitude slowly.

Implementation of Wavetable Synthesizer

Processing Diagram
Processing Diagram

To simulate sound of the music box, it can generating a chord tone is the most impotant term. Thus several number of wavetable synthesizer channels must be implimented. The number of sound channels affects load of the processor, increasing number of channels decreases sampling frequency and it results loss of the sound clarity. Therefore these terms must be weigh in balance. I decided that it is 6 channels in 32 ksps.

The foreground process reads a score and start note with each wavetable synthesizer channels in sequence. The synthesizer channels are driven in background process (32 kHz timer interrupt) and the outputs are mixed, clipped and fed to PWM modulator. Because number of channles is small, when a number of notes are on at a time, old notes are overwritten and canceled by new one. It some times stand out that especially low key notes, they decay slowly, are canceled.

I cound to implement these processes into an Atmel ATtiny45 with success. The ATtiny45 has internal 16 MHz PLL oscillator, 4KB ROM and 250 kHz fast PWM, and it does not require any external component. The processor load ratio for wavetable sinthesizer reaches over 80 percent. When use ATmega series AVRs which have hardware multiplyer, number of synthesizer channels or synthesizing accuracy will able to be increased easy.

Hardware

There is nothing to explain. The fuse setting is found in circuit diagram, and write program code will do.

Sign