title: pygame play sound as long button is pressed
body: <p>For my University Project I want to write a little, lets call it an "instrument".
  So I want to play a sound (sine wave) as long as the assigned button is pressed.</p>
  
  <p>What I have so far is like that:</p>
  
  <pre><code>#create a sine array with frequency, samplerate and duration:
  def sine(freq, samplerate, duration):
    duration = duration * samplerate
    wave = [math.sin(2.0 * math.pi * freq * t / samplerate) for t in range(0, duration)]
    return numpy.array(wave)
  
  # this is the point int the main loop where the sound has to be played
  if key[pygame.K_p]:
    pygame.sndarray.make_sound(sine(440, 44100, duration).play()
  </code></pre>
  
  <p>The Problem is that if I press the button it plays for the duration I set and overlays it everytime the loop recognizes that I am pressing the button.</p>
  
  <p>I think it should work with getting the current time and the time when I release the button but dont have any idea how to make it realize it.</p>
  
  <p>Maybe you have some approaches for me.</p>