Difference between revisions of "CSC111 Lab 5 Solutions 2014"
(→Solution Programs for Lab #5) |
|||
(One intermediate revision 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 127: | Line 130: | ||
blockingPlay( sound ) | 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 ) | ||
</source> | </source> | ||
− | + | </onlydft> | |
+ | |||
<br /> | <br /> | ||
<br /> | <br /> |