clipper.h
The diode clipper, solved.
#include <sonore/clipper.h>- 2types
- Guides: Getting started, MIDI and MPE
On this page
Design notes
The heart of every overdrive and distortion pedal is two diodes back to back across a capacitor, fed through a resistor: the Tube Screamer's feedback loop, the DS-1's output stage, the Klon's. Asked for one, a model writes tanh. A diode clipper is not tanh -- its knee is exponential rather than polynomial, and because the diodes sit across a capacitor the CORNER of the circuit moves with drive: the harder the diodes conduct, the lower their dynamic resistance and the more of the top they shunt, so a hot signal comes out darker as well as flatter.
The model is Yeh, Abel & Smith's ("Simulation of the diode limiter in guitar distortion circuits by numerical solution of ordinary differential equations", DAFx 2007): the circuit's one state equation,
C dv/dt = (vin - v)/R - 2 Is sinh(v / (n Vt)),
integrated by the trapezoidal rule with a Newton solve at each step -- the method that paper finds stable where explicit ones are not -- at an oversampled rate, because the exponential makes harmonics well past Nyquist. Their component values are the defaults: R = 2.2 kOhm, C = 10 nF, 1N914 diodes (Is = 2.52 nA, n = 1.752). Asymmetric clipping is the pedal trick of unequal diode counts each way, which the sinh splits into two exponentials with different scales.
The input is in VOLTS: a guitar is a tenth of a volt, the op-amp before a clipper makes it several. setInputGain is that op-amp.
Included by dsp.h. Uses Oversampled<> from lofi.h.
Types 2
The clipper alone, at whatever rate it is told. Run it inside Oversampled<> -- or use OversampledDiodeClipper below, which does that and keeps the rates straight.
template <int Stages = 3> class OversampledDiodeClipper
The clipper at 2^Stages times the rate, with the cascade's latency. 8x is the paper's recommendation and the default.