bellows-voice 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/register.ts", "../src/engines/vocal.ts", "../src/dsp/cascade.ts", "../src/dsp/air.ts", "../src/dsp/airway-tube.ts", "../src/dsp/side-branch.ts", "../src/dsp/area-rate.ts", "../src/dsp/glottal.ts", "../src/dsp/geometric-glottis.ts", "../src/dsp/pitch-servo.ts", "../src/dsp/fold-oscillator.ts", "../src/dsp/phonation-threshold.ts", "../src/dsp/junction-airway.ts", "../src/engines/vocal-beat-scores.ts", "../src/engines/vocal-planner.ts", "../src/engines/vocal-roof.ts", "../src/engines/vocal-drive.ts"],
4
- "sourcesContent": ["/*\n * The voice on the calling thread, for renderOffline() and Node, where no worklet runs it. A page\n * that plays through bellows' worklet does not need this: the plugin (plugin.ts) carries the\n * engine there, and importing this module is what puts a second copy of the DSP in a bundle.\n */\n\nimport { registerEngine } from 'bellowsjs';\nimport { vocalEngine } from './engines/vocal';\n\n/** Register the 'vocal' engine on this thread, for renderOffline(). */\nexport function registerVoice(): void {\n registerEngine(vocalEngine);\n}\n", "/*\n * Vocal: a singing voice built as an articulatory synthesizer. A sung\n * line's phonemes move CHIMERA's 17 articulators, CHIMERA's exact geometry\n * turns them into the tract's shape, and the junction airway (a waveguide\n * that carries the air itself: pressure behind closures, bursts, voice bars\n * and turbulence all come out of its flow) makes the sound.\n * docs/VOICE-2.md is the design and the measurements behind it.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49): the\n * articulators and their speeds (control/articulators.rs), the planner\n * (phonetics/planner.rs, engines/vocal-planner.ts), the geometry\n * (anatomy/human.rs, engines/vocal-geometry.ts), the airway's elements\n * (airway/network.rs, voice/human_airway.rs, dsp/junction-airway.ts), the\n * contact rule (voice/human_voice.rs:520-552) and the sung breath\n * (phonetics/planner.rs:376-379). Reimplemented here; see\n * THIRD_PARTY_NOTICES.md. The singer rules come from the literature: pitch\n * overshoot and preparation (Saitou, Unoki and Akagi 2005), the singer's\n * formant (Sundberg), first-resonance tuning on high notes (Joliveau,\n * Smith and Wolfe 2004). So do the parts that replaced CHIMERA's: the\n * articulators move as a six-stage cascade with return gestures (Birkholz\n * 2011, Birkholz and Hoole 2012, VocalTractLab 2.4's manual); the pitch\n * rise after a voiceless obstruent is a fold stiffness gesture (Hanson\n * 2009); the two fold models follow Titze and Birkholz, Drechsel and Stone\n * (2019) and Ishizaka and Flanagan (1972); the turbulence follows Stevens'\n * law with Birkholz's (2014) source types and places; the tract wall is\n * Birkholz and Zhang's (2025) stiffness and damping. docs/VOICE-2.md,\n * \"Integration 4\", measures them together.\n *\n * THE LAYERS, AND HOW OFTEN EACH RUNS (48 kHz)\n *\n * planner every 64 samples: gestures to articulator targets\n * articulators every 64: a six-stage cascade bank, then the contacts\n * geometry every 512 (a keyframe): the exact shape, rate limited\n * drive every 32: the shape between keyframes onto the grid\n * pitch every 32: glide, vibrato, microprosody, pressure\n * airway every sample\n *\n * The grids scale with the rate (block = 32 samples at 48 kHz, the\n * articulators every 2 blocks, the geometry every 16). The articulators\n * run to the end of each keyframe interval before it is heard, and the\n * glottal opening they set is read back at each block's own time, so no\n * layer leads the sound.\n *\n * EVENTS. `phoneme` starts a sound now. `nextPhoneme` says a sound will\n * start `nextIn` seconds from now (post `nextIn` first, then\n * `nextPhoneme`): the planner then starts its gestures before the sound\n * (a stop closes 22 to 31 ms early, a nasal lowers the velum 20 ms early,\n * the next vowel ramps in through the consonants before it) and releases a\n * closure before the next sound, as CHIMERA plans a whole utterance.\n * src/sing.ts posts every sound VOCAL_PLAN_LEAD ahead this way and then\n * again on its time as `phoneme`, which confirms it; a `phoneme` alone\n * still works, with gestures that start when it arrives. `bend` moves the\n * pitch through the glide; sing() posts it vocalGlideLead() early so the\n * glide is half way at the note.\n *\n * A note-on starts from rest: the planner's targets for the opening sound\n * are snapped to, the breath starts at 94 percent of its pressure (where\n * CHIMERA's sung breath, opening 70 ms before the first sound, is when it\n * sounds), every wave and state is cleared, so a reused voice equals a\n * fresh one. Events at the note-on's instant, before any sample, snap the\n * same way. A released voice keeps the sound it was released on.\n *\n * PARAMETERS THAT CHANGED MEANING FROM THE FORMANT VOICE\n *\n * glide the time scale of a pitch change: the glide's natural\n * frequency is 5.834 / (2 pi glide) Hz (98 percent in `glide`\n * at overshoot 0). Default 0.17 s, about 5.5 Hz, which with\n * the default overshoot puts a note change half way 46 ms in.\n * tension the glottal pulse's tension at velocity 0.8; velocity adds\n * 0.35 per unit above 0.8. Default 0.55.\n * breath CHIMERA's breathiness: the glottis rests open by\n * 0.1 breath^2 k^2 cm^2 plus a chink of (0.008 + 0.03 breath)\n * k^2, and aspiration follows from the flow through it.\n * body continuous from 0 (male) through 1 (female) to 2 (child):\n * targets, tables and the geometry's body constants blend\n * between neighbours. The airway's layout is set at note-on.\n * articulation multiplies every articulator's speed.\n * velocity sets lung pressure, 4 + 6.25 vel cmH2O held to 5 to 15\n * (9 at 0.8, CHIMERA's default), so a louder note is also\n * brighter and more pressed. It scales the output only under\n * 0.2, linearly to silence at 0.\n *\n * NEW: overshoot (fraction of an interval the glide passes its note by),\n * preparation (how far it first moves the wrong way), ring (the singer's\n * formant: epilarynx narrowed, larynx lowered, tongue root forward),\n * tuning (open the jaw so the first resonance stays above 1.15 f0),\n * nextPhoneme and nextIn (above), glottis (the fold model: 0 geometric,\n * dsp/geometric-glottis.ts; 1 self-oscillating, dsp/fold-oscillator.ts;\n * 2 CHIMERA's drawn pulse, the default; a sounding voice changes at its\n * next note; docs/VOICE-2.md, \"Vocal folds\", has the measurements).\n *\n * Randomness: forks 'glottis' and 'noise' (in the airway: the fold pulse's\n * perturbations, and one turbulence seed drawn per note) and 'vibrato' (the\n * vibrato's starting phase, drawn per note).\n */\n\nimport type { EngineDef, NamedRng, ParamSpec, Voice } from 'bellowsjs';\nimport { clamp } from 'bellowsjs';\nimport { CascadeBank } from '../dsp/cascade';\nimport { PitchGlide } from '../dsp/pitchglide';\nimport { Adsr } from 'bellowsjs';\nimport { CM_H2O, SOUND_SPEED } from '../dsp/air';\nimport { GLOTTIS_GEOMETRIC, GLOTTIS_PULSE, GLOTTIS_SELF_OSCILLATING, JunctionAirway, ductMin } from '../dsp/junction-airway';\nimport { VOCAL_DEFAULT_PHONEME } from './vocal-phonemes';\nimport { VOCAL_SOUND_COUNT } from './vocal-beats';\nimport { settingOffsets } from './vocal-settings';\nimport { VOCAL_BODIES, VOCAL_NEUTRAL } from './vocal-tables.gen';\nimport { ART, ARTICULATORS } from './vocal-articulators';\nimport { ARTICULATOR_MAX, ARTICULATOR_RATE, ARTICULATOR_TARGET_MIN, LIP_COMPRESSED, VocalPlanner, restTipFrom } from './vocal-planner';\nimport { VocalRoof } from './vocal-roof';\nimport { VOCAL_KEY_BLOCKS, VocalDrive } from './vocal-drive';\nimport { VOCAL_GLIDE_DEFAULTS, vocalDamping, vocalGlideSpeed } from './vocal-lead';\n\nexport { VOCAL_PLAN_LEAD, vocalDamping, vocalGlideLead, vocalGlideSpeed } from './vocal-lead';\n\n/** Every sound on the `phoneme` parameter: the phonemes, then the beats (engines/vocal-beats.ts). */\nconst PHONEMES = VOCAL_SOUND_COUNT;\n\n\n/** The largest jaw opening the tuning rule uses (template cm). */\nconst OPEN_MAX = 1.5;\n/**\n * f0 raised by full fold stiffness, cents: the planner's cricothyroid gesture after a voiceless\n * obstruent (Hanson 2009). The size of the explicit rise it replaced (MEASURED choice).\n */\nconst STIFF_CENTS = 60;\n/** How much full stiffness narrows the geometric folds' swing (x_rel; Birkholz et al. 2019: under 1 is stiffening). CHOICE. */\nconst STIFF_SWING = 0.25;\n/** f0 change per cmH2O of transglottal pressure away from the lungs', Hz at 120 Hz (MEASURED choice). */\nconst COUPLE = 1.5;\n/**\n * The singer's ear, for the geometric folds: their pressure term is taken against its own average\n * over this many seconds, so a closure's quick dip stays and the steady pressure a vowel holds above\n * the folds is sung away. CHOICE; without it the geometric folds sang held notes 2 to 7 cents flat\n * on average (MEASURED; docs/VOICE-2.md, \"Vocal folds\").\n */\nconst EAR_TAU = 0.25;\n\n/*\n * The folds per table body (male, female, child): rest length L0 cm (Birkholz, Drechsel and Stone\n * 2019: 1.6 and 1.2; the child's INFERRED), and the paper's most natural settings, male then female:\n * the lower edge's rest displacement (0.3 and 0.6 mm), the upper edge's over it (0.3 and 0 mm), the\n * phase lag between the edges (70 and 50 degrees) and double pulsing (0.05). The child takes the\n * female's. Skewness is 0.3 for all, inside the paper's tested range (-0.4 to 0.4; its best were 0\n * and 0.2): CALIBRATED, the setting whose vowel band levels came closest to CHIMERA's (0 left the\n * male 1.5 to 4 kHz 6 dB over it, 0.3 within 2.5 dB; docs/VOICE-2.md, \"Vocal folds\").\n */\nconst FOLD_LENGTH = [1.6, 1.2, 0.9];\nconst FOLD_REST = [0.03, 0.06, 0.06];\n/** The self-oscillating folds' rest displacement, cm: a wider glottis than this stops them above about 600 Hz (MEASURED). */\nconst SELF_REST = 0.01;\nconst FOLD_UPPER = [0.03, 0, 0];\nconst FOLD_LAG = [70 / 360, 50 / 360, 50 / 360];\nconst FOLD_SKEW = [0.3, 0.3, 0.3];\nconst FOLD_DOUBLE = 0.05;\n/** Medial compression per unit of tension away from 0.5, cm of rest displacement (pressed closes, lax opens). CHOICE. */\nconst PRESS = 0.04;\n/** Output gain over CHIMERA's: puts the loudest held vowel near 1 at velocity 1. */\nconst OUTPUT_GAIN = 0.25;\n/** CHIMERA's vibrato ramps out over this many seconds. */\nconst VIBRATO_FADE = 0.06;\nconst MIN_HZ = 20;\n/** Articulator steps per keyframe. */\nconst STEPS = VOCAL_KEY_BLOCKS / 2;\n/** CHIMERA's geometry body constants per table body (human.rs:276-278). */\nconst LIP_WIDTH = [4.6, 4.4, 4.0];\n\nconst DEFAULTS = VOCAL_GLIDE_DEFAULTS;\n\nfunction initial(params: Record<string, number>, spec: ParamSpec): number {\n const v = params[spec.name];\n return typeof v === 'number' && Number.isFinite(v) ? v : spec.default;\n}\n\n/** Grid sections for a shortest tract of minLength cm at a rate. */\nfunction gridSections(rate: number, minLength: number): number {\n const dx = SOUND_SPEED / (2 * rate);\n return Math.max(8, Math.floor((minLength - ductMin(rate)) / dx));\n}\n\nclass VocalVoice implements Voice {\n private readonly sr: number = 0;\n private readonly air: JunctionAirway;\n private readonly drive: VocalDrive;\n private readonly roofs: VocalRoof[];\n private readonly planner = new VocalPlanner();\n private readonly bank: CascadeBank;\n private readonly glide: PitchGlide;\n private readonly env: Adsr;\n private readonly vibRng: NamedRng;\n private readonly blk: number = 0;\n private readonly stepEvery: number = 0;\n private readonly keyEvery: number = 0;\n private readonly envBuf: Float32Array;\n\n /* Scratch. */\n private readonly art = new Float64Array(ARTICULATORS);\n private readonly tip = new Float64Array(2);\n private readonly rate = new Float64Array(ARTICULATORS);\n /** The glottal opening and closure at each articulator step of the keyframe interval (0 is its start). */\n private readonly abdAt = new Float64Array(STEPS + 1);\n private readonly cloAt = new Float64Array(STEPS + 1);\n private readonly stfAt = new Float64Array(STEPS + 1);\n /** The planner's breath (a factor on lung pressure) and whether a beat line holds it, per step. */\n private readonly lungAt = new Float64Array(STEPS + 1);\n private readonly beatOn = new Uint8Array(STEPS + 1);\n private lungFactor = 1;\n private beatLine = 0;\n /* Voice settings (Laver 1980: long-term postures over every sound) and anatomy. */\n private readonly setting = { jawSet: 0, tongueFront: 0, tongueHigh: 0, lipRound: 0, lipOpen: 0, larynxSet: 0, nasal: 0, twang: 0, throat: 0 };\n /** Each articulator's offset from the settings; a consonant holding the articulator takes it back. */\n private readonly setOff = new Float64Array(ARTICULATORS);\n /** Anatomy: the whole tract's length and the pharynx's, factors on the body's. */\n private size = 1;\n private pharynxScale = 1;\n /** A contact's new position for each axis (x then y), for CascadeBank.placeFrom. */\n private readonly placed = new Float64Array(2);\n /** The time of the articulator step or block being computed, s (a field: no double crosses a call). */\n private at = 0;\n\n /* Parameters. */\n private phonemeParam = VOCAL_DEFAULT_PHONEME;\n private bendParam = 0;\n private body = 0;\n private tension = 0.55;\n private breath = 0.15;\n private vibInc = 0;\n private vibDepth = 0.3;\n private vibDelay = 0.25;\n private articulation = 1;\n private attack = 0.02;\n private release = 0.15;\n private level = 1;\n private ring = 0;\n private tuning = 0;\n private nextIn = 0;\n\n /* Note. */\n private live = false;\n private fresh = false;\n private released = false;\n private noteHz = 220;\n private vel = 0.8;\n /** Samples since note-on, and the current block's position. */\n private pos = 0;\n private bi = 0;\n /** Samples left in the keyframe interval, and blocks begun in it. */\n private intervalLeft = 0;\n private blockInInterval = 0;\n private end = Infinity;\n private pLungTarget = 9;\n /** Lung pressure, cmH2O. */\n private pLung = 0;\n private pCoupleHz = 0;\n /** The pressure above the folds as the singer has adapted to it, dyn/cm^2 (geometric folds). */\n private pEar = 0;\n\n\n /* Body blend in force. */\n private bLo = 0;\n private bW = 0;\n private k = 1;\n\n /* Pitch. */\n private vibPhase = 0;\n private bloomT = 0;\n private bloomFrom = 0;\n private bloomNow = 0;\n private tuneJaw = 0;\n private abduction = 0;\n private closure = 0;\n private stiffness = 0;\n private foldRest = 0.03;\n private glottisModel = GLOTTIS_PULSE;\n private f0Now = 110;\n private depth = 0;\n /* The layout and geometry body last laid out (-1: none). */\n private laidK = -1;\n private laidN = -1;\n private laidJv = -1;\n private laidGeoK = -1;\n private laidPh = -1;\n private laidTongue = -1;\n private laidLips = -1;\n\n constructor(sampleRate: number, params: Record<string, number>, rng: NamedRng) {\n this.sr = sampleRate;\n this.roofs = VOCAL_BODIES.map((t) => new VocalRoof(t));\n // room for the largest head (size 1.25): a longer tract with too few sections went into the uniform\n // back duct and bent the area function (MEASURED: F2 at 0.756 of the size-1 value at size 1.2, not 0.833)\n this.air = new JunctionAirway(sampleRate, gridSections(sampleRate, VOCAL_BODIES[0].minLength * 1.25), rng);\n this.drive = new VocalDrive(sampleRate);\n this.blk = this.air.block;\n this.stepEvery = 2 * this.blk;\n this.keyEvery = VOCAL_KEY_BLOCKS * this.blk;\n this.bank = new CascadeBank(ARTICULATORS, sampleRate / this.stepEvery);\n this.glide = new PitchGlide(sampleRate / this.blk);\n this.env = new Adsr(sampleRate);\n this.vibRng = rng.fork('vibrato');\n this.envBuf = new Float32Array(this.blk);\n this.bi = this.blk;\n for (const spec of PARAMS) this.setParam(spec.name, initial(params, spec));\n }\n\n noteOn(freq: number, vel: number): void {\n this.noteHz = clamp(Number.isFinite(freq) ? freq : 220, MIN_HZ, this.sr * 0.25);\n this.vel = clamp(Number.isFinite(vel) ? vel : 0.8, 0, 1);\n this.live = true;\n this.fresh = true;\n this.released = false;\n this.end = Infinity;\n this.env.reset();\n this.env.trigger();\n this.vibPhase = this.vibRng();\n this.bloomT = 0;\n this.bloomFrom = 0;\n this.bloomNow = 0;\n this.start();\n }\n\n noteOff(): void {\n if (!this.live || this.released) return;\n this.released = true;\n this.env.release();\n this.end = this.pos / this.sr;\n this.planner.setEnd(this.end);\n }\n\n get active(): boolean {\n return this.live;\n }\n\n setParam(name: string, value: number): void {\n if (!Number.isFinite(value)) return;\n switch (name) {\n case 'phoneme':\n this.setPhoneme(value);\n return;\n case 'nextIn':\n this.nextIn = clamp(value, 0, 1);\n return;\n case 'nextPhoneme':\n this.setNext(value);\n return;\n case 'bend':\n this.setBend(value);\n return;\n case 'glide':\n this.glide.setSpeed(vocalGlideSpeed(value));\n return;\n case 'overshoot':\n this.glide.setDamping(vocalDamping(clamp(value, 0, 0.5)));\n return;\n case 'preparation':\n this.glide.setPreparation(clamp(value, 0, 1));\n return;\n case 'body':\n this.body = clamp(value, 0, 2);\n this.applyBody();\n if (this.live && this.fresh) this.start();\n return;\n case 'tension':\n this.tension = clamp(value, 0, 1);\n this.applyTension();\n return;\n case 'roughness':\n this.air.glottis.setRoughness(clamp(value, 0, 1));\n return;\n case 'fry':\n this.air.glottis.setFry(clamp(value, 0, 1));\n return;\n case 'drift':\n this.air.glottis.setDrift(clamp(value, 0, 20));\n return;\n case 'glottis':\n this.setGlottis(value);\n return;\n case 'breath':\n this.breath = clamp(value, 0, 1);\n return;\n case 'vibratoRate':\n this.vibInc = (clamp(value, 0, 12) * this.blk) / this.sr;\n return;\n case 'vibratoDepth':\n this.vibDepth = clamp(value, 0, 2);\n return;\n case 'vibratoDelay':\n this.vibDelay = clamp(value, 0, 1);\n return;\n case 'articulation':\n this.articulation = clamp(value, 0.25, 4);\n return;\n case 'attack':\n this.attack = clamp(value, 0.001, 1);\n this.env.set(this.attack, 0.05, 1, this.release);\n return;\n case 'release':\n this.release = clamp(value, 0.01, 2);\n this.env.set(this.attack, 0.05, 1, this.release);\n return;\n case 'level':\n this.level = clamp(value, 0, 2);\n return;\n case 'ring':\n this.ring = clamp(value, 0, 1);\n return;\n case 'mic':\n this.air.mic = clamp(value, 0, 1);\n return;\n case 'cheeks':\n this.air.cheeks = clamp(value, 0, 1);\n return;\n case 'piriform':\n this.air.piriform = value >= 0.5 ? 1 : 0;\n return;\n case 'size':\n this.size = clamp(value, 0.8, 1.25);\n this.applyBody();\n return;\n case 'pharynx':\n this.pharynxScale = clamp(value, 0.8, 1.25);\n return;\n case 'jawSet':\n case 'tongueFront':\n case 'tongueHigh':\n case 'lipRound':\n case 'lipOpen':\n case 'larynxSet':\n case 'throat':\n this.setting[name] = clamp(value, -1, 1);\n this.settings();\n return;\n case 'nasal':\n case 'twang':\n this.setting[name] = clamp(value, 0, 1);\n this.settings();\n return;\n case 'tuning':\n this.tuning = clamp(value, 0, 1);\n return;\n }\n }\n\n /** 0 geometric, 1 self-oscillating, 2 the parametric pulse; a voice that is sounding changes at its next note. */\n private setGlottis(value: number): void {\n const m = clamp(Math.round(value), 0, 2);\n this.glottisModel = m === 1 ? GLOTTIS_SELF_OSCILLATING : m === 2 ? GLOTTIS_PULSE : GLOTTIS_GEOMETRIC;\n if (!this.live) this.air.model = this.glottisModel;\n this.applyTension();\n }\n\n private setPhoneme(value: number): void {\n const idx = clamp(Math.round(value), 0, PHONEMES - 1);\n this.phonemeParam = idx;\n if (!this.live || this.released) return;\n if (this.fresh) this.start();\n else this.planner.addNow(idx, this.pos / this.sr);\n }\n\n private setNext(value: number): void {\n const idx = clamp(Math.round(value), 0, PHONEMES - 1);\n if (!this.live || this.released) return;\n this.planner.addUpcoming(idx, this.pos / this.sr + this.nextIn);\n if (this.fresh) this.settle();\n }\n\n private setBend(value: number): void {\n const b = clamp(value, -48, 48);\n this.bendParam = b;\n if (!this.live || this.released) return;\n if (this.fresh) this.glide.snap(b);\n else if (b !== this.glide.target) {\n this.glide.setTarget(b);\n this.bloomFrom = this.bloomNow;\n this.bloomT = 0;\n }\n }\n\n process(outL: Float32Array, outR: Float32Array, from: number, to: number): void {\n if (!this.live) return;\n const air = this.air;\n const blk = this.blk;\n let i = from;\n while (i < to) {\n if (this.bi === blk) {\n if (this.intervalLeft === 0) this.interval();\n this.beginBlock();\n this.bi = 0;\n }\n const left = blk - this.bi;\n const n = left < to - i ? left : to - i;\n const eb = this.envBuf;\n this.env.fill(eb, 0, n);\n air.render(outL, outR, i, n, this.bi, eb);\n this.bi += n;\n this.pos += n;\n this.intervalLeft -= n;\n i += n;\n }\n if (to > from) this.fresh = false;\n if (!this.env.active) this.live = false;\n }\n\n /* ---------------------------------------------------------------- */\n /* Note start */\n /* ---------------------------------------------------------------- */\n\n private applyBody(): void {\n const b = this.body;\n this.bLo = Math.floor(b) < 2 ? Math.floor(b) : 1;\n this.bW = b - this.bLo;\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n this.k = (A.k * (1 - w) + B.k * w) * this.size;\n this.planner.setBody(b);\n const lo = this.bLo;\n const air = this.air;\n air.foldLength = FOLD_LENGTH[lo] * (1 - w) + FOLD_LENGTH[lo + 1] * w;\n air.upperRest = FOLD_UPPER[lo] * (1 - w) + FOLD_UPPER[lo + 1] * w;\n air.lag = FOLD_LAG[lo] * (1 - w) + FOLD_LAG[lo + 1] * w;\n air.skew = FOLD_SKEW[lo] * (1 - w) + FOLD_SKEW[lo + 1] * w;\n air.doublePulse = FOLD_DOUBLE;\n this.foldRest = FOLD_REST[lo] * (1 - w) + FOLD_REST[lo + 1] * w;\n this.applyTension();\n }\n\n private applyTension(): void {\n const t = clamp(this.tension + 0.35 * (this.vel - 0.8), 0, 1);\n this.air.glottis.setTension(t);\n // the model that is sounding: a change waits for the next note, and the queued model's rest moved the\n // sounding folds (MEASURED: 2.4 dB on a held note switched from 1 to 0)\n const base = this.air.model === GLOTTIS_SELF_OSCILLATING ? SELF_REST : this.foldRest;\n this.air.restOffset = base + PRESS * (0.5 - t);\n }\n\n /** Everything from rest, on the current phoneme, bend and body. */\n private start(): void {\n this.pos = 0;\n this.bi = this.blk;\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n const k = this.k;\n const ps = this.pharynxScale;\n const pharynx = (A.pharynxScale * (1 - w) + B.pharynxScale * w) * ps;\n const tongue = A.tongueRadius * (1 - w) + B.tongueRadius * w;\n const lips = LIP_WIDTH[this.bLo] * (1 - w) + LIP_WIDTH[this.bLo + 1] * w;\n // the shortest tract shrinks with the size and, for about half its length, with the pharynx; an\n // estimate on the short side only lengthens the back duct, never shortens a grid section\n const minLength = (A.minLength * (1 - w) + B.minLength * w) * this.size * Math.min(1, 0.55 + 0.45 * ps);\n const neutralPharynx = (A.neutralPharynx * (1 - w) + B.neutralPharynx * w) * this.size * ps;\n const air = this.air;\n const n = Math.min(air.nMax, gridSections(this.sr, minLength));\n const lb = minLength - n * air.dx;\n const jv = clamp(Math.round((neutralPharynx - lb) / air.dx), 2, n - 2);\n // a new layout only for a new body; the same one just rests (configure runs cold, and cold code boxes)\n if (k !== this.laidK || n !== this.laidN || jv !== this.laidJv) {\n air.configure(k, n, jv);\n this.laidK = k;\n this.laidN = n;\n this.laidJv = jv;\n } else air.reset();\n if (pharynx !== this.laidPh || tongue !== this.laidTongue || lips !== this.laidLips || k !== this.laidGeoK) {\n this.drive.setBody(k, pharynx, tongue, lips);\n this.laidGeoK = k;\n this.laidPh = pharynx;\n this.laidTongue = tongue;\n this.laidLips = lips;\n }\n air.model = this.glottisModel;\n this.applyTension();\n this.planner.clear();\n this.planner.addNow(this.phonemeParam, 0);\n this.glide.snap(this.bendParam);\n this.pLungTarget = clamp(4 + 6.25 * this.vel, 5, 15);\n // a beat line starts breath-held: the beatboxer breathes only into a sound\n this.pLung = this.planner.silentAt(0) || this.planner.beatAt(0) ? 0 : 0.94 * this.pLungTarget;\n this.pCoupleHz = COUPLE * (this.noteHz / 120);\n this.pEar = 0;\n this.tuneJaw = 0;\n this.settle();\n }\n\n /** Snap the articulators and the shape to the plan at the current time (fresh notes only). */\n private settle(): void {\n const bank = this.bank;\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, VOCAL_NEUTRAL[i]);\n this.at = this.pos / this.sr;\n for (let pass = 0; pass < 3; pass++) {\n this.targets();\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, this.planner.target[i]);\n this.contact();\n // at rest where the contacts hold it: a note that opens on a closure starts pressed, not mid-movement\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, bank.values[i]);\n }\n this.art.set(bank.values);\n this.drive.key(this.art, true);\n this.updateGlottis();\n for (let q = 0; q <= STEPS; q++) {\n this.abdAt[q] = this.abduction;\n this.cloAt[q] = this.closure;\n this.stfAt[q] = this.stiffness;\n this.lungAt[q] = this.lungFactor;\n this.beatOn[q] = this.beatLine;\n }\n this.intervalLeft = 0;\n this.blockInInterval = 0;\n }\n\n /* ---------------------------------------------------------------- */\n /* Control */\n /* ---------------------------------------------------------------- */\n\n /** Planner targets at `at`, with the singer's offsets, clamped, into planner.target. */\n private targets(): void {\n restTipFrom(this.bank.values, this.tip);\n const p = this.planner;\n p.at = this.at;\n p.restX = this.tip[0];\n p.restY = this.tip[1];\n p.evaluateNow();\n const tg = p.target;\n const ring = this.ring;\n const tj = this.tuneJaw;\n tg[ART.epilarynx] += ring;\n tg[ART.larynx] -= 0.6 * ring;\n tg[ART.root] += 0.4 * ring;\n tg[ART.jaw] += tj;\n tg[ART.tbY] -= tj;\n tg[ART.lipAp] += 0.5 * tj;\n // the voice's settings, given back wherever a consonant holds the articulator (a closure still closes)\n const so = this.setOff;\n const held = p.held;\n for (let i = 0; i < ARTICULATORS; i++) tg[i] += so[i] * (1 - held[i]);\n for (let i = 0; i < ARTICULATORS; i++) {\n const v = tg[i];\n tg[i] = v < ARTICULATOR_TARGET_MIN[i] ? ARTICULATOR_TARGET_MIN[i] : v > ARTICULATOR_MAX[i] ? ARTICULATOR_MAX[i] : v;\n }\n }\n\n /**\n * The settings as articulator offsets. Each is a long-term posture laid over every sound, as Laver\n * (1980, The Phonetic Description of Voice Quality) describes them: jaw open or close, tongue\n * fronted or backed and raised or lowered, lips rounded and protruded or spread, larynx raised or\n * lowered, nasal (the velum down), twang (the epilarynx narrowed, the larynx a little up), and an\n * open or constricted throat (the tongue root forward or back): engines/vocal-settings.ts.\n */\n private settings(): void {\n // the shared table (engines/vocal-settings.ts), so the engine and the mouth view agree\n settingOffsets(this.setting, this.setOff);\n }\n\n private updateGlottis(): void {\n const k2 = this.k * this.k;\n const b = this.breath;\n this.abduction = (0.1 * b * b + 0.008 + 0.03 * b) * k2 + this.planner.abduction * k2;\n this.closure = this.planner.closure;\n this.stiffness = this.planner.stiffness;\n this.lungFactor = this.planner.breath;\n this.beatLine = this.planner.beat;\n }\n\n /** One articulator step ending at time `at`. */\n private step(): void {\n this.targets();\n const bank = this.bank;\n const p = this.planner;\n const art = this.articulation;\n const rate = this.rate;\n for (let i = 0; i < ARTICULATORS; i++) rate[i] = ARTICULATOR_RATE[i] * p.speed[i] * art;\n bank.setAll(p.target, rate);\n bank.step();\n this.contact();\n this.updateGlottis();\n }\n\n /**\n * Tip and body may press 0.1 k cm into the roof; past that they are\n * projected back along the contact normal (CHIMERA human_voice.rs:520-552).\n * CHIMERA then removes the inward part of the velocity; in the cascade\n * the velocity is the stages behind the output, so only the output stage\n * is moved and those stages keep going toward a target past the roof (a\n * /t/ aims 0.29 k cm past it). The articulator presses into the roof\n * while they do, and when its target turns back it leaves the roof\n * already accelerating. The lips likewise stop at LIP_COMPRESSED while\n * their stages go on to the virtual closure target.\n */\n private contact(): void {\n const bank = this.bank;\n if (bank.values[ART.lipAp] < LIP_COMPRESSED) {\n this.placed[0] = LIP_COMPRESSED;\n bank.placeFrom(ART.lipAp, this.placed, 0);\n }\n const roof = this.roofs[this.bW < 0.5 ? this.bLo : this.bLo + 1];\n const k = roof.k;\n const lim = -0.1 * k;\n const a = this.art;\n a.set(bank.values);\n // the body: its circle against the roof\n roof.bodyPoint(a);\n roof.x = roof.bx;\n roof.y = roof.by;\n roof.project();\n if (roof.sd - roof.r < lim) {\n this.depth = lim - (roof.sd - roof.r);\n this.push(roof, ART.tbX, ART.tbY);\n }\n a.set(bank.values);\n roof.tipPoint(a);\n roof.x = roof.tipX;\n roof.y = roof.tipY;\n roof.project();\n if (roof.sd < lim) {\n this.depth = lim - roof.sd;\n this.push(roof, ART.ttX, ART.ttY);\n }\n }\n\n /**\n * Move the output stages of articulators (ix, iy), at the roof's point\n * (x, y) with signed distance sd from it, out by `depth` along the normal.\n */\n private push(roof: VocalRoof, ix: number, iy: number): void {\n const sd = roof.sd;\n const depth = this.depth;\n let nx = roof.x - roof.qx;\n let ny = roof.y - roof.qy;\n const len = Math.sqrt(nx * nx + ny * ny);\n if (!(len > 1e-9)) {\n nx = 0;\n ny = -1;\n } else {\n // the normal points into the airway: away from the roof from below it, toward it from above\n const s = sd >= 0 ? 1 / len : -1 / len;\n nx *= s;\n ny *= s;\n }\n const bank = this.bank;\n const val = bank.values;\n const ax = val[ix];\n const ay = val[iy];\n const k = roof.k;\n const sx = (ax > 0.5 ? 0.86 : 1) * k;\n const sy = (ay < 7 ? roof.pharynxScale : 1) * k;\n const pl = this.placed;\n pl[0] = ax + (nx * depth) / sx;\n pl[1] = ay + (ny * depth) / sy;\n bank.placeFrom(ix, pl, 0);\n bank.placeFrom(iy, pl, 1);\n }\n\n /** A keyframe interval starts: the articulators to its end, then the shape there. */\n private interval(): void {\n const sr = this.sr;\n this.abdAt[0] = this.abdAt[STEPS];\n this.cloAt[0] = this.cloAt[STEPS];\n this.stfAt[0] = this.stfAt[STEPS];\n this.lungAt[0] = this.lungAt[STEPS];\n this.beatOn[0] = this.beatOn[STEPS];\n for (let q = 1; q <= STEPS; q++) {\n this.at = (this.pos + q * this.stepEvery) / sr;\n this.step();\n this.abdAt[q] = this.abduction;\n this.cloAt[q] = this.closure;\n this.stfAt[q] = this.stiffness;\n this.lungAt[q] = this.lungFactor;\n this.beatOn[q] = this.beatLine;\n }\n this.art.set(this.bank.values);\n this.drive.key(this.art, false);\n this.planner.forget(this.pos / sr);\n this.intervalLeft = this.keyEvery;\n this.blockInInterval = 0;\n }\n\n /** A voice block starts: shape, pitch, breath and glottis for its samples. */\n private beginBlock(): void {\n const sr = this.sr;\n const blk = this.blk;\n const air = this.air;\n this.blockInInterval++;\n const b = this.blockInInterval;\n const drive = this.drive;\n drive.u = b / VOCAL_KEY_BLOCKS;\n drive.toAirway(air);\n // the glottis at the block's end, from the articulator steps either side\n const sf = (b * STEPS) / VOCAL_KEY_BLOCKS;\n const s0 = Math.floor(sf);\n const s1 = s0 < STEPS ? s0 + 1 : STEPS;\n const fr = sf - s0;\n air.agStatic = this.abdAt[s0] + (this.abdAt[s1] - this.abdAt[s0]) * fr;\n air.closure = this.cloAt[s0] + (this.cloAt[s1] - this.cloAt[s0]) * fr;\n // the posterior chink: CHIMERA's (0.008 + 0.03 breath) k^2 part of the opening above\n const k2 = this.k * this.k;\n air.chink = (0.008 + 0.03 * this.breath) * k2;\n const stiff = this.stfAt[s0] + (this.stfAt[s1] - this.stfAt[s0]) * fr;\n air.xRel = 1 - STIFF_SWING * stiff;\n const lung = this.lungAt[s0] + (this.lungAt[s1] - this.lungAt[s0]) * fr;\n const beatLine = this.beatOn[s0] | this.beatOn[s1];\n const t = (this.pos + blk / 2) / sr;\n const p = this.planner;\n p.at = t;\n p.queryNow();\n\n // pitch: the glide, the vibrato blooming in, the folds' stiffness, the pressure across the folds\n this.glide.advance();\n const bend = this.glide.value;\n this.bloomT += blk / sr;\n const bt = this.bloomT;\n const up = 0.5 - 0.5 * Math.cos(Math.PI * Math.min(bt / Math.max(this.vibDelay, 1e-9), 1));\n const down = this.bloomFrom * (0.5 + 0.5 * Math.cos(Math.PI * Math.min(bt / VIBRATO_FADE, 1)));\n this.bloomNow = up > down ? up : down;\n let ph = this.vibPhase + this.vibInc;\n if (ph >= 1) ph -= 1;\n this.vibPhase = ph;\n const vib = Math.sin(2 * Math.PI * ph) * this.vibDepth * this.bloomNow;\n const f0 = this.noteHz * Math.pow(2, (bend + vib) / 12 + (stiff * STIFF_CENTS) / 1200);\n this.f0Now = f0;\n this.tune();\n // f0 follows the pressure across the folds against the pressure below them, which is the pressure\n // above them: a closure above the folds lowers it, effort (both pressures together) does not\n // (Titze 1989: 2 to 6 Hz per cmH2O). The geometric folds read it from block means, against the\n // singer's ear (EAR_TAU); the pulse keeps\n // its reading of each block's last sample, which aliases the cycle (MEASURED: a female /\u0251/ at\n // 494 Hz 19 cents sharp; docs/VOICE-2.md, \"Vocal folds\"). Self-oscillating folds find all this\n // themselves: their servo aims at the note.\n const pa = air.pSupra;\n this.pEar += (pa - this.pEar) * (1 - Math.exp(-blk / sr / EAR_TAU));\n if (air.model === GLOTTIS_SELF_OSCILLATING) air.f0 = f0;\n else if (air.model === GLOTTIS_GEOMETRIC) air.f0 = f0 - (this.pCoupleHz * Math.max(pa - this.pEar, 0)) / CM_H2O;\n else air.f0 = f0 + (this.pCoupleHz * (Math.max(air.dpSmooth, 0) - Math.max(air.pSubSmooth, 0))) / CM_H2O;\n\n // the sung breath (planner.rs:376-379): full drive from the note-on to its end, off in silences\n const gate = t < this.end && p.silent === 0 ? 1 : 0;\n // a beat's breath is a gesture of its own, tens of milliseconds long: the lungs follow it closely\n const tau = beatLine === 1 ? 0.003 : gate ? 0.025 : 0.05;\n this.pLung += (this.pLungTarget * gate * lung - this.pLung) * (1 - Math.exp(-blk / sr / tau));\n air.pLung = this.pLung * CM_H2O;\n // velocity is lung pressure above 0.2; under it the note also fades, so velocity 0 is silent\n air.gain = OUTPUT_GAIN * this.level * Math.min(this.vel / 0.2, 1);\n air.beginBlock();\n }\n\n /** Formant tuning: open the jaw so the vowel's first resonance stays above 1.15 f0 (the block's f0Now). */\n private tune(): void {\n const f0 = this.f0Now;\n if (!(this.tuning > 0)) {\n this.tuneJaw = 0;\n return;\n }\n const v = this.planner.vowel;\n if (v < 0) {\n this.tuneJaw = 0;\n return;\n }\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n const slope = A.tuneSlope[v] * (1 - w) + B.tuneSlope[v] * w;\n // only where opening raises R1 (an open vowel's falls as the tongue drops into the pharynx)\n if (slope < 20) {\n this.tuneJaw = 0;\n return;\n }\n const r1 = A.tuneR1[v] * (1 - w) + B.tuneR1[v] * w;\n const jaw = A.tuneJaw[v] * (1 - w) + B.tuneJaw[v] * w;\n const need = (1.15 * f0 - r1) / slope;\n const room = 2.6 - jaw;\n this.tuneJaw = this.tuning * Math.min(OPEN_MAX, room, need > 0 ? need : 0);\n }\n}\n\nconst PARAMS: ParamSpec[] = [\n { name: 'phoneme', min: 0, max: PHONEMES - 1, default: VOCAL_DEFAULT_PHONEME },\n { name: 'bend', min: -48, max: 48, default: 0, unit: 'st' },\n { name: 'glide', min: 0.005, max: 0.5, default: DEFAULTS.glide, curve: 'exp', unit: 's' },\n { name: 'body', min: 0, max: 2, default: 0 },\n { name: 'tension', min: 0, max: 1, default: 0.55 },\n /*\n * 0.02, not CHIMERA's 0.1. MEASURED on the pulse folds (docs/VOICE-NORMS.md): at 0.1 every body\n * read 1.2 to 1.3 percent jitter and 3.8 to 4.8 percent shimmer, past the MDVP screening limits\n * (1.04, 3.81) and heard as an old voice; at 0.02, 0.71 to 0.78 percent and 2.2 to 3.0 percent,\n * near the healthy means (0.63, 2.0). Raise it for an older or rougher voice.\n */\n { name: 'roughness', min: 0, max: 1, default: 0.02 },\n { name: 'fry', min: 0, max: 1, default: 0 },\n { name: 'drift', min: 0, max: 20, default: 6, unit: 'cents' },\n { name: 'glottis', min: 0, max: 2, default: 2 },\n { name: 'breath', min: 0, max: 1, default: 0.15 },\n { name: 'vibratoRate', min: 0, max: 12, default: 5.5, unit: 'Hz' },\n { name: 'vibratoDepth', min: 0, max: 2, default: 0.3, unit: 'st' },\n { name: 'vibratoDelay', min: 0, max: 1, default: 0.25, unit: 's' },\n { name: 'articulation', min: 0.25, max: 4, default: 1, curve: 'exp' },\n { name: 'attack', min: 0.001, max: 1, default: 0.02, curve: 'exp', unit: 's' },\n { name: 'release', min: 0.01, max: 2, default: 0.15, curve: 'exp', unit: 's' },\n { name: 'level', min: 0, max: 2, default: 1 },\n { name: 'overshoot', min: 0, max: 0.5, default: DEFAULTS.overshoot },\n { name: 'preparation', min: 0, max: 1, default: DEFAULTS.preparation },\n { name: 'ring', min: 0, max: 1, default: 0 },\n { name: 'mic', min: 0, max: 1, default: 0 },\n { name: 'cheeks', min: 0, max: 1, default: 0 },\n { name: 'piriform', min: 0, max: 1, default: 0 },\n { name: 'size', min: 0.8, max: 1.25, default: 1 },\n { name: 'pharynx', min: 0.8, max: 1.25, default: 1 },\n { name: 'jawSet', min: -1, max: 1, default: 0 },\n { name: 'tongueFront', min: -1, max: 1, default: 0 },\n { name: 'tongueHigh', min: -1, max: 1, default: 0 },\n { name: 'lipRound', min: -1, max: 1, default: 0 },\n { name: 'lipOpen', min: -1, max: 1, default: 0 },\n { name: 'larynxSet', min: -1, max: 1, default: 0 },\n { name: 'nasal', min: 0, max: 1, default: 0 },\n { name: 'twang', min: 0, max: 1, default: 0 },\n { name: 'throat', min: -1, max: 1, default: 0 },\n { name: 'tuning', min: 0, max: 1, default: 0 },\n { name: 'nextIn', min: 0, max: 1, default: 0, unit: 's' },\n { name: 'nextPhoneme', min: 0, max: PHONEMES - 1, default: 0 },\n];\n\nexport const vocalEngine: EngineDef = {\n id: 'vocal',\n label: 'Vocal',\n params: PARAMS,\n polyphony: 8,\n createVoice: (sampleRate, initParams, rng) => new VocalVoice(sampleRate, initParams, rng),\n};\n", "/*\n * A cascade of identical first-order lags, H(s) = 1 / (1 + tau s)^N: the\n * target approximation Birkholz fitted to measured articulator movements\n * (Birkholz, Kroger and Neuschaefer-Rube 2011, IEEE TASLP 19(5); Birkholz\n * and Hoole 2012, Interspeech: the fit error falls steeply up to N = 5 or\n * 6, and VocalTractLab uses 6). Implemented here from those papers.\n *\n * Why not the critically damped second-order tracker (critdamp.ts, N = 2):\n * from rest its velocity peaks at 0.17 of the 98 percent time with 26\n * percent of the way done, a fast start and a long tail. Real movements are\n * nearer symmetric and bell shaped; at N = 6 the peak comes at 0.42 of the\n * 98 percent time with 38 percent done.\n *\n * Each stage follows the one before it: x_k' = (x_{k-1} - x_k) / tau, with\n * x_0 the target and x_N the output. With the target held over a step of\n * length h, the errors e_k = x_k - target evolve exactly as\n *\n * e_k(h) = exp(-r) sum_{j=1..k} e_j(0) r^(k-j) / (k-j)!, r = h / tau\n *\n * (each stage is the gamma-shaped impulse response of the ones before it),\n * so a step is N (N + 1) / 2 multiply-adds with coefficients computed once\n * per rate. It is the continuous solution sampled at the step times, at any\n * step rate, stable for any r.\n *\n * Time: from rest the remaining fraction after t is the gamma tail\n * exp(-u) sum_{k<N} u^k / k!, u = t / tau. It reaches 2 percent at u =\n * 12.03 for N = 6 (5.83 for N = 2), so setTime(s) sets tau = s / 12.03.\n *\n * A rate change leaves the stages where they are: position stays\n * continuous and velocity scales with the rate (critdamp.ts scales it the\n * same way on a slowdown).\n *\n * Contact: place() moves the output stage alone. The stages before it are\n * the movement still on its way, so an articulator held against a surface\n * keeps that motion (a target past the surface stays past it), and when the\n * target turns back the output leaves the surface already accelerating.\n *\n * The only state is Float64Arrays sized at construction; step() returns\n * nothing (V8 boxes a double returned from a call it does not inline), so\n * nothing on the step path allocates.\n */\n\nimport { clamp } from 'bellowsjs';\n\n/** The default order: VocalTractLab's. */\nexport const CASCADE_ORDER = 6;\n\n/** u at which the gamma tail exp(-u) sum_{k<n} u^k / k! falls to 1 - fraction. */\nexport function cascadeSettle(order: number, fraction = 0.98): number {\n const tail = (u: number) => {\n let term = 1;\n let sum = 1;\n for (let k = 1; k < order; k++) {\n term *= u / k;\n sum += term;\n }\n return Math.exp(-u) * sum;\n };\n let lo = 0;\n let hi = 10 * order + 50;\n for (let it = 0; it < 200; it++) {\n const mid = 0.5 * (lo + hi);\n if (tail(mid) > 1 - fraction) lo = mid;\n else hi = mid;\n }\n return 0.5 * (lo + hi);\n}\n\n/** t98 / tau at N = 6: 12.03. */\nexport const CASCADE_SETTLE_98 = cascadeSettle(CASCADE_ORDER);\n\nconst VALUE_LIMIT = 1e15;\nconst MIN_RATE = 1e-3;\nconst MAX_RATE = 1e9;\nconst SETTLED = 1e-30;\n\nexport class CascadeBank {\n readonly channels: number;\n readonly order: number;\n /**\n * The outputs (the last stage), one per channel, refreshed by step(),\n * snap() and place(). Read only.\n */\n readonly values: Float64Array;\n /** Stages, channel-major: stage k of channel i at i * order + k (the last is the output). */\n private readonly x: Float64Array;\n private readonly goal: Float64Array;\n /** 1 / tau per channel, 1/s. */\n private readonly rate: Float64Array;\n /** exp(-r) r^m / m! for m = 0 .. order - 1, channel-major. */\n private readonly c: Float64Array;\n private readonly h: number;\n /** t98 / tau at this order. */\n private readonly settle: number;\n\n /**\n * stepRateHz is how often step() runs, within [1e-3, 1e9] Hz; order is the\n * number of stages, 1 to 12.\n */\n constructor(channels: number, stepRateHz: number, order = CASCADE_ORDER) {\n if (!(Number.isInteger(channels) && channels > 0 && channels <= 1 << 16)) {\n throw new RangeError(`channel count must be an integer from 1 to 65536, got ${channels}`);\n }\n if (!(Number.isInteger(order) && order >= 1 && order <= 12)) {\n throw new RangeError(`order must be an integer from 1 to 12, got ${order}`);\n }\n if (!(stepRateHz >= 1e-3 && stepRateHz <= 1e9)) {\n throw new RangeError(`step rate must be within [1e-3, 1e9] Hz, got ${stepRateHz}`);\n }\n this.channels = channels;\n this.order = order;\n this.h = 1 / stepRateHz;\n this.values = new Float64Array(channels);\n this.x = new Float64Array(channels * order);\n this.goal = new Float64Array(channels);\n this.rate = new Float64Array(channels);\n this.c = new Float64Array(channels * order);\n this.settle = cascadeSettle(order);\n // 100 ms to 98 percent until set\n for (let i = 0; i < channels; i++) this.setRate(i, this.settle / 0.1);\n }\n\n /** 1 / tau for channel i, clamped to [1e-3, 1e9] per second. */\n setRate(i: number, perSecond: number): void {\n if (!Number.isFinite(perSecond)) return;\n const q = clamp(perSecond, MIN_RATE, MAX_RATE);\n if (q === this.rate[i]) return;\n this.rate[i] = q;\n this.coefficients(i);\n }\n\n /** The 98 percent time from rest for channel i, seconds (0: arrive on the next step). */\n setTime(i: number, seconds: number): void {\n if (!Number.isFinite(seconds)) return;\n const t = clamp(seconds, 0, Number.MAX_VALUE);\n this.setRate(i, t > 0 ? this.settle / t : MAX_RATE);\n }\n\n setTarget(i: number, target: number): void {\n if (!Number.isFinite(target)) return;\n this.goal[i] = clamp(target, -VALUE_LIMIT, VALUE_LIMIT);\n }\n\n /** Every stage and the target to value: at rest there. */\n snap(i: number, value: number): void {\n if (!Number.isFinite(value)) return;\n const v = clamp(value, -VALUE_LIMIT, VALUE_LIMIT);\n this.goal[i] = v;\n this.values[i] = v;\n const n = this.order;\n for (let k = 0; k < n; k++) this.x[i * n + k] = v;\n }\n\n /** Move channel i's output stage to value, leaving the stages before it (a contact). */\n place(i: number, value: number): void {\n if (!(value - value === 0)) return;\n const v = value < -1e15 ? -1e15 : value > 1e15 ? 1e15 : value;\n this.x[i * this.order + this.order - 1] = v;\n this.values[i] = v;\n }\n\n /** place(i, src[at]): no double crosses the call. */\n placeFrom(i: number, src: Float64Array, at: number): void {\n this.place(i, src[at]);\n }\n\n /** The output's velocity, units per second. */\n velocity(i: number): number {\n const n = this.order;\n const b = i * n + n - 1;\n return n > 1 ? (this.x[b - 1] - this.x[b]) * this.rate[i] : (this.goal[i] - this.x[b]) * this.rate[i];\n }\n\n /** Stage k (0 first, order - 1 the output) of channel i. */\n stage(i: number, k: number): number {\n return this.x[i * this.order + k];\n }\n\n target(i: number): number {\n return this.goal[i];\n }\n\n /**\n * Every channel's target from targets[i] and rate (1 / tau) from rates[i]:\n * one call with arrays, so no double crosses a call boundary.\n */\n setAll(targets: Float64Array, rates: Float64Array): void {\n for (let i = 0; i < this.channels; i++) {\n const t = targets[i];\n if (t - t === 0) this.goal[i] = t < -1e15 ? -1e15 : t > 1e15 ? 1e15 : t;\n const r = rates[i];\n if (!(r - r === 0)) continue;\n const q = r < 1e-3 ? 1e-3 : r > 1e9 ? 1e9 : r;\n if (q !== this.rate[i]) {\n this.rate[i] = q;\n this.coefficients(i);\n }\n }\n }\n\n /** Advance every channel one step. */\n step(): void {\n const n = this.order;\n const x = this.x;\n const c = this.c;\n const goal = this.goal;\n for (let i = 0; i < this.channels; i++) {\n const base = i * n;\n const g = goal[i];\n let big = 0;\n // in place from the last stage down: stage k needs the old values of stages 0 .. k\n for (let k = n - 1; k >= 0; k--) {\n let s = 0;\n for (let j = 0; j <= k; j++) s += c[base + k - j] * (x[base + j] - g);\n x[base + k] = g + s;\n if (s > big) big = s;\n else if (-s > big) big = -s;\n }\n // settle exactly far under anything audible, so no subnormal stays in the state\n if (big < SETTLED) for (let k = 0; k < n; k++) x[base + k] = g;\n this.values[i] = x[base + n - 1];\n }\n }\n\n private coefficients(i: number): void {\n const n = this.order;\n const r = this.h * this.rate[i];\n let term = Math.exp(-r);\n for (let m = 0; m < n; m++) {\n this.c[i * n + m] = term;\n term *= r / (m + 1);\n }\n }\n}\n", "/*\n * Air, in the CGS units the airway works in (cm, g, s; pressure in\n * dyn/cm^2, flow in cm^3/s). The values are CHIMERA's (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49,\n * crates/chimera/src/physics.rs:5-35): warm humid air in the airway.\n */\n\n/** Density, g/cm^3. */\nexport const AIR_DENSITY = 1.14e-3;\n/** Speed of sound, cm/s. */\nexport const SOUND_SPEED = 35000;\n/** Dynamic viscosity, g/(cm s). */\nexport const AIR_DYNAMIC_VISCOSITY = 1.86e-4;\n/** Kinematic viscosity, cm^2/s. */\nexport const AIR_VISCOSITY = AIR_DYNAMIC_VISCOSITY / AIR_DENSITY;\n/** One centimetre of water, dyn/cm^2. */\nexport const CM_H2O = 980.665;\n\n/** A yielding wall per unit area: mass g/cm^2, resistance dyn s/cm^3, stiffness dyn/cm^3. */\nexport interface WallTissue {\n m: number;\n r: number;\n k: number;\n}\n\n/**\n * Soft tissue of the pharynx and mouth: Birkholz and Zhang (Interspeech 2025) fitted six speakers'\n * voice bars with M = 2.0 g/cm^2 for all, K 65,000 to 100,000 dyn/cm^3 and B 800 to 2000 dyn s/cm^3,\n * uniform over the tract. K and B are chosen here by the voice bar's duration and level\n * (docs/VOICE-2.md, \"Noise sources, walls and velum\"). CHIMERA's WALL_SOFT was m 1.5, r 1600, k 3e5.\n * The mass stays CHIMERA's 1.5, under their 2.0: with the six-stage articulators and the retuned\n * noise, 2.0 put five of the comparison renders 0.2 to 0.27 dB further from CHIMERA (DTW), the\n * vowels line most (docs/VOICE-2.md, \"Integration 4\").\n */\nexport const WALL_TRACT: WallTissue = { m: 1.5, r: 2000, k: 1e5 };\n/**\n * Relaxed cheeks: Ishizaka, French and Flanagan (1975, \"Direct determination of vocal tract wall\n * impedance\", IEEE TASSP 23) measured the cheek and neck walls by vibrating them, broad resonances\n * of 30 to 70 Hz; the per-area values reproduced from them in later models are m 1.5 g/cm^2,\n * r 800 dyn s/cm^3 and k 66 667 dyn/cm^3 (a 33.5 Hz resonance). The airway's oral walls blend from\n * WALL_TRACT toward these with the `cheeks` setting: slack cheeks let a closed mouth expand, which\n * keeps the folds voicing through a /b d g/ longer.\n */\nexport const WALL_CHEEK_RELAXED: WallTissue = { m: 1.5, r: 800, k: 66667 };\n/** The trachea's cartilage-ringed wall (physics.rs WALL_TRACHEA). */\nexport const WALL_TRACHEA: WallTissue = { m: 0.6, r: 1000, k: 1e6 };\n/** The nasal cavity's mucosa over bone (physics.rs WALL_NASAL). */\nexport const WALL_NASAL: WallTissue = { m: 1.0, r: 3000, k: 1e6 };\n", "/*\n * A tube of fixed shape in the junction airway (dsp/junction-airway.ts): the\n * trachea, or the nasal cavity behind the velum. Its sections never move,\n * so the runs of sections between a few lumped nodes are pure delays (two\n * ring buffers per segment), and the walls and viscous resistance of the\n * junctions a node stands for are summed onto it. Its node coefficients are\n * computed once per configure(), never per sample.\n *\n * Every section is c / (2 rate) long, half a sample each way, so a segment\n * of m sections (m even) delays m / 2 samples. A node is a junction of the\n * airway's kind: a series flow element (viscous resistance and a\n * Borda-Carnot kinetic loss across its area step) with a yielding wall\n * (mass, resistance and stiffness per unit area) solved implicitly as a\n * Thevenin conductance.\n *\n * The element values are CHIMERA's (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49):\n * airway/network.rs:860-930 (viscous resistance at 700 Hz, Borda-Carnot\n * expansion with a 0.1 contraction loss), :960-1010 (walls). The lumping is\n * this airway's, MEASURED in its prototype: 4 trachea and 6 nasal nodes\n * against one junction per section came within 40 to 47 dB SNR, with band\n * levels within 0.1 dB. See THIRD_PARTY_NOTICES.md.\n */\n\nimport { AIR_DENSITY, AIR_DYNAMIC_VISCOSITY, SOUND_SPEED, type WallTissue } from './air';\n\nconst RHO_C = AIR_DENSITY * SOUND_SPEED;\n/** CHIMERA's viscous resistance at 700 Hz (network.rs:866). */\nconst VISC = Math.sqrt((AIR_DENSITY * AIR_DYNAMIC_VISCOSITY * 2 * Math.PI * 700) / 2);\n/** Ring length per segment and direction; segments are far shorter than this at any supported rate. */\nexport const TUBE_RING = 256;\nconst MASK = TUBE_RING - 1;\n\nexport class AirwayTube {\n /** Node count including both ends. */\n nn = 0;\n /** Segment delays in samples (segment s joins node s and s + 1). */\n readonly D: Int32Array;\n /** Forward (toward node s + 1) and backward rings, TUBE_RING per segment. */\n readonly F: Float64Array;\n readonly B: Float64Array;\n /** Segment impedances and areas. */\n readonly Z: Float64Array;\n readonly area: Float64Array;\n /* Interior node coefficients. */\n private readonly rv: Float64Array;\n private readonly wS: Float64Array;\n private readonly gam: Float64Array;\n private readonly ibq: Float64Array;\n private readonly wV: Float64Array;\n private readonly wY: Float64Array;\n /** Flow through each node, cm^3/s. */\n readonly U: Float64Array;\n private wCm = 0;\n private wK = 0;\n private wIb = 0;\n private T = 0;\n /*\n * Side resonators on interior nodes (a paranasal sinus): a lumped acoustic mass M, resistance R and\n * stiffness K = 1 / C in series, the same equation as a wall with lumped values. Per node: its\n * conductance (0 for none), history coefficient and stiffness, and its flow and displacement.\n */\n private readonly sG: Float64Array;\n private readonly sCm: Float64Array;\n private readonly sK: Float64Array;\n private readonly sQ: Float64Array;\n private readonly sY: Float64Array;\n private readonly sP: Float64Array;\n\n /** maxNodes: the most nodes any configure() will ask for. */\n constructor(maxNodes: number) {\n const ns = maxNodes - 1;\n this.D = new Int32Array(ns);\n this.F = new Float64Array(ns * TUBE_RING);\n this.B = new Float64Array(ns * TUBE_RING);\n this.Z = new Float64Array(ns);\n this.area = new Float64Array(ns);\n this.rv = new Float64Array(maxNodes);\n this.wS = new Float64Array(maxNodes);\n this.gam = new Float64Array(maxNodes).fill(1);\n this.ibq = new Float64Array(maxNodes);\n this.wV = new Float64Array(maxNodes);\n this.wY = new Float64Array(maxNodes);\n this.U = new Float64Array(maxNodes);\n this.sG = new Float64Array(maxNodes);\n this.sCm = new Float64Array(maxNodes);\n this.sK = new Float64Array(maxNodes);\n this.sQ = new Float64Array(maxNodes);\n this.sY = new Float64Array(maxNodes);\n this.sP = new Float64Array(maxNodes);\n }\n\n /**\n * Hang a resonator on interior node m, discretized by the trapezoidal rule (side-branch.ts): 1 / D, the history coefficient M / T - R / 2 - K T / 4, and the stiffness K.\n * Call after configure(); configure() removes every resonator. Off the audio path.\n */\n addResonator(m: number, invD: number, cm: number, K: number): void {\n if (!(m >= 1 && m < this.nn - 1) || !(invD > 0)) return;\n this.sG[m] = 0.5 * invD;\n this.sCm[m] = cm * invD;\n this.sK[m] = K * invD;\n this.refresh(m);\n }\n\n /** A node's coefficients from its wall and resonator. */\n private refresh(m: number): void {\n const z1 = this.Z[m - 1];\n const g = 1 / (1 + z1 * (this.wS[m] * this.wIb + this.sG[m]));\n this.gam[m] = g;\n this.ibq[m] = 1 / (z1 * g + this.Z[m] + this.rv[m]);\n }\n\n /**\n * Lay the tube out: sections[0 .. count) of area secAreas (cm^2), nodes at\n * the even section indices nodesAt[0 .. nn) (0 and count included), walls\n * of `wall` over a perimeter `perim` times a circle's, viscous resistance\n * times viscF, sections dx cm long at `rate`. Clears every wave and wall.\n */\n configure(secAreas: Float64Array, count: number, nodesAt: Int32Array, nn: number, wall: WallTissue, perim: number, viscF: number, dx: number, rate: number): void {\n this.nn = nn;\n this.T = 1 / rate;\n const ns = nn - 1;\n for (let s = 0; s < ns; s++) {\n const a0 = nodesAt[s];\n const a1 = nodesAt[s + 1];\n this.D[s] = (a1 - a0) >> 1;\n let inv = 0;\n for (let i = a0; i < a1; i++) inv += 1 / secAreas[i];\n this.area[s] = (a1 - a0) / inv;\n this.Z[s] = RHO_C / this.area[s];\n }\n const beta = wall.m * rate + 0.5 * wall.r;\n this.wCm = wall.m * rate - 0.5 * wall.r;\n this.wK = wall.k;\n this.wIb = 1 / beta;\n this.rv.fill(0);\n this.wS.fill(0);\n // each section junction i (between sections i - 1 and i) goes to the nearest interior node\n const hr = perim * 2 * Math.sqrt(Math.PI) * dx * viscF;\n for (let i = 1; i < count; i++) {\n let best = -1;\n let bd = Infinity;\n for (let m = 1; m < nn - 1; m++) {\n const d = nodesAt[m] > i ? nodesAt[m] - i : i - nodesAt[m];\n if (d < bd) {\n bd = d;\n best = m;\n }\n }\n if (best < 0) continue;\n const al = secAreas[i - 1];\n const ar = secAreas[i];\n this.rv[best] += 0.25 * VISC * hr * (Math.pow(al, -1.5) + Math.pow(ar, -1.5));\n this.wS[best] += perim * 2 * Math.sqrt(Math.PI * 0.5 * (al + ar)) * dx;\n }\n this.sG.fill(0);\n this.sCm.fill(0);\n this.sK.fill(0);\n for (let m = 1; m < nn - 1; m++) this.refresh(m);\n this.reset();\n }\n\n /** Every wave, flow and wall at rest. */\n reset(): void {\n this.F.fill(0);\n this.B.fill(0);\n this.wV.fill(0);\n this.wY.fill(0);\n this.U.fill(0);\n this.sQ.fill(0);\n this.sY.fill(0);\n this.sP.fill(0);\n }\n\n /**\n * The interior nodes for ring position pos. The end nodes belong to the\n * airway (lungs and glottis, velum and nostrils).\n */\n interior(pos: number): void {\n const F = this.F;\n const B = this.B;\n const D = this.D;\n const Z = this.Z;\n const wCm = this.wCm;\n const wK = this.wK;\n const wIb = this.wIb;\n const T = this.T;\n const nn = this.nn;\n for (let m = 1; m < nn - 1; m++) {\n const segL = (m - 1) * TUBE_RING;\n const segR = m * TUBE_RING;\n const a = F[segL + ((pos - D[m - 1]) & MASK)];\n const b = B[segR + ((pos - D[m]) & MASK)];\n const z1 = Z[m - 1];\n const wv = this.wV[m];\n const wy = this.wY[m];\n const hist = wCm * wv - wK * wy;\n const sg = this.sG[m];\n // the history flow: (p_prev / 2 + cm q_prev - K y_prev) / D, the coefficients held already over D\n const sh = sg > 0 ? sg * this.sP[m] + this.sCm[m] * this.sQ[m] - this.sK[m] * this.sY[m] : 0;\n const ue0 = -this.wS[m] * hist * wIb - sh;\n const gam = this.gam[m];\n const u = (2 * a * gam - 2 * b + z1 * gam * ue0) * this.ibq[m];\n const p = (2 * a - z1 * (u - ue0)) * gam;\n const v = (hist + p) * wIb;\n this.wV[m] = v;\n this.wY[m] = wy + T * v;\n if (sg > 0) {\n const q = sg * p + sh;\n this.sY[m] += 0.5 * T * (q + this.sQ[m]);\n this.sQ[m] = q;\n this.sP[m] = p;\n }\n B[segL + pos] = p - a;\n F[segR + pos] = b + Z[m] * u;\n this.U[m] = u;\n }\n }\n}\n\n/** Even node positions 0 .. n with up to `inner` interior nodes, into out; returns the node count. */\nexport function evenNodes(n: number, inner: number, out: Int32Array): number {\n let c = 0;\n out[c++] = 0;\n for (let m = 1; m <= inner; m++) {\n const v = 2 * Math.round((m * n) / (inner + 1) / 2);\n if (v > out[c - 1] && v < n) out[c++] = v;\n }\n out[c++] = n;\n return c;\n}\n", "/*\n * Side branches of the airway: cavities that open off the main tube and put zeros in its spectrum.\n *\n * A closed side tube of depth L and area A presents Z(w) = -j Z0 cot(wL / c) at its mouth; near its\n * quarter-wave resonance w0 = pi c / 2L that is Z ~ j Z0 (w - w0) L / c, the impedance of a series\n * mass and spring with M = rho L / (2 A) and K = w0^2 M. A Helmholtz resonator is that element exactly:\n * M = rho L_neck / A_neck, K = rho c^2 / V. So every branch here is one lumped series M, R, K, and the\n * airway folds it into a junction as it folds a wall (docs/HOW-IT-WORKS.md, section 11.1).\n *\n * Discretized by the trapezoidal rule (the bilinear transform), which maps a passive impedance to a\n * passive discrete element at any rate: the walls' explicit spring made a 4.2 kHz branch unstable at\n * 22.05 kHz (MEASURED). With D = M / T + R / 2 + K T / 4 the branch's flow is\n *\n * q_n = p_n / (2 D) + (p_{n-1} / 2 + (M / T - R / 2 - K T / 4) q_{n-1} - K y_{n-1}) / D\n * y_n = y_{n-1} + T (q_n + q_{n-1}) / 2\n *\n * a conductance 1 / (2 D) in the junction's solve and a history flow; the resonance is pre-warped,\n * w_set = (2 / T) tan(w0 T / 2). Pure arithmetic, no state: the airway holds each branch's q, y, p.\n */\n\nimport { AIR_DENSITY, SOUND_SPEED } from './air';\n\nconst RHO = AIR_DENSITY;\n\n/** A trapezoidal branch's coefficients: 1 / D, the history coefficient M / T - R / 2 - K T / 4, and K. */\nexport type BranchCoefficients = [invD: number, history: number, stiffness: number];\n\n/** A series mass-spring branch of mass M (g/cm^4) tuned to f0 (Hz) at quality q, at `rate`. */\nexport function branchCoefficients(M: number, f0: number, q: number, rate: number): BranchCoefficients {\n const w0 = 2 * Math.PI * f0;\n const wSet = 2 * rate * Math.tan(w0 / (2 * rate));\n const K = wSet * wSet * M;\n const R = (w0 * M) / q;\n const D = M * rate + 0.5 * R + K / (4 * rate);\n return [1 / D, M * rate - 0.5 * R - K / (4 * rate), K];\n}\n\n/*\n * The piriform fossae (Dang and Honda 1997, JASA 101, 456-465): MRI volumes 2.1 to 2.9 cm^3, depths\n * 1.6 to 2.0 cm, a spectral minimum at 4 to 5 kHz. The pair as one branch of 2.5 k^3 cm^3 and 1.8 k cm,\n * end-corrected by 0.61 of each fossa's radius: 4.2 kHz in the male body.\n */\nconst PIRIFORM_VOLUME = 2.5;\nconst PIRIFORM_DEPTH = 1.8;\n/** INFERRED: soft mucosal walls; the measured minima are a few hundred Hz wide. */\nconst PIRIFORM_Q = 10;\n\n/** The piriform fossae for a body of scale k at `rate`. */\nexport function piriformBranch(k: number, rate: number): BranchCoefficients {\n const depth = PIRIFORM_DEPTH * k;\n const area = (PIRIFORM_VOLUME * k * k * k) / depth;\n const leff = depth + 0.61 * Math.sqrt(area / 2 / Math.PI);\n return branchCoefficients((RHO * leff) / (2 * area), SOUND_SPEED / (4 * leff), PIRIFORM_Q, rate);\n}\n\n/*\n * The maxillary sinuses (Dang and Honda 1996, JASA 100, 3374-3383: four Helmholtz resonators model the\n * sinuses; the maxillary zero lies between 310 and 950 Hz). The pair as one resonator of 30 k^3 cm^3\n * behind an ostium of 0.2 k^2 cm^2 and 1 k cm: 455 Hz in the male body.\n */\nconst SINUS_VOLUME = 30;\nconst SINUS_NECK_AREA = 0.2;\nconst SINUS_NECK_LENGTH = 1;\n/** INFERRED. */\nconst SINUS_Q = 8;\n\n/** The maxillary sinuses for a body of scale k at `rate`. */\nexport function sinusBranch(k: number, rate: number): BranchCoefficients {\n const v = SINUS_VOLUME * k * k * k;\n const m = (RHO * SINUS_NECK_LENGTH * k) / (SINUS_NECK_AREA * k * k);\n const f0 = Math.sqrt((RHO * SOUND_SPEED * SOUND_SPEED) / v / m) / (2 * Math.PI);\n return branchCoefficients(m, f0, SINUS_Q, rate);\n}\n", "/*\n * How fast a cross-section of the tract may open or close: CHIMERA's area\n * rate limit, ported from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth,\n * crates/chimera/src/voice/human_airway.rs:151-156 and 190-262 at\n * 1d3ea49). Reimplemented; see THIRD_PARTY_NOTICES.md. The junction\n * airway (dsp/junction-airway.ts) runs it on its grid sections and on\n * their sub-section minima, as CHIMERA runs it on its network's.\n *\n * Opening is limited to (45 k^2 + 40 A) cm^2/s: wide cavities reshape\n * fast, narrow constrictions open at a physiological rate, which sets how\n * sharp a burst is. Closing eases from that rate down to 5 k^2 cm^2/s by a\n * smoothstep between 0.03 and 0.4 k^2 cm^2, and under 0.03 k^2 slows\n * with sqrt(A / 0.03 k^2), so a seal is reached smoothly. CHIMERA's\n * comments say why: at a constant rate the flow's slope dropped to zero at\n * once, a step in the radiated pressure, and sealing at the opening rate\n * shut within about a millisecond; both are audible clicks. A prototype\n * of this voice had no limit and clicked at stop releases (MEASURED:\n * 421 click events CHIMERA lacked over 21 renders).\n */\n\nconst MAX_AREA_RATE = 45;\nconst AREA_RATE_GAIN = 40;\nconst SEAL_RATE = 5;\nconst SEAL_LO = 0.03;\nconst SEAL_HI = 0.4;\nconst SEAL_EASE = 0.03;\n\nexport class AreaSlew {\n private openR = MAX_AREA_RATE;\n private sealR = SEAL_RATE;\n private lo = SEAL_LO;\n private hi = SEAL_HI;\n private ease = SEAL_EASE;\n private dt = 0;\n\n /** The body scale k: every rate and threshold scales with k^2. */\n setScale(k: number): void {\n const k2 = k * k;\n this.openR = MAX_AREA_RATE * k2;\n this.sealR = SEAL_RATE * k2;\n this.lo = SEAL_LO * k2;\n this.hi = SEAL_HI * k2;\n this.ease = SEAL_EASE * k2;\n }\n\n /** The step limitAll() limits over, seconds. Set once; no double crosses limitAll(). */\n setStep(dt: number): void {\n this.dt = dt;\n }\n\n /** The closing rate at area a, cm^2/s. */\n private closeRate(a: number): number {\n if (a < this.ease) return this.sealR * Math.sqrt((a > 0 ? a : 0) / this.ease);\n const u = a <= this.lo ? 0 : a >= this.hi ? 1 : (a - this.lo) / (this.hi - this.lo);\n return this.sealR + (this.openR - this.sealR) * u * u * (3 - 2 * u);\n }\n\n /** The area `next` limited against `prev` over dt seconds. */\n limit(next: number, prev: number, dt: number): number {\n const d = next - prev;\n if (d > 0) {\n const lim = (this.openR + AREA_RATE_GAIN * next) * dt;\n return d > lim ? prev + lim : next;\n }\n const lim = (this.closeRate(prev) + AREA_RATE_GAIN * prev) * dt;\n return d < -lim ? prev - lim : next;\n }\n\n /** next[0 .. count) limited against prev over setStep()'s step, in place; limit() written out, so no double crosses a call. */\n limitAll(next: Float64Array, prev: Float64Array, count: number): void {\n const dt = this.dt;\n const openR = this.openR;\n const sealR = this.sealR;\n const lo = this.lo;\n const span = this.hi - this.lo;\n const ease = this.ease;\n for (let i = 0; i < count; i++) {\n const a = prev[i];\n const d = next[i] - a;\n if (d > 0) {\n const lim = (openR + AREA_RATE_GAIN * next[i]) * dt;\n if (d > lim) next[i] = a + lim;\n continue;\n }\n let rate: number;\n if (a < ease) rate = sealR * Math.sqrt((a > 0 ? a : 0) / ease);\n else {\n let u = (a - lo) / span;\n u = u < 0 ? 0 : u > 1 ? 1 : u;\n rate = sealR + (openR - sealR) * u * u * (3 - 2 * u);\n }\n const lim = (rate + AREA_RATE_GAIN * a) * dt;\n if (d < -lim) next[i] = a - lim;\n }\n }\n}\n", "/*\n * Ported from CHIMERA by Jameson Hodge (MIT), https://github.com/jamesondh/chimera-vocal-synth,\n * crates/chimera/src/sources/glottis.rs, with the Drift from crates/chimera/src/math.rs and the\n * source mapping from crates/chimera/src/voice/human_voice.rs, at 1d3ea49 (TypeScript original at\n * cd247a6^:src/engine/sources/glottis.ts). Changes from the original: an inertive orifice and a\n * derivative stand in for the airway that turned area into flow, the closure corner is band\n * limited, and vibrato, the pressure gate and the leak terms are left to the engine. See\n * THIRD_PARTY_NOTICES.md.\n *\n * Glottal source: the vocal-fold pulse of a singing voice, as the flow\n * derivative excitation a source-filter voice runs through its formants.\n *\n * WHAT IS PORTED\n *\n * A phase accumulator drives a normalised glottal area pulse, so pitch is\n * exact by construction: nothing estimates a period, the phase just wraps\n * at the requested rate. Within the open quotient the area rises as a\n * half cosine over the first `skew` of the open phase and falls over the\n * rest as a blend of a raised cosine (soft closure, zero slope at the end)\n * and a quarter cosine (abrupt closure, finite slope at the end), mixed by\n * closure sharpness (glottis.rs:231-246).\n *\n * Each cycle draws a period scale and an amplitude: jitter and shimmer\n * from one stream, diplophonia as a fixed alternation of both, and a\n * logistic map x -> r x (1 - x) with r = 2.9 + 1.1 chaos, which walks\n * through period doubling (subharmonics near 0.3) into deterministic chaos\n * past about 0.62 (glottis.rs:178-199). Fry pulls the rate toward 48 Hz,\n * shortens the open quotient toward 0.28 and adds a weaker second pulse at\n * phase 0.38 (glottis.rs:165-168, 202-213). The pitch drift is CHIMERA's\n * 1/f approximation: three one-pole filtered noises at 0.3, 0.9 and\n * 2.7 Hz, each held at unit variance, weighted 1, 1/2, 1/3 and divided by\n * 1.4 (math.rs:236-258).\n *\n * The voice mapping is CHIMERA's (human_voice.rs:317-350): open quotient\n * 0.78 - 0.36 tension, closure sharpness 0.4 tension + 1.375 max(0,\n * tension - 0.6), skew 0.56 + 0.16 tension, jitter 0.0021 + 0.0245\n * roughness, shimmer 0.02 + 0.22 roughness, diplophonia 1.4 (roughness -\n * 0.5) above 0.5. Brightness sits at its default there, where it drops\n * out, and effort at the default lung pressure of 8 cmH2O is 0.5, where\n * its open quotient term is zero. These are the Rust constants at 1d3ea49;\n * the TypeScript original at cd247a6^ mapped jitter as 0.003 + 0.035\n * roughness and sharpness as 0.25 + 0.7 tension, which upstream has since\n * retuned. CHIMERA's human voice does not tie chaos to roughness (only its\n * creatures do), so chaos has its own setter, and so do the raw jitter,\n * shimmer and diplophonia, which setRoughness sets together.\n *\n * Fixed seeds become forks of the stream given at construction: 'jitter'\n * (CHIMERA's 777) for the per-cycle draws, 'drift' (its 4242) for the\n * drift, and 'chaos' for the starting point of the logistic map, which\n * CHIMERA fixes at 0.37. A fixed start would put every pooled voice on the\n * same chaotic trajectory, in unison, so it is drawn on each reset.\n *\n * bellows' NamedRng.gauss() is the Irwin-Hall sum of four uniforms scaled\n * by SQRT2 * 0.875, standard deviation 0.714 (see types.ts). CHIMERA's is\n * the same sum scaled to unit variance. Every draw here is multiplied by\n * UNIT_GAUSS, so jitter, shimmer and the drift, whose band gains assume\n * unit variance, land at CHIMERA's depths. Both generators are\n * mulberry32, so the noise has the same character.\n *\n * The drift updates at DRIFT_CONTROL_HZ rather than every 32 samples.\n * Each band is an Ornstein-Uhlenbeck process and the one-pole update with\n * pole exp(-2 pi f / rate) and input gain sqrt(1 - pole^2) is its exact\n * discretisation, so the process is the same at any control rate; only\n * the cost changes. At 500 Hz the pitch steps every 2 ms, by 0.61 cents\n * rms at the default 6 cents of drift, against 8.5 cents rms of per-cycle\n * jitter at the default roughness of 0.1 (MEASURED). Every 32 samples it\n * cost about 5 ns a sample (MEASURED), a fifth of the unit.\n *\n * AREA TO FLOW, WHICH IS NOT A PORT\n *\n * CHIMERA outputs area and lets its FDTD airway compute flow (Bernoulli\n * drop plus the inertance of the air column), so the skew of the flow\n * pulse and the steepened closure come from the physics. There is no\n * airway here. The same two terms reduced to a single node give the\n * classic inertive orifice: subglottal pressure = (rho / 2)(U / A)^2 +\n * L dU/dt. Normalised by the peak area and the quasi-steady flow it\n * becomes\n *\n * T du/dt = 1 - (u / a)^2\n *\n * with a the area pulse and u the flow, both about 1 at peak. Flow lags\n * area while the glottis opens (inertance limits how fast the column\n * accelerates) and is pinned to the shrinking area as it closes (the\n * orifice resistance grows without bound), which skews the pulse to the\n * right and steepens the fall: the mechanism Rothenberg (1981, \"Acoustic\n * interaction between the glottal source and the vocal tract\") and Titze\n * (2008, \"Nonlinear source-filter coupling in phonation\", JASA 123) give\n * for the skewed flow of real voices. Each step is backward Euler, a\n * quadratic in the new flow solved in closed form, in the rationalised\n * form that has no cancellation and goes to exactly zero with the area.\n * Backward Euler because the closing end of the cycle is stiff: the\n * relaxation time a T / 2 goes to zero with the area, and an explicit or\n * trapezoidal step rings or goes negative there.\n *\n * T is a fixed fraction of the period, INERTANCE = 0.08, not a fixed time.\n * L = rho l / A for the epilarynx and tract gives T of 0.5 to 0.9 ms, 0.055\n * to 0.1 of a 110 Hz period (INFERRED from textbook dimensions). Holding it\n * as a fraction keeps the pulse shape, and so the timbre, the same up the\n * range, where a fixed time would skew high notes until they lost level.\n * That is also closer to life at the top: once f0 passes F1 the tract is\n * no longer inertive and the skew goes away. At 0.08 the flow peak lands\n * 0.025 of a period after the area peak at tension 0.5, and the tilt over\n * harmonics 1 to 10 is -14.6, -10.5 and -3.2 dB per octave at tension 0,\n * 0.5 and 1 (MEASURED).\n *\n * Lip radiation is a differentiator, so the excitation is the flow\n * derivative. It is taken with respect to cycle phase, the first\n * difference divided by the phase increment, which makes the output scale\n * independent of sample rate and of pitch: harmonics 1 to 10 agree within\n * 0.3 dB at 44.1, 48 and 96 kHz (MEASURED, 220 Hz). GAIN puts the peak of\n * the default pulse at 1.\n *\n * BAND LIMITING, BY MEASUREMENT\n *\n * The flow has a slope discontinuity where the area closes with any\n * sharpness, so the derivative steps there, and that step aliases. The\n * first difference of a sampled corner is already a one-sample box step;\n * the rest is measured. Alias energy against harmonic energy in dB, f0\n * 880 Hz, 48 kHz, perturbations off, 65536-point Blackman-Harris spectrum,\n * every bin more than 6 Hz from a harmonic counted as alias:\n *\n * tension 0.5 (sharpness 0.2) tension 1 (sharpness 0.95)\n * all <5 kHz <10 kHz all <5 kHz <10 kHz\n * no correction -42.5 -64.9 -56.6 -23.0 -45.6 -37.2\n * 2-point polyBLAMP -50.2 -78.1 -69.5 -34.5 -79.4 -69.5\n * 2x oversampled -52.1 -78.5 -69.0 -32.3 -59.0 -49.2\n * 4x oversampled -52.8 -89.1 -81.1 -32.9 -71.0 -61.5\n * 4-point B-spline BLAMP -52.0 -78.2 -69.8 -44.4 -77.2 -67.4\n * Kaiser BLAMP, 8 a side -52.3 -78.2 -69.8 -53.2 -77.6 -67.5\n *\n * Oversampling runs through dsp/oversample.ts, whose halfband passes 24\n * to 28.8 kHz partly and folds it back under Nyquist, so it leaves the\n * near-Nyquist total almost where it was and only gains in band. The\n * corner correction removes the corner itself, so it wins in band, where\n * the formants are, at no measurable cost: in one Node 22 process on an\n * M1, at 220 Hz and 48 kHz, the uncorrected and corrected pulse both ran\n * 33.3 ns a sample in the prototype the table was measured with, against\n * 94.4 ns at 2x and 215.9 ns at 4x. Longer residuals only move the\n * near-Nyquist total, which the formant filters bury, and need up to 8\n * samples of lookahead, so the 2-point polyBLAMP of Esqueda, Valimaki and\n * Bilbao (2016, \"Rounding corners with BLAMP\", DAFx) is the choice. What\n * remains in band at tension 0.5 is the curvature jumps at opening and at\n * the peak, 78 dB down. At 1760 Hz, tension 1, the corrected unit is still\n * -64.8 dB under 5 kHz.\n *\n * The correction needs the flow slope just before closure, one sample\n * ahead of it. Near closure the flow is pinned at u = k a, and the\n * equation above gives k^2 - T s k - 1 = 0 for an area closing with slope\n * s per unit phase, so the flow closes with slope k s. That is exact in\n * the continuous limit and needs no history, so it holds at high f0 where\n * a few samples span the whole closing phase.\n *\n * COST\n *\n * At 48 kHz this unit runs 22 to 23 ns a sample at 220 Hz and 25 to 26 ns\n * at 880 Hz, against 6.1 to 6.4 and 10.8 to 11.1 ns for a BlepOscillator\n * saw at the same pitch in the same Node 22 process on an M1 (MEASURED,\n * medians of 7 runs of 5 s, two processes): 3.6 and 2.3 times the saw,\n * about 0.11 percent of a core per voice. Quote the ratio, as\n * dsp/oscillators.ts explains; the wall clock moves with the harness.\n * The per-sample work is step(), kept under V8's 460-byte bytecode limit\n * for inlining, with the per-cycle and per-closure work in separate\n * methods: at 767 bytes it was not inlined into its caller, every call\n * boxed its return value, and it cost 34 ns. It leaves its sample in a\n * field instead of returning it, so a caller that does not inline it pays\n * a call and nothing else. Whether a caller inlines it can depend on\n * compile order, which V8 picks by timing: once step() has been optimized\n * on its own, a caller pays 1.2 times step() plus everything inlined into\n * it (reserve_inline_budget_scale_factor) out of a 920-byte cumulative\n * budget. That is 368 + 137 + 85 + 91 bytes (step, area, pulse, one\n * sinQuarter), times 1.2, 817 (MEASURED, --trace-turbo-inlining). The\n * pulse once evaluated its sine at two call sites and came to 928, so\n * process() sometimes kept the per-sample call, and in the vocal engine\n * that boxed 13 bytes a sample in 3 runs of 16 under load (MEASURED);\n * test/engines-physical/vocal.test.ts forces that order. `node\n * --print-bytecode --print-bytecode-filter=step` prints the length. A\n * caller whose own loop is large can still exhaust the budget, which is\n * what process() is for.\n *\n * Shape parameters (tension and fry) take effect at the next cycle start,\n * where the area is zero. Moving the open quotient mid-pulse could cut the\n * area to zero at once, and the pinned flow would follow it within a\n * sample: a click. Frequency is applied every sample.\n */\n\nimport type { NamedRng } from 'bellowsjs';\nimport { clamp } from 'bellowsjs';\n\n/** Turns a bellows gauss() draw (sd 0.714) into a unit-variance one, as CHIMERA draws. */\nconst UNIT_GAUSS = 1 / (Math.sqrt(1 / 3) * Math.SQRT2 * 0.875);\n\nconst HALF_PI = Math.PI / 2;\n\n/*\n * sin(pi x / 2) for x in [0, 1], by its Taylor series to x^15, each\n * coefficient derived from the last. The first omitted term bounds the\n * error at 6.1e-12, far under a float32 sample. It replaces Math.sin and\n * Math.cos in the pulse, which V8 compiles to calls out of the generated\n * code: 3.4 ns a sample cheaper (MEASURED), and independent of any\n * platform's libm.\n */\nconst S1 = HALF_PI;\nconst S3 = (-S1 * HALF_PI * HALF_PI) / (2 * 3);\nconst S5 = (-S3 * HALF_PI * HALF_PI) / (4 * 5);\nconst S7 = (-S5 * HALF_PI * HALF_PI) / (6 * 7);\nconst S9 = (-S7 * HALF_PI * HALF_PI) / (8 * 9);\nconst S11 = (-S9 * HALF_PI * HALF_PI) / (10 * 11);\nconst S13 = (-S11 * HALF_PI * HALF_PI) / (12 * 13);\nconst S15 = (-S13 * HALF_PI * HALF_PI) / (14 * 15);\n\nfunction sinQuarter(x: number): number {\n const z = x * x;\n return x * (S1 + z * (S3 + z * (S5 + z * (S7 + z * (S9 + z * (S11 + z * (S13 + z * S15)))))));\n}\n\n/** Inertive time constant of the airway, as a fraction of the glottal period. */\nconst INERTANCE = 0.08;\nconst INV_INERTANCE = 1 / INERTANCE;\n\n/**\n * Output scale. The default pulse (tension 0.5, perturbations off) has a\n * phase-derivative peak of 8.43 (MEASURED, 110 Hz at 48 kHz), so this puts\n * it at 1.\n */\nconst GAIN = 1 / 8.43;\n\n/** Drift control rate in Hz. See the header for why it is not CHIMERA's 32 samples. */\nconst DRIFT_CONTROL_HZ = 500;\n/** Slowest drift band in Hz. The others sit at 3 and 9 times it. */\nconst DRIFT_BASE_HZ = 0.3;\n/** Band weights 1, 1/2, 1/3 summed and divided by this (math.rs:254-257). */\nconst DRIFT_NORM = 1.4;\nconst MAX_DRIFT_CENTS = 100;\n\n/** Fry pulls the rate toward this many Hz. */\nconst FRY_HZ = 48;\n/** Open quotient fry moves toward. */\nconst FRY_OQ = 0.28;\n/** The second fry pulse starts at this phase, with this open quotient ratio and peak. */\nconst FRY_OFFSET = 0.38;\nconst FRY_OQ_RATIO = 0.8;\nconst FRY_PEAK = 0.55;\n\n/*\n * Per-cycle period scale limits 0.55 and 1.8 (glottis.rs:197) and amplitude\n * floor 0.12 (glottis.rs:198), written as literals in startCycle().\n */\n\n/** Where the logistic map restarts if rounding lands it on 0 or 1, CHIMERA's constant. */\nconst CHAOS_RESTART = 0.37;\n/** Range the map's start is drawn from on reset, clear of the fixed points at 0 and 1. */\nconst CHAOS_START_LO = 0.2;\nconst CHAOS_START_SPAN = 0.6;\n\n/** A closure phase no cycle reaches, for a pulse that has no corner to correct. */\nconst NO_CORNER = 2;\n\nconst MIN_HZ = 1;\n/**\n * Highest rate as a fraction of the sample rate. With the period scale\n * floor of 0.55 the phase step stays under 0.46, so the phase never\n * wraps twice in a sample.\n */\nconst MAX_HZ_FRACTION = 0.25;\nconst MAX_JITTER = 0.25;\n\n/**\n * Normalised area of one pulse at cycle phase ph (glottis.rs:233-246):\n * a half cosine rise over the first `skew` of the open phase, then a\n * fall mixing soft (cos^2, which is the raised cosine) and hard (cos)\n * closure by `sharp`.\n */\nfunction pulse(\n ph: number,\n oq: number,\n invOq: number,\n skew: number,\n invSkew: number,\n invFall: number,\n sharp: number,\n): number {\n if (ph >= oq) return 0;\n const t = ph * invOq;\n // The rise and the fall each take one quarter sine, so one evaluation\n // serves both. One call site rather than two keeps sinQuarter's 91 bytes\n // of bytecode out of step()'s inlining budget once more; see COST.\n const rising = t < skew;\n const s = sinQuarter(rising ? t * invSkew : 1 - (t - skew) * invFall);\n const s2 = s * s;\n return rising ? s2 : s2 + (s - s2) * sharp;\n}\n\nexport class GlottalSource {\n private readonly sampleRate: number;\n private readonly invSampleRate: number;\n private readonly maxHz: number;\n private readonly cycleRng: NamedRng;\n private readonly driftRng: NamedRng;\n private readonly chaosRng: NamedRng;\n /**\n * mulberry32 states of the cycle and drift draws, int32, reseeded from\n * their streams at every reset(). The generator runs inline here: a call\n * into a stream's closure per draw returned a boxed double each time\n * (MEASURED: 2 bytes a sample in the vocal engine). Reseeding from the\n * stream keeps every draw reproducible from its label, and successive\n * notes still differ because each reset advances the stream.\n */\n private cycleS = 1;\n private driftS = 1;\n\n /* Drift interval in samples, band poles, and the input gains that hold each band at unit variance. */\n private readonly driftInterval: number;\n private readonly driftPole0: number;\n private readonly driftPole1: number;\n private readonly driftPole2: number;\n private readonly driftIn0: number;\n private readonly driftIn1: number;\n private readonly driftIn2: number;\n\n /* Settings. The shape targets wait for the next cycle start. */\n private hz = 110;\n private targetOq = 0.6;\n private targetSkew = 0.64;\n private targetSharp = 0.2;\n private targetFry = 0;\n private jitter = 0;\n private shimmer = 0;\n private diplophonia = 0;\n private chaos = 0;\n private driftCents = 6;\n\n /* The shape in force for this cycle. */\n private fry = 0;\n private oq = 0.6;\n private invOq = 1 / 0.6;\n private skew = 0.64;\n private invSkew = 1 / 0.64;\n private invFall = 1 / 0.36;\n private sharp = 0.2;\n private fryGain = 0;\n private oq2 = 0;\n private invOq2 = 0;\n private end2 = 0;\n /* Where each pulse closes onto a corner the polyBLAMP corrects, NO_CORNER if it does not. */\n private closeFirst = NO_CORNER;\n private closeSecond = NO_CORNER;\n\n /* Cycle state. phase, odd, amp, ampPrev, scale and pitchFactor are read by\n * the fold models (dsp/geometric-glottis.ts, dsp/fold-oscillator.ts) that\n * take their cycle from this unit; nothing outside writes them. */\n phase = 0;\n odd = false;\n scale = 1;\n amp = 1;\n /** The amplitude of the cycle before this one, for an edge that lags into it. */\n ampPrev = 1;\n private chaosX = CHAOS_RESTART;\n private inc = 0;\n\n /* Drift state. */\n private drift0 = 0;\n private drift1 = 0;\n private drift2 = 0;\n private driftCountdown = 0;\n pitchFactor = 1;\n\n /* Flow: the inertive state, the corrected flow the derivative is taken\n * of, and the corner correction owed to the next sample. */\n private u = 0;\n private uOut = 0;\n private pending = 0;\n /** The sample step() made; see step() for why it is a field and not a return value. */\n private y = 0;\n /** The area nextArea() computed; openArea reads it. A field, so a hot loop reads it without a call. */\n aOut = 0;\n\n constructor(sampleRate: number, rng: NamedRng) {\n this.sampleRate = sampleRate;\n this.invSampleRate = 1 / sampleRate;\n this.maxHz = sampleRate * MAX_HZ_FRACTION;\n this.cycleRng = rng.fork('jitter');\n this.driftRng = rng.fork('drift');\n this.chaosRng = rng.fork('chaos');\n this.driftInterval = Math.max(1, Math.round(sampleRate / DRIFT_CONTROL_HZ));\n const controlRate = sampleRate / this.driftInterval;\n this.driftPole0 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ) / controlRate);\n this.driftPole1 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ * 3) / controlRate);\n this.driftPole2 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ * 9) / controlRate);\n this.driftIn0 = Math.sqrt(1 - this.driftPole0 * this.driftPole0);\n this.driftIn1 = Math.sqrt(1 - this.driftPole1 * this.driftPole1);\n this.driftIn2 = Math.sqrt(1 - this.driftPole2 * this.driftPole2);\n // CHIMERA's default voice: tension 0.5, roughness 0.1, and the glottis default drift of 6 cents.\n this.setTension(0.5);\n this.setRoughness(0.1);\n this.reset();\n }\n\n /**\n * Starts a note from a closed glottis. The streams carry on rather than\n * rewind, so successive notes differ while a render stays reproducible\n * from its seed. Allocates nothing.\n */\n reset(): void {\n this.phase = 0;\n this.odd = false;\n this.scale = 1;\n this.amp = 1;\n this.ampPrev = 1;\n this.chaosX = CHAOS_START_LO + CHAOS_START_SPAN * this.chaosRng();\n this.cycleS = (this.cycleRng() * 4294967296) | 0;\n this.driftS = (this.driftRng() * 4294967296) | 0;\n this.drift0 = 0;\n this.drift1 = 0;\n this.drift2 = 0;\n this.driftCountdown = 0;\n this.pitchFactor = 1;\n this.u = 0;\n this.uOut = 0;\n this.pending = 0;\n this.aOut = 0;\n this.latch();\n this.inc = this.hz * this.invSampleRate;\n }\n\n /** Target f0 in Hz before drift, fry and the per-cycle perturbations. Cheap enough per sample. */\n setFreq(hz: number): void {\n // Math.min and Math.max, not clamp(): clamp's integer bounds merged into\n // the stored double and boxed it, about 0.8 bytes a sample at 48 kHz\n if (hz !== hz) return;\n this.hz = Math.min(Math.max(hz, MIN_HZ), this.maxHz);\n }\n\n /** setFreq(src[i]): the audio path's form, so no double crosses the call. */\n setFreqFrom(src: Float64Array, i: number): void {\n const hz = src[i];\n if (hz !== hz) return;\n this.hz = Math.min(Math.max(hz, MIN_HZ), this.maxHz);\n }\n\n /** 0 lax to 1 pressed: open quotient, closure sharpness and skew. */\n setTension(t: number): void {\n const v = clamp(t, 0, 1);\n this.targetOq = clamp(0.78 - 0.36 * v, 0.25, 0.98);\n this.targetSkew = clamp(0.56 + 0.16 * v, 0.3, 0.9);\n this.targetSharp = clamp(0.4 * v + 1.375 * Math.max(0, v - 0.6), 0, 1);\n if (this.phase === 0) this.latch();\n }\n\n /** 0..1: jitter, shimmer and, above 0.5, diplophonia, by CHIMERA's mapping. */\n setRoughness(r: number): void {\n const v = clamp(r, 0, 1);\n this.jitter = 0.0021 + 0.0245 * v;\n this.shimmer = 0.02 + 0.22 * v;\n this.diplophonia = v > 0.5 ? (v - 0.5) * 1.4 : 0;\n }\n\n /** 0..1 vocal fry. */\n setFry(f: number): void {\n this.targetFry = clamp(f, 0, 1);\n if (this.phase === 0) this.latch();\n }\n\n /** Depth of the 1/f pitch drift in cents. */\n setDrift(cents: number): void {\n this.driftCents = clamp(cents, 0, MAX_DRIFT_CENTS);\n }\n\n /** Cycle-to-cycle period perturbation as a fraction, overriding setRoughness. */\n setJitter(fraction: number): void {\n this.jitter = clamp(fraction, 0, MAX_JITTER);\n }\n\n /** Cycle-to-cycle amplitude perturbation as a fraction, overriding setRoughness. */\n setShimmer(fraction: number): void {\n this.shimmer = clamp(fraction, 0, 1);\n }\n\n /** 0..1 alternation of period and amplitude between cycles, overriding setRoughness. */\n setDiplophonia(amount: number): void {\n this.diplophonia = clamp(amount, 0, 1);\n }\n\n /** 0..1 logistic-map bifurcation: period doubling near 0.3, chaos past about 0.62. */\n setChaos(amount: number): void {\n this.chaos = clamp(amount, 0, 1);\n }\n\n /** The last glottal flow sample: 0 while closed, about 1 at peak. */\n get flow(): number {\n return this.u;\n }\n\n /**\n * The glottal area of the last nextArea() sample: 0 while closed, about 1\n * at peak, scaled by the cycle's shimmer. Multiply by an area in cm^2.\n */\n get openArea(): number {\n return this.aOut;\n }\n\n /**\n * Advances one sample of the area waveform only, for a caller that solves\n * the flow itself from the pressure across the folds (src/dsp/tract.ts),\n * which is where source and tract interact. It draws the same streams at\n * the same moments as next(), so drift, jitter, shimmer and fry behave\n * the same; the flow and its derivative are not computed. Use one of\n * next() and the area methods per source, not both.\n */\n nextArea(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.startCycle();\n }\n this.phase = ph;\n this.aOut = this.area(ph);\n }\n\n /**\n * nextArea() for samples [from, to) of out, for a caller whose own loop is\n * too large to inline the pulse: called on its own, this method keeps the\n * pulse's calls inside its own optimization, as process() does for next().\n */\n processArea(out: Float64Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.nextArea();\n out[i] = this.aOut;\n }\n }\n\n /**\n * Advances the cycle by one sample and computes no area: for a fold model\n * that takes its phase, `amp` and `odd` from this unit and builds the area\n * itself (dsp/geometric-glottis.ts). The streams are drawn at the same\n * moments as by next() and nextArea().\n */\n nextPhase(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.ampPrev = this.amp;\n this.startCycle();\n }\n this.phase = ph;\n }\n\n /** nextPhase() for samples [from, to) of out, writing each phase: the block form, as processArea(). */\n processPhase(out: Float64Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.nextPhase();\n out[i] = this.phase;\n }\n }\n\n /** The rate the last sample advanced at, in Hz, after drift, fry and the cycle's perturbation. */\n get f0(): number {\n return this.inc * this.sampleRate;\n }\n\n /** One sample of the glottal flow derivative. */\n next(): number {\n this.step();\n return this.y;\n }\n\n /** Overwrites out over [from, to), for callers whose own loop is too large to inline step(). */\n process(out: Float32Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.step();\n out[i] = this.y;\n }\n }\n\n /**\n * Advances one sample and leaves it in `y`. It returns nothing, so no\n * double crosses this call for V8 to box when it is not inlined (the\n * pattern of CritDampBank.step()); everything it calls per sample is\n * inlined into it. Keep under 460 bytes of bytecode: see COST.\n */\n private step(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.startCycle();\n }\n this.phase = ph;\n const a = this.area(ph);\n\n // Backward Euler on T du/dphase = 1 - (u/a)^2, rationalised: exact zero when a is.\n let u = 0;\n if (a > 0) {\n const h = inc * INV_INERTANCE;\n const b = this.u + h;\n u = (2 * b) / (1 + Math.sqrt(1 + (4 * h * b) / (a * a)));\n }\n\n let out = u + this.pending;\n this.pending = 0;\n if (ph + inc >= this.closeFirst && ph < this.closeFirst) out += this.cornerFirst(ph, inc);\n if (ph + inc >= this.closeSecond && ph < this.closeSecond) out += this.cornerSecond(ph, inc);\n this.y = ((out - this.uOut) * GAIN) / inc;\n this.uOut = out;\n this.u = u;\n }\n\n /** CHIMERA's fry pull of the rate toward FRY_HZ (glottis.rs:166-168). */\n private fryPull(hz: number): number {\n const fry = this.fry;\n return hz * (1 - fry) + (hz < FRY_HZ ? hz : FRY_HZ) * fry;\n }\n\n /** Glottal area at phase ph: the main pulse plus, under heavy fry, the second one. */\n private area(ph: number): number {\n const amp = this.amp;\n let a = amp * pulse(ph, this.oq, this.invOq, this.skew, this.invSkew, this.invFall, this.sharp);\n if (this.fryGain > 0 && ph > FRY_OFFSET) {\n a +=\n amp *\n this.fryGain *\n pulse(ph - FRY_OFFSET, this.oq2, this.invOq2, this.skew, this.invSkew, this.invFall, this.sharp);\n }\n return a;\n }\n\n /**\n * The main pulse closes before the next sample. It closes onto zero\n * unless the second fry pulse is already open there, and an open second\n * pulse rounds the corner over about a2 T / 2 of a period, so the\n * correction fades with that time measured in samples.\n */\n private cornerFirst(ph: number, inc: number): number {\n const oq = this.oq;\n let weight = 1;\n if (this.fryGain > 0 && oq > FRY_OFFSET) {\n const a2 =\n this.amp *\n this.fryGain *\n pulse(oq - FRY_OFFSET, this.oq2, this.invOq2, this.skew, this.invSkew, this.invFall, this.sharp);\n weight = 1 / (1 + (a2 * INERTANCE) / (2 * inc));\n }\n const slope = this.amp * this.sharp * HALF_PI * this.invFall * this.invOq;\n return this.corner(ph, inc, oq, slope, weight);\n }\n\n /** The second fry pulse closes before the next sample, always onto zero. */\n private cornerSecond(ph: number, inc: number): number {\n const slope = this.amp * this.fryGain * this.sharp * HALF_PI * this.invFall * this.invOq2;\n return this.corner(ph, inc, this.end2, slope, 1);\n }\n\n /**\n * Two-point polyBLAMP for the flow corner at phase `end`, which falls\n * between this sample and the next. `slope` is the magnitude of the area\n * slope per unit phase just before closure; the flow closes k times\n * faster, k the positive root of k^2 - T s k - 1 = 0. The residual\n * (1 - |x|)^3 / 6 is added at both neighbours of the corner: this\n * sample's share is returned, the next one's is left in `pending`.\n */\n private corner(ph: number, inc: number, end: number, slope: number, weight: number): number {\n const ts = INERTANCE * slope;\n const flowSlope = 0.5 * slope * (ts + Math.sqrt(ts * ts + 4));\n const mu = weight * flowSlope * inc;\n const x = (end - ph) / inc;\n const d = 1 - x;\n this.pending += (mu * x * x * x) / 6;\n return (mu * d * d * d) / 6;\n }\n\n /** New cycle: the shape catches up with its settings, then the per-cycle draws. */\n private startCycle(): void {\n this.latch();\n this.odd = !this.odd;\n const alt = this.odd ? 1 : -1;\n let chaosP = 0;\n let chaosA = 0;\n const chaos = this.chaos;\n if (chaos > 0) {\n const r = 2.9 + 1.1 * chaos;\n let x = r * this.chaosX * (1 - this.chaosX);\n if (!(x > 0 && x < 1)) x = 0.37; // CHAOS_RESTART, a literal for the reason above\n this.chaosX = x;\n const dev = x - 0.5;\n chaosP = 0.45 * chaos * dev;\n chaosA = 1.1 * chaos * dev;\n }\n // two Irwin-Hall draws of four uniforms each (NamedRng.gauss), by mulberry32 inline\n let st = this.cycleS;\n let u0 = 0;\n let u1 = 0;\n for (let q = 0; q < 8; q++) {\n st = (st + 0x6d2b79f5) | 0;\n let t = Math.imul(st ^ (st >>> 15), st | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n const u = ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n if (q < 4) u0 += u;\n else u1 += u;\n }\n this.cycleS = st;\n const gp = (u0 - 2) * Math.SQRT2 * 0.875 * UNIT_GAUSS;\n const ga = (u1 - 2) * Math.SQRT2 * 0.875 * UNIT_GAUSS;\n // the limits as literals: a module constant merged with a double in a conditional made V8\n // box the double once a cycle (MEASURED in the vocal engine)\n const sc = 1 + this.jitter * gp + this.diplophonia * 0.08 * alt + chaosP;\n this.scale = sc < 0.55 ? 0.55 : sc > 1.8 ? 1.8 : sc;\n const amp = 1 + this.shimmer * ga - (this.odd ? this.diplophonia * 0.35 : 0) + chaosA;\n this.amp = amp > 0.12 ? amp : 0.12;\n }\n\n /** One control-rate step of the three-band drift, and the pitch factor it gives. */\n private stepDrift(): void {\n this.driftCountdown = this.driftInterval;\n // three Irwin-Hall draws, by mulberry32 inline (see cycleS)\n let st = this.driftS;\n let g0 = 0;\n let g1 = 0;\n let g2 = 0;\n for (let q = 0; q < 12; q++) {\n st = (st + 0x6d2b79f5) | 0;\n let t = Math.imul(st ^ (st >>> 15), st | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n const u = ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n if (q < 4) g0 += u;\n else if (q < 8) g1 += u;\n else g2 += u;\n }\n this.driftS = st;\n const gs = Math.SQRT2 * 0.875 * UNIT_GAUSS;\n this.drift0 = this.driftPole0 * this.drift0 + this.driftIn0 * (g0 - 2) * gs;\n this.drift1 = this.driftPole1 * this.drift1 + this.driftIn1 * (g1 - 2) * gs;\n this.drift2 = this.driftPole2 * this.drift2 + this.driftIn2 * (g2 - 2) * gs;\n const v = (this.drift0 + this.drift1 / 2 + this.drift2 / 3) / DRIFT_NORM;\n this.pitchFactor = Math.pow(2, (this.driftCents * v) / 1200);\n }\n\n /** Puts the tension and fry settings into force. Called where the area is zero. */\n private latch(): void {\n const fry = this.targetFry;\n this.fry = fry;\n const oq = fry > 0 ? this.targetOq * (1 - fry) + FRY_OQ * fry : this.targetOq;\n this.oq = oq;\n this.invOq = 1 / oq;\n this.skew = this.targetSkew;\n this.invSkew = 1 / this.targetSkew;\n this.invFall = 1 / (1 - this.targetSkew);\n this.sharp = this.targetSharp;\n const corners = this.sharp > 0;\n // NO_CORNER (2) as a literal: a module constant merged with a double in a conditional is boxed\n this.closeFirst = corners ? oq : 2;\n if (fry > 0.3) {\n const t = clamp((fry - 0.3) / 0.5, 0, 1);\n this.fryGain = FRY_PEAK * t * t * (3 - 2 * t);\n this.oq2 = oq * FRY_OQ_RATIO;\n this.invOq2 = 1 / this.oq2;\n this.end2 = FRY_OFFSET + this.oq2;\n this.closeSecond = corners ? this.end2 : 2;\n } else {\n this.fryGain = 0;\n this.end2 = 0;\n this.closeSecond = NO_CORNER;\n }\n }\n}\n", "/*\n * The geometric glottis: vocal folds whose two edges move as the\n * kinematic model of Titze (1984, \"Parameterization of the glottal area,\n * glottal flow, and vocal fold contact area\", JASA 75) does, extended by\n * Birkholz, Drechsel and Stone (2019, \"Perceptual optimization of an\n * enhanced geometric vocal fold model for articulatory speech synthesis\",\n * Interspeech, 3765-3769), and written here from those papers. It makes a\n * glottal AREA; the airway (dsp/junction-airway.ts) solves the flow\n * through it from the pressures on either side, so the source and the\n * tract interact as they do in life.\n *\n * THE FOLDS. Each fold has a lower (i = 1) and an upper (i = 2) edge. Along\n * the fold, y from the vocal processes (0) to the anterior commissure (L),\n * the edge's distance from the midline is\n *\n * x_i(y, t) = x_rest,i (1 - y / L) + x_max sin(pi y / L) sin(phi_i(t))\n *\n * a rest (prephonatory) displacement that opens a triangle toward the back,\n * plus a string-like vibration fixed at both ends. The upper edge lags the\n * lower by a phase (the mucosal wave travelling up the fold): phi_2 =\n * phi_1 - lag. The paper's naturalness test put the best male voice at a\n * lag of 70 degrees, rest 0.3 mm lower and 0.6 mm upper (a slightly\n * divergent glottis), no skew and 0.05 double pulsing; the best female at\n * 50 degrees, 0.6 and 0.6 mm, skew 0.2, 0.05. Each edge's area is twice the\n * integral of its positive part along y, plus a posterior chink, and the\n * area the air sees is the smaller of the two:\n *\n * A_i = 2 integral_0^L max(x_i, 0) dy + A_chink, A = min(A_1, A_2)\n *\n * The integral is closed form. With u = y / L, a = x_rest, b = x_max sin\n * phi, f(u) = a (1 - u) + b sin(pi u) and F(u) = a (u - u^2 / 2) - (b / pi)\n * cos(pi u). f(1) = 0 always, so the other root solves sin(pi v) / v = -a /\n * b with v = 1 - u, and sin(pi v) / v falls monotonically from pi to 0 on\n * (0, 1]: one root or none. It is read from a table (q = sqrt(1 - r / pi)\n * makes it smooth at both ends); the integral is stationary in the root,\n * f being zero there, so the table's error enters only at second order.\n *\n * AMPLITUDE. x_max = c x_rel sqrt(P_trans) L0 / L, after Titze (1989, \"On\n * the relation between subglottal pressure and fundamental frequency in\n * phonation\", JASA 85), with c set so that x_max = 1 mm at 800 Pa: the\n * folds swing wider the harder the air pushes, from the pressure the\n * airway actually has across them. The caller passes x_max. Since the\n * rest displacements here come from areas (x_rest = A_rest / L) and x_max\n * L / L0 does not depend on L, the area does not depend on the length, and\n * the paper's length rule drops out: only L0 (the body's fold length)\n * scales the area.\n *\n * SKEW. The phase is warped piecewise linearly so the opening and the\n * closing take different times (the paper's skewness s in [-1, 1]): the\n * displacement peak moves from a quarter of the cycle to (1 + s) / 4, the\n * closing quarter ends at the half cycle as before. s > 0 skews the pulse\n * to the right, as real flow pulses are.\n *\n * DOUBLE PULSING. On every second cycle the dynamic part becomes x_max\n * [(1 - d / 2)(sin phi + 1) - 1]: the opening peak drops by d, the\n * closing extreme stays (the paper's form).\n *\n * THE CYCLE. Pitch, drift, jitter, shimmer, diplophonia and chaos come from\n * a GlottalSource stepped with nextPhase(): its phase is phi_1 / 2 pi, its\n * cycle amplitude scales x_max, and its parity is the double pulse's. An\n * edge that lags into the previous cycle keeps that cycle's amplitude and\n * parity, so a new cycle's draw never steps the upper edge. Fry's second\n * pulse is the parametric source's and has no counterpart here.\n *\n * NO ALLOCATION. Inputs are fields; process() writes areas into a buffer.\n */\n\nimport type { GlottalSource } from './glottal';\n\nconst PI = Math.PI;\nconst INV_PI = 1 / PI;\nconst TWO_OVER_PI = 2 / PI;\nconst TWO_PI = 2 * PI;\n\n/** x_max per sqrt(dyn/cm^2): 0.1 cm at 800 Pa (8000 dyn/cm^2), the paper's calibration. */\nexport const GEO_AMPLITUDE = 0.1 / Math.sqrt(8000);\n\n/* The root table: v(q) and cos(pi v(q)) on q in [0, 1], q = sqrt(1 - r / pi), r = sin(pi v) / v. */\nconst ROOT_N = 256;\nconst ROOT_V = new Float64Array(ROOT_N + 2);\nconst ROOT_C = new Float64Array(ROOT_N + 2);\n(function buildRoots(): void {\n for (let k = 0; k <= ROOT_N + 1; k++) {\n const q = Math.min(1, k / ROOT_N);\n const r = PI * (1 - q * q);\n // sin(pi v) / v decreases on (0, 1]: bisect for the v that gives r\n let lo = 1e-12;\n let hi = 1;\n for (let it = 0; it < 80; it++) {\n const mid = 0.5 * (lo + hi);\n if (Math.sin(PI * mid) / mid > r) lo = mid;\n else hi = mid;\n }\n const v = 0.5 * (lo + hi);\n ROOT_V[k] = v;\n ROOT_C[k] = Math.cos(PI * v);\n }\n})();\n\n/**\n * The edge integral's arguments and result: EDGE[0] = a, EDGE[1] = b in,\n * EDGE[2] out. A typed array, so no double crosses the call: V8 boxes one\n * that crosses a call it does not inline (MEASURED: 48 bytes a sample when\n * edgeOpen() and the warp were called from the loop).\n */\nconst EDGE = new Float64Array(3);\n\n/** EDGE[2] = the integral over u in [0, 1] of max(a (1 - u) + b sin(pi u), 0), one edge's open area per 2 L. */\nfunction edgeInto(): void {\n const a = EDGE[0];\n const b = EDGE[1];\n if ((b >= 0 && a >= 0) || (b < 0 && a >= -PI * b)) {\n // open along the whole length\n EDGE[2] = 0.5 * a + TWO_OVER_PI * b;\n return;\n }\n if (!((b > 0 && -a < PI * b) || (b < 0 && a > 0))) {\n // shut along the whole length\n EDGE[2] = 0;\n return;\n }\n // one root inside (0, 1): r = -a / b in (0, pi), v solves sin(pi v) / v = r, u0 = 1 - v\n const r = -a / b;\n let q = 1 - r * INV_PI;\n q = q > 0 ? Math.sqrt(q) : 0;\n const x = q * ROOT_N;\n const k = x | 0;\n const f = x - k;\n const v = ROOT_V[k] + (ROOT_V[k + 1] - ROOT_V[k]) * f;\n const cv = ROOT_C[k] + (ROOT_C[k + 1] - ROOT_C[k]) * f;\n const u0 = 1 - v;\n // F(u0) with cos(pi u0) = -cos(pi v)\n const F0 = a * (u0 - 0.5 * u0 * u0) + b * INV_PI * cv;\n // b > 0: open on (u0, 1], F(1) - F(u0); b < 0: open on [0, u0), F(u0) - F(0)\n EDGE[2] = b > 0 ? 0.5 * a + b * INV_PI - F0 : F0 + b * INV_PI;\n}\n\n/** The integral's value for one edge, (a, b) as above: the testable form, off the audio path. */\nexport function edgeOpen(a: number, b: number): number {\n EDGE[0] = a;\n EDGE[1] = b;\n edgeInto();\n return EDGE[2];\n}\n\n/*\n * WARP. The phase ph in [0, 1) is warped piecewise linearly so the\n * displacement peak sits at `peak` of the cycle and the half cycle stays\n * where it was: the opening quarter and the closing quarter trade time, the\n * closed half is unchanged. Where the edge crosses the midline its speed\n * drops back to the unwarped one, so a right-skewed pulse lands softly (the\n * posterior part, still open at that moment, then closes at the slower\n * speed). MEASURED: against the warp with one breakpoint (the whole cycle\n * after the peak at one speed), this one put the male vowels 3 to 4 dB\n * nearer CHIMERA's at 1.5 to 4 kHz (docs/VOICE-2.md, \"Vocal folds\").\n */\nexport class GeometricGlottis {\n /* ---- Inputs: targets for the end of the next process() call. ---- */\n /** Rest displacement of the lower and upper edges at the vocal processes, cm. */\n xRest1 = 0.03;\n xRest2 = 0.06;\n /** Posterior chink, cm^2. */\n chink = 0.01;\n /** Vibration amplitude x_max, cm (GEO_AMPLITUDE x_rel sqrt(P_trans), times the voicing level). */\n xMax = 0;\n /** Fold length at rest L0, cm. */\n length = 1.6;\n /** Upper edge's phase lag, in cycles (70 degrees: 70 / 360). */\n lag = 70 / 360;\n /** Skewness s in [-1, 1]. */\n skew = 0;\n /** Double pulsing d in [0, 1]. */\n doublePulse = 0.05;\n\n /* ---- Outputs. ---- */\n /** The lower and upper edges' areas of the last sample, cm^2. */\n area1 = 0;\n area2 = 0;\n\n /* ---- Values in force at the start of the next call (ramped from). ---- */\n private r1 = 0.03;\n private r2 = 0.06;\n private ch = 0.01;\n private xm = 0;\n private first = true;\n\n /** The next process() starts from its targets rather than ramping to them. */\n reset(): void {\n this.first = true;\n this.area1 = this.area2 = 0;\n }\n\n /**\n * Steps src (nextPhase) once per sample over [from, to) and writes the\n * glottal area, cm^2, into out. The inputs ramp linearly from their values\n * at the last call to the current fields across the span.\n */\n process(src: GlottalSource, out: Float64Array, from: number, to: number): void {\n if (this.first) {\n this.r1 = this.xRest1;\n this.r2 = this.xRest2;\n this.ch = this.chink;\n this.xm = this.xMax;\n this.first = false;\n }\n const n = to - from;\n if (n <= 0) return;\n const inv = 1 / n;\n const r1a = this.r1;\n const r2a = this.r2;\n const cha = this.ch;\n const xma = this.xm;\n const dr1 = this.xRest1 - r1a;\n const dr2 = this.xRest2 - r2a;\n const dch = this.chink - cha;\n const dxm = this.xMax - xma;\n const twoL = 2 * this.length;\n let s = this.skew;\n s = s < -0.9 ? -0.9 : s > 0.9 ? 0.9 : s;\n const peak = 0.25 * (1 + s);\n const rise = 0.25 / peak;\n const fall = 0.25 / (0.5 - peak);\n let lag = this.lag;\n lag = lag < 0 ? 0 : lag > 0.5 ? 0.5 : lag;\n let d = this.doublePulse;\n d = d < 0 ? 0 : d > 1 ? 1 : d;\n const dh = 1 - 0.5 * d;\n let a1 = 0;\n let a2 = 0;\n for (let i = from; i < to; i++) {\n src.nextPhase();\n const w = (i - from + 1) * inv;\n const xm = xma + dxm * w;\n const ph = src.phase;\n // the warp (see WARP), written out for both edges: no double crosses a call\n let phi = ph < peak ? ph * rise : ph < 0.5 ? 0.25 + (ph - peak) * fall : ph;\n let s1 = Math.sin(TWO_PI * phi);\n if (src.odd) s1 = dh * (s1 + 1) - 1;\n let ph2 = ph - lag;\n let odd2 = src.odd;\n let amp2 = src.amp;\n if (ph2 < 0) {\n ph2 += 1;\n odd2 = !odd2;\n amp2 = src.ampPrev;\n }\n phi = ph2 < peak ? ph2 * rise : ph2 < 0.5 ? 0.25 + (ph2 - peak) * fall : ph2;\n let s2 = Math.sin(TWO_PI * phi);\n if (odd2) s2 = dh * (s2 + 1) - 1;\n const ch = cha + dch * w;\n EDGE[0] = r1a + dr1 * w;\n EDGE[1] = xm * src.amp * s1;\n edgeInto();\n a1 = twoL * EDGE[2] + ch;\n EDGE[0] = r2a + dr2 * w;\n EDGE[1] = xm * amp2 * s2;\n edgeInto();\n a2 = twoL * EDGE[2] + ch;\n out[i] = a1 < a2 ? a1 : a2;\n }\n this.area1 = a1;\n this.area2 = a2;\n this.r1 = this.xRest1;\n this.r2 = this.xRest2;\n this.ch = this.chink;\n this.xm = this.xMax;\n }\n}\n", "/*\n * The singer's pitch servo: a self-oscillating source finds its own\n * frequency from its tension and the pressure on it, so a singer who wants\n * a note listens and adjusts. This loop does the same once a cycle: it\n * compares each measured cycle's frequency with the target and moves a\n * multiplicative correction of the tension toward the ratio, by a fraction\n * 1 - exp(-T / tau) of the log error for a cycle of length T, so it\n * converges with time constant tau whatever the pitch. A feedforward\n * tension (the caller's, from the target) does the bulk of a glide; the\n * correction only takes up what the model's own physics adds: the\n * pressure's pull on f0, the collision's stiffening, the integrator's\n * frequency warping at a low sample rate.\n *\n * tau is a few tens of milliseconds: slow enough that the short f0 dip of a\n * voiced closure (the transglottal pressure falling, 50 to 100 ms) is\n * mostly left in, fast enough that a held note lands in a fraction of its\n * glide. The caller's weight leaves the rest of the dip in (it falls as the\n * pressure backs up above the folds). In an onset's first cycles a large\n * error converges faster. One cycle far from the target (an onset's first\n * irregular cycles, a period doubling) is ignored rather than chased; a run\n * of them is chased at the limit ratio, so a correction carried out of\n * range comes back.\n *\n * Inputs and outputs are fields; cycle() takes nothing and returns nothing.\n * The folds call it every sample so V8 optimizes and inlines it, and it\n * works only when a new cycle is pending: called once a cycle, it stayed\n * unoptimized and boxed its doubles.\n */\n\n/** Correction limits: an octave each way. */\nconst MIN_CORRECTION = 0.5;\nconst MAX_CORRECTION = 2;\n/** The error in cents at which the servo runs twice as fast as tau. */\nconst ADAPT_CENTS = 40;\nconst CENTS_PER_NEPER = 1200 / Math.LN2;\n/** A measured cycle further than this ratio from the target is not used, unless it is one of a run (FAR_RUN). */\nconst MAX_RATIO = 1.6;\n/** Full cycles in a row, all far off on one side, that mean the folds are lost rather than one odd cycle. */\nconst FAR_RUN = 3;\n\nexport class PitchServo {\n /** The frequency aimed at, Hz. */\n target = 110;\n /** The last measured cycle's frequency, Hz (the input of cycle()). */\n measured = 110;\n /** The tension correction, multiplying the feedforward. */\n correction = 1;\n /** The servo's time constant, s. */\n tau = 0.04;\n /** 1 when `measured` holds a cycle cycle() has not used yet. */\n pending = 0;\n /** 1 when the pending cycle is a full one (the folds' own depth test); only full cycles speed the servo up. */\n deep = 1;\n /** 1 while the folds are in an onset's first cycles (the folds' own test); only then may a large error speed it up. */\n onset = 1;\n /**\n * How far the cycles count, 0..1: the caller's measure of whether f0 is the tension's or the pressure's.\n * The servo stands for the tension a singer sets, and a singer lets a voiced closure's dip go by.\n */\n weight = 1;\n /** Set by the folds at an onset: the next cycle has no predecessor to agree with (the last was before the gap). */\n restart = 0;\n /** The last used cycle's log error, ln(target / measured). */\n private lastLog = 0;\n /** Full cycles in a row far off, and on which side (1 sharp, -1 flat). */\n private farRun = 0;\n private farSide = 0;\n\n reset(): void {\n this.correction = 1;\n this.measured = this.target;\n this.pending = 0;\n this.lastLog = 0;\n this.farRun = 0;\n this.farSide = 0;\n }\n\n /** One measured cycle: update the correction. A no-op unless a cycle is pending (see FoldOscillator.step). */\n cycle(): void {\n if (this.pending === 0) return;\n this.pending = 0;\n const m = this.measured;\n const t = this.target;\n if (!(m > 0) || !(t > 0)) return;\n let ratio = t / m;\n let lost = 0;\n if (ratio > MAX_RATIO || ratio < 1 / MAX_RATIO) {\n // ignored alone; a run of full cycles far off on one side is a correction carried out of range, and\n // ignoring them held it there (MEASURED: the child's /b\u0251/ in \"stops\" 0.5 s at 1.8 times its note)\n const side = ratio > 1 ? 1 : -1;\n this.farRun = this.deep === 0 ? 0 : side === this.farSide ? this.farRun + 1 : 1;\n this.farSide = side;\n if (this.farRun < FAR_RUN) return;\n // Math.min and Math.max, not a conditional: V8 boxed a double merged with a module-level constant\n ratio = Math.min(Math.max(ratio, 1 / MAX_RATIO), MAX_RATIO);\n lost = 1;\n } else this.farRun = 0;\n // in an onset (or lost) a large error converges faster: the time constant shrinks by 1 + |error| /\n // ADAPT_CENTS, so an onset's semitone or two after a voiceless stop is gone in a few cycles instead of a\n // 60 to 100 ms audible slide (MEASURED in \"twinkle\": onsets 1 to 2.7 semitones sharp, falling over 60\n // to 100 ms at tau alone). Mid-note it does not: the pressure falling in a voiced closure lowers f0 for\n // as long as the closure lasts, and chasing that dip fast took the correction from 1.08 to 1.76 in 25 ms\n // and the release 800 cents sharp (MEASURED, the same /b\u0251/)\n // Only a full cycle whose error the cycle before agrees with speeds it up (the smaller of the two, same sign): one odd\n // cycle (an irregular turn, a cycle locked to a resonance) at the fast rate threw the correction about\n // (MEASURED: drops of 15 percent in one cycle near F1 in the female melisma)\n if (this.restart !== 0) {\n this.restart = 0;\n this.lastLog = 0;\n }\n const lr = Math.log(ratio);\n const lp = this.lastLog;\n this.lastLog = lr;\n const same = lr * lp > 0 ? 1 : 0;\n const a = lr < 0 ? -lr : lr;\n const b = lp < 0 ? -lp : lp;\n // the closing folds' shallow cycles run at any rate as the pressure under them builds (MEASURED: two at\n // 366 Hz under a 460 Hz target took the correction from 1.20 to 1.42 and the note began 280 cents sharp)\n const cents = this.deep * same * (this.onset | lost) * (a < b ? a : b) * CENTS_PER_NEPER;\n const g = 1 - Math.exp((-this.weight * (1 + cents / ADAPT_CENTS)) / (m * this.tau));\n // Math.min and Math.max, not a conditional: V8 boxed a double merged with a module-level constant\n this.correction = Math.min(Math.max(this.correction * Math.pow(ratio, g), MIN_CORRECTION), MAX_CORRECTION);\n }\n}\n", "/*\n * Self-oscillating vocal folds: the two-mass model of Ishizaka and\n * Flanagan (1972, \"Synthesis of voiced sounds from a two-mass model of the\n * vocal cords\", Bell Syst. Tech. J. 51) with the pressure model of\n * Steinecke and Herzel (1995, \"Bifurcations in an asymmetric vocal-fold\n * model\", JASA 97), on a triangular glottis after Birkholz, Kroger and\n * Neuschaefer-Rube (2011, \"Synthesis of breathy, normal, and pressed\n * phonation using a two-mass model with a triangular glottis\",\n * Interspeech): written from those papers. Nothing here draws a pulse: the\n * folds open because the air pushes them, close because their springs and\n * the Bernoulli suction pull them back, and the period is whatever the\n * masses, springs and pressures make it.\n *\n * MASSES. A lower mass m1 (depth d1) and an upper mass m2 (depth d2) per\n * fold, each on a spring k_i to the body and coupled to each other by k_c,\n * with damping ratios zeta_i. Ishizaka and Flanagan's values: m1 0.125 g,\n * m2 0.025 g, k1 80 000 and k2 8000 dyn/cm, k_c 25 000 dyn/cm, zeta 0.1 and\n * 0.6, d1 0.25 and d2 0.05 cm, length 1.4 cm.\n *\n * THE TRIANGULAR GLOTTIS. At rest the folds are apart by r_i at the vocal\n * processes and meet at the anterior commissure, so mass i's edge is at\n * w_i(u) = r_i (1 - u) + x_i along the fold (u from the back, 0, to the\n * front, 1), x_i its displacement. Its open area is 2 L times the integral\n * of max(w_i, 0), its contact depth the integral of max(-w_i, 0), both\n * closed form for a line. Abduction (a breathy or voiceless glottis) is a\n * larger r_i; the folds then close only in front, or not at all, and the\n * model's own threshold rises with it, as Titze (1988) derives.\n *\n * PRESSURES (Steinecke and Herzel). With the flow separating at the\n * narrowest point, a convergent glottis (A1 > A2) has P1 = Ps - (Ps - Pe)\n * (A2 / A1)^2 on the lower mass and Pe on the upper; a divergent one has Pe\n * on both. While a mass is shut, the air below it presses with Ps. Each\n * force is P_i L d_i. Ps and Pe are the airway's pressures below and above\n * the glottis at the previous sample, and the airway solves the flow\n * through min(A1, A2) plus the chink: the folds and the air are one system.\n *\n * COLLISION. A mass in contact meets a spring h_i = 3 k_i on its mean\n * contact depth (Ishizaka and Flanagan's rule) and an extra damping ratio of\n * 1, weighted by the fraction of its length in contact.\n *\n * TENSION. Ishizaka and Flanagan scale the masses by 1 / Q and the\n * stiffnesses by Q, which moves every frequency by Q and shrinks the swing\n * by 1 / Q. Here the masses go by Q^-1.5 and the springs by Q^0.5: the\n * frequency still moves by exactly Q, and the swing by Q^-0.5, so a high\n * note keeps more of its amplitude (the folds also lengthen and thin as\n * they stretch). Q is the feedforward f / F_REF times the servo's\n * correction (dsp/pitch-servo.ts) times the caller's perturbation.\n *\n * INTEGRATION. Semi-implicit Euler at the audio rate, the damping implicit.\n * The stiffest motion, the upper mass in collision, has omega dt 0.55 at\n * Q 8 and 22050 Hz (0.82 at the largest Q, 12), inside the method's\n * stability limit of 2, so nothing oversamples (test/dsp-osc/\n * fold-oscillator.test.ts runs it at 22050 to 96000 Hz).\n *\n * Inputs are fields; step() takes and returns nothing and allocates nothing.\n */\n\nimport { PitchServo } from './pitch-servo';\n\n/* Ishizaka and Flanagan (1972) values. */\nconst M1 = 0.125;\nconst M2 = 0.025;\nconst K1 = 80000;\nconst K2 = 8000;\nconst KC = 25000;\nconst ZETA1 = 0.1;\nconst ZETA2 = 0.6;\nconst D1 = 0.25;\nconst D2 = 0.05;\n/** Collision stiffness over the spring's, and the extra damping ratio in contact. */\nconst HIT = 3;\nconst HIT_ZETA = 1;\n/**\n * The model's frequency at Q = 1, Hz. MEASURED in the vocal engine, a held\n * male /\u0251/ at 48 kHz: with 165 here the servo settled at corrections of\n * 1.03 to 1.06 from 110 to 220 Hz. The servo takes up the rest\n * (test/dsp-osc/fold-oscillator.test.ts holds it within a fifth).\n */\nexport const FOLD_F_REF = 158;\nconst MIN_Q = 0.25;\n/** The glottal area's swing over its mean that makes a cycle voiced. */\nconst DEPTH = 0.2;\n/** The swing over its mean that a cycle needs before the servo tunes on it. */\nconst TUNE_DEPTH = 0.03;\n/** A gap in full cycles longer than this many target periods ends voicing (the airway reads voicing so too). */\nexport const VOICED_GAP = 1.6;\n/** How long after the first full cycle that follows a gap the servo may speed up for a large error, s. */\nconst ONSET_S = 0.05;\nconst MAX_Q = 12;\n\nexport class FoldOscillator {\n /* ---- Inputs. ---- */\n /** Pressures below and above the glottis, dyn/cm^2 (written by the airway each sample). */\n ps = 0;\n pe = 0;\n /** Rest displacements of the lower and upper masses at the vocal processes, cm. */\n rest1 = 0.01;\n rest2 = 0.01;\n /** Posterior chink, cm^2. */\n chink = 0.01;\n /** Fold length, cm. */\n length = 1.4;\n /**\n * Where rest1, rest2, chink and length ramp to, and over how many more steps (0: no ramp). A caller\n * that updates once a block sets the block's end here and the ramp goes on from where the last\n * ended: a rest that stepped once a block moved the glottis in steps at the block rate, and a fast\n * adduction rang the tract (MEASURED: a 1.5 kHz tone 20 to 35 dB over the pulse's while the folds\n * closed after a voiceless stop). The chink and the length enter the area directly, so they ramp too.\n */\n rest1To = 0.01;\n rest2To = 0.01;\n chinkTo = 0.01;\n lengthTo = 1.4;\n rampLeft = 0;\n /** A multiplier on the tension (drift, jitter), applied after the servo. */\n perturb = 1;\n /** 0..1: how far the folds are free to move (1 - a glottal stop's closure); 0 holds them shut. */\n free = 1;\n readonly servo = new PitchServo();\n\n /* ---- Outputs. ---- */\n /** The glottal area of the last step, cm^2 (min of the two masses' plus the chink). */\n area = 0;\n area1 = 0;\n area2 = 0;\n x1 = 0;\n x2 = 0;\n v1 = 0;\n v2 = 0;\n /** Cycles counted since reset (white box). */\n cycles = 0;\n\n private readonly dt: number = 0;\n private readonly rate: number = 0;\n /* Per-block coefficients. */\n private m1 = M1;\n private m2 = M2;\n private k1 = K1;\n private k2 = K2;\n private kc = KC;\n private b1 = 0;\n private b2 = 0;\n private bh1 = 0;\n private bh2 = 0;\n private q = 1;\n /** 1 when tune() has asked for new coefficients, which the next step() computes. */\n private stale = 1;\n /* Cycle detection: samples since reset, the last v1, the last turning point's time (-1: none). */\n private n = 0;\n private lastV1 = 0;\n private lastT = -1;\n private lastVoiced = -1;\n /** The sample index until which the cycles are an onset's (the servo's fast rate). */\n private onsetEnd = -1;\n /**\n * Samples since the last voiced cycle's turning point (a large number before the first): whether the\n * folds are vibrating now. A cycle is voiced when the glottal area swings by DEPTH of its mean or more:\n * abducted folds still shiver by micrometres, and counting those turns as cycles kept the voicing on\n * through voiceless sounds (MEASURED: voicing 0.5 after 60 ms of a 0.3 cm^2 opening).\n */\n sinceTurn = 1e9;\n /* The area's range since the last turning point. */\n private aLo = 1e9;\n private aHi = 0;\n\n constructor(rate: number) {\n this.rate = rate;\n this.dt = 1 / rate;\n }\n\n reset(): void {\n this.x1 = this.x2 = this.v1 = this.v2 = 0;\n // the pressures too: the airway writes them after each step, so the first step of a note read the last\n // note's (MEASURED: a reused voice parted from a fresh one at sample 19)\n this.ps = this.pe = 0;\n this.area = this.area1 = this.area2 = 0;\n this.n = 0;\n this.lastV1 = 0;\n this.lastT = -1;\n this.lastVoiced = -1;\n this.onsetEnd = -1;\n this.sinceTurn = 1e9;\n this.aLo = 1e9;\n this.aHi = 0;\n this.cycles = 0;\n this.rampLeft = 0;\n this.servo.reset();\n this.tune();\n }\n\n /**\n * The tension for the servo's target and correction and the perturbation: once a block. It only marks\n * the coefficients stale and the next step() computes them, inside the per-sample code V8 optimizes. A\n * method called once a block or once a cycle can stay unoptimized, and then every double it computes is\n * a heap number: with that, the event call that took two doubles and the clamps below written as\n * conditionals, a held vowel on these folds grew new space by 1.2 to 1.5 bytes a sample, against 0.03\n * for the other fold models (MEASURED; test/engines-physical/vocal.test.ts, \"allocation\").\n */\n tune(): void {\n this.stale = 1;\n }\n\n /** The tension Q the coefficients are (or, after tune(), will be) computed for (white box, not the audio path). */\n get tension(): number {\n if (!this.stale) return this.q;\n const q = (this.servo.target / FOLD_F_REF) * this.servo.correction * this.perturb;\n return q < MIN_Q ? MIN_Q : q > MAX_Q ? MAX_Q : q === q ? q : 1;\n }\n\n /** One sample: forces from the last pressures, the masses moved, the areas and a cycle check. */\n step(): void {\n if (this.rampLeft > 0) {\n const k = 1 / this.rampLeft;\n this.rest1 += (this.rest1To - this.rest1) * k;\n this.rest2 += (this.rest2To - this.rest2) * k;\n this.chink += (this.chinkTo - this.chink) * k;\n this.length += (this.lengthTo - this.length) * k;\n this.rampLeft--;\n }\n if (this.stale) {\n // the coefficients for the tension: masses as Q^-1.5, springs as Q^0.5, so f0 scales as Q\n this.stale = 0;\n // clamped with Math.min and Math.max: a conditional that merges a double with a module-level\n // constant made V8 box the result (MEASURED: one heap number each time this ran)\n const raw = (this.servo.target / FOLD_F_REF) * this.servo.correction * this.perturb;\n const q = Math.min(Math.max(raw === raw ? raw : 1, MIN_Q), MAX_Q);\n this.q = q;\n const qk = Math.sqrt(q);\n const qm = 1 / (q * qk);\n this.m1 = M1 * qm;\n this.m2 = M2 * qm;\n this.k1 = K1 * qk;\n this.k2 = K2 * qk;\n this.kc = KC * qk;\n this.b1 = 2 * ZETA1 * Math.sqrt(this.m1 * this.k1);\n this.b2 = 2 * ZETA2 * Math.sqrt(this.m2 * this.k2);\n this.bh1 = 2 * HIT_ZETA * Math.sqrt(this.m1 * this.k1);\n this.bh2 = 2 * HIT_ZETA * Math.sqrt(this.m2 * this.k2);\n }\n const L = this.length;\n const twoL = 2 * L;\n const r1 = this.rest1 > 0 ? this.rest1 : 0;\n const r2 = this.rest2 > 0 ? this.rest2 : 0;\n const x1 = this.x1;\n const x2 = this.x2;\n // open integrals and contact of the two lines w = r (1 - u) + x\n let o1 = 0;\n let c1 = 0;\n let f1 = 0;\n if (x1 >= 0) o1 = 0.5 * r1 + x1;\n else if (r1 + x1 > 0) {\n o1 = ((r1 + x1) * (r1 + x1)) / (2 * r1);\n c1 = (x1 * x1) / (2 * r1);\n f1 = -x1 / r1;\n } else {\n c1 = -(0.5 * r1 + x1);\n f1 = 1;\n }\n let o2 = 0;\n let c2 = 0;\n let f2 = 0;\n if (x2 >= 0) o2 = 0.5 * r2 + x2;\n else if (r2 + x2 > 0) {\n o2 = ((r2 + x2) * (r2 + x2)) / (2 * r2);\n c2 = (x2 * x2) / (2 * r2);\n f2 = -x2 / r2;\n } else {\n c2 = -(0.5 * r2 + x2);\n f2 = 1;\n }\n const a1 = twoL * o1;\n const a2 = twoL * o2;\n // Steinecke and Herzel's pressures\n const ps = this.ps;\n const pe = this.pe;\n let p1 = ps;\n let p2 = pe;\n if (a1 > 0 && a2 > 0) {\n if (a1 >= a2) {\n const r = a2 / a1;\n p1 = ps - (ps - pe) * r * r;\n } else p1 = pe;\n } else if (a1 > 0) p2 = ps;\n const free = this.free < 0 ? 0 : this.free > 1 ? 1 : this.free;\n const k1 = this.k1;\n const k2 = this.k2;\n const kc = this.kc;\n const m1 = this.m1;\n const m2 = this.m2;\n const dt = this.dt;\n // forces: pressure (times how free the folds are), springs, coupling, collision\n const F1 = free * p1 * L * D1 - k1 * x1 - kc * (x1 - x2) + HIT * k1 * c1;\n const F2 = free * p2 * L * D2 - k2 * x2 - kc * (x2 - x1) + HIT * k2 * c2;\n const bb1 = this.b1 + this.bh1 * f1;\n const bb2 = this.b2 + this.bh2 * f2;\n const v1 = (this.v1 + (dt * F1) / m1) / (1 + (dt * bb1) / m1);\n const v2 = (this.v2 + (dt * F2) / m2) / (1 + (dt * bb2) / m2);\n this.v1 = v1;\n this.v2 = v2;\n this.x1 = x1 + dt * v1;\n this.x2 = x2 + dt * v2;\n const ch = this.chink > 0 ? this.chink : 0;\n this.area1 = a1 + ch;\n this.area2 = a2 + ch;\n this.area = (a1 < a2 ? a1 : a2) + ch;\n // a cycle: the lower mass turns from opening to closing, between this sample and the last; the period\n // since the previous turn goes to the servo (written out here: a call taking these doubles boxed them)\n this.n++;\n const ar = this.area;\n this.aLo = Math.min(this.aLo, ar);\n this.aHi = Math.max(this.aHi, ar);\n const lv = this.lastV1;\n this.lastV1 = v1;\n if (lv > 0 && v1 <= 0) {\n const t = this.n - 1 + lv / (lv - v1);\n const period = t - this.lastT;\n const swing = this.aHi - this.aLo;\n const mean = 0.5 * (this.aHi + this.aLo);\n if (this.lastT >= 0 && period > 1 && swing > TUNE_DEPTH * mean) {\n // the servo takes the onset's shallow first cycles (gating them at DEPTH left onsets up to 370 cents\n // sharp for 55 ms) but not the shiver of abducted folds, whose turns come at any rate (44 to 854 Hz\n // under a 460 Hz target) and pulled the correction off before the note began (MEASURED)\n const deep = swing > DEPTH * mean ? 1 : 0;\n if (deep) {\n // the first full cycle after a gap opens an onset\n if (this.lastVoiced < 0 || t - this.lastVoiced > (VOICED_GAP * this.rate) / this.servo.target) {\n this.onsetEnd = t + ONSET_S * this.rate;\n this.servo.restart = 1;\n }\n this.lastVoiced = t;\n }\n this.servo.measured = this.rate / period;\n this.servo.deep = deep;\n this.servo.onset = t < this.onsetEnd ? 1 : 0;\n this.servo.pending = 1;\n this.cycles++;\n }\n this.lastT = t;\n this.aLo = 1e9;\n this.aHi = 0;\n }\n this.sinceTurn = this.lastVoiced >= 0 ? this.n - this.lastVoiced : 1e9;\n // every sample, so V8 optimizes and inlines it; it works only on a sample that measured a cycle (a call\n // once a cycle stayed unoptimized and boxed its doubles)\n this.servo.cycle();\n }\n}\n", "/*\n * When the folds vibrate: the phonation threshold and its hysteresis, for\n * a fold model that does not find its own threshold (the geometric glottis,\n * dsp/geometric-glottis.ts).\n *\n * THRESHOLD. Titze (1988, \"The physics of small-amplitude oscillation of\n * the vocal folds\", JASA 83) derives the least transglottal pressure that\n * sustains oscillation as proportional to the prephonatory half-width\n * xi_0: P_th = (k_t B c / T) xi_0, with k_t the transglottal pressure\n * coefficient, B the tissue's damping per unit area, c the mucosal wave's\n * speed and T the folds' thickness. That goes to zero for folds that\n * touch, which they do not do in life, so a floor P_0 is added: Titze\n * (1992, \"Phonation threshold pressure: a missing link in glottal\n * aerodynamics\", JASA 91) measures about 0.2 kPa at a speaker's mean f0.\n *\n * P_on = P_0 + K xi_0\n *\n * ONSET AND OFFSET. Oscillation starts at P_on and, once going, keeps\n * going down to a lower pressure: the offset to onset ratio is 0.5 to 1 in\n * Lucero (1999, \"A theoretical study of the hysteresis phenomenon at vocal\n * fold oscillation onset-offset\", JASA 105). So the state switches on when\n * the pressure rises past P_on and off when it falls past OFFSET_RATIO\n * P_on, and between the two it stays as it was.\n *\n * LEVEL. The oscillation grows into and dies out of its amplitude over a\n * few cycles, not at once: the state drives a one-pole level with an onset\n * and an offset time. `drive` (0..1) scales the target: a glottal stop\n * holds the folds together whatever the pressure.\n *\n * Runs once a block. Inputs and outputs are fields; nothing allocates.\n */\n\nimport { CM_H2O } from './air';\n\n/** Threshold floor, dyn/cm^2: 0.2 kPa (Titze 1992, at the mean f0). */\nexport const THRESHOLD_FLOOR = 2000;\n/**\n * Threshold slope per cm of half-width, dyn/cm^2 per cm. k_t B c / T with\n * k_t 1.1, B 100 dyn s/cm^3, c 100 cm/s and T 0.3 cm is 3.7e4 (3.7 cmH2O\n * per mm; INFERRED values in Titze's range). CHOICE: 4 cmH2O per mm, with\n * which a voiced fricative (rest half-width about 0.3 mm) keeps voicing at\n * the pressure the airway leaves it and a voiceless one (about 1 mm) loses\n * it (test/engines-physical/vocal.test.ts).\n */\nexport const THRESHOLD_SLOPE = 4 * CM_H2O * 10;\n/** Offset pressure over onset pressure (Lucero 1999: 0.5 to 1). */\nexport const OFFSET_RATIO = 0.7;\n/** The level's onset and offset time constants, s. CHOICE: under a cycle at speech f0, as the pulse's gate. */\nconst ONSET_TAU = 0.006;\nconst OFFSET_TAU = 0.006;\n\nexport class PhonationThreshold {\n /* ---- Inputs. ---- */\n /** Transglottal pressure, dyn/cm^2 (smoothed over about a cycle). */\n pressure = 0;\n /** Prephonatory half-width xi_0, cm. */\n halfWidth = 0;\n /** 0..1: how far the folds are free to vibrate (1 - a glottal stop's closure). */\n drive = 1;\n\n /* ---- Outputs. ---- */\n /** Onset and offset pressures for the current half-width, dyn/cm^2. */\n onset = THRESHOLD_FLOOR;\n offset = OFFSET_RATIO * THRESHOLD_FLOOR;\n /** Whether the folds oscillate (hysteretic), 0 or 1. */\n on = 0;\n /** The oscillation's level, 0..1. */\n level = 0;\n\n private readonly cOn: number = 0;\n private readonly cOff: number = 0;\n\n /** dt: the interval between step() calls, s. */\n constructor(dt: number) {\n this.cOn = 1 - Math.exp(-dt / ONSET_TAU);\n this.cOff = 1 - Math.exp(-dt / OFFSET_TAU);\n }\n\n reset(): void {\n this.on = 0;\n this.level = 0;\n this.onset = THRESHOLD_FLOOR;\n this.offset = OFFSET_RATIO * THRESHOLD_FLOOR;\n }\n\n step(): void {\n const xi = this.halfWidth > 0 ? this.halfWidth : 0;\n const onset = THRESHOLD_FLOOR + THRESHOLD_SLOPE * xi;\n this.onset = onset;\n this.offset = OFFSET_RATIO * onset;\n const p = this.pressure;\n if (this.on === 0) {\n if (p > onset) this.on = 1;\n } else if (p < this.offset) this.on = 0;\n let d = this.drive;\n d = d < 0 ? 0 : d > 1 ? 1 : d;\n const target = this.on * d;\n const c = target > this.level ? this.cOn : this.cOff;\n this.level += c * (target - this.level);\n }\n}\n", "/*\n * The junction airway: a waveguide from the lungs to the lips and nostrils\n * that carries the air itself, not only its sound. Pressure builds behind a\n * closure until voicing stops, a release bursts, a voiced closure's voice\n * bar fades, and aspiration takes the tract's resonances, all from the flow.\n * Nothing is injected by rule.\n *\n * THE IDEA. Every section is c / (2 rate) long, so a wave crosses it in\n * half a sample: the Yee scheme at Courant number 1, where it is exact for\n * a lossless tube, and the scheme CHIMERA (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49) runs at\n * Courant 0.93 on an airway oversampled to 96 kHz. All the flow physics\n * lives in the junctions between sections. With power-normalized waves R\n * (toward the lips) and L (toward the lungs), a junction between impedances\n * Z1 = rho c / A1 and Z2 solves its volume flow U from\n *\n * k(U) |U| U + (Z1 + Z2 + Rv) U = 2 (p1+ - p2-) + pn\n *\n * in closed form, where k is the Borda-Carnot kinetic loss of a jet leaving\n * the narrower side (direction dependent, with a 0.1 contraction loss), Rv\n * the viscous resistance and pn a turbulence source in series. The waves\n * leave as p1- = p1+ - Z1 U and p2+ = p2- + Z2 U. Every even junction also\n * carries a yielding wall (mass, resistance and stiffness per unit area,\n * solved implicitly as a Thevenin conductance) and the anatomical flow\n * -dV/dt of moving tissue. So the mean flow runs end to end: lung pressure,\n * trachea, glottis (a junction whose area is the fold pulse), the grid,\n * the velum (a three-way node into the nasal tube) and the Flanagan R || L\n * radiation loads at the lips and nostrils, which pass DC.\n *\n * TURBULENCE. Stevens' law and Birkholz's placement (Stevens, Acoustic\n * Phonetics, 1998, pp. 103-104; Birkholz, \"Enhanced area functions for noise\n * source modeling in the vocal tract\", ISSP 2014). Each block the grid is\n * searched for constrictions: the narrowest section under 1 k^2 cm^2 and its\n * contiguous neighbours within 0.2 k^2 cm^2 of it, then up to two more runs\n * not joined to it by sections under 1 k^2 cm^2 (a second lingual\n * constriction, so the source does not jump in /su/, and a labial one). No\n * constriction, no jet: a wide tract keeps only the glottal source, so /h/ is\n * aspiration shaped by its vowel. A constriction's source pressure is\n *\n * p_s = G |v_c|^3 sqrt(A_min)\n *\n * with v_c the velocity through its narrowest section low-passed at 500 Hz,\n * in series at the junctions where it lands, its sign the flow's. Where it\n * lands depends on D, the distance from the flow separation point (the run's\n * anterior end) to the incisors: a wall source 0.25 k cm downstream when D is\n * over 2 k cm, an obstacle source at the incisors when it is under, blended\n * over 2 to 3 k cm (Birkholz's own proposal; his table lists /s z \u0283 \u0292/ as\n * obstacle sources, and this geometry's /\u0283/ separates 1.9 to 2.2 cm behind\n * the incisors), and a labiodental source 0.15 k cm downstream where the\n * lower lip forms the constriction at the incisors (/f v/), blended over D\n * from 0.5 k cm to 0. A jet that separates at or past the incisors' edge\n * (the dental /\u03B8/) has no obstacle ahead: as D falls from 0.3 k cm to 0 the\n * obstacle source gives way to a free-jet source at the wall source's place.\n * A place inside a section is split between its two\n * junctions linearly, and a source that moves or changes type ramps every\n * junction weight over one block. The noise is white through one first-order\n * low-pass at fc = 0.15 v_c / d, d = sqrt(4 A / pi), for every source:\n * Birkholz flattens the labiodental and glottal ones (a 6 kHz corner), but in\n * this airway that made /f/ rise 17 dB from 1 to 12 kHz against the human\n * recording's flat spectrum and /h/ bright (MEASURED: shape distance to the\n * human 11.5 and 18.0 dB, against 5.8 and 15.4 with Stevens' corner). Every\n * constriction source but the obstacle's share also falls through a second\n * pole at 3.5 kHz (Shadle 1991: the obstacle is the broadband source), and a\n * constriction makes noise only above the critical Reynolds number, faded in\n * over Re 1000 to 2000, so a closure's last leak is quiet. The\n * glottal (aspiration) source sits 1.5 k cm above the glottis, read from the\n * glottal flow and area; a velic source in the velum port, read from its flow\n * and area, gives the burst of a velic release (/pm/, as VocalTractLab 2.4\n * adds). In voicing, frication pulses at f0 behind a convective delay,\n * tau = D / (0.5 v_jet), with its modulation index soft-limited near 0.5\n * (Jackson and Shadle 2000; Pincas and Jackson 2005). A section at the closed\n * area makes no noise: its leak is the area floor's, not a jet; and a closing\n * seal's source reads the area the articulators command where the area rate\n * law still holds the airway's open, so a seal is not a fricative. The gains are\n * CALIBRATED here against the human recordings and CHIMERA's levels (Birkholz\n * fitted his to his own tract: wall 5, obstacle 10, labiodental 3, aspiration\n * 0.005 to 0.5).\n *\n * COST. The trachea and nasal tube are fixed, so they are delay lines\n * between a few lumped nodes (dsp/airway-tube.ts). On the grid only the\n * sections that move by more than 0.3 percent in a block are recomputed per\n * sample (sqrt(Z) from an area ramped linearly, so an opening is spread\n * over the block), a junction's kinetic root uses its series expansion when\n * the kinetic term is small, and odd and even junctions run in separate\n * loops. MEASURED in the prototype: 0.65 to 0.87 us a sample at 48 kHz\n * against 3.1 to 4.8 for one junction per section.\n *\n * NO ALLOCATION, NO BOXING. Inputs are fields the voice writes before\n * beginBlock(); render() takes indices and buffers only. Nothing per sample\n * calls a method with a double argument or result (V8 boxes doubles that\n * cross a call it did not inline). The noise is a mulberry32 generator held\n * here as an integer, seeded from the 'noise' fork at every reset(), so\n * a stream label still reproduces every sample.\n *\n * The constants are CHIMERA's unless marked; THIRD_PARTY_NOTICES.md lists\n * each with its file and line. MEASURED and CALIBRATED values are this\n * airway's, from its prototype (docs/VOICE-2.md, \"The junction airway\").\n */\n\nimport type { NamedRng } from 'bellowsjs';\nimport { AIR_DENSITY, AIR_DYNAMIC_VISCOSITY, CM_H2O, SOUND_SPEED, WALL_CHEEK_RELAXED, WALL_NASAL, WALL_TRACHEA, WALL_TRACT } from './air';\nimport { AirwayTube, TUBE_RING, evenNodes } from './airway-tube';\nimport { piriformBranch, sinusBranch } from './side-branch';\nimport { AreaSlew } from './area-rate';\nimport { GlottalSource } from './glottal';\nimport { GEO_AMPLITUDE, GeometricGlottis } from './geometric-glottis';\nimport { FoldOscillator, VOICED_GAP } from './fold-oscillator';\nimport { PhonationThreshold } from './phonation-threshold';\n\n/** The fold models: kinematic two-edge, self-oscillating two-mass, the parametric pulse (the default). */\nexport const GLOTTIS_GEOMETRIC = 0;\nexport const GLOTTIS_SELF_OSCILLATING = 1;\nexport const GLOTTIS_PULSE = 2;\n\nconst RHO = AIR_DENSITY;\nconst RHOC = AIR_DENSITY * SOUND_SPEED;\nconst IRHOC = 1 / RHOC;\nconst SRHOC = Math.sqrt(RHOC);\n/** CHIMERA's viscous resistance at 700 Hz (network.rs:866). */\nconst VISC = Math.sqrt((RHO * AIR_DYNAMIC_VISCOSITY * 2 * Math.PI * 700) / 2);\n/** Under this area a section is shut (network.rs:417). */\nconst CLOSED = 2e-4;\n/*\n * The least area any section takes, 1e-4 cm^2 (under the closed area, so a\n * sealed section still seals: its leak at full lung pressure is about\n * 0.4 cm^3/s), written as a literal wherever it is used: a module-level\n * constant in a conditional made V8 box every double that merged with it\n * (MEASURED: 1.9 KB a block). At 1e-6 the first sample of a release changed\n * the sealed section's impedance 85-fold and stepped the pressure stored in\n * its power-normalized waves: a step larger than the burst's peak (MEASURED:\n * 1.05 to 1.5 of it at the twinkle /k/, CHIMERA's 0.57).\n */\n/** CHIMERA's output gain on the radiated flow derivative (human_voice.rs:220). */\nconst OUTPUT_GAIN = 5.5e-7;\n/** A kinetic root takes its series expansion when 4 k |c| / bq^2 is under this (error under 1e-7). MEASURED. */\nconst LIN_EPS = 2e-3;\n/** A grid section moving by less than this fraction in a block steps once per block (42 to 57 dB SNR against per sample). MEASURED. */\nconst MOVE_REL = 0.003;\n/*\n * Turbulence sources: three constriction slots, the glottis, the velum port. Each writes into at\n * most TAPS junctions (its places this block and the ones it fades out of); its velocity passes\n * through a ring of MOD_RING samples for the convective delay (4 ms at 96 kHz fits).\n */\nconst NSRC = 5;\nconst SRC_ASP = 3;\nconst SRC_VEL = 4;\nconst TAPS = 16;\nconst MOD_RING = 512;\n/**\n * Source gains by type, CALIBRATED from Birkholz's (ISSP 2014, Table 1: wall 5, obstacle 10,\n * labiodental 3). Wall 1.4 times his: at 10 and 5, the voiced /z/'s frication lay under its voicing\n * in the female and child bodies (shape distance to the human 25.4 and 26.0 dB; at 14 and 7, 12.6 and\n * 12.6). The obstacle 18, chosen on the mean of five noise seeds: the child's /z/ sits at a threshold\n * where its frication either clears its voicing or does not, and the seed decides which. Its shape\n * distance to the human, mean [range] over the seeds: at 14, 26.1 [26.0..26.3]; at 15, 23.5 [12.8..26.3]\n * (frication on one seed of five); at 17, 18.0 [12.6..26.3]; at 18, 12.6 [12.4..12.9] (this airway's\n * predecessor, before the noise round, 12.4 [12.2..12.7]). The child's mean over the fricatives goes 12.16 to 10.81\n * from 15 to 18, the male's 10.23 to 10.18, the female's 10.96 to 10.89; the cost is DTW distance to\n * CHIMERA on the strengths line, female and child, 0.06 and 0.07 dB (docs/VOICE-2.md, \"Fixes after\n * verification\"). Lowering the Reynolds window's floor did not move the threshold (over Re 500 to 2000\n * and 0 to 2000, the same 23.5). The labiodental one: at his 3, /f/\n * lay 37 dB under its vowel (CHIMERA 18, the earlier library 25); at 25, with the second pole below, 27.\n */\nconst G_WALL = 7;\nconst G_OBSTACLE = 18;\nconst G_LABIAL = 25;\n/** A constriction at the lips that is not labiodental (rounding): Birkholz's labiodental gain, unfitted. */\nconst G_LIPS = 3;\n/**\n * A jet that separates at or past the incisors' edge has no obstacle ahead of it (the dental /\u03B8/):\n * the obstacle source fades out as D falls from D_FREE x k cm to 0, and a free-jet source at the\n * wall source's place, gain G_FREE, takes its share. CALIBRATED: /\u03B8/ at the incisors' obstacle read\n * 12.8 dB from the human shape, 9.0 as a free jet with the second pole (docs/VOICE-2.md).\n */\nconst D_FREE = 0.3;\nconst G_FREE = 6;\n/**\n * The common scale of p_s = G |v|^3 sqrt(A) at 48 kHz (dyn/cm^2 per (cm/s)^3 cm), times\n * sqrt(rate / 48000) elsewhere so the noise's spectral density does not change with the rate.\n * CALIBRATED with the six-stage articulators and the aspiration gains below: DTW distance to\n * CHIMERA over the comparison phrases (docs/VOICE-2.md, \"Integration 4\").\n */\nconst GAIN_SCALE = 3e-9;\n/**\n * The aspiration source's G, open (no voicing) and in modal voicing; Birkholz's is variable.\n * CALIBRATED: the open value on the breaths between vowels and on /h/ (at 20 the vowels line sat\n * 0.3 dB further from CHIMERA, and with the second pole /\u03B8/ no longer needs it), the voiced one on\n * the vowels' breath noise against CHIMERA, scaled by k^ASPIRATION_VOICED_K: the male line needs 3\n * (at 1 it read 1.1 dB further from CHIMERA), the child's about 1 (at 3, 0.24 dB further).\n */\nconst G_ASPIRATION = 10;\nconst G_ASPIRATION_VOICED = 3;\nconst ASPIRATION_VOICED_K = 3.5;\n/**\n * A jet is turbulent only above a critical Reynolds number (Flanagan; CHIMERA takes 1800): a\n * constriction's source fades in over Re 1000 to 2000, Re = v d / nu, d = 2 sqrt(A / pi). MEASURED: a\n * /t\u0283/ closure leaking 0.003 cm^2 at 2400 cm/s (Re 1000) carried frication 9 dB under the /s/ for\n * 10 ms; over Re 1800 to 3000 the female /z/ (Re about 2400) fell under its voicing (25.3 dB from the\n * human shape, against 12.7 over 1000 to 2000).\n */\nconst RE_PER_VSA = (2 / Math.sqrt(Math.PI)) * (AIR_DENSITY / AIR_DYNAMIC_VISCOSITY);\nconst RE_LO = 1000;\nconst RE_SPAN = 1 / 1000;\n/** v_c's low-pass, Hz (Birkholz 2014). */\nconst VC_HZ = 500;\n/** The slow velocity the voicing modulation is measured against, Hz: under any sung f0. */\nconst VSLOW_HZ = 25;\n/** The source corner, fc = 0.15 v / d (Stevens 1998, p. 104). */\nconst FC_LINGUAL = 0.15;\n/**\n * A second pole at this frequency for every constriction source except the obstacle's share (Shadle\n * 1991: a jet hitting an obstacle is the broadband source; a free jet, a wall or the lower lip falls\n * faster). CALIBRATED against the human recordings: /f/ 6.1 to 2.9 dB from the human shape, /\u03B8/\n * 12.2 to 9.0, Jongman spectral mean error 1.46 to 0.81 kHz; at 2500 Hz /f/ went dull (6.6).\n */\nconst P2_HZ = 3500;\n/** Constriction detection, x k^2 cm^2: under this, and the run's tolerance (Birkholz 2014). */\nconst CONSTRICTED = 1.0;\nconst RUN_TOL = 0.2;\n/** Separation-to-incisor distances, x k cm: wall/obstacle blend, labiodental blend. */\nconst D_WALL_LO = 2.0;\nconst D_WALL_HI = 3.0;\nconst D_LABIAL = 0.5;\n/** Source places, x k cm downstream of separation (wall, labiodental) or above the glottis. */\nconst WALL_DOWN = 0.25;\nconst LABIAL_DOWN = 0.15;\nconst ASPIRATION_AT = 1.5;\n/** The convective delay's speed as a fraction of the jet's, and its cap, s (Jackson and Shadle 2000). */\nconst CONVECT = 0.5;\nconst TAU_MAX = 0.004;\n/** The modulation index's soft limit (Jackson and Shadle 2000: about 0.5 at most). */\nconst MOD_MAX = 0.5;\n/** The glottal port: depth 0.3 k, slit 1.4 k, kinetic entrance 0.37 (human_airway.rs:102). */\nconst GLOTTIS_DEPTH = 0.3;\nconst GLOTTIS_SLIT = 1.4;\nconst GLOTTIS_KIN = 0.37;\n/** The velum port: length 1.0 k, kinetic 0.3 in, 0.8 out (human_airway.rs:110-118). */\nconst VELUM_LEN = 1.0;\nconst VELUM_KIN = 0.3;\nconst VELUM_EXIT = 0.8;\n/** Output high-pass (DC) and low-pass corners, Hz; the low-pass stands in for CHIMERA's decimator. MEASURED. */\nconst OUTPUT_HP = 25;\n/**\n * The close microphone's distance from the lips at `mic` 1, cm. A pressure-gradient (directional)\n * microphone answers the air's particle velocity, which near a small source carries a term in the\n * flow itself on top of the far field's flow derivative: for a monopole, u = p (1 + 1 / (j k r)) / (rho c),\n * so a cardioid (half pressure, half gradient) at r hears dU/dt + (c / 2r) U. Below c / (4 pi r),\n * 1.4 kHz at 2 cm, the flow term rises over the far field: the proximity effect, and the puff of a\n * plosive on the diaphragm, which is what makes a beatboxed kick thump on a microphone.\n */\nconst MIC_R = 2;\n/** The microphone's low cut on its flow term, Hz: a slow tongue or jaw pushing air out is not a thump. */\nconst MIC_LOW_CUT = 70;\n\nconst OUTPUT_LP = 18000;\n/** The moving-wall flow is smoothed by CHIMERA's 60 Hz two-pole (network.rs:360). */\nconst DVDT_HZ = 60;\n/** Lumped interior nodes of the trachea and of the nasal tube. MEASURED. */\nconst TRACHEA_NODES = 4;\nconst NASAL_NODES = 6;\n/** The back duct's shortest length, cm: the Lagrange read stays causal. */\nexport const DUCT_MIN = 1.25;\n/**\n * Fraction of a wall's volume velocity radiated through the skin. Birkholz and Zhang (2025) radiate\n * the whole wall flow through the mouth's radiation characteristic; CHIMERA 0.25 (human_airway.rs:86-87).\n * CALIBRATED on the voice bar (docs/VOICE-2.md).\n */\nconst WALL_RADIATION = 0.25;\n\n/** The shortest back duct at a rate, cm: max(DUCT_MIN, 3.2 dx), so a Lagrange read is causal. */\nexport function ductMin(rate: number): number {\n const dx = SOUND_SPEED / (2 * rate);\n return DUCT_MIN > 3.2 * dx ? DUCT_MIN : 3.2 * dx;\n}\n\n/** The share of the pressure under the folds that backs up above them before the pitch servo lets go, and over how much it does. */\nconst BACK_FREE = 0.1;\nconst BACK_SPAN = 0.2;\n/** The opening (over k^2, cm^2) past which the pitch servo lets go, and over how much it does. */\nconst OPEN_FREE = 0.03;\nconst OPEN_SPAN = 0.05;\n\n/** GlottalSource's area block, called through Reflect.apply so V8 never inlines it into beginBlock(). */\nconst AREA_BLOCK = GlottalSource.prototype.processArea;\n\nexport class JunctionAirway {\n readonly rate: number = 0;\n readonly block: number = 0;\n readonly dx: number = 0;\n /** Grid capacity; nG sections are in use. */\n readonly nMax: number = 0;\n nG = 0;\n /** Velum junction (grid index). */\n jv = 2;\n private k = 1;\n private readonly T: number = 0;\n\n /* ---- Inputs, written by the caller before each beginBlock(). ---- */\n /** Grid areas (cm^2), back duct end to lips, nG used. */\n readonly gridIn: Float64Array;\n /** Smallest area inside each grid section (CHIMERA's sub-section minima), cm^2. */\n readonly gridMin: Float64Array;\n /** Anatomical -dV/dt per grid junction, cm^3/s (0 .. nG). */\n readonly vflow: Float64Array;\n /** Back duct length (cm) and area (cm^2). */\n ductLen = 2;\n ductArea = 3;\n /** Velum port area, cm^2. */\n velum = 0;\n /** Lung pressure, dyn/cm^2. */\n pLung = 0;\n /** How close a directional microphone is, 0 (the far field) to 1 (a cardioid MIC_R from the lips). */\n mic = 0;\n /** How slack the cheeks are, 0 (the tract's walls) to 1 (Ishizaka's relaxed cheek). */\n cheeks = 0;\n /** The side branches on or off (a test's counterfactual). */\n branches = true;\n /**\n * The piriform fossae, 0 off or 1 on. Off by default: they lower F1 (MEASURED: General American's\n * vowels from 4.6 to 7.4 percent RMS off Hillenbrand's F1) and the vowel targets were solved without\n * them; re-solving with the branch in the solver's tube is the plan (HOW-IT-WORKS.md, section 11).\n */\n piriform = 0;\n /** The piriform junction in force this block (-1 off). */\n private pJa = -1;\n /* Per-junction wall coefficients (the throat's, the cheeks' past the split). */\n private readonly wCmA: Float64Array;\n private readonly wKsA: Float64Array;\n private readonly wIbsA: Float64Array;\n private wallCheeks = -1;\n private wallSplit = -1;\n /* The piriform branch: its junction, coefficients and state. */\n private pJ = -1;\n private pG = 0;\n private pCm = 0;\n private pK = 0;\n private pDi = 0;\n private pQ = 0;\n private pY = 0;\n private pP = 0;\n /* The microphone flow term's low cut: its state and pole. */\n private micX = 0;\n private micY = 0;\n private readonly micC: number = 0;\n /** The static glottal opening (abduction), cm^2. */\n agStatic = 0.02;\n /** How far the folds are held shut, 0..1 (a glottal stop). */\n closure = 0;\n /** Which fold model makes the glottal area: GLOTTIS_GEOMETRIC, GLOTTIS_SELF_OSCILLATING or GLOTTIS_PULSE. */\n model = GLOTTIS_PULSE;\n /** The part of agStatic that is the posterior chink, cm^2 (the fold models; the pulse uses agStatic whole). */\n chink = 0.01;\n /** Fold length at rest, cm (the fold models). */\n foldLength = 1.6;\n /** Geometric glottis: the upper edge's rest displacement over the lower's, cm; its phase lag (cycles), skew, double pulsing. */\n upperRest = 0.03;\n lag = 70 / 360;\n skew = 0;\n doublePulse = 0.05;\n /** Geometric glottis: the amplitude factor x_rel (under 1: stiffened folds). */\n xRel = 1;\n /** Added to both edges' rest displacement, cm: negative presses the folds together (the fold models). */\n restOffset = 0;\n /** The fold pulse's rate, Hz. */\n f0 = 110;\n /** Incisors and the pharynx/oral split, fractional grid positions (junction units). */\n teethX = 30;\n /** How far the lower lip forms a constriction at the incisors (0..1): labiodental, not lingual, noise. */\n labial = 0;\n splitI = 20;\n /** Output gain applied with the envelope. */\n gain = 1;\n\n /* ---- Outputs. ---- */\n voicing = 0;\n /** Pressure across the folds, dyn/cm^2, and its 30 Hz smoothing; the pressure below them, smoothed. */\n dpGlottis = 0;\n /** The transglottal pressure the fold models see: block means through a 30 Hz one-pole, dyn/cm^2. */\n pTrans = 0;\n /** The pressure above the folds, the same way, dyn/cm^2. */\n pSupra = 0;\n private dpAcc = 0;\n private paAcc = 0;\n dpSmooth = 0;\n pSubSmooth = 0;\n private pSub = 0;\n uLips = 0;\n uNose = 0;\n readonly glottis: GlottalSource;\n readonly geometric = new GeometricGlottis();\n readonly folds: FoldOscillator;\n readonly threshold: PhonationThreshold;\n /*\n * The turbulence sources over the last block, for measurement (index: constriction slots 0..2, the\n * glottis 3, the velum port 4): the mean of |v_c|^3 sqrt(A) times the closed-area fade (p_s / G\n * before the noise), the mean |v_c| (cm/s), the area read (cm^2), the summed junction weight G and\n * the weighted mean place (junction units; -1 when silent).\n */\n readonly noiseLevel = new Float64Array(NSRC);\n readonly noiseVelocity = new Float64Array(NSRC);\n readonly noiseArea = new Float64Array(NSRC);\n readonly noiseGain = new Float64Array(NSRC);\n readonly noisePlace = new Float64Array(NSRC).fill(-1);\n\n /* ---- Grid sections. ---- */\n private readonly R: Float64Array;\n private readonly L: Float64Array;\n private readonly sZ: Float64Array;\n private readonly isZ: Float64Array;\n private readonly Zs: Float64Array;\n private readonly area: Float64Array;\n private readonly dArea: Float64Array;\n private readonly aMin: Float64Array;\n private readonly dAMin: Float64Array;\n private readonly iaMin: Float64Array;\n private readonly viscC: Float64Array;\n private readonly perimF: Float64Array;\n /** A wall's surface per sqrt(area) on each section: walls lumped onto even junctions at double surface. */\n private readonly wallK: Float64Array;\n private readonly moving: Int32Array;\n private nMoving = 0;\n private readonly tgt: Float64Array;\n private readonly tgtMin: Float64Array;\n private readonly slew = new AreaSlew();\n\n /* ---- Grid junctions 0 .. nG. ---- */\n private readonly kf: Float64Array;\n private readonly kb: Float64Array;\n private readonly rv: Float64Array;\n private readonly U: Float64Array;\n private readonly pn: Float64Array;\n private readonly wS: Float64Array;\n private readonly gw: Float64Array;\n private readonly wV: Float64Array;\n private readonly wY: Float64Array;\n private readonly jmList: Int32Array;\n private nJm = 0;\n private readonly gamA: Float64Array;\n private readonly ibA: Float64Array;\n private readonly bqA: Float64Array;\n private readonly dv1: Float64Array;\n private readonly dv2: Float64Array;\n private readonly dvRaw: Float64Array;\n private readonly dvCoef: number = 0;\n private readonly wCm: number = 0;\n private readonly wKs: number = 0;\n private readonly wIbs: number = 0;\n\n /* ---- Fixed tubes. ---- */\n private readonly tr: AirwayTube;\n private readonly na: AirwayTube;\n private readonly secScratch: Float64Array;\n private readonly nodeScratch = new Int32Array(16);\n\n /* ---- Back duct (a fractional delay, Lagrange 3). ---- */\n private readonly fBuf = new Float64Array(TUBE_RING);\n private readonly bBuf = new Float64Array(TUBE_RING);\n private pos = 0;\n private ductTau = 2;\n private dTau = 0;\n private ductSZ = 1;\n private dDuctSZ = 0;\n private ductA = 1;\n\n /* ---- Glottis. ---- */\n private readonly areaBuf: Float64Array;\n private readonly areaArgs: [Float64Array, number, number];\n private agSt = 0.02;\n private agSt0 = 0.02;\n private aVib = 0;\n private aVib0 = 0;\n private uG = 0;\n private momG = 0;\n private lG = 0;\n private ag = 1e-4;\n private agAcc = 0;\n private agMean = 0.05;\n private agLast = 0;\n private pL = 0;\n private pL0 = 0;\n private visc0 = 0;\n private ldG = 0;\n\n /* ---- Velum. ---- */\n private vel = 0;\n private vel0 = 0;\n private velNow = 0;\n private uV = 0;\n private momV = 0;\n private lV = 0;\n private velLen = 1;\n\n /* ---- Radiation and output. ---- */\n private ulLips = 0;\n private lrLips = 0;\n private ulNose = 0;\n private pLipsOld = 0;\n private pNoseOld = 0;\n private radPrev = 0;\n private wallRadAcc = 0;\n private hpX = 0;\n private hpY = 0;\n private readonly hpC: number = 0;\n /* The output low-pass, a second-order Butterworth (b0, b1 = 2 b0, b2 = b0; a1, a2). */\n private readonly lb0: number = 0;\n private readonly lb1: number = 0;\n private readonly la1: number = 0;\n private readonly la2: number = 0;\n private lx1 = 0;\n private lx2 = 0;\n private ly1 = 0;\n private ly2 = 0;\n /** Per-sample ramp position within the block, (n + 1) / count. */\n private w = 0;\n /** The fold rate handed to the glottis, [0]: setFreqFrom reads it, so no double crosses the call. */\n private readonly f0Buf = new Float64Array(1);\n\n /* ---- Turbulence: slots 0..2 constrictions, SRC_ASP the glottis, SRC_VEL the velum port. ---- */\n /** Each constriction slot's separation junction last block (-1: free), its flow junction and narrowest section. */\n private readonly srcExit = new Int32Array(NSRC).fill(-1);\n private readonly srcUJ = new Int32Array(NSRC);\n private readonly srcSec = new Int32Array(NSRC);\n /**\n * Each constriction slot's commanded area, the least of the run's sections before the area rate law, at the\n * block's start and end, cm^2: the source reads it where it is under the airway's (a closing seal).\n */\n private readonly srcCmd0 = new Float64Array(NSRC);\n private readonly srcCmd1 = new Float64Array(NSRC);\n /** Junction taps per source: junction, weight at the block's start and end (G folded in). */\n private readonly nTap = new Int32Array(NSRC);\n private readonly tapJ = new Int32Array(NSRC * TAPS);\n private readonly tapW0 = new Float64Array(NSRC * TAPS);\n private readonly tapW1 = new Float64Array(NSRC * TAPS);\n /** The velic source's weight, ramped. */\n private velW0 = 0;\n private velW1 = 0;\n private pnV = 0;\n /** Per source: v_c low-passed, the slow mean of its delayed cube, the area low-passed, the noise low-pass state and coefficient. */\n private readonly vF = new Float64Array(NSRC);\n private readonly vS = new Float64Array(NSRC);\n private readonly aF = new Float64Array(NSRC);\n private readonly nL = new Float64Array(NSRC);\n private readonly nL2 = new Float64Array(NSRC);\n private readonly cLp2 = new Float64Array(NSRC).fill(1);\n private readonly cLp = new Float64Array(NSRC);\n /** Block sums of |v_c| and of |v_c|^3 sqrt(A), and the convective delay in samples at the block's start and end. */\n private readonly vAcc = new Float64Array(NSRC);\n private readonly lvAcc = new Float64Array(NSRC);\n private readonly tau0 = new Float64Array(NSRC);\n private readonly tau1 = new Float64Array(NSRC);\n /** Whether a slot modulates with voicing (1) or reads its velocity undelayed and unlimited (0). */\n private readonly modOn = new Float64Array(NSRC);\n private readonly ring = new Float64Array(NSRC * MOD_RING);\n private ringPos = 0;\n /** A place being added (fractional junction), its weight and its share at one junction: fields, so no double crosses a call. */\n private tx = 0;\n private tw = 0;\n private tShare = 0;\n /** The fastest jet the lungs can drive this block, cm/s (Bernoulli, with a margin). */\n private vMax = 0;\n /** Scratch for the detection: runs (lo, hi, narrowest section) and per-slot assignment. */\n private readonly runLo = new Int32Array(3);\n private readonly runHi = new Int32Array(3);\n private readonly runMin = new Int32Array(3);\n private readonly conLo = new Int32Array(3);\n private readonly conHi = new Int32Array(3);\n private readonly runSlot = new Int32Array(3);\n private readonly cVc: number = 0;\n private readonly cVs: number = 0;\n private readonly noiseScale: number = 0;\n private readonly rng: NamedRng;\n /** mulberry32 state, an int32. */\n private seed = 1;\n /** Block counter in the current note; 0 means the next block is the first. */\n private blocks = 0;\n\n /**\n * rate in Hz; nMax: the most grid sections any configure() will use;\n * rng: forks 'noise' (the turbulence seed per reset) and 'glottis'.\n */\n constructor(rate: number, nMax: number, rng: NamedRng) {\n this.rate = rate;\n this.T = 1 / rate;\n this.block = Math.max(8, Math.round((32 * rate) / 48000));\n this.dx = SOUND_SPEED / (2 * rate);\n this.nMax = nMax;\n this.rng = rng.fork('noise');\n const n = nMax;\n const nj = n + 1;\n this.gridIn = new Float64Array(n).fill(3);\n this.gridMin = new Float64Array(n).fill(3);\n this.vflow = new Float64Array(nj);\n this.R = new Float64Array(n);\n this.L = new Float64Array(n);\n this.sZ = new Float64Array(n);\n this.isZ = new Float64Array(n);\n this.Zs = new Float64Array(n);\n this.area = new Float64Array(n);\n this.dArea = new Float64Array(n);\n this.aMin = new Float64Array(n);\n this.dAMin = new Float64Array(n);\n this.iaMin = new Float64Array(n);\n this.viscC = new Float64Array(n);\n this.perimF = new Float64Array(n);\n this.wallK = new Float64Array(n);\n this.moving = new Int32Array(n);\n this.tgt = new Float64Array(n);\n this.tgtMin = new Float64Array(n);\n this.kf = new Float64Array(nj);\n this.kb = new Float64Array(nj);\n this.rv = new Float64Array(nj);\n this.U = new Float64Array(nj);\n this.pn = new Float64Array(nj);\n this.wS = new Float64Array(nj);\n this.gw = new Float64Array(nj);\n this.wCmA = new Float64Array(nj);\n this.wKsA = new Float64Array(nj);\n this.wIbsA = new Float64Array(nj);\n this.wV = new Float64Array(nj);\n this.wY = new Float64Array(nj);\n this.jmList = new Int32Array(nj);\n this.gamA = new Float64Array(nj).fill(1);\n this.ibA = new Float64Array(nj);\n this.bqA = new Float64Array(nj);\n this.dv1 = new Float64Array(nj);\n this.dv2 = new Float64Array(nj);\n this.dvRaw = new Float64Array(nj);\n this.dvCoef = 1 - Math.exp((-2 * Math.PI * DVDT_HZ) / rate);\n this.wCm = WALL_TRACT.m * rate - 0.5 * WALL_TRACT.r;\n this.wKs = WALL_TRACT.k;\n this.wIbs = 1 / (WALL_TRACT.m * rate + 0.5 * WALL_TRACT.r);\n this.tr = new AirwayTube(TRACHEA_NODES + 2);\n this.na = new AirwayTube(NASAL_NODES + 5);\n // the longest fixed tube (the male trachea, 12 cm) in sections, with room\n this.secScratch = new Float64Array(Math.ceil((14 * 1.2) / this.dx) + 4);\n this.glottis = new GlottalSource(rate, rng.fork('glottis'));\n this.folds = new FoldOscillator(rate);\n this.threshold = new PhonationThreshold(this.block / rate);\n this.areaBuf = new Float64Array(this.block);\n this.areaArgs = [this.areaBuf, 0, this.block];\n this.hpC = Math.exp((-2 * Math.PI * OUTPUT_HP) / rate);\n this.micC = Math.exp((-2 * Math.PI * MIC_LOW_CUT) / rate);\n const fc = Math.min(OUTPUT_LP, 0.45 * rate);\n const K = Math.tan((Math.PI * fc) / rate);\n const q = Math.SQRT1_2;\n const norm = 1 / (1 + K / q + K * K);\n this.lb0 = K * K * norm;\n this.lb1 = 2 * this.lb0;\n this.la1 = 2 * (K * K - 1) * norm;\n this.la2 = (1 - K / q + K * K) * norm;\n this.noiseScale = GAIN_SCALE * Math.sqrt(rate / 48000);\n this.cVc = 1 - Math.exp((-2 * Math.PI * VC_HZ) / rate);\n this.cVs = 1 - Math.exp((-2 * Math.PI * VSLOW_HZ) / rate);\n this.configure(1, Math.min(n, 30), 12);\n }\n\n /**\n * Lay the airway out for a body of scale k with n grid sections (at most\n * nMax) and the velum at junction jv. Allocates nothing; clears all state.\n */\n configure(k: number, n: number, jv: number): void {\n this.k = k;\n const k2 = k * k;\n const dx = this.dx;\n this.nG = n < this.nMax ? n : this.nMax;\n this.jv = jv;\n this.slew.setScale(k);\n this.slew.setStep(this.block / this.rate);\n this.visc0 = 12 * AIR_DYNAMIC_VISCOSITY * GLOTTIS_DEPTH * k * (GLOTTIS_SLIT * k) ** 2;\n this.ldG = RHO * GLOTTIS_DEPTH * k;\n this.velLen = VELUM_LEN * k;\n const sec = this.secScratch;\n const nodes = this.nodeScratch;\n // trachea: 12 k cm of 2.5 k^2 cm^2, an even number of sections\n let nTr = Math.max(6, Math.round((12 * k) / dx));\n if (nTr % 2) nTr++;\n if (nTr > sec.length) nTr = sec.length - (sec.length % 2);\n for (let i = 0; i < nTr; i++) sec[i] = 2.5 * k2;\n let nn = evenNodes(nTr, TRACHEA_NODES, nodes);\n this.tr.configure(sec, nTr, nodes, nn, WALL_TRACHEA, 1, 1, dx, this.rate);\n // nasal tube: 11.4 k cm, CHIMERA's profile (human_airway.rs:95-104)\n let nNa = Math.max(8, Math.round((11.4 * k) / dx));\n if (nNa % 2) nNa++;\n if (nNa > sec.length) nNa = sec.length - (sec.length % 2);\n for (let i = 0; i < nNa; i++) {\n const u = (i + 0.5) / nNa;\n const a = u < 0.18 ? 2.6 : u < 0.75 ? 2.0 - 0.6 * (u - 0.18) : u < 0.9 ? 1.4 : 1.0;\n sec[i] = a * k2;\n }\n nn = 0;\n nodes[nn++] = 0;\n nodes[nn++] = 2 * Math.round((0.18 * nNa) / 2);\n const extra = NASAL_NODES - 3;\n for (let e = 1; e <= extra; e++) nodes[nn++] = 2 * Math.round(((0.18 + ((0.75 - 0.18) * e) / (extra + 1)) * nNa) / 2);\n nodes[nn++] = 2 * Math.round((0.75 * nNa) / 2);\n nodes[nn++] = 2 * Math.round((0.9 * nNa) / 2);\n nodes[nn++] = nNa;\n // sorted already; drop repeats\n let c = 1;\n for (let i = 1; i < nn; i++) if (nodes[i] > nodes[c - 1]) nodes[c++] = nodes[i];\n this.na.configure(sec, nNa, nodes, c, WALL_NASAL, 3.2, 2.5, dx, this.rate);\n if (this.branches) {\n // the maxillary sinuses on the middle nasal node, the piriform fossae at the first even junction\n // above the back duct (dsp/side-branch.ts)\n const sb = sinusBranch(k, this.rate);\n this.na.addResonator(c >> 1, sb[0], sb[1], sb[2]);\n const pc = piriformBranch(k, this.rate);\n this.pJ = 2 < this.nG - 1 && jv !== 2 ? 2 : -1;\n this.pDi = pc[0];\n this.pG = 0.5 * pc[0];\n this.pCm = pc[1];\n this.pK = pc[2];\n } else this.pJ = -1;\n this.wallCheeks = -1;\n for (let i = 0; i < this.nMax; i++) {\n this.perimF[i] = i < jv ? 1.25 : 1.5;\n this.wallK[i] = 2 * this.perimF[i] * 2 * Math.sqrt(Math.PI) * dx;\n this.viscC[i] = (0.25 * VISC * this.perimF[i] * 2 * Math.sqrt(Math.PI) * dx) / Math.pow(RHOC, 1.5);\n }\n this.reset();\n this.updateWalls();\n }\n\n /** Each junction's wall coefficients: the tract's, blended toward relaxed cheeks past the split. */\n private updateWalls(): void {\n const ch = this.cheeks < 0 ? 0 : this.cheeks > 1 ? 1 : this.cheeks;\n const split = Math.ceil(this.splitI);\n if (ch === this.wallCheeks && split === this.wallSplit) return;\n this.wallCheeks = ch;\n this.wallSplit = split;\n const rate = this.rate;\n const n = this.wCmA.length;\n for (let i = 0; i < n; i++) {\n const c = i >= split ? ch : 0;\n const m = WALL_TRACT.m + (WALL_CHEEK_RELAXED.m - WALL_TRACT.m) * c;\n const r = WALL_TRACT.r + (WALL_CHEEK_RELAXED.r - WALL_TRACT.r) * c;\n const kk = WALL_TRACT.k + (WALL_CHEEK_RELAXED.k - WALL_TRACT.k) * c;\n this.wCmA[i] = m * rate - 0.5 * r;\n this.wKsA[i] = kk;\n this.wIbsA[i] = 1 / (m * rate + 0.5 * r);\n }\n }\n\n /** Back to rest: every wave, flow, wall and filter; the turbulence reseeded from its stream. */\n reset(): void {\n const k2 = this.k * this.k;\n this.tr.reset();\n this.na.reset();\n this.glottis.reset();\n this.geometric.reset();\n this.folds.reset();\n this.threshold.reset();\n this.pTrans = this.dpAcc = 0;\n this.pSupra = this.paAcc = 0;\n this.R.fill(0);\n this.L.fill(0);\n this.U.fill(0);\n this.pn.fill(0);\n this.wV.fill(0);\n this.wY.fill(0);\n this.dv1.fill(0);\n this.dv2.fill(0);\n this.dvRaw.fill(0);\n this.area.fill(3 * k2);\n this.aMin.fill(3 * k2);\n this.fBuf.fill(0);\n this.bBuf.fill(0);\n this.pos = 0;\n this.uG = this.momG = this.lG = 0;\n this.uV = this.momV = this.lV = 0;\n this.ulLips = this.lrLips = this.ulNose = 0;\n this.pLipsOld = this.pNoseOld = 0;\n this.radPrev = this.wallRadAcc = 0;\n this.hpX = this.hpY = 0;\n this.lx1 = this.lx2 = this.ly1 = this.ly2 = 0;\n this.voicing = 0;\n this.dpGlottis = this.dpSmooth = 0;\n this.pSub = this.pSubSmooth = 0;\n this.uLips = this.uNose = 0;\n this.micX = this.micY = 0;\n this.pQ = this.pY = this.pP = 0;\n this.aVib = this.aVib0 = 0;\n this.agAcc = 0;\n this.agMean = 0.05;\n this.agLast = 0;\n this.ag = 1e-4;\n this.srcExit.fill(-1);\n this.srcUJ.fill(0);\n this.srcSec.fill(0);\n this.srcCmd0.fill(0);\n this.srcCmd1.fill(0);\n this.nTap.fill(0);\n this.vF.fill(0);\n this.vS.fill(0);\n this.aF.fill(0);\n this.nL.fill(0);\n this.nL2.fill(0);\n this.vAcc.fill(0);\n this.lvAcc.fill(0);\n this.noiseLevel.fill(0);\n this.noiseVelocity.fill(0);\n this.noiseArea.fill(0);\n this.noiseGain.fill(0);\n this.noisePlace.fill(-1);\n this.tau0.fill(0);\n this.tau1.fill(0);\n this.ring.fill(0);\n this.ringPos = 0;\n this.velW0 = this.velW1 = this.pnV = 0;\n this.seed = (this.rng() * 4294967296) | 0 || 1;\n this.blocks = 0;\n }\n\n /** The next block's inputs are in the fields: limit and ramp the shape, place the sources, run the glottal pulse. */\n beginBlock(): void {\n this.updateWalls();\n this.pJa = this.piriform > 0 ? this.pJ : -1;\n const first = this.blocks === 0;\n this.blocks++;\n const blk = this.block;\n const k = this.k;\n const k2 = k * k;\n const nG = this.nG;\n const area = this.area;\n const dArea = this.dArea;\n const grid = this.tgt;\n const gmn = this.tgtMin;\n const dt = blk / this.rate;\n // targets, floored; CHIMERA's area rate law on the grid and the minima (human_airway.rs:190-262)\n for (let s = 0; s < nG; s++) {\n const a = this.gridIn[s];\n grid[s] = a > 1e-4 ? a : 1e-4;\n const m = this.gridMin[s];\n gmn[s] = m > 1e-4 ? m : 1e-4;\n }\n if (!first) {\n this.slew.limitAll(grid, area, nG);\n this.slew.limitAll(gmn, this.aMin, nG);\n }\n for (let s = 0; s < nG; s++) {\n if (grid[s] < 1e-4) grid[s] = 1e-4;\n let m = gmn[s];\n if (m > grid[s]) m = grid[s];\n gmn[s] = m < 1e-4 ? 1e-4 : m;\n }\n // the velum junction sits one section behind the pharynx/oral split, and moves only while the port is shut\n if (this.splitI >= 0) {\n let want = Math.floor(this.splitI - 1);\n want = want < 2 ? 2 : want > nG - 2 ? nG - 2 : want;\n const shut = this.vel <= CLOSED && this.velum <= CLOSED && (this.uV < 1 && this.uV > -1);\n if (first || shut) this.jv = want;\n }\n // section ramps (linear in area) and the moving set\n let nm = 0;\n for (let s = 0; s < nG; s++) {\n const a = grid[s];\n if (first) area[s] = a;\n const d = a - area[s];\n const rel = d < 0 ? -d : d;\n const mt = gmn[s];\n if (first) this.aMin[s] = mt;\n const dm = mt - this.aMin[s];\n const relm = dm < 0 ? -dm : dm;\n // a narrow minimum ramps per sample at any change: its kinetic loss goes as 1 / A^2, so even a\n // 0.3 percent step once a block was a pressure step at every block (MEASURED: block-periodic\n // clicks as a closure released slowly)\n if (rel > MOVE_REL * 0.5 * (a + area[s]) || relm > MOVE_REL * 0.5 * (mt + this.aMin[s]) || (dm !== 0 && mt < 0.5 * k2)) {\n dArea[s] = d / blk;\n this.dAMin[s] = dm / blk;\n this.moving[nm++] = s;\n } else {\n this.dAMin[s] = 0;\n this.aMin[s] = mt;\n this.iaMin[s] = 1 / mt;\n dArea[s] = 0;\n area[s] = a;\n const z = Math.sqrt(RHOC / a);\n this.sZ[s] = z;\n this.isZ[s] = 1 / z;\n this.Zs[s] = z * z;\n }\n }\n this.nMoving = nm;\n // junction elements from the block-end shape; moving junctions recompute per sample\n let njm = 0;\n const dx = this.dx;\n for (let i = 1; i < nG; i++) {\n const sl = i - 1;\n const sr = i;\n const mv = dArea[sl] !== 0 || dArea[sr] !== 0 || this.dAMin[sl] !== 0 || this.dAMin[sr] !== 0;\n if (mv) this.jmList[njm++] = i;\n const al = grid[sl];\n const ar = grid[sr];\n // the jet leaves the upstream section's minimum and expands into the downstream section; a 0.1\n // contraction loss entering a narrower minimum (network.rs:919-930)\n const ef = 1 / gmn[sl] - 1 / ar;\n const eb = 1 / gmn[sr] - 1 / al;\n const cf = 1 / gmn[sr] - 1 / al;\n const cb = 1 / gmn[sl] - 1 / ar;\n this.kf[i] = 0.5 * RHO * ((ef > 0 ? ef * ef : 0) + (cf > 0 ? 0.1 * cf * cf : 0));\n this.kb[i] = 0.5 * RHO * ((eb > 0 ? eb * eb : 0) + (cb > 0 ? 0.1 * cb * cb : 0));\n const zl = RHOC / al;\n const zr = RHOC / ar;\n const r = this.viscC[sl] * zl * Math.sqrt(zl) + this.viscC[sr] * zr * Math.sqrt(zr);\n this.rv[i] = r;\n // walls lumped onto even junctions at double surface (the velum junction too); MEASURED\n const am = 0.5 * (al + ar);\n const sw = (i & 1) === 0 && am > CLOSED ? this.wallK[sl] * Math.sqrt(am - CLOSED) : 0;\n this.wS[i] = sw;\n const gw = sw * this.wIbsA[i] + (i === this.pJa ? this.pG : 0);\n this.gw[i] = gw;\n if (!mv) {\n const gam = 1 / (1 + zl * gw);\n this.gamA[i] = gam;\n const bq = zl * gam + zr + r;\n this.bqA[i] = bq;\n this.ibA[i] = 1 / bq;\n }\n }\n this.nJm = njm;\n // the anatomical moving-wall flow, odd junctions' share on the next even one\n const raw = this.dvRaw;\n raw.fill(0);\n if (!first) {\n for (let j = 0; j <= nG; j++) {\n const to = (j & 1) === 0 ? j : j + 1 <= nG ? j + 1 : j - 1;\n raw[to] += this.vflow[j];\n }\n }\n // weighted by the fade-in as the section opens past 0.02 to 0.12 k^2 (a sealed node takes none);\n // the product is what render() smooths per sample, so the weight's own changes are smoothed too\n // (ramped per block and multiplied by a large flow, its slope changed at every block: MEASURED\n // block-periodic clicks at a velar release)\n for (let i = 0; i <= nG; i++) {\n const a1 = i > 0 ? grid[i - 1] : this.ductArea;\n const a2 = i < nG ? grid[i] : 1;\n let wv = ((a1 > a2 ? a1 : a2) - 0.02 * k2) / (0.1 * k2);\n wv = wv < 0 ? 0 : wv > 1 ? 1 : wv * wv * (3 - 2 * wv);\n raw[i] *= wv;\n }\n // the back duct\n const tau = (this.ductLen * this.rate) / SOUND_SPEED;\n if (first) this.ductTau = tau;\n this.dTau = (tau - this.ductTau) / blk;\n const da = this.ductArea > 1e-6 ? this.ductArea : 1e-6;\n const sz = Math.sqrt(RHOC / da);\n if (first) this.ductSZ = sz;\n this.dDuctSZ = (sz - this.ductSZ) / blk;\n this.ductA = da;\n // slow inputs ramp across the block\n this.vel0 = first ? this.velum : this.vel;\n this.vel = this.velum;\n this.pL0 = first ? this.pLung : this.pL;\n this.pL = this.pLung;\n const closure = this.closure < 0 ? 0 : this.closure > 1 ? 1 : this.closure;\n const st = this.agStatic * (1 - 0.92 * closure);\n this.agSt0 = first ? st : this.agSt;\n this.agSt = st;\n // the voicing gate (glottis.rs:170-176) from this airway's own pressure across the folds\n const c30 = 1 - Math.exp(-2 * Math.PI * 30 * dt);\n this.dpSmooth += c30 * (this.dpGlottis - this.dpSmooth);\n this.pSubSmooth += c30 * (this.pSub - this.pSubSmooth);\n const thr = 2.5 * CM_H2O;\n let pg = (this.dpSmooth - thr * 0.8) / (thr * 0.8);\n pg = pg < 0 ? 0 : pg > 1 ? 1 : pg * pg * (3 - 2 * pg);\n let ag0 = (this.agStatic - 0.0125 * k2 - 0.08) / 0.14;\n ag0 = ag0 < 0 ? 0 : ag0 > 1 ? 1 : ag0 * ag0 * (3 - 2 * ag0);\n const agate = 1 - ag0;\n // the pulse's alone: the fold models report their own (the folds' turning, the geometric threshold),\n // and this gate under the folds' voicing held it near 0.5 wherever the two disagreed (MEASURED: 0.40\n // before the folds' first cycle)\n const model = this.model;\n if (model === GLOTTIS_PULSE) this.voicing += (1 - Math.exp(-2 * Math.PI * 25 * dt)) * (pg * agate * (1 - closure) - this.voicing);\n let effort = (this.pLung / CM_H2O - 3) / 10;\n effort = effort < 0 ? 0 : effort > 1 ? 1 : effort;\n this.aVib0 = this.aVib;\n this.aVib = 0.17 * k2 * (0.45 + 0.75 * effort) * this.voicing;\n if (first) this.aVib0 = this.aVib;\n this.placeSources();\n this.agAcc = 0;\n this.f0Buf[0] = this.f0;\n this.glottis.setFreqFrom(this.f0Buf, 0);\n this.areaArgs[2] = blk;\n // the pressure across the folds: the last block's mean through a 30 Hz one-pole\n const dpMean = first ? 0 : this.dpAcc / blk;\n const paMean = first ? 0 : this.paAcc / blk;\n this.dpAcc = 0;\n this.paAcc = 0;\n this.pTrans += c30 * (dpMean - this.pTrans);\n this.pSupra += c30 * (paMean - this.pSupra);\n if (model === GLOTTIS_GEOMETRIC) this.geometricBlock(closure);\n else if (model === GLOTTIS_SELF_OSCILLATING) this.foldBlock(closure);\n else this.pulseBlock();\n }\n\n /** The parametric pulse into absolute areas: the static opening plus the gated pulse, averaged over two samples. */\n private pulseBlock(): void {\n Reflect.apply(AREA_BLOCK, this.glottis, this.areaArgs);\n const buf = this.areaBuf;\n const blk = this.block;\n const inv = 1 / blk;\n const last = buf[blk - 1];\n // backwards, so each sample still reads its raw predecessor\n for (let n = blk - 1; n >= 0; n--) {\n const w = (n + 1) * inv;\n const st = this.agSt0 + (this.agSt - this.agSt0) * w;\n const av = this.aVib0 + (this.aVib - this.aVib0) * w;\n // the fold pulse, averaged over two samples (a closure's top octave is softer; MEASURED)\n let ag = st + av * 0.5 * (buf[n] + (n > 0 ? buf[n - 1] : this.agLast));\n if (ag < 1e-7) ag = 1e-7;\n buf[n] = ag;\n }\n this.agLast = last;\n }\n\n /** The geometric glottis: rest displacements from the opening, the threshold from the pressure, then the areas. */\n private geometricBlock(closure: number): void {\n const g = this.geometric;\n const L = this.foldLength > 0.1 ? this.foldLength : 0.1;\n const shut = 1 - 0.92 * closure;\n const chink = (this.chink > 0 ? this.chink : 0) * shut;\n const rest = this.agSt - chink;\n const x1 = (rest > 0 ? rest : 0) / L + this.restOffset;\n const x2 = x1 + this.upperRest * shut;\n g.length = L;\n g.chink = chink;\n g.xRest1 = x1;\n g.xRest2 = x2;\n g.lag = this.lag;\n g.skew = this.skew;\n g.doublePulse = this.doublePulse;\n const th = this.threshold;\n th.pressure = this.pTrans;\n th.halfWidth = 0.25 * (x1 + x2);\n th.drive = 1 - closure;\n th.step();\n this.voicing = th.level;\n // the swing as the root of the pressure across the folds (Titze 1989, as the paper models it)\n const p = this.pTrans > 0 ? this.pTrans : 0;\n g.xMax = GEO_AMPLITUDE * this.xRel * Math.sqrt(p) * th.level;\n g.process(this.glottis, this.areaBuf, 0, this.block);\n }\n\n /** The self-oscillating folds: rest, chink, freedom and the servo's target; their perturbation from the cycle unit. */\n private foldBlock(closure: number): void {\n const f = this.folds;\n const L = this.foldLength > 0.1 ? this.foldLength : 0.1;\n const shut = 1 - 0.92 * closure;\n const chink = (this.chink > 0 ? this.chink : 0) * shut;\n const rest = this.agSt - chink;\n let r = (rest > 0 ? rest : 0) / L + this.restOffset;\n r = r > 0 ? r : 0;\n // the block's end values, ramped per step from where the last block left them (the first block of a\n // note starts on them). Restarted each block from values computed afresh, a change of chink, length or\n // press between blocks still stepped the area at the block's edge\n if (this.blocks === 1) {\n f.rest1 = r;\n f.rest2 = r;\n f.chink = chink;\n f.length = L;\n }\n f.rest1To = r;\n f.rest2To = r;\n f.chinkTo = chink;\n f.lengthTo = L;\n f.rampLeft = this.block;\n f.free = 1 - closure;\n // the cycle unit still runs, for its drift and jitter: the servo aims at the drifted pitch, the\n // cycle's period scale perturbs the tension\n this.glottis.processPhase(this.areaBuf, 0, this.block);\n f.servo.target = this.f0 * this.glottis.pitchFactor;\n // the servo learns the tension, not the pressure: with the pressure backing up above the folds (a voiced\n // closure, a narrow constriction) f0 falls for the pressure's sake, and the servo at full weight raised\n // the tension through the dip and sent the release 190 cents sharp (MEASURED, a 60 ms lip closure). The\n // back pressure's share stays under 0.08 in 95 percent of vowel frames in every body and runs 0.2 to\n // 0.97 in closures (MEASURED over twinkle, stops, fric and son)\n // Math.min and Math.max, not conditionals: V8 boxed a double merged with a module-level constant\n const back = this.pSupra / Math.max(this.pSubSmooth, CM_H2O);\n const bc = Math.min(Math.max((back - BACK_FREE) / BACK_SPAN, 0), 1);\n const bk = bc * bc * (3 - 2 * bc);\n // and not while the folds are drawn apart: f0 sags as they open into a voiceless sound, and the servo\n // wound the tension up through that offset and began the next onset 200 to 400 cents sharp (MEASURED, an\n // aspirated stop at 110 to 460 Hz). Voiced vowels hold the opening at 0.0147 k^2 in every body (MEASURED)\n const ac = Math.min(Math.max((this.agSt / (this.k * this.k) - OPEN_FREE) / OPEN_SPAN, 0), 1);\n const ab = ac * ac * (3 - 2 * ac);\n f.servo.weight = (1 - bk) * (1 - ab);\n f.perturb = 1 / this.glottis.scale;\n f.tune();\n // voicing is whether the folds turned within the last 1.6 periods of the target, smoothed as the pulse's\n // gate is (25 Hz). A count of cycles since reset left it at 1 through every voiceless sound after the\n // first cycle: the aspiration kept its quiet voiced gain and its pulsing, and the onset after a\n // voiceless stop rang the tract (MEASURED: a 1.5 kHz tone 15 dB over the pulse's in \"twinkle\", female)\n const per = this.f0 > 20 ? this.rate / this.f0 : this.rate / 20;\n const on = f.sinceTurn < VOICED_GAP * per ? 1 : 0;\n this.voicing += (1 - Math.exp((-2 * Math.PI * 25 * this.block) / this.rate)) * (on - this.voicing);\n }\n\n /**\n * Find the constrictions, give each a slot, and set every source's places, spectrum and delay\n * for the block (Birkholz 2014). Integers only cross this call; the doubles are fields.\n */\n private placeSources(): void {\n // either way: a breath drawn in (a beatbox inward snare) drives its jets as hard as one blown out\n const pl = this.pLung > 0 ? this.pLung : -this.pLung;\n this.vMax = 1.2 * Math.sqrt((2 * pl) / RHO) + 100;\n const k = this.k;\n const k2 = k * k;\n const nG = this.nG;\n const gmn = this.tgtMin;\n const dx = this.dx;\n const rate = this.rate;\n const blk = this.block;\n const tapW0 = this.tapW0;\n const tapW1 = this.tapW1;\n for (let q = 0; q < NSRC; q++) {\n const b = q * TAPS;\n let g = 0;\n let x = 0;\n for (let t = 0; t < this.nTap[q]; t++) {\n g += tapW1[b + t];\n x += tapW1[b + t] * this.tapJ[b + t];\n tapW0[b + t] = tapW1[b + t];\n tapW1[b + t] = 0;\n }\n if (q === SRC_VEL) g = this.velW1;\n this.noiseLevel[q] = this.lvAcc[q] / blk;\n this.noiseVelocity[q] = this.vAcc[q] / blk;\n this.noiseArea[q] = this.aF[q];\n this.noiseGain[q] = g;\n this.noisePlace[q] = q === SRC_VEL ? (g > 0 ? this.jv : -1) : g > 0 ? x / g : -1;\n this.lvAcc[q] = 0;\n }\n // up to three runs apart from each other: the narrowest under 1 k^2 cm^2 and its neighbours within\n // 0.2; a further run must not connect to an earlier one through sections under 1 k^2 cm^2\n const runLo = this.runLo;\n const runHi = this.runHi;\n const conLo = this.conLo;\n const conHi = this.conHi;\n const cut = CONSTRICTED * k2;\n let nr = 0;\n for (let r = 0; r < 3; r++) {\n let mn = CONSTRICTED * k2;\n let mi = -1;\n for (let s = 0; s < nG; s++) {\n const a = gmn[s];\n if (a >= mn) continue;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (free) {\n mn = a;\n mi = s;\n }\n }\n if (mi < 0) break;\n const lim = mn + RUN_TOL * k2;\n let lo = mi;\n let hi = mi;\n for (;;) {\n const s = lo - 1;\n if (s < 0 || gmn[s] >= lim) break;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (!free) break;\n lo = s;\n }\n for (;;) {\n const s = hi + 1;\n if (s >= nG || gmn[s] >= lim) break;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (!free) break;\n hi = s;\n }\n runLo[nr] = lo;\n runHi[nr] = hi;\n this.runMin[nr] = mi;\n while (lo > 0 && gmn[lo - 1] < cut) lo--;\n while (hi < nG - 1 && gmn[hi + 1] < cut) hi++;\n conLo[nr] = lo;\n conHi[nr] = hi;\n nr++;\n }\n // each run keeps the slot whose separation point was nearest (within 3 sections), else a free one\n let used = 0;\n for (let r = 0; r < nr; r++) {\n const exit = runHi[r] + 1;\n let best = -1;\n let bd = 4;\n for (let q = 0; q < 3; q++) {\n if ((used >> q) & 1 || this.srcExit[q] < 0) continue;\n const d = this.srcExit[q] > exit ? this.srcExit[q] - exit : exit - this.srcExit[q];\n if (d < bd) {\n bd = d;\n best = q;\n }\n }\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1) && this.srcExit[q] < 0 && this.nTap[q] === 0) best = q;\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1) && this.srcExit[q] < 0) best = q;\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1)) best = q;\n used |= 1 << best;\n this.runSlot[r] = best;\n }\n for (let q = 0; q < 3; q++) if (!((used >> q) & 1)) this.srcExit[q] = -1;\n for (let r = 0; r < nr; r++) {\n const q = this.runSlot[r];\n const mi = this.runMin[r];\n const exit = runHi[r] + 1;\n const a = gmn[mi];\n const fresh = this.nTap[q] === 0;\n if (fresh) this.freshSource(q, mi);\n this.srcExit[q] = exit;\n // the flow through the narrowest section itself, where the kinetic loss holds it to A sqrt(2 dp / rho); read\n // further on, a sealed section's v = U / A took the flow the cavity in between pumps (MEASURED: frication\n // at a /d/ closure as loud as the /s/)\n this.srcUJ[q] = mi + 1;\n this.srcSec[q] = mi;\n // the area the articulators command, before the rate law holds a closing seal open\n let cmd = 1e9;\n for (let s = conLo[r]; s <= conHi[r]; s++) if (this.gridMin[s] < cmd) cmd = this.gridMin[s];\n this.srcCmd0[q] = fresh ? cmd : this.srcCmd1[q];\n this.srcCmd1[q] = cmd;\n // D, the separation point to the incisors, x k cm\n const dk = ((this.teethX - exit) * dx) / k;\n // labiodental where the lower lip forms it at or past the incisors (/f v/); a tongue there (/\u03B8/) keeps the\n // obstacle source; a constriction whose narrowest section lies past the incisors is the lips' (rounding)\n let lab = dk / D_LABIAL;\n lab = lab <= 0 ? 1 : lab >= 1 ? 0 : 1 - lab * lab * (3 - 2 * lab);\n const lip = this.labial < 0 ? 0 : this.labial > 1 ? 1 : this.labial;\n let past = mi + 1 - this.teethX;\n past = past <= 0 ? 0 : past >= 1 ? 1 : past * past * (3 - 2 * past);\n const labio = lab * lip;\n const lips = (1 - labio) * past;\n lab = labio + lips;\n let wf = (dk - D_WALL_LO) / (D_WALL_HI - D_WALL_LO);\n wf = wf < 0 ? 0 : wf > 1 ? 1 : wf * wf * (3 - 2 * wf);\n // an obstacle needs the incisors downstream of separation: a jet that separates at or past their\n // edge (the dental /\u03B8/) blows into free air, a wall-type source with nothing ahead of it\n let ob = dk / D_FREE;\n ob = ob <= 0 ? 0 : ob >= 1 ? 1 : ob * ob * (3 - 2 * ob);\n this.tx = exit + (WALL_DOWN * k) / dx;\n this.tw = (1 - lab) * (wf * G_WALL + (1 - wf) * (1 - ob) * G_FREE);\n this.addAt(q);\n this.tx = this.teethX;\n this.tw = (1 - lab) * (1 - wf) * ob * G_OBSTACLE;\n this.addAt(q);\n this.tx = exit + (LABIAL_DOWN * k) / dx;\n this.tw = labio * G_LABIAL + lips * G_LIPS;\n this.addAt(q);\n const v = this.vAcc[q] / blk;\n const d = 2 * Math.sqrt((a > 1e-4 ? a : 1e-4) / Math.PI);\n let fc = (FC_LINGUAL * v) / d;\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n // the obstacle's share keeps its single corner (Shadle 1991: an obstacle source is broadband); a free\n // jet, a wall and the lower lip fall a second order above P2_HZ\n const wo = (1 - lab) * (1 - wf) * ob;\n let f2 = P2_HZ * Math.exp(wo * Math.log((0.45 * rate) / P2_HZ));\n f2 = f2 > 0.45 * rate ? 0.45 * rate : f2;\n this.cLp2[q] = 1 - Math.exp((-2 * Math.PI * f2) / rate);\n // the convective delay from the separation point to where the source sits\n const dObs = dk > 0 ? dk * k : 0;\n const ds = (1 - lab) * (wf * WALL_DOWN * k + (1 - wf) * (ob * dObs + (1 - ob) * WALL_DOWN * k)) + lab * LABIAL_DOWN * k;\n let tau = v > 1 ? ds / (CONVECT * v) : TAU_MAX;\n tau = (tau < TAU_MAX ? tau : TAU_MAX) * rate;\n this.tau0[q] = this.tau1[q];\n this.tau1[q] = tau;\n this.modOn[q] = 1;\n }\n // aspiration, 1.5 k cm above the glottis (at the duct's end when the duct is longer)\n {\n const q = SRC_ASP;\n if (this.nTap[q] === 0) this.freshSource(q, 0);\n let x = (ASPIRATION_AT * k - this.ductLen) / dx;\n x = x < 0 ? 0 : x > nG ? nG : x;\n this.tx = x;\n // Birkholz's aspiration gain is variable (0.005 to 0.5 of the others): less in modal voicing\n const vo = this.voicing;\n this.tw = G_ASPIRATION * (1 - vo) + G_ASPIRATION_VOICED * Math.pow(k, ASPIRATION_VOICED_K) * vo;\n this.addAt(q);\n const ga = this.agMean > 1e-4 ? this.agMean : 1e-4;\n let fc = (FC_LINGUAL * (this.vAcc[q] / blk)) / (2 * Math.sqrt(ga / Math.PI));\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n this.modOn[q] = 0;\n }\n // the velic source while the port is a constriction\n {\n const q = SRC_VEL;\n const vel = this.velum;\n this.velW0 = this.velW1;\n // a jet into the nasal cavity with no obstacle ahead: a wall source\n this.velW1 = vel > CLOSED && vel < CONSTRICTED * k2 ? G_WALL : 0;\n if (this.velW0 === 0 && this.velW1 > 0) this.freshSource(q, 0);\n const d = 2 * Math.sqrt((vel > 1e-4 ? vel : 1e-4) / Math.PI);\n let fc = (FC_LINGUAL * (this.vAcc[q] / blk)) / d;\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n this.modOn[q] = 0;\n }\n for (let q = 0; q < NSRC; q++) this.vAcc[q] = 0;\n // drop taps that are silent at both ends\n for (let q = 0; q < NSRC; q++) {\n const b = q * TAPS;\n let n = 0;\n for (let t = 0; t < this.nTap[q]; t++) {\n if (tapW0[b + t] === 0 && tapW1[b + t] === 0) continue;\n this.tapJ[b + n] = this.tapJ[b + t];\n tapW0[b + n] = tapW0[b + t];\n tapW1[b + n] = tapW1[b + t];\n n++;\n }\n this.nTap[q] = n;\n }\n }\n\n /** A source starting from silence: clear its filters and its delay ring; its area from section s. */\n private freshSource(q: number, s: number): void {\n this.vF[q] = 0;\n this.vS[q] = 0;\n this.nL[q] = 0;\n this.nL2[q] = 0;\n this.aF[q] = q < 3 ? this.tgtMin[s] : q === SRC_ASP ? this.ag : this.velum > 1e-4 ? this.velum : 1e-4;\n this.tau0[q] = this.tau1[q] = 0;\n this.ring.fill(0, q * MOD_RING, (q + 1) * MOD_RING);\n }\n\n /** Place source q's weight `tw` at fractional junction `tx`, split linearly between the two junctions there. */\n private addAt(q: number): void {\n const w = this.tw;\n if (!(w > 0)) return;\n const nG = this.nG;\n let x = this.tx;\n x = x < 0 ? 0 : x > nG ? nG : x;\n const j = Math.floor(x);\n const f = x - j;\n this.tShare = 1 - f;\n this.addTap(q, j);\n if (f > 0 && j < nG) {\n this.tShare = f;\n this.addTap(q, j + 1);\n }\n }\n\n /** Add tw times tShare to source q's tap at junction j. */\n private addTap(q: number, j: number): void {\n const b = q * TAPS;\n const n = this.nTap[q];\n const add = this.tw * this.tShare;\n for (let t = 0; t < n; t++)\n if (this.tapJ[b + t] === j) {\n this.tapW1[b + t] += add;\n return;\n }\n if (n >= TAPS) return;\n this.tapJ[b + n] = j;\n this.tapW0[b + n] = 0;\n this.tapW1[b + n] = add;\n this.nTap[q] = n + 1;\n }\n\n /**\n * Render count samples (at most one block, and the block must have\n * begun), adding the sound times `gain` times env[c] into outL and outR at\n * [at, at + count). off: the block's first sample still to render.\n */\n render(outL: Float32Array, outR: Float32Array, at: number, count: number, off: number, env: Float32Array): void {\n const T = this.T;\n const iT = this.rate;\n const nG = this.nG;\n const jv = this.jv;\n const R = this.R;\n const L = this.L;\n const sZ = this.sZ;\n const isZ = this.isZ;\n const Zs = this.Zs;\n const area = this.area;\n const dArea = this.dArea;\n const U = this.U;\n const pn = this.pn;\n const kf = this.kf;\n const kb = this.kb;\n const rv = this.rv;\n const viscC = this.viscC;\n const wallK = this.wallK;\n const gwA = this.gw;\n const wV = this.wV;\n const wY = this.wY;\n const wS = this.wS;\n const moving = this.moving;\n const nm = this.nMoving;\n const jmList = this.jmList;\n const njm = this.nJm;\n const gamA = this.gamA;\n const ibA = this.ibA;\n const bqA = this.bqA;\n const dv1 = this.dv1;\n const dv2 = this.dv2;\n const raw = this.dvRaw;\n const dvc = this.dvCoef;\n const aMin = this.aMin;\n const dAMin = this.dAMin;\n const iaMin = this.iaMin;\n const wIbsA = this.wIbsA;\n const wCmA = this.wCmA;\n const wKsA = this.wKsA;\n const pJ = this.pJa;\n const pG = this.pG;\n const pCm = this.pCm;\n const pK = this.pK;\n const pDi = this.pDi;\n let pQ = this.pQ;\n let pY = this.pY;\n let pP = this.pP;\n const fBuf = this.fBuf;\n const bBuf = this.bBuf;\n const tr = this.tr;\n const na = this.na;\n const areaBuf = this.areaBuf;\n const folds = this.folds;\n const selfOsc = this.model === GLOTTIS_SELF_OSCILLATING;\n const visc0 = this.visc0;\n const ldG = this.ldG;\n const blk = this.block;\n const inv = 1 / blk;\n const gain = this.gain;\n const micK = (this.mic * SOUND_SPEED) / (2 * MIC_R);\n const micC = this.micC;\n const lungZ = (0.5 * RHOC) / tr.area[0];\n const trLast = tr.nn - 2;\n const trSegF = trLast * TUBE_RING;\n const trD = tr.D[trLast];\n const trZ = tr.Z[trLast];\n const trA = tr.area[trLast];\n const ring = this.ring;\n const tapJ = this.tapJ;\n const tapW0 = this.tapW0;\n const tapW1 = this.tapW1;\n const cVc = this.cVc;\n const cVs = this.cVs;\n const noiseScale = this.noiseScale;\n const voi = this.voicing;\n const vMax = this.vMax;\n let wallRad = 0;\n for (let c = 0; c < count; c++) {\n const n = off + c;\n const w = (n + 1) * inv;\n this.w = w;\n // moving sections\n for (let mi = 0; mi < nm; mi++) {\n const s = moving[mi];\n let a = area[s] + dArea[s];\n area[s] = a;\n if (a < 1e-4) a = 1e-4;\n let mm = aMin[s] + dAMin[s];\n aMin[s] = mm;\n if (mm > a) mm = a;\n if (mm < 1e-4) mm = 1e-4;\n iaMin[s] = 1 / mm;\n const isz = Math.sqrt(a) / SRHOC;\n const z = 1 / isz;\n sZ[s] = z;\n isZ[s] = isz;\n Zs[s] = z * z;\n }\n // moving junctions' elements\n for (let mi = 0; mi < njm; mi++) {\n const i = jmList[mi];\n const zl = Zs[i - 1];\n const zr = Zs[i];\n const ef = iaMin[i - 1] - zr * IRHOC;\n const eb = iaMin[i] - zl * IRHOC;\n const cf = iaMin[i] - zl * IRHOC;\n const cb = iaMin[i - 1] - zr * IRHOC;\n kf[i] = 0.5 * RHO * ((ef > 0 ? ef * ef : 0) + (cf > 0 ? 0.1 * cf * cf : 0));\n kb[i] = 0.5 * RHO * ((eb > 0 ? eb * eb : 0) + (cb > 0 ? 0.1 * cb * cb : 0));\n const r = viscC[i - 1] * zl * sZ[i - 1] + viscC[i] * zr * sZ[i];\n rv[i] = r;\n // the wall's surface follows the area per sample too (set once a block, it stepped the\n // junction's pressure at every block of an opening: MEASURED clicks at a velar release)\n if ((i & 1) === 0) {\n const am = 0.5 * (area[i - 1] + area[i]);\n // the surface goes to zero continuously as the section seals, so the wall leaves smoothly\n const sw = am > CLOSED ? wallK[i - 1] * Math.sqrt(am - CLOSED) : 0;\n wS[i] = sw;\n gwA[i] = sw * wIbsA[i] + (i === pJ ? pG : 0);\n }\n const t = zl * gwA[i];\n const gam = t < 1e-3 ? 1 - t : 1 / (1 + t);\n gamA[i] = gam;\n const bq = zl * gam + zr + r;\n bqA[i] = bq;\n ibA[i] = 1 / bq;\n }\n this.ductTau += this.dTau;\n this.ductSZ += this.dDuctSZ;\n const pL = this.pL0 + (this.pL - this.pL0) * w;\n this.velNow = this.vel0 + (this.vel - this.vel0) * w;\n let ag: number;\n if (selfOsc) {\n folds.step();\n ag = folds.area;\n } else ag = areaBuf[n];\n if (ag < 1e-7) ag = 1e-7;\n this.ag = ag;\n this.agAcc += ag;\n // turbulence from last sample's flows: p_s = G |v_c|^3 sqrt(A), in series where each source sits\n const rp = this.ringPos;\n for (let q = 0; q < NSRC; q++) {\n const nt = this.nTap[q];\n const vel = q === SRC_VEL;\n if (nt === 0 && !(vel && (this.velW0 > 0 || this.velW1 > 0))) continue;\n let u: number;\n let a: number;\n // the source's area: the airway's, or the commanded one where that is less\n let as: number;\n if (q < 3) {\n u = U[this.srcUJ[q]];\n a = aMin[this.srcSec[q]];\n if (a > area[this.srcSec[q]]) a = area[this.srcSec[q]];\n as = this.srcCmd0[q] + (this.srcCmd1[q] - this.srcCmd0[q]) * w;\n if (as > a) as = a;\n } else if (q === SRC_ASP) {\n u = this.uG;\n a = ag;\n as = a;\n } else {\n u = this.uV;\n a = this.velNow;\n as = a;\n }\n // a section at the closed area is shut: its floor's leak is numerical, not a jet (MEASURED: read as one, a\n // /t/ closure carried frication 30 dB over CHIMERA's silence); the source fades in to 5 times that area.\n // The area rate law closes the last 0.4 cm^2 slowly so a seal does not click; the source reads the\n // commanded area there, or that dwell was a fricative (MEASURED: 10 to 20 ms at the vowel's level\n // before each /t t\u0283/ closure, -2 dB re the phrase for the male /t\u0283/, CHIMERA -23 to -32)\n let shut = (as - 2e-4) * 1250;\n shut = q === SRC_ASP ? 1 : shut <= 0 ? 0 : shut >= 1 ? 1 : shut * shut * (3 - 2 * shut);\n if (a < 1e-4) a = 1e-4;\n if (as < 1e-4) as = 1e-4;\n const af = this.aF[q] + cVc * (as - this.aF[q]);\n this.aF[q] = af;\n // no jet outruns the lungs: the flow and the area it reads can disagree for a sample as a section seals\n let vr = u / a;\n vr = vr > vMax ? vMax : vr < -vMax ? -vMax : vr;\n const vf = this.vF[q] + cVc * (vr - this.vF[q]);\n this.vF[q] = vf;\n const av = vf < 0 ? -vf : vf;\n this.vAcc[q] += av;\n // the convective delay, read linearly between ring samples\n const rb = q * MOD_RING;\n ring[rb + rp] = av;\n const td = this.tau0[q] + (this.tau1[q] - this.tau0[q]) * w;\n const ti = td | 0;\n const tf = td - ti;\n const vd = ring[rb + ((rp - ti) & (MOD_RING - 1))] * (1 - tf) + ring[rb + ((rp - ti - 1) & (MOD_RING - 1))] * tf;\n let lev = vd * vd * vd;\n const s3 = this.vS[q] + cVs * (lev - this.vS[q]);\n this.vS[q] = s3;\n // in voicing the pulsing about the slow level is soft-limited to an index near MOD_MAX\n const mw = this.modOn[q] * voi;\n if (mw > 0) {\n let m = s3 > 1 ? lev / s3 - 1 : 0;\n m = m / (1 + (m < 0 ? -m : m) * (1 / MOD_MAX));\n lev = (1 - mw) * lev + mw * s3 * (1 + m);\n }\n // mulberry32, inline: uniform in [0, 1)\n let s = (this.seed + 0x6d2b79f5) | 0;\n this.seed = s;\n s = Math.imul(s ^ (s >>> 15), s | 1);\n s ^= s + Math.imul(s ^ (s >>> 7), s | 61);\n const wv = ((((s ^ (s >>> 14)) >>> 0) / 4294967296) * 2 - 1) * 1.7320508075688772;\n const nl1 = this.nL[q] + this.cLp[q] * (wv - this.nL[q]);\n this.nL[q] = nl1;\n const nl2 = this.nL2[q] + this.cLp2[q] * (nl1 - this.nL2[q]);\n this.nL2[q] = nl2;\n const nl = nl2;\n // the dipole's sign follows the flow's, continuously through zero\n const sa = Math.sqrt(af);\n // a jet is turbulent only above the critical Reynolds number: Re = v d / nu, d = 2 sqrt(A / pi)\n let tu = (av * sa * RE_PER_VSA - RE_LO) * RE_SPAN;\n tu = q === SRC_ASP ? 1 : tu <= 0 ? 0 : tu >= 1 ? 1 : tu * tu * (3 - 2 * tu);\n const ls = shut * tu * lev * sa;\n this.lvAcc[q] += ls;\n const v = (noiseScale * ls * nl * vf) / (av + 1);\n if (vel) {\n this.pnV = v * (this.velW0 + (this.velW1 - this.velW0) * w);\n continue;\n }\n const b = q * TAPS;\n for (let t = 0; t < nt; t++) pn[tapJ[b + t]] += v * (tapW0[b + t] + (tapW1[b + t] - tapW0[b + t]) * w);\n }\n this.ringPos = (rp + 1) & (MOD_RING - 1);\n // Lagrange-3 coefficients shared by both duct reads (tau - 0.5 and tau + 0.5)\n const dF = this.ductTau - 0.5;\n const i0 = Math.floor(dF);\n const x = dF - i0;\n const hm1 = (-x * (x - 1) * (x - 2)) / 6;\n const h0 = ((x + 1) * (x - 1) * (x - 2)) / 2;\n const h1 = (-(x + 1) * x * (x - 2)) / 2;\n const h2 = ((x + 1) * x * (x - 1)) / 6;\n const pos = this.pos;\n\n // ---- phase 0: the lungs and the trachea, the glottis, odd grid junctions\n {\n const b = tr.B[(pos - tr.D[0]) & (TUBE_RING - 1)];\n const zt = tr.Z[0];\n const u = (pL - 2 * b) / (lungZ + zt);\n tr.F[pos] = b + zt * u;\n }\n tr.interior(pos);\n {\n const a = tr.F[trSegF + ((pos - trD) & (TUBE_RING - 1))];\n const p0 = (pos - (i0 + 1)) & (TUBE_RING - 1);\n const ductSZ = this.ductSZ;\n const b = (hm1 * bBuf[(p0 + 1) & (TUBE_RING - 1)] + h0 * bBuf[p0] + h1 * bBuf[(p0 - 1) & (TUBE_RING - 1)] + h2 * bBuf[(p0 - 2) & (TUBE_RING - 1)]) * ductSZ;\n const zb = ductSZ * ductSZ;\n const ia = 1 / ag;\n const lg = ldG * ia;\n const rg = visc0 * ia * ia * ia;\n // the duct's area from its impedance, which ramps per sample (stepped once a block, the exit\n // loss stepped the flow: MEASURED clicks a glottis-to-lips delay into every block)\n const exf = ia - zb * IRHOC;\n const exb = ia - 1 / trA;\n const kin = GLOTTIS_KIN * 0.5 * RHO * ia * ia;\n const kfg = kin + 0.5 * RHO * (exf > 0 ? exf * exf : 0);\n const kbg = kin + 0.5 * RHO * (exb > 0 ? exb * exb : 0);\n const m0 = lg < this.lG ? lg * this.uG : this.momG;\n this.lG = lg;\n const cc = 2 * (a - b) + m0 * iT;\n const bq = trZ + zb + rg + lg * iT;\n const u = cc >= 0 ? (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kfg * cc)) : (2 * cc) / (bq + Math.sqrt(bq * bq - 4 * kbg * cc));\n this.uG = u;\n this.momG = lg * u;\n const pBelow = 2 * a - trZ * u;\n const pAbove = 2 * b + zb * u;\n this.dpGlottis = pBelow - pAbove;\n this.dpAcc += pBelow - pAbove;\n this.paAcc += pAbove;\n folds.ps = pBelow;\n folds.pe = pAbove;\n this.pSub = pBelow;\n tr.B[trSegF + pos] = pBelow - a;\n fBuf[pos] = (pAbove - b) / ductSZ;\n }\n for (let i = 1; i < nG; i += 2) {\n if (i === jv) continue;\n const sl = i - 1;\n const zl = Zs[sl];\n const zr = Zs[i];\n const a = R[sl] * sZ[sl];\n const b = L[i] * sZ[i];\n const cc = 2 * (a - b) + pn[i];\n const ib = ibA[i];\n const kk = cc >= 0 ? kf[i] : kb[i];\n const ac = cc < 0 ? -cc : cc;\n const eps = 4 * kk * ac * ib * ib;\n let u: number;\n if (eps < LIN_EPS) u = cc * ib * (1 - 0.25 * eps);\n else {\n const bq = bqA[i];\n u = (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kk * ac));\n }\n U[i] = u;\n L[sl] = (a - zl * u) * isZ[sl];\n R[i] = (b + zr * u) * isZ[i];\n }\n if ((jv & 1) === 1) {\n this.velumNode(pos);\n na.interior(pos);\n this.nostrils(pos);\n }\n if ((nG & 1) === 1) this.lips();\n\n // ---- phase 1: even grid junctions (walls, moving-wall flow), the duct end\n for (let i = 2; i < nG; i += 2) {\n if (i === jv) continue;\n const sl = i - 1;\n const zl = Zs[sl];\n const zr = Zs[i];\n const a = R[sl] * sZ[sl];\n const b = L[i] * sZ[i];\n const ws = wS[i];\n const hist = wCmA[i] * wV[i] - wKsA[i] * wY[i];\n const wib = wIbsA[i];\n // the piriform fossae's branch, at its one junction\n const ph = i === pJ ? (0.5 * pP + pCm * pQ - pK * pY) * pDi : 0;\n // CHIMERA's 60 Hz two-pole on the moving-wall flow, per sample (network.rs:360)\n const d1 = dv1[i] + dvc * (raw[i] - dv1[i]);\n dv1[i] = d1;\n const d2 = dv2[i] + dvc * (d1 - dv2[i]);\n dv2[i] = d2;\n const ue0 = d2 - ws * hist * wib - ph;\n const gam = gamA[i];\n const cc = 2 * a * gam - 2 * b + zl * gam * ue0 + pn[i];\n const ib = ibA[i];\n const kk = cc >= 0 ? kf[i] : kb[i];\n const ac = cc < 0 ? -cc : cc;\n const eps = 4 * kk * ac * ib * ib;\n let u: number;\n if (eps < LIN_EPS) u = cc * ib * (1 - 0.25 * eps);\n else {\n const bq = bqA[i];\n u = (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kk * ac));\n }\n U[i] = u;\n const p = (2 * a - zl * (u - ue0)) * gam;\n // a wall with no surface (its junction closed) is disconnected: it must not integrate a sealed node\n if (i === pJ) {\n const qn = pG * p + ph;\n pY += 0.5 * T * (qn + pQ);\n pQ = qn;\n pP = p;\n }\n if (ws > 0) {\n const v = (hist + p) * wib;\n wV[i] = v;\n wY[i] += T * v;\n wallRad += ws * v * WALL_RADIATION;\n }\n L[sl] = (p - a) * isZ[sl];\n R[i] = (b + zr * u) * isZ[i];\n }\n if ((jv & 1) === 0) {\n this.velumNode(pos);\n na.interior(pos);\n this.nostrils(pos);\n }\n {\n const ductSZ = this.ductSZ;\n const zd = ductSZ * ductSZ;\n const p0 = (pos - i0) & (TUBE_RING - 1);\n const a = (hm1 * fBuf[(p0 + 1) & (TUBE_RING - 1)] + h0 * fBuf[p0] + h1 * fBuf[(p0 - 1) & (TUBE_RING - 1)] + h2 * fBuf[(p0 - 2) & (TUBE_RING - 1)]) * ductSZ;\n const zr = Zs[0];\n const b = L[0] * sZ[0];\n const d1 = dv1[0] + dvc * (raw[0] - dv1[0]);\n dv1[0] = d1;\n const d2 = dv2[0] + dvc * (d1 - dv2[0]);\n dv2[0] = d2;\n const ue0 = d2;\n const cc = 2 * a - 2 * b + zd * ue0 + pn[0];\n pn[0] = 0;\n const u = cc / (zd + zr);\n U[0] = u;\n const p = 2 * a - zd * (u - ue0);\n bBuf[pos] = (p - a) / ductSZ;\n R[0] = (b + zr * u) * isZ[0];\n }\n if ((nG & 1) === 0) this.lips();\n for (let q = 0; q < SRC_VEL; q++) {\n const b = q * TAPS;\n for (let t = 0; t < this.nTap[q]; t++) pn[tapJ[b + t]] = 0;\n }\n this.pnV = 0;\n this.pos = (pos + 1) & (TUBE_RING - 1);\n // the radiated flow's derivative, DC blocked, low-passed\n const rad = this.uLips + this.uNose + this.wallRadAcc + wallRad;\n this.wallRadAcc = 0;\n wallRad = 0;\n // the far field's flow derivative, and the close microphone's flow term (DC blocked below)\n const mf = micK * rad;\n const mh = mf - this.micX + micC * this.micY;\n this.micX = mf;\n this.micY = mh;\n const o = ((rad - this.radPrev) * iT + mh) * OUTPUT_GAIN;\n this.radPrev = rad;\n const hp = o - this.hpX + this.hpC * this.hpY;\n this.hpX = o;\n this.hpY = hp;\n const y = this.lb0 * (hp + this.lx2) + this.lb1 * this.lx1 - this.la1 * this.ly1 - this.la2 * this.ly2;\n this.lx2 = this.lx1;\n this.lx1 = hp;\n this.ly2 = this.ly1;\n this.ly1 = y;\n const v = y * gain * env[c];\n outL[at + c] += v;\n outR[at + c] += v;\n }\n this.pQ = pQ;\n this.pY = pY;\n this.pP = pP;\n if (off + count >= blk) this.agMean = this.agAcc / blk;\n }\n\n /** Lips: Flanagan R || L on the last grid section, with any series noise source. */\n private lips(): void {\n const sl = this.nG - 1;\n const z = this.Zs[sl];\n const a = this.R[sl] * this.sZ[sl];\n const ar = this.area[sl] > 1e-4 ? this.area[sl] : 1e-4;\n const lr = (8 * RHO) / (3 * Math.PI * Math.sqrt(Math.PI * ar));\n const rr = (128 * RHOC) / (9 * Math.PI * Math.PI * ar);\n let ul = this.ulLips;\n const lp = this.lrLips;\n if (lp > 0 && lr > lp) ul *= lp / lr;\n const h = this.T / (2 * lr);\n const pOld = this.pLipsOld;\n const src = this.pn[this.nG];\n this.pn[this.nG] = 0;\n const p = (2 * a + src - z * (ul + h * pOld)) / (1 + z * (h + 1 / rr));\n const ul2 = ul + h * (pOld + p);\n const ur = ul2 + p / rr;\n this.pLipsOld = p;\n this.U[this.nG] = ur;\n this.L[sl] = (p - src - a) * this.isZ[sl];\n this.ulLips = ul2;\n this.lrLips = lr;\n this.uLips = ur;\n }\n\n /** Nostrils: Flanagan R || L on the nasal tube's last segment. */\n private nostrils(pos: number): void {\n const c = this.na;\n const sl = c.nn - 2;\n const z = c.Z[sl];\n const a = c.F[sl * TUBE_RING + ((pos - c.D[sl]) & (TUBE_RING - 1))];\n const ar = c.area[sl];\n const lr = (8 * RHO) / (3 * Math.PI * Math.sqrt(Math.PI * ar));\n const rr = (128 * RHOC) / (9 * Math.PI * Math.PI * ar);\n const h = this.T / (2 * lr);\n const pOld = this.pNoseOld;\n const p = (2 * a - z * (this.ulNose + h * pOld)) / (1 + z * (h + 1 / rr));\n const ul2 = this.ulNose + h * (pOld + p);\n this.ulNose = ul2;\n this.pNoseOld = p;\n this.uNose = ul2 + p / rr;\n c.B[sl * TUBE_RING + pos] = p - a;\n }\n\n /**\n * The velum node: the oral section behind joins it directly, the oral\n * section ahead through the junction's series element and the nasal tube\n * through the velum port. Two coupled flows, three Gauss-Seidel passes of\n * the closed-form root.\n */\n private velumNode(pos: number): void {\n const j = this.jv;\n const R = this.R;\n const L = this.L;\n const sZ = this.sZ;\n const isZ = this.isZ;\n const Zs = this.Zs;\n const sl = j - 1;\n const sr = j;\n const na = this.na;\n const z1 = Zs[sl];\n const z2 = Zs[sr];\n const z3 = na.Z[0];\n const a = R[sl] * sZ[sl];\n const b = L[sr] * sZ[sr];\n const c3 = na.B[(pos - na.D[0]) & (TUBE_RING - 1)];\n const gw = this.gw[j];\n const d1 = this.dv1[j] + this.dvCoef * (this.dvRaw[j] - this.dv1[j]);\n this.dv1[j] = d1;\n const d2 = this.dv2[j] + this.dvCoef * (d1 - this.dv2[j]);\n this.dv2[j] = d2;\n let ue = d2;\n if (gw > 0) ue -= this.wS[j] * (this.wCmA[j] * this.wV[j] - this.wKsA[j] * this.wY[j]) * this.wIbsA[j];\n const zl = 1 / (1 / z1 + gw);\n const p0 = (2 * a) / z1 + ue;\n const src = this.pn[j];\n this.pn[j] = 0;\n const kfr = this.kf[j];\n const kbr = this.kb[j];\n const bqr = zl + z2 + this.rv[j];\n const cr0 = zl * p0 - 2 * b + src;\n let ur = this.U[j];\n let uv = 0;\n const vel = this.velNow;\n if (vel > CLOSED) {\n const ip = 1 / vel;\n const lv = RHO * this.velLen * ip;\n const rvv = VISC * 2 * Math.sqrt(Math.PI) * this.velLen * Math.sqrt(vel) * ip * ip;\n const exf = ip - 1 / na.area[0];\n const amin = this.area[sl] < this.area[sr] ? this.area[sl] : this.area[sr];\n const exb = ip - 1 / amin;\n const kin = VELUM_KIN * 0.5 * RHO * ip * ip;\n const kfv = kin + VELUM_EXIT * 0.5 * RHO * (exf > 0 ? exf * exf : 0);\n const kbv = kin + VELUM_EXIT * 0.5 * RHO * (exb > 0 ? exb * exb : 0);\n const m0 = lv < this.lV ? lv * this.uV : this.momV;\n this.lV = lv;\n const bqv = zl + z3 + rvv + lv * this.rate;\n const cv0 = zl * p0 - 2 * c3 + m0 * this.rate + this.pnV;\n uv = this.uV;\n for (let it = 0; it < 3; it++) {\n let c = cr0 - zl * uv;\n if (c >= 0) ur = kfr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr + 4 * kfr * c)) : c / bqr;\n else ur = kbr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr - 4 * kbr * c)) : c / bqr;\n c = cv0 - zl * ur;\n if (c >= 0) uv = kfv > 0 ? (2 * c) / (bqv + Math.sqrt(bqv * bqv + 4 * kfv * c)) : c / bqv;\n else uv = kbv > 0 ? (2 * c) / (bqv + Math.sqrt(bqv * bqv - 4 * kbv * c)) : c / bqv;\n }\n this.momV = lv * uv;\n } else {\n this.momV = 0;\n this.lV = 0;\n const c = cr0;\n if (c >= 0) ur = kfr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr + 4 * kfr * c)) : c / bqr;\n else ur = kbr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr - 4 * kbr * c)) : c / bqr;\n }\n this.uV = uv;\n const p = zl * (p0 - ur - uv);\n if (gw > 0) {\n const v = (this.wCmA[j] * this.wV[j] + p - this.wKsA[j] * this.wY[j]) * this.wIbsA[j];\n this.wV[j] = v;\n this.wY[j] += this.T * v;\n this.wallRadAcc += this.wS[j] * v * WALL_RADIATION;\n }\n this.U[j] = ur;\n L[sl] = (p - a) * isZ[sl];\n R[sr] = (b + z2 * ur) * isZ[sr];\n na.F[pos] = c3 + z3 * uv;\n }\n}\n", "/*\n * The beatbox scores: each drum sound as a short gestural score on the voice's tract, its acoustic hit\n * at h, with the airstream beatboxers use (vocal-beats.ts lists the sounds). CHIMERA's scores (Jameson\n * Hodge, MIT, crates/chimera/src/phonetics/beatbox.rs), reimplemented on bellows' planner; the breath\n * key, the ejective's push through the release, the kick's raised tongue body, 'ch', 'Psh' and the\n * breath in are bellows' own. See THIRD_PARTY_NOTICES.md.\n *\n * Written against BeatWriter, the few planner primitives a score needs, so the recipes live apart from\n * the planner's machinery. Runs when the planner rebuilds (event rate); allocates nothing.\n */\n\nimport { ART, ARTICULATORS, KEY_ABDUCTION, KEY_BREATH, KEY_CLOSURE } from './vocal-articulators';\nimport { VOCAL_BEATS } from './vocal-beats';\nimport { VOCAL_TABLE_PHONEMES } from './vocal-tables.gen';\n\n/** What a beat score writes with: the planner's gesture primitives (engines/vocal-planner.ts). */\nexport interface BeatWriter {\n /** The dorsum's height for [x] at this body. */\n readonly xTbY: number;\n /** Schwa's target for an articulator at this body. */\n schwaTarget(a: number): number;\n begin(): void;\n key(k: number, v: number): void;\n /** A gesture from the keys since begin(): its index, or -1 when the pool is full. */\n emit(t0: number, t1: number, ri: number, ro: number, str: number, speed: number): number;\n /** Rank gesture g as a consonant's, so its speed governs its articulators. */\n rank(g: number, speed: number): void;\n /** A consonant's oral gestures from table phoneme idx with overrides (see VocalPlanner.beatOral). */\n beatOral(idx: number, a: number, b: number, speed: number, snap: number, snapRo: number, after: number, fric: boolean, k1: number, v1: number, k2: number, v2: number, noFront: boolean): void;\n}\n\n/* Beat numbers (VOCAL_BEATS order). */\nconst BEAT_ID = (id: string): number => VOCAL_BEATS.findIndex((b) => b.id === id);\nconst B_KICK = BEAT_ID('B');\nconst B_HAT = BEAT_ID('t');\nconst B_OPEN_HAT = BEAT_ID('tss');\nconst B_SNARE = BEAT_ID('Pf');\nconst B_RIM = BEAT_ID('K');\nconst B_INWARD = BEAT_ID('^K');\nconst B_CLICK = BEAT_ID('!');\nconst B_POP = BEAT_ID('P!');\nconst B_CRASH = BEAT_ID('kch');\nconst B_HUM = BEAT_ID('m');\nconst B_CHAT = BEAT_ID('ch');\nconst B_PSH = BEAT_ID('Psh');\nconst B_IN = BEAT_ID('in');\n\n/* The table phonemes the beats are built from. */\n/** The kick's tongue body, high and short of the palate (/k/ seals at 8.35). */\nconst KICK_TBY = 7.7;\n/** How long after the release the ejective's larynx keeps rising, s. */\nconst EJECTIVE_PUSH = 0.025;\n/** A breath in's lung pressure, a fraction of the note's (about -5.7 cmH2O at the default velocity; INFERRED). */\nconst BREATH_IN = 0.5;\n/**\n * A breath in's glottal opening, cm^2 before k^2. MEASURED: wide open (0.9) the inflow, 330 cm^3/s, was\n * 76 dB under the vowel (noise grows as v^3); at 0.18 and 0.5 of the note's pressure it reads about\n * -33 dB, a quiet but audible breath (INFERRED target).\n */\nconst BREATH_IN_GLOTTIS = 0.18;\nconst P_P = VOCAL_TABLE_PHONEMES.indexOf('p');\nconst P_T = VOCAL_TABLE_PHONEMES.indexOf('t');\nconst P_K = VOCAL_TABLE_PHONEMES.indexOf('k');\nconst P_S = VOCAL_TABLE_PHONEMES.indexOf('s');\nconst P_F = VOCAL_TABLE_PHONEMES.indexOf('f');\nconst P_SH = VOCAL_TABLE_PHONEMES.indexOf('\u0283');\nconst P_M = VOCAL_TABLE_PHONEMES.indexOf('m');\n\n/**\n * A beat's gestures, its acoustic hit at h: CHIMERA's scores (phonetics/beatbox.rs), each sound a\n * short score on the tract with the airstream beatboxers use. `len` is the time to the next step,\n * which a sustained sound may fill. `first`: the line's first sound, whose ready posture starts early.\n */\nexport function writeBeatScore(w: BeatWriter, slot: number, h: number, len: number, first: boolean): void {\n const b = slot >> 1;\n const accent = (slot & 1) === 1 ? 1.3 : 1;\n const hum = b === B_HUM || b === B_IN;\n // the ready posture: jaw nearly closed, lips just apart, the dorsum a little high for the velar hits\n w.begin();\n for (let k = 0; k < ARTICULATORS; k++) {\n if (k === ART.velum) continue;\n let v = w.schwaTarget(k);\n if (k === ART.tbY) v += 0.1;\n else if (k === ART.jaw) v = 0.4;\n else if (k === ART.lipAp) v = 0.25;\n else if (k === ART.lipProt) v = 0.1;\n w.key(k, v);\n }\n w.emit(first ? h - 0.15 : h, h + len, 0.03, 0.03, 1, 0);\n if (!hum) {\n // the velum shut, so the pressure a sound builds stays in the mouth\n w.begin();\n w.key(ART.velum, w.schwaTarget(ART.velum));\n w.emit(first ? h - 0.15 : h - 0.02, h + len, 0.03, 0.03, 4, 0);\n }\n const NaN_ = NaN;\n if (b === B_KICK) {\n w.beatOral(P_P, h - 0.075, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n // the tongue body high in the mouth, short of the palate: the larynx compresses the volume behind\n // the lips, and the less of it the higher the pressure (dP = rho c^2 dV / V; MEASURED: the open\n // mouth's kick reached 7 cmH2O where the velar rimshot reached 19)\n artic(w, ART.tbY, KICK_TBY, h - 0.09, h + 0.01, 0.03, 0.04, 2);\n ejective(w, h - 0.075, h, accent);\n } else if (b === B_HAT || b === B_CHAT) {\n const fric = b === B_HAT ? P_S : P_SH;\n const end = b === B_HAT ? 0.03 : 0.05;\n w.beatOral(P_T, h - 0.05, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n w.beatOral(fric, h + 0.012, h + end, 1.6, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.03, h + end - 0.004, (b === B_HAT ? 1.25 : 1.3) * accent, b === B_HAT ? 0.36 : 0.38, 0.02);\n } else if (b === B_OPEN_HAT) {\n const end = Math.max(0.09, Math.min(0.26, len * 1.6));\n w.beatOral(P_T, h - 0.05, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n w.beatOral(P_S, h + 0.012, h + end, 1.4, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.03, h + end, 1.2 * accent, 0.4, 0.09);\n } else if (b === B_SNARE || b === B_PSH) {\n const pf = b === B_SNARE;\n w.beatOral(P_P, h - 0.06, h, 2, 3.5, 0.01, NaN_, false, -1, 0, -1, 0, false);\n w.beatOral(pf ? P_F : P_SH, h + 0.018, h + (pf ? 0.08 : 0.11), pf ? 1.6 : 1.5, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.045, h + (pf ? 0.075 : 0.1), 1.7 * accent, 0.45, pf ? 0.04 : 0.05);\n } else if (b === B_RIM) {\n w.beatOral(P_K, h - 0.08, h, 2, 4, 0.008, NaN_, false, ART.jaw, 0.35, -1, 0, false);\n ejective(w, h - 0.08, h, accent);\n } else if (b === B_INWARD) {\n w.beatOral(P_K, h - 0.06, h, 2, 4, 0.008, NaN_, false, ART.jaw, 0.35, -1, 0, false);\n w.beatOral(P_K, h + 0.012, h + 0.085, 1.4, 0, 0, 0.008, true, ART.tbY, w.xTbY - 0.015, -1, 0, false);\n w.begin();\n w.key(KEY_ABDUCTION, 0.5);\n w.emit(h - 0.05, h + 0.085, 0.02, 0.04, 6, 0);\n // the breath drawn in behind the closure, so the release rushes inward\n w.begin();\n w.key(KEY_BREATH, -1.7 * accent);\n w.emit(h - 0.035, h + 0.085, 0.015, 0.05, 2, 0);\n } else if (b === B_CLICK) {\n // the tip seals without the alveolar's fronted tongue body (that would close the pocket)\n w.beatOral(P_T, h - 0.12, h, 2, 3.5, 0.01, NaN_, false, -1, 0, -1, 0, true);\n // the back seal sits low, leaving a pocket for the dorsum to hollow\n w.beatOral(P_K, h - 0.12, h + 0.035, 2, 0, 0, NaN_, false, ART.tbY, 7.85, ART.jaw, 0.4, false);\n artic(w, ART.dorsum, 1, h - 0.03, h + 0.006, 0.04, 0.03, 2);\n } else if (b === B_POP) {\n // a light seal: pressing the lips squeezes the pocket before the suction starts\n w.beatOral(P_P, h - 0.12, h, 2, 5, 0.006, NaN_, false, ART.lipAp, -0.08, -1, 0, false);\n w.beatOral(P_K, h - 0.12, h + 0.03, 2, 0, 0, NaN_, false, -1, 0, -1, 0, false);\n // the lips stay sealed while the jaw and tongue hollow the mouth\n w.begin();\n w.key(ART.jaw, 1.6);\n w.key(ART.dorsum, 1);\n const g = w.emit(h - 0.07, h + 0.004, 0.04, 0.05, 40, 2);\n if (g >= 0) w.rank(g, 2);\n } else if (b === B_CRASH) {\n const end = Math.max(0.14, Math.min(0.34, len * 2));\n // the back of the tongue lingers by the velum after the burst ([x]) while the blade rises into a long [\u0283]\n w.beatOral(P_K, h - 0.06, h, 2, 4, 0.008, NaN_, false, -1, 0, -1, 0, false);\n w.beatOral(P_K, h + 0.002, h + 0.045, 2, 0, 0, 0.008, true, ART.tbY, w.xTbY, -1, 0, false);\n w.beatOral(P_SH, h + 0.025, h + end, 1.4, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.035, h + end, 1.75 * accent, 0.45, 0.14);\n } else if (b === B_HUM) {\n const end = Math.max(0.06, len * 0.92);\n // lips shut before the voice starts, so the note begins as a hum; the velum drops into the\n // sealed mouth while the folds are still apart, so the squeezed air does not pop out the nose\n w.beatOral(P_M, h - 0.03, h + end, 1.6, 0, 0, NaN_, false, -1, 0, -1, 0, false);\n w.begin();\n w.key(ART.velum, 0.9);\n w.emit(h - 0.02, h + end, 0.03, 0.03, 4, 0);\n w.begin();\n w.key(KEY_ABDUCTION, 0.3);\n w.emit(h - 0.08, h - 0.03, 0.02, 0.02, 5, 0);\n w.begin();\n w.key(KEY_BREATH, 0.95 * accent);\n w.emit(h - 0.01, h + end, 0.02, 0.04, 1, 0);\n } else if (b === B_IN) {\n // a breath in between phrases (Werner et al. 2021: noise with no pitch, louder the faster the\n // breath and the wider the jaw): the glottis wide, the jaw open, the velum part open (mouth and\n // nose), and the lungs below the mouth's pressure. The amounts are INFERRED, gated on level.\n const end = Math.max(0.12, len);\n artic(w, ART.jaw, 0.95, h - 0.04, h + end - 0.05, 0.05, 0.06, 1.2);\n w.begin();\n w.key(ART.lipAp, 0.9);\n w.key(ART.velum, 0.5);\n w.emit(h - 0.04, h + end - 0.05, 0.05, 0.06, 4, 0);\n w.begin();\n w.key(KEY_ABDUCTION, BREATH_IN_GLOTTIS);\n w.emit(h - 0.03, h + end, 0.03, 0.05, 8, 0);\n w.begin();\n w.key(KEY_BREATH, -BREATH_IN * accent);\n w.emit(h, h + end - 0.04, 0.06, 0.05, 2, 0);\n }\n // B_REST: the ready posture only\n}\n\n/** One articulator held at a target over [t0, t1] at strength 40, moving at `speed`. */\nfunction artic(w: BeatWriter, k: number, v: number, t0: number, t1: number, ri: number, ro: number, speed: number): void {\n w.begin();\n w.key(k, v);\n const g = w.emit(t0, t1, ri, ro, 40, speed);\n if (g >= 0) w.rank(g, speed);\n}\n\n/** The glottalic piston: the glottis sealed through the closure, the larynx raised just before the release at h. */\nfunction ejective(w: BeatWriter, at: number, h: number, accent: number): void {\n w.begin();\n w.key(KEY_CLOSURE, 1);\n w.emit(at - 0.012, h + 0.03, 0.012, 0.03, 8, 0);\n w.begin();\n w.key(ART.larynx, Math.min(1.6, 1.25 + 0.3 * accent));\n // still rising through the release: the piston, not the few tenths of a cm^3 the closure\n // compressed, drives the puff that follows the burst\n const g = w.emit(h - 0.05, h + EJECTIVE_PUSH, 0.03, 0.08, 40, 3);\n if (g >= 0) w.rank(g, 3);\n}\n\n/**\n * Lung pressure (times the note's) over [t0, t1], with the glottis held open until the breath has\n * gone, or the folds would start to buzz on what is left.\n */\nfunction blow(w: BeatWriter, t0: number, t1: number, level: number, abduction: number, tail: number): void {\n w.begin();\n w.key(KEY_ABDUCTION, abduction);\n w.emit(t0, t1 + tail + 0.02, 0.02, 0.03, 6, 0);\n w.begin();\n w.key(KEY_BREATH, level);\n w.emit(t0 - 0.01, t1, 0.02, tail, 1, 0);\n}\n", "/*\n * The articulation planner: a sung line's phonemes, as they arrive, to\n * targets and speeds for CHIMERA's 17 articulators and the glottis, at\n * control rate.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49):\n * crates/chimera/src/phonetics/planner.rs:24, 88-108, 196-390 and 532-577\n * (the gestures and their timing), control/score.rs:273-430 and\n * voice/human_voice.rs:445 (how gestures blend), control/articulators.rs\n * (speeds), as summarized with file and line in data/vocal/\n * chimera-articulation.json. Reimplemented here; see\n * THIRD_PARTY_NOTICES.md. Changes from CHIMERA: it plans online, from\n * phonemes posted as they come (with the next ones posted early when the\n * caller knows them), instead of from a whole utterance; a phrase-initial\n * consonant starts moving 60 ms earlier; palatalization, trills and\n * nasalized vowels are not used (no bellows phoneme has them).\n *\n * GESTURES. A gesture holds some articulators at targets over [t0, t1],\n * with raised-cosine ramps ri before and ro after, at a strength. Each\n * control step every articulator's target is the strength-weighted mean of\n * the active gestures on it, with the performer's rest posture at weight\n * 0.05 (the velum is a bounded key: it moves toward the gestures' mean by\n * at most their summed weight over 2). So a consonant holds only the\n * articulators it dominates (strength 40), its other targets are weak\n * (2.2), and the tongue body keeps following the vowels: the vowel\n * gestures (strength 1) ramp in over most of the consonants before them\n * (anticipation) and out over part of those after (carryover), Ohman's\n * overlap. A gesture also speeds its articulators up by its manner's\n * speed while it can act (1.55 stops and nasals, 2.8 the tap, 2.0 and\n * 1.4 an affricate's closure and release, 1.3 the rest).\n *\n * CHANGES FOR THE ARTICULATOR CASCADE (dsp/cascade.ts, six stages where\n * CHIMERA has a critically damped pair; the 98 percent times are kept):\n * - each articulator sees every gesture CASCADE_LAG of its own 98 percent\n * time ahead (0.18 of it, 5 to 28 ms), the extra time the cascade takes\n * to pass half way, so sounds keep CHIMERA's times;\n * - a consonant's release is a return gesture (VocalTractLab 2.4): from\n * its gesture's end its articulators move at RETURN_SPEED for one whole\n * movement, whatever follows, where CHIMERA held the speed 45 ms;\n * - when two consonants hold an articulator at once, a closure wins over\n * any other constriction and then the more anterior place, and an\n * approach takes the articulator from a return;\n * - a bilabial closure aims at LIP_VIRTUAL, past the lips' contact (the\n * engine stops them at LIP_COMPRESSED), and closing consonants release\n * a few ms earlier than CHIMERA's (lips 25 ms before the next sound,\n * tip 24, body 39), since a pressed articulator takes longer to leave.\n *\n * ONLINE. A segment is a phoneme and its start in voice time. The caller\n * adds them as they become known: addUpcoming() for one posted early,\n * addNow() for one that starts now. Every addition rebuilds the gestures of\n * the segments still in reach, which is how a gesture that ends before the\n * next segment (a closure releases 20 to 34 ms early) or starts before its\n * own (a stop closes 22 to 31 ms early, a nasal lowers the velum 20 ms\n * early) gets the right times when segments are posted far enough ahead,\n * and the nearest ones otherwise. Posted 0.3 s ahead, the plan equals the\n * one built from the whole line at once.\n *\n * Nothing allocates after construction: segments and gestures live in\n * fixed arrays, and a full pool drops the oldest segment.\n */\n\nimport { CASCADE_ORDER, CASCADE_SETTLE_98, cascadeSettle } from '../dsp/cascade';\nimport { CRITDAMP_SETTLE_98 } from '../dsp/critdamp';\nimport { ARTICULATORS, ART, KEY_ABDUCTION, KEY_BREATH, KEY_CLOSURE, KEY_STIFFNESS } from './vocal-articulators';\nimport { VOCAL_ACOUSTICS, vocalPhonemeIndex } from './vocal-phonemes';\nimport { VOCAL_BEAT_BASE, VOCAL_SOUND_COUNT } from './vocal-beats';\nimport { writeBeatScore } from './vocal-beat-scores';\nimport {\n VOCAL_ARTICULATOR_HZ,\n VOCAL_ARTICULATOR_MAX,\n VOCAL_ARTICULATOR_MIN,\n VOCAL_BODIES,\n VOCAL_INVENTORY,\n VOCAL_NEUTRAL,\n VOCAL_TABLE_PHONEMES,\n} from './vocal-tables.gen';\n\n/* The glottal control keys live with the articulators' (vocal-articulators.ts); exported here too for older imports. */\nexport { KEY_ABDUCTION, KEY_CLOSURE, KEY_STIFFNESS, KEY_BREATH };\nconst KEYS = ARTICULATORS + 4;\n\n/**\n * The stiffness gesture of a voiceless obstruent ramps out over this many\n * seconds after its abduction ends. Hanson (2009, \"Effects of obstruent\n * consonants on fundamental frequency at vowel onset in English\", JASA 125)\n * and Lofqvist et al. (1989) put the raised f0 after voiceless obstruents\n * in the folds' tension (cricothyroid activity that helps hold them apart\n * against the flow), lasting into the first 50 to 100 ms of the vowel.\n */\nconst STIFF_RELEASE = 0.08;\n\nexport const VOCAL_TABLE_SIZE = VOCAL_TABLE_PHONEMES.length;\n\n/* Per-phoneme classes, as numbers. */\nconst M_SILENCE = 0;\nconst M_VOWEL = 1;\nconst M_STOP = 2;\nconst M_FRICATIVE = 3;\nconst M_AFFRICATE = 4;\nconst M_NASAL = 5;\nconst M_APPROXIMANT = 6;\nconst M_LATERAL = 7;\nconst M_TAP = 8;\nconst M_GLOTTAL = 9;\n/** A beatbox sound (engines/vocal-beats.ts): its gestures come from beat(), not from the tables. */\nconst M_BEAT = 10;\nconst MANNER_CODE: Record<string, number> = {\n silence: M_SILENCE,\n vowel: M_VOWEL,\n stop: M_STOP,\n fricative: M_FRICATIVE,\n affricate: M_AFFRICATE,\n nasal: M_NASAL,\n approximant: M_APPROXIMANT,\n lateral: M_LATERAL,\n tap: M_TAP,\n glottal: M_GLOTTAL,\n};\nconst PLACE_RANK: Record<string, number> = {\n bilabial: 0,\n labiodental: 1,\n dental: 2,\n alveolar: 3,\n postalveolar: 4,\n retroflex: 5,\n palatal: 6,\n velar: 7,\n uvular: 8,\n};\n\nconst COUNT = VOCAL_TABLE_SIZE;\nif (COUNT !== VOCAL_BEAT_BASE) throw new Error('vocal planner: the beats must follow the table phonemes');\n/* Per sound: the table phonemes, then the beats (each plain and accented). */\nconst SOUNDS = VOCAL_SOUND_COUNT;\nconst MANNER = new Uint8Array(SOUNDS);\nconst VOICED = new Uint8Array(SOUNDS);\nconst RANK = new Int8Array(SOUNDS).fill(-1);\nconst ALVEOLAR = new Uint8Array(SOUNDS);\nconst NASAL = new Uint8Array(SOUNDS);\n/** 0 none, 1 open (h), 2 stop (\u0294), 3 breathy. */\nconst GLOTTAL = new Uint8Array(SOUNDS);\nconst RELEASE = new Int16Array(SOUNDS).fill(-1);\n/** Bit a set if the phoneme dominates articulator a. */\nconst DOMINANT = new Int32Array(SOUNDS);\nconst BODY_ONLY = new Uint8Array(SOUNDS);\nconst LIPS_ONLY = new Uint8Array(SOUNDS);\nfor (let i = COUNT; i < SOUNDS; i++) MANNER[i] = M_BEAT;\n/* Schwa: the beat scores' ready posture. */\nconst P_SCHWA = VOCAL_TABLE_PHONEMES.indexOf('\u0259');\n/** The velar fricative [x], which the tables lack: /k/'s place with the dorsum this far down, by body (CHIMERA's inventory). */\nconst X_TBY = [7.365, 7.43, 7.499];\n/** A voiced stop's cavity enlargement: the larynx lowered and the root advanced from schwa's (INFERRED). */\nconst VOICED_EXPAND_LARYNX = 0.45;\nconst VOICED_EXPAND_ROOT = 0.35;\nfor (let i = 0; i < COUNT; i++) {\n const d = VOCAL_INVENTORY[i];\n MANNER[i] = MANNER_CODE[d.manner];\n VOICED[i] = d.voiced ? 1 : 0;\n RANK[i] = PLACE_RANK[d.place] ?? -1;\n ALVEOLAR[i] = d.place === 'alveolar' ? 1 : 0;\n NASAL[i] = d.nasal ? 1 : 0;\n GLOTTAL[i] = d.glottal === 'open' ? 1 : d.glottal === 'stop' ? 2 : d.glottal === 'breathy' ? 3 : 0;\n RELEASE[i] = d.release;\n let mask = 0;\n for (const a of d.dominant) mask |= 1 << a;\n DOMINANT[i] = mask;\n const body = (1 << ART.tbX) | (1 << ART.tbY) | (1 << ART.root);\n const lips = (1 << ART.lipAp) | (1 << ART.labiodental);\n BODY_ONLY[i] = mask !== 0 && (mask & ~body) === 0 ? 1 : 0;\n LIPS_ONLY[i] = mask !== 0 && (mask & ~lips) === 0 ? 1 : 0;\n}\n\n/** Whether table phoneme i is a vowel. */\nexport function vocalIsVowel(i: number): boolean {\n return MANNER[i] === M_VOWEL;\n}\n\nconst SEGMENTS = 32;\nconst GESTURES = 256;\nconst GESTURE_KEYS = 12;\n/** Two segments' starts closer than this are the same segment, seconds. */\nconst SAME = 0.003;\n/** Segments whose influence has certainly ended this long ago are dropped, seconds. */\nconst FORGET = 1.5;\n/**\n * A phrase-initial consonant starts this much earlier (the prototype's measured choice: a phrase-initial\n * /\u0283/ was 17 dB weak without it). Only the first: the rest of an onset cluster keeps its own time, or the\n * /t/ of /st\u0279/ held the tongue tip from 5 ms after the note-on, outranked the /s/ and left it silent\n * (MEASURED: 45 dB under CHIMERA's above 2.5 kHz, every body).\n */\nconst INITIAL_LEAD = 0.06;\n/** No consonant holds the articulator. */\nconst NO_RANK = 127;\n/** CHIMERA's rest-posture weight in the blend. */\nconst BASE_WEIGHT = 0.05;\n\nexport class VocalPlanner {\n /* Segments, in start order. */\n private readonly segIdx = new Int16Array(SEGMENTS);\n private readonly segT0 = new Float64Array(SEGMENTS);\n private segCount = 0;\n /** Whether a vowel was dropped off the front, so no remaining consonant is phrase-initial. */\n private droppedVowel = false;\n /** The end of the phrase (Infinity until known), voice seconds. */\n private end = Infinity;\n\n /* Gestures. */\n private readonly gT0 = new Float64Array(GESTURES);\n private readonly gT1 = new Float64Array(GESTURES);\n private readonly gRi = new Float64Array(GESTURES);\n private readonly gRo = new Float64Array(GESTURES);\n private readonly gStr = new Float64Array(GESTURES);\n private readonly gSpeed = new Float64Array(GESTURES);\n /** A consonant's return: how long after t1 + ro its speed holds, s. */\n private readonly gHold = new Float64Array(GESTURES);\n /** A consonant's return speed (0: none). */\n private readonly gRet = new Float64Array(GESTURES);\n /**\n * A consonant's priority on its articulators, lower first: a closure (stop,\n * nasal, an affricate's closure) at its place rank (0 bilabial .. 8\n * uvular), anything else at 16 plus it; -1 for a gesture that is not a\n * consonant's main one.\n */\n private readonly gRank = new Int8Array(GESTURES);\n /** How far ahead each key of a gesture is evaluated, s: its articulator's added lag in the cascade (0 for the glottis). */\n private readonly gLead = new Float64Array(GESTURES * GESTURE_KEYS);\n /** The smallest and largest of a gesture's leads, to skip or take whole a gesture no key of which is in a ramp. */\n private readonly gLeadMin = new Float64Array(GESTURES);\n private readonly gLeadMax = new Float64Array(GESTURES);\n private readonly gKeyCount = new Uint8Array(GESTURES);\n private readonly gKeys = new Uint8Array(GESTURES * GESTURE_KEYS);\n private readonly gVals = new Float64Array(GESTURES * GESTURE_KEYS);\n private gCount = 0;\n\n /* Targets blended for the body. */\n private readonly vowelT = new Float64Array(COUNT * ARTICULATORS);\n private readonly consT = new Float64Array(COUNT * ARTICULATORS);\n /* Scratch for a gesture being built. */\n private readonly kTmp = new Uint8Array(KEYS);\n private readonly vTmp = new Float64Array(KEYS);\n private nTmp = 0;\n\n /* Outputs of evaluate(). */\n /** Articulator targets, clamped to range. */\n readonly target = new Float64Array(ARTICULATORS);\n /** Speed factor per articulator, 1 at rest. */\n readonly speed = new Float64Array(ARTICULATORS);\n /** Glottal abduction from gestures (cm^2 before the body's k^2), closure 0 to 1, and fold stiffness 0 to 1. */\n abduction = 0;\n closure = 0;\n stiffness = 0;\n /** The breath, a factor on the note's lung pressure: 1 in speech and song, 0 between beats, negative drawn in. */\n breath = 1;\n /** Whether the evaluated time is in a beat line (the breath rests at 0 and moves fast). */\n beat = 0;\n /**\n * How fully a consonant holds each articulator at the evaluated time, 0 to 1 (the largest ramp\n * of any consonant gesture on it): a voice setting (vocal.ts) gives way where a consonant closes.\n */\n readonly held = new Float64Array(ARTICULATORS);\n /** The dorsum's height for [x] at this body. */\n /** The dorsum's height for [x] at this body (the beat scores' velar fricative). */\n xTbY = X_TBY[0];\n /** Scratch: a consonant's targets with a beat's overrides. */\n private readonly beatT = new Float64Array(ARTICULATORS);\n /** Inputs of evaluateNow() and queryNow(): the time and the rest tip. */\n at = 0;\n restX = 0;\n restY = 0;\n /** Outputs of queryNow(). */\n silent = 0;\n vowel = -1;\n private readonly wsum = new Float64Array(KEYS);\n private readonly vsum = new Float64Array(KEYS);\n /* Per articulator at the evaluated time: the first in priority of the consonants approaching it (rankA), fully under way on it (rankF) and returning from it (rankR), and the speeds of those approaching and returning. */\n private readonly rankA = new Int8Array(ARTICULATORS);\n private readonly rankF = new Int8Array(ARTICULATORS);\n private readonly rankR = new Int8Array(ARTICULATORS);\n private readonly speedA = new Float64Array(ARTICULATORS);\n private readonly speedR = new Float64Array(ARTICULATORS);\n\n constructor() {\n this.setBody(0);\n }\n\n /** Body 0 male to 2 child, continuous: targets blend linearly between neighbours. */\n setBody(body: number): void {\n const b = body > 0 ? (body < 2 ? body : 2) : 0;\n const lo = Math.floor(b) < 2 ? Math.floor(b) : 1;\n const w = b - lo;\n const A = VOCAL_BODIES[lo];\n const B = VOCAL_BODIES[lo + 1];\n this.xTbY = X_TBY[lo] * (1 - w) + X_TBY[lo + 1] * w;\n for (let p = 0; p < COUNT; p++) {\n for (let a = 0; a < ARTICULATORS; a++) {\n this.vowelT[p * ARTICULATORS + a] = A.vowelTargets[p][a] * (1 - w) + B.vowelTargets[p][a] * w;\n this.consT[p * ARTICULATORS + a] = A.consonantTargets[p][a] * (1 - w) + B.consonantTargets[p][a] * w;\n }\n }\n this.rebuild();\n }\n\n /** Forget everything: a new note. */\n clear(): void {\n this.segCount = 0;\n this.gCount = 0;\n this.droppedVowel = false;\n this.end = Infinity;\n }\n\n /**\n * Phoneme `idx` starts at voice time t, now: a segment posted early with\n * the same sound and time is confirmed, a repeat of the sounding segment\n * is ignored, and anything planned after t is dropped, since the caller\n * has gone another way.\n */\n addNow(idx: number, t: number): void {\n for (let s = 0; s < this.segCount; s++) {\n if (this.segIdx[s] === idx && Math.abs(this.segT0[s] - t) <= SAME) return;\n }\n const n = this.segCount;\n // a beat strikes again; a phoneme repeated is the same sound held\n if (n > 0 && this.segIdx[n - 1] === idx && this.segT0[n - 1] < t - SAME && MANNER[idx] !== M_BEAT) return;\n while (this.segCount > 0 && this.segT0[this.segCount - 1] >= t - SAME) this.segCount--;\n this.push(idx, t);\n this.rebuild();\n }\n\n /** Phoneme `idx` will start at voice time t. */\n addUpcoming(idx: number, t: number): void {\n for (let s = 0; s < this.segCount; s++) {\n if (Math.abs(this.segT0[s] - t) <= SAME) {\n this.segIdx[s] = idx;\n this.rebuild();\n return;\n }\n }\n this.push(idx, t);\n this.rebuild();\n }\n\n /** The phrase ends at voice time t (the note-off). */\n setEnd(t: number): void {\n this.end = t;\n while (this.segCount > 0 && this.segT0[this.segCount - 1] >= t) this.segCount--;\n this.rebuild();\n }\n\n /** Drop segments that can no longer matter at time t. */\n forget(t: number): void {\n let drop = 0;\n while (drop + 2 < this.segCount && this.segT0[drop + 2] < t - FORGET) drop++;\n if (drop === 0) return;\n for (let s = 0; s < drop; s++) if (MANNER[this.segIdx[s]] === M_VOWEL) this.droppedVowel = true;\n this.segIdx.copyWithin(0, drop, this.segCount);\n this.segT0.copyWithin(0, drop, this.segCount);\n this.segCount -= drop;\n this.rebuild();\n }\n\n private push(idx: number, t: number): void {\n if (this.segCount === SEGMENTS) {\n if (MANNER[this.segIdx[0]] === M_VOWEL) this.droppedVowel = true;\n this.segIdx.copyWithin(0, 1);\n this.segT0.copyWithin(0, 1);\n this.segCount--;\n }\n let at = this.segCount;\n while (at > 0 && this.segT0[at - 1] > t) at--;\n for (let s = this.segCount; s > at; s--) {\n this.segIdx[s] = this.segIdx[s - 1];\n this.segT0[s] = this.segT0[s - 1];\n }\n this.segIdx[at] = idx;\n this.segT0[at] = t;\n this.segCount++;\n }\n\n private t1(s: number): number {\n return s + 1 < this.segCount ? this.segT0[s + 1] : this.end;\n }\n\n /** The segment sounding at time t (the last to start at or before it), or -1. */\n segmentAt(t: number): number {\n let cur = -1;\n for (let s = 0; s < this.segCount; s++) {\n if (this.segT0[s] <= t) cur = s;\n else break;\n }\n return cur;\n }\n\n /** Phoneme of segment s. */\n phonemeOf(s: number): number {\n return this.segIdx[s];\n }\n\n /** The vowel sounding at t or the next one, as a table phoneme, or -1. */\n vowelAt(t: number): number {\n for (let s = 0; s < this.segCount; s++) {\n if (MANNER[this.segIdx[s]] === M_VOWEL && this.t1(s) > t) return this.segIdx[s];\n }\n return -1;\n }\n\n /** Whether the segment at t (or the first, before it) is a beat. */\n beatAt(t: number): boolean {\n const s = this.segmentAt(t);\n const i = s >= 0 ? s : this.segCount > 0 ? 0 : -1;\n return i >= 0 && MANNER[this.segIdx[i]] === M_BEAT;\n }\n\n /** Whether the segment at t is silence (the breath stops). */\n silentAt(t: number): boolean {\n const s = this.segmentAt(t);\n return s >= 0 && MANNER[this.segIdx[s]] === M_SILENCE;\n }\n\n /**\n * At the time in `at`: whether the breath stops (`silent`, 0 or 1) and\n * the vowel sounding or next (`vowel`, -1 for none). The audio path's\n * form of silentAt and vowelAt.\n */\n queryNow(): void {\n const t = this.at;\n let cur = -1;\n let vowel = -1;\n for (let s = 0; s < this.segCount; s++) {\n const r = this.segT0[s];\n const idx = this.segIdx[s];\n if (r <= t) cur = s;\n // t1(s) written out: a returned double crossing a call is boxed when V8 does not inline it\n const end = s + 1 < this.segCount ? this.segT0[s + 1] : this.end;\n if (vowel < 0 && MANNER[idx] === M_VOWEL && end > t) vowel = idx;\n }\n this.silent = cur >= 0 && MANNER[this.segIdx[cur]] === M_SILENCE ? 1 : 0;\n this.vowel = vowel;\n }\n\n /* ---------------------------------------------------------------- */\n /* Building gestures */\n /* ---------------------------------------------------------------- */\n\n begin(): void {\n this.nTmp = 0;\n }\n\n key(k: number, v: number): void {\n if (v !== v) return;\n this.kTmp[this.nTmp] = k;\n this.vTmp[this.nTmp] = v;\n this.nTmp++;\n }\n\n emit(t0: number, t1: number, ri: number, ro: number, str: number, speed: number): number {\n if (this.nTmp === 0 || this.gCount === GESTURES) return -1;\n const g = this.gCount++;\n this.gT0[g] = t0;\n this.gT1[g] = t1;\n this.gRi[g] = ri;\n this.gRo[g] = ro;\n this.gStr[g] = str;\n this.gSpeed[g] = speed;\n this.gHold[g] = 0;\n this.gRet[g] = 0;\n this.gRank[g] = -1;\n const n = this.nTmp < GESTURE_KEYS ? this.nTmp : GESTURE_KEYS;\n this.gKeyCount[g] = n;\n let lo = Infinity;\n let hi = -Infinity;\n for (let q = 0; q < n; q++) {\n const k = this.kTmp[q];\n this.gKeys[g * GESTURE_KEYS + q] = k;\n this.gVals[g * GESTURE_KEYS + q] = this.vTmp[q];\n // the cascade passes half way CASCADE_LAG of a 98 percent time later than CHIMERA's tracker did:\n // each articulator sees the gesture that much ahead, at the gesture's speed\n const lead = k < ARTICULATORS ? (CASCADE_LAG * CRITDAMP_SETTLE_98) / (2 * Math.PI * VOCAL_ARTICULATOR_HZ[k] * (speed > 0 ? speed : 1)) : 0;\n this.gLead[g * GESTURE_KEYS + q] = lead;\n if (lead < lo) lo = lead;\n if (lead > hi) hi = lead;\n }\n this.gLeadMin[g] = lo;\n this.gLeadMax[g] = hi;\n this.nTmp = 0;\n return g;\n }\n\n /** A consonant's oral gestures from its targets row (planner.rs:292-321, 532-577), returning at speed `ret`. */\n private oral(idx: number, row: number, a: number, b: number, speed: number, ret: number): void {\n const T = this.consT;\n const dom = DOMINANT[idx];\n const bodyOnly = BODY_ONLY[idx] === 1;\n const sp = bodyOnly ? 1 + (speed - 1) * 0.35 : speed;\n const m = MANNER[idx];\n const closing = m === M_STOP || m === M_NASAL || m === M_AFFRICATE;\n const lipsOnly = LIPS_ONLY[idx] === 1;\n const lead = closing ? (bodyOnly ? 0.039 : lipsOnly ? 0.025 : 0.024) : 0;\n const early = closing ? (bodyOnly ? 0.024 : lipsOnly ? 0.022 : 0.031) : 0.008;\n this.begin();\n const bilabial = closing && RANK[idx] === 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k)) this.key(k, bilabial && k === ART.lipAp ? LIP_VIRTUAL : T[row + k]);\n const g = this.emit(a - early, Math.max(a + 0.01, b - lead), 0.03, bodyOnly ? 0.03 : 0.018, 40, sp);\n if (g >= 0) {\n // the return gesture: the release at the consonant's own speed for a whole movement, whatever follows\n const rs = bodyOnly ? 1 + (ret - 1) * 0.35 : ret;\n let hz = 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k) && VOCAL_ARTICULATOR_HZ[k] > hz) hz = VOCAL_ARTICULATOR_HZ[k];\n this.gRet[g] = rs;\n this.gHold[g] = CRITDAMP_SETTLE_98 / (2 * Math.PI * (hz > 0 ? hz : 10) * rs);\n this.gRank[g] = (closing ? 0 : 16) + (RANK[idx] >= 0 ? RANK[idx] : 0);\n }\n const tbXSet = T[row + ART.tbX] === T[row + ART.tbX];\n const alveolar = ALVEOLAR[idx] === 1 && !tbXSet && (closing || m === M_FRICATIVE || m === M_TAP);\n if (alveolar) {\n this.begin();\n this.key(ART.tbX, 3.2);\n this.key(ART.tbY, 7.4);\n this.emit(a, b, 0.05, 0.05, 1.2, 0);\n }\n this.begin();\n let place = NaN;\n for (let k = 0; k < ARTICULATORS; k++) {\n if (dom & (1 << k)) continue;\n const v = T[row + k];\n if (v !== v) continue;\n if (bodyOnly && k === ART.tbX) place = v;\n else this.key(k, v);\n }\n this.emit(a, b, 0.05, 0.05, 2.2, 0);\n if (place === place) {\n this.begin();\n this.key(ART.tbX, place);\n this.emit(a, b, 0.05, 0.05, 0.25, 0);\n }\n }\n\n /** Rebuild every gesture from the segments (event rate). */\n private rebuild(): void {\n this.gCount = 0;\n const n = this.segCount;\n // vowels: Ohman overlap ramps (planner.rs:88-108)\n let prevVowel = -1;\n for (let s = 0; s < n; s++) {\n const idx = this.segIdx[s];\n if (MANNER[idx] !== M_VOWEL) continue;\n const t0 = this.segT0[s];\n const t1 = this.t1(s);\n let next = -1;\n for (let q = s + 1; q < n; q++) {\n if (MANNER[this.segIdx[q]] === M_VOWEL) {\n next = q;\n break;\n }\n }\n const prevEnd = prevVowel >= 0 ? this.t1(prevVowel) : t0 - 0.08;\n const ri = Math.max(0.03, 0.75 * (t0 - prevEnd)) + 0.01;\n const ro = next >= 0 ? Math.max(0.03, 0.4 * (this.segT0[next] - t1)) + 0.01 : 0.042;\n const row = idx * ARTICULATORS;\n this.begin();\n for (let k = 0; k < ARTICULATORS; k++) this.key(k, this.vowelT[row + k]);\n this.emit(t0, t1, ri, ro, 1, 0);\n prevVowel = s;\n }\n let firstVowel = n;\n if (!this.droppedVowel) {\n for (let s = 0; s < n; s++) {\n if (MANNER[this.segIdx[s]] === M_VOWEL) {\n firstVowel = s;\n break;\n }\n }\n } else firstVowel = -1;\n for (let s = 0; s < n; s++) {\n const idx = this.segIdx[s];\n const m = MANNER[idx];\n if (m === M_VOWEL || m === M_SILENCE) continue;\n if (m === M_BEAT) {\n const t1b = this.t1(s);\n writeBeatScore(this, idx - COUNT, this.segT0[s], t1b < Infinity ? t1b - this.segT0[s] : 0.25, s === 0);\n continue;\n }\n const before = this.gCount;\n const t0 = this.segT0[s];\n const t1 = this.t1(s);\n const dur = t1 - t0;\n const row = idx * ARTICULATORS;\n if (m === M_STOP) {\n // a stop closing behind another stop's closure, already placed, aims 25 ms later (planner.rs:299)\n let placed = false;\n if (s > 1) {\n const p = this.segIdx[s - 1];\n const bb = this.segIdx[s - 2];\n if (MANNER[p] === M_STOP && RANK[p] >= 0 && RANK[p] < RANK[idx]) {\n placed = true;\n const dom = DOMINANT[idx];\n for (let k = 0; k < ARTICULATORS; k++) {\n const v = this.consT[bb * ARTICULATORS + k];\n if (dom & (1 << k) && v !== v) placed = false;\n }\n }\n }\n this.oral(idx, row, placed ? t0 + Math.min(0.025, Math.max(0, dur - 0.03)) : t0, t1, 1.55, RETURN_SPEED[idx]);\n if (VOICED[idx] === 1) {\n // a voiced stop's closure enlarges the cavity behind it, so air keeps flowing through the\n // folds and the voicing lasts: the larynx lowers and the tongue root advances (Westbury\n // 1983, JASA 73, 1322-1336; Ohala's aerodynamic voicing constraint). The amounts are\n // INFERRED, gated on the voice bar (test/engines-physical/anatomy.test.ts)\n this.begin();\n this.key(ART.larynx, this.vowelT[P_SCHWA * ARTICULATORS + ART.larynx] - VOICED_EXPAND_LARYNX);\n this.key(ART.root, this.vowelT[P_SCHWA * ARTICULATORS + ART.root] + VOICED_EXPAND_ROOT);\n this.emit(t0 + 0.15 * dur, t1, 0.03, 0.04, 3, 0);\n }\n } else if (m === M_NASAL) this.oral(idx, row, t0, t1, 1.55, RETURN_SPEED[idx]);\n else if (m === M_TAP) this.oral(idx, row, t0, t1, 2.8, RETURN_SPEED[idx]);\n else if (m === M_AFFRICATE) {\n const split = t0 + dur * 0.55;\n this.oral(idx, row, t0, split, 2.0, RETURN_SPEED[idx]);\n const rel = RELEASE[idx];\n // the release part ends as its fricative does\n if (rel >= 0) this.oral(idx, rel * ARTICULATORS, split + 0.008, t1, 1.4, RETURN_SPEED[rel]);\n } else if (m === M_FRICATIVE || m === M_APPROXIMANT || m === M_LATERAL) this.oral(idx, row, t0, t1, 1.3, RETURN_SPEED[idx]);\n if (NASAL[idx]) {\n this.begin();\n this.key(ART.velum, 0.45);\n this.emit(t0 - 0.02, t1 - 0.02, 0.05, 0.03, 4, 0);\n }\n // phonation (planner.rs:329-358)\n const gl = GLOTTAL[idx];\n this.begin();\n if (gl === 1) {\n this.key(KEY_ABDUCTION, 0.33);\n this.emit(t0 - 0.01, t1, 0.03, 0.035, 5, 0);\n } else if (gl === 2) {\n this.key(KEY_CLOSURE, 1);\n this.emit(t0, t1, 0.012, 0.015, 8, 0);\n } else if (gl === 3) {\n this.key(KEY_ABDUCTION, 0.1);\n this.emit(t0, t1, 0.03, 0.03, 5, 0);\n } else if (VOICED[idx] === 0) {\n if (m === M_STOP || m === M_AFFRICATE) {\n const nextVowel = s + 1 < n && MANNER[this.segIdx[s + 1]] === M_VOWEL;\n const afterS = s > 0 && VOCAL_TABLE_PHONEMES[this.segIdx[s - 1]] === 's';\n const aspirated = nextVowel && !afterS;\n this.key(KEY_ABDUCTION, aspirated ? 0.36 : 0.22);\n // an aspirated release holds the glottis open for the stop's VOT (Lisker and Abramson 1964:\n // p 58, t 70, k 80 ms; src/sing.ts releases that much before the beat) less the 50 ms the\n // abduction's ramp out and the voicing gate add (MEASURED), at least CHIMERA's 20 ms\n const hold = aspirated ? Math.max(0.02, STOP_VOT[idx] - 0.05) : 0.0048;\n this.emit(t0 + 0.25 * dur, t1 + hold, 0.035, aspirated ? 0.045 : 0.02, 6, 0);\n this.stiffen(t0 + 0.25 * dur, t1 + hold + (aspirated ? 0.045 : 0.02));\n } else {\n this.key(KEY_ABDUCTION, 0.3);\n this.emit(t0 - 0.015, t1 + 0.005, 0.03, 0.03, 6, 0);\n this.stiffen(t0 - 0.015, t1 + 0.035);\n }\n } else if (m === M_FRICATIVE) {\n this.key(KEY_ABDUCTION, 0.035);\n this.emit(t0, t1, 0.03, 0.03, 3, 0);\n }\n if (s === 0 && s < firstVowel) {\n for (let g = before; g < this.gCount; g++) {\n const kc = this.gKeyCount[g];\n let glottal = false;\n for (let q = 0; q < kc; q++) if (this.gKeys[g * GESTURE_KEYS + q] >= KEY_ABDUCTION) glottal = true;\n if (glottal) continue;\n this.gT0[g] -= INITIAL_LEAD;\n this.gRi[g] += 0.5 * INITIAL_LEAD;\n }\n }\n }\n // the end of the breath group (planner.rs:383-389)\n if (this.end < Infinity) {\n const last = n > 0 ? this.segIdx[n - 1] : 0;\n const m = MANNER[last];\n const sonorant = m === M_VOWEL || m === M_NASAL || m === M_APPROXIMANT || m === M_LATERAL || m === M_TAP;\n this.begin();\n this.key(KEY_ABDUCTION, 0.22);\n this.emit(this.end + (sonorant ? 0.045 : 0.015), this.end + 0.1, 0.03, 0.06, 6, 0);\n }\n }\n\n /* ---------------------------------------------------------------- */\n /* Control rate */\n /* ---------------------------------------------------------------- */\n\n /**\n * Targets and speeds at time t, with the tip's rest position (when no\n * gesture holds the tip) given by the caller from the current jaw and\n * tongue body.\n */\n evaluate(t: number, restTipX: number, restTipY: number): void {\n this.at = t;\n this.restX = restTipX;\n this.restY = restTipY;\n this.evaluateNow();\n }\n\n /**\n * evaluate() at the time and rest tip in the fields `at`, `restX` and\n * `restY`: the audio path's form, so no double crosses the call.\n */\n evaluateNow(): void {\n const t = this.at;\n const restTipX = this.restX;\n const restTipY = this.restY;\n const wsum = this.wsum;\n const vsum = this.vsum;\n const speed = this.speed;\n const rankA = this.rankA;\n const rankR = this.rankR;\n const speedA = this.speedA;\n const speedR = this.speedR;\n wsum.fill(0);\n vsum.fill(0);\n const held = this.held;\n held.fill(0);\n const rankF = this.rankF;\n rankA.fill(NO_RANK);\n rankF.fill(NO_RANK);\n rankR.fill(NO_RANK);\n speedA.fill(1);\n speedR.fill(1);\n // which consonants hold each articulator: approaching (from the ramp's start to t1; fully from t0)\n // or returning (from t1, over the ramp out and the return). When two compete, a closure wins over\n // any other constriction, then the more anterior place\n for (let g = 0; g < this.gCount; g++) {\n const rank = this.gRank[g];\n if (rank < 0) continue;\n const lo = this.gT0[g] - this.gRi[g];\n const t1 = this.gT1[g];\n const last = t1 + this.gRo[g] + this.gHold[g];\n if (t + this.gLeadMax[g] <= lo || t + this.gLeadMin[g] > last) continue;\n const kc = this.gKeyCount[g];\n const base = g * GESTURE_KEYS;\n for (let q = 0; q < kc; q++) {\n const tg = t + this.gLead[base + q];\n if (tg <= lo || tg > last) continue;\n const approach = tg < t1;\n const sp = approach ? this.gSpeed[g] : this.gRet[g];\n const k = this.gKeys[base + q];\n if (approach) {\n if (rank < rankA[k] || (rank === rankA[k] && sp > speedA[k])) {\n rankA[k] = rank;\n speedA[k] = sp;\n }\n if (tg >= this.gT0[g] && rank < rankF[k]) rankF[k] = rank;\n } else if (rank < rankR[k] || (rank === rankR[k] && sp > speedR[k])) {\n rankR[k] = rank;\n speedR[k] = sp;\n }\n }\n }\n for (let i = 0; i < ARTICULATORS; i++) speed[i] = rankA[i] !== NO_RANK ? speedA[i] : rankR[i] !== NO_RANK ? speedR[i] : 1;\n for (let g = 0; g < this.gCount; g++) {\n const lo = this.gT0[g] - this.gRi[g];\n const t0 = this.gT0[g];\n const t1 = this.gT1[g];\n const ri = this.gRi[g] > 1e-6 ? this.gRi[g] : 1e-6;\n const ro = this.gRo[g];\n if (t + this.gLeadMax[g] <= lo || t + this.gLeadMin[g] >= t1 + ro) continue;\n const str = this.gStr[g];\n const rank = this.gRank[g];\n const kc = this.gKeyCount[g];\n const base = g * GESTURE_KEYS;\n // every key between the ramps: whole, with no cosine\n const whole = t + this.gLeadMin[g] >= t0 && t + this.gLeadMax[g] <= t1;\n for (let q = 0; q < kc; q++) {\n const tg = t + this.gLead[base + q];\n if (tg <= lo || tg >= t1 + ro) continue;\n const k = this.gKeys[base + q];\n // a consonant that outranks this one, fully under way on the same articulator, takes it\n if (rank >= 0 && tg < t1 && k < ARTICULATORS && rank > rankF[k]) continue;\n let act = 1;\n if (whole) {\n // act stays 1\n } else if (tg < t0) act = 0.5 - 0.5 * Math.cos((Math.PI * (tg - lo)) / ri);\n else if (tg > t1) act = 0.5 + 0.5 * Math.cos((Math.PI * (tg - t1)) / (ro > 1e-6 ? ro : 1e-6));\n const w = act * str;\n wsum[k] += w;\n vsum[k] += w * this.gVals[base + q];\n if (rank >= 0 && k < ARTICULATORS && act > held[k]) held[k] = act;\n // and the velum for any consonant (a beat's rank 30 aside): a nasal setting must not leak an\n // obstruent's pressure through the nose (MEASURED, 0.6.0: /p/ kept 24 percent of its pressure)\n if (rank >= 0 && rank < 30 && act > held[ART.velum]) held[ART.velum] = act;\n }\n }\n const target = this.target;\n for (let i = 0; i < ARTICULATORS; i++) {\n const base = i === ART.ttX ? restTipX : i === ART.ttY ? restTipY : NEUTRAL[i];\n let tgt = base;\n if (wsum[i] > 0) {\n if (i === ART.velum) tgt = base + Math.min(1, wsum[i] / 2) * (vsum[i] / wsum[i] - base);\n else tgt = (base * BASE_WEIGHT + vsum[i]) / (BASE_WEIGHT + wsum[i]);\n }\n target[i] = tgt;\n }\n const wa = wsum[KEY_ABDUCTION];\n this.abduction = wa > 0 ? (vsum[KEY_ABDUCTION] / wa) * Math.min(1, wa / 2) : 0;\n const wc = wsum[KEY_CLOSURE];\n this.closure = wc > 0 ? (vsum[KEY_CLOSURE] / wc) * Math.min(1, wc / 2) : 0;\n const ws = wsum[KEY_STIFFNESS];\n this.stiffness = ws > 0 ? (vsum[KEY_STIFFNESS] / ws) * Math.min(1, ws) : 0;\n // the breath: a beat line rests it at 0 (the beatboxer breathes only into a sound), speech at 1\n let cur = -1;\n for (let s = 0; s < this.segCount; s++) {\n if (this.segT0[s] <= t) cur = s;\n else break;\n }\n if (cur < 0 && this.segCount > 0) cur = 0;\n const inBeat = cur >= 0 && MANNER[this.segIdx[cur]] === M_BEAT;\n this.beat = inBeat ? 1 : 0;\n const rest = inBeat ? 0 : 1;\n const wb = wsum[KEY_BREATH];\n this.breath = wb > 0 ? (rest * BASE_WEIGHT + vsum[KEY_BREATH]) / (BASE_WEIGHT + wb) : rest;\n }\n\n /* ---------------------------------------------------------------- */\n /* Beats (engines/vocal-beats.ts) */\n /* ---------------------------------------------------------------- */\n\n /**\n * A consonant's oral gestures for a beat, from table phoneme `idx`'s targets with up to two\n * overrides (k1, v1 and k2, v2; -1 for none). `snap` > 0 releases at that speed over `snapRo`\n * (beatboxers snap their releases, the heavy dorsum too); `after` (not NaN) shortens every ramp\n * in, for a release fricative that must not pry the closure open early; `fric` makes a stop's\n * place a fricative ([x] from /k/); `noFront` leaves out the tongue body's alveolar fronting.\n */\n beatOral(\n idx: number,\n a: number,\n b: number,\n speed: number,\n snap: number,\n snapRo: number,\n after: number,\n fric: boolean,\n k1: number,\n v1: number,\n k2: number,\n v2: number,\n noFront: boolean,\n ): void {\n const src = this.consT;\n const row = idx * ARTICULATORS;\n const T = this.beatT;\n for (let k = 0; k < ARTICULATORS; k++) T[k] = k === k1 ? v1 : k === k2 ? v2 : src[row + k];\n const dom = DOMINANT[idx];\n const bodyOnly = BODY_ONLY[idx] === 1;\n const m = MANNER[idx];\n const closing = !fric && (m === M_STOP || m === M_NASAL || m === M_AFFRICATE);\n const lipsOnly = LIPS_ONLY[idx] === 1;\n const lead = closing ? (bodyOnly ? 0.039 : lipsOnly ? 0.025 : 0.024) : 0;\n const early = closing ? (bodyOnly ? 0.024 : lipsOnly ? 0.022 : 0.031) : 0.008;\n const ri = after === after ? Math.min(0.03, after) : 0.03;\n const sp = snap > 0 ? snap : bodyOnly ? 1 + (speed - 1) * 0.35 : speed;\n this.begin();\n const bilabial = closing && RANK[idx] === 0;\n for (let k = 0; k < ARTICULATORS; k++) {\n if (!(dom & (1 << k))) continue;\n this.key(k, bilabial && k === ART.lipAp && k1 !== ART.lipAp ? LIP_VIRTUAL : T[k]);\n }\n const ro = snap > 0 ? snapRo : bodyOnly ? 0.03 : 0.018;\n const g = this.emit(a - early, Math.max(a + 0.01, b - lead), ri, ro, 40, sp);\n if (g >= 0) {\n const rs = snap > 0 ? snap : RETURN_SPEED[idx];\n let hz = 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k) && VOCAL_ARTICULATOR_HZ[k] > hz) hz = VOCAL_ARTICULATOR_HZ[k];\n this.gRet[g] = rs;\n this.gHold[g] = CRITDAMP_SETTLE_98 / (2 * Math.PI * (hz > 0 ? hz : 10) * rs);\n this.gRank[g] = (closing ? 0 : 16) + (RANK[idx] >= 0 ? RANK[idx] : 0);\n }\n const tbXSet = T[ART.tbX] === T[ART.tbX];\n if (!noFront && ALVEOLAR[idx] === 1 && !tbXSet) {\n this.begin();\n this.key(ART.tbX, 3.2);\n this.key(ART.tbY, 7.4);\n this.emit(a, b, Math.min(0.05, ri + 0.02), 0.05, 1.2, 0);\n }\n this.begin();\n for (let k = 0; k < ARTICULATORS; k++) {\n if (dom & (1 << k)) continue;\n if (noFront && (k === ART.tbX || k === ART.tbY)) continue;\n const v = T[k];\n if (v === v) this.key(k, v);\n }\n this.emit(a, b, Math.min(0.05, ri + 0.02), 0.05, 2.2, 0);\n }\n\n /** Give gesture g a consonant's rank, so its speed governs its articulators coming and going (the beat scores). */\n rank(g: number, speed: number): void {\n this.gRank[g] = 30;\n this.gRet[g] = speed;\n this.gHold[g] = 0.02;\n }\n\n /** Schwa's target for articulator a at this body: the beat scores' ready posture. */\n schwaTarget(a: number): number {\n return this.vowelT[P_SCHWA * ARTICULATORS + a];\n }\n\n /** A cricothyroid stiffness gesture from t0, full until t1, ramping out over STIFF_RELEASE. */\n private stiffen(t0: number, t1: number): void {\n this.begin();\n this.key(KEY_STIFFNESS, 1);\n this.emit(t0, t1, 0.03, STIFF_RELEASE, 1, 0);\n }\n}\n\n/**\n * Each articulator's rate, 1 / tau of its six-stage cascade (dsp/cascade.ts),\n * per second: CHIMERA's natural frequencies (control/articulators.rs:23)\n * with the 98 percent time kept, t98 = 5.834 / w = 12.03 tau.\n */\nexport const ARTICULATOR_RATE = Float64Array.from(VOCAL_ARTICULATOR_HZ, (hz) => (2 * Math.PI * hz * CASCADE_SETTLE_98) / CRITDAMP_SETTLE_98);\n/**\n * How much later, as a fraction of the 98 percent time, the cascade passes\n * half way than CHIMERA's critically damped tracker with the same 98\n * percent time (0.471 against 0.288 of it). Gestures are evaluated this\n * much ahead so the sounds keep their times.\n */\nexport const CASCADE_LAG = cascadeSettle(CASCADE_ORDER, 0.5) / CASCADE_SETTLE_98 - cascadeSettle(2, 0.5) / CRITDAMP_SETTLE_98;\n/**\n * Each consonant's return (release) speed, a factor on its articulators'\n * rates like the approach speeds, after VocalTractLab 2.4's return\n * gestures (manual section 6.1): it governs the whole release movement, one\n * 98 percent time long, whatever vowel follows (CHIMERA held a consonant's\n * speed 45 ms past its ramp out and left the rest of the release to the\n * vowel's rate). Stops and nasals 1.55, an affricate's closure 2.0, the tap\n * 2.8, the rest 1.3: each its approach speed, which MEASURED keeps the\n * vowels' arrival (a glide released at 1 landed its vowel 8 ms later).\n */\nconst RETURN_SPEED = Float64Array.from(VOCAL_INVENTORY, (d) =>\n d.manner === 'stop' || d.manner === 'nasal' ? 1.55 : d.manner === 'tap' ? 2.8 : d.manner === 'affricate' ? 2.0 : 1.3,\n);\n/** Each table phoneme's VOT, s (0 for all but stops), from engines/vocal-phonemes.ts. */\nconst STOP_VOT = Float64Array.from(VOCAL_TABLE_PHONEMES, (ipa) => {\n const i = vocalPhonemeIndex(ipa);\n return i >= 0 ? VOCAL_ACOUSTICS[i].vot : 0;\n});\n/** The rest posture as doubles in a typed array (a plain array of mixed literals can box its reads). */\nconst NEUTRAL = Float64Array.from(VOCAL_NEUTRAL);\n/** Each articulator's range. */\nexport const ARTICULATOR_MIN = Float64Array.from(VOCAL_ARTICULATOR_MIN);\nexport const ARTICULATOR_MAX = Float64Array.from(VOCAL_ARTICULATOR_MAX);\n/**\n * The lips stop closing here (template cm of aperture, scaled by k in the\n * geometry): CHIMERA's closure target, the most the lips are compressed.\n */\nexport const LIP_COMPRESSED = -0.25;\n/**\n * A bilabial closure's virtual target, past LIP_COMPRESSED: the lips meet\n * moving near their fastest and compress (Lofqvist and Gracco 1997), and\n * the contact holds them while their motion carries on toward it.\n */\nexport const LIP_VIRTUAL = -1.0;\n/** The lowest target each articulator may be given: its range, but the lips may aim at LIP_VIRTUAL. */\nexport const ARTICULATOR_TARGET_MIN = Float64Array.from(VOCAL_ARTICULATOR_MIN, (v, i) => (i === ART.lipAp ? Math.min(v, LIP_VIRTUAL) : v));\n\n/** CHIMERA's rest tip for a jaw and tongue body (articulators.rs:110, anatomy/human.rs:443), into out[0], out[1]. */\n/** restTip() of the jaw and tongue body in an articulator array a: no double crosses the call. */\nexport function restTipFrom(a: Float64Array, out: Float64Array): void {\n const ang = -a[ART.jaw] / 9.84;\n const c = Math.cos(ang);\n const s = Math.sin(ang);\n out[0] = -2.5 + 8.95 * c + 3.15 * s + 0.3 * (a[ART.tbX] - 2.9);\n out[1] = 10.5 + 8.95 * s - 3.15 * c + 0.35 * (a[ART.tbY] - 6.85);\n}\n\nexport function restTip(jaw: number, tbX: number, tbY: number, out: Float64Array): void {\n const cx = -2.5;\n const cy = 10.5;\n const ang = -jaw / 9.84;\n const dx = 6.45 - cx;\n const dy = 7.35 - cy;\n const c = Math.cos(ang);\n const s = Math.sin(ang);\n out[0] = cx + dx * c - dy * s + 0.3 * (tbX - 2.9);\n out[1] = cy + dx * s + dy * c + 0.35 * (tbY - 6.85);\n}\n", "/*\n * One body's roof of the mouth (the velum from the uvula tip, then the hard\n * palate to the incisors) and the projections onto it that the voice's\n * contact rule uses: a tongue tip or body that presses more than 0.1 k cm\n * into the roof is pushed back along the contact normal (CHIMERA\n * human_voice.rs:520-552). Evaluated at every articulator step, so it is a\n * fixed polyline, not the full geometry.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49): the roof\n * polylines (extracted from anatomy/human.rs), the template-to-body\n * transform (human.rs:685) and the rule that keeps the tip outside the\n * tongue body (human.rs:828). Reimplemented here; see THIRD_PARTY_NOTICES.md.\n * Nothing here allocates after construction.\n */\n\nimport { ART } from './vocal-articulators';\nimport type { VocalBodyTable } from './vocal-tables.gen';\n\nexport class VocalRoof {\n readonly k: number = 0;\n readonly pharynxScale: number = 0;\n /** Tongue body radius, body cm. */\n readonly r: number = 0;\n private readonly roofX: Float64Array;\n private readonly roofY: Float64Array;\n /* project()'s input point and its results: the signed distance and the nearest roof point. */\n x = 0;\n y = 0;\n sd = 0;\n qx = 0;\n qy = 0;\n /* The tongue body's centre of the last bodyPoint(). */\n bx = 0;\n by = 0;\n /* The tip point of the last tipPoint(). */\n tipX = 0;\n tipY = 0;\n\n constructor(t: VocalBodyTable) {\n this.k = t.k;\n this.pharynxScale = t.pharynxScale;\n this.r = t.tongueRadius * t.k;\n this.roofX = Float64Array.from(t.roofX);\n this.roofY = Float64Array.from(t.roofY);\n }\n\n /** Template to body coordinates (human.rs:685). */\n px(x: number): number {\n return (x > 0.5 ? 0.5 + (x - 0.5) * 0.86 : x) * this.k;\n }\n py(y: number): number {\n return (y < 7 ? 7 - (7 - y) * this.pharynxScale : y) * this.k;\n }\n /** d(body x) / d(template x) and likewise for y, at a template point. */\n sx(x: number): number {\n return (x > 0.5 ? 0.86 : 1) * this.k;\n }\n sy(y: number): number {\n return (y < 7 ? this.pharynxScale : 1) * this.k;\n }\n\n /**\n * The signed distance from (x, y) (the fields) to the roof, positive below\n * it (in the airway), into sd, and the nearest roof point into qx, qy.\n * Inputs and results are fields, so no double crosses the call.\n */\n project(): void {\n const x = this.x;\n const y = this.y;\n let best = Infinity;\n let sgn = 1;\n const X = this.roofX;\n const Y = this.roofY;\n for (let i = 0; i + 1 < X.length; i++) {\n const ax = X[i];\n const ay = Y[i];\n const ex = X[i + 1] - ax;\n const ey = Y[i + 1] - ay;\n const l2 = ex * ex + ey * ey;\n let t = ((x - ax) * ex + (y - ay) * ey) / l2;\n t = t < 0 ? 0 : t > 1 ? 1 : t;\n const qx = ax + ex * t;\n const qy = ay + ey * t;\n const d = Math.sqrt((x - qx) * (x - qx) + (y - qy) * (y - qy));\n if (d < best) {\n best = d;\n sgn = ex * (y - ay) - ey * (x - ax) < 0 ? 1 : -1;\n this.qx = qx;\n this.qy = qy;\n }\n }\n this.sd = best * sgn;\n }\n\n /** The tongue body's centre in body coordinates, into bx, by. */\n bodyPoint(a: ArrayLike<number>): void {\n const tx = a[ART.tbX];\n const ty = a[ART.tbY];\n this.bx = (tx > 0.5 ? 0.5 + (tx - 0.5) * 0.86 : tx) * this.k;\n this.by = (ty < 7 ? 7 - (7 - ty) * this.pharynxScale : ty) * this.k;\n }\n\n /** The tip point in body coordinates, kept 1.05 r outside the tongue body, into tipX, tipY. */\n tipPoint(a: ArrayLike<number>): void {\n // px() and py() written out, so no double crosses a call\n const k = this.k;\n const ps = this.pharynxScale;\n const ax = a[ART.tbX];\n const ay = a[ART.tbY];\n const cx = a[ART.ttX];\n const cy = a[ART.ttY];\n const bx = (ax > 0.5 ? 0.5 + (ax - 0.5) * 0.86 : ax) * k;\n const by = (ay < 7 ? 7 - (7 - ay) * ps : ay) * k;\n let tx = (cx > 0.5 ? 0.5 + (cx - 0.5) * 0.86 : cx) * k;\n let ty = (cy < 7 ? 7 - (7 - cy) * ps : cy) * k;\n const d = Math.sqrt((tx - bx) * (tx - bx) + (ty - by) * (ty - by));\n if (d < 1.05 * this.r) {\n const s = (1.05 * this.r) / (d > 1e-9 ? d : 1e-9);\n tx = bx + (tx - bx) * s;\n ty = by + (ty - by) * s;\n }\n this.tipX = tx;\n this.tipY = ty;\n }\n}\n", "/*\n * From the tract's shape to the junction airway's inputs. The exact\n * geometry (engines/vocal-geometry.ts) is evaluated about every 10.7 ms, a\n * keyframe; between two keyframes the areas, sub-section minima, lengths,\n * incisors and velum port are interpolated block by block (MEASURED in the\n * geometry's prototype: 100 Hz with interpolation lies 0.05 dB from\n * evaluating every 2.7 ms over all frames, 0.33 dB over consonants, at a\n * quarter of the cost). Each block, the interpolated profile (pharynx then\n * oral sections, glottis to lips) is resampled onto the airway's grid in one\n * sweep:\n *\n * - the back duct takes up whatever the grid does not cover (at least\n * DUCT_MIN), its area the harmonic mean over it;\n * - each grid section's area is the harmonic mean of the profile over it,\n * and its minimum the smallest sub-section minimum of the profile\n * sections it overlaps, never above its own area (CHIMERA's jet rule);\n * - the incisors and the pharynx/oral split become grid positions, and the\n * labiodental articulator tells the airway whether a front constriction\n * is the lower lip's (a labiodental noise source) or the tongue's;\n * - the anatomical moving-wall flow: each profile section's volume change\n * over the block, as -dV/dt at its place on the grid, from the smoothed\n * profile the airway hears. It must not be differenced from grid areas: a\n * grid that slides along the anatomy is not a volume change (MEASURED in\n * the airway's prototype, a spurious 382 cm^3/s at one near-closure).\n * Differenced across the keyframe interval instead, it stepped every\n * 10.7 ms and ran ahead of the smoothed areas, and a tongue leaving the\n * roof pumped a sealed closure at 80 to 500 Hz.\n *\n * CHIMERA's area rate law (human_airway.rs:190-262) limits each keyframe's\n * sections against the last, as CHIMERA limits its own. Learned from\n * CHIMERA by Jameson Hodge (MIT, https://github.com/jamesondh/chimera-vocal-synth\n * at 1d3ea49); see THIRD_PARTY_NOTICES.md. Nothing here allocates after\n * construction, and no double crosses a call: the airway's inputs are its\n * fields.\n */\n\nimport { SOUND_SPEED } from '../dsp/air';\nimport { AreaSlew } from '../dsp/area-rate';\nimport { ductMin, type JunctionAirway } from '../dsp/junction-airway';\nimport { ART } from './vocal-articulators';\nimport { ChimeraGeometry } from './vocal-geometry';\n\nconst LABIODENTAL = ART.labiodental;\n\n/** Blocks per keyframe. */\nexport const VOCAL_KEY_BLOCKS = 16;\n/** The profile smoother's natural frequency, Hz (MEASURED choice: smooth release onsets, closures still sealed). */\nconst SMOOTH_HZ = 70;\n/** Most profile sections per tube. */\nconst MAX_TUBE = 40;\n\n/** CHIMERA's section counts for a body of scale k with pharynx factor ph, at its 96 kHz airway (human_airway.rs:75-80). */\nfunction tubeCounts(k: number, ph: number, out: Int32Array): void {\n const dxMin = SOUND_SPEED / 96000 / 0.93;\n const phMin = 8.7 * k * (0.55 + 0.45 * ph) - 1.6 * k;\n const orMin = 8.3 * k - 1.0 * k;\n out[0] = Math.min(MAX_TUBE, Math.max(8, Math.floor(phMin / dxMin)));\n out[1] = Math.min(MAX_TUBE, Math.max(8, Math.floor(orMin / dxMin)));\n}\n\n/** One evaluated shape. */\nclass Key {\n readonly ph = new Float64Array(MAX_TUBE);\n readonly or = new Float64Array(MAX_TUBE);\n readonly phMin = new Float64Array(MAX_TUBE);\n readonly orMin = new Float64Array(MAX_TUBE);\n phLen = 8.8;\n orLen = 8.3;\n teeth = 16;\n velum = 0;\n /** How far the lower lip forms the front constriction (the labiodental articulator, 0..1). */\n lab = 0;\n\n copy(s: Key): void {\n this.ph.set(s.ph);\n this.or.set(s.or);\n this.phMin.set(s.phMin);\n this.orMin.set(s.orMin);\n this.phLen = s.phLen;\n this.orLen = s.orLen;\n this.teeth = s.teeth;\n this.velum = s.velum;\n this.lab = s.lab;\n }\n}\n\nexport class VocalDrive {\n readonly geometry: ChimeraGeometry;\n private readonly prev = new Key();\n private readonly next = new Key();\n private readonly counts = new Int32Array(2);\n private nPh = 18;\n private nOr = 18;\n private readonly slew = new AreaSlew();\n /* The interpolated profile: edges (cm from the glottis), areas, minima, volumes and centres per section. */\n private readonly edge = new Float64Array(2 * MAX_TUBE + 1);\n private readonly prof = new Float64Array(2 * MAX_TUBE);\n private readonly pmin = new Float64Array(2 * MAX_TUBE);\n /*\n * The profile as it is heard: areas and minima through a critically damped two-pole at SMOOTH_HZ,\n * stepped once a block, so a release between two keyframes accelerates as articulators do instead\n * of opening at the area rate law's limit from its first block (MEASURED: a 61 dB step out of the\n * closure at the twinkle /k/, against CHIMERA's 26).\n */\n private readonly sProf = new Float64Array(2 * MAX_TUBE);\n private readonly vProf = new Float64Array(2 * MAX_TUBE);\n private readonly sMin = new Float64Array(2 * MAX_TUBE);\n private readonly vMin = new Float64Array(2 * MAX_TUBE);\n /*\n * The pharynx and oral lengths and the incisors through the same smoother, so the profile moves as\n * one: interpolated straight, a length's slope turned at every keyframe while the areas eased, and\n * the volume's rate (the wall flow) stepped there (MEASURED: 228 cm^3/s in one block at a /t/).\n */\n private readonly lenIn = new Float64Array(3);\n private readonly sLen = new Float64Array(3);\n private readonly vLen = new Float64Array(3);\n private sa = 1;\n private sb = 0;\n private sc = 0;\n private sd = 1;\n private snapped = true;\n /** -dV/dt per profile section over the last block, cm^3/s, and each section's volume then, cm^3. */\n private readonly dvdt = new Float64Array(2 * MAX_TUBE);\n private readonly vol = new Float64Array(2 * MAX_TUBE);\n private keyDt = 0.01;\n private readonly blockDt: number = 0;\n private readonly lbMin: number = 0;\n private readonly dx: number = 0;\n /** Fraction of the keyframe interval toAirway() reads, [0, 1]; a field, so no double crosses the call. */\n u = 0;\n\n constructor(rate: number) {\n this.dx = SOUND_SPEED / (2 * rate);\n this.lbMin = ductMin(rate);\n this.geometry = new ChimeraGeometry({\n scale: 1,\n pharynx: 1,\n tongueRadius: 2.25,\n lipWidth: 4.6,\n });\n const blockDt = Math.max(8, Math.round((32 * rate) / 48000)) / rate;\n this.blockDt = blockDt;\n this.keyDt = VOCAL_KEY_BLOCKS * blockDt;\n this.slew.setStep(this.keyDt);\n // the smoother's exact step over one block: [e', v'] = [[sa, sb], [sc, sd]] [e, v]\n const w = 2 * Math.PI * SMOOTH_HZ;\n const k = Math.exp(-w * blockDt);\n this.sa = (1 + w * blockDt) * k;\n this.sb = blockDt * k;\n this.sc = -w * w * blockDt * k;\n this.sd = (1 - w * blockDt) * k;\n }\n\n /** A body (scale, pharynx, tongue radius, lip width), at a note-on. Allocates nothing. */\n setBody(scale: number, pharynx: number, tongueRadius: number, lipWidth: number): void {\n this.geometry.setBody(scale, pharynx, tongueRadius, lipWidth);\n tubeCounts(scale, pharynx, this.counts);\n this.nPh = this.counts[0];\n this.nOr = this.counts[1];\n this.slew.setScale(scale);\n }\n\n /**\n * A new keyframe from the articulators a (17, CHIMERA's order): the last\n * becomes the start of the interval. snap: both ends are this shape (a\n * note's start), and nothing is rate limited.\n */\n key(a: Float64Array, snap: boolean): void {\n const g = this.geometry;\n const p = this.prev;\n const q = this.next;\n p.copy(q);\n g.evaluate(a);\n const nPh = this.nPh;\n const nOr = this.nOr;\n g.resampleInto(q.ph, q.or, q.phMin, q.orMin, nPh, nOr);\n q.phLen = g.phLen;\n q.orLen = g.orLen;\n q.teeth = g.teethS;\n q.velum = g.velumPort;\n const lab = a[LABIODENTAL];\n q.lab = lab < 0 ? 0 : lab > 1 ? 1 : lab;\n if (snap) {\n p.copy(q);\n this.snapped = true;\n } else {\n this.slew.limitAll(q.ph, p.ph, nPh);\n this.slew.limitAll(q.or, p.or, nOr);\n this.slew.limitAll(q.phMin, p.phMin, nPh);\n this.slew.limitAll(q.orMin, p.orMin, nOr);\n for (let i = 0; i < nPh; i++) if (q.phMin[i] > q.ph[i]) q.phMin[i] = q.ph[i];\n for (let i = 0; i < nOr; i++) if (q.orMin[i] > q.or[i]) q.orMin[i] = q.or[i];\n }\n }\n\n /**\n * The airway's inputs at fraction `u` of the keyframe interval: grid\n * areas and minima, the duct, the velum port, incisors, split and\n * moving-wall flow, written into `air`'s fields.\n */\n toAirway(air: JunctionAirway): void {\n const u = this.u;\n const w0 = 1 - u;\n const p = this.prev;\n const q = this.next;\n const nPh = this.nPh;\n const nOr = this.nOr;\n const c = nPh + nOr;\n const sa = this.sa;\n const sb = this.sb;\n const sc = this.sc;\n const sd = this.sd;\n const fresh = this.snapped;\n const li = this.lenIn;\n const sl = this.sLen;\n const vl = this.vLen;\n li[0] = p.phLen * w0 + q.phLen * u;\n li[1] = p.orLen * w0 + q.orLen * u;\n li[2] = p.teeth * w0 + q.teeth * u;\n for (let i = 0; i < 3; i++) {\n if (fresh) {\n sl[i] = li[i];\n vl[i] = 0;\n } else {\n const e = sl[i] - li[i];\n const v = vl[i];\n sl[i] = li[i] + sa * e + sb * v;\n vl[i] = sc * e + sd * v;\n }\n }\n const phLen = sl[0];\n const orLen = sl[1];\n const edge = this.edge;\n const prof = this.prof;\n const pmin = this.pmin;\n edge[0] = 0;\n for (let i = 0; i < nPh; i++) {\n prof[i] = p.ph[i] * w0 + q.ph[i] * u;\n pmin[i] = p.phMin[i] * w0 + q.phMin[i] * u;\n edge[i + 1] = ((i + 1) * phLen) / nPh;\n }\n for (let i = 0; i < nOr; i++) {\n prof[nPh + i] = p.or[i] * w0 + q.or[i] * u;\n pmin[nPh + i] = p.orMin[i] * w0 + q.orMin[i] * u;\n edge[nPh + i + 1] = phLen + ((i + 1) * orLen) / nOr;\n }\n // the smoother, one block per call\n const sp = this.sProf;\n const vp = this.vProf;\n const sm = this.sMin;\n const vm = this.vMin;\n if (fresh) {\n for (let i = 0; i < c; i++) {\n sp[i] = prof[i];\n sm[i] = pmin[i];\n vp[i] = 0;\n vm[i] = 0;\n }\n this.snapped = false;\n } else {\n for (let i = 0; i < c; i++) {\n let e = sp[i] - prof[i];\n let v = vp[i];\n sp[i] = prof[i] + sa * e + sb * v;\n vp[i] = sc * e + sd * v;\n e = sm[i] - pmin[i];\n v = vm[i];\n sm[i] = pmin[i] + sa * e + sb * v;\n vm[i] = sc * e + sd * v;\n }\n }\n // each section's volume change over the block, -dV/dt, as the areas the airway hears move\n const iDt = 1 / this.blockDt;\n const lPh = phLen / nPh;\n const lOr = orLen / nOr;\n const vol = this.vol;\n const dvdt = this.dvdt;\n for (let i = 0; i < c; i++) {\n const a = sp[i] > 0 ? sp[i] : 0;\n prof[i] = a;\n const m = sm[i] > 0 ? sm[i] : 0;\n pmin[i] = m < a ? m : a;\n const v = a * (i < nPh ? lPh : lOr);\n dvdt[i] = fresh ? 0 : -(v - vol[i]) * iDt;\n vol[i] = v;\n }\n const L = phLen + orLen;\n const n = air.nG;\n let lb = L - n * this.dx;\n if (lb < this.lbMin) lb = this.lbMin;\n const step = (L - lb) / n;\n // the duct: harmonic mean over [0, lb)\n let k = 0;\n {\n let inv = 0;\n while (k < c && edge[k] < lb) {\n const lo = edge[k];\n const hi = edge[k + 1] < lb ? edge[k + 1] : lb;\n if (hi > lo) inv += (hi - lo) / (prof[k] > 1e-6 ? prof[k] : 1e-6);\n if (edge[k + 1] > lb) break;\n k++;\n }\n air.ductLen = lb;\n air.ductArea = inv > 0 ? lb / inv : prof[0];\n }\n // the grid sections, one sweep\n const gridIn = air.gridIn;\n const gridMin = air.gridMin;\n for (let i = 0; i < n; i++) {\n const x0 = lb + i * step;\n const x1 = x0 + step;\n while (k < c - 1 && edge[k + 1] <= x0) k++;\n let inv = 0;\n let mn = Infinity;\n let q2 = k;\n while (q2 < c && edge[q2] < x1) {\n const lo = edge[q2] > x0 ? edge[q2] : x0;\n const hi = edge[q2 + 1] < x1 ? edge[q2 + 1] : x1;\n const a = prof[q2] > 1e-6 ? prof[q2] : 1e-6;\n if (hi > lo) inv += (hi - lo) / a;\n const m = pmin[q2] < a ? pmin[q2] : a;\n if (m < mn) mn = m;\n q2++;\n }\n const ga = inv > 0 ? step / inv : prof[c - 1];\n gridIn[i] = ga;\n gridMin[i] = mn < ga ? mn : ga;\n }\n // incisors and split as grid positions; the velum port\n const teeth = sl[2];\n air.teethX = (teeth - lb) / step;\n air.splitI = (phLen - lb) / step;\n air.velum = p.velum * w0 + q.velum * u;\n air.labial = p.lab * w0 + q.lab * u;\n // the moving-wall flow at each section's place, shared between the two nearest junctions so it\n // moves along the grid continuously as the tract does (snapped to one, it jumped between blocks)\n const vflow = air.vflow;\n for (let j = 0; j <= n; j++) vflow[j] = 0;\n for (let s = 0; s < c; s++) {\n let pos = (0.5 * (edge[s] + edge[s + 1]) - lb) / step;\n pos = pos < 0 ? 0 : pos > n ? n : pos;\n let j = Math.floor(pos);\n if (j >= n) j = n - 1;\n const f = pos - j;\n vflow[j] += (1 - f) * this.dvdt[s];\n vflow[j + 1] += f * this.dvdt[s];\n }\n }\n\n /** The tract length of the current interpolated shape, cm (for layout checks). */\n get length(): number {\n const u = this.u;\n return (this.prev.phLen + this.prev.orLen) * (1 - u) + (this.next.phLen + this.next.orLen) * u;\n }\n}\n"],
5
- "mappings": ";yVAMA,OAAS,kBAAAA,OAAsB,YC4F/B,OAAS,SAAAC,MAAa,YCxDtB,OAAS,SAAAC,OAAa,YAGf,IAAMC,GAAgB,EAGtB,SAASC,GAAcC,EAAeC,EAAW,IAAc,CACpE,IAAMC,EAAQC,GAAc,CAC1B,IAAIC,EAAO,EACPC,EAAM,EACV,QAASC,EAAI,EAAGA,EAAIN,EAAOM,IACzBF,GAAQD,EAAIG,EACZD,GAAOD,EAET,OAAO,KAAK,IAAI,CAACD,CAAC,EAAIE,CACxB,EACIE,EAAK,EACLC,EAAK,GAAKR,EAAQ,GACtB,QAASS,EAAK,EA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AAG,IAAKrB,GAAW,EAAG,QAAS,CAAE,CAC/D,EAEagJ,GAAyB,CACpC,GAAI,QACJ,MAAO,QACP,OAAQjG,GACR,UAAW,EACX,YAAa,CAACV,EAAY4G,EAAY3G,IAAQ,IAAIN,GAAWK,EAAY4G,EAAY3G,CAAG,CAC1F,EDp5BO,SAAS4G,IAAsB,CACpCC,GAAeC,EAAW,CAC5B",
6
- "names": ["registerEngine", "clamp", "clamp", "CASCADE_ORDER", "cascadeSettle", "order", "fraction", "tail", "u", "term", "sum", "k", "lo", "hi", "it", "mid", "CASCADE_SETTLE_98", "VALUE_LIMIT", "MIN_RATE", "MAX_RATE", "SETTLED", "CascadeBank", "channels", "stepRateHz", "i", "perSecond", "q", "seconds", "t", "target", "value", "v", "src", "at", "n", "b", "targets", "rates", "r", "x", "c", "goal", "base", "g", "big", "s", "j", "m", "Adsr", "CM_H2O", "WALL_TRACT", "WALL_CHEEK_RELAXED", "WALL_TRACHEA", "WALL_NASAL", "RHO_C", "VISC", "TUBE_RING", "MASK", "AirwayTube", "maxNodes", "ns", "m", "invD", "cm", "K", "z1", "g", "secAreas", "count", "nodesAt", "nn", "wall", "perim", "viscF", "dx", "rate", "s", "a0", "a1", "inv", "i", "beta", "hr", "best", "bd", "d", "al", "ar", "pos", "F", "B", "D", "Z", "wCm", "wK", "wIb", "T", "segL", "segR", "a", "b", "wv", "wy", "hist", "sg", "sh", "ue0", "gam", "u", "p", "v", "q", "evenNodes", "n", "inner", "out", "c", "RHO", "branchCoefficients", "M", "f0", "q", "rate", "w0", "wSet", "K", "R", "PIRIFORM_VOLUME", "PIRIFORM_DEPTH", "PIRIFORM_Q", "piriformBranch", "k", "depth", "area", "leff", "SINUS_VOLUME", "SINUS_NECK_AREA", "SINUS_NECK_LENGTH", "SINUS_Q", "sinusBranch", "v", "m", "AreaSlew", "k", "k2", "dt", "a", "u", "next", "prev", "d", "lim", "count", "openR", "sealR", "lo", "span", "ease", "i", "rate", "clamp", "UNIT_GAUSS", "HALF_PI", "S1", "S3", "S5", "S7", "S9", "S11", "S13", "S15", "sinQuarter", "x", "z", "INERTANCE", "INV_INERTANCE", "GAIN", "DRIFT_CONTROL_HZ", "DRIFT_BASE_HZ", "DRIFT_NORM", "MAX_DRIFT_CENTS", "FRY_HZ", "FRY_OQ", "FRY_OFFSET", "FRY_OQ_RATIO", "FRY_PEAK", "CHAOS_RESTART", "CHAOS_START_LO", "CHAOS_START_SPAN", "NO_CORNER", "MIN_HZ", "MAX_HZ_FRACTION", "MAX_JITTER", "pulse", "ph", "oq", "invOq", "skew", "invSkew", "invFall", "sharp", "t", "rising", "s", "s2", "GlottalSource", "sampleRate", "rng", "controlRate", "hz", "src", "i", "v", "r", "f", "cents", "fraction", "amount", "inc", "out", "from", "to", "a", "u", "h", "b", "fry", "amp", "weight", "slope", "end", "ts", "flowSlope", "mu", "alt", "chaosP", "chaosA", "chaos", "dev", "st", "u0", "u1", "q", "gp", "ga", "sc", "g0", "g1", "g2", "gs", "corners", "PI", "INV_PI", "TWO_OVER_PI", "TWO_PI", "GEO_AMPLITUDE", "ROOT_N", "ROOT_V", "ROOT_C", "k", "q", "r", "lo", "hi", "it", "mid", "v", "EDGE", "edgeInto", "a", "b", "x", "f", "cv", "u0", "F0", "GeometricGlottis", "src", "out", "from", "to", "n", "inv", "r1a", "r2a", "cha", "xma", "dr1", "dr2", "dch", "dxm", "twoL", "s", "peak", "rise", "fall", "lag", "d", "dh", "a1", "a2", "i", "w", "xm", "ph", "phi", "s1", "TWO_PI", "ph2", "odd2", "amp2", "s2", "ch", "EDGE", "edgeInto", "CENTS_PER_NEPER", "MAX_RATIO", "FAR_RUN", "PitchServo", "m", "ratio", "lost", "side", "lr", "lp", "same", "a", "b", "cents", "g", "M1", "M2", "K1", "K2", "KC", "ZETA1", "ZETA2", "D1", "D2", "HIT", "HIT_ZETA", "FOLD_F_REF", "MIN_Q", "DEPTH", "TUNE_DEPTH", "VOICED_GAP", "ONSET_S", "MAX_Q", "FoldOscillator", "PitchServo", "rate", "q", "k", "raw", "qk", "qm", "L", "twoL", "r1", "r2", "x1", "x2", "o1", "c1", "f1", "o2", "c2", "f2", "a1", "a2", "ps", "pe", "p1", "p2", "r", "free", "k1", "k2", "kc", "m1", "m2", "dt", "F1", "F2", "bb1", "bb2", "v1", "v2", "ch", "ar", "lv", "t", "period", "swing", "mean", "deep", "THRESHOLD_FLOOR", "THRESHOLD_SLOPE", "CM_H2O", "OFFSET_RATIO", "ONSET_TAU", "OFFSET_TAU", "PhonationThreshold", "dt", "xi", "onset", "p", "d", "target", "c", "GLOTTIS_GEOMETRIC", "GLOTTIS_SELF_OSCILLATING", "GLOTTIS_PULSE", "RHO", "RHOC", "IRHOC", "SRHOC", "VISC", "CLOSED", "OUTPUT_GAIN", "LIN_EPS", "MOVE_REL", "NSRC", "SRC_ASP", "SRC_VEL", "TAPS", "MOD_RING", "G_WALL", "G_OBSTACLE", "G_LABIAL", "G_LIPS", "D_FREE", "G_FREE", "GAIN_SCALE", "G_ASPIRATION", "G_ASPIRATION_VOICED", "ASPIRATION_VOICED_K", "RE_PER_VSA", "RE_LO", "RE_SPAN", "VC_HZ", "VSLOW_HZ", "FC_LINGUAL", "P2_HZ", "CONSTRICTED", "RUN_TOL", "D_WALL_LO", "D_WALL_HI", "D_LABIAL", "WALL_DOWN", "LABIAL_DOWN", "ASPIRATION_AT", "CONVECT", "TAU_MAX", "MOD_MAX", "GLOTTIS_DEPTH", "GLOTTIS_SLIT", "GLOTTIS_KIN", "VELUM_LEN", "VELUM_KIN", "VELUM_EXIT", "OUTPUT_HP", "MIC_R", "MIC_LOW_CUT", "OUTPUT_LP", "DVDT_HZ", "TRACHEA_NODES", "NASAL_NODES", "DUCT_MIN", "WALL_RADIATION", "ductMin", "rate", "dx", "BACK_FREE", "BACK_SPAN", "OPEN_FREE", "OPEN_SPAN", "AREA_BLOCK", "GlottalSource", "JunctionAirway", "GeometricGlottis", "AreaSlew", "TUBE_RING", "nMax", "rng", "nj", "WALL_TRACT", "AirwayTube", "FoldOscillator", "PhonationThreshold", "fc", "K", "q", "norm", "k", "n", "jv", "k2", "sec", "nodes", "nTr", "i", "nn", "evenNodes", "WALL_TRACHEA", "nNa", "u", "a", "extra", "e", "c", "WALL_NASAL", "sb", "sinusBranch", "pc", "piriformBranch", "ch", "split", "m", "WALL_CHEEK_RELAXED", "r", "kk", "first", "blk", "nG", "area", "dArea", "grid", "gmn", "dt", "s", "want", "shut", "nm", "d", "rel", "mt", "dm", "relm", "z", "njm", "sl", "sr", "mv", "al", "ar", "ef", "eb", "cf", "cb", "zl", "zr", "am", "sw", "gw", "gam", "bq", "raw", "j", "to", "a1", "a2", "wv", "tau", "da", "sz", "closure", "st", "c30", "thr", "CM_H2O", "pg", "ag0", "agate", "model", "effort", "dpMean", "paMean", "buf", "inv", "last", "w", "av", "ag", "g", "L", "chink", "rest", "x1", "x2", "th", "p", "GEO_AMPLITUDE", "f", "back", "bc", "bk", "ac", "ab", "per", "on", "VOICED_GAP", "pl", "tapW0", "tapW1", "b", "x", "t", "runLo", "runHi", "conLo", "conHi", "cut", "nr", "mn", "mi", "free", "lim", "lo", "hi", "used", "exit", "best", "bd", "fresh", "cmd", "dk", "lab", "lip", "past", "labio", "lips", "wf", "ob", "v", "wo", "f2", "dObs", "ds", "vo", "ga", "vel", "add", "outL", "outR", "at", "count", "off", "env", "T", "iT", "R", "sZ", "isZ", "Zs", "U", "pn", "kf", "kb", "rv", "viscC", "wallK", "gwA", "wV", "wY", "wS", "moving", "jmList", "gamA", "ibA", "bqA", "dv1", "dv2", "dvc", "aMin", "dAMin", "iaMin", "wIbsA", "wCmA", "wKsA", "pJ", "pG", "pCm", "pK", "pDi", "pQ", "pY", "pP", "fBuf", "bBuf", "tr", "na", "areaBuf", "folds", "selfOsc", "visc0", "ldG", "gain", "micK", "micC", "lungZ", "trLast", "trSegF", "trD", "trZ", "trA", "ring", "tapJ", "cVc", "cVs", "noiseScale", "voi", "vMax", "wallRad", "mm", "isz", "pL", "rp", "nt", "as", "af", "vr", "vf", "rb", "td", "ti", "tf", "vd", "lev", "s3", "mw", "nl1", "nl2", "nl", "sa", "tu", "ls", "dF", "i0", "hm1", "h0", "h1", "h2", "pos", "zt", "p0", "ductSZ", "zb", "ia", "lg", "rg", "exf", "exb", "kin", "kfg", "kbg", "m0", "cc", "pBelow", "pAbove", "ib", "eps", "ws", "hist", "wib", "ph", "d1", "d2", "ue0", "qn", "zd", "rad", "mf", "mh", "o", "hp", "y", "lr", "rr", "ul", "lp", "h", "pOld", "src", "ul2", "ur", "z1", "z2", "z3", "c3", "ue", "kfr", "kbr", "bqr", "cr0", "uv", "ip", "lv", "rvv", "amin", "kfv", "kbv", "bqv", "cv0", "it", "BEAT_ID", "id", "VOCAL_BEATS", "b", "B_KICK", "B_HAT", "B_OPEN_HAT", "B_SNARE", "B_RIM", "B_INWARD", "B_CLICK", "B_POP", "B_CRASH", "B_HUM", "B_CHAT", "B_PSH", "B_IN", "KICK_TBY", "EJECTIVE_PUSH", "BREATH_IN", "BREATH_IN_GLOTTIS", "P_P", "VOCAL_TABLE_PHONEMES", "P_T", "P_K", "P_S", "P_F", "P_SH", "P_M", "writeBeatScore", "w", "slot", "h", "len", "first", "accent", "hum", "k", "ARTICULATORS", "ART", "v", "NaN_", "artic", "ejective", "fric", "end", "blow", "pf", "KEY_ABDUCTION", "KEY_BREATH", "g", "t0", "t1", "ri", "ro", "speed", "at", "KEY_CLOSURE", "level", "abduction", "tail", "KEYS", "ARTICULATORS", "STIFF_RELEASE", "VOCAL_TABLE_SIZE", "VOCAL_TABLE_PHONEMES", "M_SILENCE", "M_VOWEL", "M_STOP", "M_FRICATIVE", "M_AFFRICATE", "M_NASAL", "M_APPROXIMANT", "M_LATERAL", "M_TAP", "M_GLOTTAL", "M_BEAT", "MANNER_CODE", "PLACE_RANK", "COUNT", "VOCAL_BEAT_BASE", "SOUNDS", "VOCAL_SOUND_COUNT", "MANNER", "VOICED", "RANK", "ALVEOLAR", "NASAL", "GLOTTAL", "RELEASE", "DOMINANT", "BODY_ONLY", "LIPS_ONLY", "i", "P_SCHWA", "X_TBY", "VOICED_EXPAND_LARYNX", "VOICED_EXPAND_ROOT", "d", "VOCAL_INVENTORY", "mask", "a", "body", "ART", "lips", "SEGMENTS", "GESTURES", "GESTURE_KEYS", "SAME", "FORGET", "INITIAL_LEAD", "NO_RANK", "BASE_WEIGHT", "VocalPlanner", "COUNT", "ARTICULATORS", "KEYS", "X_TBY", "body", "b", "lo", "w", "A", "VOCAL_BODIES", "B", "p", "a", "idx", "s", "n", "MANNER", "M_BEAT", "t", "drop", "M_VOWEL", "at", "cur", "M_SILENCE", "vowel", "r", "end", "k", "v", "t0", "t1", "ri", "ro", "str", "speed", "g", "hi", "q", "lead", "CASCADE_LAG", "CRITDAMP_SETTLE_98", "VOCAL_ARTICULATOR_HZ", "row", "ret", "T", "dom", "DOMINANT", "bodyOnly", "BODY_ONLY", "sp", "m", "closing", "M_STOP", "M_NASAL", "M_AFFRICATE", "lipsOnly", "LIPS_ONLY", "early", "bilabial", "RANK", "ART", "LIP_VIRTUAL", "rs", "hz", "tbXSet", "ALVEOLAR", "M_FRICATIVE", "M_TAP", "place", "prevVowel", "next", "prevEnd", "firstVowel", "t1b", "writeBeatScore", "before", "dur", "placed", "bb", "RETURN_SPEED", "VOICED", "P_SCHWA", "VOICED_EXPAND_LARYNX", "VOICED_EXPAND_ROOT", "split", "rel", "RELEASE", "M_APPROXIMANT", "M_LATERAL", "NASAL", "gl", "GLOTTAL", "KEY_ABDUCTION", "KEY_CLOSURE", "nextVowel", "afterS", "VOCAL_TABLE_PHONEMES", "aspirated", "hold", "STOP_VOT", "kc", "glottal", "last", "sonorant", "restTipX", "restTipY", "wsum", "vsum", "rankA", "rankR", "speedA", "speedR", "held", "rankF", "rank", "base", "tg", "approach", "i", "whole", "act", "target", "NEUTRAL", "tgt", "wa", "wc", "ws", "KEY_STIFFNESS", "inBeat", "rest", "wb", "KEY_BREATH", "snap", "snapRo", "after", "fric", "k1", "v1", "k2", "v2", "noFront", "src", "STIFF_RELEASE", "ARTICULATOR_RATE", "CASCADE_SETTLE_98", "cascadeSettle", "CASCADE_ORDER", "VOCAL_INVENTORY", "d", "ipa", "vocalPhonemeIndex", "VOCAL_ACOUSTICS", "VOCAL_NEUTRAL", "ARTICULATOR_MIN", "VOCAL_ARTICULATOR_MIN", "ARTICULATOR_MAX", "VOCAL_ARTICULATOR_MAX", "LIP_COMPRESSED", "ARTICULATOR_TARGET_MIN", "restTipFrom", "out", "ang", "c", "VocalRoof", "t", "x", "y", "best", "sgn", "X", "Y", "i", "ax", "ay", "ex", "ey", "l2", "qx", "qy", "d", "a", "tx", "ART", "ty", "k", "ps", "cx", "cy", "bx", "by", "s", "LABIODENTAL", "ART", "VOCAL_KEY_BLOCKS", "SMOOTH_HZ", "MAX_TUBE", "tubeCounts", "k", "ph", "out", "dxMin", "phMin", "orMin", "Key", "VocalDrive", "AreaSlew", "rate", "ductMin", "ChimeraGeometry", "blockDt", "w", "scale", "pharynx", "tongueRadius", "lipWidth", "a", "snap", "g", "p", "q", "nPh", "nOr", "lab", "i", "air", "u", "w0", "c", "sa", "sb", "sc", "sd", "fresh", "li", "sl", "vl", "e", "v", "phLen", "orLen", "edge", "prof", "pmin", "sp", "vp", "sm", "vm", "iDt", "lPh", "lOr", "vol", "dvdt", "m", "L", "n", "lb", "step", "inv", "lo", "hi", "gridIn", "gridMin", "x0", "x1", "mn", "q2", "ga", "teeth", "vflow", "j", "s", "pos", "f", "PHONEMES", "VOCAL_SOUND_COUNT", "OPEN_MAX", "STIFF_CENTS", "STIFF_SWING", "COUPLE", "EAR_TAU", "FOLD_LENGTH", "FOLD_REST", "SELF_REST", "FOLD_UPPER", "FOLD_LAG", "FOLD_SKEW", "FOLD_DOUBLE", "PRESS", "OUTPUT_GAIN", "VIBRATO_FADE", "MIN_HZ", "STEPS", "VOCAL_KEY_BLOCKS", "LIP_WIDTH", "DEFAULTS", "VOCAL_GLIDE_DEFAULTS", "initial", "params", "spec", "v", "gridSections", "rate", "minLength", "dx", "ductMin", "VocalVoice", "VocalPlanner", "ARTICULATORS", "VOCAL_DEFAULT_PHONEME", "GLOTTIS_PULSE", "sampleRate", "rng", "VOCAL_BODIES", "t", "VocalRoof", "JunctionAirway", "VocalDrive", "CascadeBank", "PitchGlide", "Adsr", "PARAMS", "freq", "vel", "clamp", "name", "value", "vocalGlideSpeed", "vocalDamping", "m", "GLOTTIS_SELF_OSCILLATING", "GLOTTIS_GEOMETRIC", "idx", "b", "outL", "outR", "from", "to", "air", "blk", "i", "left", "n", "eb", "A", "B", "w", "lo", "base", "k", "ps", "pharynx", "tongue", "lips", "neutralPharynx", "lb", "jv", "bank", "VOCAL_NEUTRAL", "pass", "q", "restTipFrom", "p", "tg", "ring", "tj", "ART", "so", "held", "ARTICULATOR_TARGET_MIN", "ARTICULATOR_MAX", "settingOffsets", "k2", "art", "ARTICULATOR_RATE", "LIP_COMPRESSED", "roof", "lim", "a", "ix", "iy", "sd", "depth", "nx", "ny", "len", "s", "val", "ax", "ay", "sx", "sy", "pl", "sr", "drive", "sf", "s0", "s1", "fr", "stiff", "lung", "beatLine", "bend", "bt", "up", "down", "ph", "vib", "f0", "pa", "CM_H2O", "gate", "tau", "slope", "r1", "jaw", "need", "room", "vocalEngine", "initParams", "registerVoice", "registerEngine", "vocalEngine"]
4
+ "sourcesContent": ["/*\n * The voice on the calling thread, for renderOffline() and Node, where no worklet runs it. A page\n * that plays through bellows' worklet does not need this: the plugin (plugin.ts) carries the\n * engine there, and importing this module is what puts a second copy of the DSP in a bundle.\n */\n\nimport { registerEngine } from 'bellowsjs';\nimport { vocalEngine } from './engines/vocal';\n\n/** Register the 'vocal' engine on this thread, for renderOffline(). */\nexport function registerVoice(): void {\n registerEngine(vocalEngine);\n}\n", "/*\n * Vocal: a singing voice built as an articulatory synthesizer. A sung\n * line's phonemes move CHIMERA's 17 articulators, CHIMERA's exact geometry\n * turns them into the tract's shape, and the junction airway (a waveguide\n * that carries the air itself: pressure behind closures, bursts, voice bars\n * and turbulence all come out of its flow) makes the sound.\n * docs/VOICE-2.md is the design and the measurements behind it.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49): the\n * articulators and their speeds (control/articulators.rs), the planner\n * (phonetics/planner.rs, engines/vocal-planner.ts), the geometry\n * (anatomy/human.rs, engines/vocal-geometry.ts), the airway's elements\n * (airway/network.rs, voice/human_airway.rs, dsp/junction-airway.ts), the\n * contact rule (voice/human_voice.rs:520-552) and the sung breath\n * (phonetics/planner.rs:376-379). Reimplemented here; see\n * THIRD_PARTY_NOTICES.md. The singer rules come from the literature: pitch\n * overshoot and preparation (Saitou, Unoki and Akagi 2005), the singer's\n * formant (Sundberg), first-resonance tuning on high notes (Joliveau,\n * Smith and Wolfe 2004). So do the parts that replaced CHIMERA's: the\n * articulators move as a six-stage cascade with return gestures (Birkholz\n * 2011, Birkholz and Hoole 2012, VocalTractLab 2.4's manual); the pitch\n * rise after a voiceless obstruent is a fold stiffness gesture (Hanson\n * 2009); the two fold models follow Titze and Birkholz, Drechsel and Stone\n * (2019) and Ishizaka and Flanagan (1972); the turbulence follows Stevens'\n * law with Birkholz's (2014) source types and places; the tract wall is\n * Birkholz and Zhang's (2025) stiffness and damping. docs/VOICE-2.md,\n * \"Integration 4\", measures them together.\n *\n * THE LAYERS, AND HOW OFTEN EACH RUNS (48 kHz)\n *\n * planner every 64 samples: gestures to articulator targets\n * articulators every 64: a six-stage cascade bank, then the contacts\n * geometry every 512 (a keyframe): the exact shape, rate limited\n * drive every 32: the shape between keyframes onto the grid\n * pitch every 32: glide, vibrato, microprosody, pressure\n * airway every sample\n *\n * The grids scale with the rate (block = 32 samples at 48 kHz, the\n * articulators every 2 blocks, the geometry every 16). The articulators\n * run to the end of each keyframe interval before it is heard, and the\n * glottal opening they set is read back at each block's own time, so no\n * layer leads the sound.\n *\n * EVENTS. `phoneme` starts a sound now. `nextPhoneme` says a sound will\n * start `nextIn` seconds from now (post `nextIn` first, then\n * `nextPhoneme`): the planner then starts its gestures before the sound\n * (a stop closes 22 to 31 ms early, a nasal lowers the velum 20 ms early,\n * the next vowel ramps in through the consonants before it) and releases a\n * closure before the next sound, as CHIMERA plans a whole utterance.\n * src/sing.ts posts every sound VOCAL_PLAN_LEAD ahead this way and then\n * again on its time as `phoneme`, which confirms it; a `phoneme` alone\n * still works, with gestures that start when it arrives. `bend` moves the\n * pitch through the glide; sing() posts it vocalGlideLead() early so the\n * glide is half way at the note.\n *\n * A note-on starts from rest: the planner's targets for the opening sound\n * are snapped to, the breath starts at 94 percent of its pressure (where\n * CHIMERA's sung breath, opening 70 ms before the first sound, is when it\n * sounds), every wave and state is cleared, so a reused voice equals a\n * fresh one. Events at the note-on's instant, before any sample, snap the\n * same way. A released voice keeps the sound it was released on.\n *\n * PARAMETERS THAT CHANGED MEANING FROM THE FORMANT VOICE\n *\n * glide the time scale of a pitch change: the glide's natural\n * frequency is 5.834 / (2 pi glide) Hz (98 percent in `glide`\n * at overshoot 0). Default 0.17 s, about 5.5 Hz, which with\n * the default overshoot puts a note change half way 46 ms in.\n * tension the glottal pulse's tension at velocity 0.8; velocity adds\n * 0.35 per unit above 0.8. Default 0.55.\n * breath CHIMERA's breathiness: the glottis rests open by\n * 0.1 breath^2 k^2 cm^2 plus a chink of (0.008 + 0.03 breath)\n * k^2, and aspiration follows from the flow through it.\n * body continuous from 0 (male) through 1 (female) to 2 (child):\n * targets, tables and the geometry's body constants blend\n * between neighbours. The airway's layout is set at note-on.\n * articulation multiplies every articulator's speed.\n * velocity sets lung pressure, 4 + 6.25 vel cmH2O held to 5 to 15\n * (9 at 0.8, CHIMERA's default), so a louder note is also\n * brighter and more pressed. It scales the output only under\n * 0.2, linearly to silence at 0.\n *\n * NEW: overshoot (fraction of an interval the glide passes its note by),\n * preparation (how far it first moves the wrong way), ring (the singer's\n * formant: epilarynx narrowed, larynx lowered, tongue root forward),\n * tuning (open the jaw so the first resonance stays above 1.15 f0),\n * nextPhoneme and nextIn (above), glottis (the fold model: 0 geometric,\n * dsp/geometric-glottis.ts; 1 self-oscillating, dsp/fold-oscillator.ts;\n * 2 CHIMERA's drawn pulse, the default; a sounding voice changes at its\n * next note; docs/VOICE-2.md, \"Vocal folds\", has the measurements).\n *\n * Randomness: forks 'glottis' and 'noise' (in the airway: the fold pulse's\n * perturbations, and one turbulence seed drawn per note) and 'vibrato' (the\n * vibrato's starting phase, drawn per note).\n */\n\nimport type { EngineDef, NamedRng, ParamSpec, Voice } from 'bellowsjs';\nimport { clamp } from 'bellowsjs';\nimport { CascadeBank } from '../dsp/cascade';\nimport { PitchGlide } from '../dsp/pitchglide';\nimport { Adsr } from 'bellowsjs';\nimport { CM_H2O, SOUND_SPEED } from '../dsp/air';\nimport { GLOTTIS_GEOMETRIC, GLOTTIS_PULSE, GLOTTIS_SELF_OSCILLATING, JunctionAirway, ductMin } from '../dsp/junction-airway';\nimport { VOCAL_DEFAULT_PHONEME } from './vocal-phonemes';\nimport { VOCAL_SOUND_COUNT } from './vocal-beats';\nimport { settingOffsets } from './vocal-settings';\nimport { VOCAL_BODIES, VOCAL_NEUTRAL } from './vocal-tables.gen';\nimport { ART, ARTICULATORS } from './vocal-articulators';\nimport { ARTICULATOR_MAX, ARTICULATOR_RATE, ARTICULATOR_TARGET_MIN, LIP_COMPRESSED, VocalPlanner, restTipFrom } from './vocal-planner';\nimport { VocalRoof } from './vocal-roof';\nimport { VOCAL_KEY_BLOCKS, VocalDrive } from './vocal-drive';\nimport { VOCAL_GLIDE_DEFAULTS, vocalDamping, vocalGlideSpeed } from './vocal-lead';\n\nexport { VOCAL_PLAN_LEAD, vocalDamping, vocalGlideLead, vocalGlideSpeed } from './vocal-lead';\n\n/** Every sound on the `phoneme` parameter: the phonemes, then the beats (engines/vocal-beats.ts). */\nconst PHONEMES = VOCAL_SOUND_COUNT;\n\n\n/** The largest jaw opening the tuning rule uses (template cm). */\nconst OPEN_MAX = 1.5;\n/**\n * f0 raised by full fold stiffness, cents: the planner's cricothyroid gesture after a voiceless\n * obstruent (Hanson 2009). The size of the explicit rise it replaced (MEASURED choice).\n */\nconst STIFF_CENTS = 60;\n/** How much full stiffness narrows the geometric folds' swing (x_rel; Birkholz et al. 2019: under 1 is stiffening). CHOICE. */\nconst STIFF_SWING = 0.25;\n/** f0 change per cmH2O of transglottal pressure away from the lungs', Hz at 120 Hz (MEASURED choice). */\nconst COUPLE = 1.5;\n/**\n * The singer's ear, for the geometric folds: their pressure term is taken against its own average\n * over this many seconds, so a closure's quick dip stays and the steady pressure a vowel holds above\n * the folds is sung away. CHOICE; without it the geometric folds sang held notes 2 to 7 cents flat\n * on average (MEASURED; docs/VOICE-2.md, \"Vocal folds\").\n */\nconst EAR_TAU = 0.25;\n\n/*\n * The folds per table body (male, female, child): rest length L0 cm (Birkholz, Drechsel and Stone\n * 2019: 1.6 and 1.2; the child's INFERRED), and the paper's most natural settings, male then female:\n * the lower edge's rest displacement (0.3 and 0.6 mm), the upper edge's over it (0.3 and 0 mm), the\n * phase lag between the edges (70 and 50 degrees) and double pulsing (0.05). The child takes the\n * female's. Skewness is 0.3 for all, inside the paper's tested range (-0.4 to 0.4; its best were 0\n * and 0.2): CALIBRATED, the setting whose vowel band levels came closest to CHIMERA's (0 left the\n * male 1.5 to 4 kHz 6 dB over it, 0.3 within 2.5 dB; docs/VOICE-2.md, \"Vocal folds\").\n */\nconst FOLD_LENGTH = [1.6, 1.2, 0.9];\nconst FOLD_REST = [0.03, 0.06, 0.06];\n/** The self-oscillating folds' rest displacement, cm: a wider glottis than this stops them above about 600 Hz (MEASURED). */\nconst SELF_REST = 0.01;\nconst FOLD_UPPER = [0.03, 0, 0];\nconst FOLD_LAG = [70 / 360, 50 / 360, 50 / 360];\nconst FOLD_SKEW = [0.3, 0.3, 0.3];\nconst FOLD_DOUBLE = 0.05;\n/** Medial compression per unit of tension away from 0.5, cm of rest displacement (pressed closes, lax opens). CHOICE. */\nconst PRESS = 0.04;\n/** Output gain over CHIMERA's: puts the loudest held vowel near 1 at velocity 1. */\nconst OUTPUT_GAIN = 0.25;\n/** CHIMERA's vibrato ramps out over this many seconds. */\nconst VIBRATO_FADE = 0.06;\nconst MIN_HZ = 20;\n/** Articulator steps per keyframe. */\nconst STEPS = VOCAL_KEY_BLOCKS / 2;\n/** CHIMERA's geometry body constants per table body (human.rs:276-278). */\nconst LIP_WIDTH = [4.6, 4.4, 4.0];\n\nconst DEFAULTS = VOCAL_GLIDE_DEFAULTS;\n\nfunction initial(params: Record<string, number>, spec: ParamSpec): number {\n const v = params[spec.name];\n return typeof v === 'number' && Number.isFinite(v) ? v : spec.default;\n}\n\n/** Grid sections for a shortest tract of minLength cm at a rate. */\nfunction gridSections(rate: number, minLength: number): number {\n const dx = SOUND_SPEED / (2 * rate);\n return Math.max(8, Math.floor((minLength - ductMin(rate)) / dx));\n}\n\nclass VocalVoice implements Voice {\n private readonly sr: number = 0;\n private readonly air: JunctionAirway;\n private readonly drive: VocalDrive;\n private readonly roofs: VocalRoof[];\n private readonly planner = new VocalPlanner();\n private readonly bank: CascadeBank;\n private readonly glide: PitchGlide;\n private readonly env: Adsr;\n private readonly vibRng: NamedRng;\n private readonly blk: number = 0;\n private readonly stepEvery: number = 0;\n private readonly keyEvery: number = 0;\n private readonly envBuf: Float32Array;\n\n /* Scratch. */\n private readonly art = new Float64Array(ARTICULATORS);\n private readonly tip = new Float64Array(2);\n private readonly rate = new Float64Array(ARTICULATORS);\n /** The glottal opening and closure at each articulator step of the keyframe interval (0 is its start). */\n private readonly abdAt = new Float64Array(STEPS + 1);\n private readonly cloAt = new Float64Array(STEPS + 1);\n private readonly stfAt = new Float64Array(STEPS + 1);\n /** The planner's breath (a factor on lung pressure) and whether a beat line holds it, per step. */\n private readonly lungAt = new Float64Array(STEPS + 1);\n private readonly beatOn = new Uint8Array(STEPS + 1);\n private lungFactor = 1;\n private beatLine = 0;\n /* Voice settings (Laver 1980: long-term postures over every sound) and anatomy. */\n private readonly setting = { jawSet: 0, tongueFront: 0, tongueHigh: 0, lipRound: 0, lipOpen: 0, larynxSet: 0, nasal: 0, twang: 0, throat: 0 };\n /** Each articulator's offset from the settings; a consonant holding the articulator takes it back. */\n private readonly setOff = new Float64Array(ARTICULATORS);\n /** Anatomy: the whole tract's length and the pharynx's, factors on the body's. */\n private size = 1;\n private pharynxScale = 1;\n /** A contact's new position for each axis (x then y), for CascadeBank.placeFrom. */\n private readonly placed = new Float64Array(2);\n /** The time of the articulator step or block being computed, s (a field: no double crosses a call). */\n private at = 0;\n\n /* Parameters. */\n private phonemeParam = VOCAL_DEFAULT_PHONEME;\n private bendParam = 0;\n private body = 0;\n private tension = 0.55;\n private breath = 0.15;\n private vibInc = 0;\n private vibDepth = 0.3;\n private vibDelay = 0.25;\n private articulation = 1;\n private attack = 0.02;\n private release = 0.15;\n private level = 1;\n private ring = 0;\n private tuning = 0;\n private nextIn = 0;\n\n /* Note. */\n private live = false;\n private fresh = false;\n private released = false;\n private noteHz = 220;\n private vel = 0.8;\n /** Samples since note-on, and the current block's position. */\n private pos = 0;\n private bi = 0;\n /** Samples left in the keyframe interval, and blocks begun in it. */\n private intervalLeft = 0;\n private blockInInterval = 0;\n private end = Infinity;\n private pLungTarget = 9;\n /** Lung pressure, cmH2O. */\n private pLung = 0;\n private pCoupleHz = 0;\n /** The pressure above the folds as the singer has adapted to it, dyn/cm^2 (geometric folds). */\n private pEar = 0;\n\n\n /* Body blend in force. */\n private bLo = 0;\n private bW = 0;\n private k = 1;\n\n /* Pitch. */\n private vibPhase = 0;\n private bloomT = 0;\n private bloomFrom = 0;\n private bloomNow = 0;\n private tuneJaw = 0;\n private abduction = 0;\n private closure = 0;\n private stiffness = 0;\n private foldRest = 0.03;\n private glottisModel = GLOTTIS_PULSE;\n private f0Now = 110;\n private depth = 0;\n /* The layout and geometry body last laid out (-1: none). */\n private laidK = -1;\n private laidN = -1;\n private laidJv = -1;\n private laidGeoK = -1;\n private laidPh = -1;\n private laidTongue = -1;\n private laidLips = -1;\n\n constructor(sampleRate: number, params: Record<string, number>, rng: NamedRng) {\n this.sr = sampleRate;\n this.roofs = VOCAL_BODIES.map((t) => new VocalRoof(t));\n // room for the largest head (size 1.25): a longer tract with too few sections went into the uniform\n // back duct and bent the area function (MEASURED: F2 at 0.756 of the size-1 value at size 1.2, not 0.833)\n this.air = new JunctionAirway(sampleRate, gridSections(sampleRate, VOCAL_BODIES[0].minLength * 1.25), rng);\n this.drive = new VocalDrive(sampleRate);\n this.blk = this.air.block;\n this.stepEvery = 2 * this.blk;\n this.keyEvery = VOCAL_KEY_BLOCKS * this.blk;\n this.bank = new CascadeBank(ARTICULATORS, sampleRate / this.stepEvery);\n this.glide = new PitchGlide(sampleRate / this.blk);\n this.env = new Adsr(sampleRate);\n this.vibRng = rng.fork('vibrato');\n this.envBuf = new Float32Array(this.blk);\n this.bi = this.blk;\n for (const spec of PARAMS) this.setParam(spec.name, initial(params, spec));\n }\n\n noteOn(freq: number, vel: number): void {\n this.noteHz = clamp(Number.isFinite(freq) ? freq : 220, MIN_HZ, this.sr * 0.25);\n this.vel = clamp(Number.isFinite(vel) ? vel : 0.8, 0, 1);\n this.live = true;\n this.fresh = true;\n this.released = false;\n this.end = Infinity;\n this.env.reset();\n this.env.trigger();\n this.vibPhase = this.vibRng();\n this.bloomT = 0;\n this.bloomFrom = 0;\n this.bloomNow = 0;\n this.start();\n }\n\n noteOff(): void {\n if (!this.live || this.released) return;\n this.released = true;\n this.env.release();\n this.end = this.pos / this.sr;\n this.planner.setEnd(this.end);\n }\n\n get active(): boolean {\n return this.live;\n }\n\n setParam(name: string, value: number): void {\n if (!Number.isFinite(value)) return;\n switch (name) {\n case 'phoneme':\n this.setPhoneme(value);\n return;\n case 'nextIn':\n this.nextIn = clamp(value, 0, 1);\n return;\n case 'nextPhoneme':\n this.setNext(value);\n return;\n case 'bend':\n this.setBend(value);\n return;\n case 'glide':\n this.glide.setSpeed(vocalGlideSpeed(value));\n return;\n case 'overshoot':\n this.glide.setDamping(vocalDamping(clamp(value, 0, 0.5)));\n return;\n case 'preparation':\n this.glide.setPreparation(clamp(value, 0, 1));\n return;\n case 'body':\n this.body = clamp(value, 0, 2);\n this.applyBody();\n if (this.live && this.fresh) this.start();\n return;\n case 'tension':\n this.tension = clamp(value, 0, 1);\n this.applyTension();\n return;\n case 'roughness':\n this.air.glottis.setRoughness(clamp(value, 0, 1));\n return;\n case 'fry':\n this.air.glottis.setFry(clamp(value, 0, 1));\n return;\n case 'drift':\n this.air.glottis.setDrift(clamp(value, 0, 20));\n return;\n case 'glottis':\n this.setGlottis(value);\n return;\n case 'breath':\n this.breath = clamp(value, 0, 1);\n return;\n case 'vibratoRate':\n this.vibInc = (clamp(value, 0, 12) * this.blk) / this.sr;\n return;\n case 'vibratoDepth':\n this.vibDepth = clamp(value, 0, 2);\n return;\n case 'vibratoDelay':\n this.vibDelay = clamp(value, 0, 1);\n return;\n case 'articulation':\n this.articulation = clamp(value, 0.25, 4);\n return;\n case 'attack':\n this.attack = clamp(value, 0.001, 1);\n this.env.set(this.attack, 0.05, 1, this.release);\n return;\n case 'release':\n this.release = clamp(value, 0.01, 2);\n this.env.set(this.attack, 0.05, 1, this.release);\n return;\n case 'level':\n this.level = clamp(value, 0, 2);\n return;\n case 'ring':\n this.ring = clamp(value, 0, 1);\n return;\n case 'mic':\n this.air.mic = clamp(value, 0, 1);\n return;\n case 'cheeks':\n this.air.cheeks = clamp(value, 0, 1);\n return;\n case 'piriform':\n this.air.piriform = value >= 0.5 ? 1 : 0;\n return;\n case 'size':\n this.size = clamp(value, 0.8, 1.25);\n this.applyBody();\n return;\n case 'pharynx':\n this.pharynxScale = clamp(value, 0.8, 1.25);\n return;\n case 'jawSet':\n case 'tongueFront':\n case 'tongueHigh':\n case 'lipRound':\n case 'lipOpen':\n case 'larynxSet':\n case 'throat':\n this.setting[name] = clamp(value, -1, 1);\n this.settings();\n return;\n case 'nasal':\n case 'twang':\n this.setting[name] = clamp(value, 0, 1);\n this.settings();\n return;\n case 'tuning':\n this.tuning = clamp(value, 0, 1);\n return;\n }\n }\n\n /** 0 geometric, 1 self-oscillating, 2 the parametric pulse; a voice that is sounding changes at its next note. */\n private setGlottis(value: number): void {\n const m = clamp(Math.round(value), 0, 2);\n this.glottisModel = m === 1 ? GLOTTIS_SELF_OSCILLATING : m === 2 ? GLOTTIS_PULSE : GLOTTIS_GEOMETRIC;\n if (!this.live) this.air.model = this.glottisModel;\n this.applyTension();\n }\n\n private setPhoneme(value: number): void {\n const idx = clamp(Math.round(value), 0, PHONEMES - 1);\n this.phonemeParam = idx;\n if (!this.live || this.released) return;\n if (this.fresh) this.start();\n else this.planner.addNow(idx, this.pos / this.sr);\n }\n\n private setNext(value: number): void {\n const idx = clamp(Math.round(value), 0, PHONEMES - 1);\n if (!this.live || this.released) return;\n this.planner.addUpcoming(idx, this.pos / this.sr + this.nextIn);\n if (this.fresh) this.settle();\n }\n\n private setBend(value: number): void {\n const b = clamp(value, -48, 48);\n this.bendParam = b;\n if (!this.live || this.released) return;\n if (this.fresh) this.glide.snap(b);\n else if (b !== this.glide.target) {\n this.glide.setTarget(b);\n this.bloomFrom = this.bloomNow;\n this.bloomT = 0;\n }\n }\n\n process(outL: Float32Array, outR: Float32Array, from: number, to: number): void {\n if (!this.live) return;\n const air = this.air;\n const blk = this.blk;\n let i = from;\n while (i < to) {\n if (this.bi === blk) {\n if (this.intervalLeft === 0) this.interval();\n this.beginBlock();\n this.bi = 0;\n }\n const left = blk - this.bi;\n const n = left < to - i ? left : to - i;\n const eb = this.envBuf;\n this.env.fill(eb, 0, n);\n air.render(outL, outR, i, n, this.bi, eb);\n this.bi += n;\n this.pos += n;\n this.intervalLeft -= n;\n i += n;\n }\n if (to > from) this.fresh = false;\n if (!this.env.active) this.live = false;\n }\n\n /* ---------------------------------------------------------------- */\n /* Note start */\n /* ---------------------------------------------------------------- */\n\n private applyBody(): void {\n const b = this.body;\n this.bLo = Math.floor(b) < 2 ? Math.floor(b) : 1;\n this.bW = b - this.bLo;\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n this.k = (A.k * (1 - w) + B.k * w) * this.size;\n this.planner.setBody(b);\n const lo = this.bLo;\n const air = this.air;\n air.foldLength = FOLD_LENGTH[lo] * (1 - w) + FOLD_LENGTH[lo + 1] * w;\n air.upperRest = FOLD_UPPER[lo] * (1 - w) + FOLD_UPPER[lo + 1] * w;\n air.lag = FOLD_LAG[lo] * (1 - w) + FOLD_LAG[lo + 1] * w;\n air.skew = FOLD_SKEW[lo] * (1 - w) + FOLD_SKEW[lo + 1] * w;\n air.doublePulse = FOLD_DOUBLE;\n this.foldRest = FOLD_REST[lo] * (1 - w) + FOLD_REST[lo + 1] * w;\n this.applyTension();\n }\n\n private applyTension(): void {\n const t = clamp(this.tension + 0.35 * (this.vel - 0.8), 0, 1);\n this.air.glottis.setTension(t);\n // the model that is sounding: a change waits for the next note, and the queued model's rest moved the\n // sounding folds (MEASURED: 2.4 dB on a held note switched from 1 to 0)\n const base = this.air.model === GLOTTIS_SELF_OSCILLATING ? SELF_REST : this.foldRest;\n this.air.restOffset = base + PRESS * (0.5 - t);\n }\n\n /** Everything from rest, on the current phoneme, bend and body. */\n private start(): void {\n this.pos = 0;\n this.bi = this.blk;\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n const k = this.k;\n const ps = this.pharynxScale;\n const pharynx = (A.pharynxScale * (1 - w) + B.pharynxScale * w) * ps;\n const tongue = A.tongueRadius * (1 - w) + B.tongueRadius * w;\n const lips = LIP_WIDTH[this.bLo] * (1 - w) + LIP_WIDTH[this.bLo + 1] * w;\n // the shortest tract shrinks with the size and, for about half its length, with the pharynx; an\n // estimate on the short side only lengthens the back duct, never shortens a grid section\n const minLength = (A.minLength * (1 - w) + B.minLength * w) * this.size * Math.min(1, 0.55 + 0.45 * ps);\n const neutralPharynx = (A.neutralPharynx * (1 - w) + B.neutralPharynx * w) * this.size * ps;\n const air = this.air;\n const n = Math.min(air.nMax, gridSections(this.sr, minLength));\n const lb = minLength - n * air.dx;\n const jv = clamp(Math.round((neutralPharynx - lb) / air.dx), 2, n - 2);\n // a new layout only for a new body; the same one just rests (configure runs cold, and cold code boxes)\n if (k !== this.laidK || n !== this.laidN || jv !== this.laidJv) {\n air.configure(k, n, jv);\n this.laidK = k;\n this.laidN = n;\n this.laidJv = jv;\n } else air.reset();\n if (pharynx !== this.laidPh || tongue !== this.laidTongue || lips !== this.laidLips || k !== this.laidGeoK) {\n this.drive.setBody(k, pharynx, tongue, lips);\n this.laidGeoK = k;\n this.laidPh = pharynx;\n this.laidTongue = tongue;\n this.laidLips = lips;\n }\n air.model = this.glottisModel;\n this.applyTension();\n this.planner.clear();\n this.planner.addNow(this.phonemeParam, 0);\n this.glide.snap(this.bendParam);\n this.pLungTarget = clamp(4 + 6.25 * this.vel, 5, 15);\n // a beat line starts breath-held: the beatboxer breathes only into a sound\n this.pLung = this.planner.silentAt(0) || this.planner.beatAt(0) ? 0 : 0.94 * this.pLungTarget;\n this.pCoupleHz = COUPLE * (this.noteHz / 120);\n this.pEar = 0;\n this.tuneJaw = 0;\n this.settle();\n }\n\n /** Snap the articulators and the shape to the plan at the current time (fresh notes only). */\n private settle(): void {\n const bank = this.bank;\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, VOCAL_NEUTRAL[i]);\n this.at = this.pos / this.sr;\n for (let pass = 0; pass < 3; pass++) {\n this.targets();\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, this.planner.target[i]);\n this.contact();\n // at rest where the contacts hold it: a note that opens on a closure starts pressed, not mid-movement\n for (let i = 0; i < ARTICULATORS; i++) bank.snap(i, bank.values[i]);\n }\n this.art.set(bank.values);\n this.drive.key(this.art, true);\n this.updateGlottis();\n for (let q = 0; q <= STEPS; q++) {\n this.abdAt[q] = this.abduction;\n this.cloAt[q] = this.closure;\n this.stfAt[q] = this.stiffness;\n this.lungAt[q] = this.lungFactor;\n this.beatOn[q] = this.beatLine;\n }\n this.intervalLeft = 0;\n this.blockInInterval = 0;\n }\n\n /* ---------------------------------------------------------------- */\n /* Control */\n /* ---------------------------------------------------------------- */\n\n /** Planner targets at `at`, with the singer's offsets, clamped, into planner.target. */\n private targets(): void {\n restTipFrom(this.bank.values, this.tip);\n const p = this.planner;\n p.at = this.at;\n p.restX = this.tip[0];\n p.restY = this.tip[1];\n p.evaluateNow();\n const tg = p.target;\n const ring = this.ring;\n const tj = this.tuneJaw;\n tg[ART.epilarynx] += ring;\n tg[ART.larynx] -= 0.6 * ring;\n tg[ART.root] += 0.4 * ring;\n tg[ART.jaw] += tj;\n tg[ART.tbY] -= tj;\n tg[ART.lipAp] += 0.5 * tj;\n // the voice's settings, given back wherever a consonant holds the articulator (a closure still closes)\n const so = this.setOff;\n const held = p.held;\n for (let i = 0; i < ARTICULATORS; i++) tg[i] += so[i] * (1 - held[i]);\n for (let i = 0; i < ARTICULATORS; i++) {\n const v = tg[i];\n tg[i] = v < ARTICULATOR_TARGET_MIN[i] ? ARTICULATOR_TARGET_MIN[i] : v > ARTICULATOR_MAX[i] ? ARTICULATOR_MAX[i] : v;\n }\n }\n\n /**\n * The settings as articulator offsets. Each is a long-term posture laid over every sound, as Laver\n * (1980, The Phonetic Description of Voice Quality) describes them: jaw open or close, tongue\n * fronted or backed and raised or lowered, lips rounded and protruded or spread, larynx raised or\n * lowered, nasal (the velum down), twang (the epilarynx narrowed, the larynx a little up), and an\n * open or constricted throat (the tongue root forward or back): engines/vocal-settings.ts.\n */\n private settings(): void {\n // the shared table (engines/vocal-settings.ts), so the engine and the mouth view agree\n settingOffsets(this.setting, this.setOff);\n }\n\n private updateGlottis(): void {\n const k2 = this.k * this.k;\n const b = this.breath;\n this.abduction = (0.1 * b * b + 0.008 + 0.03 * b) * k2 + this.planner.abduction * k2;\n this.closure = this.planner.closure;\n this.stiffness = this.planner.stiffness;\n this.lungFactor = this.planner.breath;\n this.beatLine = this.planner.beat;\n }\n\n /** One articulator step ending at time `at`. */\n private step(): void {\n this.targets();\n const bank = this.bank;\n const p = this.planner;\n const art = this.articulation;\n const rate = this.rate;\n for (let i = 0; i < ARTICULATORS; i++) rate[i] = ARTICULATOR_RATE[i] * p.speed[i] * art;\n bank.setAll(p.target, rate);\n bank.step();\n this.contact();\n this.updateGlottis();\n }\n\n /**\n * Tip and body may press 0.1 k cm into the roof; past that they are\n * projected back along the contact normal (CHIMERA human_voice.rs:520-552).\n * CHIMERA then removes the inward part of the velocity; in the cascade\n * the velocity is the stages behind the output, so only the output stage\n * is moved and those stages keep going toward a target past the roof (a\n * /t/ aims 0.29 k cm past it). The articulator presses into the roof\n * while they do, and when its target turns back it leaves the roof\n * already accelerating. The lips likewise stop at LIP_COMPRESSED while\n * their stages go on to the virtual closure target.\n */\n private contact(): void {\n const bank = this.bank;\n if (bank.values[ART.lipAp] < LIP_COMPRESSED) {\n this.placed[0] = LIP_COMPRESSED;\n bank.placeFrom(ART.lipAp, this.placed, 0);\n }\n const roof = this.roofs[this.bW < 0.5 ? this.bLo : this.bLo + 1];\n const k = roof.k;\n const lim = -0.1 * k;\n const a = this.art;\n a.set(bank.values);\n // the body: its circle against the roof\n roof.bodyPoint(a);\n roof.x = roof.bx;\n roof.y = roof.by;\n roof.project();\n if (roof.sd - roof.r < lim) {\n this.depth = lim - (roof.sd - roof.r);\n this.push(roof, ART.tbX, ART.tbY);\n }\n a.set(bank.values);\n roof.tipPoint(a);\n roof.x = roof.tipX;\n roof.y = roof.tipY;\n roof.project();\n if (roof.sd < lim) {\n this.depth = lim - roof.sd;\n this.push(roof, ART.ttX, ART.ttY);\n }\n }\n\n /**\n * Move the output stages of articulators (ix, iy), at the roof's point\n * (x, y) with signed distance sd from it, out by `depth` along the normal.\n */\n private push(roof: VocalRoof, ix: number, iy: number): void {\n const sd = roof.sd;\n const depth = this.depth;\n let nx = roof.x - roof.qx;\n let ny = roof.y - roof.qy;\n const len = Math.sqrt(nx * nx + ny * ny);\n if (!(len > 1e-9)) {\n nx = 0;\n ny = -1;\n } else {\n // the normal points into the airway: away from the roof from below it, toward it from above\n const s = sd >= 0 ? 1 / len : -1 / len;\n nx *= s;\n ny *= s;\n }\n const bank = this.bank;\n const val = bank.values;\n const ax = val[ix];\n const ay = val[iy];\n const k = roof.k;\n const sx = (ax > 0.5 ? 0.86 : 1) * k;\n const sy = (ay < 7 ? roof.pharynxScale : 1) * k;\n const pl = this.placed;\n pl[0] = ax + (nx * depth) / sx;\n pl[1] = ay + (ny * depth) / sy;\n bank.placeFrom(ix, pl, 0);\n bank.placeFrom(iy, pl, 1);\n }\n\n /** A keyframe interval starts: the articulators to its end, then the shape there. */\n private interval(): void {\n const sr = this.sr;\n this.abdAt[0] = this.abdAt[STEPS];\n this.cloAt[0] = this.cloAt[STEPS];\n this.stfAt[0] = this.stfAt[STEPS];\n this.lungAt[0] = this.lungAt[STEPS];\n this.beatOn[0] = this.beatOn[STEPS];\n for (let q = 1; q <= STEPS; q++) {\n this.at = (this.pos + q * this.stepEvery) / sr;\n this.step();\n this.abdAt[q] = this.abduction;\n this.cloAt[q] = this.closure;\n this.stfAt[q] = this.stiffness;\n this.lungAt[q] = this.lungFactor;\n this.beatOn[q] = this.beatLine;\n }\n this.art.set(this.bank.values);\n this.drive.key(this.art, false);\n this.planner.forget(this.pos / sr);\n this.intervalLeft = this.keyEvery;\n this.blockInInterval = 0;\n }\n\n /** A voice block starts: shape, pitch, breath and glottis for its samples. */\n private beginBlock(): void {\n const sr = this.sr;\n const blk = this.blk;\n const air = this.air;\n this.blockInInterval++;\n const b = this.blockInInterval;\n const drive = this.drive;\n drive.u = b / VOCAL_KEY_BLOCKS;\n drive.toAirway(air);\n // the glottis at the block's end, from the articulator steps either side\n const sf = (b * STEPS) / VOCAL_KEY_BLOCKS;\n const s0 = Math.floor(sf);\n const s1 = s0 < STEPS ? s0 + 1 : STEPS;\n const fr = sf - s0;\n air.agStatic = this.abdAt[s0] + (this.abdAt[s1] - this.abdAt[s0]) * fr;\n air.closure = this.cloAt[s0] + (this.cloAt[s1] - this.cloAt[s0]) * fr;\n // the posterior chink: CHIMERA's (0.008 + 0.03 breath) k^2 part of the opening above\n const k2 = this.k * this.k;\n air.chink = (0.008 + 0.03 * this.breath) * k2;\n const stiff = this.stfAt[s0] + (this.stfAt[s1] - this.stfAt[s0]) * fr;\n air.xRel = 1 - STIFF_SWING * stiff;\n const lung = this.lungAt[s0] + (this.lungAt[s1] - this.lungAt[s0]) * fr;\n const beatLine = this.beatOn[s0] | this.beatOn[s1];\n const t = (this.pos + blk / 2) / sr;\n const p = this.planner;\n p.at = t;\n p.queryNow();\n\n // pitch: the glide, the vibrato blooming in, the folds' stiffness, the pressure across the folds\n this.glide.advance();\n const bend = this.glide.value;\n this.bloomT += blk / sr;\n const bt = this.bloomT;\n const up = 0.5 - 0.5 * Math.cos(Math.PI * Math.min(bt / Math.max(this.vibDelay, 1e-9), 1));\n const down = this.bloomFrom * (0.5 + 0.5 * Math.cos(Math.PI * Math.min(bt / VIBRATO_FADE, 1)));\n this.bloomNow = up > down ? up : down;\n let ph = this.vibPhase + this.vibInc;\n if (ph >= 1) ph -= 1;\n this.vibPhase = ph;\n const vib = Math.sin(2 * Math.PI * ph) * this.vibDepth * this.bloomNow;\n const f0 = this.noteHz * Math.pow(2, (bend + vib) / 12 + (stiff * STIFF_CENTS) / 1200);\n this.f0Now = f0;\n this.tune();\n // f0 follows the pressure across the folds against the pressure below them, which is the pressure\n // above them: a closure above the folds lowers it, effort (both pressures together) does not\n // (Titze 1989: 2 to 6 Hz per cmH2O). The geometric folds read it from block means, against the\n // singer's ear (EAR_TAU); the pulse keeps\n // its reading of each block's last sample, which aliases the cycle (MEASURED: a female /\u0251/ at\n // 494 Hz 19 cents sharp; docs/VOICE-2.md, \"Vocal folds\"). Self-oscillating folds find all this\n // themselves: their servo aims at the note.\n const pa = air.pSupra;\n this.pEar += (pa - this.pEar) * (1 - Math.exp(-blk / sr / EAR_TAU));\n if (air.model === GLOTTIS_SELF_OSCILLATING) air.f0 = f0;\n else if (air.model === GLOTTIS_GEOMETRIC) air.f0 = f0 - (this.pCoupleHz * Math.max(pa - this.pEar, 0)) / CM_H2O;\n else air.f0 = f0 + (this.pCoupleHz * (Math.max(air.dpSmooth, 0) - Math.max(air.pSubSmooth, 0))) / CM_H2O;\n\n // the sung breath (planner.rs:376-379): full drive from the note-on to its end, off in silences\n const gate = t < this.end && p.silent === 0 ? 1 : 0;\n // a beat's breath is a gesture of its own, tens of milliseconds long: the lungs follow it closely\n const tau = beatLine === 1 ? 0.003 : gate ? 0.025 : 0.05;\n this.pLung += (this.pLungTarget * gate * lung - this.pLung) * (1 - Math.exp(-blk / sr / tau));\n air.pLung = this.pLung * CM_H2O;\n // velocity is lung pressure above 0.2; under it the note also fades, so velocity 0 is silent\n air.gain = OUTPUT_GAIN * this.level * Math.min(this.vel / 0.2, 1);\n air.beginBlock();\n }\n\n /** Formant tuning: open the jaw so the vowel's first resonance stays above 1.15 f0 (the block's f0Now). */\n private tune(): void {\n const f0 = this.f0Now;\n if (!(this.tuning > 0)) {\n this.tuneJaw = 0;\n return;\n }\n const v = this.planner.vowel;\n if (v < 0) {\n this.tuneJaw = 0;\n return;\n }\n const A = VOCAL_BODIES[this.bLo];\n const B = VOCAL_BODIES[this.bLo + 1];\n const w = this.bW;\n const slope = A.tuneSlope[v] * (1 - w) + B.tuneSlope[v] * w;\n // only where opening raises R1 (an open vowel's falls as the tongue drops into the pharynx)\n if (slope < 20) {\n this.tuneJaw = 0;\n return;\n }\n const r1 = A.tuneR1[v] * (1 - w) + B.tuneR1[v] * w;\n const jaw = A.tuneJaw[v] * (1 - w) + B.tuneJaw[v] * w;\n const need = (1.15 * f0 - r1) / slope;\n const room = 2.6 - jaw;\n this.tuneJaw = this.tuning * Math.min(OPEN_MAX, room, need > 0 ? need : 0);\n }\n}\n\nconst PARAMS: ParamSpec[] = [\n { name: 'phoneme', min: 0, max: PHONEMES - 1, default: VOCAL_DEFAULT_PHONEME },\n { name: 'bend', min: -48, max: 48, default: 0, unit: 'st' },\n { name: 'glide', min: 0.005, max: 0.5, default: DEFAULTS.glide, curve: 'exp', unit: 's' },\n { name: 'body', min: 0, max: 2, default: 0 },\n { name: 'tension', min: 0, max: 1, default: 0.55 },\n /*\n * 0.02, not CHIMERA's 0.1. MEASURED on the pulse folds (docs/VOICE-NORMS.md): at 0.1 every body\n * read 1.2 to 1.3 percent jitter and 3.8 to 4.8 percent shimmer, past the MDVP screening limits\n * (1.04, 3.81) and heard as an old voice; at 0.02, 0.71 to 0.78 percent and 2.2 to 3.0 percent,\n * near the healthy means (0.63, 2.0). Raise it for an older or rougher voice.\n */\n { name: 'roughness', min: 0, max: 1, default: 0.02 },\n { name: 'fry', min: 0, max: 1, default: 0 },\n { name: 'drift', min: 0, max: 20, default: 6, unit: 'cents' },\n { name: 'glottis', min: 0, max: 2, default: 2 },\n { name: 'breath', min: 0, max: 1, default: 0.15 },\n { name: 'vibratoRate', min: 0, max: 12, default: 5.5, unit: 'Hz' },\n { name: 'vibratoDepth', min: 0, max: 2, default: 0.3, unit: 'st' },\n { name: 'vibratoDelay', min: 0, max: 1, default: 0.25, unit: 's' },\n { name: 'articulation', min: 0.25, max: 4, default: 1, curve: 'exp' },\n { name: 'attack', min: 0.001, max: 1, default: 0.02, curve: 'exp', unit: 's' },\n { name: 'release', min: 0.01, max: 2, default: 0.15, curve: 'exp', unit: 's' },\n { name: 'level', min: 0, max: 2, default: 1 },\n { name: 'overshoot', min: 0, max: 0.5, default: DEFAULTS.overshoot },\n { name: 'preparation', min: 0, max: 1, default: DEFAULTS.preparation },\n { name: 'ring', min: 0, max: 1, default: 0 },\n { name: 'mic', min: 0, max: 1, default: 0 },\n { name: 'cheeks', min: 0, max: 1, default: 0 },\n { name: 'piriform', min: 0, max: 1, default: 0 },\n { name: 'size', min: 0.8, max: 1.25, default: 1 },\n { name: 'pharynx', min: 0.8, max: 1.25, default: 1 },\n { name: 'jawSet', min: -1, max: 1, default: 0 },\n { name: 'tongueFront', min: -1, max: 1, default: 0 },\n { name: 'tongueHigh', min: -1, max: 1, default: 0 },\n { name: 'lipRound', min: -1, max: 1, default: 0 },\n { name: 'lipOpen', min: -1, max: 1, default: 0 },\n { name: 'larynxSet', min: -1, max: 1, default: 0 },\n { name: 'nasal', min: 0, max: 1, default: 0 },\n { name: 'twang', min: 0, max: 1, default: 0 },\n { name: 'throat', min: -1, max: 1, default: 0 },\n { name: 'tuning', min: 0, max: 1, default: 0 },\n { name: 'nextIn', min: 0, max: 1, default: 0, unit: 's' },\n { name: 'nextPhoneme', min: 0, max: PHONEMES - 1, default: 0 },\n];\n\nexport const vocalEngine: EngineDef = {\n id: 'vocal',\n label: 'Vocal',\n params: PARAMS,\n polyphony: 8,\n createVoice: (sampleRate, initParams, rng) => new VocalVoice(sampleRate, initParams, rng),\n};\n", "/*\n * A cascade of identical first-order lags, H(s) = 1 / (1 + tau s)^N: the\n * target approximation Birkholz fitted to measured articulator movements\n * (Birkholz, Kroger and Neuschaefer-Rube 2011, IEEE TASLP 19(5); Birkholz\n * and Hoole 2012, Interspeech: the fit error falls steeply up to N = 5 or\n * 6, and VocalTractLab uses 6). Implemented here from those papers.\n *\n * Why not the critically damped second-order tracker (critdamp.ts, N = 2):\n * from rest its velocity peaks at 0.17 of the 98 percent time with 26\n * percent of the way done, a fast start and a long tail. Real movements are\n * nearer symmetric and bell shaped; at N = 6 the peak comes at 0.42 of the\n * 98 percent time with 38 percent done.\n *\n * Each stage follows the one before it: x_k' = (x_{k-1} - x_k) / tau, with\n * x_0 the target and x_N the output. With the target held over a step of\n * length h, the errors e_k = x_k - target evolve exactly as\n *\n * e_k(h) = exp(-r) sum_{j=1..k} e_j(0) r^(k-j) / (k-j)!, r = h / tau\n *\n * (each stage is the gamma-shaped impulse response of the ones before it),\n * so a step is N (N + 1) / 2 multiply-adds with coefficients computed once\n * per rate. It is the continuous solution sampled at the step times, at any\n * step rate, stable for any r.\n *\n * Time: from rest the remaining fraction after t is the gamma tail\n * exp(-u) sum_{k<N} u^k / k!, u = t / tau. It reaches 2 percent at u =\n * 12.03 for N = 6 (5.83 for N = 2), so setTime(s) sets tau = s / 12.03.\n *\n * A rate change leaves the stages where they are: position stays\n * continuous and velocity scales with the rate (critdamp.ts scales it the\n * same way on a slowdown).\n *\n * Contact: place() moves the output stage alone. The stages before it are\n * the movement still on its way, so an articulator held against a surface\n * keeps that motion (a target past the surface stays past it), and when the\n * target turns back the output leaves the surface already accelerating.\n *\n * The only state is Float64Arrays sized at construction; step() returns\n * nothing (V8 boxes a double returned from a call it does not inline), so\n * nothing on the step path allocates.\n */\n\nimport { clamp } from 'bellowsjs';\n\n/** The default order: VocalTractLab's. */\nexport const CASCADE_ORDER = 6;\n\n/** u at which the gamma tail exp(-u) sum_{k<n} u^k / k! falls to 1 - fraction. */\nexport function cascadeSettle(order: number, fraction = 0.98): number {\n const tail = (u: number) => {\n let term = 1;\n let sum = 1;\n for (let k = 1; k < order; k++) {\n term *= u / k;\n sum += term;\n }\n return Math.exp(-u) * sum;\n };\n let lo = 0;\n let hi = 10 * order + 50;\n for (let it = 0; it < 200; it++) {\n const mid = 0.5 * (lo + hi);\n if (tail(mid) > 1 - fraction) lo = mid;\n else hi = mid;\n }\n return 0.5 * (lo + hi);\n}\n\n/** t98 / tau at N = 6: 12.03. */\nexport const CASCADE_SETTLE_98 = cascadeSettle(CASCADE_ORDER);\n\nconst VALUE_LIMIT = 1e15;\nconst MIN_RATE = 1e-3;\nconst MAX_RATE = 1e9;\nconst SETTLED = 1e-30;\n\nexport class CascadeBank {\n readonly channels: number;\n readonly order: number;\n /**\n * The outputs (the last stage), one per channel, refreshed by step(),\n * snap() and place(). Read only.\n */\n readonly values: Float64Array;\n /** Stages, channel-major: stage k of channel i at i * order + k (the last is the output). */\n private readonly x: Float64Array;\n private readonly goal: Float64Array;\n /** 1 / tau per channel, 1/s. */\n private readonly rate: Float64Array;\n /** exp(-r) r^m / m! for m = 0 .. order - 1, channel-major. */\n private readonly c: Float64Array;\n private readonly h: number;\n /** t98 / tau at this order. */\n private readonly settle: number;\n\n /**\n * stepRateHz is how often step() runs, within [1e-3, 1e9] Hz; order is the\n * number of stages, 1 to 12.\n */\n constructor(channels: number, stepRateHz: number, order = CASCADE_ORDER) {\n if (!(Number.isInteger(channels) && channels > 0 && channels <= 1 << 16)) {\n throw new RangeError(`channel count must be an integer from 1 to 65536, got ${channels}`);\n }\n if (!(Number.isInteger(order) && order >= 1 && order <= 12)) {\n throw new RangeError(`order must be an integer from 1 to 12, got ${order}`);\n }\n if (!(stepRateHz >= 1e-3 && stepRateHz <= 1e9)) {\n throw new RangeError(`step rate must be within [1e-3, 1e9] Hz, got ${stepRateHz}`);\n }\n this.channels = channels;\n this.order = order;\n this.h = 1 / stepRateHz;\n this.values = new Float64Array(channels);\n this.x = new Float64Array(channels * order);\n this.goal = new Float64Array(channels);\n this.rate = new Float64Array(channels);\n this.c = new Float64Array(channels * order);\n this.settle = cascadeSettle(order);\n // 100 ms to 98 percent until set\n for (let i = 0; i < channels; i++) this.setRate(i, this.settle / 0.1);\n }\n\n /** 1 / tau for channel i, clamped to [1e-3, 1e9] per second. */\n setRate(i: number, perSecond: number): void {\n if (!Number.isFinite(perSecond)) return;\n const q = clamp(perSecond, MIN_RATE, MAX_RATE);\n if (q === this.rate[i]) return;\n this.rate[i] = q;\n this.coefficients(i);\n }\n\n /** The 98 percent time from rest for channel i, seconds (0: arrive on the next step). */\n setTime(i: number, seconds: number): void {\n if (!Number.isFinite(seconds)) return;\n const t = clamp(seconds, 0, Number.MAX_VALUE);\n this.setRate(i, t > 0 ? this.settle / t : MAX_RATE);\n }\n\n setTarget(i: number, target: number): void {\n if (!Number.isFinite(target)) return;\n this.goal[i] = clamp(target, -VALUE_LIMIT, VALUE_LIMIT);\n }\n\n /** Every stage and the target to value: at rest there. */\n snap(i: number, value: number): void {\n if (!Number.isFinite(value)) return;\n const v = clamp(value, -VALUE_LIMIT, VALUE_LIMIT);\n this.goal[i] = v;\n this.values[i] = v;\n const n = this.order;\n for (let k = 0; k < n; k++) this.x[i * n + k] = v;\n }\n\n /** Move channel i's output stage to value, leaving the stages before it (a contact). */\n place(i: number, value: number): void {\n if (!(value - value === 0)) return;\n const v = value < -1e15 ? -1e15 : value > 1e15 ? 1e15 : value;\n this.x[i * this.order + this.order - 1] = v;\n this.values[i] = v;\n }\n\n /** place(i, src[at]): no double crosses the call. */\n placeFrom(i: number, src: Float64Array, at: number): void {\n this.place(i, src[at]);\n }\n\n /** The output's velocity, units per second. */\n velocity(i: number): number {\n const n = this.order;\n const b = i * n + n - 1;\n return n > 1 ? (this.x[b - 1] - this.x[b]) * this.rate[i] : (this.goal[i] - this.x[b]) * this.rate[i];\n }\n\n /** Stage k (0 first, order - 1 the output) of channel i. */\n stage(i: number, k: number): number {\n return this.x[i * this.order + k];\n }\n\n target(i: number): number {\n return this.goal[i];\n }\n\n /**\n * Every channel's target from targets[i] and rate (1 / tau) from rates[i]:\n * one call with arrays, so no double crosses a call boundary.\n */\n setAll(targets: Float64Array, rates: Float64Array): void {\n for (let i = 0; i < this.channels; i++) {\n const t = targets[i];\n if (t - t === 0) this.goal[i] = t < -1e15 ? -1e15 : t > 1e15 ? 1e15 : t;\n const r = rates[i];\n if (!(r - r === 0)) continue;\n const q = r < 1e-3 ? 1e-3 : r > 1e9 ? 1e9 : r;\n if (q !== this.rate[i]) {\n this.rate[i] = q;\n this.coefficients(i);\n }\n }\n }\n\n /** Advance every channel one step. */\n step(): void {\n const n = this.order;\n const x = this.x;\n const c = this.c;\n const goal = this.goal;\n for (let i = 0; i < this.channels; i++) {\n const base = i * n;\n const g = goal[i];\n let big = 0;\n // in place from the last stage down: stage k needs the old values of stages 0 .. k\n for (let k = n - 1; k >= 0; k--) {\n let s = 0;\n for (let j = 0; j <= k; j++) s += c[base + k - j] * (x[base + j] - g);\n x[base + k] = g + s;\n if (s > big) big = s;\n else if (-s > big) big = -s;\n }\n // settle exactly far under anything audible, so no subnormal stays in the state\n if (big < SETTLED) for (let k = 0; k < n; k++) x[base + k] = g;\n this.values[i] = x[base + n - 1];\n }\n }\n\n private coefficients(i: number): void {\n const n = this.order;\n const r = this.h * this.rate[i];\n let term = Math.exp(-r);\n for (let m = 0; m < n; m++) {\n this.c[i * n + m] = term;\n term *= r / (m + 1);\n }\n }\n}\n", "/*\n * Air, in the CGS units the airway works in (cm, g, s; pressure in\n * dyn/cm^2, flow in cm^3/s). The values are CHIMERA's (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49,\n * crates/chimera/src/physics.rs:5-35): warm humid air in the airway.\n */\n\n/** Density, g/cm^3. */\nexport const AIR_DENSITY = 1.14e-3;\n/** Speed of sound, cm/s. */\nexport const SOUND_SPEED = 35000;\n/** Dynamic viscosity, g/(cm s). */\nexport const AIR_DYNAMIC_VISCOSITY = 1.86e-4;\n/** Kinematic viscosity, cm^2/s. */\nexport const AIR_VISCOSITY = AIR_DYNAMIC_VISCOSITY / AIR_DENSITY;\n/** One centimetre of water, dyn/cm^2. */\nexport const CM_H2O = 980.665;\n\n/** A yielding wall per unit area: mass g/cm^2, resistance dyn s/cm^3, stiffness dyn/cm^3. */\nexport interface WallTissue {\n m: number;\n r: number;\n k: number;\n}\n\n/**\n * Soft tissue of the pharynx and mouth: Birkholz and Zhang (Interspeech 2025) fitted six speakers'\n * voice bars with M = 2.0 g/cm^2 for all, K 65,000 to 100,000 dyn/cm^3 and B 800 to 2000 dyn s/cm^3,\n * uniform over the tract. K and B are chosen here by the voice bar's duration and level\n * (docs/VOICE-2.md, \"Noise sources, walls and velum\"). CHIMERA's WALL_SOFT was m 1.5, r 1600, k 3e5.\n * The mass stays CHIMERA's 1.5, under their 2.0: with the six-stage articulators and the retuned\n * noise, 2.0 put five of the comparison renders 0.2 to 0.27 dB further from CHIMERA (DTW), the\n * vowels line most (docs/VOICE-2.md, \"Integration 4\").\n */\nexport const WALL_TRACT: WallTissue = { m: 1.5, r: 2000, k: 1e5 };\n/**\n * Relaxed cheeks: Ishizaka, French and Flanagan (1975, \"Direct determination of vocal tract wall\n * impedance\", IEEE TASSP 23) measured the cheek and neck walls by vibrating them, broad resonances\n * of 30 to 70 Hz; the per-area values reproduced from them in later models are m 1.5 g/cm^2,\n * r 800 dyn s/cm^3 and k 66 667 dyn/cm^3 (a 33.5 Hz resonance). The airway's oral walls blend from\n * WALL_TRACT toward these with the `cheeks` setting: slack cheeks let a closed mouth expand, which\n * keeps the folds voicing through a /b d g/ longer.\n */\nexport const WALL_CHEEK_RELAXED: WallTissue = { m: 1.5, r: 800, k: 66667 };\n/** The trachea's cartilage-ringed wall (physics.rs WALL_TRACHEA). */\nexport const WALL_TRACHEA: WallTissue = { m: 0.6, r: 1000, k: 1e6 };\n/** The nasal cavity's mucosa over bone (physics.rs WALL_NASAL). */\nexport const WALL_NASAL: WallTissue = { m: 1.0, r: 3000, k: 1e6 };\n", "/*\n * A tube of fixed shape in the junction airway (dsp/junction-airway.ts): the\n * trachea, or the nasal cavity behind the velum. Its sections never move,\n * so the runs of sections between a few lumped nodes are pure delays (two\n * ring buffers per segment), and the walls and viscous resistance of the\n * junctions a node stands for are summed onto it. Its node coefficients are\n * computed once per configure(), never per sample.\n *\n * Every section is c / (2 rate) long, half a sample each way, so a segment\n * of m sections (m even) delays m / 2 samples. A node is a junction of the\n * airway's kind: a series flow element (viscous resistance and a\n * Borda-Carnot kinetic loss across its area step) with a yielding wall\n * (mass, resistance and stiffness per unit area) solved implicitly as a\n * Thevenin conductance.\n *\n * The element values are CHIMERA's (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49):\n * airway/network.rs:860-930 (viscous resistance at 700 Hz, Borda-Carnot\n * expansion with a 0.1 contraction loss), :960-1010 (walls). The lumping is\n * this airway's, MEASURED in its prototype: 4 trachea and 6 nasal nodes\n * against one junction per section came within 40 to 47 dB SNR, with band\n * levels within 0.1 dB. See THIRD_PARTY_NOTICES.md.\n */\n\nimport { AIR_DENSITY, AIR_DYNAMIC_VISCOSITY, SOUND_SPEED, type WallTissue } from './air';\n\nconst RHO_C = AIR_DENSITY * SOUND_SPEED;\n/** CHIMERA's viscous resistance at 700 Hz (network.rs:866). */\nconst VISC = Math.sqrt((AIR_DENSITY * AIR_DYNAMIC_VISCOSITY * 2 * Math.PI * 700) / 2);\n/** Ring length per segment and direction; segments are far shorter than this at any supported rate. */\nexport const TUBE_RING = 256;\nconst MASK = TUBE_RING - 1;\n\nexport class AirwayTube {\n /** Node count including both ends. */\n nn = 0;\n /** Segment delays in samples (segment s joins node s and s + 1). */\n readonly D: Int32Array;\n /** Forward (toward node s + 1) and backward rings, TUBE_RING per segment. */\n readonly F: Float64Array;\n readonly B: Float64Array;\n /** Segment impedances and areas. */\n readonly Z: Float64Array;\n readonly area: Float64Array;\n /* Interior node coefficients. */\n private readonly rv: Float64Array;\n private readonly wS: Float64Array;\n private readonly gam: Float64Array;\n private readonly ibq: Float64Array;\n private readonly wV: Float64Array;\n private readonly wY: Float64Array;\n /** Flow through each node, cm^3/s. */\n readonly U: Float64Array;\n private wCm = 0;\n private wK = 0;\n private wIb = 0;\n private T = 0;\n /*\n * Side resonators on interior nodes (a paranasal sinus): a lumped acoustic mass M, resistance R and\n * stiffness K = 1 / C in series, the same equation as a wall with lumped values. Per node: its\n * conductance (0 for none), history coefficient and stiffness, and its flow and displacement.\n */\n private readonly sG: Float64Array;\n private readonly sCm: Float64Array;\n private readonly sK: Float64Array;\n private readonly sQ: Float64Array;\n private readonly sY: Float64Array;\n private readonly sP: Float64Array;\n\n /** maxNodes: the most nodes any configure() will ask for. */\n constructor(maxNodes: number) {\n const ns = maxNodes - 1;\n this.D = new Int32Array(ns);\n this.F = new Float64Array(ns * TUBE_RING);\n this.B = new Float64Array(ns * TUBE_RING);\n this.Z = new Float64Array(ns);\n this.area = new Float64Array(ns);\n this.rv = new Float64Array(maxNodes);\n this.wS = new Float64Array(maxNodes);\n this.gam = new Float64Array(maxNodes).fill(1);\n this.ibq = new Float64Array(maxNodes);\n this.wV = new Float64Array(maxNodes);\n this.wY = new Float64Array(maxNodes);\n this.U = new Float64Array(maxNodes);\n this.sG = new Float64Array(maxNodes);\n this.sCm = new Float64Array(maxNodes);\n this.sK = new Float64Array(maxNodes);\n this.sQ = new Float64Array(maxNodes);\n this.sY = new Float64Array(maxNodes);\n this.sP = new Float64Array(maxNodes);\n }\n\n /**\n * Hang a resonator on interior node m, discretized by the trapezoidal rule (side-branch.ts): 1 / D, the history coefficient M / T - R / 2 - K T / 4, and the stiffness K.\n * Call after configure(); configure() removes every resonator. Off the audio path.\n */\n addResonator(m: number, invD: number, cm: number, K: number): void {\n if (!(m >= 1 && m < this.nn - 1) || !(invD > 0)) return;\n this.sG[m] = 0.5 * invD;\n this.sCm[m] = cm * invD;\n this.sK[m] = K * invD;\n this.refresh(m);\n }\n\n /** A node's coefficients from its wall and resonator. */\n private refresh(m: number): void {\n const z1 = this.Z[m - 1];\n const g = 1 / (1 + z1 * (this.wS[m] * this.wIb + this.sG[m]));\n this.gam[m] = g;\n this.ibq[m] = 1 / (z1 * g + this.Z[m] + this.rv[m]);\n }\n\n /**\n * Lay the tube out: sections[0 .. count) of area secAreas (cm^2), nodes at\n * the even section indices nodesAt[0 .. nn) (0 and count included), walls\n * of `wall` over a perimeter `perim` times a circle's, viscous resistance\n * times viscF, sections dx cm long at `rate`. Clears every wave and wall.\n */\n configure(secAreas: Float64Array, count: number, nodesAt: Int32Array, nn: number, wall: WallTissue, perim: number, viscF: number, dx: number, rate: number): void {\n this.nn = nn;\n this.T = 1 / rate;\n const ns = nn - 1;\n for (let s = 0; s < ns; s++) {\n const a0 = nodesAt[s];\n const a1 = nodesAt[s + 1];\n this.D[s] = (a1 - a0) >> 1;\n let inv = 0;\n for (let i = a0; i < a1; i++) inv += 1 / secAreas[i];\n this.area[s] = (a1 - a0) / inv;\n this.Z[s] = RHO_C / this.area[s];\n }\n const beta = wall.m * rate + 0.5 * wall.r;\n this.wCm = wall.m * rate - 0.5 * wall.r;\n this.wK = wall.k;\n this.wIb = 1 / beta;\n this.rv.fill(0);\n this.wS.fill(0);\n // each section junction i (between sections i - 1 and i) goes to the nearest interior node\n const hr = perim * 2 * Math.sqrt(Math.PI) * dx * viscF;\n for (let i = 1; i < count; i++) {\n let best = -1;\n let bd = Infinity;\n for (let m = 1; m < nn - 1; m++) {\n const d = nodesAt[m] > i ? nodesAt[m] - i : i - nodesAt[m];\n if (d < bd) {\n bd = d;\n best = m;\n }\n }\n if (best < 0) continue;\n const al = secAreas[i - 1];\n const ar = secAreas[i];\n this.rv[best] += 0.25 * VISC * hr * (Math.pow(al, -1.5) + Math.pow(ar, -1.5));\n this.wS[best] += perim * 2 * Math.sqrt(Math.PI * 0.5 * (al + ar)) * dx;\n }\n this.sG.fill(0);\n this.sCm.fill(0);\n this.sK.fill(0);\n for (let m = 1; m < nn - 1; m++) this.refresh(m);\n this.reset();\n }\n\n /** Every wave, flow and wall at rest. */\n reset(): void {\n this.F.fill(0);\n this.B.fill(0);\n this.wV.fill(0);\n this.wY.fill(0);\n this.U.fill(0);\n this.sQ.fill(0);\n this.sY.fill(0);\n this.sP.fill(0);\n }\n\n /**\n * The interior nodes for ring position pos. The end nodes belong to the\n * airway (lungs and glottis, velum and nostrils).\n */\n interior(pos: number): void {\n const F = this.F;\n const B = this.B;\n const D = this.D;\n const Z = this.Z;\n const wCm = this.wCm;\n const wK = this.wK;\n const wIb = this.wIb;\n const T = this.T;\n const nn = this.nn;\n for (let m = 1; m < nn - 1; m++) {\n const segL = (m - 1) * TUBE_RING;\n const segR = m * TUBE_RING;\n const a = F[segL + ((pos - D[m - 1]) & MASK)];\n const b = B[segR + ((pos - D[m]) & MASK)];\n const z1 = Z[m - 1];\n const wv = this.wV[m];\n const wy = this.wY[m];\n const hist = wCm * wv - wK * wy;\n const sg = this.sG[m];\n // the history flow: (p_prev / 2 + cm q_prev - K y_prev) / D, the coefficients held already over D\n const sh = sg > 0 ? sg * this.sP[m] + this.sCm[m] * this.sQ[m] - this.sK[m] * this.sY[m] : 0;\n const ue0 = -this.wS[m] * hist * wIb - sh;\n const gam = this.gam[m];\n const u = (2 * a * gam - 2 * b + z1 * gam * ue0) * this.ibq[m];\n const p = (2 * a - z1 * (u - ue0)) * gam;\n const v = (hist + p) * wIb;\n this.wV[m] = v;\n this.wY[m] = wy + T * v;\n if (sg > 0) {\n const q = sg * p + sh;\n this.sY[m] += 0.5 * T * (q + this.sQ[m]);\n this.sQ[m] = q;\n this.sP[m] = p;\n }\n B[segL + pos] = p - a;\n F[segR + pos] = b + Z[m] * u;\n this.U[m] = u;\n }\n }\n}\n\n/** Even node positions 0 .. n with up to `inner` interior nodes, into out; returns the node count. */\nexport function evenNodes(n: number, inner: number, out: Int32Array): number {\n let c = 0;\n out[c++] = 0;\n for (let m = 1; m <= inner; m++) {\n const v = 2 * Math.round((m * n) / (inner + 1) / 2);\n if (v > out[c - 1] && v < n) out[c++] = v;\n }\n out[c++] = n;\n return c;\n}\n", "/*\n * Side branches of the airway: cavities that open off the main tube and put zeros in its spectrum.\n *\n * A closed side tube of depth L and area A presents Z(w) = -j Z0 cot(wL / c) at its mouth; near its\n * quarter-wave resonance w0 = pi c / 2L that is Z ~ j Z0 (w - w0) L / c, the impedance of a series\n * mass and spring with M = rho L / (2 A) and K = w0^2 M. A Helmholtz resonator is that element exactly:\n * M = rho L_neck / A_neck, K = rho c^2 / V. So every branch here is one lumped series M, R, K, and the\n * airway folds it into a junction as it folds a wall (docs/HOW-IT-WORKS.md, section 11.1).\n *\n * Discretized by the trapezoidal rule (the bilinear transform), which maps a passive impedance to a\n * passive discrete element at any rate: the walls' explicit spring made a 4.2 kHz branch unstable at\n * 22.05 kHz (MEASURED). With D = M / T + R / 2 + K T / 4 the branch's flow is\n *\n * q_n = p_n / (2 D) + (p_{n-1} / 2 + (M / T - R / 2 - K T / 4) q_{n-1} - K y_{n-1}) / D\n * y_n = y_{n-1} + T (q_n + q_{n-1}) / 2\n *\n * a conductance 1 / (2 D) in the junction's solve and a history flow; the resonance is pre-warped,\n * w_set = (2 / T) tan(w0 T / 2). Pure arithmetic, no state: the airway holds each branch's q, y, p.\n */\n\nimport { AIR_DENSITY, SOUND_SPEED } from './air';\n\nconst RHO = AIR_DENSITY;\n\n/** A trapezoidal branch's coefficients: 1 / D, the history coefficient M / T - R / 2 - K T / 4, and K. */\nexport type BranchCoefficients = [invD: number, history: number, stiffness: number];\n\n/** A series mass-spring branch of mass M (g/cm^4) tuned to f0 (Hz) at quality q, at `rate`. */\nexport function branchCoefficients(M: number, f0: number, q: number, rate: number): BranchCoefficients {\n const w0 = 2 * Math.PI * f0;\n const wSet = 2 * rate * Math.tan(w0 / (2 * rate));\n const K = wSet * wSet * M;\n const R = (w0 * M) / q;\n const D = M * rate + 0.5 * R + K / (4 * rate);\n return [1 / D, M * rate - 0.5 * R - K / (4 * rate), K];\n}\n\n/*\n * The piriform fossae (Dang and Honda 1997, JASA 101, 456-465): MRI volumes 2.1 to 2.9 cm^3, depths\n * 1.6 to 2.0 cm, a spectral minimum at 4 to 5 kHz. The pair as one branch of 2.5 k^3 cm^3 and 1.8 k cm,\n * end-corrected by 0.61 of each fossa's radius: 4.2 kHz in the male body.\n */\nconst PIRIFORM_VOLUME = 2.5;\nconst PIRIFORM_DEPTH = 1.8;\n/** INFERRED: soft mucosal walls; the measured minima are a few hundred Hz wide. */\nconst PIRIFORM_Q = 10;\n\n/** The piriform fossae for a body of scale k at `rate`. */\nexport function piriformBranch(k: number, rate: number): BranchCoefficients {\n const depth = PIRIFORM_DEPTH * k;\n const area = (PIRIFORM_VOLUME * k * k * k) / depth;\n const leff = depth + 0.61 * Math.sqrt(area / 2 / Math.PI);\n return branchCoefficients((RHO * leff) / (2 * area), SOUND_SPEED / (4 * leff), PIRIFORM_Q, rate);\n}\n\n/*\n * The maxillary sinuses (Dang and Honda 1996, JASA 100, 3374-3383: four Helmholtz resonators model the\n * sinuses; the maxillary zero lies between 310 and 950 Hz). The pair as one resonator of 30 k^3 cm^3\n * behind an ostium of 0.2 k^2 cm^2 and 1 k cm: 455 Hz in the male body.\n */\nconst SINUS_VOLUME = 30;\nconst SINUS_NECK_AREA = 0.2;\nconst SINUS_NECK_LENGTH = 1;\n/** INFERRED. */\nconst SINUS_Q = 8;\n\n/** The maxillary sinuses for a body of scale k at `rate`. */\nexport function sinusBranch(k: number, rate: number): BranchCoefficients {\n const v = SINUS_VOLUME * k * k * k;\n const m = (RHO * SINUS_NECK_LENGTH * k) / (SINUS_NECK_AREA * k * k);\n const f0 = Math.sqrt((RHO * SOUND_SPEED * SOUND_SPEED) / v / m) / (2 * Math.PI);\n return branchCoefficients(m, f0, SINUS_Q, rate);\n}\n", "/*\n * How fast a cross-section of the tract may open or close: CHIMERA's area\n * rate limit, ported from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth,\n * crates/chimera/src/voice/human_airway.rs:151-156 and 190-262 at\n * 1d3ea49). Reimplemented; see THIRD_PARTY_NOTICES.md. The junction\n * airway (dsp/junction-airway.ts) runs it on its grid sections and on\n * their sub-section minima, as CHIMERA runs it on its network's.\n *\n * Opening is limited to (45 k^2 + 40 A) cm^2/s: wide cavities reshape\n * fast, narrow constrictions open at a physiological rate, which sets how\n * sharp a burst is. Closing eases from that rate down to 5 k^2 cm^2/s by a\n * smoothstep between 0.03 and 0.4 k^2 cm^2, and under 0.03 k^2 slows\n * with sqrt(A / 0.03 k^2), so a seal is reached smoothly. CHIMERA's\n * comments say why: at a constant rate the flow's slope dropped to zero at\n * once, a step in the radiated pressure, and sealing at the opening rate\n * shut within about a millisecond; both are audible clicks. A prototype\n * of this voice had no limit and clicked at stop releases (MEASURED:\n * 421 click events CHIMERA lacked over 21 renders).\n */\n\nconst MAX_AREA_RATE = 45;\nconst AREA_RATE_GAIN = 40;\nconst SEAL_RATE = 5;\nconst SEAL_LO = 0.03;\nconst SEAL_HI = 0.4;\nconst SEAL_EASE = 0.03;\n\nexport class AreaSlew {\n private openR = MAX_AREA_RATE;\n private sealR = SEAL_RATE;\n private lo = SEAL_LO;\n private hi = SEAL_HI;\n private ease = SEAL_EASE;\n private dt = 0;\n\n /** The body scale k: every rate and threshold scales with k^2. */\n setScale(k: number): void {\n const k2 = k * k;\n this.openR = MAX_AREA_RATE * k2;\n this.sealR = SEAL_RATE * k2;\n this.lo = SEAL_LO * k2;\n this.hi = SEAL_HI * k2;\n this.ease = SEAL_EASE * k2;\n }\n\n /** The step limitAll() limits over, seconds. Set once; no double crosses limitAll(). */\n setStep(dt: number): void {\n this.dt = dt;\n }\n\n /** The closing rate at area a, cm^2/s. */\n private closeRate(a: number): number {\n if (a < this.ease) return this.sealR * Math.sqrt((a > 0 ? a : 0) / this.ease);\n const u = a <= this.lo ? 0 : a >= this.hi ? 1 : (a - this.lo) / (this.hi - this.lo);\n return this.sealR + (this.openR - this.sealR) * u * u * (3 - 2 * u);\n }\n\n /** The area `next` limited against `prev` over dt seconds. */\n limit(next: number, prev: number, dt: number): number {\n const d = next - prev;\n if (d > 0) {\n const lim = (this.openR + AREA_RATE_GAIN * next) * dt;\n return d > lim ? prev + lim : next;\n }\n const lim = (this.closeRate(prev) + AREA_RATE_GAIN * prev) * dt;\n return d < -lim ? prev - lim : next;\n }\n\n /** next[0 .. count) limited against prev over setStep()'s step, in place; limit() written out, so no double crosses a call. */\n limitAll(next: Float64Array, prev: Float64Array, count: number): void {\n const dt = this.dt;\n const openR = this.openR;\n const sealR = this.sealR;\n const lo = this.lo;\n const span = this.hi - this.lo;\n const ease = this.ease;\n for (let i = 0; i < count; i++) {\n const a = prev[i];\n const d = next[i] - a;\n if (d > 0) {\n const lim = (openR + AREA_RATE_GAIN * next[i]) * dt;\n if (d > lim) next[i] = a + lim;\n continue;\n }\n let rate: number;\n if (a < ease) rate = sealR * Math.sqrt((a > 0 ? a : 0) / ease);\n else {\n let u = (a - lo) / span;\n u = u < 0 ? 0 : u > 1 ? 1 : u;\n rate = sealR + (openR - sealR) * u * u * (3 - 2 * u);\n }\n const lim = (rate + AREA_RATE_GAIN * a) * dt;\n if (d < -lim) next[i] = a - lim;\n }\n }\n}\n", "/*\n * Ported from CHIMERA by Jameson Hodge (MIT), https://github.com/jamesondh/chimera-vocal-synth,\n * crates/chimera/src/sources/glottis.rs, with the Drift from crates/chimera/src/math.rs and the\n * source mapping from crates/chimera/src/voice/human_voice.rs, at 1d3ea49 (TypeScript original at\n * cd247a6^:src/engine/sources/glottis.ts). Changes from the original: an inertive orifice and a\n * derivative stand in for the airway that turned area into flow, the closure corner is band\n * limited, and vibrato, the pressure gate and the leak terms are left to the engine. See\n * THIRD_PARTY_NOTICES.md.\n *\n * Glottal source: the vocal-fold pulse of a singing voice, as the flow\n * derivative excitation a source-filter voice runs through its formants.\n *\n * WHAT IS PORTED\n *\n * A phase accumulator drives a normalised glottal area pulse, so pitch is\n * exact by construction: nothing estimates a period, the phase just wraps\n * at the requested rate. Within the open quotient the area rises as a\n * half cosine over the first `skew` of the open phase and falls over the\n * rest as a blend of a raised cosine (soft closure, zero slope at the end)\n * and a quarter cosine (abrupt closure, finite slope at the end), mixed by\n * closure sharpness (glottis.rs:231-246).\n *\n * Each cycle draws a period scale and an amplitude: jitter and shimmer\n * from one stream, diplophonia as a fixed alternation of both, and a\n * logistic map x -> r x (1 - x) with r = 2.9 + 1.1 chaos, which walks\n * through period doubling (subharmonics near 0.3) into deterministic chaos\n * past about 0.62 (glottis.rs:178-199). Fry pulls the rate toward 48 Hz,\n * shortens the open quotient toward 0.28 and adds a weaker second pulse at\n * phase 0.38 (glottis.rs:165-168, 202-213). The pitch drift is CHIMERA's\n * 1/f approximation: three one-pole filtered noises at 0.3, 0.9 and\n * 2.7 Hz, each held at unit variance, weighted 1, 1/2, 1/3 and divided by\n * 1.4 (math.rs:236-258).\n *\n * The voice mapping is CHIMERA's (human_voice.rs:317-350): open quotient\n * 0.78 - 0.36 tension, closure sharpness 0.4 tension + 1.375 max(0,\n * tension - 0.6), skew 0.56 + 0.16 tension, jitter 0.0021 + 0.0245\n * roughness, shimmer 0.02 + 0.22 roughness, diplophonia 1.4 (roughness -\n * 0.5) above 0.5. Brightness sits at its default there, where it drops\n * out, and effort at the default lung pressure of 8 cmH2O is 0.5, where\n * its open quotient term is zero. These are the Rust constants at 1d3ea49;\n * the TypeScript original at cd247a6^ mapped jitter as 0.003 + 0.035\n * roughness and sharpness as 0.25 + 0.7 tension, which upstream has since\n * retuned. CHIMERA's human voice does not tie chaos to roughness (only its\n * creatures do), so chaos has its own setter, and so do the raw jitter,\n * shimmer and diplophonia, which setRoughness sets together.\n *\n * Fixed seeds become forks of the stream given at construction: 'jitter'\n * (CHIMERA's 777) for the per-cycle draws, 'drift' (its 4242) for the\n * drift, and 'chaos' for the starting point of the logistic map, which\n * CHIMERA fixes at 0.37. A fixed start would put every pooled voice on the\n * same chaotic trajectory, in unison, so it is drawn on each reset.\n *\n * bellows' NamedRng.gauss() is the Irwin-Hall sum of four uniforms scaled\n * by SQRT2 * 0.875, standard deviation 0.714 (see types.ts). CHIMERA's is\n * the same sum scaled to unit variance. Every draw here is multiplied by\n * UNIT_GAUSS, so jitter, shimmer and the drift, whose band gains assume\n * unit variance, land at CHIMERA's depths. Both generators are\n * mulberry32, so the noise has the same character.\n *\n * The drift updates at DRIFT_CONTROL_HZ rather than every 32 samples.\n * Each band is an Ornstein-Uhlenbeck process and the one-pole update with\n * pole exp(-2 pi f / rate) and input gain sqrt(1 - pole^2) is its exact\n * discretisation, so the process is the same at any control rate; only\n * the cost changes. At 500 Hz the pitch steps every 2 ms, by 0.61 cents\n * rms at the default 6 cents of drift, against 8.5 cents rms of per-cycle\n * jitter at the default roughness of 0.1 (MEASURED). Every 32 samples it\n * cost about 5 ns a sample (MEASURED), a fifth of the unit.\n *\n * AREA TO FLOW, WHICH IS NOT A PORT\n *\n * CHIMERA outputs area and lets its FDTD airway compute flow (Bernoulli\n * drop plus the inertance of the air column), so the skew of the flow\n * pulse and the steepened closure come from the physics. There is no\n * airway here. The same two terms reduced to a single node give the\n * classic inertive orifice: subglottal pressure = (rho / 2)(U / A)^2 +\n * L dU/dt. Normalised by the peak area and the quasi-steady flow it\n * becomes\n *\n * T du/dt = 1 - (u / a)^2\n *\n * with a the area pulse and u the flow, both about 1 at peak. Flow lags\n * area while the glottis opens (inertance limits how fast the column\n * accelerates) and is pinned to the shrinking area as it closes (the\n * orifice resistance grows without bound), which skews the pulse to the\n * right and steepens the fall: the mechanism Rothenberg (1981, \"Acoustic\n * interaction between the glottal source and the vocal tract\") and Titze\n * (2008, \"Nonlinear source-filter coupling in phonation\", JASA 123) give\n * for the skewed flow of real voices. Each step is backward Euler, a\n * quadratic in the new flow solved in closed form, in the rationalised\n * form that has no cancellation and goes to exactly zero with the area.\n * Backward Euler because the closing end of the cycle is stiff: the\n * relaxation time a T / 2 goes to zero with the area, and an explicit or\n * trapezoidal step rings or goes negative there.\n *\n * T is a fixed fraction of the period, INERTANCE = 0.08, not a fixed time.\n * L = rho l / A for the epilarynx and tract gives T of 0.5 to 0.9 ms, 0.055\n * to 0.1 of a 110 Hz period (INFERRED from textbook dimensions). Holding it\n * as a fraction keeps the pulse shape, and so the timbre, the same up the\n * range, where a fixed time would skew high notes until they lost level.\n * That is also closer to life at the top: once f0 passes F1 the tract is\n * no longer inertive and the skew goes away. At 0.08 the flow peak lands\n * 0.025 of a period after the area peak at tension 0.5, and the tilt over\n * harmonics 1 to 10 is -14.6, -10.5 and -3.2 dB per octave at tension 0,\n * 0.5 and 1 (MEASURED).\n *\n * Lip radiation is a differentiator, so the excitation is the flow\n * derivative. It is taken with respect to cycle phase, the first\n * difference divided by the phase increment, which makes the output scale\n * independent of sample rate and of pitch: harmonics 1 to 10 agree within\n * 0.3 dB at 44.1, 48 and 96 kHz (MEASURED, 220 Hz). GAIN puts the peak of\n * the default pulse at 1.\n *\n * BAND LIMITING, BY MEASUREMENT\n *\n * The flow has a slope discontinuity where the area closes with any\n * sharpness, so the derivative steps there, and that step aliases. The\n * first difference of a sampled corner is already a one-sample box step;\n * the rest is measured. Alias energy against harmonic energy in dB, f0\n * 880 Hz, 48 kHz, perturbations off, 65536-point Blackman-Harris spectrum,\n * every bin more than 6 Hz from a harmonic counted as alias:\n *\n * tension 0.5 (sharpness 0.2) tension 1 (sharpness 0.95)\n * all <5 kHz <10 kHz all <5 kHz <10 kHz\n * no correction -42.5 -64.9 -56.6 -23.0 -45.6 -37.2\n * 2-point polyBLAMP -50.2 -78.1 -69.5 -34.5 -79.4 -69.5\n * 2x oversampled -52.1 -78.5 -69.0 -32.3 -59.0 -49.2\n * 4x oversampled -52.8 -89.1 -81.1 -32.9 -71.0 -61.5\n * 4-point B-spline BLAMP -52.0 -78.2 -69.8 -44.4 -77.2 -67.4\n * Kaiser BLAMP, 8 a side -52.3 -78.2 -69.8 -53.2 -77.6 -67.5\n *\n * Oversampling runs through dsp/oversample.ts, whose halfband passes 24\n * to 28.8 kHz partly and folds it back under Nyquist, so it leaves the\n * near-Nyquist total almost where it was and only gains in band. The\n * corner correction removes the corner itself, so it wins in band, where\n * the formants are, at no measurable cost: in one Node 22 process on an\n * M1, at 220 Hz and 48 kHz, the uncorrected and corrected pulse both ran\n * 33.3 ns a sample in the prototype the table was measured with, against\n * 94.4 ns at 2x and 215.9 ns at 4x. Longer residuals only move the\n * near-Nyquist total, which the formant filters bury, and need up to 8\n * samples of lookahead, so the 2-point polyBLAMP of Esqueda, Valimaki and\n * Bilbao (2016, \"Rounding corners with BLAMP\", DAFx) is the choice. What\n * remains in band at tension 0.5 is the curvature jumps at opening and at\n * the peak, 78 dB down. At 1760 Hz, tension 1, the corrected unit is still\n * -64.8 dB under 5 kHz.\n *\n * The correction needs the flow slope just before closure, one sample\n * ahead of it. Near closure the flow is pinned at u = k a, and the\n * equation above gives k^2 - T s k - 1 = 0 for an area closing with slope\n * s per unit phase, so the flow closes with slope k s. That is exact in\n * the continuous limit and needs no history, so it holds at high f0 where\n * a few samples span the whole closing phase.\n *\n * COST\n *\n * At 48 kHz this unit runs 22 to 23 ns a sample at 220 Hz and 25 to 26 ns\n * at 880 Hz, against 6.1 to 6.4 and 10.8 to 11.1 ns for a BlepOscillator\n * saw at the same pitch in the same Node 22 process on an M1 (MEASURED,\n * medians of 7 runs of 5 s, two processes): 3.6 and 2.3 times the saw,\n * about 0.11 percent of a core per voice. Quote the ratio, as\n * dsp/oscillators.ts explains; the wall clock moves with the harness.\n * The per-sample work is step(), kept under V8's 460-byte bytecode limit\n * for inlining, with the per-cycle and per-closure work in separate\n * methods: at 767 bytes it was not inlined into its caller, every call\n * boxed its return value, and it cost 34 ns. It leaves its sample in a\n * field instead of returning it, so a caller that does not inline it pays\n * a call and nothing else. Whether a caller inlines it can depend on\n * compile order, which V8 picks by timing: once step() has been optimized\n * on its own, a caller pays 1.2 times step() plus everything inlined into\n * it (reserve_inline_budget_scale_factor) out of a 920-byte cumulative\n * budget. That is 368 + 137 + 85 + 91 bytes (step, area, pulse, one\n * sinQuarter), times 1.2, 817 (MEASURED, --trace-turbo-inlining). The\n * pulse once evaluated its sine at two call sites and came to 928, so\n * process() sometimes kept the per-sample call, and in the vocal engine\n * that boxed 13 bytes a sample in 3 runs of 16 under load (MEASURED);\n * test/engines-physical/vocal.test.ts forces that order. `node\n * --print-bytecode --print-bytecode-filter=step` prints the length. A\n * caller whose own loop is large can still exhaust the budget, which is\n * what process() is for.\n *\n * Shape parameters (tension and fry) take effect at the next cycle start,\n * where the area is zero. Moving the open quotient mid-pulse could cut the\n * area to zero at once, and the pinned flow would follow it within a\n * sample: a click. Frequency is applied every sample.\n */\n\nimport type { NamedRng } from 'bellowsjs';\nimport { clamp } from 'bellowsjs';\n\n/** Turns a bellows gauss() draw (sd 0.714) into a unit-variance one, as CHIMERA draws. */\nconst UNIT_GAUSS = 1 / (Math.sqrt(1 / 3) * Math.SQRT2 * 0.875);\n\nconst HALF_PI = Math.PI / 2;\n\n/*\n * sin(pi x / 2) for x in [0, 1], by its Taylor series to x^15, each\n * coefficient derived from the last. The first omitted term bounds the\n * error at 6.1e-12, far under a float32 sample. It replaces Math.sin and\n * Math.cos in the pulse, which V8 compiles to calls out of the generated\n * code: 3.4 ns a sample cheaper (MEASURED), and independent of any\n * platform's libm.\n */\nconst S1 = HALF_PI;\nconst S3 = (-S1 * HALF_PI * HALF_PI) / (2 * 3);\nconst S5 = (-S3 * HALF_PI * HALF_PI) / (4 * 5);\nconst S7 = (-S5 * HALF_PI * HALF_PI) / (6 * 7);\nconst S9 = (-S7 * HALF_PI * HALF_PI) / (8 * 9);\nconst S11 = (-S9 * HALF_PI * HALF_PI) / (10 * 11);\nconst S13 = (-S11 * HALF_PI * HALF_PI) / (12 * 13);\nconst S15 = (-S13 * HALF_PI * HALF_PI) / (14 * 15);\n\nfunction sinQuarter(x: number): number {\n const z = x * x;\n return x * (S1 + z * (S3 + z * (S5 + z * (S7 + z * (S9 + z * (S11 + z * (S13 + z * S15)))))));\n}\n\n/** Inertive time constant of the airway, as a fraction of the glottal period. */\nconst INERTANCE = 0.08;\nconst INV_INERTANCE = 1 / INERTANCE;\n\n/**\n * Output scale. The default pulse (tension 0.5, perturbations off) has a\n * phase-derivative peak of 8.43 (MEASURED, 110 Hz at 48 kHz), so this puts\n * it at 1.\n */\nconst GAIN = 1 / 8.43;\n\n/** Drift control rate in Hz. See the header for why it is not CHIMERA's 32 samples. */\nconst DRIFT_CONTROL_HZ = 500;\n/** Slowest drift band in Hz. The others sit at 3 and 9 times it. */\nconst DRIFT_BASE_HZ = 0.3;\n/** Band weights 1, 1/2, 1/3 summed and divided by this (math.rs:254-257). */\nconst DRIFT_NORM = 1.4;\nconst MAX_DRIFT_CENTS = 100;\n\n/** Fry pulls the rate toward this many Hz. */\nconst FRY_HZ = 48;\n/** Open quotient fry moves toward. */\nconst FRY_OQ = 0.28;\n/** The second fry pulse starts at this phase, with this open quotient ratio and peak. */\nconst FRY_OFFSET = 0.38;\nconst FRY_OQ_RATIO = 0.8;\nconst FRY_PEAK = 0.55;\n\n/*\n * Per-cycle period scale limits 0.55 and 1.8 (glottis.rs:197) and amplitude\n * floor 0.12 (glottis.rs:198), written as literals in startCycle().\n */\n\n/** Where the logistic map restarts if rounding lands it on 0 or 1, CHIMERA's constant. */\nconst CHAOS_RESTART = 0.37;\n/** Range the map's start is drawn from on reset, clear of the fixed points at 0 and 1. */\nconst CHAOS_START_LO = 0.2;\nconst CHAOS_START_SPAN = 0.6;\n\n/** A closure phase no cycle reaches, for a pulse that has no corner to correct. */\nconst NO_CORNER = 2;\n\nconst MIN_HZ = 1;\n/**\n * Highest rate as a fraction of the sample rate. With the period scale\n * floor of 0.55 the phase step stays under 0.46, so the phase never\n * wraps twice in a sample.\n */\nconst MAX_HZ_FRACTION = 0.25;\nconst MAX_JITTER = 0.25;\n\n/**\n * Normalised area of one pulse at cycle phase ph (glottis.rs:233-246):\n * a half cosine rise over the first `skew` of the open phase, then a\n * fall mixing soft (cos^2, which is the raised cosine) and hard (cos)\n * closure by `sharp`.\n */\nfunction pulse(\n ph: number,\n oq: number,\n invOq: number,\n skew: number,\n invSkew: number,\n invFall: number,\n sharp: number,\n): number {\n if (ph >= oq) return 0;\n const t = ph * invOq;\n // The rise and the fall each take one quarter sine, so one evaluation\n // serves both. One call site rather than two keeps sinQuarter's 91 bytes\n // of bytecode out of step()'s inlining budget once more; see COST.\n const rising = t < skew;\n const s = sinQuarter(rising ? t * invSkew : 1 - (t - skew) * invFall);\n const s2 = s * s;\n return rising ? s2 : s2 + (s - s2) * sharp;\n}\n\nexport class GlottalSource {\n private readonly sampleRate: number;\n private readonly invSampleRate: number;\n private readonly maxHz: number;\n private readonly cycleRng: NamedRng;\n private readonly driftRng: NamedRng;\n private readonly chaosRng: NamedRng;\n /**\n * mulberry32 states of the cycle and drift draws, int32, reseeded from\n * their streams at every reset(). The generator runs inline here: a call\n * into a stream's closure per draw returned a boxed double each time\n * (MEASURED: 2 bytes a sample in the vocal engine). Reseeding from the\n * stream keeps every draw reproducible from its label, and successive\n * notes still differ because each reset advances the stream.\n */\n private cycleS = 1;\n private driftS = 1;\n\n /* Drift interval in samples, band poles, and the input gains that hold each band at unit variance. */\n private readonly driftInterval: number;\n private readonly driftPole0: number;\n private readonly driftPole1: number;\n private readonly driftPole2: number;\n private readonly driftIn0: number;\n private readonly driftIn1: number;\n private readonly driftIn2: number;\n\n /* Settings. The shape targets wait for the next cycle start. */\n private hz = 110;\n private targetOq = 0.6;\n private targetSkew = 0.64;\n private targetSharp = 0.2;\n private targetFry = 0;\n private jitter = 0;\n private shimmer = 0;\n private diplophonia = 0;\n private chaos = 0;\n private driftCents = 6;\n\n /* The shape in force for this cycle. */\n private fry = 0;\n private oq = 0.6;\n private invOq = 1 / 0.6;\n private skew = 0.64;\n private invSkew = 1 / 0.64;\n private invFall = 1 / 0.36;\n private sharp = 0.2;\n private fryGain = 0;\n private oq2 = 0;\n private invOq2 = 0;\n private end2 = 0;\n /* Where each pulse closes onto a corner the polyBLAMP corrects, NO_CORNER if it does not. */\n private closeFirst = NO_CORNER;\n private closeSecond = NO_CORNER;\n\n /* Cycle state. phase, odd, amp, ampPrev, scale and pitchFactor are read by\n * the fold models (dsp/geometric-glottis.ts, dsp/fold-oscillator.ts) that\n * take their cycle from this unit; nothing outside writes them. */\n phase = 0;\n odd = false;\n scale = 1;\n amp = 1;\n /** The amplitude of the cycle before this one, for an edge that lags into it. */\n ampPrev = 1;\n private chaosX = CHAOS_RESTART;\n private inc = 0;\n\n /* Drift state. */\n private drift0 = 0;\n private drift1 = 0;\n private drift2 = 0;\n private driftCountdown = 0;\n pitchFactor = 1;\n\n /* Flow: the inertive state, the corrected flow the derivative is taken\n * of, and the corner correction owed to the next sample. */\n private u = 0;\n private uOut = 0;\n private pending = 0;\n /** The sample step() made; see step() for why it is a field and not a return value. */\n private y = 0;\n /** The area nextArea() computed; openArea reads it. A field, so a hot loop reads it without a call. */\n aOut = 0;\n\n constructor(sampleRate: number, rng: NamedRng) {\n this.sampleRate = sampleRate;\n this.invSampleRate = 1 / sampleRate;\n this.maxHz = sampleRate * MAX_HZ_FRACTION;\n this.cycleRng = rng.fork('jitter');\n this.driftRng = rng.fork('drift');\n this.chaosRng = rng.fork('chaos');\n this.driftInterval = Math.max(1, Math.round(sampleRate / DRIFT_CONTROL_HZ));\n const controlRate = sampleRate / this.driftInterval;\n this.driftPole0 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ) / controlRate);\n this.driftPole1 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ * 3) / controlRate);\n this.driftPole2 = Math.exp((-2 * Math.PI * DRIFT_BASE_HZ * 9) / controlRate);\n this.driftIn0 = Math.sqrt(1 - this.driftPole0 * this.driftPole0);\n this.driftIn1 = Math.sqrt(1 - this.driftPole1 * this.driftPole1);\n this.driftIn2 = Math.sqrt(1 - this.driftPole2 * this.driftPole2);\n // CHIMERA's default voice: tension 0.5, roughness 0.1, and the glottis default drift of 6 cents.\n this.setTension(0.5);\n this.setRoughness(0.1);\n this.reset();\n }\n\n /**\n * Starts a note from a closed glottis. The streams carry on rather than\n * rewind, so successive notes differ while a render stays reproducible\n * from its seed. Allocates nothing.\n */\n reset(): void {\n this.phase = 0;\n this.odd = false;\n this.scale = 1;\n this.amp = 1;\n this.ampPrev = 1;\n this.chaosX = CHAOS_START_LO + CHAOS_START_SPAN * this.chaosRng();\n this.cycleS = (this.cycleRng() * 4294967296) | 0;\n this.driftS = (this.driftRng() * 4294967296) | 0;\n this.drift0 = 0;\n this.drift1 = 0;\n this.drift2 = 0;\n this.driftCountdown = 0;\n this.pitchFactor = 1;\n this.u = 0;\n this.uOut = 0;\n this.pending = 0;\n this.aOut = 0;\n this.latch();\n this.inc = this.hz * this.invSampleRate;\n }\n\n /** Target f0 in Hz before drift, fry and the per-cycle perturbations. Cheap enough per sample. */\n setFreq(hz: number): void {\n // Math.min and Math.max, not clamp(): clamp's integer bounds merged into\n // the stored double and boxed it, about 0.8 bytes a sample at 48 kHz\n if (hz !== hz) return;\n this.hz = Math.min(Math.max(hz, MIN_HZ), this.maxHz);\n }\n\n /** setFreq(src[i]): the audio path's form, so no double crosses the call. */\n setFreqFrom(src: Float64Array, i: number): void {\n const hz = src[i];\n if (hz !== hz) return;\n this.hz = Math.min(Math.max(hz, MIN_HZ), this.maxHz);\n }\n\n /** 0 lax to 1 pressed: open quotient, closure sharpness and skew. */\n setTension(t: number): void {\n const v = clamp(t, 0, 1);\n this.targetOq = clamp(0.78 - 0.36 * v, 0.25, 0.98);\n this.targetSkew = clamp(0.56 + 0.16 * v, 0.3, 0.9);\n this.targetSharp = clamp(0.4 * v + 1.375 * Math.max(0, v - 0.6), 0, 1);\n if (this.phase === 0) this.latch();\n }\n\n /** 0..1: jitter, shimmer and, above 0.5, diplophonia, by CHIMERA's mapping. */\n setRoughness(r: number): void {\n const v = clamp(r, 0, 1);\n this.jitter = 0.0021 + 0.0245 * v;\n this.shimmer = 0.02 + 0.22 * v;\n this.diplophonia = v > 0.5 ? (v - 0.5) * 1.4 : 0;\n }\n\n /** 0..1 vocal fry. */\n setFry(f: number): void {\n this.targetFry = clamp(f, 0, 1);\n if (this.phase === 0) this.latch();\n }\n\n /** Depth of the 1/f pitch drift in cents. */\n setDrift(cents: number): void {\n this.driftCents = clamp(cents, 0, MAX_DRIFT_CENTS);\n }\n\n /** Cycle-to-cycle period perturbation as a fraction, overriding setRoughness. */\n setJitter(fraction: number): void {\n this.jitter = clamp(fraction, 0, MAX_JITTER);\n }\n\n /** Cycle-to-cycle amplitude perturbation as a fraction, overriding setRoughness. */\n setShimmer(fraction: number): void {\n this.shimmer = clamp(fraction, 0, 1);\n }\n\n /** 0..1 alternation of period and amplitude between cycles, overriding setRoughness. */\n setDiplophonia(amount: number): void {\n this.diplophonia = clamp(amount, 0, 1);\n }\n\n /** 0..1 logistic-map bifurcation: period doubling near 0.3, chaos past about 0.62. */\n setChaos(amount: number): void {\n this.chaos = clamp(amount, 0, 1);\n }\n\n /** The last glottal flow sample: 0 while closed, about 1 at peak. */\n get flow(): number {\n return this.u;\n }\n\n /**\n * The glottal area of the last nextArea() sample: 0 while closed, about 1\n * at peak, scaled by the cycle's shimmer. Multiply by an area in cm^2.\n */\n get openArea(): number {\n return this.aOut;\n }\n\n /**\n * Advances one sample of the area waveform only, for a caller that solves\n * the flow itself from the pressure across the folds (src/dsp/tract.ts),\n * which is where source and tract interact. It draws the same streams at\n * the same moments as next(), so drift, jitter, shimmer and fry behave\n * the same; the flow and its derivative are not computed. Use one of\n * next() and the area methods per source, not both.\n */\n nextArea(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.startCycle();\n }\n this.phase = ph;\n this.aOut = this.area(ph);\n }\n\n /**\n * nextArea() for samples [from, to) of out, for a caller whose own loop is\n * too large to inline the pulse: called on its own, this method keeps the\n * pulse's calls inside its own optimization, as process() does for next().\n */\n processArea(out: Float64Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.nextArea();\n out[i] = this.aOut;\n }\n }\n\n /**\n * Advances the cycle by one sample and computes no area: for a fold model\n * that takes its phase, `amp` and `odd` from this unit and builds the area\n * itself (dsp/geometric-glottis.ts). The streams are drawn at the same\n * moments as by next() and nextArea().\n */\n nextPhase(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.ampPrev = this.amp;\n this.startCycle();\n }\n this.phase = ph;\n }\n\n /** nextPhase() for samples [from, to) of out, writing each phase: the block form, as processArea(). */\n processPhase(out: Float64Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.nextPhase();\n out[i] = this.phase;\n }\n }\n\n /** The rate the last sample advanced at, in Hz, after drift, fry and the cycle's perturbation. */\n get f0(): number {\n return this.inc * this.sampleRate;\n }\n\n /** One sample of the glottal flow derivative. */\n next(): number {\n this.step();\n return this.y;\n }\n\n /** Overwrites out over [from, to), for callers whose own loop is too large to inline step(). */\n process(out: Float32Array, from: number, to: number): void {\n for (let i = from; i < to; i++) {\n this.step();\n out[i] = this.y;\n }\n }\n\n /**\n * Advances one sample and leaves it in `y`. It returns nothing, so no\n * double crosses this call for V8 to box when it is not inlined (the\n * pattern of CritDampBank.step()); everything it calls per sample is\n * inlined into it. Keep under 460 bytes of bytecode: see COST.\n */\n private step(): void {\n if (--this.driftCountdown <= 0) this.stepDrift();\n\n let hz = this.hz * this.pitchFactor;\n if (this.fry > 0) hz = this.fryPull(hz);\n if (hz > this.maxHz) hz = this.maxHz;\n const inc = (hz * this.invSampleRate) / this.scale;\n this.inc = inc;\n let ph = this.phase + inc;\n if (ph >= 1) {\n ph -= 1;\n this.startCycle();\n }\n this.phase = ph;\n const a = this.area(ph);\n\n // Backward Euler on T du/dphase = 1 - (u/a)^2, rationalised: exact zero when a is.\n let u = 0;\n if (a > 0) {\n const h = inc * INV_INERTANCE;\n const b = this.u + h;\n u = (2 * b) / (1 + Math.sqrt(1 + (4 * h * b) / (a * a)));\n }\n\n let out = u + this.pending;\n this.pending = 0;\n if (ph + inc >= this.closeFirst && ph < this.closeFirst) out += this.cornerFirst(ph, inc);\n if (ph + inc >= this.closeSecond && ph < this.closeSecond) out += this.cornerSecond(ph, inc);\n this.y = ((out - this.uOut) * GAIN) / inc;\n this.uOut = out;\n this.u = u;\n }\n\n /** CHIMERA's fry pull of the rate toward FRY_HZ (glottis.rs:166-168). */\n private fryPull(hz: number): number {\n const fry = this.fry;\n return hz * (1 - fry) + (hz < FRY_HZ ? hz : FRY_HZ) * fry;\n }\n\n /** Glottal area at phase ph: the main pulse plus, under heavy fry, the second one. */\n private area(ph: number): number {\n const amp = this.amp;\n let a = amp * pulse(ph, this.oq, this.invOq, this.skew, this.invSkew, this.invFall, this.sharp);\n if (this.fryGain > 0 && ph > FRY_OFFSET) {\n a +=\n amp *\n this.fryGain *\n pulse(ph - FRY_OFFSET, this.oq2, this.invOq2, this.skew, this.invSkew, this.invFall, this.sharp);\n }\n return a;\n }\n\n /**\n * The main pulse closes before the next sample. It closes onto zero\n * unless the second fry pulse is already open there, and an open second\n * pulse rounds the corner over about a2 T / 2 of a period, so the\n * correction fades with that time measured in samples.\n */\n private cornerFirst(ph: number, inc: number): number {\n const oq = this.oq;\n let weight = 1;\n if (this.fryGain > 0 && oq > FRY_OFFSET) {\n const a2 =\n this.amp *\n this.fryGain *\n pulse(oq - FRY_OFFSET, this.oq2, this.invOq2, this.skew, this.invSkew, this.invFall, this.sharp);\n weight = 1 / (1 + (a2 * INERTANCE) / (2 * inc));\n }\n const slope = this.amp * this.sharp * HALF_PI * this.invFall * this.invOq;\n return this.corner(ph, inc, oq, slope, weight);\n }\n\n /** The second fry pulse closes before the next sample, always onto zero. */\n private cornerSecond(ph: number, inc: number): number {\n const slope = this.amp * this.fryGain * this.sharp * HALF_PI * this.invFall * this.invOq2;\n return this.corner(ph, inc, this.end2, slope, 1);\n }\n\n /**\n * Two-point polyBLAMP for the flow corner at phase `end`, which falls\n * between this sample and the next. `slope` is the magnitude of the area\n * slope per unit phase just before closure; the flow closes k times\n * faster, k the positive root of k^2 - T s k - 1 = 0. The residual\n * (1 - |x|)^3 / 6 is added at both neighbours of the corner: this\n * sample's share is returned, the next one's is left in `pending`.\n */\n private corner(ph: number, inc: number, end: number, slope: number, weight: number): number {\n const ts = INERTANCE * slope;\n const flowSlope = 0.5 * slope * (ts + Math.sqrt(ts * ts + 4));\n const mu = weight * flowSlope * inc;\n const x = (end - ph) / inc;\n const d = 1 - x;\n this.pending += (mu * x * x * x) / 6;\n return (mu * d * d * d) / 6;\n }\n\n /** New cycle: the shape catches up with its settings, then the per-cycle draws. */\n private startCycle(): void {\n this.latch();\n this.odd = !this.odd;\n const alt = this.odd ? 1 : -1;\n let chaosP = 0;\n let chaosA = 0;\n const chaos = this.chaos;\n if (chaos > 0) {\n const r = 2.9 + 1.1 * chaos;\n let x = r * this.chaosX * (1 - this.chaosX);\n if (!(x > 0 && x < 1)) x = 0.37; // CHAOS_RESTART, a literal for the reason above\n this.chaosX = x;\n const dev = x - 0.5;\n chaosP = 0.45 * chaos * dev;\n chaosA = 1.1 * chaos * dev;\n }\n // two Irwin-Hall draws of four uniforms each (NamedRng.gauss), by mulberry32 inline\n let st = this.cycleS;\n let u0 = 0;\n let u1 = 0;\n for (let q = 0; q < 8; q++) {\n st = (st + 0x6d2b79f5) | 0;\n let t = Math.imul(st ^ (st >>> 15), st | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n const u = ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n if (q < 4) u0 += u;\n else u1 += u;\n }\n this.cycleS = st;\n const gp = (u0 - 2) * Math.SQRT2 * 0.875 * UNIT_GAUSS;\n const ga = (u1 - 2) * Math.SQRT2 * 0.875 * UNIT_GAUSS;\n // the limits as literals: a module constant merged with a double in a conditional made V8\n // box the double once a cycle (MEASURED in the vocal engine)\n const sc = 1 + this.jitter * gp + this.diplophonia * 0.08 * alt + chaosP;\n this.scale = sc < 0.55 ? 0.55 : sc > 1.8 ? 1.8 : sc;\n const amp = 1 + this.shimmer * ga - (this.odd ? this.diplophonia * 0.35 : 0) + chaosA;\n this.amp = amp > 0.12 ? amp : 0.12;\n }\n\n /** One control-rate step of the three-band drift, and the pitch factor it gives. */\n private stepDrift(): void {\n this.driftCountdown = this.driftInterval;\n // three Irwin-Hall draws, by mulberry32 inline (see cycleS)\n let st = this.driftS;\n let g0 = 0;\n let g1 = 0;\n let g2 = 0;\n for (let q = 0; q < 12; q++) {\n st = (st + 0x6d2b79f5) | 0;\n let t = Math.imul(st ^ (st >>> 15), st | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n const u = ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n if (q < 4) g0 += u;\n else if (q < 8) g1 += u;\n else g2 += u;\n }\n this.driftS = st;\n const gs = Math.SQRT2 * 0.875 * UNIT_GAUSS;\n this.drift0 = this.driftPole0 * this.drift0 + this.driftIn0 * (g0 - 2) * gs;\n this.drift1 = this.driftPole1 * this.drift1 + this.driftIn1 * (g1 - 2) * gs;\n this.drift2 = this.driftPole2 * this.drift2 + this.driftIn2 * (g2 - 2) * gs;\n const v = (this.drift0 + this.drift1 / 2 + this.drift2 / 3) / DRIFT_NORM;\n this.pitchFactor = Math.pow(2, (this.driftCents * v) / 1200);\n }\n\n /** Puts the tension and fry settings into force. Called where the area is zero. */\n private latch(): void {\n const fry = this.targetFry;\n this.fry = fry;\n const oq = fry > 0 ? this.targetOq * (1 - fry) + FRY_OQ * fry : this.targetOq;\n this.oq = oq;\n this.invOq = 1 / oq;\n this.skew = this.targetSkew;\n this.invSkew = 1 / this.targetSkew;\n this.invFall = 1 / (1 - this.targetSkew);\n this.sharp = this.targetSharp;\n const corners = this.sharp > 0;\n // NO_CORNER (2) as a literal: a module constant merged with a double in a conditional is boxed\n this.closeFirst = corners ? oq : 2;\n if (fry > 0.3) {\n const t = clamp((fry - 0.3) / 0.5, 0, 1);\n this.fryGain = FRY_PEAK * t * t * (3 - 2 * t);\n this.oq2 = oq * FRY_OQ_RATIO;\n this.invOq2 = 1 / this.oq2;\n this.end2 = FRY_OFFSET + this.oq2;\n this.closeSecond = corners ? this.end2 : 2;\n } else {\n this.fryGain = 0;\n this.end2 = 0;\n this.closeSecond = NO_CORNER;\n }\n }\n}\n", "/*\n * The geometric glottis: vocal folds whose two edges move as the\n * kinematic model of Titze (1984, \"Parameterization of the glottal area,\n * glottal flow, and vocal fold contact area\", JASA 75) does, extended by\n * Birkholz, Drechsel and Stone (2019, \"Perceptual optimization of an\n * enhanced geometric vocal fold model for articulatory speech synthesis\",\n * Interspeech, 3765-3769), and written here from those papers. It makes a\n * glottal AREA; the airway (dsp/junction-airway.ts) solves the flow\n * through it from the pressures on either side, so the source and the\n * tract interact as they do in life.\n *\n * THE FOLDS. Each fold has a lower (i = 1) and an upper (i = 2) edge. Along\n * the fold, y from the vocal processes (0) to the anterior commissure (L),\n * the edge's distance from the midline is\n *\n * x_i(y, t) = x_rest,i (1 - y / L) + x_max sin(pi y / L) sin(phi_i(t))\n *\n * a rest (prephonatory) displacement that opens a triangle toward the back,\n * plus a string-like vibration fixed at both ends. The upper edge lags the\n * lower by a phase (the mucosal wave travelling up the fold): phi_2 =\n * phi_1 - lag. The paper's naturalness test put the best male voice at a\n * lag of 70 degrees, rest 0.3 mm lower and 0.6 mm upper (a slightly\n * divergent glottis), no skew and 0.05 double pulsing; the best female at\n * 50 degrees, 0.6 and 0.6 mm, skew 0.2, 0.05. Each edge's area is twice the\n * integral of its positive part along y, plus a posterior chink, and the\n * area the air sees is the smaller of the two:\n *\n * A_i = 2 integral_0^L max(x_i, 0) dy + A_chink, A = min(A_1, A_2)\n *\n * The integral is closed form. With u = y / L, a = x_rest, b = x_max sin\n * phi, f(u) = a (1 - u) + b sin(pi u) and F(u) = a (u - u^2 / 2) - (b / pi)\n * cos(pi u). f(1) = 0 always, so the other root solves sin(pi v) / v = -a /\n * b with v = 1 - u, and sin(pi v) / v falls monotonically from pi to 0 on\n * (0, 1]: one root or none. It is read from a table (q = sqrt(1 - r / pi)\n * makes it smooth at both ends); the integral is stationary in the root,\n * f being zero there, so the table's error enters only at second order.\n *\n * AMPLITUDE. x_max = c x_rel sqrt(P_trans) L0 / L, after Titze (1989, \"On\n * the relation between subglottal pressure and fundamental frequency in\n * phonation\", JASA 85), with c set so that x_max = 1 mm at 800 Pa: the\n * folds swing wider the harder the air pushes, from the pressure the\n * airway actually has across them. The caller passes x_max. Since the\n * rest displacements here come from areas (x_rest = A_rest / L) and x_max\n * L / L0 does not depend on L, the area does not depend on the length, and\n * the paper's length rule drops out: only L0 (the body's fold length)\n * scales the area.\n *\n * SKEW. The phase is warped piecewise linearly so the opening and the\n * closing take different times (the paper's skewness s in [-1, 1]): the\n * displacement peak moves from a quarter of the cycle to (1 + s) / 4, the\n * closing quarter ends at the half cycle as before. s > 0 skews the pulse\n * to the right, as real flow pulses are.\n *\n * DOUBLE PULSING. On every second cycle the dynamic part becomes x_max\n * [(1 - d / 2)(sin phi + 1) - 1]: the opening peak drops by d, the\n * closing extreme stays (the paper's form).\n *\n * THE CYCLE. Pitch, drift, jitter, shimmer, diplophonia and chaos come from\n * a GlottalSource stepped with nextPhase(): its phase is phi_1 / 2 pi, its\n * cycle amplitude scales x_max, and its parity is the double pulse's. An\n * edge that lags into the previous cycle keeps that cycle's amplitude and\n * parity, so a new cycle's draw never steps the upper edge. Fry's second\n * pulse is the parametric source's and has no counterpart here.\n *\n * NO ALLOCATION. Inputs are fields; process() writes areas into a buffer.\n */\n\nimport type { GlottalSource } from './glottal';\n\nconst PI = Math.PI;\nconst INV_PI = 1 / PI;\nconst TWO_OVER_PI = 2 / PI;\nconst TWO_PI = 2 * PI;\n\n/** x_max per sqrt(dyn/cm^2): 0.1 cm at 800 Pa (8000 dyn/cm^2), the paper's calibration. */\nexport const GEO_AMPLITUDE = 0.1 / Math.sqrt(8000);\n\n/* The root table: v(q) and cos(pi v(q)) on q in [0, 1], q = sqrt(1 - r / pi), r = sin(pi v) / v. */\nconst ROOT_N = 256;\nconst ROOT_V = new Float64Array(ROOT_N + 2);\nconst ROOT_C = new Float64Array(ROOT_N + 2);\n(function buildRoots(): void {\n for (let k = 0; k <= ROOT_N + 1; k++) {\n const q = Math.min(1, k / ROOT_N);\n const r = PI * (1 - q * q);\n // sin(pi v) / v decreases on (0, 1]: bisect for the v that gives r\n let lo = 1e-12;\n let hi = 1;\n for (let it = 0; it < 80; it++) {\n const mid = 0.5 * (lo + hi);\n if (Math.sin(PI * mid) / mid > r) lo = mid;\n else hi = mid;\n }\n const v = 0.5 * (lo + hi);\n ROOT_V[k] = v;\n ROOT_C[k] = Math.cos(PI * v);\n }\n})();\n\n/**\n * The edge integral's arguments and result: EDGE[0] = a, EDGE[1] = b in,\n * EDGE[2] out. A typed array, so no double crosses the call: V8 boxes one\n * that crosses a call it does not inline (MEASURED: 48 bytes a sample when\n * edgeOpen() and the warp were called from the loop).\n */\nconst EDGE = new Float64Array(3);\n\n/** EDGE[2] = the integral over u in [0, 1] of max(a (1 - u) + b sin(pi u), 0), one edge's open area per 2 L. */\nfunction edgeInto(): void {\n const a = EDGE[0];\n const b = EDGE[1];\n if ((b >= 0 && a >= 0) || (b < 0 && a >= -PI * b)) {\n // open along the whole length\n EDGE[2] = 0.5 * a + TWO_OVER_PI * b;\n return;\n }\n if (!((b > 0 && -a < PI * b) || (b < 0 && a > 0))) {\n // shut along the whole length\n EDGE[2] = 0;\n return;\n }\n // one root inside (0, 1): r = -a / b in (0, pi), v solves sin(pi v) / v = r, u0 = 1 - v\n const r = -a / b;\n let q = 1 - r * INV_PI;\n q = q > 0 ? Math.sqrt(q) : 0;\n const x = q * ROOT_N;\n const k = x | 0;\n const f = x - k;\n const v = ROOT_V[k] + (ROOT_V[k + 1] - ROOT_V[k]) * f;\n const cv = ROOT_C[k] + (ROOT_C[k + 1] - ROOT_C[k]) * f;\n const u0 = 1 - v;\n // F(u0) with cos(pi u0) = -cos(pi v)\n const F0 = a * (u0 - 0.5 * u0 * u0) + b * INV_PI * cv;\n // b > 0: open on (u0, 1], F(1) - F(u0); b < 0: open on [0, u0), F(u0) - F(0)\n EDGE[2] = b > 0 ? 0.5 * a + b * INV_PI - F0 : F0 + b * INV_PI;\n}\n\n/** The integral's value for one edge, (a, b) as above: the testable form, off the audio path. */\nexport function edgeOpen(a: number, b: number): number {\n EDGE[0] = a;\n EDGE[1] = b;\n edgeInto();\n return EDGE[2];\n}\n\n/*\n * WARP. The phase ph in [0, 1) is warped piecewise linearly so the\n * displacement peak sits at `peak` of the cycle and the half cycle stays\n * where it was: the opening quarter and the closing quarter trade time, the\n * closed half is unchanged. Where the edge crosses the midline its speed\n * drops back to the unwarped one, so a right-skewed pulse lands softly (the\n * posterior part, still open at that moment, then closes at the slower\n * speed). MEASURED: against the warp with one breakpoint (the whole cycle\n * after the peak at one speed), this one put the male vowels 3 to 4 dB\n * nearer CHIMERA's at 1.5 to 4 kHz (docs/VOICE-2.md, \"Vocal folds\").\n */\nexport class GeometricGlottis {\n /* ---- Inputs: targets for the end of the next process() call. ---- */\n /** Rest displacement of the lower and upper edges at the vocal processes, cm. */\n xRest1 = 0.03;\n xRest2 = 0.06;\n /** Posterior chink, cm^2. */\n chink = 0.01;\n /** Vibration amplitude x_max, cm (GEO_AMPLITUDE x_rel sqrt(P_trans), times the voicing level). */\n xMax = 0;\n /** Fold length at rest L0, cm. */\n length = 1.6;\n /** Upper edge's phase lag, in cycles (70 degrees: 70 / 360). */\n lag = 70 / 360;\n /** Skewness s in [-1, 1]. */\n skew = 0;\n /** Double pulsing d in [0, 1]. */\n doublePulse = 0.05;\n\n /* ---- Outputs. ---- */\n /** The lower and upper edges' areas of the last sample, cm^2. */\n area1 = 0;\n area2 = 0;\n\n /* ---- Values in force at the start of the next call (ramped from). ---- */\n private r1 = 0.03;\n private r2 = 0.06;\n private ch = 0.01;\n private xm = 0;\n private first = true;\n\n /** The next process() starts from its targets rather than ramping to them. */\n reset(): void {\n this.first = true;\n this.area1 = this.area2 = 0;\n }\n\n /**\n * Steps src (nextPhase) once per sample over [from, to) and writes the\n * glottal area, cm^2, into out. The inputs ramp linearly from their values\n * at the last call to the current fields across the span.\n */\n process(src: GlottalSource, out: Float64Array, from: number, to: number): void {\n if (this.first) {\n this.r1 = this.xRest1;\n this.r2 = this.xRest2;\n this.ch = this.chink;\n this.xm = this.xMax;\n this.first = false;\n }\n const n = to - from;\n if (n <= 0) return;\n const inv = 1 / n;\n const r1a = this.r1;\n const r2a = this.r2;\n const cha = this.ch;\n const xma = this.xm;\n const dr1 = this.xRest1 - r1a;\n const dr2 = this.xRest2 - r2a;\n const dch = this.chink - cha;\n const dxm = this.xMax - xma;\n const twoL = 2 * this.length;\n let s = this.skew;\n s = s < -0.9 ? -0.9 : s > 0.9 ? 0.9 : s;\n const peak = 0.25 * (1 + s);\n const rise = 0.25 / peak;\n const fall = 0.25 / (0.5 - peak);\n let lag = this.lag;\n lag = lag < 0 ? 0 : lag > 0.5 ? 0.5 : lag;\n let d = this.doublePulse;\n d = d < 0 ? 0 : d > 1 ? 1 : d;\n const dh = 1 - 0.5 * d;\n let a1 = 0;\n let a2 = 0;\n for (let i = from; i < to; i++) {\n src.nextPhase();\n const w = (i - from + 1) * inv;\n const xm = xma + dxm * w;\n const ph = src.phase;\n // the warp (see WARP), written out for both edges: no double crosses a call\n let phi = ph < peak ? ph * rise : ph < 0.5 ? 0.25 + (ph - peak) * fall : ph;\n let s1 = Math.sin(TWO_PI * phi);\n if (src.odd) s1 = dh * (s1 + 1) - 1;\n let ph2 = ph - lag;\n let odd2 = src.odd;\n let amp2 = src.amp;\n if (ph2 < 0) {\n ph2 += 1;\n odd2 = !odd2;\n amp2 = src.ampPrev;\n }\n phi = ph2 < peak ? ph2 * rise : ph2 < 0.5 ? 0.25 + (ph2 - peak) * fall : ph2;\n let s2 = Math.sin(TWO_PI * phi);\n if (odd2) s2 = dh * (s2 + 1) - 1;\n const ch = cha + dch * w;\n EDGE[0] = r1a + dr1 * w;\n EDGE[1] = xm * src.amp * s1;\n edgeInto();\n a1 = twoL * EDGE[2] + ch;\n EDGE[0] = r2a + dr2 * w;\n EDGE[1] = xm * amp2 * s2;\n edgeInto();\n a2 = twoL * EDGE[2] + ch;\n out[i] = a1 < a2 ? a1 : a2;\n }\n this.area1 = a1;\n this.area2 = a2;\n this.r1 = this.xRest1;\n this.r2 = this.xRest2;\n this.ch = this.chink;\n this.xm = this.xMax;\n }\n}\n", "/*\n * The singer's pitch servo: a self-oscillating source finds its own\n * frequency from its tension and the pressure on it, so a singer who wants\n * a note listens and adjusts. This loop does the same once a cycle: it\n * compares each measured cycle's frequency with the target and moves a\n * multiplicative correction of the tension toward the ratio, by a fraction\n * 1 - exp(-T / tau) of the log error for a cycle of length T, so it\n * converges with time constant tau whatever the pitch. A feedforward\n * tension (the caller's, from the target) does the bulk of a glide; the\n * correction only takes up what the model's own physics adds: the\n * pressure's pull on f0, the collision's stiffening, the integrator's\n * frequency warping at a low sample rate.\n *\n * tau is a few tens of milliseconds: slow enough that the short f0 dip of a\n * voiced closure (the transglottal pressure falling, 50 to 100 ms) is\n * mostly left in, fast enough that a held note lands in a fraction of its\n * glide. The caller's weight leaves the rest of the dip in (it falls as the\n * pressure backs up above the folds). In an onset's first cycles a large\n * error converges faster. One cycle far from the target (an onset's first\n * irregular cycles, a period doubling) is ignored rather than chased; a run\n * of them is chased at the limit ratio, so a correction carried out of\n * range comes back.\n *\n * Inputs and outputs are fields; cycle() takes nothing and returns nothing.\n * The folds call it every sample so V8 optimizes and inlines it, and it\n * works only when a new cycle is pending: called once a cycle, it stayed\n * unoptimized and boxed its doubles.\n */\n\n/** Correction limits: an octave each way. */\nconst MIN_CORRECTION = 0.5;\nconst MAX_CORRECTION = 2;\n/** The error in cents at which the servo runs twice as fast as tau. */\nconst ADAPT_CENTS = 40;\nconst CENTS_PER_NEPER = 1200 / Math.LN2;\n/** A measured cycle further than this ratio from the target is not used, unless it is one of a run (FAR_RUN). */\nconst MAX_RATIO = 1.6;\n/** Full cycles in a row, all far off on one side, that mean the folds are lost rather than one odd cycle. */\nconst FAR_RUN = 3;\n\nexport class PitchServo {\n /** The frequency aimed at, Hz. */\n target = 110;\n /** The last measured cycle's frequency, Hz (the input of cycle()). */\n measured = 110;\n /** The tension correction, multiplying the feedforward. */\n correction = 1;\n /** The servo's time constant, s. */\n tau = 0.04;\n /** 1 when `measured` holds a cycle cycle() has not used yet. */\n pending = 0;\n /** 1 when the pending cycle is a full one (the folds' own depth test); only full cycles speed the servo up. */\n deep = 1;\n /** 1 while the folds are in an onset's first cycles (the folds' own test); only then may a large error speed it up. */\n onset = 1;\n /**\n * How far the cycles count, 0..1: the caller's measure of whether f0 is the tension's or the pressure's.\n * The servo stands for the tension a singer sets, and a singer lets a voiced closure's dip go by.\n */\n weight = 1;\n /** Set by the folds at an onset: the next cycle has no predecessor to agree with (the last was before the gap). */\n restart = 0;\n /** The last used cycle's log error, ln(target / measured). */\n private lastLog = 0;\n /** Full cycles in a row far off, and on which side (1 sharp, -1 flat). */\n private farRun = 0;\n private farSide = 0;\n\n reset(): void {\n this.correction = 1;\n this.measured = this.target;\n this.pending = 0;\n this.lastLog = 0;\n this.farRun = 0;\n this.farSide = 0;\n }\n\n /** One measured cycle: update the correction. A no-op unless a cycle is pending (see FoldOscillator.step). */\n cycle(): void {\n if (this.pending === 0) return;\n this.pending = 0;\n const m = this.measured;\n const t = this.target;\n if (!(m > 0) || !(t > 0)) return;\n let ratio = t / m;\n let lost = 0;\n if (ratio > MAX_RATIO || ratio < 1 / MAX_RATIO) {\n // ignored alone; a run of full cycles far off on one side is a correction carried out of range, and\n // ignoring them held it there (MEASURED: the child's /b\u0251/ in \"stops\" 0.5 s at 1.8 times its note)\n const side = ratio > 1 ? 1 : -1;\n this.farRun = this.deep === 0 ? 0 : side === this.farSide ? this.farRun + 1 : 1;\n this.farSide = side;\n if (this.farRun < FAR_RUN) return;\n // Math.min and Math.max, not a conditional: V8 boxed a double merged with a module-level constant\n ratio = Math.min(Math.max(ratio, 1 / MAX_RATIO), MAX_RATIO);\n lost = 1;\n } else this.farRun = 0;\n // in an onset (or lost) a large error converges faster: the time constant shrinks by 1 + |error| /\n // ADAPT_CENTS, so an onset's semitone or two after a voiceless stop is gone in a few cycles instead of a\n // 60 to 100 ms audible slide (MEASURED in \"twinkle\": onsets 1 to 2.7 semitones sharp, falling over 60\n // to 100 ms at tau alone). Mid-note it does not: the pressure falling in a voiced closure lowers f0 for\n // as long as the closure lasts, and chasing that dip fast took the correction from 1.08 to 1.76 in 25 ms\n // and the release 800 cents sharp (MEASURED, the same /b\u0251/)\n // Only a full cycle whose error the cycle before agrees with speeds it up (the smaller of the two, same sign): one odd\n // cycle (an irregular turn, a cycle locked to a resonance) at the fast rate threw the correction about\n // (MEASURED: drops of 15 percent in one cycle near F1 in the female melisma)\n if (this.restart !== 0) {\n this.restart = 0;\n this.lastLog = 0;\n }\n const lr = Math.log(ratio);\n const lp = this.lastLog;\n this.lastLog = lr;\n const same = lr * lp > 0 ? 1 : 0;\n const a = lr < 0 ? -lr : lr;\n const b = lp < 0 ? -lp : lp;\n // the closing folds' shallow cycles run at any rate as the pressure under them builds (MEASURED: two at\n // 366 Hz under a 460 Hz target took the correction from 1.20 to 1.42 and the note began 280 cents sharp)\n const cents = this.deep * same * (this.onset | lost) * (a < b ? a : b) * CENTS_PER_NEPER;\n const g = 1 - Math.exp((-this.weight * (1 + cents / ADAPT_CENTS)) / (m * this.tau));\n // Math.min and Math.max, not a conditional: V8 boxed a double merged with a module-level constant\n this.correction = Math.min(Math.max(this.correction * Math.pow(ratio, g), MIN_CORRECTION), MAX_CORRECTION);\n }\n}\n", "/*\n * Self-oscillating vocal folds: the two-mass model of Ishizaka and\n * Flanagan (1972, \"Synthesis of voiced sounds from a two-mass model of the\n * vocal cords\", Bell Syst. Tech. J. 51) with the pressure model of\n * Steinecke and Herzel (1995, \"Bifurcations in an asymmetric vocal-fold\n * model\", JASA 97), on a triangular glottis after Birkholz, Kroger and\n * Neuschaefer-Rube (2011, \"Synthesis of breathy, normal, and pressed\n * phonation using a two-mass model with a triangular glottis\",\n * Interspeech): written from those papers. Nothing here draws a pulse: the\n * folds open because the air pushes them, close because their springs and\n * the Bernoulli suction pull them back, and the period is whatever the\n * masses, springs and pressures make it.\n *\n * MASSES. A lower mass m1 (depth d1) and an upper mass m2 (depth d2) per\n * fold, each on a spring k_i to the body and coupled to each other by k_c,\n * with damping ratios zeta_i. Ishizaka and Flanagan's values: m1 0.125 g,\n * m2 0.025 g, k1 80 000 and k2 8000 dyn/cm, k_c 25 000 dyn/cm, zeta 0.1 and\n * 0.6, d1 0.25 and d2 0.05 cm, length 1.4 cm.\n *\n * THE TRIANGULAR GLOTTIS. At rest the folds are apart by r_i at the vocal\n * processes and meet at the anterior commissure, so mass i's edge is at\n * w_i(u) = r_i (1 - u) + x_i along the fold (u from the back, 0, to the\n * front, 1), x_i its displacement. Its open area is 2 L times the integral\n * of max(w_i, 0), its contact depth the integral of max(-w_i, 0), both\n * closed form for a line. Abduction (a breathy or voiceless glottis) is a\n * larger r_i; the folds then close only in front, or not at all, and the\n * model's own threshold rises with it, as Titze (1988) derives.\n *\n * PRESSURES (Steinecke and Herzel). With the flow separating at the\n * narrowest point, a convergent glottis (A1 > A2) has P1 = Ps - (Ps - Pe)\n * (A2 / A1)^2 on the lower mass and Pe on the upper; a divergent one has Pe\n * on both. While a mass is shut, the air below it presses with Ps. Each\n * force is P_i L d_i. Ps and Pe are the airway's pressures below and above\n * the glottis at the previous sample, and the airway solves the flow\n * through min(A1, A2) plus the chink: the folds and the air are one system.\n *\n * COLLISION. A mass in contact meets a spring h_i = 3 k_i on its mean\n * contact depth (Ishizaka and Flanagan's rule) and an extra damping ratio of\n * 1, weighted by the fraction of its length in contact.\n *\n * TENSION. Ishizaka and Flanagan scale the masses by 1 / Q and the\n * stiffnesses by Q, which moves every frequency by Q and shrinks the swing\n * by 1 / Q. Here the masses go by Q^-1.5 and the springs by Q^0.5: the\n * frequency still moves by exactly Q, and the swing by Q^-0.5, so a high\n * note keeps more of its amplitude (the folds also lengthen and thin as\n * they stretch). Q is the feedforward f / F_REF times the servo's\n * correction (dsp/pitch-servo.ts) times the caller's perturbation.\n *\n * INTEGRATION. Semi-implicit Euler at the audio rate, the damping implicit.\n * The stiffest motion, the upper mass in collision, has omega dt 0.55 at\n * Q 8 and 22050 Hz (0.82 at the largest Q, 12), inside the method's\n * stability limit of 2, so nothing oversamples (test/dsp-osc/\n * fold-oscillator.test.ts runs it at 22050 to 96000 Hz).\n *\n * Inputs are fields; step() takes and returns nothing and allocates nothing.\n */\n\nimport { PitchServo } from './pitch-servo';\n\n/* Ishizaka and Flanagan (1972) values. */\nconst M1 = 0.125;\nconst M2 = 0.025;\nconst K1 = 80000;\nconst K2 = 8000;\nconst KC = 25000;\nconst ZETA1 = 0.1;\nconst ZETA2 = 0.6;\nconst D1 = 0.25;\nconst D2 = 0.05;\n/** Collision stiffness over the spring's, and the extra damping ratio in contact. */\nconst HIT = 3;\nconst HIT_ZETA = 1;\n/**\n * The model's frequency at Q = 1, Hz. MEASURED in the vocal engine, a held\n * male /\u0251/ at 48 kHz: with 165 here the servo settled at corrections of\n * 1.03 to 1.06 from 110 to 220 Hz. The servo takes up the rest\n * (test/dsp-osc/fold-oscillator.test.ts holds it within a fifth).\n */\nexport const FOLD_F_REF = 158;\nconst MIN_Q = 0.25;\n/** The glottal area's swing over its mean that makes a cycle voiced. */\nconst DEPTH = 0.2;\n/** The swing over its mean that a cycle needs before the servo tunes on it. */\nconst TUNE_DEPTH = 0.03;\n/** A gap in full cycles longer than this many target periods ends voicing (the airway reads voicing so too). */\nexport const VOICED_GAP = 1.6;\n/** How long after the first full cycle that follows a gap the servo may speed up for a large error, s. */\nconst ONSET_S = 0.05;\nconst MAX_Q = 12;\n\nexport class FoldOscillator {\n /* ---- Inputs. ---- */\n /** Pressures below and above the glottis, dyn/cm^2 (written by the airway each sample). */\n ps = 0;\n pe = 0;\n /** Rest displacements of the lower and upper masses at the vocal processes, cm. */\n rest1 = 0.01;\n rest2 = 0.01;\n /** Posterior chink, cm^2. */\n chink = 0.01;\n /** Fold length, cm. */\n length = 1.4;\n /**\n * Where rest1, rest2, chink and length ramp to, and over how many more steps (0: no ramp). A caller\n * that updates once a block sets the block's end here and the ramp goes on from where the last\n * ended: a rest that stepped once a block moved the glottis in steps at the block rate, and a fast\n * adduction rang the tract (MEASURED: a 1.5 kHz tone 20 to 35 dB over the pulse's while the folds\n * closed after a voiceless stop). The chink and the length enter the area directly, so they ramp too.\n */\n rest1To = 0.01;\n rest2To = 0.01;\n chinkTo = 0.01;\n lengthTo = 1.4;\n rampLeft = 0;\n /** A multiplier on the tension (drift, jitter), applied after the servo. */\n perturb = 1;\n /** 0..1: how far the folds are free to move (1 - a glottal stop's closure); 0 holds them shut. */\n free = 1;\n readonly servo = new PitchServo();\n\n /* ---- Outputs. ---- */\n /** The glottal area of the last step, cm^2 (min of the two masses' plus the chink). */\n area = 0;\n area1 = 0;\n area2 = 0;\n x1 = 0;\n x2 = 0;\n v1 = 0;\n v2 = 0;\n /** Cycles counted since reset (white box). */\n cycles = 0;\n\n private readonly dt: number = 0;\n private readonly rate: number = 0;\n /* Per-block coefficients. */\n private m1 = M1;\n private m2 = M2;\n private k1 = K1;\n private k2 = K2;\n private kc = KC;\n private b1 = 0;\n private b2 = 0;\n private bh1 = 0;\n private bh2 = 0;\n private q = 1;\n /** 1 when tune() has asked for new coefficients, which the next step() computes. */\n private stale = 1;\n /* Cycle detection: samples since reset, the last v1, the last turning point's time (-1: none). */\n private n = 0;\n private lastV1 = 0;\n private lastT = -1;\n private lastVoiced = -1;\n /** The sample index until which the cycles are an onset's (the servo's fast rate). */\n private onsetEnd = -1;\n /**\n * Samples since the last voiced cycle's turning point (a large number before the first): whether the\n * folds are vibrating now. A cycle is voiced when the glottal area swings by DEPTH of its mean or more:\n * abducted folds still shiver by micrometres, and counting those turns as cycles kept the voicing on\n * through voiceless sounds (MEASURED: voicing 0.5 after 60 ms of a 0.3 cm^2 opening).\n */\n sinceTurn = 1e9;\n /* The area's range since the last turning point. */\n private aLo = 1e9;\n private aHi = 0;\n\n constructor(rate: number) {\n this.rate = rate;\n this.dt = 1 / rate;\n }\n\n reset(): void {\n this.x1 = this.x2 = this.v1 = this.v2 = 0;\n // the pressures too: the airway writes them after each step, so the first step of a note read the last\n // note's (MEASURED: a reused voice parted from a fresh one at sample 19)\n this.ps = this.pe = 0;\n this.area = this.area1 = this.area2 = 0;\n this.n = 0;\n this.lastV1 = 0;\n this.lastT = -1;\n this.lastVoiced = -1;\n this.onsetEnd = -1;\n this.sinceTurn = 1e9;\n this.aLo = 1e9;\n this.aHi = 0;\n this.cycles = 0;\n this.rampLeft = 0;\n this.servo.reset();\n this.tune();\n }\n\n /**\n * The tension for the servo's target and correction and the perturbation: once a block. It only marks\n * the coefficients stale and the next step() computes them, inside the per-sample code V8 optimizes. A\n * method called once a block or once a cycle can stay unoptimized, and then every double it computes is\n * a heap number: with that, the event call that took two doubles and the clamps below written as\n * conditionals, a held vowel on these folds grew new space by 1.2 to 1.5 bytes a sample, against 0.03\n * for the other fold models (MEASURED; test/engines-physical/vocal.test.ts, \"allocation\").\n */\n tune(): void {\n this.stale = 1;\n }\n\n /** The tension Q the coefficients are (or, after tune(), will be) computed for (white box, not the audio path). */\n get tension(): number {\n if (!this.stale) return this.q;\n const q = (this.servo.target / FOLD_F_REF) * this.servo.correction * this.perturb;\n return q < MIN_Q ? MIN_Q : q > MAX_Q ? MAX_Q : q === q ? q : 1;\n }\n\n /** One sample: forces from the last pressures, the masses moved, the areas and a cycle check. */\n step(): void {\n if (this.rampLeft > 0) {\n const k = 1 / this.rampLeft;\n this.rest1 += (this.rest1To - this.rest1) * k;\n this.rest2 += (this.rest2To - this.rest2) * k;\n this.chink += (this.chinkTo - this.chink) * k;\n this.length += (this.lengthTo - this.length) * k;\n this.rampLeft--;\n }\n if (this.stale) {\n // the coefficients for the tension: masses as Q^-1.5, springs as Q^0.5, so f0 scales as Q\n this.stale = 0;\n // clamped with Math.min and Math.max: a conditional that merges a double with a module-level\n // constant made V8 box the result (MEASURED: one heap number each time this ran)\n const raw = (this.servo.target / FOLD_F_REF) * this.servo.correction * this.perturb;\n const q = Math.min(Math.max(raw === raw ? raw : 1, MIN_Q), MAX_Q);\n this.q = q;\n const qk = Math.sqrt(q);\n const qm = 1 / (q * qk);\n this.m1 = M1 * qm;\n this.m2 = M2 * qm;\n this.k1 = K1 * qk;\n this.k2 = K2 * qk;\n this.kc = KC * qk;\n this.b1 = 2 * ZETA1 * Math.sqrt(this.m1 * this.k1);\n this.b2 = 2 * ZETA2 * Math.sqrt(this.m2 * this.k2);\n this.bh1 = 2 * HIT_ZETA * Math.sqrt(this.m1 * this.k1);\n this.bh2 = 2 * HIT_ZETA * Math.sqrt(this.m2 * this.k2);\n }\n const L = this.length;\n const twoL = 2 * L;\n const r1 = this.rest1 > 0 ? this.rest1 : 0;\n const r2 = this.rest2 > 0 ? this.rest2 : 0;\n const x1 = this.x1;\n const x2 = this.x2;\n // open integrals and contact of the two lines w = r (1 - u) + x\n let o1 = 0;\n let c1 = 0;\n let f1 = 0;\n if (x1 >= 0) o1 = 0.5 * r1 + x1;\n else if (r1 + x1 > 0) {\n o1 = ((r1 + x1) * (r1 + x1)) / (2 * r1);\n c1 = (x1 * x1) / (2 * r1);\n f1 = -x1 / r1;\n } else {\n c1 = -(0.5 * r1 + x1);\n f1 = 1;\n }\n let o2 = 0;\n let c2 = 0;\n let f2 = 0;\n if (x2 >= 0) o2 = 0.5 * r2 + x2;\n else if (r2 + x2 > 0) {\n o2 = ((r2 + x2) * (r2 + x2)) / (2 * r2);\n c2 = (x2 * x2) / (2 * r2);\n f2 = -x2 / r2;\n } else {\n c2 = -(0.5 * r2 + x2);\n f2 = 1;\n }\n const a1 = twoL * o1;\n const a2 = twoL * o2;\n // Steinecke and Herzel's pressures\n const ps = this.ps;\n const pe = this.pe;\n let p1 = ps;\n let p2 = pe;\n if (a1 > 0 && a2 > 0) {\n if (a1 >= a2) {\n const r = a2 / a1;\n p1 = ps - (ps - pe) * r * r;\n } else p1 = pe;\n } else if (a1 > 0) p2 = ps;\n const free = this.free < 0 ? 0 : this.free > 1 ? 1 : this.free;\n const k1 = this.k1;\n const k2 = this.k2;\n const kc = this.kc;\n const m1 = this.m1;\n const m2 = this.m2;\n const dt = this.dt;\n // forces: pressure (times how free the folds are), springs, coupling, collision\n const F1 = free * p1 * L * D1 - k1 * x1 - kc * (x1 - x2) + HIT * k1 * c1;\n const F2 = free * p2 * L * D2 - k2 * x2 - kc * (x2 - x1) + HIT * k2 * c2;\n const bb1 = this.b1 + this.bh1 * f1;\n const bb2 = this.b2 + this.bh2 * f2;\n const v1 = (this.v1 + (dt * F1) / m1) / (1 + (dt * bb1) / m1);\n const v2 = (this.v2 + (dt * F2) / m2) / (1 + (dt * bb2) / m2);\n this.v1 = v1;\n this.v2 = v2;\n this.x1 = x1 + dt * v1;\n this.x2 = x2 + dt * v2;\n const ch = this.chink > 0 ? this.chink : 0;\n this.area1 = a1 + ch;\n this.area2 = a2 + ch;\n this.area = (a1 < a2 ? a1 : a2) + ch;\n // a cycle: the lower mass turns from opening to closing, between this sample and the last; the period\n // since the previous turn goes to the servo (written out here: a call taking these doubles boxed them)\n this.n++;\n const ar = this.area;\n this.aLo = Math.min(this.aLo, ar);\n this.aHi = Math.max(this.aHi, ar);\n const lv = this.lastV1;\n this.lastV1 = v1;\n if (lv > 0 && v1 <= 0) {\n const t = this.n - 1 + lv / (lv - v1);\n const period = t - this.lastT;\n const swing = this.aHi - this.aLo;\n const mean = 0.5 * (this.aHi + this.aLo);\n if (this.lastT >= 0 && period > 1 && swing > TUNE_DEPTH * mean) {\n // the servo takes the onset's shallow first cycles (gating them at DEPTH left onsets up to 370 cents\n // sharp for 55 ms) but not the shiver of abducted folds, whose turns come at any rate (44 to 854 Hz\n // under a 460 Hz target) and pulled the correction off before the note began (MEASURED)\n const deep = swing > DEPTH * mean ? 1 : 0;\n if (deep) {\n // the first full cycle after a gap opens an onset\n if (this.lastVoiced < 0 || t - this.lastVoiced > (VOICED_GAP * this.rate) / this.servo.target) {\n this.onsetEnd = t + ONSET_S * this.rate;\n this.servo.restart = 1;\n }\n this.lastVoiced = t;\n }\n this.servo.measured = this.rate / period;\n this.servo.deep = deep;\n this.servo.onset = t < this.onsetEnd ? 1 : 0;\n this.servo.pending = 1;\n this.cycles++;\n }\n this.lastT = t;\n this.aLo = 1e9;\n this.aHi = 0;\n }\n this.sinceTurn = this.lastVoiced >= 0 ? this.n - this.lastVoiced : 1e9;\n // every sample, so V8 optimizes and inlines it; it works only on a sample that measured a cycle (a call\n // once a cycle stayed unoptimized and boxed its doubles)\n this.servo.cycle();\n }\n}\n", "/*\n * When the folds vibrate: the phonation threshold and its hysteresis, for\n * a fold model that does not find its own threshold (the geometric glottis,\n * dsp/geometric-glottis.ts).\n *\n * THRESHOLD. Titze (1988, \"The physics of small-amplitude oscillation of\n * the vocal folds\", JASA 83) derives the least transglottal pressure that\n * sustains oscillation as proportional to the prephonatory half-width\n * xi_0: P_th = (k_t B c / T) xi_0, with k_t the transglottal pressure\n * coefficient, B the tissue's damping per unit area, c the mucosal wave's\n * speed and T the folds' thickness. That goes to zero for folds that\n * touch, which they do not do in life, so a floor P_0 is added: Titze\n * (1992, \"Phonation threshold pressure: a missing link in glottal\n * aerodynamics\", JASA 91) measures about 0.2 kPa at a speaker's mean f0.\n *\n * P_on = P_0 + K xi_0\n *\n * ONSET AND OFFSET. Oscillation starts at P_on and, once going, keeps\n * going down to a lower pressure: the offset to onset ratio is 0.5 to 1 in\n * Lucero (1999, \"A theoretical study of the hysteresis phenomenon at vocal\n * fold oscillation onset-offset\", JASA 105). So the state switches on when\n * the pressure rises past P_on and off when it falls past OFFSET_RATIO\n * P_on, and between the two it stays as it was.\n *\n * LEVEL. The oscillation grows into and dies out of its amplitude over a\n * few cycles, not at once: the state drives a one-pole level with an onset\n * and an offset time. `drive` (0..1) scales the target: a glottal stop\n * holds the folds together whatever the pressure.\n *\n * Runs once a block. Inputs and outputs are fields; nothing allocates.\n */\n\nimport { CM_H2O } from './air';\n\n/** Threshold floor, dyn/cm^2: 0.2 kPa (Titze 1992, at the mean f0). */\nexport const THRESHOLD_FLOOR = 2000;\n/**\n * Threshold slope per cm of half-width, dyn/cm^2 per cm. k_t B c / T with\n * k_t 1.1, B 100 dyn s/cm^3, c 100 cm/s and T 0.3 cm is 3.7e4 (3.7 cmH2O\n * per mm; INFERRED values in Titze's range). CHOICE: 4 cmH2O per mm, with\n * which a voiced fricative (rest half-width about 0.3 mm) keeps voicing at\n * the pressure the airway leaves it and a voiceless one (about 1 mm) loses\n * it (test/engines-physical/vocal.test.ts).\n */\nexport const THRESHOLD_SLOPE = 4 * CM_H2O * 10;\n/** Offset pressure over onset pressure (Lucero 1999: 0.5 to 1). */\nexport const OFFSET_RATIO = 0.7;\n/** The level's onset and offset time constants, s. CHOICE: under a cycle at speech f0, as the pulse's gate. */\nconst ONSET_TAU = 0.006;\nconst OFFSET_TAU = 0.006;\n\nexport class PhonationThreshold {\n /* ---- Inputs. ---- */\n /** Transglottal pressure, dyn/cm^2 (smoothed over about a cycle). */\n pressure = 0;\n /** Prephonatory half-width xi_0, cm. */\n halfWidth = 0;\n /** 0..1: how far the folds are free to vibrate (1 - a glottal stop's closure). */\n drive = 1;\n\n /* ---- Outputs. ---- */\n /** Onset and offset pressures for the current half-width, dyn/cm^2. */\n onset = THRESHOLD_FLOOR;\n offset = OFFSET_RATIO * THRESHOLD_FLOOR;\n /** Whether the folds oscillate (hysteretic), 0 or 1. */\n on = 0;\n /** The oscillation's level, 0..1. */\n level = 0;\n\n private readonly cOn: number = 0;\n private readonly cOff: number = 0;\n\n /** dt: the interval between step() calls, s. */\n constructor(dt: number) {\n this.cOn = 1 - Math.exp(-dt / ONSET_TAU);\n this.cOff = 1 - Math.exp(-dt / OFFSET_TAU);\n }\n\n reset(): void {\n this.on = 0;\n this.level = 0;\n this.onset = THRESHOLD_FLOOR;\n this.offset = OFFSET_RATIO * THRESHOLD_FLOOR;\n }\n\n step(): void {\n const xi = this.halfWidth > 0 ? this.halfWidth : 0;\n const onset = THRESHOLD_FLOOR + THRESHOLD_SLOPE * xi;\n this.onset = onset;\n this.offset = OFFSET_RATIO * onset;\n const p = this.pressure;\n if (this.on === 0) {\n if (p > onset) this.on = 1;\n } else if (p < this.offset) this.on = 0;\n let d = this.drive;\n d = d < 0 ? 0 : d > 1 ? 1 : d;\n const target = this.on * d;\n const c = target > this.level ? this.cOn : this.cOff;\n this.level += c * (target - this.level);\n }\n}\n", "/*\n * The junction airway: a waveguide from the lungs to the lips and nostrils\n * that carries the air itself, not only its sound. Pressure builds behind a\n * closure until voicing stops, a release bursts, a voiced closure's voice\n * bar fades, and aspiration takes the tract's resonances, all from the flow.\n * Nothing is injected by rule.\n *\n * THE IDEA. Every section is c / (2 rate) long, so a wave crosses it in\n * half a sample: the Yee scheme at Courant number 1, where it is exact for\n * a lossless tube, and the scheme CHIMERA (Jameson Hodge, MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49) runs at\n * Courant 0.93 on an airway oversampled to 96 kHz. All the flow physics\n * lives in the junctions between sections. With power-normalized waves R\n * (toward the lips) and L (toward the lungs), a junction between impedances\n * Z1 = rho c / A1 and Z2 solves its volume flow U from\n *\n * k(U) |U| U + (Z1 + Z2 + Rv) U = 2 (p1+ - p2-) + pn\n *\n * in closed form, where k is the Borda-Carnot kinetic loss of a jet leaving\n * the narrower side (direction dependent, with a 0.1 contraction loss), Rv\n * the viscous resistance and pn a turbulence source in series. The waves\n * leave as p1- = p1+ - Z1 U and p2+ = p2- + Z2 U. Every even junction also\n * carries a yielding wall (mass, resistance and stiffness per unit area,\n * solved implicitly as a Thevenin conductance) and the anatomical flow\n * -dV/dt of moving tissue. So the mean flow runs end to end: lung pressure,\n * trachea, glottis (a junction whose area is the fold pulse), the grid,\n * the velum (a three-way node into the nasal tube) and the Flanagan R || L\n * radiation loads at the lips and nostrils, which pass DC.\n *\n * TURBULENCE. Stevens' law and Birkholz's placement (Stevens, Acoustic\n * Phonetics, 1998, pp. 103-104; Birkholz, \"Enhanced area functions for noise\n * source modeling in the vocal tract\", ISSP 2014). Each block the grid is\n * searched for constrictions: the narrowest section under 1 k^2 cm^2 and its\n * contiguous neighbours within 0.2 k^2 cm^2 of it, then up to two more runs\n * not joined to it by sections under 1 k^2 cm^2 (a second lingual\n * constriction, so the source does not jump in /su/, and a labial one). No\n * constriction, no jet: a wide tract keeps only the glottal source, so /h/ is\n * aspiration shaped by its vowel. A constriction's source pressure is\n *\n * p_s = G |v_c|^3 sqrt(A_min)\n *\n * with v_c the velocity through its narrowest section low-passed at 500 Hz,\n * in series at the junctions where it lands, its sign the flow's. Where it\n * lands depends on D, the distance from the flow separation point (the run's\n * anterior end) to the incisors: a wall source 0.25 k cm downstream when D is\n * over 2 k cm, an obstacle source at the incisors when it is under, blended\n * over 2 to 3 k cm (Birkholz's own proposal; his table lists /s z \u0283 \u0292/ as\n * obstacle sources, and this geometry's /\u0283/ separates 1.9 to 2.2 cm behind\n * the incisors), and a labiodental source 0.15 k cm downstream where the\n * lower lip forms the constriction at the incisors (/f v/), blended over D\n * from 0.5 k cm to 0. A jet that separates at or past the incisors' edge\n * (the dental /\u03B8/) has no obstacle ahead: as D falls from 0.3 k cm to 0 the\n * obstacle source gives way to a free-jet source at the wall source's place.\n * A place inside a section is split between its two\n * junctions linearly, and a source that moves or changes type ramps every\n * junction weight over one block. The noise is white through one first-order\n * low-pass at fc = 0.15 v_c / d, d = sqrt(4 A / pi), for every source:\n * Birkholz flattens the labiodental and glottal ones (a 6 kHz corner), but in\n * this airway that made /f/ rise 17 dB from 1 to 12 kHz against the human\n * recording's flat spectrum and /h/ bright (MEASURED: shape distance to the\n * human 11.5 and 18.0 dB, against 5.8 and 15.4 with Stevens' corner). Every\n * constriction source but the obstacle's share also falls through a second\n * pole at 3.5 kHz (Shadle 1991: the obstacle is the broadband source), and a\n * constriction makes noise only above the critical Reynolds number, faded in\n * over Re 1000 to 2000, so a closure's last leak is quiet. The\n * glottal (aspiration) source sits 1.5 k cm above the glottis, read from the\n * glottal flow and area; a velic source in the velum port, read from its flow\n * and area, gives the burst of a velic release (/pm/, as VocalTractLab 2.4\n * adds). In voicing, frication pulses at f0 behind a convective delay,\n * tau = D / (0.5 v_jet), with its modulation index soft-limited near 0.5\n * (Jackson and Shadle 2000; Pincas and Jackson 2005). A section at the closed\n * area makes no noise: its leak is the area floor's, not a jet; and a closing\n * seal's source reads the area the articulators command where the area rate\n * law still holds the airway's open, so a seal is not a fricative. The gains are\n * CALIBRATED here against the human recordings and CHIMERA's levels (Birkholz\n * fitted his to his own tract: wall 5, obstacle 10, labiodental 3, aspiration\n * 0.005 to 0.5).\n *\n * COST. The trachea and nasal tube are fixed, so they are delay lines\n * between a few lumped nodes (dsp/airway-tube.ts). On the grid only the\n * sections that move by more than 0.3 percent in a block are recomputed per\n * sample (sqrt(Z) from an area ramped linearly, so an opening is spread\n * over the block), a junction's kinetic root uses its series expansion when\n * the kinetic term is small, and odd and even junctions run in separate\n * loops. MEASURED in the prototype: 0.65 to 0.87 us a sample at 48 kHz\n * against 3.1 to 4.8 for one junction per section.\n *\n * NO ALLOCATION, NO BOXING. Inputs are fields the voice writes before\n * beginBlock(); render() takes indices and buffers only. Nothing per sample\n * calls a method with a double argument or result (V8 boxes doubles that\n * cross a call it did not inline). The noise is a mulberry32 generator held\n * here as an integer, seeded from the 'noise' fork at every reset(), so\n * a stream label still reproduces every sample.\n *\n * The constants are CHIMERA's unless marked; THIRD_PARTY_NOTICES.md lists\n * each with its file and line. MEASURED and CALIBRATED values are this\n * airway's, from its prototype (docs/VOICE-2.md, \"The junction airway\").\n */\n\nimport type { NamedRng } from 'bellowsjs';\nimport { AIR_DENSITY, AIR_DYNAMIC_VISCOSITY, CM_H2O, SOUND_SPEED, WALL_CHEEK_RELAXED, WALL_NASAL, WALL_TRACHEA, WALL_TRACT } from './air';\nimport { AirwayTube, TUBE_RING, evenNodes } from './airway-tube';\nimport { piriformBranch, sinusBranch } from './side-branch';\nimport { AreaSlew } from './area-rate';\nimport { GlottalSource } from './glottal';\nimport { GEO_AMPLITUDE, GeometricGlottis } from './geometric-glottis';\nimport { FoldOscillator, VOICED_GAP } from './fold-oscillator';\nimport { PhonationThreshold } from './phonation-threshold';\n\n/** The fold models: kinematic two-edge, self-oscillating two-mass, the parametric pulse (the default). */\nexport const GLOTTIS_GEOMETRIC = 0;\nexport const GLOTTIS_SELF_OSCILLATING = 1;\nexport const GLOTTIS_PULSE = 2;\n\nconst RHO = AIR_DENSITY;\nconst RHOC = AIR_DENSITY * SOUND_SPEED;\nconst IRHOC = 1 / RHOC;\nconst SRHOC = Math.sqrt(RHOC);\n/** CHIMERA's viscous resistance at 700 Hz (network.rs:866). */\nconst VISC = Math.sqrt((RHO * AIR_DYNAMIC_VISCOSITY * 2 * Math.PI * 700) / 2);\n/** Under this area a section is shut (network.rs:417). */\nconst CLOSED = 2e-4;\n/*\n * The least area any section takes, 1e-4 cm^2 (under the closed area, so a\n * sealed section still seals: its leak at full lung pressure is about\n * 0.4 cm^3/s), written as a literal wherever it is used: a module-level\n * constant in a conditional made V8 box every double that merged with it\n * (MEASURED: 1.9 KB a block). At 1e-6 the first sample of a release changed\n * the sealed section's impedance 85-fold and stepped the pressure stored in\n * its power-normalized waves: a step larger than the burst's peak (MEASURED:\n * 1.05 to 1.5 of it at the twinkle /k/, CHIMERA's 0.57).\n */\n/** CHIMERA's output gain on the radiated flow derivative (human_voice.rs:220). */\nconst OUTPUT_GAIN = 5.5e-7;\n/** A kinetic root takes its series expansion when 4 k |c| / bq^2 is under this (error under 1e-7). MEASURED. */\nconst LIN_EPS = 2e-3;\n/** A grid section moving by less than this fraction in a block steps once per block (42 to 57 dB SNR against per sample). MEASURED. */\nconst MOVE_REL = 0.003;\n/*\n * Turbulence sources: three constriction slots, the glottis, the velum port. Each writes into at\n * most TAPS junctions (its places this block and the ones it fades out of); its velocity passes\n * through a ring of MOD_RING samples for the convective delay (4 ms at 96 kHz fits).\n */\nconst NSRC = 5;\nconst SRC_ASP = 3;\nconst SRC_VEL = 4;\nconst TAPS = 16;\nconst MOD_RING = 512;\n/**\n * Source gains by type, CALIBRATED from Birkholz's (ISSP 2014, Table 1: wall 5, obstacle 10,\n * labiodental 3). Wall 1.4 times his: at 10 and 5, the voiced /z/'s frication lay under its voicing\n * in the female and child bodies (shape distance to the human 25.4 and 26.0 dB; at 14 and 7, 12.6 and\n * 12.6). The obstacle 18, chosen on the mean of five noise seeds: the child's /z/ sits at a threshold\n * where its frication either clears its voicing or does not, and the seed decides which. Its shape\n * distance to the human, mean [range] over the seeds: at 14, 26.1 [26.0..26.3]; at 15, 23.5 [12.8..26.3]\n * (frication on one seed of five); at 17, 18.0 [12.6..26.3]; at 18, 12.6 [12.4..12.9] (this airway's\n * predecessor, before the noise round, 12.4 [12.2..12.7]). The child's mean over the fricatives goes 12.16 to 10.81\n * from 15 to 18, the male's 10.23 to 10.18, the female's 10.96 to 10.89; the cost is DTW distance to\n * CHIMERA on the strengths line, female and child, 0.06 and 0.07 dB (docs/VOICE-2.md, \"Fixes after\n * verification\"). Lowering the Reynolds window's floor did not move the threshold (over Re 500 to 2000\n * and 0 to 2000, the same 23.5). The labiodental one: at his 3, /f/\n * lay 37 dB under its vowel (CHIMERA 18, the earlier library 25); at 25, with the second pole below, 27.\n */\nconst G_WALL = 7;\nconst G_OBSTACLE = 18;\nconst G_LABIAL = 25;\n/** A constriction at the lips that is not labiodental (rounding): Birkholz's labiodental gain, unfitted. */\nconst G_LIPS = 3;\n/**\n * A jet that separates at or past the incisors' edge has no obstacle ahead of it (the dental /\u03B8/):\n * the obstacle source fades out as D falls from D_FREE x k cm to 0, and a free-jet source at the\n * wall source's place, gain G_FREE, takes its share. CALIBRATED: /\u03B8/ at the incisors' obstacle read\n * 12.8 dB from the human shape, 9.0 as a free jet with the second pole (docs/VOICE-2.md).\n */\nconst D_FREE = 0.3;\nconst G_FREE = 6;\n/**\n * The common scale of p_s = G |v|^3 sqrt(A) at 48 kHz (dyn/cm^2 per (cm/s)^3 cm), times\n * sqrt(rate / 48000) elsewhere so the noise's spectral density does not change with the rate.\n * CALIBRATED with the six-stage articulators and the aspiration gains below: DTW distance to\n * CHIMERA over the comparison phrases (docs/VOICE-2.md, \"Integration 4\").\n */\nconst GAIN_SCALE = 3e-9;\n/**\n * The aspiration source's G, open (no voicing) and in modal voicing; Birkholz's is variable.\n * CALIBRATED: the open value on the breaths between vowels and on /h/ (at 20 the vowels line sat\n * 0.3 dB further from CHIMERA, and with the second pole /\u03B8/ no longer needs it), the voiced one on\n * the vowels' breath noise against CHIMERA, scaled by k^ASPIRATION_VOICED_K: the male line needs 3\n * (at 1 it read 1.1 dB further from CHIMERA), the child's about 1 (at 3, 0.24 dB further).\n */\nconst G_ASPIRATION = 10;\nconst G_ASPIRATION_VOICED = 3;\nconst ASPIRATION_VOICED_K = 3.5;\n/**\n * A jet is turbulent only above a critical Reynolds number (Flanagan; CHIMERA takes 1800): a\n * constriction's source fades in over Re 1000 to 2000, Re = v d / nu, d = 2 sqrt(A / pi). MEASURED: a\n * /t\u0283/ closure leaking 0.003 cm^2 at 2400 cm/s (Re 1000) carried frication 9 dB under the /s/ for\n * 10 ms; over Re 1800 to 3000 the female /z/ (Re about 2400) fell under its voicing (25.3 dB from the\n * human shape, against 12.7 over 1000 to 2000).\n */\nconst RE_PER_VSA = (2 / Math.sqrt(Math.PI)) * (AIR_DENSITY / AIR_DYNAMIC_VISCOSITY);\nconst RE_LO = 1000;\nconst RE_SPAN = 1 / 1000;\n/** v_c's low-pass, Hz (Birkholz 2014). */\nconst VC_HZ = 500;\n/** The slow velocity the voicing modulation is measured against, Hz: under any sung f0. */\nconst VSLOW_HZ = 25;\n/** The source corner, fc = 0.15 v / d (Stevens 1998, p. 104). */\nconst FC_LINGUAL = 0.15;\n/**\n * A second pole at this frequency for every constriction source except the obstacle's share (Shadle\n * 1991: a jet hitting an obstacle is the broadband source; a free jet, a wall or the lower lip falls\n * faster). CALIBRATED against the human recordings: /f/ 6.1 to 2.9 dB from the human shape, /\u03B8/\n * 12.2 to 9.0, Jongman spectral mean error 1.46 to 0.81 kHz; at 2500 Hz /f/ went dull (6.6).\n */\nconst P2_HZ = 3500;\n/** Constriction detection, x k^2 cm^2: under this, and the run's tolerance (Birkholz 2014). */\nconst CONSTRICTED = 1.0;\nconst RUN_TOL = 0.2;\n/** Separation-to-incisor distances, x k cm: wall/obstacle blend, labiodental blend. */\nconst D_WALL_LO = 2.0;\nconst D_WALL_HI = 3.0;\nconst D_LABIAL = 0.5;\n/** Source places, x k cm downstream of separation (wall, labiodental) or above the glottis. */\nconst WALL_DOWN = 0.25;\nconst LABIAL_DOWN = 0.15;\nconst ASPIRATION_AT = 1.5;\n/** The convective delay's speed as a fraction of the jet's, and its cap, s (Jackson and Shadle 2000). */\nconst CONVECT = 0.5;\nconst TAU_MAX = 0.004;\n/** The modulation index's soft limit (Jackson and Shadle 2000: about 0.5 at most). */\nconst MOD_MAX = 0.5;\n/** The glottal port: depth 0.3 k, slit 1.4 k, kinetic entrance 0.37 (human_airway.rs:102). */\nconst GLOTTIS_DEPTH = 0.3;\nconst GLOTTIS_SLIT = 1.4;\nconst GLOTTIS_KIN = 0.37;\n/** The velum port: length 1.0 k, kinetic 0.3 in, 0.8 out (human_airway.rs:110-118). */\nconst VELUM_LEN = 1.0;\nconst VELUM_KIN = 0.3;\nconst VELUM_EXIT = 0.8;\n/** Output high-pass (DC) and low-pass corners, Hz; the low-pass stands in for CHIMERA's decimator. MEASURED. */\nconst OUTPUT_HP = 25;\n/**\n * The close microphone's distance from the lips at `mic` 1, cm. A pressure-gradient (directional)\n * microphone answers the air's particle velocity, which near a small source carries a term in the\n * flow itself on top of the far field's flow derivative: for a monopole, u = p (1 + 1 / (j k r)) / (rho c),\n * so a cardioid (half pressure, half gradient) at r hears dU/dt + (c / 2r) U. Below c / (4 pi r),\n * 1.4 kHz at 2 cm, the flow term rises over the far field: the proximity effect, and the puff of a\n * plosive on the diaphragm, which is what makes a beatboxed kick thump on a microphone.\n */\nconst MIC_R = 2;\n/** The microphone's low cut on its flow term, Hz: a slow tongue or jaw pushing air out is not a thump. */\nconst MIC_LOW_CUT = 70;\n\nconst OUTPUT_LP = 18000;\n/** The moving-wall flow is smoothed by CHIMERA's 60 Hz two-pole (network.rs:360). */\nconst DVDT_HZ = 60;\n/** Lumped interior nodes of the trachea and of the nasal tube. MEASURED. */\nconst TRACHEA_NODES = 4;\nconst NASAL_NODES = 6;\n/** The back duct's shortest length, cm: the Lagrange read stays causal. */\nexport const DUCT_MIN = 1.25;\n/**\n * Fraction of a wall's volume velocity radiated through the skin. Birkholz and Zhang (2025) radiate\n * the whole wall flow through the mouth's radiation characteristic; CHIMERA 0.25 (human_airway.rs:86-87).\n * CALIBRATED on the voice bar (docs/VOICE-2.md).\n */\nconst WALL_RADIATION = 0.25;\n\n/** The shortest back duct at a rate, cm: max(DUCT_MIN, 3.2 dx), so a Lagrange read is causal. */\nexport function ductMin(rate: number): number {\n const dx = SOUND_SPEED / (2 * rate);\n return DUCT_MIN > 3.2 * dx ? DUCT_MIN : 3.2 * dx;\n}\n\n/** The share of the pressure under the folds that backs up above them before the pitch servo lets go, and over how much it does. */\nconst BACK_FREE = 0.1;\nconst BACK_SPAN = 0.2;\n/** The opening (over k^2, cm^2) past which the pitch servo lets go, and over how much it does. */\nconst OPEN_FREE = 0.03;\nconst OPEN_SPAN = 0.05;\n\n/** GlottalSource's area block, called through Reflect.apply so V8 never inlines it into beginBlock(). */\nconst AREA_BLOCK = GlottalSource.prototype.processArea;\n\nexport class JunctionAirway {\n readonly rate: number = 0;\n readonly block: number = 0;\n readonly dx: number = 0;\n /** Grid capacity; nG sections are in use. */\n readonly nMax: number = 0;\n nG = 0;\n /** Velum junction (grid index). */\n jv = 2;\n private k = 1;\n private readonly T: number = 0;\n\n /* ---- Inputs, written by the caller before each beginBlock(). ---- */\n /** Grid areas (cm^2), back duct end to lips, nG used. */\n readonly gridIn: Float64Array;\n /** Smallest area inside each grid section (CHIMERA's sub-section minima), cm^2. */\n readonly gridMin: Float64Array;\n /** Anatomical -dV/dt per grid junction, cm^3/s (0 .. nG). */\n readonly vflow: Float64Array;\n /** Back duct length (cm) and area (cm^2). */\n ductLen = 2;\n ductArea = 3;\n /** Velum port area, cm^2. */\n velum = 0;\n /** Lung pressure, dyn/cm^2. */\n pLung = 0;\n /** How close a directional microphone is, 0 (the far field) to 1 (a cardioid MIC_R from the lips). */\n mic = 0;\n /** How slack the cheeks are, 0 (the tract's walls) to 1 (Ishizaka's relaxed cheek). */\n cheeks = 0;\n /** The side branches on or off (a test's counterfactual). */\n branches = true;\n /**\n * The piriform fossae, 0 off or 1 on. Off by default: they lower F1 (MEASURED: General American's\n * vowels from 4.6 to 7.4 percent RMS off Hillenbrand's F1) and the vowel targets were solved without\n * them; re-solving with the branch in the solver's tube is the plan (HOW-IT-WORKS.md, section 11).\n */\n piriform = 0;\n /** The piriform junction in force this block (-1 off). */\n private pJa = -1;\n /* Per-junction wall coefficients (the throat's, the cheeks' past the split). */\n private readonly wCmA: Float64Array;\n private readonly wKsA: Float64Array;\n private readonly wIbsA: Float64Array;\n private wallCheeks = -1;\n private wallSplit = -1;\n /* The piriform branch: its junction, coefficients and state. */\n private pJ = -1;\n private pG = 0;\n private pCm = 0;\n private pK = 0;\n private pDi = 0;\n private pQ = 0;\n private pY = 0;\n private pP = 0;\n /* The microphone flow term's low cut: its state and pole. */\n private micX = 0;\n private micY = 0;\n private readonly micC: number = 0;\n /** The static glottal opening (abduction), cm^2. */\n agStatic = 0.02;\n /** How far the folds are held shut, 0..1 (a glottal stop). */\n closure = 0;\n /** Which fold model makes the glottal area: GLOTTIS_GEOMETRIC, GLOTTIS_SELF_OSCILLATING or GLOTTIS_PULSE. */\n model = GLOTTIS_PULSE;\n /** The part of agStatic that is the posterior chink, cm^2 (the fold models; the pulse uses agStatic whole). */\n chink = 0.01;\n /** Fold length at rest, cm (the fold models). */\n foldLength = 1.6;\n /** Geometric glottis: the upper edge's rest displacement over the lower's, cm; its phase lag (cycles), skew, double pulsing. */\n upperRest = 0.03;\n lag = 70 / 360;\n skew = 0;\n doublePulse = 0.05;\n /** Geometric glottis: the amplitude factor x_rel (under 1: stiffened folds). */\n xRel = 1;\n /** Added to both edges' rest displacement, cm: negative presses the folds together (the fold models). */\n restOffset = 0;\n /** The fold pulse's rate, Hz. */\n f0 = 110;\n /** Incisors and the pharynx/oral split, fractional grid positions (junction units). */\n teethX = 30;\n /** How far the lower lip forms a constriction at the incisors (0..1): labiodental, not lingual, noise. */\n labial = 0;\n splitI = 20;\n /** Output gain applied with the envelope. */\n gain = 1;\n\n /* ---- Outputs. ---- */\n voicing = 0;\n /** Pressure across the folds, dyn/cm^2, and its 30 Hz smoothing; the pressure below them, smoothed. */\n dpGlottis = 0;\n /** The transglottal pressure the fold models see: block means through a 30 Hz one-pole, dyn/cm^2. */\n pTrans = 0;\n /** The pressure above the folds, the same way, dyn/cm^2. */\n pSupra = 0;\n private dpAcc = 0;\n private paAcc = 0;\n dpSmooth = 0;\n pSubSmooth = 0;\n private pSub = 0;\n uLips = 0;\n uNose = 0;\n readonly glottis: GlottalSource;\n readonly geometric = new GeometricGlottis();\n readonly folds: FoldOscillator;\n readonly threshold: PhonationThreshold;\n /*\n * The turbulence sources over the last block, for measurement (index: constriction slots 0..2, the\n * glottis 3, the velum port 4): the mean of |v_c|^3 sqrt(A) times the closed-area fade (p_s / G\n * before the noise), the mean |v_c| (cm/s), the area read (cm^2), the summed junction weight G and\n * the weighted mean place (junction units; -1 when silent).\n */\n readonly noiseLevel = new Float64Array(NSRC);\n readonly noiseVelocity = new Float64Array(NSRC);\n readonly noiseArea = new Float64Array(NSRC);\n readonly noiseGain = new Float64Array(NSRC);\n readonly noisePlace = new Float64Array(NSRC).fill(-1);\n\n /* ---- Grid sections. ---- */\n private readonly R: Float64Array;\n private readonly L: Float64Array;\n private readonly sZ: Float64Array;\n private readonly isZ: Float64Array;\n private readonly Zs: Float64Array;\n private readonly area: Float64Array;\n private readonly dArea: Float64Array;\n private readonly aMin: Float64Array;\n private readonly dAMin: Float64Array;\n private readonly iaMin: Float64Array;\n private readonly viscC: Float64Array;\n private readonly perimF: Float64Array;\n /** A wall's surface per sqrt(area) on each section: walls lumped onto even junctions at double surface. */\n private readonly wallK: Float64Array;\n private readonly moving: Int32Array;\n private nMoving = 0;\n private readonly tgt: Float64Array;\n private readonly tgtMin: Float64Array;\n private readonly slew = new AreaSlew();\n\n /* ---- Grid junctions 0 .. nG. ---- */\n private readonly kf: Float64Array;\n private readonly kb: Float64Array;\n private readonly rv: Float64Array;\n private readonly U: Float64Array;\n private readonly pn: Float64Array;\n private readonly wS: Float64Array;\n private readonly gw: Float64Array;\n private readonly wV: Float64Array;\n private readonly wY: Float64Array;\n private readonly jmList: Int32Array;\n private nJm = 0;\n private readonly gamA: Float64Array;\n private readonly ibA: Float64Array;\n private readonly bqA: Float64Array;\n private readonly dv1: Float64Array;\n private readonly dv2: Float64Array;\n private readonly dvRaw: Float64Array;\n private readonly dvCoef: number = 0;\n private readonly wCm: number = 0;\n private readonly wKs: number = 0;\n private readonly wIbs: number = 0;\n\n /* ---- Fixed tubes. ---- */\n private readonly tr: AirwayTube;\n private readonly na: AirwayTube;\n private readonly secScratch: Float64Array;\n private readonly nodeScratch = new Int32Array(16);\n\n /* ---- Back duct (a fractional delay, Lagrange 3). ---- */\n private readonly fBuf = new Float64Array(TUBE_RING);\n private readonly bBuf = new Float64Array(TUBE_RING);\n private pos = 0;\n private ductTau = 2;\n private dTau = 0;\n private ductSZ = 1;\n private dDuctSZ = 0;\n private ductA = 1;\n\n /* ---- Glottis. ---- */\n private readonly areaBuf: Float64Array;\n private readonly areaArgs: [Float64Array, number, number];\n private agSt = 0.02;\n private agSt0 = 0.02;\n private aVib = 0;\n private aVib0 = 0;\n private uG = 0;\n private momG = 0;\n private lG = 0;\n private ag = 1e-4;\n private agAcc = 0;\n private agMean = 0.05;\n private agLast = 0;\n private pL = 0;\n private pL0 = 0;\n private visc0 = 0;\n private ldG = 0;\n\n /* ---- Velum. ---- */\n private vel = 0;\n private vel0 = 0;\n private velNow = 0;\n private uV = 0;\n private momV = 0;\n private lV = 0;\n private velLen = 1;\n\n /* ---- Radiation and output. ---- */\n private ulLips = 0;\n private lrLips = 0;\n private ulNose = 0;\n private pLipsOld = 0;\n private pNoseOld = 0;\n private radPrev = 0;\n private wallRadAcc = 0;\n private hpX = 0;\n private hpY = 0;\n private readonly hpC: number = 0;\n /* The output low-pass, a second-order Butterworth (b0, b1 = 2 b0, b2 = b0; a1, a2). */\n private readonly lb0: number = 0;\n private readonly lb1: number = 0;\n private readonly la1: number = 0;\n private readonly la2: number = 0;\n private lx1 = 0;\n private lx2 = 0;\n private ly1 = 0;\n private ly2 = 0;\n /** Per-sample ramp position within the block, (n + 1) / count. */\n private w = 0;\n /** The fold rate handed to the glottis, [0]: setFreqFrom reads it, so no double crosses the call. */\n private readonly f0Buf = new Float64Array(1);\n\n /* ---- Turbulence: slots 0..2 constrictions, SRC_ASP the glottis, SRC_VEL the velum port. ---- */\n /** Each constriction slot's separation junction last block (-1: free), its flow junction and narrowest section. */\n private readonly srcExit = new Int32Array(NSRC).fill(-1);\n private readonly srcUJ = new Int32Array(NSRC);\n private readonly srcSec = new Int32Array(NSRC);\n /**\n * Each constriction slot's commanded area, the least of the run's sections before the area rate law, at the\n * block's start and end, cm^2: the source reads it where it is under the airway's (a closing seal).\n */\n private readonly srcCmd0 = new Float64Array(NSRC);\n private readonly srcCmd1 = new Float64Array(NSRC);\n /** Junction taps per source: junction, weight at the block's start and end (G folded in). */\n private readonly nTap = new Int32Array(NSRC);\n private readonly tapJ = new Int32Array(NSRC * TAPS);\n private readonly tapW0 = new Float64Array(NSRC * TAPS);\n private readonly tapW1 = new Float64Array(NSRC * TAPS);\n /** The velic source's weight, ramped. */\n private velW0 = 0;\n private velW1 = 0;\n private pnV = 0;\n /** Per source: v_c low-passed, the slow mean of its delayed cube, the area low-passed, the noise low-pass state and coefficient. */\n private readonly vF = new Float64Array(NSRC);\n private readonly vS = new Float64Array(NSRC);\n private readonly aF = new Float64Array(NSRC);\n private readonly nL = new Float64Array(NSRC);\n private readonly nL2 = new Float64Array(NSRC);\n private readonly cLp2 = new Float64Array(NSRC).fill(1);\n private readonly cLp = new Float64Array(NSRC);\n /** Block sums of |v_c| and of |v_c|^3 sqrt(A), and the convective delay in samples at the block's start and end. */\n private readonly vAcc = new Float64Array(NSRC);\n private readonly lvAcc = new Float64Array(NSRC);\n private readonly tau0 = new Float64Array(NSRC);\n private readonly tau1 = new Float64Array(NSRC);\n /** Whether a slot modulates with voicing (1) or reads its velocity undelayed and unlimited (0). */\n private readonly modOn = new Float64Array(NSRC);\n private readonly ring = new Float64Array(NSRC * MOD_RING);\n private ringPos = 0;\n /** A place being added (fractional junction), its weight and its share at one junction: fields, so no double crosses a call. */\n private tx = 0;\n private tw = 0;\n private tShare = 0;\n /** The fastest jet the lungs can drive this block, cm/s (Bernoulli, with a margin). */\n private vMax = 0;\n /** Scratch for the detection: runs (lo, hi, narrowest section) and per-slot assignment. */\n private readonly runLo = new Int32Array(3);\n private readonly runHi = new Int32Array(3);\n private readonly runMin = new Int32Array(3);\n private readonly conLo = new Int32Array(3);\n private readonly conHi = new Int32Array(3);\n private readonly runSlot = new Int32Array(3);\n private readonly cVc: number = 0;\n private readonly cVs: number = 0;\n private readonly noiseScale: number = 0;\n private readonly rng: NamedRng;\n /** mulberry32 state, an int32. */\n private seed = 1;\n /** Block counter in the current note; 0 means the next block is the first. */\n private blocks = 0;\n\n /**\n * rate in Hz; nMax: the most grid sections any configure() will use;\n * rng: forks 'noise' (the turbulence seed per reset) and 'glottis'.\n */\n constructor(rate: number, nMax: number, rng: NamedRng) {\n this.rate = rate;\n this.T = 1 / rate;\n this.block = Math.max(8, Math.round((32 * rate) / 48000));\n this.dx = SOUND_SPEED / (2 * rate);\n this.nMax = nMax;\n this.rng = rng.fork('noise');\n const n = nMax;\n const nj = n + 1;\n this.gridIn = new Float64Array(n).fill(3);\n this.gridMin = new Float64Array(n).fill(3);\n this.vflow = new Float64Array(nj);\n this.R = new Float64Array(n);\n this.L = new Float64Array(n);\n this.sZ = new Float64Array(n);\n this.isZ = new Float64Array(n);\n this.Zs = new Float64Array(n);\n this.area = new Float64Array(n);\n this.dArea = new Float64Array(n);\n this.aMin = new Float64Array(n);\n this.dAMin = new Float64Array(n);\n this.iaMin = new Float64Array(n);\n this.viscC = new Float64Array(n);\n this.perimF = new Float64Array(n);\n this.wallK = new Float64Array(n);\n this.moving = new Int32Array(n);\n this.tgt = new Float64Array(n);\n this.tgtMin = new Float64Array(n);\n this.kf = new Float64Array(nj);\n this.kb = new Float64Array(nj);\n this.rv = new Float64Array(nj);\n this.U = new Float64Array(nj);\n this.pn = new Float64Array(nj);\n this.wS = new Float64Array(nj);\n this.gw = new Float64Array(nj);\n this.wCmA = new Float64Array(nj);\n this.wKsA = new Float64Array(nj);\n this.wIbsA = new Float64Array(nj);\n this.wV = new Float64Array(nj);\n this.wY = new Float64Array(nj);\n this.jmList = new Int32Array(nj);\n this.gamA = new Float64Array(nj).fill(1);\n this.ibA = new Float64Array(nj);\n this.bqA = new Float64Array(nj);\n this.dv1 = new Float64Array(nj);\n this.dv2 = new Float64Array(nj);\n this.dvRaw = new Float64Array(nj);\n this.dvCoef = 1 - Math.exp((-2 * Math.PI * DVDT_HZ) / rate);\n this.wCm = WALL_TRACT.m * rate - 0.5 * WALL_TRACT.r;\n this.wKs = WALL_TRACT.k;\n this.wIbs = 1 / (WALL_TRACT.m * rate + 0.5 * WALL_TRACT.r);\n this.tr = new AirwayTube(TRACHEA_NODES + 2);\n this.na = new AirwayTube(NASAL_NODES + 5);\n // the longest fixed tube (the male trachea, 12 cm) in sections, with room\n this.secScratch = new Float64Array(Math.ceil((14 * 1.2) / this.dx) + 4);\n this.glottis = new GlottalSource(rate, rng.fork('glottis'));\n this.folds = new FoldOscillator(rate);\n this.threshold = new PhonationThreshold(this.block / rate);\n this.areaBuf = new Float64Array(this.block);\n this.areaArgs = [this.areaBuf, 0, this.block];\n this.hpC = Math.exp((-2 * Math.PI * OUTPUT_HP) / rate);\n this.micC = Math.exp((-2 * Math.PI * MIC_LOW_CUT) / rate);\n const fc = Math.min(OUTPUT_LP, 0.45 * rate);\n const K = Math.tan((Math.PI * fc) / rate);\n const q = Math.SQRT1_2;\n const norm = 1 / (1 + K / q + K * K);\n this.lb0 = K * K * norm;\n this.lb1 = 2 * this.lb0;\n this.la1 = 2 * (K * K - 1) * norm;\n this.la2 = (1 - K / q + K * K) * norm;\n this.noiseScale = GAIN_SCALE * Math.sqrt(rate / 48000);\n this.cVc = 1 - Math.exp((-2 * Math.PI * VC_HZ) / rate);\n this.cVs = 1 - Math.exp((-2 * Math.PI * VSLOW_HZ) / rate);\n this.configure(1, Math.min(n, 30), 12);\n }\n\n /**\n * Lay the airway out for a body of scale k with n grid sections (at most\n * nMax) and the velum at junction jv. Allocates nothing; clears all state.\n */\n configure(k: number, n: number, jv: number): void {\n this.k = k;\n const k2 = k * k;\n const dx = this.dx;\n this.nG = n < this.nMax ? n : this.nMax;\n this.jv = jv;\n this.slew.setScale(k);\n this.slew.setStep(this.block / this.rate);\n this.visc0 = 12 * AIR_DYNAMIC_VISCOSITY * GLOTTIS_DEPTH * k * (GLOTTIS_SLIT * k) ** 2;\n this.ldG = RHO * GLOTTIS_DEPTH * k;\n this.velLen = VELUM_LEN * k;\n const sec = this.secScratch;\n const nodes = this.nodeScratch;\n // trachea: 12 k cm of 2.5 k^2 cm^2, an even number of sections\n let nTr = Math.max(6, Math.round((12 * k) / dx));\n if (nTr % 2) nTr++;\n if (nTr > sec.length) nTr = sec.length - (sec.length % 2);\n for (let i = 0; i < nTr; i++) sec[i] = 2.5 * k2;\n let nn = evenNodes(nTr, TRACHEA_NODES, nodes);\n this.tr.configure(sec, nTr, nodes, nn, WALL_TRACHEA, 1, 1, dx, this.rate);\n // nasal tube: 11.4 k cm, CHIMERA's profile (human_airway.rs:95-104)\n let nNa = Math.max(8, Math.round((11.4 * k) / dx));\n if (nNa % 2) nNa++;\n if (nNa > sec.length) nNa = sec.length - (sec.length % 2);\n for (let i = 0; i < nNa; i++) {\n const u = (i + 0.5) / nNa;\n const a = u < 0.18 ? 2.6 : u < 0.75 ? 2.0 - 0.6 * (u - 0.18) : u < 0.9 ? 1.4 : 1.0;\n sec[i] = a * k2;\n }\n nn = 0;\n nodes[nn++] = 0;\n nodes[nn++] = 2 * Math.round((0.18 * nNa) / 2);\n const extra = NASAL_NODES - 3;\n for (let e = 1; e <= extra; e++) nodes[nn++] = 2 * Math.round(((0.18 + ((0.75 - 0.18) * e) / (extra + 1)) * nNa) / 2);\n nodes[nn++] = 2 * Math.round((0.75 * nNa) / 2);\n nodes[nn++] = 2 * Math.round((0.9 * nNa) / 2);\n nodes[nn++] = nNa;\n // sorted already; drop repeats\n let c = 1;\n for (let i = 1; i < nn; i++) if (nodes[i] > nodes[c - 1]) nodes[c++] = nodes[i];\n this.na.configure(sec, nNa, nodes, c, WALL_NASAL, 3.2, 2.5, dx, this.rate);\n if (this.branches) {\n // the maxillary sinuses on the middle nasal node, the piriform fossae at the first even junction\n // above the back duct (dsp/side-branch.ts)\n const sb = sinusBranch(k, this.rate);\n this.na.addResonator(c >> 1, sb[0], sb[1], sb[2]);\n const pc = piriformBranch(k, this.rate);\n this.pJ = 2 < this.nG - 1 && jv !== 2 ? 2 : -1;\n this.pDi = pc[0];\n this.pG = 0.5 * pc[0];\n this.pCm = pc[1];\n this.pK = pc[2];\n } else this.pJ = -1;\n this.wallCheeks = -1;\n for (let i = 0; i < this.nMax; i++) {\n this.perimF[i] = i < jv ? 1.25 : 1.5;\n this.wallK[i] = 2 * this.perimF[i] * 2 * Math.sqrt(Math.PI) * dx;\n this.viscC[i] = (0.25 * VISC * this.perimF[i] * 2 * Math.sqrt(Math.PI) * dx) / Math.pow(RHOC, 1.5);\n }\n this.reset();\n this.updateWalls();\n }\n\n /** Each junction's wall coefficients: the tract's, blended toward relaxed cheeks past the split. */\n private updateWalls(): void {\n const ch = this.cheeks < 0 ? 0 : this.cheeks > 1 ? 1 : this.cheeks;\n const split = Math.ceil(this.splitI);\n if (ch === this.wallCheeks && split === this.wallSplit) return;\n this.wallCheeks = ch;\n this.wallSplit = split;\n const rate = this.rate;\n const n = this.wCmA.length;\n for (let i = 0; i < n; i++) {\n const c = i >= split ? ch : 0;\n const m = WALL_TRACT.m + (WALL_CHEEK_RELAXED.m - WALL_TRACT.m) * c;\n const r = WALL_TRACT.r + (WALL_CHEEK_RELAXED.r - WALL_TRACT.r) * c;\n const kk = WALL_TRACT.k + (WALL_CHEEK_RELAXED.k - WALL_TRACT.k) * c;\n this.wCmA[i] = m * rate - 0.5 * r;\n this.wKsA[i] = kk;\n this.wIbsA[i] = 1 / (m * rate + 0.5 * r);\n }\n }\n\n /** Back to rest: every wave, flow, wall and filter; the turbulence reseeded from its stream. */\n reset(): void {\n const k2 = this.k * this.k;\n this.tr.reset();\n this.na.reset();\n this.glottis.reset();\n this.geometric.reset();\n this.folds.reset();\n this.threshold.reset();\n this.pTrans = this.dpAcc = 0;\n this.pSupra = this.paAcc = 0;\n this.R.fill(0);\n this.L.fill(0);\n this.U.fill(0);\n this.pn.fill(0);\n this.wV.fill(0);\n this.wY.fill(0);\n this.dv1.fill(0);\n this.dv2.fill(0);\n this.dvRaw.fill(0);\n this.area.fill(3 * k2);\n this.aMin.fill(3 * k2);\n this.fBuf.fill(0);\n this.bBuf.fill(0);\n this.pos = 0;\n this.uG = this.momG = this.lG = 0;\n this.uV = this.momV = this.lV = 0;\n this.ulLips = this.lrLips = this.ulNose = 0;\n this.pLipsOld = this.pNoseOld = 0;\n this.radPrev = this.wallRadAcc = 0;\n this.hpX = this.hpY = 0;\n this.lx1 = this.lx2 = this.ly1 = this.ly2 = 0;\n this.voicing = 0;\n this.dpGlottis = this.dpSmooth = 0;\n this.pSub = this.pSubSmooth = 0;\n this.uLips = this.uNose = 0;\n this.micX = this.micY = 0;\n this.pQ = this.pY = this.pP = 0;\n this.aVib = this.aVib0 = 0;\n this.agAcc = 0;\n this.agMean = 0.05;\n this.agLast = 0;\n this.ag = 1e-4;\n this.srcExit.fill(-1);\n this.srcUJ.fill(0);\n this.srcSec.fill(0);\n this.srcCmd0.fill(0);\n this.srcCmd1.fill(0);\n this.nTap.fill(0);\n this.vF.fill(0);\n this.vS.fill(0);\n this.aF.fill(0);\n this.nL.fill(0);\n this.nL2.fill(0);\n this.vAcc.fill(0);\n this.lvAcc.fill(0);\n this.noiseLevel.fill(0);\n this.noiseVelocity.fill(0);\n this.noiseArea.fill(0);\n this.noiseGain.fill(0);\n this.noisePlace.fill(-1);\n this.tau0.fill(0);\n this.tau1.fill(0);\n this.ring.fill(0);\n this.ringPos = 0;\n this.velW0 = this.velW1 = this.pnV = 0;\n this.seed = (this.rng() * 4294967296) | 0 || 1;\n this.blocks = 0;\n }\n\n /** The next block's inputs are in the fields: limit and ramp the shape, place the sources, run the glottal pulse. */\n beginBlock(): void {\n this.updateWalls();\n this.pJa = this.piriform > 0 ? this.pJ : -1;\n const first = this.blocks === 0;\n this.blocks++;\n const blk = this.block;\n const k = this.k;\n const k2 = k * k;\n const nG = this.nG;\n const area = this.area;\n const dArea = this.dArea;\n const grid = this.tgt;\n const gmn = this.tgtMin;\n const dt = blk / this.rate;\n // targets, floored; CHIMERA's area rate law on the grid and the minima (human_airway.rs:190-262)\n for (let s = 0; s < nG; s++) {\n const a = this.gridIn[s];\n grid[s] = a > 1e-4 ? a : 1e-4;\n const m = this.gridMin[s];\n gmn[s] = m > 1e-4 ? m : 1e-4;\n }\n if (!first) {\n this.slew.limitAll(grid, area, nG);\n this.slew.limitAll(gmn, this.aMin, nG);\n }\n for (let s = 0; s < nG; s++) {\n if (grid[s] < 1e-4) grid[s] = 1e-4;\n let m = gmn[s];\n if (m > grid[s]) m = grid[s];\n gmn[s] = m < 1e-4 ? 1e-4 : m;\n }\n // the velum junction sits one section behind the pharynx/oral split, and moves only while the port is shut\n if (this.splitI >= 0) {\n let want = Math.floor(this.splitI - 1);\n want = want < 2 ? 2 : want > nG - 2 ? nG - 2 : want;\n const shut = this.vel <= CLOSED && this.velum <= CLOSED && (this.uV < 1 && this.uV > -1);\n if (first || shut) this.jv = want;\n }\n // section ramps (linear in area) and the moving set\n let nm = 0;\n for (let s = 0; s < nG; s++) {\n const a = grid[s];\n if (first) area[s] = a;\n const d = a - area[s];\n const rel = d < 0 ? -d : d;\n const mt = gmn[s];\n if (first) this.aMin[s] = mt;\n const dm = mt - this.aMin[s];\n const relm = dm < 0 ? -dm : dm;\n // a narrow minimum ramps per sample at any change: its kinetic loss goes as 1 / A^2, so even a\n // 0.3 percent step once a block was a pressure step at every block (MEASURED: block-periodic\n // clicks as a closure released slowly)\n if (rel > MOVE_REL * 0.5 * (a + area[s]) || relm > MOVE_REL * 0.5 * (mt + this.aMin[s]) || (dm !== 0 && mt < 0.5 * k2)) {\n dArea[s] = d / blk;\n this.dAMin[s] = dm / blk;\n this.moving[nm++] = s;\n } else {\n this.dAMin[s] = 0;\n this.aMin[s] = mt;\n this.iaMin[s] = 1 / mt;\n dArea[s] = 0;\n area[s] = a;\n const z = Math.sqrt(RHOC / a);\n this.sZ[s] = z;\n this.isZ[s] = 1 / z;\n this.Zs[s] = z * z;\n }\n }\n this.nMoving = nm;\n // junction elements from the block-end shape; moving junctions recompute per sample\n let njm = 0;\n const dx = this.dx;\n for (let i = 1; i < nG; i++) {\n const sl = i - 1;\n const sr = i;\n const mv = dArea[sl] !== 0 || dArea[sr] !== 0 || this.dAMin[sl] !== 0 || this.dAMin[sr] !== 0;\n if (mv) this.jmList[njm++] = i;\n const al = grid[sl];\n const ar = grid[sr];\n // the jet leaves the upstream section's minimum and expands into the downstream section; a 0.1\n // contraction loss entering a narrower minimum (network.rs:919-930)\n const ef = 1 / gmn[sl] - 1 / ar;\n const eb = 1 / gmn[sr] - 1 / al;\n const cf = 1 / gmn[sr] - 1 / al;\n const cb = 1 / gmn[sl] - 1 / ar;\n this.kf[i] = 0.5 * RHO * ((ef > 0 ? ef * ef : 0) + (cf > 0 ? 0.1 * cf * cf : 0));\n this.kb[i] = 0.5 * RHO * ((eb > 0 ? eb * eb : 0) + (cb > 0 ? 0.1 * cb * cb : 0));\n const zl = RHOC / al;\n const zr = RHOC / ar;\n const r = this.viscC[sl] * zl * Math.sqrt(zl) + this.viscC[sr] * zr * Math.sqrt(zr);\n this.rv[i] = r;\n // walls lumped onto even junctions at double surface (the velum junction too); MEASURED\n const am = 0.5 * (al + ar);\n const sw = (i & 1) === 0 && am > CLOSED ? this.wallK[sl] * Math.sqrt(am - CLOSED) : 0;\n this.wS[i] = sw;\n const gw = sw * this.wIbsA[i] + (i === this.pJa ? this.pG : 0);\n this.gw[i] = gw;\n if (!mv) {\n const gam = 1 / (1 + zl * gw);\n this.gamA[i] = gam;\n const bq = zl * gam + zr + r;\n this.bqA[i] = bq;\n this.ibA[i] = 1 / bq;\n }\n }\n this.nJm = njm;\n // the anatomical moving-wall flow, odd junctions' share on the next even one\n const raw = this.dvRaw;\n raw.fill(0);\n if (!first) {\n for (let j = 0; j <= nG; j++) {\n const to = (j & 1) === 0 ? j : j + 1 <= nG ? j + 1 : j - 1;\n raw[to] += this.vflow[j];\n }\n }\n // weighted by the fade-in as the section opens past 0.02 to 0.12 k^2 (a sealed node takes none);\n // the product is what render() smooths per sample, so the weight's own changes are smoothed too\n // (ramped per block and multiplied by a large flow, its slope changed at every block: MEASURED\n // block-periodic clicks at a velar release)\n for (let i = 0; i <= nG; i++) {\n const a1 = i > 0 ? grid[i - 1] : this.ductArea;\n const a2 = i < nG ? grid[i] : 1;\n let wv = ((a1 > a2 ? a1 : a2) - 0.02 * k2) / (0.1 * k2);\n wv = wv < 0 ? 0 : wv > 1 ? 1 : wv * wv * (3 - 2 * wv);\n raw[i] *= wv;\n }\n // the back duct\n const tau = (this.ductLen * this.rate) / SOUND_SPEED;\n if (first) this.ductTau = tau;\n this.dTau = (tau - this.ductTau) / blk;\n const da = this.ductArea > 1e-6 ? this.ductArea : 1e-6;\n const sz = Math.sqrt(RHOC / da);\n if (first) this.ductSZ = sz;\n this.dDuctSZ = (sz - this.ductSZ) / blk;\n this.ductA = da;\n // slow inputs ramp across the block\n this.vel0 = first ? this.velum : this.vel;\n this.vel = this.velum;\n this.pL0 = first ? this.pLung : this.pL;\n this.pL = this.pLung;\n const closure = this.closure < 0 ? 0 : this.closure > 1 ? 1 : this.closure;\n const st = this.agStatic * (1 - 0.92 * closure);\n this.agSt0 = first ? st : this.agSt;\n this.agSt = st;\n // the voicing gate (glottis.rs:170-176) from this airway's own pressure across the folds\n const c30 = 1 - Math.exp(-2 * Math.PI * 30 * dt);\n this.dpSmooth += c30 * (this.dpGlottis - this.dpSmooth);\n this.pSubSmooth += c30 * (this.pSub - this.pSubSmooth);\n const thr = 2.5 * CM_H2O;\n let pg = (this.dpSmooth - thr * 0.8) / (thr * 0.8);\n pg = pg < 0 ? 0 : pg > 1 ? 1 : pg * pg * (3 - 2 * pg);\n let ag0 = (this.agStatic - 0.0125 * k2 - 0.08) / 0.14;\n ag0 = ag0 < 0 ? 0 : ag0 > 1 ? 1 : ag0 * ag0 * (3 - 2 * ag0);\n const agate = 1 - ag0;\n // the pulse's alone: the fold models report their own (the folds' turning, the geometric threshold),\n // and this gate under the folds' voicing held it near 0.5 wherever the two disagreed (MEASURED: 0.40\n // before the folds' first cycle)\n const model = this.model;\n if (model === GLOTTIS_PULSE) this.voicing += (1 - Math.exp(-2 * Math.PI * 25 * dt)) * (pg * agate * (1 - closure) - this.voicing);\n let effort = (this.pLung / CM_H2O - 3) / 10;\n effort = effort < 0 ? 0 : effort > 1 ? 1 : effort;\n this.aVib0 = this.aVib;\n this.aVib = 0.17 * k2 * (0.45 + 0.75 * effort) * this.voicing;\n if (first) this.aVib0 = this.aVib;\n this.placeSources();\n this.agAcc = 0;\n this.f0Buf[0] = this.f0;\n this.glottis.setFreqFrom(this.f0Buf, 0);\n this.areaArgs[2] = blk;\n // the pressure across the folds: the last block's mean through a 30 Hz one-pole\n const dpMean = first ? 0 : this.dpAcc / blk;\n const paMean = first ? 0 : this.paAcc / blk;\n this.dpAcc = 0;\n this.paAcc = 0;\n this.pTrans += c30 * (dpMean - this.pTrans);\n this.pSupra += c30 * (paMean - this.pSupra);\n if (model === GLOTTIS_GEOMETRIC) this.geometricBlock(closure);\n else if (model === GLOTTIS_SELF_OSCILLATING) this.foldBlock(closure);\n else this.pulseBlock();\n }\n\n /** The parametric pulse into absolute areas: the static opening plus the gated pulse, averaged over two samples. */\n private pulseBlock(): void {\n Reflect.apply(AREA_BLOCK, this.glottis, this.areaArgs);\n const buf = this.areaBuf;\n const blk = this.block;\n const inv = 1 / blk;\n const last = buf[blk - 1];\n // backwards, so each sample still reads its raw predecessor\n for (let n = blk - 1; n >= 0; n--) {\n const w = (n + 1) * inv;\n const st = this.agSt0 + (this.agSt - this.agSt0) * w;\n const av = this.aVib0 + (this.aVib - this.aVib0) * w;\n // the fold pulse, averaged over two samples (a closure's top octave is softer; MEASURED)\n let ag = st + av * 0.5 * (buf[n] + (n > 0 ? buf[n - 1] : this.agLast));\n if (ag < 1e-7) ag = 1e-7;\n buf[n] = ag;\n }\n this.agLast = last;\n }\n\n /** The geometric glottis: rest displacements from the opening, the threshold from the pressure, then the areas. */\n private geometricBlock(closure: number): void {\n const g = this.geometric;\n const L = this.foldLength > 0.1 ? this.foldLength : 0.1;\n const shut = 1 - 0.92 * closure;\n const chink = (this.chink > 0 ? this.chink : 0) * shut;\n const rest = this.agSt - chink;\n const x1 = (rest > 0 ? rest : 0) / L + this.restOffset;\n const x2 = x1 + this.upperRest * shut;\n g.length = L;\n g.chink = chink;\n g.xRest1 = x1;\n g.xRest2 = x2;\n g.lag = this.lag;\n g.skew = this.skew;\n g.doublePulse = this.doublePulse;\n const th = this.threshold;\n th.pressure = this.pTrans;\n th.halfWidth = 0.25 * (x1 + x2);\n th.drive = 1 - closure;\n th.step();\n this.voicing = th.level;\n // the swing as the root of the pressure across the folds (Titze 1989, as the paper models it)\n const p = this.pTrans > 0 ? this.pTrans : 0;\n g.xMax = GEO_AMPLITUDE * this.xRel * Math.sqrt(p) * th.level;\n g.process(this.glottis, this.areaBuf, 0, this.block);\n }\n\n /** The self-oscillating folds: rest, chink, freedom and the servo's target; their perturbation from the cycle unit. */\n private foldBlock(closure: number): void {\n const f = this.folds;\n const L = this.foldLength > 0.1 ? this.foldLength : 0.1;\n const shut = 1 - 0.92 * closure;\n const chink = (this.chink > 0 ? this.chink : 0) * shut;\n const rest = this.agSt - chink;\n let r = (rest > 0 ? rest : 0) / L + this.restOffset;\n r = r > 0 ? r : 0;\n // the block's end values, ramped per step from where the last block left them (the first block of a\n // note starts on them). Restarted each block from values computed afresh, a change of chink, length or\n // press between blocks still stepped the area at the block's edge\n if (this.blocks === 1) {\n f.rest1 = r;\n f.rest2 = r;\n f.chink = chink;\n f.length = L;\n }\n f.rest1To = r;\n f.rest2To = r;\n f.chinkTo = chink;\n f.lengthTo = L;\n f.rampLeft = this.block;\n f.free = 1 - closure;\n // the cycle unit still runs, for its drift and jitter: the servo aims at the drifted pitch, the\n // cycle's period scale perturbs the tension\n this.glottis.processPhase(this.areaBuf, 0, this.block);\n f.servo.target = this.f0 * this.glottis.pitchFactor;\n // the servo learns the tension, not the pressure: with the pressure backing up above the folds (a voiced\n // closure, a narrow constriction) f0 falls for the pressure's sake, and the servo at full weight raised\n // the tension through the dip and sent the release 190 cents sharp (MEASURED, a 60 ms lip closure). The\n // back pressure's share stays under 0.08 in 95 percent of vowel frames in every body and runs 0.2 to\n // 0.97 in closures (MEASURED over twinkle, stops, fric and son)\n // Math.min and Math.max, not conditionals: V8 boxed a double merged with a module-level constant\n const back = this.pSupra / Math.max(this.pSubSmooth, CM_H2O);\n const bc = Math.min(Math.max((back - BACK_FREE) / BACK_SPAN, 0), 1);\n const bk = bc * bc * (3 - 2 * bc);\n // and not while the folds are drawn apart: f0 sags as they open into a voiceless sound, and the servo\n // wound the tension up through that offset and began the next onset 200 to 400 cents sharp (MEASURED, an\n // aspirated stop at 110 to 460 Hz). Voiced vowels hold the opening at 0.0147 k^2 in every body (MEASURED)\n const ac = Math.min(Math.max((this.agSt / (this.k * this.k) - OPEN_FREE) / OPEN_SPAN, 0), 1);\n const ab = ac * ac * (3 - 2 * ac);\n f.servo.weight = (1 - bk) * (1 - ab);\n f.perturb = 1 / this.glottis.scale;\n f.tune();\n // voicing is whether the folds turned within the last 1.6 periods of the target, smoothed as the pulse's\n // gate is (25 Hz). A count of cycles since reset left it at 1 through every voiceless sound after the\n // first cycle: the aspiration kept its quiet voiced gain and its pulsing, and the onset after a\n // voiceless stop rang the tract (MEASURED: a 1.5 kHz tone 15 dB over the pulse's in \"twinkle\", female)\n const per = this.f0 > 20 ? this.rate / this.f0 : this.rate / 20;\n const on = f.sinceTurn < VOICED_GAP * per ? 1 : 0;\n this.voicing += (1 - Math.exp((-2 * Math.PI * 25 * this.block) / this.rate)) * (on - this.voicing);\n }\n\n /**\n * Find the constrictions, give each a slot, and set every source's places, spectrum and delay\n * for the block (Birkholz 2014). Integers only cross this call; the doubles are fields.\n */\n private placeSources(): void {\n // either way: a breath drawn in (a beatbox inward snare) drives its jets as hard as one blown out\n const pl = this.pLung > 0 ? this.pLung : -this.pLung;\n this.vMax = 1.2 * Math.sqrt((2 * pl) / RHO) + 100;\n const k = this.k;\n const k2 = k * k;\n const nG = this.nG;\n const gmn = this.tgtMin;\n const dx = this.dx;\n const rate = this.rate;\n const blk = this.block;\n const tapW0 = this.tapW0;\n const tapW1 = this.tapW1;\n for (let q = 0; q < NSRC; q++) {\n const b = q * TAPS;\n let g = 0;\n let x = 0;\n for (let t = 0; t < this.nTap[q]; t++) {\n g += tapW1[b + t];\n x += tapW1[b + t] * this.tapJ[b + t];\n tapW0[b + t] = tapW1[b + t];\n tapW1[b + t] = 0;\n }\n if (q === SRC_VEL) g = this.velW1;\n this.noiseLevel[q] = this.lvAcc[q] / blk;\n this.noiseVelocity[q] = this.vAcc[q] / blk;\n this.noiseArea[q] = this.aF[q];\n this.noiseGain[q] = g;\n this.noisePlace[q] = q === SRC_VEL ? (g > 0 ? this.jv : -1) : g > 0 ? x / g : -1;\n this.lvAcc[q] = 0;\n }\n // up to three runs apart from each other: the narrowest under 1 k^2 cm^2 and its neighbours within\n // 0.2; a further run must not connect to an earlier one through sections under 1 k^2 cm^2\n const runLo = this.runLo;\n const runHi = this.runHi;\n const conLo = this.conLo;\n const conHi = this.conHi;\n const cut = CONSTRICTED * k2;\n let nr = 0;\n for (let r = 0; r < 3; r++) {\n let mn = CONSTRICTED * k2;\n let mi = -1;\n for (let s = 0; s < nG; s++) {\n const a = gmn[s];\n if (a >= mn) continue;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (free) {\n mn = a;\n mi = s;\n }\n }\n if (mi < 0) break;\n const lim = mn + RUN_TOL * k2;\n let lo = mi;\n let hi = mi;\n for (;;) {\n const s = lo - 1;\n if (s < 0 || gmn[s] >= lim) break;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (!free) break;\n lo = s;\n }\n for (;;) {\n const s = hi + 1;\n if (s >= nG || gmn[s] >= lim) break;\n let free = true;\n for (let p = 0; p < nr; p++) if (s >= conLo[p] && s <= conHi[p]) free = false;\n if (!free) break;\n hi = s;\n }\n runLo[nr] = lo;\n runHi[nr] = hi;\n this.runMin[nr] = mi;\n while (lo > 0 && gmn[lo - 1] < cut) lo--;\n while (hi < nG - 1 && gmn[hi + 1] < cut) hi++;\n conLo[nr] = lo;\n conHi[nr] = hi;\n nr++;\n }\n // each run keeps the slot whose separation point was nearest (within 3 sections), else a free one\n let used = 0;\n for (let r = 0; r < nr; r++) {\n const exit = runHi[r] + 1;\n let best = -1;\n let bd = 4;\n for (let q = 0; q < 3; q++) {\n if ((used >> q) & 1 || this.srcExit[q] < 0) continue;\n const d = this.srcExit[q] > exit ? this.srcExit[q] - exit : exit - this.srcExit[q];\n if (d < bd) {\n bd = d;\n best = q;\n }\n }\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1) && this.srcExit[q] < 0 && this.nTap[q] === 0) best = q;\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1) && this.srcExit[q] < 0) best = q;\n if (best < 0) for (let q = 0; q < 3 && best < 0; q++) if (!((used >> q) & 1)) best = q;\n used |= 1 << best;\n this.runSlot[r] = best;\n }\n for (let q = 0; q < 3; q++) if (!((used >> q) & 1)) this.srcExit[q] = -1;\n for (let r = 0; r < nr; r++) {\n const q = this.runSlot[r];\n const mi = this.runMin[r];\n const exit = runHi[r] + 1;\n const a = gmn[mi];\n const fresh = this.nTap[q] === 0;\n if (fresh) this.freshSource(q, mi);\n this.srcExit[q] = exit;\n // the flow through the narrowest section itself, where the kinetic loss holds it to A sqrt(2 dp / rho); read\n // further on, a sealed section's v = U / A took the flow the cavity in between pumps (MEASURED: frication\n // at a /d/ closure as loud as the /s/)\n this.srcUJ[q] = mi + 1;\n this.srcSec[q] = mi;\n // the area the articulators command, before the rate law holds a closing seal open\n let cmd = 1e9;\n for (let s = conLo[r]; s <= conHi[r]; s++) if (this.gridMin[s] < cmd) cmd = this.gridMin[s];\n this.srcCmd0[q] = fresh ? cmd : this.srcCmd1[q];\n this.srcCmd1[q] = cmd;\n // D, the separation point to the incisors, x k cm\n const dk = ((this.teethX - exit) * dx) / k;\n // labiodental where the lower lip forms it at or past the incisors (/f v/); a tongue there (/\u03B8/) keeps the\n // obstacle source; a constriction whose narrowest section lies past the incisors is the lips' (rounding)\n let lab = dk / D_LABIAL;\n lab = lab <= 0 ? 1 : lab >= 1 ? 0 : 1 - lab * lab * (3 - 2 * lab);\n const lip = this.labial < 0 ? 0 : this.labial > 1 ? 1 : this.labial;\n let past = mi + 1 - this.teethX;\n past = past <= 0 ? 0 : past >= 1 ? 1 : past * past * (3 - 2 * past);\n const labio = lab * lip;\n const lips = (1 - labio) * past;\n lab = labio + lips;\n let wf = (dk - D_WALL_LO) / (D_WALL_HI - D_WALL_LO);\n wf = wf < 0 ? 0 : wf > 1 ? 1 : wf * wf * (3 - 2 * wf);\n // an obstacle needs the incisors downstream of separation: a jet that separates at or past their\n // edge (the dental /\u03B8/) blows into free air, a wall-type source with nothing ahead of it\n let ob = dk / D_FREE;\n ob = ob <= 0 ? 0 : ob >= 1 ? 1 : ob * ob * (3 - 2 * ob);\n this.tx = exit + (WALL_DOWN * k) / dx;\n this.tw = (1 - lab) * (wf * G_WALL + (1 - wf) * (1 - ob) * G_FREE);\n this.addAt(q);\n this.tx = this.teethX;\n this.tw = (1 - lab) * (1 - wf) * ob * G_OBSTACLE;\n this.addAt(q);\n this.tx = exit + (LABIAL_DOWN * k) / dx;\n this.tw = labio * G_LABIAL + lips * G_LIPS;\n this.addAt(q);\n const v = this.vAcc[q] / blk;\n const d = 2 * Math.sqrt((a > 1e-4 ? a : 1e-4) / Math.PI);\n let fc = (FC_LINGUAL * v) / d;\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n // the obstacle's share keeps its single corner (Shadle 1991: an obstacle source is broadband); a free\n // jet, a wall and the lower lip fall a second order above P2_HZ\n const wo = (1 - lab) * (1 - wf) * ob;\n let f2 = P2_HZ * Math.exp(wo * Math.log((0.45 * rate) / P2_HZ));\n f2 = f2 > 0.45 * rate ? 0.45 * rate : f2;\n this.cLp2[q] = 1 - Math.exp((-2 * Math.PI * f2) / rate);\n // the convective delay from the separation point to where the source sits\n const dObs = dk > 0 ? dk * k : 0;\n const ds = (1 - lab) * (wf * WALL_DOWN * k + (1 - wf) * (ob * dObs + (1 - ob) * WALL_DOWN * k)) + lab * LABIAL_DOWN * k;\n let tau = v > 1 ? ds / (CONVECT * v) : TAU_MAX;\n tau = (tau < TAU_MAX ? tau : TAU_MAX) * rate;\n this.tau0[q] = this.tau1[q];\n this.tau1[q] = tau;\n this.modOn[q] = 1;\n }\n // aspiration, 1.5 k cm above the glottis (at the duct's end when the duct is longer)\n {\n const q = SRC_ASP;\n if (this.nTap[q] === 0) this.freshSource(q, 0);\n let x = (ASPIRATION_AT * k - this.ductLen) / dx;\n x = x < 0 ? 0 : x > nG ? nG : x;\n this.tx = x;\n // Birkholz's aspiration gain is variable (0.005 to 0.5 of the others): less in modal voicing\n const vo = this.voicing;\n this.tw = G_ASPIRATION * (1 - vo) + G_ASPIRATION_VOICED * Math.pow(k, ASPIRATION_VOICED_K) * vo;\n this.addAt(q);\n const ga = this.agMean > 1e-4 ? this.agMean : 1e-4;\n let fc = (FC_LINGUAL * (this.vAcc[q] / blk)) / (2 * Math.sqrt(ga / Math.PI));\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n this.modOn[q] = 0;\n }\n // the velic source while the port is a constriction\n {\n const q = SRC_VEL;\n const vel = this.velum;\n this.velW0 = this.velW1;\n // a jet into the nasal cavity with no obstacle ahead: a wall source\n this.velW1 = vel > CLOSED && vel < CONSTRICTED * k2 ? G_WALL : 0;\n if (this.velW0 === 0 && this.velW1 > 0) this.freshSource(q, 0);\n const d = 2 * Math.sqrt((vel > 1e-4 ? vel : 1e-4) / Math.PI);\n let fc = (FC_LINGUAL * (this.vAcc[q] / blk)) / d;\n fc = fc < 200 ? 200 : fc > 0.45 * rate ? 0.45 * rate : fc;\n this.cLp[q] = 1 - Math.exp((-2 * Math.PI * fc) / rate);\n this.modOn[q] = 0;\n }\n for (let q = 0; q < NSRC; q++) this.vAcc[q] = 0;\n // drop taps that are silent at both ends\n for (let q = 0; q < NSRC; q++) {\n const b = q * TAPS;\n let n = 0;\n for (let t = 0; t < this.nTap[q]; t++) {\n if (tapW0[b + t] === 0 && tapW1[b + t] === 0) continue;\n this.tapJ[b + n] = this.tapJ[b + t];\n tapW0[b + n] = tapW0[b + t];\n tapW1[b + n] = tapW1[b + t];\n n++;\n }\n this.nTap[q] = n;\n }\n }\n\n /** A source starting from silence: clear its filters and its delay ring; its area from section s. */\n private freshSource(q: number, s: number): void {\n this.vF[q] = 0;\n this.vS[q] = 0;\n this.nL[q] = 0;\n this.nL2[q] = 0;\n this.aF[q] = q < 3 ? this.tgtMin[s] : q === SRC_ASP ? this.ag : this.velum > 1e-4 ? this.velum : 1e-4;\n this.tau0[q] = this.tau1[q] = 0;\n this.ring.fill(0, q * MOD_RING, (q + 1) * MOD_RING);\n }\n\n /** Place source q's weight `tw` at fractional junction `tx`, split linearly between the two junctions there. */\n private addAt(q: number): void {\n const w = this.tw;\n if (!(w > 0)) return;\n const nG = this.nG;\n let x = this.tx;\n x = x < 0 ? 0 : x > nG ? nG : x;\n const j = Math.floor(x);\n const f = x - j;\n this.tShare = 1 - f;\n this.addTap(q, j);\n if (f > 0 && j < nG) {\n this.tShare = f;\n this.addTap(q, j + 1);\n }\n }\n\n /** Add tw times tShare to source q's tap at junction j. */\n private addTap(q: number, j: number): void {\n const b = q * TAPS;\n const n = this.nTap[q];\n const add = this.tw * this.tShare;\n for (let t = 0; t < n; t++)\n if (this.tapJ[b + t] === j) {\n this.tapW1[b + t] += add;\n return;\n }\n if (n >= TAPS) return;\n this.tapJ[b + n] = j;\n this.tapW0[b + n] = 0;\n this.tapW1[b + n] = add;\n this.nTap[q] = n + 1;\n }\n\n /**\n * Render count samples (at most one block, and the block must have\n * begun), adding the sound times `gain` times env[c] into outL and outR at\n * [at, at + count). off: the block's first sample still to render.\n */\n render(outL: Float32Array, outR: Float32Array, at: number, count: number, off: number, env: Float32Array): void {\n const T = this.T;\n const iT = this.rate;\n const nG = this.nG;\n const jv = this.jv;\n const R = this.R;\n const L = this.L;\n const sZ = this.sZ;\n const isZ = this.isZ;\n const Zs = this.Zs;\n const area = this.area;\n const dArea = this.dArea;\n const U = this.U;\n const pn = this.pn;\n const kf = this.kf;\n const kb = this.kb;\n const rv = this.rv;\n const viscC = this.viscC;\n const wallK = this.wallK;\n const gwA = this.gw;\n const wV = this.wV;\n const wY = this.wY;\n const wS = this.wS;\n const moving = this.moving;\n const nm = this.nMoving;\n const jmList = this.jmList;\n const njm = this.nJm;\n const gamA = this.gamA;\n const ibA = this.ibA;\n const bqA = this.bqA;\n const dv1 = this.dv1;\n const dv2 = this.dv2;\n const raw = this.dvRaw;\n const dvc = this.dvCoef;\n const aMin = this.aMin;\n const dAMin = this.dAMin;\n const iaMin = this.iaMin;\n const wIbsA = this.wIbsA;\n const wCmA = this.wCmA;\n const wKsA = this.wKsA;\n const pJ = this.pJa;\n const pG = this.pG;\n const pCm = this.pCm;\n const pK = this.pK;\n const pDi = this.pDi;\n let pQ = this.pQ;\n let pY = this.pY;\n let pP = this.pP;\n const fBuf = this.fBuf;\n const bBuf = this.bBuf;\n const tr = this.tr;\n const na = this.na;\n const areaBuf = this.areaBuf;\n const folds = this.folds;\n const selfOsc = this.model === GLOTTIS_SELF_OSCILLATING;\n const visc0 = this.visc0;\n const ldG = this.ldG;\n const blk = this.block;\n const inv = 1 / blk;\n const gain = this.gain;\n const micK = (this.mic * SOUND_SPEED) / (2 * MIC_R);\n const micC = this.micC;\n const lungZ = (0.5 * RHOC) / tr.area[0];\n const trLast = tr.nn - 2;\n const trSegF = trLast * TUBE_RING;\n const trD = tr.D[trLast];\n const trZ = tr.Z[trLast];\n const trA = tr.area[trLast];\n const ring = this.ring;\n const tapJ = this.tapJ;\n const tapW0 = this.tapW0;\n const tapW1 = this.tapW1;\n const cVc = this.cVc;\n const cVs = this.cVs;\n const noiseScale = this.noiseScale;\n const voi = this.voicing;\n const vMax = this.vMax;\n let wallRad = 0;\n for (let c = 0; c < count; c++) {\n const n = off + c;\n const w = (n + 1) * inv;\n this.w = w;\n // moving sections\n for (let mi = 0; mi < nm; mi++) {\n const s = moving[mi];\n let a = area[s] + dArea[s];\n area[s] = a;\n if (a < 1e-4) a = 1e-4;\n let mm = aMin[s] + dAMin[s];\n aMin[s] = mm;\n if (mm > a) mm = a;\n if (mm < 1e-4) mm = 1e-4;\n iaMin[s] = 1 / mm;\n const isz = Math.sqrt(a) / SRHOC;\n const z = 1 / isz;\n sZ[s] = z;\n isZ[s] = isz;\n Zs[s] = z * z;\n }\n // moving junctions' elements\n for (let mi = 0; mi < njm; mi++) {\n const i = jmList[mi];\n const zl = Zs[i - 1];\n const zr = Zs[i];\n const ef = iaMin[i - 1] - zr * IRHOC;\n const eb = iaMin[i] - zl * IRHOC;\n const cf = iaMin[i] - zl * IRHOC;\n const cb = iaMin[i - 1] - zr * IRHOC;\n kf[i] = 0.5 * RHO * ((ef > 0 ? ef * ef : 0) + (cf > 0 ? 0.1 * cf * cf : 0));\n kb[i] = 0.5 * RHO * ((eb > 0 ? eb * eb : 0) + (cb > 0 ? 0.1 * cb * cb : 0));\n const r = viscC[i - 1] * zl * sZ[i - 1] + viscC[i] * zr * sZ[i];\n rv[i] = r;\n // the wall's surface follows the area per sample too (set once a block, it stepped the\n // junction's pressure at every block of an opening: MEASURED clicks at a velar release)\n if ((i & 1) === 0) {\n const am = 0.5 * (area[i - 1] + area[i]);\n // the surface goes to zero continuously as the section seals, so the wall leaves smoothly\n const sw = am > CLOSED ? wallK[i - 1] * Math.sqrt(am - CLOSED) : 0;\n wS[i] = sw;\n gwA[i] = sw * wIbsA[i] + (i === pJ ? pG : 0);\n }\n const t = zl * gwA[i];\n const gam = t < 1e-3 ? 1 - t : 1 / (1 + t);\n gamA[i] = gam;\n const bq = zl * gam + zr + r;\n bqA[i] = bq;\n ibA[i] = 1 / bq;\n }\n this.ductTau += this.dTau;\n this.ductSZ += this.dDuctSZ;\n const pL = this.pL0 + (this.pL - this.pL0) * w;\n this.velNow = this.vel0 + (this.vel - this.vel0) * w;\n let ag: number;\n if (selfOsc) {\n folds.step();\n ag = folds.area;\n } else ag = areaBuf[n];\n if (ag < 1e-7) ag = 1e-7;\n this.ag = ag;\n this.agAcc += ag;\n // turbulence from last sample's flows: p_s = G |v_c|^3 sqrt(A), in series where each source sits\n const rp = this.ringPos;\n for (let q = 0; q < NSRC; q++) {\n const nt = this.nTap[q];\n const vel = q === SRC_VEL;\n if (nt === 0 && !(vel && (this.velW0 > 0 || this.velW1 > 0))) continue;\n let u: number;\n let a: number;\n // the source's area: the airway's, or the commanded one where that is less\n let as: number;\n if (q < 3) {\n u = U[this.srcUJ[q]];\n a = aMin[this.srcSec[q]];\n if (a > area[this.srcSec[q]]) a = area[this.srcSec[q]];\n as = this.srcCmd0[q] + (this.srcCmd1[q] - this.srcCmd0[q]) * w;\n if (as > a) as = a;\n } else if (q === SRC_ASP) {\n u = this.uG;\n a = ag;\n as = a;\n } else {\n u = this.uV;\n a = this.velNow;\n as = a;\n }\n // a section at the closed area is shut: its floor's leak is numerical, not a jet (MEASURED: read as one, a\n // /t/ closure carried frication 30 dB over CHIMERA's silence); the source fades in to 5 times that area.\n // The area rate law closes the last 0.4 cm^2 slowly so a seal does not click; the source reads the\n // commanded area there, or that dwell was a fricative (MEASURED: 10 to 20 ms at the vowel's level\n // before each /t t\u0283/ closure, -2 dB re the phrase for the male /t\u0283/, CHIMERA -23 to -32)\n let shut = (as - 2e-4) * 1250;\n shut = q === SRC_ASP ? 1 : shut <= 0 ? 0 : shut >= 1 ? 1 : shut * shut * (3 - 2 * shut);\n if (a < 1e-4) a = 1e-4;\n if (as < 1e-4) as = 1e-4;\n const af = this.aF[q] + cVc * (as - this.aF[q]);\n this.aF[q] = af;\n // no jet outruns the lungs: the flow and the area it reads can disagree for a sample as a section seals\n let vr = u / a;\n vr = vr > vMax ? vMax : vr < -vMax ? -vMax : vr;\n const vf = this.vF[q] + cVc * (vr - this.vF[q]);\n this.vF[q] = vf;\n const av = vf < 0 ? -vf : vf;\n this.vAcc[q] += av;\n // the convective delay, read linearly between ring samples\n const rb = q * MOD_RING;\n ring[rb + rp] = av;\n const td = this.tau0[q] + (this.tau1[q] - this.tau0[q]) * w;\n const ti = td | 0;\n const tf = td - ti;\n const vd = ring[rb + ((rp - ti) & (MOD_RING - 1))] * (1 - tf) + ring[rb + ((rp - ti - 1) & (MOD_RING - 1))] * tf;\n let lev = vd * vd * vd;\n const s3 = this.vS[q] + cVs * (lev - this.vS[q]);\n this.vS[q] = s3;\n // in voicing the pulsing about the slow level is soft-limited to an index near MOD_MAX\n const mw = this.modOn[q] * voi;\n if (mw > 0) {\n let m = s3 > 1 ? lev / s3 - 1 : 0;\n m = m / (1 + (m < 0 ? -m : m) * (1 / MOD_MAX));\n lev = (1 - mw) * lev + mw * s3 * (1 + m);\n }\n // mulberry32, inline: uniform in [0, 1)\n let s = (this.seed + 0x6d2b79f5) | 0;\n this.seed = s;\n s = Math.imul(s ^ (s >>> 15), s | 1);\n s ^= s + Math.imul(s ^ (s >>> 7), s | 61);\n const wv = ((((s ^ (s >>> 14)) >>> 0) / 4294967296) * 2 - 1) * 1.7320508075688772;\n const nl1 = this.nL[q] + this.cLp[q] * (wv - this.nL[q]);\n this.nL[q] = nl1;\n const nl2 = this.nL2[q] + this.cLp2[q] * (nl1 - this.nL2[q]);\n this.nL2[q] = nl2;\n const nl = nl2;\n // the dipole's sign follows the flow's, continuously through zero\n const sa = Math.sqrt(af);\n // a jet is turbulent only above the critical Reynolds number: Re = v d / nu, d = 2 sqrt(A / pi)\n let tu = (av * sa * RE_PER_VSA - RE_LO) * RE_SPAN;\n tu = q === SRC_ASP ? 1 : tu <= 0 ? 0 : tu >= 1 ? 1 : tu * tu * (3 - 2 * tu);\n const ls = shut * tu * lev * sa;\n this.lvAcc[q] += ls;\n const v = (noiseScale * ls * nl * vf) / (av + 1);\n if (vel) {\n this.pnV = v * (this.velW0 + (this.velW1 - this.velW0) * w);\n continue;\n }\n const b = q * TAPS;\n for (let t = 0; t < nt; t++) pn[tapJ[b + t]] += v * (tapW0[b + t] + (tapW1[b + t] - tapW0[b + t]) * w);\n }\n this.ringPos = (rp + 1) & (MOD_RING - 1);\n // Lagrange-3 coefficients shared by both duct reads (tau - 0.5 and tau + 0.5)\n const dF = this.ductTau - 0.5;\n const i0 = Math.floor(dF);\n const x = dF - i0;\n const hm1 = (-x * (x - 1) * (x - 2)) / 6;\n const h0 = ((x + 1) * (x - 1) * (x - 2)) / 2;\n const h1 = (-(x + 1) * x * (x - 2)) / 2;\n const h2 = ((x + 1) * x * (x - 1)) / 6;\n const pos = this.pos;\n\n // ---- phase 0: the lungs and the trachea, the glottis, odd grid junctions\n {\n const b = tr.B[(pos - tr.D[0]) & (TUBE_RING - 1)];\n const zt = tr.Z[0];\n const u = (pL - 2 * b) / (lungZ + zt);\n tr.F[pos] = b + zt * u;\n }\n tr.interior(pos);\n {\n const a = tr.F[trSegF + ((pos - trD) & (TUBE_RING - 1))];\n const p0 = (pos - (i0 + 1)) & (TUBE_RING - 1);\n const ductSZ = this.ductSZ;\n const b = (hm1 * bBuf[(p0 + 1) & (TUBE_RING - 1)] + h0 * bBuf[p0] + h1 * bBuf[(p0 - 1) & (TUBE_RING - 1)] + h2 * bBuf[(p0 - 2) & (TUBE_RING - 1)]) * ductSZ;\n const zb = ductSZ * ductSZ;\n const ia = 1 / ag;\n const lg = ldG * ia;\n const rg = visc0 * ia * ia * ia;\n // the duct's area from its impedance, which ramps per sample (stepped once a block, the exit\n // loss stepped the flow: MEASURED clicks a glottis-to-lips delay into every block)\n const exf = ia - zb * IRHOC;\n const exb = ia - 1 / trA;\n const kin = GLOTTIS_KIN * 0.5 * RHO * ia * ia;\n const kfg = kin + 0.5 * RHO * (exf > 0 ? exf * exf : 0);\n const kbg = kin + 0.5 * RHO * (exb > 0 ? exb * exb : 0);\n const m0 = lg < this.lG ? lg * this.uG : this.momG;\n this.lG = lg;\n const cc = 2 * (a - b) + m0 * iT;\n const bq = trZ + zb + rg + lg * iT;\n const u = cc >= 0 ? (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kfg * cc)) : (2 * cc) / (bq + Math.sqrt(bq * bq - 4 * kbg * cc));\n this.uG = u;\n this.momG = lg * u;\n const pBelow = 2 * a - trZ * u;\n const pAbove = 2 * b + zb * u;\n this.dpGlottis = pBelow - pAbove;\n this.dpAcc += pBelow - pAbove;\n this.paAcc += pAbove;\n folds.ps = pBelow;\n folds.pe = pAbove;\n this.pSub = pBelow;\n tr.B[trSegF + pos] = pBelow - a;\n fBuf[pos] = (pAbove - b) / ductSZ;\n }\n for (let i = 1; i < nG; i += 2) {\n if (i === jv) continue;\n const sl = i - 1;\n const zl = Zs[sl];\n const zr = Zs[i];\n const a = R[sl] * sZ[sl];\n const b = L[i] * sZ[i];\n const cc = 2 * (a - b) + pn[i];\n const ib = ibA[i];\n const kk = cc >= 0 ? kf[i] : kb[i];\n const ac = cc < 0 ? -cc : cc;\n const eps = 4 * kk * ac * ib * ib;\n let u: number;\n if (eps < LIN_EPS) u = cc * ib * (1 - 0.25 * eps);\n else {\n const bq = bqA[i];\n u = (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kk * ac));\n }\n U[i] = u;\n L[sl] = (a - zl * u) * isZ[sl];\n R[i] = (b + zr * u) * isZ[i];\n }\n if ((jv & 1) === 1) {\n this.velumNode(pos);\n na.interior(pos);\n this.nostrils(pos);\n }\n if ((nG & 1) === 1) this.lips();\n\n // ---- phase 1: even grid junctions (walls, moving-wall flow), the duct end\n for (let i = 2; i < nG; i += 2) {\n if (i === jv) continue;\n const sl = i - 1;\n const zl = Zs[sl];\n const zr = Zs[i];\n const a = R[sl] * sZ[sl];\n const b = L[i] * sZ[i];\n const ws = wS[i];\n const hist = wCmA[i] * wV[i] - wKsA[i] * wY[i];\n const wib = wIbsA[i];\n // the piriform fossae's branch, at its one junction\n const ph = i === pJ ? (0.5 * pP + pCm * pQ - pK * pY) * pDi : 0;\n // CHIMERA's 60 Hz two-pole on the moving-wall flow, per sample (network.rs:360)\n const d1 = dv1[i] + dvc * (raw[i] - dv1[i]);\n dv1[i] = d1;\n const d2 = dv2[i] + dvc * (d1 - dv2[i]);\n dv2[i] = d2;\n const ue0 = d2 - ws * hist * wib - ph;\n const gam = gamA[i];\n const cc = 2 * a * gam - 2 * b + zl * gam * ue0 + pn[i];\n const ib = ibA[i];\n const kk = cc >= 0 ? kf[i] : kb[i];\n const ac = cc < 0 ? -cc : cc;\n const eps = 4 * kk * ac * ib * ib;\n let u: number;\n if (eps < LIN_EPS) u = cc * ib * (1 - 0.25 * eps);\n else {\n const bq = bqA[i];\n u = (2 * cc) / (bq + Math.sqrt(bq * bq + 4 * kk * ac));\n }\n U[i] = u;\n const p = (2 * a - zl * (u - ue0)) * gam;\n // a wall with no surface (its junction closed) is disconnected: it must not integrate a sealed node\n if (i === pJ) {\n const qn = pG * p + ph;\n pY += 0.5 * T * (qn + pQ);\n pQ = qn;\n pP = p;\n }\n if (ws > 0) {\n const v = (hist + p) * wib;\n wV[i] = v;\n wY[i] += T * v;\n wallRad += ws * v * WALL_RADIATION;\n }\n L[sl] = (p - a) * isZ[sl];\n R[i] = (b + zr * u) * isZ[i];\n }\n if ((jv & 1) === 0) {\n this.velumNode(pos);\n na.interior(pos);\n this.nostrils(pos);\n }\n {\n const ductSZ = this.ductSZ;\n const zd = ductSZ * ductSZ;\n const p0 = (pos - i0) & (TUBE_RING - 1);\n const a = (hm1 * fBuf[(p0 + 1) & (TUBE_RING - 1)] + h0 * fBuf[p0] + h1 * fBuf[(p0 - 1) & (TUBE_RING - 1)] + h2 * fBuf[(p0 - 2) & (TUBE_RING - 1)]) * ductSZ;\n const zr = Zs[0];\n const b = L[0] * sZ[0];\n const d1 = dv1[0] + dvc * (raw[0] - dv1[0]);\n dv1[0] = d1;\n const d2 = dv2[0] + dvc * (d1 - dv2[0]);\n dv2[0] = d2;\n const ue0 = d2;\n const cc = 2 * a - 2 * b + zd * ue0 + pn[0];\n pn[0] = 0;\n const u = cc / (zd + zr);\n U[0] = u;\n const p = 2 * a - zd * (u - ue0);\n bBuf[pos] = (p - a) / ductSZ;\n R[0] = (b + zr * u) * isZ[0];\n }\n if ((nG & 1) === 0) this.lips();\n for (let q = 0; q < SRC_VEL; q++) {\n const b = q * TAPS;\n for (let t = 0; t < this.nTap[q]; t++) pn[tapJ[b + t]] = 0;\n }\n this.pnV = 0;\n this.pos = (pos + 1) & (TUBE_RING - 1);\n // the radiated flow's derivative, DC blocked, low-passed\n const rad = this.uLips + this.uNose + this.wallRadAcc + wallRad;\n this.wallRadAcc = 0;\n wallRad = 0;\n // the far field's flow derivative, and the close microphone's flow term (DC blocked below)\n const mf = micK * rad;\n const mh = mf - this.micX + micC * this.micY;\n this.micX = mf;\n this.micY = mh;\n const o = ((rad - this.radPrev) * iT + mh) * OUTPUT_GAIN;\n this.radPrev = rad;\n const hp = o - this.hpX + this.hpC * this.hpY;\n this.hpX = o;\n this.hpY = hp;\n const y = this.lb0 * (hp + this.lx2) + this.lb1 * this.lx1 - this.la1 * this.ly1 - this.la2 * this.ly2;\n this.lx2 = this.lx1;\n this.lx1 = hp;\n this.ly2 = this.ly1;\n this.ly1 = y;\n const v = y * gain * env[c];\n outL[at + c] += v;\n outR[at + c] += v;\n }\n this.pQ = pQ;\n this.pY = pY;\n this.pP = pP;\n if (off + count >= blk) this.agMean = this.agAcc / blk;\n }\n\n /** Lips: Flanagan R || L on the last grid section, with any series noise source. */\n private lips(): void {\n const sl = this.nG - 1;\n const z = this.Zs[sl];\n const a = this.R[sl] * this.sZ[sl];\n const ar = this.area[sl] > 1e-4 ? this.area[sl] : 1e-4;\n const lr = (8 * RHO) / (3 * Math.PI * Math.sqrt(Math.PI * ar));\n const rr = (128 * RHOC) / (9 * Math.PI * Math.PI * ar);\n let ul = this.ulLips;\n const lp = this.lrLips;\n if (lp > 0 && lr > lp) ul *= lp / lr;\n const h = this.T / (2 * lr);\n const pOld = this.pLipsOld;\n const src = this.pn[this.nG];\n this.pn[this.nG] = 0;\n const p = (2 * a + src - z * (ul + h * pOld)) / (1 + z * (h + 1 / rr));\n const ul2 = ul + h * (pOld + p);\n const ur = ul2 + p / rr;\n this.pLipsOld = p;\n this.U[this.nG] = ur;\n this.L[sl] = (p - src - a) * this.isZ[sl];\n this.ulLips = ul2;\n this.lrLips = lr;\n this.uLips = ur;\n }\n\n /** Nostrils: Flanagan R || L on the nasal tube's last segment. */\n private nostrils(pos: number): void {\n const c = this.na;\n const sl = c.nn - 2;\n const z = c.Z[sl];\n const a = c.F[sl * TUBE_RING + ((pos - c.D[sl]) & (TUBE_RING - 1))];\n const ar = c.area[sl];\n const lr = (8 * RHO) / (3 * Math.PI * Math.sqrt(Math.PI * ar));\n const rr = (128 * RHOC) / (9 * Math.PI * Math.PI * ar);\n const h = this.T / (2 * lr);\n const pOld = this.pNoseOld;\n const p = (2 * a - z * (this.ulNose + h * pOld)) / (1 + z * (h + 1 / rr));\n const ul2 = this.ulNose + h * (pOld + p);\n this.ulNose = ul2;\n this.pNoseOld = p;\n this.uNose = ul2 + p / rr;\n c.B[sl * TUBE_RING + pos] = p - a;\n }\n\n /**\n * The velum node: the oral section behind joins it directly, the oral\n * section ahead through the junction's series element and the nasal tube\n * through the velum port. Two coupled flows, three Gauss-Seidel passes of\n * the closed-form root.\n */\n private velumNode(pos: number): void {\n const j = this.jv;\n const R = this.R;\n const L = this.L;\n const sZ = this.sZ;\n const isZ = this.isZ;\n const Zs = this.Zs;\n const sl = j - 1;\n const sr = j;\n const na = this.na;\n const z1 = Zs[sl];\n const z2 = Zs[sr];\n const z3 = na.Z[0];\n const a = R[sl] * sZ[sl];\n const b = L[sr] * sZ[sr];\n const c3 = na.B[(pos - na.D[0]) & (TUBE_RING - 1)];\n const gw = this.gw[j];\n const d1 = this.dv1[j] + this.dvCoef * (this.dvRaw[j] - this.dv1[j]);\n this.dv1[j] = d1;\n const d2 = this.dv2[j] + this.dvCoef * (d1 - this.dv2[j]);\n this.dv2[j] = d2;\n let ue = d2;\n if (gw > 0) ue -= this.wS[j] * (this.wCmA[j] * this.wV[j] - this.wKsA[j] * this.wY[j]) * this.wIbsA[j];\n const zl = 1 / (1 / z1 + gw);\n const p0 = (2 * a) / z1 + ue;\n const src = this.pn[j];\n this.pn[j] = 0;\n const kfr = this.kf[j];\n const kbr = this.kb[j];\n const bqr = zl + z2 + this.rv[j];\n const cr0 = zl * p0 - 2 * b + src;\n let ur = this.U[j];\n let uv = 0;\n const vel = this.velNow;\n if (vel > CLOSED) {\n const ip = 1 / vel;\n const lv = RHO * this.velLen * ip;\n const rvv = VISC * 2 * Math.sqrt(Math.PI) * this.velLen * Math.sqrt(vel) * ip * ip;\n const exf = ip - 1 / na.area[0];\n const amin = this.area[sl] < this.area[sr] ? this.area[sl] : this.area[sr];\n const exb = ip - 1 / amin;\n const kin = VELUM_KIN * 0.5 * RHO * ip * ip;\n const kfv = kin + VELUM_EXIT * 0.5 * RHO * (exf > 0 ? exf * exf : 0);\n const kbv = kin + VELUM_EXIT * 0.5 * RHO * (exb > 0 ? exb * exb : 0);\n const m0 = lv < this.lV ? lv * this.uV : this.momV;\n this.lV = lv;\n const bqv = zl + z3 + rvv + lv * this.rate;\n const cv0 = zl * p0 - 2 * c3 + m0 * this.rate + this.pnV;\n uv = this.uV;\n for (let it = 0; it < 3; it++) {\n let c = cr0 - zl * uv;\n if (c >= 0) ur = kfr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr + 4 * kfr * c)) : c / bqr;\n else ur = kbr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr - 4 * kbr * c)) : c / bqr;\n c = cv0 - zl * ur;\n if (c >= 0) uv = kfv > 0 ? (2 * c) / (bqv + Math.sqrt(bqv * bqv + 4 * kfv * c)) : c / bqv;\n else uv = kbv > 0 ? (2 * c) / (bqv + Math.sqrt(bqv * bqv - 4 * kbv * c)) : c / bqv;\n }\n this.momV = lv * uv;\n } else {\n this.momV = 0;\n this.lV = 0;\n const c = cr0;\n if (c >= 0) ur = kfr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr + 4 * kfr * c)) : c / bqr;\n else ur = kbr > 0 ? (2 * c) / (bqr + Math.sqrt(bqr * bqr - 4 * kbr * c)) : c / bqr;\n }\n this.uV = uv;\n const p = zl * (p0 - ur - uv);\n if (gw > 0) {\n const v = (this.wCmA[j] * this.wV[j] + p - this.wKsA[j] * this.wY[j]) * this.wIbsA[j];\n this.wV[j] = v;\n this.wY[j] += this.T * v;\n this.wallRadAcc += this.wS[j] * v * WALL_RADIATION;\n }\n this.U[j] = ur;\n L[sl] = (p - a) * isZ[sl];\n R[sr] = (b + z2 * ur) * isZ[sr];\n na.F[pos] = c3 + z3 * uv;\n }\n}\n", "/*\n * The beatbox scores: each drum sound as a short gestural score on the voice's tract, its acoustic hit\n * at h, with the airstream beatboxers use (vocal-beats.ts lists the sounds). CHIMERA's scores (Jameson\n * Hodge, MIT, crates/chimera/src/phonetics/beatbox.rs), reimplemented on bellows' planner; the breath\n * key, the ejective's push through the release, the kick's raised tongue body, 'ch', 'Psh' and the\n * breath in are bellows' own. See THIRD_PARTY_NOTICES.md.\n *\n * Written against BeatWriter, the few planner primitives a score needs, so the recipes live apart from\n * the planner's machinery. Runs when the planner rebuilds (event rate); allocates nothing.\n */\n\nimport { ART, ARTICULATORS, KEY_ABDUCTION, KEY_BREATH, KEY_CLOSURE } from './vocal-articulators';\nimport { VOCAL_BEATS } from './vocal-beats';\nimport { VOCAL_TABLE_PHONEMES } from './vocal-tables.gen';\n\n/** What a beat score writes with: the planner's gesture primitives (engines/vocal-planner.ts). */\nexport interface BeatWriter {\n /** The dorsum's height for [x] at this body. */\n readonly xTbY: number;\n /** Schwa's target for an articulator at this body. */\n schwaTarget(a: number): number;\n begin(): void;\n key(k: number, v: number): void;\n /** A gesture from the keys since begin(): its index, or -1 when the pool is full. */\n emit(t0: number, t1: number, ri: number, ro: number, str: number, speed: number): number;\n /** Rank gesture g as a consonant's, so its speed governs its articulators. */\n rank(g: number, speed: number): void;\n /** A consonant's oral gestures from table phoneme idx with overrides (see VocalPlanner.beatOral). */\n beatOral(idx: number, a: number, b: number, speed: number, snap: number, snapRo: number, after: number, fric: boolean, k1: number, v1: number, k2: number, v2: number, noFront: boolean): void;\n}\n\n/* Beat numbers (VOCAL_BEATS order). */\nconst BEAT_ID = (id: string): number => VOCAL_BEATS.findIndex((b) => b.id === id);\nconst B_KICK = BEAT_ID('B');\nconst B_HAT = BEAT_ID('t');\nconst B_OPEN_HAT = BEAT_ID('tss');\nconst B_SNARE = BEAT_ID('Pf');\nconst B_RIM = BEAT_ID('K');\nconst B_INWARD = BEAT_ID('^K');\nconst B_CLICK = BEAT_ID('!');\nconst B_POP = BEAT_ID('P!');\nconst B_CRASH = BEAT_ID('kch');\nconst B_HUM = BEAT_ID('m');\nconst B_CHAT = BEAT_ID('ch');\nconst B_PSH = BEAT_ID('Psh');\nconst B_IN = BEAT_ID('in');\n\n/* The table phonemes the beats are built from. */\n/** The kick's tongue body, high and short of the palate (/k/ seals at 8.35). */\nconst KICK_TBY = 7.7;\n/** How long after the release the ejective's larynx keeps rising, s. */\nconst EJECTIVE_PUSH = 0.025;\n/** A breath in's lung pressure, a fraction of the note's (about -5.7 cmH2O at the default velocity; INFERRED). */\nconst BREATH_IN = 0.5;\n/**\n * A breath in's glottal opening, cm^2 before k^2. MEASURED: wide open (0.9) the inflow, 330 cm^3/s, was\n * 76 dB under the vowel (noise grows as v^3); at 0.18 and 0.5 of the note's pressure it reads about\n * -33 dB, a quiet but audible breath (INFERRED target).\n */\nconst BREATH_IN_GLOTTIS = 0.18;\nconst P_P = VOCAL_TABLE_PHONEMES.indexOf('p');\nconst P_T = VOCAL_TABLE_PHONEMES.indexOf('t');\nconst P_K = VOCAL_TABLE_PHONEMES.indexOf('k');\nconst P_S = VOCAL_TABLE_PHONEMES.indexOf('s');\nconst P_F = VOCAL_TABLE_PHONEMES.indexOf('f');\nconst P_SH = VOCAL_TABLE_PHONEMES.indexOf('\u0283');\nconst P_M = VOCAL_TABLE_PHONEMES.indexOf('m');\n\n/**\n * A beat's gestures, its acoustic hit at h: CHIMERA's scores (phonetics/beatbox.rs), each sound a\n * short score on the tract with the airstream beatboxers use. `len` is the time to the next step,\n * which a sustained sound may fill. `first`: the line's first sound, whose ready posture starts early.\n */\nexport function writeBeatScore(w: BeatWriter, slot: number, h: number, len: number, first: boolean): void {\n const b = slot >> 1;\n const accent = (slot & 1) === 1 ? 1.3 : 1;\n const hum = b === B_HUM || b === B_IN;\n // the ready posture: jaw nearly closed, lips just apart, the dorsum a little high for the velar hits\n w.begin();\n for (let k = 0; k < ARTICULATORS; k++) {\n if (k === ART.velum) continue;\n let v = w.schwaTarget(k);\n if (k === ART.tbY) v += 0.1;\n else if (k === ART.jaw) v = 0.4;\n else if (k === ART.lipAp) v = 0.25;\n else if (k === ART.lipProt) v = 0.1;\n w.key(k, v);\n }\n w.emit(first ? h - 0.15 : h, h + len, 0.03, 0.03, 1, 0);\n if (!hum) {\n // the velum shut, so the pressure a sound builds stays in the mouth\n w.begin();\n w.key(ART.velum, w.schwaTarget(ART.velum));\n w.emit(first ? h - 0.15 : h - 0.02, h + len, 0.03, 0.03, 4, 0);\n }\n const NaN_ = NaN;\n if (b === B_KICK) {\n w.beatOral(P_P, h - 0.075, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n // the tongue body high in the mouth, short of the palate: the larynx compresses the volume behind\n // the lips, and the less of it the higher the pressure (dP = rho c^2 dV / V; MEASURED: the open\n // mouth's kick reached 7 cmH2O where the velar rimshot reached 19)\n artic(w, ART.tbY, KICK_TBY, h - 0.09, h + 0.01, 0.03, 0.04, 2);\n ejective(w, h - 0.075, h, accent);\n } else if (b === B_HAT || b === B_CHAT) {\n const fric = b === B_HAT ? P_S : P_SH;\n const end = b === B_HAT ? 0.03 : 0.05;\n w.beatOral(P_T, h - 0.05, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n w.beatOral(fric, h + 0.012, h + end, 1.6, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.03, h + end - 0.004, (b === B_HAT ? 1.25 : 1.3) * accent, b === B_HAT ? 0.36 : 0.38, 0.02);\n } else if (b === B_OPEN_HAT) {\n const end = Math.max(0.09, Math.min(0.26, len * 1.6));\n w.beatOral(P_T, h - 0.05, h, 2, 3.5, 0.01, NaN_, false, ART.jaw, 0.3, -1, 0, false);\n w.beatOral(P_S, h + 0.012, h + end, 1.4, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.03, h + end, 1.2 * accent, 0.4, 0.09);\n } else if (b === B_SNARE || b === B_PSH) {\n const pf = b === B_SNARE;\n w.beatOral(P_P, h - 0.06, h, 2, 3.5, 0.01, NaN_, false, -1, 0, -1, 0, false);\n w.beatOral(pf ? P_F : P_SH, h + 0.018, h + (pf ? 0.08 : 0.11), pf ? 1.6 : 1.5, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.045, h + (pf ? 0.075 : 0.1), 1.7 * accent, 0.45, pf ? 0.04 : 0.05);\n } else if (b === B_RIM) {\n w.beatOral(P_K, h - 0.08, h, 2, 4, 0.008, NaN_, false, ART.jaw, 0.35, -1, 0, false);\n ejective(w, h - 0.08, h, accent);\n } else if (b === B_INWARD) {\n w.beatOral(P_K, h - 0.06, h, 2, 4, 0.008, NaN_, false, ART.jaw, 0.35, -1, 0, false);\n w.beatOral(P_K, h + 0.012, h + 0.085, 1.4, 0, 0, 0.008, true, ART.tbY, w.xTbY - 0.015, -1, 0, false);\n w.begin();\n w.key(KEY_ABDUCTION, 0.5);\n w.emit(h - 0.05, h + 0.085, 0.02, 0.04, 6, 0);\n // the breath drawn in behind the closure, so the release rushes inward\n w.begin();\n w.key(KEY_BREATH, -1.7 * accent);\n w.emit(h - 0.035, h + 0.085, 0.015, 0.05, 2, 0);\n } else if (b === B_CLICK) {\n // the tip seals without the alveolar's fronted tongue body (that would close the pocket)\n w.beatOral(P_T, h - 0.12, h, 2, 3.5, 0.01, NaN_, false, -1, 0, -1, 0, true);\n // the back seal sits low, leaving a pocket for the dorsum to hollow\n w.beatOral(P_K, h - 0.12, h + 0.035, 2, 0, 0, NaN_, false, ART.tbY, 7.85, ART.jaw, 0.4, false);\n artic(w, ART.dorsum, 1, h - 0.03, h + 0.006, 0.04, 0.03, 2);\n } else if (b === B_POP) {\n // a light seal: pressing the lips squeezes the pocket before the suction starts\n w.beatOral(P_P, h - 0.12, h, 2, 5, 0.006, NaN_, false, ART.lipAp, -0.08, -1, 0, false);\n w.beatOral(P_K, h - 0.12, h + 0.03, 2, 0, 0, NaN_, false, -1, 0, -1, 0, false);\n // the lips stay sealed while the jaw and tongue hollow the mouth\n w.begin();\n w.key(ART.jaw, 1.6);\n w.key(ART.dorsum, 1);\n const g = w.emit(h - 0.07, h + 0.004, 0.04, 0.05, 40, 2);\n if (g >= 0) w.rank(g, 2);\n } else if (b === B_CRASH) {\n const end = Math.max(0.14, Math.min(0.34, len * 2));\n // the back of the tongue lingers by the velum after the burst ([x]) while the blade rises into a long [\u0283]\n w.beatOral(P_K, h - 0.06, h, 2, 4, 0.008, NaN_, false, -1, 0, -1, 0, false);\n w.beatOral(P_K, h + 0.002, h + 0.045, 2, 0, 0, 0.008, true, ART.tbY, w.xTbY, -1, 0, false);\n w.beatOral(P_SH, h + 0.025, h + end, 1.4, 0, 0, 0.008, false, -1, 0, -1, 0, false);\n blow(w, h - 0.035, h + end, 1.75 * accent, 0.45, 0.14);\n } else if (b === B_HUM) {\n const end = Math.max(0.06, len * 0.92);\n // lips shut before the voice starts, so the note begins as a hum; the velum drops into the\n // sealed mouth while the folds are still apart, so the squeezed air does not pop out the nose\n w.beatOral(P_M, h - 0.03, h + end, 1.6, 0, 0, NaN_, false, -1, 0, -1, 0, false);\n w.begin();\n w.key(ART.velum, 0.9);\n w.emit(h - 0.02, h + end, 0.03, 0.03, 4, 0);\n w.begin();\n w.key(KEY_ABDUCTION, 0.3);\n w.emit(h - 0.08, h - 0.03, 0.02, 0.02, 5, 0);\n w.begin();\n w.key(KEY_BREATH, 0.95 * accent);\n w.emit(h - 0.01, h + end, 0.02, 0.04, 1, 0);\n } else if (b === B_IN) {\n // a breath in between phrases (Werner et al. 2021: noise with no pitch, louder the faster the\n // breath and the wider the jaw): the glottis wide, the jaw open, the velum part open (mouth and\n // nose), and the lungs below the mouth's pressure. The amounts are INFERRED, gated on level.\n const end = Math.max(0.12, len);\n artic(w, ART.jaw, 0.95, h - 0.04, h + end - 0.05, 0.05, 0.06, 1.2);\n w.begin();\n w.key(ART.lipAp, 0.9);\n w.key(ART.velum, 0.5);\n w.emit(h - 0.04, h + end - 0.05, 0.05, 0.06, 4, 0);\n w.begin();\n w.key(KEY_ABDUCTION, BREATH_IN_GLOTTIS);\n w.emit(h - 0.03, h + end, 0.03, 0.05, 8, 0);\n w.begin();\n w.key(KEY_BREATH, -BREATH_IN * accent);\n w.emit(h, h + end - 0.04, 0.06, 0.05, 2, 0);\n }\n // B_REST: the ready posture only\n}\n\n/** One articulator held at a target over [t0, t1] at strength 40, moving at `speed`. */\nfunction artic(w: BeatWriter, k: number, v: number, t0: number, t1: number, ri: number, ro: number, speed: number): void {\n w.begin();\n w.key(k, v);\n const g = w.emit(t0, t1, ri, ro, 40, speed);\n if (g >= 0) w.rank(g, speed);\n}\n\n/** The glottalic piston: the glottis sealed through the closure, the larynx raised just before the release at h. */\nfunction ejective(w: BeatWriter, at: number, h: number, accent: number): void {\n w.begin();\n w.key(KEY_CLOSURE, 1);\n w.emit(at - 0.012, h + 0.03, 0.012, 0.03, 8, 0);\n w.begin();\n w.key(ART.larynx, Math.min(1.6, 1.25 + 0.3 * accent));\n // still rising through the release: the piston, not the few tenths of a cm^3 the closure\n // compressed, drives the puff that follows the burst\n const g = w.emit(h - 0.05, h + EJECTIVE_PUSH, 0.03, 0.08, 40, 3);\n if (g >= 0) w.rank(g, 3);\n}\n\n/**\n * Lung pressure (times the note's) over [t0, t1], with the glottis held open until the breath has\n * gone, or the folds would start to buzz on what is left.\n */\nfunction blow(w: BeatWriter, t0: number, t1: number, level: number, abduction: number, tail: number): void {\n w.begin();\n w.key(KEY_ABDUCTION, abduction);\n w.emit(t0, t1 + tail + 0.02, 0.02, 0.03, 6, 0);\n w.begin();\n w.key(KEY_BREATH, level);\n w.emit(t0 - 0.01, t1, 0.02, tail, 1, 0);\n}\n", "/*\n * The articulation planner: a sung line's phonemes, as they arrive, to\n * targets and speeds for CHIMERA's 17 articulators and the glottis, at\n * control rate.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49):\n * crates/chimera/src/phonetics/planner.rs:24, 88-108, 196-390 and 532-577\n * (the gestures and their timing), control/score.rs:273-430 and\n * voice/human_voice.rs:445 (how gestures blend), control/articulators.rs\n * (speeds), as summarized with file and line in data/vocal/\n * chimera-articulation.json. Reimplemented here; see\n * THIRD_PARTY_NOTICES.md. Changes from CHIMERA: it plans online, from\n * phonemes posted as they come (with the next ones posted early when the\n * caller knows them), instead of from a whole utterance; a phrase-initial\n * consonant starts moving 60 ms earlier; palatalization, trills and\n * nasalized vowels are not used (no bellows phoneme has them).\n *\n * GESTURES. A gesture holds some articulators at targets over [t0, t1],\n * with raised-cosine ramps ri before and ro after, at a strength. Each\n * control step every articulator's target is the strength-weighted mean of\n * the active gestures on it, with the performer's rest posture at weight\n * 0.05 (the velum is a bounded key: it moves toward the gestures' mean by\n * at most their summed weight over 2). So a consonant holds only the\n * articulators it dominates (strength 40), its other targets are weak\n * (2.2), and the tongue body keeps following the vowels: the vowel\n * gestures (strength 1) ramp in over most of the consonants before them\n * (anticipation) and out over part of those after (carryover), Ohman's\n * overlap. A gesture also speeds its articulators up by its manner's\n * speed while it can act (1.55 stops and nasals, 2.8 the tap, 2.0 and\n * 1.4 an affricate's closure and release, 1.3 the rest).\n *\n * CHANGES FOR THE ARTICULATOR CASCADE (dsp/cascade.ts, six stages where\n * CHIMERA has a critically damped pair; the 98 percent times are kept):\n * - each articulator sees every gesture CASCADE_LAG of its own 98 percent\n * time ahead (0.18 of it, 5 to 28 ms), the extra time the cascade takes\n * to pass half way, so sounds keep CHIMERA's times;\n * - a consonant's release is a return gesture (VocalTractLab 2.4): from\n * its gesture's end its articulators move at RETURN_SPEED for one whole\n * movement, whatever follows, where CHIMERA held the speed 45 ms;\n * - when two consonants hold an articulator at once, a closure wins over\n * any other constriction and then the more anterior place, and an\n * approach takes the articulator from a return;\n * - a bilabial closure aims at LIP_VIRTUAL, past the lips' contact (the\n * engine stops them at LIP_COMPRESSED), and closing consonants release\n * a few ms earlier than CHIMERA's (lips 25 ms before the next sound,\n * tip 24, body 39), since a pressed articulator takes longer to leave.\n *\n * ONLINE. A segment is a phoneme and its start in voice time. The caller\n * adds them as they become known: addUpcoming() for one posted early,\n * addNow() for one that starts now. Every addition rebuilds the gestures of\n * the segments still in reach, which is how a gesture that ends before the\n * next segment (a closure releases 20 to 34 ms early) or starts before its\n * own (a stop closes 22 to 31 ms early, a nasal lowers the velum 20 ms\n * early) gets the right times when segments are posted far enough ahead,\n * and the nearest ones otherwise. Posted 0.3 s ahead, the plan equals the\n * one built from the whole line at once.\n *\n * Nothing allocates after construction: segments and gestures live in\n * fixed arrays, and a full pool drops the oldest segment.\n */\n\nimport { CASCADE_ORDER, CASCADE_SETTLE_98, cascadeSettle } from '../dsp/cascade';\nimport { CRITDAMP_SETTLE_98 } from '../dsp/critdamp';\nimport { ARTICULATORS, ART, KEY_ABDUCTION, KEY_BREATH, KEY_CLOSURE, KEY_STIFFNESS } from './vocal-articulators';\nimport { VOCAL_ACOUSTICS, vocalPhonemeIndex } from './vocal-phonemes';\nimport { VOCAL_BEAT_BASE, VOCAL_SOUND_COUNT } from './vocal-beats';\nimport { writeBeatScore } from './vocal-beat-scores';\nimport {\n VOCAL_ARTICULATOR_HZ,\n VOCAL_ARTICULATOR_MAX,\n VOCAL_ARTICULATOR_MIN,\n VOCAL_BODIES,\n VOCAL_INVENTORY,\n VOCAL_NEUTRAL,\n VOCAL_TABLE_PHONEMES,\n} from './vocal-tables.gen';\n\n/* The glottal control keys live with the articulators' (vocal-articulators.ts); exported here too for older imports. */\nexport { KEY_ABDUCTION, KEY_CLOSURE, KEY_STIFFNESS, KEY_BREATH };\nconst KEYS = ARTICULATORS + 4;\n\n/**\n * The stiffness gesture of a voiceless obstruent ramps out over this many\n * seconds after its abduction ends. Hanson (2009, \"Effects of obstruent\n * consonants on fundamental frequency at vowel onset in English\", JASA 125)\n * and Lofqvist et al. (1989) put the raised f0 after voiceless obstruents\n * in the folds' tension (cricothyroid activity that helps hold them apart\n * against the flow), lasting into the first 50 to 100 ms of the vowel.\n */\nconst STIFF_RELEASE = 0.08;\n\nexport const VOCAL_TABLE_SIZE = VOCAL_TABLE_PHONEMES.length;\n\n/* Per-phoneme classes, as numbers. */\nconst M_SILENCE = 0;\nconst M_VOWEL = 1;\nconst M_STOP = 2;\nconst M_FRICATIVE = 3;\nconst M_AFFRICATE = 4;\nconst M_NASAL = 5;\nconst M_APPROXIMANT = 6;\nconst M_LATERAL = 7;\nconst M_TAP = 8;\nconst M_GLOTTAL = 9;\n/** A beatbox sound (engines/vocal-beats.ts): its gestures come from beat(), not from the tables. */\nconst M_BEAT = 10;\nconst MANNER_CODE: Record<string, number> = {\n silence: M_SILENCE,\n vowel: M_VOWEL,\n stop: M_STOP,\n fricative: M_FRICATIVE,\n affricate: M_AFFRICATE,\n nasal: M_NASAL,\n approximant: M_APPROXIMANT,\n lateral: M_LATERAL,\n tap: M_TAP,\n glottal: M_GLOTTAL,\n};\nconst PLACE_RANK: Record<string, number> = {\n bilabial: 0,\n labiodental: 1,\n dental: 2,\n alveolar: 3,\n postalveolar: 4,\n retroflex: 5,\n palatal: 6,\n velar: 7,\n uvular: 8,\n};\n\nconst COUNT = VOCAL_TABLE_SIZE;\nif (COUNT !== VOCAL_BEAT_BASE) throw new Error('vocal planner: the beats must follow the table phonemes');\n/* Per sound: the table phonemes, then the beats (each plain and accented). */\nconst SOUNDS = VOCAL_SOUND_COUNT;\nconst MANNER = new Uint8Array(SOUNDS);\nconst VOICED = new Uint8Array(SOUNDS);\nconst RANK = new Int8Array(SOUNDS).fill(-1);\nconst ALVEOLAR = new Uint8Array(SOUNDS);\nconst NASAL = new Uint8Array(SOUNDS);\n/** 0 none, 1 open (h), 2 stop (\u0294), 3 breathy. */\nconst GLOTTAL = new Uint8Array(SOUNDS);\nconst RELEASE = new Int16Array(SOUNDS).fill(-1);\n/** Bit a set if the phoneme dominates articulator a. */\nconst DOMINANT = new Int32Array(SOUNDS);\nconst BODY_ONLY = new Uint8Array(SOUNDS);\nconst LIPS_ONLY = new Uint8Array(SOUNDS);\nfor (let i = COUNT; i < SOUNDS; i++) MANNER[i] = M_BEAT;\n/* Schwa: the beat scores' ready posture. */\nconst P_SCHWA = VOCAL_TABLE_PHONEMES.indexOf('\u0259');\n/** The velar fricative [x], which the tables lack: /k/'s place with the dorsum this far down, by body (CHIMERA's inventory). */\nconst X_TBY = [7.365, 7.43, 7.499];\n/**\n * A voiced stop's glottal opening through its closure, cm^2 before k^2 (INFERRED): air keeps flowing in, so\n * the cavity never falls below the atmosphere. The cost is Ohala's aerodynamic voicing constraint: the\n * cavity fills and the folds' pressure drop falls, so voicing fades late in a long closure, as English\n * /b d g/ often devoice. MEASURED at 0.02: /\u0279dj/'s release from 75 to 13 times the line's median\n * sharpness; /b/'s closure 0.02 more open than /p/'s voices strongly early and fades late.\n */\nconst VOICED_ABDUCTION = 0.02;\nfor (let i = 0; i < COUNT; i++) {\n const d = VOCAL_INVENTORY[i];\n MANNER[i] = MANNER_CODE[d.manner];\n VOICED[i] = d.voiced ? 1 : 0;\n RANK[i] = PLACE_RANK[d.place] ?? -1;\n ALVEOLAR[i] = d.place === 'alveolar' ? 1 : 0;\n NASAL[i] = d.nasal ? 1 : 0;\n GLOTTAL[i] = d.glottal === 'open' ? 1 : d.glottal === 'stop' ? 2 : d.glottal === 'breathy' ? 3 : 0;\n RELEASE[i] = d.release;\n let mask = 0;\n for (const a of d.dominant) mask |= 1 << a;\n DOMINANT[i] = mask;\n const body = (1 << ART.tbX) | (1 << ART.tbY) | (1 << ART.root);\n const lips = (1 << ART.lipAp) | (1 << ART.labiodental);\n BODY_ONLY[i] = mask !== 0 && (mask & ~body) === 0 ? 1 : 0;\n LIPS_ONLY[i] = mask !== 0 && (mask & ~lips) === 0 ? 1 : 0;\n}\n\n/** Whether table phoneme i is a vowel. */\nexport function vocalIsVowel(i: number): boolean {\n return MANNER[i] === M_VOWEL;\n}\n\nconst SEGMENTS = 32;\nconst GESTURES = 256;\nconst GESTURE_KEYS = 12;\n/** Two segments' starts closer than this are the same segment, seconds. */\nconst SAME = 0.003;\n/** Segments whose influence has certainly ended this long ago are dropped, seconds. */\nconst FORGET = 1.5;\n/**\n * A phrase-initial consonant starts this much earlier (the prototype's measured choice: a phrase-initial\n * /\u0283/ was 17 dB weak without it). Only the first: the rest of an onset cluster keeps its own time, or the\n * /t/ of /st\u0279/ held the tongue tip from 5 ms after the note-on, outranked the /s/ and left it silent\n * (MEASURED: 45 dB under CHIMERA's above 2.5 kHz, every body).\n */\nconst INITIAL_LEAD = 0.06;\n/** No consonant holds the articulator. */\nconst NO_RANK = 127;\n/** CHIMERA's rest-posture weight in the blend. */\nconst BASE_WEIGHT = 0.05;\n\nexport class VocalPlanner {\n /* Segments, in start order. */\n private readonly segIdx = new Int16Array(SEGMENTS);\n private readonly segT0 = new Float64Array(SEGMENTS);\n private segCount = 0;\n /** Whether a vowel was dropped off the front, so no remaining consonant is phrase-initial. */\n private droppedVowel = false;\n /** The end of the phrase (Infinity until known), voice seconds. */\n private end = Infinity;\n\n /* Gestures. */\n private readonly gT0 = new Float64Array(GESTURES);\n private readonly gT1 = new Float64Array(GESTURES);\n private readonly gRi = new Float64Array(GESTURES);\n private readonly gRo = new Float64Array(GESTURES);\n private readonly gStr = new Float64Array(GESTURES);\n private readonly gSpeed = new Float64Array(GESTURES);\n /** A consonant's return: how long after t1 + ro its speed holds, s. */\n private readonly gHold = new Float64Array(GESTURES);\n /** A consonant's return speed (0: none). */\n private readonly gRet = new Float64Array(GESTURES);\n /**\n * A consonant's priority on its articulators, lower first: a closure (stop,\n * nasal, an affricate's closure) at its place rank (0 bilabial .. 8\n * uvular), anything else at 16 plus it; -1 for a gesture that is not a\n * consonant's main one.\n */\n private readonly gRank = new Int8Array(GESTURES);\n /** How far ahead each key of a gesture is evaluated, s: its articulator's added lag in the cascade (0 for the glottis). */\n private readonly gLead = new Float64Array(GESTURES * GESTURE_KEYS);\n /** The smallest and largest of a gesture's leads, to skip or take whole a gesture no key of which is in a ramp. */\n private readonly gLeadMin = new Float64Array(GESTURES);\n private readonly gLeadMax = new Float64Array(GESTURES);\n private readonly gKeyCount = new Uint8Array(GESTURES);\n private readonly gKeys = new Uint8Array(GESTURES * GESTURE_KEYS);\n private readonly gVals = new Float64Array(GESTURES * GESTURE_KEYS);\n private gCount = 0;\n\n /* Targets blended for the body. */\n private readonly vowelT = new Float64Array(COUNT * ARTICULATORS);\n private readonly consT = new Float64Array(COUNT * ARTICULATORS);\n /* Scratch for a gesture being built. */\n private readonly kTmp = new Uint8Array(KEYS);\n private readonly vTmp = new Float64Array(KEYS);\n private nTmp = 0;\n\n /* Outputs of evaluate(). */\n /** Articulator targets, clamped to range. */\n readonly target = new Float64Array(ARTICULATORS);\n /** Speed factor per articulator, 1 at rest. */\n readonly speed = new Float64Array(ARTICULATORS);\n /** Glottal abduction from gestures (cm^2 before the body's k^2), closure 0 to 1, and fold stiffness 0 to 1. */\n abduction = 0;\n closure = 0;\n stiffness = 0;\n /** The breath, a factor on the note's lung pressure: 1 in speech and song, 0 between beats, negative drawn in. */\n breath = 1;\n /** Whether the evaluated time is in a beat line (the breath rests at 0 and moves fast). */\n beat = 0;\n /**\n * How fully a consonant holds each articulator at the evaluated time, 0 to 1 (the largest ramp\n * of any consonant gesture on it): a voice setting (vocal.ts) gives way where a consonant closes.\n */\n readonly held = new Float64Array(ARTICULATORS);\n /** The dorsum's height for [x] at this body. */\n /** The dorsum's height for [x] at this body (the beat scores' velar fricative). */\n xTbY = X_TBY[0];\n /** Scratch: a consonant's targets with a beat's overrides. */\n private readonly beatT = new Float64Array(ARTICULATORS);\n /** Inputs of evaluateNow() and queryNow(): the time and the rest tip. */\n at = 0;\n restX = 0;\n restY = 0;\n /** Outputs of queryNow(). */\n silent = 0;\n vowel = -1;\n private readonly wsum = new Float64Array(KEYS);\n private readonly vsum = new Float64Array(KEYS);\n /* Per articulator at the evaluated time: the first in priority of the consonants approaching it (rankA), fully under way on it (rankF) and returning from it (rankR), and the speeds of those approaching and returning. */\n private readonly rankA = new Int8Array(ARTICULATORS);\n private readonly rankF = new Int8Array(ARTICULATORS);\n private readonly rankR = new Int8Array(ARTICULATORS);\n private readonly speedA = new Float64Array(ARTICULATORS);\n private readonly speedR = new Float64Array(ARTICULATORS);\n\n constructor() {\n this.setBody(0);\n }\n\n /** Body 0 male to 2 child, continuous: targets blend linearly between neighbours. */\n setBody(body: number): void {\n const b = body > 0 ? (body < 2 ? body : 2) : 0;\n const lo = Math.floor(b) < 2 ? Math.floor(b) : 1;\n const w = b - lo;\n const A = VOCAL_BODIES[lo];\n const B = VOCAL_BODIES[lo + 1];\n this.xTbY = X_TBY[lo] * (1 - w) + X_TBY[lo + 1] * w;\n for (let p = 0; p < COUNT; p++) {\n for (let a = 0; a < ARTICULATORS; a++) {\n this.vowelT[p * ARTICULATORS + a] = A.vowelTargets[p][a] * (1 - w) + B.vowelTargets[p][a] * w;\n this.consT[p * ARTICULATORS + a] = A.consonantTargets[p][a] * (1 - w) + B.consonantTargets[p][a] * w;\n }\n }\n this.rebuild();\n }\n\n /** Forget everything: a new note. */\n clear(): void {\n this.segCount = 0;\n this.gCount = 0;\n this.droppedVowel = false;\n this.end = Infinity;\n }\n\n /**\n * Phoneme `idx` starts at voice time t, now: a segment posted early with\n * the same sound and time is confirmed, a repeat of the sounding segment\n * is ignored, and anything planned after t is dropped, since the caller\n * has gone another way.\n */\n addNow(idx: number, t: number): void {\n for (let s = 0; s < this.segCount; s++) {\n if (this.segIdx[s] === idx && Math.abs(this.segT0[s] - t) <= SAME) return;\n }\n const n = this.segCount;\n // a beat strikes again; a phoneme repeated is the same sound held\n if (n > 0 && this.segIdx[n - 1] === idx && this.segT0[n - 1] < t - SAME && MANNER[idx] !== M_BEAT) return;\n while (this.segCount > 0 && this.segT0[this.segCount - 1] >= t - SAME) this.segCount--;\n this.push(idx, t);\n this.rebuild();\n }\n\n /** Phoneme `idx` will start at voice time t. */\n addUpcoming(idx: number, t: number): void {\n for (let s = 0; s < this.segCount; s++) {\n if (Math.abs(this.segT0[s] - t) <= SAME) {\n this.segIdx[s] = idx;\n this.rebuild();\n return;\n }\n }\n this.push(idx, t);\n this.rebuild();\n }\n\n /** The phrase ends at voice time t (the note-off). */\n setEnd(t: number): void {\n this.end = t;\n while (this.segCount > 0 && this.segT0[this.segCount - 1] >= t) this.segCount--;\n this.rebuild();\n }\n\n /** Drop segments that can no longer matter at time t. */\n forget(t: number): void {\n let drop = 0;\n while (drop + 2 < this.segCount && this.segT0[drop + 2] < t - FORGET) drop++;\n if (drop === 0) return;\n for (let s = 0; s < drop; s++) if (MANNER[this.segIdx[s]] === M_VOWEL) this.droppedVowel = true;\n this.segIdx.copyWithin(0, drop, this.segCount);\n this.segT0.copyWithin(0, drop, this.segCount);\n this.segCount -= drop;\n this.rebuild();\n }\n\n private push(idx: number, t: number): void {\n if (this.segCount === SEGMENTS) {\n if (MANNER[this.segIdx[0]] === M_VOWEL) this.droppedVowel = true;\n this.segIdx.copyWithin(0, 1);\n this.segT0.copyWithin(0, 1);\n this.segCount--;\n }\n let at = this.segCount;\n while (at > 0 && this.segT0[at - 1] > t) at--;\n for (let s = this.segCount; s > at; s--) {\n this.segIdx[s] = this.segIdx[s - 1];\n this.segT0[s] = this.segT0[s - 1];\n }\n this.segIdx[at] = idx;\n this.segT0[at] = t;\n this.segCount++;\n }\n\n private t1(s: number): number {\n return s + 1 < this.segCount ? this.segT0[s + 1] : this.end;\n }\n\n /** The segment sounding at time t (the last to start at or before it), or -1. */\n segmentAt(t: number): number {\n let cur = -1;\n for (let s = 0; s < this.segCount; s++) {\n if (this.segT0[s] <= t) cur = s;\n else break;\n }\n return cur;\n }\n\n /** Phoneme of segment s. */\n phonemeOf(s: number): number {\n return this.segIdx[s];\n }\n\n /** The vowel sounding at t or the next one, as a table phoneme, or -1. */\n vowelAt(t: number): number {\n for (let s = 0; s < this.segCount; s++) {\n if (MANNER[this.segIdx[s]] === M_VOWEL && this.t1(s) > t) return this.segIdx[s];\n }\n return -1;\n }\n\n /** Whether the segment at t (or the first, before it) is a beat. */\n beatAt(t: number): boolean {\n const s = this.segmentAt(t);\n const i = s >= 0 ? s : this.segCount > 0 ? 0 : -1;\n return i >= 0 && MANNER[this.segIdx[i]] === M_BEAT;\n }\n\n /** Whether the segment at t is silence (the breath stops). */\n silentAt(t: number): boolean {\n const s = this.segmentAt(t);\n return s >= 0 && MANNER[this.segIdx[s]] === M_SILENCE;\n }\n\n /**\n * At the time in `at`: whether the breath stops (`silent`, 0 or 1) and\n * the vowel sounding or next (`vowel`, -1 for none). The audio path's\n * form of silentAt and vowelAt.\n */\n queryNow(): void {\n const t = this.at;\n let cur = -1;\n let vowel = -1;\n for (let s = 0; s < this.segCount; s++) {\n const r = this.segT0[s];\n const idx = this.segIdx[s];\n if (r <= t) cur = s;\n // t1(s) written out: a returned double crossing a call is boxed when V8 does not inline it\n const end = s + 1 < this.segCount ? this.segT0[s + 1] : this.end;\n if (vowel < 0 && MANNER[idx] === M_VOWEL && end > t) vowel = idx;\n }\n this.silent = cur >= 0 && MANNER[this.segIdx[cur]] === M_SILENCE ? 1 : 0;\n this.vowel = vowel;\n }\n\n /* ---------------------------------------------------------------- */\n /* Building gestures */\n /* ---------------------------------------------------------------- */\n\n begin(): void {\n this.nTmp = 0;\n }\n\n key(k: number, v: number): void {\n if (v !== v) return;\n this.kTmp[this.nTmp] = k;\n this.vTmp[this.nTmp] = v;\n this.nTmp++;\n }\n\n emit(t0: number, t1: number, ri: number, ro: number, str: number, speed: number): number {\n if (this.nTmp === 0 || this.gCount === GESTURES) return -1;\n const g = this.gCount++;\n this.gT0[g] = t0;\n this.gT1[g] = t1;\n this.gRi[g] = ri;\n this.gRo[g] = ro;\n this.gStr[g] = str;\n this.gSpeed[g] = speed;\n this.gHold[g] = 0;\n this.gRet[g] = 0;\n this.gRank[g] = -1;\n const n = this.nTmp < GESTURE_KEYS ? this.nTmp : GESTURE_KEYS;\n this.gKeyCount[g] = n;\n let lo = Infinity;\n let hi = -Infinity;\n for (let q = 0; q < n; q++) {\n const k = this.kTmp[q];\n this.gKeys[g * GESTURE_KEYS + q] = k;\n this.gVals[g * GESTURE_KEYS + q] = this.vTmp[q];\n // the cascade passes half way CASCADE_LAG of a 98 percent time later than CHIMERA's tracker did:\n // each articulator sees the gesture that much ahead, at the gesture's speed\n const lead = k < ARTICULATORS ? (CASCADE_LAG * CRITDAMP_SETTLE_98) / (2 * Math.PI * VOCAL_ARTICULATOR_HZ[k] * (speed > 0 ? speed : 1)) : 0;\n this.gLead[g * GESTURE_KEYS + q] = lead;\n if (lead < lo) lo = lead;\n if (lead > hi) hi = lead;\n }\n this.gLeadMin[g] = lo;\n this.gLeadMax[g] = hi;\n this.nTmp = 0;\n return g;\n }\n\n /** A consonant's oral gestures from its targets row (planner.rs:292-321, 532-577), returning at speed `ret`. */\n private oral(idx: number, row: number, a: number, b: number, speed: number, ret: number): void {\n const T = this.consT;\n const dom = DOMINANT[idx];\n const bodyOnly = BODY_ONLY[idx] === 1;\n const sp = bodyOnly ? 1 + (speed - 1) * 0.35 : speed;\n const m = MANNER[idx];\n const closing = m === M_STOP || m === M_NASAL || m === M_AFFRICATE;\n const lipsOnly = LIPS_ONLY[idx] === 1;\n const lead = closing ? (bodyOnly ? 0.039 : lipsOnly ? 0.025 : 0.024) : 0;\n const early = closing ? (bodyOnly ? 0.024 : lipsOnly ? 0.022 : 0.031) : 0.008;\n this.begin();\n const bilabial = closing && RANK[idx] === 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k)) this.key(k, bilabial && k === ART.lipAp ? LIP_VIRTUAL : T[row + k]);\n const g = this.emit(a - early, Math.max(a + 0.01, b - lead), 0.03, bodyOnly ? 0.03 : 0.018, 40, sp);\n if (g >= 0) {\n // the return gesture: the release at the consonant's own speed for a whole movement, whatever follows\n const rs = bodyOnly ? 1 + (ret - 1) * 0.35 : ret;\n let hz = 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k) && VOCAL_ARTICULATOR_HZ[k] > hz) hz = VOCAL_ARTICULATOR_HZ[k];\n this.gRet[g] = rs;\n this.gHold[g] = CRITDAMP_SETTLE_98 / (2 * Math.PI * (hz > 0 ? hz : 10) * rs);\n this.gRank[g] = (closing ? 0 : 16) + (RANK[idx] >= 0 ? RANK[idx] : 0);\n }\n const tbXSet = T[row + ART.tbX] === T[row + ART.tbX];\n const alveolar = ALVEOLAR[idx] === 1 && !tbXSet && (closing || m === M_FRICATIVE || m === M_TAP);\n if (alveolar) {\n this.begin();\n this.key(ART.tbX, 3.2);\n this.key(ART.tbY, 7.4);\n this.emit(a, b, 0.05, 0.05, 1.2, 0);\n }\n this.begin();\n let place = NaN;\n for (let k = 0; k < ARTICULATORS; k++) {\n if (dom & (1 << k)) continue;\n const v = T[row + k];\n if (v !== v) continue;\n if (bodyOnly && k === ART.tbX) place = v;\n else this.key(k, v);\n }\n this.emit(a, b, 0.05, 0.05, 2.2, 0);\n if (place === place) {\n this.begin();\n this.key(ART.tbX, place);\n this.emit(a, b, 0.05, 0.05, 0.25, 0);\n }\n }\n\n /** Rebuild every gesture from the segments (event rate). */\n private rebuild(): void {\n this.gCount = 0;\n const n = this.segCount;\n // vowels: Ohman overlap ramps (planner.rs:88-108)\n let prevVowel = -1;\n for (let s = 0; s < n; s++) {\n const idx = this.segIdx[s];\n if (MANNER[idx] !== M_VOWEL) continue;\n const t0 = this.segT0[s];\n const t1 = this.t1(s);\n let next = -1;\n for (let q = s + 1; q < n; q++) {\n if (MANNER[this.segIdx[q]] === M_VOWEL) {\n next = q;\n break;\n }\n }\n const prevEnd = prevVowel >= 0 ? this.t1(prevVowel) : t0 - 0.08;\n const ri = Math.max(0.03, 0.75 * (t0 - prevEnd)) + 0.01;\n const ro = next >= 0 ? Math.max(0.03, 0.4 * (this.segT0[next] - t1)) + 0.01 : 0.042;\n const row = idx * ARTICULATORS;\n this.begin();\n for (let k = 0; k < ARTICULATORS; k++) this.key(k, this.vowelT[row + k]);\n this.emit(t0, t1, ri, ro, 1, 0);\n prevVowel = s;\n }\n let firstVowel = n;\n if (!this.droppedVowel) {\n for (let s = 0; s < n; s++) {\n if (MANNER[this.segIdx[s]] === M_VOWEL) {\n firstVowel = s;\n break;\n }\n }\n } else firstVowel = -1;\n for (let s = 0; s < n; s++) {\n const idx = this.segIdx[s];\n const m = MANNER[idx];\n if (m === M_VOWEL || m === M_SILENCE) continue;\n if (m === M_BEAT) {\n const t1b = this.t1(s);\n writeBeatScore(this, idx - COUNT, this.segT0[s], t1b < Infinity ? t1b - this.segT0[s] : 0.25, s === 0);\n continue;\n }\n const before = this.gCount;\n const t0 = this.segT0[s];\n const t1 = this.t1(s);\n const dur = t1 - t0;\n const row = idx * ARTICULATORS;\n if (m === M_STOP) {\n // a stop closing behind another stop's closure, already placed, aims 25 ms later (planner.rs:299)\n let placed = false;\n if (s > 1) {\n const p = this.segIdx[s - 1];\n const bb = this.segIdx[s - 2];\n if (MANNER[p] === M_STOP && RANK[p] >= 0 && RANK[p] < RANK[idx]) {\n placed = true;\n const dom = DOMINANT[idx];\n for (let k = 0; k < ARTICULATORS; k++) {\n const v = this.consT[bb * ARTICULATORS + k];\n if (dom & (1 << k) && v !== v) placed = false;\n }\n }\n }\n this.oral(idx, row, placed ? t0 + Math.min(0.025, Math.max(0, dur - 0.03)) : t0, t1, 1.55, RETURN_SPEED[idx]);\n if (VOICED[idx] === 1) {\n // a voiced stop's glottis parts a little through the closure: air keeps flowing in behind the\n // seal, so a tongue moving toward the next\n // sound cannot draw the mouth below the atmosphere and pop on release (MEASURED: /\u0279dj/ in\n // \"Harvard Yard\" fell to -9.7 cmH2O and clicked). VOICED_ABDUCTION is INFERRED, gated on the\n // release and on the voice bar (test/engines-physical/anatomy.test.ts)\n this.begin();\n this.key(KEY_ABDUCTION, VOICED_ABDUCTION);\n this.emit(t0 + 0.2 * dur, t1, 0.02, 0.03, 4, 0);\n }\n } else if (m === M_NASAL) this.oral(idx, row, t0, t1, 1.55, RETURN_SPEED[idx]);\n else if (m === M_TAP) this.oral(idx, row, t0, t1, 2.8, RETURN_SPEED[idx]);\n else if (m === M_AFFRICATE) {\n const split = t0 + dur * 0.55;\n this.oral(idx, row, t0, split, 2.0, RETURN_SPEED[idx]);\n const rel = RELEASE[idx];\n // the release part ends as its fricative does\n if (rel >= 0) this.oral(idx, rel * ARTICULATORS, split + 0.008, t1, 1.4, RETURN_SPEED[rel]);\n } else if (m === M_FRICATIVE || m === M_APPROXIMANT || m === M_LATERAL) this.oral(idx, row, t0, t1, 1.3, RETURN_SPEED[idx]);\n if (NASAL[idx]) {\n this.begin();\n this.key(ART.velum, 0.45);\n this.emit(t0 - 0.02, t1 - 0.02, 0.05, 0.03, 4, 0);\n }\n // phonation (planner.rs:329-358)\n const gl = GLOTTAL[idx];\n this.begin();\n if (gl === 1) {\n this.key(KEY_ABDUCTION, 0.33);\n this.emit(t0 - 0.01, t1, 0.03, 0.035, 5, 0);\n } else if (gl === 2) {\n this.key(KEY_CLOSURE, 1);\n this.emit(t0, t1, 0.012, 0.015, 8, 0);\n } else if (gl === 3) {\n this.key(KEY_ABDUCTION, 0.1);\n this.emit(t0, t1, 0.03, 0.03, 5, 0);\n } else if (VOICED[idx] === 0) {\n if (m === M_STOP || m === M_AFFRICATE) {\n const nextVowel = s + 1 < n && MANNER[this.segIdx[s + 1]] === M_VOWEL;\n const afterS = s > 0 && VOCAL_TABLE_PHONEMES[this.segIdx[s - 1]] === 's';\n const aspirated = nextVowel && !afterS;\n this.key(KEY_ABDUCTION, aspirated ? 0.36 : 0.22);\n // an aspirated release holds the glottis open for the stop's VOT (Lisker and Abramson 1964:\n // p 58, t 70, k 80 ms; src/sing.ts releases that much before the beat) less the 50 ms the\n // abduction's ramp out and the voicing gate add (MEASURED), at least CHIMERA's 20 ms\n const hold = aspirated ? Math.max(0.02, STOP_VOT[idx] - 0.05) : 0.0048;\n this.emit(t0 + 0.25 * dur, t1 + hold, 0.035, aspirated ? 0.045 : 0.02, 6, 0);\n this.stiffen(t0 + 0.25 * dur, t1 + hold + (aspirated ? 0.045 : 0.02));\n } else {\n this.key(KEY_ABDUCTION, 0.3);\n this.emit(t0 - 0.015, t1 + 0.005, 0.03, 0.03, 6, 0);\n this.stiffen(t0 - 0.015, t1 + 0.035);\n }\n } else if (m === M_FRICATIVE) {\n this.key(KEY_ABDUCTION, 0.035);\n this.emit(t0, t1, 0.03, 0.03, 3, 0);\n }\n if (s === 0 && s < firstVowel) {\n for (let g = before; g < this.gCount; g++) {\n const kc = this.gKeyCount[g];\n let glottal = false;\n for (let q = 0; q < kc; q++) if (this.gKeys[g * GESTURE_KEYS + q] >= KEY_ABDUCTION) glottal = true;\n if (glottal) continue;\n this.gT0[g] -= INITIAL_LEAD;\n this.gRi[g] += 0.5 * INITIAL_LEAD;\n }\n }\n }\n // the end of the breath group (planner.rs:383-389)\n if (this.end < Infinity) {\n const last = n > 0 ? this.segIdx[n - 1] : 0;\n const m = MANNER[last];\n const sonorant = m === M_VOWEL || m === M_NASAL || m === M_APPROXIMANT || m === M_LATERAL || m === M_TAP;\n this.begin();\n this.key(KEY_ABDUCTION, 0.22);\n this.emit(this.end + (sonorant ? 0.045 : 0.015), this.end + 0.1, 0.03, 0.06, 6, 0);\n }\n }\n\n /* ---------------------------------------------------------------- */\n /* Control rate */\n /* ---------------------------------------------------------------- */\n\n /**\n * Targets and speeds at time t, with the tip's rest position (when no\n * gesture holds the tip) given by the caller from the current jaw and\n * tongue body.\n */\n evaluate(t: number, restTipX: number, restTipY: number): void {\n this.at = t;\n this.restX = restTipX;\n this.restY = restTipY;\n this.evaluateNow();\n }\n\n /**\n * evaluate() at the time and rest tip in the fields `at`, `restX` and\n * `restY`: the audio path's form, so no double crosses the call.\n */\n evaluateNow(): void {\n const t = this.at;\n const restTipX = this.restX;\n const restTipY = this.restY;\n const wsum = this.wsum;\n const vsum = this.vsum;\n const speed = this.speed;\n const rankA = this.rankA;\n const rankR = this.rankR;\n const speedA = this.speedA;\n const speedR = this.speedR;\n wsum.fill(0);\n vsum.fill(0);\n const held = this.held;\n held.fill(0);\n const rankF = this.rankF;\n rankA.fill(NO_RANK);\n rankF.fill(NO_RANK);\n rankR.fill(NO_RANK);\n speedA.fill(1);\n speedR.fill(1);\n // which consonants hold each articulator: approaching (from the ramp's start to t1; fully from t0)\n // or returning (from t1, over the ramp out and the return). When two compete, a closure wins over\n // any other constriction, then the more anterior place\n for (let g = 0; g < this.gCount; g++) {\n const rank = this.gRank[g];\n if (rank < 0) continue;\n const lo = this.gT0[g] - this.gRi[g];\n const t1 = this.gT1[g];\n const last = t1 + this.gRo[g] + this.gHold[g];\n if (t + this.gLeadMax[g] <= lo || t + this.gLeadMin[g] > last) continue;\n const kc = this.gKeyCount[g];\n const base = g * GESTURE_KEYS;\n for (let q = 0; q < kc; q++) {\n const tg = t + this.gLead[base + q];\n if (tg <= lo || tg > last) continue;\n const approach = tg < t1;\n const sp = approach ? this.gSpeed[g] : this.gRet[g];\n const k = this.gKeys[base + q];\n if (approach) {\n if (rank < rankA[k] || (rank === rankA[k] && sp > speedA[k])) {\n rankA[k] = rank;\n speedA[k] = sp;\n }\n if (tg >= this.gT0[g] && rank < rankF[k]) rankF[k] = rank;\n } else if (rank < rankR[k] || (rank === rankR[k] && sp > speedR[k])) {\n rankR[k] = rank;\n speedR[k] = sp;\n }\n }\n }\n for (let i = 0; i < ARTICULATORS; i++) speed[i] = rankA[i] !== NO_RANK ? speedA[i] : rankR[i] !== NO_RANK ? speedR[i] : 1;\n for (let g = 0; g < this.gCount; g++) {\n const lo = this.gT0[g] - this.gRi[g];\n const t0 = this.gT0[g];\n const t1 = this.gT1[g];\n const ri = this.gRi[g] > 1e-6 ? this.gRi[g] : 1e-6;\n const ro = this.gRo[g];\n if (t + this.gLeadMax[g] <= lo || t + this.gLeadMin[g] >= t1 + ro) continue;\n const str = this.gStr[g];\n const rank = this.gRank[g];\n const kc = this.gKeyCount[g];\n const base = g * GESTURE_KEYS;\n // every key between the ramps: whole, with no cosine\n const whole = t + this.gLeadMin[g] >= t0 && t + this.gLeadMax[g] <= t1;\n for (let q = 0; q < kc; q++) {\n const tg = t + this.gLead[base + q];\n if (tg <= lo || tg >= t1 + ro) continue;\n const k = this.gKeys[base + q];\n // a consonant that outranks this one, fully under way on the same articulator, takes it\n if (rank >= 0 && tg < t1 && k < ARTICULATORS && rank > rankF[k]) continue;\n let act = 1;\n if (whole) {\n // act stays 1\n } else if (tg < t0) act = 0.5 - 0.5 * Math.cos((Math.PI * (tg - lo)) / ri);\n else if (tg > t1) act = 0.5 + 0.5 * Math.cos((Math.PI * (tg - t1)) / (ro > 1e-6 ? ro : 1e-6));\n const w = act * str;\n wsum[k] += w;\n vsum[k] += w * this.gVals[base + q];\n if (rank >= 0 && k < ARTICULATORS && act > held[k]) held[k] = act;\n // and the velum for any consonant (a beat's rank 30 aside): a nasal setting must not leak an\n // obstruent's pressure through the nose (MEASURED, 0.6.0: /p/ kept 24 percent of its pressure)\n if (rank >= 0 && rank < 30 && act > held[ART.velum]) held[ART.velum] = act;\n }\n }\n const target = this.target;\n for (let i = 0; i < ARTICULATORS; i++) {\n const base = i === ART.ttX ? restTipX : i === ART.ttY ? restTipY : NEUTRAL[i];\n let tgt = base;\n if (wsum[i] > 0) {\n if (i === ART.velum) tgt = base + Math.min(1, wsum[i] / 2) * (vsum[i] / wsum[i] - base);\n else tgt = (base * BASE_WEIGHT + vsum[i]) / (BASE_WEIGHT + wsum[i]);\n }\n target[i] = tgt;\n }\n const wa = wsum[KEY_ABDUCTION];\n this.abduction = wa > 0 ? (vsum[KEY_ABDUCTION] / wa) * Math.min(1, wa / 2) : 0;\n const wc = wsum[KEY_CLOSURE];\n this.closure = wc > 0 ? (vsum[KEY_CLOSURE] / wc) * Math.min(1, wc / 2) : 0;\n const ws = wsum[KEY_STIFFNESS];\n this.stiffness = ws > 0 ? (vsum[KEY_STIFFNESS] / ws) * Math.min(1, ws) : 0;\n // the breath: a beat line rests it at 0 (the beatboxer breathes only into a sound), speech at 1\n let cur = -1;\n for (let s = 0; s < this.segCount; s++) {\n if (this.segT0[s] <= t) cur = s;\n else break;\n }\n if (cur < 0 && this.segCount > 0) cur = 0;\n const inBeat = cur >= 0 && MANNER[this.segIdx[cur]] === M_BEAT;\n this.beat = inBeat ? 1 : 0;\n const rest = inBeat ? 0 : 1;\n const wb = wsum[KEY_BREATH];\n this.breath = wb > 0 ? (rest * BASE_WEIGHT + vsum[KEY_BREATH]) / (BASE_WEIGHT + wb) : rest;\n }\n\n /* ---------------------------------------------------------------- */\n /* Beats (engines/vocal-beats.ts) */\n /* ---------------------------------------------------------------- */\n\n /**\n * A consonant's oral gestures for a beat, from table phoneme `idx`'s targets with up to two\n * overrides (k1, v1 and k2, v2; -1 for none). `snap` > 0 releases at that speed over `snapRo`\n * (beatboxers snap their releases, the heavy dorsum too); `after` (not NaN) shortens every ramp\n * in, for a release fricative that must not pry the closure open early; `fric` makes a stop's\n * place a fricative ([x] from /k/); `noFront` leaves out the tongue body's alveolar fronting.\n */\n beatOral(\n idx: number,\n a: number,\n b: number,\n speed: number,\n snap: number,\n snapRo: number,\n after: number,\n fric: boolean,\n k1: number,\n v1: number,\n k2: number,\n v2: number,\n noFront: boolean,\n ): void {\n const src = this.consT;\n const row = idx * ARTICULATORS;\n const T = this.beatT;\n for (let k = 0; k < ARTICULATORS; k++) T[k] = k === k1 ? v1 : k === k2 ? v2 : src[row + k];\n const dom = DOMINANT[idx];\n const bodyOnly = BODY_ONLY[idx] === 1;\n const m = MANNER[idx];\n const closing = !fric && (m === M_STOP || m === M_NASAL || m === M_AFFRICATE);\n const lipsOnly = LIPS_ONLY[idx] === 1;\n const lead = closing ? (bodyOnly ? 0.039 : lipsOnly ? 0.025 : 0.024) : 0;\n const early = closing ? (bodyOnly ? 0.024 : lipsOnly ? 0.022 : 0.031) : 0.008;\n const ri = after === after ? Math.min(0.03, after) : 0.03;\n const sp = snap > 0 ? snap : bodyOnly ? 1 + (speed - 1) * 0.35 : speed;\n this.begin();\n const bilabial = closing && RANK[idx] === 0;\n for (let k = 0; k < ARTICULATORS; k++) {\n if (!(dom & (1 << k))) continue;\n this.key(k, bilabial && k === ART.lipAp && k1 !== ART.lipAp ? LIP_VIRTUAL : T[k]);\n }\n const ro = snap > 0 ? snapRo : bodyOnly ? 0.03 : 0.018;\n const g = this.emit(a - early, Math.max(a + 0.01, b - lead), ri, ro, 40, sp);\n if (g >= 0) {\n const rs = snap > 0 ? snap : RETURN_SPEED[idx];\n let hz = 0;\n for (let k = 0; k < ARTICULATORS; k++) if (dom & (1 << k) && VOCAL_ARTICULATOR_HZ[k] > hz) hz = VOCAL_ARTICULATOR_HZ[k];\n this.gRet[g] = rs;\n this.gHold[g] = CRITDAMP_SETTLE_98 / (2 * Math.PI * (hz > 0 ? hz : 10) * rs);\n this.gRank[g] = (closing ? 0 : 16) + (RANK[idx] >= 0 ? RANK[idx] : 0);\n }\n const tbXSet = T[ART.tbX] === T[ART.tbX];\n if (!noFront && ALVEOLAR[idx] === 1 && !tbXSet) {\n this.begin();\n this.key(ART.tbX, 3.2);\n this.key(ART.tbY, 7.4);\n this.emit(a, b, Math.min(0.05, ri + 0.02), 0.05, 1.2, 0);\n }\n this.begin();\n for (let k = 0; k < ARTICULATORS; k++) {\n if (dom & (1 << k)) continue;\n if (noFront && (k === ART.tbX || k === ART.tbY)) continue;\n const v = T[k];\n if (v === v) this.key(k, v);\n }\n this.emit(a, b, Math.min(0.05, ri + 0.02), 0.05, 2.2, 0);\n }\n\n /** Give gesture g a consonant's rank, so its speed governs its articulators coming and going (the beat scores). */\n rank(g: number, speed: number): void {\n this.gRank[g] = 30;\n this.gRet[g] = speed;\n this.gHold[g] = 0.02;\n }\n\n /** Schwa's target for articulator a at this body: the beat scores' ready posture. */\n schwaTarget(a: number): number {\n return this.vowelT[P_SCHWA * ARTICULATORS + a];\n }\n\n /** A cricothyroid stiffness gesture from t0, full until t1, ramping out over STIFF_RELEASE. */\n private stiffen(t0: number, t1: number): void {\n this.begin();\n this.key(KEY_STIFFNESS, 1);\n this.emit(t0, t1, 0.03, STIFF_RELEASE, 1, 0);\n }\n}\n\n/**\n * Each articulator's rate, 1 / tau of its six-stage cascade (dsp/cascade.ts),\n * per second: CHIMERA's natural frequencies (control/articulators.rs:23)\n * with the 98 percent time kept, t98 = 5.834 / w = 12.03 tau.\n */\nexport const ARTICULATOR_RATE = Float64Array.from(VOCAL_ARTICULATOR_HZ, (hz) => (2 * Math.PI * hz * CASCADE_SETTLE_98) / CRITDAMP_SETTLE_98);\n/**\n * How much later, as a fraction of the 98 percent time, the cascade passes\n * half way than CHIMERA's critically damped tracker with the same 98\n * percent time (0.471 against 0.288 of it). Gestures are evaluated this\n * much ahead so the sounds keep their times.\n */\nexport const CASCADE_LAG = cascadeSettle(CASCADE_ORDER, 0.5) / CASCADE_SETTLE_98 - cascadeSettle(2, 0.5) / CRITDAMP_SETTLE_98;\n/**\n * Each consonant's return (release) speed, a factor on its articulators'\n * rates like the approach speeds, after VocalTractLab 2.4's return\n * gestures (manual section 6.1): it governs the whole release movement, one\n * 98 percent time long, whatever vowel follows (CHIMERA held a consonant's\n * speed 45 ms past its ramp out and left the rest of the release to the\n * vowel's rate). Stops and nasals 1.55, an affricate's closure 2.0, the tap\n * 2.8, the rest 1.3: each its approach speed, which MEASURED keeps the\n * vowels' arrival (a glide released at 1 landed its vowel 8 ms later).\n */\nconst RETURN_SPEED = Float64Array.from(VOCAL_INVENTORY, (d) =>\n d.manner === 'stop' || d.manner === 'nasal' ? 1.55 : d.manner === 'tap' ? 2.8 : d.manner === 'affricate' ? 2.0 : 1.3,\n);\n/** Each table phoneme's VOT, s (0 for all but stops), from engines/vocal-phonemes.ts. */\nconst STOP_VOT = Float64Array.from(VOCAL_TABLE_PHONEMES, (ipa) => {\n const i = vocalPhonemeIndex(ipa);\n return i >= 0 ? VOCAL_ACOUSTICS[i].vot : 0;\n});\n/** The rest posture as doubles in a typed array (a plain array of mixed literals can box its reads). */\nconst NEUTRAL = Float64Array.from(VOCAL_NEUTRAL);\n/** Each articulator's range. */\nexport const ARTICULATOR_MIN = Float64Array.from(VOCAL_ARTICULATOR_MIN);\nexport const ARTICULATOR_MAX = Float64Array.from(VOCAL_ARTICULATOR_MAX);\n/**\n * The lips stop closing here (template cm of aperture, scaled by k in the\n * geometry): CHIMERA's closure target, the most the lips are compressed.\n */\nexport const LIP_COMPRESSED = -0.25;\n/**\n * A bilabial closure's virtual target, past LIP_COMPRESSED: the lips meet\n * moving near their fastest and compress (Lofqvist and Gracco 1997), and\n * the contact holds them while their motion carries on toward it.\n */\nexport const LIP_VIRTUAL = -1.0;\n/** The lowest target each articulator may be given: its range, but the lips may aim at LIP_VIRTUAL. */\nexport const ARTICULATOR_TARGET_MIN = Float64Array.from(VOCAL_ARTICULATOR_MIN, (v, i) => (i === ART.lipAp ? Math.min(v, LIP_VIRTUAL) : v));\n\n/** CHIMERA's rest tip for a jaw and tongue body (articulators.rs:110, anatomy/human.rs:443), into out[0], out[1]. */\n/** restTip() of the jaw and tongue body in an articulator array a: no double crosses the call. */\nexport function restTipFrom(a: Float64Array, out: Float64Array): void {\n const ang = -a[ART.jaw] / 9.84;\n const c = Math.cos(ang);\n const s = Math.sin(ang);\n out[0] = -2.5 + 8.95 * c + 3.15 * s + 0.3 * (a[ART.tbX] - 2.9);\n out[1] = 10.5 + 8.95 * s - 3.15 * c + 0.35 * (a[ART.tbY] - 6.85);\n}\n\nexport function restTip(jaw: number, tbX: number, tbY: number, out: Float64Array): void {\n const cx = -2.5;\n const cy = 10.5;\n const ang = -jaw / 9.84;\n const dx = 6.45 - cx;\n const dy = 7.35 - cy;\n const c = Math.cos(ang);\n const s = Math.sin(ang);\n out[0] = cx + dx * c - dy * s + 0.3 * (tbX - 2.9);\n out[1] = cy + dx * s + dy * c + 0.35 * (tbY - 6.85);\n}\n", "/*\n * One body's roof of the mouth (the velum from the uvula tip, then the hard\n * palate to the incisors) and the projections onto it that the voice's\n * contact rule uses: a tongue tip or body that presses more than 0.1 k cm\n * into the roof is pushed back along the contact normal (CHIMERA\n * human_voice.rs:520-552). Evaluated at every articulator step, so it is a\n * fixed polyline, not the full geometry.\n *\n * Learned from CHIMERA by Jameson Hodge (MIT,\n * https://github.com/jamesondh/chimera-vocal-synth at 1d3ea49): the roof\n * polylines (extracted from anatomy/human.rs), the template-to-body\n * transform (human.rs:685) and the rule that keeps the tip outside the\n * tongue body (human.rs:828). Reimplemented here; see THIRD_PARTY_NOTICES.md.\n * Nothing here allocates after construction.\n */\n\nimport { ART } from './vocal-articulators';\nimport type { VocalBodyTable } from './vocal-tables.gen';\n\nexport class VocalRoof {\n readonly k: number = 0;\n readonly pharynxScale: number = 0;\n /** Tongue body radius, body cm. */\n readonly r: number = 0;\n private readonly roofX: Float64Array;\n private readonly roofY: Float64Array;\n /* project()'s input point and its results: the signed distance and the nearest roof point. */\n x = 0;\n y = 0;\n sd = 0;\n qx = 0;\n qy = 0;\n /* The tongue body's centre of the last bodyPoint(). */\n bx = 0;\n by = 0;\n /* The tip point of the last tipPoint(). */\n tipX = 0;\n tipY = 0;\n\n constructor(t: VocalBodyTable) {\n this.k = t.k;\n this.pharynxScale = t.pharynxScale;\n this.r = t.tongueRadius * t.k;\n this.roofX = Float64Array.from(t.roofX);\n this.roofY = Float64Array.from(t.roofY);\n }\n\n /** Template to body coordinates (human.rs:685). */\n px(x: number): number {\n return (x > 0.5 ? 0.5 + (x - 0.5) * 0.86 : x) * this.k;\n }\n py(y: number): number {\n return (y < 7 ? 7 - (7 - y) * this.pharynxScale : y) * this.k;\n }\n /** d(body x) / d(template x) and likewise for y, at a template point. */\n sx(x: number): number {\n return (x > 0.5 ? 0.86 : 1) * this.k;\n }\n sy(y: number): number {\n return (y < 7 ? this.pharynxScale : 1) * this.k;\n }\n\n /**\n * The signed distance from (x, y) (the fields) to the roof, positive below\n * it (in the airway), into sd, and the nearest roof point into qx, qy.\n * Inputs and results are fields, so no double crosses the call.\n */\n project(): void {\n const x = this.x;\n const y = this.y;\n let best = Infinity;\n let sgn = 1;\n const X = this.roofX;\n const Y = this.roofY;\n for (let i = 0; i + 1 < X.length; i++) {\n const ax = X[i];\n const ay = Y[i];\n const ex = X[i + 1] - ax;\n const ey = Y[i + 1] - ay;\n const l2 = ex * ex + ey * ey;\n let t = ((x - ax) * ex + (y - ay) * ey) / l2;\n t = t < 0 ? 0 : t > 1 ? 1 : t;\n const qx = ax + ex * t;\n const qy = ay + ey * t;\n const d = Math.sqrt((x - qx) * (x - qx) + (y - qy) * (y - qy));\n if (d < best) {\n best = d;\n sgn = ex * (y - ay) - ey * (x - ax) < 0 ? 1 : -1;\n this.qx = qx;\n this.qy = qy;\n }\n }\n this.sd = best * sgn;\n }\n\n /** The tongue body's centre in body coordinates, into bx, by. */\n bodyPoint(a: ArrayLike<number>): void {\n const tx = a[ART.tbX];\n const ty = a[ART.tbY];\n this.bx = (tx > 0.5 ? 0.5 + (tx - 0.5) * 0.86 : tx) * this.k;\n this.by = (ty < 7 ? 7 - (7 - ty) * this.pharynxScale : ty) * this.k;\n }\n\n /** The tip point in body coordinates, kept 1.05 r outside the tongue body, into tipX, tipY. */\n tipPoint(a: ArrayLike<number>): void {\n // px() and py() written out, so no double crosses a call\n const k = this.k;\n const ps = this.pharynxScale;\n const ax = a[ART.tbX];\n const ay = a[ART.tbY];\n const cx = a[ART.ttX];\n const cy = a[ART.ttY];\n const bx = (ax > 0.5 ? 0.5 + (ax - 0.5) * 0.86 : ax) * k;\n const by = (ay < 7 ? 7 - (7 - ay) * ps : ay) * k;\n let tx = (cx > 0.5 ? 0.5 + (cx - 0.5) * 0.86 : cx) * k;\n let ty = (cy < 7 ? 7 - (7 - cy) * ps : cy) * k;\n const d = Math.sqrt((tx - bx) * (tx - bx) + (ty - by) * (ty - by));\n if (d < 1.05 * this.r) {\n const s = (1.05 * this.r) / (d > 1e-9 ? d : 1e-9);\n tx = bx + (tx - bx) * s;\n ty = by + (ty - by) * s;\n }\n this.tipX = tx;\n this.tipY = ty;\n }\n}\n", "/*\n * From the tract's shape to the junction airway's inputs. The exact\n * geometry (engines/vocal-geometry.ts) is evaluated about every 10.7 ms, a\n * keyframe; between two keyframes the areas, sub-section minima, lengths,\n * incisors and velum port are interpolated block by block (MEASURED in the\n * geometry's prototype: 100 Hz with interpolation lies 0.05 dB from\n * evaluating every 2.7 ms over all frames, 0.33 dB over consonants, at a\n * quarter of the cost). Each block, the interpolated profile (pharynx then\n * oral sections, glottis to lips) is resampled onto the airway's grid in one\n * sweep:\n *\n * - the back duct takes up whatever the grid does not cover (at least\n * DUCT_MIN), its area the harmonic mean over it;\n * - each grid section's area is the harmonic mean of the profile over it,\n * and its minimum the smallest sub-section minimum of the profile\n * sections it overlaps, never above its own area (CHIMERA's jet rule);\n * - the incisors and the pharynx/oral split become grid positions, and the\n * labiodental articulator tells the airway whether a front constriction\n * is the lower lip's (a labiodental noise source) or the tongue's;\n * - the anatomical moving-wall flow: each profile section's volume change\n * over the block, as -dV/dt at its place on the grid, from the smoothed\n * profile the airway hears. It must not be differenced from grid areas: a\n * grid that slides along the anatomy is not a volume change (MEASURED in\n * the airway's prototype, a spurious 382 cm^3/s at one near-closure).\n * Differenced across the keyframe interval instead, it stepped every\n * 10.7 ms and ran ahead of the smoothed areas, and a tongue leaving the\n * roof pumped a sealed closure at 80 to 500 Hz.\n *\n * CHIMERA's area rate law (human_airway.rs:190-262) limits each keyframe's\n * sections against the last, as CHIMERA limits its own. Learned from\n * CHIMERA by Jameson Hodge (MIT, https://github.com/jamesondh/chimera-vocal-synth\n * at 1d3ea49); see THIRD_PARTY_NOTICES.md. Nothing here allocates after\n * construction, and no double crosses a call: the airway's inputs are its\n * fields.\n */\n\nimport { SOUND_SPEED } from '../dsp/air';\nimport { AreaSlew } from '../dsp/area-rate';\nimport { ductMin, type JunctionAirway } from '../dsp/junction-airway';\nimport { ART } from './vocal-articulators';\nimport { ChimeraGeometry } from './vocal-geometry';\n\nconst LABIODENTAL = ART.labiodental;\n\n/** Blocks per keyframe. */\nexport const VOCAL_KEY_BLOCKS = 16;\n/** The profile smoother's natural frequency, Hz (MEASURED choice: smooth release onsets, closures still sealed). */\nconst SMOOTH_HZ = 70;\n/** Most profile sections per tube. */\nconst MAX_TUBE = 40;\n\n/** CHIMERA's section counts for a body of scale k with pharynx factor ph, at its 96 kHz airway (human_airway.rs:75-80). */\nfunction tubeCounts(k: number, ph: number, out: Int32Array): void {\n const dxMin = SOUND_SPEED / 96000 / 0.93;\n const phMin = 8.7 * k * (0.55 + 0.45 * ph) - 1.6 * k;\n const orMin = 8.3 * k - 1.0 * k;\n out[0] = Math.min(MAX_TUBE, Math.max(8, Math.floor(phMin / dxMin)));\n out[1] = Math.min(MAX_TUBE, Math.max(8, Math.floor(orMin / dxMin)));\n}\n\n/** One evaluated shape. */\nclass Key {\n readonly ph = new Float64Array(MAX_TUBE);\n readonly or = new Float64Array(MAX_TUBE);\n readonly phMin = new Float64Array(MAX_TUBE);\n readonly orMin = new Float64Array(MAX_TUBE);\n phLen = 8.8;\n orLen = 8.3;\n teeth = 16;\n velum = 0;\n /** How far the lower lip forms the front constriction (the labiodental articulator, 0..1). */\n lab = 0;\n\n copy(s: Key): void {\n this.ph.set(s.ph);\n this.or.set(s.or);\n this.phMin.set(s.phMin);\n this.orMin.set(s.orMin);\n this.phLen = s.phLen;\n this.orLen = s.orLen;\n this.teeth = s.teeth;\n this.velum = s.velum;\n this.lab = s.lab;\n }\n}\n\nexport class VocalDrive {\n readonly geometry: ChimeraGeometry;\n private readonly prev = new Key();\n private readonly next = new Key();\n private readonly counts = new Int32Array(2);\n private nPh = 18;\n private nOr = 18;\n private readonly slew = new AreaSlew();\n /* The interpolated profile: edges (cm from the glottis), areas, minima, volumes and centres per section. */\n private readonly edge = new Float64Array(2 * MAX_TUBE + 1);\n private readonly prof = new Float64Array(2 * MAX_TUBE);\n private readonly pmin = new Float64Array(2 * MAX_TUBE);\n /*\n * The profile as it is heard: areas and minima through a critically damped two-pole at SMOOTH_HZ,\n * stepped once a block, so a release between two keyframes accelerates as articulators do instead\n * of opening at the area rate law's limit from its first block (MEASURED: a 61 dB step out of the\n * closure at the twinkle /k/, against CHIMERA's 26).\n */\n private readonly sProf = new Float64Array(2 * MAX_TUBE);\n private readonly vProf = new Float64Array(2 * MAX_TUBE);\n private readonly sMin = new Float64Array(2 * MAX_TUBE);\n private readonly vMin = new Float64Array(2 * MAX_TUBE);\n /*\n * The pharynx and oral lengths and the incisors through the same smoother, so the profile moves as\n * one: interpolated straight, a length's slope turned at every keyframe while the areas eased, and\n * the volume's rate (the wall flow) stepped there (MEASURED: 228 cm^3/s in one block at a /t/).\n */\n private readonly lenIn = new Float64Array(3);\n private readonly sLen = new Float64Array(3);\n private readonly vLen = new Float64Array(3);\n private sa = 1;\n private sb = 0;\n private sc = 0;\n private sd = 1;\n private snapped = true;\n /** -dV/dt per profile section over the last block, cm^3/s, and each section's volume then, cm^3. */\n private readonly dvdt = new Float64Array(2 * MAX_TUBE);\n private readonly vol = new Float64Array(2 * MAX_TUBE);\n private keyDt = 0.01;\n private readonly blockDt: number = 0;\n private readonly lbMin: number = 0;\n private readonly dx: number = 0;\n /** Fraction of the keyframe interval toAirway() reads, [0, 1]; a field, so no double crosses the call. */\n u = 0;\n\n constructor(rate: number) {\n this.dx = SOUND_SPEED / (2 * rate);\n this.lbMin = ductMin(rate);\n this.geometry = new ChimeraGeometry({\n scale: 1,\n pharynx: 1,\n tongueRadius: 2.25,\n lipWidth: 4.6,\n });\n const blockDt = Math.max(8, Math.round((32 * rate) / 48000)) / rate;\n this.blockDt = blockDt;\n this.keyDt = VOCAL_KEY_BLOCKS * blockDt;\n this.slew.setStep(this.keyDt);\n // the smoother's exact step over one block: [e', v'] = [[sa, sb], [sc, sd]] [e, v]\n const w = 2 * Math.PI * SMOOTH_HZ;\n const k = Math.exp(-w * blockDt);\n this.sa = (1 + w * blockDt) * k;\n this.sb = blockDt * k;\n this.sc = -w * w * blockDt * k;\n this.sd = (1 - w * blockDt) * k;\n }\n\n /** A body (scale, pharynx, tongue radius, lip width), at a note-on. Allocates nothing. */\n setBody(scale: number, pharynx: number, tongueRadius: number, lipWidth: number): void {\n this.geometry.setBody(scale, pharynx, tongueRadius, lipWidth);\n tubeCounts(scale, pharynx, this.counts);\n this.nPh = this.counts[0];\n this.nOr = this.counts[1];\n this.slew.setScale(scale);\n }\n\n /**\n * A new keyframe from the articulators a (17, CHIMERA's order): the last\n * becomes the start of the interval. snap: both ends are this shape (a\n * note's start), and nothing is rate limited.\n */\n key(a: Float64Array, snap: boolean): void {\n const g = this.geometry;\n const p = this.prev;\n const q = this.next;\n p.copy(q);\n g.evaluate(a);\n const nPh = this.nPh;\n const nOr = this.nOr;\n g.resampleInto(q.ph, q.or, q.phMin, q.orMin, nPh, nOr);\n q.phLen = g.phLen;\n q.orLen = g.orLen;\n q.teeth = g.teethS;\n q.velum = g.velumPort;\n const lab = a[LABIODENTAL];\n q.lab = lab < 0 ? 0 : lab > 1 ? 1 : lab;\n if (snap) {\n p.copy(q);\n this.snapped = true;\n } else {\n this.slew.limitAll(q.ph, p.ph, nPh);\n this.slew.limitAll(q.or, p.or, nOr);\n this.slew.limitAll(q.phMin, p.phMin, nPh);\n this.slew.limitAll(q.orMin, p.orMin, nOr);\n for (let i = 0; i < nPh; i++) if (q.phMin[i] > q.ph[i]) q.phMin[i] = q.ph[i];\n for (let i = 0; i < nOr; i++) if (q.orMin[i] > q.or[i]) q.orMin[i] = q.or[i];\n }\n }\n\n /**\n * The airway's inputs at fraction `u` of the keyframe interval: grid\n * areas and minima, the duct, the velum port, incisors, split and\n * moving-wall flow, written into `air`'s fields.\n */\n toAirway(air: JunctionAirway): void {\n const u = this.u;\n const w0 = 1 - u;\n const p = this.prev;\n const q = this.next;\n const nPh = this.nPh;\n const nOr = this.nOr;\n const c = nPh + nOr;\n const sa = this.sa;\n const sb = this.sb;\n const sc = this.sc;\n const sd = this.sd;\n const fresh = this.snapped;\n const li = this.lenIn;\n const sl = this.sLen;\n const vl = this.vLen;\n li[0] = p.phLen * w0 + q.phLen * u;\n li[1] = p.orLen * w0 + q.orLen * u;\n li[2] = p.teeth * w0 + q.teeth * u;\n for (let i = 0; i < 3; i++) {\n if (fresh) {\n sl[i] = li[i];\n vl[i] = 0;\n } else {\n const e = sl[i] - li[i];\n const v = vl[i];\n sl[i] = li[i] + sa * e + sb * v;\n vl[i] = sc * e + sd * v;\n }\n }\n const phLen = sl[0];\n const orLen = sl[1];\n const edge = this.edge;\n const prof = this.prof;\n const pmin = this.pmin;\n edge[0] = 0;\n for (let i = 0; i < nPh; i++) {\n prof[i] = p.ph[i] * w0 + q.ph[i] * u;\n pmin[i] = p.phMin[i] * w0 + q.phMin[i] * u;\n edge[i + 1] = ((i + 1) * phLen) / nPh;\n }\n for (let i = 0; i < nOr; i++) {\n prof[nPh + i] = p.or[i] * w0 + q.or[i] * u;\n pmin[nPh + i] = p.orMin[i] * w0 + q.orMin[i] * u;\n edge[nPh + i + 1] = phLen + ((i + 1) * orLen) / nOr;\n }\n // the smoother, one block per call\n const sp = this.sProf;\n const vp = this.vProf;\n const sm = this.sMin;\n const vm = this.vMin;\n if (fresh) {\n for (let i = 0; i < c; i++) {\n sp[i] = prof[i];\n sm[i] = pmin[i];\n vp[i] = 0;\n vm[i] = 0;\n }\n this.snapped = false;\n } else {\n for (let i = 0; i < c; i++) {\n let e = sp[i] - prof[i];\n let v = vp[i];\n sp[i] = prof[i] + sa * e + sb * v;\n vp[i] = sc * e + sd * v;\n e = sm[i] - pmin[i];\n v = vm[i];\n sm[i] = pmin[i] + sa * e + sb * v;\n vm[i] = sc * e + sd * v;\n }\n }\n // each section's volume change over the block, -dV/dt, as the areas the airway hears move\n const iDt = 1 / this.blockDt;\n const lPh = phLen / nPh;\n const lOr = orLen / nOr;\n const vol = this.vol;\n const dvdt = this.dvdt;\n for (let i = 0; i < c; i++) {\n const a = sp[i] > 0 ? sp[i] : 0;\n prof[i] = a;\n const m = sm[i] > 0 ? sm[i] : 0;\n pmin[i] = m < a ? m : a;\n const v = a * (i < nPh ? lPh : lOr);\n dvdt[i] = fresh ? 0 : -(v - vol[i]) * iDt;\n vol[i] = v;\n }\n const L = phLen + orLen;\n const n = air.nG;\n let lb = L - n * this.dx;\n if (lb < this.lbMin) lb = this.lbMin;\n const step = (L - lb) / n;\n // the duct: harmonic mean over [0, lb)\n let k = 0;\n {\n let inv = 0;\n while (k < c && edge[k] < lb) {\n const lo = edge[k];\n const hi = edge[k + 1] < lb ? edge[k + 1] : lb;\n if (hi > lo) inv += (hi - lo) / (prof[k] > 1e-6 ? prof[k] : 1e-6);\n if (edge[k + 1] > lb) break;\n k++;\n }\n air.ductLen = lb;\n air.ductArea = inv > 0 ? lb / inv : prof[0];\n }\n // the grid sections, one sweep\n const gridIn = air.gridIn;\n const gridMin = air.gridMin;\n for (let i = 0; i < n; i++) {\n const x0 = lb + i * step;\n const x1 = x0 + step;\n while (k < c - 1 && edge[k + 1] <= x0) k++;\n let inv = 0;\n let mn = Infinity;\n let q2 = k;\n while (q2 < c && edge[q2] < x1) {\n const lo = edge[q2] > x0 ? edge[q2] : x0;\n const hi = edge[q2 + 1] < x1 ? edge[q2 + 1] : x1;\n const a = prof[q2] > 1e-6 ? prof[q2] : 1e-6;\n if (hi > lo) inv += (hi - lo) / a;\n const m = pmin[q2] < a ? pmin[q2] : a;\n if (m < mn) mn = m;\n q2++;\n }\n const ga = inv > 0 ? step / inv : prof[c - 1];\n gridIn[i] = ga;\n gridMin[i] = mn < ga ? mn : ga;\n }\n // incisors and split as grid positions; the velum port\n const teeth = sl[2];\n air.teethX = (teeth - lb) / step;\n air.splitI = (phLen - lb) / step;\n air.velum = p.velum * w0 + q.velum * u;\n air.labial = p.lab * w0 + q.lab * u;\n // the moving-wall flow at each section's place, shared between the two nearest junctions so it\n // moves along the grid continuously as the tract does (snapped to one, it jumped between blocks)\n const vflow = air.vflow;\n for (let j = 0; j <= n; j++) vflow[j] = 0;\n for (let s = 0; s < c; s++) {\n let pos = (0.5 * (edge[s] + edge[s + 1]) - lb) / step;\n pos = pos < 0 ? 0 : pos > n ? n : pos;\n let j = Math.floor(pos);\n if (j >= n) j = n - 1;\n const f = pos - j;\n vflow[j] += (1 - f) * this.dvdt[s];\n vflow[j + 1] += f * this.dvdt[s];\n }\n }\n\n /** The tract length of the current interpolated shape, cm (for layout checks). */\n get length(): number {\n const u = this.u;\n return (this.prev.phLen + this.prev.orLen) * (1 - u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AAK,EAAG,IAAK,EAAG,QAAS,CAAE,EAC5C,CAAE,KAAM,SAAU,IAAK,GAAI,IAAK,EAAG,QAAS,CAAE,EAC9C,CAAE,KAAM,SAAU,IAAK,EAAG,IAAK,EAAG,QAAS,CAAE,EAC7C,CAAE,KAAM,SAAU,IAAK,EAAG,IAAK,EAAG,QAAS,EAAG,KAAM,GAAI,EACxD,CAAE,KAAM,cAAe,IAAK,EAAG,IAAKrB,GAAW,EAAG,QAAS,CAAE,CAC/D,EAEagJ,GAAyB,CACpC,GAAI,QACJ,MAAO,QACP,OAAQjG,GACR,UAAW,EACX,YAAa,CAACV,EAAY4G,EAAY3G,IAAQ,IAAIN,GAAWK,EAAY4G,EAAY3G,CAAG,CAC1F,EDp5BO,SAAS4G,IAAsB,CACpCC,GAAeC,EAAW,CAC5B",
6
+ "names": ["registerEngine", "clamp", "clamp", "CASCADE_ORDER", "cascadeSettle", "order", "fraction", "tail", "u", "term", "sum", "k", "lo", "hi", "it", "mid", "CASCADE_SETTLE_98", "VALUE_LIMIT", "MIN_RATE", "MAX_RATE", "SETTLED", "CascadeBank", "channels", "stepRateHz", "i", "perSecond", "q", "seconds", "t", "target", "value", "v", "src", "at", "n", "b", "targets", "rates", "r", "x", "c", "goal", "base", "g", "big", "s", "j", "m", "Adsr", "CM_H2O", "WALL_TRACT", "WALL_CHEEK_RELAXED", "WALL_TRACHEA", "WALL_NASAL", "RHO_C", "VISC", "TUBE_RING", "MASK", "AirwayTube", "maxNodes", "ns", "m", "invD", "cm", "K", "z1", "g", "secAreas", "count", "nodesAt", "nn", "wall", "perim", "viscF", "dx", "rate", "s", "a0", "a1", "inv", "i", "beta", "hr", "best", "bd", "d", "al", "ar", "pos", "F", "B", "D", "Z", "wCm", "wK", "wIb", "T", "segL", "segR", "a", "b", "wv", "wy", "hist", "sg", "sh", "ue0", "gam", "u", "p", "v", "q", "evenNodes", "n", "inner", "out", "c", "RHO", "branchCoefficients", "M", "f0", "q", "rate", "w0", "wSet", "K", "R", "PIRIFORM_VOLUME", "PIRIFORM_DEPTH", "PIRIFORM_Q", "piriformBranch", "k", "depth", "area", "leff", "SINUS_VOLUME", "SINUS_NECK_AREA", "SINUS_NECK_LENGTH", "SINUS_Q", "sinusBranch", "v", "m", "AreaSlew", "k", "k2", "dt", "a", "u", "next", "prev", "d", "lim", "count", "openR", "sealR", "lo", "span", "ease", "i", "rate", "clamp", "UNIT_GAUSS", "HALF_PI", "S1", "S3", "S5", "S7", "S9", "S11", "S13", "S15", "sinQuarter", "x", "z", "INERTANCE", "INV_INERTANCE", "GAIN", "DRIFT_CONTROL_HZ", "DRIFT_BASE_HZ", "DRIFT_NORM", "MAX_DRIFT_CENTS", "FRY_HZ", "FRY_OQ", "FRY_OFFSET", "FRY_OQ_RATIO", "FRY_PEAK", "CHAOS_RESTART", "CHAOS_START_LO", "CHAOS_START_SPAN", "NO_CORNER", "MIN_HZ", "MAX_HZ_FRACTION", "MAX_JITTER", "pulse", "ph", "oq", "invOq", "skew", "invSkew", "invFall", "sharp", "t", "rising", "s", "s2", "GlottalSource", "sampleRate", "rng", "controlRate", "hz", "src", "i", "v", "r", "f", "cents", "fraction", "amount", "inc", "out", "from", "to", "a", "u", "h", "b", "fry", "amp", "weight", "slope", "end", "ts", "flowSlope", "mu", "alt", "chaosP", "chaosA", "chaos", "dev", "st", "u0", "u1", "q", "gp", "ga", "sc", "g0", "g1", "g2", "gs", "corners", "PI", "INV_PI", "TWO_OVER_PI", "TWO_PI", "GEO_AMPLITUDE", "ROOT_N", "ROOT_V", "ROOT_C", "k", "q", "r", "lo", "hi", "it", "mid", "v", "EDGE", "edgeInto", "a", "b", "x", "f", "cv", "u0", "F0", "GeometricGlottis", "src", "out", "from", "to", "n", "inv", "r1a", "r2a", "cha", "xma", "dr1", "dr2", "dch", "dxm", "twoL", "s", "peak", "rise", "fall", "lag", "d", "dh", "a1", "a2", "i", "w", "xm", "ph", "phi", "s1", "TWO_PI", "ph2", "odd2", "amp2", "s2", "ch", "EDGE", "edgeInto", "CENTS_PER_NEPER", "MAX_RATIO", "FAR_RUN", "PitchServo", "m", "ratio", "lost", "side", "lr", "lp", "same", "a", "b", "cents", "g", "M1", "M2", "K1", "K2", "KC", "ZETA1", "ZETA2", "D1", "D2", "HIT", "HIT_ZETA", "FOLD_F_REF", "MIN_Q", "DEPTH", "TUNE_DEPTH", "VOICED_GAP", "ONSET_S", "MAX_Q", "FoldOscillator", "PitchServo", "rate", "q", "k", "raw", "qk", "qm", "L", "twoL", "r1", "r2", "x1", "x2", "o1", "c1", "f1", "o2", "c2", "f2", "a1", "a2", "ps", "pe", "p1", "p2", "r", "free", "k1", "k2", "kc", "m1", "m2", "dt", "F1", "F2", "bb1", "bb2", "v1", "v2", "ch", "ar", "lv", "t", "period", "swing", "mean", "deep", "THRESHOLD_FLOOR", "THRESHOLD_SLOPE", "CM_H2O", "OFFSET_RATIO", "ONSET_TAU", "OFFSET_TAU", "PhonationThreshold", "dt", "xi", "onset", "p", "d", "target", "c", "GLOTTIS_GEOMETRIC", "GLOTTIS_SELF_OSCILLATING", "GLOTTIS_PULSE", "RHO", "RHOC", "IRHOC", "SRHOC", "VISC", "CLOSED", "OUTPUT_GAIN", "LIN_EPS", "MOVE_REL", "NSRC", "SRC_ASP", "SRC_VEL", "TAPS", "MOD_RING", "G_WALL", "G_OBSTACLE", "G_LABIAL", "G_LIPS", "D_FREE", "G_FREE", "GAIN_SCALE", "G_ASPIRATION", "G_ASPIRATION_VOICED", "ASPIRATION_VOICED_K", "RE_PER_VSA", "RE_LO", "RE_SPAN", "VC_HZ", "VSLOW_HZ", "FC_LINGUAL", "P2_HZ", "CONSTRICTED", "RUN_TOL", "D_WALL_LO", "D_WALL_HI", "D_LABIAL", "WALL_DOWN", "LABIAL_DOWN", "ASPIRATION_AT", "CONVECT", "TAU_MAX", "MOD_MAX", "GLOTTIS_DEPTH", "GLOTTIS_SLIT", "GLOTTIS_KIN", "VELUM_LEN", "VELUM_KIN", "VELUM_EXIT", "OUTPUT_HP", "MIC_R", "MIC_LOW_CUT", "OUTPUT_LP", "DVDT_HZ", "TRACHEA_NODES", "NASAL_NODES", "DUCT_MIN", "WALL_RADIATION", "ductMin", "rate", "dx", "BACK_FREE", "BACK_SPAN", "OPEN_FREE", "OPEN_SPAN", "AREA_BLOCK", "GlottalSource", "JunctionAirway", "GeometricGlottis", "AreaSlew", "TUBE_RING", "nMax", "rng", "nj", "WALL_TRACT", "AirwayTube", "FoldOscillator", "PhonationThreshold", "fc", "K", "q", "norm", "k", "n", "jv", "k2", "sec", "nodes", "nTr", "i", "nn", "evenNodes", "WALL_TRACHEA", "nNa", "u", "a", "extra", "e", "c", "WALL_NASAL", "sb", "sinusBranch", "pc", "piriformBranch", "ch", "split", "m", "WALL_CHEEK_RELAXED", "r", "kk", "first", "blk", "nG", "area", "dArea", "grid", "gmn", "dt", "s", "want", "shut", "nm", "d", "rel", "mt", "dm", "relm", "z", "njm", "sl", "sr", "mv", "al", "ar", "ef", "eb", "cf", "cb", "zl", "zr", "am", "sw", "gw", "gam", "bq", "raw", "j", "to", "a1", "a2", "wv", "tau", "da", "sz", "closure", "st", "c30", "thr", "CM_H2O", "pg", "ag0", "agate", "model", "effort", "dpMean", "paMean", "buf", "inv", "last", "w", "av", "ag", "g", "L", "chink", "rest", "x1", "x2", "th", "p", "GEO_AMPLITUDE", "f", "back", "bc", "bk", "ac", "ab", "per", "on", "VOICED_GAP", "pl", "tapW0", "tapW1", "b", "x", "t", "runLo", "runHi", "conLo", "conHi", "cut", "nr", "mn", "mi", "free", "lim", "lo", "hi", "used", "exit", "best", "bd", "fresh", "cmd", "dk", "lab", "lip", "past", "labio", "lips", "wf", "ob", "v", "wo", "f2", "dObs", "ds", "vo", "ga", "vel", "add", "outL", "outR", "at", "count", "off", "env", "T", "iT", "R", "sZ", "isZ", "Zs", "U", "pn", "kf", "kb", "rv", "viscC", "wallK", "gwA", "wV", "wY", "wS", "moving", "jmList", "gamA", "ibA", "bqA", "dv1", "dv2", "dvc", "aMin", "dAMin", "iaMin", "wIbsA", "wCmA", "wKsA", "pJ", "pG", "pCm", "pK", "pDi", "pQ", "pY", "pP", "fBuf", "bBuf", "tr", "na", "areaBuf", "folds", "selfOsc", "visc0", "ldG", "gain", "micK", "micC", "lungZ", "trLast", "trSegF", "trD", "trZ", "trA", "ring", "tapJ", "cVc", "cVs", "noiseScale", "voi", "vMax", "wallRad", "mm", "isz", "pL", "rp", "nt", "as", "af", "vr", "vf", "rb", "td", "ti", "tf", "vd", "lev", "s3", "mw", "nl1", "nl2", "nl", "sa", "tu", "ls", "dF", "i0", "hm1", "h0", "h1", "h2", "pos", "zt", "p0", "ductSZ", "zb", "ia", "lg", "rg", "exf", "exb", "kin", "kfg", "kbg", "m0", "cc", "pBelow", "pAbove", "ib", "eps", "ws", "hist", "wib", "ph", "d1", "d2", "ue0", "qn", "zd", "rad", "mf", "mh", "o", "hp", "y", "lr", "rr", "ul", "lp", "h", "pOld", "src", "ul2", "ur", "z1", "z2", "z3", "c3", "ue", "kfr", "kbr", "bqr", "cr0", "uv", "ip", "lv", "rvv", "amin", "kfv", "kbv", "bqv", "cv0", "it", "BEAT_ID", "id", "VOCAL_BEATS", "b", "B_KICK", "B_HAT", "B_OPEN_HAT", "B_SNARE", "B_RIM", "B_INWARD", "B_CLICK", "B_POP", "B_CRASH", "B_HUM", "B_CHAT", "B_PSH", "B_IN", "KICK_TBY", "EJECTIVE_PUSH", "BREATH_IN", "BREATH_IN_GLOTTIS", "P_P", "VOCAL_TABLE_PHONEMES", "P_T", "P_K", "P_S", "P_F", "P_SH", "P_M", "writeBeatScore", "w", "slot", "h", "len", "first", "accent", "hum", "k", "ARTICULATORS", "ART", "v", "NaN_", "artic", "ejective", "fric", "end", "blow", "pf", "KEY_ABDUCTION", "KEY_BREATH", "g", "t0", "t1", "ri", "ro", "speed", "at", "KEY_CLOSURE", "level", "abduction", "tail", "KEYS", "ARTICULATORS", "STIFF_RELEASE", "VOCAL_TABLE_SIZE", "VOCAL_TABLE_PHONEMES", "M_SILENCE", "M_VOWEL", "M_STOP", "M_FRICATIVE", "M_AFFRICATE", "M_NASAL", "M_APPROXIMANT", "M_LATERAL", "M_TAP", "M_GLOTTAL", "M_BEAT", "MANNER_CODE", "PLACE_RANK", "COUNT", "VOCAL_BEAT_BASE", "SOUNDS", "VOCAL_SOUND_COUNT", "MANNER", "VOICED", "RANK", "ALVEOLAR", "NASAL", "GLOTTAL", "RELEASE", "DOMINANT", "BODY_ONLY", "LIPS_ONLY", "i", "P_SCHWA", "X_TBY", "VOICED_ABDUCTION", "d", "VOCAL_INVENTORY", "mask", "a", "body", "ART", "lips", "SEGMENTS", "GESTURES", "GESTURE_KEYS", "SAME", "FORGET", "INITIAL_LEAD", "NO_RANK", "BASE_WEIGHT", "VocalPlanner", "COUNT", "ARTICULATORS", "KEYS", "X_TBY", "body", "b", "lo", "w", "A", "VOCAL_BODIES", "B", "p", "a", "idx", "s", "n", "MANNER", "M_BEAT", "t", "drop", "M_VOWEL", "at", "cur", "M_SILENCE", "vowel", "r", "end", "k", "v", "t0", "t1", "ri", "ro", "str", "speed", "g", "hi", "q", "lead", "CASCADE_LAG", "CRITDAMP_SETTLE_98", "VOCAL_ARTICULATOR_HZ", "row", "ret", "T", "dom", "DOMINANT", "bodyOnly", "BODY_ONLY", "sp", "m", "closing", "M_STOP", "M_NASAL", "M_AFFRICATE", "lipsOnly", "LIPS_ONLY", "early", "bilabial", "RANK", "ART", "LIP_VIRTUAL", "rs", "hz", "tbXSet", "ALVEOLAR", "M_FRICATIVE", "M_TAP", "place", "prevVowel", "next", "prevEnd", "firstVowel", "t1b", "writeBeatScore", "before", "dur", "placed", "bb", "RETURN_SPEED", "VOICED", "KEY_ABDUCTION", "VOICED_ABDUCTION", "split", "rel", "RELEASE", "M_APPROXIMANT", "M_LATERAL", "NASAL", "gl", "GLOTTAL", "KEY_CLOSURE", "nextVowel", "afterS", "VOCAL_TABLE_PHONEMES", "aspirated", "hold", "STOP_VOT", "kc", "glottal", "last", "sonorant", "restTipX", "restTipY", "wsum", "vsum", "rankA", "rankR", "speedA", "speedR", "held", "rankF", "rank", "base", "tg", "approach", "i", "whole", "act", "target", "NEUTRAL", "tgt", "wa", "wc", "ws", "KEY_STIFFNESS", "inBeat", "rest", "wb", "KEY_BREATH", "snap", "snapRo", "after", "fric", "k1", "v1", "k2", "v2", "noFront", "src", "P_SCHWA", "STIFF_RELEASE", "ARTICULATOR_RATE", "CASCADE_SETTLE_98", "cascadeSettle", "CASCADE_ORDER", "VOCAL_INVENTORY", "d", "ipa", "vocalPhonemeIndex", "VOCAL_ACOUSTICS", "VOCAL_NEUTRAL", "ARTICULATOR_MIN", "VOCAL_ARTICULATOR_MIN", "ARTICULATOR_MAX", "VOCAL_ARTICULATOR_MAX", "LIP_COMPRESSED", "ARTICULATOR_TARGET_MIN", "restTipFrom", "out", "ang", "c", "VocalRoof", "t", "x", "y", "best", "sgn", "X", "Y", "i", "ax", "ay", "ex", "ey", "l2", "qx", "qy", "d", "a", "tx", "ART", "ty", "k", "ps", "cx", "cy", "bx", "by", "s", "LABIODENTAL", "ART", "VOCAL_KEY_BLOCKS", "SMOOTH_HZ", "MAX_TUBE", "tubeCounts", "k", "ph", "out", "dxMin", "phMin", "orMin", "Key", "VocalDrive", "AreaSlew", "rate", "ductMin", "ChimeraGeometry", "blockDt", "w", "scale", "pharynx", "tongueRadius", "lipWidth", "a", "snap", "g", "p", "q", "nPh", "nOr", "lab", "i", "air", "u", "w0", "c", "sa", "sb", "sc", "sd", "fresh", "li", "sl", "vl", "e", "v", "phLen", "orLen", "edge", "prof", "pmin", "sp", "vp", "sm", "vm", "iDt", "lPh", "lOr", "vol", "dvdt", "m", "L", "n", "lb", "step", "inv", "lo", "hi", "gridIn", "gridMin", "x0", "x1", "mn", "q2", "ga", "teeth", "vflow", "j", "s", "pos", "f", "PHONEMES", "VOCAL_SOUND_COUNT", "OPEN_MAX", "STIFF_CENTS", "STIFF_SWING", "COUPLE", "EAR_TAU", "FOLD_LENGTH", "FOLD_REST", "SELF_REST", "FOLD_UPPER", "FOLD_LAG", "FOLD_SKEW", "FOLD_DOUBLE", "PRESS", "OUTPUT_GAIN", "VIBRATO_FADE", "MIN_HZ", "STEPS", "VOCAL_KEY_BLOCKS", "LIP_WIDTH", "DEFAULTS", "VOCAL_GLIDE_DEFAULTS", "initial", "params", "spec", "v", "gridSections", "rate", "minLength", "dx", "ductMin", "VocalVoice", "VocalPlanner", "ARTICULATORS", "VOCAL_DEFAULT_PHONEME", "GLOTTIS_PULSE", "sampleRate", "rng", "VOCAL_BODIES", "t", "VocalRoof", "JunctionAirway", "VocalDrive", "CascadeBank", "PitchGlide", "Adsr", "PARAMS", "freq", "vel", "clamp", "name", "value", "vocalGlideSpeed", "vocalDamping", "m", "GLOTTIS_SELF_OSCILLATING", "GLOTTIS_GEOMETRIC", "idx", "b", "outL", "outR", "from", "to", "air", "blk", "i", "left", "n", "eb", "A", "B", "w", "lo", "base", "k", "ps", "pharynx", "tongue", "lips", "neutralPharynx", "lb", "jv", "bank", "VOCAL_NEUTRAL", "pass", "q", "restTipFrom", "p", "tg", "ring", "tj", "ART", "so", "held", "ARTICULATOR_TARGET_MIN", "ARTICULATOR_MAX", "settingOffsets", "k2", "art", "ARTICULATOR_RATE", "LIP_COMPRESSED", "roof", "lim", "a", "ix", "iy", "sd", "depth", "nx", "ny", "len", "s", "val", "ax", "ay", "sx", "sy", "pl", "sr", "drive", "sf", "s0", "s1", "fr", "stiff", "lung", "beatLine", "bend", "bt", "up", "down", "ph", "vib", "f0", "pa", "CM_H2O", "gate", "tau", "slope", "r1", "jaw", "need", "room", "vocalEngine", "initParams", "registerVoice", "registerEngine", "vocalEngine"]
7
7
  }