Files
sizzletracker-android/ios/core/tests/golden_test.cpp
T
ReactorcoremeltdownandClaude Opus 5.5 dcf85ba915 iOS 0.1.0: the eight audio effects as AUv3 plugins on a C++ core
C++ ports of the Kotlin effects, checked against audio the Kotlin code renders
(25 scenarios, IosGoldenExport); an Objective-C++ AUv3 wrapper checked on the
Mac against the core (parameters, presets, saved state); a container app that
checks each plugin on the device. Built as a TrollStore .ipa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 20:47:06 +01:00

88 lines
3.4 KiB
C++

// 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 <golden dir> [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 <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <dirent.h>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include "sizzle/Effect.hpp"
using namespace sizzle;
static std::vector<float> readF32(const std::string &path) {
std::ifstream f(path, std::ios::binary);
std::vector<char> bytes((std::istreambuf_iterator<char>(f)), {});
std::vector<float> 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 <golden dir> [TYPE ...]\n", argv[0]); return 2; }
std::string dir = argv[1];
std::vector<std::string> only(argv + 2, argv + argc);
std::vector<float> 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<std::string> 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<float> 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;
}