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
@@ -34,6 +34,8 @@ pub const ATTACK_MS: [f32; BANDS] = [30., 15., 8., 4.];
|
||||
pub const RELEASE_MS: [f32; BANDS] = [200., 160., 120., 90.];
|
||||
/// Filter coefficients are recomputed this often, in samples.
|
||||
const RETUNE: usize = 16;
|
||||
/// A new note slides the band edges over about this long instead of snapping them.
|
||||
const EDGE_MS: f32 = 6.;
|
||||
const Q: f32 = std::f32::consts::FRAC_1_SQRT_2;
|
||||
const SILENT: f32 = -120.;
|
||||
|
||||
@@ -176,6 +178,9 @@ pub struct Engine {
|
||||
pitch: PitchFollower,
|
||||
hz: f32,
|
||||
hz_coef: f32,
|
||||
edge_coef: f32,
|
||||
/// The edges are sliding to a new note.
|
||||
sliding: bool,
|
||||
countdown: usize,
|
||||
edges: [f32; BANDS - 1],
|
||||
coefs: Coefs,
|
||||
@@ -226,6 +231,8 @@ impl Engine {
|
||||
pitch: PitchFollower::default(),
|
||||
hz: 0.,
|
||||
hz_coef: 1.,
|
||||
edge_coef: coefficient(rate, EDGE_MS / 3.),
|
||||
sliding: false,
|
||||
countdown: 0,
|
||||
edges: [0.; BANDS - 1],
|
||||
coefs: Coefs {
|
||||
@@ -264,7 +271,7 @@ impl Engine {
|
||||
pub fn set_settings(&mut self, s: Settings) -> Result<(), &'static str> {
|
||||
s.validate()?;
|
||||
self.tracker
|
||||
.set(s.source == Source::Midi, s.gate, s.smooth > 0.);
|
||||
.set(s.pitch.source(s.source.mode(), s.gate, s.smooth > 0.));
|
||||
self.hz_coef = coefficient(self.rate, s.smooth / 3.);
|
||||
if s.time != self.settings.time || self.fresh {
|
||||
let scale = s.time * 0.01;
|
||||
@@ -296,6 +303,7 @@ impl Engine {
|
||||
self.levels = [SILENT; BANDS];
|
||||
self.gains = [0.; BANDS];
|
||||
self.countdown = 0;
|
||||
self.sliding = false;
|
||||
self.fresh = true;
|
||||
}
|
||||
pub fn note_on(&mut self, note: u8) {
|
||||
@@ -346,9 +354,23 @@ impl Engine {
|
||||
self.delay_at = (self.delay_at + 1) % len;
|
||||
let y = self.delay[self.delay_at];
|
||||
|
||||
// Unsure tracking sends no events, so the edges hold the last sure note. A new note
|
||||
// slides them instead of snapping, so the bands do not pump on note changes.
|
||||
let (hz, jump) = self.pitch.step(self.hz_coef);
|
||||
self.hz = hz;
|
||||
if jump || self.countdown == 0 {
|
||||
let first = self.hz == 0.;
|
||||
if jump && !first {
|
||||
self.sliding = true;
|
||||
}
|
||||
if self.sliding {
|
||||
self.hz += (hz - self.hz) * self.edge_coef;
|
||||
if (hz - self.hz).abs() < 1e-3 * hz {
|
||||
self.hz = hz;
|
||||
self.sliding = false;
|
||||
}
|
||||
} else {
|
||||
self.hz = hz;
|
||||
}
|
||||
if (jump && first) || self.countdown == 0 {
|
||||
self.retune();
|
||||
self.countdown = RETUNE;
|
||||
}
|
||||
@@ -404,7 +426,7 @@ impl Engine {
|
||||
sample_rate: self.rate,
|
||||
..AnalyzerFrame::default()
|
||||
};
|
||||
if self.tracker.sounding() && self.hz > 0. {
|
||||
if self.tracker.active() && self.hz > 0. {
|
||||
f.note = Some(hz_to_midi(self.hz).round().clamp(0., 127.) as u8);
|
||||
}
|
||||
f
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Host-independent controls. Levels in dB, times in milliseconds, amounts in percent.
|
||||
use common_dsp::tracker::{Pitch, PitchMode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Bands: the fundamental, low harmonics, mid harmonics and the top.
|
||||
@@ -15,12 +16,33 @@ pub enum Source {
|
||||
Audio,
|
||||
/// Notes come from MIDI note input.
|
||||
Midi,
|
||||
/// Note starts are detected, the pitch is the set note: nothing is guessed.
|
||||
Note,
|
||||
}
|
||||
impl Source {
|
||||
pub fn mode(self) -> PitchMode {
|
||||
match self {
|
||||
Source::Audio => PitchMode::Audio,
|
||||
Source::Midi => PitchMode::Midi,
|
||||
Source::Note => PitchMode::Note,
|
||||
}
|
||||
}
|
||||
pub fn from_mode(mode: PitchMode) -> Self {
|
||||
match mode {
|
||||
PitchMode::Audio => Source::Audio,
|
||||
PitchMode::Midi => Source::Midi,
|
||||
PitchMode::Note => Source::Note,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Settings {
|
||||
pub source: Source,
|
||||
/// Note mode's note, the key lock and Follow bends.
|
||||
#[serde(default)]
|
||||
pub pitch: Pitch,
|
||||
/// Highest harmonic in the bottom band. 1 keeps the fundamental on its own.
|
||||
pub low: u32,
|
||||
/// Highest harmonic in the second band.
|
||||
@@ -54,6 +76,7 @@ impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
source: Source::Audio,
|
||||
pitch: Pitch::default(),
|
||||
low: 1,
|
||||
mid: 4,
|
||||
high: 16,
|
||||
@@ -73,6 +96,7 @@ impl Default for Settings {
|
||||
}
|
||||
impl Settings {
|
||||
pub fn validate(&self) -> Result<(), &'static str> {
|
||||
self.pitch.validate()?;
|
||||
let finite = [
|
||||
self.depth,
|
||||
self.time,
|
||||
|
||||
Generated
+13
@@ -309,11 +309,23 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "common-dsp"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common-params"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common-dsp",
|
||||
"nih_plug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common-ui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"common-dsp",
|
||||
"egui",
|
||||
]
|
||||
|
||||
@@ -1443,6 +1455,7 @@ name = "planish"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap-sys",
|
||||
"common-params",
|
||||
"crossbeam-queue",
|
||||
"nih_plug",
|
||||
"nih_plug_egui",
|
||||
|
||||
@@ -13,6 +13,7 @@ crate-type = ["cdylib", "rlib"]
|
||||
nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", rev = "de421011f41a6d10fc8c7a6084e4f4dee0143683", default-features = false }
|
||||
nih_plug_egui = { git = "https://github.com/robbert-vdh/nih-plug.git", rev = "de421011f41a6d10fc8c7a6084e4f4dee0143683" }
|
||||
planish-core = { path = "../core" }
|
||||
common-params = { path = "../../common/params" }
|
||||
planish-ui = { path = "../ui" }
|
||||
crossbeam-queue = "0.3"
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use common_params::PitchParams;
|
||||
use nih_plug::prelude::*;
|
||||
use nih_plug_egui::EguiState;
|
||||
use planish_core::{Settings, Source, BANDS, GAIN_MAX, GAIN_MIN, TOP_MAX};
|
||||
@@ -10,6 +11,26 @@ pub enum SourceParam {
|
||||
#[id = "midi"]
|
||||
#[name = "MIDI"]
|
||||
Midi,
|
||||
#[id = "note"]
|
||||
Note,
|
||||
}
|
||||
impl From<SourceParam> for Source {
|
||||
fn from(s: SourceParam) -> Self {
|
||||
match s {
|
||||
SourceParam::Audio => Source::Audio,
|
||||
SourceParam::Midi => Source::Midi,
|
||||
SourceParam::Note => Source::Note,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<Source> for SourceParam {
|
||||
fn from(s: Source) -> Self {
|
||||
match s {
|
||||
Source::Audio => SourceParam::Audio,
|
||||
Source::Midi => SourceParam::Midi,
|
||||
Source::Note => SourceParam::Note,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn linear(name: &str, v: f32, min: f32, max: f32, unit: &'static str) -> FloatParam {
|
||||
FloatParam::new(name, v, FloatRange::Linear { min, max }).with_unit(unit)
|
||||
@@ -26,6 +47,8 @@ pub struct PlanishParams {
|
||||
pub editor: Arc<EguiState>,
|
||||
#[id = "source"]
|
||||
pub source: EnumParam<SourceParam>,
|
||||
#[nested(group = "Pitch")]
|
||||
pub pitch: PitchParams,
|
||||
#[id = "depth"]
|
||||
pub depth: FloatParam,
|
||||
#[id = "time"]
|
||||
@@ -68,6 +91,7 @@ impl Default for PlanishParams {
|
||||
Self {
|
||||
editor: EguiState::from_size(planish_ui::WIDTH, planish_ui::HEIGHT),
|
||||
source: EnumParam::new("Pitch source", SourceParam::Audio),
|
||||
pitch: PitchParams::default(),
|
||||
depth: linear("Depth", d.depth, 0., 100., " %"),
|
||||
time: linear("Time", d.time, 10., 1000., " %"),
|
||||
upward: linear("Upward", d.upward, 0., 100., " %"),
|
||||
@@ -92,10 +116,8 @@ impl PlanishParams {
|
||||
pub fn settings(&self) -> Settings {
|
||||
let gains = [&self.gain_1, &self.gain_2, &self.gain_3, &self.gain_4];
|
||||
Settings {
|
||||
source: match self.source.value() {
|
||||
SourceParam::Audio => Source::Audio,
|
||||
SourceParam::Midi => Source::Midi,
|
||||
},
|
||||
source: self.source.value().into(),
|
||||
pitch: self.pitch.pitch(),
|
||||
low: self.low.value() as u32,
|
||||
mid: self.mid.value() as u32,
|
||||
high: self.high.value() as u32,
|
||||
@@ -180,13 +202,10 @@ impl PlanishParams {
|
||||
}
|
||||
}
|
||||
if new.source != old.source {
|
||||
let v = match new.source {
|
||||
Source::Audio => SourceParam::Audio,
|
||||
Source::Midi => SourceParam::Midi,
|
||||
};
|
||||
setter.begin_set_parameter(&self.source);
|
||||
setter.set_parameter(&self.source, v);
|
||||
setter.set_parameter(&self.source, new.source.into());
|
||||
setter.end_set_parameter(&self.source);
|
||||
}
|
||||
self.pitch.apply(setter, &old.pitch, &new.pitch);
|
||||
}
|
||||
}
|
||||
@@ -358,13 +358,9 @@ pub fn show(ui: &mut egui::Ui, settings: &mut Settings, state: &mut State) {
|
||||
settings.bypass = !settings.bypass;
|
||||
}
|
||||
ui.separator();
|
||||
for (source, label) in [(Source::Midi, "MIDI"), (Source::Audio, "AUDIO")] {
|
||||
let r = ui.selectable_label(settings.source == source, RichText::new(label).size(13.));
|
||||
if r.clicked() {
|
||||
settings.source = source;
|
||||
}
|
||||
}
|
||||
caption(ui, "PITCH FROM");
|
||||
let mut mode = settings.source.mode();
|
||||
pitch_from(ui, &mut mode, &mut settings.pitch);
|
||||
settings.source = Source::from_mode(mode);
|
||||
});
|
||||
ui.add_space(6.);
|
||||
let frame = state.analyzer;
|
||||
@@ -418,10 +414,7 @@ fn note_panel(
|
||||
RichText::new(format!(
|
||||
"{:.0} ms lookahead · {}",
|
||||
frame.latency as f32 / frame.sample_rate * 1000.,
|
||||
match settings.source {
|
||||
Source::Audio => "detecting pitch",
|
||||
Source::Midi => "following MIDI",
|
||||
}
|
||||
pitch_status(settings.source.mode(), &settings.pitch)
|
||||
))
|
||||
.size(12.)
|
||||
.color(MUTED),
|
||||
|
||||
Reference in new issue
Block a user