Tag Archives: Music

Baroque Performance with Werckmeister Temperament

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 :)

[MusicGeekNotes] Creating Music With Graphics, Lights and Smokes.

Create some music by clicking or dragging @ http://jabtunes.com/labs/jtenorion.html

** Warning: Can be CPU intensive. Safari / Chrome for best results. If you do not have a fast CPU, use less effects in the checkbox options.

Check out a video playing with this.

[Music Notes]
After a while, you may find that you’re creating some chinese-like, malay-like or javanese like music.

This is a clone of the fairly expensive electronic but a fairly cheap music instrument call the Tenori-On made by Yamaha.

Anyway, this version is closer’s to Andre’s implementation call ToneMatrix, a flash implementation using notes of a pentatonic scale, which allows you to pleasant sounding music evening if you click on it randomly. Just youtube it, and you can find how many others have created music with the Tonematrix.

First of all my implementation differs with using a HTML 5 Canvas to render the graphics instead of flash.

I use the the Sion Library for the audio, creating a JS to AS bridge to generate sounds. Howeveer, with the still-in-progress Mozilla Audio Data API, one can easily modify this program to run fully in javascript soon.

My initial visual effects was less than satisfactory compared to Andre’s implementation and I got stuck at creating the “ripple effects”. I first tried the ripple algorithm used in my previous experiment, but such animation would be almost usuable and very likely to hang the browser.

After a period of rest, while reading on perlin noise in canvas, I started having some inspirations for this project again.

Its then struck me that I could implement this with a simple particle system with gradients.
I was also inspired by the use of gradients, alpha and composites stumped upon this while looking up collaborative programming.

So right now, although its not all perfect, but its a big improvement from the past.

Go ahead, have fun, create some music, hack the code, or provide some suggestions.

p.s. I found the layout look like an iPad after I used curve borders, not that I wanted to replicate the iP* devices.

Other WIP screenshots here.

(a cross post on my facebook note)

“Huh?” – A Short Piano Composition

“Huh?” is a short piano composition I came out with last week. It is not delicated to anybody in mind but you can view, download or print the score for free or listen to the computer generated midi.


The long story: I went up to the piano with one day without anything in mind but started playing some tunes when i least expected it. I quickly grab a pen and paper to jot down some notes in case I forgot them and recorded this song on my netbook, everything done almost in a sitting.

Of course writing it down and typesetting it actually takes a lot more time. typed the piece of music using the software MuseScore 1.9.6 beta, a great free music notation software. I later save it as a lilypond format which was more familiar with me for tweaking the nice finishing touches for music scores layouts with the help of jedit lilypondtool.

Like several of my songs, I think it sounds a little nostalgia (like “Who am I” which Reuben Kee arranged and used for his musical). Then again, I wasn’t really expecting to compose any thing on the piano that day which prompted me to title it “Huh?”.

I got a mixed bag of reactions to the piece. Some say its sounds classical, some says pop, some says a mixed. Some thinks it from Chopin Ballet, or Granados Spanish dance – Andaluza, or a little Japanese, Korean, Amelie soundtrack sounding, some feels its too happy, too sad, etc. You get the idea. I think much would be coincidental and subjective to the listeners.

Some suggestions by my friend Gerald – playing the harmony with broken chord pattern instead of the oom-pah bass will make it sound “more fluid”, and “less static”. He also suggest arranging the melody on the flute with a harp accompaniment in broken chords, in which after I just found out from my harp friends its difficult for lever harps to play keys with 5 flats.

Have fun trying out this piece out and let me know if you have other comments.

p.s. Since I’m on the topic of music, do let me know if you want to attend the nusso concert on 19 march friday evening 2010 at VCH. Details here and here.


update: the audio generated by musescore can be heard here. http://soundcloud.com/zz85nus/huh-1
or http://soundcloud.com/zz85nus/huh-recording for the original recording.