15 KiB
AUv3 Plugin Export
Ship a SynthesizerBase subclass as an Audio Unit v3 (.appex) plugin loadable
by Logic, GarageBand, Ableton (via Bridge), Loopy Pro, AUM, and any other AUv3
host on macOS or iOS.
Overview
Lyrebird's AUv3 layer is the headless Swift API that bridges the engine into
the AUAudioUnit contract:
AUv3Driver— passiveAudioDriverdriven from the AU host's render block.AUv3RingBuffer— fixed-block → variable-frame adapter, one per AU.LyrebirdAudioUnit— openAUAudioUnitsubclass; provides parameter tree, output bus topology,internalRenderBlock, andfullStatesave/restore.LyrebirdAUParameterMapping— Mirror-driven discovery that exposes every@LiveParam/@UIParamslot as anAUParameter.
The framework ships no Xcode .appex extension target — each plugin's
.appex wrapper is supplied by the host app project. The classes above are
what that wrapper subclasses.
Minimal subclass pattern
import LyrebirdSynth
final class MyFMSynth: SynthesizerBase {
@LiveParam var carrierFreq: Double = 440
@LiveParam var modIndex: Double = 0.5
override func build() {
let mod = OscSin.Audio(freq: $carrierFreq * 2, mul: $modIndex * $carrierFreq)
let car = OscSin.Audio(freq: $carrierFreq + mod)
output(bus: 0, source: car * 0.3)
}
}
public final class MyFMSynthAudioUnit: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase {
MyFMSynth()
}
public override class func parameterMetadata() -> [String: LyrebirdAUParameterInfo] {
[
"carrierFreq": .init(min: 20, max: 8000, unit: .hertz),
"modIndex": .init(min: 0, max: 4),
]
}
}
The Xcode .appex extension target registers an AUViewController
subclass that conforms to AUAudioUnitFactory as the
NSExtensionPrincipalClass. Its createAudioUnit(with:) instantiates
MyFMSynthAudioUnit and returns it to the host. The audio component
itself is declared in the extension's Info.plist under
NSExtension.NSExtensionAttributes.AudioComponents.
Architecture
Render path
┌─────────────────┐ internalRenderBlock ┌─────────────────┐
│ AU host │ ────────────────────▶ │ LyrebirdAudioUnit │
└─────────────────┘ (frameCount=N) └────────┬────────┘
│ render(N, ABL)
▼
┌─────────────────┐
│ AUv3Driver │
│ + AUv3RingBuffer│
└────────┬────────┘
│ ring.availableToRead < N?
(yes loop)│ engine.processBlock(...)
▼
┌─────────────────┐
│ SynthesisEngine │
│ (blockSize=256) │
└────────┬────────┘
│ engine.audioBuses[0..<N]
▼
┌─────────────────┐
│ AUv3RingBuffer │ ──▶ pop into ABL
└─────────────────┘
Latency: one engine block (≈5.8 ms at 256 frames / 44.1 kHz). The host's
requested frameCount is variable per render call; the ring decouples it
from Lyrebird's fixed block size.
Parameter mapping
Every @LiveParam / @UIParam slot on the synthesizer is auto-discovered via
Mirror (oldest superclass first, declaration order within each class) and
assigned a stable AUParameterAddress. The AU's
AUParameterTree.implementorValueObserver writes new host values atomically
into the underlying ParameterNode (same path as
SynthesizerBase/updateParameter(_:value:)). The
implementorValueProvider reads the current scalar via atomic load.
Per-parameter metadata (min / max / unit / display name) is supplied by
overriding LyrebirdAudioUnit/parameterMetadata(). Parameters not present
in the dictionary fall back to permissive defaults.
Lifecycle
init: subclassmakeSynthesizer()is called; the synth's@LiveParamslots populate the parameter tree.allocateRenderResources: a freshSynthesisEngineis created at the host-negotiated sample rate; the synthesizer is added to it.internalRenderBlock: pulls samples throughAUv3Driver/render(frameCount:outputBusNumber:outputData:timestamp:pullInput:).deallocateRenderResources: synthesizer is removed, engine is stopped and released. The synth instance survives — re-allocate calls add it back to a new engine, preserving@LiveParamatomic state.
State save / restore
LyrebirdAudioUnit/fullState encodes scalar @LiveParam values as a
[String: AUValue] dictionary under lyrebirdAUFullStateKey. Setting
fullState writes each value back into the corresponding node atomically and
mirrors it into the AU parameter tree so host UI reflects the change.
Source-slot generators wired through Lyrebird's runtime source-swap path can
optionally persist across save / restore — see the "Source-slot save /
restore" section below. For types that don't conform to
LyrebirdAUPresetCodable, a loaded state restores only the scalar
target of each parameter and the source generator must be re-attached
programmatically.
Multi-bus AUs — aux output + sidechain input
LyrebirdAudioUnit supports declaring and routing ≥ 1 output bus and
≥ 0 input busses. Single-bus AUs keep working unchanged — the class
hooks default to the single-bus shape.
Declaring multiple busses
Override LyrebirdAudioUnit/lyrebirdOutputBusses (and/or
LyrebirdAudioUnit/lyrebirdInputBusses) with an array of
LyrebirdAUBusSpec:
public final class StereoCompressorAU: LyrebirdAudioUnit {
public override class func makeSynthesizer() -> SynthesizerBase {
StereoCompressorSynth()
}
public override class var lyrebirdOutputBusses: [LyrebirdAUBusSpec] {
[LyrebirdAUBusSpec(name: "Output", channelCount: 2)]
}
public override class var lyrebirdInputBusses: [LyrebirdAUBusSpec] {
[
.init(name: "Main In", channelCount: 2),
.init(name: "Sidechain", channelCount: 2),
]
}
}
The synth's build() reads from each declared input bus via
AUInput/Audio with an explicit busIndex:
override func build() {
let mainL = AUInput.Audio(busIndex: 0, channel: 0)
let mainR = AUInput.Audio(busIndex: 0, channel: 1)
let scL = AUInput.Audio(busIndex: 1, channel: 0)
let scR = AUInput.Audio(busIndex: 1, channel: 1)
let sidechain = (scL + scR) * 0.5
let env = AmplitudeFollower.Control(input: sidechain)
let gain = Compressor.Control(env: env, threshold: $threshold, ratio: $ratio)
output(bus: 0, source: mainL * gain)
output(bus: 1, source: mainR * gain)
}
Engine bus layout
The SynthesisEngine's contiguous audioBuses array holds output
busses first, then input busses, each occupying channelCount slots in
declaration order:
engine.audioBuses
┌──────────────────────────────┬──────────────────────────────┐
│ Output busses (sum of all) │ Input busses (sum of all) │
└──────────────────────────────┴──────────────────────────────┘
[0, [numOutputChannels,
Σ outputSpec.channelCount) numOutputChannels +
Σ inputSpec.channelCount)
The driver populates SynthesisEngine/auInputBusOffsets and
SynthesisEngine/auOutputBusOffsets so generators / debugging code
can map AU bus → engine bus index at render time.
Driver render contract
AUv3Driver/render(frameCount:outputBusNumber:outputData:timestamp:pullInput:)
takes an outputBusNumber argument and reads from the matching per-bus
ring. AU hosts call internalRenderBlock once per output bus per
render cycle; each call advances the engine only if the requested
bus's ring needs more frames. Other busses' rings buffer their output
until the host pulls them.
For multi-input-bus effect AUs, _fillInputStagingFromHost calls the
host's AURenderPullInputBlock once per input bus per engine block
(passing the input bus index as the 4th arg) and copies the host
samples into the matching engine input bus slice.
Topics added
LyrebirdAUBusSpecLyrebirdAudioUnit/lyrebirdOutputBussesLyrebirdAudioUnit/lyrebirdInputBussesAUv3Driver/configureBusMap(outputBusChannelCounts:inputBusChannelCounts:)AUInput/Audio/init(busIndex:channel:)lyrebirdAUDefaultOutputBusNamelyrebirdAUDefaultInputBusName
Capabilities
The wrapper handles MIDI input dispatch, host-audio input (effect AUs), a Mirror-driven SwiftUI parameter grid, factory presets, and source-slot preset save/restore.
MIDI input
Install a closure on LyrebirdAudioUnit/midiHandler and it will receive
MIDIMessage values parsed from the AU host's AURenderEvent chain on
the render thread. The closure must obey RT rules (no allocation, no
locks). The dispatch helper itself walks the event chain linearly and
parses each .MIDI event into a typed MIDIMessage:
au.midiHandler = { msg, sampleTime in
switch msg {
case .noteOn(_, let note, let velocity):
voicePool.noteOn(note: Int(note))
// configure voice from velocity, etc.
case .noteOff(_, let note, _):
voicePool.noteOff(note: Int(note))
default:
break
}
}
For polyphonic voice-pool integration use LyrebirdAUVoicePoolBinding
— pass it a VoicePool instance plus per-voice configure
closures, and wire au.midiHandler to binding.handle(message:sampleTime:).
Effect AUs
Override LyrebirdAudioUnit/lyrebirdInputChannels to return a positive
value to declare an aufx-type AU with a host input bus. The synth's
build() reads host audio via AUInput/Audio:
override func build() {
let leftIn = AUInput.Audio(channel: 0)
let rightIn = AUInput.Audio(channel: 1)
let wet = FreeVerb.Audio(input: leftIn + rightIn) * $wetMix
output(bus: 0, source: wet[0] + leftIn * (1 - $wetMix))
output(bus: 1, source: wet[1] + rightIn * (1 - $wetMix))
}
AUv3Driver pulls one engine block of input per engine.processBlock
call via the host's AURenderPullInputBlock and stages it into the
engine's input buses ([numOutputChannels, numOutputChannels + numInputChannels)). AUInput.Audio(channel:) reads from those buses at
render time, with a defensive zero-fill if the AU was instantiated as
instrument-only.
SwiftUI parameter grid
LyrebirdUI exposes LyrebirdSynthView — an auto-generated
parameter-knob grid built from a SynthesizerBase instance by walking
its Mirror for @UIParam slots (matches the discovery order in
SynthesizerBase._autoRegisterLiveParams()). Pass an optional
metadata dictionary keyed by property name to control per-knob range,
unit, and display name:
LyrebirdSynthView(
synth: au.synthesizer,
metadata: MyAUClass.parameterMetadata()
)
For a hand-tuned UI, override the AU view controller and skip
LyrebirdSynthView entirely — use ParameterKnob / ParameterSlider
directly. Only @UIParam slots appear; @LiveParam slots have no
@Observable projected value and are skipped.
Factory presets
Override LyrebirdAudioUnit/factoryPresetsForLyrebird() to return a
list of named LyrebirdAUFactoryPreset. Each entry combines a
human-readable name, a [String: AUValue] scalar values dictionary
keyed by @LiveParam / @UIParam property name, and optional
source-slot generator descriptors:
public override class func factoryPresetsForLyrebird() -> [LyrebirdAUFactoryPreset] {
[
.init(name: "Bright", scalarValues: ["cutoff": 4000, "amp": 0.8]),
.init(name: "Quiet", scalarValues: ["cutoff": 400, "amp": 0.1]),
]
}
The AU base class auto-bridges this into factoryPresets /
currentPreset so AU hosts can show the names in their preset menu.
Source-slot save / restore
Generators wired into a ParameterNode.source slot persist across
fullState save / restore + factory-preset application when the generator
conforms to LyrebirdAUPresetCodable and is registered with
LyrebirdAUPresetSourceRegistry. The protocol surface is:
public protocol LyrebirdAUPresetCodable: Generator {
static var presetTypeID: String { get }
var presetEncodedParameters: [String: AUValue] { get }
static func presetMake(from parameters: [String: AUValue]) -> any Generator
}
Call LyrebirdAUPresetSourceRegistry.register(MyGenerator.self) once
per type before instantiating the AU. Unknown presetTypeIDs in a saved
state are silently skipped — the slot reverts to its scalar target.
Out of scope
| Feature | Notes |
|---|---|
| MIDI 2.0 UMP | Not yet supported; AU base reports MIDI 1.0 protocol |
Per-sample parameter ramping (AUParameterAutomationEventType.ramp) |
Host writes apply at next sub-block boundary via standard atomic ramp |
| AU view controller hand-tuned default | The default Mirror-driven grid is intentionally minimal; users override LyrebirdSynthView or build a custom view for any non-trivial UI |
Topics
Plugin Wrapper
LyrebirdAudioUnitLyrebirdAudioUnitErrorlyrebirdAUDefaultBlockSizelyrebirdAUDefaultSampleRatelyrebirdAUFullStateKey
Render Bridge
AUv3DriverAUv3RingBufferauv3DriverDefaultMaxFramesToRender
Parameter Mapping
LyrebirdAUParameterMappingLyrebirdAUParameterEntryLyrebirdAUParameterInfolyrebirdAUParameterDefaultBoundlyrebirdAUParameterDefaultFlags
MIDI + Voice Pool
LyrebirdAUVoicePoolBindingmidiVelocityMax
Effect AU
AUInput
Presets
LyrebirdAUFactoryPresetLyrebirdAUPresetCodableLyrebirdAUPresetSourceDescriptorLyrebirdAUPresetSourceRegistrylyrebirdAUFullStateScalarKeylyrebirdAUFullStateSourcesKeylyrebirdAUFullStateSourceTypesKey