[sdiy] Sound synthesis with microcontrollers
Jaroslaw Ziembicki
aon.912230836 at aon.at
Fri Jun 27 20:59:46 CEST 2003
----- Original Message -----
From: "Rainer Buchty" <buchty at cs.tum.edu>
To: "Jaroslaw Ziembicki" <aon.912230836 at aon.at>
Cc: <synth-diy at dropmix.xs4all.nl>
Sent: Friday, June 27, 2003 7:42 PM
Subject: Re: [sdiy] Sound synthesis with microcontrollers
> > Is there anybody who is interested in similar things?
>
> Definitely.
>
> Just for curiosity: How hard is the timing on your 1-voice AVR? Would it
> be able to still handle a MIDI stream sufficiently? Any chance to view the
> code?
>
> Rainer
>
>
Hi,
The timing is very good! The sound synthesis itself runs in timer interrupts
(period = 32µs) and takes about 90% of CPU power. MIDI messages
(note on/off, pitch bend, modulation) are being processed directly in the
UART
interrupt routine. The main loop cycle time is several hundred µs (here the
LFO,
the ADSR, and the phase increments for the oscillators are being calculated;
besides, 14 switches and 8 potentiometers from the front panel are being
read).
Of course there are some drawbacks of the device:
- the sampling frequency is only 31.25 kHz,
- some aliasing can be heard at frequencies above, say, 1 kHz,
- the filter is just a 1st order LPF, without resonance.
Anyway, it was a good exercise to build this unit. It works quite well and I
use it
as a bass synthesizer in my setup.
As to the source code. It was a hobby project, just for myself, and I have
written
all the comments in Polish - so I believe you would have problems to
understand
them... But I will explain the general idea.
I used the "direct frequency synthesis". This means: a three-byte
"fixed-point"
counter (it consists of integer and fractional parts) is being incremented
by a value
(again, fixed-point) which is proportional to the sound frequency. The
accuracy and
the resolution are excellent (0.00186 Hz). The integer part of the counter
is the
sawtooth waveform; by comparing it to the half-scale value I get the square
wave.
This is how one oscillator works - and I have two of them.
There is some aliasing because pure saw/square waves are being sampled
(I reduced it a bit by some simple trick).
The filter is the simplest low pass digital filter ever invented; the
formula is:
y[i] = y[i-1] + m*( x[i] - y[i-1] );
well, it should explain everything for those who have some knowledge of
DSP...
I used 16 bit shifts in order to multiply by m because the AT90S8535 has no
multiplier. The same I had to do in the "VCA" section.
For some weeks I've been playing with a ATmega163 (which has a multiplier);
I implemented a 2nd order low pass filter with resonance there, but it
doesn't run
properly at the moment.
Well, I hope you'll find useful what I wrote here...
Regards
Jarek
More information about the Synth-diy
mailing list