[sdiy] Wavetable Design Update
Matthew Smith
matt at smiffytech.com
Wed Feb 2 09:08:36 CET 2011
Quoth Dave Manley at 02/02/11 17:38...
...
> roughly:
>
> note number mod 12 -> note
> note number / 12 -> octave
>
> 12 entry look up table followed by divide/mult by power of 2 for octaves
Thanks for that. Unfortunately I've already cracked the MIDI note number
issue (got a bit of Perl to do the sums for me.)
My problem is that given a frequency f, I have to work out timer
configuration values which are:
* The number to count up to
* The prescaler value, if required.
...for a given CPU clock frequency. The frequency range I need to be
able to calculate is pretty massive - from 2093.00 Hz for MIDI note 0 up
to 3,211,226.61 Hz for MIDI note 127. Note a) this is to clock 256
samples per cycle, b) I'm working to 2 decimal places, so really working
in cHz.
So, whether I calculate on-the-fly or use a lookup table, I've somehow
got to find an algorithm to give me the OCR1A (timer count) and TCCR1B
(prescaler) values needed to set up the counter/timer to give me my
desired output frequency. Higher frequencies will need little/no
prescaling, whilst lower frequencies might require different prescale
values to get as close as possible to the target frequency.
I *could* just spend half a day working the whole lot out by hand (trial
an error on the prescale values) but it would be nice to have a means
whereby I can throw an arbitrary frequency at the device and have it all
calculated.
NOTE: The calculation needs to be done ONCE per note request, so I'm not
terribly worried about timing. However many clock cycles it takes to do
the math, I can't believe it will cause a sufficient delay before the
timer is set and the note starts to sound that anyone would notice.
Cheers
M
--
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