From 6d8db8043ee693c2e494fa565bd8ad5b49797920 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 17 Jan 2016 15:14:44 +0100 Subject: [PATCH] python/demos/demo_pysoundcard_*: update to pysoundcard 0.5.2 (closes #42) --- python/demos/demo_pysoundcard_play.py | 2 +- python/demos/demo_pysoundcard_record.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/python/demos/demo_pysoundcard_play.py b/python/demos/demo_pysoundcard_play.py index b0bf70c1..3517d623 100755 --- a/python/demos/demo_pysoundcard_play.py +++ b/python/demos/demo_pysoundcard_play.py @@ -10,7 +10,7 @@ def play_source(source_path): f = source(source_path, hop_size = hop_size) samplerate = f.samplerate - s = Stream(sample_rate = samplerate, block_length = hop_size) + s = Stream(samplerate = samplerate, blocksize = hop_size) s.start() read = 0 while 1: diff --git a/python/demos/demo_pysoundcard_record.py b/python/demos/demo_pysoundcard_record.py index 56a7fbc1..e3816d2a 100755 --- a/python/demos/demo_pysoundcard_record.py +++ b/python/demos/demo_pysoundcard_record.py @@ -8,17 +8,22 @@ def record_sink(sink_path): hop_size = 256 duration = 5 # in seconds - s = Stream(block_length = hop_size) - g = sink(sink_path, samplerate = s.sample_rate) + s = Stream(blocksize = hop_size, channels = 1) + g = sink(sink_path, samplerate = int(s.samplerate)) + print s.channels s.start() total_frames = 0 - while total_frames < duration * s.sample_rate: - vec = s.read(hop_size) - # mix down to mono - mono_vec = vec.sum(-1) / float(s.input_channels) - g(mono_vec, hop_size) - total_frames += hop_size + try: + while total_frames < duration * s.samplerate: + vec = s.read(hop_size) + # mix down to mono + mono_vec = vec.sum(-1) / float(s.channels[0]) + g(mono_vec, hop_size) + total_frames += hop_size + except KeyboardInterrupt, e: + print "stopped after", "%.2f seconds" % (total_frames / s.samplerate) + pass s.stop() if __name__ == '__main__': -- 2.11.0