Parsons code is a notation of the overall shape of a melody. Wikipedia describes it thus:

The Parsons code, formally named the Parsons Code for Melodic Contours, is a simple notation used to identify a piece of music through melodic motion—the motion of the pitch up and down. Denys Parsons developed this system for his 1975 book, The Directory of Tunes and Musical Themes. Representing a melody in this manner makes it easy to index or search for particular pieces.

Given a sound file containing a melody, how would a program calculate its Parsons code?

  • 1
    You should really specify what you mean by "sound file". The format of "sound file" will dictate to what extent it will be possible to extract salient lines, which is crucial to computing parsons code. For example, MusicXML - midi - Wave file are 3 kinds of "sound file" in descending order of feasibility for extracting/computing parsons code. Commented Apr 10, 2014 at 2:13
  • I am no sound expert, so I may very well be wrong. I assumed that the encoding is irrelevant.
    – elpadi
    Commented Apr 10, 2014 at 18:36
  • @RolandBouman I would have said that of the three file types you mentioned, only the WAV is a sound file. MusicXML and MIDI don't contain waveform data, i.e. sound. For the purposes of this question, as long as the file is indeed a sound file, (Mp3, aac, aiff, etc.) the encoding is irrelevant.
    – NReilingh
    Commented Apr 10, 2014 at 18:54
  • If we have a sound file, the problem may be effectively impossible. If we start with MIDI or MusicXML, it's relatively easy.
    – Kevin
    Commented Apr 12, 2014 at 7:31
  • Are there databases which connect sound files with their parson code? If yes, then it might be possible to develop a machine learning system for this task. Commented Jan 14, 2019 at 6:39

1 Answer 1


It depends.

For most music the answer is no, since this amounts to transcribing, which is still most accurately done by humans. There exist libraries of Parson's codes for existing known themes and songs.

For a sound file that consists of a single melody line in isolation, this becomes much more practical. All there is to do is generate an FFT for each point in time, find the peak Hz value, and then write some simple AI to track the upwards and downwards movements of that Hz value over time. This is how "theme recognition" websites work that allow you to find a melody using a computer microphone--the recorded sound is processed into a Parson's code, which is then compared with a database of known codes for various themes, which are returned as results.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.