# [music-dsp] Wavetable interpolation

Nigel Redmon earlevel at earlevel.com
Tue May 8 02:48:23 EDT 2012

Hi Stephen,

This is so funny. I just posted the first part of an article on wavetable oscillators a few days ago, and just editing the remainder. I used that exact example of ~440 Hz with a 100-sample wave table (coincidence, or did you happen upon it? lol). I used it in the rationale of why we need to interpolate in the first place.

More is answered in part 2 (done but I wanted to let it stew a day or so and final-edit it tomorrow).

Go with linear interpolation—just oversample the wavetable (at least 2x). By this I mean that if the highest harmonic in the table is, say, the 350th, the minimum table size would be double that and you probably want to use a power of two (1024); double that, at minimum, to 2048. In a nut shell, the fewer harmonics relative to the table capacity, the smoother the waveform is, and the more accurate linear interpolation is. (Plus it keeps you away from the frequency rolloff inherent in linear interpolation.)

Single precision floating point is plenty for the samples. That's 25 bits of precision.

Nigel

http://www.earlevel.com/main/2012/05/04/a-wavetable-oscillator—part-1/

On May 7, 2012, at 2:45 PM, ChordWizard Software wrote:
> Hi all,
>
> I am working on a new project using PortAudio and testing it with a waveform stored in a buffer. This could be generated myself (sine, square, sawtooth, etc) or a more complex waveform loaded from a file.
>
> I want to be able to render the waveform at different frequencies, but I can see that I will be limited by quantisation if I just play out the samples themselves.
>
> For example, to generate a 440 Hz tone with sample rate 44100, I need 100.2272727 samples.  This gets rounded to 100 samples, which then produces an actual tone of 441 Hz.
>
> So it looks like I will be needing to interpolate between the samples in the wavetable.  Can someone point me to some discussion or resources on this?
>
> Simple linear interpolation looks easy enough to achieve, but does it introduce an unacceptable level of distortion?  Is there a rule of thumb for minimum numer of samples per waveform to keep artifacts of this type undetectable?
>
> Also, as an aside, is it general practice to calculate sample values with doubles (8 bytes) or are floats (4 bytes) generally adequate?  I'm targeting CD-quality audio (shorts @ 2 bytes) so I'm not sure if the extra precision during calculations helps much.
>
> Regards,
>
> Stephen Clarke
> Managing Director
> ChordWizard Software Pty Ltd
> corporate at chordwizard.com
> http://www.chordwizard.com
> ph: (+61) 2 4960 9520
> fax: (+61) 2 4960 9580