Add low-level tract waveguide primitives
This commit is contained in:
parent
2cb52fb929
commit
44c4e4feea
12 changed files with 438 additions and 45 deletions
|
|
@ -630,8 +630,38 @@ public static class BuiltInScripts
|
|||
name=pt_human
|
||||
diameters=0.6,0.6,0.6,0.6,0.6,0.7,0.8,1.0,1.1,1.1,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.5,1.4,1.3,1.2,1.15,1.5
|
||||
|
||||
glottis
|
||||
name=pt_glottis
|
||||
intensity=@/pink/intensity
|
||||
tenseness=@/pink/tenseness
|
||||
aspiration=0.12
|
||||
reflection=@/pink/glottal/reflection
|
||||
skew=0.42
|
||||
|
||||
tract_injection
|
||||
name=pt_constriction
|
||||
position=@/pink/constriction/index
|
||||
diameter=@/pink/constriction/diameter
|
||||
turbulence=@/pink/turbulence
|
||||
burst=0.28
|
||||
width=1
|
||||
|
||||
nasal_branch
|
||||
name=pt_nose
|
||||
junction=17
|
||||
velum=@/pink/velum
|
||||
reflection=@/pink/lip/reflection
|
||||
loss=0.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
|
||||
shape=pt_human
|
||||
glottis=pt_glottis
|
||||
injection=pt_constriction
|
||||
nasal_branch=pt_nose
|
||||
propagation=waveguide
|
||||
waveguide_loss=0.999
|
||||
substeps=2
|
||||
freq=@/pink/frequency
|
||||
gain=0.7
|
||||
attack=0.004
|
||||
|
|
|
|||
|
|
@ -405,17 +405,28 @@ public static class FaustEmitter
|
|||
var glottalReflection = parameters.Expression(OwnerField(tractPath, "glottal_reflection"), tract.GlottalReflection);
|
||||
var lipReflection = parameters.Expression(OwnerField(tractPath, "lip_reflection"), tract.LipReflection);
|
||||
var areaFunction = tract.AreaFunction;
|
||||
var glottis = tract.Glottis;
|
||||
var injection = tract.Injection;
|
||||
var shapeBack = F(areaFunction?.AverageDiameter(0.18f, 0.38f) ?? 1.35f);
|
||||
var shapeMiddle = F(areaFunction?.AverageDiameter(0.38f, 0.68f) ?? 1.5f);
|
||||
var shapeFront = F(areaFunction?.AverageDiameter(0.68f, 0.96f) ?? 1.5f);
|
||||
var shapeMinimum = F(areaFunction?.MinimumDiameter ?? 0.6f);
|
||||
var reflectionEnergy = F(areaFunction is null ? 0.12f : MathF.Min(1, areaFunction.ReflectionCoefficients.Sum(reflection => MathF.Abs(reflection)) / Math.Max(1, areaFunction.ReflectionCoefficients.Count)));
|
||||
var aspiration = $"clip01({parameters.Expression(OwnerField(tractPath, "glottis/aspiration"), glottis?.Aspiration ?? 0.08f)})";
|
||||
var glottalSkew = $"clip01({parameters.Expression(OwnerField(tractPath, "glottis/skew"), glottis?.Skew ?? 0.42f)})";
|
||||
var injectionPosition = parameters.Expression(OwnerField(tractPath, "injection/position"), injection?.Position ?? tract.ConstrictionIndex);
|
||||
var injectionDiameter = parameters.Expression(OwnerField(tractPath, "injection/diameter"), injection?.Diameter ?? tract.ConstrictionDiameter);
|
||||
var injectionTurbulence = $"clip01({parameters.Expression(OwnerField(tractPath, "injection/turbulence"), injection?.Turbulence ?? tract.Turbulence)})";
|
||||
var injectionBurst = $"clip01({parameters.Expression(OwnerField(tractPath, "injection/burst"), injection?.Burst ?? 0)})";
|
||||
var injectionWidth = $"max(0.05, {parameters.Expression(OwnerField(tractPath, "injection/width"), injection?.Width ?? 1)})";
|
||||
|
||||
source.AppendLine($"{name}_tract_phase = os.phasor(1.0, {frequency});");
|
||||
source.AppendLine($"{name}_tract_tongue_pos = clip01({tongueIndex} / {F(sections)});");
|
||||
source.AppendLine($"{name}_tract_constriction_pos = clip01({constrictionIndex} / {F(sections)});");
|
||||
source.AppendLine($"{name}_tract_injection_pos = clip01({injectionPosition} / {F(sections)});");
|
||||
source.AppendLine($"{name}_tract_tongue_close = clip01((3.5 - {tongueDiameter}) / 3.5);");
|
||||
source.AppendLine($"{name}_tract_constriction_close = clip01((1.15 - {constrictionDiameter}) / 1.15);");
|
||||
source.AppendLine($"{name}_tract_injection_close = clip01((1.15 - {injectionDiameter}) / max(0.05, 1.15 * {injectionWidth}));");
|
||||
source.AppendLine($"{name}_tract_lip = clip01({lipOpening} / 2.5);");
|
||||
source.AppendLine($"{name}_tract_shape_back = {shapeBack};");
|
||||
source.AppendLine($"{name}_tract_shape_middle = {shapeMiddle};");
|
||||
|
|
@ -426,11 +437,17 @@ public static class FaustEmitter
|
|||
source.AppendLine($"{name}_tract_f1 = max(90.0, 260.0 + {name}_tract_lip * 720.0 - {name}_tract_tongue_close * 260.0 + ({name}_tract_shape_back - 1.35) * 210.0 - (1.0 - {name}_tract_shape_min) * 120.0 + {velum} * 120.0);");
|
||||
source.AppendLine($"{name}_tract_f2 = max(180.0, 820.0 + {name}_tract_tongue_pos * 1850.0 - {name}_tract_tongue_close * 640.0 + ({name}_tract_shape_middle - 1.5) * 360.0 - (1.0 - {name}_tract_lip) * 260.0);");
|
||||
source.AppendLine($"{name}_tract_f3 = max(500.0, 1900.0 + {name}_tract_constriction_pos * 2600.0 + {name}_tract_tongue_close * 700.0 + ({name}_tract_shape_front - 1.5) * 520.0);");
|
||||
source.AppendLine($"{name}_tract_lf = (sin(2.0 * ma.PI * {name}_tract_phase) - (0.15 + {tenseness} * 0.45) * sin(4.0 * ma.PI * {name}_tract_phase)) * {intensity} * (0.45 + 0.55 * pow(max(0.0, {tenseness}), 0.25));");
|
||||
source.AppendLine($"{name}_tract_aspiration = no.noise * {intensity} * (1.0 - sqrt(max(0.0, {tenseness}))) * (0.02 + 0.16 * {name}_tract_constriction_close);");
|
||||
source.AppendLine($"{name}_tract_frication = no.noise * {turbulence} * {name}_tract_constriction_close * {intensity} * (0.2 + 0.8 * {tenseness});");
|
||||
source.AppendLine($"{name}_tract_burst = no.noise * {name}_tract_constriction_close * exp(-age * (45.0 + {name}_tract_constriction_close * 120.0)) * 0.18;");
|
||||
source.AppendLine($"{name}_tract_lf_open = select2({name}_tract_phase < (0.42 + {glottalSkew} * 0.36), -0.28 * sin(ma.PI * ({name}_tract_phase - (0.42 + {glottalSkew} * 0.36)) / max(0.001, 1.0 - (0.42 + {glottalSkew} * 0.36))), sin(ma.PI * {name}_tract_phase / max(0.001, 0.42 + {glottalSkew} * 0.36)));");
|
||||
source.AppendLine($"{name}_tract_lf = ({name}_tract_lf_open - (0.12 + {tenseness} * 0.62) * sin(4.0 * ma.PI * {name}_tract_phase)) * {intensity} * (0.45 + 0.75 * pow(max(0.0, {tenseness}), 0.35));");
|
||||
source.AppendLine($"{name}_tract_aspiration = no.noise * {intensity} * {aspiration} * (1.0 - sqrt(max(0.0, {tenseness}))) * (0.08 + 0.22 * {name}_tract_constriction_close);");
|
||||
source.AppendLine($"{name}_tract_frication = no.noise * max({turbulence} * {name}_tract_constriction_close, {injectionTurbulence} * {name}_tract_injection_close) * {intensity} * (0.25 + 0.75 * {name}_tract_injection_pos) * (0.2 + 0.8 * {tenseness});");
|
||||
source.AppendLine($"{name}_tract_burst = no.noise * max({name}_tract_constriction_close * 0.18, {name}_tract_injection_close * {injectionBurst}) * exp(-age * (45.0 + max({name}_tract_constriction_close, {name}_tract_injection_close) * 120.0));");
|
||||
source.AppendLine($"{name}_tract_raw = ({name}_tract_lf + {name}_tract_aspiration + {name}_tract_frication + {name}_tract_burst) * (0.55 + 0.45 * abs({glottalReflection}));");
|
||||
if (tract.Propagation == TractPropagationMode.Waveguide && areaFunction is not null)
|
||||
{
|
||||
return TractWaveguideExpression(source, tract, areaFunction, name, glottalReflection, lipReflection, velum);
|
||||
}
|
||||
|
||||
source.AppendLine($"{name}_tract_oral = {name}_tract_raw * 0.18 + ({name}_tract_raw : fi.resonbp({name}_tract_f1, {name}_tract_q, 1.0)) * (0.75 + {name}_tract_lip * 0.65) + ({name}_tract_raw : fi.resonbp({name}_tract_f2, {name}_tract_q, 1.0)) * (0.85 + {name}_tract_tongue_close) + ({name}_tract_raw : fi.resonbp({name}_tract_f3, {name}_tract_q, 1.0)) * (0.35 + {name}_tract_constriction_close);");
|
||||
if (hasNose)
|
||||
{
|
||||
|
|
@ -444,6 +461,78 @@ public static class FaustEmitter
|
|||
return $"{name}_tract_radiated";
|
||||
}
|
||||
|
||||
private static string TractWaveguideExpression(
|
||||
StringBuilder source,
|
||||
VocalTract tract,
|
||||
TractAreaFunction areaFunction,
|
||||
string name,
|
||||
string glottalReflection,
|
||||
string lipReflection,
|
||||
string velum)
|
||||
{
|
||||
var sections = areaFunction.Sections;
|
||||
var reflections = areaFunction.ReflectionCoefficients;
|
||||
var loss = F(Math.Clamp(tract.WaveguideLoss, 0, 1));
|
||||
source.AppendLine($"{name}_wg_loss = {loss};");
|
||||
source.AppendLine($"{name}_wg_substeps = {Math.Max(1, tract.Substeps)};");
|
||||
for (var i = 0; i < reflections.Count; i++)
|
||||
{
|
||||
source.AppendLine($"{name}_wg_k_{i + 1} = {F(reflections[i])};");
|
||||
}
|
||||
|
||||
var nasal = tract.Nasal is { AreaFunction: { } nasalShape } ? tract.Nasal : null;
|
||||
var junction = nasal is null ? -1 : Math.Clamp(nasal.JunctionIndex, 1, sections - 2);
|
||||
source.AppendLine($"{name}_wg_r_0 = ({name}_tract_raw + {name}_wg_l_0 * {glottalReflection}) : mem;");
|
||||
source.AppendLine($"{name}_wg_l_{sections - 1} = ({name}_wg_r_{sections - 1} * {lipReflection}) : mem;");
|
||||
for (var i = 1; i < sections; i++)
|
||||
{
|
||||
if (i == junction)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
source.AppendLine($"{name}_wg_scatter_{i} = {name}_wg_k_{i} * ({name}_wg_r_{i - 1} + {name}_wg_l_{i});");
|
||||
source.AppendLine($"{name}_wg_r_{i} = (({name}_wg_r_{i - 1} - {name}_wg_scatter_{i}) * {name}_wg_loss) : mem;");
|
||||
source.AppendLine($"{name}_wg_l_{i - 1} = (({name}_wg_l_{i} + {name}_wg_scatter_{i}) * {name}_wg_loss) : mem;");
|
||||
}
|
||||
|
||||
var noseOutput = "0.0";
|
||||
if (nasal is not null && nasal.AreaFunction is { } nasalFunction)
|
||||
{
|
||||
var noseSections = nasalFunction.Sections;
|
||||
var noseReflections = nasalFunction.ReflectionCoefficients;
|
||||
var noseLoss = F(Math.Clamp(nasal.Loss, 0, 1));
|
||||
var noseReflection = F(nasal.Reflection);
|
||||
var leftArea = F(areaFunction.Areas[Math.Clamp(junction - 1, 0, areaFunction.Areas.Count - 1)]);
|
||||
var rightArea = F(areaFunction.Areas[Math.Clamp(junction, 0, areaFunction.Areas.Count - 1)]);
|
||||
source.AppendLine($"{name}_nose_loss = {noseLoss};");
|
||||
for (var i = 0; i < noseReflections.Count; i++)
|
||||
{
|
||||
source.AppendLine($"{name}_nose_k_{i + 1} = {F(noseReflections[i])};");
|
||||
}
|
||||
source.AppendLine($"{name}_nose_area = max(0.000001, (0.01 + {velum} * 0.39) * (0.01 + {velum} * 0.39));");
|
||||
source.AppendLine($"{name}_nose_sum = {leftArea} + {rightArea} + {name}_nose_area;");
|
||||
source.AppendLine($"{name}_nose_reflect_left = (2.0 * {leftArea} - {name}_nose_sum) / {name}_nose_sum;");
|
||||
source.AppendLine($"{name}_nose_reflect_right = (2.0 * {rightArea} - {name}_nose_sum) / {name}_nose_sum;");
|
||||
source.AppendLine($"{name}_nose_reflect_nose = (2.0 * {name}_nose_area - {name}_nose_sum) / {name}_nose_sum;");
|
||||
source.AppendLine($"{name}_wg_l_{junction - 1} = (({name}_nose_reflect_left * {name}_wg_r_{junction - 1}) + (1.0 + {name}_nose_reflect_left) * ({name}_wg_l_{junction} + {name}_nose_l_0)) * {name}_wg_loss : mem;");
|
||||
source.AppendLine($"{name}_wg_r_{junction} = (({name}_nose_reflect_right * {name}_wg_l_{junction}) + (1.0 + {name}_nose_reflect_right) * ({name}_wg_r_{junction - 1} + {name}_nose_l_0)) * {name}_wg_loss : mem;");
|
||||
source.AppendLine($"{name}_nose_r_0 = (({name}_nose_reflect_nose * {name}_nose_l_0) + (1.0 + {name}_nose_reflect_nose) * ({name}_wg_l_{junction} + {name}_wg_r_{junction - 1})) * {name}_nose_loss : mem;");
|
||||
source.AppendLine($"{name}_nose_l_{noseSections - 1} = ({name}_nose_r_{noseSections - 1} * {noseReflection}) : mem;");
|
||||
for (var i = 1; i < noseSections; i++)
|
||||
{
|
||||
source.AppendLine($"{name}_nose_scatter_{i} = {name}_nose_k_{i} * ({name}_nose_r_{i - 1} + {name}_nose_l_{i});");
|
||||
source.AppendLine($"{name}_nose_r_{i} = (({name}_nose_r_{i - 1} - {name}_nose_scatter_{i}) * {name}_nose_loss) : mem;");
|
||||
source.AppendLine($"{name}_nose_l_{i - 1} = (({name}_nose_l_{i} + {name}_nose_scatter_{i}) * {name}_nose_loss) : mem;");
|
||||
}
|
||||
source.AppendLine($"{name}_tract_nose_waveguide = {name}_nose_r_{noseSections - 1};");
|
||||
noseOutput = $"{name}_tract_nose_waveguide";
|
||||
}
|
||||
|
||||
source.AppendLine($"{name}_tract_oral_waveguide = {name}_wg_r_{sections - 1} + {name}_wg_l_{sections - 1} * 0.05;");
|
||||
source.AppendLine($"{name}_tract_radiated = {name}_tract_oral_waveguide * (0.65 + 0.35 * abs({lipReflection})) + {noseOutput};");
|
||||
return $"{name}_tract_radiated";
|
||||
}
|
||||
|
||||
private static void EmitOperatorGraph(StringBuilder source, Playback playback, OperatorGraph graph, string name, ParameterMap parameters, List<string> warnings)
|
||||
{
|
||||
if (graph.Operators.Count == 0)
|
||||
|
|
|
|||
|
|
@ -183,6 +183,36 @@ public sealed record TractAreaFunction(IReadOnlyList<float> Diameters)
|
|||
|
||||
public sealed record TractShape(string Name, TractAreaFunction AreaFunction);
|
||||
|
||||
public sealed record GlottalSource(
|
||||
string Name = "",
|
||||
float Intensity = 0.72f,
|
||||
float Tenseness = 0.6f,
|
||||
float Aspiration = 0.08f,
|
||||
float Reflection = 0.75f,
|
||||
float Skew = 0.42f);
|
||||
|
||||
public sealed record TractInjection(
|
||||
string Name = "",
|
||||
float Position = 32,
|
||||
float Diameter = 1,
|
||||
float Turbulence = 0,
|
||||
float Burst = 0,
|
||||
float Width = 1);
|
||||
|
||||
public enum TractPropagationMode
|
||||
{
|
||||
Resonator,
|
||||
Waveguide
|
||||
}
|
||||
|
||||
public sealed record NasalBranch(
|
||||
string Name = "",
|
||||
TractAreaFunction? AreaFunction = null,
|
||||
int JunctionIndex = 17,
|
||||
float Velum = 0.01f,
|
||||
float Reflection = -0.85f,
|
||||
float Loss = 0.999f);
|
||||
|
||||
public sealed record Modulator(
|
||||
ModTarget Target,
|
||||
ModWaveform Waveform = ModWaveform.Sine,
|
||||
|
|
@ -237,7 +267,13 @@ public sealed record VocalTract(
|
|||
float LipOpening = 1.5f,
|
||||
float GlottalReflection = 0.75f,
|
||||
float LipReflection = -0.85f,
|
||||
TractAreaFunction? AreaFunction = null);
|
||||
TractAreaFunction? AreaFunction = null,
|
||||
GlottalSource? Glottis = null,
|
||||
TractInjection? Injection = null,
|
||||
NasalBranch? Nasal = null,
|
||||
TractPropagationMode Propagation = TractPropagationMode.Resonator,
|
||||
float WaveguideLoss = 0.999f,
|
||||
int Substeps = 1);
|
||||
|
||||
public sealed record PatchParameter(
|
||||
string Path,
|
||||
|
|
@ -411,6 +447,9 @@ public sealed record SynthPatch
|
|||
public IReadOnlyList<HarmonicBank> HarmonicBanks { get; init; } = Array.Empty<HarmonicBank>();
|
||||
public IReadOnlyList<SpectralBank> SpectralBanks { get; init; } = Array.Empty<SpectralBank>();
|
||||
public IReadOnlyList<TractShape> TractShapes { get; init; } = Array.Empty<TractShape>();
|
||||
public IReadOnlyList<GlottalSource> GlottalSources { get; init; } = Array.Empty<GlottalSource>();
|
||||
public IReadOnlyList<TractInjection> TractInjections { get; init; } = Array.Empty<TractInjection>();
|
||||
public IReadOnlyList<NasalBranch> NasalBranches { get; init; } = Array.Empty<NasalBranch>();
|
||||
public IReadOnlyList<OperatorGraph> OperatorGraphs { get; init; } = Array.Empty<OperatorGraph>();
|
||||
public IReadOnlyList<ControlLane> Controls { get; init; } = Array.Empty<ControlLane>();
|
||||
public IReadOnlyList<PatchParameter> Parameters { get; init; } = Array.Empty<PatchParameter>();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ public static class PatchScript
|
|||
private readonly List<SpectralBank> _spectralBanks = [];
|
||||
private readonly List<TractShape> _tractShapes = [];
|
||||
private readonly Dictionary<string, TractShape> _tractShapesByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<GlottalSource> _glottalSources = [];
|
||||
private readonly Dictionary<string, GlottalSource> _glottalSourcesByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<TractInjection> _tractInjections = [];
|
||||
private readonly Dictionary<string, TractInjection> _tractInjectionsByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<NasalBranch> _nasalBranches = [];
|
||||
private readonly Dictionary<string, NasalBranch> _nasalBranchesByName = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, string> _defaults = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Dictionary<string, Dictionary<string, string>> _layerDefaults = new(StringComparer.OrdinalIgnoreCase);
|
||||
private PendingOperatorGraph? _pendingOperatorGraph;
|
||||
|
|
@ -60,6 +66,9 @@ public static class PatchScript
|
|||
HarmonicBanks = _harmonicBanks,
|
||||
SpectralBanks = _spectralBanks,
|
||||
TractShapes = _tractShapes,
|
||||
GlottalSources = _glottalSources,
|
||||
TractInjections = _tractInjections,
|
||||
NasalBranches = _nasalBranches,
|
||||
OperatorGraphs = _operatorGraphs,
|
||||
Controls = _controls,
|
||||
Parameters = _parameters,
|
||||
|
|
@ -115,6 +124,18 @@ public static class PatchScript
|
|||
FlushPendingOperatorGraph();
|
||||
AddTractShape(fields, line);
|
||||
break;
|
||||
case "glottis":
|
||||
FlushPendingOperatorGraph();
|
||||
AddGlottalSource(fields, line);
|
||||
break;
|
||||
case "tract_injection":
|
||||
FlushPendingOperatorGraph();
|
||||
AddTractInjection(fields, line);
|
||||
break;
|
||||
case "nasal_branch":
|
||||
FlushPendingOperatorGraph();
|
||||
AddNasalBranch(fields, line);
|
||||
break;
|
||||
case "voice":
|
||||
FlushPendingOperatorGraph();
|
||||
Voices.Add(ParseVoice(ExpandVoiceFields(fields, line), VoicePath(Voices.Count), line));
|
||||
|
|
@ -286,6 +307,63 @@ public static class PatchScript
|
|||
_tractShapesByName[name] = shape;
|
||||
}
|
||||
|
||||
private void AddGlottalSource(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_glottalSourcesByName.ContainsKey(name))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate glottis `{name}`");
|
||||
}
|
||||
|
||||
var glottis = new GlottalSource(
|
||||
name,
|
||||
GetBoundFloat(fields, line, 0.72f, $"/glottis/{_glottalSources.Count}/intensity", "intensity", "pressure"),
|
||||
GetBoundFloat(fields, line, 0.6f, $"/glottis/{_glottalSources.Count}/tenseness", "tenseness", "tense"),
|
||||
GetBoundFloat(fields, line, 0.08f, $"/glottis/{_glottalSources.Count}/aspiration", "aspiration", "breath"),
|
||||
GetBoundFloat(fields, line, 0.75f, $"/glottis/{_glottalSources.Count}/reflection", "reflection", "glottal_reflection", "gr"),
|
||||
GetBoundFloat(fields, line, 0.42f, $"/glottis/{_glottalSources.Count}/skew", "skew", "open_phase"));
|
||||
_glottalSources.Add(glottis);
|
||||
_glottalSourcesByName[name] = glottis;
|
||||
}
|
||||
|
||||
private void AddTractInjection(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_tractInjectionsByName.ContainsKey(name))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate tract injection `{name}`");
|
||||
}
|
||||
|
||||
var injection = new TractInjection(
|
||||
name,
|
||||
GetBoundFloat(fields, line, 32, $"/tract_injections/{_tractInjections.Count}/position", "position", "index", "constriction_index", "ci"),
|
||||
GetBoundFloat(fields, line, 1, $"/tract_injections/{_tractInjections.Count}/diameter", "diameter", "opening", "constriction_diameter", "cd"),
|
||||
GetBoundFloat(fields, line, 0, $"/tract_injections/{_tractInjections.Count}/turbulence", "turbulence", "frication"),
|
||||
GetBoundFloat(fields, line, 0, $"/tract_injections/{_tractInjections.Count}/burst", "burst", "transient"),
|
||||
GetBoundFloat(fields, line, 1, $"/tract_injections/{_tractInjections.Count}/width", "width"));
|
||||
_tractInjections.Add(injection);
|
||||
_tractInjectionsByName[name] = injection;
|
||||
}
|
||||
|
||||
private void AddNasalBranch(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var name = Required(fields, "name", line);
|
||||
if (_nasalBranchesByName.ContainsKey(name))
|
||||
{
|
||||
throw new PatchScriptException(line, $"duplicate nasal branch `{name}`");
|
||||
}
|
||||
|
||||
var branch = new NasalBranch(
|
||||
name,
|
||||
ParseTractAreaFunction(fields, line),
|
||||
GetBoundInt(fields, line, 17, $"/nasal_branches/{_nasalBranches.Count}/junction", "junction", "junction_index", "at"),
|
||||
GetBoundFloat(fields, line, 0.01f, $"/nasal_branches/{_nasalBranches.Count}/velum", "velum", "opening"),
|
||||
GetBoundFloat(fields, line, -0.85f, $"/nasal_branches/{_nasalBranches.Count}/reflection", "reflection", "lip_reflection"),
|
||||
GetBoundFloat(fields, line, 0.999f, $"/nasal_branches/{_nasalBranches.Count}/loss", "loss"));
|
||||
_nasalBranches.Add(branch);
|
||||
_nasalBranchesByName[name] = branch;
|
||||
}
|
||||
|
||||
private Dictionary<string, string> ExpandVoiceFields(Dictionary<string, string> fields, int line)
|
||||
{
|
||||
var expanded = new Dictionary<string, string>(_defaults, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -527,6 +605,9 @@ public static class PatchScript
|
|||
|
||||
var voice = ParseVoice(voiceFields, ownerPath, line);
|
||||
var areaFunction = ParseTractAreaFunctionReference(fields, line);
|
||||
var glottis = ParseGlottalSourceReference(fields, ownerPath, line);
|
||||
var injection = ParseTractInjectionReference(fields, ownerPath, line);
|
||||
var nasal = ParseNasalBranchReference(fields, ownerPath, line);
|
||||
var sections = GetBoundInt(fields, line, areaFunction?.Sections ?? 44, OwnerField(ownerPath, "tract/sections"), "sections", "cells");
|
||||
if (sections < 4)
|
||||
{
|
||||
|
|
@ -536,7 +617,7 @@ public static class PatchScript
|
|||
{
|
||||
throw new PatchScriptException(line, "tract shape section count must match tract sections");
|
||||
}
|
||||
var noseSections = GetBoundInt(fields, line, 28, OwnerField(ownerPath, "tract/nose_sections"), "nose_sections", "nose_cells");
|
||||
var noseSections = GetBoundInt(fields, line, nasal?.AreaFunction?.Sections ?? 28, OwnerField(ownerPath, "tract/nose_sections"), "nose_sections", "nose_cells");
|
||||
if (noseSections < 0)
|
||||
{
|
||||
throw new PatchScriptException(line, "tract nose_sections must be non-negative");
|
||||
|
|
@ -547,18 +628,24 @@ public static class PatchScript
|
|||
Tract = new VocalTract(
|
||||
sections,
|
||||
noseSections,
|
||||
GetBoundFloat(fields, line, 0.72f, OwnerField(ownerPath, "tract/intensity"), "intensity", "pressure"),
|
||||
GetBoundFloat(fields, line, 0.6f, OwnerField(ownerPath, "tract/tenseness"), "tenseness", "tense"),
|
||||
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"),
|
||||
GetBoundFloat(fields, line, 12.9f, OwnerField(ownerPath, "tract/tongue_index"), "tongue_index", "tongue", "ti"),
|
||||
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"),
|
||||
GetBoundFloat(fields, line, 32, OwnerField(ownerPath, "tract/constriction_index"), "constriction_index", "ci"),
|
||||
GetBoundFloat(fields, line, 1, OwnerField(ownerPath, "tract/constriction_diameter"), "constriction_diameter", "cd"),
|
||||
GetBoundFloat(fields, line, 0, OwnerField(ownerPath, "tract/turbulence"), "turbulence", "frication"),
|
||||
GetBoundFloat(fields, line, injection?.Position ?? 32, OwnerField(ownerPath, "tract/constriction_index"), "constriction_index", "ci"),
|
||||
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, 0.75f, OwnerField(ownerPath, "tract/glottal_reflection"), "glottal_reflection", "gr"),
|
||||
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)
|
||||
areaFunction,
|
||||
glottis,
|
||||
injection,
|
||||
nasal,
|
||||
ParseTractPropagationMode(GetAny(fields, ["propagation", "model"], "resonator"), line),
|
||||
GetBoundFloat(fields, line, 0.999f, OwnerField(ownerPath, "tract/waveguide_loss"), "waveguide_loss", "loss"),
|
||||
GetBoundInt(fields, line, 1, OwnerField(ownerPath, "tract/substeps"), "substeps", "steps"))
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -967,6 +1054,88 @@ public static class PatchScript
|
|||
return shape.AreaFunction;
|
||||
}
|
||||
|
||||
private GlottalSource? ParseGlottalSourceReference(IReadOnlyDictionary<string, string> fields, string ownerPath, int line)
|
||||
{
|
||||
var hasInlineGlottis = HasAny(fields, "aspiration", "breath", "skew", "open_phase");
|
||||
var hasNamedGlottis = TryGetAny(fields, ["glottis", "source"], out var glottisName);
|
||||
if (!hasNamedGlottis && !hasInlineGlottis)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
GlottalSource? namedGlottis = null;
|
||||
if (hasNamedGlottis && !_glottalSourcesByName.TryGetValue(glottisName, out namedGlottis))
|
||||
{
|
||||
throw new PatchScriptException(line, $"unknown glottis `{glottisName}`");
|
||||
}
|
||||
|
||||
var fallback = hasNamedGlottis ? namedGlottis! : new GlottalSource();
|
||||
return new GlottalSource(
|
||||
hasNamedGlottis ? glottisName : "",
|
||||
GetBoundFloat(fields, line, fallback.Intensity, OwnerField(ownerPath, "tract/glottis/intensity"), "intensity", "pressure"),
|
||||
GetBoundFloat(fields, line, fallback.Tenseness, OwnerField(ownerPath, "tract/glottis/tenseness"), "tenseness", "tense"),
|
||||
GetBoundFloat(fields, line, fallback.Aspiration, OwnerField(ownerPath, "tract/glottis/aspiration"), "aspiration", "breath"),
|
||||
GetBoundFloat(fields, line, fallback.Reflection, OwnerField(ownerPath, "tract/glottis/reflection"), "glottal_reflection", "gr"),
|
||||
GetBoundFloat(fields, line, fallback.Skew, OwnerField(ownerPath, "tract/glottis/skew"), "skew", "open_phase"));
|
||||
}
|
||||
|
||||
private TractInjection? ParseTractInjectionReference(IReadOnlyDictionary<string, string> fields, string ownerPath, int line)
|
||||
{
|
||||
var hasInlineInjection = HasAny(fields, "burst", "transient", "width");
|
||||
var hasNamedInjection = TryGetAny(fields, ["injection", "tract_injection"], out var injectionName);
|
||||
if (!hasNamedInjection && !hasInlineInjection)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
TractInjection? namedInjection = null;
|
||||
if (hasNamedInjection && !_tractInjectionsByName.TryGetValue(injectionName, out namedInjection))
|
||||
{
|
||||
throw new PatchScriptException(line, $"unknown tract injection `{injectionName}`");
|
||||
}
|
||||
|
||||
var fallback = hasNamedInjection ? namedInjection! : new TractInjection();
|
||||
return new TractInjection(
|
||||
hasNamedInjection ? injectionName : "",
|
||||
GetBoundFloat(fields, line, fallback.Position, OwnerField(ownerPath, "tract/injection/position"), "position", "constriction_index", "ci"),
|
||||
GetBoundFloat(fields, line, fallback.Diameter, OwnerField(ownerPath, "tract/injection/diameter"), "diameter", "constriction_diameter", "cd"),
|
||||
GetBoundFloat(fields, line, fallback.Turbulence, OwnerField(ownerPath, "tract/injection/turbulence"), "turbulence", "frication"),
|
||||
GetBoundFloat(fields, line, fallback.Burst, OwnerField(ownerPath, "tract/injection/burst"), "burst", "transient"),
|
||||
GetBoundFloat(fields, line, fallback.Width, OwnerField(ownerPath, "tract/injection/width"), "width"));
|
||||
}
|
||||
|
||||
private NasalBranch? ParseNasalBranchReference(IReadOnlyDictionary<string, string> fields, string ownerPath, int line)
|
||||
{
|
||||
var hasInlineNasal = HasAny(fields, "nose_diameters", "nose_areas", "nose_junction");
|
||||
var hasNamedNasal = TryGetAny(fields, ["nasal_branch", "nasal_shape"], out var nasalName);
|
||||
if (!hasNamedNasal && !hasInlineNasal)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
NasalBranch? namedNasal = null;
|
||||
if (hasNamedNasal && !_nasalBranchesByName.TryGetValue(nasalName, out namedNasal))
|
||||
{
|
||||
throw new PatchScriptException(line, $"unknown nasal branch `{nasalName}`");
|
||||
}
|
||||
|
||||
var fallback = hasNamedNasal ? namedNasal! : new NasalBranch(AreaFunction: new TractAreaFunction([0.01f, 0.6f, 1.2f, 1.6f]));
|
||||
var areaFunction = fallback.AreaFunction;
|
||||
if (TryGetAny(fields, ["nose_diameters"], out var diameters))
|
||||
{
|
||||
areaFunction = new TractAreaFunction(ParseFloatList(diameters, line, "nose_diameters").ToArray());
|
||||
}
|
||||
if (TryGetAny(fields, ["nose_areas"], out var areas))
|
||||
{
|
||||
areaFunction = TractAreaFunction.FromAreas(ParseFloatList(areas, line, "nose_areas").ToArray());
|
||||
}
|
||||
|
||||
return new NasalBranch(
|
||||
hasNamedNasal ? nasalName : "",
|
||||
areaFunction,
|
||||
GetBoundInt(fields, line, fallback.JunctionIndex, OwnerField(ownerPath, "tract/nasal/junction"), "nose_junction", "junction", "junction_index"),
|
||||
GetBoundFloat(fields, line, fallback.Velum, OwnerField(ownerPath, "tract/nasal/velum"), "velum", "nose", "nasal"),
|
||||
GetBoundFloat(fields, line, fallback.Reflection, OwnerField(ownerPath, "tract/nasal/reflection"), "nose_reflection"),
|
||||
GetBoundFloat(fields, line, fallback.Loss, OwnerField(ownerPath, "tract/nasal/loss"), "nose_loss"));
|
||||
}
|
||||
|
||||
private static TractAreaFunction ParseTractAreaFunction(IReadOnlyDictionary<string, string> fields, int line)
|
||||
{
|
||||
var hasDiameters = TryGetAny(fields, ["diameters", "diameter"], out var diametersText);
|
||||
|
|
@ -1404,6 +1573,9 @@ 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",
|
||||
"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",
|
||||
"v" or "voice" => "voice",
|
||||
"tract" or "vt" or "tractvoice" or "tract_voice" => "tract",
|
||||
"opgraph" or "ops" or "operators" => "opgraph",
|
||||
|
|
@ -1495,6 +1667,13 @@ public static class PatchScript
|
|||
_ => target.ToString().ToLowerInvariant()
|
||||
};
|
||||
|
||||
private static TractPropagationMode ParseTractPropagationMode(string value, int line) => value.ToLowerInvariant() switch
|
||||
{
|
||||
"resonator" or "proxy" or "formant" => TractPropagationMode.Resonator,
|
||||
"waveguide" or "kl" or "kelly-lochbaum" or "kelly_lochbaum" or "tube" => TractPropagationMode.Waveguide,
|
||||
_ => throw new PatchScriptException(line, $"unknown tract propagation mode `{value}`")
|
||||
};
|
||||
|
||||
private static string Required(IReadOnlyDictionary<string, string> fields, string key, int line) =>
|
||||
fields.TryGetValue(key, out var value) ? value : throw new PatchScriptException(line, $"missing `{key}`");
|
||||
|
||||
|
|
|
|||
|
|
@ -63,18 +63,21 @@ public static class PinkTromboneReference
|
|||
new("tract_voice_authority", "voice.Tract", "Pink Trombone pressure now lowers through a tract treatment on an ordinary AquaSynth voice."),
|
||||
new("tract_area_function", "tract_shape diameters", "AquaSynth can now author reusable section diameter/area functions for tract voices."),
|
||||
new("diameter_to_reflection_coefficients", "TractAreaFunction.ReflectionCoefficients", "AquaSynth derives adjacent-section reflection coefficients from squared diameters as a reusable primitive."),
|
||||
new("glottal_source_primitive", "glottis", "AquaSynth can author reusable glottal excitation controls for tract voices."),
|
||||
new("positioned_injection_primitive", "tract_injection", "AquaSynth can author reusable constriction-position noise/burst injection controls."),
|
||||
new("main_tract_waveguide_cells", "waveguide propagation over tract_shape sections", "AquaSynth can emit an oral bidirectional tube from derived section reflection coefficients."),
|
||||
new("reflection_coefficients_applied_to_waveguide", "generated scattering junctions", "Derived reflection coefficients feed generated right/left wave scattering equations."),
|
||||
new("nose_waveguide_cells", "nasal_branch", "AquaSynth can author a nasal branch as its own diameter/area tube."),
|
||||
new("nose_junction", "generated three-way junction", "Waveguide lowering can emit a velum-controlled oral/nasal junction from local areas."),
|
||||
new("runtime_controls", "/pink/frequency,/pink/intensity,/pink/tenseness,/pink/tongue/index,/pink/tongue/diameter,/pink/velum,/pink/turbulence", "AquaSynth can expose stable runtime parameter paths."),
|
||||
new("glottal_pitch_pressure_proxy", "tract LF-style source", "AquaSynth can drive pitch/loudness-like controls without recompiling."),
|
||||
new("turbulence_proxy", "position-aware frication controls", "The tract voice has constriction index/diameter and turbulence controls."),
|
||||
new("nasal_proxy", "velum-controlled nasal resonator", "The tract voice has a velum/nasal output lane.")
|
||||
],
|
||||
[
|
||||
new("main_tract_waveguide_cells", "44 bidirectional sections", "No AquaSynth DSL authority owns arrays of right/left traveling wave state per tract section."),
|
||||
new("nose_waveguide_cells", "28 bidirectional sections", "The current DSL has no nasal branch delay-line graph or velum-controlled three-way junction."),
|
||||
new("reflection_coefficients_applied_to_waveguide", "per-block area reflection update", "AquaSynth can derive reflection coefficients, but the current Faust proxy does not apply them to bidirectional waveguide propagation."),
|
||||
new("twice_rate_tract_stepping", "two tract steps per audio sample", "AquaSynth voice graphs do not express a subgraph with its own stepping rate."),
|
||||
new("positioned_turbulence_injection", "noise injected into neighboring cells", "The current noise field is source/color pressure, not a positioned tract injection event."),
|
||||
new("closure_release_transients", "obstruction release impulse", "AquaSynth envelopes can shape amplitude, but they do not observe obstruction state and emit release transients."),
|
||||
new("positioned_turbulence_applied_to_waveguide_cells", "noise injected into neighboring cells", "AquaSynth can author positioned injection controls, but the current Faust proxy does not inject into bidirectional waveguide cell state."),
|
||||
new("stateful_closure_release_transients", "obstruction release impulse", "AquaSynth can author burst pressure, but it does not yet observe prior obstruction state and emit PT-style release transients."),
|
||||
new("lf_glottal_exactness", "Pink Trombone LF-style coefficients", "The proxy uses ordinary oscillators/noise, not the LF coefficient path from tenseness.")
|
||||
],
|
||||
"This is a deliberately non-passing rebuild: it keeps the current source-filter proxy parseable while naming the tract-DSP authority AquaSynth lacks.");
|
||||
|
|
|
|||
Loading…
Reference in a new issue