73 comments

[ 132 ms ] story [ 2866 ms ] thread
This is very interesting indeed. They say music goes hand in hand with maths, but it's never taught that way... and musical theory (at least in the UK) teaches what exists but not the principles behind it.
Lots of information out there, but you have to have an idea of what to look for.

Sit down with this 63 part series and you'll have a very good understanding of the mathematics and physics behind sound: http://www.soundonsound.com/sos/may99/articles/synthsec.htm. You'd probably come to a lot of those realizations just working with computer audio software.

Tons of papers out there on the maths behind, say, phase-vocoder techniques (same maths behind autotune): http://www.ee.columbia.edu/~dpwe/papers/LaroD99-pvoc.pdf

The average music student is more interested in the music than what's behind it. Not at all a knock on them, just how it is.

I once went with a friend to price electric pianos. The models she was looking at sampled traditional pianos to get their notes, and had a switch to toggle between different sampled instruments.

She asked why there was such a price difference between models, based on the number of keys (unfortunately I don't remember the numbers anymore, but basically some of the models had shorter keyboards).

The response was that, for models with a smaller number of keys, they could just sample one octave of the original instrument, and scale the frequencies electronically. However, once you go beyond a certain range, straight scaling didn't work anymore, so they had to sample the whole range of a traditional piano-- hence more electronics needed in the electric piano.

(comment deleted)
I don't buy it. Sampling isn't typically done for an entire octave and then scaled 2× or ½×; that would sound terrible. Rather, usually every 3rd note (or so) is sampled, and the "missing" notes are scaled from those.

More likely the reason is that keyboard size is used as a proxy to discriminate between amateurs (who can play most anything they care to on, say, a 61-key keyboard) and professionals (who would look like fools trying to fit certain pieces into 61 keys when they are meant for the full 88).

You might be surprised at the results you can get these days. There are even "soft pianos" that are almost completely synthesized rather than sampled. They can sound amazing: http://www.truepianos.com/demos.php
Analog modelling ("the soft pianos" you mention) don't have much to do with stretching samples for several octaves the OP described.
I don't think any of the models sampled one full octave and then resampled that for the other octaves. When you change the pitch of a recorded piano note through resampling, it's going to sound very artificial if you go beyond a couple of semitones. Typically you spread the samples out so you have 3, 4 or 6 per octave.

Also, most electric pianos support transposing the whole keyboard, which means that even when you just have four or five physical octaves, you can play notes lower than or higher than that. So that explanation for the price difference is not very realistic.

Typically keyboard instruments come in '60 key' (aka 5 octave) as budget models, and 88 key (7+ octaves, piano equivalent) 'pro' models. Budget samplers sometimes sample a single octave and use integral sampling changes to fill in the rest of the octaves. That used to be to save memory (which was expensive) although it is less of an issue now.

That said, it had nothing to do with being even tempered or not, it had to do with cost. But as Yamaha and others also point out, the harmonics on every key of a piano are slightly different because the keyboard is constructed with all those hammers and strings, one for each key.

>The response was that, for models with a smaller number of keys, they could just sample one octave of the original instrument, and scale the frequencies electronically.

That's not the case. It's trivially easy and cheap to sample the full scale or close to it. No manufacturer I know uses just one octave (or even just 2 or 3). And beyond 1 octave of stretching this would sound attrocious anyway.

Probably a misinformed salesman. Back in the day (eighties, early nineties) people would do something like that, but mostly for digital samples of things like a bass, flute, etc, to conserve space in the, then, limited storage of samplers.

The price difference in digital pianos has to do with brand name, mechanical and build quality (e.g key mechanism, speakers, D/A converters etc), and extra capabilities (sequencer, etc).

The NRE and storage for additional samples isn't that much cost - now. 20 years ago, yeah. Cost is way dominated by the number of parts in the MIDI controller used.

Piano sample sets can now run into the gigs of memory - a now-defunct product that pioneered this was actually called Gigasampler.

For a file format that describes how samples relate to MIDI notes, google for "SFZ files".

The thing that might not be clear from this article is that if you tune with Pythagorean Tuning, you'll run into cases where an Ab reached from one route is different than an Ab reached from another route. Since instruments like the piano need to have only one Ab in a particular octave, that is why they'll be tuned as equal temperament, or some other method that guarantees only one Ab for a particular octave.

Otherwise, you'll run into phenomena where an instrument will sound totally awesome if played in one key, but really awful if they try to play the same tune transposed to a different key.

This is also why those with sensitive ears are frustrated by their inability to make a guitar sound in tune for both G major and E major chords.

Can confirm the Gmaj/Emaj frustration.

It's usually easy to get a decent compromise. But when a guitar is really consonant in E, it sounds like a train wreck in G.

Having a guitar be in tune across every key is not strictly impossible [1], but it sure isn't easy.

[1] http://www.truetemperament.com/site/index.php?go=2&sgo=3

I heard an interview with a world-class guitarist (forgot who, but not classical) where he said he bends every (presumably fretted) note; I wonder whether this is to play non-even temperaments from an even-tempered fret spacing.
All decent musicians adjust every note on every instrument (where possible) in order to be in tune with themselves and the others they are performing with. Musicians that don't do this quickly find themselves out of a job (or making millions as the next big pop act). Mostly, this is not done particularly consciously unless you find yourself performing with a group that is either far more accomplished or far less accomplished than yourself. Of course, there are exceptions, namely open strings and piano. However, even in the case of conventional stringed instruments, it is common to adjust fingerings to avoid open strings in order to maintain tone color and more easily adjust intonation.

Basically, while studying temperament is interesting, the reality is it rarely causes practical issues. Most pianos are tuned with equal temperament, which is good enough and almost every other western instrument has enough flexibility to adjust "on the fly."

That's solving a different problem, which is intonation (having every fret on every string in tune on the entire neck). But it still just provides intonation for a single temperament, like equal temperament.

More info here: http://www.truetemperament.com/site/index.php?go=4#A1

Right, I'm aware. Maybe I misread the last line of the grandparent, but I assumed that was exactly the problem being referred to -- the vagaries of details like string width and action height mean that even an instrument nominally designed with equal temperament in mind requires per-key adjustments to sound in tune by the standards of equal temperament.
There is no per-key adjustment in equal temperament. Equal temperament assigns an exact pitch (frequency) to each note, regardless of what key, chord, or interval the note is in. These weird frets are intended to make each note on the guitar play the exact pitch that is assigned to it by equal temperament, because normal straight frets cannot do that.
Yes, that's a basic fact that I'm well aware of. To hopefully express what I'm saying more clearly: Assume your open strings on a guitar are tuned perfectly in the standard way: the A string is 110 Hz, the low E string is 110 * 2^-5/12 Hz, the D string is 110 * 2^5/12 Hz, and so forth. This will allow you to play an in-tune E minor chord on the open strings, but other chords will not be in tune (again, with reference to the equally-tempered pitch space) to the same degree because of the fact that the strings have different densities and widths. You could imagine accounting for this by tuning the strings such that some other chord was in tune, but then your original E minor chord would no longer be in tune. Thus my point that even though the guitar's design is predicated on equal temperament, it still requires per-key adjustments to be in tune for an arbitrary chord, unless you're using one of the guitars I linked to above.
It doesn't make sense to transpose something to a different key on such an instrument since none of the notes repeat. A piano tuned with Pythagorean tuning would only have one key.
That would only work for the simplest tunes. As soon as you get to classical music (which pick certain, different keys for pianistic reasons), or any tune that modulates, you'd be in for some listening pain.
I have wondered though...you could use a synthesier with an organ-style foot pedalboard, use those to set the active key and just intonate everything to that key, modulation at will.
And that's why equal temperament was invented - so different instruments can play together.
In fact, this is fairly common in Hindustani music. Many ragas have different versions of the same note depending on how you approach it and switching between ragas often requires re-tuning
Is that really why G and E chords are that way? I think it's more an issue of fret intonation. Guitars are typically tuned to equal temperament, just like a piano, so such a guitar with perfect intonation should sound just as good on every chord as a perfectly tuned piano.
Right, but when tuning by ear and actually turning the tuning knobs, it's easy to "mistakenly" make G major sound better than it would in equal temperament, which would in turn make E major sound worse. Or vice versa.
That's possible, but I think that effect is negligible in practice. I suspect the percentage error of intonation between two different frets is much higher than the difference between a just intonation and equal temperament interval.
This doesn't match my experience. When I tune by ear, I spend a lot of time compromising to get even a few basic chords to all sound good. But since we're talking about the math, I thought I'd try to put some numbers behind my experience.

  Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
  [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> A = 440
  >>> def alterBySemitones(basenote, semitones):
  ...     return basenote * (2 ** (semitones/12.0))
  ...
  >>> equal_B = alterBySemitones(A, 2)
  >>> equal_G = alterBySemitones(A, -2)
  >>> equal_E = alterBySemitones(A, -5)
  >>> major_third_ratio = 5.0/4
  >>> perfect_fifth_ratio = 3.0/2
  >>> equal_G * major_third_ratio     # B as third of G major chord
  489.9942949771866
  >>> equal_E * perfect_fifth_ratio   # B as fifth of E chord
  494.44133536930485
  >>> equal_B                         # Equal tempered B
  493.88330125612413
There's about a 4.5 Hz difference between just-tuned Bs in those two chords. For reference, the distance between that B and the Bb below it is about 27.72Hz. If your fret spacing is introducing that much error, it's going to be tough to tune the instrument for more than maybe one chord at a time.
It's not intuitive to me how big of a difference 4.5 Hz is, but you really need to use a logarithmic scale (because, for instance, shifting everything up an octave will yield different errors in Hz). In cents, that's about a 16 cent difference, while an equal tempered semitone is 100 cents. Is 16 cents easily noticeable? I don't have a nice tuner handy, so I can't say.

Still, your claim doesn't seem right to me. A perfect tuned guitar with perfect intonation in equal temperament will play the same frequencies as a perfectly tuned piano. Yet, when I play G and E chords on a piano, I don't notice the same tuning issues as I often do on guitar. That's why I assumed the bigger issue on guitars is intonation.

Yes, I should have gone logarithmic. But I spent enough time playing with that. Had to get back to work. ;) Thanks for figuring out that it's 16 cents. And yes, 16 cents is very noticeable. I might even say dramatic.

The thing is, tunesmith wasn't talking about a perfectly tuned equal temperament guitar. We're talking about tuning a guitar by ear so that one chord is sounds perfectly in tune (i.e., is in just temperament), then trying to play a different chord. It's going to sound off for the same reasons a just-tempered keyboard would. And as someone who constantly has to resist the urge to tune his B string too high in G major, I can tell you this isn't just a theoretical assertion.

That said, I have played on guitars (especially electric ones) that seem to resist sounding in tune even when the open strings are tuned "perfectly." Maybe that's a fret spacing defect in action. But it doesn't make the tuning-by-ear error negligible.

> The thing is, tunesmith wasn't talking about a perfectly tuned equal temperament guitar. We're talking about tuning a guitar by ear so that one chord is sounds perfectly in tune (i.e., is in just temperament), then trying to play a different chord.

When I reread your comment, I realized that this is what you were talking about. In that case, you're absolutely right. Although it is a pretty bad idea to tune a guitar by ear by playing a single chord. Not only will other chords sound out of tune, but even slightly different voicings of the same chord. A guitar that's designed for equal temperament really needs to be tuned as such. Correct me if I'm wrong, but I think the standard ear tuning technique (where you match the 5th or 4th fret of one string with the open string under it) will give much better equal temperament results.

16 cents is a lot. It's 1/6th of a semitone.
Pianos aren't actually tuned to equal temperament, due to the inharmonicity of their very tense and thick strings.

http://en.wikipedia.org/wiki/Stretched_tuning

Yes, but that's a technicality. The goal is to have it sound equal tempered.
Of course. I wasn't criticizing, just mentioning, in case anyone found that tidbit interesting.
I think you're referring to "the G string problem".

The deflection of the third string at the first fret G# pulls the string a bit sharp relative to the open G on the third string.

There is a specialized guitar nut called the Earvana that has additional material to shorten the open G string a wee bit to compensate for this.

In real life, getting any (non-keyboard) instrument to actually play in tune is the hardest part.

Players of bowed stringed instruments run into this difficulty too. When playing with piano, cellists often have to tune both their lowest and highest strings to the piano, and then sort of average out the discrepancy in the two strings between.
Use of non-equal temperaments on keyboard instruments is rare but not unheard of. The unique sound of each key can be exploited. As I understand it, there is a school of thought that each piece in Bach's "Well Tempered Klavier" was written for the sound of that key in a keyboard instrument tuned using the well temperament.

In addition to being tempered, the entire scale of a piano from bottom to top is "stretched" slightly by a mainstream technician.

Also as I understand it, harpsichords tend to use historical tuning methods. One possible reason is that the musician had to tun the instrument quite frequently, as opposed to the much more mechanically stable piano.

Students who study string instruments (as I did) are taught that intonation is somewhat malleable for expressive purposes. The strings are tuned in beat-free intervals to maximize resonance when playing in particular keys. And wind instruments are all over the place, with ongoing efforts to improve their intonation.

Interesting - I've had a lot of back and forths with a friend of mine with this.. I'd strum a Gmaj and hed insist its out of tune.
The usage of “perfect fifth” to indicate only the just fifth (3:2 ratio) is slightly idiosyncratic (but not unheard of); more commonly in modern usage, “perfect fifth” refers to both the just (3:2) and equal-tempered (2^(7/12)) fifths, or to any other tempered fifth, for that matter (for reasons that aren’t entirely clear—or at least differ depending on who you ask—the unison, fourth, fifth, and octave are collectively called the “perfect” intervals in common parlance, regardless of temperament).
A little more info for those who are curious: The perfect intervals (unison, 4th, 5th, 8ve) can be modified by being diminished or augmented, which shrinks or expands the interval by one half step. The other intervals (2nd, 3rd, 6th, 7th) can be either diminished, minor, major, or augmented. The major interval is what you'd get if you're measuring the intervals on a major (Ionian) scale; minor is -1 half step, dimished -2, augmented +1.

My intuition about which intervals are major / minor and which are diminished comes from the intervals that create the differences between the major and minor scales. The major scale uses all major intervals; natural minor uses minor 3rd, 6th and 7th; Dorian minor has a major 6th, and harmonic minor a major 7th. That still doesn't account for why the 2nd is called major / minor -- you could argue that you use it in Phrygian mode, but then you'd have to acknowledge that you use the diminished 5th in Locrian mode, so why not call that the major / minor 5th? (But almost no music is written in the Locrian mode).

Another intuition is that the fourth and fifth are the most consonant intervals (because the ratio of their frequencies is simplest) and so an adjustment of a half step is more of an increase in dissonance than a similar adjustment on another interval.

Finally, non-perfect 4th and 5th intervals are simply encountered much less frequently than other intervals (with the exception of the tritone between the 3rth and 7th of a dominant V chord, the characteristic dissonance that sets up the V-I authentic cadence).

Notice also that in major keys, there is only a half-step between the 3rd and the 4th tones, meaning the diminished 4th interval will sound as a major 3rd. The augmented 4th (or diminished 5th - a.k.a tritone) perfectly splits the octave in this tuning system. You can go up or down by an augmented 4th or diminished 5th as many times as you want and only ever be playing the same two note-names.
Your intuition is basically right: perfect octaves/fifths/fourths are called "perfect" because they have the most acoustically pure: 2:1, 3:2, and 4:3, respectively. They're also the oldest consonances, described supposedly by Pythagoras but extant in the Euclidean "Sectio canonis" (~3rd C. BCE).

The other intervals weren't considered consonant until much later (the middle ages), and didn't get their "major/minor" names until a bit later, in the Renaissance. Before this, they were known by their Latin names (M3 = ditone, m3 = semiditone, and so on). The m2 was found in (at least) two forms until the advent of equal temperament, usually known as the major and minor semitones.

The "major" intervals are those found in the major scale (M2, M3, M6, M7). The minor intervals aren't named in relation to the minor scale, but rather in relation to their major equivalents (a minor second is lower than a major second). "Minor" comes from "molle," which is "soft": the major third is "softened" to become the minor third, and so on.

One neat property of "perfect" intervals is that, when you invert them, they remain perfect!

Perfect unison inverts to unison. Perfect octave inverts to an octave.

Perfect 4th (C to F) inverts to a perfect 5th! And vice-versa.

Contrast to a major third, or major second, which, when inverted, becomes a minor 6th (or minor seventh.) That is, the interval quality of perfects remains the same, where as major/minor/augmented/diminished intervals change qualities.

It's worth noting that the perfect fourth, when it involves the bass, is considered a dissonance in Common Practice music,* and even in the freer harmonic contexts of twentieth century music it's a bit of a cipher: it acts as a dissonance in relatively consonant contexts and as a consonance in relatively dissonant contexts.

* If you read Schoenberg's Harmonielehre, he has some pretty idiosyncratic but somewhat plausible theories about why the 6/4 chord is dissonant, involving the overtones of the bass being diatonic (say we're talking about C 6/4 and the relevant overtones being B and D) but also dissonant with regards to the nominal root of C. That the 6/3 chord is relatively consonant is explained by the fact that the overtones of the bass in that arrangement suggest a sufficiently distant key so as not to plausibly oppose the sounding fundamentals. I think the more likely explanation is the historical one, which treats the 6/4 as the reification of the frequently used motif of a suspension from the pre-dominant harmony over the dominant bass that then passes downward to the goal tones (in C major, the archetypal lines would be A -> G -> F -> E and F -> E -> D -> C over a bassline like F (or D) -> G -> G -> C). The 6/4 chord's dissonance, then, is merely a result of the fact that its appearance came to unequivocally imply a certain resolution.

(comment deleted)
Article 2nd paragraph: "Suppose a string of a certain tension and length produces an A when plucked. If you make the string twice as tight, or keep the same tension and cut the string in half, the string will sound the A an octave higher."

This is not even dimensionally correct. The frequency is proportional to the square root of the tension.

Later: "The ratio of 3/2 is called a “perfect” fifth to distinguish it from the ratio 1.498."

I don't think so. The interval is called a "perfect" fifth to distinguish it from the "diminished" or "augmented" fifth. Nothing to do with tuning.

The usage of “perfect” to mean “just” is uncommon, but not really wrong. It’s somewhat more common in older (19th century), AFAIK.
Related is that going four steps around the circle of fifths, for a total of five pitch classes, produces the pentatonic scale (e.g. the black keys). This is the longest sequence that doesn't contain any half steps. Continue for a total of seven notes and it's the diatonic scale (e.g. white keys†). This is the longest sequence that doesn't contain consecutive half-steps. Finally, continue for a total of twelve notes, as the article describes; the resulting chromatic scale is either (in just temperament) the longest sequence where every step is at least a half step, or (in even temperament) the longest sequence before the pitch classes repeat.

† Annoyingly, the tonic (tonal center) of the diatonic scale is the second note in the sequence of fifths (e.g. C in FCGDAEB). I believe this is so you depart the tonic by a fifth in either direction, since fifths sound so good.

Yep. In other words, the common scales are the number of consecutive perfect 5ths to "almost" land back on the first note, with "almost" defined progressively stricter. This exercise could be extended to make longer scales, but the additional notes would be close enough to the first 12 to just sound to human ears more like knockoffs of notes in the first 12 than new notes in their own right.

Instead, the standard of modifying the 11 notes after the first in various ways to make instruments sound good in more keys proved to be more worthwhile.

It's tough for someone who's not a professional musician to tell the difference between a just fifth (3:2) and an equal tempered fifth (2^(7/12):1) but it's not impossible.

Probably the easiest way is to go to a piano and play a fifth with the base note at middle C. The sound noticeably changes after a couple of seconds. That's because the ratio isn't exactly 3:2 and the frequencies of the pure notes start to get out of alignment (the same phenomenon causes 'beats' when two similar but not exactly equal frequencies are played together).

It's even more pronounced when you play a C major chord (C-E-G) because the major third (C-E) isn't exactly 5:4 and the minor third (E-G) isn't exactly 6:5 either.

The equal-tempered major third is 14 cents higher (1 semitone = 100 cents) than a just-tempered third, which is pretty noticeable even for non-trained musician.
There is a great book, "Musical Applications of Microprocessors" [1] which has an excellent treatment of this. In my early experiments the floating point accuracy of 8bit micros was poor enough that even tempered scales were pretty hard to do. That said, the article describes the different techniques exceptionally well.

[1] http://www.amazon.com/Musical-Applications-Microprocessors-H...

I've calculated the values according to the described circle of fifths and drawn a plot comparing it to equal temperament (x is the pitch steps 1..13, y is the frequency 0..2, the curve at the bottom is the difference, magnified 10 times, the gray line at the bottom is the x axis). Done quick and dirty, i.e. I manually filled in the slots for the 12 pitches. I felt a bit disappointed when I reached the end of the article and was told that this isn't actually what's normally done...

http://christianjaeger.ch/scratch/octave/ (The code is written in Scheme with some libraries that I haven't published so far.)

Can anyone give a mathematical explanation of how to find n such that equally tempered divisions of the octave into n parts give rise to consonant intervals? I have read that 53 works even better than 12, but I wonder if there are more (infinitely more, I would imagine) exponents, and how this sequence (the next number is the lowest n that is better than the previous one) can be found.
I have played with this question in the past, and never found a better "formula" than a search along the following lines:

For each n, find the closest interval to a perfect fifth (3/2 ratio), and write down the error in octaves. Graph error as a function of n, and you will see certain values of n with low error. On the same graph, do the 4/3 ratio, and so forth, for a small handful of small-numbered ratios.

Somehow 19 springs to mind as having reasonably consonant intervals, but I don't remember for sure.

12 is the smallest, and is also an auspicious number in ancient cultures.

I built a tool to compare the relationship of different n-note equal temperment tunings a few years ago[1]. The UI is a bit obtuse, but it compares the frequencies of the n-note system with the frequencies of the older just intonation system. In 19 Tone Equal Temperment, the Eb and A are within 1 cent of what they would be in a just intonation tuning, which is pretty cool. I find 22 TET interesting as well.

[1] http://www.eng.uwaterloo.ca/~mawillia/music/

The "most consonant" is Pythagorean for the simple fractional intervals, so you'd have to weight somehow against that.

I'm using "minimum number of beats" as the definition of "consonant".

I expect it is obvious, but why is the ratio of 3/2 called a "fifth"? It's not because 3 + 2 = 5 is it?
If you walk up the notes of the major scale starting from your reference pitch, the fifth note in the scale will be the one that has the 3/2 pitch ratio.
The 3/2 ratio is called a "fifth" and the 5/4 ratio is called a "third". I can't make this stuff up.
Equal Temperament is an abstraction - different instruments will have an entire discipline of temperament. One of the more complex suites of temperament regimes are the temperament regimes used on pedal steel.

Getting a steel to "do" ET is actually an achievable engineering problem, but players may prefer the sound of something more akin to Just intonation and older guitars may not be able to be in ET. Guitars with all the parts to achieve ET are relatively obscure.

C, E-flat, and G walk into a bar. The bartender says, "Sorry, but we don't serve minors."

So E-flat leaves, and C and G have an open fifth between them. After a few drinks, the fifth is diminished, and G is out flat.

F comes in and tries to augment the situation, but is not sharp enough. D comes in and heads for the bathroom, saying, "Excuse me; I'll just be a second." Then A comes in, but the bartender is not convinced that this relative of C is not a minor.

Then the bartender notices B-flat hiding at the end of the bar and says, "Get out! You're the seventh minor I've found in this bar tonight."

E-flat comes back the next night in a three-piece suit with nicely shined shoes. The bartender says, "You're looking sharp tonight. Come on in, this could be a major development." Sure enough, E-flat soon takes off his suit and everything else, and is au natural.

Eventually C sobers up and realizes in horror that he's under a rest. C is brought to trial, found guilty of contributing to the diminution of a minor, and is sentenced to 10 years of D.S. without Coda at an upscale correctional facility.