the ultimate vocal synthesizer - sing, speak, beatbox, and more
Rust
What a front end can ask of the singer: a bend in the middle of the vowel, rising diphthongs and triphthongs, its own off-glide share and consonant lengths, a nasal lead, and the apical vowels ɿ ʅ
Joshua Pham88e5080fe320
diff --git a/crates/chimera-cli/src/calibrate.rs b/crates/chimera-cli/src/calibrate.rsindex 2c6f24b..24ef897 100644--- a/crates/chimera-cli/src/calibrate.rs+++ b/crates/chimera-cli/src/calibrate.rs@@ -126,7 +126,7 @@ pub fn vowels(a: &[String]) -> Result<(), String> {if vw.round { 0.12 } else { 0.85 },0.4 * (1.0 - vw.back) - 0.5 * vw.height * vw.back,0.4 * (1.0 - vw.height) * (1.0 - vw.back) - if vw.round { 0.4 } else { 0.0 },- if vw.ipa == "ɝ" { 0.6 } else { 0.0 },+ if vw.ipa == "ɝ" { 0.6 } else if vw.ipa == "ʅ" { 0.9 } else { 0.0 },];if vw.ipa == "ɯ" {x0 = vec![2.6, 7.35, 0.25, 0.5, 0.1, 0.65, 0.4, 0.2, 0.0];@@ -139,7 +139,7 @@ pub fn vowels(a: &[String]) -> Result<(), String> {return 50.0;}let mut c = 0.0;- let w = [1.0, 1.0, if vw.ipa == "ɝ" { 1.2 } else { 0.45 }];+ let w = [1.0, 1.0, if matches!(vw.ipa, "ɝ" | "ʅ") { 1.2 } else { 0.45 }];for i in 0..3 {c += w[i] * pow(ln(f[i] / t[i]), 2.0);}@@ -170,7 +170,7 @@ pub fn vowels(a: &[String]) -> Result<(), String> {// give the same formants, and without this the fit wandered (a schwa with the// tongue as low as /ɑ/), making every transition through it needlessly longc += 0.006 * (pow(p[0] - x0[0], 2.0) + pow(p[1] - x0[1], 2.0));- if vw.ipa != "ɝ" {+ if !matches!(vw.ipa, "ɝ" | "ʅ") {c += 0.5 * p[8] * p[8];}cdiff --git a/crates/chimera-cli/src/compare.rs b/crates/chimera-cli/src/compare.rsindex ab5615b..3b470e7 100644--- a/crates/chimera-cli/src/compare.rs+++ b/crates/chimera-cli/src/compare.rs@@ -291,6 +291,7 @@ fn render_notes(notes: &[Note], body_name: &str, seconds: f64) -> Result<Render,bpm: 60.0,t0: notes[i].start,vibrato: VIBRATO_CENTS,+ ..Default::default()},);v.schedule(&plan.gestures);diff --git a/crates/chimera-cli/src/render.rs b/crates/chimera-cli/src/render.rsindex 73740f3..d9dc4c1 100644--- a/crates/chimera-cli/src/render.rs+++ b/crates/chimera-cli/src/render.rs@@ -268,6 +268,7 @@ pub fn song(ctx: &Ctx, a: &[String]) -> Result<(), String> {bpm: song.bpm,t0: 0.3,vibrato: 35.0,+ ..Default::default()},);v.schedule(&plan.gestures);@@ -557,7 +558,7 @@ pub fn notes(ctx: &Ctx, a: &[String]) -> Result<(), String> {if phrase.is_empty() {return;}- let plan = plan_song(phrase, &SongOptions { body: body_name.into(), bpm, t0: start, vibrato });+ let plan = plan_song(phrase, &SongOptions { body: body_name.into(), bpm, t0: start, vibrato, nasal_lead: j["nasalLead"].as_f64(), consonant_scale: j["consonantScale"].as_f64() });v.schedule(&plan.gestures);*end = js_max(*end, plan.end);phrase.clear();diff --git a/crates/chimera/src/phonetics/ipa.rs b/crates/chimera/src/phonetics/ipa.rsindex 850dce8..0c99192 100644--- a/crates/chimera/src/phonetics/ipa.rs+++ b/crates/chimera/src/phonetics/ipa.rs@@ -6,7 +6,7 @@ use serde::Deserialize;use std::collections::{HashMap, HashSet};use std::sync::OnceLock;-const VOWEL_CHARS: &str = "iyɨʉɯuɪʏʊeøɘɵɤoəɛœɜɞʌɔæɐaɶɑɒɝɚ";+const VOWEL_CHARS: &str = "iyɨʉɯuɪʏʊeøɘɵɤoəɛœɜɞʌɔæɐaɶɑɒɝɚɿʅ";const MULTI: [&str; 14] = ["tʃ", "dʒ", "ts", "dz", "pf", "tɕ", "dʑ", "tʂ", "dʐ", "aɪ", "aʊ", "ɔɪ", "eɪ", "oʊ"];const ALIASES: [(&str, &str); 9] = [("t͡ʃ", "tʃ"), ("d͡ʒ", "dʒ"), ("t͡s", "ts"), ("d͡z", "dz"), ("ɡ", "g"), ("ʧ", "tʃ"), ("ʤ", "dʒ"), ("r̥", "r"), ("ɐ̯", "ɐ")];diff --git a/crates/chimera/src/phonetics/mod.rs b/crates/chimera/src/phonetics/mod.rsindex bf1ab37..efad454 100644--- a/crates/chimera/src/phonetics/mod.rs+++ b/crates/chimera/src/phonetics/mod.rs@@ -120,6 +120,14 @@ pub struct Syllable {/// accent, a scoop); none: the note's pitch as written#[serde(default, skip_serializing_if = "Vec::is_empty")]pub pitch: Vec<Bend>,+ /// nasalise this fraction of the vowel before a nasal coda (at most 0.25 s), as Mandarin does;+ /// None: the song's SongOptions::nasal_lead+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub nasal_lead: Option<f64>,+ /// the share of a falling diphthong's held note its off-glide takes (Mandarin's ai ao ei ou glide+ /// over the last 35%); None: the planner's 20%+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub offglide: Option<f64>,}/// Which end of its sung vowel a pitch bend sits at.@@ -127,6 +135,8 @@ pub struct Syllable {#[serde(rename_all = "lowercase")]pub enum Edge {Start,+ /// centred on the vowel's middle (a dip or a peak inside the note: Mandarin's tone 3)+ Middle,End,}diff --git a/crates/chimera/src/phonetics/planner.rs b/crates/chimera/src/phonetics/planner.rsindex a9b0dc7..91061fa 100644--- a/crates/chimera/src/phonetics/planner.rs+++ b/crates/chimera/src/phonetics/planner.rs@@ -52,10 +52,56 @@ pub fn expand(ipa: &str) -> Option<&'static [&'static str]> {"eɪ" => &["e", "i"],"oʊ" => &["o", "u"],"ɚ" => &["ɝ"],+ // rising diphthongs: a short close glide into the main vowel (Mandarin's medials: 话 ua,+ // 天 iɛ, 学 yɛ), written as one nucleus so the glide sings on the beat, inside the note+ "ia" => &["i", "a"],+ "iɛ" => &["i", "ɛ"],+ "iɑ" => &["i", "ɑ"],+ "iʊ" => &["i", "ʊ"],+ "ua" => &["u", "a"],+ "uo" => &["u", "o"],+ "uɑ" => &["u", "ɑ"],+ "uə" => &["u", "ə"],+ "yɛ" => &["y", "ɛ"],+ "uɔ" => &["u", "ɔ"],+ // a central start, Mandarin's ou ([əʊ], where English [oʊ] starts nearly at [u])+ "əʊ" => &["ə", "ʊ"],+ // triphthongs: a glide into a falling diphthong (Mandarin iao, iou, uai, uei)+ "iaʊ" => &["i", "a", "ʊ"],+ "iəʊ" => &["i", "ə", "ʊ"],+ "uaɪ" => &["u", "a", "ɪ"],+ "ueɪ" => &["u", "e", "i"],_ => return None,})}+/// A rising nucleus (a rising diphthong or a triphthong): its first part is a short glide.+pub fn is_rising(ipa: &str) -> bool {+ matches!(ipa, "ia" | "iɛ" | "iɑ" | "iʊ" | "ua" | "uo" | "uɑ" | "uə" | "yɛ" | "uɔ" | "iaʊ" | "iəʊ" | "uaɪ" | "ueɪ")+}++/// A rising nucleus's on-glide (its first part), sung short at the note's start.+pub fn onglide(ipa: &str) -> Option<&'static str> {+ if is_rising(ipa) { expand(ipa).map(|p| p[0]) } else { None }+}++/// The vowel a sung note holds: a falling diphthong's first part, a rising nucleus's second, else+/// the vowel itself.+pub fn held_vowel(ipa: &str) -> &str {+ match expand(ipa) {+ Some(p) if p.len() >= 2 => p[usize::from(is_rising(ipa))],+ _ => ipa,+ }+}++/// What a held note glides off to at its end: a falling diphthong's (or a triphthong's) last part.+pub fn offglide(ipa: &str) -> Option<&'static str> {+ match expand(ipa) {+ Some(p) if p.len() == 3 || (p.len() == 2 && !is_rising(ipa)) => Some(p[p.len() - 1]),+ _ => None,+ }+}+/// The two vowel targets of a diphthong ("aɪ" → ("a", "ɪ")), or None.pub fn diphthong_parts(ipa: &str) -> Option<(&'static str, &'static str)> {match expand(ipa) {@@ -209,8 +255,15 @@ pub fn plan_utterance(input: &[Segment], o: &PlanOptions) -> Plan {for (si, s) in input.iter().enumerate() {if let Some(parts) = expand(&s.ipa) {let base = durs[si];+ // shares of the duration: a falling diphthong 55/45, a rising one 30/70, a triphthong 25/45/30+ let shares: &[f64] = match (parts.len(), is_rising(&s.ipa)) {+ (2, false) => &[0.55, 0.45],+ (2, true) => &[0.3, 0.7],+ (3, _) => &[0.25, 0.45, 0.3],+ _ => &[1.0],+ };for (i, p) in parts.iter().enumerate() {- let dur = if parts.len() > 1 { base * (if i == 0 { 0.55 } else { 0.45 }) } else { base };+ let dur = base * shares.get(i).copied().unwrap_or(1.0);segs.push(Seg { ipa: p, dur: Some(dur), stress: s.stress, f0: s.f0, def: None, vowel: None, glide_from: i > 0, aspirated: None, vot: None, nasalized: s.nasalized, palatalized: None, breathy: s.breathy });}} else {diff --git a/crates/chimera/src/phonetics/sing.rs b/crates/chimera/src/phonetics/sing.rsindex c4bb353..289b0d9 100644--- a/crates/chimera/src/phonetics/sing.rs+++ b/crates/chimera/src/phonetics/sing.rs@@ -12,8 +12,8 @@//! These planners allocate (they run off the audio thread).use super::inventory::phoneme;-use crate::anatomy::human::BodyMix;-use super::planner::{PlanOptions, diphthong_parts, plan_utterance};+use crate::anatomy::human::{ArticKey, BodyMix};+use super::planner::{PlanOptions, held_vowel, offglide, onglide, plan_utterance};use super::{Bend, Edge, Intonation, Plan, PlannedSegment, Segment, Syllable};use crate::control::score::{ControlKey, Gesture, Targets};use crate::math::{js_max, js_min};@@ -50,6 +50,12 @@ fn consonants_at(segs: &[Segment], body: BodyMix, k: f64, hz: f64) -> Vec<Segmenout}+/// a rising diphthong's glide lasts a quarter of its vowel, at most this long (s)+const RISING_GLIDE: f64 = 0.12;+/// A falling diphthong (or a triphthong) glides off over this share of its held part, unless its+/// syllable says (Syllable::offglide).+const OFFGLIDE: f64 = 0.2;+/// a sung vowel keeps at least this long when a short note squeezes its consonants (s)const MIN_VOWEL: f64 = 0.05;/// a squeezed consonant keeps at least this long (s); a flap is 16 ms@@ -100,6 +106,13 @@ pub struct SongOptions {pub t0: f64,/// vibrato depth (cents) on held vowelspub vibrato: f64,+ /// nasalise the vowel before a nasal coda for this fraction of the vowel (at most 0.25 s), as+ /// Mandarin singers do; None or 0: the velum lowers only for the nasal itself+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub nasal_lead: Option<f64>,+ /// sung consonant length relative to spoken (None: 0.8)+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub consonant_scale: Option<f64>,}/// A bend's blending strength against the note's own pitch (6): it wins while it lasts.@@ -115,6 +128,7 @@ fn bend_gestures(bends: &[Bend], hz: f64, a: f64, b: f64, out: &mut Vec<Gesture>let len = js_min(bend.len * d, bend.max);let (t0, t1) = match bend.at {Edge::Start => (a - 0.03, a + len),+ Edge::Middle => ((a + b - len) / 2.0, (a + b + len) / 2.0),Edge::End => (b - len, b + 0.02),};let f = hz * crate::math::pow(2.0, bend.st / 12.0);@@ -146,21 +160,21 @@ pub fn plan_song(notes: &[SungNote], o: &SongOptions) -> Plan {}let mut segs: Vec<Segment> = Vec::new();let mut vowel_spans: Vec<(f64, f64)> = Vec::new();- // (note, vowel start, vowel end) of the syllables with bends+ // (note, vowel start, vowel end) of syllables with bends, and of vowels before a nasal codalet mut bend_spans: Vec<(usize, f64, f64)> = Vec::new();+ let mut nasal_spans: Vec<(f64, f64, f64, &str)> = Vec::new();// each note's onset and coda consonants, at the note's pitch (a coda at the pitch of the// note whose syllable it ends; a melisma has neither)let hz_of = |k: usize| midi_to_hz(notes[k].midi);// a bend at the vowel's start begins in the onset: the consonants already sing its pitch, so- // a rising tone starts low instead of starting at the note and dipping. Without a start- // bend this is the note's pitch, exactly as before.- let onset_hz = |k: usize| match notes[k].syl.pitch.iter().find(|b| b.at == Edge::Start) {- Some(b) => hz_of(k) * crate::math::pow(2.0, b.st / 12.0),- None => hz_of(k),+ // a rising tone starts low instead of starting at the note and dipping+ let onset_hz = |k: usize| {+ let start = notes[k].syl.pitch.iter().find(|b| b.at == Edge::Start).map_or(0.0, |b| b.st);+ hz_of(k) * crate::math::pow(2.0, start / 12.0)};- let mut onsets: Vec<Vec<Segment>> = (i..=j).map(|k| if melisma(¬es[k].syl) { Vec::new() } else { consonants_at(¬es[k].syl.onset, o.body, 0.8, onset_hz(k)) }).collect();+ let mut onsets: Vec<Vec<Segment>> = (i..=j).map(|k| if melisma(¬es[k].syl) { Vec::new() } else { consonants_at(¬es[k].syl.onset, o.body, o.consonant_scale.unwrap_or(0.8), onset_hz(k)) }).collect();let mut codas: Vec<Vec<Segment>> = (i..=j)- .map(|k| if k < j && melisma(¬es[k + 1].syl) { Vec::new() } else { consonants_at(&last_of_chain(notes, k).coda, o.body, 0.8, hz_of(k)) })+ .map(|k| if k < j && melisma(¬es[k + 1].syl) { Vec::new() } else { consonants_at(&last_of_chain(notes, k).coda, o.body, o.consonant_scale.unwrap_or(0.8), hz_of(k)) }).collect();// the phrase's last vowel leaves a short breath before the next phrase. The call's last// phrase is followed by a rest (callers split phrases at rests), so the breath comes from@@ -183,15 +197,33 @@ pub fn plan_song(notes: &[SungNote], o: &SongOptions) -> Plan {// only consonants squeezed to their floor can leave less than MIN_VOWELlet vdur = js_max(0.02, note_end - times[k] - total(&coda));segs.extend(onset);- let parts = diphthong_parts(&n.syl.nucleus.ipa);- match parts {- Some((a, b)) if !next_melisma => {- segs.push(nucleus_part(a, vdur * 0.8, hz, &n.syl.nucleus));- segs.push(nucleus_part(b, vdur * 0.2, hz, &n.syl.nucleus));+ // the nucleus in time: a rising on-glide short on the beat (not on a melisma's later+ // notes), the vowel that holds, and a falling off-glide in the note's last fifth (not+ // when a melisma continues the vowel)+ let nuc = n.syl.nucleus.ipa.as_str();+ let on = onglide(nuc).filter(|_| !melisma(&n.syl));+ let g = if on.is_some() { js_min(0.25 * vdur, RISING_GLIDE) } else { 0.0 };+ if let Some(a) = on {+ segs.push(nucleus_part(a, g, hz, &n.syl.nucleus));+ }+ let rest = vdur - g;+ // a falling diphthong glides off over this share of its held part (the front end may say)+ let glide_off = n.syl.offglide.unwrap_or(OFFGLIDE);+ match offglide(nuc).filter(|_| !next_melisma) {+ Some(b) => {+ segs.push(nucleus_part(held_vowel(nuc), rest * (1.0 - glide_off), hz, &n.syl.nucleus));+ segs.push(nucleus_part(b, rest * glide_off, hz, &n.syl.nucleus));}- _ => {- let ipa = parts.map_or(n.syl.nucleus.ipa.clone(), |p| p.0.to_string());- segs.push(nucleus_part(&ipa, vdur, hz, &n.syl.nucleus));+ None => segs.push(nucleus_part(held_vowel(nuc), rest, hz, &n.syl.nucleus)),+ }+ if coda.first().is_some_and(|c| matches!(c.ipa.as_str(), "m" | "n" | "ŋ")) {+ // the syllable whose coda this is decides (a melisma's coda is its parent's)+ let lead = last_of_chain(notes, k).nasal_lead.or(o.nasal_lead).unwrap_or(0.0);+ if lead > 0.0 {+ // the tongue body's rise toward -ng after the back vowel ɑ (ang, iang, uang); after+ // other vowels, and toward -n, it measured no better or worse+ let place = if coda[0].ipa == "ŋ" && held_vowel(nuc) == "ɑ" { "velar" } else { "" };+ nasal_spans.push((times[k], times[k] + vdur, lead, place));}}segs.extend(coda);@@ -209,6 +241,21 @@ pub fn plan_song(notes: &[SungNote], o: &SongOptions) -> Plan {for &(k, a, b) in &bend_spans {bend_gestures(¬es[k].syl.pitch, hz_of(k), a, b, &mut gestures);}+ for &(a, b, lead, place) in &nasal_spans {+ let t0 = b - js_min(lead * (b - a), 0.25);+ gestures.push(Gesture::new(t0, b + 0.02, 0.06, 0.03, 4.0, Targets::default().with(ArticKey::Velum, 0.3)).label("nasal vowel"));+ // and the tongue on its way to the coda's place, which is where -n and -ng differ+ // in the vowel: the body rising toward the velum for -ng, the tip toward the ridge+ // for -n (short of closure; the coda closes)+ let approach = match place {+ "velar" => Some(Targets::default().with(ArticKey::TbY, 7.95)),+ "alveolar" => Some(Targets::default().with(ArticKey::TtX, 6.2).with(ArticKey::TtY, 9.3)),+ _ => None,+ };+ if let Some(t) = approach {+ gestures.push(Gesture::new(t0, b + 0.02, 0.06, 0.03, 2.5, t).label("coda approach"));+ }+ }for (a, b) in vowel_spans {if b - a > 0.3 {gestures.push(vibrato_gesture(a, b, o.vibrato, None));@@ -263,8 +310,10 @@ pub fn plan_note_on(syl: &Syllable, midi: f64, o: &NoteOnOptions) -> Vec<Gesturesegs.extend(tail(&l.syl, o.body, midi_to_hz(l.midi)));}segs.extend(consonants(&syl.onset, o.body, 0.7));- let parts = diphthong_parts(&syl.nucleus.ipa);- segs.push(nucleus_part(parts.map_or(syl.nucleus.ipa.as_str(), |p| p.0), HOLD, hz, &syl.nucleus));+ if let Some(a) = onglide(&syl.nucleus.ipa) {+ segs.push(nucleus_part(a, RISING_GLIDE * 0.6, hz, &syl.nucleus));+ }+ segs.push(nucleus_part(held_vowel(&syl.nucleus.ipa), HOLD, hz, &syl.nucleus));let plan = plan_utterance(&segs, &PlanOptions { body: o.body, t0: LIVE_T0, f0: Some(hz), intonation: Some(Intonation::Flat), open_end: Some(true), ..Default::default() });let vowel = &plan.segments[plan.segments.len() - 1];let mut out: Vec<Gesture> = plan.gestures.iter().map(|g| g.tag(if g.targets.has(ControlKey::F0) { o.tag + 1.0 } else { o.tag })).collect();@@ -300,9 +349,9 @@ pub fn plan_note_off(syl: &Syllable, midi: f64, body: BodyMix) -> Vec<Gesture> {/// What follows a held vowel: the diphthong's glide (at the note's pitch) and the coda.fn tail(syl: &Syllable, body: BodyMix, hz: f64) -> Vec<Segment> {- let parts = diphthong_parts(&syl.nucleus.ipa);let mut out: Vec<Segment> = Vec::new();- if let Some((_, b)) = parts {+ // a falling diphthong (or a triphthong) glides off at the end; a rising one already holds its vowel+ if let Some(b) = offglide(&syl.nucleus.ipa) {out.push(nucleus_part(b, 0.07, hz, &syl.nucleus));}out.extend(consonants(&syl.coda, body, 0.7));diff --git a/crates/chimera/src/phonetics/vowelTargets.generated.json b/crates/chimera/src/phonetics/vowelTargets.generated.jsonindex 274b91e..3e0c0a4 100644--- a/crates/chimera/src/phonetics/vowelTargets.generated.json+++ b/crates/chimera/src/phonetics/vowelTargets.generated.json@@ -681,6 +681,68 @@0.1,-6.8]+ },+ "ɿ": {+ "artic": {+ "tbX": 2.851,+ "tbY": 7.604,+ "jaw": 0.191,+ "lipAp": 0.151,+ "lipProt": 0.327,+ "lipWidth": 0.55,+ "root": 0.871,+ "larynx": 0.313,+ "ttX": 6.373,+ "ttY": 7.441,+ "ttCurl": 0+ },+ "formants": [+ 360,+ 1401,+ 2309,+ 3762+ ],+ "target": [+ 360,+ 1400,+ 2600+ ],+ "err": [+ -0.1,+ 0.1,+ -11.2+ ]+ },+ "ʅ": {+ "artic": {+ "tbX": 2.778,+ "tbY": 7.554,+ "jaw": 0.302,+ "lipAp": 0.23,+ "lipProt": 0.35,+ "lipWidth": 1,+ "root": -0.531,+ "larynx": -0.177,+ "ttX": 6.313,+ "ttY": 7.323,+ "ttCurl": 0+ },+ "formants": [+ 399,+ 1500,+ 2019,+ 3767+ ],+ "target": [+ 400,+ 1500,+ 2000+ ],+ "err": [+ -0.2,+ 0,+ 1+ ]}},"female": {@@ -1363,6 +1425,67 @@0,-4.2]+ },+ "ɿ": {+ "artic": {+ "tbX": 2.843,+ "tbY": 7.651,+ "jaw": 0.194,+ "lipAp": 0.301,+ "lipProt": 0.35,+ "lipWidth": 0.628,+ "root": 0.62,+ "larynx": 0.561,+ "ttX": 6.369,+ "ttY": 7.454,+ "ttCurl": 0+ },+ "formants": [+ 421,+ 1681,+ 2785+ ],+ "target": [+ 421,+ 1680,+ 2990+ ],+ "err": [+ -0.2,+ 0.1,+ -6.9+ ]+ },+ "ʅ": {+ "artic": {+ "tbX": 2.681,+ "tbY": 7.528,+ "jaw": 0.557,+ "lipAp": 0.419,+ "lipProt": 0.351,+ "lipWidth": 0.939,+ "root": -0.891,+ "larynx": -0.291,+ "ttX": 5.835,+ "ttY": 8.866,+ "ttCurl": 0.89+ },+ "formants": [+ 466,+ 1799,+ 2326,+ 3644+ ],+ "target": [+ 468,+ 1800,+ 2300+ ],+ "err": [+ -0.3,+ -0.1,+ 1.1+ ]}},"child": {@@ -2026,6 +2149,66 @@0,2.5]+ },+ "ɿ": {+ "artic": {+ "tbX": 2.909,+ "tbY": 7.768,+ "jaw": 0.194,+ "lipAp": 0.141,+ "lipProt": 0.35,+ "lipWidth": 0.549,+ "root": -0.314,+ "larynx": -0.165,+ "ttX": 6.389,+ "ttY": 7.496,+ "ttCurl": 0+ },+ "formants": [+ 468,+ 1862,+ 3280+ ],+ "target": [+ 468,+ 1862,+ 3224+ ],+ "err": [+ -0.1,+ 0,+ 1.8+ ]+ },+ "ʅ": {+ "artic": {+ "tbX": 2.243,+ "tbY": 7.515,+ "jaw": 0.411,+ "lipAp": 0.591,+ "lipProt": 0,+ "lipWidth": 0.549,+ "root": -0.9,+ "larynx": -1.27,+ "ttX": 5.785,+ "ttY": 8.853,+ "ttCurl": 0.821+ },+ "formants": [+ 518,+ 1992,+ 2648+ ],+ "target": [+ 520,+ 1995,+ 2480+ ],+ "err": [+ -0.3,+ -0.1,+ 6.8+ ]}}}\ No newline at end of filediff --git a/crates/chimera/src/phonetics/vowel_data.rs b/crates/chimera/src/phonetics/vowel_data.rsindex 2963d5b..b94e734 100644--- a/crates/chimera/src/phonetics/vowel_data.rs+++ b/crates/chimera/src/phonetics/vowel_data.rs@@ -63,4 +63,8 @@ pub static VOWELS: &[VowelRef] = &[vref("ɨ", "close central", [330.0, 1600.0, 2400.0], None, None, false, 0.0, 0.5),vref("ɯ", "close back unrounded", [340.0, 1350.0, 2400.0], None, None, false, 0.0, 1.0),vref("ɤ", "close-mid back unrounded", [460.0, 1250.0, 2450.0], None, None, false, 0.35, 1.0),+ // Mandarin's apical vowels: the -i of 四 si (after z c s) and of 是 shi (after zh ch sh r), the+ // consonant's tongue held open; the retroflex one has a low F3 (approximate male means)+ vref("ɿ", "Mandarin si (apical)", [360.0, 1400.0, 2600.0], None, None, false, 0.0, 0.45),+ vref("ʅ", "Mandarin shi (apical, retroflex)", [400.0, 1500.0, 2000.0], None, None, false, 0.05, 0.55),];diff --git a/crates/chimera/tests/aspiration.rs b/crates/chimera/tests/aspiration.rsindex 9b16257..912607b 100644--- a/crates/chimera/tests/aspiration.rs+++ b/crates/chimera/tests/aspiration.rs@@ -36,7 +36,7 @@ fn the_front_end_overrides_the_english_rule() {#[test]fn sung_onsets_keep_the_flag() {let syl = |aspirated| Syllable { text: "pa".into(), onset: vec![Segment { aspirated, ..Segment::new("p") }], nucleus: Segment::new("a"), coda: vec![], melisma: None, word_end: true, phrase_end: false, ..Default::default() };- let sing = |aspirated| aspiration(&plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(aspirated) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 }).gestures);+ let sing = |aspirated| aspiration(&plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(aspirated) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() }).gestures);assert_eq!(sing(None), 0.36);assert_eq!(sing(Some(false)), 0.22);}diff --git a/crates/chimera/tests/bends.rs b/crates/chimera/tests/bends.rsindex fbc350d..e43cfca 100644--- a/crates/chimera/tests/bends.rs+++ b/crates/chimera/tests/bends.rs@@ -1,27 +1,25 @@//! Pitch bends: a syllable's front end shapes the pitch inside its note (start or end, capped in-//! length); none leaves the note as written.+//! length); none leaves the note as written. And the vowel before a nasal coda is nasalised only+//! when asked.+use chimera::anatomy::human::ArticKey;use chimera::control::score::{ControlKey, Gesture};use chimera::phonetics::sing::{SongOptions, SungNote, midi_to_hz, plan_song};use chimera::phonetics::{Bend, Edge, Segment, Syllable};-fn syl(onset: &str, v: &str, pitch: Vec<Bend>) -> Syllable {- Syllable { text: v.into(), onset: vec![Segment::new(onset)], nucleus: Segment::new(v), word_end: true, pitch, ..Default::default() }+fn syl(onset: &str, v: &str, coda: &[&str], pitch: Vec<Bend>) -> Syllable {+ Syllable { text: v.into(), onset: vec![Segment::new(onset)], nucleus: Segment::new(v), coda: coda.iter().map(|c| Segment::new(c)).collect(), word_end: true, pitch, ..Default::default() }}-fn opts() -> SongOptions {- SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, ..Default::default() }+fn opts(nasal_lead: Option<f64>) -> SongOptions {+ SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, nasal_lead, ..Default::default() }}fn labelled<'a>(gs: &'a [Gesture], l: &str) -> Vec<&'a Gesture> {gs.iter().filter(|g| g.label.as_ref().is_some_and(|x| x.as_str() == l)).collect()}-/// the pitch targets of the gestures that end by the beat (the onset's)-fn onset_f0(gs: &[Gesture]) -> Vec<f64> {- labelled(gs, "pitch").into_iter().filter(|g| g.t1 <= 0.5 + 1e-9).filter_map(|g| g.targets.get(ControlKey::F0)).collect()-}#[test]fn bends_colour_the_start_or_end_of_the_note_and_none_leave_it() {let hz = midi_to_hz(57.0);- let one = |pitch| plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("l", "a", pitch) }], &opts());+ let one = |pitch| plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("l", "a", &[], pitch) }], &opts(None));assert!(labelled(&one(vec![]).gestures, "bend").is_empty());let up = Bend { at: Edge::Start, len: 0.35, max: 0.15, st: -2.0 };let down = Bend { at: Edge::End, len: 0.35, max: 0.15, st: -3.0 };@@ -36,34 +34,61 @@ fn bends_colour_the_start_or_end_of_the_note_and_none_leave_it() {}#[test]-fn no_bends_plan_exactly_as_before() {- let notes = [SungNote { midi: 57.0, beats: 1.0, syl: syl("m", "a", vec![]) }, SungNote { midi: 60.0, beats: 1.0, syl: syl("t", "i", vec![]) }];- let p = plan_song(¬es, &opts());- assert!(labelled(&p.gestures, "bend").is_empty());- // with an empty bend list serialised away, the syllables round-trip unchanged- let j = serde_json::to_value(¬es[0].syl).unwrap();- assert!(j.get("pitch").is_none());+fn a_bend_can_sit_in_the_middle_of_the_vowel() {+ // a dip inside the note (Mandarin's tone 3 as 214, in speech): centred on the vowel's middle+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("l", "a", &[], vec![Bend { at: Edge::Middle, len: 0.4, max: 0.3, st: -4.0 }]) }], &opts(None));+ let b = labelled(&p.gestures, "bend");+ assert_eq!(b.len(), 1);+ let (vowel_start, vowel_end) = p.segments.iter().find(|s| s.kind == "vowel").map(|s| (s.t0, s.t1)).unwrap();+ assert!(((b[0].t0 + b[0].t1) / 2.0 - (vowel_start + vowel_end) / 2.0).abs() < 1e-9, "centred");+ assert!((b[0].t1 - b[0].t0 - 0.3).abs() < 1e-9, "capped at max");}#[test]fn a_melisma_keeps_its_written_pitches() {let bend = vec![Bend { at: Edge::Start, len: 0.35, max: 0.15, st: -2.0 }];- let first = syl("l", "a", bend.clone());+ let first = syl("l", "a", &[], bend.clone());let cont = Syllable { text: "~".into(), nucleus: Segment::new("a"), melisma: Some(true), pitch: bend, ..Default::default() };- let p = plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: first }, SungNote { midi: 59.0, beats: 1.0, syl: cont }], &opts());+ let p = plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: first }, SungNote { midi: 59.0, beats: 1.0, syl: cont }], &opts(None));assert_eq!(labelled(&p.gestures, "bend").len(), 1, "only the syllable's first note bends");}+#[test]+fn nasal_lead_nasalises_only_before_a_nasal_coda() {+ let notes = vec![SungNote { midi: 57.0, beats: 2.0, syl: syl("ɕ", "i", &["ŋ"], vec![]) }, SungNote { midi: 59.0, beats: 2.0, syl: syl("t", "a", &[], vec![]) }];+ assert!(labelled(&plan_song(¬es, &opts(None)).gestures, "nasal vowel").is_empty());+ let p = plan_song(¬es, &opts(Some(0.4)));+ let nv = labelled(&p.gestures, "nasal vowel");+ assert_eq!(nv.len(), 1, "only the syllable with a nasal coda");+ assert!(nv[0].targets.get(ArticKey::Velum).unwrap() > 0.0);+ assert!(nv[0].t0 > 0.5 && nv[0].t1 < 0.5 + 2.0);+}+#[test]fn a_start_bend_begins_in_the_onset() {// a rising tone starts low: the onset consonant already sings the bend's pitch, not the note'slet hz = midi_to_hz(57.0);let up = Bend { at: Edge::Start, len: 0.35, max: 0.15, st: -3.0 };- let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", vec![up]) }], &opts());- let f = onset_f0(&p.gestures);- assert!(!f.is_empty());- assert!(f.iter().all(|f| (f / hz - 2f64.powf(-3.0 / 12.0)).abs() < 1e-9), "{f:?}");+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", &[], vec![up]) }], &opts(None));+ let onset_f0: Vec<f64> = p.gestures.iter().filter(|g| g.label.as_ref().is_some_and(|l| l.as_str() == "pitch") && g.t1 <= 0.5 + 1e-9).filter_map(|g| g.targets.get(ControlKey::F0)).collect();+ assert!(!onset_f0.is_empty());+ assert!(onset_f0.iter().all(|f| (f / hz - 2f64.powf(-3.0 / 12.0)).abs() < 1e-9), "{onset_f0:?}");// without a start bend the onset sings the note- let plain = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", vec![]) }], &opts());- assert!(onset_f0(&plain.gestures).iter().all(|f| (f - hz).abs() < 1e-9));+ let plain = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", &[], vec![]) }], &opts(None));+ assert!(plain.gestures.iter().filter(|g| g.label.as_ref().is_some_and(|l| l.as_str() == "pitch") && g.t1 <= 0.5 + 1e-9).filter_map(|g| g.targets.get(ControlKey::F0)).all(|f| (f - hz).abs() < 1e-9));+}++#[test]+fn before_ng_after_a_back_vowel_the_tongue_rises_toward_the_velum() {+ // in the nasal-lead window, -ng after ɑ gets the tongue body's approach; -n and other vowels don't+ let approach = |v: &str, coda: &str| {+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: Syllable { nasal_lead: Some(0.4), ..syl("t", v, &[coda], vec![]) } }], &opts(None));+ labelled(&p.gestures, "coda approach").len()+ };+ assert_eq!(approach("ɑ", "ŋ"), 1);+ assert_eq!(approach("ɑ", "n"), 0);+ assert_eq!(approach("ə", "ŋ"), 0);+ // no nasal lead, no approach+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("t", "ɑ", &["ŋ"], vec![]) }], &opts(None));+ assert!(labelled(&p.gestures, "coda approach").is_empty());}diff --git a/crates/chimera/tests/golden/phonetics-data.json b/crates/chimera/tests/golden/phonetics-data.jsonindex 680c242..9620fae 100644--- a/crates/chimera/tests/golden/phonetics-data.json+++ b/crates/chimera/tests/golden/phonetics-data.json@@ -1 +1 @@-{"songs":[{"name":"Made of air","bpm":84,"lyrics":"Breathe in, breathe out, I am made of air. Tongue and lips and throat, singing anywhere.","notes":[[64,1],[60,1],[62,1],[57,1],[57,0.5],[60,0.5],[64,1],[62,0.5],[60,1.5],[65,1],[64,0.5],[62,0.5],[60,0.5],[62,1.5],[64,0.5],[62,0.5],[60,0.5],[59,0.5],[57,2]],"octave":{"male":-1,"female":0,"child":0}},{"name":"Twinkle, twinkle","bpm":100,"lyrics":"Twinkle twinkle little star, how I wonder what you are.","notes":[[60,1],[60,1],[67,1],[67,1],[69,1],[69,1],[67,2],[65,1],[65,1],[64,1],[64,1],[62,1],[62,1],[60,2]],"octave":{"male":-1,"female":0,"child":0}}],"vowels":[{"ipa":"i","example":"heed","male":[342,2322,3000],"female":[437,2761,3372],"child":[452,3081,3702],"round":false,"height":0,"back":0},{"ipa":"ɪ","example":"hid","male":[427,2034,2684],"female":[483,2365,3053],"child":[511,2552,3403],"round":false,"height":0.2,"back":0.15},{"ipa":"e","example":"hayed","male":[476,2089,2691],"female":[536,2530,3047],"child":[564,2656,3323],"round":false,"height":0.3,"back":0.05},{"ipa":"ɛ","example":"head","male":[580,1799,2605],"female":[731,2058,2979],"child":[749,2267,3310],"round":false,"height":0.55,"back":0.1},{"ipa":"æ","example":"had","male":[640,1760,2500],"female":[669,2349,2972],"child":[717,2501,3289],"round":false,"height":0.8,"back":0.15},{"ipa":"a","example":"front open (Fr. patte)","male":[780,1450,2550],"female":[912.5999999999999,1740,2932.5],"child":[1014,1928.5,3162],"round":false,"height":1,"back":0.35},{"ipa":"ɑ","example":"hod","male":[768,1333,2522],"female":[936,1551,2815],"child":[1002,1688,2950],"round":false,"height":1,"back":0.85},{"ipa":"ɒ","example":"Br. lot","male":[620,880,2500],"female":[725.4,1056,2875],"child":[806,1170.4,3100],"round":true,"height":0.9,"back":1},{"ipa":"ɔ","example":"hawed","male":[652,997,2538],"female":[781,1136,2824],"child":[803,1210,2982],"round":true,"height":0.65,"back":1},{"ipa":"o","example":"hoed","male":[497,910,2459],"female":[555,1035,2828],"child":[597,1137,2987],"round":true,"height":0.35,"back":1},{"ipa":"ʊ","example":"hood","male":[469,1122,2434],"female":[519,1225,2827],"child":[568,1490,3072],"round":true,"height":0.2,"back":0.85},{"ipa":"u","example":"who'd","male":[378,997,2343],"female":[459,1105,2735],"child":[494,1345,2988],"round":true,"height":0,"back":1},{"ipa":"ʌ","example":"hud","male":[623,1200,2550],"female":[753,1426,2933],"child":[749,1546,3145],"round":false,"height":0.6,"back":0.7},{"ipa":"ə","example":"sofa","male":[500,1450,2450],"female":[585,1740,2817.5],"child":[650,1928.5,3038],"round":false,"height":0.5,"back":0.5},{"ipa":"ɐ","example":"near-open central","male":[640,1350,2500],"female":[748.8,1620,2875],"child":[832,1795.5,3100],"round":false,"height":0.8,"back":0.5},{"ipa":"ɝ","example":"heard","male":[474,1379,1710],"female":[523,1588,1929],"child":[586,1719,2143],"round":true,"height":0.45,"back":0.5},{"ipa":"y","example":"Fr. tu","male":[300,1800,2150],"female":[351,2160,2472.5],"child":[390,2394,2666],"round":true,"height":0,"back":0},{"ipa":"ø","example":"Fr. peu","male":[390,1550,2250],"female":[456.29999999999995,1860,2587.5],"child":[507,2061.5,2790],"round":true,"height":0.3,"back":0.1},{"ipa":"œ","example":"Fr. peur","male":[520,1450,2350],"female":[608.4,1740,2702.5],"child":[676,1928.5,2914],"round":true,"height":0.55,"back":0.15},{"ipa":"ɨ","example":"close central","male":[330,1600,2400],"female":[386.09999999999997,1920,2760],"child":[429,2128,2976],"round":false,"height":0,"back":0.5},{"ipa":"ɯ","example":"close back unrounded","male":[340,1350,2400],"female":[397.79999999999995,1620,2760],"child":[442,1795.5,2976],"round":false,"height":0,"back":1},{"ipa":"ɤ","example":"close-mid back unrounded","male":[460,1250,2450],"female":[538.1999999999999,1500,2817.5],"child":[598,1662.5,3038],"round":false,"height":0.35,"back":1}]}\ No newline at end of file+{"songs":[{"name":"Made of air","bpm":84,"lyrics":"Breathe in, breathe out, I am made of air. Tongue and lips and throat, singing anywhere.","notes":[[64,1],[60,1],[62,1],[57,1],[57,0.5],[60,0.5],[64,1],[62,0.5],[60,1.5],[65,1],[64,0.5],[62,0.5],[60,0.5],[62,1.5],[64,0.5],[62,0.5],[60,0.5],[59,0.5],[57,2]],"octave":{"male":-1,"female":0,"child":0}},{"name":"Twinkle, twinkle","bpm":100,"lyrics":"Twinkle twinkle little star, how I wonder what you are.","notes":[[60,1],[60,1],[67,1],[67,1],[69,1],[69,1],[67,2],[65,1],[65,1],[64,1],[64,1],[62,1],[62,1],[60,2]],"octave":{"male":-1,"female":0,"child":0}}],"vowels":[{"ipa":"i","example":"heed","male":[342,2322,3000],"female":[437,2761,3372],"child":[452,3081,3702],"round":false,"height":0,"back":0},{"ipa":"ɪ","example":"hid","male":[427,2034,2684],"female":[483,2365,3053],"child":[511,2552,3403],"round":false,"height":0.2,"back":0.15},{"ipa":"e","example":"hayed","male":[476,2089,2691],"female":[536,2530,3047],"child":[564,2656,3323],"round":false,"height":0.3,"back":0.05},{"ipa":"ɛ","example":"head","male":[580,1799,2605],"female":[731,2058,2979],"child":[749,2267,3310],"round":false,"height":0.55,"back":0.1},{"ipa":"æ","example":"had","male":[640,1760,2500],"female":[669,2349,2972],"child":[717,2501,3289],"round":false,"height":0.8,"back":0.15},{"ipa":"a","example":"front open (Fr. patte)","male":[780,1450,2550],"female":[912.5999999999999,1740,2932.5],"child":[1014,1928.5,3162],"round":false,"height":1,"back":0.35},{"ipa":"ɑ","example":"hod","male":[768,1333,2522],"female":[936,1551,2815],"child":[1002,1688,2950],"round":false,"height":1,"back":0.85},{"ipa":"ɒ","example":"Br. lot","male":[620,880,2500],"female":[725.4,1056,2875],"child":[806,1170.4,3100],"round":true,"height":0.9,"back":1},{"ipa":"ɔ","example":"hawed","male":[652,997,2538],"female":[781,1136,2824],"child":[803,1210,2982],"round":true,"height":0.65,"back":1},{"ipa":"o","example":"hoed","male":[497,910,2459],"female":[555,1035,2828],"child":[597,1137,2987],"round":true,"height":0.35,"back":1},{"ipa":"ʊ","example":"hood","male":[469,1122,2434],"female":[519,1225,2827],"child":[568,1490,3072],"round":true,"height":0.2,"back":0.85},{"ipa":"u","example":"who'd","male":[378,997,2343],"female":[459,1105,2735],"child":[494,1345,2988],"round":true,"height":0,"back":1},{"ipa":"ʌ","example":"hud","male":[623,1200,2550],"female":[753,1426,2933],"child":[749,1546,3145],"round":false,"height":0.6,"back":0.7},{"ipa":"ə","example":"sofa","male":[500,1450,2450],"female":[585,1740,2817.5],"child":[650,1928.5,3038],"round":false,"height":0.5,"back":0.5},{"ipa":"ɐ","example":"near-open central","male":[640,1350,2500],"female":[748.8,1620,2875],"child":[832,1795.5,3100],"round":false,"height":0.8,"back":0.5},{"ipa":"ɝ","example":"heard","male":[474,1379,1710],"female":[523,1588,1929],"child":[586,1719,2143],"round":true,"height":0.45,"back":0.5},{"ipa":"y","example":"Fr. tu","male":[300,1800,2150],"female":[351,2160,2472.5],"child":[390,2394,2666],"round":true,"height":0,"back":0},{"ipa":"ø","example":"Fr. peu","male":[390,1550,2250],"female":[456.29999999999995,1860,2587.5],"child":[507,2061.5,2790],"round":true,"height":0.3,"back":0.1},{"ipa":"œ","example":"Fr. peur","male":[520,1450,2350],"female":[608.4,1740,2702.5],"child":[676,1928.5,2914],"round":true,"height":0.55,"back":0.15},{"ipa":"ɨ","example":"close central","male":[330,1600,2400],"female":[386.09999999999997,1920,2760],"child":[429,2128,2976],"round":false,"height":0,"back":0.5},{"ipa":"ɯ","example":"close back unrounded","male":[340,1350,2400],"female":[397.79999999999995,1620,2760],"child":[442,1795.5,2976],"round":false,"height":0,"back":1},{"ipa":"ɤ","example":"close-mid back unrounded","male":[460,1250,2450],"female":[538.1999999999999,1500,2817.5],"child":[598,1662.5,3038],"round":false,"height":0.35,"back":1},{"ipa":"ɿ","example":"Mandarin si (apical)","male":[360.0,1400.0,2600.0],"female":[421.2,1680.0,2989.9999999999995],"child":[468.0,1862.0,3224.0],"round":false,"height":0.0,"back":0.45},{"ipa":"ʅ","example":"Mandarin shi (apical, retroflex)","male":[400.0,1500.0,2000.0],"female":[468.0,1800.0,2300.0],"child":[520.0,1995.0,2480.0],"round":false,"height":0.05,"back":0.55}]}\ No newline at end of filediff --git a/crates/chimera/tests/rising.rs b/crates/chimera/tests/rising.rsnew file mode 100644index 0000000..a7b378e--- /dev/null+++ b/crates/chimera/tests/rising.rs@@ -0,0 +1,34 @@+//! Rising diphthongs (Mandarin's medials as one nucleus): sung, the glide comes on the beat and is+//! short, and the second vowel holds; a held melisma continues the vowel, not the glide.+use chimera::phonetics::sing::{SongOptions, SungNote, plan_song};+use chimera::phonetics::{Segment, Syllable};++fn vowels(nucleus: &str, beats: f64) -> Vec<(String, f64)> {+ let syl = Syllable { text: "x".into(), onset: vec![Segment::new("x")], nucleus: Segment::new(nucleus), word_end: true, ..Default::default() };+ let p = plan_song(&[SungNote { midi: 57.0, beats, syl }], &SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, ..Default::default() });+ p.segments.iter().filter(|s| s.kind == "vowel").map(|s| (s.ipa.clone(), s.t1 - s.t0)).collect()+}++#[test]+fn a_rising_diphthong_sings_a_short_glide_then_holds_its_vowel() {+ let v = vowels("ua", 2.0);+ assert_eq!(v.iter().map(|x| x.0.as_str()).collect::<Vec<_>>(), ["u", "a"]);+ assert!(v[0].1 <= 0.12 + 1e-9, "the glide is at most 120 ms, got {}", v[0].1);+ assert!(v[1].1 > 1.5, "the vowel holds the note");+ // a falling diphthong is the other way round: the first vowel holds+ let f = vowels("aɪ", 2.0);+ assert!(f[0].1 > f[1].1);+}++#[test]+fn a_syllable_can_say_how_long_its_off_glide_is() {+ let glide = |offglide: Option<f64>| {+ let syl = Syllable { text: "x".into(), onset: vec![Segment::new("x")], nucleus: Segment::new("aɪ"), word_end: true, offglide, ..Default::default() };+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl }], &SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, ..Default::default() });+ let v: Vec<f64> = p.segments.iter().filter(|s| s.kind == "vowel").map(|s| s.t1 - s.t0).collect();+ v[1] / (v[0] + v[1])+ };+ // the planner's 20% when unsaid (as before), the syllable's share when said+ assert!((glide(None) - 0.2).abs() < 1e-9);+ assert!((glide(Some(0.35)) - 0.35).abs() < 1e-9);+}diff --git a/crates/chimera/tests/sing_fast.rs b/crates/chimera/tests/sing_fast.rsindex 8ead686..4d56d54 100644--- a/crates/chimera/tests/sing_fast.rs+++ b/crates/chimera/tests/sing_fast.rs@@ -17,7 +17,7 @@ fn sing(lyrics: &str, beats: f64, bpm: f64) -> (Vec<SungNote>, Vec<f64>, Plan) {let syl = lyrics_to_syllables(lyrics, &g2p());let notes: Vec<SungNote> = syl.iter().enumerate().map(|(i, s)| SungNote { midi: if i % 2 == 0 { 60.0 } else { 64.0 }, beats, syl: s.clone() }).collect();let times = (0..notes.len()).map(|i| 0.5 + i as f64 * beats * 60.0 / bpm).collect();- let plan = plan_song(¬es, &SongOptions { body: "male".into(), bpm, t0: 0.5, vibrato: 0.0 });+ let plan = plan_song(¬es, &SongOptions { body: "male".into(), bpm, t0: 0.5, vibrato: 0.0, ..Default::default() });(notes, times, plan)}@@ -84,7 +84,7 @@ fn a_delayed_cluster_closure_stays_inside_a_short_sung_stop() {g.load_dict("harped\tHH AA1 R P T\nah\tAA1\n");let syl = lyrics_to_syllables("harped ah harped ah", &g);let notes: Vec<SungNote> = syl.iter().map(|s| SungNote { midi: 60.0, beats: 0.25, syl: s.clone() }).collect();- let plan = plan_song(¬es, &SongOptions { body: "male".into(), bpm: 180.0, t0: 0.5, vibrato: 0.0 });+ let plan = plan_song(¬es, &SongOptions { body: "male".into(), bpm: 180.0, t0: 0.5, vibrato: 0.0, ..Default::default() });let ts: Vec<_> = plan.segments.iter().enumerate().filter(|(i, s)| s.ipa == "t" && *i > 0 && plan.segments[i - 1].ipa == "p").map(|(_, s)| s.clone()).collect();assert!(!ts.is_empty());for t in ts {diff --git a/crates/chimera/tests/sound_marks.rs b/crates/chimera/tests/sound_marks.rsindex e7938ac..ada9ac5 100644--- a/crates/chimera/tests/sound_marks.rs+++ b/crates/chimera/tests/sound_marks.rs@@ -97,7 +97,7 @@ fn syl(onset: Vec<Segment>, nucleus: Segment) -> Syllable {#[test]fn a_sung_vowel_keeps_its_nasalization() {let nucleus = |n: Option<bool>| Segment { nasalized: n, ..Segment::new("ɛ") };- let sung = |n| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(vec![Segment::new("p")], nucleus(n)) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 });+ let sung = |n| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(vec![Segment::new("p")], nucleus(n)) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() });assert_eq!(labelled(&sung(Some(true)).gestures, "velum").len(), 1);assert!(labelled(&sung(None).gestures, "velum").is_empty());// a live note@@ -106,7 +106,7 @@ fn a_sung_vowel_keeps_its_nasalization() {assert!(labelled(&live(None), "velum").is_empty());// a nasalized diphthong, sung: each half is a vowel of its ownlet diph = Segment { nasalized: Some(true), ..Segment::new("aɪ") };- let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl(vec![], diph) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 });+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl(vec![], diph) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() });assert_eq!(labelled(&p.gestures, "velum").len(), 2);}@@ -269,7 +269,7 @@ fn a_breathy_vowel_parts_the_folds_for_the_whole_vowel() {#[test]fn sung_syllables_keep_their_breathiness() {- let song = |onset: Vec<Segment>, nucleus: Segment| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(onset, nucleus) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 });+ let song = |onset: Vec<Segment>, nucleus: Segment| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(onset, nucleus) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() });let live = |onset: Vec<Segment>, nucleus: Segment| plan_note_on(&syl(onset, nucleus), 57.0, &NoteOnOptions { body: "male".into(), vibrato: 0.0, tag: 1.0, legato_from: None });let (b, b_soft) = (Segment::new("b"), Segment { breathy: Some(true), ..Segment::new("b") });let (a, a_soft) = (Segment::new("a"), Segment { breathy: Some(true), ..Segment::new("a") });@@ -284,7 +284,7 @@ fn sung_syllables_keep_their_breathiness() {#[test]fn a_sung_consonant_keeps_its_palatalization() {let onset = |soft| vec![Segment { palatalized: soft, ..Segment::new("t") }];- let sung = |s| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(onset(s), Segment::new("a")) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 });+ let sung = |s| plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: syl(onset(s), Segment::new("a")) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() });assert_eq!(labelled(&sung(Some(true)).gestures, "palatalized").len(), 1);assert!(labelled(&sung(None).gestures, "palatalized").is_empty());let live = |s| plan_note_on(&syl(onset(s), Segment::new("a")), 57.0, &NoteOnOptions { body: "male".into(), vibrato: 0.0, tag: 1.0, legato_from: None });@@ -292,6 +292,6 @@ fn a_sung_consonant_keeps_its_palatalization() {assert!(labelled(&live(None), "palatalized").is_empty());// a coda toolet coda = |s| Syllable { coda: onset(s), ..syl(vec![], Segment::new("a")) };- let p = plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: coda(Some(true)) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0 });+ let p = plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: coda(Some(true)) }], &SongOptions { body: "male".into(), bpm: 90.0, t0: 0.5, vibrato: 0.0, ..Default::default() });assert_eq!(labelled(&p.gestures, "palatalized").len(), 1);}diff --git a/src/ui/analysis.ts b/src/ui/analysis.tsindex 0d3d3f8..4606638 100644--- a/src/ui/analysis.ts+++ b/src/ui/analysis.ts@@ -4,8 +4,12 @@* vowel-space interpolation for the vowel map. Never runs inside the audio thread.*/import { airwayModel, dropAirwayModel, airwayFrame, airwayAreas, airwayTransfer, TractMap, NEUTRAL, ARTIC_KEYS, VOWELS, VOWEL_TARGETS, type AirwayModel, type HumanArtic, type HumanBody, type HumanFrame } from "../wasm/engine.ts";+import { bodyWeights, type BodyMix } from "./body.ts";+/** apical vowels: sung, but not points in the vowel space */+const APICAL = new Set(["ɿ", "ʅ"]);+export interface VowelPoint {ipa: string;example: string;@@ -41,7 +45,9 @@ export class VoiceModel {const parts = bodyWeights(body).filter(([, w]) => w > 0).map(([n, w]) => ({ w, table: VOWEL_TARGETS[n] ?? {} }));- this.vowels = VOWELS.filter((v) => parts.every((p) => p.table[v.ipa])).map((v) => {+ // the vowel space (chart, pad, readouts) leaves out the apical vowels ɿ ʅ (Mandarin 四 si, 是 shi):+ // a consonant's tongue held open, not a point among the vowels; the planner still sings them+ this.vowels = VOWELS.filter((v) => !APICAL.has(v.ipa) && parts.every((p) => p.table[v.ipa])).map((v) => {const at = (f: (t: (typeof parts)[number]["table"][string]) => number | undefined) => {let acc = 0, ws = 0;for (const p of parts) {diff --git a/src/wasm/types.ts b/src/wasm/types.tsindex 7983f4f..a9441f8 100644--- a/src/wasm/types.ts+++ b/src/wasm/types.ts@@ -209,11 +209,15 @@ export interface Syllable {phraseEnd: boolean;/** pitch bends inside the sung note, written by the syllable's front end (a tone, an accent) */pitch?: Bend[];+ /** nasalise this fraction of the vowel before a nasal coda (unset: none) */+ nasalLead?: number;+ /** the share of a falling diphthong's note its off-glide takes (unset: 20%) */+ offglide?: number;}/** A bend of the pitch inside a sung note: `st` semitones, at its vowel's start or end, over `len` of the vowel (at most `max` s). */export interface Bend {- at: "start" | "end";+ at: "start" | "middle" | "end";len: number;max: number;st: number;