<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Fabulous Adventures In Coding : Music</title><link>http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx</link><description>Tags: Music</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Desafinado, Part Five: Getting Down Without Hitting The Bottom</title><link>http://blogs.msdn.com/ericlippert/archive/2005/04/18/desafinado-part-five-getting-down-without-hitting-the-bottom.aspx</link><pubDate>Mon, 18 Apr 2005 21:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:409291</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/409291.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=409291</wfw:commentRss><description>&lt;FONT face="lucida sans unicode" color=#800080 size=2&gt;
&lt;P&gt;Back in the 1960's a guy named Shepard published a paper which described a way to create a descending scale of twelve notes such that every consecutive pair was perceived as being two notes, the second one lower than the first. That's not hard -- every descending scale has that property! The kicker is that in a Shepard scale, &lt;B&gt;people also perceive the last note of the scale as higher than the first.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Clearly that's totally impossible. If every note is lower than the one before then the twelfth cannot be higher than the first. And yet Shepard's Illusion is pretty strong. Another guy named Risset figured out a way to make the scale "continuous", so it sounds like one long note constantly getting lower but never hitting bottom.&lt;/P&gt;
&lt;P&gt;It's pretty tricky to pull off the illusion, and I haven't done a perfect job, but this at least illustrates it somewhat.&lt;/P&gt;
&lt;P&gt;The key to pulling off the illusion is to have the tone actually made up of many overtones and subtones of a primary tone. Take A=440Hz, for example. As I mentioned back in part one, for some reason humans seem to strongly associate perfect octaves. 220Hz and 880Hz sound like "the same note", only lower or higher respectively. It is hard to realize that this is not one tone, but actually many.&lt;/P&gt;
&lt;P&gt;What we'll do is play the three A's from the three different octaves simultaneously. If we played them all at the same volume, it's hard for the human ear to pick out which one is the "most important", but if we play the bottom one very softly, the middle one very loud, and the top one about medium, then it's easy to "lock on" to the mid-range component of the sound. &lt;/P&gt;
&lt;P&gt;Imagine someone playing this on the piano -- hitting three A's, the middle one loud and the bottom and top ones quietly.&lt;/P&gt;
&lt;P&gt;Now move all three notes UP eleven semitones, so that the A&amp;#9837; at the bottom is just below what was previously the middle A. Play the bottom note really loud but slightly softer than the previous loud A, the middle note slightly louder than the previous high A, and the new high note very soft indeed. The human ear does not perceive that as every note moving eleven semitones up, but rather that the loudest tone has moved down.&lt;/P&gt;
&lt;P&gt;Now take all three notes down a semitone. Every time you go down a semitone, make the bottom note a little quieter and the middle and top notes a little louder. Keep going until you get back to where you started, at which point go up eleven semitones again.&lt;/P&gt;
&lt;P&gt;That's the essence of the illusion. The human ear attunes itself to the loudest part of the tone, and therefore doesn't notice that the lows are dropping out of the bottom and being replaced by very faint notes at the top. As the top notes descend they get louder and louder, and eventually the ear switches from hearing the middle note as the primary to the bottom note as the primary, and then back to the middle later. &lt;/P&gt;
&lt;P&gt;Doing this as a continuously sliding tone requires some easy calculus. &lt;/P&gt;
&lt;P&gt;Consider just one component of the sound. We want to have a sine wave that is getting slower and slower over time. Say it starts at 440Hz and when we're done, it's going at 220Hz. How are we going to model this? Well, think "cycles per second". Take a wheel spinning on a fixed axle and put a mark on the edge. Ignore the side-to-side component of the mark as the wheel spins and just look at the up-and-down motion. That motion describes a sine wave. Spin the wheel at 440 cycles per second, and we'll get a 440 Hz sine wave out of the vertical component.&lt;/P&gt;
&lt;P&gt;How are we going to slow down from 440 Hz to 220 Hz, over, say, 16 seconds? We could use a linear model -- lose 14 Hz a second -- but that's not very sensible when we're thinking of sound. Remember, humans hear sounds based on ratios, not based on absolute numbers of cycles. Really what we want is for this to decay geometrically. We want the sound to have a "half life" in the frequency domain.&lt;/P&gt;
&lt;P&gt;It is convenient to measure the speed not in revolutions per second but in radians per second. There are 2&amp;pi; radians per revolution, so a wheel that is spinning at 440 Hz is spinning at 880&amp;pi; radians per second. Let's say that we're going to decay from our original frequency f=440 Hz down to f/2 in T seconds. What is the angular velocity at time t if it is an exponential decay?&lt;/P&gt;
&lt;P&gt;&amp;omega;(t) = (2&amp;pi;f) 2&lt;SUP&gt;-t/T&lt;/SUP&gt; radians per second&lt;/P&gt;
&lt;P&gt;Check that -- yep, that gives you 880&amp;pi; radians per second for t = 0, and 440&amp;pi; radians per second for t=T. &lt;/P&gt;
&lt;P&gt;Super. Now we need to determine the height of the mark at any given time. The angular position is easily determined from the angular velocity, and the height is the sine of the angle. Let's work out the angle:&lt;/P&gt;
&lt;P&gt;&amp;Theta;(t) = &amp;int;&amp;omega;(t) dt = (-2fT&amp;pi;/ln 2) 2&lt;SUP&gt;-t/T&lt;/SUP&gt; + C&lt;/P&gt;
&lt;P&gt;for some constant C which we'll just set to zero arbitrarily -- we do not care about the phase, just the frequency. &lt;/P&gt;
&lt;P&gt;Take the sine of the angle, and we're all set, we've got our decaying wave. &lt;/P&gt;
&lt;P&gt;That takes care of the frequency decay. What about the change in volume of each component?&lt;/P&gt;
&lt;P&gt;We'll do a rough approximation of a bell curve. We want the very highest highs to come in very quietly. We want the very lowest lows to go out very quietly. And we want most of the sound energy in the middle, so that that's what you hear. Rather than muck around with computing a real bell curve, we'll just do a simple linear approximation of one.&lt;/P&gt;
&lt;P&gt;I find the illusion to be strongest when the primary note is pretty low. Let's try 110 Hz, two octaves below concert A. We'll make some simple modifications to yesterday's program. We'll decay over 16 seconds, and we'll do three decays.  And we'll use eight full octaves.&lt;/P&gt;
&lt;FONT face="Lucida Console" color=#333399 size=2&gt;&lt;BR&gt;namespace Wave { &lt;BR&gt;&amp;nbsp; using System; &lt;BR&gt;&amp;nbsp; using System.IO; &lt;BR&gt;&amp;nbsp; class MainClass { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void Main(String[] args) { &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FileStream stream = new FileStream("test.wav", FileMode.Create);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BinaryWriter writer = new BinaryWriter(stream);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int RIFF = 0x46464952;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int WAVE = 0x45564157;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int formatChunkSize = 16;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int headerSize = 8;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int format = 0x20746D66;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short formatType = 1;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short tracks = 1;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int samplesPerSecond = 44100;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short bitsPerSample = 16;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short frameSize = (short)(tracks * ((bitsPerSample + 7)/8));&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int bytesPerSecond = samplesPerSecond * frameSize;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int waveSize = 4;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int data = 0x61746164;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int T = 16;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int reps = 3;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int samplesperrep = samplesPerSecond * T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int dataChunkSize = samplesperrep * reps * frameSize;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int fileSize = waveSize + headerSize + formatChunkSize + headerSize + dataChunkSize;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(RIFF);
&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(fileSize);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(WAVE);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(format);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(formatChunkSize);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(formatType);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(tracks);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(samplesPerSecond);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(bytesPerSecond);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(frameSize);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(bitsPerSample);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(data);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(dataChunkSize);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double fundamental = 110.0;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double ampl = 10000;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int j = 0 ; j &amp;lt; reps ; ++j)&amp;nbsp;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; samplesperrep; i++)&amp;nbsp;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double t = (double)i / (double)samplesPerSecond;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp0 = (ampl/8) * t / T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp1 = (ampl/8) + (ampl/8) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp2 = (ampl/4) + (ampl/4) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp3 = (ampl/2) + (ampl/2) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp4 = (ampl/1) - (ampl/2) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp5 = (ampl/2) - (ampl/4) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double amp6 = (ampl/4) - (ampl/8) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;double amp7 = (ampl/8) - (ampl/8) * t/T;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double theta = -fundamental * 2 * Math.PI * T * Math.Pow(2, -t/T) / Math.Log(2);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short s = (short)(&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amp0*Math.Sin(theta*16)+amp1*Math.Sin(theta*8)+&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amp2*Math.Sin(theta*4)+amp3*Math.Sin(theta*2)+&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amp4*Math.Sin(theta*1)+amp5*Math.Sin(theta/2)+&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; amp6*Math.Sin(theta/4)+amp7*Math.Sin(theta/8)&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Write(s);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.Close(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stream.Close(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;BR&gt;&amp;nbsp; } &lt;BR&gt;} &lt;BR&gt;&lt;/FONT&gt;
&lt;P&gt;The brain at some point stops thinking that the lower midrange frequency is the interesting one, and switches to the higher. If you listen attentively you can notice when your brain makes the switch, and the illusion is then somewhat dispelled.&lt;/P&gt;
&lt;P&gt;Pretty weird, eh? &lt;/P&gt;
&lt;P&gt;Coming up soon: back to wackiness in scripting!&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=409291" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Science/default.aspx">Science</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx">Music</category></item><item><title>Desafinado, Part Four: Rolling Your Own WAV Files</title><link>http://blogs.msdn.com/ericlippert/archive/2005/04/15/desafinado-part-four-rolling-your-own-wav-files.aspx</link><pubDate>Fri, 15 Apr 2005 21:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:408632</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/408632.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=408632</wfw:commentRss><description>&lt;FONT face="Lucida sans unicode"&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;We’ve established why every just about piano in the world -- in fact, every concert-pitched musical instrument in the world -- is slightly out of tune. No one actually plays perfect fifths; every fifth interval is slightly flat. Why don't we hear the difference? Is the difference even perceptible?&lt;/P&gt;
&lt;P&gt;It is &lt;I&gt;very&lt;/I&gt; hard to hear unless you compare and contrast. So let's do that. Here's a little C# program I just whipped up. This program creates a WAV file that first plays two seconds of E a perfect fifth above concert A=220Hz, and then two seconds of E a slightly flattened fifth above A. &lt;/P&gt;
&lt;P&gt;Can you hear the difference?&amp;nbsp;I can't hear the difference between the two E's at all.&lt;/P&gt;
&lt;P&gt;However, you can REALLY hear the difference in the next section. The file then plays two seconds of E and a "perfect B" above it together, and then two seconds of E and a "concert B" above it. &lt;/P&gt;
&lt;P&gt;Now it is obvious -- with such clean, perfect waves you can really strongly hear it when it goes out of tune. You get a sort of ringing "wah wah wah" effect as the waves go in and out of sync with each other. The number of&amp;nbsp;wahs,&amp;nbsp;or, as piano tuners call them, &lt;STRONG&gt;beats&lt;/STRONG&gt;&amp;nbsp;per second tells you how close to a perfect fifth the notes are -- the slower the beats, the more in tune.&amp;nbsp; Experienced piano tuners can easily hear when the number of beats per second&amp;nbsp;is just right for the piano to be exactly out of tune enough to be evenly tempered. &lt;/P&gt;
&lt;P&gt;This code could use some explanation. &lt;/P&gt;
&lt;P&gt;The basic WAV file format follows the Interchange File Format specification. An IFF file consists of a series of "chunks" where chunks can contain other chunks. Each chunk starts with an eight byte header: four bytes describing the chunk, followed by four bytes giving the size of the chunk (not counting the eight byte header). The header is followed by the given number of bytes of data in a chunk-specific format. A WAV file consists of one main chunk called RIFF that contains three things: the string "WAVE", a "format" chunk that describes the sample rate, etc, and a "data" chunk that contains the sampled waveform.&lt;/P&gt;
&lt;P&gt;We won't mess around with any advanced WAV file features like cue points or playlists or compression. We'll just dump out some data and play it with the WAV file player of your choice. We'll use CD quality audio -- 44100 samples per second, each one with 16 bits per sample. (Unlike a CD, we'll do this in mono, not stereo.)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Lucida Console" color=#333399 size=2&gt;
&lt;P dir=ltr&gt;namespace Wave&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;using System;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;using System.IO;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;class MainClass {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static void Main()&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FileStream stream = new FileStream("test.wav", FileMode.Create);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BinaryWriter writer = new BinaryWriter(stream);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int RIFF = 0x46464952;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int WAVE = 0x45564157;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int formatChunkSize = 16;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int headerSize = 8;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int format = 0x20746D66;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short formatType = 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short tracks = 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int samplesPerSecond = 44100;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short bitsPerSample = 16;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short frameSize = (short)(tracks * ((bitsPerSample + 7)/8));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int bytesPerSecond = samplesPerSecond * frameSize;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int waveSize = 4;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int data = 0x61746164;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int samples = 88200 * 4;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int dataChunkSize = samples * frameSize;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int fileSize = waveSize + headerSize + formatChunkSize + headerSize + dataChunkSize;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(RIFF);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(fileSize);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(WAVE);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(format);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(formatChunkSize);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(formatType);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(tracks);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(samplesPerSecond);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(bytesPerSecond);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(frameSize);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(bitsPerSample);&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(data);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(dataChunkSize);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double aNatural = 220.0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double ampl = 10000;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double perfect = 1.5;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double concert = 1.498307077;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double freq = aNatural * perfect;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int&amp;nbsp;i = 0; i &amp;lt; samples / 4; i++) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double t = (double)i / (double)samplesPerSecond;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short s = (short)(ampl * (Math.Sin(t * freq * 2.0 * Math.PI)));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(s);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;freq = aNatural * concert;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int i = 0; i &amp;lt; samples / 4; i++)&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double t = (double)i / (double)samplesPerSecond;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short s = (short)(ampl * (Math.Sin(t * freq * 2.0 * Math.PI)));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(s);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int i = 0; i &amp;lt; samples / 4; i++) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double t = (double)i / (double)samplesPerSecond;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short s = (short)(ampl * (Math.Sin(t * freq * 2.0 * Math.PI) + Math.Sin(t * freq * perfect * 2.0 * Math.PI)));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(s);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (int i = 0; i &amp;lt; samples / 4; i++) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double t = (double)i / (double)samplesPerSecond;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;short s = (short)(ampl * (Math.Sin(t * freq * 2.0 * Math.PI) + Math.Sin(t * freq * concert * 2.0 * Math.PI)));&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Write(s);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;writer.Close();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stream.Close();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#800080 size=2&gt;
&lt;P&gt;Compile this guy up, run it, and listen to test.wav. Pretty cool eh?&lt;/P&gt;
&lt;P&gt;Next time, we'll wrap up with one of the most interesting psychological effects you can get in music -- a tone that goes down, but never hits bottom.&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=408632" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Science/default.aspx">Science</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx">Music</category></item><item><title>Desafinado, Part Three: Too Many Fifths</title><link>http://blogs.msdn.com/ericlippert/archive/2005/04/13/desafinado-part-three-too-many-fifths.aspx</link><pubDate>Wed, 13 Apr 2005 22:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:407908</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/407908.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=407908</wfw:commentRss><description>&lt;FONT face="lucida sans unicode" color=purple size=2&gt;
&lt;P&gt;Last time we established the diatonic scale which has the nice property that there are five tone intervals and six fifths:&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR align=middle&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Note&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Frequency&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;220.000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;247.500&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;260.741&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;293.333&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;330.000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;347.654&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;391.111&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;and then double for the next octave up and so on.&lt;/P&gt;
&lt;P&gt;But it's a little weird in that B doesn't have a fifth above it, just E a fifth below it. Similarly, F has no fifth below it. If there were any justice in this world, B and F ought to be fifth's of each other. But they're not quite right! A fifth above B is smack between F and G. Similarly, a fifth below F is between A and B. &lt;/P&gt;
&lt;P&gt;We stuck E and B between two other notes. So let’s do it again. The fifth below F is a little bit below B, so we'll call it "B flat", or B♭. A fifth above B is a little bit above F, so we'll call it "F sharp", or F♯ In our first octave we have&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR align=middle&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Note&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Frequency&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;220.000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;231.769&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;247.500&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;260.741&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;293.333&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;330.000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;347.654&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;371.250&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;391.111&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Gah. This doesn't solve anything. &lt;B&gt;Now we've got two more notes missing a fifth&lt;/B&gt;. Well, let's add them. A fifth below B♭ is E♭, a fifth above F♯ is C♯. And &lt;B&gt;again&lt;/B&gt;, we've got the same problem! A fifth below E♭ is A♭, a fifth above C♯ is G♯, and our first octave and a bit now looks like this:&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR align=middle&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Note&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Frequency&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;206.017&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;220.000 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;231.769 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;247.500 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;260.741&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;278.438 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;293.333 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;309.025&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;330.000 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;347.654 &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;371.250&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;391.111&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;412.033&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;417.657&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;440.000&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Hold on a minute here. This is getting ridiculous. A♭ and G♯ are less than 2% apart, and seem to have gotten out of order -- how is it that A♭ is lower than G♯? 
&lt;P&gt;This is a mess. In two octaves our stringed instrument now has over 25 strings and we don't seem to be slowing down at all as far as adding new ones goes!&lt;/P&gt;&lt;B&gt;
&lt;P&gt;We could keep on doing this literally forever&lt;/B&gt;. Why? Because as the Pythagoreans discovered, &lt;B&gt;there are no whole number ratios that can be squared, cubed, or put to any other power such that you eventually end up with two&lt;/B&gt;. We are &lt;B&gt;never&lt;/B&gt; going to multiply &lt;B&gt;any&lt;/B&gt; new note by any combination of 2/1, 1/2, 3/2 or 2/3 and end up with a note that we've already got in any other octave. The system is not closed.&lt;/P&gt;
&lt;P&gt;Look at how close A♭ and G♯ are. Wouldn't it be tempting to just "split the difference", set them equal to each other, and be done with it? &lt;/P&gt;
&lt;P&gt;Hmm.&lt;/P&gt;
&lt;P&gt;Let's throw out that A♭ in there and look at the ratios of successive notes -- not as whole number ratios, but as percentages.&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR align=middle&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Note&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Increase&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;7.0%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.3%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;6.8%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.3%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;6.8%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.1% &lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;7.0%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.3%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;6.8%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.3%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;6.8%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G♯&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;5.3%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Each note on this scale is between 5.1% and 7.0% higher than the previous note. &lt;B&gt;What if we made every interval the same percentage?&lt;/B&gt; What percentage would it be? We need to double in frequency over an octave, and have twelve steps to do it in. The twelfth root of two is about 1.05946. Suppose we redo this twelve-note scale so that every note is 5.946% higher than the previous. What do we get?&lt;/P&gt;
&lt;TABLE class=""&gt;
&lt;TBODY&gt;
&lt;TR align=middle&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Note&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Frequency&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;Difference&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;220.000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.00%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A♯/B♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;233.082&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.57%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;246.942&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.23%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;261.625&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.34%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;C♯/D♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;277.183&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.45%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;293.664&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.11%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;D♯/E♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;311.127&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.68%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;E&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;329.627&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.11%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;349.228&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.45%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;F♯/G♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;369.995&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.34%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;391.995&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.23%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;G♯/A♭&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;415.305&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;-0.56%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR align=middle&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;A&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;440.000&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class=""&gt;&lt;FONT face="lucida sans unicode" color=purple size=2&gt;0.00%&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;This is pretty darn close to the scale we deduced from Pythagorean principles. And we have successfully split the difference -- we say that A♭ and G♯ are the same frequency. Similarly, we add D♭ = C♯ and so on, so that &lt;B&gt;every note has a fifth below and a fifth above.&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;This twelve-note scale is called the &lt;B&gt;equally-tempered chromatic scale&lt;/B&gt;, and it is the scale that pianos and other musical instruments are actually tuned to. &lt;/P&gt;
&lt;P&gt;This scale is &lt;B&gt;a compromise between flexibility and tonal perfection&lt;/B&gt;. The price you pay for having a closed system is that instead of the frequency of the higher note being 1.5 times the frequency of the lower note, it's actually 1.4983 times higher -- &lt;B&gt;every fifth interval is slightly flat&lt;/B&gt;.&lt;B&gt; &lt;/P&gt;&lt;/B&gt;
&lt;P&gt;And in fact that's how piano tuners do it "by ear". They tune one string to a tuning fork, then tune a fifth above it to a &lt;B&gt;perfect&lt;/B&gt; 3:2 fifth, and then flatten the upper string just very slightly (or, equivalently, slightly sharpen the lower string if they are tuning a fifth below). Then they use that as the reference to tune the next note above it to a slightly flattened fifth, and so on until all twelve notes in one octave are tuned. Every other note can then be tuned to those reference notes. The process of getting the middle octave of the piano tuned is called "setting the temperament", which explains my little pun in part one. &lt;/P&gt;
&lt;P&gt;Bach's famous set of preludes and fugues, one in all twelve major and minor keys, is called "The Well-Tempered Clavier". Though it sounds good when played in an equal temperament, Bach actually designed the pieces to be played on a "Well Tempered" instrument. In that temperament certain intervals are kept pure while others are significantly off, and must be avoided by the composer.&lt;/P&gt;
&lt;P&gt;Next time, we get computers back into the picture. We'll write some programs that illustrate this fact, and thereby show how piano tuners can tune pianos by ear. Then in my final installment we'll write a program that illustrates a psychoacoustic oddity called Shepard's Illusion.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=407908" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Science/default.aspx">Science</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx">Music</category></item><item><title>Desafinado, Part Two: A Perfect Pythagorean Tuning</title><link>http://blogs.msdn.com/ericlippert/archive/2005/04/11/desafinado-part-two-a-perfect-pythagorean-tuning.aspx</link><pubDate>Mon, 11 Apr 2005 21:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:407252</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/407252.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=407252</wfw:commentRss><description>&lt;FONT face="Lucida Sans Unicode" color=purple size=2&gt;
&lt;P&gt;Last time we talked about the Pythagorean's discovery that sounds with vibrations in the ratios 1:2 and 2:3 sound consonant to the human ear. Let's explore the consequences of that a bit.&lt;/P&gt;
&lt;P&gt;Suppose we're building a stringed instrument from scratch and we want to tune it so that it sounds good to human ears.&amp;nbsp; Let's tune the first string so that it vibrates at 440 vibrations per second.&amp;nbsp; The unit of vibrations per second is the Hertz, so this is a 440Hz string.&amp;nbsp; Call that string "A2".&lt;/P&gt;
&lt;P&gt;There's no particularly good reason to pick 440Hz versus any other frequency, but we've got to start somewhere. Also, note that I'm assuming here that we have some magical way to exactly tune a string to a particular number of vibrations.&amp;nbsp;The practical details of piano tuning in the absense of electronic measuring equipment are interesting, but before we get into that, I want to have a theoretical basis for what the ideal tuning ought to be.&lt;/P&gt;
&lt;P&gt;Anyway, we've labeled this string "A2", and it's 440Hz.&amp;nbsp; We'll add&amp;nbsp;two more strings, an&amp;nbsp;octave above and below that: A1=220Hz and A3=880Hz.&lt;/P&gt;
&lt;P&gt;If we want to do nice harmonies and melodies, we have an intuition from Pythagorus that fifths are a good idea.&amp;nbsp;What note below A2 makes a perfect fifth with A2?&amp;nbsp; That is, what to 440Hz makes a 2:3 ratio?&amp;nbsp; Easy -- 293.333Hz.&amp;nbsp; Call that string D1, and make a string D2 an octave above it.&amp;nbsp; So far we've got&lt;/P&gt;&lt;FONT face="Lucida Console"&gt;
&lt;P&gt;Note&amp;nbsp;Frequency&lt;BR&gt;&amp;nbsp;A1&amp;nbsp;&amp;nbsp; 220.000&lt;BR&gt;&amp;nbsp;D1&amp;nbsp;&amp;nbsp; 293.333&lt;BR&gt;&amp;nbsp;A2&amp;nbsp;&amp;nbsp; 440.000&lt;BR&gt;&amp;nbsp;D2&amp;nbsp;&amp;nbsp; 586.666&lt;BR&gt;&amp;nbsp;A3&amp;nbsp;&amp;nbsp; 880.000&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;A now has a fifth below, D has a fifth above. Let's make a fifth below D. What to D2 makes a 2:3 ratio?&amp;nbsp; Call that G1, and add an octave G2 above it:&lt;/P&gt;&lt;FONT face="Lucida Console"&gt;
&lt;P&gt;Note Frequency&lt;BR&gt;&amp;nbsp;A1&amp;nbsp; &amp;nbsp;220.000&lt;BR&gt;&amp;nbsp;D1&amp;nbsp;&amp;nbsp; 293.333&lt;BR&gt;&amp;nbsp;G1&amp;nbsp;&amp;nbsp; 391.111&lt;BR&gt;&amp;nbsp;A2&amp;nbsp;&amp;nbsp; 440.000&lt;BR&gt;&amp;nbsp;D2&amp;nbsp;&amp;nbsp; 586.666&lt;BR&gt;&amp;nbsp;G2&amp;nbsp;&amp;nbsp; 782.222&lt;BR&gt;&amp;nbsp;A3&amp;nbsp;&amp;nbsp; 880.000&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Now do the same thing to G2 to make C1 and C2, and the same thing to C2 to make F1 and F2, and we end up with a stringed instrument that looks like this in the first octave: (the second octave is all these doubled, so I'm going to stop calling out which octave we're in when I name the note.&amp;nbsp; It'll be clear from context.)&lt;/P&gt;&lt;FONT face="Lucida Console"&gt;
&lt;P&gt;Note Frequency&lt;BR&gt;&amp;nbsp;A&amp;nbsp;&amp;nbsp; &amp;nbsp;220.000&lt;BR&gt;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp; 260.741&lt;BR&gt;&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp; 293.333&lt;BR&gt;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp; 347.654&lt;BR&gt;&amp;nbsp;G&amp;nbsp;&amp;nbsp;&amp;nbsp; 391.111&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;We'd then have an eleven-stringed instrument on which you could play traditional Asian music.&amp;nbsp; This is called the &lt;B&gt;pentatonic scale&lt;/B&gt; because it has five notes before it repeats.&lt;/P&gt;
&lt;P&gt;Something that's interesting about this scale is the &lt;STRONG&gt;ratios between successive notes' frequencies:&lt;/STRONG&gt;&lt;/P&gt;&lt;FONT face="Lucida Console"&gt;
&lt;P&gt;A : C = 27 : 32&lt;BR&gt;C : D =&amp;nbsp; 8 : 9&lt;BR&gt;D : F = 27 : 32&lt;BR&gt;F : G =&amp;nbsp; 8 : 9 &lt;BR&gt;G : A =&amp;nbsp; 8 : 9&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Clearly there is something interesting going on with this 8:9 ratio.&amp;nbsp; Therefore, we'll give it a name. Just as the interval between two notes that are 2:3 is called a "fifth", the interval between two notes that are 8:9 is called a "tone".&lt;/P&gt;
&lt;P&gt;There are two notable things here. First, the gaps from A to C and&amp;nbsp;D to F are awfully big, quite a bit bigger than a tone.&amp;nbsp; Second, though D:A is a fifth, there is no string such that A:x forms a fifth.&amp;nbsp; We forgot to add a fifth above A.&lt;/P&gt;
&lt;P&gt;In keeping with our intuition that the 8:9 ratio is important, let's insert tones above A and D.&amp;nbsp; We'll add notes in an&amp;nbsp;8:9 ratio,&amp;nbsp;call them B and E, and then work out the ratios of each string to its neighbour again:&lt;/P&gt;&lt;FONT face="Lucida Console"&gt;
&lt;P&gt;Note &amp;nbsp;Frequency Ratio to next&lt;BR&gt;&amp;nbsp;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 220.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 : 9&lt;BR&gt;&amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 247.500&amp;nbsp;&amp;nbsp;&amp;nbsp; 243 : 256&lt;BR&gt;&amp;nbsp;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 260.741&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8 : 9&lt;BR&gt;&amp;nbsp;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 293.333&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 : 9&lt;BR&gt;&amp;nbsp;E&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 330.000&amp;nbsp;&amp;nbsp;&amp;nbsp; 243 : 256&lt;BR&gt;&amp;nbsp;F&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 347.654&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 : 9&lt;BR&gt;&amp;nbsp;G&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 391.111&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8 : 9&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;Hey, check it out -- this has the nice additional property that E is a fifth above A! Coolness. Two birds with one stone and all that.&lt;/P&gt;
&lt;P&gt;This is called the &lt;B&gt;diatonic scale&lt;/B&gt;, and is the standard scale for western music.&amp;nbsp; These are the white keys on a piano.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Interestingly, the ancient Greeks developed this standard scale, but different groups wrote music in modes that emphasized different starting notes. If you play the scale CDEFGABC, we'd call that a "major" scale, but the Greeks would have called it the "Ionian Mode".&amp;nbsp; The Aeolian Mode started on A, and we'd call that the "natural minor" scale.&amp;nbsp; The Mixolydians started on G. (The Beatles wrote several songs in Mixolydian Mode, which is why songs like "Love Me Do" and "A Hard Day's Night" have a kind of odd sound to their chord progressions.)&amp;nbsp; There is a different Greek tribe associated with each possible starting note, but they all used this scale.&lt;/P&gt;
&lt;P&gt;Now we see where the terms "octave" and "fifth" come from. There are &lt;B&gt;eight&lt;/B&gt; diatonic notes between (inclusive) any two notes an octave apart, and for every note &lt;B&gt;except B and F&lt;/B&gt;, there are &lt;B&gt;five&lt;/B&gt; notes between two notes a fifth apart. B has no fifth above, F has no fifth below.&lt;/P&gt;
&lt;P&gt;The diatonic scale has many nice properties -- it has a large number of pairs of notes that sound good together. &lt;STRONG&gt;The greatest number of consonant pairs of any&amp;nbsp;seven note scale, in fact.&lt;/STRONG&gt;&amp;nbsp; (The proof is left as an exercise to the reader.) A consequence of this fact is that if we want &lt;STRONG&gt;more&lt;/STRONG&gt; consonant pairs, we're going to have to add &lt;STRONG&gt;more notes&lt;/STRONG&gt;. Let's do that. After all, so far everything is working out great! &lt;/P&gt;
&lt;P&gt;Next time: fixing that problem with B and F not having one of their fifths is going to screw &lt;EM&gt;everything&lt;/EM&gt; up.&lt;/P&gt;
&lt;P&gt;(Foreshadowing -- your sign of a quality blog.)&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=407252" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Science/default.aspx">Science</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx">Music</category></item><item><title>Desafinado, Part One: Eric Continues His Obsession With The Greeks</title><link>http://blogs.msdn.com/ericlippert/archive/2005/04/08/desafinado-part-one-eric-continues-his-obsession-with-the-greeks.aspx</link><pubDate>Fri, 08 Apr 2005 22:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:406605</guid><dc:creator>Eric Lippert</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/ericlippert/comments/406605.aspx</comments><wfw:commentRss>http://blogs.msdn.com/ericlippert/commentrss.aspx?PostID=406605</wfw:commentRss><description>&lt;FONT face="lucida sans unicode" color=purple size=2&gt;
&lt;P&gt;Whew.&amp;nbsp; That's enough wacky VBScript for a while.&lt;/P&gt;
&lt;P&gt;As I said a long, long time ago now, I came up with the idea of doing a little "wacky VBScript" quiz in order to illustrate some of the weird corner cases in language design.&amp;nbsp; I want to do a long -- potentially very long -- series on some of the more computer sciency fundamental issues in the theory of programming languages and what "computation" means. These quirks are just the fun corner cases.&lt;/P&gt;
&lt;P&gt;But I feel like changing gears for a bit before I get into that heavy lifting, if you'll pardon the mixed metaphor.&lt;/P&gt;
&lt;P&gt;So for the next little while, music! No computers!&lt;/P&gt;
&lt;P&gt;Well, ok, maybe &lt;EM&gt;some&lt;/EM&gt; computers. In parts one through three, we'll build up some musical theory starting from the Ancient Greeks. In Part Four, we'll write a program that illustrates what I'm talking about. In Part Five, weird psychoacoustics!&lt;/P&gt;
&lt;P&gt;*********************************************&lt;/P&gt;
&lt;P&gt;One of my many dilletantish hobbies is playing the piano.&amp;nbsp; I've got an upright at home with a lovely case and a terrible action, and it's not really in tune.&amp;nbsp; I have all the equipment I need to tune it myself, I just don't have the time right now, or the temperament.&lt;/P&gt;
&lt;P&gt;Ha ha ha ha, little piano tuner joke there.&amp;nbsp; It'll become clear why that's so funny in a bit.&lt;/P&gt;
&lt;P&gt;The ironic thing about tuning a piano is this: &lt;B&gt;all pianos are out of tune. On purpose.&lt;/P&gt;&lt;/B&gt;
&lt;P&gt;In fact, almost all music you've ever heard on all instruments has been deliberately out of tune.&lt;/P&gt;
&lt;P&gt;How is that possible?&amp;nbsp; Surely you'd have noticed!&lt;/P&gt;
&lt;P&gt;To explain, we have to go way, way back to the time of Pythagoras, that mystic ancient Greek whose dour band of crazy math geeks violently suppressed information about dodecahedra and the irrationality of root two.&amp;nbsp; Amongst the Pythagoreans' many fundamental discoveries in mathematics is that if you pluck tightened strings of &lt;STRONG&gt;equal tension and different lengths&lt;/STRONG&gt;, the sound is most &lt;B&gt;consonant&lt;/B&gt; -- pleasing to the ear&amp;nbsp;-- when the ratio between the string lengths is a &lt;B&gt;ratio of small whole numbers&lt;/B&gt;.&lt;/P&gt;
&lt;P&gt;For instance, take a string under tension and press down on it like you would on a guitar,&amp;nbsp;dividing it into two strings, one twice as long as the other.&amp;nbsp;&amp;nbsp;Or, equivalently, get two strings under the same tension, one twice as long as the other.&amp;nbsp; If you&amp;nbsp;pluck them&amp;nbsp;at the same time then&amp;nbsp;you get a very pleasing sound.&amp;nbsp; The ratio is 1:2, and this is a "perfect octave". &amp;nbsp;&amp;nbsp;Find yourself a piano and hit middle C and the next higher or lower C and you'll hear what I mean.&amp;nbsp; In some very strong sense the human ear hears these two tones as extremely similar. We hear it as "the same tone, only higher".&lt;/P&gt;
&lt;P&gt;Clearly&amp;nbsp;"octave" has something to do with the number eight -- what exactly will become clear later.&lt;/P&gt;
&lt;P&gt;Why it is that humans find small ratios pleasant is an interesting question that I might explore in another post.&amp;nbsp; But for now, just accept that small whole number ratios sound really good.&lt;/P&gt;
&lt;P&gt;If 1:2 sounds good, what about other small-number ratios?&amp;nbsp; Doubling/halving the string length gives you an octave. What about making the string 50% longer -- a ratio of 2:3?&amp;nbsp; Yes, that also sounds really good.&amp;nbsp; If you play C on a piano and then hit the G below it, that's a ratio of 2:3 in terms of string length (again, assuming that the strings are under the same tension, etc.)&amp;nbsp; &lt;/P&gt;
&lt;P&gt;This is the ratio used in Gregorian chants.&amp;nbsp; This ratio is called a "fifth", again, for reasons which will become clear later.&lt;/P&gt;
&lt;P&gt;We know nowadays something that the Pythagoreans did not: that what really matters is not the &lt;B&gt;lengths of the strings&lt;/B&gt;, but the &lt;B&gt;speed at which they vibrate&lt;/B&gt;.&amp;nbsp; It just happens that a string that is twice as long vibrates half as slowly, all other things being equal, so basically the ratios are the same whether you're talking about string length or vibration frequency, they're just opposite in order. &lt;/P&gt;
&lt;P&gt;From now on we'll talk only about ratios in terms of their vibrations per second, and stop worrying about &lt;STRONG&gt;string length&lt;/STRONG&gt;. A piano has eight octaves. If the longest string had to be 128 times longer than the shortest string then&amp;nbsp;you'd need a big room!&amp;nbsp; Therefore we vary the thickness, weight and tension of the strings so that they can be a reasonable length and yet vibrate at the right frequency. It's the vibrations that matter.&amp;nbsp;(The variance in thickness of the strings leads to practical problems with inharmonicity in the short strings, but we probably won't get into that level of detail in this series.)&lt;/P&gt;
&lt;P&gt;Next time we'll mentally&amp;nbsp;build a stringed instrument from scratch and figure out how to tune it to perfect Pythagorean pitches.&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=406605" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Rarefied+Heights/default.aspx">Rarefied Heights</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Science/default.aspx">Science</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Music/default.aspx">Music</category><category domain="http://blogs.msdn.com/ericlippert/archive/tags/Ancient+Greeks/default.aspx">Ancient Greeks</category></item></channel></rss>