CS 140 - Lab 18 Overlaying Sounds

Objectives

  1. Review previous lab on modifying the volume of a sound.
  2. Write a Java program that "combines" two sounds together into one by overlaying one sound on top of the other.

Part 1 - Review

  1. In the previous lab you wrote a program that changes the volume of a sound. In this part of the lab we're going to do this again but by adding a new method named decreaseVolume() to the Sound class in the file Sound.java. This is very similar to the way we added methods to the Picture class (for example decreaseRed()).

    In a Lab18 class add a method decreaseVolume() to the Sound class. This method should decrease the volume of the sound by 50%. Test your method on any sound file.

Part 2 - Adding Sounds

  1. Add code to your Lab18 class to open and play the Gettysburg address in the sound file gettysburg.wav. Call this sound object sound1.
  2. Add code to your Lab18 class to open and play the sound in the sound file taps.wav. Call this sound object sound2.
  3. Create a new sound that adds the two sound oubjects sound1 and sound2 into a new third sound, sound3. Play the resulting sound3 object and you should be able to hear the two different tracks.
  4. In the resulting sound3 object the taps sound file is too loud. Decrease the volume of it using your new handy decreaseVolume method before you add the sounds together. You may need to call decreaseVolume several times to get it at the right volume.

Extra Credit

Add a method to the Sound class named addSounds. Add sounds takes three Sound objects as parameters. The first two are the sound objects to add and the third is the sound object that results from adding together the first two. Test your method on the example from Part 2 above.


© Ed Harcourt