Files
ReactorcoremeltdownandClaude Opus 5 0e8032532f 0.42.0 (79): preset randomizer for five devices (Android and iOS)
A RANDOM button in the preset bar of the Synth, Morph Pad, Grain Cloud,
Wavetable and Ambience Reverb editors: it rolls a playable patch and names it.
The rules live in core/src/model/Randomizer.cpp and are shared, so a seed gives
the same patch on both platforms. Android reaches it over JNI as preset text and
imports it; iOS writes the Params into the slot. Neither touches the slot's own
files — a loaded sample or an imported wavetable survives a roll, because the
dice are for the settings, not for the sounds.

Scattering values over the parameter ranges produces silence and the occasional
scream, so the rules encode three things instead: something always sounds (a
layer is always up, an envelope that decays to nothing gets a body, a filter is
never shut, a reverb is never fully dry); levels share a budget and resonance,
drive and saturation stay out of the range where a patch screams; and tunings
come from consonant intervals rather than a uniform draw.

core/tests/randomizer_test.cpp is the specification: it renders every device over
hundreds of seeds through the real voice and fails on anything out of range,
silent, clipping or non-finite. Every bound that looks arbitrary was put there by
a seed it caught — a band-pass parked above the note (peak 0.010 against a 0.3
median), a Vel -> Cutoff mod slot closing the filter (0.41 -> 0.02), a choir-only
Morph Pad through its own band-pass, and MORPH TO, which a roll now leaves alone
because MORPH TIME carries a held note all the way onto a factory drone at a
level the randomizer never chose (1.33 with every layer of its own at zero).
--dump <TYPE> <seed> [key=value ...] re-renders one roll with overrides, which is
how each of those was found.

Also fixes the shared engine not compiling outside Apple's toolchain: a missing
<cstdint> in core/include/sizzle/Model.hpp. No change to the apps, but the
engine's tests and benchmark now build with GCC too — which is how the rules
above were iterated while the Mac was unreachable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-18 21:02:24 +01:00

208 lines
12 KiB
Markdown

# Sizzle for iOS/iPadOS
Sizzle's instruments and effects as AUv3 plugins for hosts such as AUM, GarageBand
and Loopy, in one app (`cc.tiredsysadmin.ios.sizzle`, iOS/iPadOS 15+) installed
with TrollStore. This tree is separate from the Android app and has its own
Makefile (`make -C ios help`).
| Path | What it is |
|---|---|
| `../core/` | The shared C++ engine (Android plays through it too): a port of the Android app's Kotlin DSP |
| `../core/include/sizzle/DeviceSpecs.gen.hpp` | Every device's parameters, generated from `ToolboxType` (Kotlin) |
| `../core/tests/golden_test.cpp` | Compares the core with audio the Kotlin code renders |
| `../core/tests/voices/` | The `TestVoice` wrappers `golden_test` drives the instruments through. Under `tests/`, not `src/`, so neither app compiles them |
| `../core/tests/bench.cpp` | `make bench`: what the FX chain and each effect cost. Asserts nothing, so it is not part of `core-test` |
| `../core/tests/randomizer_test.cpp` | Plays what the preset randomizer generates over many seeds: in range, audible, not clipping. `--dump <TYPE> <seed> [key=value …]` inspects one roll |
| `app/components.txt` | The plugin list (AU type, subtype, device, name) |
| `app/FX/` | The plugin extension: `SizzleDeviceAU` (shared: parameters, presets, state), `SizzleEffectAU` (aufx), `SizzleInstrumentAU` (aumu), `SizzleFXViewController` (factory + editor). The app compiles the same classes to host them itself |
| `app/Host/SizzleSession*` | The bridge to the C++ song + engine (audio output, song lock, live-note queue); one category per screen |
| `app/Host/Screens/` | Tracker, Mix, Toolbox, Setup (SwiftUI, ported from the Android tabs); `make screen-snapshots` renders them on the Mac |
| `app/Host/` | The app: `SizzleHost` plays the devices in-process (instrument → effect → output, keyboard, MIDI in, samples, benchmark); `PluginCheck` checks the extension's plugins |
| `app/tests/au_test.mm` | Mac-side test of the AUv3 wrapper |
| `app/FX/Editor/` | The SwiftUI device editor (cards, knobs, drawings), from `DeviceLayouts.json` (exported from Android) and `BespokeLayouts.swift` |
| `app/tests/editor_snapshots.swift` | `make editor-snapshots`: renders every editor tab to PNG on the Mac |
| `tools/gen_components.py` | `components.txt` → the extension's Info.plist and `Components.gen.h` |
| `spike/` | The TrollStore AUv3 feasibility spike (see the end of this file) |
Versions: `versionName` / `versionCode` in `../versions.properties`, shared with Android
(`make -C ios bump-minor` etc.); the .ipa is named by versionCode. Changes are
listed in `CHANGELOG.md` here.
## How the port is verified
The Kotlin DSP is the reference. It lives in the Android app's **test** source set
(`../app/src/test/java/.../audio`, `frasil`, `echofield`, `wavetable`) — both apps
play `core/`, so it is no longer part of either one. `make golden` runs
`IosGoldenExport` (a JVM unit test in the Android app, skipped by the normal
`make check`), which:
- writes `DeviceSpecs.gen.hpp`, so iOS uses the same parameter definitions
(keys, labels, ranges, defaults, choices) and the Mix Tightener presets;
- renders a fixed 1.5 s test signal (decaying saw burst, noise, sine sweep,
silences for tails) through every effect at its defaults and two variants that
move every parameter (the Mix Tightener uses three of its presets instead), into
`../core/golden/` (not committed; regenerate any time).
`make core-test` renders the same scenarios through the C++ core and requires a
largest difference below 1e-4. Today all 61 pass; most are bit-exact, the rest
differ by about one float ulp. It compiles the core at `-O2` — and so does Xcode
(`GCC_OPTIMIZATION_LEVEL: 2` on the `SizzleCore` target in `app/project.yml`, in
every configuration), so the build that ships is the build that was measured. An
optimisation level is not a free choice here: it decides FP contraction, and the
comparison only holds for the level the tests use. Porting rules that make this
possible:
- translate line for line, keeping Kotlin's types: `Float` → `float`,
`Double` → `double`, so every expression runs in the same precision;
- `kotlin.math` on a Float goes through Java's double `Math` and rounds back:
use the helpers in `../core/src/fx/KotlinMath.hpp` (`roundToInt` is floor(x+0.5),
`toInt` truncates and saturates);
- Kotlin `Int` wraps and `ushr` is a logical shift: use `uint32_t` for the
xorshift generators;
- settings are text, as in `ToolboxSlot`: `Params::f()` / `Params::s()` read
exactly what `slot.float()` / `slot.string()` would.
Known gap: the Tape Delay "low" variant switches all four heads off (on-values
below 0.5), so it only tests the dry path; add a scenario with heads on.
`make au-test` then checks the AUv3 wrapper on the Mac (AUAudioUnit exists on
macOS): every effect is registered in-process and driven through AVAudioEngine.
The output must equal the core's at defaults and after moving every parameter
through the AU, a Mix Tightener factory preset must equal the core with that
preset, and `fullState` must restore into a fresh instance. It also calls the
render block directly with an upstream that points the input buffers at its own
memory instead of filling the plugin's, with and without host output buffers.
All pass bit-exact.
That last check exists because AVAudioEngine in-process copies the input into the
plugin's buffers, but out of process (every real host on iOS) the input arrives
by pointer. 0.1.0 read its own buffers and was silent on the iPad while every Mac
test passed. Render code must read the input from the pulled AudioBufferList,
never from the buffers it offered.
## The plugins (0.1.0: the eight audio effects)
All eight are `aufx` plugins from one extension (`SizzleFX.appex`), manufacturer
`Tsys`, named "Tired Sysadmin: Sizzle <device>". The extension's factory picks
the device by subtype; subtypes are in `app/components.txt` and must never change
once shipped, since hosts save projects by them.
`SizzleEffectAU` (Objective-C++, no Swift on the audio path):
- **Parameters** come from the generated specs: address = index in the device's
parameter list; choices become indexed parameters with value strings; whole
numbers use the indexed unit.
- **Stereo:** the Kotlin effects are mono (Sizzle's mixer is mono), so each
channel runs its own instance (dual mono). Mono and stereo buses are accepted.
- **Threads:** AU parameter changes (host, automation events, the editor) go into
one atomic float per parameter. Whole settings (presets, restored state,
hidden keys such as the Mix Tightener's) go through a two-slot mailbox. The
render thread copies, overlays the parameter values, and calls
`Effect::update` only when something changed or the host tempo moved. No locks
on the audio thread. (Applying changes formats and parses text with
`snprintf`/`strtof` on the audio thread, only when something changed; a
numeric fast path can replace that later.)
- **Tempo** comes from the host's musical context (120 BPM without one), for the
tempo-synced Delay and Tape Engine.
- **Presets:** the Mix Tightener's factory presets are AU factory presets; user
presets use the AU's `fullState`, which stores every key as text
(`sizzleValues`), hidden ones included.
- **Bypass** passes the input through; non-finite output samples are zeroed.
The editor is generic for now (sliders, segmented switches for short choice
lists, menus for long ones, a preset menu); the card editors of the Android app
come later.
The container app lists the registered plugins, and **Check all plugins** loads
each one out of process (as a host does), renders a test signal offline and
reports PASS (finite, not silent) or FAIL.
### Build
```sh
make -C ios ipa # → ios/dist/cc.tiredsysadmin.ios.sizzle_<versionCode>.ipa
make -C ios core-test # C++ core vs Kotlin reference
make -C ios au-test # the AUv3 wrapper on the Mac
```
The device build is unsigned, then ad-hoc signed inside-out (extension first)
with each target's entitlements and zipped as `Payload/`. TrollStore re-signs at
install and keeps the entitlements.
The extension links the core with `-force_load`: effect makers are found through
weak placeholders in `Registry.cpp` (so the core test can link before every port
exists), and from a static library the linker would otherwise keep the
placeholders and leave the real ports out. That happened once; the symptom would
have been every plugin failing to start.
### Open problem: plugin registration stopped on the test iPad (2026-11-14)
On the iPad mini 4 (iOS 15.8.8, TrollStore 2), iOS stopped registering AUv3
plugins from TrollStore-installed apps partway through the evening:
- 0.1.0 (fresh install) and 0.1.1 (update) registered: mediaserverd listed all 8
`Tsys` effects, and AUM saw them (log at 21:08:46).
- Installing 0.1.2 as an update (21:11:51): mediaserverd's AUExtensionScanner
logged "NSExtensions changed for com.apple.AudioUnit-UI … added 0, removed 8".
Since then no newly installed TrollStore AUv3 is added. That includes Sizzle
0.1.0 reinstalled fresh, the extension under a new bundle ID, and the spike
reinstalled, with System or User registration. The install itself works
(LaunchServices registers the app; the plugin's data container is created);
only the audio system never sees the components. A restart and TrollStore's
"Refresh App Registrations" didn't change it.
- The package is not the cause: 0.1.0 and 0.1.2 differ only in version numbers and code.
Not yet known: whether a fresh App Store AUv3 install still registers (i.e.
whether this is TrollStore-specific), and what state the 0.1.2 update left
behind. The effects' silence fix (0.1.1) and the crash-proof check (0.1.2) are
therefore not confirmed on the device yet.
### Test on the iPad
1. Install the newest `cc.tiredsysadmin.ios.sizzle_<n>.ipa` with TrollStore.
2. Open **Sizzle**, tap **Check all plugins**: 8/8 should pass. With the iPad on
USB, `idevicesyslog` (`brew install libimobiledevice`) shows the plugin
process as `SizzleFX` and the host side as `Sizzle(AudioToolboxCore)`;
`idevicecrashreport -k -e <dir>` copies crash reports without deleting them.
3. In AUM, add an audio track or a synth, then an effect slot: the plugins are
listed as "Tired Sysadmin: Sizzle …". Try the editor, a Mix Tightener preset,
and saving and reopening an AUM session (restores `fullState`).
## Decisions
- **C++ core, not Kotlin/Native:** an AUv3 render callback must not allocate,
lock or wait for a garbage collector; plain C++ with preallocated state meets
that, and can later replace the Kotlin DSP on Android through JNI.
- **Reference audio instead of reading the code twice:** the Kotlin output is the
specification, so ports can be done by anyone (including parallel agents) and
checked mechanically.
- **XcodeGen:** projects are text (`app/project.yml`); generated projects are
git-ignored. Generated sources that iOS needs to build without the Android
toolchain (`DeviceSpecs.gen.hpp`, `FX/Info.plist`, `Components.gen.h`) are
committed.
- **One extension, factory dispatch** instead of one extension per device.
- **Generic editor first:** every parameter is reachable now; the card editors
(tabs, knobs, drawings) are a separate step.
## Next steps
All five milestones of PORTING.md are in (0.6.0). Open:
1. Sample and SF2 / wavetable files for the plugins through an App Group
(`group.cc.tiredsysadmin.ios.sizzle`), so LOAD WAV / LOAD TABLE work in AUM.
2. MIDI effects (Arpeggiator, Transposer, LFO) as `aumi` plugins.
3. On-device checks of 0.6.0: MIDI devices and apps, clock in/out, gamepads,
hardware keyboards, recording, bundles exchanged with the Android app.
## The TrollStore spike (spike/)
A host app with one sine AUv3 instrument and an App Group self-test, built to check
feasibility before porting (`make -C ios spike-ipa`).
- **Build 1:** AUM listed the plugin, loaded it and played it from a MIDI
keyboard, so hosts do see AUv3 plugins from a TrollStore install. The app
closed right after opening, and AUM showed a red X instead of an icon.
- **Build 2:** added an app icon (AUM's red X went away), the SwiftUI scene
manifest, and a crash-proof self-test on a button. Confirmed on the iPad: the
self-test works, the icon shows, sound works.