iOS port plan and instrument reference harness
PORTING.md: native SwiftUI app on a C++ engine verified against Kotlin. IosGoldenInstruments renders note scripts through the Kotlin voices; the C++ runner plays the same scripts through TestVoice makers (weak placeholders until each port lands). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6b7e2108e7
commit
bf5f2b53af
+4
-4
@@ -34,10 +34,10 @@ DEV_APP := build/dev/Build/Products/Release-iphoneos/Sizzle.app
|
||||
IPA := dist/$(APP_ID)_$(BUILD_NO).ipa
|
||||
|
||||
# C++ DSP core: reference audio lives in core/golden/ (regenerated, not committed).
|
||||
CORE_SRC := $(wildcard core/src/*.cpp core/src/fx/*.cpp)
|
||||
CORE_HDR := $(wildcard core/include/sizzle/*.hpp core/src/fx/*.hpp)
|
||||
CORE_SRC := $(wildcard core/src/*.cpp core/src/*/*.cpp)
|
||||
CORE_HDR := $(wildcard core/include/sizzle/*.hpp core/src/*/*.hpp)
|
||||
CXX ?= c++
|
||||
CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -Icore/include -Icore/src/fx
|
||||
CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -Icore/include -Icore/src -Icore/src/fx
|
||||
GOLDEN := core/golden
|
||||
SPECS_GEN := core/include/sizzle/DeviceSpecs.gen.hpp
|
||||
# Gradle needs the Android SDK; same default location as the Android Makefile.
|
||||
@@ -59,7 +59,7 @@ help:
|
||||
golden:
|
||||
cd .. && ANDROID_HOME=$(ANDROID_SDK) SIZZLE_GOLDEN_DIR=$(CURDIR)/$(GOLDEN) \
|
||||
SIZZLE_SPECS_OUT=$(CURDIR)/$(SPECS_GEN) \
|
||||
./gradlew -q :app:testDebugUnitTest --tests '*IosGoldenExport*' --rerun
|
||||
./gradlew -q :app:testDebugUnitTest --tests '*IosGolden*' --rerun
|
||||
@ls $(GOLDEN)/*.scn | wc -l | xargs echo "reference scenarios:"
|
||||
|
||||
build/core/golden_test: $(CORE_SRC) $(CORE_HDR) core/tests/golden_test.cpp
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# 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.
|
||||
|
||||
## 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.
|
||||
+1
-1
@@ -14,7 +14,7 @@ settings:
|
||||
DEVELOPMENT_TEAM: ""
|
||||
CLANG_CXX_LANGUAGE_STANDARD: c++17
|
||||
CLANG_ENABLE_OBJC_ARC: YES
|
||||
HEADER_SEARCH_PATHS: ["$(SRCROOT)/../core/include", "$(SRCROOT)/../core/src/fx"]
|
||||
HEADER_SEARCH_PATHS: ["$(SRCROOT)/../core/include", "$(SRCROOT)/../core/src", "$(SRCROOT)/../core/src/fx"]
|
||||
targets:
|
||||
SizzleCore:
|
||||
type: library.static
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
// The hook the reference tests use to play a note script through one instrument
|
||||
// voice (see IosGoldenInstruments.kt and tests/golden_test.cpp). Each instrument
|
||||
// port provides its maker (strong definition) in its own source file; the weak
|
||||
// placeholders in src/TestVoices.cpp return nullptr for kinds not ported yet.
|
||||
|
||||
#include <memory>
|
||||
#include "sizzle/Params.hpp"
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
class TestVoice {
|
||||
public:
|
||||
virtual ~TestVoice() = default;
|
||||
/** Called before each block of [frames] (AudioEngine advances shared clocks
|
||||
* such as the Morph Pad's FrasilClock here). */
|
||||
virtual void blockStart(int frames) { (void)frames; }
|
||||
virtual void noteOn(int midi, int velocity) = 0;
|
||||
virtual void noteOff(int midi) = 0;
|
||||
virtual float render() = 0;
|
||||
};
|
||||
|
||||
struct TestVoiceSetup {
|
||||
const char *type; // ToolboxType name, e.g. "MORPH_PAD"
|
||||
const Params *params; // the slot's values
|
||||
int sampleRate;
|
||||
float tempoBpm;
|
||||
double clock0; // FrasilClock.seconds when the scenario started
|
||||
};
|
||||
|
||||
/** kind "SYNTH": SynthVoice with the engine's patch for [setup.type]. */
|
||||
std::unique_ptr<TestVoice> makeSynthTestVoice(const TestVoiceSetup &setup);
|
||||
/** kind "FRASIL": FrasilVoice alone (Morph Pad). */
|
||||
std::unique_ptr<TestVoice> makeFrasilTestVoice(const TestVoiceSetup &setup);
|
||||
/** kind "WAVE": WaveVoice alone (Wavetable). */
|
||||
std::unique_ptr<TestVoice> makeWaveTestVoice(const TestVoiceSetup &setup);
|
||||
/** kind "GRAIN": GrainCloud (Grain Cloud), notes owned by live input. */
|
||||
std::unique_ptr<TestVoice> makeGrainTestVoice(const TestVoiceSetup &setup);
|
||||
|
||||
std::unique_ptr<TestVoice> makeTestVoice(const char *kind, const TestVoiceSetup &setup);
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -0,0 +1,28 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Weak placeholders for the TestVoice makers (see TestVoice.hpp): a port's strong
|
||||
// definition replaces its placeholder at link time.
|
||||
|
||||
#include <cstring>
|
||||
#include "sizzle/TestVoice.hpp"
|
||||
|
||||
#define SIZZLE_TEST_MAKER(fn) \
|
||||
__attribute__((weak)) std::unique_ptr<TestVoice> fn(const TestVoiceSetup &) { return nullptr; }
|
||||
|
||||
namespace sizzle {
|
||||
|
||||
SIZZLE_TEST_MAKER(makeSynthTestVoice)
|
||||
SIZZLE_TEST_MAKER(makeFrasilTestVoice)
|
||||
SIZZLE_TEST_MAKER(makeWaveTestVoice)
|
||||
SIZZLE_TEST_MAKER(makeGrainTestVoice)
|
||||
|
||||
std::unique_ptr<TestVoice> makeTestVoice(const char *kind, const TestVoiceSetup &s) {
|
||||
if (!std::strcmp(kind, "SYNTH")) return makeSynthTestVoice(s);
|
||||
if (!std::strcmp(kind, "FRASIL")) return makeFrasilTestVoice(s);
|
||||
if (!std::strcmp(kind, "WAVE")) return makeWaveTestVoice(s);
|
||||
if (!std::strcmp(kind, "GRAIN")) return makeGrainTestVoice(s);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace sizzle
|
||||
@@ -1,8 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Renders every reference scenario exported by IosGoldenExport (Kotlin) through the
|
||||
// C++ core and compares sample by sample.
|
||||
// Renders every reference scenario exported by IosGoldenExport / IosGoldenInstruments
|
||||
// (Kotlin) through the C++ core and compares sample by sample. Effect scenarios
|
||||
// process input.f32; instrument scenarios ("kind" line) play their note script.
|
||||
//
|
||||
// golden_test <golden dir> [TYPE ...]
|
||||
//
|
||||
@@ -20,6 +21,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "sizzle/Effect.hpp"
|
||||
#include "sizzle/TestVoice.hpp"
|
||||
|
||||
using namespace sizzle;
|
||||
|
||||
@@ -51,9 +53,12 @@ int main(int argc, char **argv) {
|
||||
int pass = 0, fail = 0, skip = 0;
|
||||
for (const auto &base : scns) {
|
||||
std::ifstream f(dir + "/" + base + ".scn");
|
||||
std::string line, type;
|
||||
int sr = 48000;
|
||||
std::string line, type, kind;
|
||||
int sr = 48000, block = 256, frames = 0;
|
||||
float tempo = 120.f;
|
||||
double clock0 = 0;
|
||||
struct Ev { int frame; bool on; int midi, vel; };
|
||||
std::vector<Ev> evs;
|
||||
Params p;
|
||||
while (std::getline(f, line)) {
|
||||
std::istringstream ls(line);
|
||||
@@ -61,13 +66,41 @@ int main(int argc, char **argv) {
|
||||
if (tag == "type") ls >> type;
|
||||
else if (tag == "sr") ls >> sr;
|
||||
else if (tag == "tempo") ls >> tempo;
|
||||
else if (tag == "kind") ls >> kind;
|
||||
else if (tag == "block") ls >> block;
|
||||
else if (tag == "frames") ls >> frames;
|
||||
else if (tag == "clock") ls >> clock0;
|
||||
else if (tag == "on") { Ev e{0, true, 0, 0}; ls >> e.frame >> e.midi >> e.vel; evs.push_back(e); }
|
||||
else if (tag == "off") { Ev e{0, false, 0, 0}; ls >> e.frame >> e.midi; evs.push_back(e); }
|
||||
else if (tag == "p") {
|
||||
std::string key, val; ls >> key; std::getline(ls, val);
|
||||
if (!val.empty() && val[0] == ' ') val.erase(0, 1);
|
||||
p.set(key.c_str(), val.c_str());
|
||||
}
|
||||
}
|
||||
if (!only.empty() && std::find(only.begin(), only.end(), type) == only.end()) continue;
|
||||
std::string label = kind.empty() ? type : kind + "_" + type;
|
||||
if (!only.empty() && std::find(only.begin(), only.end(), type) == only.end()
|
||||
&& std::find(only.begin(), only.end(), label) == only.end()) continue;
|
||||
if (!kind.empty()) {
|
||||
TestVoiceSetup setup{type.c_str(), &p, sr, tempo, clock0};
|
||||
auto v = makeTestVoice(kind.c_str(), setup);
|
||||
if (!v) { std::printf("SKIP %-36s (not ported)\n", base.c_str()); ++skip; continue; }
|
||||
std::vector<float> want = readF32(dir + "/" + base + ".f32");
|
||||
double maxErr = 0; size_t at = 0, next = 0;
|
||||
for (int i = 0; i < frames && i < (int)want.size(); ++i) {
|
||||
if (i % block == 0) v->blockStart(block);
|
||||
while (next < evs.size() && evs[next].frame == i) {
|
||||
const Ev &e = evs[next++];
|
||||
if (e.on) v->noteOn(e.midi, e.vel); else v->noteOff(e.midi);
|
||||
}
|
||||
double err = std::fabs((double)v->render() - (double)want[i]);
|
||||
if (!(err <= maxErr)) { maxErr = err; at = (size_t)i; }
|
||||
}
|
||||
bool ok = maxErr < 1e-4 && (int)want.size() == frames;
|
||||
std::printf("%s %-36s max diff %.3g at sample %zu\n", ok ? "PASS" : "FAIL", base.c_str(), maxErr, at);
|
||||
ok ? ++pass : ++fail;
|
||||
continue;
|
||||
}
|
||||
auto fx = Effect::create(type.c_str(), sr);
|
||||
if (!fx) { std::printf("SKIP %-36s (not ported)\n", base.c_str()); ++skip; continue; }
|
||||
std::vector<float> want = readF32(dir + "/" + base + ".f32");
|
||||
|
||||
Reference in New Issue
Block a user