// Jay Summet (GaTech) // CS 1316 Sound examples... // This class extends the default "Sound" class and implements a few methods to create // some sounds! public class SStest extends Sound { // Default constructor to make a blank sound of length N public SStest(int N){ super(N); } public void squareWave() { // Makes an array of sound samples from SoundSample [] samples = this.getSamples(); boolean isHigh = true; for(int i = 0; i < this.getLength(); i++){ SoundSample ss = samples[i]; if ( isHigh) { ss.setValue( 32000); } else { ss.setValue(-32000); } // Flip the isHigh variable every 44 times through the loop. if (i % 88 == 0){ isHigh = ! isHigh; } } // end for each sample } // end public void squareWave public void sawTooth(int stepLength) { //TODO: Make a sawtooth wave pattern! } // end public void sawTooth public static void main( String [] args) { SStest myObject = new SStest(44100); myObject.squareWave(); myObject.play(); /* SoundSample [] sndArray = myObject.getSamples(); SoundSample ss = null; for(int i = 0; i < 100; i++) { ss = sndArray[i]; System.out.println("i is: " + i + " + Sound is:" + ss.getValue() ); } */ } // end main } // end class SStest