Sound
method that adds two sounds together.
min
to your Sound
class. The min function
takes two integer parameters and returns the smaller of the two. min
is a class method, so be sure to
declare it static
. Here's an example of how
the function might be called in your Lab19
class.
System.out.println(Sound.min(5,10));
.wav
files. One wave file should be of your
voice and the other wave file should be of your partner's or someone else in the classroom. Make the wave files short, speak for a few seconds.
Store these on your P: drive using your name as the name of the file before the
.wav
part. For example if the lab partners are Fred and Sally then
the files should be named fred.wav
and sally.wav
.
Lab19
class for these new sound files
and also play them.
Lab19
class that
uses your min
method to print the
number of samples that is the smallest between the two sounds. Use the
getNumSamples()
method on a sound
object and pass it to min
.
addSound
method
In the previous lab you wrote a program that adds two sounds together
and puts the resulting sound into a new sound object.
In this part of the lab we're going to do this again but by adding a new
method named addSound
to the Sound
class in the
file Sound.java
. This is similar to the way you added
a decreaseVolume
method to the Sound
class.
addSound()
to the Sound
class. This method takes one parameter, a sound,
and adds it to the current sound (this). This method should use your
min
function
to calculate the the number of samples to use (recall the last lab).
Here is how your method might be called in your Lab19
class.
// assuming s1 and s2 are two sound objects // to your wave files from part 1 s1.addSound(s2); // add s2 to s1 s1.explore(); // should play the combined sound