Skip to content

song map: tempo and hits change with a 12 ms decoder offset (Apple vs Symphonia), and the tempo is wrong on both #49

Open

Description

@shinyobjectz

What happens

The same song gets a different map on the Mac than on Windows and Linux. raea-perceive song groove.mp3 (163 s, 48 kHz stereo mp3) with each backend:

backend beats first beat downbeats tempo hits
apple (AVFoundation, the Mac's default) 264 0.037 s 77 116.58 62
soft (Symphonia, the default elsewhere since #43) 264 0.024 s 74 112.79 13
ffmpeg 264 0.024 s 74 112.79 13

Why

Two separate things.

  1. The decoders differ by 12 ms. At the map's 22050 Hz, Apple's decode is 508 samples longer than Symphonia's and starts 265 samples (12 ms, about one 576-sample MP3 granule at 48 kHz) later. The gain is the same, and after aligning, the residual rms is 0.018 against a 0.32 signal. Symphonia and ffmpeg agree. If the soft decode is padded by those 265 samples and fed in as .f32, the map comes out identical to Apple's in every field. So the whole difference is the offset.
  2. The map is unstable under a 12 ms shift, and its tempo is wrong both ways. A line fitted through the beats gives 99.0 BPM on both decodes (median gap 0.605 s). Neither 116.58 nor 112.79 is the song's tempo. Beat This! marks many 2-beat "bars" in this song (1.21 s between downbeats, against a 2.42 s median). analyse.rs's downbeat fit counts each such gap as round(1.21 / 2.42) = 1 whole bar, then divides by 4 beats per bar, so the tempo comes out too high. How high depends on how many half-bars there are, and the 12 ms shift changes that (74 vs 77 downbeats). The hits (13 vs 62) move with it.

Expected

The tempo matches the beats (99 BPM here), and a few milliseconds of decoder offset don't change the map's tempo, sections or hits.

Plan

Fix (2) first: derive the tempo from the beats rather than the bar count, then check what the hits depend on. (1) is under a frame at 60 fps. Each platform's export decodes the song with that same decoder, so the beats line up with what that platform renders. Picking one reference decoder can come later, if it still matters once (2) is fixed.

Activity

  1. added a commit that references this issue on Nov 8, 2026
  2. shinyobjectz commented on Nov 8, 2026

    @shinyobjectz
    OwnerAuthor

    The tempo is fixed in 3d170ce. It's now a line fitted through every beat against its count, not through the downbeats against their bar count. Both decodes of the 163 s mp3 now read 99.0 BPM; before, they read 112.8 and 116.6. The hits went from 13 vs 62 to 6 vs 9, since they followed the tempo. A unit test with every third bar half-length reads 99.17 BPM for beats 0.605 s apart (the old code gives 119.26).

    The 12 ms decoder offset stays as it is. It's under one frame at 60 fps, and each platform exports the audio with the same decoder that made its map.

    Still open: bars (78 vs 75) and one section boundary (41.8 vs 43.0 s) follow each decode's downbeats. The two decodes' downbeats in beat indices:

    • apple: downbeats at beat phase 1 (mod 4) 66 times and phase 3 11 times; bar gaps of 4 beats 55 times and 2 beats 21 times
    • soft: phase 1 65 times, phase 3 9 times; gaps of 4 beats 57 times and 2 beats 16 times

    Every 2-beat "bar" is a stray downbeat at phase 3 inside a steady run of phase 1 (beats 51, 55, 59, 67, 71 and 131). Where these strays fall is what differs between the decodes. So bars could be counted from the beats: take the downbeat phase most downbeats agree on, and start a bar every beatsPerBar beats from it. That gives 66 identical bars on both decodes here. It would treat a real change of meter or a dropped beat as noise, though. Only letting the phase change after it holds for several bars avoids that, but the soft decode has a two-bar phase-3 run (67, 71) that a threshold of 2 would still split on. Until then, it's a known limit of reading bars straight from the model's downbeats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions