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
+45
View File
@@ -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
+28
View File
@@ -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
+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");