library for wavetable synthesis

I'm working on a monophonic synth and I'm looking for input on whether the next part will be helpful to others as a library.

Originally I was going to use the FrequencyTimer2 library to set up my interrupts and let it call a function I would write to look up the next sample in the wavetable and output that either through PWM or on a parallel DAC. Unfortunately, that library doesn't play nice with ATmega328 chips so I started looking at the Tone library.

Tone does work on the 328 chips and does some nice looking prescaler calculations to get the frequencies you want but it only does square waves. My plan now is to change the code in the tone library in one of 2 ways:

  • Option #1 is to update it to let you set a function for it to call at the specified frequency rather than toggle the output pin (this would make it just like FrequencyTimer2 but with better timer setup). To use this for wavetable synthesis your funciton would need to look up the next sample and output it. You would also need to divide your tone frequency by the number of samples in your table before setting the tone frequency.
  • Option #2 is to add parameters for output type (PWM or DAC) and the array of sample values for your waveform and have the library do all the rest for you including dividing the tone frequency you asked for by the number of samples in your wavetable.

I'm just wondering if either of these options would be useful for others. If not, I will probably shoot for option #2 as it seems cleaner from a code architecture perspective but #1 could be more reusable for other applications.

Maybe take a look at my PCM drum code, and just do the required changes to make it work in any way you want?

http://arduino.cc/forum/index.php/topic,53257.0.html

Wk

are you kidding me? this is EXACTLY what i hoped someone would do! the tone function is only square and is rather boring.
thanks for doing this!!

option 2 sounds easier....ease of use would be great