Mirror of Lyrebird dev HEAD (9f791c7c) minus maintainer-only paths. Patch release: fixes the allpass fractional-delay click (DelayLine/CombFilter/AllpassFilter/ DelayLineFeedback under a modulated delay) and lands the internal code-quality consolidation pass (~160 deduped sites + shared base classes/helpers, bit-identical output). No public API removed or changed. See RELEASES.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9.1 KiB
Lyrebird Extension SDK
This document lists the public surface available to out-of-tree Swift packages that add
Generator or Synthesizer implementations on top of the Lyrebird core module.
The surface is split into two stability tiers:
- Stable public API — covered by Lyrebird's SemVer. Breaking changes only on a MAJOR version bump.
@_spi(LyrebirdExtensions)API — low-level RT helpers that extension packages need to implement generators correctly. Signatures may evolve in MINOR releases; pin tightly if you depend on these (.upToNextMinor(from:)).
Importing
import LyrebirdSynth // stable public API
@_spi(LyrebirdExtensions) import LyrebirdSynth // stable + SPI helpers
Only declare the SPI import in files that need it. Consumers of your extension package never need the SPI import — they import your module and use its public types.
Tier 1 — Stable public API
Generator protocol & base
| Symbol | File |
|---|---|
protocol Generator |
GeneratorCore/Generator.swift |
protocol AudioGenerator |
GeneratorCore/Generator.swift |
protocol ControlGenerator |
GeneratorCore/Generator.swift |
class GeneratorBase |
GeneratorCore/GeneratorBase.swift |
protocol GeneratorEnum |
GeneratorCore/GeneratorTypes.swift |
enum ProcessingRate |
GeneratorCore/GeneratorTypes.swift |
class GeneratorArray |
GeneratorCore/GeneratorArray.swift |
+ - * / operators on GeneratorArray |
GeneratorCore/GeneratorArray.swift |
func expand<G: Generator>(...) |
GeneratorCore/GeneratorArray.swift |
Generator input
| Symbol | File |
|---|---|
protocol ValidGeneratorInput |
GeneratorCore/ValidGeneratorInput.swift |
protocol ConstantGeneratorInput |
GeneratorCore/ValidGeneratorInput.swift |
struct Closure |
GeneratorCore/ValidGeneratorInput.swift |
typealias ClosureBody |
GeneratorCore/ValidGeneratorInput.swift |
GeneratorBase storage (you read/write these in your subclass)
| Symbol | Visibility |
|---|---|
var _segmentSerial: UInt64 |
public |
var _cachedResult: [[Double]] |
public |
var _subBlockBuffer: [[Double]] |
public |
func _setupSubBlockBuffer(channels: Int = 1) |
public |
Synthesizer side (parameter & graph)
| Symbol | File |
|---|---|
struct SynthGraph |
Synthesizer/SynthGraph.swift |
class SynthesisEngine |
Engine/SynthesisEngine.swift |
@propertyWrapper struct LiveParam |
Parameters/LiveParam.swift |
protocol LiveParameterWrapper |
Parameters/LiveParam.swift |
protocol LiveParameterValue |
Parameters/LiveParam.swift |
final class ParameterNode |
Parameters/ParameterNode.swift |
Resources / data types
| Symbol | File |
|---|---|
struct HRIRFile |
Buffers/HRIRFile.swift |
let lyrebirdDefaultResultBufferSize: Int |
Math/LyrebirdConstants.swift |
Tier 2 — @_spi(LyrebirdExtensions) API
These RT-safe helpers are mandatory when implementing new generators. They are SPI to keep the public Lyrebird API surface small for application code, but are stable enough to use across MINOR versions; pin extension packages to a specific MINOR range and bump explicitly when Lyrebird's MINOR rolls over.
MulAdd helpers (GeneratorCore/MulAdd.swift)
| Symbol | Signature |
|---|---|
struct MulAddSpec |
stored mul/add inputs + precomputed identity flag |
MulAddSpec.init(mul:add:) |
call at init time |
MulAddSpec.applyIfNeeded(to:graph:count:) |
call at end of _computeSamples |
MulAddSpec.apply(to:graph:count:) |
unconditional apply (rare; prefer applyIfNeeded) |
MulAddSpec.identity |
static — for generators with no mul/add knobs |
func extractScalar(_:) |
init-time scalar detection |
func fillRampedResult(into:from:to:mulAdd:graph:count:) |
ControlGenerator ramp helper |
Input resolution helpers (GeneratorCore/InputResolutionHelpers.swift)
| Symbol | Signature |
|---|---|
func firstGeneratorSampleOrFloat(_:isGenerator:graph:count:) |
block-constant capture — first sample of a generator input (ramp start); oscillator/LF/noise Control paths |
func lastGeneratorSampleOrFloat(_:isGenerator:graph:count:) |
block-constant capture — last sample of a generator input (ramp endpoint); dynamics + delay-time paths |
Scratch buffers (Buffers/RTScratchBuffer.swift)
| Symbol | Signature |
|---|---|
struct RTScratchBuffer<Element>: ~Copyable |
single-owner heap scratch buffer; compiler-enforced single free at deinit, no ARC |
RTScratchBuffer.init(count:) |
allocate + zero-fill (Element: Numeric) |
RTScratchBuffer.init(count:repeating:) |
allocate + fill with a value |
RTScratchBuffer.baseAddress / .count / subscript |
@inline(__always); baseAddress for vDSP / Accelerate / memcpy interop |
Replaces the hand-paired UnsafeMutablePointer.allocate / deinitialize /
deallocate in a scratch-owning generator. Store as a let assigned in init
(never a per-call local) so deinit frees off the RT thread. Not for
[UnsafeMutablePointer] per-channel arrays (a ~Copyable type cannot be
Array-stored) or capacity-1 scalar boxes used via .pointee — leave those raw.
PRNG (Generators/Noise/WhiteNoise.swift)
| Symbol | Signature |
|---|---|
func xorshift64NextRaw(_:) |
raw UInt64 step |
func xorshift64Next(_:) |
step → Double in [-1, 1] |
Test-helper hooks (Engine/SynthesisEngine.swift)
For out-of-tree extension packages building their own advanceBlock-style test helpers:
| Symbol | Signature |
|---|---|
SynthesisEngine.segmentSerial |
acquiring load (read-only) |
SynthesisEngine.advanceSegmentSerial() |
wrapping increment — call between back-to-back calculatedSamples calls in tests to simulate a block boundary |
Versioning policy
Lyrebird 1.x:
-
Stable public API: SemVer. Breaking change → 2.0.
-
@_spi(LyrebirdExtensions)API: signatures may change in MINOR releases. Extension packages should pin tightly:.package(url: "...Lyrebird", "1.4.0"..<"1.5.0")
Namespacing guidance
- Module name: prefer
Lyrebird<Vendor>(e.g.LyrebirdATK). Swift module names already prevent type collisions; the prefix makes the dependency obvious inPackage.swift. - Type prefix: match your domain (
Foa*,Hoa*,Pd*, …). Keep it short and consistent within the package. - Parameter-key prefix: when your
Synthesizerreads parameters by string key, prefix them ("atk.azimuth", not"azimuth") to avoid collisions in user code that mixes multiple extension packages.
Reviewing your extension package — lyrebird_external_review
Out-of-tree packages run their custom Generator / Synthesizer code on the same real-time
audio thread as the core, under the same hard constraints (no allocation, locks, force unwraps,
or runtime type checks in _computeSamples; _checkCount first; pre-allocated, never-resized
buffers; input classification at init). The Lyrebird-internal lyrebird_review skill assumes
the Lyrebird repo's branch-and-phase workflow and docs/00-working-order.md, so it is the wrong
tool for an external package.
For that case there is a dedicated skill: lyrebird_external_review. It applies the same
RT-safety and protocol-correctness checks, but adapted for a package that merely depends on
Lyrebird:
- Builds a review diff from local changes (committed or not, including new untracked files),
or against a base ref you name — no
main-branch assumption. - Locates the vendored Lyrebird source (
.build/checkouts/Lyrebird/Sources/Lyrebird/) and points the reviewer at it, so new generators are compared against canonical analogs (e.g.ZeroCrossing) and helper signatures are verified against the real API. - Runs the project's own test suite (
swift test,--no-parallelif multi-engine flakes appear). - Invokes
lyrebird_review_agent(RT safety, protocol conformance, shared-helper usage, unit-test coverage for new generators) plus a terse line-level sweep, in parallel. - Skips all Lyrebird-internal bookkeeping (phase history, working-order docs, the
Sources/Lyrebird/subfolder taxonomy, agent/skill mirror sync) and treats file-organisation and header conventions as the project's to set — flagged as nits, never blockers.
Usage — from the root of the dependent package (e.g. a ShoeGaze checkout or any
Lyrebird<Vendor> extension repo):
/lyrebird_external_review
Optionally pass a base ref to scope the diff (/lyrebird_external_review v0.3.0). Fix any
blocking findings and re-run until clean.
The skill ships with Lyrebird at claude/skills/lyrebird_external_review/ (installer source,
copied into a consuming project by claude/install.sh) and is mirrored at
.claude/skills/lyrebird_external_review/ for auto-discovery when working inside this repo.
Install it into your extension package so contributors get the same pre-merge RT review you get
in-tree.
See also
- Writing Generators — full generator-author guide.
docs/extension-authors-guide.md— end-to-end walkthrough of building and publishing an extension package, usingLyrebirdATKas a worked example.