Prelab 6: Making Sounds
1. Review background reading
2. Upload sounds to Duke Content Server
In lab, you will be combining clips from multiple sound files into one
audio collage. Before lab, you should upload any files that you want to
use to the Duke Content Server. Your files may be in either MP3 or WAV format, although WAV
is preferred.
You should upload at least 3 sound files to the appropriate server for your
lab section. The name of the file should be something descriptive, so
that the course staff and your classmates may have some hope of guessing the content of
the files from the name.
3. Review creating sound clips
Below is a method from the class notes, clip, that will be added to
the Sound class.
/**
* Method to create a new sound by copying just part of
* the current sound to a new sound
* @param start the index to start the copy at (inclusive)
* @param end the index to stop the copy at (inclusive)
* @return a new sound with just the samples from start to
* end in it
*/
public Sound clip(int start, int end)
{
// calculate the number of samples in the clip
int lengthInSamples = end - start + 1;
Sound target = new Sound(lengthInSamples); // hold clip
int value = 0; // holds the current sample value
int targetIndex = 0; // index in target sound
int i = start; // index in original sound
// copy from start to end from source into target
while (i <= end)
{
value = this.getSampleValueAt(i);
target.setSampleValueAt(targetIndex,value);
i = i + 1;
targetIndex = targetIndex + 1;
}
return target;
}
How would this method be changed to create a new clip that is the result of
appending a new clip onto the original?
4. Creating the Sound of Silence
Write the code required to create a Sound object that creates a specified
number of seconds of silence.
Hints:
- What amplitude should silence have? Zero - that should tell you what
the sample values should be
- You can create a Sound in the following manner:
Sound s = new Sound(100); // creates a sound with 100
- The getSamplingRate() method returns the number of samples
per second for a given sound.
Fill in the method below. Assume it appears within the Sound class.
// creates a new sound and returns numSeconds seconds worth of silence
public Sound silentTime(int numSeconds)
{
}
Jeffrey R.N. Forbes
Last modified: Mon Oct 10 17:46:14 EDT 2005