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

Physical audio-transformer coloration (flux-domain JA hysteresis). More...

#include <TransformerModel.h>

Public Member Functions

void prepare (const AudioSpec &spec)
 Allocates per-channel circuit state. 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
 Clears all signal state. RT-safe.
 
void setDrive (T db) noexcept
 Core drive in dB [-12, +24]; loudness-compensated. Non-finite values are ignored.
 
void setCoreSize (T size) noexcept
 Core size [0, 1]: small chokes at 40 Hz and saturates early, big rings to 5 Hz with more low-end headroom. Default 0.5. Non-finite values are ignored.
 
void setResonance (T amount) noexcept
 Leakage/capacitance HF bell amount [0, 1] (Jensen-style). Non-finite values are ignored.
 
void setMix (T mix) noexcept
 Dry/wet mix [0, 1]; the dry path is delayed to getLatency() and the mix is ramped over at least 20 ms. Between the two ends the dry side leads as the magnetizing corner does, by phase alone, so a partial mix loses no more than 0.1 dB to phase from 20 Hz up; at 0 it is the delayed input to the bit. Non-finite values are ignored.
 
T getDrive () const noexcept
 
T getCoreSize () const noexcept
 
T getResonance () const noexcept
 
T getMix () const noexcept
 
void setOversampling (int factor)
 Configures internal oversampling of the core. SETUP THREAD ONLY: it reallocates the filters and re-runs the 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()).
 
int getOversamplingFactor () const noexcept
 Active oversampling factor (1 = off, 2 = default).
 
int getLatency () const noexcept
 Latency in samples: the active oversampler's group delay (0 at 1x). The model itself is minimum-phase IIR and memoryless NR.
 
int getLatencySamples () const noexcept
 Compatibility alias of getLatency(), in prepared-rate samples.
 
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). Setup thread: a stored oversampling factor other than the active one re-prepares, as setOversampling() does. Blobs from before the factor was stored restore the default, 2.
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes a block in-place. Pass-through until prepare() succeeds. Blocks longer than the prepared maximum are processed in pieces.
 

Detailed Description

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

Physical audio-transformer coloration (flux-domain JA hysteresis).

Template Parameters
TSample type (float or double).

Definition at line 103 of file TransformerModel.h.

Member Function Documentation

◆ getCoreSize()

template<FloatType T>
T dspark::TransformerModel< T >::getCoreSize ( ) const
inlinenoexcept

Definition at line 236 of file TransformerModel.h.

◆ getDrive()

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

Definition at line 235 of file TransformerModel.h.

◆ getLatency()

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

Latency in samples: the active oversampler's group delay (0 at 1x). The model itself is minimum-phase IIR and memoryless NR.

Definition at line 289 of file TransformerModel.h.

◆ getLatencySamples()

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

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

Definition at line 292 of file TransformerModel.h.

◆ getMix()

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

Definition at line 238 of file TransformerModel.h.

◆ getOversamplingFactor()

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

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

Definition at line 285 of file TransformerModel.h.

◆ getResonance()

template<FloatType T>
T dspark::TransformerModel< T >::getResonance ( ) const
inlinenoexcept

Definition at line 237 of file TransformerModel.h.

◆ getState()

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

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

Definition at line 295 of file TransformerModel.h.

◆ isOversamplingAutomatic()

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

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

Definition at line 282 of file TransformerModel.h.

◆ prepare()

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

Allocates per-channel circuit state. 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 112 of file TransformerModel.h.

◆ processBlock()

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

Processes a block in-place. Pass-through until prepare() succeeds. Blocks longer than the prepared maximum are processed in pieces.

Definition at line 330 of file TransformerModel.h.

◆ reset()

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

Clears all signal state. RT-safe.

Definition at line 166 of file TransformerModel.h.

◆ setAutomaticOversampling()

template<FloatType T>
void dspark::TransformerModel< 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 core 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 273 of file TransformerModel.h.

◆ setCoreSize()

template<FloatType T>
void dspark::TransformerModel< T >::setCoreSize ( T  size)
inlinenoexcept

Core size [0, 1]: small chokes at 40 Hz and saturates early, big rings to 5 Hz with more low-end headroom. Default 0.5. Non-finite values are ignored.

Definition at line 208 of file TransformerModel.h.

◆ setDrive()

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

Core drive in dB [-12, +24]; loudness-compensated. Non-finite values are ignored.

Definition at line 198 of file TransformerModel.h.

◆ setMix()

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

Dry/wet mix [0, 1]; the dry path is delayed to getLatency() and the mix is ramped over at least 20 ms. Between the two ends the dry side leads as the magnetizing corner does, by phase alone, so a partial mix loses no more than 0.1 dB to phase from 20 Hz up; at 0 it is the delayed input to the bit. Non-finite values are ignored.

Definition at line 229 of file TransformerModel.h.

◆ setOversampling()

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

Configures internal oversampling of the core. SETUP THREAD ONLY: it reallocates the filters and re-runs the calibration exactly like prepare(); never call it concurrently with processBlock().

Parameters
factorPower of two in {1, 2, 4, 8, 16}. 1 = off (zero latency; the loop's harmonics above the base Nyquist then fold into the band). 2 is the default. Other values are ignored. getLatency() reflects the new factor after this call.

Definition at line 250 of file TransformerModel.h.

◆ setResonance()

template<FloatType T>
void dspark::TransformerModel< T >::setResonance ( T  amount)
inlinenoexcept

Leakage/capacitance HF bell amount [0, 1] (Jensen-style). Non-finite values are ignored.

Definition at line 217 of file TransformerModel.h.

◆ setState()

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

Restores parameters from a blob (tolerant; rejects foreign ids). Setup thread: a stored oversampling factor other than the active one re-prepares, as setOversampling() does. Blobs from before the factor was stored restore the default, 2.

Definition at line 313 of file TransformerModel.h.


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