Understanding musical tuning systems | by richard bultitude | Medium

Understanding musical tuning systems

Why I created TuningSynth.com

richard bultitude
8 min readSep 3, 2021

Background

Five years ago, I went on a journey of discovery that took me further than I ever expected. It began when I was creating the Conditional Orchestra, a web app that converts weather data into music. For certain weather conditions I wanted to generate music using more than is in the standard western 12 note system (12 TET) but I couldn’t find a suitable pre-existing library or concise instructions on how to do so. Looking back, I’m glad I couldn’t just grab something off the shelf, because it forced me to learn about the physics of sound and music theory. The product of that work is the Tuning Synth, which is designed to help you hear and see how different musical tuning systems differ and overlap.

Chords and compromises

In nature, when matter vibrates at a given frequency it will often produce harmonics. These are effectively higher pitches (overtones)that are part of a mathematical pattern. Each of these notes can be described using whole number ratios, which belong to the harmonic series. This is sacred maths and can also be found in other aspects of nature.

The first three waveforms in the harmonic series.

To hear some of the notes in the series, go to Tuning Synth and select Harmonic Series from the Tuning System menu.

Music and audio options in The Tuning Synth

Then play a note via the on-screen keyboard, QWERTY keyboard or MIDI device. Notice how different it is from how a standard western keyboard is tuned — the second upper note is much higher, an octave higher in fact. As you go up the scale further you will notice that the higher harmonics are perceived as closer together than lower ones. This is because the human ears respond to sound in a non linear way.

The long membrane in the human ear has physical properties, which affect how we perceive pitch. See part 6 of Bo Constantinsen’s Udemy course for a full explanation.

The world’s earliest musical instrument designers based their tuning system on what they could hear, so the first systems used what is known as Just Intonation.

Though Just Intonation uses whole number ratios, it involves some painful compromises. The more people tried to organise the notes into a pleasing format, the more they struggled to make it work over multiple octaves.

Pythagoras used ratios involving only powers of 3 and 2 (3/2 is 1.5 or a perfect 5th).

A string divided into thirds. Image taken from Discovermaths’ video The Phythagorean Comma

The problem he encountered was that the 12th note in the sequence is not quite the same as the original, it’s just a little larger at 81:80. This is known as the Pythagorean comma and it means that every note beyond the octave is not an exact double or half of the original. If you want your octaves to be exactly double (2:1) you will have to use a different system.

In the Tuning Synth, select True Pythagorean — this option is the system that includes the comma — play the root note (zero), then play the 12th note. The upper one is very slightly sharper, though you probably won’t notice until you compare it with another system, which we will do later on in this article.

In true Pythagorean tuning the 12th note is not exactly double the frequency of the root

These compromises led people to create a system that approximates each note within an octave, so that each higher or lower octave is exactly double or half of the original note respectively, and thus Equal Temperament was created.

After centuries of experimentation using whole number ratios Equal Temperament won over Just Intonation because it is much easier to design instruments that support multiple octaves and polyphony (more than one note at a time). Equal temperament is so common it’s used in nearly all the music you likely hear across the world.

The magic formula

Equal temperament rests on a fairly simple formula that makes it easy to derive any note. To quote music author Bo Constantinsen, the “12 tone equal temperament divides the sonic distance between harmonics 1 and 2 into 12 equally spaced entities”.

Using a programming language, if I want the frequency of the 3rd note in a 12-note octave and we assume that the base frequency is 440Hz (A in most western music) we can simply do:

440 * Math.pow(2, 3 / 12)
> 523.2511306

If I want to divide the octave into, say, 19 notes (19 TET) and obtain the frequency for the 3rd note we simply do

440 * Math.pow(2, 3 / 19)
> 490.8894838

Given there was a gap in the market for a JavaScript library that supported this input/output approach, I created Freqi, the earliest version of which supported only Equal Temperament but a potentially infinite number of tuning systems. Freqi is used as the foundation for the Tuning Synth.

Seeing and hearing

With the Tuning Synth, you can hear the difference between true Pythagorean and other systems.

Some of the tuning system options in Tuning Synth

Try listening to the 5th note in Equal Temperament and then in Pythagorean. You should hear and see a slight dip in pitch. This really illustrates the point that Equal Temperament is an approximation and that any two notes (apart from the octave) sounding together will have some dissonance.

Take a look at the illustration below from Bo Constantinsen’s excellent Udemy course to see the misalignments I’m referring to.

The difference in frequencies between the two primary tuning systems in use. Source: how-to-hear-the-dissonances-of-equal-temperament/

Now let’s have a look at the difference using Tuning Synth. I have deliberately chosen the note with the greatest disparity.

The frequencies present in the 10th upper note using the True Pythagorean tuning system
The frequencies present in the 10th upper note using 12TET

Visualising sound

There is a plethora of ways to visualise sound ranging from 2D wave diagrams to 3D particle systems — I’m sure you’ve seen them all. The most common way to achieve a visual representation of a signal converted from the time domain to the frequency one using FFT (Fast Fourier Transform). When used with programming languages such as JavaScript piping a sound into an FFT buffer will yield an array of values each representing the amplitude of a frequency. The number of frequencies in the array is the resolution of the transform. In my case it’s set to 1024 so that there was enough data to make it useful but not so much that it slows the program down.

Seeing clearly

There are two modes: circles and bars. The circles can help the user clearly see the patterns and subtle differences between amplitudes, for example:

Sawtooth wave pattern using FFT and the visualiser set to ‘circle’ mode

The bar mode can help users quickly see the overall shape.

You can also zoom into a particular band of frequencies. This is useful when comparing two notes of similar systems, or on devices with smaller screens.

The Zoom feature allows you to visually isolate certain frequency bands

The size of the frequency nodes can be changed too, which is an important accessibility feature. The visualiser is less effective on mobile simply because the reduced resolution makes it very hard to distinguish the differences between different systems.

The root note

As mentioned earlier, I have set the app up to use 440Hz as the base frequency. There is some debate about whether 440Hz should be used for the note A in Western music, with some people arguing it should be 432Hz. Whatever your preference you can set the root note via a number input field, like so:

The tuning Synth music and audio controls’ custom root note field

It might also be preferable to set the root note to middle C, which is 256Hz (when using 440Hz for A).

Wave Type

I have deliberately offered only the four basic wave types, so that each note is as pure as possible. More complex waves make it more difficult to distinguish subtle differences in pitch as they create a wider selection of harmonics. These harmonics are what give a sound its texture, known in music as timbre. Your voice has its own unique timbre, whereby certain frequencies will dominate.

Try selecting the other wave types one by one and listen to various tuning systems using your selection. Some differences in pitch may sound more pronounced using the Square wave for example.

Play modes

One final feature I added was the ability to play either a one-shot note or a sustained one. It’s set to Sustain mode by default as that’s what going to aid hearing and seeing different frequencies. If you have been following along using the synth, you will have noticed that changing the Tuning System whilst a note is playing does not interrupt playback and so the changes in pitch are more audible.

However, just for fun, I added one-shot mode, for those who want to play with stops in between notes.

Known issues

Though Web MIDI is now supported in most modern browsers, at time of writing it’s still not available in Safari or Firefox sadly. If you want to play any Web Audio using a MIDI keyboard, you’ll have to use another browser. See caniuse for a full list.

Web MIDI browser support

Also, on iPhone 8 the audio playback is crackly and distorted. This seems to be a known issue with WebAudio Oscillators in that version of iOS.

How I made it

The Tuning Synth is an open source, bespoke JavaScript application, which uses as few 3rd party packages as possible. The primary dependency is P5.js, which provides an API for Canvas animation and sound control.

As mentioned earlier, the music tuning engine is my own library Freqi. This allowed me to generate the desired frequencies and map them to notes.

Conclusion

When I started creating the Tuning Synth, my goals were to allow:

  • Anyone to be able to access this tool for free
  • Users to play notes from a wide range of international and historical tuning systems
  • Users to hear the difference between a given note (in a twelve-note octave) in Equal Temperament and Just Intonation.
  • Users to hear the difference between a given note in both Pythagorean systems, namely with the comma and without
  • Users to see some of the mathematical patterns within pure sounds

I believe this web app meets those goals, but I would love to know if you find it useful or inspiring in any way. Comments and contributions welcome. You can fork it on GitHub here.

Happy tuning!

--

--

richard bultitude

Musician, software engineer, creative coder