Fensalir/tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2026-05-12 21:24:42 +01:00
using Aquarium.Engine.Audio;
using AquaSynth.Faust;
2026-05-12 21:24:42 +01:00
namespace Aquarium.Engine.Tests;
public sealed class SynthPlaybackTests
{
[Fact]
2026-05-18 10:11:06 +01:00
public void AquaSynthPatchCompilerCanRenderAudiblePatchForEnginePlayback()
2026-05-12 21:24:42 +01:00
{
const string script = """
voice
wave=sine
freq=440
gain=0.2
attack=0.001
sustain=0.06
decay=0.12
""";
2026-05-12 21:24:42 +01:00
2026-05-18 10:11:06 +01:00
using var compiler = new AquaSynthPatchCompiler();
if (!compiler.TryCompileScript(new AquaSynthCompileIdentity("engine_synth_smoke", "engine_synth_smoke", script), out var patch, out var error))
2026-05-12 21:24:42 +01:00
{
if (error?.Contains("Faust toolchain not found", StringComparison.OrdinalIgnoreCase) == true ||
error?.Contains("Faust DLL not found", StringComparison.OrdinalIgnoreCase) == true)
2026-05-12 21:24:42 +01:00
{
return;
2026-05-12 21:24:42 +01:00
}
2026-05-18 10:11:06 +01:00
Assert.Fail($"AquaSynth patch compiler failed to render a tiny patch: {error}");
2026-05-12 21:24:42 +01:00
}
2026-05-18 10:11:06 +01:00
using (patch)
{
var samples = patch!.Render(1.0f);
Assert.True(samples.Length > 2048, $"Rendered too few samples: {samples.Length}.");
Assert.Contains(samples, sample => MathF.Abs(sample) > 0.001f);
Assert.InRange(samples.Max(sample => MathF.Abs(sample)), 0.001f, 1.0f);
}
2026-05-12 21:24:42 +01:00
}
}