CSC111 Sample JES code

From dftwiki3
Revision as of 19:47, 9 February 2010 by Thiebaut (talk | contribs) (Created page with '--~~~~ ---- <source lang="python"> def main0(): file = pickAFile() sound = makeSound( file ) blockingPlay( sound ) def main1(): # select a sound file file = pickAFi…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut 00:47, 10 February 2010 (UTC)


def main0():
  file = pickAFile()
  sound = makeSound( file )
  blockingPlay( sound )
  
def main1():
  # select  a sound file
  file = pickAFile()
  sound = makeSound( file )
 
  # play it
  blockingPlay( sound )
 
  # lower its intensity by half
  for i in range( 0, getLength( sound ) ):
     value = getSampleValueAt( sound, i )    # get the value of the i-th sample
     setSampleValueAt( sound, i, value / 2 )  # set the sample to half its original value
 
  # play new waveform back
  blockingPlay( sound )
 
def main2():
  # select  a sound file
  file =  pickAFile()
  sound1 = makeSound( file )
  sound2 = makeSound( file )
  sound3 = makeSound( file )
  
  blockingPlay( sound1 )
  
  for i in range( 0, getLength( sound2 ) ):
     value = getSampleValueAt( sound2, i )    # get the value of the i-th sample
     setSampleValueAt( sound2, i, value / 2 )  # set the sample to half its original value

  print "number of samples = ", getLength( sound1 )
  for i in range( 5500, getLength( sound1 ) ):
    i1 = i
    i2 = i-5500
    i3 = i
    value1 = getSampleValueAt( sound1, i1 )
    value2 = getSampleValueAt( sound2, i2 )
    setSampleValueAt( sound3, i3, value1+value2 )
    
  blockingPlay( sound3 )