tuner: run real-audio harness on synthetic audio, no silent pass (#tests)
- Commit
a4761d0b20a2120f8f51a01dce3594cdda365186- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-15 17:18 UTC (20 days ago)
- Parents
17c3a50
RealAudioHarnessTest silently passed when Record-3.f32le.pcm was missing: both tests printed SKIP and returned, asserting nothing. The recording is in fact tracked, but any checkout without it (or a moved working dir) turned the whole real-audio comparison into a no-op pass that CI counted as green. RealAudioHarness now synthesises the same C/Am/F ukulele progression with Signals.strum (pcmOrSynthetic), so the production ChordDetector pipeline is measured hermetically when no recording is present; the real recording still wins when on disk. realAudioComparison also gates loosely on the production path naming some frames correctly (report remains the deliverable, thresholds stay low by design), and c4SurvivesTheProvisionalBoundary runs on the same audio. Verified: :tuner:testDevUnitTest green, 138 tests, 0 skipped, both with the recording present and with it temporarily removed.
Diff
tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarness.kt
diff --git a/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarness.kt b/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarness.ktindex 0d9bf5e2f8..9d8a9184f2 100644--- a/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarness.kt+++ b/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarness.kt@@ -20,9 +20,9 @@ import kotlin.math.sqrt * circularity looks like from outside. So this file drives the same pipeline from a decoded * recording and reports frames-named, not notes-per-frame alone. *- * The recording is not in the tree - it is 2.4 MB of PCM and this is a measurement tool, not a- * regression gate. [RealAudioHarness.pcmOrNull] returns null when it is absent and every caller- * skips, so a checkout without it still builds and tests green.+ * [RealAudioHarness.pcmOrNull] returns null when the recording is absent; callers then fall+ * back to [RealAudioHarness.syntheticPcm] (the same C/Am/F progression, synthesised), so the+ * harness runs hermetically in CI instead of silently passing. */ object RealAudioHarness { /** Mono 32-bit float, little endian, decoded to [RATE]. See `docs` in the report header. */@@ -49,6 +49,32 @@ object RealAudioHarness { return DoubleArray(bytes.size / 4) { buffer.getFloat(it * 4).toDouble() } } + /**+ * A synthetic stand-in for the recording: ukulele-voiced C, Am and F+ * strums (the [GROUND_TRUTH] progression), generated with the same+ * [Signals.strum] shape the synthetic corpus uses. Hermetic tests run+ * the production pipeline over this when no recording is present, so+ * the harness is exercised in CI instead of silently passing; the real+ * recording still wins whenever it is on disk.+ */+ fun syntheticPcm(): DoubleArray {+ val chords = listOf(+ listOf(67, 60, 64, 72), // C: G C E C+ listOf(69, 60, 64, 69), // Am: A C E A+ listOf(65, 69, 60, 65), // F: F A C F+ )+ val perChord = (RATE * 1.5).toInt()+ val out = DoubleArray(perChord * chords.size)+ chords.forEachIndexed { i, midis ->+ val strum = Signals.strum(midis, perChord, seed = 100 + i)+ strum.copyInto(out, destinationOffset = i * perChord)+ }+ return out+ }++ /** The real recording when present, otherwise [syntheticPcm]. */+ fun pcmOrSynthetic(): DoubleArray = pcmOrNull() ?: syntheticPcm()+ /** * The recording's tuning offset in cents, negative for flat, modulo one semitone. *
tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarnessTest.kt
diff --git a/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarnessTest.kt b/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarnessTest.ktindex 3147a87a78..a78394f87a 100644--- a/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarnessTest.kt+++ b/tuner/src/test/java/com/vayunmathur/tuner/domain/RealAudioHarnessTest.kt@@ -11,10 +11,10 @@ import kotlin.test.assertTrue /** * Drives NNLS and the constrained sieve over the same real recording and writes both scores out. *- * Not a gate. Everything here either skips (no recording) or asserts something that is true of- * the harness rather than of the detector, because the whole point of the file is that the- * numbers are currently bad and hard thresholds would either be vacuous or permanently red.- * `build/real-audio-report.txt` is the deliverable.+ * The report (`build/real-audio-report.txt`) is the deliverable, and the thresholds stay+ * deliberately loose — the point is that real numbers are currently bad — but the harness+ * does gate on the production detector naming some frames correctly, over the real+ * recording when present and over a synthesised C/Am/F progression otherwise. */ class RealAudioHarnessTest { private val catalog = InstrumentCatalog.parse(File("src/main/assets/instruments.json").readText())@@ -31,11 +31,7 @@ class RealAudioHarnessTest { @Test fun realAudioComparison() {- val pcm = RealAudioHarness.pcmOrNull()- if (pcm == null) {- println("SKIP: no ${RealAudioHarness.PCM_PATH}; see RealAudioHarness for how to make it")- return- }+ val pcm = RealAudioHarness.pcmOrSynthetic() val fraction = RealAudioHarness.tuningOffsetCents(pcm) val report = StringBuilder()@@ -60,6 +56,13 @@ class RealAudioHarnessTest { File("build").mkdirs() File("build/real-audio-report.txt").writeText(report.toString()) println(report)+ // The harness must actually measure the production pipeline, not+ // just print: on the synthetic progression (or the recording) the+ // shipping detector names at least some frames, correctly.+ val (productionScore, _) = production(pcm, ChordExtractor.CHROMA_HMM)+ assertTrue(productionScore.tonal > 0, "no tonal frames measured: ${productionScore.report()}")+ assertTrue(productionScore.named > 0, "production detector named no frames: ${productionScore.report()}")+ assertTrue(productionScore.correct > 0, "production detector named no frame correctly: ${productionScore.report()}") } private fun appendHeader(report: StringBuilder, pcm: DoubleArray, fraction: Double) {@@ -256,11 +259,7 @@ class RealAudioHarnessTest { */ @Test fun c4SurvivesTheProvisionalBoundary() {- val pcm = RealAudioHarness.pcmOrNull()- if (pcm == null) {- println("SKIP: no ${RealAudioHarness.PCM_PATH}")- return- }+ val pcm = RealAudioHarness.pcmOrSynthetic() val cents = RealAudioHarness.tuningOffsetCents(pcm) - 100.0 val constantQ = RealAudioHarness.compensated(cents) val frames = RealAudioHarness.hops(pcm, constantQ.requiredSamples, RealAudioHarness.HOP)