feat: stable note tracking, NOTE pitch source and unsure fallback
Producers found the tracked plugins jumpy: the shared tracker switched notes after 10 ms and retuned every 5 ms, so growls and formant basses flickered and every tracked plugin acted on wrong notes. Shared tracker (common-dsp): - A new note needs a steady read for 40 ms; an octave down 80 ms, an octave up 200 ms (an octave-up read still fits the note's period and counts as agreeing). Inside a note the tuning only moves past a 0.25 semitone deadband. Follow bends keeps the old fast behaviour as an option. - A trust score turns the note unsure while reads disagree; Tracker::active and NoteState report it, and Fallback latches "step back" across note ends. - Notes end when the window start stays below the gate's release level for 20 ms, so short gaps between notes are seen without waiting for the gate. - PitchSource replaces the old (midi, gate, glide) arguments: Audio, MIDI or Note mode (a set note, no detection), plus a key lock (minor, major, root only) that snaps reads to the key. - stems.rs: synthetic stems (growls, wobble, reese, formant, 808 slide, layered drop, noise riser) and a score; examples/tracker_report scores the corpus or real WAV stems. On the corpus the old behaviour makes up to 28 extra note starts per second; the stable default makes none. Plugins: - Anvil, Lathe, Temper, Knurl, Planish, Braze and Forge gain the NOTE pitch source, the key lock and Follow bends (shared common-params crate and a shared header switch in common-ui). - Unsure tracking: Anvil brings the original sub back in place of the sine, Lathe passes the audio through, Knurl fades its texture out; Temper, Planish and Braze hold their last sure tuning. Readouts show the note only when it is sure. - Anvil gains Mode: Replace or Enhance (keeps the original sub and adds the sine under it). - Planish slides its band edges over 6 ms on a new note instead of snapping. - Ballast defaults to Grid parts, which need no tracking.
This commit is contained in:
1 parent
7c873f2bd0
commit
adfb2c0287
66 files changed
+2246
-261
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use common_dsp::meter::HarmonicMeter;
|
||||
use common_dsp::oversample::Oversampler;
|
||||
use common_dsp::svf::{Svf, SvfCoef};
|
||||
use common_dsp::tracker::{NoteEvent, Tracker, TrackerConfig};
|
||||
use common_dsp::tracker::{NoteEvent, PitchMode, PitchSource, Scale, Tracker, TrackerConfig};
|
||||
use common_dsp::{hz_to_midi, Saw};
|
||||
use std::f32::consts::TAU;
|
||||
|
||||
@@ -174,7 +174,7 @@ fn harmonic_meter_reads_saw_harmonics() {
|
||||
#[test]
|
||||
fn tracker_reports_notes_at_output_time() {
|
||||
let mut t = Tracker::new(RATE, TrackerConfig::BASS);
|
||||
t.set(false, -42., false);
|
||||
t.set(PitchSource::default());
|
||||
let l = t.latency();
|
||||
assert!(l < (0.08 * RATE) as usize, "{l}");
|
||||
let onset = 4800;
|
||||
@@ -210,7 +210,11 @@ fn tracker_reports_notes_at_output_time() {
|
||||
#[test]
|
||||
fn tracker_delays_midi_by_the_latency() {
|
||||
let mut t = Tracker::new(RATE, TrackerConfig::BASS);
|
||||
assert!(t.set(true, -42., true));
|
||||
assert!(t.set(PitchSource {
|
||||
mode: PitchMode::Midi,
|
||||
glide: true,
|
||||
..PitchSource::default()
|
||||
}));
|
||||
let l = t.latency();
|
||||
let mut events = vec![];
|
||||
for i in 0..l + 2000 {
|
||||
@@ -248,3 +252,127 @@ fn tracker_delays_midi_by_the_latency() {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_tracker_holds_its_notes_on_the_stem_corpus() {
|
||||
let stable = PitchSource::default();
|
||||
let bends = PitchSource {
|
||||
bends: true,
|
||||
..stable
|
||||
};
|
||||
let (mut extra_stable, mut extra_bends) = (0., 0.);
|
||||
for stem in common_dsp::stems::all(RATE) {
|
||||
let s = common_dsp::stems::score(
|
||||
RATE,
|
||||
TrackerConfig::BASS,
|
||||
stable,
|
||||
&stem.samples,
|
||||
&stem.truth,
|
||||
);
|
||||
let b =
|
||||
common_dsp::stems::score(RATE, TrackerConfig::BASS, bends, &stem.samples, &stem.truth);
|
||||
assert!(s.extra_starts <= 0.25, "{}: {s:?}", stem.name);
|
||||
assert!(s.wrong <= 0.05, "{}: {s:?}", stem.name);
|
||||
assert!(s.wrong <= b.wrong + 0.005, "{}: {s:?} vs {b:?}", stem.name);
|
||||
extra_stable += s.extra_starts;
|
||||
extra_bends += b.extra_starts;
|
||||
}
|
||||
// Follow bends keeps the fast 0.1 behaviour, which flickers on formant basses.
|
||||
assert!(
|
||||
extra_bends > 10. * extra_stable.max(1.),
|
||||
"{extra_stable} vs {extra_bends}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tracker_turns_inactive_when_reads_stop_agreeing() {
|
||||
let mut t = Tracker::new(RATE, TrackerConfig::BASS);
|
||||
t.set(PitchSource::default());
|
||||
let mut saw = Saw::new(RATE, 55.);
|
||||
let mut seed = 1u32;
|
||||
let mut active = vec![];
|
||||
for i in 0..(RATE * 1.5) as usize {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 17;
|
||||
seed ^= seed << 5;
|
||||
let noise = seed as f32 / u32::MAX as f32 - 0.5;
|
||||
let x = if i < 24000 { 0.5 * saw.sample() } else { noise };
|
||||
t.process(x, |_| {});
|
||||
active.push(t.active());
|
||||
}
|
||||
let l = t.latency();
|
||||
assert!(active[l + 12000..l + 23000].iter().all(|a| *a));
|
||||
// Unreadable sound is no evidence against the note, so trust fades slowly: growls read
|
||||
// only now and then. Within half a second of noise, tracked processing stops acting.
|
||||
assert!(active[l + 48000..].iter().all(|a| !*a));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn note_mode_plays_the_set_note_on_each_onset() {
|
||||
let mut t = Tracker::new(RATE, TrackerConfig::BASS);
|
||||
t.set(PitchSource {
|
||||
mode: PitchMode::Note,
|
||||
note: 29,
|
||||
..PitchSource::default()
|
||||
});
|
||||
let mut saw = Saw::new(RATE, 220.);
|
||||
let mut events = vec![];
|
||||
for i in 0..48000 {
|
||||
let x = if (4800..20000).contains(&i) || i >= 30000 {
|
||||
0.5 * saw.sample()
|
||||
} else {
|
||||
0.
|
||||
};
|
||||
t.process(x, |e| events.push(e));
|
||||
if i == 15000 {
|
||||
assert!(t.active());
|
||||
}
|
||||
}
|
||||
let starts: Vec<_> = events
|
||||
.iter()
|
||||
.filter_map(|e| match e {
|
||||
NoteEvent::Start { pitch, .. } => Some(*pitch),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(starts, vec![29., 29.]);
|
||||
assert!(!events.iter().any(|e| matches!(e, NoteEvent::Move { .. })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_lock_snaps_reads_to_the_scale() {
|
||||
// F minor: F G Ab Bb C Db Eb. F#1 (30) leans to G1 when read sharp.
|
||||
assert_eq!(Scale::Minor.snap(29, 30.4), 31.);
|
||||
assert_eq!(Scale::Minor.snap(29, 29.6), 29.);
|
||||
assert_eq!(Scale::Major.snap(0, 61.), 60.);
|
||||
assert_eq!(Scale::Root.snap(29, 40.6), 41.);
|
||||
assert_eq!(Scale::Root.snap(29, 35.4), 41.);
|
||||
assert_eq!(Scale::Free.snap(29, 30.37), 30.37);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn key_lock_keeps_a_drifting_wobble_on_its_root() {
|
||||
let stem = common_dsp::stems::all(RATE)
|
||||
.into_iter()
|
||||
.find(|s| s.name == "wobble")
|
||||
.unwrap();
|
||||
let free = PitchSource::default();
|
||||
let root = PitchSource {
|
||||
note: 31,
|
||||
scale: Scale::Root,
|
||||
..free
|
||||
};
|
||||
let f = common_dsp::stems::score(RATE, TrackerConfig::BASS, free, &stem.samples, &stem.truth);
|
||||
let r = common_dsp::stems::score(RATE, TrackerConfig::BASS, root, &stem.samples, &stem.truth);
|
||||
assert!(r.unsure + r.wrong < f.unsure + f.wrong, "{f:?} vs {r:?}");
|
||||
assert!(r.wrong <= 0.02, "{r:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn note_names_parse_back() {
|
||||
for n in 0..=127u8 {
|
||||
assert_eq!(common_dsp::parse_note(&common_dsp::note_name(n)), Some(n));
|
||||
}
|
||||
assert_eq!(common_dsp::parse_note(" f1 "), Some(29));
|
||||
assert_eq!(common_dsp::parse_note("H2"), None);
|
||||
}
|
||||
Reference in new issue
Block a user