Lab 12
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. 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
Lect48c.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.
Lab Assignment 12
Due: Thursday 4/15/2010 by 11:59 pm
Create a Java program that will:
- Contain a comment indicating
- your Name,
- Net-ID,
- Course Name,
- Assignment Name and
- a short description of
the assignment
- Contain the main() method that will
- Prompt the user for the "Foreground" sound file and make a sound object
from this file.
- Prompt the user for the "Background" sound file and make a sound object
from this file.
- Call the method addSoundtrack() that will take two sounds
(the foreground sound and the background sound) and return
a new sound.
- play (or explore) the resulting sound and prompt the user to save it in a file
- Contain the addSoundtrack() method that will:
- take two sounds as paramters (the foreground sound and the
background sound).
- Create a new sound that is the length of the foreground sound.
The samples in the new sound should be the result of adding
the background sound to the foreground sound, but the
volume of the background sound should be one-third of the sound from its
original file. To do this, first divide the background sound sample
values by 3 before adding the two values together.
- check for and correct any "clipping" that may result from the resulting
value being greater than 32,767 or less than -32,768.
- Note: if the background sound file is shorter than the foreground
sound file, repeat the background sound as often as needed to give a
background sound to the entire foreground sound.
- return the newly created sound.
Here are some example sound files you can use with this assignment.
Submittal of the Lab Assignment
-
Go to the blackboard site for the class
-
Select "Assignments" on the left bar
-
Locate the correct assignment to submit; click on "View/Complete Assignment" at the bottom of that assignment
-
Next to "Attach local file", click "Choose file",
choose the file you want to submit;
please submit only ONE file, properly named.
For example for lab2,
name it Lab2yournetid.java,
for example if your Net ID is sfranz3,
the filename would be Lab2sfranz3.java
Please only submit source code
file (the .java file, not the .class).
Also, if you have any comment about your program, please write it
down in the same file; please do NOT write in the "Comments" field on
the submission page (this will go into a different file and will be
easily missed).
-
Hit "Submit"
-
Go back once again to View/Complete assignment and make sure that your file was submitted; also, this page will show your grade and comments (if any) after assignments are graded.