Distortion for Dummies by Dummy
The by far most requested feature for Sputter is distortion and bitcrushing. While bitcrushing is relatively easy to implement, distortion is a whole field by itself. You are not going to get a top of the line distortion plugin in Sputter, but I am aiming for a little bit more than the most basic and straightforward stuff.
The simplest and crudest distortion algorithm is to just multiply the signal by a large amount, then hard cut it. When running through a sine wave, it looks something like this:
Now it looks and sounds more like a square wave than a sine. That is what will happen at some point no matter what distortion algorithm you run it through, but when hard clipping it happens almost immediately. It may sound OK in some situations, but in most cases it sounds harsh and sharp. What we want, similar to analog style distortion, is to have the “corners” more rounded off like this:
So how to achieve this? One common way is to use a transfer function. Those of you who have used a wave shaper will know what I am talking about. For those who have not, I will attempt to explain it.
Usually, when you have no transfer function, you can think of that as a transfer function f(x)=x
which looks like this:
If you look closely you will see that for each x value the y is the same. So if we took a waveform and ran it through this function, we would read off the y-value corresponding to the x-value of the sample and send that to the sound card. Take a look at this to (hopefully) better comprehend it:
The sample marked in red is something like 0.9, and so is the corresponding y-value. Nothing has changed.
Instead we can use a more “s”-like funtion, like f(x)=2/pi * arctan(x)
. It looks like this:
You might notice that as x increases, y comes close to but never exceeds 1.
Let’s multiply our waveform’s amplitude by 20 and run it through:
For the sample marked in red, instead of sending 19 (or so) to the soundcard (which is way more than it can handle) we send the corresponding y-value which is almost 1. Using this technique we achieve the smooth and quite well sounding distortion in the second picture above.
I have successfully implemented this in a Pure Data patch. It will soon(ish) come to Sputter and Spitback, but first there are a few more ideas I would like to try to refine it even further. One of them is having more transfer functions in addition to f(x)=2/pi * arctan(x)
as shown above. For example, something like this might be interesting:
In this case any samples above 2 will just be hard clipped, but the ones below zero won’t. Another thing I will try is to add some filters, as described in this great talk by Ivan Cohen.
It will be interesting and fun to work and experiment further with this. I will post some sound clips on here for sure once I have got the filters worked out. Not sure if this will happen before or after the holidays, but everything else is in order so it should not be too far off.
In any case, happy holidays to all of you!