def start(self, quit_event=None, show=None):
stream = self.pyaudio_instance.open(
rate=RATE,
frames_per_buffer=FRAMES,
format=pyaudio.paInt16,
channels=2,
input=True,
# output_device_index=1,
stream_callback=self._callback)
self.event.clear()
if not quit_event:
quit_event = threading.Event()
phat = [0] * (2 * direction_n + 1)
while not (quit_event.is_set() or self.event.is_set()):
try:
data = self.queue.get()
buf = np.fromstring(data, dtype='int16')
tau, cc = gcc_phat(buf[0::2] * window, buf[1::2] * window, fs=RATE, max_tau=max_tau, interp=1)
theta = math.asin(tau / max_tau) * 180 / math.pi
print('\ntheta: {}'.format(int(theta)))
for i, v in enumerate(cc):
phat[i] = int(v * 512)
if show:
show(phat)
# print [l for l in level]
except KeyboardInterrupt:
break
stream.close()
评论列表
文章目录