Difference between revisions of "CSC111 Lab 5 Solutions 2014"

From dftwiki3
Jump to: navigation, search
 
(2 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 123: 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 )
 
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 />

Latest revision as of 20:39, 9 January 2015

--D. Thiebaut (talk) 21:37, 25 February 2014 (EST)



...