Lab 13
In this lab, you will take a single sound file and have it fade in (increase) from silence to full volume and then fade out (decrease) into silence again. Program 71 from the book will be a very helpful method to use in this lab!
You can find sample soundtrack files to use for this lab here.
Also, this code might help you out as well.
Think about what happens when you are increasing the volume of a sound.
Say I have a sound that I divide into 10 sections. Each sections is
1/10th of entire sound. At the end of the sound I want
to have full volume, yet at the beginning I want to have silence. I can
do this by first finding the number of SoundSamples in each of the
10 sections (i.e. total number of samples divided by 10). That means that
I can break my sound into 10 sections, where on each section I increase
my volume by an additional 10%. By the time I have reached the end of
the song, I will have been at full volume.
Note that is is different than what was done during class with example
Lect48b.java.
I will do the same for when I decrease a sound, only this time it is the reverse.
You may have to use doubles when you step up to the next interval.
Because you will increase each sample by a percentage, you will have to
use a double. However, you may recast this value to an int when you set
the SampleValue in the new sound file.
The result will be a file that increases in "steps", but for the purposes
of this exercise this is OK. Hopefully you will not notice it!
This lab will require three methods. The first method will take in the
first half of the sound and increase the volume from silence to 100%. The
second method will take in the second half of the sound and decrease the
volume from 100% to silence. Finally, a third method will put these two
parts back together again.
- Method 1: increase():
- this method will be given in the first half of the sound as a parameter
- divide the sound into 10 equal length sections
- set the first section to 1/10th of its volume
- set the second section to 2/10ths of its volume
- continue until the ninth section is set to 9/10ths of its volume
- the tenth section is set to 10/10ths of its volume (i.e. left unmodified)
- and return the modified sound.
- Method 2: decrease():
- this method will be given in the second half of the sound as a parameter
- divide the sound into 10 equal length sections
- set the first section to 10/10th of its volume (i.e. left unmodified)
- set the second section to 9/10ths of its volume
- continue until the ninth section is set to 2/10ths of its volume
- the tenth section is set to 1/10th of its volume
- and return the modified sound.
- Method 3: joinSounds():
- this method will take two sounds as its parameters
- create a new sound whose length is equal to the length of the
two sounds added together
- join the two sounds so that the first sound is in the beginning
of the new sounds and the second sound is at the end of the new sound.
- return the joined sound
My final result should be the same sound I asked for in the beginning,
only now it will fade in from silence to full volume and then back down
again.
You should also have code to save the sound on the hard drive.
Lab Assignment 13
Due: Thursday 4/22/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 a soundtrack file
- Create a sound object from the file
- Split this sound into two parts of equal length
- Send the first part to the increase() method, and return
- Send the second part to the decrease() method, and return
- Send these two parts to the joinSounds() method, and return
- Play (or explore) the sound.
- Prompt the user for a name and save it.
Here is an example of what your sound might sound like:
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.