prep for 1.2.0 release updates
This commit is contained in:
+373
-2
@@ -16,7 +16,7 @@ extension OscSin: GeneratorEnum {
|
||||
}
|
||||
```
|
||||
|
||||
All paired built-in generators (`OscSin`, `OscTable`, `Impulse`, `WhiteNoise`, `LFStepNoise`, `LFLineNoise`, `PinkNoise`, `BrownNoise`, `GrayNoise`, `ClipNoise`, `Dust`, `Dust2`, `Crackle`, `LFCurveNoise`, `UniformNoise`, `GaussNoise`, `LpRandNoise`, `HpRandNoise`, `MeanRandNoise`, `ExpRandNoise`, `ExponentialNoise`, `GammaNoise`, `LaplaceNoise`, `ALaplaceNoise`, `HcosNoise`, `LogisticNoise`, `PoissonNoise`, `ArcsinNoise`, `BetaRandNoise`, `CauchyNoise`, `EnvelopeGen`, `PlayBuffer`, `RecordBuffer`, `In`, `Out`, `SendTrigger`, `Demand`, `TimedDemand`) conform to `GeneratorEnum`. New paired generators must do the same — see `docs/protocols/writing-generators.md`.
|
||||
All paired built-in generators (`OscSin`, `OscTable`, `Impulse`, `Phasor`, `WhiteNoise`, `LFStepNoise`, `LFLineNoise`, `PinkNoise`, `BrownNoise`, `GrayNoise`, `ClipNoise`, `Dust`, `Dust2`, `Crackle`, `LFCurveNoise`, `UniformNoise`, `GaussNoise`, `LpRandNoise`, `HpRandNoise`, `MeanRandNoise`, `ExpRandNoise`, `ExponentialNoise`, `GammaNoise`, `LaplaceNoise`, `ALaplaceNoise`, `HcosNoise`, `LogisticNoise`, `PoissonNoise`, `ArcsinNoise`, `BetaRandNoise`, `CauchyNoise`, `EnvelopeGen`, `PlayBuffer`, `RecordBuffer`, `In`, `Out`, `SendTrigger`, `Demand`, `TimedDemand`, `Trig`, `Trig1`, `TriggeredDelay`, `PulseCount`, `Stepper`, `Schmidt`, `Slew`, `ZeroCrossing`, `Slope`, `RunningMin`, `RunningMax`, `CrossFade`, `LinearCrossFade`, `Select`, `Waveshaper`, `CrossoverDistortion`, `Formlet`, `LFGauss`, `LorenzLinear`, `HenonStepped`, `QuadStepped`, `LinCongStepped`, `GbmanStepped`, `StandardStepped`, `FBSineStepped`, `LatoocarfianStepped`, `CuspStepped`) conform to `GeneratorEnum`. New paired generators must do the same — see `docs/protocols/writing-generators.md`.
|
||||
|
||||
## RT-allocation model (all generators)
|
||||
|
||||
@@ -184,6 +184,21 @@ Impulse.Audio(freq: 1.0, initPhase: 0.5) // first fire at half-period offset
|
||||
- `initPhase` is a fraction [0, 1) — `0.0` fires at sample 0 of the first block.
|
||||
- State: `LyrebirdFloat` phase accumulator.
|
||||
|
||||
#### Phasor
|
||||
Linear phase accumulator (ramp generator). Equivalent to SuperCollider `Phasor`. Accumulates `rate` units per sample within the half-open range `[start, end)`. On a ≤0 → >0 rising edge of `trig`, phase resets to `resetPos`.
|
||||
|
||||
```swift
|
||||
Phasor.Audio() // default: ramp 0..1 at 1/sample
|
||||
Phasor.Audio(rate: 440.0 * 1024.0 / 44100.0, start: 0, end: 1024) // 1024-sample wavetable scan at 440 Hz
|
||||
Phasor.Audio(trig: Impulse.Audio(freq: 2.0), rate: 0.01, resetPos: 0) // reset on trigger
|
||||
Phasor.Control(rate: 0.001) // slow ramp at control rate
|
||||
```
|
||||
|
||||
- `rate` is the **per-sample phase increment** (not Hz). For table scanning: `rate = freq * tableSize / sampleRate`.
|
||||
- `start` / `end` define the half-open range `[start, end)`. Wrapping is via `truncatingRemainder` — safe for rates larger than the span.
|
||||
- `trig` scans the full audio-rate trigger block per audio block in both `.Audio` and `.Control` variants.
|
||||
- Standalone sync/ramp primitive; works at any rate in the signal graph.
|
||||
|
||||
---
|
||||
|
||||
### Noise
|
||||
@@ -862,6 +877,36 @@ All `AudioGenerator` and `ControlGenerator` instances inherit a `[n]` subscript
|
||||
|
||||
Out-of-range `n` returns silence. See `docs/stdlib/multichannel.md` for full examples.
|
||||
|
||||
### CrossFade.Audio / CrossFade.Control (SC `XFade2`)
|
||||
|
||||
Equal-power crossfade between two inputs. Maps `pan ∈ [−1, 1]` to a quarter-sine/cosine
|
||||
gain pair so that `gainA² + gainB² = 1` at every position. `mul` plays the role of SC's
|
||||
`level` argument. Mono output (channel 0 of each input). Both `Audio` and `Control` variants.
|
||||
|
||||
```swift
|
||||
let xfade = CrossFade.Audio(inA: osc1, inB: osc2, pan: modLFO)
|
||||
```
|
||||
|
||||
### LinearCrossFade.Audio / LinearCrossFade.Control (SC `LinXFade2`)
|
||||
|
||||
Linear crossfade between two inputs. `gainA = (1 − pan) * 0.5`, `gainB = (1 + pan) * 0.5`
|
||||
so `gainA + gainB = 1` everywhere. Useful when constant-amplitude sum is preferred over
|
||||
constant power. `mul` plays the role of SC's `level` argument. Mono output. Both variants.
|
||||
|
||||
```swift
|
||||
let xfade = LinearCrossFade.Audio(inA: dry, inB: wet, pan: sendLevel)
|
||||
```
|
||||
|
||||
### Select.Audio / Select.Control (SC `Select`)
|
||||
|
||||
Index-selected N-input switch. Outputs the input at integer index `which` (truncated toward
|
||||
zero, clamped to `[0, N−1]`). All inputs are pulled every block regardless of selection —
|
||||
SC parity: non-selected sources advance their internal state. Both `Audio` and `Control` variants.
|
||||
|
||||
```swift
|
||||
let sel = Select.Audio(which: modLFO, inputs: [osc1, osc2, osc3])
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## LyrebirdMusicMath — Musical Conversion Utilities
|
||||
@@ -998,16 +1043,24 @@ let freqCR = LinExp.Control(env, inLo: 0.0, inHi: 1.0, outLo: 80.0, outHi: 8000
|
||||
|
||||
## Dynamics
|
||||
|
||||
Five signal-processing generators for amplitude tracking, pitch detection, limiting, compression, and expansion. Full API reference: `docs/stdlib/dynamics.md`.
|
||||
Seven signal-processing generators for amplitude tracking, pitch detection, limiting, normalizing, RMS matching, compression, and expansion. Full API reference: `docs/stdlib/dynamics.md`.
|
||||
|
||||
| Generator | Variants | Description |
|
||||
|-----------|----------|-------------|
|
||||
| `AmplitudeFollower` | Audio + Control | Envelope follower; asymmetric attack/release one-pole smoother |
|
||||
| `FreqTracker` | Audio only | YIN-based pitch tracker; 2-channel out (Hz + confidence 0..1) |
|
||||
| `LookAheadLimiter` | Audio only | True look-ahead limiter; no overshoot; `lookAheadTime` latency |
|
||||
| `Normalizer` | Audio only | Look-ahead peak normalizer; scales up AND down to `level`; `dur` latency |
|
||||
| `Balance` | Audio only | RMS level matcher; scales `in` to track the running RMS of `test`; decoupled `hp`/`smooth`; optional `logDomain` glide |
|
||||
| `Compressor` | Audio + Control | Feed-forward compressor; threshold/ratio/attack/release/knee/makeup |
|
||||
| `Expander` | Audio + Control | Downward expander/gate; mirrors `Compressor` below threshold |
|
||||
|
||||
`Balance` (sc3-plugins `Balance`, JoshUGens) tracks the running mean-square of two signals via a one-pole lowpass on squared samples (pole `b1 = exp(-2π·hp/sr)` from the `hp` cutoff in Hz, snapshotted per block) and outputs `in · sqrt(ms_test / (ms_in + tiny))`. Because the gain is a ratio of two identically-normalised mean-squares, the normalisation cancels — only the `hp` window length matters (equivalent to SC's unnormalised running-sum form, but bounded + denormal-safe). Canonical use: bring a filtered signal back up to the level of the unfiltered source. Silent `in` stays silent; silent `test` drives `in` toward zero; `tiny` (1e-10) guards the divide. Takes `mul`/`add`.
|
||||
|
||||
A single one-pole on `x²` ripples at twice the signal frequency, so a high `hp` lets that ripple modulate the gain (amplitude-modulation sidebands, worst on bass). `Balance` adds a second, **decoupled** one-pole on the gain via `smooth` (seconds): raise `hp` for fast level detection, then raise `smooth` to suppress the ripple independently. `smooth == 0` (default) bypasses the lag — bit-identical to the classic single-pole form. Set `logDomain: true` to smooth the gain in the **decibel (log) domain** instead: it smooths the level *difference in dB* (`log10(ms_test/ms_in)`) then exps back, so a `+6 dB` and a `−6 dB` correction glide with the same shape and time (symmetric, perceptually even — like an analogue auto-leveller), versus the default linear-gain lag which is faster on boosts than cuts. The log path costs one `log10` + one `exp` per sample and floors the power so silence stays finite.
|
||||
|
||||
`Normalizer` (SC `Normalizer`) shares `LookAheadLimiter`'s ring-buffer + monotonic sliding-window-max deque, but its gain law is `level / windowPeak` applied unconditionally (vs the limiter's `maxAmp / windowPeak` only when over the ceiling), so quiet passages are scaled **up** and loud ones **down** to track `level`. Instant attack (no overshoot) + one-pole smoothed release (time constant `dur`); output delayed by `Int(dur·sampleRate)`. `sampleRate` is required at init. An exactly-silent window holds gain (no `level/0`); a near-silent non-zero window amplifies its noise floor toward `level` (intended normalizer behaviour).
|
||||
|
||||
All generators are single-channel in/out. Multi-channel use via MCE. `AmplitudeFollower`, `Compressor`, `Expander` conform to `GeneratorEnum`.
|
||||
|
||||
---
|
||||
@@ -1247,6 +1300,20 @@ LFTriangle.Audio(freq: 4.0, mul: 0.1) // gentle tremolo LFO
|
||||
LFDutyCycle.Audio(freq: 6.0, dutyCycle: 0.2)
|
||||
```
|
||||
|
||||
### LFGauss (SC `LFGauss`)
|
||||
Gaussian bell-shaped oscillator. Over each `period` (seconds) the output traces a Gaussian bell — near `0` at the period boundaries, peaking at `1.0` at the period midpoint. `width` is the standard deviation as a fraction of the half-period (smaller → narrower spike). Output range `(0, 1]`. A smooth non-band-limited LFO and a ready-made grain-window shape. Paired `GeneratorEnum` (Audio + Control). `period` and `width` accept generator inputs; `phase` is an init-only `[0, 1)` offset (`0` starts at a trough, `0.5` at the peak).
|
||||
|
||||
```
|
||||
x = 2·phase − 1 (phase advances 1 / (period · sr) per sample)
|
||||
out = exp(−0.5 · (x / width)²)
|
||||
```
|
||||
|
||||
```swift
|
||||
LFGauss.Audio(period: 0.02, width: 0.15) // ~50 Hz bell-train LFO
|
||||
LFGauss.Audio(period: 0.5, width: 0.1, phase: 0.0) // grain envelope, starts at trough
|
||||
LFGauss.Control(period: 2.0, width: 0.25) // slow swell
|
||||
```
|
||||
|
||||
### WavetableMorph
|
||||
Linear-interpolation wavetable scanner across an array of equal-length mono `LyrebirdBuffer` tables. `position` ∈ `[0, table_count − 1]` selects between adjacent tables; fractional positions blend.
|
||||
|
||||
@@ -1266,6 +1333,78 @@ WavetableMorph.Audio(
|
||||
|
||||
---
|
||||
|
||||
## Chaotic / Strange-Attractor Oscillators
|
||||
|
||||
`Generators/Chaotic/`. Oscillators that iterate a discrete chaotic map at a chosen `freq` (iterations/sec, **not** once per sample) and bridge successive iterations with `interpolation` (`.none` held/aliased, `.linear`, `.cubic`). Shared base `ChaoticBase` (analogous to `NoiseBase`) owns `freq`, `mulAdd`, the interpolation kernel, a 4-value history ring, and the sub-iteration phase accumulator; per-map `_Base` subclasses add the map variables + `iterate()`. `freq` and map parameters are read once per block (no per-sample audio-rate modulation). `Control` advances one audio block per call and ramps via `fillRampedResult`. `Crackle` (under Noise) is the only per-sample chaotic map and is unrelated to this family.
|
||||
|
||||
### LorenzLinear (SC `LorenzL`)
|
||||
Lorenz strange attractor by forward Euler (`x' = x + h·s·(y−x)`, etc.), output = `x`. Default `interpolation: .linear`. Output is the **raw** `x` coordinate (`|x|` ≲ 25 on the attractor) — scale with `mul`. The Euler step `h` defaults to `0.02`: SC's nominal `0.05` diverges under plain forward Euler (verified — blows up within ~25 steps), so keep `h` below ~0.03.
|
||||
|
||||
```swift
|
||||
LorenzLinear.Audio(freq: 22050.0, mul: 0.05) // classic attractor tone, scaled to ~[-1,1]
|
||||
LorenzLinear.Control(freq: 200.0, mul: 0.05) // slow chaotic LFO
|
||||
```
|
||||
|
||||
### HenonStepped (SC `HenonN`)
|
||||
Hénon map `x[n+1] = 1 − a·x[n]² + b·x[n−1]`, output = `x`. Default `interpolation: .none` (held/stepped — the aliased SC `HenonN` character). Canonical `a = 1.4`, `b = 0.3` → bounded chaotic orbit in roughly `[-1.5, 1.5]`.
|
||||
|
||||
```swift
|
||||
HenonStepped.Audio(freq: 22050.0) // gritty stepped chaos
|
||||
HenonStepped.Audio(freq: 8000.0, interpolation: .cubic) // smoothed
|
||||
```
|
||||
|
||||
### QuadStepped (SC `QuadN`)
|
||||
General quadratic map `x[n+1] = a·x[n]² + b·x[n] + c`, output `x`, default `.none`. Canonical `a = 1`, `b = −1`, `c = −0.75` → chaotic, bounded ~`[-1.25, 1.25]` (conjugate to the logistic map).
|
||||
|
||||
```swift
|
||||
QuadStepped.Audio(freq: 6000.0)
|
||||
```
|
||||
|
||||
### LinCongStepped (SC `LinCongN`)
|
||||
Linear-congruential map `x[n+1] = (a·x[n] + c) mod m`, output stays in `[0, m)`, default `.none`. Canonical `a = 1.1`, `c = 0.13`, `m = 1`.
|
||||
|
||||
```swift
|
||||
LinCongStepped.Audio(freq: 6000.0) // output in [0, 1)
|
||||
LinCongStepped.Audio(freq: 6000.0, mul: 2.0, add: -1.0) // bipolarised to [-1, 1)
|
||||
```
|
||||
|
||||
### GbmanStepped (SC `GbmanN`)
|
||||
Gingerbreadman map `x[n+1] = 1 − y[n] + |x[n]|`, `y[n+1] = x[n]`; output `x`, default `.none`. No shape parameters — only initial conditions `xi`/`yi`. Bounded chaotic (`|x| ≲ 8`).
|
||||
|
||||
```swift
|
||||
GbmanStepped.Audio(freq: 6000.0, mul: 0.2)
|
||||
```
|
||||
|
||||
### StandardStepped (SC `StandardN`)
|
||||
Chirikov standard map (kicked rotor): `y' = (y + k·sin(x)) mod 2π`, `x' = (x + y') mod 2π`; output `x` ∈ `[0, 2π)`. Larger `k` → stronger chaos (default `1`). Scale with `mul: 1/π, add: -1` for `[-1, 1)`.
|
||||
|
||||
```swift
|
||||
StandardStepped.Audio(freq: 6000.0, k: 1.0)
|
||||
```
|
||||
|
||||
### FBSineStepped (SC `FBSineN`)
|
||||
Feedback sine map: `x' = sin(im·y + fb·x)`, `y' = (a·y + c) mod 2π`; output `x` ∈ `[-1, 1]`. Defaults `im=1`, `fb=0.1`, `a=1.1`, `c=0.5`.
|
||||
|
||||
```swift
|
||||
FBSineStepped.Audio(freq: 6000.0)
|
||||
```
|
||||
|
||||
### LatoocarfianStepped (SC `LatoocarfianN`)
|
||||
Pickover's Latoocarfian: `x' = sin(b·y) + c·sin(b·x)`, `y' = sin(a·x) + d·sin(a·y)`; output `x` ∈ ~`[-1.5, 1.5]`. Chaos generally needs `|a|, |b| ≤ 3` (defaults `a=1`, `b=3`, `c=d=0.5`).
|
||||
|
||||
```swift
|
||||
LatoocarfianStepped.Audio(freq: 6000.0)
|
||||
```
|
||||
|
||||
### CuspStepped (SC `CuspN`)
|
||||
Cusp map: `x' = a − b·√|x|`; output `x`. Canonical `a=1`, `b=1.9` → chaotic, bounded ~`[-0.9, 1.0]`.
|
||||
|
||||
```swift
|
||||
CuspStepped.Audio(freq: 6000.0)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## EnvelopePoll
|
||||
|
||||
Read a fixed-shape `Envelope` at arbitrary times. Output is the envelope's level at `time` seconds. No internal phase or trigger — purely a value lookup. Useful for driving filter cutoff curves, panning trajectories, or pattern-driven scoring.
|
||||
@@ -1323,6 +1462,18 @@ Lag2UpDown.Control(input: $sig, lagUp: 0.01, lagDown: 0.3) // cascade asymmetri
|
||||
- `time`, `lagUp`, `lagDown` are 60 dB time constants in seconds.
|
||||
- All accept audio-rate inputs; coefficient recomputation per block.
|
||||
|
||||
### Slew
|
||||
Linear slew-rate limiter. Equivalent to SuperCollider `Slew`. Moves the output toward `input` at a maximum rate of `up` units per second when rising and `dn` units per second when falling. On the first block the output is initialised directly to the first input value.
|
||||
|
||||
```swift
|
||||
Slew.Audio(input: controlSignal, up: 500.0, dn: 200.0) // asymmetric slopes
|
||||
Slew.Control(input: $cv, up: 100.0, dn: 100.0) // smooth CV at control rate
|
||||
```
|
||||
|
||||
- `up` / `dn` are slopes in **units per second** (not per sample). The per-sample step is `up / sampleRate` (audio) or `up / (sampleRate / blockSize)` (control).
|
||||
- **Linear** rate-limiting — distinct from the **exponential** smoothing produced by the `Lag` family. Use `Lag` for an RC-filter curve; use `Slew` for a linear ramp at a controlled maximum slope.
|
||||
- `Slew.Control` produces a flat output block (like `Lag.Control`); use `Slew.Audio` for smoothly interpolated output.
|
||||
|
||||
### Decay / Decay2 / LeakDC
|
||||
- **`Decay`**: One-pole exponential decay tail on each non-zero input sample. `decayTime` is the 60 dB decay time in seconds.
|
||||
- **`Decay2`**: Differenced pair of Decays — produces a percussive attack-then-release envelope from an impulse train.
|
||||
@@ -1358,6 +1509,36 @@ ResonatorBank.Audio(input: excitation, buffer: buffer)
|
||||
- Buffer `channelCount` precondition: `resonatorBankChannelCount` (= 3).
|
||||
- Each row is a complex resonator; bank is summed to mono output.
|
||||
|
||||
### Klank.Audio (SC `Klank`)
|
||||
Modulatable counterpart of `ResonatorBank` — parallel two-pole resonator bank with the three SC `Klank` block-rate modulation parameters. Spec buffer rows are `(freq, amp, decay)` (SC channel order). Audio-only.
|
||||
|
||||
```swift
|
||||
let spec = LyrebirdBuffer(count: 3, channelCount: klankSpecChannelCount) // freq, amp, decay
|
||||
// fill rows with N resonator specs
|
||||
Klank.Audio(input: excitation, buffer: spec,
|
||||
freqscale: 1.0, freqoffset: 0.0, decayscale: 1.0)
|
||||
```
|
||||
|
||||
- `freqscale` / `freqoffset` / `decayscale` are any `ValidGeneratorInput`, snapshotted once per audio block: `freq_eff = freq·freqscale + freqoffset`, `decay_eff = decay·decayscale`.
|
||||
- Buffer `channelCount` precondition: `klankSpecChannelCount` (= 3); channel indices `klankFreqChannel` / `klankAmpChannel` / `klankDecayChannel`.
|
||||
- Whole-table live swap via `setBuffer(_:engine:)` (RT-safe `RTBufferSlot`); new buffer must match the initial bank size. `freq_eff` floored at `0.1` Hz, `decay_eff` at `1e-6` s; `amp` unclamped.
|
||||
- Same vDSP per-sample kernel as `ResonatorBank`; summed to mono.
|
||||
|
||||
### Klang.Audio (SC `Klang`)
|
||||
Additive sine-partial bank — the source counterpart of `Klank` (no input). Outputs the sum of N table-lookup sines. Spec buffer rows are `(freq, amp, phase)` (SC channel order). Audio-only.
|
||||
|
||||
```swift
|
||||
let spec = LyrebirdBuffer(count: 4, channelCount: klangSpecChannelCount) // freq, amp, phase
|
||||
// fill rows with N partial specs
|
||||
Klang.Audio(buffer: spec, freqscale: 1.0, freqoffset: 0.0,
|
||||
interpolation: .linear)
|
||||
```
|
||||
|
||||
- `freqscale` / `freqoffset` snapshotted once per block: `freq_eff = freq·freqscale + freqoffset`.
|
||||
- `freq` / `amp` re-read from the table each block (live `setValue` + `setBuffer(_:engine:)` swap retune the bank). The `phase` channel seeds each partial's phase accumulator at `init` only — phases free-run thereafter, so table swaps never click.
|
||||
- Buffer `channelCount` precondition: `klangSpecChannelCount` (= 3); channel indices `klangFreqChannel` / `klangAmpChannel` / `klangPhaseChannel`.
|
||||
- `interpolation: TableInterpolation` (`.none` / `.linear` / `.cubic`) on the shared sine table; `amp` and `freq_eff` unclamped (negatives invert / reverse).
|
||||
|
||||
### MuTronIII.Audio / .Control
|
||||
*See [MuTronIII](#mutroniii) under Filters above for full description.*
|
||||
|
||||
@@ -1374,6 +1555,20 @@ RingingFilter(input: trig, freq: 440.0, bandwidth: 80.0) // tuned ringing
|
||||
- `Comb` / `Allpass` use a circular delay line allocated to `maxDelay × sampleRate`; `delay` and `decayTime` can be retuned per block. Feedback coefficient derives from the shared `combFeedbackCoeff(decayTime:delay:)` helper.
|
||||
- `Resonating` and `Ringing` are biquads tuned by `freq` + (`decayTime` | `bandwidth`).
|
||||
|
||||
### Formlet (SC `Formlet`)
|
||||
FOF-like resonant filter parameterised by `attackTime` / `decayTime` rather than `freq` + `Q`. The impulse response is a sine at `freq` under a rise-then-fall (Decay2-style) envelope — the basis of formant / vowel synthesis. Defined as the difference of two `ResonatingFilter` (Ringz) outputs at the same `freq`:
|
||||
|
||||
```
|
||||
Formlet(in, freq, attack, decay) == ResonatingFilter(in, freq, decay) − ResonatingFilter(in, freq, attack)
|
||||
```
|
||||
|
||||
Paired `GeneratorEnum` (Audio + Control). Reuses `runTwoPoleResonatorScalarBlock` / `…InterpolatedBlock` and `resonatingCoeffs`. `freq`, `attackTime`, `decayTime` all accept generator inputs (block-boundary coefficient interpolation).
|
||||
|
||||
```swift
|
||||
Formlet.Audio(input: impulse, freq: 880.0, attackTime: 0.001, decayTime: 0.1)
|
||||
Formlet.Control(input: trig, freq: 220.0, attackTime: 0.01, decayTime: 0.5)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Triggers
|
||||
@@ -1414,6 +1609,74 @@ SendTrigger.Control(trig: Impulse.Control(freq: 4.0), id: 7, value: $cutoff)
|
||||
- `id` is `Int32`, init-only.
|
||||
- Events delivered via the engine's lock-free `TriggerListener` queue.
|
||||
|
||||
### Trig
|
||||
SC `Trig`. On each ≤0 → >0 rising edge of `input`, captures the input value at that frame and outputs it for `dur` seconds, then returns to `0.0`. A new edge during the hold restarts the timer and re-captures the level.
|
||||
|
||||
```swift
|
||||
Trig.Audio(input: Impulse.Audio(freq: 4.0), dur: 0.1)
|
||||
Trig.Control(input: envTrig, dur: 0.5)
|
||||
```
|
||||
|
||||
- `dur`: hold duration in seconds (init-time scalar; converted to samples via engine sample rate; minimum 1 sample).
|
||||
- The `input` signal is both the trigger source and the level captured on each rising edge.
|
||||
|
||||
### Trig1
|
||||
SC `Trig1`. Identical to `Trig` but always outputs `1.0` (unity) regardless of the input level for `dur` seconds after each ≤0 → >0 rising edge. Useful for generating fixed-amplitude gate pulses.
|
||||
|
||||
```swift
|
||||
Trig1.Audio(input: Impulse.Audio(freq: 4.0), dur: 0.05)
|
||||
Trig1.Control(input: envTrig, dur: 0.2)
|
||||
```
|
||||
|
||||
- `dur`: hold duration in seconds (init-time scalar; minimum 1 sample).
|
||||
|
||||
### TriggeredDelay
|
||||
SC `TDelay`. Delays a trigger by `dur` seconds: on a ≤0 → >0 rising edge of `input`, starts a countdown. When the countdown elapses, emits a single-sample `1.0`. Additional edges arriving while the countdown is active are **ignored** (only the first edge per idle cycle is honoured).
|
||||
|
||||
```swift
|
||||
TriggeredDelay.Audio(input: Impulse.Audio(freq: 2.0), dur: 0.2)
|
||||
TriggeredDelay.Control(input: clockTrig, dur: 0.1)
|
||||
```
|
||||
|
||||
- `dur`: delay duration in seconds (init-time scalar; minimum 1 sample).
|
||||
|
||||
### PulseCount
|
||||
SC `PulseCount`. Running counter that increments by 1 on each ≤0 → >0 rising edge of `trig`. A rising edge of `reset` clears the counter to `0.0` before the `trig` increment at that sample.
|
||||
|
||||
```swift
|
||||
PulseCount.Audio(trig: Impulse.Audio(freq: 4.0))
|
||||
PulseCount.Control(trig: clock, reset: resetTrig)
|
||||
```
|
||||
|
||||
- Counter is never clamped and grows without bound.
|
||||
|
||||
### Stepper
|
||||
SC `Stepper`. Wrapping integer step counter. On each rising edge of `trig`, advances by `step` within `[min, max]`, wrapping at the boundaries. `reset` returns the value to `resetval`. All range/step/reset parameters are init-time scalars.
|
||||
|
||||
```swift
|
||||
// 8-step sequencer index cycling 0..7
|
||||
Stepper.Audio(trig: Impulse.Audio(freq: 4.0), min: 0, max: 7, step: 1, resetval: 0)
|
||||
Stepper.Control(trig: clock, reset: resetSig, min: 0, max: 15)
|
||||
```
|
||||
|
||||
- `min`, `max`: range (inclusive). `max` must be ≥ `min`. Defaults: `0` / `7`.
|
||||
- `step`: signed increment per edge. Defaults to `1`. Negative values step downward.
|
||||
- `resetval`: value written on a reset edge; clamped to `[min, max]`. Defaults to `0`.
|
||||
|
||||
### Schmidt
|
||||
SC `Schmidt`. Schmitt trigger with hysteresis. Maintains binary `0.0` / `1.0` state with separate switch-on (`hi`) and switch-off (`lo`) thresholds. Prevents chatter near the threshold.
|
||||
|
||||
- State `0.0` → `1.0`: when `input > hi`.
|
||||
- State `1.0` → `0.0`: when `input < lo`.
|
||||
- In the hysteresis band `[lo, hi]`: state unchanged.
|
||||
|
||||
```swift
|
||||
Schmidt.Audio(input: amp, lo: 0.1, hi: 0.3)
|
||||
Schmidt.Control(input: $cv, lo: 0.2, hi: 0.8)
|
||||
```
|
||||
|
||||
- `lo`, `hi`: any `ValidGeneratorInput` — scalar literals, `ParameterNode`, `@LiveParam`, or audio/control-rate generators. When using audio-rate generators for per-sample varying thresholds, ensure they conform to `Generator` (not `Closure`).
|
||||
|
||||
---
|
||||
|
||||
## Random Generators
|
||||
@@ -2255,3 +2518,111 @@ let onset = OnsetDetector.Control(analysis: analysis, method: .spectralFlux,
|
||||
- `OnsetDetector` exposes `OnsetDetectionMethod` enum (`.spectralFlux`, `.complexDomain`, etc.); fires `1.0` for one block at each detected onset.
|
||||
|
||||
---
|
||||
|
||||
## Time-Domain Analysis
|
||||
|
||||
Four SuperCollider-parity time-domain analysis and measurement generators. Source files live in `Sources/Lyrebird/Generators/Analysis/`.
|
||||
|
||||
| Generator | SC equivalent | Audio | Control | Description |
|
||||
|-----------|--------------|-------|---------|-------------|
|
||||
| `ZeroCrossing` | `ZeroCrossing` | yes | yes | Frequency estimate (Hz) from rising zero-crossing spacing. Output held between crossings; `0.0` until the first full period is measured. |
|
||||
| `Slope` | `Slope` | yes | yes | Per-second rate of change: `(x[n] − x[n−1]) × sampleRate`. First sample/block outputs `0.0` (lazy init — no startup spike). |
|
||||
| `RunningMin` | `RunningMin` | yes | yes | Running minimum since the last trigger reset. Lazy-initialised to the first input value. Rising `trig` edge resets to the current input. |
|
||||
| `RunningMax` | `RunningMax` | yes | yes | Running maximum since the last trigger reset. Identical behaviour to `RunningMin` but tracking the maximum. |
|
||||
|
||||
All four are paired generators conforming to `GeneratorEnum`. `Control` variants bypass the sub-block loop (scan the full audio-rate input block once per audio cycle and output a flat result).
|
||||
|
||||
```swift
|
||||
// Frequency estimation.
|
||||
let zcFreq = ZeroCrossing.Audio(input: audioSignal)
|
||||
let zcFreqCtl = ZeroCrossing.Control(input: audioSignal) // block-rate measurement
|
||||
|
||||
// Rate-of-change differentiation.
|
||||
let diff = Slope.Audio(input: envelope) // per-sample differentiation
|
||||
let diffCtl = Slope.Control(input: $cv) // block-rate differentiation
|
||||
|
||||
// Peak / trough tracking.
|
||||
let peakTracker = RunningMax.Audio(input: signal)
|
||||
let peakTrackerReset = RunningMax.Audio(input: signal, trig: resetClock)
|
||||
let troughTracker = RunningMin.Control(input: $cv, trig: gate)
|
||||
```
|
||||
|
||||
Parameters common to all four:
|
||||
- `input`: signal to analyse (`any ValidGeneratorInput`)
|
||||
- `mul`: output multiplier, default `1.0`
|
||||
- `add`: output offset, default `0.0`
|
||||
- `RunningMin` / `RunningMax` additionally accept `trig` (default `0.0`)
|
||||
|
||||
---
|
||||
|
||||
## Waveshaping / Distortion
|
||||
|
||||
Transfer-function and stochastic distortion generators. Source files live in
|
||||
`Sources/Lyrebird/Generators/Waveshaping/`.
|
||||
|
||||
| Generator | SC equivalent | Audio | Control | Description |
|
||||
|-----------|--------------|-------|---------|-------------|
|
||||
| `Waveshaper` | `Shaper` | yes | yes | Table-lookup transfer-function waveshaper. Input clamped to `[-1, 1]` before linear-interpolated table lookup. RT-safe live table swap via `setTable(_:engine:)`. |
|
||||
| `CrossoverDistortion` | `CrossoverDistortion` | yes | yes | Dead-zone / crossover distortion. Signals in `[-amp, amp]` are silenced; signals outside that range are shifted toward zero. Optional C¹ smooth knee. |
|
||||
| `Disintegrator` | `Disintegrator` | yes | — | Stochastic sample-dropping distortion. Each sample is independently disintegrated (replaced by `input × multiplier`) with probability `probability`. Audio-only. |
|
||||
|
||||
`Waveshaper` and `CrossoverDistortion` conform to `GeneratorEnum`. `Disintegrator` is Audio-only and does not.
|
||||
|
||||
### Waveshaper (SC `Shaper`)
|
||||
|
||||
Transfer-function waveshaper using a `LyrebirdBuffer` as the transfer curve.
|
||||
|
||||
```swift
|
||||
let table = LyrebirdBuffer(count: 1024)
|
||||
table.fill { i, n in
|
||||
let x = Double(i) / Double(n - 1) * 2.0 - 1.0
|
||||
return tanh(x * 4.0) // soft saturation
|
||||
}
|
||||
let shaper = Waveshaper.Audio(table: table, input: signal)
|
||||
let lfoShaper = Waveshaper.Control(table: table, input: lfoSignal)
|
||||
```
|
||||
|
||||
- `table`: mono `LyrebirdBuffer` (at least 2 samples). The transfer curve is indexed by the clamped input `x ∈ [-1, 1]` via `pos = (x × 0.5 + 0.5) × (tableSize − 1)` with linear interpolation.
|
||||
- `input`: signal to waveshape. Values outside `[-1, 1]` are clamped (saturating, not wrapping).
|
||||
- `mul` / `add`: standard output multiplier and offset.
|
||||
- `setTable(_:engine:)`: RT-safe live table swap. New table must be mono and same size as the initial table.
|
||||
|
||||
### CrossoverDistortion (inspired by SC `CrossoverDistortion`)
|
||||
|
||||
Crossover / dead-zone distortion with optional smooth knee. The implementation is a clean
|
||||
owned formula — not claimed bit-exact with SuperCollider, but sharing the same conceptual model.
|
||||
|
||||
```swift
|
||||
// Hard-knee crossover: dead zone ±0.5, then linear continuation.
|
||||
let dist = CrossoverDistortion.Audio(input: signal, amp: 0.5, smooth: 0.0)
|
||||
|
||||
// Soft-knee: C¹ quadratic ease-in at the dead-zone boundary.
|
||||
let softDist = CrossoverDistortion.Audio(input: signal, amp: 0.3, smooth: 0.5)
|
||||
```
|
||||
|
||||
- `amp`: dead-zone half-width (≥ 0). Signals in `[−amp, amp]` are zeroed. **Not an output gain** — use `mul` for gain. SC also names this `amp`.
|
||||
- `smooth`: knee smoothness `[0, 1]`. `0` = hard knee (instantaneous transition); `1` = full-width C¹ ease-in over the full dead-zone width.
|
||||
- Transfer function: for `|x| > amp`, `over = |x| − amp`. Hard-knee: `out = sign(x) × over`. Soft-knee: `out = sign(x) × over² / (2 × kneeWidth)` within the knee, then linear continuation maintaining C¹ continuity.
|
||||
|
||||
### Disintegrator (SC `Disintegrator`)
|
||||
|
||||
Stochastic sample-dropping distortion. Audio-only — "block-rate disintegration" has no
|
||||
meaningful physical interpretation; the random draw must happen per sample.
|
||||
|
||||
```swift
|
||||
// Drop ~50 % of samples to silence.
|
||||
let dist = Disintegrator.Audio(input: signal, probability: 0.5, multiplier: 0.0)
|
||||
|
||||
// Attenuate ~30 % of samples by half.
|
||||
let grit = Disintegrator.Audio(input: signal, probability: 0.3, multiplier: 0.5)
|
||||
|
||||
// Deterministic seed for tests.
|
||||
let det = Disintegrator.Audio(input: signal, probability: 0.5, seed: 42)
|
||||
```
|
||||
|
||||
- `probability`: `[0, 1]` chance per sample of disintegration. Clamped internally.
|
||||
- `multiplier`: scale factor applied to disintegrated samples. `0.0` → silence; `1.0` → no change (same as `probability = 0`).
|
||||
- `seed`: optional PRNG seed. `nil` = time-derived unique seed; explicit value = deterministic/reproducible output.
|
||||
- `mul` / `add`: applied after disintegration to all samples (including undisintegrated ones).
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user