[sdiy] Wavetable Design Update
Scott Gravenhorst
music.maker at gte.net
Wed Feb 2 14:46:16 CET 2011
Tom Wiltshire <tom at electricdruid.net> wrote:
>
>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.
To be sure that is true - I use 17 bit wide table, your point induces me to go back and calculate
the number of cents of error. I don't hear an error in the high register, so I suspect it's <= 5
cents.
>> 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.
>
I hate divides too, the divide I use happens only once at note start, so while it contributes a
tiny bit of latency (25 MIPs MCU) that amounts to a few microseconds, it is not required during
oscillator operation. It was either that or a 128 location table for all possibe notes.
-- ScottG
________________________________________________________________________
-- Scott Gravenhorst
-- FPGA MIDI Synthesizer Information: home1.gte.net/res0658s/FPGA_synth/
-- FatMan: home1.gte.net/res0658s/fatman/
-- NonFatMan: home1.gte.net/res0658s/electronics/
-- When the going gets tough, the tough use the command line.
More information about the Synth-diy
mailing list