madmom.features.chords

This module contains chord recognition related functionality.

madmom.features.chords.load_chords(filename)[source]

Load labelled chord segments from a file. Chord segments must follow the following format, one chord label per line:

<start_time> <end_time> <chord_label>

All times should be given in seconds.

Parameters:

filename : str or file handle

File containing the segments

Returns:

numpy structured array

Structured array with columns ‘start’, ‘end’, and ‘label’, containing the start time, end time, and segment label respectively

Notes

Segment files cannot contain comments, because e.g. chord annotations can contain the ‘#’ character! The maximum label length is 32 characters.

madmom.features.chords.write_chords(chords, filename)[source]

Write chord segments to a file.

Parameters:

chords : numpy structured array

Chord segments, one per row (column definition see notes).

filename : str or file handle

Output filename or handle

Returns:

numpy structured array

Chord segments.

Notes

Chords are represented as numpy structured array with three named columns: ‘start’ contains the start time in seconds, ‘end’ the end time in seconds, and ‘label’ the chord label.

madmom.features.chords.majmin_targets_to_chord_labels(targets, fps)[source]

Converts a series of major/minor chord targets to human readable chord labels. Targets are assumed to be spaced equidistant in time as defined by the fps parameter (each target represents one ‘frame’).

Ids 0-11 encode major chords starting with root ‘A’, 12-23 minor chords. Id 24 represents ‘N’, the no-chord class.

Parameters:

targets : iterable

Iterable containing chord class ids.

fps : float

Frames per second. Consecutive class

Returns:

chord labels : list

List of tuples of the form (start time, end time, chord label)

class madmom.features.chords.DeepChromaChordRecognitionProcessor(model=None, fps=10, **kwargs)[source]

Recognise major and minor chords from deep chroma vectors [R44] using a Conditional Random Field.

Parameters:

model : str

File containing the CRF model. If None, use the model supplied with madmom.

fps : float

Frames per second. Must correspond to the fps of the incoming activations and the model.

References

[R44](1, 2) Filip Korzeniowski and Gerhard Widmer, “Feature Learning for Chord Recognition: The Deep Chroma Extractor”, Proceedings of the 17th International Society for Music Information Retrieval Conference (ISMIR), 2016.

Examples

To recognise chords in an audio file using the DeepChromaChordRecognitionProcessor you first need to create a madmom.audio.chroma.DeepChromaProcessor to extract the appropriate chroma vectors.

>>> from madmom.audio.chroma import DeepChromaProcessor
>>> dcp = DeepChromaProcessor()
>>> dcp  
<madmom.audio.chroma.DeepChromaProcessor object at ...>

Then, create the DeepChromaChordRecognitionProcessor to decode a chord sequence from the extracted chromas:

>>> decode = DeepChromaChordRecognitionProcessor()
>>> decode  
<madmom.features.chords.DeepChromaChordRecognitionProcessor object at ...>

To transcribe the chords, you can either manually call the processors one after another,

>>> chroma = dcp('tests/data/audio/sample2.wav')
>>> decode(chroma)
... 
array([(0. , 1.6, u'F:maj'), (1.6, 2.5, u'A:maj'), (2.5, 4.1, u'D:maj')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', '<U32')])

or create a SequentialProcessor that connects them:

>>> from madmom.processors import SequentialProcessor
>>> chordrec = SequentialProcessor([dcp, decode])
>>> chordrec('tests/data/audio/sample2.wav')
... 
array([(0. , 1.6, u'F:maj'), (1.6, 2.5, u'A:maj'), (2.5, 4.1, u'D:maj')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', '<U32')])
class madmom.features.chords.CNNChordFeatureProcessor(**kwargs)[source]

Extract learned features for chord recognition, as described in [R45].

References

[R45](1, 2) Filip Korzeniowski and Gerhard Widmer, “A Fully Convolutional Deep Auditory Model for Musical Chord Recognition”, Proceedings of IEEE International Workshop on Machine Learning for Signal Processing (MLSP), 2016.

Examples

>>> proc = CNNChordFeatureProcessor()
>>> proc  
<madmom.features.chords.CNNChordFeatureProcessor object at 0x...>
>>> features = proc('tests/data/audio/sample2.wav')
>>> features.shape
(41, 128)
>>> features 
array([[ 0.05798,  0.     , ...,  0.02757,  0.014  ],
       [ 0.06604,  0.     , ...,  0.02898,  0.00886],
       ...,
       [ 0.00655,  0.1166 , ...,  0.00651,  0.     ],
       [ 0.01476,  0.11185, ...,  0.00287,  0.     ]])
class madmom.features.chords.CRFChordRecognitionProcessor(model=None, fps=10, **kwargs)[source]

Recognise major and minor chords from learned features extracted by a convolutional neural network, as described in [R46].

Parameters:

model : str

File containing the CRF model. If None, use the model supplied with madmom.

fps : float

Frames per second. Must correspond to the fps of the incoming activations and the model.

References

[R46](1, 2) Filip Korzeniowski and Gerhard Widmer, “A Fully Convolutional Deep Auditory Model for Musical Chord Recognition”, Proceedings of IEEE International Workshop on Machine Learning for Signal Processing (MLSP), 2016.

Examples

To recognise chords using the CRFChordRecognitionProcessor, you first need to extract features using the CNNChordFeatureProcessor.

>>> featproc = CNNChordFeatureProcessor()
>>> featproc  
<madmom.features.chords.CNNChordFeatureProcessor object at 0x...>

Then, create the CRFChordRecognitionProcessor to decode a chord sequence from the extracted features:

>>> decode = CRFChordRecognitionProcessor()
>>> decode  
<madmom.features.chords.CRFChordRecognitionProcessor object at 0x...>

To transcribe the chords, you can either manually call the processors one after another,

>>> feats = featproc('tests/data/audio/sample2.wav')
>>> decode(feats)
... 
... 
array([(0. , 0.2, u'N'), (0.2, 1.6, u'F:maj'),
       (1.6, 2.4..., u'A:maj'), (2.4..., 4.1, u'D:min')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', '<U32')])

or create a madmom.processors.SequentialProcessor that connects them:

>>> from madmom.processors import SequentialProcessor
>>> chordrec = SequentialProcessor([featproc, decode])
>>> chordrec('tests/data/audio/sample2.wav')
... 
... 
array([(0. , 0.2, u'N'), (0.2, 1.6, u'F:maj'),
       (1.6, 2.4..., u'A:maj'), (2.4..., 4.1, u'D:min')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', '<U32')])