Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Teoria.js - Music theory for JavaScript (saebekassebil.github.com)
77 points by saebekassebil on Jan 13, 2013 | hide | past | favorite | 21 comments



Neat! I've been reading up and playing around with this stuff the past few weeks, from both the waveform synthesis side and the music theory side. I don't think I've quite wrapped my head around the basic concepts yet. (i.e.: Why have non-chromatic scales that skip semitones? Why do some sets of notes sound good and not others? What parts of sound quality derive from innate psychoacoustics, and what parts are my bias from growing up in the Western world?) I'll definitely be taking a closer look at saebekassebil's Javascript code, which seems to be an attempt to organize these concepts.

It's strange how once you get interested in a topic, you start seeing stuff about it everywhere. First the Clojure-based Overtone project, and now this...


As to why some sets of notes sound good or harmonious and others sound "bad" or dissonant, we find that frequencies with the simplest mathematical ratios tend to sound the most harmonious, while frequencies with more complex ratios sound more dissonant.

So for example the simplest ratio 2:1 corresponds to an octave interval. Notes which are an octave apart sound so similar that we describe them with same letter. So concert A is 440Hz and the "A" note one octave higher is 880Hz.

The next simplest ratio, 3:2 corresponds to the interval known as a perfect fifth. So given the example of concert A at 440Hz again, one perfect fifth above concert A is the note E which has a frequency of 660Hz as (440 * 3) / 2 = 660.

We find the simplest ratios of frequency intervals present in music from cultures the world over. The traditional classical Western twelve-note scale consists of the 12 simplest frequency ratios. In some Eastern music we hear a pentatonic or five note scale, which consists of the five simplest frequency ratios.

So this aspect of music we can attribute to innate psycho-acoustics or even physics rather than cultural bias.


> So this aspect of music we can attribute to innate psycho-acoustics or even physics rather than cultural bias.

It's inextricable from cultural bias, though the physics obviously plays some role. The cultural bias comes into play more strongly around the question of how much dissonance is "good" vs. "bad", and how the more dissonant bits should interplay with the more consonant bits of music.

Certainly, "more consonant = better" isn't true in any culture I can think of.... Imagine an orchestra that tunes up, then they all play the note A in various octaves for 3 hours.

Possibly also worth mentioning that this isn't quite correct:

> The traditional classical Western twelve-note scale consists of the 12 simplest frequency ratios

You're thinking of the major scale, maybe? The ratios for a tritone, major 7th, etc. are more complex (and not the first 12 simplest...) and if you try to actually come up with ratios for an even-tempered scale you're really in trouble.


> It's inextricable from cultural bias, though the physics obviously plays some role.

Of course, as you say, our cultural biases/values play a role in how we create music and what music we appreciate with how much consonance/dissonance.

But the fact that certain musical intervals sound more harmonious or more dissonant seems to be a result of the human ear's response to the physical nature of the frequency of the sound waves, and thus a response that is shared across cultures.

> The ratios for a tritone, major 7th, etc. are more complex

Yeah, I guess that's true that the ratios between those 12 frequencies aren't the 12 simplest, but they can be derived by following the simplest non-octave ratio - 3:2 or a perfect fifth - starting from a root note and moving up one perfect fifth 12 times.

Thus if you start from C: C - G - D - A - E - B - F# - C# - G# - D# - A#/Bb - F and that's all 12 notes. I guess I thought that because of that pattern those were the twelve simplest ratios. Thanks for the heads up.

And yes this principle applies to the Just tempered Scale not the even-tempered scale.


    Why do some note combinations sound good.  
This is a discussion of equal temperament vs. just intonation ratios

http://irkenkitties.com/blog/2012/11/28/consonant-intervals-...

___________________

You can read a lot in the subreddit

http://www.reddit.com/r/musictheory/comments/16h5fk/how_do_y...

http://www.reddit.com/r/musictheory/comments/16gl5h/a_questi...

_________________

Equal temperament instruments present all kinds of problems, wolf intervals in the extreme (Pianos have inharmonicity/octave stretching, flutes effectively have octave stretching, guitars have all kinds of funkiness

http://www.truetemperament.com/

https://en.wikipedia.org/wiki/Wolf_interval


Overtone is a SuperCollider client written in Clojure. SuperCollider itself has a much larger library of useful code relevant to music theory.

The guy who wrote Overtone did so while he was learning music, but he isn't actually a composer. SuperCollider was developed mostly by academic musicians with a deep knowledge of experimental and traditional computer music practice. So it and the Quarks (packages) community have a wealth of code to explore.

http://supercollider.sourceforge.net/ http://quarks.sourceforge.net/


> It's strange how once you get interested in a topic, you start seeing stuff about it everywhere.

I've noticed this too. It's so strange and creepy at the same time. Whenever a topic interests me it seems to pop up in the news and everywhere, but I can't remember seeing it before at this frequency, also it never seems to appear again when I stop being interested in it.


You might like to check out this music synthesis library in Javascript: http://mohayonao.github.com/timbre


I made a quick fork to add audio to this using the Web Audio API (webkit only, tested on Chrome and Safari).

http://acarabott.github.com/teoria/


Had fun figuring out where mine and my wife's hearing fell off. Now I know where to put it when I want my kids to bugger off. :)


http://onlinetonegenerator.com/ has a nice hearing test using the audio API of Firefox.


This isn't really what I expected when I saw "music theory". It would be more aptly titled something like "frequency visualizer of chords".


I took a quick look at the Javascript code on saebekassebil's GitHub, and it does seem to be the start of some sort of music theory library. The waveform visualizer demo just doesn't seem to be very revealing of what the library is about.


The actual library does look like it does quite a bit more than waveforms -- it's mostly focused on relationships of notes (in scales, intervals, etc.), and perhaps only secondarily on frequencies. Interesting!

I have done similar work in Java -- built a library exploring note relationships, and also handling basic notation display -- but one of these days I'm going to need to migrate everything from Java applets (I know, I know) to HTML5, so I'm collecting these kinds of resources that may prove useful....

The name selection isn't great, BTW... there's been a well-known music theory website at teoria.com for more than a decade. It's a generic term (just "theory" in Spanish), so this likely isn't a legal issue, but that's going to make it quite hard to find this in Google.


Teoria.js does have a music theory api for working with notes, chords and intervals. I'm actually using it for a site I'm working on: http://groktar.com/?m=kTD4PzaNwv (shameless plug)


Same here, not what I expected. Looks great, though!


Okay, this link doesn't look like it does this justice. I found the Github page to be much better:

https://github.com/saebekassebil/teoria


On a similar note to this, I had great fun writing the keyboard and stave search input for for http://www.folktunefinder.com in JavaScript (you'll find keyboard-xxx.js file in there if you look).

(For bonus points the search engine is written in Go).


I've never considered the waveform of a chord before, is the reason that some intervals sound harmonious because the period of their combined waves is short?


Yes, exactly.


As a once undergrad music student now working in acoustics, thanks for creating this. Something like this has been on my list of things to program, especially with libraries out there like D3.js. Good luck!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: