diff --git a/docs/pink-trombone-parity.md b/docs/pink-trombone-parity.md index 3674bfe..b682d82 100644 --- a/docs/pink-trombone-parity.md +++ b/docs/pink-trombone-parity.md @@ -3,9 +3,10 @@ ## Objective Use Pink Trombone as old-school speech parity pressure, not as a vague mascot -for "more vocal knobs." The current AquaSynth speech-loss surface is a -source/filter proxy. Pink Trombone is a moving vocal-tract waveguide. Those are -not the same machine. +for "more vocal knobs." The current AquaSynth tract voice is a tract-shaped +voice treatment with Pink Trombone-style controls. Pink Trombone itself is still +a moving vocal-tract waveguide. Those are related machines, but not the same +machine. This packet exists so the mismatch stays inspectable. @@ -50,6 +51,12 @@ and emits a transient when a closure opens. Current AquaSynth can express: - runtime parameters with stable paths; +- a `tract` voice command owned by `Voice.Tract`; +- Pink Trombone-shaped controls for intensity, tenseness, tongue body, + constriction, velum/nasal opening, turbulence, lip opening, and end + reflections; +- a Faust-lowered tract voice proxy with LF-style excitation, aspiration, + frication, oral resonators, and a velum-controlled nasal lane; - oscillator/noise sources; - ADSR and staged rate/level envelopes; - low/high/band/notch filters; @@ -57,7 +64,7 @@ Current AquaSynth can express: - patch-level and voice-local modulation; - compiled Faust control sweeps through `/speech/output/N`. -Current AquaSynth cannot express: +Current AquaSynth cannot exactly express: - a 44-cell bidirectional tract waveguide; - independent right/left traveling-wave state arrays; @@ -70,30 +77,36 @@ Current AquaSynth cannot express: - obstruction-state release transients; - exact Pink Trombone LF glottal coefficient updates. -## First Parity Rung +## Current Parity Rung -The first committed rung is structural, not audio: +The current committed rung is an expressive tract voice, not exact Pink +Trombone anatomy: - `PinkTromboneReference.ToReferencePatch()` records the source, tract features, and relevant controls. - `ReferenceRebuildCatalog.PinkTromboneRebuilds` contains the current - AquaSynth source-filter proxy as a deliberately non-passing rebuild. -- The proxy script parses and emits Faust, but its missing features explicitly - name the waveguide authorities AquaSynth does not own. + AquaSynth tract-voice proxy as a deliberately non-passing rebuild. +- The `tract` DSL command parses into an ordinary `Voice` with `Voice.Tract`, + so this remains a voice with a very expressive tract treatment. +- The proxy script parses and emits Faust with live controls, but its missing + features explicitly name the waveguide authorities AquaSynth does not own. +- `tools/vocal-tract-playground` exposes the same control surface for fast + knob-twiddling through a small WebAudio witness. - `PinkTromboneReferenceDeclaresMissingWaveguideAuthority` prevents the proxy from being mistaken for real tract parity. -That is the correct failure for now. A failed exactness claim is better than a -successful little lie with sliders. +That is the correct shape for now. It should be fun to touch, but still honest +about the parts of Pink Trombone it cannot claim. ## Next Cut Do not add another formant workaround. The next coherent implementation is one of these: -1. Add a dedicated tract-DSP model to AquaSynth.Faust/Core: typed tract sections, - diameter curves, reflection calculation, glottal source, nasal branch, and a - Faust emitter for that structure. +1. Promote `Voice.Tract` from tract-shaped proxy lowering to a dedicated tract + DSP model in AquaSynth.Faust/Core: typed tract sections, diameter curves, + reflection calculation, glottal source, nasal branch, and a Faust emitter for + that structure. 2. Add a test-only Pink Trombone oracle renderer and compare AquaSynth's first tract-DSP candidate against fixed vowel/constriction fixtures. diff --git a/src/AquaSynth.Core/BuiltInScripts.cs b/src/AquaSynth.Core/BuiltInScripts.cs index ce571d5..7e95f55 100644 --- a/src/AquaSynth.Core/BuiltInScripts.cs +++ b/src/AquaSynth.Core/BuiltInScripts.cs @@ -621,39 +621,28 @@ public static class BuiltInScripts param name=velum path=/pink/velum default=0.01 min=0.01 max=0.4 step=0.001 unit=diameter param name=constriction_index path=/pink/constriction/index default=32 min=0 max=44 step=0.001 unit=cell param name=constriction_diameter path=/pink/constriction/diameter default=1 min=-1 max=4 step=0.001 unit=diameter + param name=turbulence path=/pink/turbulence default=0.18 min=0 max=1 step=0.001 + param name=lip_opening path=/pink/lip/opening default=1.5 min=0.35 max=2.5 step=0.001 unit=diameter + param name=glottal_reflection path=/pink/glottal/reflection default=0.75 min=-0.95 max=0.95 step=0.001 + param name=lip_reflection path=/pink/lip/reflection default=-0.85 min=-0.98 max=0.1 step=0.001 - defaults - wave=saw + tract freq=@/pink/frequency - gain=@/pink/intensity + gain=0.7 attack=0.004 - sustain=0.18 - decay=0.08 - lpf=0.64 - lpf_q=@/pink/tenseness - tremolo=0.02 - tremolo_hz=6 - formants=520:90:0.8,1250:170:1,2600:320:0.45 - formant_mix=0.42 - - voice - - voice - wave=noise - freq=2500 - gain=0.04 - noise=0.8 - hpf=0.45 - lpf=0.7 - formants=1800:220:0.8,3600:480:0.55 - formant_mix=0.35 - - voice - wave=sine - freq=360 - gain=@/pink/velum - formants=300:80:1,900:180:0.45 - formant_mix=0.55 + sustain=0.35 + decay=0.12 + intensity=@/pink/intensity + tenseness=@/pink/tenseness + tongue_index=@/pink/tongue/index + tongue_diameter=@/pink/tongue/diameter + velum=@/pink/velum + constriction_index=@/pink/constriction/index + constriction_diameter=@/pink/constriction/diameter + turbulence=@/pink/turbulence + lip=@/pink/lip/opening + glottal_reflection=@/pink/glottal/reflection + lip_reflection=@/pink/lip/reflection """; public const string Dx7StyleAlgorithm32AdditiveOrgan = """ diff --git a/src/AquaSynth.Core/FaustExport.cs b/src/AquaSynth.Core/FaustExport.cs index 9457642..e73dc6d 100644 --- a/src/AquaSynth.Core/FaustExport.cs +++ b/src/AquaSynth.Core/FaustExport.cs @@ -181,7 +181,10 @@ public static class FaustEmitter var frequency = $"(({baseFreq}){vibrato}) * {arpeggio} * pow(2.0, patch_mod_pitch + {pitch})"; var dutyExpression = $"clip01({parameters.Expression(OwnerField(ownerPath, "osc/duty"), voice.Oscillator.Duty)} + {parameters.Expression(OwnerField(ownerPath, "duty/ramp"), voice.Duty.RampPerSecond)} * age + patch_mod_duty + {duty})"; var fmIndex = $"max(0.0, {parameters.Expression(OwnerField(ownerPath, "fm/index"), voice.Fm.Index)} + patch_mod_fm_index + {fmIndexMod}) * {FmDecay(parameters.Expression(OwnerField(ownerPath, "fm/decay"), voice.Fm.IndexDecaySeconds), voice.Fm.IndexDecaySeconds, parameters.IsBound(OwnerField(ownerPath, "fm/decay")))}"; - var oscillator = oscillatorOverride ?? OscillatorExpression(patch, voice, ownerPath, frequency, dutyExpression, fmIndex, parameters); + var oscillator = oscillatorOverride ?? + (voice.Tract is { } tract + ? TractExpression(source, tract, ownerPath, name, frequency, noteGate, parameters) + : OscillatorExpression(patch, voice, ownerPath, frequency, dutyExpression, fmIndex, parameters)); var envelope = voice.RateLevelEnvelope is not null ? RateLevelEnvelopeExpression(voice.RateLevelEnvelope, noteGate) : EnvelopeExpression( @@ -378,6 +381,58 @@ public static class FaustEmitter }; } + private static string TractExpression( + StringBuilder source, + VocalTract tract, + string ownerPath, + string name, + string frequency, + string gate, + ParameterMap parameters) + { + var tractPath = OwnerField(ownerPath, "tract"); + var sections = Math.Max(4, tract.Sections); + var hasNose = tract.NoseSections > 0; + var intensity = $"clip01({parameters.Expression(OwnerField(tractPath, "intensity"), tract.Intensity)})"; + var tenseness = $"clip01({parameters.Expression(OwnerField(tractPath, "tenseness"), tract.Tenseness)})"; + var tongueIndex = parameters.Expression(OwnerField(tractPath, "tongue_index"), tract.TongueIndex); + var tongueDiameter = parameters.Expression(OwnerField(tractPath, "tongue_diameter"), tract.TongueDiameter); + var velum = $"clip01(({parameters.Expression(OwnerField(tractPath, "velum"), tract.Velum)} - 0.01) / 0.39)"; + var constrictionIndex = parameters.Expression(OwnerField(tractPath, "constriction_index"), tract.ConstrictionIndex); + var constrictionDiameter = parameters.Expression(OwnerField(tractPath, "constriction_diameter"), tract.ConstrictionDiameter); + var turbulence = $"clip01({parameters.Expression(OwnerField(tractPath, "turbulence"), tract.Turbulence)})"; + var lipOpening = parameters.Expression(OwnerField(tractPath, "lip_opening"), tract.LipOpening); + var glottalReflection = parameters.Expression(OwnerField(tractPath, "glottal_reflection"), tract.GlottalReflection); + var lipReflection = parameters.Expression(OwnerField(tractPath, "lip_reflection"), tract.LipReflection); + + 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_tongue_close = clip01((3.5 - {tongueDiameter}) / 3.5);"); + source.AppendLine($"{name}_tract_constriction_close = clip01((1.15 - {constrictionDiameter}) / 1.15);"); + source.AppendLine($"{name}_tract_lip = clip01({lipOpening} / 2.5);"); + source.AppendLine($"{name}_tract_q = 2.0 + {tenseness} * 10.0 + {name}_tract_constriction_close * 8.0;"); + source.AppendLine($"{name}_tract_f1 = max(90.0, 260.0 + {name}_tract_lip * 720.0 - {name}_tract_tongue_close * 260.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 - (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);"); + 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_raw = ({name}_tract_lf + {name}_tract_aspiration + {name}_tract_frication + {name}_tract_burst) * (0.55 + 0.45 * abs({glottalReflection}));"); + 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) + { + source.AppendLine($"{name}_tract_nose = ({name}_tract_raw : fi.resonbp(260.0 + {velum} * 560.0, 3.0 + {velum} * 9.0, 1.0) : fi.lowpass(2, 2400.0 + {velum} * 1200.0)) * {velum};"); + } + else + { + source.AppendLine($"{name}_tract_nose = 0.0;"); + } + source.AppendLine($"{name}_tract_radiated = ({name}_tract_oral * (0.65 + 0.35 * abs({lipReflection})) + {name}_tract_nose);"); + return $"{name}_tract_radiated"; + } + private static void EmitOperatorGraph(StringBuilder source, Playback playback, OperatorGraph graph, string name, ParameterMap parameters, List warnings) { if (graph.Operators.Count == 0) diff --git a/src/AquaSynth.Core/Model.cs b/src/AquaSynth.Core/Model.cs index 157f635..d370d95 100644 --- a/src/AquaSynth.Core/Model.cs +++ b/src/AquaSynth.Core/Model.cs @@ -178,6 +178,21 @@ public sealed record OperatorGraph( public Note Note { get; init; } = Note ?? new(); } +public sealed record VocalTract( + int Sections = 44, + int NoseSections = 28, + float Intensity = 0.72f, + float Tenseness = 0.6f, + float TongueIndex = 12.9f, + float TongueDiameter = 2.43f, + float Velum = 0.01f, + float ConstrictionIndex = 32, + float ConstrictionDiameter = 1, + float Turbulence = 0, + float LipOpening = 1.5f, + float GlottalReflection = 0.75f, + float LipReflection = -0.85f); + public sealed record PatchParameter( string Path, string Label, @@ -334,6 +349,7 @@ public sealed record Voice public Phaser Phaser { get; init; } = new(); public Arpeggio? Arpeggio { get; init; } public FrequencyModulation Fm { get; init; } = new(); + public VocalTract? Tract { get; init; } public VoiceColor Color { get; init; } = new(); public IReadOnlyList Formants { get; init; } = Array.Empty(); public IReadOnlyList FormantFrames { get; init; } = Array.Empty(); diff --git a/src/AquaSynth.Core/PatchScript.cs b/src/AquaSynth.Core/PatchScript.cs index 9f890e2..f3340a1 100644 --- a/src/AquaSynth.Core/PatchScript.cs +++ b/src/AquaSynth.Core/PatchScript.cs @@ -112,6 +112,10 @@ public static class PatchScript FlushPendingOperatorGraph(); Voices.Add(ParseVoice(ExpandVoiceFields(fields, line), VoicePath(Voices.Count), line)); break; + case "tract": + FlushPendingOperatorGraph(); + Voices.Add(ParseTractVoice(ExpandVoiceFields(fields, line), VoicePath(Voices.Count), line)); + break; case "opgraph": StartOperatorGraph(fields, line); break; @@ -480,6 +484,57 @@ public static class PatchScript }; } + private Voice ParseTractVoice(IReadOnlyDictionary fields, string ownerPath, int line) + { + var voiceFields = new Dictionary(fields, StringComparer.OrdinalIgnoreCase); + if (!HasAny(voiceFields, "wave", "w")) + { + voiceFields["wave"] = "saw"; + } + if (!HasAny(voiceFields, "gain", "g")) + { + voiceFields["gain"] = "0.6"; + } + if (!HasAny(voiceFields, "sustain", "s", "gate", "hold", "duration")) + { + voiceFields["sustain"] = "0.35"; + } + if (!HasAny(voiceFields, "decay", "d", "release", "rel")) + { + voiceFields["decay"] = "0.12"; + } + + var voice = ParseVoice(voiceFields, ownerPath, line); + var sections = GetBoundInt(fields, line, 44, OwnerField(ownerPath, "tract/sections"), "sections", "cells"); + if (sections < 4) + { + throw new PatchScriptException(line, "tract sections must be at least 4"); + } + var noseSections = GetBoundInt(fields, line, 28, OwnerField(ownerPath, "tract/nose_sections"), "nose_sections", "nose_cells"); + if (noseSections < 0) + { + throw new PatchScriptException(line, "tract nose_sections must be non-negative"); + } + + return voice with + { + 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, 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, 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, -0.85f, OwnerField(ownerPath, "tract/lip_reflection"), "lip_reflection", "lr")) + }; + } + private void AddModBus(IReadOnlyDictionary fields, int line) { var name = GetAny(fields, ["name", "n"], "mod"); @@ -1274,6 +1329,7 @@ public static class PatchScript "harmonics" or "partials" or "drawbars" => "harmonics", "spectrum" or "spectral" or "padsource" or "pad_source" => "spectrum", "v" or "voice" => "voice", + "tract" or "vt" or "tractvoice" or "tract_voice" => "tract", "opgraph" or "ops" or "operators" => "opgraph", "operator" or "op" => "operator", "route" or "edge" => "route", diff --git a/src/AquaSynth.Core/PinkTromboneReference.cs b/src/AquaSynth.Core/PinkTromboneReference.cs index 011800f..cb0c7a4 100644 --- a/src/AquaSynth.Core/PinkTromboneReference.cs +++ b/src/AquaSynth.Core/PinkTromboneReference.cs @@ -45,7 +45,11 @@ public static class PinkTromboneReference new("/pink/tongue/diameter", "Tongue diameter", 2.43f, 0, 4, 0.001f, "diameter", "control", "Tongue-body diameter target."), new("/pink/velum", "Velum", 0.01f, 0.01f, 0.4f, 0.001f, "diameter", "control", "Nasal branch opening diameter."), new("/pink/constriction/index", "Constriction index", 32, 0, 44, 0.001f, "cell", "control", "Fricative or closure constriction position."), - new("/pink/constriction/diameter", "Constriction diameter", 1, -1, 4, 0.001f, "diameter", "control", "Fricative or closure constriction diameter.") + new("/pink/constriction/diameter", "Constriction diameter", 1, -1, 4, 0.001f, "diameter", "control", "Fricative or closure constriction diameter."), + new("/pink/turbulence", "Turbulence", 0.18f, 0, 1, 0.001f, "normalized", "control", "Breath and frication noise pressure."), + new("/pink/lip/opening", "Lip opening", 1.5f, 0.35f, 2.5f, 0.001f, "diameter", "control", "Mouth radiation opening proxy."), + new("/pink/glottal/reflection", "Glottal reflection", 0.75f, -0.95f, 0.95f, 0.001f, "coefficient", "control", "Source-end reflection proxy."), + new("/pink/lip/reflection", "Lip reflection", -0.85f, -0.98f, 0.1f, 0.001f, "coefficient", "control", "Lip-end reflection proxy.") ]; public static ReferenceRebuild CurrentAquaSynthProxy() => @@ -56,10 +60,11 @@ public static class PinkTromboneReference ReferenceId, BuiltInScripts.PinkTromboneProxy, [ - new("runtime_controls", "/pink/frequency,/pink/intensity,/pink/tenseness,/pink/tongue/index,/pink/tongue/diameter,/pink/velum", "AquaSynth can expose stable runtime parameter paths."), - new("glottal_pitch_pressure_proxy", "oscillator-frequency-plus-gain", "AquaSynth can drive pitch/loudness-like controls without recompiling."), - new("turbulence_proxy", "noise-voice", "AquaSynth can emit a separate noise source for frication pressure."), - new("formant_proxy", "static-resonant-bandpass-bank", "AquaSynth can sketch vowel/body color with formant filters.") + new("tract_voice_authority", "voice.Tract", "Pink Trombone pressure now lowers through a tract treatment on an ordinary AquaSynth voice."), + 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."), diff --git a/state/evidence.jsonl b/state/evidence.jsonl index b065b5c..d84e39d 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -130,3 +130,4 @@ {"date":"2026-05-25","topic":"vocal-tract-control-playground","lesson":"The current AquaSynth vocal-tract lane is touchable as a voice-patch target surface before it is a Pink Trombone-class tract simulation. A useful playground should expose the real VocalTractControlTarget knobs directly: these are the controls the learned speech driver predicts from phonetic and utterance input, not learned controls themselves. Keep the tract-ish visualization honest that the WebAudio renderer is a lab proxy rather than full waveguide anatomy.","evidence":"Added tools/vocal-tract-playground with static HTML/CSS/JS, a Node static server, WebAudio source/filter synthesis, tract canvas visualization, presets, and sliders for the 14 base voice-patch target controls plus six mel bands. Verified with `node --check` on app.js/serve.mjs, curl against http://localhost:5125/, and browser interaction: Play toggled audio, Ee preset updated controls and canvas, console errors were empty."} {"date":"2026-05-25","topic":"speech-loss-control-authority","lesson":"Exporting `/speech/output/N` controls is not proof that the speech training surface is usable. Every base VocalTractControlTarget output must route into audible DSP before gradient descent is trusted; epsilon keep-alive references are not control authority.","evidence":"The compiled Faust speech-loss surface previously used tongue body, tongue tip, lip aperture, lip rounding, and velum only in the final keep-controls epsilon. Routed tract controls into small resonant source-filter proxies, velum into a nasal tone, LFO depth into tremolo depth, and added tests that fail when base controls are only declared/kept alive. Focused verification: `dotnet test AquaSynth.sln --no-restore --filter FaustRenderedSpeechLossSurfaceTests` passed. Full `dotnet test AquaSynth.sln --no-restore` timed out twice at 120s and 300s without a result; orphaned dotnet workers were stopped."} {"date":"2026-05-25","topic":"pink-trombone-parity-boundary","lesson":"Pink Trombone parity must pressure AquaSynth at the tract-DSP authority, not through more source/filter proxy controls. The current DSL can expose parameters and formant/noise proxies, but it cannot exactly represent Pink Trombone's moving bidirectional waveguide graph: 44 main tract cells, 28 nasal cells, diameter-to-area reflection coefficients, velum junction, twice-rate tract stepping, positioned turbulence injection, closure transients, or exact LF glottal coefficient updates.","evidence":"Inspected `chdh/pink-trombone-mod` source (`Synthesizer.ts`, `Glottis.ts`, `Tract.ts`, `TractShaper.ts`) and added `docs/pink-trombone-parity.md`, `PinkTromboneReference`, a current non-passing AquaSynth proxy rebuild, and `PinkTromboneReferenceDeclaresMissingWaveguideAuthority` so the proxy cannot be mistaken for actual tract parity."} +{"date":"2026-05-25","topic":"tract-voice-dsl","lesson":"Pink Trombone pressure belongs on the voice as an expressive tract treatment before it becomes exact anatomy. The `tract` DSL command now lowers into `Voice.Tract`, exposes PT-shaped runtime controls, and emits a Faust tract-voice proxy; it must not be treated as a separate patch graph owner or as exact 44-cell/28-cell waveguide parity.","evidence":"Added `VocalTract` on `Voice`, `tract` parsing and field-site bindings, Faust tract proxy lowering, an updated built-in Pink Trombone proxy, parity docs/reference metadata, and a WebAudio tract playground with matching knobs. Focused tests covered parse -> model -> Faust and Pink Trombone reference declarations."} diff --git a/state/map.yaml b/state/map.yaml index 3913495..c2d04af 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -42,6 +42,7 @@ modules: speech_backpropagation_pipeline: src/AquaSynth.Core/SpeechBackpropagationPipeline.cs speech_distributed_training: src/AquaSynth.Core/SpeechDistributedTraining.cs vocal_tract_learning: src/AquaSynth.Core/VocalTractLearning.cs + tract_voice_model: src/AquaSynth.Core/Model.cs faust_emitter: src/AquaSynth.Core/FaustExport.cs faust_compiler: src/AquaSynth.Faust/FaustCompiler.cs native_faust_runtime: src/AquaSynth.Faust/NativeFaustRuntime.cs diff --git a/state/spine.yaml b/state/spine.yaml index 6a29558..cef7815 100644 --- a/state/spine.yaml +++ b/state/spine.yaml @@ -1,6 +1,6 @@ project: AquaSynth spine_version: 1 -updated: 2026-05-20T22:00:00+01:00 +updated: 2026-05-25T23:20:00+01:00 prime_directive: > Build coherent synth machinery. References exist to reveal missing structure, @@ -110,7 +110,7 @@ live_invariants: - Do not hide missing graph structure behind unrelated voice fields. - The speech lane is the active center: IPA parity, utterance embeddings, synth-driver automation, rendered loss, and compiled Faust control sweeps take priority over new DX7/Zyn digestion. - Every learned speech arrow must stay inspectable: utterance metadata -> embedding, embedding plus phonetic features -> automation, automation -> rendered audio, rendered audio -> loss/gradient. - - Pink Trombone parity is structural waveguide pressure, not permission to add more formant proxy knobs. Current AquaSynth cannot exactly express the 44-cell main tract, 28-cell nasal branch, diameter-to-reflection updates, twice-rate tract stepping, positioned turbulence injection, or closure transients through the ordinary `voice` DSL. + - Pink Trombone parity is structural waveguide pressure, not permission to add more formant proxy knobs. AquaSynth now has a `tract` DSL command that lowers into `Voice.Tract` with PT-shaped runtime controls and a Faust tract-voice proxy; it is still an ordinary voice treatment, not a separate graph owner and not an exact 44-cell/28-cell bidirectional waveguide. - eSpeak NG is an early parity reference for timing, IPA coverage, and log-mel pressure, not an anatomy oracle or final target. - Do not expand into prosody, emotional context, personality, or broad Weksa expressivity until the tiny IPA utterance harness can show useful loss movement. - Speech training receipts must keep time as a witness: every request, render result, and checkpoint should record stage decision time, latency spent, latency budget, confidence, and artifact/model identifiers. diff --git a/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs b/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs index b8470e3..9224993 100644 --- a/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs +++ b/tests/AquaSynth.Dsl.Tests/PatchScriptTests.cs @@ -81,6 +81,29 @@ public sealed class PatchScriptTests Assert.Contains("fi.resonbp(500", faust); } + [Fact] + public void ParserSupportsPinkTromboneStyleTractVoice() + { + var patch = PatchScript.Parse(""" + param path=/pink/tenseness default=.6 min=0 max=1 step=.001 + tract freq=140 intensity=.72 tenseness=@/pink/tenseness tongue_index=18 tongue_diameter=1.4 velum=.2 constriction_index=32 constriction_diameter=.45 turbulence=.8 + """); + + var voice = Assert.Single(patch.Voices); + Assert.NotNull(voice.Tract); + Assert.Equal(44, voice.Tract.Sections); + Assert.Equal(28, voice.Tract.NoseSections); + Assert.Equal(18, voice.Tract.TongueIndex); + Assert.Equal(.45f, voice.Tract.ConstrictionDiameter, 5); + Assert.Contains(patch.ParameterBindings, binding => binding.FieldPath == "/voices/0/tract/tenseness"); + + var faust = FaustEmitter.Emit(patch, new FaustExportOptions("tract_voice")).Source; + Assert.Contains("tract_lf", faust); + Assert.Contains("tract_frication", faust); + Assert.Contains("tract_nose", faust); + Assert.Contains("fi.resonbp", faust); + } + [Fact] public void ParserPreservesDeclaredPatchParameters() { @@ -303,7 +326,7 @@ public sealed class PatchScriptTests Assert.Contains(reference.Features, feature => feature.Name == "reflection_formula"); Assert.Contains(reference.Parameters, parameter => parameter.Path == "/pink/tongue/index"); Assert.Contains(reference.Parameters, parameter => parameter.Path == "/pink/constriction/diameter"); - Assert.Contains(rebuild.MatchedFeatures, feature => feature.Name == "formant_proxy"); + Assert.Contains(rebuild.MatchedFeatures, feature => feature.Name == "tract_voice_authority"); Assert.Contains(rebuild.MissingFeatures, feature => feature.Name == "main_tract_waveguide_cells"); Assert.Contains(rebuild.MissingFeatures, feature => feature.Name == "diameter_to_reflection_coefficients"); Assert.Contains(rebuild.MissingFeatures, feature => feature.Name == "nose_waveguide_cells"); diff --git a/tools/vocal-tract-playground/README.md b/tools/vocal-tract-playground/README.md index aa9df27..3d40a88 100644 --- a/tools/vocal-tract-playground/README.md +++ b/tools/vocal-tract-playground/README.md @@ -1,6 +1,6 @@ -# AquaSynth Vocal Tract Playground +# AquaSynth Tract Voice Playground -Touchable WebAudio playground for the current `VocalTractControlTarget` surface. +Touchable WebAudio playground for the Aqua DSL `tract` voice surface. Run it from this directory: @@ -14,9 +14,11 @@ Then open: http://localhost:5125/ ``` -This is a voice-patch control witness, not a Pink Trombone-class tract -simulation. It exposes the knobs the learned speech driver is meant to control: -phonetic and utterance input go into the model, the model predicts this -`VocalTractControlTarget` vector, and the voice patch renders sound from those -values. The WebAudio source/filter proxy only makes that target vector touchable -while the proper tract renderer continues to mature. +This is a tract-voice control witness. It exposes the same Pink +Trombone-shaped controls that Aqua DSL now lowers through `tract`: frequency, +intensity, tenseness, tongue index/diameter, velum, constriction +index/diameter, turbulence, lip opening, and radiation reflection controls. + +The browser synth runs a small 44-cell/28-cell waveguide-style witness so the +knobs are touchable while the Faust lowering keeps maturing toward exact Pink +Trombone parity. diff --git a/tools/vocal-tract-playground/app.js b/tools/vocal-tract-playground/app.js index 0bc1959..22772cc 100644 --- a/tools/vocal-tract-playground/app.js +++ b/tools/vocal-tract-playground/app.js @@ -1,63 +1,51 @@ "use strict"; const controlSpecs = [ - ["Tongue body", "tongueBody", "tract", 0.56], - ["Tongue tip", "tongueTip", "tract", 0.42], - ["Lip aperture", "lipAperture", "tract", 0.72], - ["Lip rounding", "lipRounding", "tract", 0.18], - ["Velum", "velum", "tract", 0.18], - ["Glottal tenseness", "glottalTenseness", "source", 0.48], - ["Turbulence", "turbulence", "source", 0.14], - ["Pressure", "pressure", "source", 0.68], - ["AM depth", "amDepth", "source", 0.08], - ["FM depth", "fmDepth", "source", 0.05], - ["LFO rate", "lfoRate", "source", 0.22], - ["LFO depth", "lfoDepth", "source", 0.06], - ["Filter cutoff", "filterCutoff", "spectral", 0.58], - ["Filter resonance", "filterResonance", "spectral", 0.22], - ["Mel low", "mel0", "spectral", 0.62], - ["Mel low-mid", "mel1", "spectral", 0.55], - ["Mel mid", "mel2", "spectral", 0.48], - ["Mel high-mid", "mel3", "spectral", 0.42], - ["Mel high", "mel4", "spectral", 0.36], - ["Mel air", "mel5", "spectral", 0.30] + ["Frequency", "frequency", "source", 140, 60, 420, "Hz"], + ["Intensity", "intensity", "source", 0.72, 0, 1, ""], + ["Tenseness", "tenseness", "source", 0.60, 0, 1, ""], + ["Tongue index", "tongueIndex", "tract", 12.9, 8, 34, "cell"], + ["Tongue diameter", "tongueDiameter", "tract", 2.43, 0.45, 3.6, "diam"], + ["Velum", "velum", "tract", 0.01, 0.01, 0.4, "diam"], + ["Constriction index", "constrictionIndex", "tract", 32, 2, 43, "cell"], + ["Constriction diameter", "constrictionDiameter", "tract", 1.0, -0.7, 3.4, "diam"], + ["Turbulence", "turbulence", "source", 0.18, 0, 1, ""], + ["Lip opening", "lipOpening", "tract", 1.5, 0.35, 2.5, "diam"], + ["Glottal reflection", "glottalReflection", "spectral", 0.75, -0.95, 0.95, ""], + ["Lip reflection", "lipReflection", "spectral", -0.85, -0.98, 0.1, ""], + ["Gain", "gain", "source", 0.7, 0, 1, ""] ]; const presets = { open: { - tongueBody: 0.42, tongueTip: 0.30, lipAperture: 0.92, lipRounding: 0.05, - velum: 0.12, glottalTenseness: 0.42, turbulence: 0.04, pressure: 0.76, - amDepth: 0.04, fmDepth: 0.04, lfoRate: 0.18, lfoDepth: 0.03, - filterCutoff: 0.68, filterResonance: 0.20, mel0: 0.78, mel1: 0.68, - mel2: 0.54, mel3: 0.40, mel4: 0.30, mel5: 0.22 + frequency: 140, intensity: 0.72, tenseness: 0.58, tongueIndex: 13, + tongueDiameter: 2.7, velum: 0.01, constrictionIndex: 32, + constrictionDiameter: 1.4, turbulence: 0.08, lipOpening: 1.7, + glottalReflection: 0.75, lipReflection: -0.85, gain: 0.72 }, ee: { - tongueBody: 0.82, tongueTip: 0.72, lipAperture: 0.46, lipRounding: 0.02, - velum: 0.10, glottalTenseness: 0.58, turbulence: 0.05, pressure: 0.68, - amDepth: 0.03, fmDepth: 0.08, lfoRate: 0.26, lfoDepth: 0.04, - filterCutoff: 0.78, filterResonance: 0.32, mel0: 0.35, mel1: 0.52, - mel2: 0.82, mel3: 0.72, mel4: 0.58, mel5: 0.36 + frequency: 165, intensity: 0.68, tenseness: 0.72, tongueIndex: 27, + tongueDiameter: 1.05, velum: 0.01, constrictionIndex: 34, + constrictionDiameter: 1.2, turbulence: 0.04, lipOpening: 1.1, + glottalReflection: 0.75, lipReflection: -0.85, gain: 0.68 }, oo: { - tongueBody: 0.30, tongueTip: 0.24, lipAperture: 0.36, lipRounding: 0.88, - velum: 0.11, glottalTenseness: 0.44, turbulence: 0.03, pressure: 0.70, - amDepth: 0.03, fmDepth: 0.03, lfoRate: 0.16, lfoDepth: 0.03, - filterCutoff: 0.36, filterResonance: 0.38, mel0: 0.82, mel1: 0.70, - mel2: 0.38, mel3: 0.22, mel4: 0.18, mel5: 0.12 + frequency: 128, intensity: 0.72, tenseness: 0.55, tongueIndex: 12, + tongueDiameter: 2.9, velum: 0.01, constrictionIndex: 38, + constrictionDiameter: 1.5, turbulence: 0.03, lipOpening: 0.55, + glottalReflection: 0.75, lipReflection: -0.9, gain: 0.74 }, ss: { - tongueBody: 0.68, tongueTip: 0.86, lipAperture: 0.32, lipRounding: 0.02, - velum: 0.08, glottalTenseness: 0.10, turbulence: 0.92, pressure: 0.78, - amDepth: 0.18, fmDepth: 0.12, lfoRate: 0.36, lfoDepth: 0.05, - filterCutoff: 0.88, filterResonance: 0.62, mel0: 0.12, mel1: 0.18, - mel2: 0.36, mel3: 0.76, mel4: 0.92, mel5: 0.86 + frequency: 130, intensity: 0.48, tenseness: 0.22, tongueIndex: 28, + tongueDiameter: 0.75, velum: 0.01, constrictionIndex: 34, + constrictionDiameter: 0.35, turbulence: 0.95, lipOpening: 1.2, + glottalReflection: 0.65, lipReflection: -0.82, gain: 0.78 }, ma: { - tongueBody: 0.48, tongueTip: 0.38, lipAperture: 0.28, lipRounding: 0.18, - velum: 0.78, glottalTenseness: 0.40, turbulence: 0.04, pressure: 0.64, - amDepth: 0.08, fmDepth: 0.04, lfoRate: 0.20, lfoDepth: 0.05, - filterCutoff: 0.42, filterResonance: 0.28, mel0: 0.74, mel1: 0.72, - mel2: 0.58, mel3: 0.40, mel4: 0.30, mel5: 0.22 + frequency: 132, intensity: 0.66, tenseness: 0.52, tongueIndex: 14, + tongueDiameter: 2.2, velum: 0.33, constrictionIndex: 18, + constrictionDiameter: 0.8, turbulence: 0.12, lipOpening: 1.35, + glottalReflection: 0.78, lipReflection: -0.84, gain: 0.72 } }; @@ -77,7 +65,7 @@ const noiseMeter = document.getElementById("noiseMeter"); const nasalMeter = document.getElementById("nasalMeter"); function makeControls() { - for (const [label, id, family, value] of controlSpecs) { + for (const [label, id, family, value, min, max, unit] of controlSpecs) { const row = document.createElement("div"); row.className = "control"; row.dataset.family = family; @@ -93,98 +81,73 @@ function makeControls() { const input = document.createElement("input"); input.id = id; input.type = "range"; - input.min = "0"; - input.max = "1"; - input.step = "0.001"; + input.min = min.toString(); + input.max = max.toString(); + input.step = max - min > 20 ? "0.01" : "0.001"; input.value = value.toString(); input.addEventListener("input", () => { state[id] = Number(input.value); - valueEl.value = state[id].toFixed(3); + valueEl.value = formatValue(id, state[id], unit); updateAudio(); }); row.append(labelEl, valueEl, input); controlsRoot.append(row); - controls.set(id, { input, valueEl }); + controls.set(id, { input, valueEl, unit }); } syncControls(); } +function formatValue(id, value, unit) { + const digits = id.includes("Index") || id === "frequency" ? 1 : 3; + return `${value.toFixed(digits)}${unit ? ` ${unit}` : ""}`; +} + function syncControls() { for (const [id, pair] of controls) { pair.input.value = state[id].toString(); - pair.valueEl.value = state[id].toFixed(3); + pair.valueEl.value = formatValue(id, state[id], pair.unit); } updateMeters(); + updateAudio(); draw(); } function applyPreset(name) { Object.assign(state, presets[name]); syncControls(); - updateAudio(); -} - -function createNoiseBuffer(context) { - const buffer = context.createBuffer(1, context.sampleRate * 2, context.sampleRate); - const data = buffer.getChannelData(0); - for (let i = 0; i < data.length; i++) { - data[i] = Math.random() * 2 - 1; - } - return buffer; } async function startAudio() { - if (audio) { - return; - } + if (audio) return; const context = new AudioContext(); const master = context.createGain(); - const voice = context.createOscillator(); - const voiceGain = context.createGain(); - const noise = context.createBufferSource(); - const noiseGain = context.createGain(); - const nasal = context.createBiquadFilter(); - const low = context.createBiquadFilter(); - const mid = context.createBiquadFilter(); - const high = context.createBiquadFilter(); - const air = context.createBiquadFilter(); + const processor = context.createScriptProcessor(1024, 0, 1); + const synth = createTractSynth(context.sampleRate); - voice.type = "sawtooth"; - noise.buffer = createNoiseBuffer(context); - noise.loop = true; - - nasal.type = "bandpass"; - low.type = "peaking"; - mid.type = "peaking"; - high.type = "peaking"; - air.type = "highpass"; - - voice.connect(voiceGain).connect(nasal).connect(low).connect(mid).connect(high).connect(air).connect(master); - noise.connect(noiseGain).connect(high); - master.connect(context.destination); + processor.onaudioprocess = event => { + const output = event.outputBuffer.getChannelData(0); + synth.render(output, state); + }; master.gain.value = 0.0; - voice.start(); - noise.start(); - - audio = { context, master, voice, voiceGain, noiseGain, nasal, low, mid, high, air }; + processor.connect(master).connect(context.destination); + audio = { context, master, processor, synth }; updateAudio(); playButton.textContent = "Stop"; playButton.setAttribute("aria-pressed", "true"); } async function stopAudio() { - if (!audio) { - return; - } + if (!audio) return; const old = audio; audio = null; old.master.gain.setTargetAtTime(0, old.context.currentTime, 0.02); + old.processor.disconnect(); await new Promise(resolve => setTimeout(resolve, 80)); await old.context.close(); playButton.textContent = "Play"; @@ -193,45 +156,223 @@ async function stopAudio() { function updateAudio() { updateMeters(); - if (!audio) { - return; - } + if (!audio) return; - const t = audio.context.currentTime; - const pitch = 82 + state.pressure * 120 + state.glottalTenseness * 80; - const wobble = 1 + Math.sin(t * (0.5 + state.lfoRate * 8)) * state.lfoDepth * 0.08; - const rounded = 1 - state.lipRounding * 0.38; - const aperture = 0.25 + state.lipAperture * 0.85; - - audio.voice.frequency.setTargetAtTime(pitch * wobble * (1 + state.fmDepth * 0.12), t, 0.015); - audio.voiceGain.gain.setTargetAtTime((1 - state.turbulence * 0.75) * state.pressure * aperture * 0.24, t, 0.025); - audio.noiseGain.gain.setTargetAtTime(state.turbulence * state.pressure * (0.05 + state.tongueTip * 0.22), t, 0.02); - audio.master.gain.setTargetAtTime(0.72, t, 0.03); - - audio.nasal.frequency.setTargetAtTime(220 + state.velum * 260, t, 0.02); - audio.nasal.Q.setTargetAtTime(0.5 + state.velum * 5, t, 0.02); - audio.nasal.gain?.setTargetAtTime?.(state.velum * 8, t, 0.02); - - audio.low.frequency.setTargetAtTime((280 + state.tongueBody * 620) * rounded, t, 0.02); - audio.low.Q.setTargetAtTime(0.7 + state.filterResonance * 8, t, 0.02); - audio.low.gain.setTargetAtTime((state.mel0 - 0.5) * 18, t, 0.02); - - audio.mid.frequency.setTargetAtTime(780 + state.tongueTip * 1450 + state.lipAperture * 300, t, 0.02); - audio.mid.Q.setTargetAtTime(0.8 + state.filterResonance * 7, t, 0.02); - audio.mid.gain.setTargetAtTime(((state.mel1 + state.mel2) * 0.5 - 0.5) * 18, t, 0.02); - - audio.high.frequency.setTargetAtTime(1900 + state.tongueTip * 2600 + state.filterCutoff * 1800, t, 0.02); - audio.high.Q.setTargetAtTime(0.7 + state.filterResonance * 10, t, 0.02); - audio.high.gain.setTargetAtTime(((state.mel3 + state.mel4) * 0.5 - 0.5) * 22, t, 0.02); - - audio.air.frequency.setTargetAtTime(3200 + state.filterCutoff * 6500, t, 0.02); - audio.air.Q.setTargetAtTime(0.7, t, 0.02); + audio.master.gain.setTargetAtTime(state.gain, audio.context.currentTime, 0.03); } function updateMeters() { - pressureMeter.value = state.pressure; + pressureMeter.value = state.intensity; noiseMeter.value = state.turbulence; - nasalMeter.value = state.velum; + nasalMeter.value = (state.velum - 0.01) / 0.39; +} + +function createTractSynth(sampleRate) { + const sections = 44; + const noseSections = 28; + const right = new Float32Array(sections); + const left = new Float32Array(sections); + const junctionRight = new Float32Array(sections); + const junctionLeft = new Float32Array(sections + 1); + const reflection = new Float32Array(sections); + const diameter = new Float32Array(sections); + const targetDiameter = new Float32Array(sections); + const noseRight = new Float32Array(noseSections); + const noseLeft = new Float32Array(noseSections); + const noseJunctionRight = new Float32Array(noseSections); + const noseJunctionLeft = new Float32Array(noseSections + 1); + const noseReflection = new Float32Array(noseSections); + const noseDiameter = new Float32Array(noseSections); + let glottalPhase = 0; + let noise = 0.1234567; + let lastConstrictionDiameter = 1.0; + let transient = 0; + let dcBlockX = 0; + let dcBlockY = 0; + + initRest(); + updateNose(0.01); + + function rand() { + noise = (noise * 16807) % 2147483647; + return noise / 1073741823.5 - 1; + } + + function initRest() { + for (let i = 0; i < sections; i++) { + const base = i < 7 ? 0.6 : i < 10 ? 1.1 : 1.5; + diameter[i] = base; + targetDiameter[i] = base; + } + } + + function updateTargets(s) { + for (let i = 0; i < sections; i++) { + let base = i < 7 ? 0.6 : i < 10 ? 1.1 : 1.5; + if (i > 10 && i < 39) { + const angle = 1.1 * Math.PI * (s.tongueIndex - i) / 22; + const fixedTongueDiameter = 2 + (s.tongueDiameter - 2) / 1.5; + let curve = (1.5 - fixedTongueDiameter + 1.7) * Math.cos(angle); + if (i === 8 || i === 38) curve *= 0.8; + if (i === 10 || i === 37) curve *= 0.94; + base = 1.5 - curve; + } + targetDiameter[i] = Math.max(0, base); + } + + applyConstriction(s.constrictionIndex, s.constrictionDiameter); + targetDiameter[sections - 1] = Math.max(0.05, s.lipOpening); + } + + function applyConstriction(position, constrictionDiameter) { + const newDiameter = Math.max(0, constrictionDiameter - 0.3); + const range = position < 25 ? 10 : 5; + const lower = Math.max(0, Math.floor(position - range - 1)); + const upper = Math.min(sections - 1, Math.ceil(position + range + 1)); + for (let i = lower; i <= upper; i++) { + const offset = Math.abs(i - position) - 0.5; + let scale; + if (offset <= 0) scale = 0; + else if (offset > range) scale = 1; + else scale = 0.5 * (1 - Math.cos(Math.PI * offset / range)); + const difference = targetDiameter[i] - newDiameter; + if (difference > 0) targetDiameter[i] = newDiameter + difference * scale; + } + } + + function slewDiameters() { + for (let i = 0; i < sections; i++) { + const speed = i < 17 ? 0.00035 : i < 32 ? 0.00045 : 0.0007; + diameter[i] += Math.max(-speed, Math.min(speed * 2, targetDiameter[i] - diameter[i])); + } + } + + function updateNose(velum) { + for (let i = 0; i < noseSections; i++) { + const d = 2 * (i / noseSections); + let value = i === 0 ? velum : d < 1 ? 0.4 + 1.6 * d : 0.5 + 1.5 * (2 - d); + noseDiameter[i] = Math.min(value, 1.9); + } + for (let i = 1; i < noseSections; i++) { + const a0 = Math.max(1e-6, noseDiameter[i - 1] * noseDiameter[i - 1]); + const a1 = Math.max(1e-6, noseDiameter[i] * noseDiameter[i]); + noseReflection[i] = (a0 - a1) / (a0 + a1); + } + } + + function updateReflection() { + for (let i = 1; i < sections; i++) { + const a0 = Math.max(1e-6, diameter[i - 1] * diameter[i - 1]); + const a1 = Math.max(1e-6, diameter[i] * diameter[i]); + reflection[i] = (a0 - a1) / (a0 + a1); + } + } + + function glottis(s) { + glottalPhase += s.frequency / sampleRate; + glottalPhase -= Math.floor(glottalPhase); + const t = glottalPhase; + const tenseness = Math.max(0, Math.min(1, s.tenseness)); + const openPhase = 0.55 + 0.32 * (1 - tenseness); + const pulse = t < openPhase + ? Math.sin(Math.PI * t / openPhase) + : -0.28 * Math.sin(Math.PI * (t - openPhase) / (1 - openPhase)); + const harmonicBite = (0.12 + tenseness * 0.62) * Math.sin(4 * Math.PI * t); + const aspiration = rand() * s.intensity * (1 - Math.sqrt(tenseness)) * 0.18; + return (pulse - harmonicBite + aspiration) * s.intensity * (0.45 + 0.75 * Math.pow(tenseness, 0.35)); + } + + function injectTurbulence(s) { + const thinness = Math.max(0, Math.min(1, 8 * (0.7 - s.constrictionDiameter))); + const openness = Math.max(0, Math.min(1, 30 * (s.constrictionDiameter - 0.3))); + const frontLift = 0.35 + 0.65 * Math.max(0, Math.min(1, s.constrictionIndex / 44)); + const amount = rand() * s.turbulence * thinness * openness * s.intensity * frontLift * 1.8; + const i = Math.floor(s.constrictionIndex); + const delta = s.constrictionIndex - i; + if (i + 1 < sections) { + right[i + 1] += amount * (1 - delta) * 0.5; + left[i + 1] += amount * (1 - delta) * 0.5; + } + if (i + 2 < sections) { + right[i + 2] += amount * delta * 0.5; + left[i + 2] += amount * delta * 0.5; + } + } + + function step(input, s) { + injectTurbulence(s); + junctionRight[0] = left[0] * s.glottalReflection + input; + junctionLeft[sections] = right[sections - 1] * s.lipReflection; + + for (let i = 1; i < sections; i++) { + const w = reflection[i] * (right[i - 1] + left[i]); + junctionRight[i] = right[i - 1] - w; + junctionLeft[i] = left[i] + w; + } + + const noseStart = sections - noseSections + 1; + const velumArea = Math.max(1e-6, s.velum * s.velum); + const leftArea = Math.max(1e-6, diameter[noseStart] * diameter[noseStart]); + const rightArea = Math.max(1e-6, diameter[noseStart + 1] * diameter[noseStart + 1]); + const sum = leftArea + rightArea + velumArea; + const rl = (2 * leftArea - sum) / sum; + const rr = (2 * rightArea - sum) / sum; + const rn = (2 * velumArea - sum) / sum; + junctionLeft[noseStart] = rl * right[noseStart - 1] + (1 + rl) * (noseLeft[0] + left[noseStart]); + junctionRight[noseStart] = rr * left[noseStart] + (1 + rr) * (right[noseStart - 1] + noseLeft[0]); + noseJunctionRight[0] = rn * noseLeft[0] + (1 + rn) * (left[noseStart] + right[noseStart - 1]); + + for (let i = 0; i < sections; i++) { + right[i] = junctionRight[i] * 0.999; + left[i] = junctionLeft[i + 1] * 0.999; + } + const lipOutput = right[sections - 1]; + + noseJunctionLeft[noseSections] = noseRight[noseSections - 1] * s.lipReflection; + for (let i = 1; i < noseSections; i++) { + const w = noseReflection[i] * (noseRight[i - 1] + noseLeft[i]); + noseJunctionRight[i] = noseRight[i - 1] - w; + noseJunctionLeft[i] = noseLeft[i] + w; + } + for (let i = 0; i < noseSections; i++) { + noseRight[i] = noseJunctionRight[i] * 0.999; + noseLeft[i] = noseJunctionLeft[i + 1] * 0.999; + } + + return lipOutput * (0.85 + s.lipOpening * 0.28) + noseRight[noseSections - 1] * Math.max(0, Math.min(1, s.velum / 0.4)); + } + + function updateTransient(s) { + const opening = s.constrictionDiameter - lastConstrictionDiameter; + if (opening > 0.18 && lastConstrictionDiameter < 0.28) { + transient += opening * s.intensity * (0.18 + s.turbulence * 0.42); + } + lastConstrictionDiameter = s.constrictionDiameter; + } + + function condition(output) { + const blocked = output - dcBlockX + 0.995 * dcBlockY; + dcBlockX = output; + dcBlockY = blocked; + return Math.tanh(blocked * 1.9); + } + + return { + render(output, s) { + updateTargets(s); + updateNose(s.velum); + updateReflection(); + updateTransient(s); + for (let i = 0; i < output.length; i++) { + slewDiameters(); + transient *= 0.995; + const g = glottis(s) + rand() * transient; + const a = step(g, s); + const b = step(g, s); + output[i] = condition((a + b) * 0.72); + } + } + }; } function draw() { @@ -243,12 +384,10 @@ function draw() { const cx = width * 0.5; const cy = height * 0.54; - const time = performance.now() * 0.001; - phase += 0.018 + state.pressure * 0.02; + phase += 0.018 + state.intensity * 0.02; drawGrid(width, height); - drawTract(cx, cy, width * 0.76, height * 0.42, time); - drawSpectralBars(width, height); + drawTract(cx, cy, width * 0.76, height * 0.42); drawReadout(width, height); animationFrame = requestAnimationFrame(draw); @@ -271,29 +410,31 @@ function drawGrid(width, height) { } } -function drawTract(cx, cy, length, scale, time) { +function drawTract(cx, cy, length, scale) { const pointsTop = []; const pointsBottom = []; const samples = 72; - const lipPinch = 1 - state.lipAperture * 0.72; - const rounding = state.lipRounding * 0.18; - const body = state.tongueBody; - const tip = state.tongueTip; - const velum = state.velum; - for (let i = 0; i <= samples; i++) { + const cell = i / samples * 44; const u = i / samples; const x = cx - length / 2 + u * length; - const tongueBody = Math.exp(-Math.pow((u - 0.48) / 0.22, 2)) * body * 0.52; - const tongueTip = Math.exp(-Math.pow((u - 0.76) / 0.12, 2)) * tip * 0.50; - const lips = Math.exp(-Math.pow((u - 0.97) / 0.08, 2)) * lipPinch; - const throat = Math.exp(-Math.pow((u - 0.10) / 0.16, 2)) * (0.12 + state.glottalTenseness * 0.18); - const pulse = Math.sin(time * (2 + state.lfoRate * 8) + u * 7) * state.amDepth * 0.08; - const radius = Math.max(0.10, 0.62 - tongueBody - tongueTip - lips - throat + rounding + pulse); - const yTop = cy - radius * scale * 0.5; - const yBottom = cy + radius * scale * 0.5; - pointsTop.push([x, yTop]); - pointsBottom.push([x, yBottom]); + let diameter = cell < 7 ? 0.6 : cell < 10 ? 1.1 : 1.5; + if (cell > 10 && cell < 39) { + const angle = 1.1 * Math.PI * (state.tongueIndex - cell) / 22; + const fixedTongueDiameter = 2 + (state.tongueDiameter - 2) / 1.5; + diameter = 1.5 - (1.5 - fixedTongueDiameter + 1.7) * Math.cos(angle); + } + const distance = Math.abs(cell - state.constrictionIndex); + const range = state.constrictionIndex < 25 ? 10 : 5; + if (distance < range) { + const narrowed = Math.max(0, state.constrictionDiameter - 0.3); + const mix = 0.5 * (1 + Math.cos(Math.PI * distance / range)); + diameter = Math.min(diameter, diameter * (1 - mix) + narrowed * mix); + } + if (i === samples) diameter = state.lipOpening; + const radius = Math.max(0.04, diameter / 3.2); + pointsTop.push([x, cy - radius * scale * 0.5]); + pointsBottom.push([x, cy + radius * scale * 0.5]); } const grad = ctx.createLinearGradient(cx - length / 2, cy, cx + length / 2, cy); @@ -318,44 +459,53 @@ function drawTract(cx, cy, length, scale, time) { ctx.lineWidth = 4; ctx.stroke(); - const glottisX = cx - length * 0.52; - const lipX = cx + length * 0.52; - drawSource(glottisX, cy, scale); - drawLips(lipX, cy, scale); - drawNasalBranch(cx + length * 0.20, cy, scale, velum); + drawSource(cx - length * 0.52, cy, scale); + drawLips(cx + length * 0.52, cy, scale); + drawNasalBranch(cx + length * 0.20, cy, scale, state.velum); + drawConstriction(cx - length / 2 + (state.constrictionIndex / 44) * length, cy, scale); drawWave(cx, cy, length, scale); } function drawSource(x, y, scale) { - const height = scale * (0.24 + state.glottalTenseness * 0.22); + const height = scale * (0.20 + state.tenseness * 0.26); ctx.fillStyle = "#f47f67"; ctx.fillRect(x - 18, y - height / 2, 10, height); ctx.fillRect(x + 8, y - height / 2, 10, height); ctx.fillStyle = "rgba(244, 127, 103, 0.25)"; ctx.beginPath(); - ctx.arc(x, y, 28 + state.pressure * 24, 0, Math.PI * 2); + ctx.arc(x, y, 24 + state.intensity * 28, 0, Math.PI * 2); ctx.fill(); } function drawLips(x, y, scale) { - const aperture = 8 + state.lipAperture * 44; - const round = 18 + state.lipRounding * 36; + const aperture = 8 + state.lipOpening * 24; ctx.strokeStyle = "#7fd18b"; ctx.lineWidth = 5; ctx.beginPath(); - ctx.ellipse(x, y, round, aperture, 0, 0, Math.PI * 2); + ctx.ellipse(x, y, 28, aperture, 0, 0, Math.PI * 2); ctx.stroke(); } function drawNasalBranch(x, y, scale, velum) { - ctx.strokeStyle = `rgba(118, 199, 212, ${0.2 + velum * 0.75})`; - ctx.lineWidth = 8 + velum * 10; + const open = (velum - 0.01) / 0.39; + ctx.strokeStyle = `rgba(118, 199, 212, ${0.18 + open * 0.78})`; + ctx.lineWidth = 5 + open * 14; ctx.beginPath(); ctx.moveTo(x, y - scale * 0.16); ctx.bezierCurveTo(x + scale * 0.12, y - scale * 0.55, x + scale * 0.40, y - scale * 0.62, x + scale * 0.60, y - scale * 0.38); ctx.stroke(); } +function drawConstriction(x, y, scale) { + const close = Math.max(0, Math.min(1, (1.2 - state.constrictionDiameter) / 1.2)); + ctx.strokeStyle = `rgba(242, 184, 75, ${0.25 + close * 0.7})`; + ctx.lineWidth = 3 + close * 9; + ctx.beginPath(); + ctx.moveTo(x, y - scale * 0.28); + ctx.lineTo(x, y + scale * 0.28); + ctx.stroke(); +} + function drawWave(cx, cy, length, scale) { ctx.strokeStyle = "rgba(240, 244, 237, 0.45)"; ctx.lineWidth = 2; @@ -363,7 +513,7 @@ function drawWave(cx, cy, length, scale) { for (let i = 0; i <= 160; i++) { const u = i / 160; const x = cx - length / 2 + u * length; - const amp = (0.12 + state.pressure * 0.22) * scale * (1 - state.turbulence * 0.35); + const amp = (0.10 + state.intensity * 0.22) * scale * (1 - state.turbulence * 0.25); const y = cy + Math.sin(u * 18 + phase) * amp * Math.sin(Math.PI * u); if (i === 0) ctx.moveTo(x, y); else ctx.lineTo(x, y); @@ -371,26 +521,13 @@ function drawWave(cx, cy, length, scale) { ctx.stroke(); } -function drawSpectralBars(width, height) { - const values = [state.mel0, state.mel1, state.mel2, state.mel3, state.mel4, state.mel5]; - const x0 = width * 0.08; - const y0 = height * 0.91; - const barW = Math.max(16, width * 0.035); - const gap = barW * 0.45; - for (let i = 0; i < values.length; i++) { - const h = values[i] * height * 0.20; - ctx.fillStyle = i < 2 ? "#f2b84b" : i < 4 ? "#7fd18b" : "#76c7d4"; - ctx.fillRect(x0 + i * (barW + gap), y0 - h, barW, h); - } -} - function drawReadout(width, height) { ctx.fillStyle = "#f0f4ed"; ctx.font = "700 22px system-ui, sans-serif"; - ctx.fillText(`voice patch target vector[20] pressure=${state.pressure.toFixed(2)} noise=${state.turbulence.toFixed(2)} velum=${state.velum.toFixed(2)}`, 28, 42); + ctx.fillText(`tract voice sections=44 nose=28 freq=${state.frequency.toFixed(1)}Hz tense=${state.tenseness.toFixed(2)} velum=${state.velum.toFixed(2)}`, 28, 42); ctx.fillStyle = "#a8b3a3"; ctx.font = "15px system-ui, sans-serif"; - ctx.fillText("These are the knobs the learned speech driver will predict", 28, height - 24); + ctx.fillText("Aqua DSL tract voice controls: source, tongue, velum, constriction, turbulence, radiation", 28, height - 24); } document.querySelectorAll("[data-preset]").forEach(button => { @@ -398,11 +535,8 @@ document.querySelectorAll("[data-preset]").forEach(button => { }); playButton.addEventListener("click", async () => { - if (audio) { - await stopAudio(); - } else { - await startAudio(); - } + if (audio) await stopAudio(); + else await startAudio(); }); panicButton.addEventListener("click", stopAudio); diff --git a/tools/vocal-tract-playground/index.html b/tools/vocal-tract-playground/index.html index 4055414..866744e 100644 --- a/tools/vocal-tract-playground/index.html +++ b/tools/vocal-tract-playground/index.html @@ -3,7 +3,7 @@ - AquaSynth Vocal Tract Playground + AquaSynth Tract Voice Playground @@ -12,7 +12,7 @@

AquaSynth lab

-

Vocal Tract Playground

+

Tract Voice Playground