Midterm Exam 1 Review Spring 2003: Increase the volume, stepped #2
Try the problem here from Sp 2003 Midterm Review #1
Do we have to know this? If I recall correctly, you said that we are only responsible for what we covered on or before Friday...we didn't get to this, (the indexing of the sound) right?
| That's true, but it's still not a hard problem. Try it! Mark Guzdial |
Def increaseVolumeStepped(sound):
for sampleIndex in range (1,getLength(sound/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*.5)
for sampleIndex in range (getLength(sound)/3, getLength (sound) +1):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*1.2)
for sampleIndex in range (getLength(sound)/3, getLength (sound) +2):
largest=0
for s in getSampleIndex
largest=max(largest, getSample(s))
multiplier=32767.0/largest
louder=multipliergetSample(s)
setSample(s,louder)
| Did you try this code? It doesn't look to me like it would work yet. Mark Guzdial |
def increaseVolumeStepped(sound):
for sampleIndex in range(1,getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*0.5)
for sampleIndex in range(getLength(sound)/3, getLength(sound)/3+getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*1.2)
for sampleIndex in range (getLength(sound)/3+getLength(sound)/3,getLength(sound)+1):
largest=0
for s in getSamples(sound):
largest=max(largest,getSample(s) )
multiplier = 32767.0/largest
for s in getSamples(sound):
louder= multiplier * getSample(s)
setSample(s,louder)
I wrote this code, but I can't get it to work. Any suggestions? JES is telling me that there is a problem in the last line. I'm also not sure about how the fractions work. Does line 8 make sense?
Lauren Biddle
| Your sampleIndex loops make a lot of sense, but I don't understand why you're doing getSamples(s) inside of that. Mark Guzdial |
def increaseVolumeStepped(sound):
for sampleIndex in range(1,getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*0.5)
for sampleIndex in range(getLength(sound)/3, getLength(sound)/3+getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*1.2)
for sampleIndex in range (getLength(sound)/3+getLength(sound)/3, getLength(sound)+1):
largest=0
for s in SampleIndex(sound):
largest=max(largest,getSample(s))
multiplier = 32767.0/largest
for s in sampleIndex(sound):
louder= multiplier*sample(s)
No matter what I try, I can't figure out the last part of this problem. I can't seem to write the normalize segment correctly. Line 18 is wrong every time. What do I do?
Lauren Biddle
| You are SO close, Lauren! Here's a couple of hints: (a) you're going to end up with FOUR main loops, and NONE nested; (b) your two loops for normalizing are going to have to go from 2/3 along to the end of the sound. Mark Guzdial |
def increaseVolumeStepped(sound):
for sampleIndex in range(1,getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*0.5)
for sampleIndex in range(getLength(sound)/3, getLength(sound)/3+getLength(sound)/3):
value=getSampleValueAt(sound,sampleIndex)
setSampleValueAt(sound,sampleIndex,value*1.2)
largest=0
for sampleIndex in range (getLength(sound)/3+getLength(sound)/3, getLength(sound)+1):
value=getSampleValueAt(sound,sampleIndex)
largest=max(largest, value)
multiplier = 32767.0/largest
for s in range (getLength(sound)/3+getLength(sound)/3, getLength(sound)+1):
louder= multiplier* getSampleValueAt(sound, s)
setSampleValueAt(sound,s,louder)
Finally!!!Thanks to Chris Sung, I think I got it.
Lauren Biddle
Thank you so much for a correct answer–but what was the final consensus on being prepared to do this on the midterm since it came after friday?
| No, you don't need it for today's exam. Chris and Lauren, I think your program will work, but it will take a long to process – unnnecessarily. Move that last loop out, so that it's not indented (nested) inside the third loop. You'll have four loops at the highest level, and that's all you need. Mark Guzdial |
GO JACKETS!! CS THIRTEEN FIFTEEN IS THE BOMB
Link to this Page