Files
Lyrebird/README.md
T
josh b6fdee8bfc Lyrebird 2.0.0 — Linux support
Consolidated release: the cross-platform Linux port (engine, generators, CLI,
REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable
WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux
live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive.
See RELEASES.md and LINUX_README.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-10 21:09:11 -07:00

389 lines
19 KiB
Markdown

# Lyrebird
A native macOS/iOS audio synthesis framework written in Swift. Implement `Generator` and `Synthesizer` protocols; the Lyrebird engine handles Core Audio I/O 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.
---
## 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 Core Audio 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
```
### Synthesizers — a graph plus live parameters
A `SynthesizerBase` subclass owns a graph built in `build()` and exposes `@LiveParam` (atomic, RT-safe) or `@UIParam` (SwiftUI-bindable) properties. The `$name` projection injects each parameter into the graph as a smoothed control-rate node:
```swift
final class FMTone: SynthesizerBase {
@LiveParam var carrierFreq: Double = 440
@LiveParam var modIndex: Double = 3.0
override func build() {
let mod = OscSin.Audio(freq: $carrierFreq * 2, mul: $modIndex * $carrierFreq)
let car = OscSin.Audio(freq: $carrierFreq + mod)
let env = EnvelopeGen.Control(envelope: Envelope(
levels: [0, 1, 0.7, 0], durations: [0.02, 1.5, 0.5], curves: [2, 0, -3.5]))
output(bus: 0, source: Pan2(input: car * env * 0.2)) // stereo to hardware bus 0
}
}
```
### Engine — drive Core Audio and schedule voices
The engine opens the audio device, pre-allocates all bus memory at `start()`, and runs the graph on the real-time thread. Adding or scheduling a synth is lock-free; `schedule(_:after:)` fires at an exact sample offset:
```swift
let engine = SynthesisEngine(
blockSize: 512,
sampleRate: 48_000,
numOutputChannels: 2,
numInputChannels: 0,
driver: CoreAudioDriver()) // NRTDriver for offline, iOSAudioDriver for iOS
try engine.start()
try engine.add(FMTone()) // sounds immediately
let tone = FMTone()
try engine.schedule(tone, after: 2.5) // sample-accurate, 2.5 s from now
tone.carrierFreq = 660 // live, atomic, no glitch
```
Swap `CoreAudioDriver()` for `NRTDriver(outputURL:duration:)` and the identical graph renders offline to a CAF file. See [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md) to add the package and scaffold projects, and [`ARCHITECTURE.md`](ARCHITECTURE.md) for how the threading and scheduling work underneath.
### Live coding — prototype in the interpreter
`lyrebird repl` runs `swift build`, then drops you into a Swift REPL with `import LyrebirdSynth` wired up. Define generators and synthesizers, add them to a running engine, and retune them in place — audio never stops, because `@LiveParam` writes are atomic and `add`/`remove` go through the lock-free scheduler:
```
$ lyrebird repl
```
```swift
import LyrebirdSynth
let engine = SynthesisEngine(
blockSize: 512, sampleRate: 48_000,
numOutputChannels: 2, numInputChannels: 0,
driver: CoreAudioDriver())
try engine.start()
// Define a synth right in the session.
final class SineTone: SynthesizerBase {
@LiveParam var freq: Double = 440
@LiveParam var amp: Double = 0.3
override func build() {
output(bus: 0, source: OscSin.Audio(freq: $freq) * $amp)
}
}
let tone = SineTone()
try engine.add(tone) // audio starts immediately
tone.freq = 880 // retune live — no glitch, no restart
tone.amp = 0.1
engine.remove(tone) // fades out at the next block boundary
```
Prefer a GUI? The `LyrebirdScratch` app embeds `LyrebirdScratchView`: type a snippet, press **⌘↩** to compile-and-hot-swap it against the live engine (or **⌘⇧↩** to layer additively). Each snippet receives a `SnippetContext` — `context.engine` and `context.play(_:)`:
```swift
// Snippet body — `context: SnippetContext` is in scope.
final class Blip: SynthesizerBase {
override func build() {
let env = EnvelopeGen.Control(envelope: Envelope(
levels: [0, 1, 0], durations: [0.005, 0.25], curves: [0, -4]))
output(bus: 0, source: OscSin.Audio(freq: 660) * env * 0.3)
}
}
context.play(Blip())
```
The REPL is text-only and works from any project that depends on Lyrebird; the scratchpad is macOS-only (it shells out to `swiftc` and `dlopen`s the result). Details: [`docs/tooling/repl.md`](docs/tooling/repl.md) and `LiveCompile/Sources/LyrebirdLiveCompileUI/LyrebirdLiveCompileUI.docc/LiveCoding.md`.
---
## New here?
**Read [`LYREBIRD_START_HERE.md`](LYREBIRD_START_HERE.md)** — it covers the eight demo projects, how to open the workspace, where to add synthesizers, and the gotchas that will bite you.
**New to Swift itself?** [`docs/learning-swift/`](docs/learning-swift/README.md) is a four-part intro to Swift written for Lyrebird users (not iOS developers): a Hello-World tone, Swift basics and best practices, the type system and functional style applied to synthesis graphs, and Xcode / packages / Debug-vs-Release / debugging.
---
## Requirements
| Platform | OS | Xcode | Swift |
|---|---|---|---|
| macOS | 15+ | 16+ | 6.0 |
| iOS | 18+ | 16+ | 6.0 |
---
## Adding Lyrebird to your own project
Add the package:
```
https://realizedsound.mooo.com/josh/Lyrebird.git
```
**File ▸ Add Package Dependencies…** → that URL → **Up to Next Major** from `1.0.0` → add the `Lyrebird` product (and `LyrebirdUI` for the SwiftUI controls). Write `import LyrebirdSynth` in your code (the product is `Lyrebird`; the module it vends is `LyrebirdSynth`).
That's it — the `Lyrebird` product links **statically**, so there's no dynamic framework, no embed step, and **no special build settings**: you do *not* need a `disable-library-validation` entitlement or a `SWIFT_USE_INTEGRATED_DRIVER` override. It just links, even under Hardened Runtime / sandbox / AUv3.
Full walk-through (SPM manifest form, local-path dev dependency, per-template details): [`INSTALLATION_AND_USAGE.md`](INSTALLATION_AND_USAGE.md). DocC version: **Getting Started ▸ Adding Lyrebird to your own Xcode project**.
**On Linux?** The non-UI core — engine, generators, CLI, offline render, live ALSA audio, MIDI, and OSC — builds and runs on Linux (no Xcode, no SwiftUI). Start here: [`docs/linux-getting-started.md`](docs/linux-getting-started.md).
---
## Opening in Xcode
For the demo projects, open **`Lyrebird.xcworkspace`** — not any individual `.xcodeproj`. The workspace links all eight demos to the local Lyrebird package.
For the package itself:
```bash
xed . # opens Package.swift — Xcode auto-generates schemes for every target
```
### Schemes
Workspace scheme selector exposes ten entries:
| Scheme | Purpose | Platform |
|---|---|---|
| `Lyrebird-Package` | Umbrella — builds Lyrebird + LyrebirdUI + LyrebirdLiveCompile + LyrebirdC + LyrebirdBenchmark + LyrebirdCLI, runs the test suites, launches/profiles `LyrebirdCLI` | macOS |
| `LyrebirdQuickstartDemo` | CLI — fastest sound: a one-oscillator `SineTone` that plays 440 Hz for 10 s and exits | macOS |
| `LyrebirdUI` | Builds the `LyrebirdUI` module only (SwiftUI parameter controls + visualisations) | macOS |
| `LyrebirdDemo` | CLI — plays through default output via `CoreAudioDriver` | macOS |
| `LyrebirdMacOSDemo` | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
| `LyrebirdiOSDemo` | SwiftUI app — same UI via `iOSAudioDriver` (RemoteIO) | iOS |
| `LyrebirdNRTDemo` | CLI — offline render to CAF via `NRTDriver` | macOS |
| `LyrebirdScoreDemo` | CLI — builds notated `Score`s (result-builder DSL), exports MusicXML, renders to CAF via `NRTDriver` | macOS |
| `LyrebirdAUv3Demo` | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro, etc. Run the host app once to register the extension. | macOS |
| `LyrebirdScratch` | Live-coding scratchpad — type Swift snippets, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
Use `Lyrebird-Package` for day-to-day development of the engine and tests.
### Xcode gotchas
| Issue | Fix |
|---|---|
| Schemes don't appear | Close Xcode, run `swift package resolve`, reopen |
| `Synchronization.Atomic` not indexed | Requires Xcode 16+ — false errors in older versions, still builds |
| Nimble in Package dependencies | Cosmetic — LineNoise transitive dep, never built in Lyrebird targets |
| Build fails with Swift driver errors | Xcode 26 bug affecting the **demo workspace** (which dynamic-links for live-coding) — it already sets `SWIFT_USE_INTEGRATED_DRIVER = NO` + `parallelizeBuildables = NO`. Your own project links Lyrebird statically and is unaffected. |
| `dyld: Library not loaded` | Only the bundled demos/AUv3 use the dynamic `LyrebirdDynamic` product; their entitlements already set `disable-library-validation`. External consumers link the static `Lyrebird` product and never hit this. |
---
## Building and testing from the terminal
```bash
swift build # build all targets
swift test # run all 5481 tests
swift test --filter LyrebirdTests # run one suite
swift run lyrebird # run the CLI
swift run lyrebird repl # Swift REPL with Lyrebird available
swift run LyrebirdDemo # run the hardware smoke-test demo
```
---
## Demo projects
All eight live in [`Demos/`](Demos/). Open via `Lyrebird.xcworkspace`.
| Demo | What it does | Platform |
|---|---|---|
| [`LyrebirdQuickstartDemo`](Demos/LyrebirdQuickstartDemo/) | CLI — fastest sound: a one-oscillator `SineTone` plays 440 Hz for 10 s, then exits (mirrors the `quickstart` template) | macOS |
| [`LyrebirdDemo`](Demos/LyrebirdDemo/) | CLI — plays through default output via `CoreAudioDriver` | macOS |
| [`LyrebirdMacOSDemo`](Demos/LyrebirdMacOSDemo/) | SwiftUI app — live oscilloscope, `@UIParam` knobs | macOS |
| [`LyrebirdiOSDemo`](Demos/LyrebirdiOSDemo/) | SwiftUI app — same UI system via `iOSAudioDriver` (RemoteIO) | iOS |
| [`LyrebirdNRTDemo`](Demos/LyrebirdNRTDemo/) | CLI — offline render to CAF file via `NRTDriver` | macOS |
| [`LyrebirdScoreDemo`](Demos/LyrebirdScoreDemo/) | CLI — notated `Score` → MusicXML export + offline render to CAF via `NRTDriver` | macOS |
| [`LyrebirdAUv3Demo`](Demos/LyrebirdAUv3Demo/) | AUv3 host app + `aumu` plugin extension (`Realized Sound: LyrebirdFM`) — a two-operator FM synth wrapped as `LyrebirdAudioUnit`, loadable in Logic, GarageBand, AUM, Loopy Pro | macOS |
| [`LyrebirdScratch`](Demos/LyrebirdScratch/) | Live-coding scratchpad — type Swift, ⌘↩ compiles and runs against the engine, ⌘⇧↩ additive | macOS |
Each demo has a `Synthesizers/` folder — drop new `SynthesizerBase` subclasses there. See [`LYREBIRD_START_HERE.md`](LYREBIRD_START_HERE.md) for step-by-step instructions and per-demo notes.
---
## The `lyrebird` CLI
Install onto your `$PATH` (one-time):
```bash
swift build -c release --product LyrebirdCLI
cp .build/release/LyrebirdCLI /usr/local/bin/lyrebird
lyrebird --help # verify
```
Then:
```bash
lyrebird new MyFirstSound --template quickstart # fastest path to sound (plays 10 s, then exits)
cd MyFirstSound && lyrebird run # hear it
lyrebird new MyPiece --template ui-demo # a richer standalone project
open MyPiece/MyPiece.xcworkspace # open in Xcode (workspace refs Package.swift)
lyrebird # enter the lyrebird> 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.
| Package | Description |
|---|---|
| [`LyrebirdATK`](#) | First-order Ambisonics toolkit (37 `Foa*` UGens, MIT KEMAR HRIR set, binaural decoder). Worked example for the Extension SDK. |
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 using LyrebirdATK as the reference.
---
## 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)
│ ├── 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.