[sdiy] Wavetable Design Update
Tom Wiltshire
tom at electricdruid.net
Wed Feb 2 15:03:07 CET 2011
On 2 Feb 2011, at 12:36, Scott Gravenhorst wrote:
> Dave Manley <dlmanley at sonic.net> wrote:
>> On 2/1/2011 10:28 PM, Matthew Smith wrote:
>>
>>> * How to convert from my note numbers (these will be all the
>> MIDI-defined notes plus intermediate detune values) to the
>> prescaler/counter values to plug into AVR's onboard counter. I
>> would appear to > have two options: a lookup table (would not fit
>> in ATTINY2313 FLASH) or to calculate these at note-on. I'm
>> favouring the second approach for flexibility (would even allow
>> an actual frequency to be > specified rather than a note number)
>> but haven't the foggiest how to work out the algorithm required.
>>
>> 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
>
> I did what Dave described for my phase accumulator oscillator designs. What I
> learned, however, was the it is best to consider the 12 values for note to be the
> lowest pitches that will be produced and use the octave number to left shift. This
> ensures that octaves are true octaves. If one right shifts, significant bits get
> shifted into the bit bucket and notes that should be octaves will beat because the
> are not exactly 1/2 the frequency of the higher one.
How interesting to hear a justification for doing it the other way around!
So it looks like there's a tradeoff to be made between higher accuracy for the higher octaves (right shifting) or perfect, beat-free octaves (left-shifting). You choose, I guess.
> I chose to calculate the octave
> value in my MIDI microcontroller - which does not have a divide instruction - I did
> the division with a "subtract 12 many times" loop which was plenty fast enough. The
> divide loop provided both the octave number (quotient) and the note number
> (remainder). This method works very well for me.
Like I said, I hate division. Even the dsPIC which does have a divide instruction spends 17 cycles doing it. Best avoided if possible.
Tom
More information about the Synth-diy
mailing list