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 musicdsp.org 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))
http://musicdsp.org/archive.php?classid=4#46
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.
http://www.musicdsp.org/archive.php?classid=4#203
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.
http://www.musicdsp.org < excellent public source code archive
http://en.wikipedia.org/wiki/Distortion
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.