denote.chords¶
Model-free chord recognition: spectral-peak chroma, chord templates, a hidden Markov model.
The pieces behind the chroma_hmm backend, usable on their own:
peaks_chroma(y, sr): a(frames, 12)chroma from spectral peaks, log-compressedchord_templates(vocabulary): unit templates with each tone’s overtones folded indecode_chords(chroma, ...): free decoding (Viterbi, or the causal forward filter), optionally restricted to avocabularyalign_sequence(chroma, sequence): a left-to-right decode through a known ordered chord list (chord-sequence-to-audio alignment: when each chord happens)
Labels are Harte syntax (C:maj, A:min7, N for no chord), the vocabulary of
mir_eval.chord and the JAMS chord namespace. All times are seconds.
>>> chord_label(9, "min")
'A:min'
>>> parse_chord_label("Am7")
('A:min7', 9, (0, 3, 7, 10))
Module Attributes
Harte shorthand -> semitone intervals above the root. |
|
flat between 0.4 and 0.6). |
|
Per-transition probabilities of the order-tolerant alignment (a jump to a section start, a skipped entry). |
Functions
|
Force the decode through |
|
Harte label of a pitch class and a quality shorthand. |
|
|
|
|
|
Every root x quality as Harte labels, qualities outermost (``C:maj . |
|
|
|
|
|
Run-length the per-frame path into |
|
|
- denote.chords.DFLT_JUMP_P = 0.01¶
Per-transition probabilities of the order-tolerant alignment (a jump to a section start, a skipped entry).
- denote.chords.DFLT_NO_CHORD_COS = 0.5¶
flat between 0.4 and 0.6).
- Type:
Cosine a frame must beat to be a chord (measured on GuitarSet
- denote.chords.QUALITY_INTERVALS = {'6': (0, 4, 7, 9), '7': (0, 4, 7, 10), 'aug': (0, 4, 8), 'dim': (0, 3, 6), 'dim7': (0, 3, 6, 9), 'hdim7': (0, 3, 6, 10), 'maj': (0, 4, 7), 'maj7': (0, 4, 7, 11), 'min': (0, 3, 7), 'min6': (0, 3, 7, 9), 'min7': (0, 3, 7, 10), 'sus2': (0, 2, 7), 'sus4': (0, 5, 7)}¶
Harte shorthand -> semitone intervals above the root. The SSOT for template tones.
- denote.chords.align_sequence(chroma, sequence, level_db=None, *, hop_s=0.046, kappa=20.0, gate_db=45.0, no_chord_cos=0.5, harmonics=0.6, stay=None, sections=None, jump_p=0.01, skip_p=0.02)[source]¶
Force the decode through
sequence(repeats allowed): a left-to-right HMM.With
sectionsthe order is tolerant, as in JumpDTW (Fremerey et al. 2010):sectionsis one key per entry (a system or page number, a section name): a new section starts where the key changes. At the end of a section the decode may jump to the start of any section (a repeat, a skip, a D.S.), at costjump_p; within a section it may skip one entry (a chord the recording leaves out), at costskip_p; it may start at any section and stop after any. Withoutsectionsthe order is strict.Returns
(path, labels, positions):path[t]indexeslabels, one label per position of[N, *sequence, N](a no-chord state may precede and follow the sequence, for an intro or an outro);positions[t]is the sequence index of framet(-1for the no-chord ends), which keeps two equal neighbouring chords apart.
- denote.chords.chord_label(root, quality)[source]¶
Harte label of a pitch class and a quality shorthand.
- Return type:
- denote.chords.chord_templates(vocabulary, *, harmonics=0.6, n_harmonics=6)[source]¶
(K, 12)unit-norm templates and the Harte labels, one per vocabulary entry.harmonics> 0 adds each chord tone’s overtones (harmonichweightedharmonics**(h-1)), which is how a played chord actually fills the chroma; 0 gives binary templates.
- denote.chords.decode_chords(chroma, level_db=None, *, vocabulary=None, hop_s=0.046, dwell_s=2.0, kappa=20.0, gate_db=45.0, no_chord_cos=0.5, harmonics=0.6, causal=False)[source]¶
(path, states): the state index per frame and the Harte labels (Nlast).vocabularyrestricts the states to those chords (default: every major and minor triad). A chord stays fordwell_sseconds on average.causal=Truereads a frame’s decision from the frames up to it only (what a live follower can know); default is offline Viterbi.
- denote.chords.default_vocabulary(qualities=('maj', 'min'))[source]¶
Every root x quality as Harte labels, qualities outermost (
C:maj ... B:maj, C:min ...).
- denote.chords.emissions(chroma, templates, level_db=None, *, kappa=20.0, gate_db=45.0, no_chord_cos=0.5)[source]¶
(frames, K + 1)normalised likelihoodsexp(kappa * cosine); the last column is the no-chord state: a fixed cosineno_chord_cos(a frame is a chord only when some template matches better;Noneuses the cosine with flat chroma instead, which log compression makes far too high), and it wins in frames more thangate_dbbelow the loudest so far.- Return type:
ndarray
- denote.chords.parse_chord_label(label)[source]¶
(harte_label, root_pc, intervals)of a chord given as Harte (A:min7) or in common symbols (F#m,Bb; sevenths and the like needchordsym). RaisesValueErrorwhen unreadable.
- denote.chords.path_to_segments(path, labels, *, hop_s, duration=None, split_on=None)[source]¶
Run-length the per-frame path into
[{start, end, label}](frametspanst * hop_s+- half a hop).split_on(e.g. sequence positions) also cuts where it changes.
- denote.chords.peaks_chroma(y, sr, *, window_s=0.186, hop_s=0.046, min_hz=55.0, max_hz=2100.0, floor_db=50.0, log_compression=100.0)[source]¶
(chroma (frames, 12), level_db (frames,))from spectral peaks only (HPCP-like).Local maxima within
floor_dbof the frame’s top and betweenmin_hzandmax_hz; frequency refined by parabolic interpolation; each peak goes to its nearest pitch class, weighted bycos^2of its distance in semitones, and its magnitude is compressed aslog(1 + log_compression * |X| / frame max). Frametis centred att * hop_s.- Return type:
Tuple[ndarray,ndarray]