This baroque era tuning seems to be a popular method for performing pieces like Bach’s well tempered clavier. It is a tuning system based on the Pythagorean tuning but “tempered” with so it would sound well on different chromatic scales.

As a (pretenious) baroque music lover and thanks also to the wonderful influence of my harpsichordist(/musicology) friend, I’ve dived into implementing the Werckmeister tuning system in javascript last night for more experiments with audio synthesis in HTML5 audio.

First, let us look at the basic method for deriving frequencies using the equal temperament (ET). Taking A440 (concert pitch A at 440hz), we can calculate frequencies by doing this.

*var noteFrequency = 440 * Math.pow(2, semitones / 12);*

where semitones is the number of semitones away from the concert A. Pretty simple right?

Instead of a universal formula for ET, or recalculating the tempering of frequencies, we would use the chart for frequency relation of the Werckmeister I (III) system ["correct temperament" based on 1/4 comma divisions], conveniently taken from wikipedia.

Since there’s 12 distinct notes in an octave, to get a frequency of a particular note, you multiply the relative ratio of the note you wish to get. For different octaves, with simply half or double the frequency, which can be expressed as powers of 2, *eg. Math.pow(2, octave_difference);*

So after we precompute the ratio table into rational numbers, we can calculate and check cents by running *Math.log(werckmeisterRatio)/Math.log(2)* 1200 )* on each note. The precision you would get would be higher than the rounded numbers in wikipedia.

Now, what’s left is to multiply the frequency ratios to a real frequency, but what frequency should we use? What’s more puzzling is that the base frequency for the charts is using C and intead of concert A. But no worries, my friend tells me 415hz (or even 390hz) is usually used for the baroque A, and with that we can estimate the frequency of C. [This topic of frequency is always an area of debate. But a reason how they calculated the lower baroque pitch, at least from a book I’ve read, is by measuring the frequencies created by organs from the baroque era]. One way you could do it is by running *baseFrequency = 415 / Math.pow(2, 9/12);*

(If you’re observant enough, that’s a equal temperament formula. for the werckmeister method, check out the source code)

Now, let’s test the system using a favorite piece of mine – the 3rd movement of Brandenburg Concerto No. 5, by J. S. Bach. Years ago I typeset this piece in lilypond, which generates the midi too (which is available for download together with the pdf). Credits to Matt Westcott’s brilliant jasmad library, we can interpret and play a midi file in the browser simply with javascript without any real midi devices or midi software on the computer, with any tuning system but you’ve to tolerate my poor audio synthesizing capabilities here.

So for the first time in the history of music, let’s us listen to a live performance of Bach’s Brandenburg Concerto in the Html5 Audio Concert hall, played on periodic javascript instruments, in the Werckmeister temperament, performed by the javascript chamber orchestra!

Free entrance @ http://jabtunes.com/labs/werckmeister/ (Firefox attire recommended:)

p.s. relevant source code for midi number to frequency using werckmeister’s tuning @ https://gist.github.com/1406293

p.p.s. actually, what’s unclear is that in a chamber setting, what temperament do instruments apart from the keyboard use? to the real musicians, please enlighten