Skip to content

the ultimate vocal synthesizer - sing, speak, beatbox, and more

Rust

Closure physics: no more clicks when articulators seal; working click rarefaction and ingressive breath

Jameson Hodge6f47b0b011e7
diff --git a/src/engine/anatomy/human.ts b/src/engine/anatomy/human.ts
index 2463acc..9559a48 100644
--- a/src/engine/anatomy/human.ts
+++ b/src/engine/anatomy/human.ts
@@ -306,14 +306,19 @@ export class HumanVocalTract {
const bl = dist(pF, T);
const curl = clamp(a.ttCurl, 0, 1);
const ctrl = add(add(pF, scale(tanF, bl * 0.5)), v(0, (0.18 + 0.5 * curl) * k));
- // dorsum depression (clicks): pull the middle of the blade/body down
+ // dorsum depression (clicks): hollow the tongue between the back (velar) contact at the top
+ // of the body and the tip, leaving both contacts in place, so a sealed pocket expands
const blade = bezier2(pF, ctrl, T, 7);
if (a.dorsum > 0) {
- for (let i = 0; i < arcPts.length; i++) {
- const t = i / (arcPts.length - 1);
- const w = Math.sin(Math.min(1, t * 1.3) * Math.PI);
- arcPts[i] = add(arcPts[i], v(0, -a.dorsum * 0.9 * k * w * w));
- }
+ const x0 = B.x, x1 = T.x;
+ const dip = (p: Vec): Vec => {
+ const u = (p.x - x0) / Math.max(1e-6, x1 - x0);
+ if (u <= 0 || u >= 1) return p;
+ const w = Math.sin(Math.PI * Math.pow(u, 0.8));
+ return add(p, v(0, -a.dorsum * 0.9 * k * w * w));
+ };
+ for (let i = 0; i < arcPts.length; i++) arcPts[i] = dip(arcPts[i]);
+ for (let i = 1; i < blade.length - 1; i++) blade[i] = dip(blade[i]);
}
// underside back to the frenulum / floor of mouth (jaw-carried)
const fren = J(5.7, 6.15);
diff --git a/src/engine/phonetics/planner.ts b/src/engine/phonetics/planner.ts
index f10da5f..6de8b3b 100644
--- a/src/engine/phonetics/planner.ts
+++ b/src/engine/phonetics/planner.ts
@@ -65,7 +65,7 @@ export function isVowel(ipa: string, body = "male"): boolean {
return !!VT[body]?.[ipa] || ipa in EXPAND;
}
-function vowelArtic(ipa: string, body: string): Partial<HumanArtic> | null {
+export function vowelArtic(ipa: string, body: string): Partial<HumanArtic> | null {
const v = VT[body]?.[ipa] ?? VT.male?.[ipa];
if (!v) return null;
const out: Partial<HumanArtic> = {};
diff --git a/src/engine/voice/humanAirway.ts b/src/engine/voice/humanAirway.ts
index 8ec9d9f..c77066a 100644
--- a/src/engine/voice/humanAirway.ts
+++ b/src/engine/voice/humanAirway.ts
@@ -99,31 +99,85 @@ export class HumanAirway {
maxAreaRate = 45;
/** additional rate per cm² of current area (1/s) */
areaRateGain = 40;
+ /**
+ * The last part of a closure is slower than a release: contact spreads over the palate as
+ * tissue compresses, while a release is ballistic. Sealing at the opening rate drove the air
+ * the articulator displaces through a slit that shut within ~1 ms (an audible click). Below
+ * sealHi cm² the closing rate eases from maxAreaRate down to sealRate.
+ */
+ sealRate = 5;
+ sealLo = 0.03;
+ sealHi = 0.4;
+
+ /** areas committed at the start of the current control step (slew-limit baseline) */
+ private basePh: Float64Array | null = null;
+ private baseOr: Float64Array | null = null;
+ private basePhMin: Float64Array | null = null;
+ private baseOrMin: Float64Array | null = null;
+ private baseDt = 0;
/** Geometry → targets for the next block. Returns the computed frame. `dt` enables slew limiting. */
apply(a: HumanArtic, dt = 0): HumanFrame {
+ if (dt > 0) {
+ if (!this.basePh) {
+ this.basePh = new Float64Array(this.nPh);
+ this.baseOr = new Float64Array(this.nOr);
+ this.basePhMin = new Float64Array(this.nPh);
+ this.baseOrMin = new Float64Array(this.nOr);
+ }
+ this.basePh.set(this.phAreas);
+ this.baseOr!.set(this.orAreas);
+ this.basePhMin!.set(this.phMin);
+ this.baseOrMin!.set(this.orMin);
+ }
+ this.baseDt = dt;
+ return this.commit(a, dt);
+ }
+
+ /**
+ * Recompute the geometry within the same control step (after a contact correction moved an
+ * articulator), still slew-limited against the areas the step started from: re-applying
+ * without the limit let closures appear within one block, a pressure and output spike.
+ */
+ reapply(a: HumanArtic): HumanFrame {
+ return this.commit(a, this.baseDt);
+ }
+
+ private commit(a: HumanArtic, dt: number): HumanFrame {
const f = (this.frame = this.tract.compute(a));
- const oldPh = dt > 0 ? Float64Array.from(this.phAreas) : null;
- const oldOr = dt > 0 ? Float64Array.from(this.orAreas) : null;
- const oldPhMin = dt > 0 ? Float64Array.from(this.phMin) : null;
- const oldOrMin = dt > 0 ? Float64Array.from(this.orMin) : null;
const { phLen, orLen } = this.tract.resample(a, f, this.nPh, this.nOr, this.phAreas, this.orAreas, this.phMin, this.orMin);
- if (oldPh && oldOr && oldPhMin && oldOrMin) {
+ const oldPh = this.basePh, oldOr = this.baseOr, oldPhMin = this.basePhMin, oldOrMin = this.baseOrMin;
+ if (dt > 0 && oldPh && oldOr && oldPhMin && oldOrMin) {
// both section areas and sub-section minima are rate-limited: the minima set the jet
// (Borda–Carnot) losses ∝ 1/A², so a fast drop chokes the flow within a block
// rate limit grows with cross-section: wide cavities reshape fast, narrow constrictions
// (lateral extent ~1–2 cm) open and close at physiological rates (sets burst sharpness)
const k2 = this.body.scale * this.body.scale;
const clampArr = (cur: Float64Array, old: Float64Array, mins: Float64Array, oldMins: Float64Array) => {
+ const openR = this.maxAreaRate * k2, gain = this.areaRateGain;
+ const sealR = this.sealRate * k2, lo = this.sealLo * k2, hi = this.sealHi * k2;
+ // closing rate at area A: the release rate eased down to the seal rate near contact
+ const closeR = (A: number) => {
+ const u = A <= lo ? 0 : A >= hi ? 1 : (A - lo) / (hi - lo);
+ return sealR + (openR - sealR) * u * u * (3 - 2 * u);
+ };
for (let i = 0; i < cur.length; i++) {
- const lim = (this.maxAreaRate * k2 + this.areaRateGain * Math.max(old[i], cur[i])) * dt;
const d = cur[i] - old[i];
- if (d > lim) cur[i] = old[i] + lim;
- else if (d < -lim) cur[i] = old[i] - lim;
- const limM = (this.maxAreaRate * k2 + this.areaRateGain * Math.max(oldMins[i], mins[i])) * dt;
+ if (d > 0) {
+ const lim = (openR + gain * cur[i]) * dt;
+ if (d > lim) cur[i] = old[i] + lim;
+ } else {
+ const lim = (closeR(old[i]) + gain * old[i]) * dt;
+ if (d < -lim) cur[i] = old[i] - lim;
+ }
const dm = mins[i] - oldMins[i];
- if (dm > limM) mins[i] = oldMins[i] + limM;
- else if (dm < -limM) mins[i] = oldMins[i] - limM;
+ if (dm > 0) {
+ const limM = (openR + gain * mins[i]) * dt;
+ if (dm > limM) mins[i] = oldMins[i] + limM;
+ } else {
+ const limM = (closeR(oldMins[i]) + gain * oldMins[i]) * dt;
+ if (dm < -limM) mins[i] = oldMins[i] - limM;
+ }
if (mins[i] > cur[i]) mins[i] = cur[i];
if (mins[i] < 0) mins[i] = 0;
}
diff --git a/src/engine/voice/humanVoice.ts b/src/engine/voice/humanVoice.ts
index 3d3da72..ac47be1 100644
--- a/src/engine/voice/humanVoice.ts
+++ b/src/engine/voice/humanVoice.ts
@@ -284,11 +284,13 @@ export class HumanVoice {
this.clock += dt;
// contact constraint on the frame computed anyway; re-apply only if a correction was made
this.airway.apply(this.artic.x, dt);
- if (this.enforceContacts()) this.airway.apply(this.artic.x, 0);
+ if (this.enforceContacts()) this.airway.reapply(this.artic.x);
this.airway.net.beginBlock(this.ctrlEvery);
this.ctrlCounter = this.ctrlEvery;
// breath: fast attack, slower release; a speaking score breathes on its own
- const gateGoal = Math.max(this.gateTarget, breathVal * breathAct);
+ // a negative breath gesture (ingressive: inward K snares, gasps) overrides the performer's breath
+ const scoreBreath = breathVal * breathAct;
+ const gateGoal = scoreBreath < 0 ? scoreBreath : Math.max(this.gateTarget, scoreBreath);
const tau = gateGoal > this.gate ? 0.025 : 0.07;
this.gate += (gateGoal - this.gate) * (1 - Math.exp(-dt / tau));
this.pLung = this.source.pressure * CM_H2O * this.gate;
diff --git a/tools/measure-closures.ts b/tools/measure-closures.ts
new file mode 100644
index 0000000..54f969d
--- /dev/null
+++ b/tools/measure-closures.ts
@@ -0,0 +1,31 @@
+/**
+ * Closure-onset transients in VCV syllables: the largest output step (sample-to-sample
+ * difference, a click detector) around the closure onset, relative to the vowel's own.
+ * A physical closure is quieter than the vowel it ends; a teleporting one clicks.
+ * Usage: bun tools/measure-closures.ts [p,t,k,b,d,g]
+ */
+import { HumanVoice } from "../src/engine/voice/humanVoice.ts";
+import { planUtterance } from "../src/engine/phonetics/planner.ts";
+import { tokenizeIpa } from "../src/engine/phonetics/ipa.ts";
+
+const FS = 48000;
+const items = (process.argv[2] ?? "p,t,k,b,d,g,s,n").split(",");
+const rows: string[] = [];
+for (const c of items) {
+ const v = new HumanVoice({ fsOut: FS });
+ const plan = planUtterance(tokenizeIpa(`ˈɑ${c}ɑ`), { body: "male", t0: 0.05, f0: 110 });
+ v.schedule(plan.gestures);
+ const N = Math.round(FS * (plan.end + 0.2));
+ const out = new Float32Array(N);
+ for (let i = 0; i < N; i += 128) v.render(out, i, Math.min(128, N - i));
+ const seg = plan.segments[1];
+ const step = (a: number, b: number) => {
+ let m = 0;
+ for (let i = Math.max(1, Math.round(a * FS)); i < Math.round(b * FS); i++) m = Math.max(m, Math.abs(out[i] - out[i - 1]));
+ return m;
+ };
+ const vowelStep = step(0.14, 0.26);
+ const closeStep = step(seg.t0 - 0.015, seg.t0 + 0.04);
+ rows.push(`${c} closure-onset max step / vowel max step ${(closeStep / vowelStep).toFixed(2)}`);
+}
+console.log(rows.join("\n"));