Add Aquarium synth playback tests

This commit is contained in:
Meta Vens 2026-05-12 21:24:42 +01:00
commit 282efc4a68
7 changed files with 123 additions and 0 deletions

View file

@ -29,6 +29,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameCult.Networking", "..\C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aquarium.Sample.Minimal", "src\Aquarium.Sample.Minimal\Aquarium.Sample.Minimal.csproj", "{7564E6C2-FF01-4B5B-8C2B-F9CD796858BA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aquarium.Engine.Tests", "tests\Aquarium.Engine.Tests\Aquarium.Engine.Tests.csproj", "{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -183,6 +187,18 @@ Global
{7564E6C2-FF01-4B5B-8C2B-F9CD796858BA}.Release|x64.Build.0 = Release|Any CPU
{7564E6C2-FF01-4B5B-8C2B-F9CD796858BA}.Release|x86.ActiveCfg = Release|Any CPU
{7564E6C2-FF01-4B5B-8C2B-F9CD796858BA}.Release|x86.Build.0 = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|x64.ActiveCfg = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|x64.Build.0 = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|x86.ActiveCfg = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Debug|x86.Build.0 = Debug|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|Any CPU.Build.0 = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|x64.ActiveCfg = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|x64.Build.0 = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|x86.ActiveCfg = Release|Any CPU
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -192,5 +208,6 @@ Global
{51FE01D8-9EEF-46B2-8D8C-3307AC2221C1} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{33654E0D-B31A-4062-B6AC-C1CE4C1A1F65} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{7564E6C2-FF01-4B5B-8C2B-F9CD796858BA} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{37363FC6-5AA3-49B4-A3B1-E4AB2CC986EB} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
EndGlobal

View file

@ -6,4 +6,7 @@
<Project Path="src/Aquarium.Sample.Minimal/Aquarium.Sample.Minimal.csproj" />
<Project Path="../AquariumSynthCSharp/src/AquariumSynth.Dsl/AquariumSynth.Dsl.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/Aquarium.Engine.Tests/Aquarium.Engine.Tests.csproj" />
</Folder>
</Solution>

View file

@ -18,6 +18,34 @@ internal sealed class AquariumSynthHost : IDisposable
private string? faustLoadError;
private float timeSeconds;
internal static bool TryRenderScriptWithNativeFaust(string name, string script, float gain, out float[] samples, out string? error)
{
samples = [];
if (!FaustNative.TryLoad(out var native, out var loadError))
{
error = loadError;
return false;
}
using (native)
{
try
{
var patch = PatchScript.Parse(script);
var export = FaustEmitter.Emit(patch, new FaustExportOptions(SafeFaustName(name)));
using var compiled = native!.Compile(SafeFaustName(name), export.Source, EstimateDuration(patch));
samples = compiled.Render(gain);
error = null;
return true;
}
catch (Exception ex)
{
error = ex.Message;
return false;
}
}
}
public void Update(AquariumSynthDocument synth, float deltaSeconds)
{
timeSeconds += Math.Max(deltaSeconds, 0.0f);

View file

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Aquarium.Engine.Tests")]

View file

@ -73,3 +73,4 @@
{"timestamp":"2026-05-12T20:04:11+01:00","topic":"debug-ui-mouse-input-capture","lesson":"Renderer input capture must include both keyboard ownership and mouse ownership. If Debug UI consumes wheel or mouse interaction but the renderer only reports keyboard capture, the same wheel event leaks into client camera/runtime controls after the overlay handles it.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"user dropdown scroll capture correction"}
{"timestamp":"2026-05-12T20:20:42+01:00","topic":"synth-playground-control-authority","lesson":"The synth playground's source text owns recompilation through the synth host compile key and debounce; Play owns only manual trigger firing. Do not make Play force compilation or present compile status as an interactive control when it is only state feedback.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"user synth playground UI correction"}
{"timestamp":"2026-05-12T21:07:53+01:00","topic":"synth-failed-compile-state","lesson":"A failed synth compile key must be remembered separately from the ready compile key. If failed source leaves ReadyKey empty while DesiredKey still points at the same bad script, the host retries every frame and the UI appears stuck on Compiling instead of showing Failed until the source changes.","files":["src/Aquarium.Engine/Audio/AquariumSynthHost.cs","state/evidence.jsonl"],"source":"user failed compilation status correction"}
{"timestamp":"2026-05-12T21:19:20+01:00","topic":"aquarium-synth-dogfood-tests","lesson":"The deprecated Rust synth fork can remain historical evidence, but active synth confidence must live in the C# dogfood path. Aquarium needs tests that render built-in scripts through its native Faust runtime wrapper and inspect the resulting samples, not just parser/export tests in the DSL library.","files":["src/Aquarium.Engine/Audio/AquariumSynthHost.cs","tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs","state/evidence.jsonl"],"source":"user deprecated Rust repo clarification"}

View file

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Aquarium.Engine\Aquarium.Engine.csproj" />
<ProjectReference Include="..\..\..\AquariumSynthCSharp\src\AquariumSynth.Dsl\AquariumSynth.Dsl.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,45 @@
using Aquarium.Engine.Audio;
using AquariumSynth.Dsl;
namespace Aquarium.Engine.Tests;
public sealed class SynthPlaybackTests
{
[Fact]
public void ClassicSfxrPresetsRenderAudibleDistinctShapesThroughAquariumFaustPath()
{
var analyzer = new AudioAnalyzer(new AudioAnalysisConfig(
FftSize: 512,
HopSize: 256,
MelBandCount: 24));
var renders = new List<(string Name, float[] Samples, AudioAnalysis Analysis)>();
foreach (var (name, script) in BuiltInScripts.ClassicSfxrPrimitiveGolfScripts)
{
if (!AquariumSynthHost.TryRenderScriptWithNativeFaust($"sfxr_{name}", script, 1.0f, out var samples, out var error))
{
Assert.Fail($"{name} failed to render through Aquarium Faust path: {error}");
}
var analysis = analyzer.Analyze(samples);
renders.Add((name, samples, analysis));
Assert.True(samples.Length > 2048, $"{name} rendered too few samples: {samples.Length}");
Assert.InRange(analysis.Features.Peak, 0.005f, 1.0f);
Assert.InRange(analysis.Features.Rms, 0.0005f, 0.8f);
Assert.InRange(analysis.Features.DurationSeconds, 0.015f, 1.4f);
Assert.True(analysis.Features.ZeroCrossingRate > 20.0f, $"{name} zero-crossing rate is suspiciously low: {analysis.Features.ZeroCrossingRate}");
}
Assert.Equal(BuiltInScripts.ClassicSfxrPrimitiveGolfScripts.Count, renders.Count);
for (var index = 1; index < renders.Count; index++)
{
var previous = renders[index - 1];
var current = renders[index];
var comparison = analyzer.Compare(previous.Samples, current.Samples);
Assert.True(
comparison.Score < 0.98f,
$"{previous.Name} and {current.Name} rendered nearly identical envelopes; score={comparison.Score:0.000}");
}
}
}