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 map's tempo is the beats' own (part of #49). It was a line fitted through the downbeats against their bar count. Where Beat This! marks downbeats two beats apart in places, that counted each half bar as a whole one: a 99 BPM song read as 112.8 on Symphonia's decode and 116.6 on AVFoundation's, whose 12 ms offset moved three downbeats. Now the line goes through every beat against its count (a missed beat counted by its gap), so both decodes give 99.0. The hits come out 9 vs 6 rather than 62 vs 13, since they followed the tempo. Bars and one section boundary still follow the downbeats the model gives each decode. A unit test with every third bar half reads 99.17 for beats 0.605 s apart (119.26 before)
shinyobjectz3d170ce60d35
diff --git a/systems/song/src/song/analyse.rs b/systems/song/src/song/analyse.rsindex 64c0a22a..d07a73df 100644--- a/systems/song/src/song/analyse.rs+++ b/systems/song/src/song/analyse.rs@@ -35,9 +35,10 @@ pub fn analyse(x: &[f32], spect: &[[f32; MELS]], beats: &[f64], downs: &[f64], m}}let down_i = kept_d;- // the tempo: a line fitted through the downbeats against their bar count (a missed downbeat counted by its gap),- // over the beats per bar; never a median of single gaps, which 20 ms frames quantise (0.46 / 0.44 s read as one- // tempo or the other)+ // the tempo: a line fitted through the beats against their count (a missed beat counted by its gap). Never a+ // median of single gaps, which 20 ms frames quantise (0.46 / 0.44 s read as one tempo or the other); nor a line+ // through the downbeats against their bar count, which a song whose downbeats come two beats apart in places+ // counts as whole bars: 99 BPM read as 112.8 or 116.6, by where a 12 ms decoder offset put three downbeats (#49)let fit = |pts: &[(f64, f64)]| -> Option<f64> {if pts.len() < 3 {return None;@@ -47,26 +48,9 @@ pub fn analyse(x: &[f32], spect: &[[f32; MELS]], beats: &[f64], downs: &[f64], m(sxx > 0.0).then(|| sxy / sxx)};let gap = {- let mut bar_gaps: Vec<f64> = down_i.windows(2).map(|w| beats[w[1]] - beats[w[0]]).collect();- bar_gaps.sort_by(f64::total_cmp);- let bar_median = bar_gaps.get(bar_gaps.len() / 2).copied().unwrap_or(4.0 * median);let mut k = 0.0;- let pts: Vec<(f64, f64)> = down_i- .iter()- .enumerate()- .map(|(j, d)| {- if j > 0 {- k += ((beats[*d] - beats[down_i[j - 1]]) / bar_median).round().max(1.0);- }- (k, beats[*d])- })- .collect();- let beats_in_bar = (bar_median / median).round().max(1.0);- fit(&pts).map(|s| s / beats_in_bar).unwrap_or_else(|| {- let mut k = 0.0;- let pts: Vec<(f64, f64)> = (0..n).map(|i| { if i > 0 { k += ((beats[i] - beats[i - 1]) / median).round().max(1.0); } (k, beats[i]) }).collect();- fit(&pts).unwrap_or(median)- })+ let pts: Vec<(f64, f64)> = (0..n).map(|i| { if i > 0 { k += ((beats[i] - beats[i - 1]) / median).round().max(1.0); } (k, beats[i]) }).collect();+ fit(&pts).unwrap_or(median)};let tempo = 60.0 / gap;let mut counts = [0usize; 9];diff --git a/systems/song/src/song/mod.rs b/systems/song/src/song/mod.rsindex 106a2827..61fe12d8 100644--- a/systems/song/src/song/mod.rs+++ b/systems/song/src/song/mod.rs@@ -409,4 +409,21 @@ mod tests {assert!(stop["time"].as_f64().unwrap() >= drop_t - 2.5);assert_eq!(m["beatsPerBar"], 4);}++ /// #49: downbeats two beats apart in places (as Beat This! marks some songs) leave the tempo the beats' own+ #[test]+ fn half_bars_leave_the_tempo_the_beats() {+ let beat = 0.605;+ let x = vec![0f32; (40.0 * SR) as usize];+ let beats: Vec<f64> = (0..64).map(|i| 0.02 + i as f64 * beat).collect();+ // bars of 4, then 2, 4, 4, 2, ... (every third bar half)+ let (mut downs, mut i, mut k) = (Vec::new(), 0, 0);+ while i < beats.len() {+ downs.push(beats[i]);+ i += if k % 3 == 1 { 2 } else { 4 };+ k += 1;+ }+ let m = analyse(&x, &beatthis::spectrogram(&x), &beats, &downs, &[]);+ assert!((m["tempo"].as_f64().unwrap() - 60.0 / beat).abs() < 0.05, "tempo {} for beats {beat} s apart", m["tempo"]);+ }}