March 2017 update: browsers are gradually removing support for Java
applets. This is because Java is a big security risk, like Flash.
Right now, I don't see what alternative technology one could use to
have something like the Java Tuner run inside a browser. Java itself
however is not going away anytime soon as far as I know, so there is
always the possibility of running the Java Tuner applet outside the
This is explained in the technical notes below.
2011 - New URL: http://leware.net/temper/sa/accord.htm (please update your bookmarks).
This Java applet demonstrates various historical tunings and
temperaments and allows one to experiment with them.
It was developed to accompany a text on
Understanding temperaments, and is
complemented by a set of MIDI files
demonstrating various tunings and temperaments.
Java is what made it worthwhile to develop this applet.
A new version,
based on the JavaSound API in JDK 1.3, is now (Feb 2002) available.
Works on recent browsers (eg. NN 6.x with Java 1.4).
Also now available,
same applet with more (custom) temperaments.
This current version (here) uses the sun.audio.* Java classes.
Maybe it won't load (needs
above classes); maybe the sound will be choppy; maybe it will
be off pitch (e.g. NeXT has a rate of 8013 instead of 8000,
about 3 cents sharp);
and it might be a bit slow.
A list of environments on which it works well is given below.
Comments welcome: (some questions).
Last updates: june 2000 (MIDI input), april 2000 (various enhancements).
Dec 2001: tuning (up/down arrow) now
done on note pointed at, not main selection: better for tuning
practice! Apr 2003: "minor" piece is in relative key, addition of "true pitch" to JavaSound version.
If you wish to support this work, you can make a donation via PayPal.
||meta or alt
||adjust note at cursor|
± 1 cent; shift: ± 5 cents
|adjust overall pitch|
± 1 cent; shift: ± 5 cents
||move selected note(s)|
± 5ths; shift: ± chromatic
± 5ths; shift: ± chromatic
|Click on note to select; shift-click to build interval/chord
- To hear a given note, click on it (primary selection).
To hear an interval or chord,
add/remove up to four notes total (primary plus three secondary selections) by shift-clicking
(or middle/right mouse button -- secondary selections will be grey).
The right/left arrows can be used to move the selected note(s) around
the circle of fifths, e.g. C, G, D, ... (shift arrows will move chromatically:
C, C#, D, ...).
When playing more than
one note, the secondary selection(s) will always be above the primary
selected note; this may result in folding the whole chord down an octave to avoid aliasing
- To select a given temperament, click on the appropriate button in
the Tunings & temperaments list. One could even tune a harpsichord
using these (but be careful that your environment is generating accurate
frequencies! -- not responsible for broken strings).
The wolf interval (worst 5th) is systematically placed
between G# and Eb. The tuning can be rotated around the circle
with meta left/right arrows (note names now reflect enharmonic differences).
This allows to move the wolf around. A small marker, inside the circle, shows
the current rotation.
The tunings and temperaments proposed are:
(I still need to label the irregulars with I, II or III as appropriate)
- Pythagore: Tuning with eleven pure fifths. Major thirds are 22 cents sharp.
- Just intonation: Marpurg's Monochord 1 which Barbour presented as the model form of just intonation. Illustration at right shows the structure: straight lines are pure intervals.
- Salinas 1/3 comma: Regular, open temperament with eleven fifths tempered by 1/3 of a comma. Major thirds are 7 cents flat, minor thirds are pure.
- Aaron's mean tone 1/4 comma: Regular, open temperament with eleven fifths tempered by 1/4 of a comma. Major thirds are pure, minor thirds 5 cents flat.
- Silbermann 1/6 comma: Regular, open temperament with eleven fifths tempered by 1/6 of a comma. Major thirds are 7 cents sharp, minor thirds 11 cents flat.
- Kirnberger: Irregular, closed temperament. The four fifths from C to E are tempered enough (1/4 of a comma) to get a pure third. Then we have two pure fifths from E to F# and five from C down to Db (C#).
- Vallotti: Irregular, closed temperament. Six pure fifths from B to F (i.e. all fifths that include a note with accidental). The other fifths are tempered (twice as much as in equal temperament).
- Werckmeister: Irregular, closed temperament. Three tempered fifths from C to A, and one more between B and F#. All other fifths are pure.
- Equal: Fully regular, closed temperament. Twelve fifths flattened by two cents (1/11th of a comma). Major thirds are 14 cents sharp (but our ears are accustomed to it by now).
- You can also make your own temperament
(or even practice tuning)
on notes and using up/down arrow to adjust pitch (by a cent at
a time or, with shift, 5 cents --
before current V1.10, the main selection was adjusted).
This temperament can be rotated as above.
- The Frequencies table on the right gives,
for each note, the
deviation in cents (from the equal-tempered note)
within the tuning/temperament, and the frequency. Also shown,
between each note, the deviation of the corresponding fifth from pure.
The absolute value of the deviation in cents in this table is quite
arbitrary: it depends from which note one starts to lay out the tuning
or temperament (it is often C, hence C's deviation is often zero).
What is important and characteristic of the tuning or temperament are
the relative values. For example, in mean tone, C's deviation is 0 and
G's deviation is -3; this means that G is 3 cents lower relative to C
than it would be in equal temperament (a bit confusing, I know).
At the bottom of the table, in ()s, the mean deviation (mdc) and frequency
adjustments (fac) in cents -- relevant to pitch constraint/control.
- The table at bottom right, Selected intervals,
gives, for each secondary selection (shift-clicked),
the size in cents of the interval it makes with the primary
selection and, for 3rds, 4ths, 5ths and 6ths,
the deviation of that interval from pure.
It also checks whether other intervals are fairly close (within 8 cents right now)
to a simple-ratio
interval, and, if this is the case, shows the deviation from it.
This check is also done if a supposedly consonant
interval is a wolf (try rotating the major third around in mean tone).
This table might be a bit confusing, I agree (and I'm trying to improve it).
- The Sound buttons are used to select what sound the applet is to
generate. "Stop" means no sound, "play" means play the selected notes once
whenever anything changes, "repeat" means play and repeat indefinitely
the selected notes (changes will be taken into account).
- The Pitch buttons are used to constrain the pitch. "A-440"
constrains A to be at 440 Hz, and similarly for the next two
(note that A-415 is, more accurately, at 415.3 Hz,
and A-466 at 466.16); "selected"
constrains the pitch of the currently selected note;
"mean 440" adjusts the pitch so that notes are, on average, at the same
pitch as equal temperament (based on A at 440 Hz -- some temperaments tend to have lots
of -ve cents adjustments on the notes, resulting otherwise in somewhat
lower pitch). Similarly for "mean 415". The last button, "free", means that
the pitch is not constrained;
it can then be adjusted using the meta up/down arrows, including with shift
(this adjustment is normally done after setting the temperament).
The current pitch reference if any (first four choices) is highlighted
in the table at the right.
- The Special play buttons
allow to play short
pieces transposed to the selected note.
are the simple
major and minor
harmonic sequences (from my wife's organ) shown
at right (minor piece is in the relative key, a minor third down, and has
a tierce de Picardie at the end -- try both in C and in B, with an irregular temperament),
and the first few measures
from a medieval piece, on parole
(sounds good in Pythagore's tuning).
The pieces will always be played
in the pitch of C, while keeping all other characteristics of the selected key
in the tuning or temperament (i.e. relationship between the notes,
colors of the chords, &c.). There are two reasons for this:
The option MIDI plays the last MIDI file read in (see below).
The other option, milliwatt,
plays an 8-second, 1004 Hz, 0 dBm reference tone (the "milliwatt" tone, a sine wave)
which can be useful
to calibrate your audio path (from computer to whatever -- but be careful).
The last option, circle, plays fifths and major thirds around the
Note that all these options require a fair bit of computation
for the sample to be played which can take several seconds
(during which time one shouldn't change anything in the applet).
- The point of this feature is to demonstrate how the different keys in
the different tunings/temperaments sound; these differences are probably
easier to hear if the pitch is held constant. Another way to think about it
is that one is
staying in C and rotating the tuning in the other direction instead.
- Keeping the pitch constant avoids aliasing problems which are never very
far when using µ-law at 8 kHz as is currently the case. The JDK 1.3 version,
based on better audio support from Java,
offers the choice (true pitch or stay in C).
- Frequencies or cents can be directly entered into the applet:
(I realize it's not a fully functional text input field, but it's really for special cases -- might improve some day).
- Click on one of the cents or frequencies in the table on the right or on the word "milliwatt".
For notes, enter frequencies that are not more than a few semitones away
from the usual. For "milliwatt", anything higher than 4000 will result in aliasing problems (ie. you won't get the frequency entered).
For cents, enter the deviations from equal-tempered cents (typically ± a few 10s), not the cents from C.
- The current value (with greater precision than in table) appears in the bottom right. Modify it with backspace, signs, numbers and period.
- Hit ENTER (RETURN) for the applet to take it into consideration.
- Click anywhere else to cancel input.
- Keyboard functions:
- c saves the current temperament (eg. following adjustments by user) so it's available thru the "user" temperament button.
- w writes out frequencies of current temperatment/tuning to Java console (can be copied and saved in plain text files); r will read temperament/tuning (same format as w, i.e. 12 frequencies, one per line) from the Java console (note that some environments don't support input on the Java console).
- m reads MIDI file input.midi which can then be played with the special "MIDI" button. See notes on MIDI files.
- d will dump information on the current temperament/tuning onto the Java console.
- l to make the note/interval sound last 2 seconds instead of default 1 second.
- 0 to 9 specify the harmonic content: 0 is pure sine waves, 9 is greatest harmonic content (limited to 5th harmonic at present).
- - (minus) to play everything an octave lower (in my environment, makes differences more audible), + (plus) to return to an octave higher (note that playing at higher octaves than original pitch will lead you into aliasing problems and is not recommended -- except as demo of aliasing problems).
- ~ (tilde) to simulate an out of tune condition (e.g. if you want to practice tuning); repeat for worse results.
- a (in stand-alone application) will write a samples.au file for the current sample (not properly synched, length has to be updated by hand); p will write the last short piece (same issues). Mostly for development.
- The resolution is now much better than one cent (one hundreth of a semitone).
Twelve notes per octave are assumed here (there are other options).
- The applet will not work properly if run in two
browser windows at the same time.
Examples and games:
- Setting a temperament on C=256.
- Click on C's frequency, change it to 256, hit ENTER.
- Click on C (main select).
- Click on pitch "selected".
- Click on the desired tuning/temperament or edit your own (eg. by entering cents).
- Dial tone (North-American):
Similarly, one can emulate ring-back tone with A=440 (primary select) and B=480, similarly to above.
- Set frequency of F to 350.
- Set frequency of A to 440 (yes, dial tone contains A 440 -- so we have a tuning fork in every home!).
- Type 0 to generate sine waves.
- Click on F (main select), shift-click on A (secondary select).
- Click on "play" and you should hear dial tone.
- Effects of harmonics: select a chord (say C-E-G), click on the
various tunings (say pythagore, just, mean tone, equal) comparing the
sound qualities: you should hear obvious differences. Now type '0' (zero)
and try these same tunings: hardly any difference now, because there are
no harmonics beating with one another.
Environments on which I believe the applet works decently:
I have personally run it on the following:
- MacOS8, Mac Runtime Java (MRJ) 1.0, 1.5 and 2.0, CyberDog 2.0.
- Linux (on Pentium), Linux JDK 1.1.3.
- SGI Unix, Netscape?
- Win 95, Microsoft I.E. 3.01.
- Win 95, JDK 1.2.
- jview on Win2K or WinXP (using the classes here based on the sun.audio package).
- Windows, JDK 1.3 and later with the newer classes.
- HotJava will require the following line in its properties file:
(because it accesses the sun.audio package). Otherwise, I don't know if
the sound works with this browser.
- MacOS 7.5 with Netscape navigator 3.01, and MacOS 8.1 with navigator 4.05 (choppy sound)
- MacOS 8.1 with MRJ 2.0 (flawless) (no longer available: MRJ-specific classes)
- Win95 and Netscape navigator 4.05 (no problems)
- A few Unices (Linux, HP, AIX, Sun) under various JDKs and under navigator (no sound :-) -- it was not configured)
Future plans include
turning this applet into a virtual instrument to
practice tuning with (when Java Sound becomes available).
- I tend to be quite jealous of my source code (must be some "control" thing,
a nice case study for a psy), and, at any rate, the code is
not very well commented,
and it shows signs of entropy setting in
(so pride is also a factor here).
However, I've been asked a few times how I do it, so I'added
a separate page with a short applet
that demonstrates how
the I dealt with audio in JavaTuner, including my µ-law (mu-law) Java code.
- The audio generated by the applet can only be, for now anyway,
µ-law at 8 kHz (Sun's basic .au format).
This is an audio encoding at 8 kHz, using 8 bits and a logarithmic
companding (to improve quality of weak signals). It is universally used
on the North-American telephone system (to carry voice). It is also,
at present, the most universal audio encoding on the Web (esp. in Java).
It's a bit low for quality
sound, but, hopefully, one can still get
accurate frequencies which is the main point of this applet.
Unfortunately, to avoid aliasing problems (Nyquist's theorem), I cannot
generate enough harmonics (I stop at the 5th) to get a good sound that
would better highlight the differences between the various temperaments
and make the beats more audible (but I'm still experimenting).
Headphones can help here.
- The applet uses sun.audio.AudioPlayer class as the main I/F to audio hardware.
I know that better things are coming as part of the Java Media thrust
(Java Sound API, beyond JDK 1.2).
Update (early 1999): the new JavaSound API has just been released. Besides
computing samples at higher resolutions (which would be slower, but still worth a try -- maybe I'll get into it this year), it offers
nothing really new to help this application. The MIDI API would be a good way
except that it does not guarantee me a specific implementation (and, as I have
seen with plugins, they do differ quite a bit, with some being useless for our purposes).
At any rate, this new API surely won't be available on
browsers for some time to come. The sun.audio.AudioPlayer is still the only way I'm currently aware
of that an applet can use to play locally-generated audio samples.
- The applet also runs as a stand-alone application. For this, you need to download
the following class files (about 50 Kbytes total):
And then start the application with java Accord (or whatever is appropriate in your Java runtime).
It can also run under an applet viewer with, for example, the following
HTML stub. (See also MRJ-specific notes.)
- The applet is based on JDK 1.0; it will move to JDK 1.2 when the new
sound API becomes available.
- The GUI is under the browser/AWT thread. A separate thread created by the
applet converts the frequencies to µ-law samples (at 8 kHz) for the
- The µ-law samples are generated when needed. This means a delay
between the time the note is clicked and the time playing starts.
JIT compilers should help a lot here.
Still, even without JIT, it's much faster than getting the samples from
a server (which would allow better quality and get around the choppy
sound in some environments).
On a modern 200+ MHz machine, the delay is under 0.5 seconds, with no JIT
(short pieces take a fair bit longer to compute; without JIT, several
seconds, with JIT, under half a second).
- I did my own buttons because I didn't want to get into LayoutManagers
that deeply. And 3D diamond buttons with gradual shading
would look kind of funny in the circle of fifths.
I found that Graphics.drawOval and fillOval center differently on different
platforms (not impressive). Also neither are very nice (ragged edges).
What I would really
have liked is a Graphics.drawPixels() function to draw small pixmaps. But,
no such luck.
- I wish I had better control over font sizes (for better layout). Some
platforms don't seem to support anything more than one font size.
About the author:
||My main work was software development (telephony signalling protocols)
at Alcatel-Lucent; that's where I learned about µ-law.
But, in a previous life, I was very much into (early) music,
and also into tuning
(as a semi-professional harpsichord tuner); this led me to a study of
historical tunings and temperaments.
Copyright: Pierre Lewis,
Page URL: http://leware.net/temper/sa/accord.htm
Retour / Zurück / Back