# Lyrebird A native macOS, iOS, and Linux audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles platform audio I/O (Core Audio on Apple, ALSA on Linux) and signal graph evaluation with no heap allocation on the real-time thread. Informed by 20+ years of SuperCollider practice, adapted to Swift idioms and a single-process architecture. --- ## Try it — run a demo The fastest way in is a demo project, not a snippet to copy. Each demo under [`Demos/`](Demos/) is a standalone SwiftPM package that depends on this checkout, so `swift run` from its folder builds and runs it — on **macOS** (Xcode optional) and **Linux** (VS Code optional), no project file to open: ```bash git clone https://git.lyrebirdsynth.net/josh/Lyrebird.git cd Lyrebird (cd Demos/LyrebirdQuickstartDemo && swift run) # a 440 Hz sine — the shortest path to sound (cd Demos/LyrebirdNRTDemo && swift run) # offline render → an audio file, no sound device needed (cd Demos/LyrebirdDemo && swift run) # a fuller reverb smoke-test through your default output ``` These three run the same on macOS and Linux. Each has a `Synthesizers/` folder — drop a `SynthesizerBase` subclass in, re-run, and you are building your own voice. The GUI demos (SwiftUI on macOS/iOS; the GTK4 UI on Linux) and the full list are under [Demo projects](#demo-projects). On Linux the live-audio demos need `libasound2-dev`; the offline NRT demo needs nothing. Full Linux setup is in the [On Linux](#on-linux--vs-code-or-any-editor-no-xcode) notes and [`docs/linux-getting-started.md`](docs/linux-getting-started.md). --- ## A quick taste Three layers, each usable on its own: **Generators** are the unit signal graph, **Synthesizers** package a graph plus live parameters into a playable voice, and the **Engine** drives the platform audio backend (Core Audio on Apple, ALSA on Linux) and schedules voices sample-accurately. ### Generators — compose a signal graph with operators Generators are pure DSP nodes. Standard arithmetic operators (`+ - * /`) wire them together; literals coerce to constants automatically. This is a two-operator FM voice expressed as a plain graph: ```swift import LyrebirdSynth // Modulator → carrier FM, shaped by an amplitude envelope. let modIndex = 3.0 let modulator = OscSin.Audio(freq: 220.0) * (440.0 * modIndex) let carrier = OscSin.Audio(freq: 440.0 + modulator) // frequency modulation let env = EnvelopeGen.Control(envelope: Envelope( levels: [0, 1, 0.7, 0], durations: [0.02, 1.5, 0.5], curves: [2, 0, -3.5])) 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.. interactive shell lyrebird repl # Swift REPL with Lyrebird importable lyrebird --version ``` Arrow-key editing, tab completion, persistent history (`~/.lyrebird_history`). `import LyrebirdSynth` works immediately inside the REPL session. Full CLI reference: [`docs/tooling/cli-guide.md`](docs/tooling/cli-guide.md). Project scaffolding templates: [`docs/tooling/project-system.md`](docs/tooling/project-system.md). --- ## Extensions Lyrebird supports out-of-tree Swift packages that add `Generator` or `Synthesizer` implementations. Extension packages depend on Lyrebird via SwiftPM, host their own source, and ship their own version releases — core users pin the version range they want. Building your own extension package: - **API contract**: [`docs/protocols/extension-sdk.md`](docs/protocols/extension-sdk.md) — tier-1 stable public surface + tier-2 `@_spi(LyrebirdExtensions)` symbols and versioning policy. - **Walk-through**: [`docs/extension-authors-guide.md`](docs/extension-authors-guide.md) — end-to-end build a new extension package. --- ## Project structure ``` LyrebirdII/ ├── LYREBIRD_START_HERE.md ← start here for demo projects ├── Package.swift ├── Sources/ │ ├── Lyrebird/ # core framework — Generator, Synthesizer, engine │ ├── LyrebirdUI/ # SwiftUI views — LyrebirdScopeView, LyrebirdStatusView, LyrebirdEnvelopeView │ ├── LyrebirdCLI/ # lyrebird CLI binary │ └── LyrebirdDemo/ # macOS CLI hardware smoke-test ├── Demos/ │ ├── LyrebirdQuickstartDemo/ # fastest sound — SineTone plays 10 s then exits │ ├── LyrebirdDemo/ # (same as Sources/LyrebirdDemo — workspace target) │ ├── LyrebirdGUIDemo/ # cross-platform GUI — SwiftUI (macOS) + GTK4 (Linux), one source │ ├── LyrebirdMacOSDemo/ # macOS SwiftUI app │ ├── LyrebirdiOSDemo/ # iOS SwiftUI app │ ├── LyrebirdNRTDemo/ # offline renderer │ ├── LyrebirdScoreDemo/ # notated Score → MusicXML + offline render │ ├── LyrebirdAUv3Demo/ # AUv3 `aumu` plugin reference (LyrebirdFM) │ └── LyrebirdScratch/ # live-coding scratchpad (macOS, no sandbox) ├── Tests/ │ ├── LyrebirdTests/ # 5253 engine + generator tests │ ├── LyrebirdUITests/ # SwiftUI component tests │ └── LyrebirdCLITests/ # CLI tests └── docs/ ├── 00-working-order.md # active phase plan ├── engine/ ├── protocols/ ├── signal-flow/ ├── stdlib/ ├── tooling/ └── ui/ ``` --- ## Documentation ### API reference (DocC) & in-editor help Lyrebird ships a DocC catalog for the `Lyrebird` and `LyrebirdUI` modules (built via the [swift-docc-plugin](https://github.com/apple/swift-docc-plugin)). Every public Generator, Synthesizer, and engine type carries doc comments, and each Generator's `init` parameters are documented (unit, range, default) so help is useful from both the symbol and the call site. **In Xcode — browse the full reference:** 1. Select a framework scheme (`Lyrebird-Package`, or your app target). 2. **Product ▸ Build Documentation** (⌃⇧⌘D). The compiled docs open in the Developer Documentation window. 3. Reopen any time with **Window ▸ Developer Documentation** (⇧⌘0) and search for `Lyrebird`, a generator (`OscSin`), or a protocol (`Generator`). **In Xcode — contextual / Quick Help (inline, while coding):** - **Option-click** any symbol (type, method, `init` parameter) for a Quick Help popover. - Or open the **Quick Help inspector** (⌥⌘2) and click into a symbol — it tracks the cursor. - Hovering an `init` shows each parameter's doc (e.g. `freq` — Hz, no clamping; `q` — `0.707` = Butterworth). Place the cursor inside a call to read params without leaving the editor. **From the terminal — generate or live-preview DocC:** ```bash # Build a DocC archive for the core module swift package generate-documentation --target Lyrebird # Same for the UI module swift package generate-documentation --target LyrebirdUI # Live-preview in a browser (auto-reloads as you edit doc comments) swift package --disable-sandbox preview-documentation --target Lyrebird ``` `generate-documentation` writes a `.doccarchive` under `.build/` — double-click to open in Xcode, or host it as a static site (`--transform-for-static-hosting`). ### Guides | Topic | Doc | |---|---| | **Start here / demo projects** | [`LYREBIRD_START_HERE.md`](LYREBIRD_START_HERE.md) | | **New to Swift? Intro for Lyrebird users** | [`docs/learning-swift/README.md`](docs/learning-swift/README.md) | | **What's new / release notes** | [`RELEASES.md`](RELEASES.md) | | Engine setup and Core Audio | `docs/engine/synthesis-engine.md` | | Bus memory / In / Out | `docs/engine/bus-system.md` | | Sample-accurate scheduling | `docs/engine/scheduling.md` | | Generator protocol + DemandGenerator | `docs/protocols/generator.md` | | Synthesizer / node tree | `docs/protocols/synthesizer.md` | | Writing custom generators | `docs/protocols/writing-generators.md` | | Out-of-tree extension packages (Generator/Synthesizer) | `docs/protocols/extension-sdk.md` | | Authoring + publishing an extension package (worked example) | `docs/extension-authors-guide.md` | | Signal evaluation order | `docs/signal-flow/signal-flow.md` | | All built-in generators | `docs/stdlib/generators.md` | | Musical math (MIDI↔Hz, dB, intervals) | `docs/stdlib/generators.md` — LyrebirdMusicMath section | | NRT / offline rendering | `docs/tooling/nrt-guide.md` | | REPL / hot-swap | `docs/tooling/repl.md` | | Xcode file templates | `docs/tooling/xcode-templates.md` | | GUI / parameter binding | `docs/ui/gui-system.md` | | Active phase plan | `docs/00-working-order.md` | | Completed phases | `docs/01-completed-working-order.md` | --- ## Hard constraints - **No AVAudioEngine** — direct Core Audio (`kAudioUnitSubType_HALOutput` on macOS, RemoteIO on iOS) - **No allocation on the RT audio thread** — render callback cannot alloc, lock, or block - **No dynamic resizing of bus memory** — all buffers pre-allocated at `engine.start()` - **No Xcode Playgrounds** — all tests use Swift Testing (`@Test`, `#expect`, `@Suite`) - **No SwiftUI in core `Lyrebird` module** — GUI lives in the separate `LyrebirdUI` module --- ## Release notes Per-version changes are in [`RELEASES.md`](RELEASES.md). The current release (1.1) adds the algorithmic-composition stack: a music-theory toolkit, pattern library, score DSL, and MusicXML / MIDI round-trips. ## Contributing New Generators (in-tree) and out-of-tree extension packages are both welcome — see [`CONTRIBUTING.md`](CONTRIBUTING.md). ## License MIT — see [`LICENSE`](LICENSE). © 2026 Joshua Parmenter / realizedsound.