import com.jsyn.JSyn;
import com.jsyn.Synthesizer;
import com.jsyn.unitgen.LineOut;
import com.jsyn.unitgen.LinearRamp;
import com.jsyn.unitgen.SawtoothOscillatorBL;
import com.jsyn.unitgen.UnitOscillator;
/**
* Simple synthesizer example.
*
* Based on source from
* http://www.softsynth.com/jsyn/docs/usersguide.php#AppletTemplate
* @author Phil Burk (C) 2010 Mobileer Inc
*
*/
public class SawFaders
{
private Synthesizer synth;
public UnitOscillator osc;
private LinearRamp lag;
private LineOut lineOut;
public SawFaders()
{
synth = JSyn.createSynthesizer();
// Add a tone generator.
synth.add( osc = new SawtoothOscillatorBL() );
// Add a lag to smooth out amplitude changes and avoid pops.
synth.add( lag = new LinearRamp() );
// Add an output mixer.
synth.add( lineOut = new LineOut() );
// Connect the oscillator to the output.
osc.output.connect( 0, lineOut.input, 0 );
// Set the minimum, current and maximum values for the port.
lag.output.connect( osc.amplitude );
lag.input.setup( 0.0, 0.5, 1.0 );
lag.time.set( 0.2 );
}
public void start()
{
// Start synthesizer using default stereo output at 44100 Hz.
synth.start();
// We only need to start the LineOut. It will pull data from the
// oscillator.
lineOut.start();
}
public void stop()
{
synth.stop();
}
/** Play note at given frequency for given number of milliseconds.
*/
public void playNote(double freq, long millis) throws InterruptedException {
osc.noteOn(freq, 1.0);
Thread.sleep(millis);
}
public static void main( String args[] ) throws InterruptedException
{
// Start up the synth and play some notes.
SawFaders saw = new SawFaders();
saw.start();
double note = 220;
for (int i = 0; i < 24; i++) {
saw.playNote(note, 100);
note *= (1 + 1/12.0);
}
saw.stop();
}
}