tube.h
A valve gain stage and the tone stack after it.
#include <sonore/tube.h>- 2types
- Guides: Getting started, MIDI and MPE
On this page
Design notes
"Make me an amp" produced a tanh every time, and a tanh is what a valve is not: it is symmetric, and a single-ended triode stage is not. The stage's asymmetry -- cut-off on one side, grid conduction on the other, the plate swinging further one way than the other -- is where the even harmonics come from, and the even harmonics are the sound.
TubeStage is the common-cathode triode stage WITH ITS CAPACITORS. The static transfer -- plate voltage against grid voltage with the plate load in the loop -- is Koren's triode ("Improved vacuum-tube models for SPICE simulations", 1996) solved once at prepare() into a table. That curve is what the first version had, and it is most of the sound of a stage played quietly. What it is not is the sound of a stage played hard, because the two things a driven triode does that a curve cannot are both capacitors:
BLOCKING. Past 0 V the grid conducts, and the current it draws charges the
input coupling capacitor through the source's impedance. The capacitor
holds that charge for R_g C_in (22 ms here) and holds the grid negative
with it, so after a loud transient the stage is biased towards cut-off
and the next few milliseconds come out GATED -- the "blocking distortion"
every overdriven preamp has, and the reason a hard-hit chord chokes and
then swells. The grid current is Dempwolf & Zölzer's ("A physically-
motivated triode model for circuit simulations", DAFx 2011) with their
ECC83 fit, the node solved by Newton each sample with the source
impedance in series -- which is what bounds the current and the charging
rate, and the reason a stage driven from a low impedance blocks harder.
BIAS SHIFT. The cathode bypass capacitor holds the cathode voltage at
its idle value only on average: a loud passage raises the mean cathode
current, the capacitor charges, the bias moves negative and the stage's
duty cycle and gain move with it, over R_k C_k (37 ms). Set the bypass to
zero and the cathode is degenerated instead: the voltage is solved from
the current each sample and the gain halves, which is the other stage
every amp has.
That is the model Pakarinen & Yeh's review (CMJ 2009) puts between the static waveshaper and a full nodal simulation, and it is Macak & Schimmel's (DAFx 2010) arrangement: the reactive parts as first-order states, the tube as a static nonlinearity between them. Not a K-method matrix solve -- a plate load that is a resistor needs none -- but every capacitor the circuit has, doing what it does.
A single stage INVERTS. The default output gain is 1/(small-signal gain), which is negative, so a quiet signal comes out at unity and the right way up -- a plugin that blends a stage with its dry input would otherwise cancel. Pass a negative output gain to keep the inversion.
ToneStack is the '59 Fender Bassman passive stack, from Yeh & Smith's "Discretization of the '59 Fender Bassman Tone Stack" (DAFx 2006): the three-knob network's transfer function is derived symbolically from the component values, so the knobs interact exactly as the circuit's do (the mid scoop with everything at noon is the circuit's, not a shape drawn to look like it), and the bilinear transform turns the cubic into a third- order digital filter. The bilinear expansion here is derived from the substitution rather than copied, and the unit test checks the digital response against the analogue one at the pre-warped frequency, where the two are equal by construction. The filter runs in DOUBLE: the network's slowest pole (R2 C2, ~8 Hz) puts a z-pole at 0.999 at 48 kHz, which a float transposed-direct-form section renders with a low-frequency error the ear can hear as a tilt.
Included by dsp.h.
Types 2
One common-cathode triode stage, 12AX7 by default: 300 V supply, 100 kΩ plate load, 1.5 kΩ cathode bypassed by 25 µF, driven through 38 kΩ (the plate impedance of the stage before it) and a 22 nF coupling capacitor into a 1 MΩ grid leak. The input is in VOLTS at the source (a ±1 signal is ±1 V, which is a hot line level into a first stage -- setInputGain is the volume knob before it); the output is the plate swing normalised so a small signal comes out at unity, the right way up.
The Bassman stack: bass, mid and treble pots on a passive network of three capacitors and four resistors. Knobs are 0..1 (the pot's travel); everything at 0.5 gives the deep mid scoop the circuit is famous for, and the knobs interact -- turning the bass up moves the mid notch -- because that is what the network does. Passive, so it only ever cuts: the peak of the response is a few dB below unity and the scoop is 20 dB under that.