Live data from Hacker News

Basic Music Theory in ~200 Lines of Python

mvanga.com

181–190 of 192 posts

Re: Basic Music Theory in ~200 Lines of Python

#181
post #144

Earlier quoted context omitted.

Ah alright, I finally understand you. What you meant to say is the reason why Western classical music is built on the 12 note chromatic scale is because the musicians used the math! It has nothing to do with history. Sound about right?

Although I agree with you... didn't Pythagoras derive the pythagorean tuning of diatonic doing the math with the 3:2 ratio? I know near zero music history, but I was under the impression that that's the evolution from diatonic scales and eventually into our western music system.

Yes, intervals are just ratios of numbers, corresponding to frequency ratios. 2:1 is an octave, 3:2 is a fifth, 4:3 a fourth and so on. I didn't even know this was controversial.

Of course a lot of other stuff in music and music theory is due to history and tradition. For example the names of the intervals (octave, fourth, fifth etc.) presumes a 7-note scale. Using 7 as reference is tradition, e.g. the pentatonic scale has 5 notes.

Re: Basic Music Theory in ~200 Lines of Python

#182
post #181
post #144

Earlier quoted context omitted.

Although I agree with you... didn't Pythagoras derive the pythagorean tuning of diatonic doing the math with the 3:2 ratio? I know near zero music history, but I was under the impression that that's the evolution from diatonic scales and eventually into our western music system.

Yes, intervals are just ratios of numbers, corresponding to frequency ratios. 2:1 is an octave, 3:2 is a fifth, 4:3 a fourth and so on. I didn't even know this was controversial. Of course a lot of other stuff in music and music theory is due to history and tradition. For example the names of the intervals (octave, fourth, fifth etc.) presumes a 7-note scale. Using 7 as reference is tradition, e.g. the pentatonic sca…

> Using 7 as reference is tradition, e.g. the pentatonic scale has 5.

That's our point.

Re: Basic Music Theory in ~200 Lines of Python

#183

Anyone wanting to take things back a step further to first principles may enjoy this (shameless plug - I wrote it) Deriving the piano keyboard from biological principles using clustering (Jupyter) https://fiftysevendegreesofrad.github.io/JupyterNotes/piano....

> If you hear a sound of frequency f and others of frequency 2f, 3f, etc then 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... Wow that's interesting enough to share as a standalone post, so I took the liberty! Thanks for the link!

@harperlee no worries about the share, it's great to see the variety of responses on the other thread

Re: Basic Music Theory in ~200 Lines of Python

#184
post #182
post #181

Earlier quoted context omitted.

Yes, intervals are just ratios of numbers, corresponding to frequency ratios. 2:1 is an octave, 3:2 is a fifth, 4:3 a fourth and so on. I didn't even know this was controversial. Of course a lot of other stuff in music and music theory is due to history and tradition. For example the names of the intervals (octave, fourth, fifth etc.) presumes a 7-note scale. Using 7 as reference is tradition, e.g. the pentatonic sca…

> Using 7 as reference is tradition, e.g. the pentatonic scale has 5. That's our point.

Ok, but that is kind of orthogonal to the point I was making. I was just stating that it follows from the math that the notes in a 7-note scale are not evenly spaced. The same is true for a pentatonic scale, for the same reason: The intervals corresponds to the simplest ratios (2:3, 3:4 etc.) but these do not in turn correspond to divide the octave evenly.

Re: Basic Music Theory in ~200 Lines of Python

#185
Notation wise and officially it is a loop. But the tuning is a compromise. Hence some sounds are not harmonised that way using the current scale. There is a reason why well-tempered clavier tuning is still a bit of debate. You may have to tune fir some songs differently in those days. Hence assume all flat and sharp are equal is a bit too pure that might not exist n the real world.

Re: Basic Music Theory in ~200 Lines of Python

#186
post #157

Earlier quoted context omitted.

So, this is for a few reasons. Syntax is a skill floor, but it's not anywhere close to a skill ceiling. If you want rapid-fire example of the various forms a given language commonly uses, I recommend X in Y minute guides. Those show off the various bits of syntax for a given programming language, though without rigorously defining them as such. Part of the reason that programming syntax is usually taught by example,…

> Part of the reason that programming syntax is usually taught by example, rather than by formalism is that the formalisms for programming syntax, well, look like this: (cribbing from wikipedia). Here's the thing though -- a "what is this syntax" guide does not imply that you need a formalism of the syntax. What the person is asking for, in my opinion, is a linkage between the symbols and the concepts. For example, w…

This is the answer that actually explains my problem! I went to the Learn X in Y site that another comment recommended and scrolled to the python guide[1]. It is a list of syntax, but it is (in my mind) insane! It goes right through all the math that is there and then jumps into lists. The first thing it does is show this!

# Add stuff to the end of a list with append li.append(1) # li is now [1]

And this is exactly the kind of stuff that keeps me from getting deeper into programming. I look at that, and wonder, "what the hell is that . doing?" Now, I know enough python to know that it is calling some function on an object called 'li', and that li is a list. or something that can take a .append() command. I also know that append() is some kind of function. But, these guides never give me enough detail on what the . means. Worse, it seems difficult to find answers to this kind of stuff in aggregate. If I google everything I can find stack exchange pages on each piece of syntax and can get to the point, but for fluency and retention I really need that conceptual piece.

I don't write software, but I use python/pandas for basic work with restructuring data. The hurdle to understanding how to slice data frames was incredible for me. I couldn't understand from the examples why the behavior works the way it does. I often feel like I can get working code without any real connection or understanding of why the code works.

You're answer is great, I wish there was a solution for this disconnect since I can't imagine I'm the only one who feels this way.

[1] https://learnxinyminutes.com/docs/python/

Re: Basic Music Theory in ~200 Lines of Python

#187

Earlier quoted context omitted.

> Coincidentally there are no commonly used scales or modes with two consecutive semitones. It's common in Bebop to add a passing tone to otherwise heptatonic scales. Consecutive semitones are also a common feature in blues.

That’s true but in those cases they are passing tones. For examples in a bebop scale you don’t tend to arpeggiate using both the consecutive tones.

> That’s true but in those cases they are passing tones.

That may well be their main function, especially in bebop (it's not so certain in blues), but they're still considered as part of the scale.

> For examples in a bebop scale you don’t tend to arpeggiate using both the consecutive tones.

That's true for any non-chord tones. The intervals are still very common (in bebop you commonly simply walk the whole scale up and/or down in straight 8ths or 16ths, playing adding the passing tone for the chord tones to end up on the downbeats).

Re: Basic Music Theory in ~200 Lines of Python

#188

Earlier quoted context omitted.

The quoted sentence seems false to me. Most physical objects do not have naturally harmonic vibration spectra. The vibration modes are not integer multiples ofthe fundamental (except for a vibrating string). Only the finely tuned western instruments do. So this is a somewhat backwards argument.

The code itself also contradicts that sentence. Notice that the first roughness graph doesn't have any local minima at rational numbers. It's only when the overtones are added to the notes (at integer multiples of the fundamental frequency) that the minima appear. So the code thinks that human ears don't detect integer multiples specifically, they just detect sounds whose overtones line up with each other.

Good point, but our ears definitely do perceive the 2 to 1 ratio. Maybe that particular phenomenon is better analysed through the usual pschoacoustic approach of "at what point do we stop perceiving one sound and start perceiving two "?

Re: Basic Music Theory in ~200 Lines of Python

#189
post #157

Earlier quoted context omitted.

> Part of the reason that programming syntax is usually taught by example, rather than by formalism is that the formalisms for programming syntax, well, look like this: (cribbing from wikipedia). Here's the thing though -- a "what is this syntax" guide does not imply that you need a formalism of the syntax. What the person is asking for, in my opinion, is a linkage between the symbols and the concepts. For example, w…

This is the answer that actually explains my problem! I went to the Learn X in Y site that another comment recommended and scrolled to the python guide[1]. It is a list of syntax, but it is (in my mind) insane! It goes right through all the math that is there and then jumps into lists. The first thing it does is show this! # Add stuff to the end of a list with append li.append(1) # li is now [1] And this is exactly t…

I'm just glad there's someone else with the same problem!

I think the best way might be to make something like Albertini's charts for file encodings, but for programming.

An example is here: https://raw.githubusercontent.com/corkami/pics/master/binary...

Of course even within that graph there could be more expansion that it would be nice to see

Re: Basic Music Theory in ~200 Lines of Python

#190

Earlier quoted context omitted.

Yes, but shapes are not usually random. Bars, cylinders, cubes, rectangles, squares and circles are everywhere. That does not mean that they will have a string like attenuation curve for those higher harmonics, but they'll be there.

> Yes, but shapes are not usually random. Bars, cylinders, cubes, rectangles, squares and circles are everywhere. While there are some exceptions, this is skewed in the modern industrial world. If we're making evolutionary scale arguments about sound perception it's a much tougher sell.

Consider one of the only objects that actually matters in this context: vocal cords. Of course it's true that many inert objects don't have audible overtones or resonate at all, but nearly all animal vocalizations do. More complex auditory processing means better ability to distinguish between kin and predators. The fact that non-living objects tend to produce sounds via the same principles is just icing on the cake.
Post reply on HN