TuningLib

Yesterday, I added a new Quark to Supercollider, called TuningLib. It requires a recent version of MathLib, one with the Bessel.sc file included. There are several classes in the new Quark, all realted to tuning.

Stuff from Jascha

Scala – This class is based on the SCL class from Jascha Narveson, but updated so it’s a subclass of the newer Tuning class. It opens Scala Files, which means you can use the large and interesting scala file library of thousands of tunings.
Key – Jascha’s SCL file also did a bunch of other interesting tuning-related things that the newer Tuning class does not, so I put these features in Key. It tracks your key changes and can interpolate between a given frequency or tuning ratio and the current active Scale.

Dissonance Curves

DissonanceCurve – is, I think, the most interesting part of the TuningLib. It generates Tunings, on the fly, for a given timbre. Give it your spectrum as lists of frequencies and amplitudes, or as a FFT buffer or as the specs for an FM tone, and it makes two different scales.
The first kind of scale it makes is the sort described by Bill Sethares. If you want to see the generated curve, you can plot it. Or you can get a Tuning from it. Or, you can get a scale made up of the n most consonant Tuning ratios. This is used in the second section of my piece Blakes 9
The other sort of tuning it does is based on a similar idea, but using the classic Just Intonation notions of consonance. Like with Sethares’ algorithm, every partial of a timbre’s spectrum is compared against every partial of the proposed tuning. It calculates the ratio between the frequencies. This could be 3/2, for example, or 115/114 or any whole number ratio. The numerator and denominator of that ratio are summed. In just intonation, smaller numbers are considered more consonant, so the smaller the sum, the more consonant the ratio. (This sum is related to Clarence Barlow‘s ideas of ‘digestibility.’) Then, the resultant sum is scaled by the amplitude of the quieter of the two partials. So if they are 3/2 and one has an amplitude of 0.2 and the other of 0.1, the result will be 0.5 ( = (3 + 2) * 0.1). This process repeats for every partial, and the results for each are summed, giving the level of dissonance (or digestibility) of the proposed tuning.
After computing the relative dissonance of all 1200 possible tunings in an octave, the next step is to figure out which ones to select as members of a scale. For this, the algorithm uses a moving window of n potential tunings. For a given tuning, if it is the most consonant of the n/2 tunings below it and the n/2 tunings above it, then it gets added to the Tuning returned by digestibleTuning.
I don’t have any sound examples for this usage yet, but I’m working on some. I don’t know of any pieces by anybody else using this algorithm either, but I’m sure I’m not the first person to think of it. If you know of any prior work using this idea, please leave a comment.

Tuning Tables

Lattice – This is based on some tuning methods that Ellen Fullman showed me a few years ago. Based on the numbers you feed it, which should be an array of 2 and then odd numbers, it generates a tuning table. for [2, 5, 3, 7, 9], it creates:

 1/1  5/4  3/2  7/4  9/8
 8/5  1/1  6/5  7/5  9/5
 4/3  5/3  1/1  7/6  3/2
 8/7  10/7 12/7 1/1  9/7
 16/9 10/9 4/3  14/9 1/1

You can use this class to navigate around in your generated table. For otonality, adjacent fractions are horizontal neighbors, so they share a denominator. For utonality, neighbors are on the vertical axis, so they have the same numerator. Three neighboring ratios make up a triad. You can walk around the table, so that you’re playing a triad, and then pick a member f that triad to be a pivot. Then, create a new triad on the other axis that contains your pivot as one of the members.
For example, one possible walk around the table, starting at 0,0 would be [1/1, 5/4, 3/2], [5/4, 1/1, 5/3], [3/2, 4/3, 5/3], [8/5, 4/3, 8/7], [8/7, 9/7, 1/1] etc. As you can (hopefully) see, the table wraps around at the edges.
I’ve done several pieces using this class, usually initializing it with odd numbers up to 21. Two examples are Beep and Bell Tolls

Undocumented

There is also a class FMSpectrum that will compute the spectrum for a FM tone if given the carrier frequency, the modulation frequency and depth (in Hz). I would like to also add in a class to calculate the spectrum of phase-modulated signals, but I don’t have the formula for this. If you know it (or where to find it), leave a comment!

More Tuning

While continuing to ponder tuning, I realized that it would be possible to create a dissonance curve for just intonation. Instead of judging how close the frequencies are to each other to look for roughness, you would look at what tuning ratio they described. If one frequency was 1.5 times the other, then that’s a ratio of 3 / 2. Then add the numerator and denominator to get 5. Then scale by amplitude.
In Sethares’ dissonance curves, you get scale degrees by searching for minima in the curve, but that approach is not a meaningful way to sort just ratios. Instead, they can be sorted by their relative dissonance.
I’ve updated my class, DissonanceCurve.sc (and fixed the url. sorry) so it can do just curves also. I ran it with the following (rough draft-ish) code:

 b = Buffer.alloc(s,1024); // use global buffers for plotting the data
 c = BufferTool.open(s, "sounds/a11wlk01.wav"); 

// when that's loaded, evaluate the following
(

 Task({

   d = SynthDef(foo, 
    { FFT(b, PlayBuf.ar(1, c.bufnum, BufRateScale.kr(c.bufnum))); 0.0 }).play;

  0.2.rand(3.7).wait;

   e = DissonanceCurve.newFromFFT(b, 1024, highInterval: 2, action: {arg dis;
 
    var degr, top5;
 
    d.free;

     dis.scale.do({ |deg|
  
      postf(" % / %,",
        deg.numerator, deg.denominator);
     });
    "n---just---".postln;
    dis.scale.size.max(25).do({ |index|
 
     degr = dis.just_scale[index];
        postf(" % / %,",
         degr.numerator, degr.denominator);
     }); 

 
   });
 
 
 }).play
)

And, after seriously heating up my computer, and waiting a bit, I got the following output:

 1 / 1, 29 / 28, 6 / 5 , 5 / 4 , 33 / 26, 4 / 3, 15 / 11, 29 / 21, 7 / 5, 10 / 7, 
3 / 2 , 8 / 5, 5 / 3, 27 / 16, 49 / 29, 12 / 7, 67 / 39, 7 / 4, 17 / 9, 2 / 1, 
---just---
 1 / 1, 3 / 2, 2 / 1, 4 / 3, 5 / 4, 6 / 5, 7 / 6, 9 / 8,  8 / 7, 10 / 9, 5 / 3, 
12 / 11, 15 / 14, 13 / 12, 11 / 10, 16 / 15, 9 / 7, 7 / 5, 14 / 13, 22 / 21, 7 / 4, 
10 / 7, 21 / 20, 11 / 8, 11 / 9,

The top section is the Sethares algorithm dissonance curve. I made a minor adjustment so that it looks at fractions one cent on either side of them minima and grabs the simpler one if it exists. (This is optional, add “simplify: false” to the method invokation to turn it off.)
The bottom section is the 25 least dissonant just ratios. Looking first at those, note that 1/1 is the least dissonant,as one would expect. Usually, 2/1 would be next, but note that in this case, it’s 3/2 instead. The algorithm does favor low number ratios, which is logical. Notice, also, that it tends to favor smaller numbers. There are a lot of (d+1)/d fractions: 4/3, 5/4, 6/5, 7/6, 9/8. It hugely favors these numbers. The top half of the octave is under represented. I do not know why this is so.
But Sethares’ algorithm, because it uses the critical band, tends to favor higher pitches as more consonant. However, since we search for minima rather than order the intervals by dissonance, this tendency’s effect on the results is reduced.
Both of these computations of dissonance seem to give meaningful data that does seem to have some kind of correlation to each other. On both lists we find, 6/5, 5/4, 4/3, etc. However, the length of the list of just ratios is arbitrary. If we take only the Sethares intervals that are in the top 5% most consonant (least dissonant) just intervals, we are left with:

 1/1, 29/28, 6/5, 5/4, 4/3, 15/11, 7/5, 10/7, 3/2, 8/5, 5/3, 12/7, 7/4,
2/1

Of those, 29/28 is the most dissonant, by both measures, so it may not be a the best scale degree. If that’s the case, then the top 5% is not the best cutoff. So what is? How do we choose it?
On the other hand, one way that just intonation is corralled is through factorization limits. For example, 7-limit tuning means that all the numbers in the ratios must be multiples of numbers that are less than 7. So 14 is ok (7 * 2), but 11 and 13 are not, as they’re prime and greater than 7. If we were to apply a 7-limit to the Sethares curve, the scale we would have is

1/1, 6/5, 5/4, 4/3, 7/5, 10/7, 3/2, 8/5, 5/3, 27/16, 12/7, 7/4, 2/1

Is that better? Does the 27/16 (aka: (3*3*3)/(4*4)) impact that?
Alas, we can’t use our ears because we don’t know what moment of the source was measured. But we can use our ears with a synthetic sound whose frequency content is known.

f = [50] ++ ( [50/27, 18/7, 54/25, 25/27, 9/7, 27/25, 25/54, 9/14, 27/50] * 300);
a = [0.055, 0.1, 0.1, 0.1, 0.105, 0.105, 0.105, 0.11, 0.11, 0.11];
e = DissonanceCurve.new(f, a, 2);

With some print statements, abbreviated for the sake of not being too boring, we get a Sethares scale of 1, 7/6, 25/21, 25/18, 36/25, 42/25, 12/7, 2, which, note, falls within a 7-limit. For the top 8 just results, we get, 1, 3/2, 6/5, 5/4, 7/5, 5/3, 34/27, 10/9. A list which does not include 2! And if we do the top 5% thing described above, we get, 1, 7/6, 25/21, 25/18, 36/25, 2. And we can compare these aurally:

(
 SynthDef("space", {|out = 0, freq = 440, amp 0.2, dur = 1, pan = 0|
  var cluster, env, panner;
 
  // detune
  freq = freq + 2.0.rand2;
 
  cluster = 
  SinOsc.ar(50, 1.0.rand, 0.055 * amp) + 
  SinOsc.ar((freq * 50/27) + 1.0.rand2, 1.0.rand, 0.1 * amp) + 
  SinOsc.ar((freq * 18/7) + 1.0.rand2, 1.0.rand, 0.1 * amp) + 
  SinOsc.ar((freq * 54/25) + 1.0.rand2, 1.0.rand, 0.1 * amp) + 
  SinOsc.ar((freq * 25/27) + 1.0.rand2, 1.0.rand, 0.105 * amp) + 
  SinOsc.ar((freq * 9/7) + 1.0.rand2, 1.0.rand, 0.105 * amp) + 
  SinOsc.ar((freq * 27/25) + 1.0.rand2, 1.0.rand, 0.105 * amp) + 
  SinOsc.ar((freq * 25/54) + 1.0.rand2, 1.0.rand, 0.11 * amp) + 
  SinOsc.ar((freq * 9/14) + 1.0.rand2, 1.0.rand, 0.11 * amp) + 
  SinOsc.ar((freq * 27/50) + 1.0.rand2, 1.0.rand, amp * 0.11);
 
  env = EnvGen.kr(Env.perc(0.05, dur + 1.0.rand, 1, -4), doneAction: 2);
  panner = Pan2.ar(cluster, pan, env);
  Out.ar(out, panner);
 }).send(s);
)
(
   Pbind(
  //Sethares
    freq,  Prand([1, 7/6, 25/21, 25/18, 36/25, 42/25, 12/7, 2] *300, 27),
    dur,  0.3,
    instrument,  space,
    amp,  0.2,
    pan,  0
   ).play   
)
(
   Pbind(
  // Just
    freq,  Prand([1, 3/2, 6/5, 5/4, 7/5, 5/3, 34/27, 10/9] *300, 27),
    dur,  0.3,
    instrument,  space,
    amp,  0.2,
    pan,  0
   ).play   
)

(
   Pbind(
  // Top 5%
    freq,  Prand([1, 7/6, 25/21, 25/18, 36/25, 2] *300, 27),
    dur,  0.3,
    instrument,  space,
    amp,  0.2,
    pan,  0
   ).play   
)

Which of those pbinds do you think sounds best? Leave a comment.

Questions about Differing Approaches to Tuning

Let’s start by all admitting that Equal Temperament is a compromise and that computers can do better. They’re fast at math and nothing physical needs to move, so we can can do better and be more in tune. (The next admission is that I haven’t had the attention span to actually read all the way through the Just Intonation Primer, although it is a very informative book and everyone should buy a copy and actually read it. Nor have a I read Tuning Timbre Spectrum Scale, alas.)
When we say “in tune,” what does that actually mean? On the one hand, we are talking about beating. You know that when you’re trying to tune two sound-generating objects playing the same note, there’s weird phasing and stuff that happens until you get it right. The beating sound you get when tuning a guitar. There’s also just a sort of roughness you hear when you play two notes that are really close to each other, like a C and a C# together. Both of these things seem to have something to do with being in tune and both suggest possible approaches.
Just Intonation, seem to be all about beating and zero crossings. Note relationships described with ratios in which the numerator and denominator are small, whole numbers have less beating. This is because when the waveforms cross, it’s at the low energy position, so they don’t interfere. 3/2 is thus very in tune. You can compute the amount of dissonance by adding the numerator to the denominator. Lower numbers are more in tune.
Bill Sethares, though, likes ten tone equal temperament (and writing songs in Klingon) and came up with some timbres that sound good in such a strange tuning. He’s got some math about dissonance curves. The roughness mentioned above has to do with how our ears work and critical bandwidth. If we hear two tones that are close to each other in pitch, the ear hairs they stimulate overlap, so the interfere with each other and create roughness. We can take a timbre and see how much internal roughness it has and then transpose it a bit and measure the roughness of the original and the transposed version played at the same time. Do this a bunch of times and you get a curve. The minima on the curve are good scale degrees.
Both of these approaches are perceptual and both seem to be in conflict. They both seem to use different parts of our perception, one more around critical band and the other more around amplitude and phase. So I wonder how to get them to work together? I can compute a dissonance curve that goes from 1 -1200 cents, but if I do it from a FFT’s spectrogram, the data I’m putting in is inexact. It only knows 512 frequencies, each of them slightly blurred and I’m using it with 1200 transpositions. Also, the transpositions are appropriately logarithmic, but the bins of the FFT are not, they’re linear. Should I do a similarly linear comparison and save myself a lot of unnecessary computation or does it make sense to do it by cents? Since I know there are artifacts in the spectrogram, should I find the minima and then search for “good” tuning ratios near them? Should the internal dissonance in the sample change the approach that I use?
I ported Sethares’ code to SuperCollider. You can download a working draft of DissonanceCurve.sc, if you desire. It’s quite math intensive for FFTs, but I have a synthDef made up of SinOsc, which is easy to analyze, since all the frequencies and amplitudes are known and there aren’t many of them. The freqs are in f and the amps are in a:

f = [50] ++ ( [50/27, 18/7, 54/25, 25/27, 9/7, 27/25, 25/54, 9/14, 27/50] * 300);
a = [0.055, 0.1, 0.1, 0.1, 0.105, 0.105, 0.105, 0.11, 0.11, 0.11];

e = DissonanceCurve.new(f, a, 2);
e.scale.do({ |deg|
  
 postf("Interval % - Dissonance %tRatio % / % n",
  deg.interval, deg.dissonance, deg.numerator, deg.denominator);
});

Which prints

Interval 1 - Dissonance 0.93194694734913 Ratio 1 / 1 
Interval 1.1667536657322 - Dissonance 1.1967977845161 Ratio 7 / 6 
Interval 1.1905817347928 - Dissonance 1.1395899373121 Ratio 25 / 21 
Interval 1.3883134504798 - Dissonance 0.92933737113208 Ratio 118 / 85 
Interval 1.4405968618317 - Dissonance 0.95473900132736 Ratio 85 / 59 
Interval 1.6798510690642 - Dissonance 0.79165734602377 Ratio 42 / 25 
Interval 1.7141578884562 - Dissonance 0.80288033573481 Ratio 12 / 7 
Interval 2 - Dissonance 0.49046268655094 Ratio 2 / 1 

118 / 85 is not a ratio of small, whole numbers, but it’s apparently less dissonant than 7 / 6 or even 85/59 or even the internal dissonance of the source sound! But, if we look in the curve, we can find the ratios 1 cent distant on either side of 118 / 85:

Interval 1.3875117607442 - Dissonance 0.9386025721761 Ratio 111 / 80 
Interval 1.3883134504798 - Dissonance 0.929337371132 Ratio 118 / 85 
Interval 1.3891156034233 - Dissonance 0.92966297781753 Ratio 25 / 18 

25 / 18 is a much smaller ratio and a distance of 1 cent is not perceivable, so it’s probably a better number. But I am still slightly confused / unconvinced. Note also, that sounds closer to 2/1 are all, in general, less dissonant that sounds closer to 1/1, because of the nature of the algorithm / critical bandwidth. But for just intonation, an inversion is barely more or less dissonant than it’s non-inverted form.
Also, an issue: the width of the critical band changes in different frequency ranges and I think it might help to use the Bark scale or something in the Dissonance Curve code, but the math is, as yet, a bit beyond me.
For the purposes of showing off, here’s a silly example with FFTs, which is not at all real time:(WARNING: THIS IS SLOW!)

 b = Buffer.alloc(s,1024); // use global buffers for plotting the data
 c = BufferTool.open(s, "sounds/a11wlk01.wav"); 
 d = { FFT(b, PlayBuf.ar(1, c.bufnum, BufRateScale.kr(c.bufnum))); 0.0 }.play;

// when that's playing, evaluate the following

 e = DissonanceCurve.newFromFFT(b, 1024, highInterval: 2, action: {arg dis;
 
  dis.scale.do({ |deg|
  
   postf("Interval % - Dissonance %tRatio % / % n",
    deg.interval, deg.dissonance, deg.numerator, deg.denominator);
  });
 });

Go and get a snack while that’s going. Make a cup of tea. You won’t be able to do anything else with SuperCollider until it finishes, so leave some comments about tuning. How should I be trying to combine dissonances curves and Just Intonation?
(My result for the code above (timing matters) was:

Interval 1 - Dissonance 2.4284846123288 Ratio 1 / 1 
Interval 1.0346671040459 - Dissonance 2.9055490440413 Ratio 30 / 29 
Interval 1.0557976305092 - Dissonance 2.9396229209406 Ratio 19 / 18 
Interval 1.0588513011885 - Dissonance 2.9394283497832 Ratio 18 / 17 
Interval 1.0625273666152 - Dissonance 2.9404120579786 Ratio 17 / 16 
Interval 1.0767375682475 - Dissonance 2.9248076874065 Ratio 14 / 13 
Interval 1.1114938763335 - Dissonance 2.8528563216285 Ratio 10 / 9 
Interval 1.1250584846888 - Dissonance 2.8384180012931 Ratio 9 / 8 
Interval 1.1302693892732 - Dissonance 2.8422250578475 Ratio 26 / 23 
Interval 1.1335384537169 - Dissonance 2.8404168678269 Ratio 17 / 15 
Interval 1.1667536657322 - Dissonance 2.773742908553 Ratio 7 / 6 
Interval 1.2002486666653 - Dissonance 2.6741210623142 Ratio 6 / 5 
Interval 1.2497735102289 - Dissonance 2.5747254321313 Ratio 5 / 4 
Interval 1.2628354511916 - Dissonance 2.5907859768328 Ratio 24 / 19 
Interval 1.2664879348481 - Dissonance 2.5910058160679 Ratio 19 / 15 
Interval 1.2856518332381 - Dissonance 2.5784271202225 Ratio 9 / 7 
Interval 1.3332986770912 - Dissonance 2.4554262314412 Ratio 4 / 3 
Interval 1.3503499461682 - Dissonance 2.4863589672953 Ratio 27 / 20 
Interval 1.3573881591926 - Dissonance 2.4874055968135 Ratio 19 / 14 
Interval 1.3755418181397 - Dissonance 2.469278592016 Ratio 11 / 8 
Interval 1.3811148862791 - Dissonance 2.4674194148261 Ratio 29 / 21 
Interval 1.3843096285337 - Dissonance 2.4676720796587 Ratio 18 / 13 
Interval 1.3891156034233 - Dissonance 2.4680185402198 Ratio 25 / 18 
Interval 1.4003945316219 - Dissonance 2.4587789993728 Ratio 7 / 5 
Interval 1.4289941397411 - Dissonance 2.432946313225 Ratio 10 / 7 
Interval 1.5000389892858 - Dissonance 2.2587031579717 Ratio 3 / 2 
Interval 1.5262592089606 - Dissonance 2.3003029027958 Ratio 29 / 19 
Interval 1.529789693524 - Dissonance 2.299895874529 Ratio 26 / 17 
Interval 1.5333283446696 - Dissonance 2.2993307022943 Ratio 23 / 15 
Interval 1.555631119012 - Dissonance 2.2871143779032 Ratio 14 / 9 
Interval 1.5619338268699 - Dissonance 2.2878440907054 Ratio 25 / 16 
Interval 1.6002899594453 - Dissonance 2.2385589006945 Ratio 8 / 5 
Interval 1.6114208563635 - Dissonance 2.2381572659306 Ratio 29 / 18 
Interval 1.6188844330948 - Dissonance 2.236239217168 Ratio 34 / 21 
Interval 1.625443414535 - Dissonance 2.2331690259349 Ratio 13 / 8 
Interval 1.6663213678518 - Dissonance 2.1624083601251 Ratio 5 / 3 
Interval 1.68763159226 - Dissonance 2.1765673941027 Ratio 27 / 16 
Interval 1.7141578884562 - Dissonance 2.1648475763908 Ratio 12 / 7 
Interval 1.7501759894904 - Dissonance 2.1359651045669 Ratio 7 / 4 
Interval 1.8004197968362 - Dissonance 2.0659411117752 Ratio 9 / 5 
Interval 1.8340080864093 - Dissonance 2.0362153732133 Ratio 11 / 6 
Interval 2 - Dissonance 1.6432830079835 Ratio 2 / 1 

Yikes)

Quick JJiCalc Tutorial

Launching JJiCalc

After you download the software to your computer, you can run it by
double-clicking on JJiCalc.jar. Or, if you have a command prompt,
you can type “java -jar JJiCalc.jar” .

Opening Files

Once the software is launched, click on the file menu and select open.
A dialog box will come up listing files and directories on your computer.
This box may look different from ones that you are used to. On OS X, the
box will list files in the root directory. If you want to get to your
home directory, click on the Users folder, then on your directory name.
Go to the directory where you put the software. In the JJiCalc folder,
there is a folder called tuning. Go there and open the file called
old_grandad.jic
Eight tuning ratios will appear in the top of the tuning table. The
title “Old Grandad” will appear in the title bar. (If you want to change
the name, just type in the title field.) On the top right hand side
of the application window are some buttons. One of them is called
“Comments.” If you click on comments, you can view the comments made about
the scale.

Lattice

Click the button marked “Lattice” to see the tuning lattice for the scale.
A new window will pop up, which shows ratios connected by lines. If you
want to hear a tuning ratio, you can click on it in the lattice. Click
on 3/2. The box around the ratio will turn gray and you should hear the
sound of the ratio being played. If you don’t hear anything and you’ve made
sure that sounds are working on your computer, you may need to update
your Java libraries, especially Swing.
If you click again on the ratio, it will stop playing. You can play
any number of ratios at the same time as you would like. Click on 3/2,
5/4 and 1/1.

Pop-up Menus

You can also play ratios directly from the tuning table. If you have a
multi-button mouse, right click on the numerator or denominator of one of
the ratios. If you are on a macintosh with a single-button mouse, option
click on the numerator or denominator. A pop-up menu will appear with
the options “Enable Sound”, “Freeze this Cell”, and “Clear this Cell”. To
hear the ratio, select “Enable Sound.” To stop hearing the ratio, right
or control click again and select “Disable Sound.”
Frozen cells can’t be played. Also, they can’t be cleared and will not
be sorted. To freeze a cell, right or control click on the cell for the
pop-up menu. To defrost a cell, do the same thing again, but select
“Defrost this Cell”. To erase the contents of a cell and remove a ratio
from the table, select “Clear this Cell”.

Cents, Hertz, Fret Position

In the middle of the bottom of the application, there is a section of
buttons labelled “View As.” Click the one labelled “ET +-Cents”. This
will calculate the closest Equally Tempered pitches, plus or minus the
cents needed to get your tuning. In the gray boxes below each ratio,
you should see a postive or negative number indicating the cents to add
or subtract, with the closest ET pitch below that. The JJiCalc assumes
that 1/1 is C0, so therefore 5/4 is E0 -13.7 cents.
To calculate Hertz, click the button marked Hertz in the “View As”
section. 1/1 defaults to 440. If you would like to use a different
base frequency, on the bottom right is a section called “base frequency.”
Type in what frequency you would like in the text area marked “1/1 freq”.
Then, click the button “Update Base”. If you play the ratios, they will
sound at the new frequencies. The displayed Hertz will not change,
however, until you click the “Hertz” button again in the “View As” area.
If you click the button “fret pos”, it will calculate fret positions
for you. The top number is the integer part of the fret position and the
bottom number is the decimal section. Below 3/2, there is 0. in the top
box and 3333 in the bottom box. Thus, for a string 1 meter long,
the fret position for 3/2 would be at 0.3333 meters.
You can change the string length by typing it in the text area labelled
“Str. Len.” and then clicking the button labelled “string len”. This will
cause your fret positions to recompute. There is a known bug: The
recomputed numbers will be incorrect.
After you change the String
Length, click the “fret pos” button again to figure out the correct fret
positions.

Adding New Ratios

Go to an empty table cell and (left) click in the numerator box. type
15 and then in the denominator box, type 16. This adds a 15/16 minor
second. If you click the lattice button, you will see your new
fraction in the lattice.
The JJiCalc automatically reduces your fractions for you. In another empty
cell, enter in 32/30. As soon as you click off of the cell, it will
reduce to 16/15. There is an option under the Configuration menu to turn
this reduction off. This is a known bug: Your fractions will always
reduce.

The Configuration Menu

One thing that works in the configuration menu is changing the wave
form setting. You can hear your fractions played as sine waves,
square waves or sawtooth waves.

Sorting

all of our tunings are in scale order except for the new one, 16/15.
On the right is a button marked “Sort”. Click it to but the ratios
in order from smallest to largest.
All of the things in the gray boxes below the ratios will clear when
you hit sort.

Saving

When you save your file, all of the data including the 1/1 frequency,
the title, the comments, the ratios and the stuff written in the gray
boxes below the ratios all get saved. Saving a tuning gives you the same
kind of dialog box you got when you openned old_grandad.jic. If you
type in the name of a file that already exists, a box will appear to
ask if you’re sure you want to overwrite the old file.

Other Formats

If you don’t want to save anyhting but the title, the comments and the
ratios (but not the stuff in the gray boxes), go to the File menu, then
look in the Export submenu and select “Ratios only.”
JJiCalc also supports the Scala file format. To save your tuning as a
Scala file, select “Scala File” under the Export menu. There is a very
large set of tunings in the Scala format that you can download from http://www.xs4all.nl/~huygensf/doc/scales.zip. To open
these tunings, select “Scala File” from the import menu. Not all Scala
tunings are Just Intoned. If the Scala tuning that you open contains
some non-just tunings, JJiCalc will approximate them as fractions.

Lovely Day

Not only was it a Wednesday, a relatively happy day during the week, since I don’t have too many stressful classes, but the weather was so nice that it felt like home. I could walk around with only a shirt and light swearer and feel nice.

I gave my presentation about tuning during class today. It was a bit of a disaster. Aaron said it was ok and that people were just scared of math, but I think maybe he was just being nice. Nobody knows what it means to be out of tune. I said, “out of tune notes beat. Beating is out of tune. the paino beats, so therefore it is out of tune.” I didn’t help that I was showing them a Pythagorean Tuning Lattice. That lattice has really nice fifths, fourths and octaves and horrible thirds, so it’s very very similar to Equal Temperment. I was on the way to talking about 5 limit intonation (which has wonderful thirds), when I played an example of the 7th and said, “that’s a terrible 7th.” and then I said something about how it didn’t matter that thirds were terrible because they weren’t considered consonant. And then the ethno types wanted to argue with me about consonance and dissonance. The ancient greeks thought it was consonant!! No, only string players would have used this tuning because it’s horribly out of tune. No, it’s in tune according to what they thought. Tuning is culturally constructed!
tuning is based on the overtone series. It is not socially constructed because it is centered around a physical fact. some notes are out of tune. the piano is out of tune and you’re wrong, because not everything is culturally constructed.
uh yeah

the to-do list of doom

old items

  • pedagogy things is done, now i need to write a syllabus for an intro to harmony class, due in 2 weeks
  • i now owe six instrument definitions, and i’ve done none of them.
  • still the world’s most clueless TA. I think we might be doing a realization of I am Sitting in a Room
  • I’m on the ITS comittee of the OtherMinds Board now. they didn’t ask me to run for secretary. (If you are a potential donor and want to go to a party wihtout me, let me know, and I’ll get you onto the list)
  • listened to Krystalnacht by John Zorn. Too many issues on top of the piece to say much about it, really. If you try to look at it abstractly and not as a programatic work, some of the tracks do not stand up on their own. the second track could never have been written about a non-programatic topic.
  • so, this morning, i thought i should put the JJICalc on Aaron’s computer before I left for school, to see if it would be loud enough. the program wouldn’t run. I ran out the door and charged off to school. got to the bike rack and realized that I left my keys sitting on my porch railing. Went back for my keys. Went back to school, now late for class and printed my handouts. Walked late into class. at the break went to try to find a key to the room where the Mac Truck is kept, so I could grab a laptop from it. the secretaries say that it’s very strictly against the rules and this is exactly why the mac truck is kept locked (and why grad students don’t get keys). then they let me have one anyway and it runs JJICalc just fine. The problem is that I compiled the calc on a new version of java and some macs are running older version of java and apparently there’s no backwards compatibility. I need to compile the program on an old machine so that it can run on other old machines. Write once, compile everywhere.
  • Haven’t touched OSC, but my perl script can get themes off of moo objects
  • emailed music prof about Joan of Arc mystery play. this prof doesn’t send prompt replies, so i may have to drop the research.
  • I’m going to analyze Turtle Dreams by Meredith Monk for my composition seminar. I don’t know if a score exists. Neely seems to think that a score is unnecessary.
  • The five minute piece is for piano. It’s started. Only god knows when it’s due.
  • none of the other composers know what’s going on either

new things

  • Must read inch-thick handout about Stravinsky by next wednesday
  • Aaron has organized a house concert where all the composition students will present five minutes worth of stuff. I must figure out what to do, as it is this saturday, I don’t think I can make people learn my SolReSol duet
  • Must return overdue library books and enquire as to the status of the books that i requested via inter-library loan
  • Must find and speak with a bell maker, but first, must find out how to find and speak with a bell maker.

Talking about Tuning

I’m scheduled to teach “anything” to my seminar on Wednesday. I though I should tackle tuning. This talk is just written and the sound samples and diagrams have not yet been generated.

what is Just Intonation?

Lou Harrison said that “Just Intonation is the best intonation.” An intonation is a type of tuning. Just tuning is a tuning that uses fractions. In just intonation, pitches are set using whole number ratios. To understand this, let’s look at the harmonic series.

Harmonic Series

The fundamental is the base frequency. (sound sample)
The first overtone is twice the base frequency. It’s relationship to the base frequency is 2/1. In other words, the base frequency * 2 = the first overtone. this makes a perfect (or just) octave. (sound sample)
The second overtone is 3 times the base frequency. It makes an octave plus a fifth. this fifth is perfectly in tune with the base frequency and the first overtone. (sound sample) but is an octave too high to use in a scale between those two notes. We can divide it by 2 to make it an octave lower. this new pitch, the fifth between the base frequency and the octave, is related to the base frequency by a ratio of 3/2. (sound sample) The three comes from it’s place in the harmonic series. The two comes from dividing it down to be in the first octave.

2’s and octaves

All notes in the first octave, will be between the ratios of the base frequency, which is 1/1 and the octave, which is 2/1. If something is too small, it is below 1/1, and if it’s too large it’s over 2/1. We can transpose it to the correct octave by multiplying or dividing by 2.

Therefore 2’s are very important for transposition, but they don’t change a pitch, except by octave. If the base frequency is C and we multiply it by 3, we get a G. If we multiply it by 3/2s, we also get a G, but in the first octave. so 2’s are “for free” you can multiply and divide by them any time you need to change the octave and you will still have the same note as before, just an octave higher or lower.

Inversion

the inversion of a fifth is a fourth. So we can invert the fifth fraction to get a fourth. the inversion of 3/2 is 2/3. But 2/3 is too small. It is not between 1/1 and 2/1. We can multiply it by 2, to get 4/3, a perfect just fourth. (sound sample)

You can do this with any tuning fraction. Invert it to find the inversion, then multiply or divide it by 2 to put it in the correct octave.

Pythagoras

3/2, the perfect, just fifth is a ratio made up of small, whole numbers. Small numbers sound more in tune because they are lower in the harmonic series. 3/2 is the most in-tune sounding note that you can get aside from the perfect octave.

There’s a story that pythagoras was walking by blacksmith shop and heard very harmonius sounds. After experimenting with the smiths, he discovered two excellent intervals, 3/2 and 9/8.

9/8 is a major second and since it still has small numbers, it sounds really good. (sound sample)

From this, he hypothesized that good rations were made up of powers of 3 over powers of 2 and their inversions. You know that the circle of fifths will eventually take you through all 11 notes in an octave. According to pythagoras, you can use this to tune all the notes. First, turn the first two strings as a perfect 3/2 fifth. Then tune from the 3/2 to the next fifth, a 9/8. then tune from the 9/8 to the next fifth, the 27/16. Notice that everyone of these ratios is a power of 3 over a power of 2.

Lattices

You can create a chart of these (pass out handout) called a tuning lattice. a lattice of powers of 3 over powers of 2 is called a Pythagorean tuning lattice. The line on your handouts at the top is a pythagorean tuning lattice. Below that, is chart of them in oder of the notes in the scale. Notice that E, the third is not a small number ratio. It is 81/64. This was considered ok at the time because thirds weren’t considered consonant. Notice also, that the octaves don’t line up. The octave, instead of being 2/1 is 243/128.

this is a sound sample of the tuning lattice going around the circle of fifths. (sound sample). This is a sound sample of it climbing the scale diatonically and then chromatically (sound sample). And this sound sample shows the difference between 243/128 and a 2/1 octave.

N-limit tuning

That last example demonstrates why mixing in other numbers than just three is a good idea. People often use 5’s, 7’s and sometimes higher prime numbers like 11’s. Your tuning system draws it’s name from the largest prime number that you use. A tuning that used 2’s and 3’s is a 3-limit tuning. One that uses 2’3, 3’s and 5’s is a 5-limit tuning.

(if I have time)

5-limit tuning

(Draw on blackboard) this is a tuning lattice of 5’s. This note 5/4 is a just third. The ratio has much smaller numbers than the pythagorean third. This is the pythagorean third (sound sample). This is the 5-limit third (sound sample). there’s almost a quarter-tone difference between them (sound sample).

N-limit lattices

When you are drawing lattices, every new prime number gets a new axis. so a tuning lattice could be thought of as an N-dimensional array, where N is the number of prime numbers. this one, with 5’s and 3’s is a two dimensional array. If we added 7’s, we’d need a new axis and we’d have a three dimensional array.

We can add notes to our lattice that are multiples of 5’s and 3’s. (draw on blackboard) All of these notes are the note right below it multiplied by 3/2s. Remember before, that multiplying fractions was raising them. Like 3/2 * 3/2 makes a note a fifth above. So because all of these notes are multiplies by 3/2s, they are all a fifth higher than the notes below them.

this is useful for two reasons. One is that 6/5 is the smallest numbers ratio we’ve yet seen for d#, the minor third. (sound sample). So adding lines like this helps us find extra ratios. the other thing that it’s good for is transposing. All of these notes are the same as the ones right below it, but raised by a fifth. So you might use this when you modulate to a new key.

Uses of Lattices

composers use lattices like these to figure out what tunings they want to use in their piece and then manipulate them for key changes and transpositions. they then use this to give instructions to instrumentalists or to program them into synthesizers.

One composer that uses tuning lattices to figure out how to tune her instrument is Ellen Fullman. She uses larger prime numbers to tune the many strings of her Long String Instrument. This track is based on a sweep of the harmonics of a C chord. (sound sample)

Pythagorean tuning lattices

Pythagoras really liked threes. A lot. You probably remember this from school. What they don’t tell you in grammer school is that the tuning ratio 3/2 is a perfect fifth. Pythagoras is creditted with discovering that. The story goes that he walked into a shop where metal smithing was going on and the smithing was very consonant and melodic sounding. He ordered the smiths to switch hammers and pieces of metal. In his experiments, he discovered that the tuning was not in the arms of the smiths or in the hammers, but in the strips of metal they were hitting. Somehow, he got from this discovery to 3/2, which is obviously completely perfect because it has a three in it and three is the most perfect of all numbers. Pythagoras really liked threes
Alas, it was downhill from there. You may recall the circle of fiths. It leads around to every note in the scale and is a nifty trick for remembering sharps and flats. So, theoretically, if you really liked fifths, you could tune every fifth from the fifth below it. The fraction for note N = 3/2 * (N-1). So the first note is 1/1. The second is 3/2. the third is 9/8. The fourth is 27/16. The fifth is 81/64. Every note is 3^^x/2^^y. This tuning was invented by Pythagoras and the list of notes you get from it it called a Pythagorean Tuning Lattice.
Not really a very good tuning system, but one used for hundreds of years. Anyway, Kyle Gann wrote a paper on tuning for beginners: http://home.earthlink.net/~kgann/tuning.html. In it, he says, “Equal temperament could be described as the musical equivalent to eating a lot of red meat and processed sugars and watching violent action films.” I knew it!

Musically Inclined

Well, yesterday was mother’s day, a day I had been actively dreading since October. It wasn’t actually that bad. I guess I worked it all out in the pre-dread. Unlike my birthday, where I didn’t expect to feel miserable around at all, and yet I did. It was horrible, despite cool people and cool events. Anyway, the next date on the dread calendar is June 21st, when my mom would turn 66, but will not. Christi is playing that night at the Chapel of the chimes concert. Yes, the one you’ve heard of. Yes, the huge, big deal. Yes, it’s in a mausoleum. I’m estatic for Christi, but still full of dread.
Perhaps keeping busy is what made Mother’s Day ok. I had band practice for about five hours with Tennis Roberts. Our songs are now ending ok. Chand has taken to mixing his electronic drum sounds (he plays an electronic kit) with a vocoder to other source sounds. It sounds very industrial and awesome with pink noise. With other source files, I’m not so sure about it. We’re a sort of a tonal band and it’s hard to play along with a tape where you don’t know the tones, especially if the tones are from a random sample and hold thing, so they’re not in any particular temperment. Which would be the tones on the mp3s that I made that Chand is using. Anyway, it doesn’t matter that much, since I don’t play in any particular temperment anyway. The open notes are in tune, but the rest is not.
I’m sort of getting into tuning right now. Ellen Fullman has a piece called “Harmonic Cross Sweep” on her album Change of Direction. The piece blows my mind. Go listen to the mp3. It’s just intoned microtonal coolness. So I started reading Harry Partch, since he wrote about Just Intonation and influenced everyone just intoned these days. But he can’t stop ranting. In his book Genesis of a Music, he complains about how cello players are so anal they won’t even let you take an awl to their finger board. It takes him a long time to explain the tuning thing, so I joined the Just Intonation Network and I’m reading their primer text on tunings. It’s a much easier read than Partch and is very informative. But really, the biggest influence on my thoughts about tuning was Kendon.
The last time I played bass guitar in a band before this one, it was called Trap Door Spirder Woman or the Kraft Ebbings or somehting. We never played outside of Kendon’s basement, except to play in my basement. Kendon had this guitar where the nech was cracked. It was nearly broken in two. He was always tuning it in between ever song. I kind of got into the sound of him tuning. It was very cool. It should have been a song. And he always had to tune because after the first three chords, everything was different, since the guitar neck wasn’t rigid. The situation made Kendon unhappy. He was saving up for a new guitar. But it was awesome. It was so completely out of tune screwed up bad that it was great. Really, equal temperment is all out of tune. This broken guitar was just the next step on a broken tuning. But it was beautifully broken.
So with Tennis Roberts, I started playing Tammy’s fretless bass with the thought that I could be out of tune all the time. I could put notes in between the notes. I could put four steps where three belong. I could be always completely, sharply off. It’s awesome.

Tuning (or Math Is Hard)

I’m readin Harry Partch’s Genesis of a Music to try to find out how this just intonation thing works. Briefly, Just intonation is “natural” tuning based on ratios. Think of a guitar string: if you divide it in half, you get an octave. If you divide it by three you get a fith (sort of). All tunings until recently were based on fractions. Then we switched to irrational numbers. So your piano is now tuned irrationally. (I always suspected as much.)
Harry Partch’s book is out of print. This is not actually shocking. The first section is a history of opera and vocal music from Plato through the early twentieth century, seen as a fight between those who think notes out to mirror words and those who think words ought to be bended or exaggerated to fit notes. There are definitely bits of wisdom in there, but my goodness, it’s not an easy read. He certainly has a liking for five dollar words. Why use a short word when a longer one will do? His thesis (whatever it is) becomes a victim of unintended irony. The notes ought to be working for the words, but with the words he uses, I think Webster’s dictionary is driving his writing. Or maybe he studied for the GREs much harder than I did.
Then comes the mathematical part. I foolishly thought I had some idea of just intonation because of a computer program I wrote around fifth or eigth grade. I had programmed the computer (in BASIC, of course) to play several Christmas Carols. But I thought it would be cool if I could program it (in BASIC) to write new songs and play them. This started very simply:
playsound(random(), 2); play a “random” pitch for two miliseconds. This is, incidentally, the sound played by the computer game Gauntlet when you exit a level. My brother was kind of excited. But it’s not really very musical, so I decided to generate arpegios.
An arpegio is a “broken chord.” It is all the notes of a particular chord played sequentially instead of all at once. An arpegio on C would play C, then E, then G, (then maybe high C followed by G,) then E, then C. Do Mi Sol Mi Do. My program picked a pitch in the scales that we’re used to (A= 440 Hz) and generated an arpegio on top of it using fractions. Let $N be the starting pitch.
$sol = $N * 3 / 2; This is easy to deduce because of the overtone series on a brass instrument. (I’m ignoring transposition here.) The pedal tone on a trumpet is C. The low open note on a trumpet is C, one octave higher. The next open note is G. A pedal tone is a note that isn’t usually played as it’s too low and hard to produce. The wavelength of a pedaltone is equal to the length of the horn. The low open note, one octave higher, has a wavelength equal to half the length of the horn. The next open note is one third of the length of the horn. The next note, another octave of C, is equal to one quarter the length of the horn. All open notes on a trumpet or baritone or tuba or whatever have a whole number relationship to the length of the horn.
The frequncies are related by the same whole note ratio, but inversely. The first open note (above the pedal tone) uses half the horn and is double the frequency (in Hz). The next open note uses one third of the horn and is triple the frequency of the pedal tone. So it you had a brass horn where the pedal tone was A (220 Hz), the first open tone would be 440 hz (the note A) and the next open tone would be 660 Hz (the note E). Ok, now, see how A is both 220 and 440? It’s also 110 and 880. Every octave is a doubling of frequency. If you want to find a pitch one octave higher, then you multiply by 2. If you want the octave lower, you divide by two. This sounds right. If your piano is perefctly in tune, every A on it will be double the frequency of the A below and half the frequency of the A above. If you could see the sine waves, they would line up exactly and be perfectly in tune with each other.
Ok, back to my arpegio program from my youth. The fifth note in the major scale, Sol, is the second open note on my trumpet and the frequency is equal to three times the pedal tone. So if you take the first note of your arpegio and mutiply the Hz by three, you get a fifth, but it’s one octave too high. Ah, but we can lower it one octave by dividing the frequency in half. So
$sol = $n * 3 / 2; Yay!
I also figured out the third and was able to play arpegios with wild abandon. I’d pick some pitch from an array that contained the Hz for one octave to the Equally Tempered Scale, generate an arpegio on top of it, then pick another pitch from the same array and then play an arpegio on top of it, then pick . . .. I really liked infinite loops. My favorite command in BASIC was “goto.”
And so, with great anticipation, I started up my program and the first arpegio sounded great, but the on the next one, the first note sounded . . . off. And on the next one, the first note sounded terrible! What was going on?
Luckily for me, my father had designed an electronic organ only a few years earlier. (He wasn’t great for camping trips, but man, he was 100% there for technology explainations, even if he couldn’t quite manage to disuade me from my goto obessision, he was great for helping me debug stuff.) The problem? Mixing tuning systems! things that sound “right” in fractional, just intoned systems, sound really really right. But it has some problems. Everything is tuned perfectly to the starting pitch. But if you switch keys, without retuning, everything sounds off. All the distances are perfect from C for the notes in the C scale, for example, but the fractions are off from what they ought to be if you start playing in D. Take my word for this, I don’t have a soundfile to illustrate it, nor the math to work it all out here. But this a problem in tuning, for every tuning, is that the tuning can only be perfect in one key at a time.
this was “solved” with equal temperment. everything in equal temperment is equally out of tune. Tuning is based on irrational numbers instead of re-tweaked fractions. All the octaves in equal temperment are perfect. Everything else is off. If you have pitch N, to figure out the pictch one semitone above N (remember that there are twelve “semitones”, or “half steps” or distinct piches in every octave),
N[m+1] = N[m] * (1 + N[m] *2^^(1/12)); or, more generally, N[m+x] = N[m] * (1 + N[m] *2^^(x/12)); Got that? It’s irrational. It’s logarythmic. All the thirds sound kind of wrong. It’s lead to all sort of dissonance and twelve-tone systems and post-diatonic harmony and hell, post-tuned music like noise. Or maybe all the debauchery would have happned anyway. But you can see how fractions are a LOT easier to think about.
which brings us back to Harry Partch, whom I am reading to better understand tuning, so I can do perfectly just intoned, tuned works for computer. Because the computer can re-tune instantly, should a key change be required. Also, there’s no reason why the octave need have twelve tones in it. It could have thirteen, or twenty, or five. And with a perfect understand of these fractional systems, I could write even more music-producing computer programs, but not in BASIC and with fewer GOTO staements (you can see that this has been a work-in-progress for a long time.)
So you’d think, with my (admittedly, minimal) experience with just intonation, I would be able to get something out of this book. This is what it says:

In the ratio 3/2, 2 represents 1/1, the lower limit of the 2/1. the tone at the upper limit of the 2/1 may be represented by 4 (a doubling of 2); hence the interval from the 3 of 3/2 to this upper limit of the 2/1 is the interval from 3 to 4, or 4/3, which is therefor the complement of 3/2 within the 2/1; the two intervals might be expressed thus: 2:3:4. . ..

ummmmmm  yeah  ummmmm  I have no idea what that says. Not even a little clue. It cuold all be in German, for what I can understand of it (disturbingly, I have forgotten all of my German…). Maybe I should stick to equal temperment. Or to noise.