/** * Class for creating a template for a simple Java program * * @author Pat Troy: troy AT uic DOT edu */ // Note the name of the class in the following line MUST // match the name of the file. public class Lect1122a { public static void main (String[] args) { System.out.println("Begin Java Exection"); System.out.println(""); // put your Java Program here String filename = FileChooser.pickAFile(); Sound s = new Sound (filename); System.out.println ("S1 Length: " + s.getLength()); System.out.println ("S1 Sampling Rate: " + s.getSamplingRate()); System.out.println ("S1 Time: " + s.getLength()/s.getSamplingRate()); Sound s2; s2 = normalizeSound (s); System.out.println ("S2 length: " + s2.getLength()); System.out.println ("S2 Sampling Rate: " + s2.getSamplingRate()); System.out.println ("S2 Time: " + s2.getLength()/s2.getSamplingRate()); s2.explore(); Sound s3; s3 = decreasePitch (s2); System.out.println ("S3 length: " + s3.getLength()); System.out.println ("S3 Sampling Rate: " + s3.getSamplingRate()); System.out.println ("S3 Time: " + s3.getLength()/s3.getSamplingRate()); s3.explore(); System.out.println(""); System.out.println("End Java Exection"); } public static Sound decreasePitch (Sound s1) { // add error check code here int l1 = s1.getLength(); int l3 = s1.getLength()*2; Sound s3; s3 = new Sound (l3); SoundSample ssarray1[]; SoundSample ssarray3[]; int largest; int value1; int i; ssarray1 = s1.getSamples(); ssarray3 = s3.getSamples(); for ( i = 0 ; i < l3 ; ++i ) { value1 = ssarray1[i / 2].getValue(); ssarray3[ i ].setValue(value1); } return s3; } public static Sound normalizeSound (Sound s1) { Sound s2; s2 = new Sound (s1.getLength()); SoundSample ssarray1[]; SoundSample ssarray2[]; int largest; int value; int i; double mult; ssarray1 = s1.getSamples(); ssarray2 = s2.getSamples(); // find the maximum value from the sound largest = 0; for ( i = 0 ; i < s1.getLength() ; ++i ) { value = ssarray1[i].getValue(); if (value > largest) { largest = value; } } System.out.println ("Largest: " + largest); // deterrmine the multiplier mult = 32767.0/largest; for ( i = 0 ; i < s1.getLength() ; ++i ) { value = ssarray1[i].getValue(); value = (int)(value * mult); if (value > 32767) { value = 32767; } if (value < -32768) { value = -32768; } ssarray2[i].setValue(value); } return s2; } } // end of Template class