Skip to content

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

Rust

Drop the song-wide tuning knobs: SongOptions.nasal_lead and consonant_scale, and render notes' "nasalLead" and "consonantScale"

Joshua Pham20b882ab02b5
diff --git a/crates/chimera-cli/src/render.rs b/crates/chimera-cli/src/render.rs
index 5816756..3ea06e9 100644
--- a/crates/chimera-cli/src/render.rs
+++ b/crates/chimera-cli/src/render.rs
@@ -287,7 +287,6 @@ pub fn song(ctx: &Ctx, a: &[String]) -> Result<(), String> {
bpm: song.bpm,
t0: 0.3,
vibrato: 35.0,
- ..Default::default()
},
);
v.schedule(&plan.gestures);
@@ -521,8 +520,7 @@ fn render_tracked(v: &mut HumanVoice, out: &mut [f32], artic: bool, tele: bool)
/// sync; `--tele` writes the voice's whole telemetry over time (see `TeleRecorder`), which the
/// app's duet page replays on a 3D head. The melody file may give `"syllables"` (IPA
/// onset/nucleus/coda per sounding note, optional `"pitch"` bends) instead of `"lyrics"`: a
-/// language front end's output (docs/language-front-ends.md). Optional sing-planner settings:
-/// `"nasalLead"`, `"consonantScale"`.
+/// language front end's output (docs/language-front-ends.md).
pub fn notes(ctx: &Ctx, a: &[String]) -> Result<(), String> {
let mut artic_out: Option<String> = None;
let mut tele_out: Option<String> = None;
@@ -577,7 +575,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, nasal_lead: j["nasalLead"].as_f64(), consonant_scale: j["consonantScale"].as_f64() });
+ let plan = plan_song(phrase, &SongOptions { body: body_name.into(), bpm, t0: start, vibrato });
v.schedule(&plan.gestures);
*end = js_max(*end, plan.end);
phrase.clear();
diff --git a/crates/chimera/src/phonetics/sing.rs b/crates/chimera/src/phonetics/sing.rs
index 289b0d9..ff6a3db 100644
--- a/crates/chimera/src/phonetics/sing.rs
+++ b/crates/chimera/src/phonetics/sing.rs
@@ -106,13 +106,6 @@ pub struct SongOptions {
pub t0: f64,
/// vibrato depth (cents) on held vowels
pub 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.
@@ -172,9 +165,9 @@ pub fn plan_song(notes: &[SungNote], o: &SongOptions) -> Plan {
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(&notes[k].syl) { Vec::new() } else { consonants_at(&notes[k].syl.onset, o.body, o.consonant_scale.unwrap_or(0.8), onset_hz(k)) }).collect();
+ let mut onsets: Vec<Vec<Segment>> = (i..=j).map(|k| if melisma(&notes[k].syl) { Vec::new() } else { consonants_at(&notes[k].syl.onset, o.body, 0.8, onset_hz(k)) }).collect();
let mut codas: Vec<Vec<Segment>> = (i..=j)
- .map(|k| if k < j && melisma(&notes[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)) })
+ .map(|k| if k < j && melisma(&notes[k + 1].syl) { Vec::new() } else { consonants_at(&last_of_chain(notes, k).coda, o.body, 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
@@ -218,7 +211,7 @@ pub fn plan_song(notes: &[SungNote], o: &SongOptions) -> Plan {
}
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);
+ let lead = last_of_chain(notes, k).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
diff --git a/crates/chimera/tests/bends.rs b/crates/chimera/tests/bends.rs
index e43cfca..12496a4 100644
--- a/crates/chimera/tests/bends.rs
+++ b/crates/chimera/tests/bends.rs
@@ -9,8 +9,8 @@ use chimera::phonetics::{Bend, Edge, Segment, Syllable};
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(nasal_lead: Option<f64>) -> SongOptions {
- SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, nasal_lead, ..Default::default() }
+fn opts() -> SongOptions {
+ SongOptions { body: "male".into(), bpm: 60.0, t0: 0.5, ..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()
@@ -19,7 +19,7 @@ fn labelled<'a>(gs: &'a [Gesture], l: &str) -> Vec<&'a Gesture> {
#[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(None));
+ let one = |pitch| plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("l", "a", &[], pitch) }], &opts());
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,7 +36,7 @@ fn bends_colour_the_start_or_end_of_the_note_and_none_leave_it() {
#[test]
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 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());
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();
@@ -49,15 +49,16 @@ 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 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(None));
+ let p = plan_song(&[SungNote { midi: 57.0, beats: 1.0, syl: first }, SungNote { midi: 59.0, beats: 1.0, syl: cont }], &opts());
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(&notes, &opts(None)).gestures, "nasal vowel").is_empty());
- let p = plan_song(&notes, &opts(Some(0.4)));
+ // the syllable says its nasal lead (a front end: Mandarin's 0.4); unsaid, none
+ let notes = |lead| vec![SungNote { midi: 57.0, beats: 2.0, syl: Syllable { nasal_lead: lead, ..syl("ɕ", "i", &["ŋ"], vec![]) } }, SungNote { midi: 59.0, beats: 2.0, syl: Syllable { nasal_lead: lead, ..syl("t", "a", &[], vec![]) } }];
+ assert!(labelled(&plan_song(&notes(None), &opts()).gestures, "nasal vowel").is_empty());
+ let p = plan_song(&notes(Some(0.4)), &opts());
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);
@@ -69,12 +70,12 @@ 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's
let 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(None));
+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", &[], vec![up]) }], &opts());
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(None));
+ let plain = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("m", "a", &[], vec![]) }], &opts());
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));
}
@@ -82,13 +83,13 @@ fn a_start_bend_begins_in_the_onset() {
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));
+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: Syllable { nasal_lead: Some(0.4), ..syl("t", v, &[coda], vec![]) } }], &opts());
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));
+ let p = plan_song(&[SungNote { midi: 57.0, beats: 2.0, syl: syl("t", "ɑ", &["ŋ"], vec![]) }], &opts());
assert!(labelled(&p.gestures, "coda approach").is_empty());
}