/** * 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 Lect1115b { 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()); Sound s2; s2 = normalizeSound (s); System.out.println ("S2 length: " + s2.getLength()); s2.explore(); System.out.println(""); System.out.println("End Java Exection"); } 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