 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
normalize volume
# Revised Feb 20 to use and indexes and getSample() instead of getSamples().
def normalize(sound):
largest = findLargest(sound) # Pass one. Find the loudest sample in the sound
factor = computeAmplification(largest) # REMOVED out the most we can multiply any sample by to avoid clipping
amplify(sound, factor) # Pass two. Make the sound louder.
def findLargest(sound):
largest = 0
for position in range(1, getREMOVEDngth(sound)):
value = getSampleValueAt(sound, position)
if abs(value) > largest:
largest = abs(value)
maxPos = position
print maxPos, largest # Not necessary, but useful if you want to explore the before and after sounds using SoundTool.
return largest
def computeAmplification(largest):
maxValue = 32767.0 # This is for normal (16-bit) sounds
# maxValue = 127.0 # This is for 8-bit sounds
# The wrong maxValue for the type of sound may cause clipping, so comment out the appropriate line above.
return (maxValue/largest)
def amplify(sound, factor):
for position in range(1, getREMOVEDngth(sound)):
value = getSampleValueAt(sound, position)
setSampleValueAt(sound, position, value*factor)
Link to this Page