Difference between revisions of "CSC111 Sound Modification Exercises"

From dftwiki3
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 10:17, 26 February 2014 (EST)
 
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 10:17, 26 February 2014 (EST)
 
----
 
----
<onlydft>
+
 +
=First we solve it in Pure Python with a List of integers=
 
<source lang="python">
 
<source lang="python">
 
# playing with an array of numbers
 
# playing with an array of numbers
Line 68: Line 69:
 
      
 
      
 
</source>
 
</source>
</onlydft>
+
=Then we apply the Algorithm to JES=
 +
<source lang="python">
 +
file = pickAFile()
 +
sound = makeSound( file )
 +
blockingPlay( sound )
 +
 
 +
startClear = 10561
 +
noSamples = getLength( sound )
 +
 
 +
for i in range( startClear, noSamples ):
 +
  setSampleValueAt( sound, i, 0 )
 +
 
 +
blockingPlay( sound )
 +
 
 +
lenSeq = 10502
 +
startRepeat = 4071
 +
for i in range( lenSeq-1, -1, -1 ):
 +
  j = i + startRepeat
 +
  valueRight = getSampleValueAt( sound, j )
 +
  valueLeft  = getSampleValueAt( sound, i )
 +
  setSampleValueAt( sound, j, valueRight + valueLeft/3 )
 +
 
 +
blockingPlay( sound )
 +
 
 +
</source>
 +
 
 
<br />
 
<br />
 
<br />
 
<br />

Latest revision as of 12:32, 26 February 2014

--D. Thiebaut (talk) 10:17, 26 February 2014 (EST)


First we solve it in Pure Python with a List of integers

# playing with an array of numbers
# to practice using JES for playing with sounds
# 
array = [2,3,4,1,10,1,-1,2,1]
print( "len(sound) = ", len( array ) )

#--- different ways to print the array ---
for sample in array:
    print( sample, end=" " )
print()

for i in range( len( array ) ):
    sample = array[i]
    print( sample, end=" " )
print()

for sample in [2,3,4,1,10,1,-1,2,1]:
    print( sample, end=" " )
print()

#--- clear array starting at Index 4 ---
startIndex = 4

for i in range( startIndex, len( array ) ):
    array[i] = 0

print( "version with cleared end:", array )

#--- reverse array ---
for i in range( 0, len( array )//2 ):
    j = len( array )-1 - i
    #print( i, j )
    temp = array[i]
    array[i] = array[j]
    array[j] = temp

print( "reversed version = ", array )

#--- get original back with cleared end ---
array = [2, 3, 4, 1, 0, 0, 0, 0, 0]
copyLen = 6  # want to copy sequence of first 4 at end of itself
for i in range( 0, copyLen ):
    j = i+copyLen
    #print( i, j )
    if j < len( array ):
        array[j] = array[i]

print( "array with copied sequence: " , array )

#--- echo ---
#--- get original back with cleared end ---
array = [2, 3, 4, 1, 0, 0, 0, 0, 0]
lenSeq = 4
startRepeat = 2
for i in range( lenSeq-1, -1, -1 ):
    j = i+startRepeat
    print( i, j )
    valueRight = array[j]
    valueLeft  = array[i]
    array[j] = valueRight + valueLeft/2

print( "echoed array = ", array )

Then we apply the Algorithm to JES

file = pickAFile()
sound = makeSound( file )
blockingPlay( sound )

startClear = 10561
noSamples = getLength( sound )

for i in range( startClear, noSamples ):
  setSampleValueAt( sound, i, 0 )
  
blockingPlay( sound )

lenSeq = 10502
startRepeat = 4071
for i in range( lenSeq-1, -1, -1 ):
  j = i + startRepeat
  valueRight = getSampleValueAt( sound, j )
  valueLeft  = getSampleValueAt( sound, i )
  setSampleValueAt( sound, j, valueRight + valueLeft/3 )
  
blockingPlay( sound )