|
import jm.JMC;
|
As well as the jm.music classes, the jm.audio classes are imported. The audio.data folder contains input and output code, the audio.synth folder contains synthesis tools not used in the sample-based example, and the jmInst class contains the instrument classes including the TriangleInst class used in this tutorial.
public final class AudioScale implements JMC{
|
The class is declared, then the main method. Structurally this class is very basic, everything happens in the main method.
//declare an instance of the triangle wave instrument TriangleInst tri = new TriangleInst(8000); //Put the instrument(s) into an array called ensemble Instrument[] ensemble = {tri}; |
First audio priority is to declare instruments and then an instrument array. The TriangleInst takes one argument, the sampling rate. The ensemble array holds all the instruments to be used by this score, only one in this case.
Score s = new Score("JMDemo - Audio Scale"); // The third argument to the Part constructor //specifies an element in the instrument array Part p = new Part("Melody", 0); Phrase phr = new Phrase(); |
The jMusic score is created in the 'normal' way. This is the nice thing about jMusic, the same score file can be used to render audio or MIDI versions of the score. Importantly, the second argument to the part indicates which instrument in the instrument array is to be used by the part.
for(short i=0;i<25;i++){
|
A chromatic scale is created.
p.addPhrase(phr);
|
The phrase is packed into a part, then into a score.
Write.au(s, "AudioScale.au", ensemble);
|
This is a the magic line that
renders the score as an audio file - simple isn't it! The
writeAU() method takes two arguments, the file name and the
Instrument array to be used.
|
|
|
© 2002 Andew R Brown |
|
|