ref: 6d8db8043ee693c2e494fa565bd8ad5b49797920
parent: 0e39e88682fa5034d05fc93608c5c3608478b098
author: Paul Brossier <piem@piem.org>
date: Sun Jan 17 10:14:44 EST 2016
python/demos/demo_pysoundcard_*: update to pysoundcard 0.5.2 (closes #42)
--- a/python/demos/demo_pysoundcard_play.py
+++ b/python/demos/demo_pysoundcard_play.py
@@ -10,7 +10,7 @@
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:
--- a/python/demos/demo_pysoundcard_record.py
+++ b/python/demos/demo_pysoundcard_record.py
@@ -8,17 +8,22 @@
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__':