In this tutorial we explore the use of different tuning systems. The example class allows a musical piece to be rendered in one of four tuning systems, the equal temperment system used in modern times, just intonation, pythagorean tuning, and mean-tone. This demonstrates that with the ability of jMusic to play audio notes at any frequency you are not limited to the chromatic tuning normally associated with MIDI systems. It is possible to implement tuning schemes that don't even follow the conventional pattern of 12 notes to the octave.
The differences in tunings sounds like this [1199kb
Lets have a closer look.
Here we import the usual suspects for a jMusic
piece, we need the Instrument class for the audio rendering.
The class is declared and implements the JMC which allows us to use the jMusic constatans such as C (crotchet) for a rhythm value of 1.0 etc.
The main method is quite simple, and simply calls
the constructor to create an instance of the class.
The constructor takes no argments.
The first task is to have some music to text the
tuning systems with. We have used the first section of the one of Bela
Bartok's simple but interesting piano works. The pitch and rhythm values
are in separate arrays, because we need to process the pitches later on.
The above excerpt is not from Tuning_Systems.java,
it is from JMC.java
In the current version of Tuning_Systems.java,
EQUAL (equal temperment) is used. Equal temperment basically
sacrifices portability (the ability to transpose) for authenticity (true
If transposition is not an issue, then it may be a
good idea to use a tuning system that uses truer intervals.
These arrays hold the ratio values of each semitone scale degree as a multiple of the root of the scale. For example, C4 is the first (zeroth) scale degree and has a ration of 1:1.0 with itself, C# has a ration of 1:1.059 in the chromatic system, and so on.
Here is a table of all the values for these tuning systems.
As stated above, the currently active tuning system
is assigned to the variable modeRatios. This is where you can
experiment with the different tuning systems that are in JMC, or (even
better) make you own up!
A score is created and two parts are added, the
soprano and alto parts. A separate method, creatPart, is used for this
purpose. We will see more about this method below. For now we are only
concerned that it returns a Part that is added to the score.
Next, the score is rended as an audio file. This requires the declaration of a couple of jMusic audio instruments. We use instances of the SquareLPFinst that takes a sample rate and low pass filter cutoff frequency as arguments. These instruments are added to the instrument array, insts, which is passed to the Write() method.
If you don't have the Instrument it can be
downloaded from the jMusic web site, via the instrument page. or
you can simply use another instrument of your choice.
This method, mentioned earlier, is where all the interesting work of this example is done. Each of the pitches is turned into the appropriate frequency for the current tuning system. Notes are created using that pitch and added to a Phrase with is added to a Part and returned to the calling method.
In more detail, each pitch is processed in turn;
If the pitch is a REST then a rest-note is created with the corresponding rhythm value and added to the phrase.
Otherwise the pitch's frequency needs to be calculated. First, we work out which semitone degree it is.
Next we calulate the frequency by looking up the appropriate ratio in the current tuning ratio array and multiplying the root frequency by that ration value.
Finally, we create a note of that frequency with the corresponding rhythmValue and add it to the Phrase.
Now that the Phrase is created we add it to the Part which is then returned.
Rending a retuned MIDI file
For those of you that don't want to go to the trouble of writing out your music as pitch and rhythm arrays, below is a link to a modified version of the above class that reads in a MIDI file and renders out an audio file in the specified tuning system. This should save you some time :)
© 2002 Andrew R Brown