diff --git a/packages/AquaSynth.Core.0.1.0-aquasynth.1.nupkg b/packages/AquaSynth.Core.0.1.0-aquasynth.2.nupkg similarity index 81% rename from packages/AquaSynth.Core.0.1.0-aquasynth.1.nupkg rename to packages/AquaSynth.Core.0.1.0-aquasynth.2.nupkg index 55157c5..a490e71 100644 Binary files a/packages/AquaSynth.Core.0.1.0-aquasynth.1.nupkg and b/packages/AquaSynth.Core.0.1.0-aquasynth.2.nupkg differ diff --git a/packages/AquaSynth.Faust.0.1.0-aquasynth.1.nupkg b/packages/AquaSynth.Faust.0.1.0-aquasynth.2.nupkg similarity index 95% rename from packages/AquaSynth.Faust.0.1.0-aquasynth.1.nupkg rename to packages/AquaSynth.Faust.0.1.0-aquasynth.2.nupkg index 53f6b22..5e1a2ce 100644 Binary files a/packages/AquaSynth.Faust.0.1.0-aquasynth.1.nupkg and b/packages/AquaSynth.Faust.0.1.0-aquasynth.2.nupkg differ diff --git a/src/Aquarium.Engine/Aquarium.Engine.csproj b/src/Aquarium.Engine/Aquarium.Engine.csproj index 451894a..917ae49 100644 --- a/src/Aquarium.Engine/Aquarium.Engine.csproj +++ b/src/Aquarium.Engine/Aquarium.Engine.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Aquarium.Engine/Audio/AquariumSynthHost.cs b/src/Aquarium.Engine/Audio/AquariumSynthHost.cs index 5320f8b..981b381 100644 --- a/src/Aquarium.Engine/Audio/AquariumSynthHost.cs +++ b/src/Aquarium.Engine/Audio/AquariumSynthHost.cs @@ -8,16 +8,9 @@ internal sealed class AquariumSynthHost : IDisposable private readonly Dictionary patches = new(StringComparer.Ordinal); private readonly WasapiAudioDevice audioDevice = new(); - private AquaSynthNativeCompiler? compiler; - private string? faustLoadError; + private readonly AquaSynthRenderSession renderSession = new(new AquaSynthNativeOptions(DspSourceDirectory: Path.Combine(AppContext.BaseDirectory, "Synth"))); private float timeSeconds; - internal static bool TryRenderScriptWithNativeFaust(string name, string script, float gain, out float[] samples, out string? error) - { - var options = new AquaSynthNativeOptions(DspSourceDirectory: Path.Combine(AppContext.BaseDirectory, "Synth")); - return AquaSynthNativeCompiler.TryRenderScript(name, script, gain, out samples, out error, options); - } - public void Update(AquariumSynthDocument synth, float deltaSeconds) { timeSeconds += Math.Max(deltaSeconds, 0.0f); @@ -26,7 +19,6 @@ internal sealed class AquariumSynthHost : IDisposable return; } - EnsureFaustLoaded(); foreach (var patch in synth.Patches) { var runtime = GetRuntime(patch); @@ -91,22 +83,14 @@ internal sealed class AquariumSynthHost : IDisposable return; } - if (compiler is null) - { - runtime.FailedKey = desiredKey; - SetStatus(runtime, AquariumSynthPatchCompileState.Failed, faustLoadError ?? "AquaSynth Faust toolchain not found", patch.FaustCompileRevision); - return; - } - - StartCompile(runtime, patch, identity, desiredKey, compiler); + StartCompile(runtime, patch, identity, desiredKey); } private void StartCompile( PatchRuntime runtime, AquariumSynthPatch patch, AquaSynthCompileIdentity identity, - string compileKey, - AquaSynthNativeCompiler activeCompiler) + string compileKey) { SetStatus(runtime, AquariumSynthPatchCompileState.Compiling, "compiling AquaSynth DSP", patch.FaustCompileRevision); var patchId = patch.Id; @@ -116,7 +100,23 @@ internal sealed class AquariumSynthHost : IDisposable { try { - var compiled = activeCompiler.CompileScript(identity); + if (!renderSession.TryCompileScript(identity, out var compiled, out var error)) + { + lock (runtime.Sync) + { + runtime.Compiled?.Dispose(); + runtime.Compiled = null; + runtime.ReadyKey = ""; + runtime.FailedKey = compileKey; + runtime.SoundCache.Clear(); + runtime.CompileTask = null; + runtime.SetStatus(AquariumSynthPatchCompileState.Failed, error ?? "AquaSynth render session unavailable", revision, timeSeconds); + } + + Console.WriteLine($"Aquarium synth patch `{patchId}` AquaSynth compile failed: {error}"); + return; + } + lock (runtime.Sync) { runtime.Compiled?.Dispose(); @@ -125,10 +125,10 @@ internal sealed class AquariumSynthHost : IDisposable runtime.FailedKey = ""; runtime.SoundCache.Clear(); runtime.CompileTask = null; - runtime.SetStatus(AquariumSynthPatchCompileState.Ready, $"ready in {compiled.Manifest.CompileMilliseconds:0} ms", revision, timeSeconds); + runtime.SetStatus(AquariumSynthPatchCompileState.Ready, $"ready in {compiled!.Manifest.CompileMilliseconds:0} ms", revision, timeSeconds); } - Console.WriteLine($"Aquarium synth patch `{patchId}` compiled by AquaSynth in {compiled.Manifest.CompileMilliseconds:0} ms."); + Console.WriteLine($"Aquarium synth patch `{patchId}` compiled by AquaSynth in {compiled!.Manifest.CompileMilliseconds:0} ms."); } catch (Exception ex) { @@ -178,26 +178,6 @@ internal sealed class AquariumSynthHost : IDisposable audioDevice.Play(sound.Samples, sampleRate); } - private void EnsureFaustLoaded() - { - if (compiler is not null || faustLoadError is not null) - { - return; - } - - var options = new AquaSynthNativeOptions(DspSourceDirectory: Path.Combine(AppContext.BaseDirectory, "Synth")); - if (AquaSynthNativeCompiler.TryLoad(out var loaded, out var error, options)) - { - compiler = loaded; - Console.WriteLine($"Aquarium AquaSynth Faust toolchain loaded: {loaded!.FaustVersion}"); - } - else - { - faustLoadError = error; - Console.WriteLine($"Aquarium AquaSynth Faust toolchain unavailable: {error}"); - } - } - private void PublishStatus(PatchRuntime runtime, AquariumSynthPatch patch) { AquariumSynthPatchStatus status; @@ -257,7 +237,7 @@ internal sealed class AquariumSynthHost : IDisposable } audioDevice.Dispose(); - compiler?.Dispose(); + renderSession.Dispose(); } private sealed class PatchRuntime(string id) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 7d9a71c..c3c2b4d 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -70,6 +70,7 @@ {"timestamp":"2026-05-13T00:26:00+01:00","topic":"synth-package-boundary","lesson":"Aquarium must not build against the live AquariumSynthCSharp project while a synth agent is mutating it. Consume AquariumSynth.Dsl as a pinned repo-local NuGet package and update that package only by deliberate version bump.","files":["NuGet.config","packages/AquariumSynth.Dsl.0.1.0-aquarium.1.nupkg","src/Aquarium.Engine/Aquarium.Engine.csproj","scripts/update-synth-package.ps1","state/map.yaml","state/memory.json","state/scratch.md","state/evidence.jsonl"],"source":"user asked whether synth-agent work can break Aquarium builds"} {"timestamp":"2026-05-17T15:15:00+01:00","topic":"aquasynth-native-audio-ownership","lesson":"Aquarium should host completed synth products, not own AquaSynth parsing, Faust emission, native libfaust factory creation, render duration estimation, compile keys, DSP source artifacts, or sample-buffer rendering. Those responsibilities now live in AquaSynth.Faust through AquaSynthNativeCompiler; AquariumSynthHost keeps scheduling, debounce/status, cache playback, and WASAPI output.","files":["src/Aquarium.Engine/Audio/AquariumSynthHost.cs","src/Aquarium.Engine/Aquarium.Engine.csproj","scripts/update-synth-package.ps1","scripts/publish-win-x64.ps1","state/map.yaml","state/memory.json"],"source":"user asked to finish taking over Aquarium's current audio rendering ownership so the engine does not concern itself with synth internals"} {"timestamp":"2026-05-17T15:45:00+01:00","topic":"aquasynth-package-split","lesson":"Aquarium consumes AquaSynth.Faust, not a catch-all AquaSynth.Dsl package. AquaSynth.Faust carries the runtime/toolchain surface and pulls AquaSynth.Core transitively for the built-in patch editor's parser/model/built-in script needs.","files":["src/Aquarium.Engine/Aquarium.Engine.csproj","packages/AquaSynth.Core.0.1.0-aquasynth.1.nupkg","packages/AquaSynth.Faust.0.1.0-aquasynth.1.nupkg","scripts/update-synth-package.ps1","scripts/publish-win-x64.ps1","state/map.yaml","state/memory.json","state/scratch.md"],"source":"user pointed out .Dsl no longer described the package and confirmed Aquarium still needs DSL through the Faust dependency"} +{"timestamp":"2026-05-17T16:05:00+01:00","topic":"aquasynth-render-session-boundary","lesson":"AquariumSynthHost no longer exposes a static native render smoke helper or calls AquaSynthNativeCompiler.TryLoad. AquaSynth.Faust owns lazy compiler loading through AquaSynthRenderSession; Aquarium holds that session and only schedules compile/playback requests.","files":["src/Aquarium.Engine/Audio/AquariumSynthHost.cs","tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs","src/Aquarium.Engine/Aquarium.Engine.csproj","packages/AquaSynth.Core.0.1.0-aquasynth.2.nupkg","packages/AquaSynth.Faust.0.1.0-aquasynth.2.nupkg"],"source":"user called out AquariumSynthHost keeping compiler load and TryRenderScriptWithNativeFaust as a convenience exemption"} {"timestamp":"2026-05-13T00:40:00+01:00","topic":"generic-sdf-field-ids","lesson":"Aquarium shared SDF code must not special-case Epiphany object identities. SDF field ids are generic base-plus-object-index metadata; Self, Cursor, and role meaning stay in Epiphany's object table and shaders, while temporal reprojection uses uploaded AquariumSdfObject current/previous centers for every SDF object.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Epiphany/EpiphanySceneBuilder.cs","docs/epiphany-agent-sdf-visual-language.md","state/memory.json"]} {"timestamp":"2026-05-13T01:05:00+01:00","topic":"sdf-metallic-roughness-pbr","lesson":"SDF surfaces now use the industry-standard metallic-roughness material language: baseColor, metallic, roughness, and emission. The shared shader derives dielectric F0, metal-tinted specular F0, non-metal diffuse color, direct Cook-Torrance GGX specular, Fresnel-gated Lambert diffuse, diffuse irradiance IBL, and roughness-mip PMREM specular from those fields.","files":["src/Aquarium.Engine/Render/Shaders/D3D12SdfCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12SdfProxy.hlsli","src/Aquarium.Epiphany/Shaders","docs/epiphany-agent-sdf-visual-language.md","state/memory.json"],"source":"Khronos glTF 2.0 metallic-roughness material model; Google Filament material model notes"} {"timestamp":"2026-05-13T01:45:00+01:00","topic":"imagination-topology-spec","lesson":"Imagination's visual spec needs topology, not just evocative nouns. The target is a luminous opal seed wrapped by broad translucent curling ribbon-sheets with traced raised rims, visible interior apertures, vertical fountain bias, sparse candidate filaments/sparks, and cool backlog shadow. Trefoil/tube curves may define rim paths, but tubes alone do not satisfy the petal form.","files":["docs/epiphany-agent-sdf-visual-language.md","state/memory.json"],"source":"user supplied imagegen reference and noted current output did not match the imagined impossible flower"} diff --git a/state/map.yaml b/state/map.yaml index 51095c7..8bfcc45 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -44,8 +44,8 @@ current_model: dependencies: cult_math: E:\Projects\CultMath cult_lib: E:\Projects\CultLib - aqua_synth_faust: NuGet package AquaSynth.Faust 0.1.0-aquasynth.1 from repo-local packages feed - aqua_synth_core: transitive NuGet package AquaSynth.Core 0.1.0-aquasynth.1 from repo-local packages feed + aqua_synth_faust: NuGet package AquaSynth.Faust 0.1.0-aquasynth.2 from repo-local packages feed + aqua_synth_core: transitive NuGet package AquaSynth.Core 0.1.0-aquasynth.2 from repo-local packages feed docs: doctrine: docs/aquarium-engine-doctrine.md engine_client_boundary: docs/engine-client-boundary.md diff --git a/tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs b/tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs index e610808..d710bbc 100644 --- a/tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs +++ b/tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs @@ -1,11 +1,12 @@ using Aquarium.Engine.Audio; +using AquaSynth.Faust; namespace Aquarium.Engine.Tests; public sealed class SynthPlaybackTests { [Fact] - public void EngineSynthHostCanRenderAudibleFaustPatch() + public void AquaSynthRenderSessionCanRenderAudiblePatchForEnginePlayback() { const string script = """ voice @@ -17,7 +18,8 @@ public sealed class SynthPlaybackTests decay=0.12 """; - if (!AquariumSynthHost.TryRenderScriptWithNativeFaust("engine_synth_smoke", script, 1.0f, out var samples, out var error)) + using var session = new AquaSynthRenderSession(); + if (!session.TryRenderScript("engine_synth_smoke", script, 1.0f, out var samples, out var error)) { if (error?.Contains("Faust toolchain not found", StringComparison.OrdinalIgnoreCase) == true || error?.Contains("Faust DLL not found", StringComparison.OrdinalIgnoreCase) == true) @@ -25,7 +27,7 @@ public sealed class SynthPlaybackTests return; } - Assert.Fail($"Aquarium synth host failed to render a tiny Faust patch: {error}"); + Assert.Fail($"AquaSynth render session failed to render a tiny patch: {error}"); } Assert.True(samples.Length > 2048, $"Rendered too few samples: {samples.Length}.");