Files
Lyrebird/LYREBIRD_START_HERE.md
josh 62b2f5dbec v1.5.0 release: LyrebirdRandom + Live Scratch editor
LyrebirdRandom scalar distribution sampling (seedable value type + shared
Random) with DistributionKind.sample dispatcher. Live Scratch editor: rename to
LyrebirdScratch, App Support artifact staging, Format Code (⌥⌘F), Render to File
(⌥⌘R offline CAF), line-number gutter, manual completion, Foundation in snippets,
scroll-jump fix, scheduling/NRT docs.
2026-07-22 07:53:12 -07:00

13 KiB
Raw Permalink Blame History

Lyrebird — Start Here

Eight demo projects live in this workspace. This guide covers how to open them, what each one does, where to add your own synthesizers, and the gotchas that will bite you if you don't know about them.


Opening the Workspace

Open Lyrebird.xcworkspace — not any individual .xcodeproj file. The workspace links all eight demo projects together so they share the local Lyrebird package.

Once open, pick a scheme from the scheme picker at the top of the Xcode window and hit Run.


The Eight Demos

LyrebirdQuickstartDemo — Fastest Sound

The shortest path to hearing Lyrebird. A command-line tool that starts the engine, adds a one-oscillator SineTone, plays a 440 Hz tone for 10 seconds through CoreAudioDriver, then stops and exits. Start here.

  • Where the synth lives: Demos/LyrebirdQuickstartDemo/LyrebirdQuickstartDemo/Synthesizers/SineTone.swift — one build() with a single OscSin.Audio through Pan2.
  • Wire it up: main.swift is engine.start() → engine.add(SineTone()) → Thread.sleep(10) → engine.stop(). No RunLoop — it self-terminates.
  • Run it: pick the LyrebirdQuickstartDemo scheme and hit Run, or from the terminal cd Demos/LyrebirdQuickstartDemo && swift run.
  • Same as the CLI template: this mirrors lyrebird new MyFirstSound --template quickstart.

LyrebirdDemo — Real-Time CLI

A command-line tool that plays audio through your default output device using CoreAudioDriver.

  • Where to add synthesizers: Demos/LyrebirdDemo/LyrebirdDemo/Synthesizers/ — General/SineTone.swift and General/DelaySample.swift are the starting examples (the folder is grouped into General/, Buffer/, Granular/, Spectral/)
  • Wire it up: main.swift adds a synth and plays it — try engine.add(mySynth), or try engine.schedule(mySynth, after: seconds) for sample-accurate start. (As shipped, main.swift runs a demo harness — BufferDemos(engine: engine).runDemo(); swap in your own.)
  • To stop: Ctrl-C in the Xcode console, or give a voice an envelope/line that frees itself (see below)

You can also run this from the terminal: cd Demos/LyrebirdDemo && swift run


LyrebirdMacOSDemo — macOS GUI App

A SwiftUI app with a live oscilloscope, parameter knobs, and real-time audio.

  • Where to add synthesizers: Demos/LyrebirdMacOSDemo/LyrebirdMacOSDemo/Synthesizers/ — SineToneUI.swift is the example
  • UI binding: mark synthesizer properties with @UIParam and they auto-appear as knobs in the window. No extra wiring needed.
  • Scope: LyrebirdScopeView is already wired — it shows the first two output channels of whatever is playing
final class MySynth: SynthesizerBase {
    @UIParam var freq: Double = 440.0
    @UIParam var amp:  Double = 0.5

    override func build() {
        // Use the $-projected nodes ($freq / $amp), not the bare values —
        // the projection is what makes each knob update reach the audio graph live.
        let sig = OscSin.Audio(freq: $freq) * $amp
        output(bus: 0, source: Pan2(input: sig, pan: 0))
    }
}

LyrebirdiOSDemo — iOS App

A SwiftUI app using iOSAudioDriver (RemoteIO). Same @UIParam knob system as the macOS demo.

  • Where to add synthesizers: Demos/LyrebirdiOSDemo/LyrebirdiOSDemo/Synthesizers/
  • Critical: AVAudioSession must be activated before creating SynthesisEngine. The demo's LyrebirdiOSDemoApp.swift does this — keep that order when adding setup code or the engine will pick up the wrong sample rate.
// Correct order — do not rearrange:
try AVAudioSession.sharedInstance().setCategory(.playback)
try AVAudioSession.sharedInstance().setActive(true)   // ← must come first
let engine = SynthesisEngine(...)
  • Simulator has no audio output — run on device for sound

LyrebirdNRTDemo — Offline Renderer

A command-line tool that renders audio to a CAF file without playing anything in real time. Useful for batch rendering, testing synthesizer graphs, or processing existing audio.

  • Output file: ~/Desktop/nrt_output.caf — open in any DAW or QuickTime after running
  • First run: macOS will prompt for Desktop folder access. Click Allow. If you dismiss it by mistake, re-enable in System Settings → Privacy & Security → Files and Folders.
  • Where to add synthesizers: Demos/LyrebirdNRTDemo/LyrebirdNRTDemo/Synthesizers/ — FMTone.swift is the example
  • Schedule voices: in main.swift, call engine.schedule(MySynth(), after: startTime)

Soundfile input: pass a source file to NRTDriver and it feeds audio into the engine's input buses block-by-block, exactly like a microphone would in real time:

let driver = NRTDriver(
    outputURL: outputURL,
    duration: 5.0,
    inputURL: URL(fileURLWithPath: "/path/to/source.wav"),
    inputStartOffset: 2.0    // skip first 2 seconds
)
let engine = SynthesisEngine(
    blockSize: 512,
    sampleRate: 48000,
    numOutputChannels: 2,
    numInputChannels: 2,     // must be ≥ channel count of source file
    driver: driver
)

Read input channels inside a synthesizer using raw bus indices:

// Input channel 0 with numOutputChannels=2 → raw bus index 2
let left  = In.Audio(bus: 2)   // numOutputChannels + 0
let right = In.Audio(bus: 3)   // numOutputChannels + 1

ExtAudioFile handles sample-rate conversion automatically if the source file's rate differs from the engine's. Channels beyond what the file contains stay silent.


LyrebirdScoreDemo — Score / MusicXML + Offline Render

A command-line tool that builds notated Scores with the result-builder DSL, exports them to MusicXML on the Desktop, round-trips them through the parser as a sanity check, then renders the audio to a CAF file via NRTDriver.

  • Output files: ~/Desktop/LyrebirdScoreDemo.musicxml (a multi-part demo score), ~/Desktop/LyrebirdScoreSections.musicxml (a sectioned showcase), and ~/Desktop/LyrebirdScoreDemo.caf (rendered audio). Open the .musicxml in Dorico / MuseScore / Finale; open the .caf in any DAW.
  • Where the score is built: Demos/LyrebirdScoreDemo/LyrebirdScoreDemo/Demos/ScoreDemo.swift — makeScore() (eight parts) and makeSectionedShowcase().
  • Notation coverage: clefs, keys, dynamics/hairpins, ties, tuplets, grace notes, multi-staff Staff/Voice, sustain Pedal, repeats with 1st/2nd endings, Sections + rehearsal marks, glissandi, per-note display overrides, and page layout. Reference: Sources/Lyrebird/Lyrebird.docc/ScoreSystem.md.
  • Rehearsal-mark tip: use single-letter Section labels ("A", "B", "C") — notation editors auto-sequence rehearsal marks and hide custom words.

LyrebirdAUv3Demo — AUv3 Plugin Reference

A container app + .appex extension target shipping Realized Sound: LyrebirdFM — a two-operator FM synthesizer wrapped as an aumu Audio Unit v3. Loadable in Logic, GarageBand, AUM, Loopy Pro, and any other AUv3 host on macOS.

  • First run: build & run the container app once. macOS registers the embedded extension on launch; after that, every AUv3 host on the machine can see the plugin.
  • Validate from the terminal: auval -v aumu LBFM RLZS should print PASS.
  • Where to add synthesizers: Demos/LyrebirdAUv3Demo/LyrebirdFMExtension/ — LyrebirdFM.swift is the SynthesizerBase subclass; LyrebirdFMAudioUnit.swift is the LyrebirdAudioUnit wrapper.
  • Copy as a template: see Demos/LyrebirdAUv3Demo/README.md for the step-by-step on duplicating this directory to ship your own AUv3 plugin (4-char component subtype, manufacturer code, signing, etc.).
  • Not yet wired in the template: MIDI input, SwiftUI parameter UI in the view controller, source-slot preset save/restore, effect-type AU (aufx), iOS container. The framework supports them all — see Sources/Lyrebird/Lyrebird.docc/AUv3.md for the hooks.

LyrebirdScratch — Live-Coding Scratchpad

A macOS app that compiles a typed Swift snippet against the live engine at ⌘↩. Backed by LyrebirdScratchView and LiveSession from the LyrebirdLiveCompile SPM target.

v1 surface:

  • Type arbitrary Swift code in the editor pane. The snippet body has context: SnippetContext in scope.
  • context.engine — the host SynthesisEngine, started at launch.
  • context.play(synth) — adds a Synthesizer to the engine and tracks it for cleanup.
  • context.play { <graph> } — plays a bare generator graph, no SynthesizerBase subclass needed.
  • context.play(slot: "name") { <graph> } — plays into a named slot; re-running that slot replaces just that voice in place while the rest keeps playing (persists across a ⌘↩ run).
  • context.reportMessage(_:) — writes a string back to the host status bar.
  • ⌘↩ — compile and replace. Removes the previous run's anonymous synths (named slots persist), compiles the snippet via swiftc -emit-library, dlopens the resulting dylib, calls lyrebird_snippet_entry.
  • ⌘⇧↩ — compile additive. Prior synths stay in the engine.
  • Clear Synths toolbar button — full reset: removes all tracked synths and every named slot immediately.

Why this app cannot be sandboxed: swiftc is a subprocess (posix_spawn); the output dylib is unsigned. Both are blocked by the macOS App Sandbox. This app is a direct-distribution developer tool only. The entitlements file (LyrebirdScratch.entitlements) sets com.apple.security.cs.disable-library-validation = true to let Hardened Runtime dlopen the unsigned snippet dylib.

Dylib lifetime: loaded dylibs are never unloaded. Synthesizer instances reference types from the dylib; unloading while they are active would crash. Every ⌘↩ evaluation writes a new uniquely-named dylib to a per-session temp dir. This is intentional v1 behaviour; a future release may revisit with an XPC worker approach.

Not yet implemented: syntax highlighting, line-number gutter, snippet save/load, multi-snippet tabs, async compile (editor does not freeze during compilation in v1 — swiftc blocks the main actor for the duration of the compile).


Adding a Synthesizer (Any Demo)

  1. Create a file in the demo's Synthesizers/ folder
  2. Add it to the Xcode target's Sources build phase (select the target, Build Phases → Compile Sources → +)
  3. Subclass SynthesizerBase and implement build()
import LyrebirdSynth

final class MySynth: SynthesizerBase {
    override func build() {
        let sig = OscSin.Audio(freq: 440) * 0.3
        output(bus: 0, source: Pan2(input: sig, pan: 0))
    }
}

Self-freeing voices: there is no doneAction property to set on the synthesizer. Instead, build a DoneActionWatchable generator — EnvelopeGen, Line, ExponentialLine, etc. — inside build() with doneAction: .freeNode; it self-registers, and the engine frees the node when that generator finishes. (DoneAction cases are .nothing, .freeNode, .loop.)


Common Gotchas

Symptom Cause Fix
dyld: Library not loaded: @rpath/Lyrebird.framework Hardened Runtime's Library Validation rejects the ad-hoc–signed SPM framework Check that the target's entitlements file contains com.apple.security.cs.disable-library-validation = true. Then do Product → Clean Build Folder (⇧⌘K) — Xcode may be launching a cached binary.
Desktop file never appears / TCC prompt didn't show macOS denied Desktop access on first run System Settings → Privacy & Security → Files and Folders → find the demo and re-enable
iOS audio wrong pitch or silent AVAudioSession not activated before engine init Activate session first — see the iOS demo note above
NRT input buses are silent In.Audio(bus: n) uses raw engine bus index Input channel n lives at raw index numOutputChannels + n, not n
Build fails with Swift driver errors Xcode 26 integrated driver bug Already worked around in the workspace: SWIFT_USE_INTEGRATED_DRIVER = NO, parallelizeBuildables = NO, type: .dynamic on the Lyrebird library product in Package.swift

Going Deeper

Topic Doc
New to Swift? Intro for Lyrebird users docs/learning-swift/README.md
Engine setup and Core Audio docs/engine/synthesis-engine.md
Bus system, In/Out generators docs/engine/bus-system.md
Sample-accurate scheduling docs/engine/scheduling.md
Generator protocol docs/protocols/generator.md
Synthesizer and node tree docs/protocols/synthesizer.md
All built-in generators docs/stdlib/generators.md
NRT / offline rendering docs/tooling/nrt-guide.md
Score / MusicXML authoring Sources/Lyrebird/Lyrebird.docc/ScoreSystem.md
REPL / hot-swap docs/tooling/repl.md
Xcode file templates docs/tooling/xcode-templates.md
GUI / parameter binding docs/ui/gui-system.md
Hard constraints and code style CLAUDE.md