Wavetable oscillator implementation

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Urs wrote: Mon Aug 06, 2018 10:02 pm
A well known, very popular synth has 2 pre-calculated bandlimited wavetables per octave and just switches. Each wavetable is cleverly positioned so that end of bands and lowest possible aliasing meet at around 17kHz (when used at 44.1kHz). I have never seen anyone complain ever.

We let me be the first to complain. I always thought that plugin sounded like garbage, especially with anything involving pitch envelopes or legato.

Post

This is a great thread that I'd like to revive.
I was wondering what is the purpose of selecting a wavetable of size 2048 if you base your wavetables on sampling "simple" waveforms (squares saws, triangles), or rather waveforms which are cyclic within just one cycle (non-evolving sources, single-cycle-waveforms). If you sample at 44100Hz you dont get any benefits of larger wavetables anyway?
I'm planning on creating single-cycle waveforms sampled at 44100 at D3 which approximates to a wavetable size of 300 samples and then performing antialiasing/bandlimiting either by on-the-fly PTR (Polynomial Transition Regions) or FFT-bandlimit-iFFT.
But is that a dead-end?
------------
also known as Ambient Lifeforms and Orbital Resonance
http://www.ambientlifeforms.dk/

Post

If you do the math on the minimum length of a single cycle wavetable required at 20Hz (lower end of human hearing) to be able to represent harmonics up to 20kHz (upper end of undamaged human hearing), with regards to Nyquist, you end up with something around 2000 samples. So 2048 is just a convenient rounding up from that.

Post

cjohs wrote: Fri Jul 17, 2020 8:16 am I was wondering what is the purpose of selecting a wavetable of size 2048 if you base your wavetables on sampling "simple" waveforms (squares saws, triangles), or rather waveforms which are cyclic within just one cycle (non-evolving sources, single-cycle-waveforms)...
About to shut down for the night, this will be brief but maybe enough to get you started thinking about it.

Without going into the other stuff, there are two reasons for a larger wavetables: number of harmonics, and SNR (signal / noise ratio).

The table length determines how many harmonics you can fit, just as it does with the size of FFT. So, if you use a 512 sample table for a sawtooth, if you sweep the oscillator down from say 500 Hz to 20 Hz, you'll hear the lack of upper harmonics. 2048 is really the least you can have for a 20 Hz saw with harmonics through your hearing range. A much larger table would let you run it sub audio and still get a crisp "tick" each cycle. (I sometimes might use 4092 or 8196 for most tables, and add a 32k sub audio table, let's you sweep deep and still sound like a sawtooth. Or you can get more complicated and track a straight-segment oscillator for sub, better for use as an LFO.)

And the more samples you have, the better the SNR. (It all depends on interpolation, but for example's sake it's linear interpolation.) But remember, if you fill the wavetable with exactly one cycle, the second harmonic will be half as many sample (but repeated twice), etc. That means the high harmonics have pretty poor SNR if you you make just the minimum table from the previous paragraph. This may be acceptable, but it's a fact—for higher harmonics, you should consider they have effectively shorter "sine" tables.

Anyway, that's the short answer why 2048 or whatever—number of harmonics, and SNR. 2048 is not very good for the high harmonics with a low-audio fundamental, the upper harmonics are quite noisy—but the high harmonics are usually masked in that case, and switching in reduced-harmonic tables for higher frequencies also improves the SNR at the top.

PS—If the math isn’t obvious where 2048 comes from: 20 Hz as the bottom audio frequency, therefore harmonics are spaced 20 Hz apart. For all harmonics, say 20 kHz, that’s 1000 harmonics, or at least 800 for 16k. You need something more than two samples, worst case, and we want it a power of 2 for various binary conveniences. 2048 is the smallest power of 2 that will handle either case.
My audio DSP blog: earlevel.com

Post

earlevel wrote: Fri Jul 17, 2020 8:58 am Without going into the other stuff, there are two reasons for a larger wavetables: number of harmonics, and SNR (signal / noise ratio).
But... the harmonics are always at a higher frequency than the fundamental, so I thought they would be inherent in a single cycle with a tablesize based on the fundamental frequency... shouldn't they? :?

So if I up my tablesize to contain the single-cycle for instance 10 times (by sampling the same singlecyclewaveform at D3 and keeping 10 cycles in a 3000 samples wavetable) I will have a gain in both harmonic content and SNR ?

It is clear to me that a higher samplerate (for instance 88200Hz instead of 44100Hz) will get a higher number of harmonics ... but a larger wavetable...
------------
also known as Ambient Lifeforms and Orbital Resonance
http://www.ambientlifeforms.dk/

Post

earlevel wrote: Fri Jul 17, 2020 8:58 am The table length determines how many harmonics you can fit, just as it does with the size of FFT. So, if you use a 512 sample table for a sawtooth, if you sweep the oscillator down from say 500 Hz to 20 Hz, you'll hear the lack of upper harmonics. 2048 is really the least you can have for a 20 Hz saw with harmonics through your hearing range. A much larger table would let you run it sub audio and still get a crisp "tick" each cycle. (I sometimes might use 4092 or 8196 for most tables, and add a 32k sub audio table, let's you sweep deep and still sound like a sawtooth.
Ahhh so what you are saying is that I should actually sample the lowest possible frequency (lowest possible note) and use that as the base of my tablesize - so still a single-cycle-waveform.
That will (if the source material is good enough) enable higher number of harmonics and better SNR.
------------
also known as Ambient Lifeforms and Orbital Resonance
http://www.ambientlifeforms.dk/

Post

Worse than harmonics dropping out on the top end ("muffled sound") is the Gibbs effect. When the harmonics of rich waveforms suddenly break up at a frequency in the audible spectrum, the ringing becomes audible in itself and may even be more perceptible than the actual waveform. This happens often with wavetable based oscillators when you pitch them down towards 10Hz or below. The size of the wavetable then determines the frequency at which this becomes audible. With a size of 512 it already becomes audible in common bass notes.

Post

cjohs wrote: Fri Jul 17, 2020 10:11 amAhhh so what you are saying is that I should actually sample the lowest possible frequency (lowest possible note) and use that as the base of my tablesize - so still a single-cycle-waveform.
That will (if the source material is good enough) enable higher number of harmonics and better SNR.
Right...Sorry—first thing I thought when I woke up was I need to do a massive edit to my previous rambling comment, was tired and in a rush to get to bed. Let me try more succinctly...

OK, basic part is the number of harmonics—you want harmonics to sound unbounded (continue through the audio range if they would normally with the waveform—sawtooth for instance). The top frequency you want divided by the lowest, times 2(+) gives you the minimum table size, so 20-20k needs at least 2048.

Further, oversampling the tables (making them bigger) helps with the SNR for cheaper forms of interpolation. (See my sine table article I linked to previously for a discussion of that with linear interpolation. The worst case is the highest harmonic.)

And we usually use multiple tables to facilitate cheap interpolation, fewer harmonics as we go up. So for a constant table size, the effective oversampling goes up. By the time you get to the highest table, a sine wave fundamental, you're heavily oversampled at 2048. So, the worst case is the table with the most harmonics (the first/lowest table). Fortunately, there are other factors like masking and lower harmonic strength at the highest harmonics that help out on the apparent SNR for the low notes, so the oversampling you need might be a lot less than what you might calculate for good lerp SNR for the highest harmonic.

And what Urs said about Gibbs, that was what I was getting at with switching to a different method for sub-audio, such as a straight-segment LFO.

PS—Another rushed try, but I wanted to more clearly explain why this matters for lower forms of interpolation. After all, if we use truly high quality interpolation, like sinc interpolation, we need only one table and no oversampling.
My audio DSP blog: earlevel.com

Post

Urs wrote: Fri Jul 17, 2020 10:31 am Worse than harmonics dropping out on the top end ("muffled sound") is the Gibbs effect. When the harmonics of rich waveforms suddenly break up at a frequency in the audible spectrum, the ringing becomes audible in itself and may even be more perceptible than the actual waveform. This happens often with wavetable based oscillators when you pitch them down towards 10Hz or below. The size of the wavetable then determines the frequency at which this becomes audible. With a size of 512 it already becomes audible in common bass notes.
Also one should be careful about evaluating what is and isn't "audible" once you approach Nyquist. The high-frequency hearing varies a lot between individuals and it also gets worse as we age and you probably don't want to end up in a situation where it sounds fine to you, yet genuinely painful for someone younger with much better high-frequency hearing. Gentle roll-off might be "muffled" but it's always the safe approach.

Fortunately it's easy to use a FFT analyzer to see what's going on there and if there is anything "suspicious" then bring it down to a lower frequency and see if it sounds "good enough" or not. :)

Post

We used to have a tool which downsamples audio in realtime (with occasional skips obviously) because there's no denying we're a bunch of old farts by now.

Post

What is a common wavetable index update rate among popular synths? E.g. In case we have 256 wavetables and index is quickly modulated changing wavetable per sample will be very slow and hard to optimize.
giq

Post Reply

Return to “DSP and Plugin Development”