/** * Class for creating a template for a simple Java program * * @author Pat Troy: troy AT uic DOT edu */ import java.awt.Color; // Note the name of the class in the following line MUST // match the name of the file. public class Lect1118d { public static void main (String[] args) { String fname = FileChooser.pickAFile(); //System.out.println (fname); Sound s1 = new Sound (fname); System.out.println ("Number of samples in the sound: " + s1.getLength()); System.out.println ("Number of samples per second: " + s1.getSamplingRate()); double lengthInSeconds = s1.getLength() / s1.getSamplingRate(); System.out.println ("The length in seconds of the sound: " + lengthInSeconds); Sound s3; s3 = createSoundClip (s1, 17407, 26726); Sound s4; s4 = createSoundClip (s1, 33413, 40052); Sound s5; s5 = joinSounds (s4, s3); s5.explore(); } public static Sound createSoundClip (Sound s1, int startIndex, int endIndex) { SoundSample sampArr1[] = s1.getSamples(); SoundSample samp1; int index; int sampVal1; int length3; length3 = endIndex - startIndex; Sound s3 = new Sound(length3); SoundSample sampArr3[] = s3.getSamples(); SoundSample samp3; int sampVal3; int index2; System.out.println ("Number of samples in the sound: " + sampArr3.length + ", " + length3); for ( index = 0 ; index < sampArr3.length ; index++ ) { index2 = index + startIndex; samp1 = sampArr1[index2]; sampVal1 = samp1.getValue(); sampVal3 = sampVal1 * 2; // store the new sample value into the array for s3 samp3 = sampArr3[index]; samp3.setValue(sampVal3); } return s3; } public static Sound joinSounds (Sound s1, Sound s2) { SoundSample sampArr1[] = s1.getSamples(); SoundSample samp1; int index; int sampVal1; SoundSample sampArr2[] = s2.getSamples(); SoundSample samp2; int sampVal2; int length3; length3 = sampArr1.length + sampArr2.length; Sound s3 = new Sound(length3); SoundSample sampArr3[] = s3.getSamples(); SoundSample samp3; int sampVal3; int index2; System.out.println ("Number of samples in the sound: " + sampArr3.length + ", " + length3); // copy the samples from Sound s1 into the final sound for ( index = 0 ; index < sampArr1.length ; index++ ) { samp1 = sampArr1[index]; sampVal1 = samp1.getValue(); sampVal3 = sampVal1 * 2; // store the new sample value into the array for s3 samp3 = sampArr3[index]; samp3.setValue(sampVal3); } // copy the samples from Sound s2 into the finnal sound for ( index = 0 ; index < sampArr2.length ; index++ ) { samp2 = sampArr2[index]; sampVal2 = samp2.getValue(); sampVal3 = sampVal2 * 2; // store the new sample value into the array for s3 index2 = index + sampArr1.length; samp3 = sampArr3[index2]; samp3.setValue(sampVal3); } return s3; } } // end of class