import jm.audio.io.*; import jm.audio.synth.*; import jm.music.data.Note; import jm.audio.AudioObject; public final class PluckInst extends jm.audio.Instrument{ /** The points to use in the construction of Envelopes */ private EnvPoint[] pointArray = new EnvPoint[10]; /** The number of channels */ private int channels; /** the sample rate passed to the instrument */ private int sampleRate; /** the filter cutoff frequency in hertz */ private int cutoff; /** A constructor to set an initial sampling rate */ private Filter filt; /** The envelope to apply, by default it does nothing */ private double[] envPoints; public PluckInst(int sampleRate){ this(sampleRate, 2); } /** A constructor to set an initial sampling rate and num of chans*/ public PluckInst(int sampleRate, int channels){ this(sampleRate,channels, new double[] {0.0, 1.0, 1.0, 0.0}); } /** A constructor to set initial sampling rate, channels and envelope*/ public PluckInst(int sampleRate, int channels, double[] envPoints){ this(sampleRate, channels, envPoints, (int)(sampleRate * 0.45)); } /** A constructor to set initial sampling rate, channels and envelope * and cutoff point. */ public PluckInst(int sampleRate, int channels, double[] envPoints, int cutoff){ this.sampleRate = sampleRate; this.channels = channels; this.envPoints = envPoints; this.cutoff = cutoff; } /** Initialisation method used to build the objects that this instrument * will use */ public void createChain(){ SimplePluck plk = new SimplePluck(this, this.sampleRate, this.channels); filt = new Filter(plk, this.cutoff, Filter.LOW_PASS); Volume vol = new Volume(filt); StereoPan span = new StereoPan(vol); Envelope env = new Envelope(span, this.envPoints); SampleOut sout = new SampleOut(env); } public void actionEvent(Object obj, int intValue) { filt.setCutOff((double)intValue); } }