/** * Create a 1 second echo in the sound * * @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 Lect1123d { 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 = createEcho (s1, 0.5); s3.explore(); } public static Sound createEcho (Sound s1, double echoDelay) { SoundSample sampArr1[] = s1.getSamples(); SoundSample samp1; int index; int sampVal1; int length3; // increase the pitch by 9-10ths length3 = sampArr1.length + (int)(s1.getSamplingRate() * echoDelay); 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 < sampArr1.length ; index++ ) { samp1 = sampArr1[index]; sampVal1 = samp1.getValue(); sampVal3 = sampVal1; // store the new sample value into the array for s3 samp3 = sampArr3[index]; samp3.setValue(sampVal3); } SoundSample samp2; for ( index = 0 ; index < sampArr1.length ; index++ ) { samp1 = sampArr1[index]; sampVal1 = samp1.getValue(); index2 = index + (int)(s1.getSamplingRate() * echoDelay); samp3 = sampArr3[index2]; sampVal3 = samp3.getValue(); sampVal3 = sampVal3 + (sampVal1 / 2); // store the new sample value into the array for s3 samp3.setValue(sampVal3); } return s3; } } // end of class