Skip to content

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

Rust

Hill climb 32: the lungs' port gives the steady flow the lower airways' 0.8 cmH2O/(L/s), lungs 7.2, effort held; folds held apart lose closed phase (the /ɑvɑ/ click test reads a voice pulse)

Jameson Hodge68df41eac436
diff --git a/crates/chimera/src/phonetics/planner.rs b/crates/chimera/src/phonetics/planner.rs
index f3546b8..0f89f55 100644
--- a/crates/chimera/src/phonetics/planner.rs
+++ b/crates/chimera/src/phonetics/planner.rs
@@ -26,7 +26,7 @@ const BREATH_SUNG_AT: f64 = 0.06;
/// (Stevens 1971; Elie & Laprie's "regime B"). Here that is a mean glottal area of about 0.13 cm²,
/// through constrictions of 0.10-0.18. The pressure behind the constriction then rises and the
/// voicing weakens by itself, most in /z/, whose constriction is the narrowest. 0.12-0.14 match the
-/// TSP speakers' voicing better; female /z/ can't take them yet (hill-climb log, experiment 23).
+/// TSP speakers' voicing better; `an_f_does_not_click` stops them (hill-climb log, experiments 23 and 32).
const VOICED_FRICATIVE_OPENING: f64 = 0.09;
/// /ð/ after a nasal keeps a small opening: the speakers' has no dip there, nasal level throughout, and
/// this reads about their level (hill-climb log, experiment 24).
@@ -331,7 +331,9 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {
// phonation
let k2 = 1.0; // abduction is body-scaled in the voice
if def.glottal == Some(Glottal::Open) {
- gestures.push(Gesture::new(t0 - 0.01, t1, 0.03, 0.035, 5.0, one(ControlKey::ABDUCTION, 0.33 * k2)).label("h"));
+ // the folds close 10 ms before the span's end: with the lungs' port fixed, /h/ is 4-5 dB louder and MFA
+ // reads it about that much longer than the speakers' (hill-climb log, experiment 32)
+ gestures.push(Gesture::new(t0 - 0.01, t1 - 0.01, 0.03, 0.035, 5.0, one(ControlKey::ABDUCTION, 0.33 * k2)).label("h"));
} else if def.glottal == Some(Glottal::Breathy) {
gestures.push(Gesture::new(t0, t1, 0.03, 0.03, 5.0, one(ControlKey::ABDUCTION, 0.1 * k2)).label("ɦ"));
} else if def.glottal == Some(Glottal::Stop) {
@@ -477,11 +479,12 @@ fn nasal_closure_delay(place: &str) -> f64 {
/// a nasal's sound leaves for the nose. After a sibilant the noise falls as the closing area nears its
/// channel's, and at the tip the tongue is already up: 16-23, 25-35, 14-21. Nothing to aim for
/// otherwise: a pause, stop or nasal before it has nothing running up to the closure, /f t/ closes on
-/// time, and after /ɹ l/ the tip closes late already (hill-climb log, experiment 26).
+/// time, and after /ɹ l/ the tip closes late already (hill-climb log, experiment 26). The tip's 19 centres its fall
+/// in running speech with the lungs' port fixed (experiment 32).
fn stop_closure_delay(place: &str, prev: Option<&Seg>) -> f64 {
let Some(prev) = prev else { return 0.0 };
let (lips, tip, dorsum) = if prev.vowel.is_some() {
- (0.005, 0.02, 0.015)
+ (0.005, 0.019, 0.015)
} else if matches!(prev.ipa, "s" | "z" | "ʃ" | "ʒ") {
(0.02, 0.03, 0.02)
} else {
diff --git a/crates/chimera/src/sources/glottis.rs b/crates/chimera/src/sources/glottis.rs
index 83ce8e5..d9d75f9 100644
--- a/crates/chimera/src/sources/glottis.rs
+++ b/crates/chimera/src/sources/glottis.rs
@@ -22,6 +22,8 @@ pub struct GlottisParams {
pub chink: f64,
/// open quotient 0..1
pub open_quotient: f64,
+ /// how much of the cycle folds held apart lose of their closed phase, per cm² of abduction
+ pub open_with_abduction: f64,
/// fraction of the open phase spent opening (0.5 symmetric, larger = faster closing)
pub skew: f64,
/// 0 = smooth (raised-cosine) closure, 1 = abrupt slope at closure
@@ -54,6 +56,7 @@ pub const DEFAULT_GLOTTIS: GlottisParams = GlottisParams {
abduction: 0.0,
chink: 0.006,
open_quotient: 0.62,
+ open_with_abduction: 0.0,
skew: 0.62,
closure_sharpness: 0.6,
effort: 0.7,
@@ -200,6 +203,8 @@ impl ParametricGlottis {
// pulse shape within the cycle
let mut oq = clamp(p.open_quotient - 0.18 * (p.effort - 0.5), 0.25, 0.98);
+ // the chink is left out: it's a gap behind folds that still meet
+ oq = js_min(0.98, oq + p.open_with_abduction * js_max(0.0, self.static_sm - p.chink));
if p.fry > 0.0 {
oq = oq * (1.0 - p.fry) + 0.28 * p.fry;
}
diff --git a/crates/chimera/src/voice/human_airway.rs b/crates/chimera/src/voice/human_airway.rs
index 9ddcd59..4732b17 100644
--- a/crates/chimera/src/voice/human_airway.rs
+++ b/crates/chimera/src/voice/human_airway.rs
@@ -6,14 +6,24 @@
use crate::airway::network::{AirwayNetwork, Area, NoiseSpec, PortSpec, Tube, TubeSpec};
use crate::anatomy::human::{HumanArtic, HumanBody, HumanFrame, HumanVocalTract};
-use crate::math::{PI, js_max, js_min, js_round, smoothstep as smooth, sqrt};
-use crate::physics::{C_SOUND, RHO, WALL_NASAL, WALL_SOFT, WALL_TRACHEA};
+use crate::math::{PI, exp, js_max, js_min, js_round, smoothstep as smooth, sqrt};
+use crate::physics::{C_SOUND, CM_H2O, RHO, WALL_NASAL, WALL_SOFT, WALL_TRACHEA};
/// The teeth source's band tops out at f = St·u/δ, the jet's speed and eddy size where it meets the
/// teeth. St is of order 1 for a near-circular jet such as /s/ or /ʃ/ (Krane 2005, JASA 118, eq. 13),
-/// and the real speakers' /s/ and /ʃ/ (TSP) start to fall at about this model's v/D. 1.15 is the
-/// value kept of those tried (hill-climb log, experiment 21).
-const TEETH_STROUHAL: f64 = 1.15;
+/// and 1.0 is that, with no fitted factor. The real speakers' /s/ and /ʃ/ (TSP) start to fall at 0.8-1.0
+/// of this model's v/D (hill-climb log, experiments 21, 30 and 32).
+const TEETH_STROUHAL: f64 = 1.0;
+/// Lower-airway resistance, male (cmH₂O per L/s): what air flowing out of the lungs loses below the
+/// modelled trachea. Plethysmography gives 1.3-1.5 from the mouth to the alveoli (DuBois 1956, Fisher
+/// 1968), 1.40 in eight young men (Juntendo 1980); about 1/3-1/2 of it is above the mid-trachea (Ferris
+/// 1964 and others), in what the tract already models, and the rest is linear up to 2 L/s (Ferris
+/// 1964). A woman's 1.87 in the same study is 1.34 times his, about 1/k³ (0.9 → 1.37): Poiseuille's
+/// ℓ/r⁴, as resistance goes with 1/lung volume (hill-climb log, experiment 30).
+const LOWER_AIRWAY_R: f64 = 0.8;
+/// The gas's inertance in the bronchial tree below the trachea, male (g/cm⁴): ρ·Σℓ/A over Weibel's model
+/// A is about 4.6 /cm. Body scale k: 1/k, as ℓ/A.
+const LOWER_AIRWAY_L: f64 = 5.2e-3;
/// A turbulent mixing layer grows about as δ ≈ 0.17·x (textbook range, Pope 2000, ch. 5), so δ
/// reaches the jet's diameter about 6 D downstream, where a round jet's core ends.
const JET_SPREAD: f64 = 0.17;
@@ -39,6 +49,13 @@ pub struct HumanAirway {
pub nasal: Tube,
pub fossa: Tube,
pub lungs: usize,
+ pub lung_port: usize,
+ /// what the lung port's resistance has over the lower airways' (dyn·s/cm⁵)
+ pub lung_port_excess: f64,
+ /// one-pole coefficient per internal sample at the corner where the lower airways' inertance
+ /// reaches that excess: below it the lungs see the lower airways' resistance, above it the
+ /// port's acoustic termination
+ pub lung_port_coef: f64,
pub glottis_port: usize,
pub velum_port: usize,
pub rad_lips: usize,
@@ -120,7 +137,12 @@ impl HumanAirway {
let lungs = net.add_pressure_node("lungs");
let tr_a = 2.5 * k * k;
- net.add_port(lungs, trachea.first_node(), PortSpec::new(tr_a, 1.0).kinetic(0.0, 0.0).resistance((0.5 * RHO * C_SOUND) / tr_a));
+ // half the trachea's characteristic impedance terminates its sound. That's a value for waves,
+ // not for the steady flow: at /ʃ/'s 0.5 L/s it took 4 of the lungs' 8 cmH₂O
+ let r_ac = (0.5 * RHO * C_SOUND) / tr_a;
+ let lung_port = net.add_port(lungs, trachea.first_node(), PortSpec::new(tr_a, 1.0).kinetic(0.0, 0.0).resistance(r_ac));
+ let lung_port_excess = r_ac - LOWER_AIRWAY_R * (CM_H2O / 1000.0) / (k * k * k);
+ let lung_port_coef = 1.0 - exp((-lung_port_excess * k / LOWER_AIRWAY_L) / fs);
let glottis_port = net.add_port(trachea.last_node(), pharynx.first_node(), PortSpec::new(0.0, 0.3 * k).kinetic(0.37, 1.0).slit(1.4 * k));
net.connect(pharynx.last_node(), oral.first_node());
let velum_port = net.add_port(pharynx.last_node(), nasal.first_node(), PortSpec::new(0.0, 1.0 * k).kinetic(0.3, 0.8));
@@ -143,6 +165,9 @@ impl HumanAirway {
nasal,
fossa,
lungs,
+ lung_port,
+ lung_port_excess,
+ lung_port_coef,
glottis_port,
velum_port,
rad_lips,
@@ -156,7 +181,7 @@ impl HumanAirway {
frame: None,
ph_len: 8.8,
or_len: 8.3,
- noise_gain: NoiseGains { glottis: 3.2e-6, constriction: 2.2e-6, teeth: 3.0e-6 },
+ noise_gain: NoiseGains { glottis: 3.2e-6, constriction: 1.364e-6, teeth: 3.0e-6 },
max_area_rate: 45.0,
area_rate_gain: 40.0,
seal_rate: 5.0,
@@ -330,7 +355,9 @@ impl HumanAirway {
// obstacle source: a narrow anterior jet impinging on the incisors (sibilants)
let s_min = if min_i < n_ph_i { (min_i as f64 + 0.5) * dx_ph } else { self.ph_len + ((min_i - n_ph_i) as f64 + 0.5) * dx_or };
let behind = (f.teeth_s - s_min) / self.body.scale;
- let w_dist = smooth(0.15, 0.5, behind) * (1.0 - smooth(2.6, 4.0, behind));
+ // a jet that leaves its channel at the teeth doesn't strike them: /θ/'s narrowest section
+ // sits 0.7-0.9 cm behind them, /s/'s 1.8-1.9 (hill-climb log, experiment 30)
+ let w_dist = smooth(1.0, 1.5, behind) * (1.0 - smooth(2.6, 4.0, behind));
let w_jet = 1.0 - smooth(0.2 * k2, 0.5 * k2, min_a);
let wt = w_dist * w_jet;
if wt > 1e-3 {
diff --git a/crates/chimera/src/voice/human_voice.rs b/crates/chimera/src/voice/human_voice.rs
index 834e826..db05f54 100644
--- a/crates/chimera/src/voice/human_voice.rs
+++ b/crates/chimera/src/voice/human_voice.rs
@@ -46,7 +46,16 @@ fn default_brightness() -> f64 {
DEFAULT_SOURCE.brightness
}
-pub const DEFAULT_SOURCE: VoiceSource = VoiceSource { f0: 110.0, glide: 0.06, pressure: 8.0, breathiness: 0.15, tension: 0.5, fry: 0.0, roughness: 0.1, vibrato_depth: 0.0, vibrato_rate: 6.0, drift: 5.0, voiced: true, brightness: 0.25 };
+/// `pressure` 7.2 holds what the folds read in vowels, 7.1-7.2 cmH₂O, once the lungs' port stopped taking
+/// its 0.8 (hill-climb log, experiment 30).
+pub const DEFAULT_SOURCE: VoiceSource = VoiceSource { f0: 110.0, glide: 0.06, pressure: 7.2, breathiness: 0.15, tension: 0.5, fry: 0.0, roughness: 0.1, vibrato_depth: 0.0, vibrato_rate: 6.0, drift: 5.0, voiced: true, brightness: 0.25 };
+
+/// Vocal effort from the lung pressure (cmH₂O). The folds read 0.8 less than the lungs while the
+/// lungs' port took its share, so `(lungs − 3)/10` was this law on the same folds' pressure. The port's fix
+/// moves neither the folds' pressure nor their effort (hill-climb log, experiment 32).
+fn effort_at(pressure: f64) -> f64 {
+ clamp((pressure.abs() - 2.2) / 10.0, 0.0, 1.0)
+}
/// `Partial<VoiceSource>`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize)]
@@ -165,6 +174,8 @@ pub struct HumanVoice {
/// lung pressure applied this sample, ramped toward `p_lung` across the control block
p_lung_now: f64,
p_lung_step: f64,
+ /// the lung port's flow below its corner (cm³/s)
+ lung_flow: f64,
f0: f64,
pub output_gain: f64,
dc_x: f64,
@@ -222,6 +233,7 @@ impl HumanVoice {
p_lung: 0.0,
p_lung_now: 0.0,
p_lung_step: 0.0,
+ lung_flow: 0.0,
f0: DEFAULT_SOURCE.f0,
output_gain: 5.5e-7,
dc_x: 0.0,
@@ -321,6 +333,9 @@ impl HumanVoice {
// air and damps the tract, which lifts H1 and the band below 500 Hz.
g.chink = (0.008 + 0.03 * s.breathiness) * k2;
g.open_quotient = 0.78 - 0.36 * s.tension + body.open_phase;
+ // Zhang 2016 (JASA 139, 1493, table II): closed quotient −0.0247 per degree of resting angle, in a 3D
+ // model whose 0-4° open 0-10.1 mm². It's secondary there to the folds' thickness (hill-climb log, experiment 32)
+ g.open_with_abduction = 0.98;
// The folds close along their length and depth over a return phase, not all at once, so
// a sung or spoken voice closes softly (0.22 at tension 0.55): an abrupt closure put
// 3-8 dB too much energy above 2 kHz. Pressing harder than that brings the abrupt closure
@@ -340,13 +355,14 @@ impl HumanVoice {
g.vibrato_depth = s.vibrato_depth;
g.vibrato_rate = s.vibrato_rate;
g.drift = s.drift;
- g.effort = clamp((s.pressure.abs() - 3.0) / 10.0, 0.0, 1.0);
+ g.effort = effort_at(s.pressure);
}
/// Render `out.len()` output samples.
pub fn render(&mut self, out: &mut [f32]) {
let m = self.m;
let lungs = self.airway.lungs;
+ let (lung_port, lung_excess, lung_coef) = (self.airway.lung_port, self.airway.lung_port_excess, self.airway.lung_port_coef);
let sub_node = self.airway.trachea.last_node();
let supra = self.airway.pharynx.first_node();
let gp = self.airway.glottis_port;
@@ -362,7 +378,10 @@ impl HumanVoice {
self.ctrl_counter -= 1;
let net = &mut self.airway.net;
self.p_lung_now += self.p_lung_step;
- net.set_fixed_pressure(lungs, self.p_lung_now);
+ // the port's resistance is for sound: below its corner the lungs give back what it
+ // takes beyond the lower airways' own, a passive R_dc + R·s/(s + ωc)
+ self.lung_flow += lung_coef * (net.u[lung_port] - self.lung_flow);
+ net.set_fixed_pressure(lungs, self.p_lung_now + lung_excess * self.lung_flow);
let a = self.glottis.next(net.p[sub_node] - net.p[supra]);
net.set_port_area(gp, a);
let y = net.step();
@@ -497,7 +516,7 @@ impl HumanVoice {
self.p_lung_step = (self.p_lung - self.p_lung_now) / self.ctrl_every as f64;
// vocal effort follows the pressure actually applied: a harder breath (a louder sung note)
// gives wider, sharper-closing pulses, as in real phonation, not just more flow
- self.glottis.params.effort = clamp(((self.source.pressure * self.gate).abs() - 3.0) / 10.0, 0.0, 1.0);
+ self.glottis.params.effort = effort_at(self.source.pressure * self.gate);
// pitch glide
let g = js_max(0.002, if self.score_f0.is_some() { 0.03 } else { self.source.glide });
self.f0 *= pow(f0_target / self.f0, 1.0 - exp(-dt / g));
diff --git a/crates/chimera/tests/affricates.rs b/crates/chimera/tests/affricates.rs
index 4a6a6ac..1d58e20 100644
--- a/crates/chimera/tests/affricates.rs
+++ b/crates/chimera/tests/affricates.rs
@@ -52,7 +52,8 @@ fn frication(fr: &[(f64, f64)], t0: f64, t1: f64, name: &str) -> (usize, usize)
let fric: Vec<usize> = (at(t0)..at(t1 + 0.1)).filter(|&i| fr[i].1 < -10.0 && fr[i].0 > vowel - 30.0).collect();
let (first, last) = (*fric.first().unwrap_or_else(|| panic!("{name}: no frication")), *fric.last().unwrap());
let voiced = (last..fr.len()).find(|&i| fr[i].0 > vowel - 8.0).unwrap();
- ((last - first + 1) * 10, (voiced - last - 1) * 10)
+ // the frication's last frame can itself be within 8 dB of the vowel: no gap at all
+ ((last - first + 1) * 10, (voiced - last).saturating_sub(1) * 10)
}
const VOICES: [(HumanBody, &str, f64); 2] = [(BODY_MALE, "male", 112.0), (BODY_FEMALE, "female", 205.0)];
diff --git a/crates/chimera/tests/lung_port.rs b/crates/chimera/tests/lung_port.rs
new file mode 100644
index 0000000..bd9047f
--- /dev/null
+++ b/crates/chimera/tests/lung_port.rs
@@ -0,0 +1,82 @@
+//! The lungs' port (experiment 32). Its resistance, half the trachea's characteristic impedance, is a
+//! termination for sound, and it also sat in the steady flow: 8.2 cmH₂O/(L/s) male, 10.1 female, so
+//! /ʃ/ lost about half the lungs' pressure before the folds, and every open-glottis sound was
+//! underdriven. And what the fix leans on: the folds' effort stays where it was, and folds held apart
+//! lose closed phase.
+use chimera::anatomy::human::{BODY_FEMALE, BODY_MALE, HumanBody};
+use chimera::phonetics::ipa::tokenize_ipa;
+use chimera::phonetics::planner::{PlanOptions, plan_utterance};
+use chimera::physics::CM_H2O;
+use chimera::voice::human_voice::{HumanVoice, SourcePatch};
+
+const FS: f64 = 48000.0;
+const VOICES: [(HumanBody, &str, f64); 2] = [(BODY_MALE, "male", 112.0), (BODY_FEMALE, "female", 205.0)];
+
+/// Render a VCV and call `at` on every block inside the middle half of the span of `ipa`.
+fn in_span(body: HumanBody, name: &str, f0: f64, vcv: &str, ipa: &str, mut at: impl FnMut(&HumanVoice)) {
+ let plan = plan_utterance(&tokenize_ipa(vcv), &PlanOptions { body: name.into(), t0: 0.05, f0: Some(f0), ..Default::default() });
+ let s = plan.segments.iter().find(|s| s.ipa == ipa).unwrap();
+ let (a, b) = (s.t0 + (s.t1 - s.t0) / 4.0, s.t1 - (s.t1 - s.t0) / 4.0);
+ let mut v = HumanVoice::new(FS, body, 2);
+ v.set_source(&SourcePatch::f0(f0));
+ v.schedule(&plan.gestures);
+ let mut block = [0.0f32; 128];
+ let mut n = 0usize;
+ while (n as f64) < FS * (plan.end + 0.05) {
+ v.render(&mut block);
+ n += block.len();
+ let t = n as f64 / FS;
+ if t >= a && t <= b {
+ at(&v);
+ }
+ }
+}
+
+#[test]
+fn a_fricative_keeps_the_lungs_pressure_at_its_folds() {
+ for (body, name, f0) in VOICES {
+ let mut folds = vec![];
+ in_span(body, name, f0, "ˈɑʃɑ", "ʃ", |v| folds.push(v.airway.net.p[v.airway.trachea.last_node()] / CM_H2O));
+ folds.sort_by(f64::total_cmp);
+ let median = folds[folds.len() / 2];
+ // 0.6 L/s through the lower airways' 0.8-1.1 cmH₂O/(L/s) and the trachea's walls. It read 4.1-4.2
+ assert!(median > 5.8, "{name}: {median} cmH₂O under the folds in /ʃ/");
+ }
+}
+
+#[test]
+fn the_port_moves_neither_the_folds_pressure_nor_their_effort() {
+ let mut v = HumanVoice::with_defaults(FS);
+ v.set_source(&SourcePatch::default());
+ assert!((v.glottis.params.effort - 0.5).abs() < 1e-12, "{}", v.glottis.params.effort);
+ // what the folds read in a stressed vowel before the fix: 7.1-7.2 cmH₂O
+ for (body, name, f0) in VOICES {
+ let mut folds = vec![];
+ in_span(body, name, f0, "ˈɑtɑ", "ɑ", |v| folds.push(v.airway.net.p[v.airway.trachea.last_node()] / CM_H2O));
+ let mean = folds.iter().sum::<f64>() / folds.len() as f64;
+ assert!((6.5..7.5).contains(&mean), "{name}: {mean} cmH₂O under the folds in /ɑ/");
+ }
+}
+
+#[test]
+fn folds_held_apart_meet_for_less_of_the_cycle() {
+ let closed_share = |abduction: f64| {
+ let mut g = HumanVoice::with_defaults(FS).glottis;
+ g.params.abduction = abduction;
+ g.params.chink = 0.01;
+ g.params.jitter = 0.0;
+ g.params.drift = 0.0;
+ let (mut closed, mut n) = (0, 0);
+ for i in 0..(0.5 * FS) as usize {
+ let a = g.next(7.0 * CM_H2O);
+ if i as f64 > 0.25 * FS {
+ closed += i32::from(a <= abduction + 0.01 + 1e-9);
+ n += 1;
+ }
+ }
+ f64::from(closed) / f64::from(n)
+ };
+ // Zhang 2016, table II: closed quotient −0.0247 per degree, where 0-4° open 0-10.1 mm²
+ let lost = closed_share(0.0) - closed_share(0.1);
+ assert!((lost - 0.098).abs() < 0.02, "closed share lost at 0.1 cm²: {lost}");
+}