def run(sample_queue): # streaming.py Settings stream.EASY_DSP_BOARD_IP_ADDRESS = '10.42.0.2' stream.EASY_DSP_WSAUDIO_SERVER_PORT = 7321 stream.EASY_DSP_WSCONFIG_SERVER_PORT = 7322 stream.sample_rate = EASY_DSP_AUDIO_FREQ_HZ stream.channel_count = EASY_DSP_NUM_CHANNELS stream.frame_count = EASY_DSP_AUDIO_BUFFER_SIZE_BYTES // (EASY_DSP_NUM_CHANNELS * EASY_DSP_AUDIO_FORMAT_BYTES) stream.volume = EASY_DSP_VOLUME def handle_samples(buffer): # printProgress( # "handle_buffer: received {count} bytes | shape {shape} | type {dtype}".format(count=buffer.nbytes, # shape=buffer.shape, # dtype=buffer.dtype)) sample_queue.put(buffer) def handle_config(args=None): print("handle_config: new config ({frames},{sampleRate},{channelCount},{volume})".format( frames=stream.frame_count, sampleRate=stream.sample_rate, channelCount=stream.channel_count, volume=stream.volume)) stream.change_config() stream.process_samples = handle_samples stream.process_config = handle_config stream.start() stream.loop_callbacks()
def run(q_samples): streaming.EASY_DSP_BOARD_IP_ADDRESS = '10.42.0.2' streaming.EASY_DSP_WSAUDIO_SERVER_PORT = 7321 streaming.EASY_DSP_WSCONFIG_SERVER_PORT = 7322 streaming.sample_rate = EASY_DSP_AUDIO_FREQ_HZ streaming.channel_count = EASY_DSP_NUM_CHANNELS streaming.frame_count = EASY_DSP_AUDIO_BUFFER_SIZE_BYTES // (EASY_DSP_NUM_CHANNELS * EASY_DSP_AUDIO_FORMAT_BYTES) streaming.volume = EASY_DSP_VOLUME def handle_samples(buffer): """ Add incoming audio buffer to sample queue. Parameters ---------- buffer : :py:class:`~numpy.ndarray` (N_sample, N_channel) audio packet """ msg = ('handle_samples: ' f'received={buffer.nbytes} bytes, ' f'shape={buffer.shape}, ' f'type={buffer.dtype}') print(msg) q_samples.put(buffer) def handle_config(args=None): msg = ('handle_config: new_config=(' f'{streaming.frame_count}, ' f'{streaming.sample_rate}, ' f'{streaming.channel_count}, ' f'{streaming.volume})') print(msg) streaming.change_config() streaming.process_samples = handle_samples streaming.process_config = handle_config streaming.start() streaming.loop_callbacks()
### Define Callbacks ################################################################################################### def handle_samples(buffer): printProgress( "handle_buffer: received {count} bytes | shape {shape} | type {dtype}". format( count=buffer.nbytes, shape=buffer.shape, dtype=buffer.dtype, )) def handle_config(args=None): printProgress( "handle_config: new config ({frames},{sampleRate},{channelCount},{volume})" .format(frames=stream.frame_count, sampleRate=stream.sample_rate, channelCount=stream.channel_count, volume=stream.volume)) ######################################################################################################################## if __name__ == '__main__': stream.change_config() stream.process_samples = handle_samples stream.process_config = handle_config stream.start() stream.loop_callbacks()
""" Parameters ---------- buffer : :py:class:`~numpy.ndarray` (N_sample, N_channel) audio packet """ msg = ('handle_samples: ' f'received={buffer.nbytes} bytes, ' f'shape={buffer.shape}, ' f'type={buffer.dtype}') print(msg) def handle_config(args=None): msg = ('handle_config: new_config=(' f'{streaming.frame_count}, ' f'{streaming.sample_rate}, ' f'{streaming.channel_count}, ' f'{streaming.volume})') print(msg) ################################################################################ if __name__ == '__main__': streaming.change_config() streaming.process_samples = handle_samples streaming.process_config = handle_config streaming.start() streaming.loop_callbacks()