![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
def upDown():
source=makeSound(sound)
target=makeSound(sound)
targetIndex=1
half=(getLength(source)/2)+1
for sourceIndex in range(1,half):
value=getSampleValueAt(source,sourceIndex)
setSampleValueAt(target,targetIndex,value*2)
targetIndex=targetIndex+1
for sourceIndex in range(half,(getLength(source)+1):
value=getSampleValueAt(source,sourceIndex)
setSampleValueAt(target,targetIndex,int(value/2))
targetIndex=targetIndex+1
| Don't forget to use code tags when you post your code! :) You have a few problems with this code, primarily in defining variables before you use them. 1.where do you define "value2" in the first for loop, or did you want value*2? 2.where do you increase your targetIndex in the second loop? 3.do you need to redefine value within the second loop? (hint, if you don't, you won't hear any sound) 4.Can you set a sample value to a sample that has a decimal place? (This deals with the division in the second loop) Amanda Bennett |
def splice():
source=makeSound(sound1)
target=makeSound(sound2)
r=getSamplingRate(source)
r2=getSamplingRate(target)
targetIndex=2*r2
for s in range (r,.5*r):
v=getSampleValueAt(source,s)
setSampleValueAt(target,targetIndex,v)
targetIndex=targetIndex+1
return target
def move():
sound=makeSound(sound)
sound2=makeSound(sound)
r=getSamplingRate(sound)
targetIndex=2*r
for s in range(4*r,5r+1):
v=getSampleValueAt(sound,s)
setSampleValueAt(sound2,targetIndex,v)
targetIndex=targetIndex+1
return sound2
def upDown (sound):
for i in range (1, getLength (sound)/2):
value=getSampleValueAt(sound, i)
value=value*2
setSampleValueAt(sound,i,value)
for i in range (getLength(sound)/2,getLength(sound)):
value=getSampleValueAt(sound, i)
value=value/2
setSampleValueAt(sound,i,value)
return sound
def changeSound(sound):
targetIndex=88200
for i in range(176400,220500):
value=getSampleValueAt(sound,i)
setSampleValueAt(sound,targetIndex,value)
targetIndex=targetIndex+1
return sound
def pasteSound(sourceSound, targetSound):
source=makeSound(sourceSound)
target=makeSound(targetSound)
targetIndex=44100
for s in range(22051,33075):
value=getSampleValueAt(source,s)
setSampleValueAt(target,targetIndex,value)
targetIndex=targetIndex+1
return target
def sound3(sound):
rate = getSamplingRate(sound)
start = rate*4
end = rate*5
targetindex = rate * 2
for index in range(start, end):
value = getSampleValueAt(sound,index)
setSampleValueAt(sound, targetindex, value)
targetindex = targetindex + 1
return sound