# SPDX-License-Identifier: MIT """Rungs 2 and 5a: the synthetic .spc cases through spc700-python + smp + dsp, compared with the snes_spc 0.9.0 referee run as a closed box (OBSERVED). Skipped when the referee is not built. The referee's audio trails its own register snapshots by 4 samples (OBSERVED); the comparison lines the streams up by that. ``saturation`` differs by design (D1 in docs/dsp/validation.md): the module follows the documents, not the referee. """ from __future__ import annotations import subprocess import sys from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[2] REFEREE = ROOT / "reference" / "dsp" / "build" / "spc_dump" sys.path.insert(0, str(ROOT / "scripts")) CASES = [ "brr", "echo", "echo-wrap", "edges", "edl-zero", "endx-override", "env-quirks", "envelopes", "flg", "kon-ring", "kon-timing", "latch-sweep", "noise-pmod", ] # fmt: skip SAMPLES = 8000 @pytest.fixture(scope="module") def synthetic(tmp_path_factory) -> Path: if not REFEREE.exists(): pytest.skip("referee not built: scripts/dsp_build_referees.py") out = tmp_path_factory.mktemp("spc") subprocess.run( [sys.executable, "-I", str(ROOT / "scripts" / "dsp_make_spc.py"), str(out)], check=True, capture_output=True, ) return out @pytest.mark.slow @pytest.mark.parametrize("case", CASES) def test_value_exact_against_the_referee(synthetic: Path, case: str): import dsp_compare assert dsp_compare.compare(synthetic / f"{case}.spc", SAMPLES, 1, 0, 4) == 0 @pytest.mark.slow def test_saturation_differs_as_recorded(synthetic: Path): import dsp_compare different = dsp_compare.compare(synthetic / "saturation.spc", SAMPLES, 1, 0, 4) assert different == SAMPLES - 8 # D1: every sample once the echo path saturates