Compare graph tract parity fixtures

This commit is contained in:
Meta Vens 2026-05-26 19:23:14 +01:00
commit c8086f7c74
8 changed files with 85 additions and 14 deletions

View file

@ -653,6 +653,7 @@ public static class FaustEmitter
source.AppendLine($"{name}_graph_connection_coupling_{SafeIdentifier(connection.Name)} = clip01({parameters.Expression(OwnerField(connectionPath, "coupling"), connection.Coupling)});");
source.AppendLine($"{name}_graph_connection_loss_{SafeIdentifier(connection.Name)} = clip01({parameters.Expression(OwnerField(connectionPath, "loss"), connection.Loss)});");
}
source.AppendLine($"{name}_graph_radiation_gain = 24.0;");
foreach (var sourceName in network.SourcePorts)
{
@ -759,7 +760,7 @@ public static class FaustEmitter
}
nextStates.AddRange(segments.Select(segment => $"{name}_graph_next_l{segment.Index}"));
source.Replace(string.Join(", ", NextStatesPlaceholder(stateCount)), string.Join(", ", nextStates));
source.AppendLine($" {name}_graph_out = {(radiated.Count == 0 ? "0.0" : string.Join(" + ", radiated))};");
source.AppendLine($" {name}_graph_out = ({(radiated.Count == 0 ? "0.0" : string.Join(" + ", radiated))}) * {name}_graph_radiation_gain;");
source.AppendLine(" };");
source.AppendLine("};");
source.AppendLine($"{name}_acoustic_graph_radiated = {name}_graph({name}_graph_drive);");

View file

@ -1215,7 +1215,10 @@ public static class PatchScript
{
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);
var baseOralArea = tract.AreaFunction ?? new TractAreaFunction([0.6f, 0.8f, 1.2f, 1.5f, 1.5f, 1.2f, 0.8f, 0.6f], 17);
var oralArea = tract.Propagation == TractPropagationMode.Graph
? TractGraphAreaFunction(tract, baseOralArea)
: baseOralArea;
AddAcousticPathRecord(new AcousticPath(primaryPathName, oralArea, 343, tract.WaveguideLoss));
var sourceNames = new List<string>();
@ -1233,7 +1236,14 @@ public static class PatchScript
tract.Glottis?.Skew ?? 0.42f,
tract.Glottis?.Aspiration ?? 0.08f);
AddAcousticSourcePortRecord(source);
AddAcousticTerminalRecord(new AcousticTerminal(source.Name, source.Path, source.Position, AcousticTerminalKind.Source, source.Name));
AddAcousticTerminalRecord(new AcousticTerminal(
source.Name,
source.Path,
source.Position,
AcousticTerminalKind.Source,
source.Name,
1,
tract.GlottalReflection));
sourceNames.Add(sourceName);
if (tract.Injection is { } injection)
@ -1352,6 +1362,33 @@ public static class PatchScript
private static float NormalizeTractIndex(float index, int sections) =>
sections <= 0 ? 0 : Math.Clamp(index / Math.Max(1, sections - 1), 0, 1);
private static TractAreaFunction TractGraphAreaFunction(VocalTract tract, TractAreaFunction areaFunction)
{
var sections = areaFunction.Sections;
var diameters = new float[sections];
for (var i = 0; i < sections; i++)
{
var diameter = areaFunction.Diameters[i];
if (i == sections - 1)
{
diameter = tract.LipOpening;
}
else
{
var tongueWidth = Math.Max(1, sections * 0.18f);
var tongueWeight = MathF.Exp(0 - MathF.Pow((i - tract.TongueIndex) / tongueWidth, 2));
diameter += (tract.TongueDiameter - diameter) * tongueWeight;
}
var constrictionWidth = Math.Max(1, sections * 0.09f);
var constrictionWeight = MathF.Exp(0 - MathF.Pow((i - tract.ConstrictionIndex) / constrictionWidth, 2));
diameter = Math.Min(diameter, tract.ConstrictionDiameter + Math.Max(0, diameter - tract.ConstrictionDiameter) * (1 - constrictionWeight));
diameters[i] = Math.Max(0, diameter);
}
return new TractAreaFunction(diameters, areaFunction.LengthCentimeters);
}
private void AddModBus(IReadOnlyDictionary<string, string> fields, int line)
{
var name = GetAny(fields, ["name", "n"], "mod");

View file

@ -5,6 +5,7 @@ public sealed record PinkTromboneParityFixture(
string Description,
PinkTromboneFixtureControls Controls,
string AquaScript,
string GraphAquaScript,
IReadOnlyList<string> ReferenceFeatures);
public sealed record PinkTromboneFixtureControls(
@ -98,9 +99,9 @@ public static class PinkTromboneParityFixtures
string description,
PinkTromboneFixtureControls controls,
IReadOnlyList<string> referenceFeatures) =>
new(id, description, controls, Script(controls), referenceFeatures);
new(id, description, controls, Script(controls, "waveguide"), Script(controls, "graph"), referenceFeatures);
private static string Script(PinkTromboneFixtureControls controls) =>
private static string Script(PinkTromboneFixtureControls controls, string propagation) =>
$$"""
patch gain=0.82 soft_clip=true
@ -113,7 +114,7 @@ public static class PinkTromboneParityFixtures
nasal_branch name=nose junction=17 velum=.01 reflection=-.85 loss=.999 diameters=0.01,0.35,0.5,0.65,0.8,0.95,1.1,1.25,1.4,1.55,1.7,1.8,1.9,1.9,1.85,1.75,1.65,1.55,1.45,1.35,1.25,1.15,1.05,0.95,0.85,0.75,0.65,0.55
tract_motion name=motion diameter_slew=18 shape_return=8 constriction_slew=24 velum_slew=16 obstruction_threshold=.05
tract shape=human glottis=modal injection=inj nasal_branch=nose motion=motion propagation=waveguide waveguide_loss=.999 freq={{F(controls.Frequency)}} gain={{F(controls.Gain)}} sustain=.45 decay=.12 tongue_index={{F(controls.TongueIndex)}} tongue_diameter={{F(controls.TongueDiameter)}} constriction_index={{F(controls.ConstrictionIndex)}} constriction_diameter={{F(controls.ConstrictionDiameter)}} turbulence={{F(controls.Turbulence)}} velum={{F(controls.Velum)}} lip={{F(controls.LipOpening)}} burst={{F(controls.Burst)}} glottal_reflection={{F(controls.GlottalReflection)}} lip_reflection={{F(controls.LipReflection)}}
tract shape=human glottis=modal injection=inj nasal_branch=nose motion=motion propagation={{propagation}} waveguide_loss=.999 freq={{F(controls.Frequency)}} gain={{F(controls.Gain)}} sustain=.45 decay=.12 tongue_index={{F(controls.TongueIndex)}} tongue_diameter={{F(controls.TongueDiameter)}} constriction_index={{F(controls.ConstrictionIndex)}} constriction_diameter={{F(controls.ConstrictionDiameter)}} turbulence={{F(controls.Turbulence)}} velum={{F(controls.Velum)}} lip={{F(controls.LipOpening)}} burst={{F(controls.Burst)}} glottal_reflection={{F(controls.GlottalReflection)}} lip_reflection={{F(controls.LipReflection)}}
""";
private static string F(float value) =>