Post Lab 11: Audio Editing
Due Friday, December 3, 2010
In this assignment you will write a Program that will edit audio files by
creating an echo effect.
Computers represent sounds as a series of discrete measurements
of a sound's amplitude at a fixed interval. Each amplitude measurement
is called a sample.
The file Sound.java contains a Java class that
has a static method to read an audio file into an array of shorts. Each element
of the array is a sample from the specified audio file.
It is possible to modify a sound by simply changing the amplitudes in the array of
samples.
An echo can be added to a sound by repeatedly copying and diminishing
the amplitude of the sound. The distance between copies of amplitude is
the delay of the echo and the amount that the copy diminishes
is the decay of the echo.
Create a program that does the following:
- Prompt the user to enter the name of an audio file (the file must be located
in the same directory as the java file). The read method of the
Sound class will return null if it is unable to read the specified file. If
it is unable to read the file the program should prompt the user again for a file name.
- Print the length of the sound in seconds. The sampleRate method of the
Sound class will return the number of samples per second of a sound file.
Use the samples per second and the length of the sample array returned by the
read method to determine the length of the sound.
- Prompt the user to enter the delay of the echo effect to be produced in seconds.
The delay should allow fractional seconds, but not negative values. Prompt the user
again if the number of seconds is not positive.
- Prompt the user to enter the decay of the echo. The decay should be a number
between 0 and 1. Prompt the user again if an invalid decay is entered.
- Calculate how many samples the new echo modified sound will be. The number
of repetitions of the echo can be computed using the equation:
numEchos = log(0.01) / log(decay)
The new sound length can then be computed as:
newLength = originalLength + numEchos * delay
If the new length is longer than 30 seconds, you should prompt the user to enter new
delay and decay values.
- Create an array to store the new echo modified sound (using the calculated length)
and copy the original sound into it.
- Add the echo effect to the new sound by copying and scaling amplitudes. In order
to ensure that the calculated amplitudes do not exceed the allowed level use the following
equation:
samplei = (samplei - delay * decay + samplei) / (1.0 + decay)
- Play the sound using the play method of the Sound class.
You can test your program using the audio files hello.aiff
and guitar.wav. You can also test it on your own files, however,
the sound class requires that the audio file be a 16-bit aiff or wav file. You can convert a file
to this format using the open-source sound editing program
Audacity.
Submission
From your postlab11 directory, tar your code using the command:
tar czf username.tgz *
Where username is the name you use to log into the lab machines.
To submit your code, copy the tar file containing your code
to the directory:
~bouchard/cpsc120/post11