A waveshaper is an audio effect that changes an audio signal by mapping an input signal to the output signal by applying a fixed or variable mathematical function, called the shaping function or transfer function, to the input signal. The function can be any function at all. Mathematically, the operation is defined by the waveshaper equation where f is the shaping function, x is the input function, and a is the index function, which in general may vary as a function of time. This parameter a is often used as a constant gain factor called the distortion index. In practice, the input to the waveshaper, x, is considered on for digitally sampled signals, and f will be designed such that y is also on to prevent unwanted clipping in software.
Commonly used shaping functions
Sin, arctan, polynomial functions, or piecewise functions are commonly used as waveshaping transfer functions. It is also possible to use table-driven functions, consisting of discrete points with some degree of interpolation or linear segments.
Polynomials
A polynomial is a function of the form Polynomial functions are convenient as shaping functions because, when given a single sinusoid as input, a polynomial of degree N will only introduce up to the Nth harmonic of the sinusoid. To prove this, consider a sinusoid used as input to the general polynomial. Next, use the inverse Euler's formula to obtain complex sinusoids. Finally, use the binomial formula to transform back to trigonometric form and find coefficients for each harmonic. From the above equation, several observations can be made about the effect of a polynomial shaping function on a single sinusoid:
All of the sinusoids generated are harmonically related to the original input.
The frequency never exceeds.
All odd monomial terms generate odd harmonics from n down to the fundamental, and all even monomial terms generate even harmonics from n down to DC.
The shape of the spectrum produced by each monomial term is fixed and determined by the binomial coefficients.
The weight of that spectrum in the overall output is determined solely by its coefficient and the amplitude of the input by
Problems associated with waveshapers
The sound produced by digital waveshapers tends to be harsh and unattractive, because of problems with aliasing. Waveshaping is a non-linear operation, so it's hard to generalize about the effect of a waveshaping function on an input signal. The mathematics of non-linear operations on audio signals is difficult, and not well understood. The effect will be amplitude-dependent, among other things. But generally, waveshapers—particularly those with sharp corners -- tend to introduce large numbers of high frequency harmonics. If these introduced harmonics exceed the nyquist limit, then they will be heard as harsh inharmonic content with a distinctly metallic sound in the output signal. Oversampling can somewhat but not completely alleviate this problem, depending on how fast the introduced harmonics fall off. With relatively simple, and relatively smooth waveshaping functions, atan, this procedure may reduce aliased content in the harmonic signal to the point that it is musically acceptable. But waveshaping functions other than polynomial waveshaping functions will introduce an infinite number of harmonics into the signal, some which may audibly alias even at the supersampled frequency.