diff --git a/docs/physical-voice-modeling-research.md b/docs/physical-voice-modeling-research.md index f849779..fd4f17c 100644 --- a/docs/physical-voice-modeling-research.md +++ b/docs/physical-voice-modeling-research.md @@ -202,17 +202,32 @@ Avoid concepts as primary public abstractions: ## Next Implementation Cut -Add model records before more audio golf: +First implementation cut is now underway in `src/AquaSynth.Core/Model.cs` and +`src/AquaSynth.Core/PatchScript.cs`. The new neutral records are the ownership +surface: - `AcousticPath`: name, length, area curve, propagation speed, loss profile. -- `AcousticBranch`: from path/position to path/position, opening/coupling, - branch kind. - `AcousticSourcePort`: path/position, source model, pressure/tension/noise controls. +- `AcousticBranch`: from path/position to path/position, opening/coupling, + branch kind. - `AcousticRadiationPort`: path/position, opening/reflection/radiation filter. - `WaveClockPolicy`: unit grid, half-sample grid, fractional delay order, max delay, and smoothing mode. +- `AcousticPortNetwork`: names one primary path and the source, branch, + radiation, and wave-clock records that make it renderable. -Then lower the current PT fixtures through those records as one larynx-shaped -configuration. A syrinx should be expressible by adding two source ports and a -bronchial/tracheal branch topology, not by forking the tract voice. +Parser support exists for `path`, `source_port`, `branch`, `radiation_port`, +`wave_clock`, and `acoustic_network`. Existing PT-pressure commands now also +feed the acoustic record lists: `tract_shape` demotes to an `AcousticPath`, +`glottis`/`tract_injection` demote to `AcousticSourcePort`, `nasal_branch` +demotes to an `AcousticPath` plus `AcousticBranch`, and each `tract` voice +gets an `AcousticPortNetwork` over generated oral/source/branch/radiation +records. + +This is intentionally a structural first cut. Faust lowering still uses the +current `Voice.Tract` renderer, but the neutral acoustic records now exist so +the next cuts can move waveguide/proxy lowering authority out of PT-shaped +fields without losing fixture compatibility. A syrinx can already be authored +as two labial `source_port` records plus bronchial/tract `branch` topology; the +next proof is to give that network an audible lowering path. diff --git a/docs/pink-trombone-dsl-parity-plan.md b/docs/pink-trombone-dsl-parity-plan.md index 8f0af41..7e432d0 100644 --- a/docs/pink-trombone-dsl-parity-plan.md +++ b/docs/pink-trombone-dsl-parity-plan.md @@ -143,6 +143,16 @@ delay is about 0.5 samples per cell. That makes PT's two tract updates per output sample look like a discretization strategy for a half-sample cell grid, not a reusable Aqua language concept. +The acoustic-port cut has also started. Aqua now has neutral model records for +`AcousticPath`, `AcousticSourcePort`, `AcousticBranch`, +`AcousticRadiationPort`, `WaveClockPolicy`, and `AcousticPortNetwork`. +Parser commands `path`, `source_port`, `branch`, `radiation_port`, +`wave_clock`, and `acoustic_network` can express a larynx, paired labial +syrinx-like sources, or stranger source/topology combinations without adding a +species mode. Existing PT-shaped commands now populate those acoustic records +as compatibility aliases: they no longer have to be the only authority surface +for the next renderer. + Exact Pink Trombone timing still needs pressure, but the next backend cut is no longer "add more substeps." The current Faust-friendly compromise chooses a unit-delay scattering grid from physical length. The deeper target remains diff --git a/src/AquaSynth.Core/Model.cs b/src/AquaSynth.Core/Model.cs index 60296f9..6699d3b 100644 --- a/src/AquaSynth.Core/Model.cs +++ b/src/AquaSynth.Core/Model.cs @@ -223,6 +223,102 @@ public sealed record TractAreaFunction(IReadOnlyList Diameters, float Len public sealed record TractShape(string Name, TractAreaFunction AreaFunction); +public enum AcousticSourceKind +{ + Glottal, + Labial, + Reed, + TurbulenceJet, + Click, + Synthetic +} + +public enum AcousticBranchKind +{ + SideBranch, + Nasal, + Bronchial, + Lateral, + Resonator +} + +public enum AcousticRadiationKind +{ + Lip, + Nostril, + Beak, + Vent, + Membrane +} + +public enum WaveClockDelayStrategy +{ + UnitGrid, + HalfSampleGrid, + FractionalLinear, + FractionalLagrange, + FractionalThiran, + CrossfadedVariable +} + +public sealed record AcousticPath( + string Name, + TractAreaFunction AreaFunction, + float PropagationSpeedMetersPerSecond = 343, + float Loss = 0.999f); + +public sealed record AcousticSourcePort( + string Name, + string Path, + float Position = 0, + AcousticSourceKind Kind = AcousticSourceKind.Glottal, + float Pressure = 0.72f, + float Tension = 0.6f, + float Opening = 0.5f, + float Noise = 0.08f, + float Balance = 1, + bool Active = true); + +public sealed record AcousticBranch( + string Name, + string FromPath, + float FromPosition, + string ToPath, + float ToPosition = 0, + AcousticBranchKind Kind = AcousticBranchKind.SideBranch, + float Opening = 0, + float Coupling = 1, + bool Passive = true); + +public sealed record AcousticRadiationPort( + string Name, + string Path, + float Position = 1, + AcousticRadiationKind Kind = AcousticRadiationKind.Lip, + float Opening = 1, + float Reflection = -0.85f, + float Loss = 1); + +public sealed record WaveClockPolicy( + string Name, + WaveClockDelayStrategy Strategy = WaveClockDelayStrategy.UnitGrid, + int FractionalOrder = 1, + int MaxDelaySamples = 2048, + float SmoothingMilliseconds = 5); + +public sealed record AcousticPortNetwork( + string Name, + string PrimaryPath, + string WaveClock = "", + IReadOnlyList? SourcePorts = null, + IReadOnlyList? Branches = null, + IReadOnlyList? RadiationPorts = null) +{ + public IReadOnlyList SourcePorts { get; init; } = SourcePorts ?? Array.Empty(); + public IReadOnlyList Branches { get; init; } = Branches ?? Array.Empty(); + public IReadOnlyList RadiationPorts { get; init; } = RadiationPorts ?? Array.Empty(); +} + public sealed record GlottalSource( string Name = "", float Intensity = 0.72f, @@ -323,7 +419,8 @@ public sealed record VocalTract( TractPropagationMode Propagation = TractPropagationMode.Resonator, float WaveguideLoss = 0.999f, int Substeps = 1, - float IndexScale = 1); + float IndexScale = 1, + AcousticPortNetwork? AcousticNetwork = null); public sealed record PatchParameter( string Path, @@ -482,6 +579,7 @@ public sealed record Voice public Arpeggio? Arpeggio { get; init; } public FrequencyModulation Fm { get; init; } = new(); public VocalTract? Tract { get; init; } + public AcousticPortNetwork? AcousticNetwork { get; init; } public VoiceColor Color { get; init; } = new(); public IReadOnlyList Formants { get; init; } = Array.Empty(); public IReadOnlyList FormantFrames { get; init; } = Array.Empty(); @@ -501,6 +599,12 @@ public sealed record SynthPatch public IReadOnlyList TractInjections { get; init; } = Array.Empty(); public IReadOnlyList NasalBranches { get; init; } = Array.Empty(); public IReadOnlyList TractMotions { get; init; } = Array.Empty(); + public IReadOnlyList AcousticPaths { get; init; } = Array.Empty(); + public IReadOnlyList AcousticSourcePorts { get; init; } = Array.Empty(); + public IReadOnlyList AcousticBranches { get; init; } = Array.Empty(); + public IReadOnlyList AcousticRadiationPorts { get; init; } = Array.Empty(); + public IReadOnlyList WaveClocks { get; init; } = Array.Empty(); + public IReadOnlyList AcousticNetworks { get; init; } = Array.Empty(); public IReadOnlyList OperatorGraphs { get; init; } = Array.Empty(); public IReadOnlyList Controls { get; init; } = Array.Empty(); public IReadOnlyList Parameters { get; init; } = Array.Empty(); diff --git a/src/AquaSynth.Core/PatchScript.cs b/src/AquaSynth.Core/PatchScript.cs index 143b0fe..9bb72ed 100644 --- a/src/AquaSynth.Core/PatchScript.cs +++ b/src/AquaSynth.Core/PatchScript.cs @@ -46,6 +46,18 @@ public static class PatchScript private readonly Dictionary _nasalBranchesByName = new(StringComparer.OrdinalIgnoreCase); private readonly List _tractMotions = []; private readonly Dictionary _tractMotionsByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _acousticPaths = []; + private readonly Dictionary _acousticPathsByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _acousticSourcePorts = []; + private readonly Dictionary _acousticSourcePortsByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _acousticBranches = []; + private readonly Dictionary _acousticBranchesByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _acousticRadiationPorts = []; + private readonly Dictionary _acousticRadiationPortsByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _waveClocks = []; + private readonly Dictionary _waveClocksByName = new(StringComparer.OrdinalIgnoreCase); + private readonly List _acousticNetworks = []; + private readonly Dictionary _acousticNetworksByName = new(StringComparer.OrdinalIgnoreCase); private readonly Dictionary _defaults = new(StringComparer.OrdinalIgnoreCase); private readonly Dictionary> _layerDefaults = new(StringComparer.OrdinalIgnoreCase); private PendingOperatorGraph? _pendingOperatorGraph; @@ -72,6 +84,12 @@ public static class PatchScript TractInjections = _tractInjections, NasalBranches = _nasalBranches, TractMotions = _tractMotions, + AcousticPaths = _acousticPaths, + AcousticSourcePorts = _acousticSourcePorts, + AcousticBranches = _acousticBranches, + AcousticRadiationPorts = _acousticRadiationPorts, + WaveClocks = _waveClocks, + AcousticNetworks = _acousticNetworks, OperatorGraphs = _operatorGraphs, Controls = _controls, Parameters = _parameters, @@ -143,6 +161,30 @@ public static class PatchScript FlushPendingOperatorGraph(); AddTractMotion(fields, line); break; + case "acoustic_path": + FlushPendingOperatorGraph(); + AddAcousticPath(fields, line); + break; + case "source_port": + FlushPendingOperatorGraph(); + AddAcousticSourcePort(fields, line); + break; + case "branch": + FlushPendingOperatorGraph(); + AddAcousticBranch(fields, line); + break; + case "radiation_port": + FlushPendingOperatorGraph(); + AddAcousticRadiationPort(fields, line); + break; + case "wave_clock": + FlushPendingOperatorGraph(); + AddWaveClock(fields, line); + break; + case "acoustic_network": + FlushPendingOperatorGraph(); + AddAcousticNetwork(fields, line); + break; case "voice": FlushPendingOperatorGraph(); Voices.Add(ParseVoice(ExpandVoiceFields(fields, line), VoicePath(Voices.Count), line)); @@ -312,6 +354,11 @@ public static class PatchScript var shape = new TractShape(name, areaFunction); _tractShapes.Add(shape); _tractShapesByName[name] = shape; + AddAcousticPathRecord(new AcousticPath( + name, + areaFunction, + GetBoundFloat(fields, line, 343, $"/acoustic/paths/{_acousticPaths.Count}/speed", "speed", "wave_speed", "propagation_speed"), + GetBoundFloat(fields, line, 0.999f, $"/acoustic/paths/{_acousticPaths.Count}/loss", "loss"))); } private void AddGlottalSource(IReadOnlyDictionary fields, int line) @@ -331,6 +378,19 @@ public static class PatchScript GetBoundFloat(fields, line, 0.42f, $"/glottis/{_glottalSources.Count}/skew", "skew", "open_phase")); _glottalSources.Add(glottis); _glottalSourcesByName[name] = glottis; + if (TryGetAny(fields, ["path"], out var path)) + { + RequireAcousticPath(path, line); + AddAcousticSourcePortRecord(new AcousticSourcePort( + name, + path, + GetBoundFloat(fields, line, 0, $"/acoustic/sources/{_acousticSourcePorts.Count}/position", "position", "pos", "at"), + AcousticSourceKind.Glottal, + glottis.Intensity, + glottis.Tenseness, + glottis.Skew, + glottis.Aspiration)); + } } private void AddTractInjection(IReadOnlyDictionary fields, int line) @@ -350,6 +410,19 @@ public static class PatchScript GetBoundFloat(fields, line, 1, $"/tract_injections/{_tractInjections.Count}/width", "width")); _tractInjections.Add(injection); _tractInjectionsByName[name] = injection; + if (TryGetAny(fields, ["path"], out var path)) + { + RequireAcousticPath(path, line); + AddAcousticSourcePortRecord(new AcousticSourcePort( + name, + path, + injection.Position, + AcousticSourceKind.TurbulenceJet, + injection.Burst, + 0, + injection.Diameter, + injection.Turbulence)); + } } private void AddNasalBranch(IReadOnlyDictionary fields, int line) @@ -369,6 +442,24 @@ public static class PatchScript GetBoundFloat(fields, line, 0.999f, $"/nasal_branches/{_nasalBranches.Count}/loss", "loss")); _nasalBranches.Add(branch); _nasalBranchesByName[name] = branch; + if (branch.AreaFunction is { } nasalArea) + { + AddAcousticPathRecord(new AcousticPath( + name, + nasalArea, + GetBoundFloat(fields, line, 343, $"/acoustic/paths/{_acousticPaths.Count}/speed", "speed", "wave_speed", "propagation_speed"), + branch.Loss)); + } + AddAcousticBranchRecord(new AcousticBranch( + name, + GetAny(fields, ["from_path"], "oral"), + branch.JunctionIndex, + name, + 0, + AcousticBranchKind.Nasal, + branch.Velum, + 1, + true)); } private void AddTractMotion(IReadOnlyDictionary fields, int line) @@ -390,6 +481,214 @@ public static class PatchScript _tractMotionsByName[name] = motion; } + private void AddAcousticPath(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_acousticPathsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate acoustic path `{name}`"); + } + + var path = new AcousticPath( + name, + ParseTractAreaFunction(fields, line, 17), + GetBoundFloat(fields, line, 343, $"/acoustic/paths/{_acousticPaths.Count}/speed", "speed", "wave_speed", "propagation_speed"), + GetBoundFloat(fields, line, 0.999f, $"/acoustic/paths/{_acousticPaths.Count}/loss", "loss")); + AddAcousticPathRecord(path); + } + + private void AddAcousticSourcePort(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_acousticSourcePortsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate acoustic source port `{name}`"); + } + + var path = Required(fields, "path", line); + RequireAcousticPath(path, line); + var port = new AcousticSourcePort( + name, + path, + GetBoundFloat(fields, line, 0, $"/acoustic/sources/{_acousticSourcePorts.Count}/position", "position", "pos", "at"), + ParseAcousticSourceKind(GetAny(fields, ["kind", "source_kind"], "glottal"), line), + GetBoundFloat(fields, line, 0.72f, $"/acoustic/sources/{_acousticSourcePorts.Count}/pressure", "pressure", "intensity"), + GetBoundFloat(fields, line, 0.6f, $"/acoustic/sources/{_acousticSourcePorts.Count}/tension", "tension", "tenseness", "tense"), + GetBoundFloat(fields, line, 0.5f, $"/acoustic/sources/{_acousticSourcePorts.Count}/opening", "opening", "open"), + GetBoundFloat(fields, line, 0.08f, $"/acoustic/sources/{_acousticSourcePorts.Count}/noise", "noise", "aspiration"), + GetBoundFloat(fields, line, 1, $"/acoustic/sources/{_acousticSourcePorts.Count}/balance", "balance"), + TryGetAny(fields, ["active"], out var active) ? ParseBool(active, line) : true); + AddAcousticSourcePortRecord(port); + } + + private void AddAcousticBranch(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_acousticBranchesByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate acoustic branch `{name}`"); + } + + var fromPath = GetAny(fields, ["from_path", "from"], ""); + var toPath = GetAny(fields, ["to_path", "to"], ""); + if (fromPath.Length == 0) throw new PatchScriptException(line, "branch missing `from_path`"); + if (toPath.Length == 0) throw new PatchScriptException(line, "branch missing `to_path`"); + RequireAcousticPath(fromPath, line); + RequireAcousticPath(toPath, line); + var branch = new AcousticBranch( + name, + fromPath, + GetBoundFloat(fields, line, 0, $"/acoustic/branches/{_acousticBranches.Count}/from_position", "from_position", "from_pos", "from_at", "at"), + toPath, + GetBoundFloat(fields, line, 0, $"/acoustic/branches/{_acousticBranches.Count}/to_position", "to_position", "to_pos", "to_at"), + ParseAcousticBranchKind(GetAny(fields, ["kind", "branch_kind"], "side"), line), + GetBoundFloat(fields, line, 0, $"/acoustic/branches/{_acousticBranches.Count}/opening", "opening", "open"), + GetBoundFloat(fields, line, 1, $"/acoustic/branches/{_acousticBranches.Count}/coupling", "coupling"), + TryGetAny(fields, ["passive"], out var passive) ? ParseBool(passive, line) : true); + AddAcousticBranchRecord(branch); + } + + private void AddAcousticRadiationPort(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_acousticRadiationPortsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate acoustic radiation port `{name}`"); + } + + var path = Required(fields, "path", line); + RequireAcousticPath(path, line); + var port = new AcousticRadiationPort( + name, + path, + GetBoundFloat(fields, line, 1, $"/acoustic/radiation/{_acousticRadiationPorts.Count}/position", "position", "pos", "at"), + ParseAcousticRadiationKind(GetAny(fields, ["kind", "radiation_kind"], "lip"), line), + GetBoundFloat(fields, line, 1, $"/acoustic/radiation/{_acousticRadiationPorts.Count}/opening", "opening", "open"), + GetBoundFloat(fields, line, -0.85f, $"/acoustic/radiation/{_acousticRadiationPorts.Count}/reflection", "reflection"), + GetBoundFloat(fields, line, 1, $"/acoustic/radiation/{_acousticRadiationPorts.Count}/loss", "loss")); + AddAcousticRadiationPortRecord(port); + } + + private void AddWaveClock(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_waveClocksByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate wave clock `{name}`"); + } + + var policy = new WaveClockPolicy( + name, + ParseWaveClockDelayStrategy(GetAny(fields, ["strategy", "delay", "mode"], "unit_grid"), line), + GetBoundInt(fields, line, 1, $"/acoustic/wave_clocks/{_waveClocks.Count}/order", "order", "fractional_order"), + GetBoundInt(fields, line, 2048, $"/acoustic/wave_clocks/{_waveClocks.Count}/max_delay", "max_delay", "max_delay_samples"), + GetBoundFloat(fields, line, 5, $"/acoustic/wave_clocks/{_waveClocks.Count}/smoothing_ms", "smoothing_ms", "smooth_ms")); + AddWaveClockRecord(policy); + } + + private void AddAcousticNetwork(IReadOnlyDictionary fields, int line) + { + var name = Required(fields, "name", line); + if (_acousticNetworksByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"duplicate acoustic network `{name}`"); + } + + var primaryPath = Required(fields, "path", line); + RequireAcousticPath(primaryPath, line); + var waveClock = GetAny(fields, ["wave_clock", "clock"], ""); + if (waveClock.Length > 0 && !_waveClocksByName.ContainsKey(waveClock)) + { + throw new PatchScriptException(line, $"unknown wave clock `{waveClock}`"); + } + + var network = new AcousticPortNetwork( + name, + primaryPath, + waveClock, + ParseNameList(GetAny(fields, ["sources", "source_ports"], "")), + ParseNameList(GetAny(fields, ["branches"], "")), + ParseNameList(GetAny(fields, ["radiation", "radiation_ports"], ""))); + foreach (var sourceName in network.SourcePorts) RequireAcousticSourcePort(sourceName, line); + foreach (var branchName in network.Branches) RequireAcousticBranch(branchName, line); + foreach (var radiationName in network.RadiationPorts) RequireAcousticRadiationPort(radiationName, line); + AddAcousticNetworkRecord(network); + } + + private void AddAcousticPathRecord(AcousticPath path) + { + if (_acousticPathsByName.ContainsKey(path.Name)) return; + _acousticPaths.Add(path); + _acousticPathsByName[path.Name] = path; + } + + private void AddAcousticSourcePortRecord(AcousticSourcePort port) + { + if (_acousticSourcePortsByName.ContainsKey(port.Name)) return; + _acousticSourcePorts.Add(port); + _acousticSourcePortsByName[port.Name] = port; + } + + private void AddAcousticBranchRecord(AcousticBranch branch) + { + if (_acousticBranchesByName.ContainsKey(branch.Name)) return; + _acousticBranches.Add(branch); + _acousticBranchesByName[branch.Name] = branch; + } + + private void AddAcousticRadiationPortRecord(AcousticRadiationPort port) + { + if (_acousticRadiationPortsByName.ContainsKey(port.Name)) return; + _acousticRadiationPorts.Add(port); + _acousticRadiationPortsByName[port.Name] = port; + } + + private void AddWaveClockRecord(WaveClockPolicy policy) + { + if (_waveClocksByName.ContainsKey(policy.Name)) return; + _waveClocks.Add(policy); + _waveClocksByName[policy.Name] = policy; + } + + private void AddAcousticNetworkRecord(AcousticPortNetwork network) + { + if (_acousticNetworksByName.ContainsKey(network.Name)) return; + _acousticNetworks.Add(network); + _acousticNetworksByName[network.Name] = network; + } + + private void RequireAcousticPath(string name, int line) + { + if (!_acousticPathsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"unknown acoustic path `{name}`"); + } + } + + private void RequireAcousticSourcePort(string name, int line) + { + if (!_acousticSourcePortsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"unknown acoustic source port `{name}`"); + } + } + + private void RequireAcousticBranch(string name, int line) + { + if (!_acousticBranchesByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"unknown acoustic branch `{name}`"); + } + } + + private void RequireAcousticRadiationPort(string name, int line) + { + if (!_acousticRadiationPortsByName.ContainsKey(name)) + { + throw new PatchScriptException(line, $"unknown acoustic radiation port `{name}`"); + } + } + private Dictionary ExpandVoiceFields(Dictionary fields, int line) { var expanded = new Dictionary(_defaults, StringComparer.OrdinalIgnoreCase); @@ -662,31 +961,35 @@ public static class PatchScript var tongueIndex = GetBoundFloat(fields, line, 12.9f, OwnerField(ownerPath, "tract/tongue_index"), "tongue_index", "tongue", "ti"); var constrictionIndex = GetBoundFloat(fields, line, injection?.Position ?? 32, OwnerField(ownerPath, "tract/constriction_index"), "constriction_index", "ci"); + var tract = new VocalTract( + sections, + noseSections, + GetBoundFloat(fields, line, glottis?.Intensity ?? 0.72f, OwnerField(ownerPath, "tract/intensity"), "intensity", "pressure"), + GetBoundFloat(fields, line, glottis?.Tenseness ?? 0.6f, OwnerField(ownerPath, "tract/tenseness"), "tenseness", "tense"), + tongueIndex, + GetBoundFloat(fields, line, 2.43f, OwnerField(ownerPath, "tract/tongue_diameter"), "tongue_diameter", "td"), + GetBoundFloat(fields, line, 0.01f, OwnerField(ownerPath, "tract/velum"), "velum", "nose", "nasal"), + constrictionIndex, + GetBoundFloat(fields, line, injection?.Diameter ?? 1, OwnerField(ownerPath, "tract/constriction_diameter"), "constriction_diameter", "cd"), + GetBoundFloat(fields, line, injection?.Turbulence ?? 0, OwnerField(ownerPath, "tract/turbulence"), "turbulence", "frication"), + GetBoundFloat(fields, line, 1.5f, OwnerField(ownerPath, "tract/lip_opening"), "lip", "lip_opening", "mouth"), + GetBoundFloat(fields, line, glottis?.Reflection ?? 0.75f, OwnerField(ownerPath, "tract/glottal_reflection"), "glottal_reflection", "gr"), + GetBoundFloat(fields, line, -0.85f, OwnerField(ownerPath, "tract/lip_reflection"), "lip_reflection", "lr"), + areaFunction, + glottis, + injection, + nasal, + motion, + propagation, + GetBoundFloat(fields, line, 0.999f, OwnerField(ownerPath, "tract/waveguide_loss"), "waveguide_loss", "loss"), + GetBoundInt(fields, line, 1, OwnerField(ownerPath, "tract/substeps"), "substeps", "steps"), + indexScale); + var acousticNetwork = EnsureTractAcousticNetwork(ownerPath, tract); + return voice with { - Tract = new VocalTract( - sections, - noseSections, - GetBoundFloat(fields, line, glottis?.Intensity ?? 0.72f, OwnerField(ownerPath, "tract/intensity"), "intensity", "pressure"), - GetBoundFloat(fields, line, glottis?.Tenseness ?? 0.6f, OwnerField(ownerPath, "tract/tenseness"), "tenseness", "tense"), - tongueIndex, - GetBoundFloat(fields, line, 2.43f, OwnerField(ownerPath, "tract/tongue_diameter"), "tongue_diameter", "td"), - GetBoundFloat(fields, line, 0.01f, OwnerField(ownerPath, "tract/velum"), "velum", "nose", "nasal"), - constrictionIndex, - GetBoundFloat(fields, line, injection?.Diameter ?? 1, OwnerField(ownerPath, "tract/constriction_diameter"), "constriction_diameter", "cd"), - GetBoundFloat(fields, line, injection?.Turbulence ?? 0, OwnerField(ownerPath, "tract/turbulence"), "turbulence", "frication"), - GetBoundFloat(fields, line, 1.5f, OwnerField(ownerPath, "tract/lip_opening"), "lip", "lip_opening", "mouth"), - GetBoundFloat(fields, line, glottis?.Reflection ?? 0.75f, OwnerField(ownerPath, "tract/glottal_reflection"), "glottal_reflection", "gr"), - GetBoundFloat(fields, line, -0.85f, OwnerField(ownerPath, "tract/lip_reflection"), "lip_reflection", "lr"), - areaFunction, - glottis, - injection, - nasal, - motion, - propagation, - GetBoundFloat(fields, line, 0.999f, OwnerField(ownerPath, "tract/waveguide_loss"), "waveguide_loss", "loss"), - GetBoundInt(fields, line, 1, OwnerField(ownerPath, "tract/substeps"), "substeps", "steps"), - indexScale) + Tract = tract with { AcousticNetwork = acousticNetwork }, + AcousticNetwork = acousticNetwork }; } @@ -707,6 +1010,99 @@ public static class PatchScript }; } + private AcousticPortNetwork EnsureTractAcousticNetwork(string ownerPath, VocalTract tract) + { + var prefix = ownerPath.Replace("/", "_", StringComparison.Ordinal).Trim('_'); + var primaryPathName = $"{prefix}_oral"; + var oralArea = tract.AreaFunction ?? new TractAreaFunction([0.6f, 0.8f, 1.2f, 1.5f, 1.5f, 1.2f, 0.8f, 0.6f], 17); + AddAcousticPathRecord(new AcousticPath(primaryPathName, oralArea, 343, tract.WaveguideLoss)); + + var sourceNames = new List(); + var branchNames = new List(); + var radiationNames = new List(); + + var sourceName = string.IsNullOrWhiteSpace(tract.Glottis?.Name) ? $"{prefix}_source" : $"{prefix}_{tract.Glottis!.Name}"; + AddAcousticSourcePortRecord(new AcousticSourcePort( + sourceName, + primaryPathName, + 0, + AcousticSourceKind.Glottal, + tract.Intensity, + tract.Tenseness, + tract.Glottis?.Skew ?? 0.42f, + tract.Glottis?.Aspiration ?? 0.08f)); + sourceNames.Add(sourceName); + + if (tract.Injection is { } injection) + { + var injectionName = string.IsNullOrWhiteSpace(injection.Name) ? $"{prefix}_injection" : $"{prefix}_{injection.Name}"; + AddAcousticSourcePortRecord(new AcousticSourcePort( + injectionName, + primaryPathName, + injection.Position, + AcousticSourceKind.TurbulenceJet, + injection.Burst, + 0, + injection.Diameter, + injection.Turbulence)); + sourceNames.Add(injectionName); + } + + if (tract.Nasal is { AreaFunction: { } nasalArea } nasal) + { + var nasalPathName = string.IsNullOrWhiteSpace(nasal.Name) ? $"{prefix}_nasal" : $"{prefix}_{nasal.Name}"; + AddAcousticPathRecord(new AcousticPath(nasalPathName, nasalArea, 343, nasal.Loss)); + AddAcousticBranchRecord(new AcousticBranch( + nasalPathName, + primaryPathName, + nasal.JunctionIndex, + nasalPathName, + 0, + AcousticBranchKind.Nasal, + nasal.Velum, + 1, + true)); + AddAcousticRadiationPortRecord(new AcousticRadiationPort( + $"{nasalPathName}_radiation", + nasalPathName, + 1, + AcousticRadiationKind.Nostril, + nasal.Velum, + nasal.Reflection, + nasal.Loss)); + branchNames.Add(nasalPathName); + radiationNames.Add($"{nasalPathName}_radiation"); + } + + var lipName = $"{prefix}_lip"; + AddAcousticRadiationPortRecord(new AcousticRadiationPort( + lipName, + primaryPathName, + 1, + AcousticRadiationKind.Lip, + tract.LipOpening, + tract.LipReflection, + 1)); + radiationNames.Add(lipName); + + var clockName = $"{prefix}_clock"; + AddWaveClockRecord(new WaveClockPolicy( + clockName, + tract.Propagation == TractPropagationMode.Waveguide + ? WaveClockDelayStrategy.UnitGrid + : WaveClockDelayStrategy.FractionalLinear)); + + var network = new AcousticPortNetwork( + $"{prefix}_network", + primaryPathName, + clockName, + sourceNames, + branchNames, + radiationNames); + AddAcousticNetworkRecord(network); + return network; + } + private void AddModBus(IReadOnlyDictionary fields, int line) { var name = GetAny(fields, ["name", "n"], "mod"); @@ -1665,6 +2061,12 @@ public static class PatchScript "tract_injection" or "injection" or "frication" or "burst" => "tract_injection", "nasal_branch" or "nose_branch" or "nasal" => "nasal_branch", "tract_motion" or "shape_motion" or "slew" => "tract_motion", + "path" or "acoustic_path" or "morphology_path" => "acoustic_path", + "source_port" or "acoustic_source" or "port_source" => "source_port", + "branch" or "acoustic_branch" => "branch", + "radiation_port" or "radiation" or "acoustic_radiation" => "radiation_port", + "wave_clock" or "waveclock" or "clock" => "wave_clock", + "acoustic_network" or "port_network" or "network" => "acoustic_network", "v" or "voice" => "voice", "tract" or "vt" or "tractvoice" or "tract_voice" => "tract", "opgraph" or "ops" or "operators" => "opgraph", @@ -1763,6 +2165,53 @@ public static class PatchScript _ => throw new PatchScriptException(line, $"unknown tract propagation mode `{value}`") }; + private static AcousticSourceKind ParseAcousticSourceKind(string value, int line) => value.ToLowerInvariant() switch + { + "glottal" or "glottis" or "larynx" => AcousticSourceKind.Glottal, + "labial" or "labia" or "syrinx" => AcousticSourceKind.Labial, + "reed" => AcousticSourceKind.Reed, + "turbulence" or "turbulence_jet" or "jet" or "frication" => AcousticSourceKind.TurbulenceJet, + "click" => AcousticSourceKind.Click, + "synthetic" or "synth" or "alien" => AcousticSourceKind.Synthetic, + _ => throw new PatchScriptException(line, $"unknown acoustic source kind `{value}`") + }; + + private static AcousticBranchKind ParseAcousticBranchKind(string value, int line) => value.ToLowerInvariant() switch + { + "side" or "side_branch" => AcousticBranchKind.SideBranch, + "nasal" or "nose" => AcousticBranchKind.Nasal, + "bronchial" or "bronchus" => AcousticBranchKind.Bronchial, + "lateral" => AcousticBranchKind.Lateral, + "resonator" => AcousticBranchKind.Resonator, + _ => throw new PatchScriptException(line, $"unknown acoustic branch kind `{value}`") + }; + + private static AcousticRadiationKind ParseAcousticRadiationKind(string value, int line) => value.ToLowerInvariant() switch + { + "lip" or "mouth" => AcousticRadiationKind.Lip, + "nostril" or "nose" => AcousticRadiationKind.Nostril, + "beak" => AcousticRadiationKind.Beak, + "vent" => AcousticRadiationKind.Vent, + "membrane" => AcousticRadiationKind.Membrane, + _ => throw new PatchScriptException(line, $"unknown acoustic radiation kind `{value}`") + }; + + private static WaveClockDelayStrategy ParseWaveClockDelayStrategy(string value, int line) => value.ToLowerInvariant() switch + { + "unit" or "unit_grid" or "grid" => WaveClockDelayStrategy.UnitGrid, + "half" or "half_sample" or "half_sample_grid" => WaveClockDelayStrategy.HalfSampleGrid, + "linear" or "fractional_linear" => WaveClockDelayStrategy.FractionalLinear, + "lagrange" or "fractional_lagrange" => WaveClockDelayStrategy.FractionalLagrange, + "thiran" or "allpass" or "fractional_thiran" => WaveClockDelayStrategy.FractionalThiran, + "crossfade" or "crossfaded" or "variable" or "crossfaded_variable" => WaveClockDelayStrategy.CrossfadedVariable, + _ => throw new PatchScriptException(line, $"unknown wave clock strategy `{value}`") + }; + + private static IReadOnlyList ParseNameList(string value) => + string.IsNullOrWhiteSpace(value) + ? Array.Empty() + : value.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + private static string Required(IReadOnlyDictionary fields, string key, int line) => fields.TryGetValue(key, out var value) ? value : throw new PatchScriptException(line, $"missing `{key}`"); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 5c990d1..d13199c 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -145,3 +145,4 @@ {"timestamp":"2026-05-26T11:03:00+01:00","topic":"physical-voice-modeling-research","claim":"The next voice architecture should be an acoustic port network, not a Pink Trombone module: continuous morphology owns paths/area curves, source ports model larynx/syrinx/reed/noise exciters, branch and radiation ports own topology, and wave-clock policies choose unit/half-sample/fractional-delay lowering. Faust `physmodels.lib` and `delays.lib` provide relevant primitives (`pm.chain`, `pm.l2s`, `pm.waveguideFd*`, `de.fdelay*`, Lagrange, Thiran/allpass), but AquaSynth should generate custom scattering where live area controls and inspectable differentiable parameters matter.","evidence":"Added docs/physical-voice-modeling-research.md after checking Faust 2.85.5 local libraries plus primary literature on half-sample/fractional-delay vocal-tract waveguides, waveguide tract acoustics, and differentiable articulatory/source-filter synthesis."} {"timestamp":"2026-05-26T14:50:00+01:00","topic":"physical-voice-research-packet","claim":"Physical voice modeling research is now persisted as a local packet under `research/physical-voice-modeling/`, with a distilled summary, source manifest, hashes, local Faust library captures, an open waveguide vocal-tract PDF, and downloaded HTML snapshots for fractional-delay vocal-tract and DDSP review sources.","evidence":"Added `research/physical-voice-modeling/README.md`, `SUMMARY.md`, `SOURCES.md`, and source files under `research/physical-voice-modeling/sources/`; updated docs and spine to point at the packet."} {"timestamp":"2026-05-26T15:30:00+01:00","topic":"physical-voice-practical-researchers","claim":"The practical physical voice modeling lineage points to reusable Aqua semantics: Birkholz/VocalTractLab for multi-level gestures and articulatory controls, Story/TubeTalker for continuous area functions and tract-length/coupling parameters, Smith for bidirectional delay-line scattering and fractional-delay waveguides, and Fels/ArtiSynth for separating biomechanics, acoustics, timeline control, and diagnostics. These are architecture pressures, not modules to clone.","evidence":"Added `research/physical-voice-modeling/PEOPLE.md`, `talks/TALKS.md`, downloaded VTL, Praat, Gnuspeech, SndKit, Story/Birkholz/Fels paper sources, captured talk pages, and saved public YouTube transcripts for Julius Smith CIRMMT and Brad Story NCVS."} +{"timestamp":"2026-05-26T16:25:00+01:00","topic":"physical-voice-acoustic-port-model","claim":"AquaSynth now has first-cut neutral acoustic voice records and parser commands for paths, source ports, branches, radiation ports, wave clocks, and acoustic port networks. PT-shaped tract commands populate those records as compatibility aliases, while current Faust audio still renders through `Voice.Tract`. This creates the intended migration path: move lowering authority toward acoustic networks without forking a syrinx/bird/PT mode.","evidence":"Added `AcousticPath`, `AcousticSourcePort`, `AcousticBranch`, `AcousticRadiationPort`, `WaveClockPolicy`, `AcousticPortNetwork`; parser commands `path`, `source_port`, `branch`, `radiation_port`, `wave_clock`, `acoustic_network`; focused tests `ParserSupportsReusableAcousticPortNetworkPrimitives`, `ParserSupportsPinkTromboneStyleTractVoice`, and `WaveguideTractDefaultsToAcousticUnitDelayGrid` passed."} diff --git a/state/spine.yaml b/state/spine.yaml index ab014ef..8ba08b1 100644 --- a/state/spine.yaml +++ b/state/spine.yaml @@ -1,6 +1,6 @@ project: AquaSynth spine_version: 1 -updated: 2026-05-26T15:30:00+01:00 +updated: 2026-05-26T16:25:00+01:00 prime_directive: > Build coherent synth machinery. References exist to reveal missing structure, @@ -116,6 +116,7 @@ live_invariants: - Pink Trombone parity is structural waveguide pressure, not permission to add more formant proxy knobs. AquaSynth now has a `tract` DSL command that lowers into `Voice.Tract` with PT-shaped runtime controls and a Faust tract-voice proxy; it is still an ordinary voice treatment, not a separate graph owner and not an exact 44-cell/28-cell bidirectional waveguide. - Physical voice modeling should generalize around continuous acoustic morphologies, acoustic port networks, source ports, branch/radiation ports, and wave-clock policies. A larynx, syrinx, or alien voice should differ by topology and source-port configuration, not by special-case modules. Faust `physmodels.lib`/`delays.lib` provide useful primitives (`pm.chain`, `pm.l2s`, `pm.waveguideFd*`, `de.fdelay*`, Thiran/allpass and Lagrange delays), but AquaSynth should still generate tract/branch scattering where live area controls and inspectable training parameters matter. - The physical voice research packet now includes a practical implementation/researcher map (`research/physical-voice-modeling/PEOPLE.md`) and talk/transcript ledger (`research/physical-voice-modeling/talks/TALKS.md`). Birkholz/VocalTractLab pressures multi-level articulatory control and gestures; Story/TubeTalker pressures continuous parametric area functions and length/coupling; Smith pressures bidirectional delay-line scattering and fractional-delay waveguides; Fels/ArtiSynth pressures separation between biomechanics, acoustics, timeline controls, and diagnostics. These are reusable DSL semantics, not modules to clone. + - Physical voice implementation has started moving PT pressure into neutral acoustic owners: `AcousticPath`, `AcousticSourcePort`, `AcousticBranch`, `AcousticRadiationPort`, `WaveClockPolicy`, and `AcousticPortNetwork`. Parser commands `path`, `source_port`, `branch`, `radiation_port`, `wave_clock`, and `acoustic_network` now exist. Existing `tract_shape`, `glottis`, `tract_injection`, `nasal_branch`, and `tract` commands populate acoustic records as compatibility aliases while the current `Voice.Tract` Faust renderer still owns audio. - PT expressive parity should decompose into reusable Aqua primitives before audio golf: `tract_shape` owns continuous diameter/area geometry over normalized position, physical length (`length_cm`), interpolation/resampling, derived reflection coefficients, and per-cell acoustic delay; `tract` may resample that geometry to a chosen compiled `sections` grid without making authoring sample count anatomy; `glottis` owns excitation controls; `tract_injection` owns positioned frication/burst controls and now distributes frication pressure into waveguide section updates; `nasal_branch` owns a second diameter/area tube; `tract_motion` owns control slew and obstruction threshold; `propagation=waveguide` lowers tract voices into a Faust-friendly `wg_loop ~ si.bus(...)` feedback component with compiled right/left traveling-wave state, live per-section diameter/area/reflection fields, obstruction-history burst pressure, and legacy substep clock intent. Waveguide tracts now default to an acoustic unit-delay grid from physical length at the current 44.1 kHz target, so a 17 cm oral tract emits about 22 sections instead of treating PT's 44 half-sample cells as anatomy; `VocalTract.IndexScale` maps runtime PT-index controls onto that emitted grid. PT's 44 oral and 28 nasal cells are reference discretization, not Aqua morphology authority. `PinkTromboneParityFixtures` defines fixed Aqua DSL workouts, `PinkTromboneReferenceRenderer` renders deterministic PT-style fixture references, and `AudioComparison` includes log-mel cosine similarity. Current waveguide baseline is weak but measured: cosine about 0.61 open vowel, 0.63 front vowel, 0.54 nasal, 0.37 sibilant, and -0.08 closure-release. Remaining low-level gap is fractional-delay waveguide lowering whose clock derives from physical length, propagation speed, and sample rate so runtime morphology motion does not require recompilation; closure/release timing is still badly wrong. - If dotnet builds hang in this workspace, stop orphan dotnet workers and retry with `--disable-build-servers -p:UseSharedCompilation=false -p:BuildInParallel=false`; plain parallel/shared builds can stall without useful diagnostics. - eSpeak NG is an early parity reference for timing, IPA coverage, and log-mel pressure, not an anatomy oracle or final target. diff --git a/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs b/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs index ece7956..3d44ae9 100644 --- a/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs +++ b/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs @@ -127,6 +127,14 @@ public sealed class PatchScriptTests Assert.Equal(TractPropagationMode.Waveguide, voice.Tract.Propagation); Assert.Equal(.998f, voice.Tract.WaveguideLoss, 5); Assert.Equal(2, voice.Tract.Substeps); + Assert.NotNull(voice.AcousticNetwork); + Assert.NotNull(voice.Tract.AcousticNetwork); + Assert.Contains(patch.AcousticPaths, path => path.Name == "voices_0_oral"); + Assert.Contains(patch.AcousticSourcePorts, port => port.Name == "voices_0_modal" && port.Kind == AcousticSourceKind.Glottal); + Assert.Contains(patch.AcousticSourcePorts, port => port.Name == "voices_0_sibilant" && port.Kind == AcousticSourceKind.TurbulenceJet); + Assert.Contains(patch.AcousticBranches, branch => branch.Name == "voices_0_nose" && branch.Kind == AcousticBranchKind.Nasal); + Assert.Contains(patch.AcousticRadiationPorts, port => port.Name == "voices_0_lip" && port.Kind == AcousticRadiationKind.Lip); + Assert.Contains(patch.WaveClocks, clock => clock.Name == "voices_0_clock" && clock.Strategy == WaveClockDelayStrategy.UnitGrid); Assert.Contains(patch.ParameterBindings, binding => binding.FieldPath == "/glottis/0/tenseness"); var faust = FaustEmitter.Emit(patch, new FaustExportOptions("tract_voice")).Source; @@ -152,6 +160,35 @@ public sealed class PatchScriptTests Assert.Contains("tract_oral_waveguide", faust); } + [Fact] + public void ParserSupportsReusableAcousticPortNetworkPrimitives() + { + var patch = PatchScript.Parse(""" + path name=trachea length_cm=12 diameters=.4,.7,1,1 + path name=oral length_cm=17 diameters=.6,1.1,1.6,1.2,.8 + source_port name=left_labium path=trachea kind=labial position=.1 pressure=.7 tension=.55 opening=.4 noise=.02 + source_port name=right_labium path=trachea kind=labial position=.1 pressure=.65 tension=.5 opening=.45 noise=.03 balance=.8 + branch name=throat from_path=trachea from_position=.9 to_path=oral kind=bronchial opening=.8 coupling=.7 + radiation_port name=mouth path=oral kind=lip position=1 opening=1.4 reflection=-.82 + wave_clock name=continuous strategy=thiran order=1 max_delay=4096 smoothing_ms=3 + acoustic_network name=syrinxish path=trachea wave_clock=continuous sources=left_labium,right_labium branches=throat radiation=mouth + v w=saw f=140 gain=.1 + """); + + var network = Assert.Single(patch.AcousticNetworks); + Assert.Equal("syrinxish", network.Name); + Assert.Equal("trachea", network.PrimaryPath); + Assert.Equal(["left_labium", "right_labium"], network.SourcePorts); + Assert.Equal(["throat"], network.Branches); + Assert.Equal(["mouth"], network.RadiationPorts); + + Assert.Equal(2, patch.AcousticPaths.Count); + Assert.All(patch.AcousticSourcePorts, port => Assert.Equal(AcousticSourceKind.Labial, port.Kind)); + Assert.Equal(AcousticBranchKind.Bronchial, Assert.Single(patch.AcousticBranches).Kind); + Assert.Equal(AcousticRadiationKind.Lip, Assert.Single(patch.AcousticRadiationPorts).Kind); + Assert.Equal(WaveClockDelayStrategy.FractionalThiran, Assert.Single(patch.WaveClocks).Strategy); + } + [Fact] public void TractAreaFunctionOwnsContinuousMorphology() {