package rice2604hw; /* ======================================================== 2604 JWRMandelInst J.Rice -------------------------------------------------------- A JMSL file which is an intermediary between a circuit and a MusicJob. This instrument controls an FM pair which feed into a StateVariableFilter. The cutoff frequency of the filter is varied as a function of the two oscillator frequencies. The highPass and lowPass outputs are then fed to left and right channels respectively. ======================================================== */ import MandelMusic.MandelInstrument; import java.lang.*; import com.softsynth.jmsl.*; import com.softsynth.jsyn.*; //=========================================================== class JWRMandelInst extends MandelInstrument { FilteredFM osc; LineOut myOut; //- - - - - - - - - - - - - - - - - - - - public JWRMandelInst() throws SynthException { super(); osc = new FilteredFM(); myOut = new LineOut(); osc.output0.connect(0, myOut.input, 1); //<=channel switch osc.output1.connect(0, myOut.input, 0); //<<==test here osc.caramplitude.set(0.0); osc.modamplitude.set(20.0); //edited 10/30/00 } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public double open(double playTime) { int itime = (int)JMSL.clock.timeToNative(playTime); osc.start(itime); myOut.start(itime); return playTime; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public double close(double playTime) { int itime = (int)JMSL.clock.timeToNative(playTime); osc.stop(itime); myOut.stop(itime); return playTime; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ public void setAll(double dar[]) { //This method allows the applet //to change params without using play() osc.freq1.set(dar[0] * 2500.0); osc.freq2.set(scaleUp(dar[1])); osc.cutoff.set(scaleUp(dar[2])); osc.resonance.set(dar[4]); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public void pleaseStopNow() { osc.caramplitude.set(0.0); } //---------------------------------------- public double play(double playTime, double timeStretch, double dar[]) { int itime = (int)JMSL.clock.timeToNative(playTime); osc.freq1.set(itime, scaleUp(dar[0])); osc.freq2.set(itime, scaleUp(dar[1])); osc.cutoff.set(itime, scaleUp(dar[2])); osc.caramplitude.set(itime, 0.5); osc.modamplitude.set(itime, 40.0); //editted 10/30/00 osc.resonance.set(itime, dar[4]); double distance = dar[3]; double duration = Math.max(distance, 0.01); JMSL.out.println(getName() + " " + scaleUp(dar[0]) + " " + scaleUp(dar[1]) + " " + scaleUp(dar[2])); JMSL.out.println(getName() + " " + duration); return playTime + duration * timeStretch; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double scaleUp(double x) { return x * 1000.0 + 80; //6000->1000 } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static void main(String args[]) { JWRMandelInst jwr = new JWRMandelInst(); double[] dar = {0.5, 0.5, 0.5, 0.5, 0.5}; jwr.play(JMSL.now(), 1.0, dar); } } //===============================END ALL========================================