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
check: a voice ending a sentence isn't a dead stop; bands read in dBFS
Stephan Fitzpatrickf246af81be29
diff --git a/apps/check/src/sound.rs b/apps/check/src/sound.rsindex e6ebcee8..8c7e61f2 100644--- a/apps/check/src/sound.rs+++ b/apps/check/src/sound.rs@@ -23,8 +23,10 @@ pub(crate) fn pct(v: &[f64], q: f64) -> f64 {s[lo] + (s[hi] - s[lo]) * (r - lo as f64)}-/// Each 10 ms step's level in dB, for the whole mix and in three bands (low < 500 Hz, mid to 4 kHz, high to 12 kHz):-/// a bed that stops under a voice shows in the band the voice doesn't fill (a projector's clatter in the highs)+/// Each 10 ms step's level in dBFS, for the whole mix and in three bands (low < 500 Hz, mid to 4 kHz, high to 12 kHz):+/// a bed that stops under a voice shows in the band the voice doesn't fill (a projector's clatter in the highs). A band's+/// level is its share of the step's mean square (Parseval, undoing the Hann window's power), so a tone reads the same in+/// its band as in the mixpub(crate) fn levels(x: &[f32]) -> (Vec<f64>, [Vec<f64>; 3]) {use std::f64::consts::PI;let n = x.len() / HOP;@@ -38,6 +40,8 @@ pub(crate) fn levels(x: &[f32]) -> (Vec<f64>, [Vec<f64>; 3]) {let bins: Vec<(usize, Vec<(f64, f64)>)> = (0..=HOP / 2).filter_map(|k| Some((band(k)?, (0..HOP).map(|i| (-2.0 * PI * ((k * i) % HOP) as f64 / HOP as f64).sin_cos()).collect()))).collect();+ // one-sided bins (no DC or Nyquist in any band) count twice; the window keeps mean(w²) of the power+ let scale = 2.0 / (HOP * HOP) as f64 / (hann.iter().map(|h| h * h).sum::<f64>() / HOP as f64);let (mut rms, mut bands) = (Vec::with_capacity(n), [Vec::with_capacity(n), Vec::with_capacity(n), Vec::with_capacity(n)]);for f in x.chunks_exact(HOP) {let ms = f.iter().map(|&v| (v as f64).powi(2)).sum::<f64>() / HOP as f64;@@ -49,17 +53,22 @@ pub(crate) fn levels(x: &[f32]) -> (Vec<f64>, [Vec<f64>; 3]) {e[*b] += re * re + im * im;}for b in 0..3 {- bands[b].push(10.0 * (e[b] / HOP as f64 + 1e-12).log10());+ bands[b].push(10.0 * (e[b] * scale + 1e-18).log10());}}(rms, bands)}/// Dead stops: a steady sound (a bed: a projector, rain, room tone, a held chord) that goes in one 10 ms step instead of-/// fading. Steady: over the second before, its level smoothed to 50 ms varies by under 3 dB (a voice or music with-/// phrases never holds that still). The stop: down 12 dB or more in one step, and the 300 ms after it DROP dB under the-/// bed. In the whole mix or one band, so a bed that stops under a voice shows where the voice doesn't cover it.+/// fading. Steady: over the second before, its level smoothed to 50 ms varies by under 3 dB. The stop: down 12 dB or more+/// in one step, from within AT dB of the bed one or two steps before (a fade that has already brought it down isn't a+/// stop), to DROP dB under the bed by the next step (gone, not a voice's tail that comes back up), and the 300 ms after it+/// DROP dB under the bed. In the whole mix or one band, so a bed that stops under a voice shows where the voice doesn't+/// cover it. Dense speech can pass for steady in the lows (its pitch fills them evenly), but a word ends in a tail that+/// rises again after the first drop, where a cut source is gone in one step.pub(crate) fn dead_stops(rms: &[f64], bands: &[Vec<f64>; 3]) -> Vec<(f64, String)> {+ /// dB under the bed the sound may be just before it stops+ const AT: f64 = 6.0;let mut found: Vec<(f64, String)> = Vec::new();let n = rms.len();for (name, lv) in [("the mix", rms), ("the lows", &bands[0][..]), ("the mids", &bands[1][..]), ("the highs", &bands[2][..])] {@@ -71,10 +80,13 @@ pub(crate) fn dead_stops(rms: &[f64], bands: &[Vec<f64>; 3]) -> Vec<(f64, Stringlet pre = &sm[i - 100..i - 2];let (bed, mean) = (pct(pre, 50.0), pre.iter().sum::<f64>() / pre.len() as f64);let sd = (pre.iter().map(|v| (v - mean).powi(2)).sum::<f64>() / pre.len() as f64).sqrt();- let floor = if name == "the mix" { -50.0 } else { -65.0 };+ // under this nobody hears it stop+ let floor = if name == "the mix" { -50.0 } else { -80.0 };let at = i as f64 * HOP as f64 / SR as f64;- if bed > floor && sd < 3.0 && bed - pct(&lv[i..i + 30], 10.0) >= DROP && !found.iter().any(|(t, _)| (t - at).abs() < 0.5) {- found.push((at, format!("{name}: a steady sound at {bed:.0} dB stops dead in 10 ms: its source ran out (make it as long as its Sequence), or a Sequence cut it with no fadeOut")));+ let was_up = lv[i - 1].max(lv[i - 2]) >= bed - AT;+ let gone = lv[i + 1] <= bed - DROP && bed - pct(&lv[i..i + 30], 10.0) >= DROP;+ if bed > floor && sd < 3.0 && was_up && gone && !found.iter().any(|(t, _)| (t - at).abs() < 0.5) {+ found.push((at, format!("{name}: a steady sound at {bed:.0} dBFS stops dead in 10 ms: its source ran out (make it as long as its Sequence), or a Sequence cut it with no fadeOut or one too short to hear (fade a bed out over 100 ms or more)")));}}}diff --git a/apps/check/src/testdata/its-a-race-12s.levels b/apps/check/src/testdata/its-a-race-12s.levelsnew file mode 100644index 00000000..c0fd6459--- /dev/null+++ b/apps/check/src/testdata/its-a-race-12s.levels@@ -0,0 +1,6 @@+# its-a-race (raea 0.1.0-canary.2, Linux export), 12.00-14.00 s: each 10 ms step's level in dBFS, one line per track:+# the mix, the lows, the mids, the highs. The voice ends "thing." at 13.36 s and pauses; nothing is cut there.+-9.4 -9.8 -10.1 -9.6 -9.2 -10.6 -11.9 -11.6 -10.1 -11.4 -11.0 -12.3 -10.0 -12.4 -12.2 -11.9 -11.6 -14.0 -16.2 -19.8 -17.9 -18.8 -22.8 -23.0 -25.0 -27.5 -26.2 -27.7 -30.9 -25.5 -17.2 -12.1 -11.3 -11.6 -12.3 -12.5 -12.2 -11.0 -12.4 -12.0 -12.5 -12.5 -12.3 -11.7 -12.8 -11.9 -12.1 -12.9 -12.4 -11.4 -11.1 -10.2 -11.2 -12.2 -11.8 -11.6 -12.7 -11.6 -12.0 -13.0 -13.1 -12.1 -13.8 -13.2 -14.3 -16.3 -19.5 -17.7 -17.0 -19.2 -16.0 -12.7 -12.9 -13.2 -15.4 -15.0 -15.6 -18.1 -19.1 -16.3 -17.9 -22.2 -28.5 -27.6 -28.4 -26.2 -12.5 -13.3 -12.2 -13.1 -12.3 -13.4 -14.6 -15.2 -12.2 -13.0 -12.4 -13.1 -13.3 -11.8 -13.2 -14.1 -11.5 -14.8 -16.7 -16.5 -16.2 -17.0 -19.1 -21.8 -22.1 -22.2 -22.3 -16.9 -12.7 -11.9 -14.7 -13.1 -12.9 -13.9 -16.6 -15.8 -14.9 -15.1 -18.6 -15.9 -17.3 -18.9 -15.6 -19.4 -21.3 -16.8 -18.7 -22.6 -17.7 -19.1 -27.5 -28.1 -29.8 -41.1 -35.5 -37.2 -39.2 -40.4 -40.4 -39.4 -47.0 -39.7 -40.4 -51.7 -42.6 -44.1 -46.9 -48.2 -51.3 -48.3 -54.1 -54.6 -55.0 -50.8 -54.1 -51.6 -55.5 -53.5 -51.7 -54.7 -51.8 -55.6 -57.5 -54.8 -51.2 -54.0 -51.8 -51.8 -47.9 -50.9 -51.1 -47.9 -53.1 -50.0 -46.5 -49.4 -49.4 -48.3 -55.7 -51.1 -48.7 -58.9 -54.4 -54.6 -50.3 -51.6 -58.0 -60.7 -60.2 -56.3 -58.9 -55.1 -48.8 -48.3+-14.9 -13.6 -13.9 -11.8 -10.1 -11.9 -13.2 -13.9 -13.7 -14.6 -14.1 -15.8 -17.2 -14.8 -13.9 -15.5 -13.5 -13.1 -16.6 -21.9 -21.1 -20.4 -23.3 -22.7 -28.8 -27.3 -26.5 -29.2 -35.7 -27.5 -22.6 -22.5 -19.2 -18.5 -19.7 -20.1 -17.9 -17.9 -15.1 -15.8 -15.0 -13.3 -12.8 -13.5 -13.7 -13.6 -16.6 -18.3 -17.9 -17.1 -17.1 -18.0 -16.5 -14.8 -15.7 -15.5 -16.9 -15.5 -15.9 -16.3 -16.4 -15.2 -15.0 -13.5 -15.7 -16.3 -23.9 -18.8 -18.5 -23.4 -18.3 -14.9 -16.9 -17.7 -16.7 -14.8 -15.0 -18.9 -21.1 -15.8 -16.0 -21.6 -29.5 -28.3 -27.8 -29.9 -10.9 -13.0 -12.6 -15.2 -15.0 -15.2 -15.6 -16.4 -10.9 -11.7 -13.4 -16.4 -17.2 -16.1 -13.2 -12.7 -11.2 -14.8 -20.7 -20.7 -15.1 -16.6 -20.0 -21.9 -21.4 -21.1 -24.0 -20.7 -14.1 -12.1 -14.9 -13.9 -15.8 -17.8 -18.0 -17.5 -18.0 -17.0 -19.3 -18.6 -19.4 -17.7 -15.2 -19.0 -21.7 -16.0 -21.9 -26.4 -17.1 -18.4 -30.6 -32.5 -28.5 -40.9 -36.5 -39.9 -42.0 -41.9 -39.9 -38.6 -48.0 -39.9 -41.4 -51.5 -41.3 -44.6 -49.2 -51.7 -51.6 -46.6 -55.4 -54.4 -57.2 -51.8 -53.6 -54.4 -67.4 -54.8 -52.1 -59.4 -52.1 -60.5 -57.8 -56.5 -50.9 -55.9 -56.8 -54.8 -50.8 -52.6 -53.3 -48.0 -51.4 -50.9 -49.4 -53.1 -50.5 -48.2 -60.7 -51.3 -48.6 -57.8 -54.4 -56.1 -50.3 -53.1 -61.4 -63.3 -63.1 -55.4 -63.0 -64.0 -49.9 -47.3+-12.0 -10.4 -12.3 -11.7 -10.7 -10.7 -14.9 -14.4 -12.3 -16.6 -13.5 -14.5 -11.1 -16.7 -15.5 -18.9 -13.4 -22.6 -23.6 -21.8 -26.7 -20.9 -28.7 -30.7 -30.0 -33.2 -34.9 -34.4 -36.3 -31.4 -24.7 -16.0 -10.5 -9.2 -9.7 -10.8 -12.7 -15.1 -19.7 -17.3 -19.4 -19.3 -20.1 -19.5 -21.5 -19.3 -18.7 -18.7 -15.4 -13.5 -14.9 -12.2 -15.0 -15.6 -14.6 -13.9 -16.5 -13.7 -13.6 -15.2 -14.7 -13.5 -16.3 -19.3 -20.2 -19.0 -23.1 -24.0 -23.2 -23.2 -17.9 -13.7 -16.6 -17.8 -22.7 -24.8 -28.6 -28.2 -32.4 -34.7 -34.6 -36.6 -38.0 -40.1 -42.3 -35.2 -23.1 -16.8 -16.8 -18.0 -18.1 -23.6 -26.2 -29.0 -29.4 -35.4 -27.7 -27.3 -21.4 -26.4 -28.5 -27.2 -31.6 -32.5 -31.8 -36.6 -30.0 -35.9 -34.5 -38.9 -46.2 -36.8 -36.4 -28.6 -24.0 -19.9 -20.8 -18.7 -14.8 -20.7 -21.7 -21.0 -17.7 -24.2 -26.8 -25.9 -25.1 -35.3 -33.6 -35.9 -31.9 -33.1 -37.1 -37.0 -39.4 -41.9 -41.4 -41.3 -44.5 -52.1 -49.2 -51.5 -50.8 -55.7 -54.8 -54.7 -59.0 -53.6 -56.8 -62.2 -59.4 -59.3 -58.9 -61.8 -63.8 -64.5 -65.8 -59.9 -62.2 -60.3 -64.8 -63.2 -62.9 -61.9 -64.4 -68.0 -64.8 -63.3 -65.8 -65.6 -60.6 -59.4 -60.2 -62.9 -61.1 -65.1 -61.8 -61.2 -63.9 -60.1 -60.1 -63.2 -64.3 -62.1 -64.6 -58.1 -62.4 -63.1 -60.3 -64.0 -65.1 -66.5 -64.5 -64.1 -61.3 -63.4 -63.7 -64.4 -61.6 -61.3+-67.9 -67.4 -67.8 -66.7 -64.9 -65.1 -68.8 -66.5 -65.0 -67.2 -65.0 -68.4 -65.1 -63.2 -62.2 -64.6 -69.9 -69.5 -65.1 -59.3 -71.5 -71.7 -73.7 -70.1 -73.6 -71.9 -70.5 -68.0 -64.9 -59.0 -52.7 -48.0 -46.1 -43.3 -46.8 -49.0 -48.5 -45.5 -46.1 -48.9 -42.3 -48.5 -48.3 -53.6 -53.2 -52.8 -47.4 -44.4 -54.5 -56.1 -56.2 -54.6 -52.5 -53.6 -53.8 -57.0 -54.5 -55.2 -54.0 -53.7 -51.1 -59.0 -56.1 -55.7 -57.7 -58.6 -64.5 -65.6 -64.7 -66.6 -61.2 -51.6 -49.8 -51.2 -54.4 -58.5 -57.3 -62.0 -59.5 -58.1 -51.3 -45.8 -48.4 -47.1 -45.8 -50.3 -46.3 -42.4 -42.0 -47.7 -51.6 -52.3 -56.7 -59.0 -61.9 -65.4 -64.7 -63.4 -59.2 -58.6 -54.0 -55.7 -53.6 -47.1 -44.8 -41.1 -44.5 -41.3 -44.8 -43.8 -45.0 -46.5 -47.4 -48.1 -52.2 -52.5 -53.3 -54.0 -57.1 -58.2 -61.1 -60.7 -60.3 -59.0 -57.6 -59.4 -62.1 -66.4 -65.6 -68.2 -66.6 -66.0 -72.4 -68.6 -68.9 -72.2 -73.0 -71.9 -75.4 -73.8 -73.7 -76.3 -74.6 -77.1 -76.4 -76.4 -75.2 -76.3 -75.4 -76.6 -77.8 -77.1 -74.6 -76.5 -74.6 -77.6 -76.2 -77.3 -74.8 -78.0 -76.6 -79.6 -80.0 -77.4 -75.6 -77.0 -76.9 -75.9 -77.0 -76.4 -76.4 -76.5 -78.2 -77.6 -76.1 -77.6 -77.7 -76.8 -76.7 -77.5 -76.9 -77.7 -75.2 -76.9 -78.1 -76.3 -76.9 -78.3 -79.3 -78.9 -77.1 -76.9 -79.3 -77.4 -78.4 -77.1 -76.3 -77.9 -76.2 -76.3diff --git a/apps/check/src/tests.rs b/apps/check/src/tests.rsindex 1f1deea2..ec062ed5 100644--- a/apps/check/src/tests.rs+++ b/apps/check/src/tests.rs@@ -103,6 +103,45 @@ fn a_steady_sound_that_stops_dead_is_found_and_a_faded_one_isnt() {let faded: Vec<f32> = tone(4.0, &[(0.0, 3.0, -20.0)]).into_iter().enumerate().map(|(i, v)| v * (1.0 - ((i as f32 / SR as f32) - 2.0).clamp(0.0, 1.0))).collect();let (rms, bands) = levels(&faded);assert!(dead_stops(&rms, &bands).is_empty());+ // a source cut partway through a 10 ms step is as dead+ let cut: Vec<f32> = tone(4.0, &[(0.0, 2.0 + 117.0 / SR as f64, -20.0)]);+ let (rms, bands) = levels(&cut);+ assert_eq!(dead_stops(&rms, &bands).len(), 1);+ // a 100 ms fadeOut is a fade, though its last step falls into silence+ let short: Vec<f32> = tone(4.0, &[(0.0, 2.0, -20.0)]).into_iter().enumerate().map(|(i, v)| v * ((2.0 - i as f32 / SR as f32) / 0.1).clamp(0.0, 1.0)).collect();+ let (rms, bands) = levels(&short);+ assert!(dead_stops(&rms, &bands).is_empty(), "{:?}", dead_stops(&rms, &bands));+}++#[test]+fn bands_read_in_dbfs() {+ // a tone in the middle of its band reads there what it reads in the mix: -20 dBFS peak is -23 dBFS RMS+ let sine = |hz: f64| (0..SR).map(|i| (0.1 * (2.0 * std::f64::consts::PI * hz * i as f64 / SR as f64).sin()) as f32).collect::<Vec<_>>();+ for (hz, band) in [(200.0, 0), (2000.0, 1), (8000.0, 2)] {+ let (rms, bands) = levels(&sine(hz));+ assert!((rms[50] + 23.0).abs() < 0.1, "{}", rms[50]);+ assert!((bands[band][50] - rms[50]).abs() < 0.2, "{hz} Hz: band {} vs the mix {}", bands[band][50], rms[50]);+ }+}++#[test]+fn a_voice_that_ends_a_sentence_isnt_a_dead_stop() {+ // its-a-race at 12-14 s: "AI became a thing." ends at 13.36 s and the speaker pauses. Its lows held within 2.6 dB over+ // the second before and fell 12 dB in one step, so they read as a bed cut dead ("a steady sound at -0 dB", before the+ // bands read in dBFS), but the mix follows the source there and the word's tail comes back up after the first drop+ let tracks: Vec<Vec<f64>> = include_str!("testdata/its-a-race-12s.levels")+ .lines()+ .filter(|l| !l.starts_with('#'))+ .map(|l| l.split_whitespace().map(|v| v.parse().unwrap()).collect())+ .collect();+ let bands = [tracks[1].clone(), tracks[2].clone(), tracks[3].clone()];+ let stops = dead_stops(&tracks[0], &bands);+ assert!(stops.is_empty(), "{stops:?}");+ // the same voice with a bed under it that's cut at 13.6 s: that one is still found+ let bed = 10f64.powf(-30.0 / 10.0);+ let highs: Vec<f64> = tracks[3].iter().enumerate().map(|(i, v)| 10.0 * (10f64.powf(v / 10.0) + if i < 160 { bed } else { 0.0 }).log10()).collect();+ let found = dead_stops(&tracks[0], &[tracks[1].clone(), tracks[2].clone(), highs]);+ assert!(found.iter().any(|(at, says)| (at - 1.6).abs() < 0.02 && says.starts_with("the highs")), "{found:?}");}#[test]diff --git a/sdk/guides/craft/motion/sound.md b/sdk/guides/craft/motion/sound.mdindex ab93e4bd..9de32e6f 100644--- a/sdk/guides/craft/motion/sound.md+++ b/sdk/guides/craft/motion/sound.md@@ -68,7 +68,8 @@ everyone else. Two checks, both cheap:loops only between `startFrom` and `endAt`, and that loop is a hard jump. Tile it instead: copies of the take end toend, each in its own Sequence, crossfading over 1.5 s (`fadeIn`/`fadeOut`), or make the take as long as the span.- **Check the finished file.** `raea check FILM.mp4 --words words.json` (the voice's words on the film's clock)- reports, by timecode, dead stops (a steady sound that ends in one 10 ms step), stretches with no voice louder than+ reports, by timecode, dead stops (a steady sound that ends in one 10 ms step: fade a bed out over 100 ms or more;+ a voice ending its word isn't one), stretches with no voice louder thanthe voice, a bed closer than 12 dB to the voice over it, and a true peak over -1 dBTP. Fix every line it prints, orsay why it stands.