123456789101112131415161718192021222324252627282930313233 |
- def audio_visualize_3d(self):
- t = np.linspace(0, 2. * np.pi, self.window * 2)
- xf = np.cos(t)
- yf = np.sin(t)
- fig = plt.figure()
- ax = fig.gca(projection='3d')
- lf, = ax.plot(xf, yf, np.zeros(self.window * 2), lw=1, color='lightblue')
- ax.set_zlim(-0.2, 1.2)
- ax.set_axis_off()
- plt.show(block=False)
- plt.pause(self.record_delay)
- while self.stream.is_active():
- data = self.stream.read(self.window)
- data_int = struct.unpack(str(self.window * 2) + 'B', data)
- z_detrend = detrend(data_int)
- zf = np.abs(np.fft.fft(z_detrend))
- z_vals = zf / (64 * self.window)
- ind = np.where(z_vals > (np.max(z_vals) + np.min(z_vals)) / 2)
- z_vals[ind[0]] *= 4
- lf.set_xdata(xf)
- lf.set_ydata(yf)
- lf.set_3d_properties(z_vals)
- try:
- ax.figure.canvas.draw()
- ax.figure.canvas.flush_events()
- except TclError:
- self.stream.stop_stream()
- self.stream.close()
- break
|