From 56726223f636da17e23be289742cc27a78da1e03 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Sun, 29 Nov 2026 13:57:47 -0800 Subject: [PATCH] =?UTF-8?q?v2.3.2=20release:=20README=20=E2=80=94=20add=20?= =?UTF-8?q?a=20'write=20your=20own=20Generator'=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a complete HardClip audio-rate distortion to the quick-taste section, showing GeneratorBase + AudioGenerator conformance, init-time input resolution, the _checkCount guard, and filling/returning the pre-allocated _result in place — the Generator-authoring counterpart to the existing graph-composition example. Co-Authored-By: Claude Opus 4.8 --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index d6f143c..c5287bc 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,42 @@ let env = EnvelopeGen.Control(envelope: Envelope( let voice = carrier * env * 0.2 // ready to route to a bus ``` +### Generators — or write your own + +A Generator is an RT-safe DSP node: subclass `GeneratorBase`, conform to `AudioGenerator`, fill the inherited pre-allocated `_result` buffer, and return it. No allocation, locks, or runtime type checks on the render thread — inputs are classified once at `init`. This is a complete hard-clip distortion: + +```swift +import LyrebirdSynth + +/// Hard-clip distortion — clamps its input signal to ±`level`. +final class HardClip: GeneratorBase, AudioGenerator { + private let input: any ValidGeneratorInput + private let level: Double + + init(input: any ValidGeneratorInput, level: Double = 0.5) { + self.input = input._resolvedInput() // resolve/classify inputs off the RT thread + self.level = level + super.init() // allocates _result: one mono channel, 512 frames + } + + func _computeSamples(graph: SynthGraph, count: Int) -> [[Double]] { + _checkCount(count) // bounds guard — no force-unwraps on the RT thread + guard let signal = input.calculatedSamples(graph: graph, count: count).first else { + return _result + } + for i in 0..