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:
Reactorcoremeltdown
2026-11-15 21:49:02 +01:00
co-authored by Claude Opus 5.5
parent 6b7e2108e7
commit bf5f2b53af
7 changed files with 327 additions and 10 deletions
+38 -5
View File
@@ -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");