This lab will have you combine two sound files to add a "background" soundtrack to a foreground sound. The following files of the Gettysburg Address and the Preamble of the U.S. Constitution are great foreground sound files.
The background file should be repeated it if is not as long as the foreground file. To do this, if the current index from the foreground sound is a value bigger than the length of the background sound, you need to subtract the length of the background sound from the current index until the result produces a valid array index for background sound. The use of the modulus operator % may help perform this calculation.
We will also want to make the background sound quieter than it originally is, so we wish to make its volume a third of its original value. The example program of Lect1103a.java is a good starting place for this lab. Here are some good files for the background sound:
To combine two sound files, you simply just add the sample values together. The only problem occurs if the resulting value goes above 32,767 or below -32,768. A simple solution is to use an if statement to check for this. Two simple if statements can check for this and correct the problem if it occurs. To correct this, just set the value to either 32,767 if the value was greater than 32,767 or set the value to -32768. if the value was less than -32,768. The example program of Lect1103b.java shows how to correct for this issue of "clipping".
Create a Java program that will:
Your header block comment for the program must include the following:
Header block comments for each method must include the following: