4
$\begingroup$

I am a bit confused with the concept of band limited wavetables and the methods such as BLET, BLIP, MinBLEP, polyBLEP etc.

As far as I understand certain waveforms contain infinite harmonics, which alias back into the signal, even if they were generated at a certain frequency below the Nyquist rate. According to this paper Alias-Free Digital Synthesis of Classic Analog Waveforms, these basic waveforms have aliasing "due to having to round off the discontinuity time to the nearest available sampling instant".

What and were is the discontinuity of the waveform if the wavetable contains e.g. a full cycle of a sawtooth wave at a certain frequency? (where looping the table will restart the new cycle from the last point of the old one)

After reading through some code on how MinBLEPs work, Im confused with how all these steps are linked. E.g. the signal is windowed and FFT'd and I assume the cepstrum function is used to look for the discontinuity inside the FFT bins. I dont get what the minimum phase is used for. The signal is then run through the iFFT.

I please need help in understanding how all these techniques are combined and what exactly is done in the practical sense.

After all of this, is the minBLEP a kind of wavelet that is stored in a buffer and then applied to the signal being generated, so that it smooths the discontinuities? At first I thought this was all done inside an oscillator which needs some level of look ahead to constantly detect discontinuities and apply the minBLEP wavelet at the correct time, but now I don't get how this is done inside the wavetable generator function itself (offline), that an oscillator can just scan in real time.

$\endgroup$

3 Answers 3

11
$\begingroup$

It looks like you are mixing up two techniques: MinBLEP and band-limited wavetables.

Band-limited wavetables

Let's assume you have a 256 sample long array with a waveform of interest - for example a naive sawtooth, with the first sample in your array at -1 and the last sample at 1.

To replay this data at a variable pitch, two techniques are possible:

First, you can control the rate at which the data is played. For example, to get a 440 Hz pitch, you replay the 256 samples verbatim, at a rate of 112640 Hz. This is possible with custom hardware, and is the technique used in early wavetable synthesizers (PPG Wave, Prophet VS). This requires one clock/DAC per oscillator, and is rather expensive!

Or you use a fixed sample-rate, and you modify the pitch by interpolation through the wavetable. Let's say the sample rate is 48kHz. Playing the data one sample after the other yields a tone with a frequency of $48000 / 256 = 187.5$ Hz. To play a tone at 440Hz, you would need to play the data at $440 / (48000 / 256)=2.35$ its original rate, and that's where you get into trouble. Two ways of understanding why:

  • You can consider the discontinuity. You'll reach the end of the table and "wrap around" between the 109th and 110th sample. So the discontinuity should actually be located between these samples.

  • Or you can think in terms of frequency content: by playing the data at 2.35 its original rate, any harmonic it contains at a frequency above nyquist / 2.35 will be aliased.

There are two ways of dealing with the problem. A first approach is to use band-limited interpolation, which is a way of replaying the data in such a way that aliased components are filtered. Another solution is to pre-compute several variants of your waveform in which the highest harmonics are progressively filtered. For example, when you have to playback the data at twice its original rate, you use a different sawtooth wavetable in which all harmonics above nyquist/4 are filtered-out. Obviously, you can't have a table ready for every possible playback rate, so a common solution is to pre-compute a dozen of such tables (for example one per octave), and interpolate between them. Korg did that on their DW series, I used it on my DIY AVR-based synths.

There are different ways of building such a band-limited table. You can work by additive synthesis (adding the right number of harmonics), or try to derive the band-limited waveforms by operations on a band-limited impulse (sinc waveform).

minBlep

This technique is completely unrelated to wavetable synthesis. The idea is to precompute a table containing a band-limited and causal step waveform. This computation is done once and for all, and involves an FFT/IFFT - that's probably where you encountered these operations, which are used only at this offline step. The code you link to in your question only covers this step!

Then, in real-time, you generate the naive waveform, and whenever there is a discontinuity in the waveform, you add, over the next 40 samples or so, samples from the band-limited step table to smooth the edge. Which samples you need to add from the minBlep table are determined by the fractional sample at which the discontinuity occurs. No look-ahead is involved: the point of minBLEP is that the correction is causal, so you don't have to start adding it before the discontinuity occurs.

Note that the computational cost of this method will increase as the frequency goes up, since the discontinuities will be more frequent - you'll have to keep track of an increasing number of overlapping corrections.

I wouldn't recommend minBLEP by the way. PolyBLEP uses a polynomial approximation of the band-limited step function and yields very good results. No lookup data is required and the code is easier to write because the correction only lasts for a handful of samples.

The two together?

It would be a strange idea to mix the two techniques together, but someone could use minBLEP offline to precompute a band-limited sawtooth for various band-limiting ratios. For example, a 256 sample-long naive sawtooth, then a 256 sample-long sawtooth with no harmonic above 0.25, then a 256 sample-long sawtooth with no harmonic above 0.125... And then one could use wavetable playback to replay them - selecting/crossfading one of these tables depending on the required playback rate. This would be a bit odd, there are simpler ways of building wavetables!

$\endgroup$
1
  • 1
    $\begingroup$ What an excellent answer - thank you. Do you have a link to your DIY AVR-based synths? $\endgroup$
    – donturner
    Aug 11, 2016 at 15:42
1
$\begingroup$

Saw has a discontinuity when it jumps from 1 to -1. It takes an infinite number of sine wave harmonics to do that, and you can only represent those up to half the sample rate. Once you get above half the sample rate…well, you can see what happens.

Imagine the camera can capture a rotation 1,000 times per second. If a wheel is rotating 499 times per second, 1/500 less than half a rotation: the same point on the wheel has almost gone halfway around. The shorter distance it's rotated is forward.

Now rotate the wheel 500 times per second: it goes halfway around, so every other frame is the same.

Now rotate the wheel 501 times per second.

Rotate the wheel backwards 499 times per second.

The last two place the wheel in the exact same position each frame. One of these is turning 499 times per second; the other is turning 499 times per second in the opposite direction. That or they're turning 501 times per second in opposite directions.

So if you try to record the wheel turning forwards or backwards 700 times per second at 1,000 frames per second, and you don't know which direction it's turning, it looks to be turning backwards at 300 rotations per second.

That's aliasing. Sine waves are literally a rotating wheel: if you stick a dot on the right side of the wheel, rotate it counter-clockwise at a fixed rate, and record on the X axis the fraction of a rotation the wheel has turned and on the Y axis the height of the dot, you get a sine wave. (The horizontal position is cosine.) Above half the sample rate, it starts looking like you're running the sine wave backwards, but below half the sample rate.

So, again, to go from +1 at one sample to -1 at exactly the next sample, you need to add up an infinite number of sine waves. At a finite sample rate. That's the discontinuity.

$\endgroup$
1
$\begingroup$

A guitar doesnt have the range of a piano. Both instruments are always very out of tune. A stretch tuned piano is up to 20 percent sharp in the top octave. At a sample rate of 88000 in the range of C2 to G5 are the integer round of the number of samples for the waveform in tune enough? What if you just built a pulse wav and restrict the range of the instrument? What if the user could move the pitch a sample up and down for any note they choose depending on the music? What would the ear actually percieve if you calculated a pulse train with a slightly different length each time? You could get to a round of .5 by having a length of 377 for one and 388 for the next one and back and forth. Has anyone tried this before I waste a lot of time :) pitch in samples https://www.wikiwand.com/en/Piano_tuning

$\endgroup$
1
  • $\begingroup$ that's a sorta odd sample rate. if it was 88200, i might understand the source. Shouldn't these wavetables for the different notes be resampled at a rate that makes the single-cycle period exactly an integer number of samples long? $\endgroup$ Feb 22 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.