summaryrefslogtreecommitdiff
path: root/contrib/python/pyrtaudio/PyRtAudioTest.py
diff options
context:
space:
mode:
authorGary Scavone <gary@music.mcgill.ca>2011-04-13 00:50:38 +0000
committerStephen Sinclair <sinclair@music.mcgill.ca>2013-10-11 01:38:27 +0200
commit6faf4336eb5952b141e1c239d194f5cd70f0a885 (patch)
tree0138f26b95005b27ecc888e0c2dacf5f7ffe09b5 /contrib/python/pyrtaudio/PyRtAudioTest.py
parent24a98a1971301e582dc56ef2c6ac94c342b674dd (diff)
Updates for release 4.0.8, including new python binding, new teststops.cpp program, ALSA "default" flag, and various changes to stopping behavior (GS).
Diffstat (limited to 'contrib/python/pyrtaudio/PyRtAudioTest.py')
-rw-r--r--contrib/python/pyrtaudio/PyRtAudioTest.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/contrib/python/pyrtaudio/PyRtAudioTest.py b/contrib/python/pyrtaudio/PyRtAudioTest.py
new file mode 100644
index 0000000..1966ce5
--- /dev/null
+++ b/contrib/python/pyrtaudio/PyRtAudioTest.py
@@ -0,0 +1,70 @@
+
+import rtaudio as rt
+
+from math import cos
+
+import struct
+
+
+class audio_generator:
+ def __init__(self):
+ self.idx = -1
+ self.freq = 440.
+ def __call__(self):
+ self.idx += 1
+ if self.idx%48000 == 0:
+ self.freq *= 2**(1/12.)
+ return 0.5*cos(2.*3.1416*self.freq*self.idx/48000.)
+
+
+class callback:
+ def __init__(self, gen):
+ self.gen = gen
+ self.i = 0
+ def __call__(self,playback, capture):
+ [struct.pack_into("f", playback, 4*o, self.gen()) for o in xrange(256)]
+ self.i = self.i + 256
+ if self.i > 48000*10:
+ print '.'
+ return 1
+
+dac = rt.RtAudio()
+
+n = dac.getDeviceCount()
+print 'Number of devices available: ', n
+
+for i in range(n):
+ try:
+ print dac.getDeviceInfo(i)
+ except rt.RtError as e:
+ print e
+
+
+print 'Default output device: ', dac.getDefaultOutputDevice()
+print 'Default input device: ', dac.getDefaultInputDevice()
+
+print 'is stream open: ', dac.isStreamOpen()
+print 'is stream running: ', dac.isStreamRunning()
+
+oParams = {'deviceId': 1, 'nChannels': 1, 'firstChannel': 0}
+iParams = {'deviceId': 1, 'nChannels': 1, 'firstChannel': 0}
+
+try:
+ dac.openStream(oParams,oParams,48000,256,callback(audio_generator()) )
+except rt.RtError as e:
+ print e
+else:
+ dac.startStream()
+
+ import time
+ print 'latency: ', dac.getStreamLatency()
+
+ while (dac.isStreamRunning()):
+ time.sleep(0.1)
+
+ print dac.getStreamTime()
+
+ dac.stopStream()
+ dac.abortStream()
+ dac.closeStream()
+