File: priming_output.py

package info (click to toggle)
python-sounddevice 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: python: 2,482; sh: 12; makefile: 10
file content (27 lines) | stat: -rwxr-xr-x 793 bytes parent folder | download
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)