Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Using Tunings And Scales

baffo32 edited this page · 2 revisions

Using Tunings and Scales

Audiolet has built in support for non-western and microtonal tunings and scales, but is somewhat lacking in actual classes describing different tunings. Therefore if you are going to be creating work using these features you will need to do a little work to define your tuning and scale. This tutorial will take you through how to define a tuning and a scale, and how to use it in your application.

Creating a Tuning

To create a new tuning we need to create a subclass of the Tuning class. In this example we will create the Pythagorean tuning.

var PythagoreanTuning = function() {
    var semitones = [0.90225, 2.03910, 2.94135, 4.07820,
                     4.98045, 6.11730, 7.01955, 7.92180,
                     9.05865, 9.96090, 11.09775];
    Tuning.call(this, semitones, 2);
};
extend(PythagoreanTuning, Tuning);

Here you can see that tunings are defined by a series of semitone values. For the Pythagorean scale these can be calculated directly from the interval ratios, but for the purposes of this tutorial we can trust Wikipedia. The call to the constructor of Tuning also takes a second value, defining the ratio between octaves. This allows us to create stretched or compressed tunings.

Creating a Scale

Creating a new scale is almost identical to creating a Tuning, but instead of passing semitone values we instead pass the degrees to use. For example to create the Phrygian scale:

var PhrygianScale = function(tuning) {
    var degrees = [0, 1, 3, 5, 7, 8, 10];
    Scale.call(this, degrees, tuning);
};
extend(PhrygianScale, Scale);

You can see that in the constructor of our scale we specifiy the tuning we want to use. If this is left blank then a 12-tone equal temperament tuning is used.

Using Scales and Tunings

Now we have defined our scale and tuning we can start to use them. This is a simple matter of constructing the classes, and using the Scale.getFrequency function to get the frequency of a note.

var tuning = new PythagoreanTuning();
var scale = new PhrygianScale(tuning);

// Get the first four notes of the second octave
var baseFrequency = 65; // The base frequency of the scale
var octave = 1; // The second octave
var freq1 = scale.getFrequency(0, baseFrequency, octave);
var freq2 = scale.getFrequency(1, baseFrequency, octave);
var freq3 = scale.getFrequency(2, baseFrequency, octave);
var freq4 = scale.getFrequency(3, baseFrequency, octave);
Something went wrong with that request. Please try again.