Deriving the piano keyboard from biological principles using clustering
fiftysevendegreesofrad.github.ioGet the top HN stories in your inbox every day.
vnorilo
sideshowb
Hi, author of TFA here. Thanks for your comments :)
You're right the harmonic model used is a bit of a bodge. I didn't know that about hammer position, very interesting. Let me know if you ever get around to trying different timbres in the code.
I think we are more in agreement than you think on clustering, though. Although I neglected to discuss what's anatomically reachable, and also the nuances of history, my point is that the desired subset you mention can be defined by using clustering to pick a subset that sounds good.
vnorilo
Thank you for writing it!
I think perhaps the way I would state the subset problem is that white keys are in a way the "subset that sounds good" to the culture where the piano keyboard arose. More in the vein of discussion than suggesting you'd need to change anything :)
The black keys are means of transposing that subset.
It is a very interesting but in a way unrelated insight that the black keys also form a consonant group.
And then music and musicians naturally coevolve with instruments and do whatever they please!
jacquesm
Are you aware of the Janko keyboard?
mannykannot
In a recent article about his Sixtyforgan (an organ made from a Commodore 64 and a spring reverberation tank), Linus Akesson explained how he had used the key layout of a chromatic button accordion.
This appears to differ from the Janko layout, though they both apparently share the feature that "if you know the shape of a particular chord or scale, you can automatically play the same thing in another key just by moving your hand" (so long as you have five rows of buttons, in the accordion layout.)
There are many ways to skin this cat apparently, though as with QWERTY, established convention is hard to change.
recursive
I had not heard of it. It looks similarly motivated the harmonic table layout. https://en.wikipedia.org/wiki/Harmonic_table_note_layout
sideshowb
I think I've seen that before yes. On a related note I've been learning to play accordion this past year.
elihu
> The modern piano mitigates this by having the hammers strike strings at a position that avoids exciting the 5th harmonic...
I think it's actually the 7th harmonic that pianos avoid, if I remember correctly. (I guess one could verify this by measuring the hammer position on a piano string and figure out if it's hitting the node at 1/5 of the string length or 1/7th).
This random google result agrees with me:
https://pages.mtu.edu/~suits/badnote.html
I have a theory that pianos and guitars have become the dominant musical instruments of the last hundred years or so simply because you can get away with mis-tuning them and they still sound pretty good. (I once had the opportunity to play a 15-tone equal tempered guitar, and it still sounded good, which led me to believe that you can get away with almost anything with a guitar.) Which isn't to say that guitars don't sound better in just intonation, they do.
On the other hand organs and accordions, for instance, sound amazing in just intonation but not nearly so good in 12-tone equal temperament. The notes (especially thirds and sixths) clash with each other too much. It's tolerable, but not great.
I've been working with a group of people converting guitars to 41 tone equal temperament; they have a nicer third (off by about 5 cents instead of about 15) and a closer 4th and 5th (off by about half a cent instead of 2) and can approximate 7-limit just intonation intervals pretty closely. The trick to make it playable is to omit half the frets, so it's fretted for 20.5-tone equal temperament, and any notes not available on one string are available on the string next to it. It sounds like it shouldn't work, but it does.
magicalhippo
Your post reminded me of this video[1] by Adam Neely, where he tries various tuning systems around A = 432 Hz.
As a non-musician it really made me appreciate how little I know about the technical side of music.
weinzierl
> "Much of the music in the world operates roughly on the pentatonic scale which coincides with the black keys, [..]"
I think there is not so much music in the pentatonic that is formed by the black keys, or a related scale. Off the top of my head only Paul Desmond's Take Five comes to my mind. I think this mainly because it is horrible to read and write in traditional notation.
Coincidentally I played a bit of Stevie Wonder's music recently which was all in E-flat minor. I have to say it is very pleasant to play, especially if you use Steve's often unusual fingerings.
Reading it OTOH was not so pleasant. This hints to me that our music is not only influenced by the way it sounds and the way it can be played but also by what is convenient to write down and read - and sometimes it takes a blind artist to overcome this limitations.
vnorilo
Surely not related to black keys, that is what I tried to say. Most pentatonic music traditiona predate keyboards.
jmrm
AFAIK Stevie's songs uses a lot of black keys due to being easier to him to locate them using touch instead of sight.
weinzierl
That's what I meant when I wrote that his fingerings are pleasant to play and I meant that you don't have to be blind to benefit from the fact that they facilitate easy orientation on the keys.
For example Stevie actually plays the main melody of the main riff of Superstition distributed to both of his hands. This allows him to simultaneously play some bass notes with his left and some higher chords with his right hand while completely avoiding to move his hands away from their basic position. His hands never jump. Playing the melody with both hands is unusual and not what most Superstition tutorials show, but it is actually very pleasant and safe because everything just lies under your fingers.
The other side of the same coin is that Stevie never had to worry if his music is easy to write and read. That also facilitates playability and maybe emphasizes pleasant movements over looks on a sheet of paper.
carlob
I highly doubt that anyone with that level of musical training really needs to look at the keyboard...just like you probably don't while you type.
CPLX
That doesn't really make any sense.
iainmerrick
I think there is not so much music in the pentatonic that is formed by the black keys, or a related scale.
Depending how strictly you’re using “pentatonic” there, I don’t think you’re correct, unless I’m misunderstanding. In the wider classical and jazz repertoire there’s plenty of music written in Eb, Gb etc, heavy on the black notes.
For example, Debussy’s piano music often uses keys with lots of flats (or lots of sharps). Chopin supposedly played the black keys with his thumbs in some cases, against the accepted style at the time.
In jazz, Billy Strayhorn (who I think was strongly influenced by Debussy) seemed to be very fond of writing in Db.
sanotehu
Interesting... Do you have a source copy for this? I'm always interested to play music as the artist intended and Stevie Wonder is one of my favourites :)
weinzierl
If you are interested in Superstition, see my answer to jeffwass for a potentially useful link.
looneysquash
I'd be interested in that as well.
stainforth
So here's my question then - is the musical notation we have the most logical and ergonomic language it could be?
Kye
No, not even remotely. But it's not trying to be. Notation is a way to communicate music to a player or conductor who applies their own interpretation to it. Notation is more like a movie script than a novel.
tomsmeding
> The modern piano mitigates this by having the hammers strike strings at a position that avoids exciting the 5th harmonic
This is fascinating! I always wondered why a piano could work so well despite in reality having slightly ill-tuned thirds. Thanks for sharing the tidbit.
yesenadam
But isn't everything in equal temperament "ill-tuned"? The fifths aren't real (3/2x frequency) fifths, etc. Everything except octaves - but piano tuners tell me that octaves that are "too big" (>2x) sound better![0]
[0] https://en.wikipedia.org/wiki/Stretched_tuning#Intervals_and...
vnorilo
Yes, but while fifths are off by 2/100, major seconds by 4/100, thirds are by 14/100 or 16/100.
The former create gentle swirling interference, the latter a rough stuttering. If you hit a fifth on a piano and listen carefully, you can hear the slow cycle in the sound.
The stretched octaves are due to high string tension causing some inharmonicity, ie. sharpening higher harmonics.
elihu
Yeah, pianos deal with both the tuning inaccuracies that are inherent to 12-tone equal temperament in addition to piano-specific oddities like having to stretch the octave.
Basically, the harmonics that rise off of piano strings aren't exact multiples of the fundamental -- they're a little bit off, because piano strings don't behave entirely like ideal strings, they behave like metal cylinders. In the mid-range they're pretty pretty close to plain equal temperament, but in the high treble the strings get shorted but the string gauge stays almost the same, which means the ratio of diameter to length increases and they act less like strings and more like cylinders. The bass has similar issues with single and double wound strings. So, the fix is to just stretch the octave enough so that the harmonics of low notes line up better with the fundamentals of higher notes, and so on. (What we perceive as "out of tune-ness" is the wobbly sound of two frequencies played together that almost but don't quite line up, creating a beat frequency.)
weinzierl
Piano tuning is a science in its own. Google for Railsback Curve if you want to fall down a rabbit hole.
pantulis
You mention "TFA" a couple of times, what is it?
jfengel
Old joke explained: RTFA means Read The Fine Article -- except that F doesn't really stand for fine. It's usually meant as a crabby way of saying "The article answers your question".
From that, "TFA" just means "The Article", but without any of the crabbiness, and without the F really standing for anything. That's just a shortcut, and a nice instance where a bit of Internet lore became nicer rather than meaner.
gamacodre
I'll sometimes read TFA as "the featured article," but I don't know whether I picked that up along the way or invented it to make internal sense of nice things said about TFA.
RTFA derives directly from RTFM ("Read The ... Manual"), which I always interpret with the full force of the embedded expletive.
heresie-dabord
> Clustering is not the point of black and white keys. Rather it is the facility to pick an anatomically reachable, desired subset of 12 keys available per octave.
This is the essential point of critique that makes TFA an exercise in assembling loose hypotheses for publication on the InterWobbles.
moralestapia
Disclaimer: I do not have a music degree.
I thought (read) that the distribution of black and white keys came to be like that to provide a visual pattern which allows you to easily distinguish the different octaves.
yummypaint
Extending further into 2 dimentions creates some interesting possibilities. I have become a big fan of the wicki-hayden isomorphic layout (hex grid). It ends up grouping western scales into vertical bands. Moving horizontally changes by two semitones, moving another direction changes the note by fifths.
I built a keyboard with this layout because it's such a convenient way to conceptualize arrangement of notes, but there are certainly tradeoffs when it comes to actually playing. You end up with duplicate notes, so you can play in unison with yourself like on most string instruments. The isomorphic nature of it is one of the strongest points: you only need to train your muscle memory once for each chord (major, minor, etc), and you can use that exact shape anywhere on the keyboard. Its good for jamming and discovery, but i cant imagine being able to play as many notes/second as a normal piano.
See figure 11: http://rainboard.shiverware.com/images/0/08/Isomorphic_Tesse...
jng
Next to this interesting article and comments, I think mention should be made of von Helmholtz's XIX century book "On the sensations of tone". He is considered to be the father of acoustics, and derived the consonance/dissonance of the notes in the diatonic scale from first physical principles. He extracted and computed what is described as "roughness" here as the amount of "beats" between the upper partials of the notes - where beats are the slow phase oscillations caused by two vibrations of very close frequencies. But of course, he first had to study strings and pipes for 8 years, and come up with the (then) innovative concept of upper partials (harmonics). I'm a software person by trade, amateur but very dedicated musician, read this book many years ago, thoroughly enjoyed it, and I heartily recommend it today.
codeulike
We know that notes with simple ratios to their frequencies sound 'good' together (e.g. an octave is a 2:1 frequency ratio, a 'fifth' is more or less a 3:2 frequency ratio), a perfect fourth is 4:3 ratio - https://en.wikipedia.org/wiki/Interval_ratio
Equal temperament messes with that a little but its still approximately there.
So why should simple ratios sound good? From what I've read, its probably overtones, and the way overtones excite the cilia in our inner ear. If you plot the overtones from the two notes of an octave or a fifth, they co-incide a lot.
And then why the pattern of notes on the piano keyboard? (More precisely 'why does the major scale use those 7 semitones?') ... I think with that scale, and the other scales, its something to do with squeezing the most amount of 'relationships' possible from a subset of notes without muddying the waters by having too many in play. Music is all about patterns and a mix of repetition and progression, and so having a finite number of notes that have intersting relationships with each other gives a good canvas to work with.
(Any why 12 semitones? Again, to do with getting the most interesting relationships without muddying things ... I think its possible to divide the octave into 19 or 43 parts and get some interesting ratios/relationships, but then it gets quite fiddly)
analog31
12 tones is the smallest approximately rational scale. There's a technological reason for preferring this. Up until fairly recent times, a musician had to be able to tune and maintain their own instrument. Also, we can't grow more fingers.
There may also be a benefit to more widely spaced notes, notably (!) that it's easier to distinguish if you're playing a "real" note or not, and if it's the same note as the one you're hearing someone else play. This would make it easier to learn musical ideas and pass them on to others, giving 12 tone music (fewer tones if using an agreed upon scale) a built in error correction code, and a sort of evolutionary advantage over time if you will.
klodolph
With the exception of a couple instruments like the piano and electronic keyboards, don't musicians still tune their own instruments?
analog31
That's true.
When my dad got a harpsichord, part of the process was getting trained by the maker on how to tune it. There's an old joke: Q: What's a harpsichordist doing when they're not tuning their harpsichord? A: Playing out of tune.
jedimastert
I'll just put in that I think things like 12 tone scales and 7 note diatonic scales were local minima in a vast landscape that we happen to hit upon and settle into. The more I look at what music is from a neurological perspective, the more it feels/seems like the deepening and establishing of patterns is the main mode.
elihu
The major scale is just the most straightforward way to be able to construct the most usable 4:5:6 ratios and 10:12:15 ratios (i.e. major and minor chords) from the fewest possible notes. In equal temperament, those ratios are approximated rather than exact, but those are the mathematical relationships implied by the chords.
The desirability of "simple ratios" is based on the idea that if we play two pure sine waves at the same time, they sound good if they're exactly the same frequency and if they're some distance apart, but they sound bad if the two notes are close but don't line up. (This creates a beat frequency, which make the music sound unstable and noisy.)
Notes played on real instruments have harmonics, and so if you play two notes at once all those harmonics either need to be a long way from each other or they need to line up. Notes with frequencies that correspond to simple ratios are the ones where the harmonics also line up in the cleanest way.
Simple ratios like 2:1 or 3:2 are very stable and consonant. Larger ratios like 5:4 make modern music a bit more interesting. Still larger ratios like 7:4 and 11:8 can start to sound pretty alien and sort of dissonant and more complex.
Basically, the most consonant music, which is easy to play (imprecisely) in 12-tone equal temperament, is pretty well explored territory. There is only one major chord, and we won't find anything that sounds any more "major-chordish" than it. But there's a huge unexplored territory when it comes to larger ratios that can't be played accurately enough to be intelligible on 12-tone equal tempered instruments.
If you scroll down a bit on this page, I made a visualization of how 12-tone equal temperament lines up with a straightforward just-intonation scale based on the ratios implied by the 12-TET chromatic scale. It's really amazing both how well 12-tone equal temperament lines up, and at the same time how much better things could sound if you play the exact just intervals rather than this system that by some weird mathematical coincidence happens to be good enough for most simple musical purposes.
alok-g
>> why 12 semitones?
As you noted, other numbers like 19, 43, and obviously also 24, gives interesting ratios.
My current understanding is that while human ear is easily able to distinguish finer frequency ratios, singers aren't able to match vocals to much higher precisions. 19 may perhaps still work, but 43 I think would be out of question.
OscarCunningham
The 7 note major scale is more-or-less an historical accident: https://en.wikipedia.org/wiki/Musical_system_of_ancient_Gree....
tantalor
> there's a good chance these sounds come from the same object, due to the physical principle of resonance. And so our perception of sound evolved to reflect this... we discovered that making decent music increases the odds of mating
It is likely we did evolve this unique ability, which our cousins do not have, but we have no idea why. These hypotheses about "same object" and "music -> sex" is unsourced speculation.
sideshowb
Hi, author here. Thanks for the link. You're right I have no expertise in the hypotheses you mention, for the post I intended them as light hearted framing.
I'd be interested to know how the MRI results you link would compare for any bird species which use songs as a mating call/indicator of fitness. That would be another piece of the puzzle I guess.
IIRC there has also been work by musicians attempting to link our notions of beauty to processes of pattern matching/learning, though again more in the realm of speculation than neuroscience.
And for the record I like to think my own interest in music is at least slightly more profound than the quote above implies ;-)
alok-g
Thanks a lot for sharing this. Loved reading.
pierrec
There are lots of things to love here. The interval roughness function based on the harmonic series is interesting, and I wonder if it could be used to give some kind of score to chords or tuning systems, and maybe even generate them.
The article also made me realize that there are two different ways of arriving to 12 tones per octave:
- The pythagorean way: you keep iterating the "pythagorean tuning algorithm" described in the article until it gives you a note that's almost exactly like one you already have (I believe this is a less convoluted way of describing the "useful coincidence" hinted at by the author). It gives you a scale made of 12 notes, with more or less complex natural relationships between them.
- The logarithmic way: you test all n-tone equal (logarithmic) divisions of the octave, up to some large n where notes end up too close together. You compare how much they deviate against the most important natural intervals: pure 2nd, 3rd and 5th. You'll find that 12-tone equal temperament forms a deep local minimum.
Historically, ancient scales were constructed using methods similar to the first. My interpretation is that musicians desired to freely transpose melodies without making them sound bad, so scales got more refined, and those that maintained 12 notes to the octave started approximating equal division. Eventually, logarithmic tuning satisfied that demand exactly. I'd say the more interesting coincidence is that this transition could (theoretically) be smoothly done between obvious natural and equal temperaments - precisely because the above two methods result in the same number of notes. Of course, history isn't smooth, and alternative systems can be found in all periods. Maybe the dominion of 12 will even come to an end at some point.
sideshowb
I like your simplification of the pythagorean tuning algorithm and would run with that if explaining this again.
On your first point I think there exists a vst that tunes each chord you play to be as consonant as possible.
A related side project I had was to take a midi file and through optimization specific to that file, define a scale to play it on which is makes a trade-off between 1. making the original tune as recognizable as possible, 2. as different to a western scale as possible, 3. as consonant as possible. I've yet to make it sound good!
vanderZwan
> Roughness and smoothness is all very well, but if you want to write some music, the conventional way to do it is to pick a subset of all possible frequencies to use for your notes and use these as the building blocks for your tune. Actually most musicians don't even do that, they just work with the notes others have picked already. This is unoriginal, perhaps, but convenient for working together.
Is this a tongue-in-cheek comment on unreasonable expectations of originality from artists, given that most programmers don't do their work by constructing their own programming language from the ground up either?
sideshowb
The tone of the whole thing is fairly flippant, really (an experiment with a different style of writing which I haven't used since!). I certainly wouldn't criticize anyone for using a standard tuning, indeed I do so myself most of the time. Like I said for one thing it makes collaboration (with other musicians or instrument-makers) easier, then there's the fact that the standard tunings themselves form part of the cultural background we're building on when we make more music. For example if we take the roughness plot in the article as representative (which vnorilo rightly calls into question, but still) we see that any interval in the continuous range between an 5th and octave is evaluated as smoother than a minor third. But we don't perceive it that way, I suspect because of our cultural background.
billynomates111
If you want to make an apple pie you must first invent the universe.
d_rc
Here is the notebook code in Deepnote if anyone wants to play with it: https://deepnote.com/project/JupyterNotes-zXwE7yVJSLeJx4aNp3...
SeanLuke
12-note equal temperament is a reasonable local minimum but it is by no means the best in the sense of roughness: 31-note is better. Not to promote 31-note (which I do not use), but how is it that this article can arrive at 12-note in some sense of optimality with regard to roughness criteria when it is clearly not?
sideshowb
Hello. I wasn't suggesting 12 is optimal, so much as trying to explain the link between clustering and pianos. I guess by going for 2^7~=(3/2)^12 over other such correspondences I'm bringing some history to the table, intentionally or not.
ciconia
This is not the first time that I come across an article where the author derives harmonic rules from purely physical or mathematical principles. I always find it a pity that the author has apparently not made the effort of reading up a bit on the history of musical theory.
The actual harmonic rules employed today in all kinds of western music, especially as they relate to musical notation and the physical layouts (the UI so to speak) of various western musical instruments, have as much to do with the evolution of music theory as with the physical behavior of sound waves and human perception thereof.
Case in point, the layout of white and black keys on the keyboard: the disposition of white and black keys has more to do with the theory of hexachords developed in the 12th century. The hexachord system used to notate and transmit music was originally comprised of three overlapping hexachords, each including 6 notes (ut-re-mi-fa-sol-la) , which together cover in total 8 notes to the octave: The natural hexachord C D E F G A, the soft (molle) hexachord F G A Bb C D, and the hard (durum) hexachord G A B C D E. I should add that this system was superimposed on the greek modes of gregorian chant, made of two tetrachords for 7 notes to the octave.
So the soft hexachord starts on fa - the fourth tone of the natural hexachord, and the hard hexachord starts on sol - the fifth tone of the natural hexachord. And if you you play a melody and you want to go to Bb - the B flat (B-molle / bémol) is actually a fa on the soft hexachord. Likewise, a B natural (B-durum - bécarre) would be a mi on the hard hexachord. The terms bémol and bécarre (Bb and B natural) actually derive from the soft and hard hexachords (soft - round, hard - square). So the Bb was in fact the first "black" key (although some of the earliest keyboards have 8 "white" keys to the octave, with the Bb looking just like its neighbors).
Later, from the 14th century on, as music changed, more hexachords were introduced starting at different places on the natural hexachord, for more harmonic complexity. Along with those hexachords, more "black" keys were introduced. Actually some baroque keyboards include more than 12 keys to the octave, for use with meantone tuning: they would have split "black" keys in order to play the fa or mi of the note, for example Eb or D#, which in meantone tuning are not equivalent. But as composers and keyboardists started exploring both equal temperament and irregular temperaments, those distinctions were lost.
The modern keyboard with its 7 white keys and 5 black keys is rather a consequence of the evolution of western music over long centuries, not of any kind of absolute natural phenomenon.
MarkLowenstein
No doubt that you can trace the history to explain it. But is there an inherent allure of the eventual design that steered these decisions toward a result like this? The article gives a very compelling theory as to why it might.
If the effect of "inherent allure" sounds improbable, ask yourself if it might explain why common keyboard commands are nice comfortable ones to type, like ls and dir - and you never find yourself typing qza or xwz. All have good historical reasons, like not many operations starting with Z, but I think if there really was a common "Query Zeta Array" operation, it's likely it would have been renamed or there would be a tool with an easier-to-type name that would wrap it.
anamexis
Thanks for the summary, that is really interesting.
Also, I don't think the OP is making any claim that the piano keyboard is the result of any kind of natural phenomenon. They're just pointing out that you can create the same piano keyboard that we have using mathematical derivation, which is also interesting.
jng
Very interesting, I am familiar with many of the concepts and steps in the evolution of equal temperament, but I was not familiar with this part of the story at all (although I have seen pictures or drawings of keyboards with multiple split black keys). And very new to me, understanding the source of the terms "bemol" and "becuadro" (the words in Spanish for "flat" and "natural" - natural as in a note that loses its alteration and goes back to its neither-flat-nor-sharp pitch). Will try to delve into this in more detail some day with more time available. Thanks!
Valodim
I can relatedly recommend eevee's post "Music theory for nerds". I'm sure it's one of those that experts will huff and puff about, but it made a bunch of concepts between sound perception and music theory "click" for me: https://eev.ee/blog/2016/09/15/music-theory-for-nerds/
leethargo
Nice article and application idea (clustering).
After reading about the dissonance theory by Sethares [1] used as the basis of TFA, I also did some related experiments of finding the most consonant 3-note chords in different scales (not limited to 12 tone equal temperament) [2].
This whole topic (scales, microtonal music) is a huge rabbit hole for nerds with some musical curiosity and I can highly recommend the text book by Sethares on the topic.
[1] https://sethares.engr.wisc.edu/consemi.html [2] https://rschwarz.github.io/posts/consonant-triads
sideshowb
IIRC there's a vst out there that retunes itself on the fly to make each chord as consonant as possible
Get the top HN stories in your inbox every day.
(disclaimer: music degree)
I often huff and puff at articles like TFA, but here I found myself nodding: the method is sound and makes sense.
Some comments I must leave though:
Clustering is not the point of black and white keys. Rather it is the facility to pick an anatomically reachable, desired subset of 12 keys available per octave. As a simplified European tradition baseline, that is the white keys transposed by some number of semitones. The salient thing here is to have a row of keys which are mostly two semitones apart but have a one semitone gap at strategic locations to produce the scale.
Much of the music in the world operates roughly on the pentatonic scale which coincides with the black keys, or the complement of "European" scales in a 12 step equally tempered octave. Pentatonic scales are mostly two semitone steps with strategic 3 semitone steps.
Finally, the harmonic model in TFA does not resemble the piano very much. Would be interesting to see how different harmonic models and temperaments in various historical keyboard instruments interact with the computation. The modern piano is equally tempered. In a harpsichord, that would generate a lot of roughness for the thirds which are way out of tune. The modern piano mitigates this by having the hammers strike strings at a position that avoids exciting the 5th harmonic (which produces a justly intoned third on top of fundamental frequency).
Would be interesting to see what kind of difference to the roughness calculation it would make to omit the 5th harmonic!