Posted By

svleeuwen on 11/08/11

Statistics

Viewed 233 times
Favorited by 0 user(s)

Playing with sound

/ Published in: Python  Copy this code and paste it in your HTML
2. # Due Wednesday October 12th
3. import sound
4. import time
5.
6. def rem_vocals(snd):
7. #Return a copy of sound with vocals removed
8.
9. new_snd = sound.copy(snd)
10. for sample in new_snd:
11. left = sound.get_left(sample)
12. right = sound.get_right(sample)
13. delete_vocals = (left - right)/2.0
14. sound.set_left(sample,int(delete_vocals))
15. sound.set_right(sample,int(delete_vocals))
16. return new_snd
18. #Return a copy of sound with the beginning faded. Number of samples faded is defined by fade_length
19.
20. '''Return original sound snd with selected number of samples faded in via new_snd'''
21. new_snd2 = sound.copy(snd)
23. #required due to samples starting at 0, not 1
24. index = 0
25. for samp in new_snd2:
26. index = sound.get_index(samp)
29. #Tracks number of samples done, is also used as the fade factor
32. sound.set_left(samp, int(left2))
33. sound.set_right(samp,int(right2))
34. return new_snd2
36. #Return a copy of sound with the end faded. Number of samples faded is defined by fade_length
37.
38. '''Return original sound snd with selected number of samples faded out via new_snd'''
39. new_snd=sound.copy(snd)
43. #tracks the number of untouched samples
45. samp_index=0
46. for samp in new_snd:
47. samp_index=sound.get_index(samp)
49. # if we have reached the point to begin fading,then below
50. if samp_index == len(snd)-1:
52. #if at last sample, fade factor is set to zero
56. sound.set_left(samp, int(left))
57. sound.set_right(samp,int(right))
58. samp_todo-= 1
59.
60. #Tracks number of samples done,starts at one and ends at zero
61. return new_snd
63. #Returns a copy of sound with the beginning and ending faded.Number of samples faded is defined by fade_legnth
64.
65. new_snd=sound.copy(snd)
68. return new_snd
69. '''Return original sound snd with selected number of samples
70. faded in and out via new_snd'''
71. #new_snd = sound.copy(snd)
74. ##tracks the number of untouched samples
76. #index = 0
78. #for samp in new_snd:
79. #samp_index=sound.get_index(samp)
84. #sound.set_left(samp, int(left2))
85. #sound.set_right(samp,int(right2))
87. #if samp_index == len(snd)-1:
91. #sound.set_left(samp, int(left))
92. #sound.set_right(samp,int(right))
93. #samp_todo-=1
95. #return new_snd
96.
97. def left_to_right (snd, pan_length):
98. #Returns a copy of sound with panning applied to it. Left starts at 0,right starts at max
99. '''Return original sound snd with selected samples panned to the right
100. and others to the left via new_snd'''
101. new_snd= sound.copy(snd)
102. samps_to_pan = pan_length - 1
103. index = 0
106. for samp in new_snd :
107. if index <= samps_to_pan :
108. left = sound.get_left(samp)
109. right = sound.get_right(samp)
110. avg= (left+right)/2.0
115. sound.set_values(samp,left,right)
116. index+=1
117. return new_snd
118.
119. if __name__ == "__main__": Subscribe to comments