Files
Lyrebird/docs/roadmap/ios-support.md
T
2026-06-01 18:27:40 -07:00

5.4 KiB

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:

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.