1.0.0 release

This commit is contained in:
2026-06-01 18:27:40 -07:00
parent b1ab0f102c
commit 1f20fcab20
1151 changed files with 230703 additions and 14 deletions
+61
View File
@@ -0,0 +1,61 @@
# Phase 96b — Ableton Link (Deferred)
This phase is **deferred**. Phase 96a (MIDI Clock follow) is implemented and merged.
---
## Goal
Peer-to-peer beat and tempo synchronisation over a local network (LAN/WiFi) using the
Ableton Link open-source SDK. Multiple apps on the same network share a common timeline
and tempo without a designated leader — any participant can change tempo and all others
follow.
---
## Shape
The integration would follow the same pattern as `MIDIClockFollower` (Phase 96a):
```swift
public final class AbletonLinkFollower: @unchecked Sendable {
public init(engine: SynthesisEngine, clock: LyrebirdClock, quantum: Double = 4.0)
public func start() throws
public func stop()
public var sessionTempo: Double { get }
public var isConnected: Bool { get }
}
```
`AbletonLinkFollower.start()` connects to the Link session and begins pushing session
tempo changes to `clock.bpm`. The `quantum` (default 4 beats) defines the phase-sync
window. On `.start()`, the follower aligns the local `LyrebirdClock` beat phase to the
Link session timeline.
---
## Prerequisites
- **Ableton Link C++ SDK** (`ableton/link`, Apache 2.0) as a SwiftPM binary or source
dependency. The SDK's `ABLLink.h` C bridging header or Swift overlay must be added to
`Package.swift`.
- A thin C or C++ wrapper to call Link from Swift (the SDK is header-only C++; a minimal
shim is needed to expose an Objective-C or C-compatible interface).
- Network capability entitlements on macOS/iOS (Bonjour + peer-to-peer networking).
---
## Effort estimate
High. The main complexity is the C++/Swift FFI for the Link SDK and testing peer-to-peer
behaviour without dedicated hardware (requires at least two simulators or devices on the
same LAN).
---
## References
- [Ableton Link SDK](https://github.com/Ableton/link) — Apache 2.0 open source
- [Link API overview](https://ableton.github.io/link/)
- Phase 96a implementation: `Sources/Lyrebird/MIDI/Sync/MIDIClockFollower.swift`
- Related: `docs/tooling/midi-clock-sync.md`
+76
View File
@@ -0,0 +1,76 @@
# AUv3 Extension Project (Phase 104b sketch)
Phase 104a ships only the Swift API surface (``LyrebirdAudioUnit``,
``AUv3Driver``, parameter mapping, ring buffer, `fullState`). Wrapping that as
an actual `.appex` plugin is Phase 104b's job, which lives in a separate
Xcode-managed sub-directory because SwiftPM cannot build app extensions.
This file is the planning sketch for that work — kept as a roadmap entry so
contributors can pick it up after 104a lands.
## Demos/LyrebirdAUv3Demo layout (104b)
```
Demos/LyrebirdAUv3Demo/
LyrebirdAUv3Demo.xcodeproj
LyrebirdAUv3Demo/ container app target
LyrebirdAUv3DemoApp.swift minimal SwiftUI app entry
ContentView.swift "Install me so the AU registers"
Info.plist
LyrebirdFMExtension/ .appex AUv3 extension target
LyrebirdFM.swift example SynthesizerBase subclass
LyrebirdFMAudioUnit.swift LyrebirdAudioUnit subclass
LyrebirdFMAudioUnitViewController.swift empty AUViewController (104c populates)
Info.plist AudioComponents declaration
README.md "How to copy this template"
```
## Example AudioComponentDescription
```xml
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>AudioComponents</key>
<array>
<dict>
<key>type</key> <string>aumu</string>
<key>subtype</key> <string>LBFM</string>
<key>manufacturer</key><string>RLZS</string>
<key>name</key> <string>Realized Sound: LyrebirdFM</string>
<key>version</key> <integer>1</integer>
<key>factoryFunction</key><string>...</string>
<key>sandboxSafe</key><true/>
<key>tags</key> <array><string>Synth</string></array>
</dict>
</array>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.AudioUnit-UI</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).LyrebirdFMAudioUnitViewController</string>
</dict>
```
## Validation pass
- `auval -v aumu LBFM RLZS` from terminal — must produce a `PASS` summary.
- Load in Logic Pro / GarageBand / AUM / Loopy Pro and verify the plugin
instantiates, exposes its parameters, and plays back via host MIDI.
## auval pitfalls 104a already handles
- `parameterTree` non-nil before `allocateRenderResources` ✓
- `latency` returns finite value (0 for instrument) ✓
- `tailTime` returns 0 for instrument ✓
- `internalRenderBlock` returns `noErr` and writes into the supplied ABL ✓
- `maximumFramesToRender` honoured by the driver's ring sizing ✓
## Open items handed off to 104b
- Code-signing scheme (Josh's team ID or placeholder for forks).
- iOS app-extension entitlements (`com.apple.security.app-sandbox` etc.).
- Embedding the SwiftPM `Lyrebird` package as a local dependency of the
Xcode project (vs. publishing the package to a registry).
- README walkthrough of "how to fork this template for your own synth".
+112
View File
@@ -0,0 +1,112 @@
# iOS Support — Roadmap ✓ COMPLETE
> All four phases shipped. See `docs/01-completed-working-order.md` (iOS phases section) for the authoritative implementation record. This file is preserved as the original plan with implementation notes appended.
Builds on prior analysis: `docs/support_for_iOS_findings.md`.
## What Stayed Untouched (as planned)
All Generators, SynthesisEngine, bus system, scheduling, patterns, MIDI, OSC, envelopes, spectral, granular — zero changes needed. ✓
`LyrebirdWindow.swift` was the only AppKit-only file expected. However, `ParameterKnob.swift` and `ParameterXY.swift` also used `Color(nsColor:)` / `NSColor` system colors — not caught during planning, discovered at iOS compile time. Fixed via `PlatformColors.swift` (see iOS-3 notes below).
---
## Phases
### Phase iOS-1 — iOSAudioDriver ✓
**Implemented as planned with one important correction:**
The original plan used `engine.sampleRate` for the AU stream format. In practice, `setPreferredSampleRate` is a hint — many devices (iPhone 6s+, most modern hardware) lock to 48 kHz regardless. Configuring the AU at 44100 when the session runs at 48000 causes a per-callback frame-count mismatch → choppy audio.
**Actual implementation:**
- AU stream formats use `session.sampleRate` (actual committed rate) after `setActive(true)`, not `engine.sampleRate`
- `setPreferredIOBufferDuration(blockSize / sampleRate)` added to align hardware buffer with `MaximumFramesPerSlice`
- Category: `.playback` for output-only (not `.playAndRecord` — avoids unnecessary mic permission); `.playAndRecord` + `.defaultToSpeaker` only when `numInputChannels > 0`
- `sessionSampleRate: Double?` property exposes actual committed rate
- Tests in `Tests/LyrebirdTests/iOSAudioDriverTests.swift` (`#if os(iOS)` guarded)
---
### Phase iOS-2 — Package.swift + LyrebirdC ARM64 ✓
`DenormalUtils.c` unchanged — `fesetenv(FE_DFL_DISABLE_DENORMS_ENV)` is a Darwin-wide extension available on iOS ARM64 without guards. `swift build` clean.
Added `.linkedFramework("AVFoundation", .when(platforms: [.iOS]))` to the `Lyrebird` target (not in original plan — needed because `iOSAudioDriver.swift` imports AVFoundation).
---
### Phase iOS-3 — LyrebirdUI AppKit Isolation ✓
`LyrebirdWindow.swift` guarded as planned. Additionally: `ParameterKnob.swift` and `ParameterXY.swift` used `Color(nsColor: .controlBackgroundColor/separatorColor)` — AppKit-only, not caught during planning.
**Fix:** New `Sources/LyrebirdUI/Controls/PlatformColors.swift` defines `Color.lyrebirdControlBackground` and `Color.lyrebirdSeparator` with `#if os(macOS)` / `#else` branches using `NSColor` / `UIColor` respectively. Both control files updated to use these instead.
---
### Phase iOS-4 — iOS Demo App
**Goal:** Runnable iOS demo proving the stack works end-to-end. Mirrors `LyrebirdMacOSDemo` layout and UI exactly.
**New:** `Demos/LyrebirdiOSDemo/LyrebirdiOSDemo.xcodeproj`
**Modified:** `Lyrebird.xcworkspace/contents.xcworkspacedata` — add new project ref
**Same source structure as macOS demo:**
```
LyrebirdiOSDemo/
LyrebirdiOSDemoApp.swift ← SwiftUI @main (replaces main.swift + AppDelegate)
Synthesizers/
SineToneUI.swift ← identical to macOS demo
UI/
NoteController.swift ← identical to macOS demo (no AppKit)
SineToneView.swift ← identical to macOS demo (pure SwiftUI)
```
### Phase iOS-4 — iOS Demo App ✓
**Key differences from original plan:**
AVAudioSession is pre-activated in `App.init` **before** `SynthesisEngine` is created, not just before `engine.start()`. This is required to read the hardware's actual sample rate and pass it into the engine at construction time. The original plan activated session inside `iOSAudioDriver.setup()`, which is called during `engine.start()` — too late for the engine's `sampleRate` property.
**Actual App.init pattern:**
```swift
let session = AVAudioSession.sharedInstance()
try? session.setCategory(.playback, mode: .default)
try? session.setActive(true)
let sampleRate = session.sampleRate // actual hardware rate
let driver = iOSAudioDriver()
let engine = SynthesisEngine(blockSize: 512, sampleRate: sampleRate, ...)
```
All other differences from macOS demo as planned:
- No `main.swift`, no `AppDelegate`, no `NSApplication`, no `LyrebirdWindow`
- SwiftUI `@main` App struct handles lifecycle
- `iOSAudioDriver()` instead of `CoreAudioDriver()`
- Engine `start()`/`stop()` tied to `.onAppear`/`.onDisappear` on root view
`SineToneView.swift` and `NoteController.swift` copy verbatim from the macOS demo — both are already pure SwiftUI/Swift with no AppKit.
---
## File Change Summary
| File | Change |
|------|--------|
| `Sources/Lyrebird/AudioDrivers/iOSAudioDriver.swift` | **New** — RemoteIO driver |
| `Sources/Lyrebird/AudioDrivers/CoreAudioDriver.swift` | Add `#if os(macOS)` guard |
| `Sources/LyrebirdUI/LyrebirdWindow.swift` | Add `#if os(macOS)` guard |
| `Package.swift` | Add `.iOS(.v18)` |
| `Sources/LyrebirdC/DenormalUtils.c` | Verify/guard ARM64 FTZ |
| `Demos/LyrebirdiOSDemo/` | **New** — iOS demo Xcode project (mirrors macOS demo) |
| `Lyrebird.xcworkspace/contents.xcworkspacedata` | Add iOS demo project ref |
Zero changes to all Generators, SynthesisEngine, bus system, all other LyrebirdUI files.
---
## Order of Operations
iOS-1 → iOS-2 → iOS-3 → iOS-4. Each phase is independently mergeable. iOS-2 and iOS-3 can be done in parallel. iOS-4 requires iOS-1 through iOS-3 complete.
+209
View File
@@ -0,0 +1,209 @@
# PitchShift A/B experiment — current pool model vs SC 4-head SOLA
Status: **resolved**. After A/B listening, the SC-faithful 4-head SOLA variant was
adopted as the primary granular pitch shifter and renamed to `PitchShift.Audio`. The
former dynamic grain-pool `PitchShift.Audio` was preserved (its tunable `overlap` and
selectable grain-read `interpolation` remain valuable) and renamed to
`TuneablePitchShift.Audio`. Tests, demos, benchmark, and `PitchShifting.md` were
updated end-to-end as part of the rename. The rest of this document is kept as the
historical experiment plan.
## Background
`Sources/Lyrebird/Generators/Granular/PitchShift.swift` currently uses a dynamic
grain pool: triggers fire every `windowSamples / overlap` ticks and allocate a
free `GrainState` slot. Default `overlap = 8`, pool size = 64.
The SuperCollider `PitchShift` UGen (`server/plugins/DelayUGens.cpp:4581–5044`)
uses a **fixed 4-read-head SOLA** model:
- Single power-of-two circular delay buffer, write head with `& mask` wrap.
- Always exactly four read heads. Each head re-triggered every `framesize / 4`
samples (cyclic stage 0→3).
- Window envelope is an inline accumulator: each head carries `ramp` and
`ramp_slope` floats; slope flips sign at quarter-window boundaries. Heads
1/3 form one inverted-slope pair, 2/4 another → 4-way constant-power
cross-fade.
- `samp_slope = 1 - pchratio`; read at `iwrphase - dsamp`. `startpos` is
set so the head trails the writer for any clamped pitchRatio.
- Output normalized by `value *= 0.5` to compensate triangle OLA gain of 2.0.
After the recent fixes ([PitchShift.swift:140](Sources/Lyrebird/Generators/Granular/PitchShift.swift)
lookback formula + inline triangle envelope) the Lyrebird implementation is
correct at all clamped pitchRatios but still spends per-grain bookkeeping time
the SC version doesn't.
## Goal
Determine whether replacing the current pool model with the SC 4-head SOLA
model is worth the migration cost. Decision based on three axes:
1. **Sound quality** — listening tests at typical and extreme settings.
2. **CPU cost** — measured at `overlap = 4` (matched comparison) and at
`overlap = 8` (Lyrebird's default).
3. **API surface** — what features (overlap parameter, pitchDispersion,
timeDispersion) survive in the 4-head model and which do not.
## Approach
### Side-by-side implementation
Add a second class `PitchShift.Audio4` (working name) implementing the SC
4-head SOLA model alongside the existing `PitchShift.Audio`. Both live in
`Sources/Lyrebird/Generators/Granular/PitchShift.swift` (or a new
`PitchShift4Head.swift`) and share `_Base`-like configuration where useful.
The 4-head class:
- Drops the `overlap` parameter (fixed at 4 by construction).
- Drops the dynamic `_grains: [GrainState]` pool and `lyrebirdGrainPoolSize`
dependency.
- Stores per-head fields directly on the class:
```swift
var dsamp1, dsamp2, dsamp3, dsamp4: Double
var dsampSlope1, dsampSlope2, dsampSlope3, dsampSlope4: Double
var ramp1, ramp2, ramp3, ramp4: Double
var rampSlope1, rampSlope2, rampSlope3, rampSlope4: Double
var stage: Int = 3
var counter: Int
let slope: Double // 2 / framesize
let framesize: Int
```
- Uses a power-of-two capture buffer (round `captureSize` up at init) and a
precomputed `_captureMask = captureSize - 1` for `& mask` wrap.
- Normalizes output by `* 0.5` to match SC's triangle OLA gain compensation.
- Keeps `pitchDispersion`: applied at each stage trigger, identical to SC.
- Keeps `timeDispersion`: applied to `startpos` via `+= timedisp * frand()`,
identical to SC.
### Surface decision
Two viable shapes:
**Option 1 — separate type**
- `PitchShift.Audio` keeps current grain-pool model, retains `overlap`.
- `PitchShift.Audio4` exposes the 4-head model, no `overlap` parameter.
- User picks. Both ship.
**Option 2 — switchable mode**
- `PitchShift.Audio` gains a `mode: PitchShiftMode` enum: `.pool` (current),
`.fourHead` (SC). Init dispatches to one or the other internally.
- Smaller API footprint; one type covers both.
Recommend **Option 1** for the experiment (cleanest diff, easiest to delete
the loser). Decision on long-term shape comes after measurement.
### Benchmark harness
Add a benchmark in `Sources/LyrebirdBenchmark/`:
- Single-instance stress: 1 PitchShift driven by a sine, 60 s render at 48 kHz,
blockSize 256. Measure wall-clock and per-block min/max/avg.
- Polyphonic stress: 32 instances in parallel groups, same render.
- Run for: pool model `overlap=4`, pool model `overlap=8`, 4-head model.
- Use Instruments (Time Profiler) for hot-path attribution if anything looks off.
### A/B listening test
Render six audio files via NRT (`docs/tooling/nrt-guide.md`) using a fixed
input (sine sweep + percussive sample + sustained voice):
| File | Model | pitchRatio | windowSize | overlap | Notes |
|------|-------|------------|------------|---------|-------|
| 1 | pool | 1.5 | 0.05 | 4 | matched comparison |
| 2 | 4-head | 1.5 | 0.05 | — | matched comparison |
| 3 | pool | 0.5 | 0.05 | 4 | octave down |
| 4 | 4-head | 0.5 | 0.05 | — | octave down |
| 5 | pool | 4.0 | 0.05 | 4 | extreme up — was the buggy region |
| 6 | 4-head | 4.0 | 0.05 | — | extreme up |
Save to a stable directory. Subjective listening + spectrogram inspection
(LyrebirdSpectrumView NRT capture, or external tool) for transient artifacts,
spectral leakage, periodic flutter.
### Test parity
Mirror the existing `PitchShiftTests` suite for `PitchShift.Audio4`:
- silence in → silence out
- pitchRatio clamp behavior
- deterministic output with fixed seed
- mul/add scaling
- high-pitchRatio read-head safety regression
Plus 4-head-specific:
- output gain compensation (`* 0.5`) verified against constant input
- `overlap` parameter not present (compile-time check or doc note)
## Decision criteria
After benchmarks + listening tests, switch architectures if **all three** hold:
1. 4-head CPU cost ≤ pool model at matched `overlap=4` (expected — fewer
indirections, fewer field loads, no slot scan).
2. 4-head sound quality is subjectively equal or better at the three
pitchRatio test points.
3. Loss of `overlap` parameter is acceptable. (The current docs already note
`overlap > 16` is a CPU-vs-quality knob with diminishing returns, so a
fixed 4 may be fine for most users.)
If any fail, keep both via Option 1 indefinitely or scrap the 4-head class.
## Files involved
| File | Role |
|---|---|
| `Sources/Lyrebird/Generators/Granular/PitchShift.swift` | current pool model, untouched until decision |
| `Sources/Lyrebird/Generators/Granular/PitchShift4Head.swift` | new 4-head class (Option 1) |
| `Tests/LyrebirdTests/PitchShift4HeadTests.swift` | parity test suite |
| `Sources/LyrebirdBenchmark/main.swift` | add PitchShift A/B benchmark |
| `docs/stdlib/generators.md` | document new type / mode if shipped |
## Estimated effort
- 4-head implementation + tests: ~half day.
- Benchmark harness + run: ~half day.
- A/B render + listening notes: ~half day.
- Decision + cleanup or merge: ~half day.
Total ~2 days when scheduled. Not blocking any current phase.
## Open questions — resolved at implementation time
1. **Param compatibility.** `windowSize > 0` precondition retained;
internal `framesize` clamps to ≥ 4 samples after rounding to a multiple
of 4. Audible difference at < ~3 samples is moot.
2. **`pitchRatio` clamp.** Kept at Lyrebird `[0.25, 4]` for cross-variant
consistency. SC's `[0, 4]` not adopted.
3. **MCE expansion.** Both mono; nothing to change.
## Implementation log
Landed:
- `Sources/Lyrebird/Generators/Granular/PitchShift4Head.swift` — `PitchShift.Audio4`
- `Tests/LyrebirdTests/PitchShift4HeadTests.swift` — 10 parity tests
- `Sources/LyrebirdBenchmark/main.swift` — A/B benchmark section
- `Sources/Lyrebird/Lyrebird.docc/Generators/PitchShifting.md` — variant section
Bench results (release build, 16 instances in parallel, 10 000 iterations):
```
PitchShift.Audio overlap=4 ×16 2968 ns/block
PitchShift.Audio overlap=8 ×16 2877 ns/block
PitchShift.Audio4 ×16 2864 ns/block
```
Single-instance numbers are dominated by `OscSin → Pan2 → Out` overhead, so the
inter-variant difference is small (≈ 2 % spread). At polyphony of 16, the 4-head
model is the fastest variant, edging the `overlap = 8` pool by ~0.5 % and the
matched `overlap = 4` pool by ~3.5 %. CPU criterion (1) is met.
## Pending — listening test + decision
Plan above (NRT renders at three pitchRatios, subjective listening + spectrogram
inspection) is unchanged. After listening:
- If `Audio4` is judged equal-or-better at all three pitchRatios: deprecate
`PitchShift.Audio` over a phase or two, keep `Audio4`.
- If both have niches: keep both indefinitely. Update DocC to nudge users toward
the right one (steady tonal material → Audio4; transient / textural material
with higher `overlap` → Audio).
- If `Audio4` is worse: revert the file, keep the bench as historical context.