Distortion can refer to a variety of mathematically distinct effects, referring to an aesthetic associated with warmth, fuzziness, dirtiness, harshness.
One generic method for achieving distortion digitally is to use a "non-linear transfer function" (NLTF), a memoryless filter that maps amplitudes from an input signal to an output signal according to a deterministic function. As the name implies, we exclude any boring linear functions that only serve to amplify or attenuate. Many non-linear transfer functions can be used, with different effects:
- f(x) = x if -1 < x < 1; -1 if x < -1; 1 if x > 1 is "clip distortion," which can occur naturally when digital audio caps. It is ringy and tends to add odd harmonics. (It only has any effect when the signal is amplified so that it peaks beyond [-1,1].)
- f(x) = x if -1 < x < 1; -x - 2 if x < -1; -x + 2 if x > 1 is "fold distortion," which is similar to clip distortion but even buzzier.
- f(x) = x if -1 < x < 1; x + 2 if x < -1; x - 2 if x > 1 is "wrap distortion," which is buzzier and harsher still than fold distortion.
- f(x) = tanh(x) (hyperbolic tangent) is quite a bit like clip distortion, but much, much subtler. It is a form of "soft clipping."
- f(x) = 0 if x = 0; 1 - x if x > 0; -1 - x if x < 0 is "inside-out distortion," which generates extremely abrasive and noisy audio. Good shit.
Stephen McGovern provides an interesting algorithm for distortion that results in an infinite family of NLTFs. The formula is, given an odd positive integer n: f(x) = (sin(arcsin(x)) + sin(3 arcsin(x))/3 + sin(5 arcsin(x))/5 + sin(7 arcsin(x))/7 + ... + sin(n arcsin(x)) / n) * 2/pi. As n approaches infinity, the sound becomes similar to extreme amplification + clipping, since the formula is essentially a Fourier series for a square wave. Small values of n produce a milder effect that's still interesting. By fading out each partial for in-between values of n, the distortion can be smoothly modulated with ease.
Not all distortion effects are NLTFs. Here are some others:
- Decimation reduces the sample rate or bit depth.
- Trevor Wishart describes an algorithm where a signal is sliced into zero-crossings and some sections are silenced. If the silencing is periodic, it sounds like a sort of "purring." Interesting enough, but the real fun begins when the silencing is random, yielding very noisy sounds reminiscent of distortion. The density of randomly silenced sections can be modulated to control the amount of noise.