Rewrite Program 100 so that you normalize the first second of a sound, then slowly decrease the sound in steps of 1/5 for each following second. (How many samples are in a second? getSamplingRate is the number of samples per second for the given sound.)

What will be an ideal response?


```
def increaseAndDecrease3(sound):
sampleRate = getSamplingRate(sound)
largest = -1
#Normalize
for sampleIndex in range(0,sampleRate):
largest = max(largest ,getSampleValueAt(sound, sampleIndex) )

multiplier = 32767.0 / largest

for sampleIndex in range(0,sampleRate):
louder = multiplier * getSampleValueAt(sound, sampleIndex)
setSampleValueAt(sound, sampleIndex,louder)

#Decrease by fifths
for sampleIndex in range(sampleRate, getLength(sound)):
amntToDecreaseBy = (int(sampleIndex)/int(sampleRate))*0.2
newVal = getSampleValueAt(sound, sampleIndex)*(1.0-amntToDecreaseBy)
setSampleValueAt(sound, sampleIndex,newVal)
```

Note: The first section is just a translation of Program 97. The second section “decreases” by making use of integer division, and then multiplying by (1amntToDeceaseBy) as multiplying by just amntToDecreaseBy would have the effect of increasing the values with time. Additionally, its worth noting that this function assumes a sound with a length greater than one, and that with sounds past six seconds in length
it will begin to show strange results as you’ll be multiplying by negative values.

Computer Science & Information Technology

You might also like to view...

Briefly describe the four common learning styles.

What will be an ideal response?

Computer Science & Information Technology

HUD is an acronym meaning Heads Up Display.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A web service’s methods can be called by methods on other machines using ___________.

a) Representational State Transfer (REST) architecture b) Simple Object Access Protocol c) Both (a) and (b). d) None of the above.

Computer Science & Information Technology

Which of the following is a correct name for the function that calculates an average of values?

A. AVG B. AVERAGE C. MEAN D. AVGVAL

Computer Science & Information Technology