[sdiy] Wavetable Design Update

Dave Manley dlmanley at sonic.net
Wed Feb 2 09:24:39 CET 2011


On 2/2/2011 12:08 AM, Matthew Smith wrote:
> 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.

Probably the prescale values only change at certain break points?  Then you'd need
one 12-entry LUT per prescale.  It might require a base value per prescale along
with the LUT value divided by the correct power of 2.

Off to look up the details about OCR1A and TCCR1B...

-Dave



More information about the Synth-diy mailing list