the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
Hill climb: the geometry and beat-sequencer snapshots are blessable too
Jameson Hodge2ccecf4d065d
diff --git a/crates/chimera/tests/golden_geometry.rs b/crates/chimera/tests/golden_geometry.rsindex 495faca..8086ef7 100644--- a/crates/chimera/tests/golden_geometry.rs+++ b/crates/chimera/tests/golden_geometry.rs@@ -1,8 +1,11 @@//! The anatomy model against the TypeScript engine: grids, area functions, contacts, outlines.+//! Re-blessed with `CHIMERA_BLESS=1` after an intended change to the geometry (the articulations+//! stay; what they produce is rewritten).mod common;use chimera::anatomy::geom::Vec2;use chimera::anatomy::human::{BodyName, HumanArtic, HumanFrame, HumanVocalTract};use common::*;+use serde_json::json;fn flat(ps: &[Vec2]) -> Vec<f64> {ps.iter().flat_map(|p| [p.x, p.y]).collect()@@ -10,16 +13,31 @@ fn flat(ps: &[Vec2]) -> Vec<f64> {#[test]fn geometry_matches_typescript() {- let cases = load("geometry");+ let mut cases = load("geometry");+ let bless_it = blessing();let mut tracts: std::collections::HashMap<String, HumanVocalTract> = Default::default();let mut f = HumanFrame::default();let mut worst_all = 0.0f64;- for (ci, c) in cases.as_array().unwrap().iter().enumerate() {+ for (ci, c) in cases.as_array_mut().unwrap().iter_mut().enumerate() {let body = c["body"].as_str().unwrap();let artic: HumanArtic = serde_json::from_value(c["artic"].clone()).unwrap();let t = tracts.entry(body.to_string()).or_insert_with(|| HumanVocalTract::new(BodyName::parse(body).body()));t.compute(&artic, &mut f);let label = format!("case {ci} ({body})");+ let (n_ph, n_or) = (18, 18);+ let (mut ph, mut or, mut ph_min, mut or_min) = (vec![0.0; n_ph], vec![0.0; n_or], vec![0.0; n_ph], vec![0.0; n_or]);+ if bless_it {+ c["grid"] = json!(f.grid.iter().map(|r| json!([r.region, r.d, r.area, r.s])).collect::<Vec<_>>());+ c["scalars"] = json!([f.length, f.pharynx_length, f.teeth_s, f.lip_s, f.velum_port, f.lip_area, f.tongue_radius, f.tip.x, f.tip.y, f.split_index as f64, t.contact_tip, t.contact_body, t.contact_tip_n.x, t.contact_tip_n.y, t.contact_body_n.x, t.contact_body_n.y]);+ for (key, pts) in [("outer", &f.outer), ("inner", &f.inner), ("tongue", &f.tongue), ("velum", &f.velum), ("upperLip", &f.upper_lip), ("lowerLip", &f.lower_lip)] {+ if c[key].is_array() {+ c[key] = json!(flat(pts));+ }+ }+ let (ph_len, or_len) = t.resample(&artic, &f, &mut ph, &mut or, Some(&mut ph_min), Some(&mut or_min));+ c["resample"] = json!({ "phLen": ph_len, "orLen": or_len, "ph": ph, "or": or, "phMin": ph_min, "orMin": or_min });+ continue;+ }let grid = c["grid"].as_array().unwrap();assert_eq!(grid.len(), f.grid.len(), "{label}: grid size");let mut w = 0.0f64;@@ -37,8 +55,6 @@ fn geometry_matches_typescript() {}}let rs = &c["resample"];- let (n_ph, n_or) = (18, 18);- let (mut ph, mut or, mut ph_min, mut or_min) = (vec![0.0; n_ph], vec![0.0; n_or], vec![0.0; n_ph], vec![0.0; n_or]);let (ph_len, or_len) = t.resample(&artic, &f, &mut ph, &mut or, Some(&mut ph_min), Some(&mut or_min));w = w.max(worst(&format!("{label} lengths"), &[num(&rs["phLen"]), num(&rs["orLen"])], &[ph_len, or_len], 1e-6));for (key, arr) in [("ph", &ph), ("or", &or), ("phMin", &ph_min), ("orMin", &or_min)] {@@ -47,5 +63,8 @@ fn geometry_matches_typescript() {assert!(w < 1e-9, "{label}: worst relative difference {w:e}");worst_all = worst_all.max(w);}+ if bless_it {+ return save_json("geometry", &cases);+ }println!("geometry: {} cases, worst relative difference {worst_all:e}", cases.as_array().unwrap().len());}diff --git a/crates/chimera/tests/golden_planning.rs b/crates/chimera/tests/golden_planning.rsindex 03afb6f..90ba241 100644--- a/crates/chimera/tests/golden_planning.rs+++ b/crates/chimera/tests/golden_planning.rs@@ -3,7 +3,8 @@//! the same keys everywhere, strings and labels exact, `speed`/`releaseHold`/`tag` exact, other//! numbers to 1e-9 relative (absolute floor 1e-9). The planners' expectations (utterances,//! durations, phrases, songs, live notes) are re-blessed with `CHIMERA_BLESS=1` after an intended-//! change, like the audio fixtures; the beat sequencer's stay the TypeScript engine's.+//! change, like the audio fixtures. So are the beat sounds' gestures and the beat player's output,+//! which carry the calibrated vowel targets; the beat notation stays the TypeScript engine's.mod common;use chimera::anatomy::human::BODY_MALE;use chimera::control::beat_player::BeatPlayer;@@ -78,14 +79,21 @@ fn de<T: serde::de::DeserializeOwned>(v: &Value) -> T {/// planning.json (its inputs stay). The tests run in parallel, so each rewrites the file under a/// lock with only its own section changed.fn bless(section: &str, field: &str, got: Vec<Value>) {+ bless_with(|f| {+ let items = f[section].as_array_mut().unwrap();+ assert_eq!(items.len(), got.len());+ for (item, v) in items.iter_mut().zip(got) {+ item[field] = v;+ }+ });+}++/// Rewrite planning.json under the lock, changing only what `edit` changes.+fn bless_with(edit: impl FnOnce(&mut Value)) {static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());let _held = LOCK.lock().unwrap();let mut f = load("planning");- let items = f[section].as_array_mut().unwrap();- assert_eq!(items.len(), got.len());- for (item, v) in items.iter_mut().zip(got) {- item[field] = v;- }+ edit(&mut f);save_json("planning", &f);}@@ -209,29 +217,39 @@ fn live_notes_match_typescript() {#[test]fn beat_sounds_match_typescript() {- let f = load("planning");+ let mut f = load("planning");let mut st = Stats::default();- let sounds = f["sounds"].as_array().unwrap();+ let bless_it = blessing();+ let mut cmp = |path: &str, want: &mut Value, got: Value, st: &mut Stats| if bless_it { *want = got } else { cmp(path, want, &got, st) };+ let sounds = f["sounds"].as_array_mut().unwrap();assert_eq!(sounds.len(), BEAT_SOUNDS.len());for (s, want) in BEAT_SOUNDS.iter().zip(sounds) {// the catalogue the UI receiveslet mut meta = want.as_object().unwrap().clone();meta.remove("builds");meta.remove("leadIn");- cmp(&format!("sound {}", s.id), &Value::Object(meta), &val(s), &mut st);- for b in want["builds"].as_array().unwrap() {- let body = b["body"].as_str().unwrap();+ self::cmp(&format!("sound {}", s.id), &Value::Object(meta), &val(s), &mut st);+ for b in want["builds"].as_array_mut().unwrap() {+ let body = b["body"].as_str().unwrap().to_string();let o: BeatBuild = de(&b["o"]);let mut out = Vec::new();- (s.build)(body.into(), &o, &mut out);- cmp(&format!("sound {} {body} {}", s.id, b["o"]), &b["gestures"], &val(&out), &mut st);+ (s.build)(body.as_str().into(), &o, &mut out);+ let path = format!("sound {} {body} {}", s.id, b["o"]);+ cmp(&path, &mut b["gestures"], val(&out), &mut st);}for body in ["male", "female", "child"] {- cmp(&format!("leadIn {} {body}", s.id), &want["leadIn"][body], &json!(BeatPlayer::lead_in(s.id, body.into())), &mut st);+ cmp(&format!("leadIn {} {body}", s.id), &mut want["leadIn"][body], json!(BeatPlayer::lead_in(s.id, body.into())), &mut st);}}for body in ["male", "female", "child"] {- cmp(&format!("ready {body}"), &f["ready"][body], &val(&beat_ready(body.into())), &mut st);+ cmp(&format!("ready {body}"), &mut f["ready"][body], val(&beat_ready(body.into())), &mut st);+ }+ if bless_it {+ let (sounds, ready) = (f["sounds"].clone(), f["ready"].clone());+ return bless_with(|g| {+ g["sounds"] = sounds;+ g["ready"] = ready;+ });}report("sounds", &st);}@@ -293,9 +311,16 @@ fn run_player(ops: &[Value]) -> Vec<Value> {fn beat_player_matches_typescript() {let f = load("planning");let mut st = Stats::default();+ let mut got_all = Vec::new();for (i, s) in f["player"].as_array().unwrap().iter().enumerate() {- let got = run_player(s["ops"].as_array().unwrap());- cmp(&format!("player {i}"), &s["out"], &Value::Array(got), &mut st);+ let got = Value::Array(run_player(s["ops"].as_array().unwrap()));+ if !blessing() {+ cmp(&format!("player {i}"), &s["out"], &got, &mut st);+ }+ got_all.push(got);+ }+ if blessing() {+ return bless("player", "out", got_all);}report("player", &st);}diff --git a/docs/hill-climb/README.md b/docs/hill-climb/README.mdindex 8b5c452..27024cf 100644--- a/docs/hill-climb/README.md+++ b/docs/hill-climb/README.md@@ -132,12 +132,14 @@ speech judged against the batch's baseline and required to be not WORSE):3. The bench is no more than **10 % slower** than the batch's baseline.4. **The tests pass.**1. Bless the golden fixtures in `crates/chimera/tests/golden`. They are snapshots of the- sound (the `.f32` files) and of the planners' output (the utterance, duration, phrase,- song and live-note plans in `planning.json`), and they change with any change to either.- Run `CHIMERA_BLESS=1 cargo test --workspace --no-fail-fast` **twice**: `engine.rs` reads- a fixture that `golden_planning` blesses, so its first run can fail. The beat- sequencer's expectations in `planning.json` are not blessed: a voice change shouldn't- move them.+ sound (the `.f32` files), of the planners' output (the utterance, duration, phrase, song+ and live-note plans, the beat sounds' gestures and the beat player's output, in+ `planning.json`) and of the tract geometry (area functions, contacts and outlines, in+ `geometry.json`), and they change with any change to these. Run `CHIMERA_BLESS=1 cargo+ test --workspace --no-fail-fast` **twice**: `engine.rs` reads a fixture that+ `golden_planning` blesses, so its first run can fail. The beat notation's expectations+ are not blessed. Other geometry tests (`geometry_continuity`, `airway`) are real checks,+ not snapshots: if one fails, fix the cause as part of the change.2. Then run `cargo test --workspace --no-fail-fast` and `bun run wasm && bun test tests`.Every test must pass, with one exception. If your change alters the airway's linearacoustics on purpose (wall or radiation losses, tract geometry), the airway checks indiff --git a/docs/hill-climb/log.md b/docs/hill-climb/log.mdindex 653d342..d9bfd50 100644--- a/docs/hill-climb/log.md+++ b/docs/hill-climb/log.md@@ -627,3 +627,18 @@ judge is Whisper. See the README's "current batch" section for the rules.- After that, the /ʃ/'s level: the female /ʃ/ is 21 dB below its vowel and the male 11 dB.The teeth source's gain, or how its weight depends on the distance behind the teeth (2.5 cmfor /ʃ/, just short of where `w_dist` starts to fade, at 2.6), is the place to look.++### Decision after experiment 11: the geometry and beat-sequencer snapshots are blessable++Experiment 11 changed the mouth's area rule in front of the tongue tip and recalibrated the vowel+tables, as the rules ask. Two TypeScript-era snapshots then failed by design: `golden_geometry`+(the area functions) and the beat sounds' and beat player's gestures in `planning.json` (their+vowel targets moved by 0.001). Like the audio and planner fixtures in batch 1, they are now+blessed with `CHIMERA_BLESS=1` (`golden_geometry.rs`, `golden_planning.rs`). On the current engine+blessing them changes no value (geometry within 7e-14; planning only in number formatting and+two last-digit floats). The beat notation stays fixed.++`geometry_continuity` is a real check, not a snapshot, so experiment 11's failure there stands: its+recalibrated child /ə/ posture lands on a jump in the area function at the top of the pharynx,+near the raised velum. That jump was already there; experiment 12 fixes it together with+experiment 11's change.