0% found this document useful (0 votes)
122 views3 pages

Lab5 AnswerSheet

This document contains the summaries and code for several functions that manipulate sound objects in JES, including: - duplicateSound duplicates a sound object - fadeDown/fadeUp fades the volume of a sound up or down over time by a factor - fadeIn fades the start of a sound down and then back up - cropSound crops a sound by starting index and number of samples - cropSoundByTime crops a sound by starting time and duration

Uploaded by

nislam57
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views3 pages

Lab5 AnswerSheet

This document contains the summaries and code for several functions that manipulate sound objects in JES, including: - duplicateSound duplicates a sound object - fadeDown/fadeUp fades the volume of a sound up or down over time by a factor - fadeIn fades the start of a sound down and then back up - cropSound crops a sound by starting index and number of samples - cropSoundByTime crops a sound by starting time and duration

Uploaded by

nislam57
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Multimedia Programming

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:
#
#
#
#
#
#

This function fades down a sound by a certain factor.


Beginning of sound will remain unchanged and will slowly
fade to a certain factor. The end of the sound will be
quieter by that largest factor.
Takes two parameters: a sound file and a largest factor
Make sure that largest factor is floating point number

def fadeDown(sound, factor):


curFactor = 1.0
for s in getSamples(sound):
value = getSampleValue(s)
setSampleValue(s, value / curFactor)
curFactor = curFactor + ((factor 1) / (getNumSamples(sound) 1))

return sound

fadeUp code:
#
#
#
#
#

This function fades up a sound by a certain factor.


Beginning of sound will remain unchanged and will slowly increase by a certain
factor. The end of the sound will be louder by that largest factor.
Takes two parameters: a sound file and a largest factor
Make sure that largest factor is a floating point number

def fadeUp(sound, factor):


curFactor = 1.0
for s in getSamples(sound):
value = getSampleValue(s)
setSampleValue(s, value * curFactor)
curFactor = curFactor + ((factor 1) / (getNumSamples(sound) 1))
return sound

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.

def fadeIn(sound, betweenIndex, factor):


for firstPortion in (0, betweenIndex):
fadeDown(sound, factor)
return sound
for lastPortion in (betweenIndex, getLength(sound)):
fadeUp(sound, factor)
return sound

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)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy