|
public void createChain(){ |
Oscillator class
Inside the Oscillaor class we can see that there is a constructor that takes four arguments, an audio instrument, the current sample rate, an array of floating point values to be used as the lookup table, and the number of channels for this instrument.
In the instruments shown thus far, these arguments have been filled by the following line inside the createChain() method.
Oscillator wt = new Oscillator(this, Oscillator.SINE_WAVE, |
Each wavetable instance takes an array of floats that describe the wave table data. Often this data is one cycle of a waveform provided by the Oscillator class. The timbral information is provided by the Oscillator class that, in this case, returns a single cycle of sine wave floating point values to be used as a wave table.
The oscillator class has a number of methods to generate wavetable data. The sine wave generating method is shown below.
public final class Oscillator{ /** * Static function returning a sineWave created from * from a certain number of samples. * @param numOfSamples the number of samples to create * @return an array containing the sinewaves sample data */ public static float[] getSineWave(int numOfSamples){ float[] sampleArray = new float[numOfSamples]; float increment = (float)(Math.PI*2) / (float)numOfSamples; float x = (float)0.0; for(int i=0;i<numOfSamples;i++){ sampleArray[i] = (float)((float)Math.sin(x+( (float)2.0*(float)Math.PI))); x += increment; } return sampleArray; } |
There are methods to generate the following wave tables and you can always add others that you might want to include.
SquareWave, PulseWave, SawTooth, and TriangleWave.
SampleOut class
The sampleout class constructor takes the previous audio object in the chain as its only argument.
SampleOut sout = new SampleOut(span); |
Arpeggio composition
This program creates a three part score from a four note cell. Each subsequent layer is both higher and faster than the one below it, and a different instrument is assigned to each part so that each has its own timbre. The dynamic of each note is set randomly within a specified range and the panning position is set to a specific location for two of the parts and at random for the third. The three phrases, once constructed, are modified in various ways-In particular there is considerable use of volume fading in and out, and the highest part has the note order randomised using the Mod.shuffle() method.
import jm.music.data.*; |
Enjoy.
|
|
|
© 2001 Andrew Brown |
|
|