summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2015-07-12 19:12:44 +0200
committerMatthias Geier <Matthias.Geier@gmail.com>2017-02-12 12:49:20 +0100
commit21df69e2b2be4d59b5c8257d7efbf27a75eeb8dd (patch)
treebd94d10f45032f3009484ab35712f75569b7691c
parent4f0c8084606366c09561279d8b5f3eb89fc5c7fe (diff)
Add priming_output example
-rwxr-xr-xexamples/priming_output.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/priming_output.py b/examples/priming_output.py
new file mode 100755
index 0000000..a02e837
--- /dev/null
+++ b/examples/priming_output.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+"""Test priming output buffer.
+
+See http://www.portaudio.com/docs/proposals/020-AllowCallbackToPrimeStream.html
+
+Note that this is only supported in some of the host APIs.
+
+"""
+import sounddevice as sd
+
+
+def callback(indata, outdata, frames, time, status):
+ outdata.fill(0)
+ if status.priming_output:
+ assert status.input_underflow, 'input underflow flag should be set'
+ assert not indata.any(), 'input buffer should be filled with zeros'
+ print('Priming output buffer!')
+ outdata[0] = 1
+ else:
+ print('Not priming, I quit!')
+ raise sd.CallbackStop
+
+
+with sd.Stream(channels=2, callback=callback,
+ prime_output_buffers_using_stream_callback=True) as stream:
+ while stream.active:
+ sd.sleep(100)