Guest User

Untitled

a guest
Jul 14th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. CHANNELS = 2
  2. RATE = 44100
  3. class Sound(object):
  4. def __init__(self,balloon):
  5. self.t = time()
  6. self.freq = self.get_freq()
  7. self.phase = 0
  8. self.p = pyaudio.PyAudio()
  9. self.stream = self.p.open(format=pyaudio.paFloat32,
  10. channels=CHANNELS,
  11. rate=RATE,
  12. output=True,
  13. stream_callback=self.callback)
  14. self.stream.start_stream()
  15.  
  16. def callback(self,in_data, frame_count, time_info, status):
  17. bal = self.get_balance() #number between 1 and 0
  18. right = (np.sin(self.phase+2*np.pi*self.freq*(self.t+np.arange(frame_count)/float(RATE))))
  19. data = np.zeros((right.shape[0]*2,),np.float32)
  20. data[::2] = bal*right #right speaker
  21. data[1::2] = (1-bal)*right #left speaker
  22. self.t+=frame_count/float(RATE)
  23. return (data, pyaudio.paContinue)
  24.  
  25. data[::2] = right #right speaker
  26. data[1::2] = right #left speaker
Advertisement
Add Comment
Please, Sign In to add comment