DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::TubePreamp< T > Class Template Reference

One/two 12AX7 stages with sag and a WDF tone circuit. More...

#include <TubePreamp.h>

Public Types

enum class  OversamplingMode { LinearPhase , MinimumPhase }
 How the oversampler filters (see setOversamplingMode()). More...
 
enum class  GridModel { Clamp , Conduction }
 How the stages model grid conduction (see setGridModel()). More...
 

Public Member Functions

void prepare (const AudioSpec &spec)
 Allocates both stage configurations per channel and runs the reference calibration. Invalid specs (non-positive or non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through.
 
void reset () noexcept
 Re-settles every stage at its DC operating point. RT-safe.
 
void setCabinet (bool on) noexcept
 Runs the wet signal through a loudspeaker cabinet (off by default).
 
bool isCabinet () const noexcept
 Whether the cabinet stage is on.
 
CabinetModel< T > & getCabinet () noexcept
 The cabinet model: its setters are safe from any thread.
 
void setDrive (T db) noexcept
 Input drive in dB [-12, +36]; level-compensated. Non-finite values are ignored.
 
void setTreble (T treble) noexcept
 Treble control of the FMV stack [0, 1]. Non-finite values are ignored.
 
void setBass (T bass) noexcept
 Bass control of the FMV stack [0, 1] (log-taper, like the original). Non-finite values are ignored.
 
void setMiddle (T middle) noexcept
 Middle control of the FMV stack [0, 1]. Non-finite values are ignored.
 
void setSag (T sag) noexcept
 Supply sag depth [0, 1] (0 = stiff supply). Non-finite values are ignored.
 
void setStages (int stages) noexcept
 Number of triode stages (1 = clean/edge, 2 = high gain). RT-safe; the prepared latency does not change. A running stream keeps its circuit while the new path warms for 5 ms, then crossfades over 20 ms. Reversing a running fade preserves both circuit states.
 
void setOversampling (int factor)
 Configures internal oversampling of the nonlinear circuit (visible, tunable and switchable off). SETUP THREAD ONLY - it reallocates the polyphase filters and re-runs the reference calibration exactly like prepare(); never call it concurrently with processBlock().
 
void setAutomaticOversampling (bool on)
 Lets the host rate choose the factor (SETUP THREAD ONLY, as setOversampling()).
 
bool isOversamplingAutomatic () const noexcept
 Whether the factor follows the host rate (setAutomaticOversampling()).
 
void setOversamplingMode (OversamplingMode mode)
 Chooses the oversampler's filters (SETUP THREAD ONLY, as setOversampling(): an active instance is prepared again).
 
OversamplingMode getOversamplingMode () const noexcept
 The oversampler's filters (setOversamplingMode()).
 
int getOversamplingFactor () const noexcept
 Active oversampling factor (1 = off, 2 = default).
 
void setGridModel (GridModel model)
 Selects the grid model. SETUP THREAD ONLY, like setOversampling(): it rebuilds the circuits and re-runs the reference calibration. Out-of-range values are clamped.
 
GridModel getGridModel () const noexcept
 The selected grid model.
 
void setOutput (T db) noexcept
 Static output trim in dB [-24, +12]. Non-finite values are ignored.
 
void setMix (T mix) noexcept
 Dry/wet mix [0, 1]; dry is latency-compensated and the mix is ramped over at least 20 ms. Non-finite values are ignored.
 
T getDrive () const noexcept
 
T getTreble () const noexcept
 
T getBass () const noexcept
 
T getMiddle () const noexcept
 
T getSag () const noexcept
 
int getStages () const noexcept
 
T getOutput () const noexcept
 
T getMix () const noexcept
 
int getLatency () const noexcept
 Latency in prepared-rate samples added by the oversampler and the continuous core (0 at 1x = off); reflects the current factor, so hosts can compensate (PDC).
 
int getLatencySamples () const noexcept
 Compatibility alias of getLatency(), in prepared-rate samples.
 
T getSupplyVoltage () const noexcept
 Effective B+ supply voltage of channel 0 (sag meter readout). During a stage transition, uses the same blend weights as the wet paths.
 
std::vector< uint8_t > getState () const
 Serializes the parameter state (setup/UI threads; allocates).
 
bool setState (const uint8_t *data, size_t size)
 Restores parameters from a blob (tolerant; rejects foreign ids).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a block in-place. Pass-through until prepare() succeeds.
 

Detailed Description

template<FloatType T>
class dspark::TubePreamp< T >

One/two 12AX7 stages with sag and a WDF tone circuit.

Template Parameters
TSample type (float or double).

Definition at line 855 of file TubePreamp.h.

Member Enumeration Documentation

◆ GridModel

template<FloatType T>
enum class dspark::TubePreamp::GridModel
strong

How the stages model grid conduction (see setGridModel()).

  • Clamp (default): a soft clamp of the grid voltage toward +0.7 V, referenced to ground. It starts at 0 V, while the cathode sits near +1.2 V, so it compresses from about -1.2 V grid-to-cathode and the grid never reaches the cathode.
  • Conduction: grid current of the grid-to-cathode voltage (12AX7 fit of Dempwolf and Zoelzer, DAFx-11), added to the cathode current. 0.25 mA at +0.5 V, 0.62 mA at +1 V. Each grid is fed from its source (the drive-scaled input, or the interstage signal) through a 22 nF coupling capacitor, a 1 M ohm grid leak to ground and a 68 k ohm series resistance. Grid current charges the coupling capacitor, so a loud passage leaves the stage biased colder until the capacitor discharges through the grid leak (22 ms): blocking distortion. At rest a 1 V step drives the grid to 0.936 V (Clamp: 0.624 V) and 20 V to 1.730 V (Clamp: 0.700 V) before the capacitor charges; see setGridModel() for the effect on the output. The coupling network is also a 7.2 Hz high-pass on each grid.
Enumerator
Clamp 
Conduction 

Definition at line 1154 of file TubePreamp.h.

◆ OversamplingMode

template<FloatType T>
enum class dspark::TubePreamp::OversamplingMode
strong

How the oversampler filters (see setOversamplingMode()).

Enumerator
LinearPhase 

Linear-phase half-bands: the latency of the factor, the dry path a delay (default).

MinimumPhase 

Elliptic allpass half-bands: a few samples of latency, the dry path through the same filters.

Definition at line 1102 of file TubePreamp.h.

Member Function Documentation

◆ getBass()

template<FloatType T>
T dspark::TubePreamp< T >::getBass ( ) const
inlinenoexcept

Definition at line 1221 of file TubePreamp.h.

◆ getCabinet()

template<FloatType T>
CabinetModel< T > & dspark::TubePreamp< T >::getCabinet ( )
inlinenoexcept

The cabinet model: its setters are safe from any thread.

Definition at line 995 of file TubePreamp.h.

◆ getDrive()

template<FloatType T>
T dspark::TubePreamp< T >::getDrive ( ) const
inlinenoexcept

Definition at line 1219 of file TubePreamp.h.

◆ getGridModel()

template<FloatType T>
GridModel dspark::TubePreamp< T >::getGridModel ( ) const
inlinenoexcept

The selected grid model.

Definition at line 1202 of file TubePreamp.h.

◆ getLatency()

template<FloatType T>
int dspark::TubePreamp< T >::getLatency ( ) const
inlinenoexcept

Latency in prepared-rate samples added by the oversampler and the continuous core (0 at 1x = off); reflects the current factor, so hosts can compensate (PDC).

Definition at line 1231 of file TubePreamp.h.

◆ getLatencySamples()

template<FloatType T>
int dspark::TubePreamp< T >::getLatencySamples ( ) const
inlinenoexcept

Compatibility alias of getLatency(), in prepared-rate samples.

Definition at line 1234 of file TubePreamp.h.

◆ getMiddle()

template<FloatType T>
T dspark::TubePreamp< T >::getMiddle ( ) const
inlinenoexcept

Definition at line 1222 of file TubePreamp.h.

◆ getMix()

template<FloatType T>
T dspark::TubePreamp< T >::getMix ( ) const
inlinenoexcept

Definition at line 1226 of file TubePreamp.h.

◆ getOutput()

template<FloatType T>
T dspark::TubePreamp< T >::getOutput ( ) const
inlinenoexcept

Definition at line 1225 of file TubePreamp.h.

◆ getOversamplingFactor()

template<FloatType T>
int dspark::TubePreamp< T >::getOversamplingFactor ( ) const
inlinenoexcept

Active oversampling factor (1 = off, 2 = default).

Definition at line 1132 of file TubePreamp.h.

◆ getOversamplingMode()

template<FloatType T>
OversamplingMode dspark::TubePreamp< T >::getOversamplingMode ( ) const
inlinenoexcept

The oversampler's filters (setOversamplingMode()).

Definition at line 1129 of file TubePreamp.h.

◆ getSag()

template<FloatType T>
T dspark::TubePreamp< T >::getSag ( ) const
inlinenoexcept

Definition at line 1223 of file TubePreamp.h.

◆ getStages()

template<FloatType T>
int dspark::TubePreamp< T >::getStages ( ) const
inlinenoexcept

Definition at line 1224 of file TubePreamp.h.

◆ getState()

template<FloatType T>
std::vector< uint8_t > dspark::TubePreamp< T >::getState ( ) const
inline

Serializes the parameter state (setup/UI threads; allocates).

Definition at line 1244 of file TubePreamp.h.

◆ getSupplyVoltage()

template<FloatType T>
T dspark::TubePreamp< T >::getSupplyVoltage ( ) const
inlinenoexcept

Effective B+ supply voltage of channel 0 (sag meter readout). During a stage transition, uses the same blend weights as the wet paths.

Definition at line 1238 of file TubePreamp.h.

◆ getTreble()

template<FloatType T>
T dspark::TubePreamp< T >::getTreble ( ) const
inlinenoexcept

Definition at line 1220 of file TubePreamp.h.

◆ isCabinet()

template<FloatType T>
bool dspark::TubePreamp< T >::isCabinet ( ) const
inlinenoexcept

Whether the cabinet stage is on.

Definition at line 992 of file TubePreamp.h.

◆ isOversamplingAutomatic()

template<FloatType T>
bool dspark::TubePreamp< T >::isOversamplingAutomatic ( ) const
inlinenoexcept

Whether the factor follows the host rate (setAutomaticOversampling()).

Definition at line 1099 of file TubePreamp.h.

◆ prepare()

template<FloatType T>
void dspark::TubePreamp< T >::prepare ( const AudioSpec &  spec)
inline

Allocates both stage configurations per channel and runs the reference calibration. Invalid specs (non-positive or non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through.

Definition at line 864 of file TubePreamp.h.

◆ processBlock()

template<FloatType T>
void dspark::TubePreamp< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes a block in-place. Pass-through until prepare() succeeds.

Definition at line 1300 of file TubePreamp.h.

◆ reset()

template<FloatType T>
void dspark::TubePreamp< T >::reset ( )
inlinenoexcept

Re-settles every stage at its DC operating point. RT-safe.

Definition at line 957 of file TubePreamp.h.

◆ setAutomaticOversampling()

template<FloatType T>
void dspark::TubePreamp< T >::setAutomaticOversampling ( bool  on)
inline

Lets the host rate choose the factor (SETUP THREAD ONLY, as setOversampling()).

With it on, every prepare() takes the smallest factor that brings the circuit to an internal rate of at least 88.2 kHz: 2x at 44.1 and 48 kHz (the default factor) and none from 88.2 kHz up. The nonlinearity then runs at about the same rate whatever the session rate, and a high-rate session stops paying for a factor it does not need. Off by default; an explicit setOversampling() turns it off.

Parameters
onTrue to choose the factor from the rate.

Definition at line 1090 of file TubePreamp.h.

◆ setBass()

template<FloatType T>
void dspark::TubePreamp< T >::setBass ( T  bass)
inlinenoexcept

Bass control of the FMV stack [0, 1] (log-taper, like the original). Non-finite values are ignored.

Definition at line 1018 of file TubePreamp.h.

◆ setCabinet()

template<FloatType T>
void dspark::TubePreamp< T >::setCabinet ( bool  on)
inlinenoexcept

Runs the wet signal through a loudspeaker cabinet (off by default).

The cabinet comes after the circuit and before the dry/wet mix, adds no latency and fades in and out over 20 ms. Its settings (size of the box, brightness of the speaker, distance of the microphone) are those of getCabinet(). Safe from any thread.

Definition at line 989 of file TubePreamp.h.

◆ setDrive()

template<FloatType T>
void dspark::TubePreamp< T >::setDrive ( T  db)
inlinenoexcept

Input drive in dB [-12, +36]; level-compensated. Non-finite values are ignored.

Definition at line 1001 of file TubePreamp.h.

◆ setGridModel()

template<FloatType T>
void dspark::TubePreamp< T >::setGridModel ( GridModel  model)
inline

Selects the grid model. SETUP THREAD ONLY, like setOversampling(): it rebuilds the circuits and re-runs the reference calibration. Out-of-range values are clamped.

Conduction is a change of character, so it is opt-in. Against Clamp at 2x, one stage, 1 kHz at -6 dBFS: the output differs by -21.9 dB at 0 dB drive and -7.7 dB at +12 dB, where the second harmonic moves from -15.0 to -16.5 dBc, the third from -15.4 to -21.1 dBc and the level rises 1.6 dB. From +24 dB the charged coupling capacitor holds the stage near cutoff for most of the cycle: the second harmonic rises from -21.2 to -3.9 dBc and the level falls 1.3 dB (two stages, +36 dB: 5.3 dB). Blocking: after a 300 ms burst at +24 dB (1 kHz, -6 dBFS) a 0.01 tone comes out 15.6 dB below its settled level 2 ms later, 10.8 dB at 10 ms and 1.8 dB at 20 ms, recovered by 40 ms; during the burst the supply reads 277.4 V against 264.4 V without the coupling network (less plate current). Against the point circuit at 32x the core error stays within 1.8 dB of the Clamp figure (worst -56.6 dB, Clamp -58.4). Inside each internal sample the coupling capacitor follows its equation: the leak toward the source exactly (stage 1; a predicted ramp in stage 2) and the grid current's charge integrated piece by piece from the currents at the integration nodes (a linear ramp, or a held value, bent or stepped at every boundary under grid current, which the output kernel cannot remove). Worst alias over the documented sweep at 2x (after 2 s of settling): -102.8/-88.2/-83.2 dBc at one stage, +12/+24/+36 dB (Clamp -87.7/-80.6/-80.6) and -90.5/-88.1/-84.5 at two stages (Clamp -83.0/-83.0/-84.8), against -85.5/-74.0/-74.0 and -81.6/-73.1/-73.1 with the capacitor ramped across each sample. The two-stage +36 dB figure is the output kernel's leakage of the fifth harmonic, which the conduction circuit makes 1.5 dB stronger (-12.6 against -14.1 dBc at 15.25 kHz). At 4x -120.2/-114.1/-105.5 (one stage) and -115.2/-103.1/-102.6 dBc (two stages; Clamp -102.0/-96.4/-96.4 and -93.9/-93.9/-105.8), at 8x -120.2/-114.1/-111.9 and -115.2/-110.5/-109.7. CPU at 2x rises 13-64 % against Clamp, most for high tones at +24..+36 dB drive.

Definition at line 1192 of file TubePreamp.h.

◆ setMiddle()

template<FloatType T>
void dspark::TubePreamp< T >::setMiddle ( T  middle)
inlinenoexcept

Middle control of the FMV stack [0, 1]. Non-finite values are ignored.

Definition at line 1026 of file TubePreamp.h.

◆ setMix()

template<FloatType T>
void dspark::TubePreamp< T >::setMix ( T  mix)
inlinenoexcept

Dry/wet mix [0, 1]; dry is latency-compensated and the mix is ramped over at least 20 ms. Non-finite values are ignored.

Definition at line 1213 of file TubePreamp.h.

◆ setOutput()

template<FloatType T>
void dspark::TubePreamp< T >::setOutput ( T  db)
inlinenoexcept

Static output trim in dB [-24, +12]. Non-finite values are ignored.

Definition at line 1205 of file TubePreamp.h.

◆ setOversampling()

template<FloatType T>
void dspark::TubePreamp< T >::setOversampling ( int  factor)
inline

Configures internal oversampling of the nonlinear circuit (visible, tunable and switchable off). SETUP THREAD ONLY - it reallocates the polyphase filters and re-runs the reference calibration exactly like prepare(); never call it concurrently with processBlock().

Parameters
factorPower-of-two multiplier in {1,2,4,8,16}. 1 = OFF (no internal resampling, zero added latency; the triode/grid nonlinearity then aliases in-band unless the surrounding chain is oversampled). 2 is the default. Higher factors lower the residual error at higher CPU. Invalid or non-power-of-two values are ignored. getLatency() reflects the new factor after this call (0 at 1x).

Definition at line 1064 of file TubePreamp.h.

◆ setOversamplingMode()

template<FloatType T>
void dspark::TubePreamp< T >::setOversamplingMode ( OversamplingMode  mode)
inline

Chooses the oversampler's filters (SETUP THREAD ONLY, as setOversampling(): an active instance is prepared again).

MinimumPhase runs polyphase allpass half-bands: at 2x the circuit's latency falls from the factor's linear-phase delay to a few samples, and the dry copy of the mix crosses the same filters, so a partial mix adds in phase. getLatency() reflects the change.

Parameters
modeLinearPhase (default) or MinimumPhase.

Definition at line 1119 of file TubePreamp.h.

◆ setSag()

template<FloatType T>
void dspark::TubePreamp< T >::setSag ( T  sag)
inlinenoexcept

Supply sag depth [0, 1] (0 = stiff supply). Non-finite values are ignored.

Definition at line 1034 of file TubePreamp.h.

◆ setStages()

template<FloatType T>
void dspark::TubePreamp< T >::setStages ( int  stages)
inlinenoexcept

Number of triode stages (1 = clean/edge, 2 = high gain). RT-safe; the prepared latency does not change. A running stream keeps its circuit while the new path warms for 5 ms, then crossfades over 20 ms. Reversing a running fade preserves both circuit states.

Definition at line 1045 of file TubePreamp.h.

◆ setState()

template<FloatType T>
bool dspark::TubePreamp< T >::setState ( const uint8_t *  data,
size_t  size 
)
inline

Restores parameters from a blob (tolerant; rejects foreign ids).

Definition at line 1267 of file TubePreamp.h.

◆ setTreble()

template<FloatType T>
void dspark::TubePreamp< T >::setTreble ( T  treble)
inlinenoexcept

Treble control of the FMV stack [0, 1]. Non-finite values are ignored.

Definition at line 1009 of file TubePreamp.h.


The documentation for this class was generated from the following file: