[sdiy] Wavetables
Matthew Smith
matt at smiffytech.com
Sat Jan 22 06:15:43 CET 2011
Hi Folks
In furtherance of my understanding of digital systems, I have decided to
construct a wavetable-based waveform generator. Whilst there is a
certain temptation to do the whole thing with an Atmel XMega ("fix it
all in software") which has a DAC on board and everything, building from
more discrete parts sounds more educational - and fun.
I'm still going to cheat by using an 8-bit DAC rather than building that
side by hand, but the general scheme is a series of flipflops providing
address stepping from an incoming square wave selecting locations from
an EPROM or E2PROM (probably use the latter as easier to erase)
hard-wired to permanent read, data lines feeding the DAC.
I'm going to do the square wave source as a separate module to make this
more versatile - this I *will* be doing with a microcontroller, probably
an ATTINY2313, since I have a few kicking around and I'm familiar with
them. MIDI comes in to the UART, note on starts a timer set up as a
square wave generator running at n.f where f is the not frequency from a
lookup table and n is the number of samples that make up a cycle in the
prom data.
Will use a couple of pins on the microcontroller to provide gate and
trigger signals. (If I use a device with an onboard ADC, I might even
provide for frequency modulation of the square wave - or possibly do
this digitally, signalling by SPI or I2C.)
Now, this raises questions:
1) The actual sampling issue is where I get out of my depth. (My math
ain't good. Really ain't good.) Assuming that I need to cover the
(slightly limited*) frequency range provided by MIDI note numbers, the
system needs to be able to produce waveforms from 27.5Hz to 4186Hz. As
the waveform being output is actually a set of steps, as far as I can
see, the quality of the waveform will get WORSE as frequency DECREASES
(even with a capacitor on the output of the DAC.)
So, taking 27.5Hz as the worst-case scenario, what is a sensible number
of samples per cycle required to produce a reasonable quality
sine/triangle/sawtooth waveform? (Being the value of n I mentioned a
paragraph or three back.)
2) I know how to create sine tables (surprise, surprise) but what are
the corresponding formulae for creating tables of triangle and sawtooth
values? Is this just plain trigonometry, where you're dealing with a
right-angled triangle? (What I really can't figure is whether these
waveforms are always above the line, or whether they have a negative
component because the line is actually half-way up the waveform.)
3) This is just laziness but also for the prevention of transcription
errors: does anyone have a machine-readable file of MIDI notes to frequency?
Cheers
M
* Limited if you're into pipe organs.
--
Matthew Smith
Smiffytech - Technology Consulting & Web Application Development
Business: http://www.smiffytech.com/
Blog/personal: http://www.smiffysplace.com/
LinkedIn: http://www.linkedin.com/in/smiffy
Skype: msmiffy
Twitter: @smiffy
More information about the Synth-diy
mailing list