Add host-facing AquaSynth patch compiler

This commit is contained in:
Meta Vens 2026-05-18 10:11:00 +01:00
commit 90649b3de2
9 changed files with 90 additions and 32 deletions

View file

@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>AquaSynth.Core</AssemblyName>
<PackageId>AquaSynth.Core</PackageId>
<Version>0.1.0-alpha.2</Version>
<Version>0.1.0-alpha.3</Version>
<Authors>GameCult</Authors>
<Company>GameCult</Company>
<Description>AquaSynth patch model, DSL parser, analysis helpers, presets, and Faust source emitter.</Description>

View file

@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<AssemblyName>AquaSynth.Faust</AssemblyName>
<PackageId>AquaSynth.Faust</PackageId>
<Version>0.1.0-alpha.2</Version>
<Version>0.1.0-alpha.3</Version>
<Authors>GameCult</Authors>
<Company>GameCult</Company>
<Description>Native Faust toolchain loading, compile manifests, DSP factory lifetime, and offline rendering for AquaSynth patches.</Description>

View file

@ -123,14 +123,14 @@ public sealed class AquaSynthCompiledPatch : IDisposable
}
}
public sealed class AquaSynthRenderSession : IDisposable
public sealed class AquaSynthPatchCompiler : IDisposable
{
private readonly AquaSynthNativeOptions options;
private AquaSynthNativeCompiler? compiler;
private string? loadError;
private bool disposed;
public AquaSynthRenderSession(AquaSynthNativeOptions? options = null)
public AquaSynthPatchCompiler(AquaSynthNativeOptions? options = null)
{
this.options = options ?? new AquaSynthNativeOptions();
}
@ -591,6 +591,56 @@ internal sealed class NativeUtf8String : IDisposable
}
}
public sealed class AquaSynthRenderSession : IDisposable
{
private readonly AquaSynthPatchCompiler compiler;
private bool disposed;
public AquaSynthRenderSession(AquaSynthNativeOptions? options = null)
{
compiler = new AquaSynthPatchCompiler(options);
}
public string? LoadError => compiler.LoadError;
public bool IsReady => compiler.IsReady;
public string? FaustVersion => compiler.FaustVersion;
public bool TryCompileScript(AquaSynthCompileIdentity identity, out AquaSynthCompiledPatch? patch, out string? error)
{
ObjectDisposedException.ThrowIf(disposed, this);
return compiler.TryCompileScript(identity, out patch, out error);
}
public bool TryRenderScript(string name, string script, float gain, out float[] samples, out string? error)
{
samples = [];
if (!TryCompileScript(new AquaSynthCompileIdentity(name, name, script), out var patch, out error))
{
return false;
}
using (patch)
{
samples = patch!.Render(gain);
error = null;
return true;
}
}
public void Dispose()
{
if (disposed)
{
return;
}
compiler.Dispose();
disposed = true;
}
}
internal sealed class NativeStringArray : IDisposable
{
private readonly NativeUtf8String[] strings;