1.0.0 release
This commit is contained in:
@@ -1,3 +1,378 @@
|
||||
# Lyrebird
|
||||
|
||||
A real-time synthesis and signal processing library built in Swift
|
||||
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 `LyrebirdScratchDemo` 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 six demo projects, how to open the workspace, where to add synthesizers, and the gotchas that will bite you.
|
||||
|
||||
---
|
||||
|
||||
## 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).
|
||||
|
||||
Then three settings a hand-made project needs (the `lyrebird new` scaffolds set all three for you):
|
||||
|
||||
1. **Embed the framework.** App targets: confirm Lyrebird shows under *General ▸ Frameworks, Libraries, and Embedded Content* as **Embed & Sign** (Xcode sets this automatically). CLI/SwiftPM executables need no embed.
|
||||
2. **Disable library validation** — required for any target with **Hardened Runtime** (signed apps + all AUv3). `Lyrebird` ships as a `.dynamic` library; its SPM-built `libLyrebird.dylib` is ad-hoc-signed, so dyld otherwise fails with `dyld: Library not loaded`. Add to the target's `.entitlements`, then clean build (⇧⌘K):
|
||||
```xml
|
||||
<key>com.apple.security.cs.disable-library-validation</key>
|
||||
<true/>
|
||||
```
|
||||
Plain debug apps without Hardened Runtime can skip this.
|
||||
3. **Xcode 26 Swift-driver workaround** (only if the build throws Swift driver errors): set `SWIFT_USE_INTEGRATED_DRIVER = NO` and `parallelizeBuildables = NO` in Build Settings.
|
||||
|
||||
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**.
|
||||
|
||||
---
|
||||
|
||||
## Opening in Xcode
|
||||
|
||||
For the demo projects, open **`Lyrebird.xcworkspace`** — not any individual `.xcodeproj`. The workspace links all six 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 eight entries:
|
||||
|
||||
| Scheme | Purpose | Platform |
|
||||
|---|---|---|
|
||||
| `Lyrebird-Package` | Umbrella — builds Lyrebird + LyrebirdUI + LyrebirdLiveCompile + LyrebirdC + LyrebirdBenchmark + LyrebirdCLI, runs the test suites, launches/profiles `LyrebirdCLI` | 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 |
|
||||
| `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 |
|
||||
| `LyrebirdScratchDemo` | 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 |
|
||||
| LineNoise concurrency warnings | Expected — `LyrebirdCLI` uses `.swiftLanguageMode(.v5)` intentionally |
|
||||
| Nimble in Package dependencies | Cosmetic — LineNoise transitive dep, never built in Lyrebird targets |
|
||||
| Build fails with Swift driver errors | Xcode 26 bug — workspace already sets `SWIFT_USE_INTEGRATED_DRIVER = NO`, `parallelizeBuildables = NO`, `type: .dynamic`. In your own project see [Adding Lyrebird to your own project](#adding-lyrebird-to-your-own-project) |
|
||||
| `dyld: Library not loaded` | Hardened Runtime rejects the ad-hoc-signed SPM framework — add `com.apple.security.cs.disable-library-validation = true` to entitlements, then clean build (⇧⌘K). Full steps: [Adding Lyrebird to your own project](#adding-lyrebird-to-your-own-project) |
|
||||
|
||||
---
|
||||
|
||||
## Building and testing from the terminal
|
||||
|
||||
```bash
|
||||
swift build # build all targets
|
||||
swift test # run all 3544 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 six live in [`Demos/`](Demos/). Open via `Lyrebird.xcworkspace`.
|
||||
|
||||
| Demo | What it does | Platform |
|
||||
|---|---|---|
|
||||
| [`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 |
|
||||
| [`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 |
|
||||
| [`LyrebirdScratchDemo`](Demos/LyrebirdScratchDemo/) | 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 MyPiece --template ui-demo # scaffold a 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/
|
||||
│ ├── LyrebirdDemo/ # (same as Sources/LyrebirdDemo — workspace target)
|
||||
│ ├── LyrebirdMacOSDemo/ # macOS SwiftUI app
|
||||
│ ├── LyrebirdiOSDemo/ # iOS SwiftUI app
|
||||
│ ├── LyrebirdNRTDemo/ # offline renderer
|
||||
│ ├── LyrebirdAUv3Demo/ # AUv3 `aumu` plugin reference (LyrebirdFM)
|
||||
│ └── LyrebirdScratchDemo/ # live-coding scratchpad (macOS, no sandbox)
|
||||
├── Tests/
|
||||
│ ├── LyrebirdTests/ # 3544 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) |
|
||||
| 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
|
||||
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
||||
Reference in New Issue
Block a user