madmom.features.chords

This module contains chord recognition related functionality.

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 [1] 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

[1]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  # doctest: +ELLIPSIS
<madmom.audio.chroma.DeepChromaProcessor object at ...>

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

>>> decode = DeepChromaChordRecognitionProcessor()
>>> decode  # doctest: +ELLIPSIS
<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)
... # doctest: +NORMALIZE_WHITESPACE +NORMALIZE_ARRAYS
array([(0. , 1.6, 'F:maj'), (1.6, 2.5, 'A:maj'), (2.5, 4.1, 'D:maj')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', 'O')])

or create a SequentialProcessor that connects them:

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

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

References

[1]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  # doctest: +ELLIPSIS
<madmom.features.chords.CNNChordFeatureProcessor object at 0x...>
>>> features = proc('tests/data/audio/sample2.wav')
>>> features.shape
(41, 128)
>>> features # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
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 [1].

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

[1]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  # doctest: +ELLIPSIS
<madmom.features.chords.CNNChordFeatureProcessor object at 0x...>

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

>>> decode = CRFChordRecognitionProcessor()
>>> decode  # doctest: +ELLIPSIS
<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)
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +IGNORE_UNICODE
... # doctest: +NORMALIZE_ARRAYS
array([(0. , 0.2, 'N'), (0.2, 1.6, 'F:maj'),
       (1.6, 2.4..., 'A:maj'), (2.4..., 4.1, 'D:min')],
      dtype=[('start', '<f8'), ('end', '<f8'), ('label', 'O')])

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

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