blob: a02e837b8ff06d95fdce463dedff24b4607d6f4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
|