Skip to content

Section and Structure ​

Section analysis divides a track into longer musical spans such as intro, verse, chorus, bridge, instrumental, and outro. It is a structural estimate: useful for navigation and visualization, but not a replacement for a producer's arrangement notes.

Use it to navigate a track, set loop points around a chorus, or build a structural visualization — anywhere you need an approximate map of the song's large-scale form.

For newcomers, think of section analysis as building a map of the song. It looks at large spans such as an intro, verse-like area, chorus-like area, or bridge-like area, rather than short events like individual beats or chords.

Reading a self-similarity matrix ​

The central tool is the self-similarity matrix (SSM). It compares every moment of a feature sequence against every other moment.

You can read it as a "which parts sound alike?" table:

Pattern in the SSMMeaning
Bright cellThese two times sound similar
Block along the diagonalA span is internally consistent, so it may be one section
Stripe away from the diagonalTwo different times sound similar, often a repeated chorus or repeated verse
From repetition to a section list
self-similarity matrixtime →a repeat, off the diagonalnoveltydetected sectionsintroABACAtime →
  • frames that sound alike
  • novelty
  • boundary
Each A section is similar to itself along the diagonal and to the other A sections off it — those off-diagonal blocks are the repetition cue. The novelty curve measures how sharply the matrix changes from one moment to the next, and its peaks are where boundaries get placed.

Two signals are especially useful:

  • Novelty means the SSM changes suddenly. It helps find boundaries.
  • Repetition means similar material appears in separate places. It helps group recurring sections.

Novelty alone tends to split too much. Repetition alone can miss one-off parts. libsonare combines both.

Boundaries first ​

libsonare averages MFCC (c1 to c13) and chroma over each beat, so the track becomes one column per beat. Stretches before the first beat, after the last one and across large gaps in the beat track are filled with columns at the median beat spacing, and a track with fewer than 8 beats gets a fixed 0.5 s grid instead. Boundary candidates are the peaks of a checkerboard novelty curve over those columns: a small checkerboard-shaped kernel slides along the diagonal of the self-similarity matrix and compares "just before" with "just after", and the score spikes where the two blocks differ.

A peak becomes a boundary only if the harmony on its two sides measurably differs: the cosine distance between the average chroma either side must reach 0.017 (a boundary into or out of silence always qualifies). A timbre test on the raw MFCC exists but is switched off, because steady material drifts in MFCC by too much to tell apart from a real change. Normalized features make even a steady chord look like novelty, and this check is what keeps that drift from being cut into sections. When the beat tracker trusts the meter, each boundary also moves onto the nearest downbeat within one column.

minSectionSec (default 4 s) sets the scale of the analysis. The kernel spans twice this on each side of a boundary, repetition is matched over runs of this length, and a merge pass folds any span still shorter than it into a neighbor, so it is a real floor on the length of a returned section. The floor is tested half a column short, because boundaries sit on beat times and a shortfall below the grid's resolution should not remove a section. The one exception is a lone whole-track section: when merging leaves a single span, it is returned whatever its length. The leading and trailing spans are bounded by the file edges rather than by two peaks, and very short edits, drops, or pickup bars are absorbed into neighboring spans rather than returned on their own. Peaks are spaced at least minSectionSec apart, capped at 2 s.

A novelty peak is kept when it reaches threshold of the largest novelty within 60 seconds on either side, not of the whole-track maximum, so a dominant change does not hide weaker section changes far from it. A lone dominant event, one that no other event within the window reaches 30% of, is set aside when the reference is taken, so a short loud burst does not mask the section changes around it. Section analysis uses a threshold of 0.22 and the 60 s window and exposes neither; threshold, absoluteThreshold and referenceWindow are options of detectBoundaries only, whose default threshold stays 0.3.

A track longer than 2048 columns has adjacent columns merged pairwise until it fits, which coarsens the grid but not the times: boundary timeSec values stay on the original audio timeline. The boundary detector behind detectBoundaries works on frames instead and mean-pools them when the self-similarity matrix would grow too large; there the diagnostic frame field refers to the pooled grid, so place markers from time, not from frame.

The boundary stage is reachable on its own, without the labeling that follows it: detectBoundaries / detect_boundaries returns the transitions and the novelty curve they were picked from, which is what a caller applying its own threshold needs. It is the frame-level detector, not the beat-grid one inside section analysis. See detectBoundaries(request).

Then repetition ​

Mean chroma cannot tell a verse from a chorus in the same key, so sections are compared as sequences instead. The column self-similarity matrix is smoothed along its diagonals over a run of minSectionSec, and two sections are scored by sliding the shorter one along the longer one (with 1 s of slack either side) and averaging the smoothed similarity along the best alignment. A pair whose lengths differ more than fourfold scores 0.

Three steps turn the scores into groups:

  1. A section that the novelty split in two is rejoined when its two halves line up, one after the other, with a single other section of about their combined length.
  2. Sections whose pair scores reach 0.60 are grouped by complete linkage, so every member of a group matches every other. Groups are numbered 0, 1, 2... in order of first appearance, and a section that repeats nothing has a group of its own.
  3. Two neighboring sections of one group are merged only when the group occurs elsewhere and the merged section is at most 1.25 times its longest other occurrence. Two back-to-back choruses that are each a full chorus stay two occurrences.

The result is group on every section, and the C++ section_self_similarity() returns the pair scores before the 0.60 cut for a caller that wants its own threshold.

Then labels ​

Labels are read off the groups by a fixed rule table, applied in this order. A row only sees the sections the rows above left unlabeled.

RuleLabelCondition
1ChorusOf the groups that occur at least twice, the one with the largest occurrence count times mean energy
2VerseOf the other groups that occur at least twice, the one covering the most time
3Pre-ChorusEvery other repeated group whose occurrences are all followed directly by a Chorus and whose mean length is shorter than the Chorus's
4IntroThe first section, if it is outside rules 1 to 3 and is quiet or short, or if it belongs to one of them but is instrumental
5OutroThe same test for the last section
6InstrumentalA section sharing a group with the Intro or Outro, or one with low vocal likelihood next to a Chorus, Verse or Pre-Chorus occurrence
7BridgeA section with a Chorus occurrence somewhere before it and another somewhere after it
8UnknownAnything else

"Quiet" means the section's median frame RMS is below 35% of the loudest section's (of the second loudest when there are four or more sections, so one burst does not set the bar); "short" means at most 0.75 times the Chorus's mean length (or the median section length when there is no Chorus). Energy is the section's median frame RMS, and vocal likelihood is the share of spectral energy in the vocal band (300 to 3400 Hz) weighted by how tonal the section is.

A label's confidence is in [0.5, 1]: for rules 1 to 3 it rises with how well the group's occurrences match each other, for an edge section found by quietness it rises with how quiet it is, and for a Bridge or an instrumental it follows the vocal likelihood. Unknown always has confidence 0, and no label is demoted to Unknown afterwards.

Typical outcomes follow from the rules:

PatternLabel
The repeated group with the most energy over its occurrencesChorus
Another repeated group covering the most timeVerse
A shorter repeated group always right before the ChorusPre-Chorus
Quiet or short first or last spanIntro / outro
A one-off span with low vocal likelihood beside a repeatInstrumental
A one-off span between two chorusesBridge

Repetition decides the labels, so unusual forms read by the rules and not by the genre. An AABA form reads A as Chorus; a song with one chorus and a repeating verse reads the verse as Chorus; a track that repeats an instrumental riff reads the riff as Chorus.

Uniform material is given no form at all

Material that never changes gets no boundaries and comes back as one Unknown span. So does a track whose sections all fall into a single group, such as the same eight bars repeated, because one group carries no contrast to label. With a different intro in front, the same repeating material reads as an intro followed by choruses.

These labels are intentionally heuristic. They are good for orientation, not for declaring a canonical song form. Prefer group and the boundaries when you only need to know what repeats.

Two ways to get Unknown ​

Unknown means no labeling rule matched. It always has confidence 0, and it comes back in two shapes:

What you seeWhat happenedWhat to do
One section from 0 to the end of the trackNo boundary survived: no novelty peak cleared the boundary thresholds, the sound never measurably changed, every section fell into one group, or the merges folded everything into one span. Silence and a very short clip also end here.Treat the track as unsegmented. To look for structure anyway, call detectBoundaries and read the novelty curve against a lower threshold, or shorten minSectionSec.
One or more of several sectionsA section no rule claims: an edge section that is neither quiet nor short and repeats nothing, or an interior section that repeats nothing and does not sit between two choruses (a final chorus a key higher is the usual case).Keep it as a section; the position and the group are the information. Name it by hand if your UI needs a label.

PreChorus is produced like any other label, so a filter on it returns the sections rule 3 found, or nothing when the track has no such group. Thresholds and options are in Sections.

Filtering Unknown out drops real stretches of the track

Both of these are spans of music the labeling declined to name, not padding. To drop only the unsegmented-track case, test for a single section covering the whole track rather than the label alone.

Why the result is an estimate ​

Song structure is partly subjective. Two listeners may disagree about the exact start of a chorus, and different genres use different cues. A techno track and a ballad do not announce sections in the same way.

Treat section output as a strong hint for navigation, looping, and visualization. It works best on music with clear repeated sections, and it is weaker on through-composed material (music that keeps developing instead of repeating sections), ambient, or very gradual material. A boundary being a few seconds off is normal, so automatic results are best used as a starting point for review.

How libsonare computes it

SectionAnalyzer computes MFCC c1 to c13, chroma and frame RMS from one shared STFT at 22050 Hz, hop 512, and averages them per beat column. MFCC is centered over the audible columns and chroma is L2-normalized per column, each block is L2-normalized, and the two are weighted equally. A column whose mean RMS carries no evidence of sound is silent and holds zeros. The checkerboard novelty runs on those columns with a kernel half-width of twice minSectionSec (truncated near the track edges), candidates are kept only where the chroma cosine distance across the boundary clears a floor, and survivors are snapped to downbeats and put through the minimum-length merge. Sections are scored pairwise on the diagonally smoothed self-similarity matrix, joined, grouped and merged as above, and labeled by the rule table. A silent file has no energy to compare, so it returns one Unknown span with confidence 0. section_at(time) outside every span returns an empty Unknown with start and end both 0, a lookup miss and not a detection. The beats come from BeatAnalyzer; inside analyze() they are the chord-refined beats, so sections from analyze() and from analyzeSections on the same track can differ.

Related: Mel, MFCC, and Timbre, Chroma Features, MIR Overview