Processing Sound Ranges part 2 Barb Ericson Georgia
Processing Sound Ranges part 2 Barb Ericson Georgia Institute of Technology Sept 2005 Georgia Institute of Technology
Learning Goals • Processing ranges of Sound values – Splicing sounds together to create a sentence – Mirroring a sound – Blending sounds • Computing concepts – Looping through a range – Returning a value from a method – Change more than one variable in a for loop – Identify algorithms that cross media boundaries Georgia Institute of Technology
Create an Audio Sentence Exercise • Create a method that splices 3 sounds together to finish the sentence, “Guzdial is”. – Make sure that you don’t copy past the end of the current sound – Be sure to include silence between words – Can you make this method more general? • How about a method to splice a sound into the middle of another sound? – Take starting point in target for splice Georgia Institute of Technology
Reversing a Sound • To reverse a sound – Create a copy of the original sound • Sound orig = new Sound(this. get. File. Name()); – Then loop starting the source. Index at the last index in the source and the target. Index at the first index in the target • Decrement the source. Index each time • Increment the target. Index each time 100 | 200 | 300 | 400 | 500 target. Index 500 | 400 | 300 | 200 | 100 Georgia Institute of Technology source. Index
Reversing Method public void reverse() { Sound orig = new Sound(this. get. File. Name()); int length = this. get. Length(); // loop through the samples for (int target. Index = 0, source. Index = length - 1; target. Index < length && source. Index >= 0; target. Index++, source. Index--) this. set. Sample. Value. At(target. Index, orig. get. Sample. Value. At(source. Index)); } Georgia Institute of Technology
Testing the Reverse Method String file = File. Chooser. get. Media. Path( “thisisatest. wav”); Sound s = new Sound(file); s. explore(); s. reverse(); s. explore(); Georgia Institute of Technology
Reverse Part of a Sound Exercise • Reverse just the second half of a sound – Start the target. Index at the length / 2 – Start the source. Index at the length – 1 – Loop while the target. Index < length 100 | 200 | 300 | 400 | 500 100 | 200 | 500 | 400 | 300 target. Index Georgia Institute of Technology source. Index
Mirror a Sound • Copy the first half of the sound to the second half – And reverse the sounds in the second half – This is very similar to mirroring a picture • Calculate the midpoint (length / 2) • Start the source index at 0 and copy from index to length – index -1 • While index < midpoint 100 | 200 | 300 | 400 | 500 100 | 200 | 300 | 200 | 100 Georgia Institute of Technology
Mirror Sound Method public void mirror. Front. To. Back() { int length = this. get. Length(); // save the length int mirror. Point = length / 2; // mirror around this int value = 0; // hold the current value // loop from 1 to mirror. Point for (int i = 0; i < mirror. Point; i++) { value = this. get. Sample. Value. At(i); this. set. Sample. Value. At(length – i - 1, value); } } Georgia Institute of Technology
Testing Mirror Method Sound s = new Sound(File. Chooser. get. Media. Path( "croak. wav")); s. explore(); s. mirror. Front. To. Back(); s. explore(); Georgia Institute of Technology
Mirror Back to Front Exercise • Write a method to mirror from the back to the front – Copy the back half of the sound reversed to the front midpoint 100 | 200 | 300 | 400 | 500 | 400 | 300 | 400 | 500 Georgia Institute of Technology
Blend Sounds • Like blending pictures we can blend two sounds: – Copy the first 20, 000 values of sound 1 – Copy from both by adding. 5 * sound 1 value and. 5 * sound 2 value – Copy the next 20, 000 values of sound 2 Georgia Institute of Technology
Blend Sounds Method public void blend. Sounds() { Sound sound 1 = new Sound(File. Chooser. get. Media. Path("aah. wav")); Sound sound 2 = new Sound(File. Chooser. get. Media. Path("bassoonc 4. wav")); int value = 0; // copy the first 20, 000 samples from sound 1 into target for (int index=0; index < 20000; index++) this. set. Sample. Value. At(index, sound 1. get. Sample. Value. At(index)); Georgia Institute of Technology
Blend Sounds - Continued // copy the next 20, 000 samples from sound 1 and blend that // with the first 20, 000 samples from sound 2 for (int index = 0; index < 20000; index++) { value = (int) ((sound 1. get. Sample. Value. At(index + 20000) * 0. 5) + (sound 2. get. Sample. Value. At(index) * 0. 5)); this. set. Sample. Value. At(index + 20000, value); } // copy the next 20, 000 samples from sound 2 into the target for (int index=20000; index < 40000; index++) this. set. Sample. Value. At(index + 20000, sound 2. get. Sample. Value. At(index)); } Georgia Institute of Technology
Testing Blend Sounds String file. Name = File. Chooser. get. Media. Path( "sec 3 silence. wav"); Sound target = new Sound(file. Name); target. explore(); target. blend. Sounds() target. explore(); Georgia Institute of Technology
Summary • You can splice sounds together using more than one loop in a method • You can mirror sounds just like you mirrored a picture • You can blend sounds just like you blended two pictures Georgia Institute of Technology
- Slides: 16