CS 111 - 4/21/15 Lab 12: Step 1. Get the preamble.wav into a Sound use pickAFile() to get filename then Sound s = new Sound ( filename ); Step 2: Create Sounds for each word using the Sample numbers/indexes given in the lab write-up and the method makeSoundByte() from Lect0414c.java: For the Sound: We Sound s1 = makeSoundByte (s, 7519, 15235); Do this for all the words needed. Sound s2 = makeSoundByte (s, ... , ... ); Sound s3 = makeSoundByte (s, ... , ... ); ... Step 3: Join the sounds create in step 2 together to make one long sound. Use the method joinSounds() from Lect0414b.java Sound sentence; sentence = joinSounds ( s1 , s2 ); sentence = joinSounds ( sentence, s3 ); ... Step 4: Explore(), play() or write() sound as described in the lab write-up Project 4: We are manipulation the digits in multiple integer values. The code from last week, - converted individual characters from a String into decimal values char ch = 'x'; int asciiNum = (int) ch; // discussion: assume we have a value of 385 // one's digit is 5 // ten's digit is 8 // hundred's digit is 3 // 385 = 3 * 100 + 8 * 10 + 5 * 1 // = 3 * 10^2 + 8 * 10^1 + 5 * 10^0 int digit0; // one's digit int digit1; // ten's digit int digit2; // hundred's digit digit0 = asciiNum % 10; digit1 = (asciiNum/10) % 10; digit2 = (asciiNum/100) % 10; For the project: Replace the least significant digit (the one's digit) from the amplitude value of the sound with the cooresponding digit from the character's ASCII digit Embedding process to put a text message into a sound. 1. Get the sound into the array of SoundSamples .getSamples() method 2. Set the one's digit for all amplitude values in the array of SoundSamples to zero. Note: the write-up for the assignment refers to this as "smoothing" the sound. Assume the amplitude value is 13726 int amp1 = 13726; int amp2 = amp1 / 10 * 10; // approach 1 int amp3 = amp1 - (amp1%10); // approach 2 We can loop through the SoundSample array, access each amplitude value, perform one of the two above approaches, the save the new amplitude value back into the SoundSample array. 3. Loop through the message and embed the digits from the message's ascii values into the SoundSample array. Code from Lect0414a.java // put your Java Program here String message; message = SimpleInput.getString("Enter a message to be embedded in a sound"); int len; len = message.length(); // loop through the string and display each character int i; for ( i = 0 ; i < len ; i++ ) { char ch; ch = message.charAt(i); int asciiValue; asciiValue = (int) ch; System.out.println ("The character at position " + i + " is " + ch + " which have ASCII value of " + asciiValue ); int digit0; int digit1; int digit2; digit0 = asciiValue % 10; digit1 = (asciiValue/10) % 10; digit2 = (asciiValue/100) % 10; System.out.println ("Digit0: " + digit0 + ", Digit1: " + digit1 + ", Digit2: " + digit2); // add the three digits into 3 different locations // in the "smoothed" SoundSample array }