def setUp(self): self.n_channels = 2 self.buff32 = AudioBuffer(16, self.n_channels) self.data_str = '\x01\x02\x03\x04' self.data_strs = [ '\x01\x02\x03\x04', '\x01\x02\x03\x04', '\x01\x02', '\x01', '\x01' ] self.num_types = 5 self.data12 = [''] * self.num_types for i in range(len(self.data_strs)): self.data12[i] = self.data_str * self.n_channels * 12
def testReduceChannels(self): n_in = 7 n_out = 2 n_samples = 10 data_in = np.arange(n_in * n_samples) buf = AudioBuffer(n_samples, n_in) data_out = buf.reduce_channels(data_in, n_in, n_out) correct = [ x for x in range(n_in * n_samples) if x % n_in == 0 or (x - 1) % n_in == 0 ] self.assertListFloatEqual(correct, data_out)
PLOT_POLAR = True EXTERNAL_PLOT = False PLAY_AUDIO = False TIMEOUT = 1 # Setup mics mic_layout = np.array([[-.03, 0], [.01, 0], [-.01, 0], [.03, 0]]) # Track whether we have quit or not done = False # Events for signaling new data is available audio_produced_event = threading.Event() data_produced_event = threading.Event() # Setup data buffers - use 4 * buffer length in case data get's backed up # at any point, so it will not be lost in_buf = AudioBuffer(length=4 * FRAMES_PER_BUF, n_channels=NUM_CHANNELS_IN) out_buf = AudioBuffer(length=4 * FRAMES_PER_BUF, n_channels=NUM_CHANNELS_OUT) def read_in_data(in_data, frame_count, time_info, status_flags): if done: # Must do this or calls to stop_stream may not succeed return None, pyaudio.paComplete write_num = in_buf.get_available_write() if write_num > frame_count: write_num = frame_count in_buf.write_bytes(in_data[:(write_num * SAMPLE_SIZE * NUM_CHANNELS_IN)]) in_buf.notify_of_audio() return None, pyaudio.paContinue def write_out_data(in_data, frame_count, time_info, status_flags):
MIC_ABOVE = np.array([0, 0, 1]) CAMERA_LOC = np.array([0, 0, 0]) # Setup mics mic_layout = np.array([[.03, 0], [-.01, 0], [.01, 0], [-.03, 0]]) # Track whether we have quit or not done = False switch_beamforming = False # Switch beamforming from on to off or off to on # Events for signaling new data is available audio_produced_event = threading.Event() data_produced_event = threading.Event() # Setup data buffers - use 4 * buffer length in case data get's backed up # at any point, so it will not be lost in_buf = AudioBuffer(length=4 * FRAMES_PER_BUF, n_channels=NUM_CHANNELS_IN) out_buf = AudioBuffer(length=4 * FRAMES_PER_BUF, n_channels=NUM_CHANNELS_OUT) # Setup record buffer N_SECS_RECORD = 20 N_RECORD_FRAMES = N_SECS_RECORD * SAMPLE_RATE record_buf = AudioBuffer(length=N_RECORD_FRAMES, n_channels=NUM_CHANNELS_OUT) def read_in_data(in_data, frame_count, time_info, status_flags): if done: # Must do this or calls to stop_stream may not succeed return None, pyaudio.paComplete write_num = in_buf.get_available_write() if write_num > frame_count: write_num = frame_count in_buf.write_bytes(in_data[:(write_num * SAMPLE_SIZE * NUM_CHANNELS_IN)])