diff --git a/docs/acoustic-graph-flow-audit.md b/docs/acoustic-graph-flow-audit.md index 7f2098a..b452601 100644 --- a/docs/acoustic-graph-flow-audit.md +++ b/docs/acoustic-graph-flow-audit.md @@ -110,9 +110,15 @@ and pressure events, not decorative source clicks. Current `AcousticSourcePort.Transient` can emit a short pressure-shaped pulse, but it is still a local source-port expression. It does not own upstream -pressure storage in the graph state. A post-commit reservoir experiment was -stable but inaudible because it lived outside the actual wave variables and did -not change the local boundary state. +pressure storage in the graph state. Graph source evaluation has started moving +into node context: each node now names incident pressure and a node-local source +sum, and generated tract injection source banks are placed at cell centers +rather than directly on graph/radiation nodes. That matches the waveguide-cell +mental model better than terminal-born clicks. + +This still is not full pressure storage. A first node-pressure-informed +turbulence release only moved metrics slightly, which says the release source is +now closer to the right layer but still lacks an actual upstream reservoir. Required cut: graph lowering needs a closure/reservoir primitive that can store pressure on one side of a severe constriction and release it through the diff --git a/src/AquaSynth.Core/FaustExport.cs b/src/AquaSynth.Core/FaustExport.cs index a6d5f4d..e04c313 100644 --- a/src/AquaSynth.Core/FaustExport.cs +++ b/src/AquaSynth.Core/FaustExport.cs @@ -687,6 +687,15 @@ public static class FaustEmitter source.AppendLine($" {name}_graph_in_{segment.Index}_start = l{segment.Index};"); source.AppendLine($" {name}_graph_in_{segment.Index}_end = r{segment.Index};"); } + foreach (var node in graphNodes) + { + var ports = incident[node.Name]; + var incidentPressure = ports.Count == 0 + ? "0.0" + : $"({string.Join(" + ", ports.Select(port => GraphIncoming(name, port)))}) / {F(ports.Count)}"; + source.AppendLine($" {name}_graph_node_incident_pressure_{node.Name} = {incidentPressure};"); + source.AppendLine($" {NodeSourceIdentifier(name, node)} = {NodeSourceExpression(patch, name, node, sources, frequency, parameters)};"); + } var connectionGroups = network.Connections .Select(connectionName => connections.TryGetValue(connectionName, out var connection) ? connection : null) @@ -710,7 +719,7 @@ public static class FaustEmitter } var safeConnection = SafeIdentifier(connection.Name); - if (TryEmitThreePortBranchScatter(source, name, connection, safeConnection, ports, sources)) + if (TryEmitThreePortBranchScatter(source, name, connection, safeConnection, ports)) { continue; } @@ -722,7 +731,7 @@ public static class FaustEmitter { var incoming = GraphIncoming(name, port); var outgoing = GraphOutgoing(name, port); - var sourceInjection = NodeSourceExpression(name, node, sources); + var sourceInjection = NodeSourceIdentifier(name, node); var portCoupling = $"{name}_graph_connection_coupling_{safeConnection}"; var portArea = ConnectionPortAreaExpression(name, terminal, nodePortCount); var portAdmittance = $"(0.6 + 0.4 * sqrt(clip01({portArea} / max(0.000001, {connectionMaxArea}))))"; @@ -749,7 +758,7 @@ public static class FaustEmitter continue; } - var sourceInjection = NodeSourceExpression(name, node, sources); + var sourceInjection = NodeSourceIdentifier(name, node); var reflection = $"{name}_graph_node_reflection_{node.Name}"; if (TryEmitTwoPortPathScatter(source, name, node, ports, sourceInjection)) { @@ -846,7 +855,8 @@ public static class FaustEmitter SynthPatch patch, AcousticSourcePort port, string frequency, - ParameterMap parameters) + ParameterMap parameters, + string? localPressure = null) { var index = AcousticSourcePortIndex(patch, port); var path = $"/acoustic/sources/{index}"; @@ -860,6 +870,9 @@ public static class FaustEmitter var phase = $"os.phasor(1.0, {frequency}{detune})"; var closure = $"clip01((0.12 - ({opening})) / 0.12)"; var release = $"(max(0.0, (({closure}) : mem) - ({closure})) : + ~ *(0.995))"; + var releasePressure = localPressure is null + ? "1.0" + : $"(0.20 + 2.80 * clip01((abs({localPressure}) * ({closure})) : + ~ *(0.992)))"; return port.Kind switch { AcousticSourceKind.Glottal => @@ -869,7 +882,7 @@ public static class FaustEmitter AcousticSourceKind.Reed => $"(ma.tanh(sin(2.0 * ma.PI * {phase}) * (1.0 + {pressure} * 8.0)) * {opening} + no.noise * {noise} * 0.2) * {balance}", AcousticSourceKind.TurbulenceJet => - $"((no.noise : fi.highpass(2, 900.0 + 2600.0 * clip01(1.0 - {opening}))) * {noise} * {pressure} * min(clip01((0.8 - {opening}) / 0.8), clip01(8.0 * (0.7 - {opening})) * clip01(30.0 * ({opening} - 0.3))) * 0.62 + {transient} * {pressure} * {release} * 0.58 * (0.8 + 0.8 * clip01({opening} / 0.8))) * {balance}", + $"((no.noise : fi.highpass(2, 900.0 + 2600.0 * clip01(1.0 - {opening}))) * {noise} * {pressure} * min(clip01((0.8 - {opening}) / 0.8), clip01(8.0 * (0.7 - {opening})) * clip01(30.0 * ({opening} - 0.3))) * 0.62 + {transient} * {pressure} * {release} * {releasePressure} * 0.58 * (0.8 + 0.8 * clip01({opening} / 0.8))) * {balance}", AcousticSourceKind.Click => $"no.noise * {pressure} * max({opening}, {transient}) * exp(0.0 - age * 120.0) * {balance}", AcousticSourceKind.Synthetic => @@ -1604,8 +1617,7 @@ public static class FaustEmitter string voiceName, AcousticConnection connection, string safeConnection, - IReadOnlyList<(AcousticGraphNode node, AcousticTerminal terminal, AcousticGraphPort port, int nodePortCount)> ports, - IReadOnlyDictionary sources) + IReadOnlyList<(AcousticGraphNode node, AcousticTerminal terminal, AcousticGraphPort port, int nodePortCount)> ports) { if (ports.Count != 3 || connection.Law != AcousticConnectionLaw.AreaScattering) { @@ -1646,7 +1658,7 @@ public static class FaustEmitter { var incoming = GraphIncoming(voiceName, item.port); var outgoing = GraphOutgoing(voiceName, item.port); - var sourceInjection = NodeSourceExpression(voiceName, item.node, sources); + var sourceInjection = NodeSourceIdentifier(voiceName, item.node); source.AppendLine($" {outgoing} = ({voiceName}_graph_connection_pressure_{safeConnection} - {incoming} + ({sourceInjection}) / {F(Math.Max(1, item.nodePortCount))}) * {voiceName}_graph_connection_loss_{safeConnection};"); } source.AppendLine($" {voiceName}_graph_connection_energy_in_{safeConnection} = {string.Join(" + ", portItems.Select(item => $"({areaExpressions[item.port]}) * pow({GraphIncoming(voiceName, item.port)}, 2.0)"))};"); @@ -1702,14 +1714,27 @@ public static class FaustEmitter return expression; } + private static string NodeSourceIdentifier(string voiceName, AcousticGraphNode node) => + $"{voiceName}_graph_node_source_{node.Name}"; + private static string NodeSourceExpression( + SynthPatch patch, string voiceName, AcousticGraphNode node, - IReadOnlyDictionary sources) + IReadOnlyDictionary sources, + string frequency, + ParameterMap parameters) { var sourceTerms = node.Terminals .Where(terminal => terminal.Kind == AcousticTerminalKind.Source && sources.ContainsKey(terminal.Port.Length == 0 ? terminal.Name : terminal.Port)) - .Select(terminal => $"{voiceName}_graph_source_{SafeIdentifier(terminal.Port.Length == 0 ? terminal.Name : terminal.Port)}") + .Select(terminal => + { + var sourceName = terminal.Port.Length == 0 ? terminal.Name : terminal.Port; + var port = sources[sourceName]; + return port.Kind == AcousticSourceKind.TurbulenceJet + ? AcousticSourceExpression(patch, port, frequency, parameters, $"{voiceName}_graph_node_incident_pressure_{node.Name}") + : $"{voiceName}_graph_source_{SafeIdentifier(sourceName)}"; + }) .ToList(); return sourceTerms.Count == 0 ? "0.0" : string.Join(" + ", sourceTerms); } diff --git a/src/AquaSynth.Core/PatchScript.cs b/src/AquaSynth.Core/PatchScript.cs index 2296e6a..665860e 100644 --- a/src/AquaSynth.Core/PatchScript.cs +++ b/src/AquaSynth.Core/PatchScript.cs @@ -1368,12 +1368,12 @@ public static class PatchScript if (tract.Propagation == TractPropagationMode.Graph) { var sourceWidth = Math.Max(0.25f, injection.Width); - var sourceIndexScale = tract.IndexScale / Math.Max(1, tract.Sections - 1); - for (var section = 2; section < tract.Sections; section++) + var sourceIndexScale = tract.IndexScale / Math.Max(1, tract.Sections); + for (var section = 1; section < tract.Sections; section++) { AddTractInjectionSource( $"{injectionName}_{section}", - section / (float)Math.Max(1, tract.Sections - 1), + (section + 0.5f) / Math.Max(1, tract.Sections), new AcousticSourcePositionControl(tract.ConstrictionIndex, sourceWidth, sourceIndexScale)); } } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 104cc80..dc34c41 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -182,3 +182,4 @@ {"evidence":"Added `ParameterBindingTransform.Square` with scalar binding scale, used generated tract graph lowering to map live velum diameter into nasal side-port terminal area_scale, and stopped mirroring velum to nostril opening or lip opening to terminal area_scale. Focused structural tests and PT graph parity passed. Latest static artifact artifacts/parity/pink-trombone-logmel/20260527T170220540: open/front/nasal/ma/sibilant/closure cosine 0.6157/0.6879/0.6338/0.6089/0.4868/0.6525. Latest utterance artifact artifacts/parity/pink-trombone-utterance-logmel/20260527T170253143: mama/papa/thrombosis cosine 0.7232/0.7947/0.5651, rmsRatio 4.8301/5.0214/5.4566, articulation 0.1668/0.1560/0.1289.","claim":"Live graph controls must preserve physical dimensions at field ownership sites. Velum is a diameter/control gesture that becomes branch admittance through area, while radiation aperture and lip path area are separate owners. The current audio is still over-radiated and poorly articulated, but reverting to raw mirrored controls would reintroduce sample-flow mangling.","timestamp":"2026-05-27T17:05:00+01:00","topic":"acoustic-graph-transformed-bindings"} {"evidence":"Graph radiation now emits named per-terminal radiation flow/admittance signals and weights boundary flow by bounded local terminal admittance instead of a fixed 4x output scalar plus kind gain. Focused structural and PT parity tests passed. Latest static artifact artifacts/parity/pink-trombone-logmel/20260527T170548495: open/front/nasal/ma/sibilant/closure cosine 0.6675/0.7216/0.7251/0.7098/0.4862/0.6513, rmsRatio 0.2590/0.4287/0.3704/0.4017/0.3957/0.5635. Latest utterance artifact artifacts/parity/pink-trombone-utterance-logmel/20260527T170618466: mama/papa/thrombosis cosine 0.7428/0.7830/0.5442, rmsRatio 2.7955/2.4594/2.7397, articulation 0.1288/0.1226/0.1151.","claim":"Radiation is now less of a global loudness patch and more of a local boundary-flow witness. This reduces over-radiation after the side-port fix, but the speech still fails on articulation, so the next coherent work is passive multi-port scattering plus pressure storage/release rather than more output coloring.","timestamp":"2026-05-27T17:10:00+01:00","topic":"acoustic-graph-radiation-admittance"} {"evidence":"Added generated Faust `graph_connection_energy_in_*` and `graph_connection_energy_out_*` probes for the named three-port branch scatter and fenced them with structural tests. Focused structural tests passed.","claim":"Passivity must be inspected where samples are scattered, not inferred from output loudness. The next branch-law pass can now compare local incoming/outgoing area-weighted wave energy before changing more audio behavior.","timestamp":"2026-05-27T17:14:00+01:00","topic":"acoustic-graph-branch-energy-probes"} +{"evidence":"Moved graph source evaluation into recursive node context by emitting per-node incident pressure and node-local source sums, and moved generated tract injection source banks from graph nodes to cell centers with `1 / sections` index scaling. Focused structural and PT parity tests passed. Latest utterance artifact artifacts/parity/pink-trombone-utterance-logmel/20260527T172949293: mama/papa/thrombosis cosine 0.6654/0.7746/0.5522, rmsRatio 3.0010/2.5712/2.4943, articulation 0.1444/0.1177/0.1193. Latest static artifact artifacts/parity/pink-trombone-logmel/20260527T172843945: closure-release rmsRatio 1.0078, cosine 0.6505.","claim":"Moving turbulence/release sources into graph node context and cell-centered geometry is architecturally correct even though papa articulation still worsens. PT-class source injection is cell-local wave excitation, not a click born on the radiation terminal; the remaining plosive failure points to missing upstream pressure storage rather than source placement.","timestamp":"2026-05-27T17:32:00+01:00","topic":"acoustic-graph-cell-centered-sources"} diff --git a/state/spine.yaml b/state/spine.yaml index ae1094f..44d2031 100644 --- a/state/spine.yaml +++ b/state/spine.yaml @@ -1,6 +1,6 @@ project: AquaSynth spine_version: 1 -updated: 2026-05-27T17:14:00+01:00 +updated: 2026-05-27T17:32:00+01:00 prime_directive: > Build coherent synth machinery. References exist to reveal missing structure, @@ -121,6 +121,7 @@ live_invariants: - `acoustic` / `acoustic_voice` can now render an `AcousticPortNetwork` through a compact Faust response proxy or, when typed terminals are present, a compiled bidirectional Faust segment graph. Graph lowering splits paths at terminal positions, aggregates co-located terminals into graph nodes, orders connection ports deterministically, scatters area-weighted/pressure/bypass connection groups, injects source terminals even at connected nodes, and sums radiation terminals. Segment delay follows physical segment length and the network `wave_clock` strategy through unit-grid, half-sample, linear fractional, Lagrange, or Thiran/allpass Faust delay primitives. Source, branch, radiation, terminal, and connection controls can bind through ordinary Aqua parameters into emitted Faust. PT-shaped `tract` authoring now routes accepted parity through `propagation=graph`; the old waveguide parity lane is not a comparison baseline or historical pressure lane. - Pink Trombone log-mel parity now writes graph candidates only. Generated tract graphs mirror live `/pink/...` tract bindings into acoustic source, terminal, radiation, and path-area fields. Graph generation stopped baking first-frame tongue/constriction/lip morphology into the path; `AcousticPath.AreaControl` now turns tongue/constriction/lip controls into live area expressions at graph sample points. Velum owns nasal branch entrance diameter, which lowers through a squared parameter-binding transform into side-port admittance; generated nasal connections keep full connection coupling, and the nasal terminal carries the side-port admittance limit. The first nasal tube sample is no longer allowed to decide the velum opening. Lip opening owns path area and radiation aperture, not terminal area scaling. Graph radiation now uses aperture as a boundary impedance owner: lip/beak opening blends boundary reflection from near-closed termination to declared open-end reflection, names per-port boundary flow (`incoming - outgoing`), and weights output by bounded local terminal admittance rather than a fixed 4x output scalar. Latest static graph evidence after radiation admittance normalization is under `artifacts/parity/pink-trombone-logmel/20260527T170548495`: open/front/nasal/ma/sibilant/closure cosine 0.6675/0.7216/0.7251/0.7098/0.4862/0.6513; latest utterance evidence under `artifacts/parity/pink-trombone-utterance-logmel/20260527T170618466`: mama/papa/thrombosis cosine 0.7428/0.7830/0.5442 with rmsRatio 2.7955/2.4594/2.7397 and articulation 0.1288/0.1226/0.1151. The output is less absurdly loud, but articulation and speech-band motion are still the live failure. - `docs/acoustic-graph-flow-audit.md` compares Aqua's graph to Birkholz/VTL, Story/TubeTalker, Smith waveguides, ArtiSynth, and PT/SndKit. The graph records can name the research-backed architecture, but current Faust lowering still mangles multi-port branch sample flow. The kept physical fix moves nasal coupling from global connection damping into transformed side-port admittance and emits a named three-port branch scatter for two same-path ports plus one side branch. Radiation now has named flow/admittance probes and local terminal-admittance weighting, reducing over-radiation without restoring the old damper. The three-port branch law also emits `graph_connection_energy_in_*` and `graph_connection_energy_out_*` probes so passivity can be inspected at the actual scatter site. Do not revert that ownership fix just because the next broken subsystem screams; next cut is passive/admittance-normalized three-port scattering plus graph-native pressure storage/release. + - Graph source lowering now names per-node incident pressure and node-local source sums inside the recursive graph loop. Generated tract injection source banks now use cell-centered positions and `1 / sections` index scaling, so turbulence/release energy is born inside tube cells rather than directly on graph/radiation nodes. Latest source-position artifact under `artifacts/parity/pink-trombone-utterance-logmel/20260527T172949293`: mama/papa/thrombosis cosine 0.6654/0.7746/0.5522, rmsRatio 3.0010/2.5712/2.4943, articulation 0.1444/0.1177/0.1193. Static closure-release RMS improved to 1.0078 under `artifacts/parity/pink-trombone-logmel/20260527T172843945`, but papa articulation worsened; keep the cell-centered source placement because it is the correct graph-level source geometry, not because metrics liked it. - 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; `AcousticAreaControl` owns live sampled morphology controls on a path; `WaveClockPolicy` owns the legal delay floor instead of forcing every segment to one sample; generated graph tracts now use `HalfSampleGrid` to match the PT/Kelly-Lochbaum half-sample regime; ordinary same-path graph interiors now own signed two-port area-discontinuity scattering; `glottis` owns excitation controls with mild harmonic waveshaping and a small higher-harmonic brightness term for graph sources; `tract_injection` owns positioned frication/burst controls; `AcousticSourcePort.Transient` owns graph-native release/click energy as a pressure pulse rather than filtered noise; sustained `TurbulenceJet` lowering owns a narrow-open aperture gate so closed constrictions no longer hiss; `AcousticSourcePositionControl` owns differentiable runtime weights over fixed source terminals so moving articulators can move source energy without recompiling the graph; `AcousticRadiationPort` owns aperture-dependent boundary reflection, flow radiation, and current post-flow normalization; `nasal_branch` owns a second diameter/area tube and branch aperture while `AcousticConnection.Coupling` owns structural max admittance; `tract_motion` owns control slew and obstruction threshold; `AcousticPortNetwork` owns graph lowering. `PinkTromboneReferenceRenderer` ports the pinned MIT `chdh/pink-trombone-mod` DSP source (`external/pink-trombone-mod` at 359c2d3b42b10280404c1650dc601902112b4c90), and reference WAVs before `artifacts/parity/pink-trombone-utterances/20260526T211902375` are invalid. The accepted PT utterance curriculum is mama, papa, and thrombosis; lulek was cut because its control sketch taught a bad artifact. Latest graph-only utterance smoke under `artifacts/parity/pink-trombone-utterance-logmel/20260527T150836912`: mama/papa/thrombosis remain `not-accepted-articulation` with cosine 0.8337/0.8893/0.5317 and articulation scores 0.2118/0.1890/0.2594. `AudioComparison.Articulation` reports envelope cosine, active-frame ratio, silence mismatch, envelope/spectral flux ratios, motor-band ratio, speech-band ratio, and an articulation score so log-mel cannot forge a listening receipt. A direct LF coefficient source was tested and cut because it overdrove the graph and broke static open vowel; a broader harmonic-tail source was tested and cut because it worsened voiced-band behavior. A naive midpoint admittance scatter was tested and cut because it collapsed `mama`; the kept area-discontinuity scatter needed the opposite reflection sign for this graph state convention, and re-testing the literal SndKit sign after the clock fix made `thrombosis` loud/unstable. A long noisy release transient was tested and cut because it turned papa into motor-band energy; deterministic pressure release with PT-scale decay is structurally kept but still not sufficient. Next pressure is true graph pressure storage/release at severe closures; output coloring alone is not allowed to impersonate articulation. - 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 151cde0..88d6c68 100644 --- a/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs +++ b/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs @@ -322,11 +322,37 @@ public sealed class PatchScriptTests Assert.Contains("graph_connection_pressure_voices_0_nose_connection", export.Source); Assert.Contains("graph_connection_energy_in_voices_0_nose_connection", export.Source); Assert.Contains("graph_connection_energy_out_voices_0_nose_connection", export.Source); + Assert.Contains("graph_node_incident_pressure_", export.Source); + Assert.Contains("graph_node_source_", export.Source); Assert.Contains("graph_radiation_admittance_voices_0_lip", export.Source); Assert.Contains("graph_radiation_flow_voices_0_lip", export.Source); Assert.Contains("patch_param_0) * (patch_param_0", export.Source); } + [Fact] + public void GeneratedGraphInjectionSourcesOccupyCellCenters() + { + var patch = PatchScript.Parse(""" + tract_shape name=human length_cm=17 diameters=.6,.8,1.2,1.5,1.2,.8 + tract_injection name=inj position=5 width=1 turbulence=.5 burst=.8 + tract shape=human injection=inj propagation=graph sections=6 constriction_index=5 + """); + + var injectionSources = patch.AcousticSourcePorts + .Where(port => port.Kind == AcousticSourceKind.TurbulenceJet) + .OrderBy(port => port.Position) + .ToArray(); + + Assert.Equal(5, injectionSources.Length); + Assert.Equal(0.25f, injectionSources[0].Position, 3); + Assert.Equal(0.9167f, injectionSources[^1].Position, 3); + Assert.All(injectionSources, source => + { + Assert.NotNull(source.PositionControl); + Assert.Equal(1f / 6f, source.PositionControl!.IndexScale, 4); + }); + } + [Fact] public void TractAreaFunctionOwnsContinuousMorphology() {