MIDI Transpose

A piano has 88 keys, about 7 1/2 octaves, allowing songs to have a very large range of notes, from the very lowest, to the very highest.  Most piano compositions do not use the entire range, but it is very common for piano pieces to span 4-5 octaves.  In comparison the xylophone used in the Build Your Music project has only 25 notes, or 2 octaves.  Most pieces written for piano (other than the most basic beginner songs) span more than 2 octaves.  Below is shown a few measures from Beethoven’s Piano Sonata Opus 10, No 1, 3rd Movement.  The yellow highlights the range of notes that can be played by the G-to-G 2-octave chromatic xylophone.  As you can see, this song has notes both above and below the range of the xylophone.

01 Notes Outside of Range

One option would be to have the xylophone simply not play any notes above or below its range.  But in that case, the song would not sound good.  At best, you would hear gaps where there should be notes, and at worst, you might not even be able to recognize the song.  Of course, you could limit yourself to only use songs within the xylophone range, but that would likely eliminate most of your favorites.

Instead of cutting off notes, the robotic xylophone software performs an “octave transpose” on any notes above or below the xylophone range.  Notes higher than the highest xylophone note are transposed lower by 1 or 2 octaves until they are within the range of the xylophone.  Likewise, notes lower than the lowest xylophone note are transposed higher by 1 or 2 octaves.  Below is measures 7 and 8 from Scott Joplin’s Maple Leaf Rag.  In this section of the song, the notes range from A♭1 to A♭6.  The figure illustrates how A♭1 and A♭2 are transposed up to an A♭3, while A♭5 and A♭6 are transposed down to an A♭4.

02 Octave Transpose Notes

The octave transpose does not always sound perfect, but I have found that for the majority of songs, this is a very good way to preserve all the notes of the song and have the song be recognizable on the xylophone.

Some MIDI files may have notes that are lower than the range of the xylophone, but not any notes that are higher.  Some songs might have the highest note be lower than the highest note on the xylophone.  For example, the song God Bless America shown below has C5 as the highest note.  If this song were played directly on the G3-to-G5 xylophone with the octave-transpose as described above, the top half-octave on the xylophone would not even be used.  At the same time, all of the harmony would be compressed into the lower notes of the xylophone.

03 Highest Note C5

I have found that for most songs, they come out sounding the best when the highest note in the melody matches the highest note on the xylophone.  So in the above example of God Bless America, the song would have to be transposed a fifth (7 half-steps) higher, to make the highest note in the melody a G5.  For many songs, the melody spans only 1 octave, so that leaves the lower octave of the xylophone for all of the harmony and background notes.

The INI file (see SD Card Config page) gives two different ways to specify the transpose:

  • Line 5 is the Transpose (T) in # of half-steps.  This can be either positive (to transpose higher) or negative (to transpose lower).  In the example above, we would set T=7 to make the highest note a G5 instead of a C5.
  • Line 6 is the Target Highest Note (THN) as the MIDI note number.  This tells the program which note in the original MIDI file should correspond to the highest note on the xylophone.  In the above example, we would set THN=72 (the MIDI note number for C5).

I will illustrate the transpose function further.  On the G-to-G xylophone, we have:

Lowest Note: LN = 55 (G3)

Highest Note: HN = 79 (G5)

Then the Transposed Note (TN) is determined from the original MIDI Note (MN) by:

TN = MN + T + HNTHN

For notes outside of the xylophone range, the number of octaves (N) to be transposed is determined from TN by the piecewise function:

OctTrans2

Then the actual note played on the xylophone (XN) is:

XN = TN + 12*N

Note that with the above octave-transpose function, we should always have LN <= XN <= HN.  In the case where the transposed note TN is more than 2 octaves outside of the xylophone range, it is straight-forward to extend the function N(TN).

You may notice that the values for Transpose (T) and Target Highest Note (THN) are somewhat redundant with each other.  Just one of them is enough to specify the transpose of the MIDI file.  Using THN to define the transpose comes in handy if the same MIDI file will be played on different xylophones.  (E.g. same MIDI file played on both a C-to-C and a G-to-G xylophone).  Conversely, defining the transpose in # of half-steps is a little more intuitive.