The Simple Tuning Problem that has Defied Musicians for Millennia

Note : Cet article en français

Foreword: this article is about music theory, explained to non-musicians and musicians alike, with very simple math (all you need is basic fractions). Unless you know Werckmeister and Valotti, you will definitely learn something cool from this article. 🙂

Musicians have always had to tune their instruments to avoid having their audience’s ears bleeding. This is not only true for an organ that has 20,000+ pipes. One of the simplest instruments, a flute made of a stick of bamboo (or a bone, can you think of anything more romantic than playing your favorite tune on your sweetheart’s tibia?… just kidding) with holes in it has to be constructed very carefully: move a hole by a single millimeter, your flute will sound out of tune.

2500 years ago, Pythagoras, with the limited instruments of the time, racked his brain on the problem of tuning and finally devised the “circle of fifths”, exposing the impossibility to tune any instrument perfectly:

Pythagoras understood that music is essentially mathematics: notes, harmonics, pitches are all about different frequencies and how these frequencies interact with each other. Our brains and ears recognize matching frequencies as harmonious and non matching frequencies as dissonant. In fact, the brain loves everything that is mathematically related. That is why we love symmetries such as these:

Back to music. When two notes are played together, they form an “interval”, which is the distance between their respective frequencies. Intervals sound great to the ear when the frequencies of the two notes composing the interval are mathematically related by integer fractions. If they are out of tune and too far from a perfect ratio, they start sounding bad. Besides, any listener will hear “beats” as soon as the interval is a little off, which makes it easier to tune perfect intervals with a very good precision, the ear is a very delicate and precise organ.

Let’s hear what it sounds like! I have recorded a simple fifth, C-G, on my spinet, an instrument that has only one string per note, which makes hearing things more simple. First, let’s listen to a fifth that has been perfectly tuned, it sounds regular, fading away slowly (for best results, use a headset):

Visually, the sound wave is a gradually decreasing sound:

Now when this fifth starts getting out of tune, it starts “beating”, follow the visual indication. If needed, play the video a couple of times until you clearly hear the beats:

The beats clearly show on the audio wave:

Finally, when the fifth is clearly out of tune, the beats get faster, note that this is not a digital sound effect, this is exactly how it sounds on my spinet:

And when looking at the sound wave, the beats are even more visible:

And the only thing I did was to change the G very slightly, actually less than 1% of its perfect value!

Now, let’s have a look at the different perfect intervals that can be formed.

Take a frequency and its double: you have an octave. For instance 440 Hz and 880 Hz.
Now take 3/2 of a frequency, you have a harmonious fifth.
Take the 4/3, you get a fourth.
5/4, a major third.
6/5, a minor third.

Remember, as soon as two notes don’t respect these perfect intervals, they start sounding “off” and their combination starts “beating”.

So far, so good, everything looks pretty simple, we just need to tune our instrument using perfect intervals, et voilà!

But here comes the problem: it is mathematically impossible to slice an octave into 12 notes (called semitones) that have perfect fifths, forget even about perfect fourth or thirds. This assertion might sound blunt. We need proof! Let’s dig into the problem.

An octave is generally very “round” to the ear. It’s the combination of a frequency and its double, the brain is very satisfied with that. In fact, when tuned correctly, it is even sometimes difficult to say that there are actually two notes there, they “blend” perfectly. Can you hear the two notes here making an octave:

With his circle of fifths, Pythagoras proved that, if you wanted to tune your instruments so that it would have perfect fifths, your octave would sound like this:

Ouch! Your ears could do with some little extra care now. You can listen to the perfect octave above to get away from this annoying sound ringing in your ear. While Pythagoras used many fifths and octaves to prove this, we can actually use just 5 notes to demonstrate it.

Let’s calculate how much we have between C and D if we want to maintain things perfect. C-G is a fifth, so it is a 3/2 interval, as we have seen in the table just above. This means that G is 3/2 of C. D-G is a fourth, so it is a 4/3 interval. Which means that to go from G down to D, we have to divide by 4/3:

G = C × 3/2

D = G ÷4/3 = G × 3/4 = (C × 3/2) × 3/4 = C × 9/8

So D is 9/8 of C when building it with perfect intervals. Great. This is just simple math, jumping from one note to the other using basic fractions.

Now, let’s see what we have between C and E. E must also be 9/8 of D, as it is a normal tone in the scale, no different than C-D.

So E must mathematically be 81/64 of C. And 81/64 ≈ 1.265. Wait a second. C-E is a major third. We have said earlier that perfect major thirds use a 5/4 interval. However, 5/4 = 1.25, not 1.265. Close. But not exact. That’s our first “uh-oh” problem: when we use perfect intervals to build the interval C-D, we can no longer create perfect intervals for the major third C-E, and you can guess that it will also be the case with other intervals.

For instance, let’s go on to the next octave using 9/8 as a step for a tone. C -> D is 9/8, C -> E is 9²/8² (9/8 times 9/8), C -> F# is 9³/8³, etc.:

So an octave constructed with 6 tones is actually 9⁶/8⁶ ≈2.0273. But we said an octave needs to have a ratio of 2 to sound perfect, not 2.0273. Oh well, here goes perfection in music! And you heard what 2.0273 instead of 2 sounds like before, it’s simply horrible! Let’s play it again:

At this point, we have to accept one fact that is hard to swallow: dividing an octave into 12 notes is never going to produce exact fifths, fourths or thirds. Very close approximations of them, but never exact. However you tune your notes, they will never sound perfect. Such an annoying thought for a musician! However perfect his music is, it will never sound right! And not only will it not sound perfect, some of it will sound pretty nasty if you’re not extra careful.

We will not go into much more detail. At this point, you came to realize that when cutting an octave into 12 notes to produce the standard European scale, you have to make trade-offs: if you want some intervals to sound close to prefect, some other intervals will have to be sacrificed. Some fifths will not be exact 3/2 intervals. Some thirds will be really off from their exact intervals. Mostly everything will be off, really, ever so slightly. The goal is to find a slicing that minimizes the roughness in the ear coming from all these intervals that are off. Pythagoras showed that you could tune most notes almost perfectly but that you would then have an inevitable rogue interval that would sound so terrible that it is called a “Wolf interval” since it howls like a wolf when you hear it!

Many musicians since Pythagoras have tried to address the problem in one way or another, designing “the best slicing” of their choice. These different variations in slicing the octave cake are called “temperaments”. If you know a little about classical music, this could remind you of the title of J.S. Bach’s “Well-Tempered Keyboard”. In the 18th century, there were many different temperaments, each suffering from various problems when playing in different keys, such as the Werckmeister and the Valotti cited in the prologue of this article. Bach’s work “The Well-Tempered Keyboard” uses many intervals in order to give a practical demonstration of his temperament in which you could play in various keys without problem and without hearing any wolf interval.

Besides, with a given temperament, musicians started to understand that every key had a different “mood”, some sad, some scary, some joyful, due to the different parts of the melody that sounded rounder or harsher than the others depending on which intervals they were using most. Therefore, they chose the keys of their compositions very carefully.

Here is an example of a classification from various composers such as Charpentier or Rameau:

  • C major: joyful
  • C minor: sad, mourning, love sorrow
  • D major: funny, triumphant, victory
  • D minor: calm, grave, tender, devotion
  • E flat major: pathetic, cruel, harsh, devotion
  • E flat minor: horrible, anxiety
  • ..
  • F major: storm, furious
  • etc.

Nowadays, one temperament is used almost universally (except for baroque players, mostly): the “equal” temperament. It has actually been invented some centuries ago (in fact, a Chinese mathematician described it around 400 AD), but it can be tuned perfectly only with the precision of electronic devices (although there are methods to reach very good approximations of it, people began to use it in the 18th century). Rather than making compromises, the equal temperament makes every single interval as equally good/bad as the others. Basically, the octave is cut into 12 absolutely equal pieces. This is why some musicians criticize it and why it faced some resistance before being adopted: it has no “color”. Whether you play your tune in C or in G flat, it will sound exactly the same, at a different pitch, but with the same harmonics. In other temperaments, as we have seen, every key has its own “mood”. You may not even be able to play some keys in some temperaments because they will sound hideous, as if you were playing on one of those out of tune pianos in the pubs of the 1900s. But in equal temperament, nothing sounds exactly right at all, it is just never totally hideous either. In fact, in the equal temperament, no single interval is perfect, except for the octave.

This is it for a very short introduction to music theory of temperaments. Many books have been written on the subject, and it is still not over as people still come up with new ideas to get the best compromises out of a scale. I hope this has intrigued you and made you wonder a little more about this simple problem that has annoyed musicians for thousands of years.

For some examples of how a temperament can affect how you hear things, you can have a look at the Wikipedia page for musical tuning and listen to the samples in the “Systems for the twelve-note chromatic scale” section, the “just intonation” is particularly telling!

Deuxième vidéo sur la blockchain

Deuxième vidéo d’une série sur la blockchain. Si vous avez entendu parler de cette technologie mais que vous vous posez des tas de questions, cette série est faite pour vous !

Après avoir donné un rapide historique et les divers usages de cette technologie dans la première vidéo, on s’attaque cette fois à ce que c’est un peu plus en détail sans pour autant virer dans la technique.

Visible aussi sur youtube : https://youtu.be/Zhvq0wE8F3Q

 

Mounting Synology drives on Linux

I’ve just unmounted my drives from my Synology box, replaced by a home-brewed server. I’ll write some other article about the reasons that made me switch. Just in case you wonder, the Synology box is running fine. That’s not the point.

I took the disks from the Synology box and plugged them into a host with simple Linux distrib (in my case, Ubuntu, but that shouldn’t matter).

Just type:

mount /dev/vg1000/lv /mnt

That’s it. You have the file system from your Synology box on your Linux machine. It may come handy in case your box crashed and you are waiting for a new one. In the meantime, you have access to your data.

In case you want to reuse the disks and dispose of them (WARNING: the following will destroy your data on those disks), here is how to do it.

vgremove vg1000

Now check the md volumes that are available and that you didn’t create yourself (just use ls /dev/md12*). Then stop those volumes (replace md12? with the volumes you want to stop if you have additional ones on your system that you obviously don’t want to stop – they won’t stop if they are mounted anyway):

mdadm -S /dev/md12?

Empty the beginning of the related disks, for each disk replace the … by your disk letter:

dd if=/dev/zero of=/dev/sd… bs=1M count=1024

And now you can play around with partitioning etc without being bothered again by vg1000 or mdadm.

Première vidéo d’une série sur la blockchain

Première vidéo d’une série sur la blockchain. Si vous avez entendu parler de cette technologie mais que vous vous posez des tas de questions, cette série est faite pour vous !

Visible aussi sur youtube : https://www.youtube.com/watch?v=6xOyBMkRcHQ

A Strange Rubik’s Cube Story

Two years ago, my wife offered me a very nice gift:

While that was a great gift and the kind of challenge that I would take on, I felt embarrassed as I even had no idea how to solve this:

Right.

And at the same time, I remembered how, as a child, I had swapped stickers on a 3×3 Rubik’s cube in the hope of solving it. Embarrassing.

So I took the bull by the horns and learned a method to solve virtually any cube. It’s quite simple when done right but requires some persistence and trial and error at the beginning. I’ll probably make some video tutorials even if there are already many of them out there. The method I use enables me to go from this:

to this where the 2×2 and 3×3 have been solved and the others are on the way:

to finally all of them solved:

And those don’t have stickers, no cheating allowed.

There are many methods to solve cubes. Fast ones, especially for the 3×3, that don’t really work for other cubes. Universal and slow ones.

My goal was to solve any cube, including my wife’s present, not to do what is called “speed cubing”. I actually wanted to learn as few “algorithms” or “formulas” as possible as I don’t plan to solve cubes for the rest of my life. I reduced it to:

  • 2 algorithms for the 2×2,
  • 2 more algorithms for the 3×3 (that’s 4 in total),
  • 3 more algorithms for the 4×4 and all others (7 algorithms in total).

Most of these “algorithms” are easily memorized using mnemonics such as a little story. It is also necessary to be able to perform the mirrored version of every algorithm, but that’s not a big deal with a little training.

Here are the basic steps to solve all these cubes. First solve the center part of a single face (here the green one), this doesn’t need any algorithm as it is quite simple (note that nothing has to be done for the 2×2 and 3×3):

Next, solve the edges of that face, making sure that the other sides match the colors of the centers of the other sides. No need for an algorithm here either, it is quite intuitive. However, for cubes with an even number of pieces, you have to memorize the order of the colors, clockwise red, white, orange, yellow. Just use whatever mnemonic works for you. If RWOY, like in “Rob Rwoy” works, then that’s what it is. 🙂

Note how it forms a cross on top of the cube (again except for the 2×2 which still doesn’t change).

Then solve 3 of the green corners on all cubes, which is very easy:

Let’s turn all the cubes to the side to have a better look at what happens next:

Start solving the edges from the green corners (see how the edges that are closer to us in the picture start getting solved), this again doesn’t require any algorithm:

Let’s turn the cubes again:

Now solve the last edge and solve the half edge under it as well as other edges that may not have been finished yet. Here comes the first algorithm:

Note that at this point, the 2×2 is half solved and 2/3 of the 3×3 is solved as well. Let’s turn the cubes to their other side, where everything will happen from now:

At this point, the 4 blue corners can be solved with 3 different algorithms (one of them is a combination of two others, so it doesn’t count as new), and the middle blue edge is also solved with one algorithm. At this point, the 2×2 and 3×3 are solved. So it looks like this:

Now let’s solve the remaining top edges (blue ones) with one algorithm:

Note that the edges of the second row from the top are still not solved, so now is the time to solve them, one algorithm is required for this:

And now, the centers need to be solved with one single algorithm declined in different ways, it is generally the longest part, especially with bigger cubes, and needs some planning, memory and solving skills. Et voila!

Stay tuned for some videos in the future that will show how to learn and apply the different algorithms.

Mind Maps: a Miracle Tool for Writers

This may be a long post, but I hope to keep it entertaining for both writers and non writers. Let me know what you think!

Some history – where I come from

I’ve always loved to write. As a child, I already started writing similar stories than the ones I was reading: children stories. At the time, I was left with that time’s simple tools, a pencil and pieces of paper:

Then, my father seeing that I really loved it, decided to buy me a typewriter (I unfortunately don’t have it anymore, but it was this model):

Besides the fact that it was difficult at first and hurt my fingers since the keys were so hard, it did improve the presentation of my writings by quite a bit, I even allowed myself to make ASCII art even though I didn’t know it would be called that way a decade later:

And when the occasion arose, I had to draw things myself on the paper:

I even went as far as making fake old maps to add to the mystery of the fiction I was writing:

At the time, if you wanted to know about one place where your story was taking place, you basically had to go there and get some documentation:

You could also read lots of books to get a grasp of the place, its atmosphere, its inhabitants and culture, etc. You had to be a real detective.

Then my parents decided that it was time for me to have a computer,

This thing was top notch at the time, it had no hard disk and everything had to be on floppy disks which weren’t so reliable. It was a great improvement on the typewriter, though, and soon MSDOS had no secrets for me. I added a 20 Mb (yes, megabytes) hard disk later which cost me an arm and a leg at the time… I could use Word 2.0 to write, it was great. You could FIX things without typing back a full page! And then, PRINT it and write gibberish on it as much as you wanted to!

Great times. Believe it or not, I still have the files for these books.

Since then, and that’s like 30 years now, nothing much has changed when it comes to the comfort of writing. Of course, you can now travel the world from your desk by watching videos and reading traveler blogs, there is more material around than you can handle anyway.

But the writing, technically? Good ol’ Word. Ah, Libre Office has come around so that you don’t depend on a private company anymore, but that’s pretty much all there is to it.

Of course, in the more recent years, self-publishing has enabled anyone to publish books, while publishing anything was practically impossible before unless an editor accepted to support you.

Tools and Constraints

There are some tools for professional writers. I won’t quote them here because I don’t want to rant, but the added value doesn’t compensate for their price, at least that’s my own opinion.

As a writer, I have quite a number of needs in order to write efficiently:

  • describe the characters in my story, have their personality and picture at hand whenever I need it,
  • describe the places where my story happens, possibly along with pictures, maps or drawings,
  • dynamically design the plot in the most flexible way possible, by quickly arranging events and/or themes seamlessly,
  • have an overview of the entire book the whole time to see where I stand,
  • count words inside chapters to make sure they are roughly balanced (Word documents count the total words of the document, they don’t break the counts into chapters),
  • handling of Table of Contents, presentation of the book, references, footnotes, etc., should be easy and not troublesome, in fact you should never even think about those as it would distract you from writing,
  • navigate efficiently through the book with shortcuts rather than having to scroll pages and pages to reach one chapter,
  • have the finished product in the form of an epub and various pdf formats (one for reading on a screen, one for a small paperback edition with small characters and at least one for a big paperback edition for people with poor vision),
  • manage to have a history of changes.

Frankly, none of the current software can deal with all these constraints easily. Word/LibreOffice documents are a nightmare. LaTeX constantly distracts you from the contents and doesn’t provide an easy way to navigate through the whole document (I wrote my PhD using LaTeX).

Mind Maps are the Perfect Tool

In the meantime, as a computer engineer, I started using Mind Maps at work to organize ideas. Scientific, computer-related ideas.

If you don’t know what a Mind Map is, it’s just a simple tree of ideas such as this:

You organize your ideas in nodes which are broken into smaller nodes as you refine your ideas. These are great for technical planning and thinking.

Some day, I started planning a new book inside a mind map. Just to draw the basic canvas of the story. Then I added my characters into it.

The main plot was in front of me, the characters next to it. Why not write the book inside the mind map? I know that, as soon as you start breaking your ideas into different documents, some of these documents will become out of date very quickly. By writing directly inside the mind map, I had only one document to maintain.

Most Mind Mapping software allows to type some HTML notes inside every node, that’s where I typed the main text of the book. And because it’s HTML, I can add images, put some formatting, bold, etc.

Converting a Mind Map to PDF and EPUB

To my knowledge, there is no converter to create a PDF or an EPUB from a Mind Map. If you think about it, a Mind Map is a simple text document that can be easily parsed, in the meantime libraries to generate PDFs exist, while an EPUB is a simple Zip file with some HTML files inside.

So I wrote a converter in Java, which also counts the number of words in every chapter and sub-chapter.

Thanks to this, I can easily:

  • have everything in one place with all I need visible in one document: the characters and locations along with the basic ideas, the whole book where chapters are nodes and sub-chapters are sub-nodes, and the nodes’ contents is the text of the book itself, so it’s extremely fast and easy to navigate from one part of the book to another,
  • navigate from a character to a given chapter with a simple mouse click,
  • move ideas, events, plots around during the planning phase, while developing characters and locations in the same document,
  • count words in every chapter and sub-chapter with my converter to make sure that things are not totally out of balance,
  • have one single source file for many output formats for the readers, which are even described in the Mind Map,
  • Mind Maps are text files, it is easy to compare a file with a previous backup to see what has changed.

Here is an example of a test mind map that is later transformed into a book (nodes with a yellow icon have notes typed into them):

The generated PDF looks like this:

And the generated Epub is readable on any reader, uploadable to any self-publishing platform.

I hope this converter can help other people as well. Note that its current version as I write this article is rather limited but is perfectly suitable for a simple novel. Its limitations are listed in the description of the tool itself on gitlab.

Did you like this? Let me know in the comments below!

Moon Tests with a CCD Camera

Following up with the pictures of the moon taken with a Nikon camera on a 114mm Newtonian telescope, I have recently bought a quite cheap CCD camera. There are a few advantages and a few drawbacks.

Here are the qualities of the CCD:

very easy to mount directly on the telescope
directly exposed to the object without any extra lenses
instant results on the computer screen with a large view of objects in full screen

need to have a computer around (along with the brightness of the screen that can have an impact on your night vision)
no possibility of playing with contrast/exposure time since it is a cheap camera, you have to rely on the automatic settings, some more expensive ones do have these kinds of settings, but that’s definitely another budget

And here are the qualities of a full camera:

playing with contrast/exposure time depending on the object you’re trying to take – the moon and a deep sky object will definitely not want the same settings

mounting the camera on the telescope is not difficult but needs some precautions
having to go through at least an eyepiece and a refractor can create a lot of chromatic aberrations and distortions, as seen on the pictures in that post (look out for a blue halo around the moon or around the craters, for instance) compared to the ones in this current post.
the weight of the camera can be an extra load on the telescope’s mount, especially if the mount is already reaching its limits with the tube on its own

So finally, here are two sample pictures taken on the same telescope:

Note that those pictures were taken from my balcony, right in the middle of the city, and all astronomers know that this is the worst setting to do any kind of viewing and especially any kind of photography.  The thing is that you won’t realize what this really means until you see this video (2Mb):

See the wobbling? That’s the air heated unevenly that moves around. It somehow totally reminds me of what you see when you look at the bottom of a very very still pool filled with water, look at this one:

Isn’t that simply amazing?

Learning words in foreign languages

Recently I was asked how many times you should hear a word in a foreign language before it really sticks into your mind.

Sometimes, hearing/reading one word one single time in the right context will imprint it into your mind forever. And sometimes, you will repeat one word 100 times and it will not stick. Spaced repetition is a powerful way to get the words to stick while reducing the number of times you are exposed to each word, but it is not magical either. With the wrong context, you may also fail with spaced repetition.

I learned one thing from decades of studying, it is that context is everything. That’s why trying to immerse yourself in a certain context while learning a language is important. The best of all is to simply be in the country of the language you’re learning. But as it is not always possible, here are a few tricks.

When I use Anki to do spaced repetition, I listen to some music in the language I’m learning while repeating the words. This switches the brain into the mode “oh, that’s this language, okay!”, as well as cheering you up and setting up a mood. You might even want to tap your feet with the rhythm while learning words. And on all my cards, I have an image of something that is characteristic of the country/ies where that language is spoken, as well as some sentences in which the word is used – because learning a word by itself is boring, and learning it within a sentence makes it more interesting. I will make a post later to explain how I did it technically. Associating a picture with the word also helps quite a bit, especially for physical objects.

Teachers know that bored students don’t learn anything. That’s why teachers who make their classes very emotionally alive are more successful than others. There are some very serious scientific studies on this but I’m sure you have in your own experience that teacher who stood above all others because his classes were so lively, funny or exhilarating.

And of course it all depends on the language you’re learning and the language(s) you already know. The learning curve of Japanese or Arabic is obviously much greater for a native monolingual English speaker than the one of German for someone who knows Dutch and Danish.

So there is no “number of times for a word to stick”, it’s all about context!

The Moon

The Moon is back with its normal non-eclipsoid figure. 😀

Here is a picture taken with a Nikon D5100 mounted with a simple Barlow on a Celestron 115/910. I’ve had both the telescope and the camera for a long time now, but never took the next step of taking pictures. Thanks to the recently acquired barlow, this is a dream come true.

This is taken from a balcony in the middle of a big city, not exactly your ideal conditions for taking pictures of the sky especially during a hot summer with lots of temperature differences, but the results are still quite good and I have not applied any software fix on them. Exposure: 1/200 s, sensitivity 1000 ISO. Enjoy!

Note the difference in chromatic aberrations depending on the location of the details mostly due to the barlow lens, the following animation shows the same details taken in the center of the picture compared to the edge (1/100 s, 400 ISO):

Moon Eclipse + Mars / 2018-07-27

The sky was kind enough to let us see the moon eclipse yesterday for a short time, as it was quite cloudy. A very nice experience.

Of course, without forgetting its friend Mars (take your time, it’s an animation) :

The clouds also allowed for some creepy shots, you’d wonder if Freddy Krueger was around.

 

Note that these are raw photos. No filters.