Programming Tools & Computer Science I

CSC 185 & 201, Spring 2013, Northern Virginia Community College

Homework 8: classpath and packaging in Java

2013-04-02

Due:

Apr 10, 11:59PM

To submit:

Send an email to me at jal2016@email.vccs.edu with subject CSC 185 HW8, containing your your answers attached in a zip file.

Or, put your work in your Bitbucket repository in homework/185/hw8, and email me with subject CSC 185 HW8 when you're done.

Directions:

  1. Modify the program shown below to play a different tune. This uses the JSyn library, and to compile and run you'll need to have the JSyn jar file in your classpath.

    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();
        }
    
    }