memlnaut-nisps/tests/cpp/test_mode_curve_overrides.cpp

123 lines
6.5 KiB
C++
Raw Normal View History

feat: curve truth, DriverConfig, real telemetry, engine benchmark Four items from one workflow, committed together because their build and CI wiring genuinely interleaves — nisps/CMakeLists.txt, run-all-tests.sh and ci.yml each carry hunks from two of them, and the stage renumbering (1/5 -> 1/6) touches every line. Splitting would produce commits that do not build, which is worse than a commit that does four things and says so. S26 part 2 — the curve declaration now matches reality. params[].curve stays the mode-wide DEFAULT; a voice_spaces entry may now be {name, curve_overrides} declaring only the slots where THAT voice space deviates. The 6 modes with one voice space are byte-identical. The values were derived MECHANICALLY by a new codegen/curve-audit.ts that models the four idioms a p[N]*p[N] regex misses (alias form, memlcelium's implicit-counter sq() lambda, loop-generated indices, smooth_params_), inlines helpers, and RAISES rather than guessing when it cannot reduce an expression. A drift gate cross-checks 1179 (voice space x param) slots against engine source on every run and was proved to fail loudly on three drift classes. Application stays in the engine: nisps/engines, nisps/pipeline and nisps/core are untouched, generated output is pure insertion (755 insertions, 0 deletions), and the rebuilt nisps.wasm was byte-identical. S4 / 7.2 — firmware reads the active mode's driver config at mode start, and mic/line is real. My brief assumed the engine owns this; the code disagreed and the code was right. sound_analysis_midi's EngineT is NoOpEngine — the mic lives on a separately-composed AnalysisEngine member — so engine-level wiring would have compiled, passed every gate, and left the one mic mode on line input. Hence a mode-level seam defaulting to engine().driver_config(). Separately, DriverConfig's defaults (line_level 0, output_volume 1.0) had drifted from memllib's actual 3/0.8 because nothing had ever read them; wiring them as-is would have made every silent mode louder and its line input maximally insensitive — a behaviour change disguised as plumbing. Now pinned by a test. Also: GetSysClockSpeed() panic()s on unsupported sample rates and runs on the first line of setup(), so sample_rate needed a fallback ahead of clock setup. CI's firmware env list gains soundanalysismidi — it is the only mic variant and nothing else compiles that path. Plan 5e — telemetry is real. A loss_history C-API entry across the full 5-layer chain lets the browser read the per-iteration loss the core already records. The audit named one fabrication site; there were two — wasm-iml.ts's synchronous train() published lossHistory: [loss] as well. A third, ctx.loss, was not merely dead but actively synthetic (fallbacks of prev * 0.82 and a literal 0.5, rendered by nothing) and is deleted. The firmware buffer stays untouched, per the L25 call. EngineApi.lossHistory() reads spine state rather than the MLP handle, because trainAsync() fits on the worker's mirror net and the handle would give a subtly-wrong second answer. Plan 5f — engine throughput is measurable. One source compiled twice (CMake natively, emcc for WASM) so the targets compare directly and no WASM export is added. Sequencers are driven into a working state, and every row prints its own working-state evidence so a number produced by an idle engine is visible rather than plausible. Reports, never asserts: a wall-clock threshold on shared hardware is meaningless or flaky, same call as the firmware size job. ALIGNMENT: the telemetry defect is deleted (built, not deferred); the performance defect is rewritten to what is actually left — these are HOST numbers, and nothing measures the RP2350 at 150 MHz, which is the target the mission's constraint is about. Q4 (memllib ownership) and Q5 (legacy feedback modes) are closed. Corrections to my own earlier claims, both found by agents contradicting the brief: manifold/ONBOARDING.md was NOT "now accurate" — its primitives list still named five deleted primitives and cited a seededGradient() that does not exist. And the parity harness misses the sequencer engines because it runs 128 frames while their sequencers evaluate every 400-500 samples, NOT because all-params-0.5 fails to trigger them (it does trigger: 0.5 maps to ratio 2, firing three times per bar). The fix is a longer window, not different params. Gates: run-all-tests.sh ALL GREEN — 4/4 ctest, parity PASS, lint clean, curve drift 1179 slots ok, 39 e2e (was 33). Firmware: 5 envs built including the mic variant.
2026-07-21 22:02:23 +02:00
// tests/cpp/test_mode_curve_overrides.cpp — the C++ side of the per-voice-space
// curve declaration.
//
// The authority on WHAT the table should contain is codegen/tests/
// curve_drift_test.ts, which derives it from nisps/engines/*.hpp source (the
// curve is not observable from engine output — see that file's header). This
// test covers what TypeScript cannot see: that the generated C++ table is
// well-formed, reachable through `nisps::ParamSchema`, and that
// `nisps::effective_curve()` resolves it correctly. A handful of spot checks
// pin the wiring so a mis-indexed span cannot pass as "all linear".
#include "test_helpers.hpp"
#include "../../nisps/modes/breakor.hpp"
#include "../../nisps/modes/channel_strip.hpp"
#include "../../nisps/modes/elysiamorf.hpp"
#include "../../nisps/modes/memlcelium.hpp"
#include "../../nisps/modes/paf_synth.hpp"
#include "../../nisps/modes/slp_workshop.hpp"
#include "../../nisps/modes/sound_analysis_midi.hpp"
#include "../../nisps/modes/verb_fx.hpp"
#include "../../nisps/modes/xiasri.hpp"
using namespace nisps;
namespace {
// Every override must address a real (voice space, param) pair and must be a
// real deviation — a row restating the default is dead weight that would make
// the table's size a lie about how much the voice spaces actually differ.
void check_well_formed(const ParamSchema& s) {
for (const auto& o : s.curve_overrides) {
NISPS_EXPECT(o.voice_space < s.voice_spaces.size());
NISPS_EXPECT(o.param < s.params.size());
if (o.param < s.params.size()) {
NISPS_EXPECT(o.curve != s.params[o.param].curve);
}
}
// No duplicate (voice_space, param) rows: effective_curve() returns the
// first match, so a duplicate would silently shadow.
for (std::size_t i = 0u; i < s.curve_overrides.size(); ++i) {
for (std::size_t j = i + 1u; j < s.curve_overrides.size(); ++j) {
const bool same = s.curve_overrides[i].voice_space == s.curve_overrides[j].voice_space &&
s.curve_overrides[i].param == s.curve_overrides[j].param;
NISPS_EXPECT(!same);
}
}
}
} // namespace
NISPS_TEST(curve_overrides_well_formed) {
check_well_formed(modes::PAFSynthMode::param_schema());
check_well_formed(modes::ChannelStripMode::param_schema());
check_well_formed(modes::VerbFXMode::param_schema());
check_well_formed(modes::XIASRIMode::param_schema());
check_well_formed(modes::MEMLCeliumMode::param_schema());
check_well_formed(modes::SLPWorkshopMode::param_schema());
check_well_formed(modes::BreakOrMode::param_schema());
check_well_formed(modes::ElysiamorfMode::param_schema());
check_well_formed(modes::SoundAnalysisMIDIMode::param_schema());
}
// Single-voice-space and voice-space-less modes deviate from nothing: their
// mode-wide `curve` already is the whole truth.
NISPS_TEST(curve_overrides_empty_where_one_voice_space) {
NISPS_EXPECT(modes::XIASRIMode::param_schema().curve_overrides.empty());
NISPS_EXPECT(modes::MEMLCeliumMode::param_schema().curve_overrides.empty());
NISPS_EXPECT(modes::SLPWorkshopMode::param_schema().curve_overrides.empty());
NISPS_EXPECT(modes::BreakOrMode::param_schema().curve_overrides.empty());
NISPS_EXPECT(modes::ElysiamorfMode::param_schema().curve_overrides.empty());
NISPS_EXPECT(modes::SoundAnalysisMIDIMode::param_schema().curve_overrides.empty());
}
// channel_strip: the mode-wide default IS WannabeNeve66 (voice space 0).
// SSL 4K/9K additionally square comp_ratio (slot 11); the vox strips do not
// square comp_release (13); Neve 80 quantises everything but the two gains.
NISPS_TEST(curve_overrides_channel_strip) {
const auto& s = modes::ChannelStripMode::param_schema();
NISPS_EXPECT(effective_curve(s, 0u, 11u) == Curve::linear); // WannabeNeve66
NISPS_EXPECT(effective_curve(s, 1u, 11u) == Curve::square); // SSL 4K G-ist
NISPS_EXPECT(effective_curve(s, 2u, 11u) == Curve::square); // SSL 9K-inda
NISPS_EXPECT(effective_curve(s, 0u, 13u) == Curve::square); // comp_release
NISPS_EXPECT(effective_curve(s, 3u, 13u) == Curve::linear); // MaleVox
NISPS_EXPECT(effective_curve(s, 4u, 13u) == Curve::linear); // FemaleVox
NISPS_EXPECT(effective_curve(s, 5u, 1u) == Curve::linear); // Neve 80 stepped
NISPS_EXPECT(effective_curve(s, 5u, 0u) == Curve::square); // …but pre_gain
NISPS_EXPECT(effective_curve(s, 5u, 23u) == Curve::square); // …and post_gain
}
// paf_synth: the mode-wide default is Rowantares (voice space 1), NOT voice
// space 0 — the enum order is QuadDetune, VS1, VS2, Perc, Single1, QuadOct,
// QuadDist while the param NAMES came from VS1's mapping.
NISPS_TEST(curve_overrides_paf_synth) {
const auto& s = modes::PAFSynthMode::param_schema();
NISPS_EXPECT(effective_curve(s, 1u, 8u) == Curve::square); // Rowantares == default
NISPS_EXPECT(effective_curve(s, 0u, 8u) == Curve::linear); // Ellipticacacia
NISPS_EXPECT(effective_curve(s, 4u, 5u) == Curve::square); // Magnetarch shape gain
NISPS_EXPECT(effective_curve(s, 3u, 32u) == Curve::square); // Aquillow env release
NISPS_EXPECT(effective_curve(s, 6u, 19u) == Curve::linear); // Ipeleiades vfr is linear
NISPS_EXPECT(effective_curve(s, 5u, 19u) == Curve::square); // …but Elderstar squares it
}
// verb_fx: the mode-wide default is Default (voice space 0), which is the ONLY
// all-linear voice space. Every other one deviates.
NISPS_TEST(curve_overrides_verb_fx) {
const auto& s = modes::VerbFXMode::param_schema();
NISPS_EXPECT(!s.curve_overrides.empty());
for (std::size_t i = 0u; i < s.params.size(); ++i) {
NISPS_EXPECT(effective_curve(s, 0u, i) == Curve::linear);
}
NISPS_EXPECT(effective_curve(s, 1u, 29u) == Curve::sqrt); // Resonant fbank res
NISPS_EXPECT(effective_curve(s, 2u, 1u) == Curve::square); // Soft lp0_fb
NISPS_EXPECT(effective_curve(s, 3u, 37u) == Curve::sqrt); // Cathedral delay time
NISPS_EXPECT(effective_curve(s, 5u, 39u) == Curve::square); // Chamber delay1 time
NISPS_EXPECT(effective_curve(s, 6u, 29u) == Curve::sqrt); // Metallic alternates…
NISPS_EXPECT(effective_curve(s, 6u, 30u) == Curve::square); // …by index parity
NISPS_EXPECT(effective_curve(s, 7u, 42u) == Curve::sqrt); // Granular overrides Soft
NISPS_EXPECT(effective_curve(s, 8u, 0u) == Curve::sqrt); // Diffuse xfade
NISPS_EXPECT(effective_curve(s, 9u, 21u) == Curve::square); // Dark fbank freqs
NISPS_EXPECT(effective_curve(s, 10u, 21u) == Curve::sqrt); // Bright fbank freqs
}