Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
6.3 KiB
Markdown
108 lines
6.3 KiB
Markdown
# Porting Sizzle to iOS/iPadOS
|
|
|
|
The whole Android app (`../app`, ~20k lines of Kotlin) as a native iOS/iPadOS 15+
|
|
app. Target hardware includes the iPad mini 4 (A8, 2 GB RAM). Decided 2026-11-15:
|
|
|
|
- **Interface:** native, SwiftUI with UIKit where SwiftUI is too slow on an A8
|
|
(the tracker grid). Written fresh, following the Android screens.
|
|
- **Engine, model and file formats:** C++ in `core/`, each part checked against
|
|
the Kotlin app's own output (reference audio and reference files), like the
|
|
effects in 0.1.x. Swift talks to the core through an Objective-C++ facade.
|
|
- **Plugins:** the AUv3 extension keeps shipping Sizzle's devices to other hosts;
|
|
the app itself hosts the same code in-process (no per-plugin process cost, no
|
|
dependence on the system plugin registry).
|
|
|
|
The Kotlin app stays the reference. When it changes, the reference files are
|
|
regenerated (`make -C ios golden`) and the C++ follows.
|
|
|
|
## Map: Android → iOS
|
|
|
|
| Android (Kotlin) | Lines | iOS | How it's checked |
|
|
|---|---|---|---|
|
|
| `audio/Effects.kt`, `AmbienceReverb.kt` | 1,150 | `core/src/fx` (done in 0.1.0) | reference audio per effect |
|
|
| `audio/SynthVoice.kt`, `SynthPatch.kt` | 500 | `core/src/synth` | reference audio per voice |
|
|
| `frasil/` (Morph Pad) | 950 | `core/src/frasil` | reference audio per voice |
|
|
| `wavetable/` | 730 | `core/src/wavetable` | reference audio per voice, table data |
|
|
| `echofield/`, `audio/GrainSources.kt` (Grain Cloud) | 1,100 | `core/src/echofield` | reference audio per voice |
|
|
| `audio/SampleVoice.kt`, `SampleStore.kt`, `SoundFontLoader.kt` | 570 | `core/src/sampler` | reference audio with generated samples / test SF2 |
|
|
| `model/` | 1,360 | `core/src/model` | via file round trips and full-song renders |
|
|
| `audio/AudioEngine.kt` (sequencer, mixer, routing, arp, clock) | 1,680 | `core/src/engine` | full-song renders (`samples/*.sng`, generated songs) |
|
|
| `io/` (.sng, projects, presets, bundles, backups) | 1,800 | `core/src/io` | Kotlin-written files parsed and re-written byte-identical |
|
|
| `input/` (MIDI in/out, clock, gamepad, key bindings) | 1,350 | CoreMIDI, GameController (Obj-C++/Swift) | unit tests on the parsers; on device |
|
|
| `playback/` (background service, sound module) | 430 | AVAudioSession, background audio | on device |
|
|
| `ui/` + `AppViewModel` | 8,000 | `app/` SwiftUI | on device / simulator screenshots |
|
|
|
|
## Milestones
|
|
|
|
Each milestone ends with a build that runs on the iPad.
|
|
|
|
1. **Instruments in C++.** Synth, Morph Pad, Wavetable, Grain Cloud, then Sampler
|
|
and SF2/XI, each matching Kotlin voice renders. Plus AUv3 instruments (`aumu`)
|
|
and the in-app host's first form: a device list with a keyboard, so each one
|
|
can be played on the iPad and measured on the A8.
|
|
2. **Model, files and engine.** Project model, .sng / project / preset formats
|
|
(byte-identical round trips with Kotlin-written files), and the sequencer and
|
|
mixer engine (full-song renders match Kotlin). MIDI effects (arp, transposer,
|
|
LFO) come with the engine.
|
|
3. **App shell and tracker.** Tabs (Tracker, Mix, Toolbox, Setup), transport,
|
|
pattern grid, arrangement roll, keyboards, song load/save. Audio through
|
|
AVAudioEngine; background audio.
|
|
4. **Toolbox and mixer.** Device editors (cards from the DeviceLayouts data, then
|
|
the bespoke editors), presets, mixer with FX routing.
|
|
5. **Everything else.** MIDI in/out and clock sync, gamepad and key bindings,
|
|
recording, sample recorder, sharing/import, backups, themes, settings.
|
|
|
|
## Progress
|
|
|
|
- 2026-11-15: all six instruments' sound is in C++ and matches Kotlin bit for bit
|
|
(Synth, Morph Pad, Wavetable, Grain Cloud, Sampler, SF2/XI), plus the 12 factory
|
|
wavetables, the sample store and the WAV/SF2/XI readers (`core/tests/sampler_test`).
|
|
`make -C ios core-test`: 61 reference scenarios + 16 sampler tests.
|
|
|
|
- 2026-11-15, 0.2.0: the instruments as AUv3 (`aumu`) on `sizzle::Instrument` (the
|
|
engine's per-channel voice pool), checked on the Mac against the C++ instruments
|
|
with sample-accurate MIDI (`make -C ios au-test`). The app hosts every device
|
|
in-process (`SizzleHost`, manufacturer 'Tsyl'), so it works without the system
|
|
plugin registry, and benchmarks each device on the device it runs on.
|
|
|
|
Measured on the iPad mini 4 (A8, iOS 15.8.8), 0.3.0's Benchmark: 10 s of 44.1 kHz
|
|
audio per device, share of one core (instruments with an 8-note chord held,
|
|
effects on noise, stereo):
|
|
|
|
| Device | Cost | Device | Cost |
|
|
|---|---|---|---|
|
|
| Ambience Reverb | 9.3% | Morph Pad (8 notes) | 9.6% |
|
|
| Tape Delay | 1.5% | Wavetable (8 notes) | 6.1% |
|
|
| 10-Band EQ | 1.4% | Synth (8 notes) | 5.0% |
|
|
| Tape Engine | 1.1% | Grain Cloud (8 notes) | 1.1% |
|
|
| Mix Tightener | 0.9% | SF2/XI loader (8 notes) | 0.8% |
|
|
| Bitcrusher | 0.5% | Sampler (8 notes) | 0.4% |
|
|
| Filter | 0.3% | | |
|
|
| Granular Glitch | 0.2% | | |
|
|
|
|
All fourteen together come to about 38% of one core; the A8 has two. The C++ DSP is
|
|
cheap enough for the whole suite on this iPad. What made AUM struggle with a few
|
|
AUv3s is the per-plugin process round trip, which the in-app host avoids.
|
|
|
|
Notes for the engine port (from the voice ports):
|
|
- Kotlin seeds every new FrasilVoice and GrainCloud from global counters, and every
|
|
SynthVoice builds a FrasilVoice. The C++ engine owns one `frasil::FrasilSeeds`,
|
|
one `echofield::GrainSeeds` and one `frasil::FrasilClock`, and builds its voice
|
|
pools in AudioEngine's order, or full-song renders won't match.
|
|
- `synth::SynthPatch` has an id standing in for Kotlin's object identity
|
|
(`setPatch` skips retuning for the same patch): reuse the patch built per block,
|
|
don't rebuild it.
|
|
- `sampler::SampleStore`: the audio thread calls `quiescent()` once per block;
|
|
voices pin samples. The Grain Cloud's custom-sample pointer isn't pinned yet.
|
|
|
|
## Rules for ports
|
|
|
|
- Translate line for line and keep Kotlin's types (`Float` → `float`, `Double` →
|
|
`double`); use `core/src/fx/KotlinMath.hpp` for kotlin.math semantics;
|
|
`uint32_t` for xorshift; port `java.util.Random` exactly where it is seeded.
|
|
- No allocation or locks on the audio path; allocate in constructors / `prepare`.
|
|
- A port is done when its reference scenarios pass (`make -C ios core-test`).
|
|
Never loosen the tolerance; find the precision difference instead.
|
|
- Global Kotlin state (e.g. `FrasilClock`) becomes explicit state passed in or
|
|
owned by the engine, and the reference files record its starting value.
|