/** * 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 Lect1116c { 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 = normalizeSound (s1); s3.explore(); } public static Sound normalizeSound (Sound s1) { SoundSample sampArr1[] = s1.getSamples(); SoundSample samp1; int index; int sampVal1; int length3; length3 = sampArr1.length; Sound s3 = new Sound(length3); SoundSample sampArr3[] = s3.getSamples(); SoundSample samp3; int sampVal3; double samplingRate = s1.getSamplingRate(); int numberSamplesIn3Seconds = (int)(samplingRate * 3); // determine the volume multiplier double volumeMult; volumeMult = 1.0 / numberSamplesIn3Seconds; System.out.println ("Number of samples in the sound: " + sampArr3.length + ", " + length3); for ( index = 0 ; index < sampArr3.length ; index++ ) { samp1 = sampArr1[index]; sampVal1 = samp1.getValue(); if ( index < numberSamplesIn3Seconds ) sampVal3 = (int)(sampVal1 * volumeMult*index); // normalize the sound value else sampVal3 = sampVal1; // store the new sample value into the array for s3 samp3 = sampArr3[index]; samp3.setValue(sampVal3); sampArr3[index] = samp3; } return s3; } } // end of class