0.41.1 (77): cleanup and optimisation round (Android and iOS)

Nothing user-visible changes, except that the Android app is half the size and
both are lighter on the battery.

R8 is on for release builds (21.5 MB -> 10.1 MB); only the two JNI classes are
pinned by name, since the app reflects over nothing of its own, and `make dist`
keeps the mapping beside the APK. The Kotlin DSP that core/ replaced in 0.37.0
was still compiled into every APK with nothing calling it — it moves to the test
source set, where it belongs as the reference the C++ is checked against — and
the golden tests' TestVoice wrappers leave core/src for core/tests/voices, so
neither app compiles them either.

Speed: channel gain, mute/solo and the FX chain are read once per audio block
instead of once per frame in Engine::fillBlock (both platforms, bit-identical —
all 61 reference scenarios still match); the transport pollers idle at 100 ms
(Android) and 10 Hz (iOS) instead of polling flat out while a song is stopped,
woken by any transport call; ProjectIo.save builds into one pre-sized buffer and
a burst of edits is coalesced into one engine sync; the Kotlin grain sources and
factory wavetables are built when their editor opens rather than at launch, where
they duplicated ~6 MB the engine already renders in core/; and Xcode builds the
DSP core at -O2, the level the golden tests measure, not -Os.

Fix: `make lint` failed on a manifest asking for ACCESS_FINE_LOCATION without
ACCESS_COARSE_LOCATION (the BLE MIDI scan on Android 8-11), so `make check`
passes again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Reactorcoremeltdown
2026-11-18 10:21:09 +01:00
co-authored by Claude Opus 5
parent cdabf3018b
commit dd04a61e22
46 changed files with 508 additions and 192 deletions
+94 -53
View File
@@ -41,7 +41,7 @@ in exactly what it needs and nothing else:
| `make staging` | non-debuggable build, release-like performance, debug key |
| `make install` | `adb install -r` of the staging APK (keeps projects/presets) |
| `make release` | **unsigned** release APK, named for F-Droid |
| `make dist` | stages the release APK + F-Droid metadata under `dist/` |
| `make dist` | stages the release APK + its R8 mapping + F-Droid metadata under `dist/` |
| `make publish` | uploads `dist/` to the private F-Droid repo — **manual only** |
| `make bump-minor` | feature bump: `x.(y+1).0`, versionCode +1 |
@@ -98,11 +98,11 @@ the numbers by hand is how they drift apart.
### 2.3 Build types
| Type | Debuggable | Signing | Use |
|------|-----------|---------|-----|
| `debug` | yes | debug key | breakpoints, instant-run edits |
| `staging` | **no** | debug key | anything on a real device |
| `release` | no | **unsigned** | publishing only |
| Type | Debuggable | R8 | Signing | Use |
|------|-----------|----|---------|-----|
| `debug` | yes | no | debug key | breakpoints, instant-run edits |
| `staging` | **no** | no | debug key | anything on a real device |
| `release` | no | **yes** | **unsigned** | publishing only |
`staging` exists because `debug` is misleading: a debuggable build makes ART run
the app un-optimised and Compose several times slower, so UI "snappiness"
@@ -114,6 +114,22 @@ installs without a release keystore. **Use `staging` for every on-device test.**
the private F-Droid repo; `fdroid publish` signs what lands in the unsigned
directory. No keystore should ever exist in this checkout.
`release` is also the only build R8 touches (shrink + optimise + obfuscate, plus
unused-resource removal). The app reflects over nothing of its own — songs,
presets, themes and bindings are all hand-written text parsers — so
`app/proguard-rules.pro` keeps exactly one thing: **native method names**. JNI
resolves `Java_cc_tiredsysadmin_android_sizzle_audio_NativeEngine_*` by name at
runtime, so a renamed class or method is an `UnsatisfiedLinkError` on first play,
not a build error. Everything else (Compose, media3, DataStore, coroutines) ships
its own consumer rules inside its AAR.
A release stack trace is therefore obfuscated. `make dist` copies
`app/build/outputs/mapping/release/mapping.txt` to
`dist/<application_id>_<versionCode>-mapping.txt`; keep it for every published
APK, because it is the only way to read a crash from that build. It is never
uploaded. `staging` keeps R8 off on purpose: it exists to measure the UI, and a
readable stack trace is worth more there than the last few hundred KB.
### 2.4 Publishing
Publishing is **always a manual action, never automatic** — it is not a side
@@ -214,35 +230,28 @@ cc.tiredsysadmin.android.sizzle
│ ├── MidiTrace.kt Optional receive/engine trace (setprop log.tag.SizzleMidiTrace VERBOSE)
│ └── MidiInput.kt Lists/opens MIDI sources (USB, BLE, other apps' virtual ports), reconnects dead ones -> MidiSoundModule / CC bindings
│
├── audio/ The real-time sound engine (own thread)
├── audio/ The engine's face (the DSP itself is core/, in C++)
│ ├── AudioEngine.kt Drives core/ through NativeEngine: transport, sync, meters, recording
│ ├── NativeEngine.kt JNI to core/src/host/EngineHost (src/main/cpp/jni_engine.cpp)
│ ├── NativeAudioBridge.kt Starts/stops the Oboe stream (which renders in C++, no JVM call)
│ ├── Transport.kt TransportState snapshot published to the UI
│ ├── SynthVoice.kt One synth note (3-osc subtractive), or a Morph Pad / Wavetable note (FrasilVoice / WaveVoice)
│ ├── GrainSources.kt The Grain Cloud's ten built-in sources, synthesised in the background
│ ├── SampleVoice.kt Pitched + sliced playback of a decoded sample
│ ├── SampleStore.kt Process-wide decoded-PCM cache + WAV encode/decode
│ ├── SampleStore.kt Process-wide decoded-PCM cache + WAV encode/decode (mirrored into core/)
│ ├── SampleRecorder.kt Ad-hoc mic/USB capture into a sample
│ ├── SoundFontLoader.kt Extract PCM from an .sf2 / .xi into the SampleStore
│ ├── Effects.kt Insert DSP: TapeDelay, Filter, Bitcrusher, GraphicEq (+ AudioEffect API)
│ ├── AmbienceReverb.kt FDN reverb processor
│ ├── MasterRecorder.kt Renders the master bus (with FX tail) to a WAV
│ ├── NativeAudioBridge.kt JNI bridge to the Oboe callback (calls fillBlock)
│ └── AudioEngine.kt Oboe/AudioTrack + sample-accurate sequencer + voice/FX mixing
│ └── GrainSources.kt The Grain Cloud's ten built-in sources (the UI draws their peaks)
│
├── frasil/ MPL-2.0 (not GPL): the Morph Pad, ported from FRASIL (see §5.7)
│ ├── FrasilDefs.kt Its settings, engine-unit mapping, the 36 drone presets
│ ├── FrasilPatch.kt Parsed slot snapshot (+ morph target); FrasilClock (the shared TIDE time)
│ └── FrasilVoice.kt One pad note: choir + partials + breath, drift, tide, warmth
│ └── FrasilDefs.kt Its settings, engine-unit mapping, the 36 drone presets
│
├── wavetable/ The Wavetable synth (Sizzle's own, GPL; see §5.9)
│ ├── WaveTables.kt Band-limited tables: FFT, one mip level per octave, 12 generated tables, WAV import
│ ├── WaveDefs.kt Its settings, 12 factory presets
│ └── WaveVoice.kt WavePatch + one note: 2 table oscillators, bend, unison, sub, SVF, 2 envelopes, LFO
│ ├── WaveTables.kt Band-limited tables: FFT, one mip level per octave (the editor draws them)
│ └── WaveDefs.kt Its settings, 12 factory presets
│
├── echofield/ MIT: the Grain Cloud, ported from ECHOFIELD (see §5.8)
│ ├── EchofieldDefs.kt Its settings, 14 factory presets, the source list
│ └── GrainCloud.kt GrainPatch + one channel's cloud: modes, scheduler, grains, gate, auto-level
│ └── EchofieldDefs.kt Its settings, 14 factory presets, the source list
│
├── cpp/native_audio.cpp Low-latency Oboe stream; RT callback pulls audio via JNI
├── cpp/native_audio.cpp Low-latency Oboe stream; its RT callback renders core/ directly
├── cpp/jni_engine.cpp The JNI surface of core/src/host/EngineHost
│
├── io/ Human-readable text persistence
│ ├── PresetIo.kt Instrument/effect preset <-> KEY=VALUE text
@@ -409,11 +418,17 @@ playback continues. Samples go across as they enter `SampleStore` (`put` /
`remove` mirror into the native store). Transport, meters, scope and finished
recordings are polled from a 10 ms thread.
The Kotlin engine (`ReferenceEngine` and the voices and effects under `audio/`,
`frasil/`, `echofield/`, `wavetable/`) is now only a reference: the
`IosGolden*` unit tests render it so the C++ can be checked bit for bit
(`make -C ios golden core-test`). The UI still uses a few of those Kotlin classes
to draw (wavetable frames, Grain Cloud source peaks, sample decoding).
The Kotlin engine is now only a reference, and lives in the **test** source set:
`app/src/test/java/.../audio` (`ReferenceEngine`, `SynthVoice`, `SynthPatch`,
`Effects`, `AmbienceReverb`, `SampleVoice`, `MasterRecorder`), `.../frasil`
(`FrasilVoice`, `FrasilPatch`), `.../echofield` (`GrainCloud`) and
`.../wavetable` (`WaveVoice`). The `IosGolden*` unit tests render it so the C++
can be checked bit for bit (`make -C ios golden core-test`). It is **not** in
`src/main`, because nothing in the app calls it any more — there it would only be
dead code in every APK. What the UI genuinely still needs to *draw* did stay in
`src/main`: `wavetable/WaveTables` (table frames), `audio/GrainSources` (source
peaks), `audio/SampleStore` + `SoundFontLoader` (sample decoding), and the three
`*Defs` files (parameter and preset data, shared with the editors).
**Parity rule:** every feature or fix lands in both apps in the same change, with
one shared version bump. Engine and DSP work goes into `core/` only.
@@ -429,7 +444,9 @@ ordinary device callback, so it is listed and played like USB gear. Connected
addresses are remembered (`SettingsStore.bleMidiDevices`) and reopened by
address at start, without a scan. Permissions: `BLUETOOTH_SCAN`
(`neverForLocation`) + `BLUETOOTH_CONNECT` on Android 12+, `ACCESS_FINE_LOCATION`
(and the legacy `BLUETOOTH` / `BLUETOOTH_ADMIN`) on 8-11, asked for when SCAN is
with `ACCESS_COARSE_LOCATION` (the platform treats FINE as an upgrade of COARSE
and refuses a FINE-only request; `make lint` enforces it) and the legacy
`BLUETOOTH` / `BLUETOOTH_ADMIN` on 8-11, asked for when SCAN is
first tapped. The emulator has no usable Bluetooth radio (its Bluetooth service
crashes on a scan); test on a phone.
@@ -710,14 +727,20 @@ of real time on a desktop JVM.
### Add a new instrument or effect
1. Add an entry to `ToolboxType` (`model/Toolbox.kt`) with its `ParamSpec` list.
2. Teach the engine how to sound it:
It all happens in `core/` (C++), which is what both apps play — never in the
Kotlin reference, which only follows so the golden comparison still holds:
- **Instrument**: handle its type where the engine picks a voice per channel
(see how `NES_SYNTH`, `SAMPLER`, and `SOUNDFONT` are dispatched in
`AudioEngine`).
- **Signal effect**: add a processor in `audio/Effects.kt` implementing
`AudioEffect` and register it in `AudioEffect.create(...)`; the per-channel
insert chain picks it up automatically.
(see how `NES_SYNTH`, `SAMPLER` and `SOUNDFONT` are dispatched in
`core/src/engine/Engine.cpp`).
- **Signal effect**: add a processor under `core/src/fx/` implementing
`sizzle::Effect` (`core/include/sizzle/Effect.hpp`) and register its maker in
`core/src/fx/Registry.cpp`; the per-channel insert chain picks it up
automatically, and so does the AUv3 wrapper once it is in `ios/app/components.txt`.
- **MIDI effect** (arp/transpose/LFO-style): hook into the sequencer instead
of the signal path (see `advanceArps` / `applyLfos` in `AudioEngine`).
of the signal path (see `advanceArps` / `applyLfos` in `Engine.cpp`).
- **Keep the reference in step**: mirror the change in the Kotlin file under
`app/src/test/.../audio` (or `frasil` / `echofield` / `wavetable`), then
`make -C ios golden core-test` to check the two sample for sample.
The Toolbox picker, parameter editor, and preset save/load all work automatically
from the `ParamSpec` list (the editor then shows one card with every parameter).
3. Group its controls: add a case to `DeviceLayouts.pagesFor` (cards, tones,
@@ -740,14 +763,25 @@ the Settings theme picker immediately.
## 7. Threading & performance notes
- The audio render loop is in `AudioEngine.renderLoop()` on a `MAX_PRIORITY`
thread. It **must never allocate or block**. Keep it that way.
- The audio render loop is `Engine::fillBlock` in `core/src/engine/Engine.cpp`,
called from the Oboe real-time callback (`src/main/cpp/native_audio.cpp`) — all
C++, with no JVM call on the audio thread, so no GC pause can glitch it. It
**must never allocate, lock or block**. Keep it that way: the active-voice index
lists are rebuilt once per block, per-channel mixer gains and FX-chain pointers
are hoisted out of the per-sample loop, and `EngineHost` only ever *try*-locks.
(`AudioEngine.startAudioTrack` keeps a Kotlin `MAX_PRIORITY` loop as the
fallback when Oboe cannot start; it calls the same `nativeRender`.)
- Timing is derived from *counting audio samples* (`samplesPerLine`), not from
timers, so playback never drifts.
- UI ⇄ audio sharing is lock-free by design (audio reads plain fields). This can
produce a one-frame-stale read during a simultaneous edit — harmless for a
tracker. If you ever add compound state that must be read atomically, publish it
as an immutable snapshot (like `TransportState`) rather than adding locks.
- UI ⇄ audio sharing crosses through text: `ProjectIo.save` plus
`EngineHost::syncProjectText`, which diffs and copies only what changed (§5.4.2).
`save` is therefore a hot path, not just the file writer — it builds into one
pre-sized buffer, and `AudioEngine.requestSync` coalesces a burst of edits
(a drag fires one per pointer event) into one sync per `SYNC_COALESCE_MS`.
- The transport poller (`AudioEngine.start`) runs at 100 Hz only while the song
plays or a take is armed; stopped and idle it waits 100 ms a turn, and any
transport call wakes it through a semaphore so the playhead is never late.
`AppModel.pollTransport` does the same on iOS (30 Hz playing, 10 Hz idle).
- Block size is `BLOCK_FRAMES = 192` (~4 ms @ 48 kHz). Lower = tighter latency,
higher = safer against underruns.
- **UI rendering**: the pattern grid (`PatternGrid`) and arrangement roll
@@ -856,11 +890,11 @@ polish and interchange niceties, not functional gaps.
empty. Voices are a lane×track matrix so lanes layer polyphonically.
- **Per-channel effect DSP** (milestone 3 ✓): each mixer channel runs an insert
chain built from its FX slots — Tape Delay, Digital Reverb, Filter (LP/HP/BP),
Bitcrusher, and 10-band EQ are real processors in `audio/Effects.kt`. Effect
Bitcrusher, and 10-band EQ are real processors in `core/src/fx/`. Effect
parameters update live per audio block; add/remove rebuilds the chain.
- **Sampler instrument** ✓: WAV import (SAF file picker) + ad-hoc mic/USB
recorder (`audio/SampleRecorder.kt`), decoded to a mono cache
(`audio/SampleStore.kt`), played pitched + sliced by `audio/SampleVoice.kt`.
(`audio/SampleStore.kt`), played pitched + sliced by `core/src/sampler/SampleVoice.cpp`.
Its editor (`ui/toolbox/SamplerEditor.kt`) shows a waveform with two draggable
slice markers, start-octave + volume, and a two-octave audition keyboard. Each
(lane, track) has both a synth and a sample voice; the channel instrument type
@@ -893,11 +927,16 @@ polish and interchange niceties, not functional gaps.
(`version`/`bpm`/`sig`, `block`…`endblock` with `roll`/`track`/steps) — covered
by passing JVM unit tests in `app/src/test`.
- Background playback foreground service with Play/Pause/Stop notification.
- **Full C++ audio port** ✓ (0.37.0): the whole DSP — sequencer, mixer, every
instrument and effect, the master recorder — is `core/`, shared with the iOS app
and driven over JNI. The Kotlin DSP it replaced lives on in the **test** source
set (`app/src/test/.../audio`, `frasil`, `echofield`, `wavetable`) as the
reference the C++ is checked against, so none of it ships in the APK.
- **Oboe / AAudio native output** ✓ (default): `src/main/cpp/native_audio.cpp`
opens a low-latency Oboe stream whose real-time callback pulls audio via JNI
(`audio/NativeAudioBridge.kt`) from the SAME `AudioEngine.fillBlock` the
AudioTrack loop uses — so both backends produce identical sound, only the
delivery path differs. Oboe is the default engine; it falls back to the
(`audio/NativeAudioBridge.kt`) from the SAME `Engine::fillBlock` the AudioTrack
fallback loop reaches through `nativeRender` — so both backends produce
identical sound, only the delivery path differs. Oboe is the default engine; it falls back to the
AudioTrack loop only if it fails to initialise (or the native lib is absent),
surfacing a popup with the reason (there is no user toggle).
Built via **NDK r27** (`ndkVersion` in `app/build.gradle.kts`) + CMake + the
@@ -909,9 +948,9 @@ polish and interchange niceties, not functional gaps.
`llvm-readelf -l <lib>.so` → LOAD `Align 0x4000`.)
- **SF2 / XI loader instrument** ✓: `audio/SoundFontLoader.kt` extracts PCM from
an `.sf2` / `.xi` into the `SampleStore`, played back through the same
`SampleVoice` path as the Sampler; edited via `ui/toolbox/SoundFontEditor.kt`
`SampleVoice` path in `core/` as the Sampler; edited via `ui/toolbox/SoundFontEditor.kt`
(root note, volume, ADSR).
- **Master recording** ✓: `audio/MasterRecorder.kt` renders the stereo master bus
- **Master recording** ✓: `core/src/host/MasterRecorder.cpp` renders the stereo master bus
(plus a configurable FX tail) to a WAV in a user-chosen folder (SAF).
- **Stereo output & recording** ✓: `fillBlock` renders interleaved stereo and the
recorder captures two channels (voices/inserts are mono, so both channels carry
@@ -933,11 +972,13 @@ polish and interchange niceties, not functional gaps.
- **Byte-exact desktop `.sng` compatibility.** `io/SngFormat.kt` reads/writes the
reference line format and round-trips musically; a field-for-field byte match
with the CLI project layout is the remaining interchange nicety.
- **Full C++ audio port.** The DSP currently runs in Kotlin behind the Oboe
callback (via JNI). Porting the hot path to C++ would remove JVM/GC from the
real-time thread — a performance hardening step, not a functional gap.
- **Route the Oboe backend through the chosen output device** (Oboe
`setDeviceId`), matching the AudioTrack path's device selection.
- **Block-rate FX processing.** Insert effects are `process(float)` per sample, so
a four-effect chain on four channels is 16 virtual calls per frame. Giving
`Effect` a block entry point (defaulting to a loop over `process`) would let the
heavier ports vectorise. Sample-for-sample identical if done carefully, but it
touches every effect and the golden comparison, so it is its own change.
---