# a function to apply a 'fade in' to a sound

def fadeIn(sound):

  fadefactor = 0.0001 #set the starting fade factor
  i = 1 #set the starting sound sample
  while fadefactor < 1.0: #loop until fading is finished
    sample = (getSampleValueAt(sound, i))*fadefactor #calculate the faded sample
    setSampleValueAt(sound, i, sample) #write the faded sample to the sound
    fadefactor = fadefactor + 0.0001 #reduce the fading
    i = i + 1 #move to the next sample in the sound

  play(sound)

  return sound

