Expand graph vocal modeling DSL
This commit is contained in:
parent
aa779473c4
commit
12e5669ebc
11 changed files with 498 additions and 74 deletions
|
|
@ -788,9 +788,10 @@ public static class FaustEmitter
|
|||
var admittance = $"{name}_graph_radiation_admittance_{safeTerminal}";
|
||||
var flow = $"({string.Join(" + ", ports.Select(port => $"({GraphIncoming(name, port)} - {GraphOutgoing(name, port)})"))})";
|
||||
var flowName = $"{name}_graph_radiation_flow_{safeTerminal}";
|
||||
source.AppendLine($" {referenceArea} = {RadiationReferenceAreaExpression(radiationPort.Kind, opening)};");
|
||||
source.AppendLine($" {differentiation} = {RadiationDifferentiationExpression(radiationPort.Kind, opening)};");
|
||||
source.AppendLine($" {highpass} = {RadiationHighpassExpression(radiationPort.Kind, opening, true)};");
|
||||
source.AppendLine($" {name}_graph_radiation_model_{safeTerminal} = {F((int)EffectiveRadiationModel(radiationPort))};");
|
||||
source.AppendLine($" {referenceArea} = {RadiationReferenceAreaExpression(radiationPort, opening)};");
|
||||
source.AppendLine($" {differentiation} = {RadiationDifferentiationExpression(radiationPort, opening)};");
|
||||
source.AppendLine($" {highpass} = {RadiationHighpassExpression(radiationPort, opening, true)};");
|
||||
source.AppendLine($" {admittance} = {ProbeSignal(options, $"/debug/{name}/radiation/{terminal.Name}/admittance", $"sqrt(clip01(({terminalArea}) / max(0.000001, ({terminalArea}) + ({referenceArea}))))", 0, 1)};");
|
||||
source.AppendLine($" {flowName} = {ProbeSignal(options, $"/debug/{name}/radiation/{terminal.Name}/flow", flow, -2, 2)};");
|
||||
radiated.Add($"(({flowName} * (1.0 - ({differentiation})) + ({flowName} : fi.highpass(1, {highpass})) * ({differentiation})) * {loss} * {admittance})");
|
||||
|
|
@ -801,10 +802,10 @@ public static class FaustEmitter
|
|||
{
|
||||
var delayExpression = SegmentDelayExpression(segment);
|
||||
var maxDelay = SegmentMaxDelay(segment, waveClock);
|
||||
var loss = SegmentLossExpression(name, segment);
|
||||
source.AppendLine($" {name}_graph_delay_{segment.Index} = {delayExpression};");
|
||||
source.AppendLine($" {name}_graph_next_r{segment.Index} = {GraphOutgoing(name, new AcousticGraphPort(segment, true))} : {WaveClockDelayExpression(waveClock, maxDelay, $"{name}_graph_delay_{segment.Index}")} * {loss};");
|
||||
source.AppendLine($" {name}_graph_next_l{segment.Index} = {GraphOutgoing(name, new AcousticGraphPort(segment, false))} : {WaveClockDelayExpression(waveClock, maxDelay, $"{name}_graph_delay_{segment.Index}")} * {loss};");
|
||||
source.AppendLine($" {name}_graph_segment_loss_{segment.Index} = {SegmentLossExpression(name, segment)};");
|
||||
source.AppendLine($" {name}_graph_next_r{segment.Index} = {GraphOutgoing(name, new AcousticGraphPort(segment, true))} : {WaveClockDelayExpression(waveClock, maxDelay, $"{name}_graph_delay_{segment.Index}")} * {name}_graph_segment_loss_{segment.Index};");
|
||||
source.AppendLine($" {name}_graph_next_l{segment.Index} = {GraphOutgoing(name, new AcousticGraphPort(segment, false))} : {WaveClockDelayExpression(waveClock, maxDelay, $"{name}_graph_delay_{segment.Index}")} * {name}_graph_segment_loss_{segment.Index};");
|
||||
nextStates.Add($"{name}_graph_next_r{segment.Index}");
|
||||
}
|
||||
nextStates.AddRange(segments.Select(segment => $"{name}_graph_next_l{segment.Index}"));
|
||||
|
|
@ -847,36 +848,47 @@ public static class FaustEmitter
|
|||
return $"(({closedReflection}) * (1.0 - clip01({aperture})) + ({openReflection}) * clip01({aperture}))";
|
||||
}
|
||||
|
||||
private static string RadiationReferenceAreaExpression(AcousticRadiationKind kind, string aperture) => kind switch
|
||||
private static AcousticRadiationModel EffectiveRadiationModel(AcousticRadiationPort port) =>
|
||||
port.Model != AcousticRadiationModel.SimpleReflection
|
||||
? port.Model
|
||||
: port.Kind switch
|
||||
{
|
||||
AcousticRadiationKind.Beak => AcousticRadiationModel.Beak,
|
||||
AcousticRadiationKind.Nostril => AcousticRadiationModel.Nostril,
|
||||
AcousticRadiationKind.Membrane or AcousticRadiationKind.Vent => AcousticRadiationModel.Wall,
|
||||
_ => AcousticRadiationModel.SimpleReflection
|
||||
};
|
||||
|
||||
private static string RadiationReferenceAreaExpression(AcousticRadiationPort port, string aperture) => EffectiveRadiationModel(port) switch
|
||||
{
|
||||
AcousticRadiationKind.Lip or AcousticRadiationKind.Beak => $"max(0.18, 1.50 * 1.50 * (0.35 + 0.65 * clip01({aperture})))",
|
||||
AcousticRadiationKind.Nostril => $"max(0.08, 0.70 * 0.70 * (0.50 + 0.50 * clip01({aperture})))",
|
||||
AcousticRadiationKind.Membrane => "0.35",
|
||||
AcousticRadiationKind.Vent => "0.80",
|
||||
AcousticRadiationModel.LipPiston => $"max(0.18, 1.90 * 1.90 * (0.30 + 0.70 * clip01({aperture})))",
|
||||
AcousticRadiationModel.Beak => $"max(0.10, 1.10 * 1.10 * (0.25 + 0.75 * clip01({aperture})))",
|
||||
AcousticRadiationModel.Nostril => $"max(0.08, 0.70 * 0.70 * (0.50 + 0.50 * clip01({aperture})))",
|
||||
AcousticRadiationModel.Wall => "0.35",
|
||||
_ => "1.0"
|
||||
};
|
||||
|
||||
private static string RadiationDifferentiationExpression(AcousticRadiationKind kind, string aperture) => kind switch
|
||||
private static string RadiationDifferentiationExpression(AcousticRadiationPort port, string aperture) => EffectiveRadiationModel(port) switch
|
||||
{
|
||||
AcousticRadiationKind.Lip or AcousticRadiationKind.Beak => $"(0.55 + 0.25 * clip01({aperture}))",
|
||||
AcousticRadiationKind.Nostril => $"(0.45 + 0.20 * clip01({aperture}))",
|
||||
AcousticRadiationKind.Membrane => "0.20",
|
||||
AcousticRadiationKind.Vent => $"(0.30 + 0.20 * clip01({aperture}))",
|
||||
AcousticRadiationModel.LipPiston => $"(0.62 + 0.24 * clip01({aperture}))",
|
||||
AcousticRadiationModel.Beak => $"(0.50 + 0.22 * clip01({aperture}))",
|
||||
AcousticRadiationModel.Nostril => $"(0.45 + 0.20 * clip01({aperture}))",
|
||||
AcousticRadiationModel.Wall => "0.18",
|
||||
_ => "0.50"
|
||||
};
|
||||
|
||||
private static string RadiationHighpassExpression(AcousticRadiationKind kind, string aperture, bool graph) => kind switch
|
||||
private static string RadiationHighpassExpression(AcousticRadiationPort port, string aperture, bool graph) => EffectiveRadiationModel(port) switch
|
||||
{
|
||||
AcousticRadiationKind.Lip or AcousticRadiationKind.Beak => graph
|
||||
AcousticRadiationModel.LipPiston => graph
|
||||
? $"(120.0 + 180.0 * clip01({aperture}))"
|
||||
: $"(60.0 + 50.0 * clip01({aperture}))",
|
||||
AcousticRadiationKind.Nostril => graph
|
||||
AcousticRadiationModel.Beak => graph
|
||||
? $"(180.0 + 220.0 * clip01({aperture}))"
|
||||
: $"(90.0 + 90.0 * clip01({aperture}))",
|
||||
AcousticRadiationModel.Nostril => graph
|
||||
? $"(55.0 + 75.0 * clip01({aperture}))"
|
||||
: $"(30.0 + 30.0 * clip01({aperture}))",
|
||||
AcousticRadiationKind.Membrane => "15.0",
|
||||
AcousticRadiationKind.Vent => graph
|
||||
? $"(20.0 + 35.0 * clip01({aperture}))"
|
||||
: $"(15.0 + 20.0 * clip01({aperture}))",
|
||||
AcousticRadiationModel.Wall => "15.0",
|
||||
_ => "20.0"
|
||||
};
|
||||
|
||||
|
|
@ -947,7 +959,7 @@ public static class FaustEmitter
|
|||
|
||||
private static bool IsTissueValveSource(AcousticSourcePort port) =>
|
||||
port.Model == AcousticSourceModel.TissueValve ||
|
||||
port.Model == AcousticSourceModel.Default && port.Kind == AcousticSourceKind.Labial;
|
||||
port.Model == AcousticSourceModel.Default && port.Kind is AcousticSourceKind.Labial or AcousticSourceKind.Glottal;
|
||||
|
||||
private static string TissueValveInlineExpression(
|
||||
string frequency,
|
||||
|
|
@ -1342,8 +1354,15 @@ public static class FaustEmitter
|
|||
{
|
||||
var baseLoss = F(Math.Clamp(segment.Path.Loss, 0, 1));
|
||||
var area = $"{voiceName}_graph_segment_area_{segment.Index}";
|
||||
var apertureLoss = $"sqrt(clip01(({area}) / max(0.000001, ({area}) + 0.02)))";
|
||||
return $"({baseLoss}) * ({apertureLoss})";
|
||||
var apertureLoss = segment.Path.LossModel switch
|
||||
{
|
||||
AcousticLossModel.None => "1.0",
|
||||
AcousticLossModel.Viscous => $"sqrt(clip01(({area}) / max(0.000001, ({area}) + 0.020)))",
|
||||
AcousticLossModel.Birkholz2024 => $"sqrt(clip01(({area}) / max(0.000001, ({area}) + 0.012))) * (0.998 - 0.010 * clip01(0.080 / max(0.000001, ({area}) + 0.080)))",
|
||||
AcousticLossModel.Wall => $"(0.996 - 0.018 * clip01(0.050 / max(0.000001, ({area}) + 0.050)))",
|
||||
_ => $"sqrt(clip01(({area}) / max(0.000001, ({area}) + 0.02)))"
|
||||
};
|
||||
return $"clip01(({baseLoss}) * ({apertureLoss}))";
|
||||
}
|
||||
|
||||
private static int SegmentMaxDelay(AcousticGraphSegment segment, WaveClockPolicy waveClock)
|
||||
|
|
@ -1604,15 +1623,48 @@ public static class FaustEmitter
|
|||
var drive = $"max(0.0, {parameters.Expression(OwnerField(path, "drive"), port.Drive)})";
|
||||
var loadCoupling = $"max(0.0, {parameters.Expression(OwnerField(path, "load_coupling"), port.LoadCoupling)})";
|
||||
var restOpening = $"max(0.0, {parameters.Expression(OwnerField(path, "rest_opening"), port.RestOpening)})";
|
||||
var upperMass = $"max(0.02, {parameters.Expression(OwnerField(path, "upper_mass"), port.UpperMass)})";
|
||||
var lowerMass = $"max(0.02, {parameters.Expression(OwnerField(path, "lower_mass"), port.LowerMass)})";
|
||||
var upperStiffness = $"max(0.0, {parameters.Expression(OwnerField(path, "upper_stiffness"), port.UpperStiffness)})";
|
||||
var lowerStiffness = $"max(0.0, {parameters.Expression(OwnerField(path, "lower_stiffness"), port.LowerStiffness)})";
|
||||
var couplingStiffness = $"max(0.0, {parameters.Expression(OwnerField(path, "coupling_stiffness"), port.CouplingStiffness)})";
|
||||
var collisionStiffness = $"max(0.0, {parameters.Expression(OwnerField(path, "collision_stiffness"), port.CollisionStiffness)})";
|
||||
var collisionDamping = $"max(0.0, {parameters.Expression(OwnerField(path, "collision_damping"), port.CollisionDamping)})";
|
||||
var verticalPhase = $"clip01({parameters.Expression(OwnerField(path, "vertical_phase"), port.VerticalPhase)})";
|
||||
var reservoirPressure = $"max(0.0, {parameters.Expression(OwnerField(path, "reservoir_pressure"), port.ReservoirPressure)})";
|
||||
var downstreamPressure = $"max(0.0, {parameters.Expression(OwnerField(path, "downstream_pressure"), port.DownstreamPressure)})";
|
||||
|
||||
source.AppendLine($" {prefix}_stiffness_hint = max(0.00002, min(0.16, pow(2.0 * ma.PI * max(20.0, {frequency}) / ma.SR, 2.0)));");
|
||||
source.AppendLine($" {prefix}_reservoir_pressure = ({pressure}) * ({drive}) * ({reservoirPressure});");
|
||||
source.AppendLine($" {prefix}_downstream_pressure = ({downstreamPressure}) + ({loadCoupling}) * {prefix}_load_pressure;");
|
||||
source.AppendLine($" {prefix}_pressure_drive = max(0.0, {prefix}_reservoir_pressure - {prefix}_downstream_pressure);");
|
||||
source.AppendLine($" {prefix}_stiffness = max(({stiffness}), {prefix}_stiffness_hint * (0.35 + 1.65 * ({tension})));");
|
||||
source.AppendLine($" {prefix}_pressure_drive = max(0.0, ({pressure}) * ({drive}) - ({loadCoupling}) * {prefix}_load_pressure);");
|
||||
source.AppendLine($" {prefix}_velocity_decay = min(0.9995, max(0.20, 1.0 - ((0.008 + 0.08 * ({damping})) / ({mass}))));");
|
||||
source.AppendLine($" {prefix}_displacement_decay = min(0.9998, max(0.20, 1.0 - 0.0008 / ({mass})));");
|
||||
source.AppendLine($" {prefix}_force = ({prefix}_pressure_drive * (0.0004 + 0.0024 * (1.0 - clip01({opening}))) - ({loadCoupling}) * {prefix}_load_pressure * 0.001) / ({mass});");
|
||||
source.AppendLine($" {prefix}_velocity = {prefix}_force : + ~ *({prefix}_velocity_decay / (1.0 + 10.0 * {prefix}_stiffness + 0.4 * ({saturation})));");
|
||||
source.AppendLine($" {prefix}_displacement = {prefix}_velocity : + ~ *({prefix}_displacement_decay / (1.0 + 1.5 * {prefix}_stiffness));");
|
||||
switch (port.Law)
|
||||
{
|
||||
case AcousticValveLaw.TwoMass:
|
||||
case AcousticValveLaw.BodyCover:
|
||||
source.AppendLine($" {prefix}_upper_stiffness_effective = max(({upperStiffness}), {prefix}_stiffness * (0.80 + 0.45 * ({tension})));");
|
||||
source.AppendLine($" {prefix}_lower_stiffness_effective = max(({lowerStiffness}), {prefix}_stiffness * (1.05 + 0.55 * ({tension})));");
|
||||
source.AppendLine($" {prefix}_coupling_stiffness = ({couplingStiffness}) * (1.0 + 1.5 * ({tension}));");
|
||||
source.AppendLine($" {prefix}_lower_velocity_decay = min(0.9995, max(0.20, 1.0 - ((0.010 + 0.090 * ({damping}) + 0.040 * ({collisionDamping})) / ({lowerMass}))));");
|
||||
source.AppendLine($" {prefix}_upper_velocity_decay = min(0.9995, max(0.20, 1.0 - ((0.012 + 0.105 * ({damping}) + 0.030 * ({collisionDamping})) / ({upperMass}))));");
|
||||
source.AppendLine($" {prefix}_lower_force = ({prefix}_pressure_drive * (0.0005 + 0.0028 * (1.0 - clip01({opening}))) - ({loadCoupling}) * {prefix}_load_pressure * 0.0012) / ({lowerMass});");
|
||||
source.AppendLine($" {prefix}_upper_force = ({prefix}_pressure_drive * (0.0003 + 0.0018 * (1.0 - clip01({opening}))) - ({loadCoupling}) * {prefix}_load_pressure * 0.0008) / ({upperMass});");
|
||||
source.AppendLine($" {prefix}_lower_velocity = {prefix}_lower_force : + ~ *({prefix}_lower_velocity_decay / (1.0 + 10.0 * {prefix}_lower_stiffness_effective + {prefix}_coupling_stiffness + 0.4 * ({saturation})));");
|
||||
source.AppendLine($" {prefix}_upper_velocity = ({prefix}_upper_force + {prefix}_lower_velocity * {prefix}_coupling_stiffness * 0.35) : + ~ *({prefix}_upper_velocity_decay / (1.0 + 10.0 * {prefix}_upper_stiffness_effective + {prefix}_coupling_stiffness + 0.4 * ({saturation})));");
|
||||
source.AppendLine($" {prefix}_lower_displacement = {prefix}_lower_velocity : + ~ *(min(0.9998, max(0.20, 1.0 - 0.0008 / ({lowerMass}))));");
|
||||
source.AppendLine($" {prefix}_upper_displacement = {prefix}_upper_velocity : + ~ *(min(0.9998, max(0.20, 1.0 - 0.0008 / ({upperMass}))));");
|
||||
source.AppendLine($" {prefix}_collision = ({collisionStiffness}) * max(0.0, 0.0 - (({restOpening}) + ({opening}) + {prefix}_upper_displacement));");
|
||||
source.AppendLine($" {prefix}_displacement = {prefix}_lower_displacement * (1.0 - ({verticalPhase})) + ({prefix}_upper_displacement - {prefix}_collision) * ({verticalPhase});");
|
||||
break;
|
||||
default:
|
||||
source.AppendLine($" {prefix}_velocity_decay = min(0.9995, max(0.20, 1.0 - ((0.008 + 0.08 * ({damping})) / ({mass}))));");
|
||||
source.AppendLine($" {prefix}_displacement_decay = min(0.9998, max(0.20, 1.0 - 0.0008 / ({mass})));");
|
||||
source.AppendLine($" {prefix}_force = ({prefix}_pressure_drive * (0.0004 + 0.0024 * (1.0 - clip01({opening}))) - ({loadCoupling}) * {prefix}_load_pressure * 0.001) / ({mass});");
|
||||
source.AppendLine($" {prefix}_velocity = {prefix}_force : + ~ *({prefix}_velocity_decay / (1.0 + 10.0 * {prefix}_stiffness + 0.4 * ({saturation})));");
|
||||
source.AppendLine($" {prefix}_displacement = {prefix}_velocity : + ~ *({prefix}_displacement_decay / (1.0 + 1.5 * {prefix}_stiffness));");
|
||||
break;
|
||||
}
|
||||
source.AppendLine($" {prefix}_aperture = max(0.0, ({restOpening}) + ({opening}) + {prefix}_displacement - ({saturation}) * pow({prefix}_displacement, 3.0));");
|
||||
source.AppendLine($" {prefix}_turbulence = no.noise : fi.highpass(2, 1200.0 + 2800.0 * clip01(1.0 - {prefix}_aperture));");
|
||||
source.AppendLine($" {prefix}_flow = ma.tanh({prefix}_pressure_drive * {prefix}_aperture * (2.0 + 10.0 * ({drive})));");
|
||||
|
|
|
|||
|
|
@ -240,6 +240,13 @@ public enum AcousticSourceModel
|
|||
TissueValve
|
||||
}
|
||||
|
||||
public enum AcousticValveLaw
|
||||
{
|
||||
OneMass,
|
||||
TwoMass,
|
||||
BodyCover
|
||||
}
|
||||
|
||||
public enum AcousticBranchKind
|
||||
{
|
||||
SideBranch,
|
||||
|
|
@ -258,6 +265,24 @@ public enum AcousticRadiationKind
|
|||
Membrane
|
||||
}
|
||||
|
||||
public enum AcousticLossModel
|
||||
{
|
||||
Custom,
|
||||
None,
|
||||
Viscous,
|
||||
Birkholz2024,
|
||||
Wall
|
||||
}
|
||||
|
||||
public enum AcousticRadiationModel
|
||||
{
|
||||
SimpleReflection,
|
||||
LipPiston,
|
||||
Beak,
|
||||
Nostril,
|
||||
Wall
|
||||
}
|
||||
|
||||
public enum WaveClockDelayStrategy
|
||||
{
|
||||
UnitGrid,
|
||||
|
|
@ -293,7 +318,11 @@ public sealed record AcousticPath(
|
|||
TractAreaFunction AreaFunction,
|
||||
float PropagationSpeedMetersPerSecond = 343,
|
||||
float Loss = 0.999f,
|
||||
AcousticAreaControl? AreaControl = null);
|
||||
AcousticAreaControl? AreaControl = null,
|
||||
string AreaCurve = "",
|
||||
AcousticLossModel LossModel = AcousticLossModel.Custom);
|
||||
|
||||
public sealed record AcousticAreaCurve(string Name, TractAreaFunction AreaFunction);
|
||||
|
||||
public sealed record AcousticAreaControl(
|
||||
float TongueIndex = 12.9f,
|
||||
|
|
@ -327,7 +356,18 @@ public sealed record AcousticSourcePort(
|
|||
float Saturation = 0.8f,
|
||||
float Drive = 1,
|
||||
float LoadCoupling = 0.35f,
|
||||
float RestOpening = 0.02f);
|
||||
float RestOpening = 0.02f,
|
||||
AcousticValveLaw Law = AcousticValveLaw.OneMass,
|
||||
float UpperMass = 0.20f,
|
||||
float LowerMass = 0.35f,
|
||||
float UpperStiffness = 0,
|
||||
float LowerStiffness = 0,
|
||||
float CouplingStiffness = 0.08f,
|
||||
float CollisionStiffness = 0.6f,
|
||||
float CollisionDamping = 0.15f,
|
||||
float VerticalPhase = 0.18f,
|
||||
float ReservoirPressure = 1,
|
||||
float DownstreamPressure = 0);
|
||||
|
||||
public sealed record AcousticSourcePositionControl(
|
||||
float Index = 0,
|
||||
|
|
@ -352,7 +392,8 @@ public sealed record AcousticRadiationPort(
|
|||
AcousticRadiationKind Kind = AcousticRadiationKind.Lip,
|
||||
float Opening = 1,
|
||||
float Reflection = -0.85f,
|
||||
float Loss = 1);
|
||||
float Loss = 1,
|
||||
AcousticRadiationModel Model = AcousticRadiationModel.SimpleReflection);
|
||||
|
||||
public sealed record AcousticTerminal(
|
||||
string Name,
|
||||
|
|
@ -538,6 +579,15 @@ public sealed record ControlCurve(
|
|||
public IReadOnlyList<ControlCurvePoint> Points { get; init; } = Points ?? Array.Empty<ControlCurvePoint>();
|
||||
}
|
||||
|
||||
public sealed record GestureGroup(
|
||||
string Name,
|
||||
IReadOnlyList<string> Curves,
|
||||
float Depth = 1,
|
||||
bool Enabled = true)
|
||||
{
|
||||
public IReadOnlyList<string> Curves { get; init; } = Curves ?? Array.Empty<string>();
|
||||
}
|
||||
|
||||
public enum ParameterBindingTransform
|
||||
{
|
||||
Identity,
|
||||
|
|
@ -714,6 +764,7 @@ public sealed record SynthPatch
|
|||
public IReadOnlyList<TractInjection> TractInjections { get; init; } = Array.Empty<TractInjection>();
|
||||
public IReadOnlyList<NasalBranch> NasalBranches { get; init; } = Array.Empty<NasalBranch>();
|
||||
public IReadOnlyList<TractMotion> TractMotions { get; init; } = Array.Empty<TractMotion>();
|
||||
public IReadOnlyList<AcousticAreaCurve> AcousticAreaCurves { get; init; } = Array.Empty<AcousticAreaCurve>();
|
||||
public IReadOnlyList<AcousticPath> AcousticPaths { get; init; } = Array.Empty<AcousticPath>();
|
||||
public IReadOnlyList<AcousticSourcePort> AcousticSourcePorts { get; init; } = Array.Empty<AcousticSourcePort>();
|
||||
public IReadOnlyList<AcousticBranch> AcousticBranches { get; init; } = Array.Empty<AcousticBranch>();
|
||||
|
|
@ -726,6 +777,7 @@ public sealed record SynthPatch
|
|||
public IReadOnlyList<ControlLane> Controls { get; init; } = Array.Empty<ControlLane>();
|
||||
public IReadOnlyList<PatchParameter> Parameters { get; init; } = Array.Empty<PatchParameter>();
|
||||
public IReadOnlyList<ControlCurve> ControlCurves { get; init; } = Array.Empty<ControlCurve>();
|
||||
public IReadOnlyList<GestureGroup> GestureGroups { get; init; } = Array.Empty<GestureGroup>();
|
||||
public IReadOnlyList<ParameterBinding> ParameterBindings { get; init; } = Array.Empty<ParameterBinding>();
|
||||
public Playback Playback { get; init; } = new();
|
||||
public Repeat? Repeat { get; init; }
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public static class PatchScript
|
|||
private readonly List<OperatorGraph> _operatorGraphs = [];
|
||||
private readonly List<PatchParameter> _parameters = [];
|
||||
private readonly List<ControlCurve> _controlCurves = [];
|
||||
private readonly List<GestureGroup> _gestureGroups = [];
|
||||
private readonly List<ParameterBinding> _parameterBindings = [];
|
||||
private readonly List<PatchLayer> _layers = [];
|
||||
private readonly List<HarmonicBank> _harmonicBanks = [];
|
||||
|
|
@ -47,6 +48,8 @@ public static class PatchScript
|
|||
private readonly Dictionary<string, NasalBranch> _nasalBranchesByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<TractMotion> _tractMotions = [];
|
||||
private readonly Dictionary<string, TractMotion> _tractMotionsByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<AcousticAreaCurve> _acousticAreaCurves = [];
|
||||
private readonly Dictionary<string, AcousticAreaCurve> _acousticAreaCurvesByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<AcousticPath> _acousticPaths = [];
|
||||
private readonly Dictionary<string, AcousticPath> _acousticPathsByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<AcousticSourcePort> _acousticSourcePorts = [];
|
||||
|
|
@ -89,6 +92,7 @@ public static class PatchScript
|
|||
TractInjections = _tractInjections,
|
||||
NasalBranches = _nasalBranches,
|
||||
TractMotions = _tractMotions,
|
||||
AcousticAreaCurves = _acousticAreaCurves,
|
||||
AcousticPaths = _acousticPaths,
|
||||
AcousticSourcePorts = _acousticSourcePorts,
|
||||
AcousticBranches = _acousticBranches,
|
||||
|
|
@ -101,6 +105,7 @@ public static class PatchScript
|
|||
Controls = _controls,
|
||||
Parameters = _parameters,
|
||||
ControlCurves = _controlCurves,
|
||||
GestureGroups = _gestureGroups,
|
||||
ParameterBindings = _parameterBindings,
|
||||
Playback = Playback,
|
||||
Repeat = Repeat,
|
||||
|
|
@ -169,6 +174,10 @@ public static class PatchScript
|
|||
FlushPendingOperatorGraph();
|
||||
AddTractMotion(fields, line);
|
||||
break;
|
||||
case "area_curve":
|
||||
FlushPendingOperatorGraph();
|
||||
AddAcousticAreaCurve(fields, line);
|
||||
break;
|
||||
case "acoustic_path":
|
||||
FlushPendingOperatorGraph();
|
||||
AddAcousticPath(fields, line);
|
||||
|
|
@ -241,6 +250,10 @@ public static class PatchScript
|
|||
FlushPendingOperatorGraph();
|
||||
AddControlCurve(fields, line);
|
||||
break;
|
||||
case "gesture":
|
||||
FlushPendingOperatorGraph();
|
||||
AddGestureGroup(fields, line);
|
||||
break;
|
||||
case "sfxr":
|
||||
FlushPendingOperatorGraph();
|
||||
AddSfxrPatch(ParseSfxrCommand(fields, line));
|
||||
|
|
@ -382,7 +395,8 @@ public static class PatchScript
|
|||
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")));
|
||||
GetBoundFloat(fields, line, 0.999f, $"/acoustic/paths/{_acousticPaths.Count}/loss", "loss"),
|
||||
LossModel: ParseAcousticLossModel(GetAny(fields, ["loss_model", "loss_kind"], "custom"), line)));
|
||||
}
|
||||
|
||||
private void AddGlottalSource(IReadOnlyDictionary<string, string> fields, int line)
|
||||
|
|
@ -402,7 +416,7 @@ 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))
|
||||
if (TryGetAny(fields, ["path"], out var path))
|
||||
{
|
||||
RequireAcousticPath(path, line);
|
||||
AddAcousticSourcePortRecord(new AcousticSourcePort(
|
||||
|
|
@ -413,7 +427,10 @@ public static class PatchScript
|
|||
glottis.Intensity,
|
||||
glottis.Tenseness,
|
||||
glottis.Skew,
|
||||
glottis.Aspiration));
|
||||
glottis.Aspiration,
|
||||
Model: AcousticSourceModel.TissueValve,
|
||||
Law: AcousticValveLaw.TwoMass,
|
||||
ReservoirPressure: 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -514,15 +531,32 @@ public static class PatchScript
|
|||
throw new PatchScriptException(line, $"duplicate acoustic path `{name}`");
|
||||
}
|
||||
|
||||
var areaFunction = ParseTractAreaFunction(fields, line, 17);
|
||||
var areaCurve = GetAny(fields, ["area_curve", "curve"], "");
|
||||
var path = new AcousticPath(
|
||||
name,
|
||||
ParseTractAreaFunction(fields, line, 17),
|
||||
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"),
|
||||
ParseAcousticAreaControl(fields, line, _acousticPaths.Count));
|
||||
ParseAcousticAreaControl(fields, line, _acousticPaths.Count),
|
||||
areaCurve,
|
||||
ParseAcousticLossModel(GetAny(fields, ["loss_model", "loss_kind"], "custom"), line));
|
||||
AddAcousticPathRecord(path);
|
||||
}
|
||||
|
||||
private void AddAcousticAreaCurve(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_acousticAreaCurvesByName.ContainsKey(name))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate area curve `{name}`");
|
||||
}
|
||||
|
||||
var curve = new AcousticAreaCurve(name, ParseTractAreaFunction(fields, line, 17));
|
||||
_acousticAreaCurves.Add(curve);
|
||||
_acousticAreaCurvesByName[name] = curve;
|
||||
}
|
||||
|
||||
private static bool HasAcousticAreaControl(IReadOnlyDictionary<string, string> fields) =>
|
||||
HasAny(
|
||||
fields,
|
||||
|
|
@ -593,7 +627,18 @@ public static class PatchScript
|
|||
GetBoundFloat(fields, line, 0.8f, $"/acoustic/sources/{_acousticSourcePorts.Count}/saturation", "saturation", "sat"),
|
||||
GetBoundFloat(fields, line, 1, $"/acoustic/sources/{_acousticSourcePorts.Count}/drive", "drive", "flow_gain"),
|
||||
GetBoundFloat(fields, line, 0.35f, $"/acoustic/sources/{_acousticSourcePorts.Count}/load_coupling", "load_coupling", "load_feedback"),
|
||||
GetBoundFloat(fields, line, 0.02f, $"/acoustic/sources/{_acousticSourcePorts.Count}/rest_opening", "rest_opening", "rest_aperture"));
|
||||
GetBoundFloat(fields, line, 0.02f, $"/acoustic/sources/{_acousticSourcePorts.Count}/rest_opening", "rest_opening", "rest_aperture"),
|
||||
ParseAcousticValveLaw(GetAny(fields, ["law", "valve_law"], kind == AcousticSourceKind.Glottal ? "two_mass" : "one_mass"), line),
|
||||
GetBoundFloat(fields, line, 0.20f, $"/acoustic/sources/{_acousticSourcePorts.Count}/upper_mass", "upper_mass"),
|
||||
GetBoundFloat(fields, line, 0.35f, $"/acoustic/sources/{_acousticSourcePorts.Count}/lower_mass", "lower_mass"),
|
||||
GetBoundFloat(fields, line, 0, $"/acoustic/sources/{_acousticSourcePorts.Count}/upper_stiffness", "upper_stiffness"),
|
||||
GetBoundFloat(fields, line, 0, $"/acoustic/sources/{_acousticSourcePorts.Count}/lower_stiffness", "lower_stiffness"),
|
||||
GetBoundFloat(fields, line, 0.08f, $"/acoustic/sources/{_acousticSourcePorts.Count}/coupling_stiffness", "coupling_stiffness", "coupling_spring"),
|
||||
GetBoundFloat(fields, line, 0.6f, $"/acoustic/sources/{_acousticSourcePorts.Count}/collision_stiffness", "collision_stiffness"),
|
||||
GetBoundFloat(fields, line, 0.15f, $"/acoustic/sources/{_acousticSourcePorts.Count}/collision_damping", "collision_damping"),
|
||||
GetBoundFloat(fields, line, 0.18f, $"/acoustic/sources/{_acousticSourcePorts.Count}/vertical_phase", "vertical_phase"),
|
||||
GetBoundFloat(fields, line, 1, $"/acoustic/sources/{_acousticSourcePorts.Count}/reservoir_pressure", "reservoir_pressure", "subglottal_pressure", "bronchial_pressure"),
|
||||
GetBoundFloat(fields, line, 0, $"/acoustic/sources/{_acousticSourcePorts.Count}/downstream_pressure", "downstream_pressure", "supraglottal_pressure"));
|
||||
AddAcousticSourcePortRecord(port);
|
||||
AddAcousticTerminalRecord(new AcousticTerminal(
|
||||
port.Name,
|
||||
|
|
@ -682,7 +727,8 @@ public static class PatchScript
|
|||
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"));
|
||||
GetBoundFloat(fields, line, 1, $"/acoustic/radiation/{_acousticRadiationPorts.Count}/loss", "loss"),
|
||||
ParseAcousticRadiationModel(GetAny(fields, ["model", "radiation_model"], "simple_reflection"), line));
|
||||
AddAcousticRadiationPortRecord(port);
|
||||
AddAcousticTerminalRecord(new AcousticTerminal(
|
||||
port.Name,
|
||||
|
|
@ -1356,7 +1402,10 @@ public static class PatchScript
|
|||
1,
|
||||
true,
|
||||
null,
|
||||
0.10f);
|
||||
0.10f,
|
||||
Model: AcousticSourceModel.TissueValve,
|
||||
Law: AcousticValveLaw.TwoMass,
|
||||
ReservoirPressure: 1);
|
||||
var sourceIndex = _acousticSourcePorts.Count;
|
||||
AddAcousticSourcePortRecord(source);
|
||||
MirrorParameterBinding(OwnerField(tractPath, "intensity"), $"/acoustic/sources/{sourceIndex}/pressure");
|
||||
|
|
@ -1474,7 +1523,8 @@ public static class PatchScript
|
|||
AcousticRadiationKind.Nostril,
|
||||
1,
|
||||
nasal.Reflection,
|
||||
nasal.Loss);
|
||||
nasal.Loss,
|
||||
AcousticRadiationModel.Nostril);
|
||||
var nasalRadiationIndex = _acousticRadiationPorts.Count;
|
||||
AddAcousticRadiationPortRecord(nasalRadiation);
|
||||
MirrorParameterBinding(OwnerField(tractPath, "lip_reflection"), $"/acoustic/radiation/{nasalRadiationIndex}/reflection");
|
||||
|
|
@ -1499,7 +1549,8 @@ public static class PatchScript
|
|||
AcousticRadiationKind.Lip,
|
||||
1,
|
||||
tract.LipReflection,
|
||||
1);
|
||||
1,
|
||||
AcousticRadiationModel.LipPiston);
|
||||
var lipIndex = _acousticRadiationPorts.Count;
|
||||
AddAcousticRadiationPortRecord(lip);
|
||||
MirrorParameterBinding(OwnerField(tractPath, "lip_reflection"), $"/acoustic/radiation/{lipIndex}/reflection");
|
||||
|
|
@ -1803,6 +1854,34 @@ public static class PatchScript
|
|||
GetAny(fields, ["rate", "automation", "automation_rate"], "control")));
|
||||
}
|
||||
|
||||
private void AddGestureGroup(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_gestureGroups.Any(group => group.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate gesture group `{name}`");
|
||||
}
|
||||
|
||||
var curveNames = ParseNameList(RequiredAny(fields, ["curves", "curve"], line));
|
||||
if (curveNames.Count == 0)
|
||||
{
|
||||
throw new PatchScriptException(line, "gesture group needs at least one curve");
|
||||
}
|
||||
foreach (var curveName in curveNames)
|
||||
{
|
||||
if (_controlCurves.All(curve => !curve.Name.Equals(curveName, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
throw new PatchScriptException(line, $"gesture group references unknown curve `{curveName}`");
|
||||
}
|
||||
}
|
||||
|
||||
_gestureGroups.Add(new GestureGroup(
|
||||
name,
|
||||
curveNames,
|
||||
GetFloat(fields, line, 1, "depth", "amount", "mix"),
|
||||
TryGetAny(fields, ["enabled", "active"], out var enabled) ? ParseBool(enabled, line) : true));
|
||||
}
|
||||
|
||||
private float GetBoundFloat(
|
||||
IReadOnlyDictionary<string, string> fields,
|
||||
int line,
|
||||
|
|
@ -2094,13 +2173,23 @@ public static class PatchScript
|
|||
GetBoundFloat(fields, line, fallback.ObstructionThreshold, OwnerField(ownerPath, "tract/motion/obstruction_threshold"), "obstruction_threshold", "closure"));
|
||||
}
|
||||
|
||||
private static TractAreaFunction ParseTractAreaFunction(IReadOnlyDictionary<string, string> fields, int line, float defaultLengthCentimeters)
|
||||
private TractAreaFunction ParseTractAreaFunction(IReadOnlyDictionary<string, string> fields, int line, float defaultLengthCentimeters)
|
||||
{
|
||||
if (TryGetAny(fields, ["area_curve", "curve"], out var curveName))
|
||||
{
|
||||
if (!_acousticAreaCurvesByName.TryGetValue(curveName, out var curve))
|
||||
{
|
||||
throw new PatchScriptException(line, $"unknown area curve `{curveName}`");
|
||||
}
|
||||
|
||||
return curve.AreaFunction;
|
||||
}
|
||||
|
||||
var hasDiameters = TryGetAny(fields, ["diameters", "diameter"], out var diametersText);
|
||||
var hasAreas = TryGetAny(fields, ["areas", "area"], out var areasText);
|
||||
if (hasDiameters == hasAreas)
|
||||
{
|
||||
throw new PatchScriptException(line, "tract shape needs exactly one of diameters or areas");
|
||||
throw new PatchScriptException(line, "tract shape needs exactly one of diameters, areas, or area_curve");
|
||||
}
|
||||
|
||||
var samples = ParseFloatList(hasDiameters ? diametersText! : areasText!, line, hasDiameters ? "diameters" : "areas");
|
||||
|
|
@ -2536,6 +2625,7 @@ public static class PatchScript
|
|||
"harmonics" or "partials" or "drawbars" => "harmonics",
|
||||
"spectrum" or "spectral" or "padsource" or "pad_source" => "spectrum",
|
||||
"tractshape" or "tract_shape" or "area_function" or "tract_area" => "tract_shape",
|
||||
"area_curve" or "areacurve" or "morphology_curve" or "morph_curve" => "area_curve",
|
||||
"glottis" or "glottal" or "excitation" => "glottis",
|
||||
"tract_injection" or "injection" or "frication" or "burst" => "tract_injection",
|
||||
"nasal_branch" or "nose_branch" or "nasal" => "nasal_branch",
|
||||
|
|
@ -2558,7 +2648,8 @@ public static class PatchScript
|
|||
"mod" or "wob" or "wobble" or "bus" => "mod",
|
||||
"lfo" or "control" => "control",
|
||||
"param" or "parameter" => "param",
|
||||
"curve" or "control_curve" or "automation" or "gesture" => "curve",
|
||||
"curve" or "control_curve" or "automation" => "curve",
|
||||
"gesture" or "gesture_group" or "gesturegroup" => "gesture",
|
||||
"s" or "sfxr" => "sfxr",
|
||||
_ => command
|
||||
};
|
||||
|
|
@ -2664,18 +2755,30 @@ public static class PatchScript
|
|||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return kind == AcousticSourceKind.Labial ? AcousticSourceModel.TissueValve : AcousticSourceModel.Default;
|
||||
return kind is AcousticSourceKind.Labial or AcousticSourceKind.Glottal
|
||||
? AcousticSourceModel.TissueValve
|
||||
: AcousticSourceModel.Default;
|
||||
}
|
||||
|
||||
return value.ToLowerInvariant() switch
|
||||
{
|
||||
"default" or "auto" => kind == AcousticSourceKind.Labial ? AcousticSourceModel.TissueValve : AcousticSourceModel.Default,
|
||||
"default" or "auto" => kind is AcousticSourceKind.Labial or AcousticSourceKind.Glottal
|
||||
? AcousticSourceModel.TissueValve
|
||||
: AcousticSourceModel.Default,
|
||||
"legacy" or "proxy" => AcousticSourceModel.Legacy,
|
||||
"tissue_valve" or "tissue-valve" or "valve" or "labial_oscillator" or "labial-oscillator" => AcousticSourceModel.TissueValve,
|
||||
_ => throw new PatchScriptException(line, $"unknown acoustic source model `{value}`")
|
||||
};
|
||||
}
|
||||
|
||||
private static AcousticValveLaw ParseAcousticValveLaw(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"one" or "1" or "one_mass" or "one-mass" or "single_mass" or "single-mass" => AcousticValveLaw.OneMass,
|
||||
"two" or "2" or "two_mass" or "two-mass" => AcousticValveLaw.TwoMass,
|
||||
"body_cover" or "body-cover" or "cover" => AcousticValveLaw.BodyCover,
|
||||
_ => throw new PatchScriptException(line, $"unknown acoustic valve law `{value}`")
|
||||
};
|
||||
|
||||
private static AcousticBranchKind ParseAcousticBranchKind(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"side" or "side_branch" => AcousticBranchKind.SideBranch,
|
||||
|
|
@ -2696,6 +2799,26 @@ public static class PatchScript
|
|||
_ => throw new PatchScriptException(line, $"unknown acoustic radiation kind `{value}`")
|
||||
};
|
||||
|
||||
private static AcousticLossModel ParseAcousticLossModel(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"custom" or "default" or "auto" => AcousticLossModel.Custom,
|
||||
"none" or "ideal" => AcousticLossModel.None,
|
||||
"viscous" or "viscosity" => AcousticLossModel.Viscous,
|
||||
"birkholz_2024" or "birkholz-2024" or "birkholz" => AcousticLossModel.Birkholz2024,
|
||||
"wall" or "wall_loss" or "wall-loss" => AcousticLossModel.Wall,
|
||||
_ => throw new PatchScriptException(line, $"unknown acoustic loss model `{value}`")
|
||||
};
|
||||
|
||||
private static AcousticRadiationModel ParseAcousticRadiationModel(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"simple" or "simple_reflection" or "simple-reflection" or "reflection" => AcousticRadiationModel.SimpleReflection,
|
||||
"lip_piston" or "lip-piston" or "piston" => AcousticRadiationModel.LipPiston,
|
||||
"beak" => AcousticRadiationModel.Beak,
|
||||
"nostril" or "nose" => AcousticRadiationModel.Nostril,
|
||||
"wall" => AcousticRadiationModel.Wall,
|
||||
_ => throw new PatchScriptException(line, $"unknown acoustic radiation model `{value}`")
|
||||
};
|
||||
|
||||
private static AcousticTerminalKind ParseAcousticTerminalKind(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"junction" or "node" or "scatter" => AcousticTerminalKind.Junction,
|
||||
|
|
|
|||
Loading…
Reference in a new issue