Lab5 AnswerSheet
Lab5 AnswerSheet
Lab Exercise #5
Please answer the lab questions in this answer sheet, save the document and
submit via Drexel Learn.
Team Members: Nibras Islam, Angelo Dellomargio, Jeffrey Clark
Changing Volume
What do you think the duplicateSound function does? Do you think there is a similar
function for images?
The duplicateSound function takes as input a sound object and returns a new sound object
with the same sample values as the original. We think there may be a similar function for images.
And in fact, according to JES, it is called duplicatePicture.
Answer to Design questions:
The initial value of curFactor should be 1 if the sample value of the first sample is to be
unchanged. (If initial value of curFactor is greater than 1, than the value of the first sample
will be less than original and if the initial value of curFactor is less than 1 but greater than 0,
the value of the first sample will be greater than original).
The values of curFactor throughout the execution of the function forms an arithmetic
progression with first term (corresponding to the first sample) 1 and last term (corresponding to
the last sample) the value passed to the parameter factor. Thus the common difference, the
number which curFactor should be increased by, is :
(factor 1 / getNumSamples(sound) 1)
fadeDown code:
#
#
#
#
#
#
return sound
fadeUp code:
#
#
#
#
#
fadeIn code:
#
#
#
#
#
This function will make the first portion of a sound quieter by some
factor.
It will then gradually increase the volume until it reaches original level.
Takes three parameters: a sound file, the index at which to divide the
two portions, and the factor to be used.
Cropping Sounds
Answer to Design questions:
The resulting sound should have length equal to the absolute value of the difference between the
index at which we want to start at and how many samples we want to include.
The sum of the index we want to start at and the amount of samples we want to include cannot be
greater than the length of the original sound.
We can find the length of the sound by using the getLength or getNumSamples command
on JES
cropSound code
# This function will crop a sound.
# Takes three parameters: sound file, index at which to start cropping,
# and how many samples after that initial index to include
def cropSound(sound, index, numberOfSamples):
if (index + numberOfSamples > getNumSamples(sound)):
print Invalid entry
else:
target = makeEmptySound(abs(index numberOfSamples))
indexTarget = 0
for source in range(index, numberOfSamples):
value = getSampleValueAt(sound, source)
setSampleValueAt(target, indexTarget, value)
indexTarget = indexTarget + 1
return target
cropSoundByTime code
# This function will crop a sound.
#Takes three parameters: sound file, time at which to start cropping (in
#
def cropSoundByTime(sound, secondsToStartAt, howManySeconds):
startIndex = secondsToStartAt * getSamplingRate(sound)
numberOfSamplesToInclude = howManySeconds * getSamplingRate(sound)
cropSound(sound, startIndex, numberOfSamplesToInclude)