Difference between revisions of "CSC111 Lab 3 Solution"
(Created page with 'Here are some program that can be used for different sound operations: <source lang="python"> def part4(): # reverses sound1 into sound2 file = pickAFile() sound1 = makeSo…') |
|||
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
<source lang="python"> | <source lang="python"> | ||
+ | # ------------------------------------------------------ | ||
def part4(): | def part4(): | ||
# reverses sound1 into sound2 | # reverses sound1 into sound2 | ||
Line 17: | Line 18: | ||
blockingPlay( sound2 ) | blockingPlay( sound2 ) | ||
+ | # ------------------------------------------------------ | ||
def part5(): | def part5(): | ||
# reverses sound1 into sound2 | # reverses sound1 into sound2 | ||
Line 33: | Line 35: | ||
blockingPlay( sound1 ) | blockingPlay( sound1 ) | ||
+ | # ------------------------------------------------------ | ||
def part6(): | def part6(): | ||
# copy a sound to a different place (offset) | # copy a sound to a different place (offset) | ||
Line 50: | Line 53: | ||
blockingPlay( sound2 ) | blockingPlay( sound2 ) | ||
+ | # ------------------------------------------------------ | ||
def part7(): | def part7(): | ||
# make tow copies of sound1 into sound2 | # make tow copies of sound1 into sound2 | ||
Line 75: | Line 79: | ||
blockingPlay( sound2 ) | blockingPlay( sound2 ) | ||
+ | # ------------------------------------------------------ | ||
def part8(): | def part8(): | ||
# make tow copies of sound1 into sound2 | # make tow copies of sound1 into sound2 | ||
Line 100: | Line 105: | ||
blockingPlay( sound2 ) | blockingPlay( sound2 ) | ||
+ | # ------------------------------------------------------ | ||
def part9(): | def part9(): | ||
# make tow copies of sound1 into sound2 | # make tow copies of sound1 into sound2 | ||
Line 132: | Line 138: | ||
blockingPlay( sound2 ) | blockingPlay( sound2 ) | ||
+ | # ------------------------------------------------------ | ||
def part10(): | def part10(): | ||
# A more general version of Part9() | # A more general version of Part9() | ||
Line 153: | Line 160: | ||
</source> | </source> | ||
+ | |||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | <br /> | ||
+ | [[Category:CSC111]][[Category:Jes]][[Category:Python]] |
Latest revision as of 20:33, 11 February 2010
Here are some program that can be used for different sound operations:
# ------------------------------------------------------
def part4():
# reverses sound1 into sound2
file = pickAFile()
sound1 = makeSound( file )
sound2 = makeSound( file )
N = getLength( sound1 )
for i in range( 1, N ):
s = getSampleValueAt( sound1, i )
j = N-i
setSampleValueAt( sound2, j, s )
blockingPlay( sound1 )
blockingPlay( sound2 )
# ------------------------------------------------------
def part5():
# reverses sound1 into sound2
file = pickAFile()
sound1 = makeSound( file )
blockingPlay( sound1 )
N = getLength( sound1 )
for i in range( 1, N/2 ):
s1 = getSampleValueAt( sound1, i )
j = N-i
s2 = getSampleValueAt( sound1, j )
setSampleValueAt( sound1, i, s2 )
setSampleValueAt( sound1, j, s1 )
blockingPlay( sound1 )
# ------------------------------------------------------
def part6():
# copy a sound to a different place (offset)
# into an empty sound object (twice as long)
file = pickAFile()
sound1 = makeSound( file )
N = getLength( sound1 )
blockingPlay( sound1 )
sound2 = makeEmptySound( N * 2 )
offset = 15000
for i in range( 1, N ):
s = getSampleValueAt( sound1, i )
j = i+offset
setSampleValueAt( sound2, j, s )
blockingPlay( sound2 )
# ------------------------------------------------------
def part7():
# make tow copies of sound1 into sound2
# one at offset 0, one at offset 15000
file = pickAFile()
sound1 = makeSound( file )
N = getLength( sound1 )
blockingPlay( sound1 )
sound2 = makeEmptySound( N * 2 )
offset = 0
for i in range( 1, N ):
s = getSampleValueAt( sound1, i )
j = i+offset
setSampleValueAt( sound2, j, s )
offset = 15000
for i in range( 1, N ):
s1 = getSampleValueAt( sound1, i )
j = i+offset
s2 = getSampleValueAt( sound2, j )
setSampleValueAt( sound2, j, s1+s2 )
blockingPlay( sound2 )
# ------------------------------------------------------
def part8():
# make tow copies of sound1 into sound2
# one at offset 0, one at offset 15000
file = pickAFile()
sound1 = makeSound( file )
N = getLength( sound1 )
blockingPlay( sound1 )
sound2 = makeEmptySound( N * 2 )
offset = 0
for i in range( 1, N ):
s = getSampleValueAt( sound1, i )
j = i+offset
setSampleValueAt( sound2, j, s )
offset = 7000
for i in range( 1, N ):
s1 = getSampleValueAt( sound1, i )
j = i+offset
s2 = getSampleValueAt( sound2, j )
setSampleValueAt( sound2, j, s1/2 + s2 )
blockingPlay( sound2 )
# ------------------------------------------------------
def part9():
# make tow copies of sound1 into sound2
# one at offset 0, one at offset 14000
file = pickAFile()
sound1 = makeSound( file )
N = getLength( sound1 )
blockingPlay( sound1 )
sound2 = makeEmptySound( N * 2 )
offset = 0
for i in range( 1, N ):
s = getSampleValueAt( sound1, i )
j = i+offset
setSampleValueAt( sound2, j, s )
offset = 7000
for i in range( 1, N ):
s1 = getSampleValueAt( sound1, i )
j = i+offset
s2 = getSampleValueAt( sound2, j )
setSampleValueAt( sound2, j, s1/2 + s2 )
offset = 14000
for i in range( 1, N ):
s1 = getSampleValueAt( sound1, i )
j = i+offset
s2 = getSampleValueAt( sound2, j )
setSampleValueAt( sound2, j, s1/4 + s2 )
blockingPlay( sound2 )
# ------------------------------------------------------
def part10():
# A more general version of Part9()
file = pickAFile()
sound1 = makeSound( file )
N = getLength( sound1 )
blockingPlay( sound1 )
sound2 = makeEmptySound( N * 2 )
divider = 1
for offset in [0, 7000, 14000 ]:
for i in range( 1, N ):
s1 = getSampleValueAt( sound1, i )
j = i+offset
s2 = getSampleValueAt( sound2, j )
setSampleValueAt( sound2, j, s1/divider + s2 )
divider = divider * 2
blockingPlay( sound2 )