Skip to content

Commit 21df69e

Browse files
committed
Add priming_output example
1 parent 4f0c808 commit 21df69e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/priming_output.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
"""Test priming output buffer.
3+
4+
See http://www.portaudio.com/docs/proposals/020-AllowCallbackToPrimeStream.html
5+
6+
Note that this is only supported in some of the host APIs.
7+
8+
"""
9+
import sounddevice as sd
10+
11+
12+
def callback(indata, outdata, frames, time, status):
13+
outdata.fill(0)
14+
if status.priming_output:
15+
assert status.input_underflow, 'input underflow flag should be set'
16+
assert not indata.any(), 'input buffer should be filled with zeros'
17+
print('Priming output buffer!')
18+
outdata[0] = 1
19+
else:
20+
print('Not priming, I quit!')
21+
raise sd.CallbackStop
22+
23+
24+
with sd.Stream(channels=2, callback=callback,
25+
prime_output_buffers_using_stream_callback=True) as stream:
26+
while stream.active:
27+
sd.sleep(100)

0 commit comments

Comments
 (0)