ChordSuggester (I)

Source: Deep Learning on Medium

Some music theory

To fully understand the system, it is necessary to have a basic knowledge of music theory. In this article some important musical concepts will be explained.

The elements of music

Musical composition includes several aspects, such as melody, rhythm or harmony.

The Elements of Music: Melody, Rhythm, & Harmony: Melody, Rhythm and Harmony by Jason Martineau
  • Melody refers to how notes are disposed horizontally, in time, one before the other. For example, Gregorian Chant focuses just on melody, having a repetitive rhythm and no harmony.
Gregorian Chant score: all the notes have same duration (no rhythm) and only one note sound at once.
  • Rhythm refers to how note durations are combined. Even using just rhythmic resources, good compositions can be created. One example could be African percussion, which tends to be much richer than classical European music.
Sometimes, a rich rhythm is enough
  • Harmony refers to how notes are disposed vertically i.e. how several ones sound at the same time. ChordSuggester will focus on this aspect. For example, the second movement of Beethoven’s 7th symphony does not have a special melody or rhythm, but its harmony makes it one of the great masterpieces on history.

Of course, these three elements can be combined to create even more interesting compositions. A well-know example is The Pink Panther Theme by the great American composer Henry Mancini:

What is a note?

A note is just a sound with a given frequency (in reality is an aggregate of several frequencies but we can simplify the problem attending just to the frequency with more amplitude, called fundamental frequency). This sound can be represented mathematically:

A note with its several frequencies. In this case, the fundamental frequency is the red one.

The English system represents musical using letters (A,B,C,D,E,F,G) corresponding to (La,Si,Do,Re,Mi,Fa,Sol) in Latin system .

Origin of Latin naming system. UT was replaced by DO for simplicity when singing. SI comes from the initials of Sant Joannes

Attending only to the fundamental frequency, we can univocally identify a note with a frequency:

Musical Harmonic Series

What is an interval?

The interval is the distance between two notes. This distance is measured in semitones (or half-steps in USA). The distance between adjacent notes in a piano is one semitone.

Distance between notes

For example, the distance between D and G is 5 semitones (ST), i.e., 2 tones (T) and 1 ST.

Additionally, we can use accidentals to modify our notes:

  • A ‘#’, called sharp, increases a note in one ST.
  • A ‘♭’, called sharp, increases a note in one ST.

Note that, for example, G♭= F#, A♭= G# or even E# = F (distance between E and F is just one ST).

As a result, we have the chromatic scale, that contains all these 12 notes:

Chromatic scale (ascending and descending) played by a flute.
Ascending and descending chromatic scale in a sheet

The intervals have a musical name. For example, a distance of 3 ST is called a minor third. Below there is a table including interval names and frequency ratios:

Interval names (0 STs = Unison, 1 ST = Minor 2nd…) and its frequency ratios

Let’s attend a moment to the frequency ratios. Note that the simplest ratios (excluding unison and octave that are trivial) correspond to Perfect Fifth (3/2) and Major Third (5/4).

And… here comes the curious thing!! These intervals are considered the most pleasant (consonant is the musical term) by our ear versus other more complex (dissonant) as Minor Second (16/15). Therefore, our musical system is not arbitrarily chosen, it makes physical sense and even satisfies the KISS principle!

More information about that (video in Spanish):

What is a chord?

A chord is a set of several notes sounding at the same time. Theoretically, there is no limit on the number of notes to be included in a chord.

Nevertheless, it’s not very common to have more than 6 notes in a chord and the more usual is to have 3 or 4.

We find several ways to represent a chord:

  • Indicating the notes it has (we will see it in the code, where we use an array of 12 positions).
  • Naming it. This is the musical way.

The name of a chord is composed by:

  • Root (AKA fundamental): is the main note. For example, could be ‘B’
  • Type or Quality: is a name that indicates the intervals from the root note. For example, the most extended chord, that is the major chord contains a Major Third (4 STs) and a Perfect Fifth (7 STs) from the root note. Again, most extended = simplest. For example, a Cmaj chord or simply C is composed by C, E and G notes.
Major chords: 4 and 7 semitones
Minor chords: 3 and 7 semitones
7th chords, 4, 7 and 10 semitones
  • Slash: A slash chord is a chord (eg. G/B) which indicates emphasis of a bass note other than the root of the chord. When a chord is played it is typically assumed the bass will emphasise the root of the chord. Occasionally a different note is preferred and results in a chord with an alternate bass note. The inclusion of the slash note (AKA on) made the problem more complex, so it was ignored for the current approach.

Relation between chords: the circle of 5ths

The harmony not only consist on setting notes vertically (create a chord) but also on disposing chords horizontally (one before the other).

In order to be interesting, a composition must create tension and distension. There are tons of theory behind that, but we can summarise it by looking at this diagram called Circle of Fifths:

Circle of fifths

Let’s suppose that we start with the chord C. If we go clockwise and choose a chord (the nearest, the more normal), we will create tension: G. The ear will ask us to go back counterclockwise and play again a C. This is the simplest chord progression and, again, on of the most common. Other interesting progression is C-F-G, that initially creates distension in order to generate a greater tension when going to G. For that reason, there are lost of songs with an amplitude 3 inside the circle of 5ths.

More information: