/** * 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 Lect1122c { 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 s3; s3 = createEcho (s); 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 createEcho (Sound s1) { // add error check code here int len1 = s1.getLength(); int echoLength = (int)(s1.getSamplingRate() * 0.5); int len3 = s1.getLength() + echoLength; Sound s3; s3 = new Sound (len3); SoundSample ssarray1[]; SoundSample ssarray3[]; int largest; int value1; int value2; int i; ssarray1 = s1.getSamples(); ssarray3 = s3.getSamples(); for ( i = 0 ; i < len1 ; ++i ) { value1 = ssarray1[i].getValue(); ssarray3[ i ].setValue(value1); } for ( i = 0 ; i < len1 ; ++i ) { value1 = ssarray3[i].getValue(); value2 = ssarray3[i + echoLength].getValue(); value1 = value1 / 3; ssarray3[ i + echoLength ].setValue(value1 + value2); } 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