Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CHANNELS = 2
- RATE = 44100
- class Sound(object):
- def __init__(self,balloon):
- self.t = time()
- self.freq = self.get_freq()
- self.phase = 0
- self.p = pyaudio.PyAudio()
- self.stream = self.p.open(format=pyaudio.paFloat32,
- channels=CHANNELS,
- rate=RATE,
- output=True,
- stream_callback=self.callback)
- self.stream.start_stream()
- def callback(self,in_data, frame_count, time_info, status):
- bal = self.get_balance() #number between 1 and 0
- right = (np.sin(self.phase+2*np.pi*self.freq*(self.t+np.arange(frame_count)/float(RATE))))
- data = np.zeros((right.shape[0]*2,),np.float32)
- data[::2] = bal*right #right speaker
- data[1::2] = (1-bal)*right #left speaker
- self.t+=frame_count/float(RATE)
- return (data, pyaudio.paContinue)
- data[::2] = right #right speaker
- data[1::2] = right #left speaker
Advertisement
Add Comment
Please, Sign In to add comment