Beats and Downbeats
Beats are the perceived pulse positions in the music. Downbeats are the first beat of a bar: the stronger "one" that anchors meter. libsonare exposes both beat and downbeat detection as time arrays.
Beat, downbeat, and bar
A beat is a single pulse: what you tap your foot to.
A bar groups a fixed number of beats, and the time signature says how many. In 4/4, a bar has four beats.
The downbeat is the first beat of each bar, the accent you feel as the start of the cycle. Beat tracking gives you the grid; downbeat detection tells you where the grid starts repeating. That is what you align loops, lyrics, and sections to.
Why beats are not just an even 60/BPM grid
You might expect beats to be trivial once the tempo is known: divide the timeline evenly. Real music makes that unreliable:
- tempo can drift;
- players can push or pull the beat;
- intros can be rubato (played with free, elastic timing);
- onset evidence can be noisy.
Beat tracking therefore solves an optimization problem. It tries to find beat times that line up with strong onsets and keep roughly steady spacing near the tempo.
Dynamic programming finds the globally best trade-off instead of greedily snapping each beat to the nearest onset and accumulating error.
Beat tracking
Beat tracking starts from the onset-strength envelope and a tempo estimate. The tracker rewards frames with strong onset evidence and uses dynamic programming to choose a sequence whose spacing stays close to the expected beat period.
When adaptive tempo is enabled in the native configuration, the tracker can follow local period changes while still penalizing sudden jumps. This is still a pulse estimate, not a score-level transcription.
A beat, downbeat or onset time marks the start of the evidence that produced it, not the peak of the hit. A time can therefore sit slightly ahead of the attack you hear.
Picture a chain of beats rather than a rigid grid. Each gap between two neighboring beats may stretch or shrink a little, but every deviation from the expected beat period costs points (the cost grows with the square of the deviation, scaled by tightness), while every beat that lands on a strong onset earns points. The tracker scores every possible chain across the whole track and keeps the best one, so snapping one beat to a nearby sound is only worth it when the gaps on either side stay plausible.
Downbeat tracking
Downbeats are inferred after beats are placed. libsonare estimates meter phase and scores beat positions with beat strength, low-frequency energy, and a phase prior. The downbeat result is therefore more dependent on arrangement cues than raw beat tracking.
Chord-change evidence is a fourth cue, but it only becomes available once chords are known. The whole-track analysis path detects chords and then refines the downbeats a second time with that evidence; the standalone detectDownbeats helper never reaches that stage. Run the full music analysis when downbeat placement matters and the harmony is the clearest cue in the arrangement.
Sparse intros, pickups (notes that lead in before the first downbeat), weak bass, or ambiguous meter can shift the perceived "one." For UI, it is useful to show downbeats as an assistive overlay rather than as an absolute truth.
Beat tracking answers "where is the pulse", and downbeat tracking answers "which beat opens the bar". The first follows a regular grid; the second leans on musical accents such as bass and chord changes, so it is the estimate more likely to miss.
The evidence behind the decision
The evidence used by downbeat and meter scoring is published as AnalysisResult.beatObservations. accent, hasAttack, lowFrequencyEnergy, and chordChange are indexed by beat. subdivisionAccent has one value for each interval between beats. accent is the maximum 5 ms RMS near the strongest attack around each beat, in linear units. An empty optional stream indicates unmeasured evidence. A zero indicates measured silence. Empty hasAttack treats every beat as attacked. Empty lowFrequencyEnergy disables masked-beat scoring. Chord analysis fills chordChange.
beat.strength and beatObservations.accent are different measurements
A beat's strength is the raw onset-envelope value in one frame at the beat. It is not normalized, its scale depends on the material, and it moves with beat-position jitter.
accent is the maximum 5 ms RMS near the strongest attack around the beat, in linear units. It is the windowed attack measurement used by the library's downbeat and meter analysis. Use accent for comparing beats and strength when the value at the exact frame is what you need.
How libsonare computes it
BeatAnalyzer computes beat positions and the public beatObservations record contains their measured accent, attack, low-frequency, subdivision, and chord-change evidence. chordChange is populated after chord detection. The public detectBeats and detectDownbeats helpers return time lists in seconds. Full analysis can also refine downbeats with chord-change evidence.
Related: Onset Detection, Tempo and BPM, Chord Recognition