Files
sizzletracker-android/ios/PORTING.md
T
ReactorcoremeltdownandClaude Opus 5.5 435305e42a iOS 0.5.0: hand-built editors (Tape Delay, Tape Engine, Mix Tightener, Granular scope, Wavetable tables, Grain Cloud source)
Effect visualisation through the C++ effect, engine and AU; custom wavetables and
grain sources load and persist with the song; the app's slot editor hosts the
file picker for bespoke views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:01:14 +01:00

8.4 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.

  • 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.

  • 2026-11-15: the engine (core/src/engine, sizzle::engine::Engine): AudioEngine.kt's sequencer, arrangement playlist with loop regions, note-offs, arpeggiator, transposer, MIDI LFO, mixer, FX chains and master limiter. core/tests/engine_test renders the four reference songs (demo, mix, waltz, midifx) and matches Kotlin (demo and midifx bit for bit; mix and waltz within 1e-5, from the Tape Engine's known one-ulp difference fed through the rest of the song). Not ported: audio output (the app calls fillBlock), WAV writing (MasterSink), CoreMIDI (the engine fills the outgoing queue, pollMidiOut), effect scope/playhead views (done in 0.5.0: Granular Glitch). Decisions: the voice pools are built in AudioEngine's field order from EngineGlobals (clock and seed counters); swapped FX chains and playlists are freed by a later main-thread rebuild once the audio thread has finished a block; the live note calls touch voices directly like the Kotlin, so the app must call them on the audio thread (or serialise them with it). The MIDI LFO writes its value into the target slot as text every block, like Kotlin; that goes through kotlinFloatToChars (no allocation).

  • 2026-11-16: file formats (core/src/io, sizzle::io): ProjectIo (.szg), SngFormat (.sng) and PresetIo (.szp), ported from io/*.kt with Kotlin's string semantics (io/KotlinText: lineSequence, Unicode trim, toIntOrNull with Unicode digits, toFloatOrNull with Java's parseFloat grammar). core/tests/io_test re-writes every reference file byte for byte, except [TOOLBOX] pairs (Kotlin writes ConcurrentHashMap order; compared as sets), and checks .szg -> .sng / .szp. model::kotlinFloatToString is JDK 17's FloatingDecimal ported line for line and was compared with JDK 17.0.14 on all 2^32 float bit patterns. Kotlin's own lossy spots, kept as is: PresetIo.import drops NAME (fill() overwrites it); a .sng track channel comes from the mixer, which import leaves alone; names with ;, values with , or = break a [TOOLBOX] line. Params caps keys at 23 bytes, values at 31 and slots at 96 keys, so a long sample path would be cut short.

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.