Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
A song's bars are the same on every decoder: a downbeat or two the model marks mid-bar, between downbeats whole bars apart, are counted from the beats, so a 12 ms decoder offset no longer gives the Mac 78 bars and the rest 75 (#49)
shinyobjectzb034e31a6165
diff --git a/systems/song/src/song/analyse.rs b/systems/song/src/song/analyse.rsindex f7741adb..796c8a0f 100644--- a/systems/song/src/song/analyse.rs+++ b/systems/song/src/song/analyse.rs@@ -2,6 +2,34 @@use super::*;+/// The downbeats without the model's strays: one or two downbeats off the bar's phase, between two that are whole+/// bars apart, are that stretch's bars counted from the beats. Beat This! marks a downbeat mid-bar here and there, and+/// where it does moves with a 12 ms decoder offset, so the same song had 78 bars on a Mac and 75 elsewhere (#49). A+/// phase that holds for three downbeats is the music's (a dropped beat, a change of meter) and stays.+pub(super) fn steady(down: &[usize], bpb: usize) -> Vec<usize> {+ const HOLD: usize = 3;+ let mut out: Vec<usize> = Vec::new();+ let mut i = 0;+ while i < down.len() {+ let Some(&a) = out.last() else {+ out.push(down[i]);+ i += 1;+ continue;+ };+ if (down[i] - a) % bpb == 0 {+ out.push(down[i]);+ i += 1;+ } else if let Some(j) = (i..down.len().min(i + HOLD)).find(|j| (down[*j] - a) % bpb == 0) {+ out.extend((a + bpb..down[j]).step_by(bpb));+ i = j;+ } else {+ out.push(down[i]);+ i += 1;+ }+ }+ out+}+/// The map from a song's 22 050 Hz mono samples, its log-mel frames, beats and downbeats (seconds) and any/// `[Section]` markers.pub fn analyse(x: &[f32], spect: &[[f32; MELS]], beats: &[f64], downs: &[f64], marks: &[(f64, String)]) -> Value {@@ -61,6 +89,7 @@ pub fn analyse(x: &[f32], spect: &[[f32; MELS]], beats: &[f64], downs: &[f64], m}}let bpb = (2..counts.len()).max_by_key(|c| counts[*c]).filter(|c| counts[*c] > 0).unwrap_or(4);+ let down_i = steady(&down_i, bpb);// bars: one per downbeat, and a pickup before the firstlet mut bar_starts: Vec<usize> = Vec::new();if let Some(&first) = down_i.first() {diff --git a/systems/song/src/song/mod.rs b/systems/song/src/song/mod.rsindex 61fe12d8..4fd66af0 100644--- a/systems/song/src/song/mod.rs+++ b/systems/song/src/song/mod.rs@@ -358,6 +358,18 @@ mod tests {assert_eq!(srt_markers(s), vec![(13.404, "Verse 1".to_string()), (114.654, "Glitch Ska Break".to_string())]);}+ #[test]+ fn stray_downbeats_between_whole_bars_are_dropped_and_a_phase_that_holds_stays() {+ // #49: a downbeat marked mid-bar (51, 55, 59), and two in a row off the phase (67, 71) between 65 and 73+ let model = [1, 5, 9, 49, 51, 53, 55, 57, 59, 61, 65, 67, 71, 73, 77];+ assert_eq!(analyse::steady(&model, 4), vec![1, 5, 9, 49, 53, 57, 61, 65, 69, 73, 77]);+ // the other decode's downbeats there, with no strays: the same bars+ assert_eq!(analyse::steady(&[1, 5, 9, 49, 53, 57, 61, 65, 69, 73, 77], 4), vec![1, 5, 9, 49, 53, 57, 61, 65, 69, 73, 77]);+ // a dropped beat moves the phase for good (three downbeats hold it), and bars of three in a song of fours stay+ assert_eq!(analyse::steady(&[0, 4, 8, 11, 15, 19, 23], 4), vec![0, 4, 8, 11, 15, 19, 23]);+ assert_eq!(analyse::steady(&[0, 4, 8, 11, 14, 17, 20, 24], 4), vec![0, 4, 8, 11, 14, 17, 20, 24]);+ }+#[test]fn beats_refine_to_the_parabola_vertex() {let mut l = vec![-5f32; 10];