Waveshaping - Pt 1: Theory

Author: Snyxol (Alexander Eslava)

Waveshaping can be described as an extension of overdrive, which can be used to alter a sound from subtle to extreme using only a few parameters. This synthesis method provides sounds ranging from "distorted through the roof" to smooth, fluid or even more complex soundscapes. The most flexible shaper within the Wave 2/XT/XTk/pc is the waveshaper-filter. Closely related to this is the Sin>LP-filter. The mixer before the filter in the signal path is capable of distorting the audio-signal in a couple of ways also. Furthermore the Wave provides us with an overdrive in the effects section.

Although it is up to each sound craftsman to create his sounds by continually trying, trying, trying.... there are certain cases, in which the slightest alteration of parameters may lead to radical results and the waveshaper-filter is such a case. Thus being familiar with the behaviour of a waveshaper is essential while attempting to create particular kinds of sounds. So let's begin with the basics of waveshaping-synthesis and see what "mutilations" the shapers in the Wave can do to the waves.

This will require some math, but don't be intimidated! Its almost all high-school level!!

We will address detailed sound programming tips in the next workshop due to the size of this particular topic.

1) What is wave-shaping?!

A shaper is a function f(x), which depends on only one variable x[n]. x[n] is the n-th sample of a control or audio signal. Thus n is equivalent to the time, which in digital systems is quantisized by the sampling-rate.

Alternatively one can imagine a shaper as a table, which maps every input value x to an output value y=f(x).

Trivial special case: the linear* function f(x)=a*x with the constant a is an amplifier. It simply increases or decreases the volume of the signal without changing the sound itself. Only the non-linear functions deserve the title "shaper".

*linear: a function is linear exclusively while: 1. f(a*x) =a*f(x) ; a=const. 2. f(x+y)=f(x)+f(y) ...both expressions can be combined to f(a*x+b*y)=a*f(x)+b*f(y) ; a,b=const.

Non-linear functions applied on audio-signals result in a distortion of the wave, which changes it's spectrum in a very weird and very difficult to describe way. Some overtones may be added or amplified while others are dampend, like in a very complex filter. So may we speak of a shaper as a filter?! Nope!

Differences between a filter and a shaper:

Filter: only the spectrum of the input wave is relevant. The waveform has no direct influence on the sound color of the filter output. The phases of the harmonics might be deliberately shifted (which changes the waveform, not the sound). It changes the spectrum distinctly (side-effect: the waveform changes, of course).

Furthermore it is just linear*. Which means:

1. if the input-amplitude is changed by the factor a, then only the output-amplitude is changed by a, as well. The spectrum however remains the same.
2. It doesn't matter, whether two waves are first mixed and then filtered, or vice versa. One can't hear whether a sound contains one voice, in which two detuned sawtooth of equal amplitude are filtered, or two detuned voices in each of which only one sawtooth is filtered.

Waveshaper: only the waveform of the input wave is relevant. The spectrum of the input-wave has no direct influence on the sound color of the waveshaper output. Thus the phases of the harmonics must not be shifted freely, because this would bend the waveform itself and changing the tonal color. It distorts the waveform distinctly which is followed by a complex change of the spectrum most of the time.

In general a shaper-function is non-linear:

1. if the input-amplitude is changed, then also the waveform and thus the spectrum.

(exception: f(x)=x; f(a*x)=a*x. the wave x only changes it's amplitude while the form and the spectrum remain constant; this is generally valid for exponential functions)

2. it is a relevant difference whether two waves are first added or distorted. If the sum of two equal, detuned oscs is distorted, the result will be a periodic, wobbling changing of the sound, which may sound more or less earthy and strange, depending on the shaper-function. If a normal detune-hovering is required (as without distortion), there are two detuned voices to be used per note and one shaped osc per voice (or even both shaped, but not detuned).

While FM distorts a wave horizontally (in time), wave-shaping distorts it vertically.

If a shaper is placed immediately after an oscillator, the result is a new constant waveform with a new harmonic spectrum which can be deliberately filtered.

Even more fascinating is shaping placed after the filter. The most well-known type is probably the filter-overdrive, which enriches a muffled low-pass-filtered sound with new, even different harmonics and thus modifies it from warm and dark to crunchy and rough. This post-filter-distortion destroyes the prior work done by the LP-filter (dampening higher harmonics). The filter is mainly abused for changing the waveform of the oscillator. Eventhough a filter-sweep sounds very smooth and the spectrum morphs slowly, the filter modifies the output-wave quite heavily, even with slow cutoff frequency modulation and mainly at great resonance-values.

Since, as is well known, the shaper reacts on waveform-changes, the shaper-output morphs stunningly fast. The result is a wild, crazy and drastically changing sound.

Though there is snag: Aliasing. Even if the oscillator is band-limited (free of aliasing), the shaper function adds frequencies to the spectrum which are above half the sampling rate (Nyquist-frequency). Digital audio systems cannot handle those above-Nyquist-frequencies correctly, but mirrors their frequencies around half the sampling rate, which transforms those overtones into wrong ones ("alias" tones), sounding dissonant and metallic-like. This is not necessarily awful-sounding , its a matter of taste and sound category. E.g., aliasing can add a cool digital spice to aggressive distortion sounds.


a) Parabolic distortion: f(x)=x

All input-samples are squared. A sawtooth-wave e.g. is distorted to an overtone-poorer parabolic wave. (this can also be accomplished by Ringmodulation: multiply two sawtooth-waves of equal phases)

b) Exponentiator: f(x)=a*exp(b*x) with constants a,b

...is often used for controller-signals. Using this a synthesizer computes the frequency of it's oscillator deriving from the note-number. In general all logarithmically scaled parameters like volume, lfo-rate and envelope-times are transformed this way.

c) Hard-clipping: f(x)= {x, for |x|<1}

{+1, for x>+1}
{-1, for x<-1}

The signal x gets abruptly limited to the range of [-1;+1]. Dull waves are enriched with many harmonics. While using as filter-overdrive, the result sounds harsh scratching, works great for biting agressive sounds.

d) Soft-clipping / saturation: e.g. f(x)=(arctan x)/pi
f(x)=(sign x) *(1-0,25/(|x|+0,25)) (build up of hyperbolics)
f(x)=1-(x-1) , for 0<=x<1; |
f(x)=-1+(x+1) , for -1 f(x)=sign x , for |x|>=1 |

The signal x is smoothly limited to the range of [-1;+1]. Contrary to hard-clipping, the signal is not cut abruptly, but follows the smooth transition to the saturation value. This enriches dull sounds with more low and middle than with high harmonics. There are many possible functions for this same effect, but they all sound different.

Analog tapes creates a similar saturation-behaviour which provides a mix with a warm characteritic. (Because of this behviour many producers prefer to work with old tape decks rather than using digital epuipment.)

This effect is also suitable for filter-overdrive: decreasing amplification before saturation results in a warm, smooth grunge. Using extremely high pre-amplification ends up with a harshness equal to hard-clipping.

2)Mixer-Clipping: Overflow and Saturation

as described on page 46 in the manual.

The mixer of the oscillator section applies its own waveshaper (with 2 selectable functions) on the sum of the input signals (ringmod + noise + wave1 + wave2), limiting the output to the range [-M;+M], with:

M: maximal mixer output amplitude

(though the ROM and RAM waves are stored in only 8 bit resolution (quantizing to 256 steps), the output of each oscillator is a smooth interpolated 24 bit depth signal. the Motorola 56303 DSP inside the MW2 computes with 24 bit fixpoint numbers, providing 16.7 million equally big quantization steps.)

The "saturation" mode does hardclipping.

"Overflow" distortion mode: to samples of the mixer sum, which are in the forbidden range of x>+M OR x<-M, the values -2M or +2M, respectively, are added. This simulates the numeric overflow of the -Wave1 and PPG Wave. The harsh transitions generated by the overflow-clipping are equivalent to adding pulse-waves (with variable pulse width).
Another way to visualize overflow:
if the level of the mixer-sum is beyond legal range, some "magic" pulse-waves are mixed into it (see graphics). Those pulse wides can be well-directed adjusted by modulating the amplitudes of the mixer-input-sources.

Overflow function: f(x)= {x, for |x|<=M}
{x-2M, for +M {x+2M, for -3M<=x<-M}

(this formula is applicable only if wave1+2 and ringmod are chosen in the mixer. This way the sum never exceeds 3M. If noise or the external input is engaged as well, any sum-sample may overflow even two times.)

...always beware of overflow introducing heavy aliasing.

3) Sin(x)->LP-Filter

Here is a sine-shaper inserted after the mixer and BEFORE a 12dB-LP-filter. Because the mixer-output is always within the values of [-M ; +M], the definition range (possible x values) [-M ; +M] is sufficient for the shaping function. At increasing amplitude the input-signal first gets compressed softly at the upper and lower peaks. As the amplitude exceeds the M/2-threshold, peaks get wrapped towards the zero axis.

Sinus-Shaper: f(x) = M * sin (p /M * x), -M <= x <= +M

example: 2 waves of increasing amplitude becoming more and more squeezed:

By combining Sin->LP-filter and overflow-mixer-ditortion, the overflow-jumps will be eliminated totally because the signal values -M and +M are bent to zero. The resulting distortion can sound even smoother than engaging saturation type mixer-clipping.

4) Waveshaper Filter

First of all and contrary to the Sin(x)->LP-filter, the Shaper is routed AFTER the 12dB-LP-filter. This routing provides grungy filter-overdrive and much more crazier sounds. Further one can choose an arbitrary wave out of the current wavetable to define the shaping function. I refer to this wave as "shaper-wave". (dont mess it up with the wave that GETS shaped!) It is exactly this feature that makes the waveshaper a very flexible distorter, gifted far beyond common hard/soft overdrive like that found in many other analog/ v.a. synthesizers.

Fast filter-sweeps at high resonance create hard, weird, dirty and often screaming distortion. (reasons: see section 1)

Softer and less agressive sweeps are achievable by very, very slow filter-sweeps and low cutoff, or even without any filtering while slowly modulating only ones or boths oscillator's amplitudes (not detuned) in the mixer.

Now what does the distortion-function f(x) look like, that is defined by a particular shaper-wave?

Briefly: its the same as the shaper-wave itself from 90 to 270 (samples 32...97), but interpolated linearly.

Specifically: the output level of the filter itself is limited to 2M (twice the mixer-output), no matter how high the resonance is cranked up. Thus the definition range (allowed input values) of the shaper-function has to be [-2M ; +2M]. Output-values produced by the shaper roam within these borders as well.

A wave-cycle is always made of 128 samples. Mostly the wave reveals an odd symmetry: the first half is fetched from ROM/RAM, the second is it's mirror-image on the point (64,5 ; 0). Formally:

Wave[65 + n] = -Wave[64 - n], n = 0, ..., 63

Among the ROM-wavetables in the Wave2/XT/XTk, WT 65 "True PWM" (which emulates the normal pulse-oscillator) is the only one without this type of symmetry.

In the shaper-wave, only samples 32 to 97 are relevant; the first and latter 31 samples are without any effect. Neighbouring shaper-samples are interpolated linearly, giving the function the shape of a continous polygon. Accordingly there are no jumps in it, only steep transitions are possible.

The definition range [-2M ; +2M] refers to the sample-range [32,5 ; 96,5].

E.g: Input-value "-2M" is mapped to the average of samples 32 and 33:
f(-2M) = (Wave[32] + Wave[33]) / 2;
f(+2M) = (Wave[96] + Wave[97]) / 2;

The plot of this function equals the wave-cycle from 90 to 270 (samples 32...97), except that neighbouring samples are connected by a straight line instead of a smooth, round interpolation curve. In the picture "shaper-wave" below the pink frame contains a plot of the corresponding shaping function.

... now let's engage this function to shape a triangle-wave of rising amplitude (without filtering):

Preservation of Odd Harmonics

All shaper waves, except from WT "True PWM", generate shaping functions pointsymmetric to the origin (odd symmetry):

(1) f(-x) = - f(x)

A big advantage of such a shaper is that the output wave has odd harmonics only, if the input wave consists only of odd harmonics, too. At deep pitches shaped filter sweeps with odd harmonics only sound hollow and mostly more pleasant (for my taste), whereas waveshaped sounds with both even and odd harmonics (like saw) have a more dirty and woody character. But on high pitches, odd harmonics sound more flute-like, and sounds with both even and odd harmonics could be nicer. (thats only my personal feeling, but I want to give a guideline for waveshaping sound programming beginners ;-))

Now I want to prove the property:
(2) odd symmetric shaper functions preserve odd harmonics.

!!! big math-haters can skip the rest of this article!!! :)

x(t) is a audio signal depending on time. If this signal is a periodic waveform, then T is its cycle lengh.
(periodic means: x(t+k*T)=x(t), for k=...,-1,0,1,2,...)

(3) A wave consisting of odd harmonics is equivalent to the symmetry:
x(t+T/2) = - x(t)
(visually: the 2. half is the sign inverted copy 1. half)

Proof for (3):

=>: a sine wave with a frequency that is an odd multiple of the base frequency has this symmetry. And a sum of two such odd overtones has this symmetry, too:
y(t): sum wave
x1(t), x2(t): sinoids
y(t+T/2) = x1(t+T/2)+x2(t+T/2) = -x1(t)-x2(t) = -y(t)

<=: Consider a wave x(t) with the symmetry x(t+T/2) = - x(t). Dismantle it into a sum of a wave xO(t) containing its odd harmonics and a wave xE(t) consisting of its even overtones:
(6) x(t)=xE(t)+xO(t)
a sine wave x1(t) with a frequency that is an even multiple of the base frequency has the symmetry:
x1(t+T/2) = + x1(t)

In a little proof analog to the above => proof, one can show that the sum of two even harmonics has the same symmetry, too. This implicites:
(4) xE(t+T/2) = + xE(t)
Whereas the odd part has the property:
(5) xO(t+T/2) = - xO(t)
first (6) and then (4) and (5) into (3):
x(t+T/2) = - x(t)
xE(t+T/2)+xO(t+T/2) = -xE(t)-xO(t)
xE(t)-xO(t) = -xE(t)-xO(t)

* xE(t)=0
Means : no even harmonics.

Proof for (2):
We insert an odd harmonic wave into an odd symmetric shaper function.
y(t) is the output wave, x(t) the input.
To show: y(t+T/2) = - y(t)
Using (1) and (3):
y(t+T/2) = f(x(t+T/2)) = f(-x(t)) = -f(x(t)) = -y(t)


A slightly different version of this workshop was originally published at Amazona.de