Difference between revisions of "CSC111 Lab 5 Solutions 2014"
Line 42: | Line 42: | ||
""" | """ | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
# JES Program | # JES Program | ||
# JES program to take a sound file and play with it | # JES program to take a sound file and play with it |
Revision as of 17:17, 27 February 2014
--D. Thiebaut (talk) 21:37, 25 February 2014 (EST)
Solution Programs for Lab #5
# lab5 solution programs (loops)
# D. Thiebaut
# single For-Loops
"""
for i in range( 3, 8 ):
print( i, end=" ")
print()
for i in [3, 4, 5, 6, 7]:
print( i, end=" " )
print()
for i in range( 4, 20+1, 2 ):
print( i, end=" " )
print()
for i in range( -3, 19+1, 2 ):
print( i, end=" " )
print()
start = int( input( "start where? " ) )
end = int( input( "end where? " ) )
if start <= end:
for i in range( start, end+1 ):
print( i, end=" " )
else:
for i in range( start, end-1, -1 ):
print( i, end=" " )
print()
for i in range( 11 ):
print( "%s%s----%s%s" % ( i*'*', i*'..', i*'-', i*'??' ) )
"""
# JES Program
# JES program to take a sound file and play with it
# D. Thiebaut
#
file = pickAFile()
sound = makeSound( file )
blockingPlay( sound )
# get start index for clearing
startIndex = 13393 # index just before "the force..."
# get the number of samples in the sound file
noSamples = getLength( sound )
# clear all the samples from startIndex to end:
for i in range( startIndex, noSamples ):
setSampleValueAt( sound, i, 0 )
# play sound again
#blockingPlay( sound )
# Copy "remember" to the end of itself in the waveform
rememberLength = startIndex # that's the length of the word "remember"
for i in range( 0, startIndex ):
value = getSampleValueAt( sound, i )
setSampleValueAt( sound, i+rememberLength, value )
# play sound: "remember, remember"
blockingPlay( sound )
# get the original sound again
# and clear all but the word "remember"
sound = makeSound( file )
blockingPlay( sound )
startIndex = 13393 # index just before "the force..."
noSamples = getLength( sound )
# clear all the samples from startIndex to end:
for i in range( startIndex, noSamples ):
setSampleValueAt( sound, i, 0 )
# overlap remember on top of itself, starting at Index 6000
# which is roughly half the length of the word
endOfRemember = 13393
offset = 6000
for i in range( endOfRemember, 0, -1 ):
sourceValue = getSampleValueAt( sound, i)
destValue = getSampleValueAt( sound, i+offset )
setSampleValueAt( sound, i+offset, sourceValue + destValue )
blockingPlay( sound )