add xrun handling to the examples

it's very primitive, but it shows adequately what can happen and what to
do about it minimally (that is, complain and move on).
This commit is contained in:
Oswald Buddenhagen
2024-02-01 23:21:12 +01:00
parent d23b26b2e5
commit ae5c4aad9b
4 changed files with 9 additions and 4 deletions

View File

@@ -84,7 +84,8 @@ class SinePlayer(Thread):
except Empty:
pass
if buffer:
self.device.write(buffer)
if self.device.write(buffer) < 0:
print("Playback buffer underrun! Continuing nonetheless ...")
isine = SinePlayer()

View File

@@ -47,7 +47,8 @@ if __name__ == '__main__':
# Read data from stdin
data = f.read(320)
while data:
out.write(data)
if out.write(data) < 0:
print("Playback buffer underrun! Continuing nonetheless ...")
data = f.read(320)
out.close()

View File

@@ -39,7 +39,8 @@ def play(device, f):
data = f.readframes(periodsize)
while data:
# Read data from stdin
device.write(data)
if device.write(data) < 0:
print("Playback buffer underrun! Continuing nonetheless ...")
data = f.readframes(periodsize)

View File

@@ -59,6 +59,8 @@ if __name__ == '__main__':
# Read data from device
l, data = inp.read()
if l:
if l < 0:
print("Capture buffer overrun! Continuing nonetheless ...")
elif l:
f.write(data)
time.sleep(.001)