mirror of
https://github.com/larsimmisch/pyalsaaudio.git
synced 2026-04-16 08:05:30 +00:00
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:
3
isine.py
3
isine.py
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user