Class Lfo
A bipolar (-1..+1) low-frequency oscillator for modulation (chorus, flanger, phaser, tremolo, auto-pan). Allocation-free; the sample-and-hold waveform uses a deterministic generator so output is reproducible.
public sealed class Lfo
- Inheritance
-
Lfo
- Inherited Members
Constructors
Lfo(int)
Creates an LFO.
public Lfo(int sampleRate)
Parameters
sampleRateintSample rate in Hz. Must be positive.
Properties
DelaySeconds
An optional delay in seconds before the LFO starts oscillating. During the delay Process() outputs 0 (the bipolar neutral value), matching the SoundFont/SFZ LFO delay behaviour. The delay is re-armed by Reset().
public float DelaySeconds { get; set; }
Property Value
FrequencyHz
Oscillation frequency in Hz. Must be positive.
public float FrequencyHz { get; set; }
Property Value
SampleRate
Sample rate in Hz. Must be positive.
public int SampleRate { get; set; }
Property Value
StartPhase
The phase, as a fraction of a cycle in [0, 1), that the oscillator starts from. Setting it moves the current phase there immediately (like Reset(), which also re-applies it); values outside [0, 1) wrap. The default of 0 keeps the historical behaviour (triangle and square start at +1, sine and sawtooth rising through their zero / minimum). Because the phase does not advance during DelaySeconds, the first sample after the delay expires is taken at this phase โ a SoundFont LFO (SF2.04 ยง8.1.2 gens 21/23) "begins its upward ramp from zero" when its delay elapses, which for the triangle waveform is a start phase of 0.75.
public float StartPhase { get; set; }
Property Value
Waveform
Oscillator waveform. Default Sine.
public LfoWaveform Waveform { get; set; }
Property Value
Methods
Advance(int)
Advances the oscillator by samples samples in one
call, returning the value the last of that many Process()
calls would have returned (0 while the delay is still running; for
samples = 0 the state is untouched and the value
the next call will return is reported). The resulting state is
bit-identical to repeated Process() calls: the delay
countdown is consumed in O(1), and the phase accumulator is stepped
with the same per-sample additions Process performs (a closed-form
phase + n x increment would round differently), but the waveform โ
the dominant per-sample cost โ is evaluated only once. Intended for
control-rate consumers that read the LFO once per block.
public float Advance(int samples)
Parameters
samplesintNumber of samples to advance by. Must not be negative.
Returns
Process()
Advances one sample and returns the next oscillator value in [-1, 1].
public float Process()
Returns
Reset()
Resets the phase to StartPhase (and re-seeds the sample-and-hold generator).
public void Reset()
SyncToTempo(double, NoteDivision)
Sets FrequencyHz from a tempo and note division.
public void SyncToTempo(double bpm, NoteDivision division)
Parameters
bpmdoubledivisionNoteDivision