How Does Distortion2: Shape Work?

I am interested to know how the different types of distortion on the distortion2 device work?

So for example, the razor mode cuts off the top of the waveform and amplifies it producing a clipping effect, presumably? But how does the shape mode work? And what exactly is the tone control doing- EQing before distortion? What about fold?

I just want to know more specifically how the distortion2 device is processing the signal. Or generally different ways in which distortion devices can process the signal?

Or can someone point me in the direction of a good resource for detail information on approaches to signal processing for different effects. I’m building some of my own effects in max/msp basically and I want to know how to make something similar to shape distortion.

If you run a clean sinewave through the Distortion2 device, it becomes clear (visually, at least) what each mode is doing to the waveform:

( wow… I did have an image embedded here, but I guess imageshack wanted to go all political and replace my original shit… )

Correct. It’s a very simple effect. You have your input signal, which is expected to be a floating point value within the range [-1.0, 1.0] (the standard for VST plugins and almost every audio app). Then you have a threshold value which is expected to be within [0.0, 1.0].
The code then looks something like this:

if (input > threshold) {  
 output = threshold  
} else if (input < -threshold) {  
 output = -threshold  
} else {  
 output = input  

The Shape mode is applying a process known as waveshaping to the input. There are several examples of this effect online that you can grab code from, but below I have provided the very simple code for the method I use in my own plugins, which I in turn got from some time ago. Waveshaping typically overdrives the sound with a much smoother/softer curve, and is also commonly known as soft saturation. You can really crank your audio this way without getting a harsh sound.

k = 2 * threshold / (1 - threshold)  
output = (1 + k) * input / (1 + k * abs(input))

If threshold is set to the maximum 1.0, the waveshaper will return a completely distorted sound, so if you only want to get a softer sound you may prefer to scale down the threshold a little bit like so:

threshold = threshold * 0.95  

I’m not 100% sure on this, but I suspect that it’s probably just a very simple form of EQing or filtering of some kind. If you leave the distortion’s tone set to neutral and then put an EQ device after it in the chain, it’s possible to boost/cut certain frequencies and get pretty close to the way it sounds when adjusting the tone slider.

This is what’s known as foldback distortion. When the input levels go above/below a certain threshold, the signal is inverted so that the peaks fold back in on themselves and create an interesting new waveform.
The code for this is also quite simple:

if (input > threshold || input < -threshold) {  
 output = fabs(fabs(fmod(input - threshold, threshold * 4)) - threshold * 2) - threshold  
} else {  
 output = input  

The multiplications of 4 and 2 are there to normalise the signal again, since folding back the peaks can reduce the volume.

Shift is another one I’m not 100% sure about, but just from looking at the waveform, it seems to me that it takes all input values which are in the range [-1.0, 0.0] (ie. the negative phase of the waveform), and then flips them into the positive phase in a similar way to the foldback method. It then appears to be scaling the output back up to the normal range [-1.0, 1.0]. I have not yet experimented with coding a similar effect myself, but I suspect it would be trivial to figure out with a few minutes of trial and error. < excellent public source code archive

There are a couple of other sites that were a great resource to me a few years ago, but I have lost track of the links at the moment. If I remember them I will post another reply here.

1 Like

Thank God there’s people in this world like dblue. Cheers for this mate, I was interested in learning about this stuff too.

Yes I was hoping you might have some answers on this, very useful thanks!