Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

change a sound's loudness

# Three functions that change the volume of a sound.


# Make a sound quieter
def decreaseVolume(sound):
   for sample in getSamples(sound):
      value = getSample(sample)
      setSample(sample, value *0.5)

# Make a sound quieter
# Be careful! This can lead to clipping.
def increaseVolume(sound):
  for sample in getSamples(sound):
    value = getSample(sample)
    setSample(sample, value* 2)









# Adjust loudness of sound by maximimzing it without clipping.
def normalize(sound):

 # 1. Find loudest sample
  largest = 0
  for s in getSamples(sound):        
    largest = max(largest, getSample(s) )    
  print "Largest sample value in original sound was",  largest 

 # 2. Compute amplification factor
  amplification = 32767.0 / largest
  print ”Amplification multiplier is", amplification   

  # 3. Multiply each sample's value by that amount
  for s in getSamples(sound):      
    louder =  amplification  getSample(s)  
    setSample(s, louder)  



Link to this Page