the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Issue #50: a tongue pressed low shortened the oral tube under its stable length (Courant 1.24), and the airway squealed at the limiter with the voice off
Jameson Hodgee48c2c82fa13
diff --git a/crates/chimera/src/voice/human_airway.rs b/crates/chimera/src/voice/human_airway.rsindex e7a99bd..a98b4d9 100644--- a/crates/chimera/src/voice/human_airway.rs+++ b/crates/chimera/src/voice/human_airway.rs@@ -41,6 +41,10 @@ pub struct HumanAirway {pub frame: Option<HumanFrame>,pub ph_len: f64,pub or_len: f64,+ /// shortest section (cm) the airway's time step allows, at Courant number 0.97: a pharynx or+ /// oral tube is never shorter than its node count times this. (The node counts are sized for+ /// 0.93; the beatbox's raised larynx already reaches 0.954, stably, and stays as it was.)+ pub dx_stable: f64,/// noise gains (tunable)pub noise_gain: NoiseGains,/// max area change rate (cm²/s, body-scaled): a physiological guard against geometric jumps@@ -142,6 +146,7 @@ impl HumanAirway {frame: None,ph_len: 8.8,or_len: 8.3,+ dx_stable: (C_SOUND / fs) / 0.97,noise_gain: NoiseGains { glottis: 3.2e-6, constriction: 2.2e-6, teeth: 3.0e-6 },max_area_rate: 45.0,area_rate_gain: 40.0,@@ -255,6 +260,12 @@ impl HumanAirway {clamp_arr(&mut self.ph_areas, &base[0], &mut self.ph_min, &base[2]);clamp_arr(&mut self.or_areas, &base[1], &mut self.or_min, &base[3]);}+ // A pose past the expected extremes (the tongue pressed into the floor of the mouth moves+ // the pharynx/oral split forward: issue #50, a 5.3 cm oral tube) made sections shorter than+ // one time step allows: Courant number 1.24, a self-oscillating airway that squealed at the+ // limiter with the voice off. Such a tube is stretched instead; poses in range are unchanged.+ let ph_len = js_max(ph_len, self.n_ph as f64 * self.dx_stable);+ let or_len = js_max(or_len, self.n_or as f64 * self.dx_stable);self.ph_len = ph_len;self.or_len = or_len;self.net.set_tube_targets(self.pharynx, &self.ph_areas, Some(ph_len), Some(&self.ph_min));diff --git a/crates/chimera/tests/engine.rs b/crates/chimera/tests/engine.rsindex 5b0d481..782e6d7 100644--- a/crates/chimera/tests/engine.rs+++ b/crates/chimera/tests/engine.rs@@ -125,3 +125,50 @@ fn the_voice_holds_for_a_child_at_low_device_rates() {assert!(rms > 0.67 * reference && rms < 1.5 * reference, "child at {fs} Hz: RMS {rms:.3}, 48 kHz {reference:.3}");}}++#[test]+fn an_extreme_pose_does_not_squeal_with_the_voice_off() {+ // Issue #50: lips back, tongue low, larynx up, soft palate down. The low tongue moved the+ // pharynx/oral split forward and shortened the oral tube to 5.3 cm, below its 18 sections'+ // stable length: the airway self-oscillated (Courant number 1.24), a 4-6 kHz squeal at the+ // limiter (RMS 0.5) with no voice at all.+ let pose = ArticPatch::default()+ .with(ArticKey::LipAp, 2.4)+ .with(ArticKey::LipProt, -0.2)+ .with(ArticKey::TbX, 3.75)+ .with(ArticKey::TbY, 2.0)+ .with(ArticKey::Larynx, 1.6)+ .with(ArticKey::Velum, 1.4);+ let mut e = Engine::new(48000.0);+ e.set_artic(&pose, None);+ let mut out = vec![0.0f32; 72000];+ for chunk in out.chunks_mut(128) {+ e.render(chunk);+ }+ // (the first second is the mouth moving there, whose walls push a little air)+ let peak = out[48000..].iter().fold(0.0f32, |m, x| m.max(x.abs()));+ assert!(peak < 1e-3, "voice off at the issue #50 pose: peak {peak}");+ // the guard: no pose the Play screen reaches, no body and no airway rate the oversampling+ // picks (64 kHz for a 16 or 32 kHz device, 96 kHz in the browser) puts a section under the+ // time step's limit (a child's piriform fossa at 64 kHz was 1.09: its voice rang 3x loud)+ use chimera::anatomy::human::NEUTRAL;+ use chimera::voice::human_airway::HumanAirway;+ for body in [BodyName::Male, BodyName::Female, BodyName::Child] {+ for fs in [64000.0, 66150.0, 88200.0, 96000.0] {+ let mut air = HumanAirway::new(fs, body.body());+ for tb_y in [0.0, 2.0, 5.67, 8.0] {+ for lip_prot in [-0.2, 1.5] {+ for larynx in [-1.6, 1.6] {+ let mut a = NEUTRAL;+ a.tb_y = tb_y;+ a.lip_prot = lip_prot;+ a.larynx = larynx;+ air.apply(&a, 0.0);+ let cfl = air.net.check_cfl();+ assert!(cfl <= 0.971, "{body:?} at {fs} Hz, tbY {tb_y} lipProt {lip_prot} larynx {larynx}: Courant number {cfl:.3}");+ }+ }+ }+ }+ }+}