Music theory for programmers
18 points by thev
18 points by thev
My father always wanted to be a composer, but was stymied by a lack of mathematical ability. When I proved to have some mathematical talent, he was so excited for me to get into music, but I proved to have zero musical talent and have always been vastly confused by the most elementary parts of the topic. The use of the word "elementary" is literal - by the second half of first grade, I was completely lost at what was going on in music class.
My first confusion that even this article commits is the claim that, when you double the frequency, you get the same note. This is always presented as so obvious to not need explanation, but, while I'm well versed in the harmonics explanation, I've never actually heard a sameness between the two sounds. Alternately, I may have completely misunderstood what a note is supposed to be?
My second confusion was at least slightly addressed by this article. At forty-four years old, this is the first time that I've ever heard that the first beat of a measure was supposed to be played louder. I was always just given the tautological definition that, in 4/4 time, a beat was defined as a fourth of a measure and a measure was defined as four beats. By that definition, I could merge ever pair of measures, declare the time signature is 8/4, and get back the exact same song. I was always told that was wrong, but the only explanation I ever got was that 8/4 wasn't 4/4 time.
I think insights like these are useful, thanks. I have my own analogous hang-ups about how music is taught.
In terms of "double frequency = same note", I think people did a big disservice describing it this way. Maybe they should have said something like "the same note class", as in trying to convey this modular arithmetic idea. I will say that doubling the frequency means that, in some sense, the lower frequency note is "embedded" in the higher frequency note as all the peaks of the lower frequency note appear in the doubled frequency note.
I will also point out that many animals that make melodies, like birds singing a tune, can't recognize pitch shifts. So, try to teach a bird the same song just shifted up an octave and they need to learn a whole new song. So, in some sense, this gives some validation about your inability to "hear the same note" shifted up an octave or that it should be obvious they're the same.
An the article does say "... the first beat of each group is the strong one." but, to me, it's not obvious that means "play louder". One could argue that we by the act of mentally grouping things into fours, we put more focus on the first note, when listening, say. I always took it as obvious that 8/4 was functionally identical to 4/4 but I've never taken any music theory courses. Looking at the Wikipedia artical on time signature:
... changing the bottom number and keeping the top number fixed only formally changes notation, without changing meaning ...
There might be some suggestions on how quickly to play a tune but, formally, I take this to mean 8/4 should be exactly equivalent to two 4/4.
The time signature gives you the formal notation mapping but, as you note, it’s got a degree of freedom (actually a few).
So the choice of signature controls how people will “count” and that’s designed, usually, to be a guide as to the feel and rhythm of the piece. Writing a piece in 6/8 is different from writing in 3/4 even though they’re the same. The first has a faster “pulse” and admits more groupings like 3-3 (a “shuffle”).
Not sure if this is helpful but another way I think of time signatures is like, not always as an inherent mathematical truth about a song, but a way of communicating to a performer. So you try to pick one that makes it as easy you can for the performer to understand what you're trying to get across. So while you could re-notate a 4/4 song as 8/4, the main thing you lose is this assumption that the pulse of the music (mostly) repeats repeats every 4 beats: it could also be true that it repeats every 8 beats, but if you want the performer to feel a repeated strong pulse every four beats (maybe not even the first beat of the bar! but just that it repeats at that interval) then you could convey that more clearly with 4/4.
Related, this great meme + analysis from Adam Neely: "every song is in 4/4 if you don't count like a nerd!"
I share the same feeling that these concepts are typically explained very badly. One of my main complaints is that there is usually very little effort made to distinguish between facts that are true of music in general vs facts that are true of western music. In particular the conventional musical notation is taken as a given, when I feel like it obscures more than it explains.
It would be like if you taught a new programmer Javascript and told them that the behavior of arrays you see in that language are just How Arrays Work In Computers rather than specific language design choices (and sometimes mistakes!) which you can make differently.
Yes, this. Even “western music” encompasses more variation than how music theory is typically taught. Looking at the ergonomics of a drum kit and electric guitar will teach you more about rock music than any classical theory. And western theory spends approximately zero time on timbre so how is it going to talk about electronic genres.
Fun side detail: the harmonic structure that is implicit in a lot of western theories breaks down when applied to bells (such as you might find in a church town) which, due to being three dimensional rather than two, have radically different harmonics and pairs of notes that would be consonant on eg a stringed instrument are dissonant on bells.
My first confusion that even this article commits is the claim that, when you double the frequency, you get the same note.
The best explanation I have seen is this video on the physics of dissonance, which illustrates how notes that are “too close” to each other sound bad. Even when the fundamental frequencies of two notes are not too close, their overtones can clash causing them to sound dissonant. When the overtones are in the harmonic series and the frequencies are doubled there’s no dissonance, so the notes don’t have the texture of a chord containing notes in other ratios, so it sounds almost as if they are the same note. But this depends on the overtone structure of the notes, so if they aren’t perfectly harmonic then the octave consonance won’t quite work.
…this is the first time that I've ever heard that the first beat of a measure was supposed to be played louder.
This is true in a lot of European/occidental music, but there are lots of exceptions. Typically in blues/rock/jazz, the snare drum hits on 2st and 4th beat, and in the reggae world there’s this funny thing called “one drop” where nothing happens on the first beat.
Typically in blues/rock/jazz, the snare drum hits on 2st and 4th beat
And even the way we perceive the pitch of percussion as accent can be flipped completely. Typically the low kick will still be on 1+3 with the higher pitched snare as an accent on 2+4. But go listen to a Brazilian samba bateria, now you have the low surdo drum play on 2+4, which gives it this really nice wobbly vibe, especially when you add in the polyrhythms.
My first confusion that even this article commits is the claim that, when you double the frequency, you get the same note. This is always presented as so obvious to not need explanation, but, while I'm well versed in the harmonics explanation, I've never actually heard a sameness between the two sounds.
As someone who has been learning music lately (not my first attempt), I also don't really 'hear' the sameness between the same note at different octave in isolation, however I can easily distinguish when two notes are not the same. If you placed C4 and C5 I don't think I could say definitively they're the same note, but if you played C4 and D5 I would be able to tell with certainty they are not the same note and my ability to determine that has only gotten better with practice.
this is the first time that I've ever heard that the first beat of a measure was supposed to be played louder
Maybe it's a common stylistic choice (especially in genres that don't often make use of drums, for example), but with music there's basically nothing that is "supposed" to be done, it is done and often for a reason, but almost nothing is a requirement. This is the first time I think I've heard anything about it as well.
Time signatures have often tripped me up too. When speaking with people who know music theory, it seems like they'll compare and contrast the time signatures of different songs like it says something significant about the composition, but in the back of my mind I'm always thinking, isn't it just a notation thing? Can it really change a song's character when you could contort all the notes to fit a different time signature?
Maybe it's something I'd get if I tried making music myself.
You can definitely analyze a song in different time signatures! Similar to how you can read a book and pick out different themes and use different lenses to look at it from. Those may or may not be what the author intended but it doesn't make the analysis wrong. But similarly some analysis can seem like more of a stretch than others (how much is actually there vs me inferring? etc)
I left another reply on another comment but as an author, I feel you just do the best you can to communicate what you want the song to feel like to the people performing the song, and some ways of notating will feel like better fits to your vision than others.
You can essentially describe pretty much all music in the same time signature. In music notation, it can be notated to work. But the problem is the difficulty in communicating what it is you want the reader of the sheet music to play.
I was always just given the tautological definition that, in 4/4 time, a beat was defined as a fourth of a measure and a measure was defined as four beats. By that definition, I could merge ever pair of measures, declare the time signature is 8/4, and get back the exact same song.
Ohhh, I feel this so much! Time signatures were explained to me numerically before they were explained in terms of rhythm/emphasis.
What frustrated me was that this made transcription "impossible": if you heard a tune that was a multiple-of-four beats, it could just as easily be 2/4 time as it could 4/4 time, so you couldn't write it down. (And even counting beats was not a guarantee because of rests, etc.) In practice, everything is 4/4, and "you'll know" when it's not. But it really irritated me—I mean, what a defective notation system, right?!
I think the numbers are just the easiest aspect to teach. "Some beats are louder" gives you a more accurate picture, but emphasis isn't purely volume, either—otherwise you couldn't play rhythmically on a harpsichord. But how do you teach the subtle changes in timing? How do you codify that a waltz makes you want to tap your foot every 3 beats?
I think music theory teaching that just says "the only reason we do it this way is because people got used to it and it sounds familiar so we like" does students a disserve because it makes everything in music sound arbitrary, which it's not.
I also think posts like this which say "it's all just math and logic under the hood and makes perfect sense" in some CS also do students a deep disservice. It sucks the human element out and encourages students to think about music as simply playing a game where you have to follow the rules to get a correct answer.
The truth is that music is a mixture of both. There is real math behind acoustics and psychoacoustics. The sounds, pitches, intervals, and chords we like are not completely random. But as music listeners, we are also not simply listening to discriminate whether the composer followed the math rules right. We want tension and release, a mixture of the familiar and unfamiliar.
If you follow all the rules, your music won't sound wrong, but it will sound boring. You need enough of a foundation of theory to not waste too much time trying to brute force good chords from scratch, but you also need to know when to jam a weird note in because that spiciness perks up the listener's ear in just the right way.
And, as a listener, you are already doing that. The sounds that catch your ear are the ones that have enough familiarity and consistency with rules and tradition that you can aurally parse them, but that have enough novelty and originality to be worth listening to.
I think this is very well said. Personally as a programmer I find I overindex on trying to understand things at a low level and do them "right." The thing I need to deliberately lean into instead is to learn from references, how they chose to do things and what worked, which is a very different kind of study. So it becomes less of an intractable "do something slightly different if it works" and more "use this voicing I picked up that they use in jazz because it works here." I think you have to learn to mimic existing styles and learn the differences between them, and then you'll start being able to synthesize your own - math is never going to get you there.
I’m a little cautious that using perfect synthesis to explain music theory and to then make some pretty universal claims about music across all cultures is maybe not accurate? Most physical instruments are not perfect (a great example of this is the frets on a regular guitar compared to the wobbly frets on a “true temperament” guitar), there’s more that goes into even something as simple as a scale than just the harmonic series in a vacuum.
Even if we limit ourselves to western music, 12 tone equal temperament was adopted in the 18th century, which moved further away from the harmonic series based tuning system that preceded it (Just intonation) because there are organisational properties that make it more useful most of the time.
(Edit: Corrected the proceeding paragraph which I initially wrote entirely backwards from what i meant)
This is good stuff! I really wish I’d had something like this in my early 20s when I first got a keyboard and nothing made sense — “Why do they divide the octave in 12 but then have seven note names? Seven doesn’t go into twelve!” It was also confusing that sometimes they talk about intervals in terms of numbers of semitones and sometimes in scale steps. Being a nerd, I couldn’t work with something whose structure didn’t make sense to me.
It wasn’t until my 40s that I got back into music and gradually figured this shit out. I made a bunch of spreadsheets of scales and chords and stuff as learning aids.
Oh, and add me to the list of people for whom octaves don’t sound like “the same note”. Very similar, yes, but I still have to think a moment to tell an octave interval from a fifth.
Just the last week I was writing groups for drum rudiments. I was working with paradiddles and shift, reverse and flip operations, turns out it gives a few different groups, mostly related to the cycle groups and their quotients. Also playing with free monoids / generating new rudiments from smaller cells gives different strings and it's nice to play with, e.g, instead of combining L and R strokes combining LL, LR, RR, RL, not too complicated or fancy, but certainly fun to play with
Also, its interesting to work with representations of sheet music, with parallel/sequential composition on the one hand and dividing the whole of the song into fractions on the other, and mapping between both, with some anciliary data
Still, haven't found a simple one-liner that outputs say the first page of stick control using just a few primitives and combinators