Difference between revisions of "CSC111 Lab 5 Solutions 2014"
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 21:37, 25 February 2014 (EST) | --[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 21:37, 25 February 2014 (EST) | ||
---- | ---- | ||
+ | |||
+ | <onlydft> | ||
+ | |||
=Solution Programs for Lab #5= | =Solution Programs for Lab #5= | ||
Line 52: | Line 55: | ||
blockingPlay( sound ) | blockingPlay( sound ) | ||
+ | # ======================================================= | ||
+ | # clear waveform after "Remember" | ||
# get start index for clearing | # get start index for clearing | ||
startIndex = 13393 # index just before "the force..." | startIndex = 13393 # index just before "the force..." | ||
Line 65: | Line 70: | ||
#blockingPlay( sound ) | #blockingPlay( sound ) | ||
+ | # ======================================================= | ||
# Copy "remember" to the end of itself in the waveform | # Copy "remember" to the end of itself in the waveform | ||
rememberLength = startIndex # that's the length of the word "remember" | rememberLength = startIndex # that's the length of the word "remember" | ||
Line 75: | Line 81: | ||
# get the original sound again | # get the original sound again | ||
− | |||
sound = makeSound( file ) | sound = makeSound( file ) | ||
blockingPlay( sound ) | blockingPlay( sound ) | ||
+ | |||
+ | # ======================================================= | ||
+ | # copy Always right after Remember | ||
+ | startAlways = 30444 # index just before "Always" | ||
+ | endRemember = 8968 | ||
+ | |||
+ | # set j to the end of Remember | ||
+ | j = endRemember | ||
+ | for i in range( startAlways, noSamples ): | ||
+ | # copy from Always | ||
+ | value = getSampleValueAt( sound, i ) | ||
+ | # into waveform after Remember | ||
+ | setSampleValueAt( sound, j, value ) | ||
+ | # advance j by 1 | ||
+ | j = j+1 | ||
+ | |||
+ | # now j points to the end of the moved "Always" | ||
+ | endRememberAlways = j | ||
+ | |||
+ | # clear from the end of RememberAlways to the end of the waveform | ||
+ | for i in range( endRememberAlways, noSamples ): | ||
+ | setSampleValueAt( sound, i, 0 ) | ||
+ | |||
+ | blockingPlay( sound ) | ||
+ | |||
+ | """ | ||
+ | # ======================================================= | ||
+ | # create an echo | ||
startIndex = 13393 # index just before "the force..." | startIndex = 13393 # index just before "the force..." | ||
Line 93: | Line 126: | ||
sourceValue = getSampleValueAt( sound, i) | sourceValue = getSampleValueAt( sound, i) | ||
destValue = getSampleValueAt( sound, i+offset ) | destValue = getSampleValueAt( sound, i+offset ) | ||
− | setSampleValueAt( sound, i+offset, sourceValue + destValue ) | + | setSampleValueAt( sound, i+offset, sourceValue//3 + destValue ) |
+ | |||
+ | blockingPlay( sound ) | ||
+ | """ | ||
+ | # ======================================================= | ||
+ | # reverse the whole waveform | ||
+ | file = pickAFile() | ||
+ | sound = makeSound( file ) | ||
+ | blockingPlay( sound ) | ||
+ | |||
+ | # make j the index of the last sample in the sound | ||
+ | j = getLength(sound)-1 | ||
+ | |||
+ | # make i go from beginning of sound to half way. | ||
+ | for i in range( getLength( sound ) // 2 ): | ||
+ | # get the two samples at Index i and at Index j | ||
+ | valueAti = getSampleValueAt( sound, i ) | ||
+ | valueAtj = getSampleValueAt( sound, j ) | ||
+ | |||
+ | # swap them | ||
+ | temp = valueAti | ||
+ | valueAti = valueAtj | ||
+ | valueAtj = temp | ||
+ | |||
+ | # put the swapped versions back in sound | ||
+ | setSampleValueAt( sound, i, valueAti ) | ||
+ | setSampleValueAt( sound, j, valueAtj ) | ||
+ | |||
+ | # move j to the left by 1. The for loop moves i to the right | ||
+ | j = j-1 | ||
+ | |||
blockingPlay( sound ) | blockingPlay( sound ) | ||
</source> | </source> | ||
− | + | </onlydft> | |
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |