// 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. // // golden_test [TYPE ...] // // A scenario passes when the largest difference is below 1e-4 (float rounding and // libm vs Java Math differ by an ulp here and there). Types with no C++ port yet are // listed as SKIP. Exit status is non-zero if any scenario fails. #include #include #include #include #include #include #include #include #include #include "sizzle/Effect.hpp" using namespace sizzle; static std::vector readF32(const std::string &path) { std::ifstream f(path, std::ios::binary); std::vector bytes((std::istreambuf_iterator(f)), {}); std::vector out(bytes.size() / 4); std::memcpy(out.data(), bytes.data(), out.size() * 4); return out; } int main(int argc, char **argv) { if (argc < 2) { std::fprintf(stderr, "usage: %s [TYPE ...]\n", argv[0]); return 2; } std::string dir = argv[1]; std::vector only(argv + 2, argv + argc); std::vector input = readF32(dir + "/input.f32"); if (input.empty()) { std::fprintf(stderr, "no input.f32 in %s (run make -C ios golden)\n", dir.c_str()); return 2; } std::vector scns; if (DIR *d = opendir(dir.c_str())) { while (dirent *e = readdir(d)) { std::string n = e->d_name; if (n.size() > 4 && n.compare(n.size() - 4, 4, ".scn") == 0) scns.push_back(n.substr(0, n.size() - 4)); } closedir(d); } std::sort(scns.begin(), scns.end()); 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; float tempo = 120.f; Params p; while (std::getline(f, line)) { std::istringstream ls(line); std::string tag; ls >> tag; if (tag == "type") ls >> type; else if (tag == "sr") ls >> sr; else if (tag == "tempo") ls >> tempo; 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; auto fx = Effect::create(type.c_str(), sr); if (!fx) { std::printf("SKIP %-36s (not ported)\n", base.c_str()); ++skip; continue; } std::vector want = readF32(dir + "/" + base + ".f32"); fx->update(p, tempo); double maxErr = 0; size_t at = 0; for (size_t i = 0; i < input.size() && i < want.size(); ++i) { float y = fx->process(input[i]); double e = std::fabs((double)y - (double)want[i]); if (!(e <= maxErr)) { maxErr = e; at = i; } // NaN counts as worst } bool ok = maxErr < 1e-4 && want.size() == input.size(); std::printf("%s %-36s max diff %.3g at sample %zu\n", ok ? "PASS" : "FAIL", base.c_str(), maxErr, at); ok ? ++pass : ++fail; } std::printf("\n%d passed, %d failed, %d not ported\n", pass, fail, skip); return fail ? 1 : 0; }