Files
sizzletracker-android/ios/PORTING.md
T
ReactorcoremeltdownandClaude Opus 5.5 a5b2f4c873 iOS core: Synth voice, Sampler, sample store and SF2/XI loader ported, bit-exact with Kotlin
All six instruments now run in C++ (61 reference scenarios, 16 sampler tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:06:51 +01:00

5.0 KiB

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.

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.